usbengines/usbotgwatcher/inc/cusbbusactivityobserver.h
changeset 35 9d8b04ca6939
child 63 ef2686f7597e
equal deleted inserted replaced
34:7858bc6ead78 35:9d8b04ca6939
       
     1 /*
       
     2  * Copyright (c) 2008 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:  Monitors USB activity
       
    15  *
       
    16  */
       
    17 
       
    18 #ifndef C_USBBUSACTIVITYOBSERVER_H
       
    19 #define C_USBBUSACTIVITYOBSERVER_H
       
    20 
       
    21 #include <e32base.h>
       
    22 #include <e32property.h>
       
    23 
       
    24 /**
       
    25  *  This interface has to be implemented by observer
       
    26  *  to receive notifications from USB bus activity property
       
    27  */
       
    28 NONSHARABLE_CLASS(MUsbBusActivityObserver)
       
    29     {
       
    30 public:
       
    31 
       
    32     /**
       
    33      * Called when bus turn to idle
       
    34      */
       
    35     virtual void BusIdleL() = 0;
       
    36 
       
    37     /**
       
    38      * Called when when bus is in Idle, and some activity appears on the bus
       
    39      */
       
    40     virtual void BusActiveL() = 0;
       
    41 
       
    42     /**
       
    43      * Called when when error happened
       
    44      * @param aError errorcode
       
    45      */
       
    46     virtual void BusActivityErrorL(TInt aError) = 0;
       
    47 
       
    48     };
       
    49 
       
    50 /**
       
    51  *  Class observes USB OTG State property
       
    52  *
       
    53  */
       
    54 NONSHARABLE_CLASS(CUsbBusActivityObserver) : public CActive
       
    55     {
       
    56 
       
    57 public:
       
    58 
       
    59     enum TBusActivity
       
    60         {
       
    61         EBusIdle = 0, EBusActive = 1
       
    62         };
       
    63 
       
    64     /**
       
    65      * Two-phased constructor.
       
    66      */
       
    67     static CUsbBusActivityObserver* NewL();
       
    68 
       
    69     /**
       
    70      * Destructor.
       
    71      */
       
    72     virtual ~CUsbBusActivityObserver();
       
    73 
       
    74     /**
       
    75      * Returns bus activity state
       
    76      * @return bus activity
       
    77      */
       
    78     TBusActivity BusActivity();
       
    79 
       
    80     /**
       
    81      * Adds subscriber for the notification
       
    82      * @param aObserver Observer
       
    83      */
       
    84     void SubscribeL(MUsbBusActivityObserver& aObserver);
       
    85 
       
    86     /**
       
    87      * Removes observer
       
    88      * @param aObserver Observer
       
    89      */
       
    90     void UnsubscribeL(MUsbBusActivityObserver& aObserver);
       
    91 
       
    92 private:
       
    93 
       
    94     // From CActive
       
    95     /**
       
    96      * Called when request on bus activity completed
       
    97      */
       
    98     void RunL();
       
    99 
       
   100     /**
       
   101      * Called by framwork, when canceling outstanding request
       
   102      */
       
   103     void DoCancel();
       
   104 
       
   105     /**
       
   106      * Called when RunL leaves
       
   107      * @param aError error code
       
   108      */
       
   109     TInt RunError(TInt aError);
       
   110 
       
   111 private:
       
   112 
       
   113     /**
       
   114      * Default constructor
       
   115      */
       
   116     CUsbBusActivityObserver();
       
   117 
       
   118     /**
       
   119      * 2nd phase construction
       
   120      */
       
   121     void ConstructL();
       
   122 
       
   123 private:
       
   124     // data
       
   125 
       
   126     /**
       
   127      * The observer reports state changes to own observers
       
   128      * Not owns
       
   129      */
       
   130     RPointerArray<MUsbBusActivityObserver> iObservers;
       
   131 
       
   132     /**
       
   133      * The observer observes property change
       
   134      */
       
   135     RProperty iBusActivity;
       
   136 
       
   137     };
       
   138 
       
   139 #endif //  C_USBOTGSTATEOBSERVER_H