harvester/common/inc/propertywatcher.h
changeset 0 c53acadfccc6
equal deleted inserted replaced
-1:000000000000 0:c53acadfccc6
       
     1 /*
       
     2 * Copyright (c) 2006-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:  Definition of CPropertyWatcher class.*
       
    15 */
       
    16 
       
    17 
       
    18 #ifndef PROPERTYWATCHER_H
       
    19 #define PROPERTYWATCHER_H
       
    20 
       
    21 // SYSTEM INCLUDE
       
    22 #include <e32base.h>
       
    23 
       
    24 // FORWARD DECLARATIONS
       
    25 class CListener;
       
    26 class MKeyObserver;
       
    27 class MKeyAndStatusObserver;
       
    28 
       
    29 // CLASS DECLARATION
       
    30 /**
       
    31  *  An instance of the CPropertyWatcher object - singleton.
       
    32  *  Create listeners for RProperty key changes. This class
       
    33  *  uses TLS implementation. 
       
    34  *
       
    35  *  @code
       
    36  *	
       
    37  * // Get instance
       
    38  * iPropertyWatcher = CPropertyWatcher::GetInstanceL();
       
    39  *	
       
    40  * // Set wanted key, give gategory's uid, observed key and this pointer.
       
    41  * iPropertyWatcher->ListenKeyChangesL( KUidSystemCategory,
       
    42  *  	conn::KUidBackupRestoreKey, this );
       
    43  *	iPropertyWatcher->ListenKeyChangesL( KPSUidScreenSaver,
       
    44  *  	KScreenSaverOn, this );
       
    45  *
       
    46  * ...
       
    47  *  // Implement NotifyKeyL for key canges or NotifyKeyAndStatusL for
       
    48  *  // key and status changes. 
       
    49  *  void CRestoreWatcher::NotifyKeyL( 
       
    50  *		const TInt aKeyValue,
       
    51  *		const TUid aPropertyCategory,
       
    52  *		const TUint aKey)
       
    53  *	{
       
    54  *	
       
    55  *	// In interface check key's category. 
       
    56  *	if( aPropertyCategory == KUidSystemCategory &&
       
    57  *		aKey == conn::KUidBackupRestoreKey )
       
    58  *		{
       
    59  *		TInt backupStateValue = aKeyValue;
       
    60  *		backupStateValue &= conn::KBURPartTypeMask;
       
    61  *		
       
    62  *		if ( backupStateValue >= conn::EBURRestoreFull )
       
    63  *			{
       
    64  *			// Handle backup here
       
    65  *			}
       
    66  *		}
       
    67  *	
       
    68  *	if( aPropertyCategory == KPSUidScreenSaver && aKey == KScreenSaverOn )
       
    69  *		{
       
    70  *		//Handle screensaver activity here 
       
    71  *		}	
       
    72  *	}
       
    73  * 
       
    74  *  // Destruction
       
    75  * 
       
    76  * 	if( iPropertyWatcher )
       
    77  *		{
       
    78  *		iPropertyWatcher->StopListeningKeyChanges( 
       
    79 			KUidSystemCategory,
       
    80 			conn::KUidBackupRestoreKey, this );
       
    81  *		
       
    82  *		iPropertyWatcher->Delete(); // Release connection to TLS object.
       
    83  *		} 
       
    84  * 
       
    85  * @endcode
       
    86  */
       
    87 NONSHARABLE_CLASS( CPropertyWatcher ) : public CBase
       
    88     {
       
    89  public: // Exported.
       
    90 		
       
    91 	/*!
       
    92 	@function GetInstanceL
       
    93 	@Create a CPropertyWatcher object, 
       
    94 	@result a pointer to the created instance of CPropertyWatcher.
       
    95 	*/
       
    96 	IMPORT_C static CPropertyWatcher* GetInstanceL();
       
    97 	
       
    98 	/*!
       
    99 	@function Delete
       
   100 	@Release an instance of this singleton.
       
   101 	*/
       
   102 	IMPORT_C void Delete();
       
   103 		
       
   104 	/*!
       
   105 	@function ListenKeyChanges
       
   106 	@Registers to watcher and get events from watcher via MKeyObserver interface.
       
   107 	@param aPropertyCategory observed key's category.       
       
   108 	@param aKey observed key.
       
   109 	@aValueObserver client's pointer. Notive that this is not taking ownership.
       
   110 	*/
       
   111 	IMPORT_C void ListenKeyChangesL( const TUid aPropertyCategory,
       
   112 			 const TUint aKey,
       
   113 			 const MKeyObserver* aValueObserver
       
   114 			);
       
   115    /*
       
   116 	@function ListenKeyAndStatusChangesL
       
   117 	@Registers to watcher and get events from watcher via MKeyAndStatusObserver interface.
       
   118 	@param aPropertyCategory observed key's category.       
       
   119 	@param aKey observed key.
       
   120 	@aStatusObserver client's pointer. Notive that this is not taking ownership.
       
   121 	*/
       
   122    IMPORT_C void ListenKeyAndStatusChangesL( const TUid aPropertyCategory,
       
   123 			const TUint aKey,
       
   124 			const MKeyAndStatusObserver* aStatusObserver );
       
   125 
       
   126    /*
       
   127 	@function StopListeningKeyChanges
       
   128 	@Stops listening key changes. 
       
   129 	@param aPropertyCategory observed key's category.       
       
   130 	@param aKey observed key.
       
   131 	@aValueObserver client's pointer.
       
   132 	*/
       
   133    IMPORT_C void StopListeningKeyChanges( 
       
   134 			const TUid aPropertyCategory,
       
   135 			const TUint aKey,
       
   136 			const MKeyObserver* aKeyObserver );
       
   137    
       
   138    /*
       
   139 	@function StopListeningKeyAndStatusChanges
       
   140 	@Stops listening key and status changes. MDS need this to stop Active sheduler during restore.
       
   141 	@param aPropertyCategory observed key's category.       
       
   142 	@param aKey observed key.
       
   143 	@aValueObserver client's pointer.
       
   144 	*/
       
   145     IMPORT_C void StopListeningKeyAndStatusChanges( 
       
   146 			const TUid aPropertyCategory,
       
   147 			const TUint aKey,
       
   148 			MKeyAndStatusObserver* aStatusObserver );
       
   149  
       
   150 private:  
       
   151    /*!
       
   152 	@function ~CPropertyWatcher
       
   153 	@Destroy the object and release all memory objects.
       
   154 	*/
       
   155 	~CPropertyWatcher();  
       
   156 
       
   157 private:
       
   158 	/*!
       
   159 	@function FindListener
       
   160 	@Find if there is allredy listener which matches
       
   161 	@aPropertyCategory and aKey.
       
   162 	@return listener index, KErrNotFound if not exists.
       
   163 	*/    	
       
   164 	TInt FindListener( const TUid aPropertyCategory, const TUint aKey ) const;
       
   165   
       
   166 private:
       
   167   
       
   168 	/*!@iListenersArray - all listeners for different key values.
       
   169 	 * Owned by this class.
       
   170 	 */
       
   171 	RPointerArray<CListener> iListenersArray;    
       
   172     };
       
   173 
       
   174 #endif // PROPERTYWATCHER
       
   175