|
1 /* |
|
2 * Copyright (c) 2007 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: Command scheduler. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 #ifndef C_ALFCOMMANDSCHEDULER_H |
|
21 #define C_ALFCOMMANDSCHEDULER_H |
|
22 |
|
23 #include <e32base.h> |
|
24 #include <alf/alfcommand.h> |
|
25 #include <hwrmlight.h> |
|
26 |
|
27 class CAlfEnv; |
|
28 |
|
29 /** |
|
30 * Command scheduler. |
|
31 * |
|
32 * Schedules the commands (see alfcommand.h) which are send to |
|
33 * to the environment class with a timeout != 0. |
|
34 * |
|
35 * @since S60 v3.2 |
|
36 */ |
|
37 NONSHARABLE_CLASS( CAlfCommandScheduler ) : |
|
38 public CBase, |
|
39 public MHWRMLightObserver |
|
40 { |
|
41 |
|
42 public: |
|
43 |
|
44 /** |
|
45 * Constructor |
|
46 */ |
|
47 static CAlfCommandScheduler* NewL( CAlfEnv& aEnv ); |
|
48 |
|
49 /** |
|
50 * Destructor |
|
51 */ |
|
52 virtual ~CAlfCommandScheduler(); |
|
53 |
|
54 /** |
|
55 * Executes given command in given time. |
|
56 * |
|
57 * @param aCommand Command to execute. |
|
58 * @param aTimeInMilliSeconds Time to execution. |
|
59 */ |
|
60 void ScheduleCommandL( const TAlfCommand& aCommand, |
|
61 TInt aTimeInMilliSeconds ); |
|
62 |
|
63 /** |
|
64 * Cancel all commands for given object. |
|
65 * |
|
66 * @param aObject All commands associated to this object are cancelled. |
|
67 */ |
|
68 void CancelCommands( TAny* aObject ); |
|
69 |
|
70 /** |
|
71 * Cancels all commands for the given object with given operation. |
|
72 * |
|
73 * @param aObject Associated object. |
|
74 * @param aCommandOperation Operation which is cancelled. |
|
75 */ |
|
76 void CancelCommands( TAny* aObject, TAlfOp aCommandOperation); |
|
77 |
|
78 /** |
|
79 * Cancels all commands for the given object with given type and paramter. |
|
80 * |
|
81 * @param aObject Associated object. |
|
82 * @param aCommandType Command type. |
|
83 * @param aParam Custom parater (only checked if |
|
84 * aCommandType equals EAlfCommandTypeCustomEvent) |
|
85 */ |
|
86 void CancelCommands( TAny* aObject, |
|
87 TAlfCommandType aCommandType, |
|
88 TInt aParam ); |
|
89 |
|
90 /** |
|
91 * Calculates the milliseconds until the command. |
|
92 * |
|
93 * @param aObject Associated object. |
|
94 * @return Time left in milliseconds to the first found command, which |
|
95 * matched the criteria. KErrNotFound if the none found. The return |
|
96 * value is set to 0 if the command timer has expired and waits |
|
97 * execution from the active scheduler. |
|
98 */ |
|
99 TInt MilliSecondsUntilCommand( |
|
100 TAny* aObject ); |
|
101 |
|
102 /** |
|
103 * Calculates the milliseconds until the command. |
|
104 * |
|
105 * @param aObject Associated object. |
|
106 * @param aCommandOperation Operation which is checked. |
|
107 * @return Time left in milliseconds to the first found command, which |
|
108 * matched the criteria. KErrNotFound if the none found. The return |
|
109 * value is set to 0 if the command timer has expired and waits |
|
110 * execution from the active scheduler. |
|
111 */ |
|
112 TInt MilliSecondsUntilCommand( |
|
113 TAny* aObject, |
|
114 TAlfOp aCommandOperation ); |
|
115 |
|
116 /** |
|
117 * Calculates the milliseconds until the command. |
|
118 * |
|
119 * @param aObject Associated object. |
|
120 * @param aCommandType Command type. |
|
121 * @param aParam Custom parater (only checked if |
|
122 * aCommandType equals EAlfCommandTypeCustomEvent) |
|
123 * @return Time left in milliseconds to the first found command, which |
|
124 * matched the criteria. KErrNotFound if the none found. The return |
|
125 * value is set to 0 if the command timer has expired and waits |
|
126 * execution from the active scheduler. |
|
127 */ |
|
128 TInt MilliSecondsUntilCommand( |
|
129 TAny* aObject, |
|
130 TAlfCommandType aCommandType, |
|
131 TInt aParam ); |
|
132 |
|
133 /** |
|
134 * Executes the command. Called when timer triggers. |
|
135 * |
|
136 * @param aCommand Command to execute. |
|
137 */ |
|
138 void ExecuteEventL( TAlfCommand& aCommand ); |
|
139 |
|
140 /** |
|
141 * Called when the application foreground status changes. |
|
142 * |
|
143 * @param aForeground ETrue if the application is (partially) on foreground. |
|
144 */ |
|
145 void AppicationOnForeground( TBool aForeground ); |
|
146 |
|
147 /** |
|
148 * From MHWRMLightObserver |
|
149 * |
|
150 * Called when display light status changes. |
|
151 */ |
|
152 void LightStatusChanged(TInt aTarget, CHWRMLight::TLightStatus aStatus); |
|
153 |
|
154 private: |
|
155 |
|
156 CAlfCommandScheduler( CAlfEnv& aEnv); |
|
157 |
|
158 void ConstructL(); |
|
159 |
|
160 void UpdateSchedulerState(); |
|
161 void Run(); |
|
162 void Pause(); |
|
163 |
|
164 private: // data |
|
165 |
|
166 // Timed command class. |
|
167 class CTimedEvent : public CTimer |
|
168 { |
|
169 public: |
|
170 static CTimedEvent* NewLC( |
|
171 const TAlfCommand& aCommand, |
|
172 CAlfCommandScheduler& aScheduler ); |
|
173 ~CTimedEvent(); |
|
174 |
|
175 void ExecuteAfter( TInt aIntervalInMilliSeconds, TBool aStartPaused ); |
|
176 void Pause(); |
|
177 void Continue(); |
|
178 TInt TimeLeftInMilliSeconds() const; |
|
179 |
|
180 protected: |
|
181 CTimedEvent( CAlfCommandScheduler& aScheduler ); |
|
182 void ConstructL(const TAlfCommand& aCommand); |
|
183 void RunL(); |
|
184 TInt RunError(TInt aError); |
|
185 public: |
|
186 TAlfCommand* iCommand; |
|
187 private: |
|
188 CAlfCommandScheduler& iScheduler; |
|
189 TTime iLastStartTime; |
|
190 TInt iTimeLeftInMilliSeconds; |
|
191 }; |
|
192 |
|
193 // Timed commands. |
|
194 RPointerArray<CTimedEvent> iEvents; |
|
195 |
|
196 // Environment. |
|
197 CAlfEnv& iEnv; |
|
198 |
|
199 // Internal flags. |
|
200 TUint iFlags; |
|
201 |
|
202 // Light controller/observer. Own. |
|
203 CHWRMLight* iLight; |
|
204 }; |
|
205 |
|
206 |
|
207 #endif // C_ALFCOMMANDSCHEDULER_H |