|
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 "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: DS notepad datastore. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #ifndef __NSMLNOTEPADDATASTORE_H__ |
|
20 #define __NSMLNOTEPADDATASTORE_H__ |
|
21 |
|
22 //CONSTANTS |
|
23 const TInt KNSmlCompactAfterChanges = 16; |
|
24 const TInt KNSmlDataStoreMaxSize = 102400; // 100 k |
|
25 const TInt KNSmlDefaultStoreNameMaxSize = 256; |
|
26 const TInt KNSmlItemDataExpandSize = 1024; |
|
27 const TInt KUTF8Lenght = 4; |
|
28 const TInt KNullCharLen = 1; |
|
29 const TInt KUnicodeSize = 2; |
|
30 |
|
31 |
|
32 _LIT(KNSmlNotepadStoreFormatRsc,"z:NSmlNotepadDataStoreFormat.rsc"); |
|
33 _LIT( KNSmlDriveC, "C" ); |
|
34 _LIT8( KMimePlainText, "text/plain" ); |
|
35 _LIT8( KMimePlainTextVersion, "1.0" ); |
|
36 |
|
37 // FORWARD DECLARATIONS |
|
38 class CNSmlNotepadModsFetcher; |
|
39 class CNSmlChangeFinder; |
|
40 class CNSmlNotepadDatabase; |
|
41 class CNpdItem; |
|
42 class CNSmlDataItemUidSet; |
|
43 |
|
44 // CLASS DECLARATION |
|
45 |
|
46 // ------------------------------------------------------------------------------------------------ |
|
47 // CNSmlNotepadDataStore |
|
48 // |
|
49 // @lib nsmlnotepaddataprovider.lib |
|
50 // ------------------------------------------------------------------------------------------------ |
|
51 class CNSmlNotepadDataStore : public CSmlDataStore |
|
52 { |
|
53 public: |
|
54 /** |
|
55 * Two-phased constructor. |
|
56 */ |
|
57 static CNSmlNotepadDataStore* NewL(); |
|
58 |
|
59 /** |
|
60 * Destructor. |
|
61 */ |
|
62 virtual ~CNSmlNotepadDataStore(); |
|
63 |
|
64 private: |
|
65 |
|
66 /** |
|
67 * Default constructor. |
|
68 */ |
|
69 CNSmlNotepadDataStore(); |
|
70 |
|
71 /** |
|
72 * 2nd phase constructor. |
|
73 */ |
|
74 void ConstructL(); |
|
75 |
|
76 |
|
77 |
|
78 public: |
|
79 /** |
|
80 * Default store name of client. |
|
81 * @return Default store name. |
|
82 */ |
|
83 const TDesC& DefaultStoreNameL() const; |
|
84 |
|
85 /** |
|
86 * Gets a list of all notepad databases on client. |
|
87 * @return List of databases. |
|
88 */ |
|
89 CDesCArray* DoListStoresLC(); |
|
90 |
|
91 |
|
92 /** |
|
93 * DoOpenL() opens the data store specified by aStoreName asynchronously. |
|
94 * @param aStoreName The name of the data store to open. |
|
95 * @param aContext Identifies the specific synchronisation relationship to use for the synchronisation. |
|
96 * @param aStatus On completion of the open, contains the result code. |
|
97 */ |
|
98 |
|
99 void DoOpenL(const TDesC& aStoreName, MSmlSyncRelationship& aContext, TRequestStatus& aStatus); |
|
100 |
|
101 /** |
|
102 * DoCancelRequest() cancels the current asynchronous request, including open. Only one asynchronous request may be outstanding at any one time. |
|
103 */ |
|
104 void DoCancelRequest(); |
|
105 |
|
106 /** |
|
107 * DoStoreName() returns the name of the open data store. |
|
108 * @return The name of the currently opened data store. |
|
109 */ |
|
110 const TDesC& DoStoreName() const; |
|
111 |
|
112 /** |
|
113 * DoBeginTransactionL() starts the transaction mode. During this mode calls to CreateItemL, ReplaceItemL, |
|
114 * WriteItemL, CommitItemL, MoveItemL, DeleteItemL and SoftDeleteItemL will be part of this transaction. |
|
115 * Their RequestStatus must be completed, even if the change is not yet really executed in the Data Store. |
|
116 * If a RequestStatus is completed with an error code, the transaction has failed and a rollback must be |
|
117 * done. In this case RevertTransaction will be called. |
|
118 */ |
|
119 void DoBeginTransactionL(); |
|
120 |
|
121 /** |
|
122 * DoCommitTransactionL() will be called at the end of a successful transaction. At this point in time the |
|
123 * operations within the transaction are applied to the Data Store in an atomic way. If all operations |
|
124 * succeed, the RequestStatus must be completed with KErrNone. If an operation fails, a rollback must be |
|
125 * done and the RequestStatus must be completed with an appropriate error code. |
|
126 */ |
|
127 void DoCommitTransactionL(TRequestStatus& aStatus); |
|
128 |
|
129 /** |
|
130 * DoRevertTransaction() will be called to abort an ongoing transaction. None of the operations already |
|
131 * submitted may be applied to the Data Store. The RequestStatus must be completed with KErrNone as a revert |
|
132 * cannot fail. |
|
133 */ |
|
134 void DoRevertTransaction(TRequestStatus& aStatus); |
|
135 |
|
136 /** |
|
137 * DoBeginBatchL() starts the batch mode. During this mode calls to CreateItemL, ReplaceItemL, |
|
138 * WriteItemL, CommitItemL, MoveItemL, DeleteItemL and SoftDeleteItemL will be part of this batch. |
|
139 * Their RequestStatus must be completed with KErrNone, which only signals acceptance of the operation |
|
140 * for batch processing. |
|
141 */ |
|
142 void DoBeginBatchL(); |
|
143 |
|
144 /** |
|
145 * DoCommitBatchL() will be called at the end of the batch mode. This tells the Data Store to |
|
146 * process the batched operations (in the order they were submitted), and to append the error code |
|
147 * for each operation to aResultArray. |
|
148 * The error codes in aResultArray are only valid if the RequestStatus is completed with KErrNone. |
|
149 * If the RequestStatus is completed with an error code none of the operations in the batch mode |
|
150 * were applied to the Data Store. |
|
151 */ |
|
152 void DoCommitBatchL(RArray<TInt>& aResultArray, |
|
153 TRequestStatus& aStatus); |
|
154 |
|
155 /** |
|
156 * DoCancelBatch() will be called to abort an ongoing batch mode. None of the operations already |
|
157 * submitted may be applied to the Data Store. |
|
158 */ |
|
159 void DoCancelBatch(); |
|
160 |
|
161 /** |
|
162 * DoSetRemoteStoreFormatL() sets the SyncML server Data Format - this may optionally be used by the Data |
|
163 * Provider to filter out properties that the server does not support, and should be used to avoid deleting |
|
164 * these properties in case the server sends a changed item to the Data Provider |
|
165 */ |
|
166 void DoSetRemoteStoreFormatL(const CSmlDataStoreFormat& aServerDataStoreFormat); |
|
167 |
|
168 /** |
|
169 * DoSetRemoteMaxObjectSize() sets the SyncML server maximum object size - this may optionally be used by the |
|
170 * Data Provider to not send items to the server exceeding its maximum size. 0 means there is no limit. |
|
171 */ |
|
172 void DoSetRemoteMaxObjectSize(TInt aServerMaxObjectSize); |
|
173 |
|
174 /** |
|
175 * DoMaxObjectSize() gets the Data Store maximum object size which is reported to the SyncML server. 0 means |
|
176 * there is no limit. |
|
177 * @return The maximum object size. |
|
178 */ |
|
179 TInt DoMaxObjectSize() const; |
|
180 |
|
181 /** |
|
182 * DoOpenItemL() opens the data item specified by aUid asynchronously for reading. |
|
183 * @param aUid Item UID which going to be read. |
|
184 * @param aFieldChange Accept field changes. |
|
185 * @param aParent Parent of the item. |
|
186 * @param aSize Size of the item data. |
|
187 * @param aMimeType MIME type of the item. |
|
188 * @param aMimeVer MIME version used on item. |
|
189 * @param aStatus On completion of the opening of item, contains the result code. |
|
190 */ |
|
191 void DoOpenItemL(TSmlDbItemUid aUid, |
|
192 TBool& aFieldChange, |
|
193 TInt& aSize, |
|
194 TSmlDbItemUid& aParent, |
|
195 TDes8& aMimeType, |
|
196 TDes8& aMimeVer, |
|
197 TRequestStatus& aStatus); |
|
198 |
|
199 /** |
|
200 * DoCreateItemL() sets the item properties and reference to aUid which will be created. |
|
201 * @param aUid Reference to item UID which going to be created. |
|
202 * @param aSize Size of the item to be created. |
|
203 * @param aParent Parent of the item. |
|
204 * @param aMimeType MIME type of the item. |
|
205 * @param aMimeVer MIME version used on item. |
|
206 * @param aStatus On completion of the creating an item, contains the result code. |
|
207 */ |
|
208 void DoCreateItemL(TSmlDbItemUid& aUid, |
|
209 TInt aSize, |
|
210 TSmlDbItemUid aParent, |
|
211 const TDesC8& aMimeType, |
|
212 const TDesC8& aMimeVer, |
|
213 TRequestStatus& aStatus); |
|
214 |
|
215 /** |
|
216 * DoReplaceItemL() opens the data item specified by aUid asynchronously to be updated. |
|
217 * @param aUid Item UID which going to be updated. |
|
218 * @param aSize Size of the item data. |
|
219 * @param aParent Parent of the item. |
|
220 * @param aFieldChange Accept field changes. |
|
221 * @param aStatus On completion of the updating of item, contains the result code. |
|
222 */ |
|
223 void DoReplaceItemL(TSmlDbItemUid aUid, |
|
224 TInt aSize, |
|
225 TSmlDbItemUid aParent, |
|
226 TBool aFieldChange, |
|
227 TRequestStatus& aStatus); |
|
228 |
|
229 /** |
|
230 * DoReadItemL() reads data(or size of aBuffer) of an item opened in DoOpenItemL() to given aBuffer. |
|
231 * @param aBuffer Buffer to item data. |
|
232 */ |
|
233 void DoReadItemL(TDes8& aBuffer); |
|
234 |
|
235 /** |
|
236 * DoWriteItemL() writes aData of an item opened in DoCreateItemL() or DoReplaceItemL() to be saved on database. |
|
237 * @param aData Item data (or part of data). |
|
238 */ |
|
239 void DoWriteItemL(const TDesC8& aData); |
|
240 |
|
241 /** |
|
242 * DoCommitItemL() completes an item operation started in DoCreateItemL() or DoReplaceItemL(). |
|
243 * @param aStatus On completion of the operation, contains the result code. |
|
244 */ |
|
245 void DoCommitItemL(TRequestStatus& aStatus); |
|
246 |
|
247 /** |
|
248 * DoCloseItem() completes an item operation started in DoOpenItemL(). |
|
249 */ |
|
250 void DoCloseItem(); |
|
251 |
|
252 /** |
|
253 * DoMoveItemL() moves item specified by aUid asynchronously. |
|
254 * @param aUid Item UID which going to be moved. |
|
255 * @param aNewParent A new parent of the item. |
|
256 * @param aStatus On completion of the moving an item, contains the result code. |
|
257 */ |
|
258 void DoMoveItemL(TSmlDbItemUid aUid, |
|
259 TSmlDbItemUid aNewParent, |
|
260 TRequestStatus& aStatus); |
|
261 |
|
262 /** |
|
263 * DoDeleteItemL() deletes item specified by aUid asynchronously. |
|
264 * @param aUid Item UID which going to be deleted. |
|
265 * @param aStatus On completion of the deleting an item, contains the result code. |
|
266 */ |
|
267 void DoDeleteItemL(TSmlDbItemUid aUid, |
|
268 TRequestStatus& aStatus); |
|
269 |
|
270 /** |
|
271 * DoSoftDeleteItemL() soft deletes item specified by aUid asynchronously. |
|
272 * @param aUid Item UID which going to be softdeleted. |
|
273 * @param aStatus On completion of the softdeleting an item, contains the result code. |
|
274 */ |
|
275 void DoSoftDeleteItemL(TSmlDbItemUid aUid, |
|
276 TRequestStatus& aStatus); |
|
277 |
|
278 /** |
|
279 * DoDeleteAllItemsL() deletes all items from opened database asynchronously. |
|
280 * @param aStatus On completion of delete, contains the result code. |
|
281 */ |
|
282 void DoDeleteAllItemsL(TRequestStatus& aStatus); |
|
283 |
|
284 /** |
|
285 * DoHasSyncHistory() checks if previous sync with opened server and context. |
|
286 * @return ETrue if there is synchonization history. |
|
287 */ |
|
288 TBool DoHasSyncHistory() const; |
|
289 |
|
290 /** |
|
291 * DoAddedItems() gets all added items on client since previous synchronization. |
|
292 * @return Added items. |
|
293 */ |
|
294 const MSmlDataItemUidSet& DoAddedItems() const; |
|
295 |
|
296 /** |
|
297 * DoDeletedItems() gets all deleted items on client since previous synchronization. |
|
298 * @return Deleted items. |
|
299 */ |
|
300 const MSmlDataItemUidSet& DoDeletedItems() const; |
|
301 |
|
302 /** |
|
303 * DoSoftDeletedItems() gets all softdeleted items on client since previous synchronization. |
|
304 * @return Soft deleted items. |
|
305 */ |
|
306 const MSmlDataItemUidSet& DoSoftDeletedItems() const; |
|
307 |
|
308 /** |
|
309 * DoModifiedItems() gets all modified items on client since previous synchronization. |
|
310 * @return Modified items. |
|
311 */ |
|
312 const MSmlDataItemUidSet& DoModifiedItems() const; |
|
313 |
|
314 /** |
|
315 * DoMovedItems() gets all moved items on client since previous synchronization. |
|
316 * @return Moved items. |
|
317 */ |
|
318 const MSmlDataItemUidSet& DoMovedItems() const; |
|
319 |
|
320 /** |
|
321 * DoResetChangeInfoL() resets client synchronization data => next time will be slow sync. |
|
322 * @param aStatus On completion of reset, contains the result code. |
|
323 */ |
|
324 void DoResetChangeInfoL(TRequestStatus& aStatus); |
|
325 |
|
326 /** |
|
327 * DoCommitChangeInfoL() commits client synchronization changes for given aItems list. |
|
328 * @param aStatus On completion of given items, contains the result code. |
|
329 * @param aItems Item ids to be commited. |
|
330 */ |
|
331 void DoCommitChangeInfoL(TRequestStatus& aStatus, |
|
332 const MSmlDataItemUidSet& aItems); |
|
333 |
|
334 /** |
|
335 * DoCommitChangeInfoL() commits all client synchronization changes. |
|
336 * @param aStatus On completion of all items, contains the result code. |
|
337 */ |
|
338 void DoCommitChangeInfoL(TRequestStatus& aStatus); |
|
339 |
|
340 |
|
341 private: |
|
342 /** |
|
343 * DoOwnStoreFormatL() gets the data storeformat from resource file. |
|
344 * @return CSmlDataStoreFormat object |
|
345 */ |
|
346 CSmlDataStoreFormat* DoOwnStoreFormatL(); |
|
347 /** |
|
348 * OpenItemL() opens the the specified item from notepad database. |
|
349 * @param aUid, uid of the memo. |
|
350 * @param aItem, content of the memo. |
|
351 * @return KErrNone on success, system wide error on failure |
|
352 */ |
|
353 TInt OpenItemL(TSmlDbItemUid& aUid,CBufBase& aItem); |
|
354 /** |
|
355 * ConvertSyncItemToNoteL() converst teh sync item(text) to notepad memo item(CNpdItem). |
|
356 * @param aSyncItem, descriptor that represents content of the memo |
|
357 * @param aNote, content of the memo. |
|
358 * @returns KErrNone on success, system wide error on failure. |
|
359 */ |
|
360 TInt ConvertSyncItemToNoteL(const TDesC8& aSyncItem, CNpdItem& aNote); |
|
361 |
|
362 /** |
|
363 * ConvertNoteToSyncItemL() converst the notepad memo item(CNpdItem) to descriptor item(TDesC) |
|
364 * @param aNote, content of the memo. |
|
365 * @returns descriptor of that represents content of the memo. |
|
366 */ |
|
367 HBufC8* ConvertNoteToSyncItemL(CNpdItem& aNote); |
|
368 /** |
|
369 * DoAddItemToDataBaseL() add the the item to the notepad database |
|
370 * @param aItem, represents content of the notepad memo |
|
371 * @returns id the of memo. |
|
372 */ |
|
373 TInt DoAddItemToDataBaseL(CBufBase& aItem,TInt& aUid); |
|
374 |
|
375 /** |
|
376 * DoReplaceItemAtDataBaseL() replaces the tem in notepad database for given uid |
|
377 * @param aItem, represents content of the notepad memo |
|
378 * @param aUid, uid of the memo. |
|
379 */ |
|
380 TInt DoReplaceItemAtDataBaseL(CBufBase& aItem, TInt& aUid); |
|
381 /** |
|
382 * DriveBelowCriticalLevelL() checks the available size of the drive C |
|
383 * @param aSize, size to be check |
|
384 * @returns ETrue if size available else EFalse. |
|
385 */ |
|
386 TBool DriveBelowCriticalLevelL( TInt aSize ); |
|
387 |
|
388 private: // data |
|
389 |
|
390 // MODULE DATA STRUCTURES |
|
391 enum TNSmlDataStoreStatus // DataStore status |
|
392 { |
|
393 ENSmlClosed = 1, |
|
394 ENSmlOpenAndWaiting, |
|
395 ENSmlItemOverflow, |
|
396 ENSmlItemOpen, |
|
397 ENSmlItemCreating, |
|
398 ENSmlItemUpdating |
|
399 }; |
|
400 |
|
401 CNSmlNotepadDatabase* iNpdDb; |
|
402 CNSmlChangeFinder* iChangeFinder; |
|
403 CNSmlNotepadModsFetcher* iNotepadModsFetcher; |
|
404 |
|
405 TRequestStatus* iCallerStatus; |
|
406 |
|
407 TPtrC8 iMimeTypeItem; |
|
408 TPtrC8 iMimeVersionItem; |
|
409 |
|
410 TPtrC8 iUsedMimeType; |
|
411 TPtrC8 iUsedMimeVersion; |
|
412 |
|
413 RStringF iServerMimeType; |
|
414 RStringF iServerMimeVersion; |
|
415 |
|
416 |
|
417 TInt iServerMaxObjectSize; |
|
418 TBool iSnapshotRegistered; |
|
419 TBool iSyncHistory; |
|
420 HBufC* iOpenedStoreName; |
|
421 HBufC* iDefaultStoreName; |
|
422 TInt64 iOpenedStoreId; |
|
423 TInt iReaderPosition; |
|
424 TInt iWriterPosition; |
|
425 TInt* iAddItemId; |
|
426 TInt iReplaceItemId; |
|
427 CBufBase* iItemData; |
|
428 TInt iItemSize; |
|
429 TInt iUid; |
|
430 TKeyArrayFix iKey; |
|
431 CSmlDataStoreFormat* iOwnStoreFormat; |
|
432 TInt iModificationCount; |
|
433 TInt iDrive; |
|
434 RFs iRfs; |
|
435 RStringPool iStringPool; |
|
436 CNSmlDataItemUidSet* iNewUids; |
|
437 CNSmlDataItemUidSet* iDeletedUids; |
|
438 CNSmlDataItemUidSet* iSoftDeletedUids; |
|
439 CNSmlDataItemUidSet* iReplacedUids; |
|
440 CNSmlDataItemUidSet* iMovedUids; |
|
441 TNSmlDataStoreStatus iState; |
|
442 |
|
443 TBool iDataBaseOpened; |
|
444 }; |
|
445 |
|
446 #endif // __NSMLNOTEPADDATASTORE_H__ |
|
447 |
|
448 // End of File |