usbuis/usbui/USBClassChangeUIPlugin/inc/usbotghoststatewatcher.h
branchRCL_3
changeset 80 e02eb84a14d2
parent 0 1e05558e2206
equal deleted inserted replaced
79:25fce757be94 80:e02eb84a14d2
       
     1 /*
       
     2 * Copyright (c) 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:  OtgHost state watcher class.
       
    15  *
       
    16 */
       
    17 
       
    18 
       
    19 #ifndef USBOTGHOSTSTATEWATCHER_H
       
    20 #define USBOTGHOSTSTATEWATCHER_H
       
    21 
       
    22 // INCLUDE FILES
       
    23 #include <e32base.h>
       
    24 #include <e32property.h>
       
    25 #include <usbman.h>
       
    26 #include <usbhostdefs.h>
       
    27 
       
    28 
       
    29 /**
       
    30  * A callback interface for informing about OtgHost state changes
       
    31  */
       
    32 class MUSBOtgHostStateObserver
       
    33     {
       
    34     public:
       
    35         
       
    36         /**
       
    37          * Informs the observer that USB Otg Id Pin state has changed.
       
    38          * @param aIsPinOn Id pin state - ETrue(On), EFalse(Off) 
       
    39          */
       
    40         virtual void OtgHostIdPinStateChanged(TBool aIsIdPinOn) = 0;
       
    41 
       
    42         /**
       
    43          * Informs the observer that USB host event.
       
    44          * @param aEventInfo Device information related to this event
       
    45          */
       
    46         virtual void HostEventNotify(TDeviceEventInformation aEventInfo) = 0;
       
    47     };
       
    48 
       
    49 // CLASS DECLARATION
       
    50 
       
    51 /**
       
    52  * Class that listens for USB OtgHost state changes then notifies
       
    53  * the observer.
       
    54  */
       
    55 class CUSBOtgHostStateWatcher : CBase
       
    56     {
       
    57     class CUSBOtgIdPinStateWatcher : public CActive
       
    58         {
       
    59     public:
       
    60         /**
       
    61          * Two-phased constructor. 
       
    62          *
       
    63          * @param aOtgHostStateWatcher Reference to the owner - CUSBOtgHostStateWatcher.
       
    64          * @return Pointer to created object.
       
    65          */
       
    66         static CUSBOtgIdPinStateWatcher* NewL(CUSBOtgHostStateWatcher& aOtgHostStateWatcher);
       
    67 
       
    68         /** C++ destructor */
       
    69         virtual ~CUSBOtgIdPinStateWatcher();
       
    70 
       
    71         /**
       
    72          * Get Id pin state
       
    73          * @aIsIdPinOn Receive Id pin on/off state. ETrue: Id pin on, EFalse: Id pin off.
       
    74          * @return KErrNone if successful, otherwise the error that occurred 
       
    75          */
       
    76         TInt IsIdPinOn(TBool &aIsIdPinOn);
       
    77         
       
    78     protected:
       
    79         // from base class CActive
       
    80         /**
       
    81          * From CActive.
       
    82          * This method is called when Id pin state has changed.
       
    83          */
       
    84         void RunL();
       
    85 
       
    86         /**
       
    87          * From CActive.
       
    88          * In this implementation this method should never be called.
       
    89          *
       
    90          * @param aError the leave code
       
    91          * @return KErrNone
       
    92          */
       
    93         TInt RunError(TInt aError);
       
    94 
       
    95         /**
       
    96          * From CActive
       
    97          * If there is outstanding request pending when Cancel() is called then
       
    98          * this method must cancel request.
       
    99          */
       
   100         void DoCancel();
       
   101 
       
   102     private:
       
   103         /**
       
   104          * C++ constructor
       
   105          * @param aOtgHostStateWatcher Reference to the owner - CUSBOtgHostStateWatcher.
       
   106          */
       
   107         CUSBOtgIdPinStateWatcher(CUSBOtgHostStateWatcher& aOtgHostStateWatcher);
       
   108         
       
   109         /**
       
   110          * 2nd phase constructor.
       
   111          */
       
   112         void ConstructL();
       
   113         
       
   114     private: // Data
       
   115         /**
       
   116          * The observer observes property change
       
   117          */
       
   118         RProperty iIdPin;
       
   119         
       
   120         /**
       
   121          * The owner - CUSBOtgHostStateWatcher
       
   122          */
       
   123         CUSBOtgHostStateWatcher& iOtgHostStateWatcher;
       
   124         };
       
   125 
       
   126     class CUSBHostEventNotifWatcher : public CActive
       
   127         {
       
   128     public:
       
   129         /**
       
   130          * Two-phased constructor. 
       
   131          *
       
   132          * @param aOtgHostStateWatcher Reference to the owner - CUSBOtgHostStateWatcher.
       
   133          * @return Pointer to created object.
       
   134          */
       
   135         static CUSBHostEventNotifWatcher* NewL(CUSBOtgHostStateWatcher& aOtgHostStateWatcher);
       
   136 
       
   137         /** C++ destructor */
       
   138         virtual ~CUSBHostEventNotifWatcher();
       
   139 
       
   140     protected:
       
   141         // from base class CActive
       
   142         /**
       
   143          * From CActive.
       
   144          * This method is called when host event emerged .
       
   145          */
       
   146         void RunL();
       
   147 
       
   148         /**
       
   149          * From CActive.
       
   150          * In this implementation this method should never be called.
       
   151          *
       
   152          * @param aError the leave code
       
   153          * @return KErrNone
       
   154          */
       
   155         TInt RunError(TInt aError);
       
   156 
       
   157         /**
       
   158          * From CActive
       
   159          * If there is outstanding request pending when Cancel() is called then
       
   160          * this method must cancel request.
       
   161          */
       
   162         void DoCancel();
       
   163 
       
   164     private:
       
   165         /**
       
   166          * C++ constructor
       
   167          * @param aOtgHostStateWatcher Reference to the owner - CUSBOtgHostStateWatcher.
       
   168          */
       
   169         CUSBHostEventNotifWatcher(CUSBOtgHostStateWatcher& aOtgHostStateWatcher);
       
   170         
       
   171         /**
       
   172          * 2nd phase constructor.
       
   173          */
       
   174         void ConstructL();
       
   175         
       
   176     private: // Data
       
   177         /**
       
   178          * Notification info comes to this member
       
   179          */
       
   180         TDeviceEventInformation iEventInfo;
       
   181         
       
   182         /**
       
   183          * The owner - CUSBOtgHostStateWatcher
       
   184          */
       
   185         CUSBOtgHostStateWatcher& iOtgHostStateWatcher;
       
   186         };
       
   187     
       
   188     public:  // Constructors and destructor
       
   189         
       
   190         /**
       
   191          * Two-phased constructor. Uses existing usb manager session.
       
   192          * Note that it's not possible (and usually not necessary) to attach
       
   193          * more than one USBOtgHostStateWatcher to the same session.
       
   194          *
       
   195          * @param aObserver  Reference to OtgHost state observer.
       
   196          * @param aUsbMan    Existing usb manager session.
       
   197          * @return Pointer to created object.
       
   198          */
       
   199         static CUSBOtgHostStateWatcher* NewL(MUSBOtgHostStateObserver& aObserver,
       
   200             RUsb& aUsbMan);
       
   201         
       
   202         /**
       
   203          * Destructor.
       
   204          */
       
   205         virtual ~CUSBOtgHostStateWatcher();
       
   206 
       
   207         /**
       
   208          * Get Id pin state
       
   209          * @aIsIdPinOn Receive Id pin on/off state. ETrue: Id pin on, EFalse: Id pin off.
       
   210          * @return KErrNone if successful, otherwise the error that occurred 
       
   211          * @see CUSBOtgIdPinStateWatcher::IsIdPinOn
       
   212          */
       
   213         TInt IsIdPinOn(TBool &aIsIdPinOn);
       
   214         
       
   215         /**
       
   216          * Check wheather a pheripheral device is connected or not. 
       
   217          * @aIsConnected A pheripheral device connected(ETrue) or not(EFailse).
       
   218          * @return KErrNone if successful, otherwise the error that occurred 
       
   219          */
       
   220        TInt IsPeripheralConnected(TBool &aIsConnected);
       
   221         
       
   222     private:
       
   223 
       
   224         /**
       
   225          * Private constructor.
       
   226          * @param aObserver Reference to MUSBOtgHostStateObserver.
       
   227          * @param aUsbMan Existing usb manager session.
       
   228          */
       
   229         CUSBOtgHostStateWatcher(MUSBOtgHostStateObserver& aObserver, RUsb& aUsbMan);
       
   230 
       
   231         /**
       
   232          * 2nd phase constructor.
       
   233          */
       
   234         void ConstructL();
       
   235         
       
   236     private: // Data
       
   237 
       
   238         /**
       
   239          * Usb Manager
       
   240          */
       
   241         RUsb& iUsbMan;
       
   242 
       
   243         /**
       
   244          * Property of peripheral-connected
       
   245          */
       
   246         RProperty iPeripheral;
       
   247         
       
   248         /**
       
   249          * The observer of OTG/host events
       
   250          */
       
   251         MUSBOtgHostStateObserver& iObserver;
       
   252         
       
   253         /**
       
   254          * The watcher of Otg Id Pin state
       
   255          * Own.
       
   256          */
       
   257         CUSBOtgIdPinStateWatcher* iOtgIdPinWatcher;
       
   258         
       
   259         /**
       
   260          * The watcher of host event
       
   261          * Own.
       
   262          */
       
   263         CUSBHostEventNotifWatcher* iHostEventWatcher;
       
   264         
       
   265     };
       
   266 
       
   267 #endif   // USBOTGHOSTSTATEWATCHER_H