omads/omadsappui/AspSyncUtil/inc/AspSyncHandler.h
changeset 19 2691f6aa1921
parent 4 e6e896426eac
child 20 e1de7d03f843
equal deleted inserted replaced
4:e6e896426eac 19:2691f6aa1921
     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: Creates sync job and receives progress events 
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #ifndef ASPSYNCHANDLER_H
       
    20 #define ASPSYNCHANDLER_H
       
    21 
       
    22 // INCLUDES
       
    23 #include <e32base.h>
       
    24 #include <SyncMLObservers.h>
       
    25 #include <textresolver.h>
       
    26 
       
    27 
       
    28 #include "AspProgressDialog.h"
       
    29 #include "AspState.h"
       
    30 #include "AspProfile.h"
       
    31 
       
    32 
       
    33 
       
    34 // CLASS DECLARATION
       
    35 
       
    36 
       
    37 /**
       
    38 * MAspProgressDialogObserver
       
    39 * 
       
    40 * Observer interface function for observing sync events.
       
    41 */
       
    42 NONSHARABLE_CLASS (MAspSyncObserver)
       
    43     {
       
    44     public:
       
    45         /**
       
    46         * Callback method
       
    47         * Get's called when a synchronization has completed.
       
    48         */
       
    49         virtual void HandleSyncEventL(TInt aError, TInt aInfo1) = 0;
       
    50     };
       
    51 
       
    52 
       
    53 /**
       
    54 * TAspSyncParam
       
    55 *
       
    56 * This class is used as sync parameter type.
       
    57 */
       
    58 NONSHARABLE_CLASS (TAspSyncParam)
       
    59 	{
       
    60     public:
       
    61     	TAspSyncParam(TInt aApplicationId);
       
    62         
       
    63     public:
       
    64 		// calling application id
       
    65 		TInt iApplicationId;
       
    66 
       
    67 		// profile id
       
    68 		TInt iProfileId;
       
    69 
       
    70 		// job id
       
    71 		TInt iJobId;
       
    72 
       
    73 		// taskId
       
    74 		TInt iTaskId;
       
    75 
       
    76         // sync direction
       
    77 		TInt iSyncDirection;
       
    78 		
       
    79 		// progress dialog modality
       
    80 		TInt iDialogMode;
       
    81 	};
       
    82 
       
    83 
       
    84 /**
       
    85 * CAspSyncHandler
       
    86 * 
       
    87 * CAspSyncHandler handles data synchronizing.
       
    88 */
       
    89 NONSHARABLE_CLASS (CAspSyncHandler) : public CBase, 
       
    90                         public MAspProgressDialogObserver,
       
    91 						public MAspActiveCallerObserver,
       
    92 						public MSyncMLEventObserver,
       
    93 						public MSyncMLProgressObserver
       
    94 						
       
    95 	{
       
    96 
       
    97     public:
       
    98         /**
       
    99         * Two-phased constructor.
       
   100         */
       
   101 	    static CAspSyncHandler* NewL(const TAspParam& aParam);
       
   102 
       
   103 	    /**
       
   104         * Destructor.
       
   105         */
       
   106 	    virtual ~CAspSyncHandler();
       
   107 
       
   108     private:
       
   109 	    /**
       
   110         * By default Symbian 2nd phase constructor is private.
       
   111         */
       
   112 	    void ConstructL();
       
   113 
       
   114 	    /**
       
   115         * C++ default constructor.
       
   116         */
       
   117 	    CAspSyncHandler(const TAspParam& aParam);
       
   118 
       
   119 		
       
   120 	private:	
       
   121         /**
       
   122         * From MAspProgressDialogObserver
       
   123     	* Gets called when sync progress dialog closes.
       
   124         * @param aButtonId Button id.
       
   125         * @return None
       
   126         */
       
   127 		void HandleDialogEventL(TInt aButtonId);
       
   128 
       
   129     
       
   130 	private: // from MAspActiveCallerObserver
       
   131 		/**
       
   132         * From MAspActiveCallerObserver
       
   133 		* Called when CAspActiveCaller completes.
       
   134         * @param aCallId.
       
   135         * @return None.
       
   136         */
       
   137 		void HandleActiveCallL(TInt aCallId);
       
   138 
       
   139 
       
   140     private:    // from MSyncMLEventObserver
       
   141         
       
   142 		/**
       
   143         * From MSyncMLEventObserver
       
   144 		* Called when SyncML session events oocur.
       
   145         * @param aEvent.
       
   146         * @param aIdentifier.
       
   147         * @param aError.
       
   148         * @param aAdditionalData.
       
   149         * @return None.
       
   150         */
       
   151         void OnSyncMLSessionEvent(TEvent aEvent, TInt aIdentifier, TInt aError, TInt aAdditionalData);
       
   152 	
       
   153 	
       
   154     private:  //from MSyncMLProgressObserver
       
   155 	    
       
   156 	    /**
       
   157 	    * Receives notification of a synchronisation error.
       
   158         * @param aErrorLevel  The error level.
       
   159 	    * @param aError		  The type of error. This is one of the SyncMLError error values.	
       
   160 	    * @param aTaskId      The ID of the task for which the error occurred.
       
   161 	    * @param aInfo1       An integer that can contain additional information about the error. Normally 0.
       
   162 	    * @param aInfo2       An integer that can contain additional information about the error. Normally 0.
       
   163 	    * @return             None.
       
   164 	    */
       
   165 	    void OnSyncMLSyncError(TErrorLevel aErrorLevel, TInt aError, TInt aTaskId, TInt aInfo1, TInt aInfo2);
       
   166        	
       
   167        	/**
       
   168 	    * Receives notification of synchronisation progress.
       
   169 	    * @param aStatus	The current status, e.g. 'Connecting'.
       
   170 	    * @param aInfo1	An integer that can contain additional information about the progress.
       
   171 	    * @param aInfo2	An integer that can contain additional information about the progress.
       
   172 	    */
       
   173 	    void OnSyncMLSyncProgress(TStatus aStatus, TInt aInfo1, TInt aInfo2);
       
   174 	    
       
   175 	    /**
       
   176 	    * Receives notification of modifications to synchronisation tasks.
       
   177         * @param aTaskId               The ID of the task.
       
   178 	    * @param aClientModifications  Modifications made on the clients Data Store.
       
   179 	    * @param aServerModifications  Modifications made on the server Data Store.
       
   180 	    */
       
   181 	    void OnSyncMLDataSyncModifications(TInt aTaskId, const TSyncMLDataSyncModifications& aClientModifications, const TSyncMLDataSyncModifications& aServerModifications);
       
   182 
       
   183 	private:
       
   184 	    void OnSyncMLDataSyncModificationsL(TInt aTaskId, const TSyncMLDataSyncModifications& aClientModifications, const TSyncMLDataSyncModifications& aServerModifications);
       
   185 	    
       
   186 	    
       
   187 	private:
       
   188         /**
       
   189         * Shows progress dialog.
       
   190 		* @param None.
       
   191         * @return Error code.
       
   192         */
       
   193         void ShowProgressDialogL();
       
   194 
       
   195         /**
       
   196         * Shows error dialog.
       
   197 		* @param None.
       
   198         * @return Error code.
       
   199         */
       
   200         void ShowErrorNote();
       
   201         
       
   202         /**
       
   203         * Completes sync operation.
       
   204 		* @param aError.
       
   205         * @return None.
       
   206         */
       
   207         void SynchronizeCompleted(TInt aError);
       
   208 	
       
   209 	public:
       
   210 	
       
   211         /**
       
   212         * Performs synchronization.
       
   213 		* @param aSyncParam.
       
   214         * @return None
       
   215         */
       
   216         void SynchronizeL(TAspSyncParam& aSyncParam);
       
   217         
       
   218         /**
       
   219         * Sets sync observer.
       
   220 		* @param aObserevr.
       
   221         * @return None
       
   222         */
       
   223         void SetObserver(MAspSyncObserver* aObserver);
       
   224 
       
   225     
       
   226     private:
       
   227         /**
       
   228         * Performs synchronization.
       
   229 		* @param aSyncParam.
       
   230         * @return None
       
   231         */
       
   232         void DoSynchronizeL(TAspSyncParam& aSyncParam);
       
   233 
       
   234 	private:
       
   235 		/**
       
   236         * Utility function.
       
   237         * @return CAspResHandler.
       
   238         */
       
   239 		CAspResHandler* ResHandlerL();
       
   240 		
       
   241 		/**
       
   242         * Utility function.
       
   243         * @return Progress dialog.
       
   244         */
       
   245 		CAspProgressDialog* Dialog();
       
   246 
       
   247 		/**
       
   248         * Utility function.
       
   249         * @return Sync state.
       
   250         */
       
   251 		CAspState* State();
       
   252 
       
   253     public:
       
   254 
       
   255 		/**
       
   256         * Utility function.
       
   257         * @return ETrue if sync is currently running, EFalse otherwise.
       
   258         */
       
   259 		TBool SyncRunning();
       
   260 
       
   261     private:
       
   262 		/**
       
   263         * Updates progress dialog.
       
   264         * @param None.
       
   265     	* @return None.
       
   266         */
       
   267 		void UpdateDialogL();
       
   268 
       
   269 		/**
       
   270         * Updates progress dialog.
       
   271         * @param None.
       
   272     	* @return None.
       
   273         */
       
   274 		void UpdateDialog();
       
   275 
       
   276 		/**
       
   277         * Get list profiles that can be used for syncing.
       
   278         * @param aApplicationId Application (sync content) id.
       
   279     	* @return None.
       
   280         */
       
   281 		CAspProfileList* GetProfileListLC(TInt aApplicationId);
       
   282 		
       
   283 		/**
       
   284         * Utility function.
       
   285         * @param None.
       
   286         * @return None.
       
   287         */
       
   288         void CreateContentListL();
       
   289 
       
   290 		/**
       
   291         * Utility function.
       
   292         * @param None.
       
   293         * @return ETrue if server alert sync, EFalse otherwise.
       
   294         */
       
   295         TBool IsServerAlertSync();
       
   296 
       
   297 		/**
       
   298         * Opens sync session.
       
   299         * @param None.
       
   300         * @return None.
       
   301         */
       
   302         void OpenSyncSessionL();
       
   303 
       
   304 		/**
       
   305         * Closes sync session.
       
   306         * @param None.
       
   307         * @return None.
       
   308         */
       
   309         void CloseSyncSession();
       
   310         
       
   311 		/**
       
   312         * Calculates progress count.
       
   313         * @param aC Phone side sync events.
       
   314         * @param aS Server side sync events.
       
   315         * @return Progress count.
       
   316         */
       
   317         TInt ProgressCount(const TSyncMLDataSyncModifications& aC,
       
   318                            const TSyncMLDataSyncModifications& aS);
       
   319                            
       
   320 		/**
       
   321         * Checks that sync profile has valid local database.
       
   322         * @param aProfileId.
       
   323         * @return None.
       
   324         */
       
   325         void CheckLocalDatabaseL(TInt aProfileId);
       
   326         
       
   327 		/**
       
   328         * Checks whether progress dialog needs to be updated.
       
   329         * @param None.
       
   330         * @return Boolean.
       
   331         */
       
   332         TBool UpdateRequired();
       
   333         
       
   334 		/**
       
   335         * Completes sync with short delay.
       
   336         * @param aError.
       
   337         * @return None.
       
   338         */
       
   339         void CompleteWithDelay(TInt aError);
       
   340         
       
   341         TBool IsRoamingL();
       
   342         
       
   343         void ReadRepositoryL(TInt aKey, TInt& aValue);
       
   344         
       
   345         TInt BearerTypeL(TInt aProfileId);
       
   346         
       
   347 #ifdef _DEBUG
       
   348     private:  // debug code
       
   349         void GetSyncStatusText(TDes& aText, MSyncMLProgressObserver::TStatus aStatus);
       
   350         void GetSyncEventText(TDes& aText, MSyncMLEventObserver::TEvent aEvent);
       
   351         void LogSessionEvent(TEvent& aEvent, TInt aIdentifier, TInt aError);
       
   352         void LogProgressEvent(TStatus& aStatus, TInt aInfo1);
       
   353         void LogErrorEvent(TErrorLevel aErrorLevel, TInt aError);
       
   354         void LogModificationEvent(TInt aTaskId, const TSyncMLDataSyncModifications& aC, const TSyncMLDataSyncModifications& aS);
       
   355         void LogModificationEvent(TInt aTaskId, const TDesC& aText);
       
   356 #endif
       
   357 
       
   358     private:
       
   359 		// id of the calling application
       
   360 		TInt iApplicationId;
       
   361 
       
   362 		// profile id
       
   363 		TInt iProfileId;
       
   364 		
       
   365 		// sync session
       
   366 		RSyncMLSession iSyncSession;
       
   367 
       
   368 		// sync job
       
   369 		RSyncMLDataSyncJob iSyncJob;
       
   370 		
       
   371 		// needed for getting data provider names
       
   372 		CAspContentList* iContentList;
       
   373 		
       
   374 		// shows sync progress dialog
       
   375 		CAspProgressDialog* iProgressDialog;
       
   376 
       
   377 		// sync handler state
       
   378 		CAspState* iState;
       
   379 
       
   380 		// reads strings
       
   381 		CAspResHandler* iResHandler;
       
   382 
       
   383 		// for making function call via active scheduler
       
   384 		CAspActiveCaller* iActiveCaller;
       
   385 
       
   386 		// is sync currently running
       
   387 		TBool iSyncRunning;
       
   388 		
       
   389 		// is current sync servert alert sync
       
   390 		TBool iServerAlertSync;
       
   391 
       
   392 		// is sync session open
       
   393 		TBool iSyncSessionOpen;
       
   394 		
       
   395 		// sync error code
       
   396 		TInt iSyncError;
       
   397 		
       
   398 		// current sync job id
       
   399 		TInt iCurrentSyncJobId;
       
   400 		
       
   401 		// sync observer, used for sending sync completion event
       
   402 		MAspSyncObserver* iSyncObserver;
       
   403 
       
   404         // for converting error code to error string
       
   405         CTextResolver* iTextResolver;
       
   406         
       
   407 		// has "sync completed" event arrived 
       
   408 		TBool iCompleteEventReceived;
       
   409 		
       
   410 		// has "sync stopped" event arrived 
       
   411 		TBool iStopEventReceived;
       
   412 		
       
   413 		// sync modality 
       
   414 		TBool iIsSynchronousOperation;
       
   415 		
       
   416 	    // for stopping code until sync is finished
       
   417     	CActiveSchedulerWait* iWait;
       
   418 		
       
   419 	};
       
   420 	
       
   421 	
       
   422 
       
   423 
       
   424 	
       
   425 #endif  // ASPSYNCHANDLER_H
       
   426 
       
   427 
       
   428 // End of file