resourcemgmt/hwresourcesmgr/server/inc/HWRMGenericTimer.h
changeset 0 4e1aa6a622a0
equal deleted inserted replaced
-1:000000000000 0:4e1aa6a622a0
       
     1 /*
       
     2 * Copyright (c) 2006-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:
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 
       
    21 /**
       
    22  @file
       
    23  @internalTechnology 
       
    24 */
       
    25 
       
    26 #ifndef HWRMGENERICTIMER_H
       
    27 #define HWRMGENERICTIMER_H
       
    28 
       
    29 //  INCLUDES
       
    30 #include <e32base.h>
       
    31 
       
    32 // CONSTANTS
       
    33 const TInt KHWRMGenericTimerMaxTime(0); 
       
    34 
       
    35 /**
       
    36 *  An interface for handling timer expiration events.
       
    37 */
       
    38 class MHWRMGenericTimerCallback
       
    39     {
       
    40     public:
       
    41         /** 
       
    42         * Called when the timer fires
       
    43         *
       
    44         * @param aTimerId Timer identifier to id which timer fired.
       
    45         * @param aCutOff ETrue if timer firing occurred because maximum ontime
       
    46         *                was reached.
       
    47         */
       
    48         virtual void GenericTimerFired(TInt aTimerId, TBool aCutOff) = 0;
       
    49     };
       
    50 
       
    51 /**
       
    52 *  Timer class for supervising Genericting time.
       
    53 */
       
    54 class CHWRMGenericTimer : public CTimer
       
    55     {
       
    56     public:  // Constructors and destructor
       
    57 
       
    58         /**
       
    59         * Two-phased constructor.
       
    60         *
       
    61         * @param aCallback Callback object for informing timer firing
       
    62         * @param aMaxTime Maximum time timer is allowed to run. If KHWRMGenericTimerMaxTime,
       
    63         *        then timer has no maximum time.
       
    64         * @param aTimerId Timer identifier used in timer fired callback.
       
    65         */
       
    66         static CHWRMGenericTimer* NewL(MHWRMGenericTimerCallback& aCallback,
       
    67                                      const TTimeIntervalMicroSeconds32& aMaxTime,
       
    68                                      TInt aTimerId);
       
    69                 
       
    70         /**
       
    71         * Destructor.
       
    72         */
       
    73         ~CHWRMGenericTimer();
       
    74         
       
    75         /**
       
    76         * Set the timer.
       
    77         *
       
    78         * @param aInterval timer will expire after this duration.
       
    79         *        If aInterval is zero, then timer is not started unless
       
    80         *        maximum time has been specified, in which case the 
       
    81         *        maximum time is used as duration.
       
    82         */
       
    83         void Set(const TTimeIntervalMicroSeconds32& aInterval);
       
    84         
       
    85         /**
       
    86         * Cancels the timer and returns the remaining time.
       
    87         * Timer can be resumed with Set call.
       
    88         *
       
    89         * @return Remaining time on timer. Will be Zero if timer is not active,
       
    90         *         otherwise it is always positive.
       
    91         */
       
    92         TTimeIntervalMicroSeconds32 Freeze();
       
    93         
       
    94         /**
       
    95         * Set the maximum time, till the timer runs 
       
    96         */
       
    97 
       
    98         void SetMaximumTime(TTimeIntervalMicroSeconds32& aMaximumTime);
       
    99 
       
   100         /*
       
   101         * Returns the Timer Id
       
   102         */
       
   103         inline TInt GetTimerId()
       
   104         {
       
   105         return iTimerId;
       
   106         }
       
   107         
       
   108         
       
   109     public:  // From base classes
       
   110 
       
   111         // From CTimer
       
   112         void RunL();
       
   113         
       
   114     protected:
       
   115     
       
   116         /**
       
   117         * Constructor
       
   118         *
       
   119         * @param aCallback Callback object for informing timer firing
       
   120         * @param aMaxTime Maximum time timer is allowed to run. If KHWRMGenericTimerMaxTime,
       
   121         *        then timer has no maximum time.
       
   122         * @param aTimerId Timer identifier used in timer fired callback.
       
   123         */
       
   124         CHWRMGenericTimer(MHWRMGenericTimerCallback& aCallback, 
       
   125                         const TTimeIntervalMicroSeconds32& aMaxTime,
       
   126                         TInt aTimerId);
       
   127         
       
   128         /**
       
   129         * Second phase constructor
       
   130         */
       
   131         
       
   132     private: // Data
       
   133         MHWRMGenericTimerCallback&    iCallback;    // Callback for timer fired messages. Not owned.
       
   134         TTimeIntervalMicroSeconds32   iMaximumTime; // Maximum Timer time
       
   135         TBool                         iCutOff;      // Indicates that timer was cut off by max duration
       
   136         TInt                          iTimerId;     // In case multiple timers are needed.
       
   137         
       
   138         TTime                         iActivationTime; // Stores the time the timer is set to activate.
       
   139     };
       
   140 
       
   141 #endif // HWRMGENERICTIMER_H   
       
   142             
       
   143 // End of File