syncmlfw/ds/hostserver/dshostserverbase/inc/Nsmldsasyncrequesthandler.h
changeset 0 b497e44ab2fc
child 54 085438c28042
equal deleted inserted replaced
-1:000000000000 0:b497e44ab2fc
       
     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:  Asynchronous request handlers for DS host server.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #ifndef __NSMLDSASYNCREQUESTHANDLER_H__
       
    20 #define __NSMLDSASYNCREQUESTHANDLER_H__
       
    21 
       
    22 // INCLUDES
       
    23 #include <e32base.h>
       
    24 #include <nsmldsconstants.h>
       
    25 #include <nsmlconstants.h>
       
    26 
       
    27 #include "nsmldshostconstants.h"
       
    28 #include "nsmldshostitem.h"
       
    29 #include "nsmldsitemmodificationset.h"
       
    30 
       
    31 // FORWARD DECLARATIONS
       
    32 class CNSmlDSHostSession;
       
    33 class CSmlDataStore;
       
    34 struct TNSmlDSDataStoreElement;
       
    35 struct TNSmlDSDataProviderElement;
       
    36 class CNSmlAdapterLog;
       
    37 
       
    38 // CLASS DECLARATION
       
    39 
       
    40 // ------------------------------------------------------------------------------------------------
       
    41 // Base class for asynchronous request handlers.
       
    42 //
       
    43 // @lib nsmldshostserver.lib
       
    44 // ------------------------------------------------------------------------------------------------
       
    45 class CNSmlDSAsyncRequestHandler : public CActive
       
    46     {
       
    47 	public: // destructor
       
    48 
       
    49 		/**
       
    50 		* C++ default destructor.
       
    51 		*/	
       
    52 		virtual ~CNSmlDSAsyncRequestHandler();
       
    53 		
       
    54 	public:	// New functions
       
    55 
       
    56 		/**
       
    57 		* Initializes the object for asynchronous calls.
       
    58 		* @return CSmlDataStore&. The asynchronous service provider for the request.
       
    59 		*/
       
    60 		CSmlDataStore& CallDSAsyncLC();
       
    61 		
       
    62 		/**
       
    63 		* Pushes item to cleanupstack, item, which sets the request status
       
    64 		* on leave CleanupStack::PopAndDestroy()
       
    65 		*/
       
    66 		void SetRequestStatusOnLeaveLC();  
       
    67     
       
    68 		/**
       
    69 		* Called when the item pushed in CNSmlDSAsyncCallBackForOpen::SetRequestStatusOnLeaveLC() is 
       
    70 		* destroyed from the cleanupstack. Sets the request status.
       
    71 		* @param aP. instance of CNSmlDSAsyncCallBackForOpen.
       
    72 		*/
       
    73 		static void SetRequestStatusOnLeaveCleanup( TAny* aP );
       
    74 		
       
    75 	public: // Functions from base classes
       
    76 
       
    77 		/**
       
    78 		* calls CActive::SetActive().
       
    79 		*/
       
    80 		void SetActive();
       
    81 		
       
    82 	protected:
       
    83 
       
    84 		/**
       
    85 		* A C++ constructor of this class. 
       
    86 		* @param aPriority. The priority of the active object,
       
    87 		* @param aSession. The session object of the request.
       
    88 		* @param aDSItem. contains the data store, which provides the asynchronous service.
       
    89 		* @param aMessage. The message associated with the request.
       
    90 		*/
       
    91 		CNSmlDSAsyncRequestHandler(TInt aPriority,
       
    92     		CNSmlDSHostSession* aSession, 
       
    93 			TNSmlDSDataStoreElement* aDSItem, 
       
    94 			const RMessagePtr2& aMessage );
       
    95         
       
    96 		/**
       
    97 		* Adds object to Active scheduler.
       
    98 		*/
       
    99 		void AddToSchedulerL();
       
   100 		
       
   101 	private:	//Functions from base class
       
   102 
       
   103 		TInt RunError(TInt aError);
       
   104 		
       
   105 	public:		//Data
       
   106 
       
   107 		CNSmlDSHostSession* iSession;		//session for request.
       
   108 		TNSmlDSDataStoreElement* iDSItem;	//data store for request
       
   109 		RMessagePtr2 iMessage;			//message for request.
       
   110     };
       
   111 
       
   112 // ------------------------------------------------------------------------------------------------
       
   113 // Asynchronous request handler, that calls callback method, when request finishes.
       
   114 //
       
   115 // @lib nsmldshostserver.lib
       
   116 // ------------------------------------------------------------------------------------------------
       
   117 class CNSmlDSAsyncCallBack : public CNSmlDSAsyncRequestHandler
       
   118     {
       
   119 	public:	//DATA TYPES
       
   120 		enum TCallBackOperation
       
   121 			{
       
   122 			EFinished = 0,
       
   123 			ECanceled,
       
   124 			EFree
       
   125 			};
       
   126 		typedef TInt (CNSmlDSHostSession::*RequestFinishedFunction) 
       
   127 			(CNSmlDSAsyncCallBack* aDSAO, CNSmlDSAsyncCallBack::TCallBackOperation aOperation);
       
   128 	public: 	//Constructors and destructors
       
   129 
       
   130 		/**
       
   131 		* A C++ constructor of this class.
       
   132 		* @param aSession. The session object of the request.
       
   133 		* @param aDSItem. Contains the data store, which provides the asynchronous service.
       
   134 		* @param aMessage. The message associated with the request.
       
   135 		* @param aReqFinishedFunc.the call back function this object calls, when request completes.
       
   136 		* @param aPtr. Pointer to request specific data.
       
   137 		*/
       
   138 		CNSmlDSAsyncCallBack( CNSmlDSHostSession* aSession, 
       
   139 			TNSmlDSDataStoreElement* aDSItem, 
       
   140 			const RMessage2& aMessage,
       
   141 			RequestFinishedFunction aReqFinishedFunc = NULL,
       
   142 			TAny* aPtr = NULL );
       
   143 		/**
       
   144 		* C++ destructor
       
   145 		*/
       
   146 		virtual ~CNSmlDSAsyncCallBack();
       
   147 
       
   148 	private: // Functions from base classes
       
   149 
       
   150 		void DoCancel();
       
   151 		void RunL();
       
   152     
       
   153 	public:
       
   154 
       
   155 		TAny* iPtr; // request specific data.
       
   156 
       
   157 	protected:
       
   158 
       
   159 		RequestFinishedFunction iReqFinishedFunc;
       
   160     };
       
   161 
       
   162 // ------------------------------------------------------------------------------------------------
       
   163 // Asynchronous request handler for CSmlDataStore::Open
       
   164 //
       
   165 // @lib nsmldshostserver.lib
       
   166 // ------------------------------------------------------------------------------------------------    
       
   167 class CNSmlDSAsyncCallBackForOpen : public CNSmlDSAsyncCallBack
       
   168 	{
       
   169 	public: //Constructor
       
   170 		/**
       
   171 		* A C++ constructor of this class. 
       
   172 		* @param aSession. The session object of the request.
       
   173 		* @param aMessage. The message associated with the request.
       
   174 		* @param aReqFinishedFunc. the call back function this object calls, when request completes.
       
   175 		*/
       
   176 		CNSmlDSAsyncCallBackForOpen( CNSmlDSHostSession* aSession, 
       
   177 			const RMessage2& aMessage,
       
   178 			RequestFinishedFunction aReqFinishedFunc = NULL );        
       
   179 
       
   180 	public:	//Data
       
   181 
       
   182 		TNSmlDSDataProviderElement* iDpi;	//Data provider for request
       
   183 		HBufC* iServerId;
       
   184 		HBufC* iRemoteDB;
       
   185 	};
       
   186 
       
   187 // ------------------------------------------------------------------------------------------------
       
   188 // Asynchronous request handler for fetching all changed items.
       
   189 //
       
   190 // @lib nsmldshostserver.lib
       
   191 // ------------------------------------------------------------------------------------------------
       
   192 class CNSmlDSChangedItemsFetcher : public CNSmlDSAsyncRequestHandler
       
   193 	{
       
   194 	public:	//DATA TYPES
       
   195 		typedef void ( CNSmlDSHostSession::*RequestFinishedFunction ) 
       
   196 			( CNSmlDSChangedItemsFetcher* aDSAO );
       
   197 	public:// Constructor and destructor
       
   198 
       
   199 		/**
       
   200 		* Creates new instance of the CNSmlDSChangedItemsFetcher and pushed it to the cleanup stack.
       
   201 		* @param aSession. The session object of the request.
       
   202 		* @param aDSItem. Contains the data store, which provides the asynchronous service.
       
   203 		* @param aMessage. The message associated with the request.
       
   204 		* @param aReqFinishedFunc. The call back function this object calls, when request completes.
       
   205 		* @return CNSmlDSChangedItemsFetcher*. Newly created instance.
       
   206 		*/
       
   207 		static CNSmlDSChangedItemsFetcher* NewLC( CNSmlDSHostSession* aSession, 
       
   208 			TNSmlDSDataStoreElement* aDSItem, 
       
   209 			const RMessage2& aMessage,
       
   210 			RequestFinishedFunction aReqFinishedFunc );
       
   211 		
       
   212 		/**
       
   213 		* C++ destructor
       
   214 		*/
       
   215 		virtual ~CNSmlDSChangedItemsFetcher();
       
   216     
       
   217 	public:	//New methods
       
   218     
       
   219 		/**
       
   220 		* Fetches all changed items asynchronously. Calls the call back method when done.
       
   221 		*/
       
   222 		void FetchAllChangedItemsL();
       
   223 
       
   224 		/**
       
   225 		* Returns the changes after they are fetched. 
       
   226 		* @return RNSmlDbItemModificationSet*. Contains the requested changes.
       
   227 		*/    
       
   228 		const RNSmlDbItemModificationSet* ChangedItems() const;
       
   229     
       
   230 	protected:
       
   231 
       
   232 		/**
       
   233 		* A C++ constructor of this class. 
       
   234 		* @param aSession. The session object of the request.
       
   235 		* @param aDSItem. Contains the data store, which provides the asynchronous service.
       
   236 		* @param aMessage. The message associated with the request.
       
   237 		* @param aReqFinishedFunc. The call back function this object calls, when request completes.
       
   238 		*/
       
   239 		CNSmlDSChangedItemsFetcher( CNSmlDSHostSession* aSession, 
       
   240 			TNSmlDSDataStoreElement* aDSItem, 
       
   241 			const RMessage2& aMessage,
       
   242 			RequestFinishedFunction aReqFinishedFunc );
       
   243         
       
   244 		/**        
       
   245 		* Symbian 2nd phase constructor
       
   246 		*/
       
   247 		void ConstructL();
       
   248     
       
   249 	private: // Functions from base classes
       
   250 
       
   251 		virtual void DoCancel();
       
   252 		virtual void RunL();
       
   253     
       
   254 	public:
       
   255 	protected:
       
   256 		RequestFinishedFunction iReqFinishedFunc;
       
   257 		TNSmlDbItemModification::TNSmlDbItemModificationType iNextModsToFetch;
       
   258 		RNSmlDbItemModificationSet* iChangedItems;
       
   259 	}; 
       
   260 
       
   261 #endif //__NSMLDSASYNCREQUESTHANDLER_H__
       
   262 
       
   263 // End of File