usbuis/usbui/USBClassChangeUIPlugin/inc/USBDeviceStateWatcher.h
branchRCL_3
changeset 80 e02eb84a14d2
parent 0 1e05558e2206
equal deleted inserted replaced
79:25fce757be94 80:e02eb84a14d2
       
     1 /*
       
     2 * Copyright (c) 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:  Device state watcher class.
       
    15  *
       
    16 */
       
    17 
       
    18 
       
    19 #ifndef USBDEVICESTATEWATCHER_H
       
    20 #define USBDEVICESTATEWATCHER_H
       
    21 
       
    22 // INCLUDE FILES
       
    23 #include <e32base.h>
       
    24 #include <usbman.h>
       
    25 
       
    26 /**
       
    27  * A callback interface for informing about device state changes
       
    28  */
       
    29 class MUSBDeviceStateObserver
       
    30     {
       
    31     public:
       
    32         
       
    33         /**
       
    34          * Informs the observer that USB device state has changed.
       
    35          * @param aPreviousState previous device state.
       
    36          * @param aCurrentState current device state.
       
    37          */
       
    38         virtual void DeviceStateChanged(TUsbDeviceState aPreviousState,
       
    39                                         TUsbDeviceState aCurrentState) = 0;
       
    40     };
       
    41 
       
    42 // CLASS DECLARATION
       
    43 
       
    44 /**
       
    45  * Class that listens for USB device state changes and notifies
       
    46  * the observer.
       
    47  */
       
    48 class CUSBDeviceStateWatcher : public CActive
       
    49     {
       
    50     public:  // Constructors and destructor
       
    51         
       
    52         /**
       
    53          * Two-phased constructor. Uses existing usb manager session.
       
    54          * Note that it's not possible (and usually not necessary) to attach
       
    55          * more than one USBDeviceStateWatcher to the same session.
       
    56          *
       
    57          * @param aObserver  Reference to device state observer.
       
    58          * @param aUsbMan    Existing usb manager session.
       
    59          * @return Pointer to created object.
       
    60          */
       
    61         static CUSBDeviceStateWatcher* NewL(MUSBDeviceStateObserver& aObserver,
       
    62             RUsb& aUsbMan);
       
    63         
       
    64         /**
       
    65          * Two-phased constructor. Creates its own usb manager session.
       
    66          *
       
    67          * @param aObserver  Reference to device state observer.
       
    68          * @return Pointer to created object.
       
    69          */
       
    70         static CUSBDeviceStateWatcher* NewL(MUSBDeviceStateObserver& aObserver);
       
    71         
       
    72         /**
       
    73         * Destructor.
       
    74         */
       
    75         virtual ~CUSBDeviceStateWatcher();
       
    76 
       
    77     public: // from base class CActive
       
    78 
       
    79         /**
       
    80         * From CActive.
       
    81         * This method is called when device state has changed.
       
    82         */
       
    83         void RunL();
       
    84 
       
    85         /**
       
    86         * From CActive.
       
    87         * In this implementation this method should never be called.
       
    88         *
       
    89         * @param aError the leave code
       
    90         * @return KErrNone
       
    91         */
       
    92         TInt RunError(TInt aError);
       
    93 
       
    94         /**
       
    95         * From CActive
       
    96         * If there is outstanding request pending when Cancel() is called then
       
    97         * this method must cancel request.
       
    98         */
       
    99         void DoCancel();
       
   100 
       
   101     private:
       
   102 
       
   103         /**
       
   104          * Private constructor.
       
   105          *
       
   106          * @param aObserver Reference to MUSBDeviceStateObserver.
       
   107          */
       
   108         CUSBDeviceStateWatcher(MUSBDeviceStateObserver& aObserver);
       
   109 
       
   110         /**
       
   111          * 2nd phase constructor.
       
   112          * Creates its own usb manager session.
       
   113          */
       
   114         void ConstructL();
       
   115         
       
   116         /**
       
   117          * 2nd phase constructor.
       
   118          * Uses existing usb manager session.
       
   119          *
       
   120          * @param aUsbMan    Existing usb manager session.
       
   121          */
       
   122         void ConstructL(RUsb& aUsbMan);
       
   123         
       
   124         /**
       
   125          * Code shared by all ConstructL methods.
       
   126          */
       
   127         void CommonConstructL();
       
   128         
       
   129         // Disable default C++ behavior that makes no sense
       
   130         // for this implementation.
       
   131         CUSBDeviceStateWatcher();
       
   132         CUSBDeviceStateWatcher(const CUSBDeviceStateWatcher&);
       
   133         CUSBDeviceStateWatcher& operator=(const CUSBDeviceStateWatcher&);
       
   134 
       
   135     private: // Data
       
   136 
       
   137         /**
       
   138          * Handle to Usb Manager
       
   139          */
       
   140         RUsb iUsbMan;
       
   141 
       
   142         /**
       
   143          * Current device state
       
   144          */
       
   145         TUsbDeviceState iCurrentState;
       
   146 
       
   147         /**
       
   148          * Last known device state
       
   149          */
       
   150         TUsbDeviceState iPreviousState;
       
   151 
       
   152         /**
       
   153          * Refernce to the observer
       
   154          */
       
   155         MUSBDeviceStateObserver& iObserver;
       
   156     };
       
   157 
       
   158 #endif   // USBDEVICESTATEWATCHER_H