contextengine/inc/contextengineao.h
changeset 0 c53acadfccc6
equal deleted inserted replaced
-1:000000000000 0:c53acadfccc6
       
     1 /*
       
     2 * Copyright (c) 2007-2009 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:
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #ifndef CONTEXTENGINEAO_H
       
    20 #define CONTEXTENGINEAO_H
       
    21 
       
    22 // system include
       
    23 #include <e32base.h>
       
    24 
       
    25 // user include
       
    26 #include "contextplugin.h"
       
    27 #include "mpropertyobserver.h"
       
    28 
       
    29 // forward declarations
       
    30 class CContextSnapshotItem;
       
    31 class MContextInitializationObserver;
       
    32 class MContextSnapshotObserver;
       
    33 class CMdESession;
       
    34 class CPropertyWatcher;
       
    35 
       
    36 /**
       
    37 * This class implements an active object for collecting context metadata
       
    38 * asyncronously from the context plugins.
       
    39 */
       
    40 NONSHARABLE_CLASS( CContextEngineAO ) : public CActive, 
       
    41 									    public MContextPluginObserver,
       
    42 										public MKeyObserver
       
    43   	{
       
    44 public:
       
    45 
       
    46 	/**
       
    47 	 * State for context engine (=this active object).
       
    48 	 * Possible states: Ready for snapshot, initializing plugins or taking a snapshot.
       
    49 	 */
       
    50 	enum TContextEngineState { EReady = 0, EInitialization, ESnapshot };
       
    51 
       
    52 	/**
       
    53 	 * Creates and constructs a new instance of CContextEngineAO.
       
    54 	 *
       
    55 	 * @return A pointer to the new instance.
       
    56 	 */
       
    57 	static CContextEngineAO* NewL( MContextInitializationObserver* aInitObserver,
       
    58 		MContextSnapshotObserver* aSnapshotObserver );
       
    59 
       
    60 	/**
       
    61 	 * Destructor.
       
    62 	 */
       
    63 	virtual ~CContextEngineAO();
       
    64 
       
    65 public:
       
    66 	/**
       
    67 	 * Set a pointer to MdESession. The pointer is given forward to context plugins.
       
    68 	 * Session must be set in order to successfully harvest context data.
       
    69 	 *
       
    70 	 * @param aSession Session pointer to set.
       
    71 	 */
       
    72 	void SetMdeSession( CMdESession* aSession );
       
    73 
       
    74 	/**
       
    75 	 * Start taking a context snapshot (for multiple objects).
       
    76 	 *
       
    77 	 * @param aItem  Observer to inform about snapshot completion
       
    78 	 *               and MdE objects the snapshot is taken to.
       
    79 	 */
       
    80 	void StartSnapshot( CContextSnapshotItem* aItem );
       
    81 
       
    82 	/**
       
    83 	 * Method used to clarify how many plug-ins are loaded.
       
    84 	 *
       
    85 	 * @return Amount of plug-ins loaded.
       
    86 	 */
       
    87 	TInt PluginCount();
       
    88 
       
    89 public:   // from base class CActive
       
    90 
       
    91 	/**
       
    92 	 * From CActive.
       
    93 	 * Every call takes a context snapshot from one plug-in.
       
    94 	 */
       
    95 	void RunL();
       
    96 
       
    97 	/**
       
    98 	 * From CActive.
       
    99 	 * Handles a leave occurring in the request completion event handler RunL().
       
   100 	 *
       
   101 	 * @param aError  An error code.
       
   102 	 * @return An error code.
       
   103 	 */
       
   104 	TInt RunError( TInt aError );
       
   105 
       
   106 	/**
       
   107 	 * From CActive.
       
   108 	 * Cancels ????.
       
   109 	 */
       
   110 	void DoCancel();
       
   111 
       
   112 public:   // from MContextPluginObserver
       
   113 
       
   114 	/**
       
   115 	 * From MContextPluginObserver.
       
   116 	 * This is derived from MContextPluginObserver and it is called
       
   117 	 * by each plug-in when they have initialized.
       
   118 	 * Error code for the first encountered error is returned as a parameter.
       
   119 	 *
       
   120 	 * @param aErrorCode  Error code for the first error occurred during initialization.
       
   121 	 */
       
   122 	void PluginInitializationStatus( TInt aErrorCode );
       
   123 	
       
   124 	/**
       
   125 	 * From MContextPluginObserver.
       
   126 	 * This is derived from MContextPluginObserver and it is called
       
   127 	 * by each plug-in when they have taken the context snapshot.
       
   128 	 * Error code for the first encountered error is returned as a parameter.
       
   129 	 *
       
   130 	 * @param aErrorCode  Error code for the first error occurred while taking the snapshot.
       
   131 	 */
       
   132 	void PluginSnapshotStatus( CHarvesterData* aHD );
       
   133         
       
   134 public: // From MKeyObserver.   	
       
   135 
       
   136 	/**
       
   137 	 * Method NotifyKeyL from MKeyObserver get notifications when
       
   138 	 * property key has changed.
       
   139 	 */
       
   140 	void NotifyKeyL( 
       
   141 			const TInt aKeyValue,
       
   142 			const TUid aPropertyCategory,
       
   143 			const TUint aKey );     
       
   144 
       
   145 private:
       
   146 
       
   147 	/**
       
   148 	 * Default constructor, implicitly called by NewL().
       
   149 	 */
       
   150 	CContextEngineAO( MContextInitializationObserver* aInitObserver,
       
   151 		MContextSnapshotObserver* aSnapshotObserver );
       
   152 
       
   153 	/**
       
   154 	 * 2nd phase construction, called by NewL().
       
   155 	 */
       
   156 	void ConstructL();
       
   157 
       
   158 	/**
       
   159 	 * Load context plugins.
       
   160 	 */
       
   161 	void LoadPluginsL();
       
   162 
       
   163 	/**
       
   164 	 * Initialize this object. Thus load and initialize context plugins.
       
   165 	 */
       
   166 	void InitializeL();
       
   167 
       
   168 	/**
       
   169 	  * Called when
       
   170 	  * Backup&Restore is backing up or restoring.
       
   171 	  */
       
   172 	 void BackupRestoreStart();
       
   173 
       
   174 	 /**
       
   175 	  * Called when
       
   176 	  * Backup&Restore has finished backup or restore.
       
   177 	  */
       
   178 	 void BackupRestoreReady();
       
   179 
       
   180 	/**
       
   181 	 * Method HandleBackupRestoreKeyActionL.
       
   182 	 * If user make full restore sets restore flag on.
       
   183 	 */
       
   184 	void HandleBackupRestoreKeyAction( const TUint aKeyValue );
       
   185     
       
   186 private: // data
       
   187 
       
   188 	/**
       
   189 	 * This observer is used to inform the client application about
       
   190 	 * finishing plug-in initializations.
       
   191 	 */
       
   192 	MContextInitializationObserver* iInitializationObserver;
       
   193 	
       
   194 	/**
       
   195 	 * This observer is used to inform Context Engine about
       
   196 	 * finishing a context snapshot.
       
   197 	 */
       
   198 	MContextSnapshotObserver* iContextSnapshotObserver;
       
   199 
       
   200 	/**
       
   201 	 * Plug-in array contains the plug-ins.
       
   202 	 */
       
   203 	RPointerArray<CContextPlugin> iPlugins;
       
   204 
       
   205 	/**
       
   206 	 * Number of plug-ins currently not being initialized yet.
       
   207 	 */
       
   208 	TInt iUninitializedPluginsCount;
       
   209 	
       
   210 	/**
       
   211 	 * Number of HDs currently not completed the snapshot yet.
       
   212 	 */
       
   213 	TInt iPluginSnapshotsLacking;
       
   214 	
       
   215 	/**
       
   216 	 * Item to which we are currently doing a snapshot for.
       
   217 	 */
       
   218 	CContextSnapshotItem* iItem;
       
   219 	
       
   220 	/**
       
   221 	 * State of this active object.
       
   222 	 */
       
   223 	TContextEngineState iState;
       
   224 	
       
   225 	/** First error code encountered in initialization is cached here and returned later. */
       
   226 	TInt iInitializationError;
       
   227 	
       
   228 	/** First error code encountered in snapshot is cached here and returned later. */
       
   229 	TInt iSnapshotError;
       
   230 	
       
   231 	/**
       
   232 	  * iMdESession - MDE session.
       
   233 	  */
       
   234 	CMdESession* iMdESession;
       
   235 
       
   236 	/**
       
   237 	 * iPropertyWatcher - constains observed key's, owned by this class.
       
   238 	 */
       
   239 	CPropertyWatcher* iPropertyWatcher;
       
   240 	
       
   241     /**
       
   242      * iPropertyWatcher - used to check if only one plugin has not finished work.
       
   243      */
       
   244     TBool iLastPlugin;
       
   245     };
       
   246 
       
   247 #endif // CONTEXTENGINEAO_H