bluetoothengine/btui/devmodel/inc/btregistryobserver.h
branchRCL_3
changeset 56 9386f31cc85b
parent 0 f63038272f30
equal deleted inserted replaced
55:613943a21004 56:9386f31cc85b
       
     1 /*
       
     2 * Copyright (c) 2006-2007 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:  Registry observer is listening to registry changes and
       
    15 * 				  and reporting the changed devices to the listener.
       
    16 *
       
    17 */
       
    18 
       
    19 #ifndef BTREGISTRYOBSERVER_H
       
    20 #define BTREGISTRYOBSERVER_H
       
    21 
       
    22 #include <e32base.h>
       
    23 #include <e32property.h>
       
    24 #include <btmanclient.h>
       
    25 #include <btengdevman.h> 
       
    26 
       
    27 /** This class will inform the listener about the new BTregistry status
       
    28 *after registry change events. 
       
    29 *
       
    30 * This class will listen to events about registry changes and inform
       
    31 * the listener about the latest registry status. The listener can
       
    32 * also ask the status using refresh. This is usefull for for
       
    33 * for example retrieval of initial lists of devices. 
       
    34 *
       
    35 *@lib btdevmodel.dll
       
    36 *@since S60 V3.2
       
    37 */
       
    38 NONSHARABLE_CLASS(MBTRegistryObserver)
       
    39     {
       
    40 public:
       
    41 	/** The aDeviceArray constents are deleted after this
       
    42 	* call returns. If storage is wanted the array and its contents
       
    43 	* must be copied by implementor.
       
    44 	*/
       
    45     virtual void RegistryChangedL(const CBTDeviceArray* aDeviceArray) = 0;
       
    46     };
       
    47     
       
    48 NONSHARABLE_CLASS(CBTRegistryObserver) : public CActive, public MBTEngDevManObserver
       
    49     {
       
    50 public: 
       
    51 	/** NewL
       
    52 	 *@param aObserver The class that is listening to registry changes
       
    53 	 *@param aPattern The pattern to be used to retrieve the changed objects.
       
    54 	 */
       
    55     static CBTRegistryObserver* NewL(MBTRegistryObserver* aObserver, 
       
    56         const TBTRegistrySearch aPattern);
       
    57     
       
    58     /** Destructor*/
       
    59     virtual ~CBTRegistryObserver();       
       
    60 
       
    61 	/** Start listening to registry changes. 
       
    62 	 *
       
    63 	 *Calling this while registry observer is running is silently ignored.
       
    64 	 */
       
    65     void StartIfNotRunning();
       
    66 
       
    67     /* Registry observer will retrieve list of devices in the backround 
       
    68      * and send it to the listener, when one is retrieved.
       
    69      */
       
    70     void Refresh();
       
    71     
       
    72     /** Check if this is running.       
       
    73      *@return ETrue if not listening to registry changes.
       
    74      */
       
    75     inline TBool IsStopped() {return iIsStopped;}
       
    76 
       
    77     /** This will stop listening and cancel any retrieval of devicelists,
       
    78     * if any.
       
    79     * @param none.
       
    80     * @return none.
       
    81     */
       
    82     void Cancel();    
       
    83 private:
       
    84 	/* Constructor that may not leave.
       
    85 	 *@param aObserver The class that is listening to registry changes
       
    86 	 *@param aPattern The pattern to be used to retrieve the changed objects.
       
    87 	 */
       
    88     CBTRegistryObserver(MBTRegistryObserver* aObserver, const TBTRegistrySearch aPattern);
       
    89 	/** 2nd phase constructor. Called by NewL only.
       
    90     * @param none.
       
    91     * @return none.	
       
    92 	 */
       
    93     void ConstructL();
       
    94 
       
    95 	/** This is called when registry changes occur, but not when deviceLists are
       
    96 	* retrieved, since HandleGetDevicesComplete is called then. 
       
    97 	*
       
    98 	* If one or more registry events occur during devicelist retrieval, there
       
    99 	* will be one new devicelist retrieval after the current retrieval is done.
       
   100 	*
       
   101     * @param none.
       
   102     * @return none.
       
   103 	*/
       
   104     void RunL();
       
   105     
       
   106     /** This will clear iRegDeviceArray and delete its contents.
       
   107     * @param none.
       
   108     * @return none.     
       
   109     */
       
   110     void DeleteAllocatedDevices();
       
   111     
       
   112     
       
   113     /** This will cancel listening. To be called by Cancel only.
       
   114      * @param none.
       
   115      * @return none.
       
   116 	 */
       
   117     void DoCancel();    
       
   118     
       
   119 	/** This is called when devicelist have been read from BtDevMan 
       
   120 	* @param aErr KErrNone or the accurred error.
       
   121 	* @param aDeviceArray the devices that have been retrieved.
       
   122     * @return none.
       
   123     */
       
   124     void HandleGetDevicesComplete(TInt aErr, CBTDeviceArray* aDeviceArray);
       
   125     
       
   126 private:
       
   127     MBTRegistryObserver* iObserver; // the class listening to this class
       
   128     CBTDeviceArray* iRegDeviceArray;  // this is used for retrieving devices
       
   129     TBTRegistrySearch iSearchPattern; // the search used to retrieve devices
       
   130     								 // NOTE: this class does not filter the results,
       
   131     								 // but the one listening to this (if filtering is done).
       
   132     RProperty iProperty;
       
   133     CBTEngDevMan* iDevMan;			// the object that is used to retrieve the device lists.
       
   134     TBool iIsStopped;				// is this runining.
       
   135     TBool iAnotherEventPending;		// Has there been one or more changes during this retrieval.
       
   136     								// if this is true then HandleGetDevices will start a new search.
       
   137     };
       
   138     
       
   139 #endif