multimediacommscontroller/mmccshared/inc/mcctimermanager.h
changeset 0 1bce908db942
equal deleted inserted replaced
-1:000000000000 0:1bce908db942
       
     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:    
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 
       
    21 #ifndef CMCCTIMERMANAGER_H
       
    22 #define CMCCTIMERMANAGER_H
       
    23 
       
    24 // INCLUDES
       
    25 #include <e32base.h>
       
    26 #include "mccexpirationhandler.h"
       
    27 
       
    28 // CLASS DEFINITION
       
    29 /**
       
    30  * Several logical timers can run simultaneously, but only one RTimer is used.
       
    31  *
       
    32  */
       
    33 class CMccTimerManager
       
    34 	: public CActive,
       
    35 	  public MMccTimerManager
       
    36 	{
       
    37 	public: // Constructors and destructor
       
    38 
       
    39 		/**
       
    40 		 * Static constructor.
       
    41 		 *
       
    42 		 * @see CMccTimerManager::NewLC
       
    43 		 * @return An initialized instance of this class.
       
    44 		 */
       
    45 		static CMccTimerManager* NewL();
       
    46 
       
    47 		/**
       
    48 		 * Static constructor. Leaves pointer to cleanup stack.
       
    49 		 *
       
    50 		 * @see CMccTimerManager::NewL
       
    51 		 * @return An initialized instance of this class.
       
    52 		 */
       
    53 		static CMccTimerManager* NewLC();
       
    54 
       
    55 	    /// Destructor
       
    56 		~CMccTimerManager();
       
    57 
       
    58 	public: // From CActive
       
    59 	
       
    60 		void DoCancel();
       
    61 		void RunL();
       
    62 		TInt RunError( TInt aError );
       
    63 
       
    64 	public: // From MMccTimerManager
       
    65 
       
    66 		TMccTimerId StartL( MMccExpirationHandler* aObserver,
       
    67 						 TUint aMilliseconds );
       
    68 
       
    69 		TMccTimerId StartL( MMccExpirationHandler* aObserver,
       
    70 						 TUint aMilliseconds,
       
    71 						 TAny* aTimerParam );
       
    72 						 
       
    73 		TInt Stop( TMccTimerId aTimerId );
       
    74 		
       
    75 		TBool IsRunning( TMccTimerId aTimerId ) const;
       
    76 
       
    77 	private: // New methods
       
    78 
       
    79 		/**
       
    80 		 * Generates a new unique TMccTimerId value. This is basically just
       
    81 		 * a linear sequence of TUint32 values (0,1,2,3,4...n)
       
    82 		 *
       
    83 		 * @return New TimerId value
       
    84 		 */
       
    85 		TMccTimerId NewTimerId();
       
    86 
       
    87 		/**
       
    88 		 * Finds a timer entry from the iEntries array based on the supplied id.
       
    89 		 *
       
    90 		 * @return Timer entry index within iEntries or KErrNotFound.
       
    91 		 */
       
    92 		TInt FindEntry( TMccTimerId aTimerId ) const;
       
    93 
       
    94 		/// Queue the first timer entry to the system timer (if any)
       
    95 		void ActivateFirstEntry();
       
    96 		
       
    97 	private: //  Constructors and destructor
       
    98 
       
    99 		/// Default constructor
       
   100 		inline CMccTimerManager();
       
   101 		
       
   102 		/// 2nd phase constructor
       
   103 		inline void ConstructL();
       
   104 
       
   105 	private: // Nested classes
       
   106 
       
   107 		// CLASS DEFINITION
       
   108 		/**
       
   109 		 * TEntry defines a simple timer entry container for CMccTimerManager.
       
   110 		 */
       
   111 		class TEntry
       
   112 			{
       
   113 			public: // Constructors and destructor
       
   114 
       
   115 				/// Default constructor. Resets all member variables.
       
   116 				TEntry();
       
   117 
       
   118 			public: // Data
       
   119 
       
   120 				/// Unique timer id within CMccTimerManager
       
   121 				TMccTimerId iId;
       
   122 				/// Timestamp of system clock when this entry should expire. 
       
   123 				TTime iTimeStamp;
       
   124 				/// Observer that is notified on timer expiration. Not owned.
       
   125 				MMccExpirationHandler* iObserver;
       
   126 				/// Parameter value that is passed to the observer.
       
   127 				TAny* iObserverParam;
       
   128 
       
   129 			};
       
   130 
       
   131 	private: // Data
       
   132 
       
   133 		/// System timer. Owned.
       
   134 		RTimer iTimer;
       
   135 
       
   136 		/// Timer entry array. Owned.
       
   137 		CArrayFixFlat< TEntry > iEntries;
       
   138 
       
   139 		/// Counter used to produce unique TimerId values
       
   140 		TMccTimerId iTimerIdCounter;
       
   141 		
       
   142     #ifdef TEST_EUNIT
       
   143     public:
       
   144         friend class UT_CMccTimerManager;
       
   145     #endif
       
   146 	};
       
   147 
       
   148 #endif // CMCCTIMERMANAGER_H