|
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 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: Main transaction class for handling server client communication |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #ifndef TRANSACTION_H |
|
20 #define TRANSACTION_H |
|
21 |
|
22 // INCLUDES |
|
23 #include <e32base.h> |
|
24 #include <e32std.h> |
|
25 |
|
26 #include <ApEngineconsts.h> |
|
27 #include "FeedsServerMsg.h" |
|
28 |
|
29 #include "FeedsEntity.h" |
|
30 #include "FeedsInterface.h" |
|
31 |
|
32 // CONSTANTS |
|
33 |
|
34 // MACROS |
|
35 |
|
36 // FUNCTION PROTOTYPES |
|
37 |
|
38 // CLASS DECLARATION |
|
39 class CIdle; |
|
40 class CPackedFolder; |
|
41 class CPackedFeed; |
|
42 class CFeedsMap; |
|
43 class CTransaction; |
|
44 class RFeedsInterface; |
|
45 class CFeedsEntity; |
|
46 struct TFeedsServerSetting; |
|
47 |
|
48 // DATA TYPES |
|
49 |
|
50 // Feeds Events |
|
51 enum TFeedsEvent |
|
52 { |
|
53 EFeedsRequestCompleted, |
|
54 EFeedsRequestFailed |
|
55 }; |
|
56 |
|
57 class CTransaction : public CActive |
|
58 { |
|
59 public: |
|
60 // Data types |
|
61 enum TTransactionType |
|
62 { |
|
63 ENone = 0, |
|
64 // folder related |
|
65 EFetchRootFolderItem, |
|
66 EWatchForChanges, |
|
67 EAddFolderItem, |
|
68 EDeleteFolderItem, |
|
69 EChangeFolderItem, |
|
70 EMoveFolderItem, |
|
71 EMoveFolderItemTo, |
|
72 EUpdateFolderItem, |
|
73 EImportOPML, |
|
74 EExportOPML, |
|
75 |
|
76 // feed related |
|
77 EFetchFeed, |
|
78 EUpdateItemStatus, |
|
79 |
|
80 // general client related |
|
81 EChangeSettings, |
|
82 EFetchSettings, |
|
83 EWatchForSettingChanges, |
|
84 ECancelAll, |
|
85 EDisconnectManualUpdateConnection, |
|
86 EPrintDBTables |
|
87 }; |
|
88 |
|
89 public: |
|
90 // Construct/Destructor |
|
91 /** |
|
92 * Two-phased constructor. |
|
93 */ |
|
94 static CTransaction* NewL(MTransactionObserver& aObserver, TInt aUniqueId, |
|
95 TInt aFolderListId); |
|
96 |
|
97 static CTransaction* NewLC(MTransactionObserver& aObserver, TInt aUniqueId, |
|
98 TInt aFolderListId); |
|
99 |
|
100 /** |
|
101 * Destructor. |
|
102 */ |
|
103 virtual ~CTransaction(); |
|
104 |
|
105 public: |
|
106 // From CActive |
|
107 /** |
|
108 * Implements cancellation of an outstanding request. |
|
109 * |
|
110 * @return void. |
|
111 */ |
|
112 virtual void DoCancel(); |
|
113 |
|
114 /** |
|
115 * Handles an active object's request completion event. |
|
116 * |
|
117 * @return void. |
|
118 */ |
|
119 virtual void RunL(); |
|
120 |
|
121 /** |
|
122 * Handles an active object's errors. |
|
123 * |
|
124 * @param aError The error. |
|
125 * @return A status code. |
|
126 */ |
|
127 virtual TInt RunError(TInt aError); |
|
128 |
|
129 public: |
|
130 // New methods |
|
131 /** |
|
132 * Starts an CIdle to delete the instance after the callstack has unrolled. |
|
133 * |
|
134 * @return Void |
|
135 */ |
|
136 IMPORT_C void AutoDelete(); |
|
137 |
|
138 /** |
|
139 * Returns the handler's type. |
|
140 * |
|
141 * @return Void |
|
142 */ |
|
143 IMPORT_C TTransactionType Type(); |
|
144 |
|
145 private: |
|
146 // New Methods |
|
147 /** |
|
148 * C++ default constructor. |
|
149 */ |
|
150 CTransaction(MTransactionObserver& aObserver, TInt aUniqueId, |
|
151 TInt aFolderListId); |
|
152 |
|
153 /** |
|
154 * By default Symbian 2nd phase constructor is private. |
|
155 */ |
|
156 void ConstructL(); |
|
157 |
|
158 /** |
|
159 * Starts the handler |
|
160 * |
|
161 * @return void |
|
162 */ |
|
163 void Start(); |
|
164 |
|
165 /** |
|
166 * Called to handle the response. |
|
167 * |
|
168 * @return Void |
|
169 */ |
|
170 void RequestCompletedL(TInt aStatusCode); |
|
171 |
|
172 /** |
|
173 * Request the FeedsServer to cancel all activities that can be cancelled. |
|
174 * |
|
175 * @return void |
|
176 */ |
|
177 void CancelAllL(); |
|
178 |
|
179 private: |
|
180 /** |
|
181 * Deletes the instance after the callstack has unrolled.. |
|
182 * |
|
183 * @return Void |
|
184 */ |
|
185 static TInt DelayedDelete(TAny* aPtr); |
|
186 |
|
187 public: // Function from client request handler |
|
188 /** |
|
189 * Print tables of database. |
|
190 * |
|
191 * @since 7.1 |
|
192 * @return void |
|
193 */ |
|
194 void DebugPrintTables(); |
|
195 |
|
196 /** |
|
197 * Disconnect connection provided by client for manual update. |
|
198 * |
|
199 * @return void |
|
200 */ |
|
201 void DisconnectManualUpdateConnection(); |
|
202 |
|
203 /** |
|
204 * Sets up a notifier to execute when the settings of given folder list changes. |
|
205 * |
|
206 * @param aFolderListId The folder-list's id. |
|
207 * @return void |
|
208 */ |
|
209 void WatchSettingsL(); |
|
210 |
|
211 /** |
|
212 * Handles the upating of the FeedsServer settings. |
|
213 * |
|
214 * @return void |
|
215 */ |
|
216 void ChangeServerSettingsL(const TFeedsServerSetting& aNewSetting); |
|
217 |
|
218 /** |
|
219 * Handles the fetching of the FeedsServer settings. |
|
220 * |
|
221 * @return void |
|
222 */ |
|
223 void FetchServerSettingsL(); |
|
224 |
|
225 /** |
|
226 * Handles the fetching of the feeds server settings synchronously. |
|
227 * |
|
228 * @since 7.1 |
|
229 * @return void |
|
230 */ |
|
231 void FetchServerSettingsSyncL(); |
|
232 |
|
233 |
|
234 /** |
|
235 * Returns the FeedsServer's settings. |
|
236 * |
|
237 * @return The settings. |
|
238 */ |
|
239 IMPORT_C TFeedsServerSetting Settings(); |
|
240 |
|
241 public: |
|
242 /** |
|
243 * Sets the feed interface object |
|
244 * |
|
245 * @param aFeedInterface |
|
246 * @return void |
|
247 */ |
|
248 void SetFeedInterface(RFeedsInterface* aFeedInterface) |
|
249 { |
|
250 iFeedInterface = aFeedInterface; |
|
251 } |
|
252 |
|
253 /** |
|
254 * Returns transaction id |
|
255 * |
|
256 * @return Transaction id |
|
257 */ |
|
258 IMPORT_C TInt GetId(); |
|
259 |
|
260 /** |
|
261 * Returns Status code |
|
262 * |
|
263 * @return Status code |
|
264 */ |
|
265 IMPORT_C TInt GetStatusCode(); |
|
266 |
|
267 /** |
|
268 * Cancels the request |
|
269 * @return Status code |
|
270 */ |
|
271 IMPORT_C void CancelRequest(); |
|
272 |
|
273 public: |
|
274 //Folder related functions |
|
275 /** |
|
276 * Fetch the root folder associated with the given folder list id. |
|
277 * |
|
278 * @param aFolderListId The folder-list's id. |
|
279 * @return void |
|
280 */ |
|
281 void FetchFolderItemL(TBool aItemTitleNeed); |
|
282 |
|
283 /** |
|
284 * Add a new folder item. |
|
285 * |
|
286 * @param aTitle The title. |
|
287 * @param aUrl The url if this is not a folder. |
|
288 * @param aIsFolder Whether or not this is a folder. |
|
289 * @param aParent The parent folder-item. |
|
290 * @return void |
|
291 */ |
|
292 void AddFolderItemL(const TDesC& aTitle, const TDesC& aUrl, |
|
293 TBool aIsFolder, const CFeedsEntity& aParent, TInt aFreq); |
|
294 |
|
295 /** |
|
296 * Change a folder item. |
|
297 * |
|
298 * @param aTitle The title. |
|
299 * @param aUrl The url if this is not a folder. |
|
300 * @return void |
|
301 */ |
|
302 void ChangeFolderItemL(const CFeedsEntity& aFolderItem, |
|
303 const TDesC& aTitle, const TDesC& aUrl, TInt aFreq); |
|
304 |
|
305 /** |
|
306 * Delete one or more folder items. |
|
307 * |
|
308 * @param aFolderItems The list of folder items. |
|
309 * @return void |
|
310 */ |
|
311 void DeleteFolderItemL(const RPointerArray<const CFeedsEntity>& aFolderItems); |
|
312 |
|
313 /** |
|
314 * Export one or more folder items. |
|
315 * |
|
316 * @param aFolderItems The list of folder items. |
|
317 * @return void |
|
318 */ |
|
319 void ExportFolderItemL(const RPointerArray<const CFeedsEntity>& aFolderItems, |
|
320 const TDesC &aExportFileName); |
|
321 |
|
322 /** |
|
323 * Move one or more folder items to a different parent folder. |
|
324 * |
|
325 * @param aFolderItems The list of folder items. |
|
326 * @param aParent The parent. |
|
327 * @return void |
|
328 */ |
|
329 void MoveFolderItemsToL(const RPointerArray<const CFeedsEntity>& aFolderItems, |
|
330 const CFeedsEntity& aParent); |
|
331 |
|
332 /** |
|
333 * Move one or more folder items to a new position. |
|
334 * |
|
335 * @param aFolderItems The list of folder items. |
|
336 * @param aIndex The target index. |
|
337 * @return void |
|
338 */ |
|
339 void MoveFolderItemsL(const RPointerArray<const CFeedsEntity>& aFolderItems, |
|
340 TInt aIndex); |
|
341 |
|
342 /** |
|
343 * Update one or more feed. |
|
344 * |
|
345 * @param aFolderItems The list of folder items. |
|
346 * @return void |
|
347 */ |
|
348 void UpdateFolderItemsL( |
|
349 const RPointerArray<const CFeedsEntity>& aFolderItems); |
|
350 |
|
351 /** |
|
352 * Update all of the feeds associated with the given folder list id. |
|
353 * |
|
354 * @param aFolderListId The folder-list's id. |
|
355 * @return void |
|
356 */ |
|
357 void UpdateFolderItemsL(); |
|
358 |
|
359 /** |
|
360 * Sets up a notifier to execute when the folder list changes. |
|
361 * |
|
362 * @param aFolderListId The folder-list's id. |
|
363 * @return void |
|
364 */ |
|
365 void WatchFolderListL(); |
|
366 |
|
367 /** |
|
368 * Returns the folder-item -- the caller takes ownership. |
|
369 * Only returns a valid folder item after a sucessful call to FetchFolderItemL. |
|
370 * |
|
371 * @return The folder item. |
|
372 */ |
|
373 |
|
374 CFeedsEntity* OrphanFolderItem(); |
|
375 |
|
376 /** |
|
377 * Import OPML file passed from the client. |
|
378 * |
|
379 * @param aFolderListId The folder list id to which imported feeds belong. |
|
380 * @param aAutoUpdate The flag to or not to auto update the feeds with aFolderListId. |
|
381 * @param aPath The OPML file path. |
|
382 * @return void. |
|
383 */ |
|
384 void ImportOPMLL(const TDesC& aPath, TBool aClearFolderList); |
|
385 |
|
386 public: |
|
387 //Feed related functions |
|
388 /** |
|
389 * Fetch the given feed. |
|
390 * |
|
391 * @param aUrl The url of the feed to fetch (if length equals zero then the aFeedId is used instead). |
|
392 * @param aFeedId The id of the feed. |
|
393 * @param aForceUpdate If ETrue the feed is always updated before returning it. |
|
394 * @param aNoCache If ETrue the feed isn't placed in database after updating. |
|
395 * @return void |
|
396 */ |
|
397 void FetchFeedHelperL(const TDesC& aUrl, TInt aFeedId, TBool aForceUpdate, |
|
398 TBool aNoCache); |
|
399 |
|
400 /** |
|
401 * Fetch the given feed. |
|
402 * |
|
403 * @param aUrl The url of the feed to fetch. |
|
404 * @param iFolderListId The folder list ID associate with the feed. |
|
405 * @param aForceUpdate If ETrue the feed is always updated before returning it. |
|
406 * @param aNoCache If ETrue the feed isn't placed in database after updating. |
|
407 * @return void |
|
408 */ |
|
409 void FetchFeedL(const TDesC& aUrl, TBool aForceUpdate, TBool aNoCache); |
|
410 |
|
411 /** |
|
412 * Fetch the given feed. |
|
413 * |
|
414 * @param aFeedId The id of the feed. |
|
415 * @param aForceUpdate If ETrue the feed is always updated before returning it. |
|
416 * @param aNoCache If ETrue the feed isn't placed in database after updating. |
|
417 * @return void |
|
418 */ |
|
419 void FetchFeedL(TInt aFeedId, TBool aForceUpdate = EFalse, TBool aNoCache = EFalse); |
|
420 |
|
421 /** |
|
422 * Handles the upating of a the feed's item-status. |
|
423 * |
|
424 * @param aFeedId The feed. |
|
425 * @param aItemIds The id's of the items to update. |
|
426 * @param aItemStatus The new status of the items. |
|
427 * @return void |
|
428 */ |
|
429 void UpdateItemStatusL(TInt aFeedId, const RArray<TInt>& aItemIds, |
|
430 const RArray<TFeedItemStatus>& aItemStatus, TInt aUnreadCount); |
|
431 |
|
432 /** |
|
433 * Returns the feedentity -- the caller takes ownership. |
|
434 * |
|
435 * @return The FeedsEntity. |
|
436 */ |
|
437 CFeedsEntity* OrphanFeedsEntity(); |
|
438 |
|
439 /** |
|
440 * Returns Type of transaction being handled by this object |
|
441 * |
|
442 * @return TTransactionType. |
|
443 */ |
|
444 IMPORT_C TTransactionType GetType(); |
|
445 |
|
446 /** |
|
447 * Extract the current settings from the servers response. |
|
448 * |
|
449 * @since 7.1 |
|
450 * @param aResponseBuffer The response buffer to extract the settings from. |
|
451 * @return The settings. |
|
452 */ |
|
453 static TFeedsServerSetting SettingsFromResponseBuffPtrL(CBufFlat& aResponseBuffer); |
|
454 |
|
455 /** |
|
456 * returns the current settings. |
|
457 * |
|
458 * @since 7.1 |
|
459 * @param . |
|
460 * @return The settings. |
|
461 */ |
|
462 void GetSetting(TFeedsServerSetting& aSetting); |
|
463 |
|
464 // friend class declaration. |
|
465 friend class RFeedsInterface; |
|
466 |
|
467 private: |
|
468 /** |
|
469 * Initialises iSetting by reading response buffer from server. |
|
470 * |
|
471 * @return ETrue if waiter is completed. |
|
472 */ |
|
473 void SettingsFromResponseBufferL(); |
|
474 |
|
475 private: // Data members. |
|
476 |
|
477 MTransactionObserver& iObserver; |
|
478 TTransactionType iType; |
|
479 CBufFlat* iRequestBuff; |
|
480 TPtrC8 iRequestBuffPtr; |
|
481 TInt iFolderListId; // Folderlist should be stored in transaction instead of FeedsEntity |
|
482 |
|
483 // Data |
|
484 CIdle* iAutoDelete; |
|
485 TBool iNotifyOnCancel; |
|
486 TInt iId; |
|
487 TInt iTranStatus; |
|
488 |
|
489 // Used to handle FetchFolderItemL/FetchFeed |
|
490 TFeedsServerResponseType iServerResponseType; |
|
491 TPckg<TFeedsServerResponseType> iServerResponseTypePkg; |
|
492 HBufC8* iResponseBuffer; |
|
493 CBufFlat* iSettingsResponseBuffer; |
|
494 TPtr8 iResponsePtr; |
|
495 CPacked* iPacked; |
|
496 CFeedsEntity* iFeedsEntity; |
|
497 TFeedsServerSetting iSetting; |
|
498 |
|
499 // Used to handle AddFolderItemL |
|
500 TInt iResponseEntryId; |
|
501 TPckg<TInt> iResponseEntryIdPkg; |
|
502 RFeedsInterface* iFeedInterface; |
|
503 |
|
504 }; |
|
505 |
|
506 #endif // TRANSACTION_H |
|
507 |
|
508 // End of File |