|
1 // Copyright (c) 1997-2009 Nokia Corporation and/or its subsidiary(-ies). |
|
2 // All rights reserved. |
|
3 // This component and the accompanying materials are made available |
|
4 // under the terms of "Eclipse Public License v1.0" |
|
5 // which accompanies this distribution, and is available |
|
6 // at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
7 // |
|
8 // Initial Contributors: |
|
9 // Nokia Corporation - initial contribution. |
|
10 // |
|
11 // Contributors: |
|
12 // |
|
13 // Description: |
|
14 // MultiAlrm version of supervisor |
|
15 // |
|
16 // |
|
17 |
|
18 /** |
|
19 @file |
|
20 */ |
|
21 |
|
22 // System includes |
|
23 #include <eikenv.h> |
|
24 #include <eiksrv.h> |
|
25 #include <asshdalarm.h> |
|
26 |
|
27 // User includes |
|
28 #include "EIKSRV.PAN" |
|
29 #include "EIKALSUP.H" |
|
30 #include <uikon/eiknotifyalert.h> |
|
31 |
|
32 // Constants |
|
33 const TInt KAlarmMinuteInMicroSeconds = 60000000; |
|
34 |
|
35 // See eiksrv.cpp for initialization of |
|
36 // EXPORT_C extern const TInt KEikAlarmDefaultSnoozeInMinutes |
|
37 |
|
38 CEikAlmControlSupervisor* CEikAlmControlSupervisor::NewLC(MEikServAlarmFactory& aAlarmControl, CEikServAlarmAlertSession* aSession) |
|
39 { |
|
40 CEikAlmControlSupervisor* supervisor = new (ELeave) CEikAlmControlSupervisor(); |
|
41 CleanupStack::PushL(supervisor); |
|
42 supervisor->ConstructL(aAlarmControl, aSession); |
|
43 return supervisor; |
|
44 } |
|
45 |
|
46 void CEikAlmControlSupervisor::ConstructL(MEikServAlarmFactory& aAlarmControlFactory, CEikServAlarmAlertSession* aSession) |
|
47 { |
|
48 iMinuteCountDown = CPeriodic::NewL(ESnoozeCountDownPriority); |
|
49 iAlarmAlert = aAlarmControlFactory.NewAlarmL(*this); |
|
50 iSession = aSession; |
|
51 } |
|
52 |
|
53 CEikAlmControlSupervisor::CEikAlmControlSupervisor() |
|
54 { |
|
55 } |
|
56 |
|
57 CEikAlmControlSupervisor::~CEikAlmControlSupervisor() |
|
58 { |
|
59 delete iMinuteCountDown; |
|
60 delete iAlarmData; |
|
61 |
|
62 if (iAlarmAlert) |
|
63 iAlarmAlert->Release(); |
|
64 } |
|
65 |
|
66 /** |
|
67 Services requests to the server |
|
68 @param aMessage Message from client. |
|
69 @internalTechnology |
|
70 */ |
|
71 void CEikAlmControlSupervisor::ServiceL(const RMessage2 &aMessage) |
|
72 { |
|
73 __ASSERT_DEBUG(iAlarmAlert, Panic(EEsPanicAlarmAlert)); |
|
74 __ASSERT_DEBUG(!aMessage.IsNull(), Panic(EEsPanicAlarmAlert)); |
|
75 |
|
76 switch (aMessage.Function()) |
|
77 { |
|
78 case EASAltOpCodeVisible: |
|
79 case EASAltOpCodeVisibleAll: |
|
80 SetVisibility(aMessage.Int0()); |
|
81 break; |
|
82 case EASAltOpCodeSetState: |
|
83 case EASAltOpCodeSetStateAll: |
|
84 iAlarmAlert->UpdateForAlarmServerState(aMessage.Int0()); |
|
85 break; |
|
86 case EASAltOpCodeSetAlarm: |
|
87 UpdateAlarmInfoL(aMessage); |
|
88 break; |
|
89 case EASAltOpCodeStartPlayingSound: |
|
90 StartPlayAlarmL(aMessage); |
|
91 break; |
|
92 case EASAltOpCodeStopPlayingSound: |
|
93 case EASAltOpCodeStopPlayingSoundAll: |
|
94 StopPlayAlarm(); |
|
95 break; |
|
96 default: |
|
97 break; |
|
98 } |
|
99 } |
|
100 |
|
101 /** |
|
102 @internalTechnology |
|
103 */ |
|
104 void CEikAlmControlSupervisor::CancelTimeCountDown() |
|
105 { |
|
106 iMinuteCountDown->Cancel(); |
|
107 } |
|
108 |
|
109 void CEikAlmControlSupervisor::SetVisibility(TBool aVisible) |
|
110 { |
|
111 iVisible = aVisible; |
|
112 |
|
113 if (aVisible) |
|
114 iAlarmAlert->ShowAlarm(); |
|
115 else |
|
116 iAlarmAlert->HideAlarm(); |
|
117 } |
|
118 |
|
119 /** |
|
120 Static callback function. Decrements snooze minutes |
|
121 @param aAlarmControl Pointer to this. Gets cast to CEikAlarmControlSupervisor* |
|
122 @internalComponent |
|
123 */ |
|
124 TInt CEikAlmControlSupervisor::CallbackSnoozeDecrement(TAny *aAlarmControl) |
|
125 { |
|
126 __ASSERT_ALWAYS(aAlarmControl, Panic(EEsPanicAlarmAlert)); |
|
127 static_cast<CEikAlmControlSupervisor*>(aAlarmControl)->DecrementSnoozeMinutes(); |
|
128 return KErrNone; |
|
129 } |
|
130 |
|
131 /** |
|
132 @internalComponent |
|
133 */ |
|
134 void CEikAlmControlSupervisor::DecrementSnoozeMinutes() |
|
135 { |
|
136 iPauseSoundMinutes--; |
|
137 iAlarmAlert->UpdateSoundPauseTimeInterval(iPauseSoundMinutes); |
|
138 if (iPauseSoundMinutes <= 0) |
|
139 CancelTimeCountDown(); |
|
140 } |
|
141 |
|
142 /** |
|
143 @internalComponent |
|
144 */ |
|
145 void CEikAlmControlSupervisor::StartTimeCountDown() |
|
146 { |
|
147 TCallBack callback(&CallbackSnoozeDecrement, this); |
|
148 CancelTimeCountDown(); |
|
149 iMinuteCountDown->Start(KAlarmMinuteInMicroSeconds, KAlarmMinuteInMicroSeconds, callback); |
|
150 iAlarmAlert->UpdateSoundPauseTimeInterval(iPauseSoundMinutes); |
|
151 } |
|
152 |
|
153 /** |
|
154 @internalTechnology |
|
155 */ |
|
156 void CEikAlmControlSupervisor::SynchronizeCountDownTimer() |
|
157 { |
|
158 CancelTimeCountDown(); |
|
159 |
|
160 TTime now; |
|
161 now.UniversalTime(); |
|
162 if (iPauseSoundDueTime > now) |
|
163 { |
|
164 // sychronise timer (needed when machine has been turned off during snooze) |
|
165 TTimeIntervalSeconds seconds; |
|
166 iPauseSoundDueTime.SecondsFrom(now, seconds); |
|
167 iPauseSoundMinutes = (seconds.Int()/60)+1; // +1 because will be called back in less than a minute |
|
168 |
|
169 const TInt delay = ((seconds.Int())%60)*1000000; // pity there's no TTime::MicroSeconds32From :-( |
|
170 const TCallBack callback(&CallbackSnoozeDecrement, this); |
|
171 iMinuteCountDown->Start(delay, KAlarmMinuteInMicroSeconds, callback); |
|
172 } |
|
173 else |
|
174 iPauseSoundMinutes = 0; |
|
175 |
|
176 TASAltClientServerStateFlags alarmState(iAlarmAlert->CurrentServerState()); |
|
177 |
|
178 if (!((alarmState[EASAltStateFlagsInQuietPeriod] || |
|
179 alarmState[EASAltStateFlagsSilentRunning] || |
|
180 alarmState[EASAltStateFlagsAlarmHasNoSoundFileName]) && |
|
181 (iPauseSoundMinutes==0))) |
|
182 { |
|
183 iAlarmAlert->UpdateSoundPauseTimeInterval(iPauseSoundMinutes); |
|
184 } |
|
185 } |
|
186 |
|
187 |
|
188 /** |
|
189 Update the alerts information on the current alarm. Extracts owner and establishes whether alarm time is local |
|
190 @param aMessage Message from client. EASAltOpCodeSetAlarm |
|
191 @internalComponent |
|
192 */ |
|
193 void CEikAlmControlSupervisor::UpdateAlarmInfoL(const RMessage2& aMessage) |
|
194 { |
|
195 const TInt KDataSlot = 2; |
|
196 iPauseSoundMinutes = 0; |
|
197 iMinuteCountDown->Cancel(); |
|
198 iPauseSoundDueTime.UniversalTime(); |
|
199 |
|
200 TASShdAlarm alarm; |
|
201 TPckg<TASShdAlarm> pAlarm(alarm); |
|
202 aMessage.ReadL(0, pAlarm); |
|
203 iAlarmId = alarm.Id(); |
|
204 |
|
205 TFullName owner; |
|
206 aMessage.ReadL(1, owner); |
|
207 |
|
208 // Create new alarm data (use temporary newAlarmData and reassign iAlarmData on success) |
|
209 HBufC8* newAlarmData = NULL; |
|
210 if(alarm.HasAssociatedData()) |
|
211 { |
|
212 const TInt desLength = aMessage.GetDesLengthL(KDataSlot); |
|
213 newAlarmData = HBufC8::NewLC(desLength); // Push in case ReadL() below leaves |
|
214 TPtr8 readPtr(newAlarmData->Des()); |
|
215 aMessage.ReadL(KDataSlot, readPtr); |
|
216 } |
|
217 else |
|
218 { |
|
219 newAlarmData = HBufC8::NewLC(0); |
|
220 } |
|
221 |
|
222 delete iAlarmData; |
|
223 iAlarmData = newAlarmData; |
|
224 CleanupStack::Pop(newAlarmData); |
|
225 newAlarmData = NULL; |
|
226 |
|
227 // These lines will make sure the alert server is given the alarm in local time, if the alarm is |
|
228 // set in local time (a floating alarm) |
|
229 //------------------------------------------- |
|
230 if (alarm.IsFloating()) |
|
231 { |
|
232 TTimeIntervalSeconds offset = User::UTCOffset(); |
|
233 if (alarm.NextDueTime() != Time::NullTTime()) |
|
234 alarm.NextDueTime() += offset; |
|
235 |
|
236 if (alarm.OriginalExpiryTime() != Time::NullTTime()) |
|
237 alarm.OriginalExpiryTime() += offset; |
|
238 } |
|
239 |
|
240 iAlarmAlert->UpdateAlarmInfo(alarm, owner); |
|
241 iAlarmAlert->UpdateForAlarmServerState(iAlarmAlert->CurrentServerState()); |
|
242 } |
|
243 |
|
244 /** |
|
245 This method will trigger a new alarm in aMinutesToSnooze minutes and start the |
|
246 alarm timer. |
|
247 |
|
248 @internalTechnology */ |
|
249 TTime CEikAlmControlSupervisor::ReturnTimeToSnooze(TInt aMinutesToSnooze) |
|
250 { |
|
251 if (iPauseSoundMinutes <= 0) |
|
252 iPauseSoundMinutes = aMinutesToSnooze; |
|
253 |
|
254 iPauseSoundDueTime.UniversalTime(); |
|
255 iPauseSoundDueTime += TTimeIntervalMinutes(iPauseSoundMinutes); |
|
256 |
|
257 const TTime time = iPauseSoundDueTime; |
|
258 StartTimeCountDown(); |
|
259 return time; |
|
260 } |
|
261 |
|
262 |
|
263 |
|
264 void CEikAlmControlSupervisor::StartPlayAlarmL(const RMessage2& aMessage) |
|
265 { |
|
266 TBuf<KMaxAlarmSoundNameLength> alarmSoundName; |
|
267 aMessage.ReadL(0, alarmSoundName); |
|
268 iAlarmAlert->StartPlayAlarmL(alarmSoundName); |
|
269 } |
|
270 |
|
271 |
|
272 void CEikAlmControlSupervisor::StopPlayAlarm() |
|
273 { |
|
274 iAlarmAlert->StopPlayAlarm(); |
|
275 } |
|
276 |
|
277 |
|
278 /** |
|
279 Acknowledges a notifying alarm |
|
280 (i.e. an alarm that is going off or has expired). |
|
281 |
|
282 When an alarm has expired, the alarm control is notified and can call |
|
283 this function to acknowledge the alarm. |
|
284 */ |
|
285 EXPORT_C void CEikAlmControlSupervisor::CmdAcknowledgeAlarm() |
|
286 { |
|
287 if (iSession) |
|
288 { |
|
289 TRAP_IGNORE(iSession->RespondEventL(EASAltAlertServerResponseClear, AlarmId())); |
|
290 } |
|
291 } |
|
292 |
|
293 /** |
|
294 Acknowledges all notifying alarms |
|
295 (i.e. all alarms that are going off or have expired). |
|
296 |
|
297 When an alarm has expired, the alarm control is notified and can call |
|
298 this function to acknowledge all alarms that are currently notifying. |
|
299 */ |
|
300 EXPORT_C void CEikAlmControlSupervisor::CmdAcknowledgeAllAlarms() |
|
301 { |
|
302 if (iSession) |
|
303 { |
|
304 TRAP_IGNORE(iSession->ClearAllAlarmsL()); |
|
305 } |
|
306 } |
|
307 |
|
308 |
|
309 |
|
310 /** |
|
311 Increases the alarm's snooze period by the specified number of minutes. |
|
312 |
|
313 If the alarm has expired, it is snoozed by aNumMinutes. |
|
314 MEikServAlarm::UpdateSoundPauseTimeInterval() is called, which might, for instance, |
|
315 update the view to display the new snooze period. |
|
316 |
|
317 @param aNumMinutes The number of minutes to add to the snooze period. |
|
318 */ |
|
319 EXPORT_C void CEikAlmControlSupervisor::CmdPauseAlarmSoundL(TInt aNumMinutes) |
|
320 { |
|
321 // If the argument is KUseDefaultAlarmSnoozeIncrement (minus one) then change it to KAlarmDefaultSnoozeInMinutes. |
|
322 // The use of KUseDefaultAlarmSnoozeIncrement as default argument (rather than KAlarmDefaultSnoozeInMinutes) |
|
323 // is needed to allow KAlarmDefaultSnoozeInMinutes being ROM patchable constant. |
|
324 if(aNumMinutes == KEikUseDefaultAlarmSnoozeIncrement) |
|
325 aNumMinutes = KEikAlarmDefaultSnoozeInMinutes; |
|
326 |
|
327 if(iPauseSoundMinutes + aNumMinutes <= 0) |
|
328 return; |
|
329 |
|
330 iPauseSoundMinutes += aNumMinutes; |
|
331 |
|
332 // Update the client's TTime so that they don't need to |
|
333 // call "ReturnTimeToSnoozeL" (synchronous) in response to |
|
334 // an asynch completion here... |
|
335 const TTime time = ReturnTimeToSnooze(KEikAlarmDefaultSnoozeInMinutes); |
|
336 if (iSession) |
|
337 iSession->RespondEventL(EASAltAlertServerResponsePauseSound, AlarmId(), time); |
|
338 } |
|
339 |
|
340 /** |
|
341 Silences the alarm sound that is playing, without changing the alarm's state. |
|
342 */ |
|
343 EXPORT_C void CEikAlmControlSupervisor::CmdSilenceAlarmSound() |
|
344 { |
|
345 if (iSession) |
|
346 { |
|
347 TRAP_IGNORE(iSession->RespondEventL(EASAltAlertServerResponseSilence, AlarmId())); |
|
348 } |
|
349 } |
|
350 |
|
351 |
|
352 /** |
|
353 If an alarm has expired, this function snoozes it for the default |
|
354 period (e.g. 5 minutes). |
|
355 |
|
356 This function shall be called in response to the user switching away from the |
|
357 application when an alarm has expired. |
|
358 |
|
359 @return Always ETrue. |
|
360 */ |
|
361 EXPORT_C TBool CEikAlmControlSupervisor::CmdTaskAwayFromAlarmL() |
|
362 { |
|
363 return CmdTaskAwayFromAlarmL(KEikAlarmDefaultSnoozeInMinutes); |
|
364 } |
|
365 |
|
366 /** |
|
367 If an alarm has expired, this function snoozes it for specified snooze period. |
|
368 |
|
369 This function shall be called in response to the user switching away from the |
|
370 application when an alarm has expired. |
|
371 |
|
372 @param aMinutesToSnooze Minutes to be added to the snooze period. |
|
373 @return Always ETrue. |
|
374 */ |
|
375 EXPORT_C TBool CEikAlmControlSupervisor::CmdTaskAwayFromAlarmL(TInt aMinutesToSnooze) |
|
376 { |
|
377 // Update the client's TTime so that they don't need to |
|
378 // call "ReturnTimeToSnoozeL" (synchronous) in response to |
|
379 // an asynch completion here... |
|
380 aMinutesToSnooze = Max(1, aMinutesToSnooze); //minimum snooze time is one minute, to avoid live lock between alarm server & eik server |
|
381 const TTime time = ReturnTimeToSnooze(aMinutesToSnooze); |
|
382 if (iSession) |
|
383 { |
|
384 iSession->RespondEventL(EASAltAlertServerResponseSnooze, AlarmId(), time); |
|
385 } |
|
386 return ETrue; |
|
387 } |
|
388 |
|
389 |
|
390 TBool CEikAlmControlSupervisor::IsVisible() const |
|
391 { |
|
392 return iVisible; |
|
393 } |
|
394 |
|
395 |
|
396 TAlarmId CEikAlmControlSupervisor::AlarmId() const |
|
397 { |
|
398 return iAlarmId; |
|
399 } |
|
400 |
|
401 /** |
|
402 Gets data associated with alarm. |
|
403 |
|
404 @param aData Application specific 8-bit data that was queued with the Alarm. |
|
405 @return KErrNotFound if no data is associated with current alarm, KErrNone otherwise. |
|
406 */ |
|
407 EXPORT_C TDesC8& CEikAlmControlSupervisor::AlarmData() const |
|
408 { |
|
409 return *iAlarmData; |
|
410 } |
|
411 |
|
412 |
|
413 EXPORT_C void CEikAlmControlSupervisor::CEikAlmControlSupervisor_Reserved1() |
|
414 { |
|
415 } |
|
416 |
|
417 |
|
418 EXPORT_C void CEikAlmControlSupervisor::CEikAlmControlSupervisor_Reserved2() |
|
419 { |
|
420 } |
|
421 |