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