omads/omadsextensions/adapters/mms/inc/mmsdatastore.h
changeset 36 9ba7f05d28a5
equal deleted inserted replaced
35:0ca79e3612d9 36:9ba7f05d28a5
       
     1 /*
       
     2 * Copyright (c) 2005-2010 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:  Part of SyncML Data Synchronization Plug In Adapter
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 #ifndef __MMSDATASTORE_H__
       
    21 #define __MMSDATASTORE_H__
       
    22 
       
    23 // INCLUDES
       
    24 #include "mmsdataproviderdefs.h" 
       
    25 #include "changefinder.h"
       
    26 
       
    27 
       
    28 // FORWARD DECLARATIONS
       
    29 class CMsvSession; 
       
    30 class CNSmlDataItemUidSet;
       
    31 class CMmsCodecClient;
       
    32 class CMmsAdapterMsvApi;
       
    33 class CMsvOperationActiveSchedulerWait;
       
    34 class TNSmlSnapshotItem;
       
    35 class COMADSFolderObject;
       
    36 
       
    37 /**
       
    38 * @brief This class is derived from ECom Data Store plugin-interface (CSmlDataStore).
       
    39 * It performs the actual synchronization commands, which are received from
       
    40 * the DS engine.
       
    41 */
       
    42 class CMmsDataStore : public CSmlDataStore
       
    43     {
       
    44 public:  
       
    45     
       
    46     /**
       
    47     * Constructor
       
    48 	*
       
    49 	* @return CMmsDataStore*, a new CSmsDataStore instance.
       
    50     */
       
    51     static CMmsDataStore* NewL(CMsvSession &aMsvSession);
       
    52     
       
    53 	/**
       
    54     * Destructor
       
    55     */
       
    56     virtual ~CMmsDataStore();
       
    57 
       
    58 protected:
       
    59    
       
    60    	// Virtual functionality from CSmlDataStore, for comments see the CSmlDataStore header file
       
    61 	virtual void DoOpenL(const TDesC& aStoreName, MSmlSyncRelationship& aContext, TRequestStatus& aStatus);
       
    62 	virtual void DoCancelRequest();
       
    63 	virtual const TDesC& DoStoreName() const;
       
    64 	virtual void DoBeginTransactionL();
       
    65 	virtual void DoCommitTransactionL(TRequestStatus& aStatus);
       
    66 	virtual void DoRevertTransaction(TRequestStatus& aStatus);
       
    67 	virtual void DoBeginBatchL();
       
    68 	virtual void DoCommitBatchL(RArray<TInt>& aResultArray, TRequestStatus& aStatus);
       
    69 	virtual void DoCancelBatch();
       
    70 	virtual void DoSetRemoteStoreFormatL(const CSmlDataStoreFormat& aServerDataStoreFormat);
       
    71 	virtual void DoSetRemoteMaxObjectSize(TInt aServerMaxObjectSize);
       
    72 	virtual TInt DoMaxObjectSize() const;
       
    73 	virtual void DoOpenItemL(TSmlDbItemUid aUid, TBool& aFieldChange, TInt& aSize,
       
    74 	    TSmlDbItemUid& aParent, TDes8& aMimeType, TDes8& aMimeVer, TRequestStatus& aStatus);
       
    75 	virtual void DoCreateItemL(TSmlDbItemUid& aUid, TInt aSize, TSmlDbItemUid aParent,
       
    76 	    const TDesC8& aMimeType, const TDesC8& aMimeVer, TRequestStatus& aStatus);
       
    77 	virtual void DoReplaceItemL(TSmlDbItemUid aUid, TInt aSize, TSmlDbItemUid aParent,
       
    78 	    TBool aFieldChange, TRequestStatus& aStatus);
       
    79 	virtual void DoReadItemL(TDes8& aBuffer);
       
    80 	virtual void DoWriteItemL(const TDesC8& aData);
       
    81 	virtual void DoCommitItemL(TRequestStatus& aStatus);
       
    82 	virtual void DoCloseItem();
       
    83 	virtual void DoMoveItemL(TSmlDbItemUid aUid, TSmlDbItemUid aNewParent, TRequestStatus& aStatus);
       
    84 	virtual void DoDeleteItemL(TSmlDbItemUid aUid, TRequestStatus& aStatus);
       
    85 	virtual void DoSoftDeleteItemL(TSmlDbItemUid aUid, TRequestStatus& aStatus);
       
    86 	virtual void DoDeleteAllItemsL(TRequestStatus& aStatus);
       
    87 	virtual TBool DoHasSyncHistory() const;
       
    88 	virtual const MSmlDataItemUidSet& DoAddedItems() const;
       
    89 	virtual const MSmlDataItemUidSet& DoDeletedItems() const;
       
    90 	virtual const MSmlDataItemUidSet& DoSoftDeletedItems() const;
       
    91 	virtual const MSmlDataItemUidSet& DoModifiedItems() const;
       
    92 	virtual const MSmlDataItemUidSet& DoMovedItems() const;
       
    93 	virtual void DoResetChangeInfoL(TRequestStatus& aStatus);
       
    94 	virtual void DoCommitChangeInfoL(TRequestStatus& aStatus, const MSmlDataItemUidSet& aItems);
       
    95 	virtual void DoCommitChangeInfoL(TRequestStatus& aStatus);
       
    96 
       
    97 private: 
       
    98 
       
    99 	/**
       
   100     * C++ Constructor.
       
   101     */
       
   102     CMmsDataStore();
       
   103     
       
   104 	/**
       
   105     * 2nd-phase Constructor.
       
   106     *
       
   107     * @param aMsvSession	IN: a session handle to message store
       
   108     */    
       
   109     void ConstructL(CMsvSession &aMsvSession);
       
   110 	
       
   111 	/**
       
   112     * Registers snapshot to ChangeFinder.
       
   113     */
       
   114 	void RegisterSnapshotL() const;
       
   115 
       
   116 	/**
       
   117     * Registers a single folder to snapshot, used by RegisterSnapshotL.
       
   118     * 
       
   119     * @param aSnapshot	IN: a snapshot item array.
       
   120     * @param aId		IN: folder id.
       
   121 	* @return TInt, Not used.
       
   122     */
       
   123 	TInt RegisterFolderL(CSnapshotArray* aSnapshot, const TMsvId& aId) const;
       
   124 	
       
   125 	/**
       
   126     * Deletes all messages in a specified folder
       
   127     * 
       
   128     * @param aId	IN: a folder id, which is to be emptied
       
   129 	* @return TInt, not used.
       
   130     */	
       
   131 	TInt DeleteAllMessagesInFolderL(TMsvId aId);
       
   132 	
       
   133 	/**
       
   134     * Checks whether the specified MMS message exists in message store.
       
   135     * 
       
   136     * @param aId	IN: message ID
       
   137 	* @return TBool, ETrue if the item id exists in the message store. Otherwise EFalse.
       
   138     */
       
   139     TBool MmsItemExists(TMsvId aUid);
       
   140 	
       
   141 	/**
       
   142     * This function resolves the status bits from the message entry
       
   143     * 
       
   144     * @param aUnread  IN: the status bits are determined from this value
       
   145 	* @return TUint8, Status byte.
       
   146     */	
       
   147 	TUint8 ResolveStatusBits(TBool aUnread);
       
   148 	
       
   149 	/**
       
   150     * This function reads data of opened message from MMS engine to client buffer.
       
   151     * Data is retriveved from MMS engine in chunks whose size can be less that 
       
   152     * client buffer size, for effectivity client buffer is allways filled with data.
       
   153     * Recursive algorith is used for that.
       
   154     * 
       
   155     * @param aBuffer	   OUT: client data buffer
       
   156 	* @return TInt, KErrNone or KErrOverflow if all MMS message data has been read.
       
   157     */		
       
   158 	TInt ReadDataRecursively(TDes8& aBuffer);
       
   159 	
       
   160 	/**
       
   161     * This function updates MMS message status
       
   162     * 
       
   163     * @param aId  IN: Identifies MMS message in message store
       
   164 	* @param aUnread IN:  New status (unread/read)
       
   165     */		
       
   166 	void UpdateMmsStatusL(TMsvId aId, TBool aUnread);
       
   167 	
       
   168     /**
       
   169     * Registers user folder messages to snapshot, used by RegisterSnapshotL.
       
   170     * 
       
   171     * @param aSnapshot	IN: a snapshot item array.
       
   172 	* @return TInt, Not used.
       
   173     */	
       
   174     TInt RegisterUserFoldersL(CSnapshotArray* aSnapshot) const;
       
   175 	
       
   176     /**
       
   177     * Cleans all user folders from SMS messages
       
   178     *
       
   179     * @return   KErrNone in case of success
       
   180     */	   
       
   181     TInt CleanUserFoldersL(); 
       
   182 	
       
   183 private: // Data members
       
   184 
       
   185 	/**
       
   186 	* @brief Data Store states:
       
   187 	* EMmsClosed:			Store is closed.
       
   188     * EMmsOpenAndWaiting:	Store is ready to be used.
       
   189     * EMmsItemOpen:			Item is being read.
       
   190     * EMmsItemCreating:		Item is being created.
       
   191     * EMmsItemUpdating:		Item is being updated.
       
   192 	*/
       
   193     enum TState
       
   194         {
       
   195         EMmsClosed = 0,
       
   196         EMmsOpenAndWaiting,
       
   197         EMmsItemOpen,
       
   198         EMmsItemOpenFieldUpdate,
       
   199         EMmsItemCreating,
       
   200         EMmsItemUpdating,
       
   201         EFolderOpen,
       
   202         EFolderCreating,
       
   203         EFolderUpdating
       
   204         };  	
       
   205 
       
   206     /**
       
   207 	* A flag indicating the existence of synchronization history.
       
   208 	*/
       
   209     TBool iHasHistory;
       
   210     
       
   211     /**
       
   212 	* Flag indicating, whether database is opened.
       
   213 	*/
       
   214     TBool iDataBaseOpened;
       
   215 
       
   216     /**
       
   217 	* The state of the active object.
       
   218 	*/
       
   219 	TState iCurrentState;	
       
   220 	
       
   221     /**
       
   222 	* Access to streams, used by ChangeFinder.
       
   223 	*/
       
   224     MSmlSyncRelationship* iContext;
       
   225     
       
   226     /**
       
   227 	* Key that is used in sorting snapshot.
       
   228 	*/
       
   229     const TKeyArrayFix iKey;
       
   230 
       
   231     /**
       
   232 	* Change finder, used to determine db modifications.
       
   233 	*/
       
   234     CChangeFinder* iChangeFinder;
       
   235             
       
   236     /**
       
   237 	* Used to access MMS message store
       
   238 	*/
       
   239     CMmsCodecClient* iCodecClient;
       
   240     
       
   241     /**
       
   242 	* Used to access message folders
       
   243 	*/    
       
   244     CMmsAdapterMsvApi* iMsvApi;
       
   245 
       
   246     /**
       
   247 	* Waiter object for asynchronous operations
       
   248 	*/
       
   249     CMsvOperationActiveSchedulerWait* iMsvWait;
       
   250 
       
   251     /**
       
   252 	* Message server session handle
       
   253 	*/
       
   254     CMsvSession* iMsvSession;
       
   255 	
       
   256     /**
       
   257 	* The location for temporary data
       
   258 	*/
       
   259     CBufFlat* iDataBuffer;
       
   260     
       
   261     /**
       
   262 	* Counter of partial data reading
       
   263 	*/   
       
   264     TInt iReadCounter;
       
   265     
       
   266     /**
       
   267 	* To store information whether current MMS message is unread
       
   268 	*/     
       
   269     TBool iUnread;
       
   270     
       
   271     /**
       
   272 	* Data chunk used in partial data reading from MMS engine
       
   273 	*/        
       
   274     TPtrC8 iReadDataChunk;
       
   275     
       
   276     /**
       
   277 	* Current read position at the data chunk from MMS engine
       
   278 	*/      
       
   279     TInt iReadPosition;
       
   280 
       
   281     /**
       
   282 	* Indicates wheter this is the last data chunk from MMS engine
       
   283 	*/        
       
   284     TBool iLastDataChunk;
       
   285     
       
   286     /**
       
   287 	* Indicates whether all data related to current message has been read
       
   288 	*/         
       
   289     TBool iReadAllData;
       
   290     
       
   291     /**
       
   292 	* Counter of partial data writing
       
   293 	*/   
       
   294     TInt iWriteCounter;
       
   295     
       
   296     /**
       
   297 	* Indicates wheter this was only status update
       
   298 	*/      
       
   299     TInt iWrittenDataLength;
       
   300 
       
   301     /**
       
   302 	* Stores the currently active message id.
       
   303 	*/
       
   304     TMsvId iCurrentId;
       
   305     
       
   306     /**
       
   307 	* Pointer to the variable, receiving the created Uid.
       
   308 	*/
       
   309 	TSmlDbItemUid* iCreatedUid;  
       
   310 
       
   311     /**
       
   312 	* Stores the parent id of currently active message.
       
   313 	*/
       
   314     TMsvId iParentId;
       
   315 
       
   316     /**
       
   317 	* Used to get asynchronous return values.
       
   318 	*/
       
   319     TRequestStatus*  iCallerStatus;
       
   320     
       
   321     /**
       
   322 	* Used to store new items.
       
   323 	*/
       
   324 	CNSmlDataItemUidSet* iNewItems;
       
   325 
       
   326     /**
       
   327 	* Used to store deleted items.
       
   328 	*/
       
   329     CNSmlDataItemUidSet* iDeletedItems;
       
   330 
       
   331     /**
       
   332 	* Used to store updated items.
       
   333 	*/
       
   334     CNSmlDataItemUidSet* iUpdatedItems;
       
   335 
       
   336     /**
       
   337 	* Used to store moved items.
       
   338 	*/
       
   339     CNSmlDataItemUidSet* iMovedItems;
       
   340 
       
   341     /**
       
   342 	* Used to store soft-deleted items (not supported).
       
   343 	*/
       
   344     CNSmlDataItemUidSet* iSoftDeletedItems;
       
   345     
       
   346     /**
       
   347 	* Used to parse OMA DS Folder Objects
       
   348 	*/    
       
   349     COMADSFolderObject* iFolderObjectParser;   
       
   350 
       
   351     /**
       
   352 	* Reserved pointer for future extension.
       
   353 	*/
       
   354     TAny* iReserved;
       
   355     };
       
   356 
       
   357 #endif // __MMSDATASTORE_H__  
       
   358