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