omads/omadsappui/AspSyncUtil/inc/AspDbNotifier.h
branchRCL_3
changeset 24 8e7494275d3a
parent 23 2bb96f4ecad8
child 25 4f0867e42d62
equal deleted inserted replaced
23:2bb96f4ecad8 24:8e7494275d3a
     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: Used by UI to update settings based on DB changes 
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #ifndef ASPDBNOTIFIER_H
       
    20 #define ASPDBNOTIFIER_H
       
    21 
       
    22 #include <e32std.h>
       
    23 #include <SyncMLObservers.h>
       
    24 
       
    25 #include "AspUtil.h"
       
    26 
       
    27 
       
    28 // CLASS DECLARATION
       
    29 
       
    30 
       
    31 /**
       
    32 * TAspDbEvent
       
    33 *
       
    34 * TAspDbEvent represents sync event that is sent to UI.
       
    35 */
       
    36 NONSHARABLE_CLASS (TAspDbEvent)
       
    37 	{
       
    38 	public:
       
    39 		TInt iType;	
       
    40 		TInt iProfileId;
       
    41 		TInt iError;
       
    42 
       
    43     public:
       
    44 		/**
       
    45         * Constructor
       
    46         * @param aType Event type.
       
    47         * @return None. 
       
    48         */
       
    49     	TAspDbEvent(TInt aType);
       
    50 	};
       
    51 
       
    52 
       
    53 
       
    54 /**
       
    55 * MAspDbEventHandler
       
    56 *
       
    57 * Observer interface function.
       
    58 */
       
    59 NONSHARABLE_CLASS (MAspDbEventHandler)
       
    60 	{
       
    61 	public:
       
    62 		/**
       
    63         * CAspDbNotifier calls this to inform that database has changed.
       
    64         * @param aEvent Database event.
       
    65         * @return None. 
       
    66         */
       
    67 		virtual void HandleDbEventL(TAspDbEvent aEvent) = 0;
       
    68 	};
       
    69 
       
    70 
       
    71 /**
       
    72 * CAspDbNotifier
       
    73 * 
       
    74 * CAspDbNotifier is used to observe sync database events. These events
       
    75 * are used to update UI.
       
    76 */
       
    77 NONSHARABLE_CLASS (CAspDbNotifier) : public CBase,
       
    78                                      public MAspActiveCallerObserver,
       
    79                                      public MSyncMLEventObserver
       
    80 	{
       
    81     public:
       
    82 	    enum TEventType
       
    83 			{
       
    84 			EUpdate,
       
    85 			EUpdateAll,
       
    86 			EDelete,
       
    87 	        EClose
       
    88 			};
       
    89 
       
    90 	public:
       
    91 		/**
       
    92         * Two-phased constructor
       
    93         * @param aDatabase Reference to RDbDatabase instance.
       
    94 		* @param aHandler Pointer to MAspDbEventHandler instance.
       
    95         * @return None. 
       
    96         */
       
    97 		static CAspDbNotifier* NewL(const TAspParam& aParam, MAspDbEventHandler* aHandler);
       
    98 
       
    99         /**
       
   100         * Destructor.
       
   101         */
       
   102 		virtual ~CAspDbNotifier();
       
   103 
       
   104 	private:
       
   105 
       
   106 		/**
       
   107         * Constructor
       
   108         * @param aParam.
       
   109 		* @param aHandler Pointer to event handler.
       
   110         * @return None. 
       
   111         */
       
   112 		CAspDbNotifier(const TAspParam& aParam, MAspDbEventHandler* aHandler);
       
   113 
       
   114         /**
       
   115         * By default Symbian OS constructor is private.
       
   116         */
       
   117 		void ConstructL();
       
   118 
       
   119 	public:
       
   120 		/**
       
   121 		* Start requesting events from db.
       
   122         * @param None. 
       
   123         * @return None. 
       
   124         */
       
   125 		void RequestL();
       
   126 
       
   127    
       
   128 	private:   // from MAspActiveCallerObserver
       
   129 	
       
   130 		/**
       
   131         * From MAspActiveCallerObserver
       
   132 		* Called when CAspActiveCaller completes.
       
   133         * @param aCallId.
       
   134         * @return None.
       
   135         */
       
   136 		void HandleActiveCallL(TInt aCallId);
       
   137 
       
   138     private:    // from MSyncMLEventObserver
       
   139         
       
   140 		/**
       
   141         * Called when SyncML session events oocur.
       
   142         * @param aEvent Event type.
       
   143         * @param aIdentifier Object id.
       
   144         * @param aError Error code.
       
   145         * @param aAdditionalData Additional data.
       
   146         * @return None.
       
   147         */
       
   148         void OnSyncMLSessionEvent(TEvent aEvent, TInt aIdentifier, TInt aError, TInt aAdditionalData);
       
   149         
       
   150 		/**
       
   151         * Called when SyncML session events oocur.
       
   152         * @param aEvent Event type.
       
   153         * @param aIdentifier Object id.
       
   154         * @param aError Error code.
       
   155         * @param aAdditionalData Additional data.
       
   156         * @return None.
       
   157         */
       
   158         void HandleSessionEventL(TEvent aEvent, TInt aIdentifier, TInt aError, TInt aAdditionalData);
       
   159 
       
   160     public:
       
   161 		/**
       
   162         * Calls database event observer with delay.
       
   163         * @param None.
       
   164         * @return None.
       
   165         */
       
   166 		void CallObserverWithDelay();
       
   167 
       
   168 		/**
       
   169         * Calls database event observer.
       
   170         * @param None.
       
   171         * @return None.
       
   172         */
       
   173 		void CallObserver();
       
   174 		
       
   175 		/**
       
   176         * Disable/enable observer calling.
       
   177         * @param aDisable.
       
   178         * @return None.
       
   179         */
       
   180 		void SetDisabled(TBool aDisable);
       
   181 
       
   182 		/**
       
   183         * Finds out how many profiles have changed.
       
   184         * @param None.
       
   185         * @return Profile count.
       
   186         */
       
   187 		TInt ChangedProfileCount();
       
   188 		
       
   189 		/**
       
   190         * Get one database event from event array.
       
   191         * @param aIndex.
       
   192         * @return Database event.
       
   193         */
       
   194         TAspDbEvent Event(TInt aIndex);
       
   195         
       
   196 		/**
       
   197         * Return number of received database events.
       
   198         * @param None.
       
   199         * @return Event count.
       
   200         */
       
   201 		TInt EventCount();
       
   202 
       
   203 		/**
       
   204         * Reset event array.
       
   205         * @param None.
       
   206         * @return None.
       
   207         */
       
   208 		void Reset();
       
   209 
       
   210 		/**
       
   211         * Find out whether event array contains event that causes UI to close.
       
   212         * @param None.
       
   213         * @return Array index.
       
   214         */
       
   215 		TInt FindCloseEvent();
       
   216 
       
   217 		/**
       
   218         * Find out whether event array contains events for one profile only.
       
   219         * @param None.
       
   220         * @return Array index.
       
   221         */
       
   222 		TInt FindSingleProfileEvent();
       
   223 		
       
   224 		/**
       
   225         * Find out whether event array contains profile event.
       
   226         * @param None.
       
   227         * @return Array index.
       
   228         */
       
   229 		TInt FindProfileEvent();
       
   230 		
       
   231 		/**
       
   232         * Find out whether event array only contains events with same profile id.
       
   233         * @param aId Profile id.
       
   234         * @return Boolean.
       
   235         */
       
   236 		TBool IsUniqueProfileId(TInt aId);
       
   237 		
       
   238 		/**
       
   239         * Creates one update event.
       
   240         * @param aIdentifier Profile id.
       
   241         * @param aError Error code.
       
   242         * @return None.
       
   243         */
       
   244 		void CreateUpdateEventL(TInt aIdentifier, TInt aError);
       
   245 		
       
   246 		/**
       
   247         * Find out whether event array contains delete event.
       
   248         * @param None.
       
   249         * @return Boolean.
       
   250         */
       
   251 		TBool ProfileDeleted();
       
   252 		
       
   253 		/**
       
   254         * Call event observer if event array contains update event.
       
   255         * @param None.
       
   256         * @return None.
       
   257         */
       
   258         void CheckUpdateEventL();
       
   259 		
       
   260 		/**
       
   261 		* Utility function.
       
   262 		* @return Sync session.
       
   263         */
       
   264 		RSyncMLSession& Session();
       
   265 		
       
   266 		
       
   267 #ifdef _DEBUG
       
   268     private:
       
   269         void GetSyncEventText(TDes& aText, MSyncMLEventObserver::TEvent aEvent);
       
   270         void LogSessionEvent(TEvent& aEvent, TInt aIdentifier, TInt aError);
       
   271 #endif
       
   272 		
       
   273 
       
   274 
       
   275 	private:  
       
   276 		// sync session
       
   277 		RSyncMLSession* iSyncSession;
       
   278 	
       
   279 		// Pointer to event handler
       
   280 		MAspDbEventHandler* iHandler;
       
   281 
       
   282 		// for making function call via active scheduler
       
   283 		CAspActiveCaller* iActiveCaller;
       
   284 
       
   285 		// for storing ids of changed profiles
       
   286 		RArray<TAspDbEvent> iList;
       
   287 
       
   288 		// can observer be called
       
   289 		TBool iDisabled;
       
   290 
       
   291 		// is synchronizing going on
       
   292 		//TBool iSyncRunning;
       
   293 		
       
   294 		// have sync session events been requested from RSyncMLSession
       
   295 		TBool iSessionEventRequested;
       
   296 		
       
   297 		// is this object destroyed
       
   298 		TBool* iDestroyedPtr;
       
   299 	};
       
   300 
       
   301 
       
   302 #endif   // ASPDBNOTIFIER_H
       
   303 
       
   304 
       
   305 // End of file