usbengines/usbotgwatcher/inc/cusbtimer.h
changeset 0 1e05558e2206
child 3 47c263f7e521
equal deleted inserted replaced
-1:000000000000 0:1e05558e2206
       
     1 /*
       
     2 * Copyright (c) 2008-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:  timer
       
    15  *
       
    16 */
       
    17 
       
    18 #ifndef C_USBTIMER_H
       
    19 #define C_USBTIMER_H
       
    20 
       
    21 #include <e32base.h>
       
    22 
       
    23 class CUsbTimer;
       
    24 
       
    25 /**
       
    26  * timer ids for usbotgwatcher
       
    27  */
       
    28 enum TUsbTimerId
       
    29     {
       
    30     EDeviceAttachmentTimer,
       
    31     EInactiveTimer,
       
    32     EIconBlinkingTimer,
       
    33     ETooMuchPowerRequiredTimer
       
    34     };
       
    35 
       
    36 /**
       
    37  * Observers gets feedback by implementing this interface
       
    38  */
       
    39 class MUsbTimerObserver
       
    40     {
       
    41     friend class CtUsbOtgWatcher;
       
    42 
       
    43 public:
       
    44 
       
    45     /**
       
    46      * Observer must implement this interace
       
    47      * which is called back when timer expires
       
    48      * @param timer id
       
    49      */
       
    50     virtual void TimerElapsedL(TUsbTimerId aTimerId) = 0;
       
    51     };
       
    52 
       
    53 /* *
       
    54  * Wrapper class, will report to MUsbTimerObserver once time is over
       
    55  * Name CUsbTimer is given due to CTimer name already used
       
    56  */
       
    57 NONSHARABLE_CLASS(CUsbTimer) : public CActive
       
    58     {
       
    59 public:
       
    60 
       
    61     /**
       
    62      * Two-phased constructor
       
    63      *
       
    64      * @param aObserver will get call back
       
    65      * @param aTimerId timer id
       
    66      */
       
    67     static CUsbTimer * NewL(MUsbTimerObserver* aObserver,
       
    68             TUsbTimerId aTimerId);
       
    69 
       
    70     /**
       
    71      * Destructor.
       
    72      */
       
    73     virtual ~CUsbTimer();
       
    74 
       
    75     /**
       
    76      * calls RunL after aMilliseconds
       
    77      * @param aMilliseconds time in millisecs
       
    78      */
       
    79     void After(TInt aMilliseconds);
       
    80 
       
    81 public:
       
    82 
       
    83     // from base class CActive
       
    84     /**
       
    85      * Called when request is completed
       
    86      */
       
    87     void RunL();
       
    88 
       
    89     /**
       
    90      * called when RunL leaves
       
    91      * @param aError error code
       
    92      * @return error code
       
    93      */
       
    94     TInt RunError(TInt aError);
       
    95 
       
    96     /**
       
    97      * Called when request is cancelled
       
    98      */
       
    99     void DoCancel();
       
   100 
       
   101 private:
       
   102 
       
   103     /**
       
   104      * Default constructor
       
   105      * @param aObserver will get call back
       
   106      * @param aTimerId timer id 
       
   107      */
       
   108     CUsbTimer(MUsbTimerObserver* aObserver, TUsbTimerId aTimerId);
       
   109 
       
   110     /**
       
   111      * 2nd phase construction
       
   112      */
       
   113     void ConstructL();
       
   114 
       
   115 private:
       
   116     // data
       
   117 
       
   118     /**
       
   119      * Observer
       
   120      * not own
       
   121      */
       
   122     MUsbTimerObserver* iObserver;
       
   123 
       
   124     /**
       
   125      * RTimer API
       
   126      */
       
   127     RTimer iTimer;
       
   128 
       
   129     /**
       
   130      * timer id
       
   131      */
       
   132     TUsbTimerId iTimerId;
       
   133     };
       
   134 
       
   135 #endif //  C_USBTIMER_H