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