realtimenetprots/sipfw/SIP/LightWeightTimer/inc/TimerManager.h
changeset 0 307788aac0a8
equal deleted inserted replaced
-1:000000000000 0:307788aac0a8
       
     1 /*
       
     2 * Copyright (c) 2005-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 * Name          : TimerManager.h
       
    16 * Part of       : LightWeightTimer
       
    17 * This header file is included by the subsystem which is 
       
    18 * responsible for creating the CTimerManager instance.
       
    19 * Version       : SIP/4.0
       
    20 *
       
    21 */
       
    22 
       
    23 
       
    24 
       
    25 
       
    26 /**
       
    27  @internalComponent
       
    28 */
       
    29 
       
    30 #ifndef TIMERMANAGER_H
       
    31 #define TIMERMANAGER_H
       
    32 
       
    33 // INCLUDES
       
    34 #include <e32base.h>
       
    35 #include "Lwtimer.h"
       
    36 #include "mtimernotifier.h"
       
    37 
       
    38 // FORWARD DECLARATIONS
       
    39 class CTimerStore;
       
    40 class CSingleTimer;
       
    41 
       
    42 // CLASS DECLARATION
       
    43 
       
    44 /**
       
    45  * CTimerManager is the main class of the Lightweight timer subsystem. It is
       
    46  * intended to be used in a way that there is only one instance of the
       
    47  * CTimerManager class, and the basic timer services are available through the
       
    48  * MTimerManager interface.
       
    49  *
       
    50  * Several logical timers can run simultaneously, but only one RTimer is used.
       
    51  */
       
    52 class CTimerManager :
       
    53     public CBase,
       
    54 	public MTimerNotifier,
       
    55 	public MTimerManager
       
    56 	{
       
    57 public: // Constructors and destructor
       
    58 
       
    59 	/**
       
    60 	 * Creates an instance of CTimerManager.
       
    61 	 *
       
    62 	 * @see CTimerManager::NewLC
       
    63 	 *	
       
    64 	 * @return value The new CTimerManager object. Ownership is transferred.
       
    65 	 */
       
    66 	static CTimerManager* NewL();
       
    67 
       
    68 	/**
       
    69 	 * Creates an instance of CTimerManager and pushes it to CleanupStack.
       
    70 	 *
       
    71 	 * @see CTimerManager::NewL
       
    72 	 *
       
    73 	 * @return value The new CTimerManager object. Ownership is transferred.
       
    74 	 */
       
    75 	static CTimerManager* NewLC();
       
    76 
       
    77     /**
       
    78      * Destructor
       
    79      */
       
    80 	~CTimerManager();
       
    81 
       
    82 public: //From MTimerNotifier
       
    83 
       
    84 	void TimerExpiredL(TTimerId aTimerId);
       
    85 
       
    86 	TInt LeaveOccurred();
       
    87 
       
    88 public: //From MTimerManager	
       
    89 
       
    90 	TTimerId StartL(MExpirationHandler* aObserver,
       
    91 				    TUint aMilliseconds);
       
    92 
       
    93 	TTimerId StartL(MExpirationHandler* aObserver,
       
    94 					TUint aMilliseconds,
       
    95 					TAny* aTimerParam);
       
    96 
       
    97 	TInt Stop(TTimerId aTimerId);
       
    98 	
       
    99 	TBool IsRunning(TTimerId aTimerId) const;
       
   100 	
       
   101 	TInt ExpiresAfter( TTimerId aTimerId, TUint& aExpiresAfterInMillisecs) const;
       
   102 
       
   103 private: // Constructors
       
   104 
       
   105 	CTimerManager();
       
   106 
       
   107 	/**
       
   108 	 * Second phase constructor.	 
       
   109 	 */
       
   110 	void ConstructL();
       
   111 
       
   112 private: // For internal use
       
   113 
       
   114 	/**
       
   115 	 * Generates a new unique TTimerId value.
       
   116 	 *	 
       
   117 	 * @return value New TimerId value
       
   118 	 */
       
   119 	TTimerId NewTimerId();
       
   120 
       
   121 	/**
       
   122 	 * Set a timer running with the duration of the shortest timer.
       
   123 	 *
       
   124 	 * @pre iTimer must not be active	 
       
   125 	 */
       
   126 	void SetTimerWithShortestValueL();
       
   127 
       
   128 	/**
       
   129 	 * Checks if the recently added new timer is shorter than any of the
       
   130 	 * existing timers. If it is, the currently running CSingleTimer is
       
   131 	 * canceled and CSingleTimer is started again, now with the duration of
       
   132 	 * the new timer.
       
   133 	 *
       
   134 	 * @param aTimerId TimerId of the new timer
       
   135 	 * @param aMilliseconds Duration of the new timer, in milliseconds
       
   136 	 */
       
   137 	void CheckIsNewTimerShortestL(TTimerId aTimerId, TUint aMilliseconds);
       
   138 
       
   139 	/**
       
   140 	 * Set a dummy timer to simulate a longer timer without the need to use
       
   141 	 * RTimer::At.
       
   142 	 */
       
   143 	void SetInternalTimerL() const;
       
   144 
       
   145 	/**
       
   146 	 * Calculates a TTime value by adding the specified amount of time
       
   147 	 * (aMilliseconds) to current time.	 
       
   148 	 *
       
   149 	 * @param aMilliseconds Amount of milliseconds from current time	 
       
   150 	 * @return value TTime
       
   151 	 */
       
   152 	TTime MillisecToTTime(TUint aMilliseconds) const;
       
   153 
       
   154 	/**
       
   155 	 * Calculates the amount of milliseconds between current time and aTime and
       
   156 	 * fills the result into aMilliseconds.
       
   157 	 *
       
   158 	 * @param aTime time
       
   159 	 * @param aMilliseconds Amount of milliseconds from current time	 
       
   160 	 * @return value ETrue If successful
       
   161 	 *				 EFalse The duration between aTime and current time is too
       
   162 	 *						large to fit into TUint.
       
   163 	 */
       
   164 	TBool TTimeToMillisec(TTime aTime, TUint& aMilliseconds) const;	
       
   165 
       
   166 private: // Data
       
   167 
       
   168 	//Contains information of existing timer requests. Owned.
       
   169 	CTimerStore* iTimerStore;
       
   170 
       
   171 	//Timer used by all the timer requests. Owned.
       
   172 	CSingleTimer* iTimer;
       
   173 
       
   174 	//Counter used to produce unique TimerId values
       
   175 	TTimerId iTimerIdCounter;
       
   176 
       
   177 	//ETrue if CTimerManager is calling MExpirationHandler::TimerExpiredL.
       
   178 	//Otherwise value is EFalse.
       
   179 	//This flag is needed as user of CTimerManager might set a new timer within
       
   180 	//MExpirationHandler::TimerExpiredL, and CTimerManager has to recognize such
       
   181 	//a situation.
       
   182 	TBool iNowExpiring;
       
   183 
       
   184 private: // For testing purposes
       
   185 
       
   186 	void __DbgTestInvariant() const;
       
   187 	
       
   188 
       
   189 #ifdef CPPUNIT_TEST	
       
   190 	friend class CTimerManager_test;
       
   191 	friend class CTimerStore_test;
       
   192 	friend class CTimerRequest_test;
       
   193 	friend class CSingleTimer_test;
       
   194 #endif
       
   195 	};
       
   196 
       
   197 #endif // end of TIMERMANAGER_H
       
   198 
       
   199 // End of File