usbengines/usbotgwatcher/inc/cusbvbusobserver.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:  Implements VBus observer
       
    15  *
       
    16  */
       
    17 
       
    18 #ifndef C_USBVBUSOBSERVER_H
       
    19 #define C_USBVBUSOBSERVER_H
       
    20 
       
    21 #include <e32base.h>
       
    22 #include <e32property.h>
       
    23 
       
    24 /**
       
    25  * Observers of this class have to implement this interface
       
    26  * to get call back on VBus events
       
    27  */
       
    28 NONSHARABLE_CLASS( MUsbVBusObserver)
       
    29     {
       
    30 public:
       
    31 
       
    32     /**
       
    33      * VBus down event received
       
    34      */
       
    35     virtual void VBusDownL() = 0;
       
    36     /**
       
    37      * VBus up event received
       
    38      */
       
    39     virtual void VBusUpL() = 0;
       
    40     /**
       
    41      * error handler
       
    42      * @param aError error code
       
    43      */
       
    44     virtual void VBusObserverErrorL(TInt aError)=0;
       
    45 
       
    46     };
       
    47 
       
    48 /**
       
    49  *  Class observes VBUS property
       
    50  *
       
    51  */
       
    52 NONSHARABLE_CLASS( CUsbVBusObserver ) : public CActive
       
    53     {
       
    54 
       
    55 public:
       
    56     enum TState
       
    57         {
       
    58         EVBusDown = 0, EVBusUp = 1
       
    59 
       
    60         };
       
    61 
       
    62     /**
       
    63      * Two-phased constructor.
       
    64      */
       
    65     static CUsbVBusObserver* NewL();
       
    66 
       
    67     /**
       
    68      * Destructor.
       
    69      */
       
    70     virtual ~CUsbVBusObserver();
       
    71 
       
    72     /**
       
    73      * VBus state getter
       
    74      * @return VBus state
       
    75      */
       
    76     TState VBus() /* not const. read comment in impl*/;
       
    77 
       
    78     /**
       
    79      * Adds observer to a list
       
    80      * @param aObserver observer
       
    81      */
       
    82     void SubscribeL(MUsbVBusObserver& aObserver);
       
    83 
       
    84     /**
       
    85      * removes observer from list
       
    86      * @param aObserver observer
       
    87      */
       
    88     void UnsubscribeL(MUsbVBusObserver& aObserver);
       
    89 
       
    90 private:
       
    91 
       
    92     // From CActive
       
    93     /**
       
    94      * Called when request completed
       
    95      *
       
    96      */
       
    97     void RunL();
       
    98 
       
    99     /**
       
   100      * Called when request is cancelled
       
   101      *
       
   102      */
       
   103     void DoCancel();
       
   104 
       
   105     /**
       
   106      * Called when RunL leaves
       
   107      * @param aError error code
       
   108      * @return error code
       
   109      *
       
   110      */
       
   111     TInt RunError(TInt aError);
       
   112 
       
   113 private:
       
   114 
       
   115     /**
       
   116      * Default constructor
       
   117      */
       
   118     CUsbVBusObserver();
       
   119 
       
   120     /**
       
   121      * 2nd phase constructor
       
   122      */
       
   123     void ConstructL();
       
   124 
       
   125 private:
       
   126     // data
       
   127 
       
   128     /**
       
   129      * The observer reports state changes to own observers
       
   130      * Not owns
       
   131      */
       
   132     RPointerArray<MUsbVBusObserver> iObservers;
       
   133 
       
   134     /**
       
   135      * The observer observes property change
       
   136      */
       
   137     RProperty iVBus;
       
   138 
       
   139     };
       
   140 
       
   141 #endif //  C_USBVBUSOBSERVER_H