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