|
1 /* |
|
2 * Copyright (c) 2010 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 #include "cactivitymanager.h" |
|
19 #include <f32file.h> |
|
20 #include "OstTraceDefinitions.h" |
|
21 #ifdef OST_TRACE_COMPILER_IN_USE |
|
22 #include "cactivitymanagerTraces.h" |
|
23 #endif |
|
24 |
|
25 |
|
26 // --------------------------------------------------------------------------- |
|
27 // CActivityManager::NewL() |
|
28 // --------------------------------------------------------------------------- |
|
29 // |
|
30 CActivityManager* CActivityManager::NewL(MActivityManagerObserver* aObserver, TInt aTimeout) |
|
31 { |
|
32 OstTraceFunctionEntry0( CACTIVITYMANAGER_NEWL_ENTRY ); |
|
33 CActivityManager* self = new (ELeave) CActivityManager(aObserver, aTimeout); |
|
34 CleanupStack::PushL(self); |
|
35 self->ConstructL(); |
|
36 CleanupStack::Pop(self); |
|
37 OstTraceFunctionExit0( CACTIVITYMANAGER_NEWL_EXIT ); |
|
38 return self; |
|
39 } |
|
40 |
|
41 // --------------------------------------------------------------------------- |
|
42 // CActivityManager::CActivityManager() |
|
43 // --------------------------------------------------------------------------- |
|
44 // |
|
45 CActivityManager::CActivityManager(MActivityManagerObserver* aObserver, TInt aTimeout) |
|
46 : CActive(CActive::EPriorityHigh), iObserver(aObserver), iTimeout(aTimeout), iPreviousStatus(KErrNotFound) |
|
47 { |
|
48 OstTraceFunctionEntry0( CACTIVITYMANAGER_CACTIVITYMANAGER_ENTRY ); |
|
49 CActiveScheduler::Add(this); |
|
50 OstTraceFunctionExit0( CACTIVITYMANAGER_CACTIVITYMANAGER_EXIT ); |
|
51 } |
|
52 |
|
53 // --------------------------------------------------------------------------- |
|
54 // CActivityManager::~CActivityManager() |
|
55 // --------------------------------------------------------------------------- |
|
56 // |
|
57 CActivityManager::~CActivityManager() |
|
58 { |
|
59 OstTraceFunctionEntry0( DUP1_CACTIVITYMANAGER_CACTIVITYMANAGER_ENTRY ); |
|
60 |
|
61 iObserver = NULL; |
|
62 Cancel(); |
|
63 |
|
64 #ifdef MONITOR_LIGHTS |
|
65 delete iLight; |
|
66 iLight = NULL; |
|
67 #endif |
|
68 |
|
69 iTimer.Cancel(); |
|
70 iTimer.Close(); |
|
71 OstTraceFunctionExit0( DUP1_CACTIVITYMANAGER_CACTIVITYMANAGER_EXIT ); |
|
72 } |
|
73 |
|
74 // --------------------------------------------------------------------------- |
|
75 // CActivityManager::ConstructL() |
|
76 // --------------------------------------------------------------------------- |
|
77 // |
|
78 void CActivityManager::ConstructL() |
|
79 { |
|
80 iTimer.CreateLocal(); |
|
81 iWatch = ENone; |
|
82 } |
|
83 |
|
84 // --------------------------------------------------------------------------- |
|
85 // CTMActivityManager::SetTimeout() |
|
86 // --------------------------------------------------------------------------- |
|
87 // |
|
88 void CActivityManager::SetTimeout(TInt aTimeout) |
|
89 { |
|
90 iTimeout = aTimeout; |
|
91 Reset(); |
|
92 } |
|
93 |
|
94 // --------------------------------------------------------------------------- |
|
95 // CActivityManager::Reset() |
|
96 // --------------------------------------------------------------------------- |
|
97 // |
|
98 void CActivityManager::Reset() |
|
99 { |
|
100 #ifdef MONITOR_LIGHTS |
|
101 delete iLight; |
|
102 iLight = NULL; |
|
103 #endif |
|
104 |
|
105 Cancel(); |
|
106 Start(); |
|
107 } |
|
108 |
|
109 // --------------------------------------------------------------------------- |
|
110 // CActivityManager::DoCancel() |
|
111 // --------------------------------------------------------------------------- |
|
112 void CActivityManager::DoCancel() |
|
113 { |
|
114 |
|
115 #ifdef MONITOR_LIGHTS |
|
116 delete iLight; |
|
117 iLight = NULL; |
|
118 #endif |
|
119 |
|
120 iTimer.Cancel(); |
|
121 iWatch = ENone; |
|
122 } |
|
123 |
|
124 // --------------------------------------------------------------------------- |
|
125 // CActivityManager::Start() |
|
126 // --------------------------------------------------------------------------- |
|
127 // |
|
128 void CActivityManager::Start() |
|
129 { |
|
130 OstTraceFunctionEntry0( CACTIVITYMANAGER_START_ENTRY ); |
|
131 |
|
132 #ifdef MONITOR_LIGHTS |
|
133 if(!iLight) |
|
134 { |
|
135 TRAP_IGNORE(iLight = CHWRMLight::NewL(this)); |
|
136 } |
|
137 #endif |
|
138 |
|
139 if ( iWatch == ENone ) |
|
140 { |
|
141 iFirstRound = ETrue; |
|
142 |
|
143 if( !IsActive() ) |
|
144 { |
|
145 SetActive(); |
|
146 TRequestStatus* statusPtr = &iStatus; |
|
147 User::RequestComplete( statusPtr, KErrNone ); |
|
148 } |
|
149 } |
|
150 OstTraceFunctionExit0( CACTIVITYMANAGER_START_EXIT ); |
|
151 } |
|
152 |
|
153 // --------------------------------------------------------------------------- |
|
154 // CActivityManager::RunL() |
|
155 // --------------------------------------------------------------------------- |
|
156 // |
|
157 void CActivityManager::RunL() |
|
158 { |
|
159 OstTraceFunctionEntry0( CACTIVITYMANAGER_RUNL_ENTRY ); |
|
160 if(iFirstRound) |
|
161 { |
|
162 iFirstRound = EFalse; |
|
163 if (!IsActive()) |
|
164 { |
|
165 iWatch = EWaitingForInactivity; |
|
166 iTimer.Inactivity(iStatus, iTimeout); |
|
167 SetActive(); |
|
168 } |
|
169 NotifyObserver(); |
|
170 OstTraceFunctionExit0( CACTIVITYMANAGER_RUNL_EXIT ); |
|
171 return; |
|
172 } |
|
173 |
|
174 if (iStatus == KErrNone) |
|
175 { |
|
176 if (iWatch == EWaitingForInactivity) |
|
177 { |
|
178 TInt inactivity = User::InactivityTime().Int(); |
|
179 if (inactivity >= iTimeout) |
|
180 { |
|
181 NotifyObserver(); |
|
182 |
|
183 if (!IsActive()) //observer might have called a Reset() |
|
184 { |
|
185 iTimer.Inactivity(iStatus,0); |
|
186 iWatch = EWaitingForActivity; |
|
187 } |
|
188 } |
|
189 else |
|
190 { |
|
191 iTimer.Inactivity(iStatus,iTimeout); |
|
192 } |
|
193 } |
|
194 else if (iWatch == EWaitingForActivity) |
|
195 { |
|
196 NotifyObserver(); |
|
197 |
|
198 if (!IsActive()) //observer might have called a Reset() |
|
199 { |
|
200 iTimer.Inactivity(iStatus,iTimeout); |
|
201 iWatch = EWaitingForInactivity; |
|
202 } |
|
203 } |
|
204 |
|
205 if (!IsActive()) //observer might have called a Reset() |
|
206 { |
|
207 SetActive(); |
|
208 } |
|
209 } |
|
210 else |
|
211 { |
|
212 iWatch = ENone; |
|
213 } |
|
214 OstTraceFunctionExit0( DUP1_CACTIVITYMANAGER_RUNL_EXIT ); |
|
215 } |
|
216 |
|
217 // --------------------------------------------------------------------------- |
|
218 // CActivityManager::RunError() |
|
219 // --------------------------------------------------------------------------- |
|
220 // |
|
221 TInt CActivityManager::RunError(TInt aError) |
|
222 { |
|
223 OstTraceFunctionEntry0( CACTIVITYMANAGER_RUNERROR_ENTRY ); |
|
224 if (aError != KErrNone) |
|
225 { |
|
226 Reset(); |
|
227 } |
|
228 |
|
229 // nothing to do |
|
230 OstTraceFunctionExit0( CACTIVITYMANAGER_RUNERROR_EXIT ); |
|
231 return KErrNone; |
|
232 } |
|
233 |
|
234 // ----------------------------------------------------------------------------- |
|
235 // IsInactive() |
|
236 // ----------------------------------------------------------------------------- |
|
237 // |
|
238 TBool CActivityManager::IsInactive() |
|
239 { |
|
240 OstTraceFunctionEntry0( CACTIVITYMANAGER_ISINACTIVE_ENTRY ); |
|
241 |
|
242 #ifdef MONITOR_LIGHTS |
|
243 #ifdef _DEBUG |
|
244 TInt inactivityTime = User::InactivityTime().Int(); |
|
245 #endif |
|
246 #else |
|
247 TInt inactivityTime = User::InactivityTime().Int(); |
|
248 #endif |
|
249 |
|
250 //if lights are off or inactivity timer is less that target the device is not idle |
|
251 if( User::InactivityTime() >= TTimeIntervalSeconds(iTimeout) |
|
252 #ifdef MONITOR_LIGHTS |
|
253 || !iLights |
|
254 #endif |
|
255 ) |
|
256 { |
|
257 OstTraceFunctionExit0( CACTIVITYMANAGER_ISINACTIVE_EXIT ); |
|
258 return ETrue; |
|
259 } |
|
260 OstTraceFunctionExit0( DUP1_CACTIVITYMANAGER_ISINACTIVE_EXIT ); |
|
261 return EFalse; |
|
262 } |
|
263 |
|
264 #ifdef MONITOR_LIGHTS |
|
265 // ----------------------------------------------------------------------------- |
|
266 // LightStatusChanged() |
|
267 // ----------------------------------------------------------------------------- |
|
268 // |
|
269 void CActivityManager::LightStatusChanged(TInt aTarget, CHWRMLight::TLightStatus aStatus) |
|
270 { |
|
271 if(aTarget & CHWRMLight::EPrimaryDisplay) |
|
272 { |
|
273 if( aStatus == CHWRMLight::ELightOff ) |
|
274 { |
|
275 iLights = EFalse; |
|
276 } |
|
277 else |
|
278 { |
|
279 iLights = ETrue; |
|
280 } |
|
281 |
|
282 NotifyObserver(); |
|
283 } |
|
284 } |
|
285 #endif |
|
286 |
|
287 // ----------------------------------------------------------------------------- |
|
288 // NotifyObserver() |
|
289 // ----------------------------------------------------------------------------- |
|
290 // |
|
291 void CActivityManager::NotifyObserver() |
|
292 { |
|
293 OstTraceFunctionEntry0( CACTIVITYMANAGER_NOTIFYOBSERVER_ENTRY ); |
|
294 TBool status = IsInactive(); |
|
295 OstTrace1( TRACE_NORMAL, CACTIVITYMANAGER_NOTIFYOBSERVER, "CActivityManager::NotifyObserver;status=%d", status ); |
|
296 |
|
297 if( iPreviousStatus != status ) |
|
298 { |
|
299 iPreviousStatus = status; |
|
300 if (iObserver) |
|
301 { |
|
302 iObserver->ActivityChanged(status); |
|
303 } |
|
304 } |
|
305 OstTraceFunctionExit0( CACTIVITYMANAGER_NOTIFYOBSERVER_EXIT ); |
|
306 } |