|
1 /* |
|
2 * Copyright (c) 2005 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 the License "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: Represent a session on server side. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #ifndef FEEDS_SERVER_SESSION_H |
|
20 #define FEEDS_SERVER_SESSION_H |
|
21 |
|
22 // INCLUDES |
|
23 #include <e32base.h> |
|
24 |
|
25 #include "LeakTracker.h" |
|
26 #include "UpdateFeedTask.h" |
|
27 #include "UpdateAllFeedsTask.h" |
|
28 #include "ImportFeedsTask.h" |
|
29 #include "PackedFolder.h" |
|
30 |
|
31 // CONSTANTS |
|
32 // Fixed for Bug id - JJUN-78VES7 (FeedsServer crashes under IPC attack) |
|
33 #define KMaxTitleLength 256 |
|
34 // MACROS |
|
35 |
|
36 // DATA TYPES |
|
37 |
|
38 // FUNCTION PROTOTYPES |
|
39 |
|
40 // FORWARD DECLARATIONS |
|
41 |
|
42 // CLASS DECLARATION |
|
43 class CFeedsServer; |
|
44 class CPacked; |
|
45 class CPackedFeed; |
|
46 class CPackedFolder; |
|
47 class CSessionHttpConnection; |
|
48 |
|
49 |
|
50 /** |
|
51 * Represents a session on server side. |
|
52 * |
|
53 * \b Library: FeedsEngine.lib |
|
54 * |
|
55 * @since 3.1 |
|
56 */ |
|
57 NONSHARABLE_CLASS(CFeedsServerSession): public CSession2, public MUpdateFeedTaskObserver, |
|
58 public MUpdateAllFeedsTaskObserver, public MImportFeedsTaskObserver |
|
59 { |
|
60 public: // Constructors and destructor |
|
61 |
|
62 /** |
|
63 * Constructor. |
|
64 */ |
|
65 static CFeedsServerSession* NewL(CFeedsServer& aFeedsServer); |
|
66 |
|
67 /** |
|
68 * Destructor. |
|
69 */ |
|
70 ~CFeedsServerSession(); |
|
71 |
|
72 |
|
73 private: // From CSession2 |
|
74 /** |
|
75 * Client-server framework calls this function to handle messages |
|
76 * from client. This calls DispatchMessageL under the trap harness |
|
77 * in order to propagate any errors back to the client (via |
|
78 * RMessage2::Complete) rather than leaving. |
|
79 * |
|
80 * @since 3.1 |
|
81 * @param aMessage A received message. |
|
82 * @return Void. |
|
83 */ |
|
84 virtual void ServiceL(const RMessage2& aMessage); |
|
85 |
|
86 |
|
87 public: // From MUpdateFeedTaskObserver |
|
88 /** |
|
89 * Notifies the observer that the task is about to start a lengthy |
|
90 * operation. In response the observer could display somekind of |
|
91 * status indicator. |
|
92 * |
|
93 * @since 3.0 |
|
94 * @return void. |
|
95 */ |
|
96 virtual void StartWait(); |
|
97 |
|
98 /** |
|
99 * Called upon completion of the task. |
|
100 * |
|
101 * @since 3.0 |
|
102 * @param aPackedFeed The resulting feed. aPackedFeed is adopted by the |
|
103 * implementing class. |
|
104 * @param aFeedUrl The feed's url. |
|
105 * @param aStatusCode The completion status of the request. |
|
106 * @return Void |
|
107 */ |
|
108 virtual void Completed(CPackedFeed* aPackedFeed, const TDesC& aFeedUrl, TInt aFeedId, TInt aStatusCode); |
|
109 |
|
110 |
|
111 public: // From MUpdateAllFeedsTaskObserver |
|
112 /** |
|
113 * Called to notify the obsever how many feeds remain to be updated. |
|
114 * |
|
115 * @since 3.1 |
|
116 * @param aStatusCode The completion status of the request. |
|
117 * @return Void |
|
118 */ |
|
119 virtual void UpdateAllFeedsProgress(TInt aMaxCount, TInt aRemaining); |
|
120 |
|
121 /** |
|
122 * Called upon completion of the task. |
|
123 * |
|
124 * @since 3.1 |
|
125 * @param aStatusCode The completion status of the request. |
|
126 * @return Void |
|
127 */ |
|
128 virtual void UpdateAllFeedsCompleted(TInt aStatusCode); |
|
129 |
|
130 /** |
|
131 * Returns the server's http-connection instance; |
|
132 * |
|
133 * @since 3.1 |
|
134 * @return The database. |
|
135 */ |
|
136 inline virtual CHttpConnection& HttpConnection() {return (CHttpConnection&) *iHttpConnection;} |
|
137 |
|
138 public: // From MImportFeedsTaskObserver |
|
139 /** |
|
140 * Called to notify the obsever to indicate the start of OPML import |
|
141 * |
|
142 * @since 3.2 |
|
143 * @return Void |
|
144 */ |
|
145 virtual void StartImportWait(); |
|
146 |
|
147 /** |
|
148 * Called to notify the obsever to indicate the completion OPML import |
|
149 * |
|
150 * @since 3.2 |
|
151 * @param aStatusCode The completion status of the request. |
|
152 * @return Void |
|
153 */ |
|
154 virtual void ImportCompleted(TInt aStatusCode); |
|
155 |
|
156 public: // New methods |
|
157 /** |
|
158 * |
|
159 * |
|
160 * @since 3.1 |
|
161 * @param aMessage The message to write to. |
|
162 * @return void. |
|
163 */ |
|
164 void NetworkConnectionNeededL(); |
|
165 |
|
166 |
|
167 private: // New methods |
|
168 /** |
|
169 * C++ default constructor. |
|
170 */ |
|
171 CFeedsServerSession(CFeedsServer& aFeedsServer); |
|
172 |
|
173 /** |
|
174 * By default Symbian 2nd phase constructor is private. |
|
175 */ |
|
176 void ConstructL(); |
|
177 |
|
178 /** |
|
179 * Handle messages from the client. |
|
180 * |
|
181 * @since 3.1 |
|
182 * @param aMessage A received message. |
|
183 * @return Void. |
|
184 */ |
|
185 void DispatchMessageL(const RMessage2& aMessage); |
|
186 |
|
187 /** |
|
188 * Returns the root folder item -- fetching it if need be. |
|
189 * |
|
190 * @since 3.1 |
|
191 * @param aMessage A received message. |
|
192 * @return void. |
|
193 */ |
|
194 void GetRootFolderL(const RMessage2& aMessage); |
|
195 |
|
196 /** |
|
197 * Returns the requested feed -- fetching it if need be. |
|
198 * |
|
199 * @since 3.1 |
|
200 * @param aMessage A received message. |
|
201 * @return void. |
|
202 */ |
|
203 void GetFeedL(const RMessage2& aMessage); |
|
204 |
|
205 /** |
|
206 * Cancel all activities that can be cancelled. |
|
207 * |
|
208 * @since 3.1 |
|
209 * @param aMessage A received message. |
|
210 * @return void. |
|
211 */ |
|
212 void CancelAllRequestsL(const RMessage2& aMessage); |
|
213 |
|
214 /** |
|
215 * Cancel all feed related activities that can be cancelled. |
|
216 * |
|
217 * @since 3.1 |
|
218 * @return void. |
|
219 */ |
|
220 void CancelFeedRequestsL(); |
|
221 |
|
222 /** |
|
223 * Cancel all folder related activities that can be cancelled. |
|
224 * |
|
225 * @since 3.1 |
|
226 * @return void. |
|
227 */ |
|
228 void CancelFolderRequestsL(); |
|
229 |
|
230 /** |
|
231 * Updates the given feed's item status. |
|
232 * |
|
233 * @since 3.1 |
|
234 * @param aMessage A received message. |
|
235 * @return void. |
|
236 */ |
|
237 void ChangeFeedItemStatusL(const RMessage2& aMessage); |
|
238 |
|
239 /** |
|
240 * Updates the database to reflect the addition of the folder item. |
|
241 * A update root folder item is sent out to all active |
|
242 * folder item sessions. |
|
243 * |
|
244 * @since 3.1 |
|
245 * @param aMessage A received message. |
|
246 * @return void. |
|
247 */ |
|
248 void AddFolderItemL(const RMessage2& aMessage); |
|
249 |
|
250 /** |
|
251 * Updates the database to reflect the edited folder item. |
|
252 * A update root folder item is sent out to all active |
|
253 * folder item sessions. |
|
254 * |
|
255 * @since 3.1 |
|
256 * @param aMessage A received message. |
|
257 * @return void. |
|
258 */ |
|
259 void ChangeFolderItemL(const RMessage2& aMessage); |
|
260 |
|
261 /** |
|
262 * Updates the database to reflect the deletion of the folder item. |
|
263 * A update root folder item is sent out to all active |
|
264 * folder item sessions. |
|
265 * |
|
266 * @since 3.1 |
|
267 * @param aMessage A received message. |
|
268 * @return void. |
|
269 */ |
|
270 void DeleteFolderItemsL(const RMessage2& aMessage); |
|
271 |
|
272 /** |
|
273 * Updates the database to reflect the moved folder items. |
|
274 * A update root folder item is sent out to all active |
|
275 * folder item sessions. |
|
276 * |
|
277 * @since 3.1 |
|
278 * @param aMessage A received message. |
|
279 * @return void. |
|
280 */ |
|
281 void MoveFolderItemsL(const RMessage2& aMessage); |
|
282 |
|
283 /** |
|
284 * Updates the database to reflect the new parentage of the |
|
285 * folder items. A update root folder item is sent out to |
|
286 * all active folder item sessions. |
|
287 * |
|
288 * @since 3.1 |
|
289 * @param aMessage A received message. |
|
290 * @return void. |
|
291 */ |
|
292 void MoveFolderItemsToL(const RMessage2& aMessage); |
|
293 |
|
294 /** |
|
295 * Update the given folder items or all feeds associated with the folder list id. |
|
296 * |
|
297 * @since 3.1 |
|
298 * @param aMessage A received message. |
|
299 * @return void. |
|
300 */ |
|
301 void UpdateFolderItemsL(const RMessage2& aMessage); |
|
302 |
|
303 /** |
|
304 * Returns the settings. |
|
305 * |
|
306 * @since 3.1 |
|
307 * @param aMessage A received message. |
|
308 * @return void. |
|
309 */ |
|
310 void GetSettingsL(const RMessage2& aMessage); |
|
311 |
|
312 /** |
|
313 * Updates the database to reflect the new settings. |
|
314 * A update settings is sent out to all active |
|
315 * server sessions. |
|
316 * |
|
317 * @since 3.1 |
|
318 * @param aMessage A received message. |
|
319 * @return void. |
|
320 */ |
|
321 void ChangeSettingsL(const RMessage2& aMessage); |
|
322 |
|
323 /** |
|
324 * Sets up a notifier to execute when the settings changes. |
|
325 * |
|
326 * @since 3.2 |
|
327 * @param aMessage A received message. |
|
328 * @return void. |
|
329 */ |
|
330 void WatchSettingsL(const RMessage2& aMessage); |
|
331 |
|
332 /** |
|
333 * Disconnect the session http connection provided by client app. |
|
334 * |
|
335 * @since 3.1 |
|
336 * @return void. |
|
337 */ |
|
338 void DisconnectManualUpdateConnection(const RMessage2& aMessage); |
|
339 |
|
340 /** |
|
341 * Sets up a notifier to execute when the folder list changes. |
|
342 * |
|
343 * @since 3.1 |
|
344 * @param aMessage A received message. |
|
345 * @return void. |
|
346 */ |
|
347 void WatchFolderListL(const RMessage2& aMessage); |
|
348 |
|
349 /** |
|
350 * Notify the session that the given folder-list changed. |
|
351 * |
|
352 * @since 3.1 |
|
353 * @return void. |
|
354 */ |
|
355 void NotifyFolderListChanged(TInt aFolderListId); |
|
356 |
|
357 /** |
|
358 * Notify the session that the settings of given folder-list changed. |
|
359 * |
|
360 * @since 3.2 |
|
361 * @return void. |
|
362 */ |
|
363 void NotifySettingsChanged(TInt aFolderListId); |
|
364 |
|
365 /** |
|
366 * Called upon completion of the task -- helper method for Completed. |
|
367 * |
|
368 * @since 3.1 |
|
369 * @param aPackedFeed The resulting feed. Adopted by this method. |
|
370 * @param aFeedUrl The feed's url. |
|
371 * @param aStatusCode The completion status of the request. |
|
372 * @return Void |
|
373 */ |
|
374 void CompletedHelperL(CPackedFeed*& aPackedFeed, const TDesC& aFeedUrl,TInt aFeedId); |
|
375 |
|
376 /** |
|
377 * Send the next chunk of the token-array to the client. |
|
378 * |
|
379 * @since 3.1 |
|
380 * @param aPacked The source of the payload to send. |
|
381 * @param aMessage The message to write to. |
|
382 * @return void. |
|
383 */ |
|
384 void SendTokenChunkL(CPacked& aPacked, const RMessagePtr2& aMessage); |
|
385 |
|
386 /** |
|
387 * Send the next chunk of the string-table to the client. |
|
388 * |
|
389 * @since 3.1 |
|
390 * @param aPacked The source of the payload to send. |
|
391 * @param aMessage The message to write to. |
|
392 * @return void. |
|
393 */ |
|
394 void SendStringTableChunkL(CPacked& aPacked, const RMessage2& aMessage); |
|
395 |
|
396 /** |
|
397 * Set the connection to use. |
|
398 * |
|
399 * @since 3.1 |
|
400 * @param aMessage The message to write to. |
|
401 * @return void. |
|
402 */ |
|
403 void SetConnectionL(const RMessage2& aMessage); |
|
404 |
|
405 /** |
|
406 * Import OPML file passed from the client. |
|
407 * |
|
408 * @since 3.2 |
|
409 * @param aMessage The message passed by client |
|
410 * @return void. |
|
411 */ |
|
412 void ImportOPMLL( const RMessage2& aMessage ); |
|
413 |
|
414 /** |
|
415 * Import OPML file passed from the client asyncronously. |
|
416 * |
|
417 * @since 3.2 |
|
418 * @param aMessage The message passed by client |
|
419 * @return void. |
|
420 */ |
|
421 void ImportOPMLAsyncL( const RMessage2& aMessage ); |
|
422 |
|
423 /** |
|
424 * Export feeds as an OPML file passed from the client. |
|
425 * |
|
426 * @since 3.2 |
|
427 * @return void. |
|
428 */ |
|
429 void ExportOPMLL( const RMessage2& aMessage ); |
|
430 |
|
431 /** |
|
432 * Completes any pending (asynchronous) message from the client |
|
433 * with the specified error code. |
|
434 */ |
|
435 void CompleteClientPendingMessage( TInt aCompletionCode = KErrNone ); |
|
436 |
|
437 /** |
|
438 * Set up an asynchronous message from the client so that we can |
|
439 * complete it at a later date. |
|
440 */ |
|
441 void SetClientPendingMessage( RMessagePtr2 aMessage ); |
|
442 |
|
443 /** |
|
444 * Extracts the message sent by the client |
|
445 * |
|
446 * @since 3.2 |
|
447 * @return void. |
|
448 */ |
|
449 void ExtractClientImportMessageL(); |
|
450 |
|
451 /** |
|
452 * Callback function for calling SendTokenChunkL from CompletedHelperL() function |
|
453 * This ensures if GetFeedL call was cancelled then no data should be sent to client. |
|
454 * |
|
455 * @since ? |
|
456 * @ param aPtr Pointer to CFeedServerSession class |
|
457 * @return Integer |
|
458 */ |
|
459 static TInt LazyCallBack(TAny* aPtr); |
|
460 |
|
461 /** |
|
462 * Called upon completion of the task. |
|
463 * |
|
464 * @since 7.1 |
|
465 * @param aStatusCode The completion status of the request. |
|
466 * @return Void |
|
467 */ |
|
468 void UpdateAllFeedsCompletedL(TInt aStatusCode); |
|
469 |
|
470 |
|
471 private: // Friends |
|
472 friend class CFeedsServer; |
|
473 |
|
474 |
|
475 private: |
|
476 TLeakTracker iLeakTracker; |
|
477 |
|
478 CFeedsServer& iFeedsServer; |
|
479 CSessionHttpConnection* iHttpConnection; |
|
480 |
|
481 CUpdateAllFeedsTask* iUpdateAllFeedsTask; |
|
482 TInt iUpdateAllFolderListId; |
|
483 TInt iFolderListId; |
|
484 CUpdateFeedTask* iUpdateFeedTask; |
|
485 RMessagePtr2 iPendingMessage; |
|
486 |
|
487 // TODO: These variables aren't safe to use if multiple requests |
|
488 // are being made in the same RFeedsServer session. This would be |
|
489 // an issue if the client had two active RFeeds or two active |
|
490 // RFolderItems or even one active RFeed and one active RFolderItem |
|
491 // (which may happen if a client is fetching a feed and a different |
|
492 // client changes their shared folder list). |
|
493 CPackedFeed* iPackedFeed; |
|
494 TBool iStoreFeeds; |
|
495 |
|
496 CPackedFolder* iPackedFolder; |
|
497 |
|
498 TInt iWatchFolderListId; |
|
499 RMessage2 iWatchFolderListMessage; |
|
500 RMessagePtr2 iWatchSettingsMessage; |
|
501 |
|
502 // iResponseTokensSent and iResponseOffset are used by GetFeed and GetRootFolder |
|
503 // There may be multiple GetFeed or GetRootFolder request coming from client for one feed or |
|
504 // folder list request,These two variable keep track of what part of CPacked should be sent |
|
505 // to the client. |
|
506 // for GetRootFolder iCurrentRequest = 0 |
|
507 // for GetFeed iCurrentRequest = 1; |
|
508 TInt iCurrentRequest; |
|
509 TBool iResponseTokensSent[2]; |
|
510 TInt iResponseOffset[2]; |
|
511 |
|
512 CImportFeedsTask* iOPMLImportTask; |
|
513 |
|
514 TInt iCurrOp; |
|
515 TInt iPrevOp; |
|
516 HBufC* iExportOPMLFileName; |
|
517 CIdle* iLazyCaller; //To call SetTokenChunkL function; |
|
518 TInt iPendingStatus; |
|
519 TInt iPendingMessageHandle; |
|
520 TBool iGetFeedCalled; |
|
521 |
|
522 |
|
523 }; |
|
524 |
|
525 |
|
526 #endif // FEEDS_SERVER_SESSION_H |
|
527 |
|
528 // End of File |