sensorservices/sensorserver/inc/server/sensrvtimer.h
changeset 0 4e1aa6a622a0
equal deleted inserted replaced
-1:000000000000 0:4e1aa6a622a0
       
     1 /*
       
     2 * Copyright (c) 2006 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:  Generic sensor server timer
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #ifndef SENSRVTIMER_H
       
    20 #define SENSRVTIMER_H
       
    21 
       
    22 #include <e32base.h>
       
    23 
       
    24 const TInt KSensrvTimerMaxTime(0); 
       
    25 
       
    26 /**
       
    27 * A callback interface for handling timer expiration events.
       
    28 *
       
    29 * @since S60 5.0
       
    30 */
       
    31 class MSensrvTimerCallback
       
    32     {
       
    33     public:
       
    34 
       
    35         /** 
       
    36         * Called when the timer fires
       
    37         *
       
    38         * @since S60 5.0
       
    39         * @param aTimerId Timer identifier to id which timer fired.
       
    40         */
       
    41         virtual void TimerFired(TInt aTimerId) = 0;
       
    42     };
       
    43 
       
    44 /**
       
    45 *  Timer class for sensor server timing needs.
       
    46 *
       
    47 * @since S60 5.0
       
    48 */
       
    49 class CSensrvTimer : public CTimer
       
    50     {
       
    51     public:  
       
    52     
       
    53         /**
       
    54         * Predefined timer identifiers
       
    55         *
       
    56         * @since S60 5.0
       
    57         */
       
    58         enum TTimerId
       
    59             {
       
    60             ETimerIdSsyCleanupTimer       = 1,
       
    61             ETimerIdBufferPeriodTimer     = 2,
       
    62             ETimerIdTransactionTimer      = 3,
       
    63             ETimerIdSsyInactivityTimer    = 4
       
    64             };
       
    65 
       
    66         /**
       
    67         * Two-phased constructor.
       
    68         *
       
    69         * @since S60 5.0
       
    70         * @param aCallback Callback object for informing timer firing
       
    71         * @param aMaxTime Maximum time timer is allowed to run. If KSensrvTimerMaxTime,
       
    72         *        then timer has no maximum time.
       
    73         * @param aTimerId Timer identifier used in timer fired callback.
       
    74         */
       
    75         static CSensrvTimer* NewL(MSensrvTimerCallback& aCallback,
       
    76                                   const TTimeIntervalMicroSeconds32& aMaxTime,
       
    77                                   TInt aTimerId);
       
    78                 
       
    79         /**
       
    80         * Destructor.
       
    81         */
       
    82         ~CSensrvTimer();
       
    83         
       
    84         /**
       
    85         * Set the timer.
       
    86         *
       
    87         * @since S60 5.0
       
    88         * @param aInterval timer will expire after this duration.
       
    89         *        If aInterval is zero, then timer is not started unless
       
    90         *        maximum time has been specified, in which case the 
       
    91         *        maximum time is used as duration.
       
    92         */
       
    93         void Set(const TTimeIntervalMicroSeconds32& aInterval);
       
    94         
       
    95         
       
    96     public:  
       
    97 
       
    98         // From CTimer
       
    99         void RunL();
       
   100         
       
   101     protected:
       
   102     
       
   103         /**
       
   104         * C++ constructor
       
   105         *
       
   106         * @since S60 5.0
       
   107         * @param aCallback Callback object for informing timer firing
       
   108         * @param aMaxTime Maximum time timer is allowed to run. If KSensrvTimerMaxTime,
       
   109         *        then timer has no maximum time.
       
   110         * @param aTimerId Timer identifier used in timer fired callback.
       
   111         */
       
   112         CSensrvTimer(MSensrvTimerCallback& aCallback, 
       
   113                      const TTimeIntervalMicroSeconds32& aMaxTime,
       
   114                      TInt aTimerId);
       
   115         
       
   116     private: 
       
   117     
       
   118         /**
       
   119         * Callback for timer fired messages. 
       
   120         * Not own.
       
   121         */
       
   122         MSensrvTimerCallback& iCallback;    
       
   123         
       
   124         /**
       
   125         * Maximum timer time.
       
   126         */
       
   127         TTimeIntervalMicroSeconds32 iMaximumTime; 
       
   128         
       
   129         /**
       
   130         * In case multiple timers are needed
       
   131         */        
       
   132         TInt iTimerId;
       
   133     };
       
   134 
       
   135 
       
   136 
       
   137 #endif // SENSRVTIMER_H