|
1 /* |
|
2 * Copyright (c) 2008 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: Pushes data to existing stream from outside |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #ifndef C_CDUNDATAPUSHER_H |
|
20 #define C_CDUNDATAPUSHER_H |
|
21 |
|
22 #include "DunTransporter.h" |
|
23 |
|
24 class MDunCompletionReporter; |
|
25 |
|
26 /** |
|
27 * Class used for storing data related to data push |
|
28 * (data coming from MDunStreamManipulator::NotifyDataPushRequest()) |
|
29 * |
|
30 * @lib dunutils.lib |
|
31 * @since S60 v3.2 |
|
32 */ |
|
33 NONSHARABLE_CLASS( TDunDataPush ) |
|
34 { |
|
35 |
|
36 public: |
|
37 |
|
38 /** |
|
39 * Data to push to the stream (not copied) |
|
40 */ |
|
41 const TDesC8 *iPushedData; |
|
42 |
|
43 /** |
|
44 * Callback to call when data is processed by the stream |
|
45 * If this is NULL then no callback will be made |
|
46 */ |
|
47 MDunCompletionReporter* iCallback; |
|
48 |
|
49 }; |
|
50 |
|
51 /** |
|
52 * Class for notifications of stream manipulator's completion events |
|
53 * |
|
54 * @lib dunutils.lib |
|
55 * @since S60 v3.2 |
|
56 */ |
|
57 NONSHARABLE_CLASS( MDunCompletionReporter ) |
|
58 { |
|
59 |
|
60 public: |
|
61 |
|
62 /** |
|
63 * Gets called when data from |
|
64 * MDunStreamManipulator::NotifyDataPushRequest() has been processed and |
|
65 * CDunDownstream is ready to process more data. |
|
66 * |
|
67 * @since S60 5.0 |
|
68 * @param aAllPushed ETrue if all in the queue were pushed, EFalse otherwise |
|
69 * @return None |
|
70 */ |
|
71 virtual void NotifyDataPushComplete( TBool aAllPushed ) = 0; |
|
72 |
|
73 }; |
|
74 |
|
75 /** |
|
76 * Class for pushing data to existing CDunDownstream stream from outside |
|
77 * |
|
78 * @lib dunutils.lib |
|
79 * @since S60 v3.2 |
|
80 */ |
|
81 NONSHARABLE_CLASS( CDunDataPusher ) : public CActive, |
|
82 public MDunEndpointReady |
|
83 { |
|
84 |
|
85 public: |
|
86 |
|
87 /** |
|
88 * Two-phased constructor. |
|
89 * @param aParent Parent class owning this friend class (CDunDownstream) |
|
90 * @param aStreamCallback Callback to call when events processed |
|
91 * @return Instance of self |
|
92 */ |
|
93 static CDunDataPusher* NewL( CDunDownstream& aParent, |
|
94 MDunCompletionReporter* aStreamCallback ); |
|
95 |
|
96 /** |
|
97 * Destructor. |
|
98 */ |
|
99 virtual ~CDunDataPusher(); |
|
100 |
|
101 /** |
|
102 * Resets data to initial values |
|
103 * |
|
104 * @since S60 3.2 |
|
105 * @return None |
|
106 */ |
|
107 void ResetData(); |
|
108 |
|
109 /** |
|
110 * Sets media to be used for this endpoint |
|
111 * |
|
112 * @since S60 3.2 |
|
113 * @param aComm RComm pointer to use as the endpoint |
|
114 * @return Symbian error code on error, KErrNone otherwise |
|
115 */ |
|
116 TInt SetMedia( RComm* aComm ); |
|
117 |
|
118 /** |
|
119 * Sets media to be used for this endpoint |
|
120 * |
|
121 * @since S60 3.2 |
|
122 * @param aSocket RSocket pointer to use as the endpoint |
|
123 * @return Symbian error code on error, KErrNone otherwise |
|
124 */ |
|
125 TInt SetMedia( RSocket* aSocket ); |
|
126 |
|
127 /** |
|
128 * Adds event notification to queue |
|
129 * |
|
130 * @since S60 3.2 |
|
131 * @param aPushedData Data to push to the stream (not copied) |
|
132 * @param aCallback Callback to call when data is processed by the stream |
|
133 * @return Symbian error code on error, KErrNone otherwise |
|
134 */ |
|
135 TInt AddToEventQueue( const TDesC8 *aPushedData, |
|
136 MDunCompletionReporter* aCallback ); |
|
137 |
|
138 /** |
|
139 * Finds an event from queue |
|
140 * |
|
141 * @since S60 5.0 |
|
142 * @param aPushedData Data to push to the stream (not copied) |
|
143 * @return Index of found event, Symbian error code otherwise |
|
144 */ |
|
145 TInt FindEventFromQueue( const TDesC8 *aPushedData ); |
|
146 |
|
147 /** |
|
148 * Stops one event in the event queue |
|
149 * |
|
150 * @since S60 5.0 |
|
151 * @param aPushedData Data to push to the stream (not copied) |
|
152 * @return Symbian error code on error, KErrNone otherwise |
|
153 */ |
|
154 TInt StopOneEvent( const TDesC8 *aPushedData ); |
|
155 |
|
156 /** |
|
157 * Sends queued data in round robin |
|
158 * |
|
159 * @since S60 3.2 |
|
160 * @return ETrue if sending started, EFalse if nothing to do |
|
161 */ |
|
162 TBool SendQueuedData(); |
|
163 |
|
164 /** |
|
165 * Stops sending for write endpoint |
|
166 * |
|
167 * @since S60 3.2 |
|
168 * @return Symbian error code on error, KErrNone otherwise |
|
169 */ |
|
170 TInt Stop(); |
|
171 |
|
172 /** |
|
173 * Stops sending for write endpoint and clears event queue |
|
174 * |
|
175 * @since S60 3.2 |
|
176 * @return Symbian error code on error, KErrNone otherwise |
|
177 */ |
|
178 TInt StopAndClearQueue(); |
|
179 |
|
180 /** |
|
181 * Signals completion status in round robin and clears event queue |
|
182 * |
|
183 * @return Symbian error code on error, KErrNone otherwise |
|
184 * @return None |
|
185 */ |
|
186 TInt SignalCompletionAndClearQueue(); |
|
187 |
|
188 private: |
|
189 |
|
190 CDunDataPusher( CDunDownstream& aParent, |
|
191 MDunCompletionReporter* aStreamCallback ); |
|
192 |
|
193 void ConstructL(); |
|
194 |
|
195 /** |
|
196 * Initializes this class |
|
197 * |
|
198 * @since S60 3.2 |
|
199 * @return None |
|
200 */ |
|
201 void Initialize(); |
|
202 |
|
203 /** |
|
204 * Manages one event's data push |
|
205 * |
|
206 * @since S60 3.2 |
|
207 * @return None |
|
208 */ |
|
209 TInt ManageOneEvent(); |
|
210 |
|
211 /** |
|
212 * Check whether an error code is severe error or not |
|
213 * |
|
214 * @since S60 3.2 |
|
215 * @param aError Error code to check for severity |
|
216 * @param aIsError ETrue if error code is error, EFalse if not error |
|
217 * @return ETrue if severe error detected, EFalse if not severe error |
|
218 */ |
|
219 TBool ProcessErrorCondition( TInt aError, TBool& aIsError ); |
|
220 |
|
221 // from base class CActive |
|
222 |
|
223 /** |
|
224 * From CActive. |
|
225 * Gets called when endpoint data write complete |
|
226 * |
|
227 * @since S60 3.2 |
|
228 * @return None |
|
229 */ |
|
230 void RunL(); |
|
231 |
|
232 /** |
|
233 * From CActive. |
|
234 * Gets called on cancel |
|
235 * |
|
236 * @since S60 3.2 |
|
237 * @return None |
|
238 */ |
|
239 void DoCancel(); |
|
240 |
|
241 // from base class MDunEndpointReady |
|
242 |
|
243 /** |
|
244 * Gets called when endpoint is ready |
|
245 * |
|
246 * @since S60 5.0 |
|
247 * @return None |
|
248 */ |
|
249 void NotifyEndpointReady(); |
|
250 |
|
251 /** |
|
252 * Gets called when endpoint is not ready |
|
253 * |
|
254 * @since S60 5.0 |
|
255 * @return None |
|
256 */ |
|
257 void NotifyEndpointNotReady(); |
|
258 |
|
259 private: // data |
|
260 |
|
261 /** |
|
262 * Parent class owning this friend class (CDunDownstream) |
|
263 */ |
|
264 CDunDownstream& iParent; |
|
265 |
|
266 /** |
|
267 * Callback to call when notification via MDunCompletionReporter to be made |
|
268 * Not own. |
|
269 */ |
|
270 MDunCompletionReporter* iStreamCallback; |
|
271 |
|
272 /** |
|
273 * Event queue for pushed data requests |
|
274 */ |
|
275 RArray<TDunDataPush> iEventQueue; |
|
276 |
|
277 /** |
|
278 * Current state of data push: active or inactive |
|
279 */ |
|
280 TDunState iPushState; |
|
281 |
|
282 /** |
|
283 * Index of current event to serve |
|
284 */ |
|
285 TInt iEventIndex; |
|
286 |
|
287 /** |
|
288 * Flag to be set when endpoint is ready or not |
|
289 */ |
|
290 TBool iEPReady; |
|
291 |
|
292 /** |
|
293 * RSocket object of local media side |
|
294 * If this is set then iComm is not used |
|
295 * Not own. |
|
296 */ |
|
297 RSocket* iSocket; |
|
298 |
|
299 /** |
|
300 * RComm object of local media or network side |
|
301 * If this is set then iSocket is not used |
|
302 * Not own. |
|
303 */ |
|
304 RComm* iComm; |
|
305 |
|
306 }; |
|
307 |
|
308 #endif // C_DUNDATAPUSHER_H |