|
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: This header file is included by the subsystem which is |
|
15 * responsible for creating the CMceTimerManager instance. |
|
16 * |
|
17 */ |
|
18 |
|
19 |
|
20 |
|
21 |
|
22 #ifndef __CMCETIMERMANAGER_H__ |
|
23 #define __CMCETIMERMANAGER_H__ |
|
24 |
|
25 |
|
26 |
|
27 // INCLUDES |
|
28 #include <e32base.h> |
|
29 #include "mceexpirationhandler.h" |
|
30 |
|
31 // Timer call back function used by CDeltaTimer |
|
32 typedef TInt(*MceTimerCallBack)(TAny *aPtr); |
|
33 |
|
34 // CLASS DEFINITION |
|
35 /** |
|
36 * CMceTimerManager is the main class of the Lightweight timer subsystem. It is |
|
37 * intended to be used in a way that there is only one instance of the |
|
38 * CMceTimerManager class, and the basic timer services are available through the |
|
39 * MTimerManager interface. |
|
40 * |
|
41 * Several logical timers can run simultaneously, but only one CTimer derived |
|
42 * timer is used. |
|
43 */ |
|
44 class CMceTimerManager : |
|
45 public CBase, |
|
46 public MMceTimerManager |
|
47 |
|
48 { |
|
49 public: // Constructors and destructor |
|
50 |
|
51 /** |
|
52 * Static constructor. |
|
53 * |
|
54 * @see CMceTimerManager::NewLC |
|
55 * @return An initialized instance of this class. |
|
56 */ |
|
57 static CMceTimerManager* NewL(); |
|
58 |
|
59 /** |
|
60 * Static constructor. Leaves pointer to cleanup stack. |
|
61 * |
|
62 * @see CMceTimerManager::NewL |
|
63 * @return An initialized instance of this class. |
|
64 */ |
|
65 static CMceTimerManager* NewLC(); |
|
66 |
|
67 /// Destructor |
|
68 ~CMceTimerManager(); |
|
69 |
|
70 public: // From MTimerManager: |
|
71 |
|
72 TMceTimerId StartL( MMCEExpirationHandler* aObserver, |
|
73 TUint aMilliseconds ); |
|
74 |
|
75 TMceTimerId StartL( MMCEExpirationHandler* aObserver, |
|
76 TUint aMilliseconds, |
|
77 TAny* aTimerParam ); |
|
78 |
|
79 TInt Stop( TMceTimerId aTimerId ); |
|
80 |
|
81 TBool IsRunning( TMceTimerId aTimerId ) const; |
|
82 |
|
83 static TInt TimerExpiredCallBack(TAny *aPtr); |
|
84 |
|
85 private: // New methods |
|
86 |
|
87 /** |
|
88 * Generates a new unique TMceTimerId value. This is basically just |
|
89 * a linear sequence of TUint32 values (0,1,2,3,4...n) |
|
90 * |
|
91 * @return New TimerId value |
|
92 */ |
|
93 TMceTimerId NewTimerId(); |
|
94 |
|
95 /** |
|
96 * Finds a timer entry from the iEntries array based on the supplied id. |
|
97 * |
|
98 * @return Timer entry index within iEntries or KErrNotFound. |
|
99 */ |
|
100 TInt FindEntry( TMceTimerId aTimerId ) const; |
|
101 |
|
102 /// Queue the first timer entry to the system timer (if any) |
|
103 void ActivateFirstEntry(); |
|
104 |
|
105 private: // Constructors and destructor |
|
106 |
|
107 /// Default constructor |
|
108 inline CMceTimerManager(); |
|
109 |
|
110 /// 2nd phase constructor |
|
111 inline void ConstructL(); |
|
112 |
|
113 private: // Nested classes |
|
114 |
|
115 // CLASS DEFINITION |
|
116 class TEntry // : public TDeltaTimerEntry |
|
117 { |
|
118 public: // Constructors and destructor |
|
119 |
|
120 /// Default constructor. Resets all member variables. |
|
121 TEntry(); |
|
122 |
|
123 public: // Data |
|
124 |
|
125 /// Unique timer id within CMceTimerManager |
|
126 TMceTimerId iId; |
|
127 |
|
128 /// Observer that is notified on timer expiration. Not owned. |
|
129 MMCEExpirationHandler* iObserver; |
|
130 |
|
131 /// Parameter value that is passed to the observer. Not owned |
|
132 TAny* iObserverParam; |
|
133 |
|
134 /// Parameter value that is passed to the CDeltaTimer::QueueLong |
|
135 TDeltaTimerEntry iEntry; |
|
136 |
|
137 /// Parameter value that is contain the call back function |
|
138 TCallBack iCallBack; |
|
139 |
|
140 /// Used to remove TEntry pointer from CMceTimerManager::iEntries. Not owned |
|
141 CMceTimerManager* iTimerManager; |
|
142 |
|
143 |
|
144 }; |
|
145 |
|
146 private: // Data |
|
147 |
|
148 /// Timer entry array. Owned. |
|
149 RPointerArray< TEntry > iEntries; |
|
150 |
|
151 /// Counter used to produce unique TimerId values |
|
152 TMceTimerId iTimerIdCounter; |
|
153 |
|
154 /// Implemented the timer queue and scheduler logic |
|
155 CDeltaTimer *iTimerContainer; |
|
156 |
|
157 private: // For testing purposes |
|
158 |
|
159 #ifdef MCE_TIMER_MANAGER_UNIT_TEST |
|
160 friend class CMceTimerManagerTest; |
|
161 #endif |
|
162 |
|
163 }; |
|
164 |
|
165 |
|
166 #endif // __CMCETIMERMANAGER_H__ |