|
1 // Copyright (c) 1999-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 // |
|
15 |
|
16 #ifndef __ASSRVSOUNDCONTROLLER_H__ |
|
17 #define __ASSRVSOUNDCONTROLLER_H__ |
|
18 |
|
19 // System includes |
|
20 #include <e32base.h> |
|
21 #include <babitflags.h> |
|
22 |
|
23 // User includes |
|
24 #include <asshddefs.h> |
|
25 #include "ASSrvAlarmObserver.h" |
|
26 #include "ASSrvAlarmQueueObserver.h" |
|
27 #include "ASSrvSoundSettingsObserver.h" |
|
28 #include "ASSrvSoundControllerObserver.h" |
|
29 #include "ASSrvEnvironmentChangeObserver.h" |
|
30 |
|
31 // Classes referenced |
|
32 class TASSrvAlarm; |
|
33 class CASSrvServerWideData; |
|
34 class MASSrvSoundControllerObserver; |
|
35 |
|
36 |
|
37 // |
|
38 // ----> CASSrvSoundController (header) |
|
39 // |
|
40 /** |
|
41 * The sound controller performs all the timing related functionality associated |
|
42 * with the sound play intervals (these essentially are "auto-snoozed" alarm sounds, |
|
43 * whereby after a given length of time, the alarm sound is silenced for a small |
|
44 * amount of time). For example, the sound plays for 30 seconds, then is silent |
|
45 * for 30, then it plays again for 30 seconds, and then is slient for 1 minute, etc. |
|
46 * |
|
47 * The sound controller notifies an observer which actually implements the sound |
|
48 * playing functionality (in fact, the observer is just a proxy for the Alarm |
|
49 * Alert Server, where the sound is really played). |
|
50 */ |
|
51 class CASSrvSoundController : public CTimer, |
|
52 public MASSrvAlarmObserver, |
|
53 public MASSrvSoundSettingsObserver, |
|
54 public MASSrvAlarmQueueObserver, |
|
55 public MASSrvEnvironmentChangeObserver |
|
56 { |
|
57 // |
|
58 public: // STATIC CONSTRUCT / DESTRUCT |
|
59 // |
|
60 static CASSrvSoundController* NewL(CASSrvServerWideData& aServerWideData, MASSrvSoundControllerObserver& aObserver); |
|
61 ~CASSrvSoundController(); |
|
62 |
|
63 // |
|
64 private: // INTERNAL CONSTRUCT |
|
65 // |
|
66 CASSrvSoundController(CASSrvServerWideData& aServerWideData, MASSrvSoundControllerObserver& aObserver); |
|
67 void ConstructL(); |
|
68 |
|
69 // |
|
70 private: // FROM MASSrvAlarmObserver |
|
71 // |
|
72 |
|
73 /** |
|
74 * @see MASSrvAlarmObserver |
|
75 * |
|
76 * When an alarm expires, we should start timing the alarm sound intervals. Note that |
|
77 * no sound is played directly by the alarm server - it's all handled by proxy in the |
|
78 * EikSrv thread (Alarm Alert Server). |
|
79 * |
|
80 * We only ever receive one notification that an alarm has expired (unless its snoozed |
|
81 * and then the snooze expires). Therefore, the sound controller has to perform cycle |
|
82 * management for the alerting (notifying) head alarm in the queue). |
|
83 */ |
|
84 void MASSrvAlarmObsHandleEvent(TObserverEvent aEvent, const TASSrvAlarm& aAlarm, TInt aEventSpecificData); |
|
85 |
|
86 // |
|
87 private: // FROM MASSrvSoundSettingsObserver |
|
88 // |
|
89 |
|
90 /** |
|
91 * @see MASSrvSoundSettingsObserver |
|
92 */ |
|
93 void MASSoundSettingsHandleChangeEvent(TSoundSettingsEvent aEvent); |
|
94 |
|
95 // |
|
96 private: // FROM MASSrvAlarmQueueObserver |
|
97 // |
|
98 |
|
99 /** |
|
100 * @see MASSrvAlarmQueueObserver |
|
101 */ |
|
102 void MAlarmQueueObserverHandleEvent(TASSrvAlarmQueueEvent aEvent, TAlarmId aAlarmId); |
|
103 |
|
104 // |
|
105 private: // FROM MASSrvEnvironmentChangeObserver |
|
106 // |
|
107 |
|
108 /** |
|
109 * @see MASSrvEnvironmentChangeObserver |
|
110 * |
|
111 * Since PREQ234 all alarm silent periods are stored in UTC time but specified in |
|
112 * local time hence the need to track changes to system time. |
|
113 */ |
|
114 |
|
115 void MEnvChangeHandleEvent(TInt aChanges, TUint aWorkdays, TBool aWorkdaysChanged); |
|
116 |
|
117 // |
|
118 public: // ACCESS |
|
119 // |
|
120 |
|
121 /** |
|
122 * Stops any sound from playing and resets the sound timer to an idle state. |
|
123 */ |
|
124 void CancelAllSounds(); |
|
125 |
|
126 /** |
|
127 * Stop playing any sounds until the specified time updating with UTC offset changes. |
|
128 */ |
|
129 void MakeAllSoundsQuietUntil(const TTime& aTime); |
|
130 |
|
131 /** |
|
132 * Returns the |
|
133 */ |
|
134 inline const TTime& SoundsQuietUntil() const { return iTimeToReturnToNormalSoundTimingBehaviour; } |
|
135 |
|
136 /** |
|
137 * Stop playing the sound (for just this alarm) until the specified time. |
|
138 */ |
|
139 void CurrentAlarmSoundPausedUntil(const TTime& aTime); |
|
140 |
|
141 /** |
|
142 * Returns a boolean indicating whether or not the alarm server is currently |
|
143 * in a quiet period. |
|
144 */ |
|
145 TBool InQuietPeriod() const; |
|
146 |
|
147 /** |
|
148 * Return a boolean indicating whether sound is currently |
|
149 * paused within the alarm server. |
|
150 */ |
|
151 TBool SoundIsPausedForAlarm() const; |
|
152 |
|
153 /** |
|
154 * Cancel a previously enabled silent period |
|
155 */ |
|
156 void CancelSilence(); |
|
157 |
|
158 /** |
|
159 * Do not update silent period with UTC offset changes. |
|
160 */ |
|
161 inline void SetFixed() { Flags().Set(ESoundControllerFlagsIsFixed); } |
|
162 |
|
163 /** |
|
164 * Update silent period with UTC offset changes. |
|
165 */ |
|
166 inline void SetFloating() { Flags().Clear(ESoundControllerFlagsIsFixed); } |
|
167 |
|
168 void CancelSound(TAlarmId aAlarmId); |
|
169 |
|
170 // |
|
171 private: // FROM CActive |
|
172 // |
|
173 |
|
174 /** |
|
175 * @see CActive |
|
176 */ |
|
177 void RunL(); |
|
178 |
|
179 /** |
|
180 * Replacement of CActive::Cancel function |
|
181 */ |
|
182 void Cancel(); |
|
183 |
|
184 // |
|
185 private: // INTERNAL |
|
186 // |
|
187 |
|
188 /** |
|
189 * Access the server wide data |
|
190 */ |
|
191 inline CASSrvServerWideData& ServerData() const { return iServerWideData; } |
|
192 |
|
193 /** |
|
194 * Writable access to this class' interal flags |
|
195 */ |
|
196 inline TBitFlags& Flags() { return iSoundControllerFlags; } |
|
197 |
|
198 /** |
|
199 * Access to this class' interal flags |
|
200 */ |
|
201 inline const TBitFlags& Flags() const { return iSoundControllerFlags; } |
|
202 |
|
203 /** |
|
204 * Writable access to the id of the currently notifying alarm |
|
205 */ |
|
206 inline TAlarmId& IdOfNotifyingAlarm() { return iIdOfNotifyingAlarm; } |
|
207 |
|
208 /** |
|
209 * The id of the currently notifying alarm |
|
210 */ |
|
211 inline TAlarmId IdOfNotifyingAlarm() const { return iIdOfNotifyingAlarm; } |
|
212 |
|
213 /** |
|
214 * Handle a timer event - called when the sound timer expires |
|
215 */ |
|
216 void ReactToSoundTimerExpiry(); |
|
217 |
|
218 /** |
|
219 * Notify observers about the specified event |
|
220 */ |
|
221 void NotifySoundEvent(MASSrvSoundControllerObserver::TSoundControllerEvent aEvent, TAlarmId aAlarmId); |
|
222 |
|
223 /** |
|
224 * Manage sound timing |
|
225 */ |
|
226 void StartSoundTimingForAnyWaitingAlarmAfterPausingOrQuietPeriod(); |
|
227 |
|
228 /** |
|
229 * Calculate when the next start/stop timer period should be for |
|
230 * alarm sounds |
|
231 */ |
|
232 void WorkOutAndScheduleForNextSoundCycle(); |
|
233 |
|
234 /** |
|
235 * Indicates that the Sound Controller is disabled (ie. no sounds |
|
236 * intervals configured in the rsc file) |
|
237 */ |
|
238 TBool IsSoundControllerDisabled() const; |
|
239 |
|
240 |
|
241 void PlayPreviousNotifyingAlarm(); |
|
242 |
|
243 // |
|
244 private: // INTERNAL ENUMERATIONS |
|
245 // |
|
246 /** |
|
247 * Internal sound flags |
|
248 */ |
|
249 enum TSoundControllerFlags |
|
250 { |
|
251 /** |
|
252 * Pausing |
|
253 */ |
|
254 ESoundControllerFlagsPausing = 0, |
|
255 |
|
256 /** |
|
257 * Quiet period |
|
258 */ |
|
259 ESoundControllerFlagsInQuietPeriod = 1, |
|
260 |
|
261 /** |
|
262 * Until (floating) or For (fixed) silent period |
|
263 */ |
|
264 |
|
265 ESoundControllerFlagsIsFixed = 2, |
|
266 }; |
|
267 |
|
268 // |
|
269 private: // MEMBER DATA |
|
270 // |
|
271 |
|
272 /** |
|
273 * The alarm id of the alarm which is currently being timed. KNullAlarmID if |
|
274 * no current alarm to notify. |
|
275 */ |
|
276 TAlarmId iIdOfNotifyingAlarm; |
|
277 |
|
278 /** |
|
279 * Record the previous sound event we sent to the SoundControlllerObserver |
|
280 * (and AlertServer) so that we can suppress duplicate events. |
|
281 */ |
|
282 MASSrvSoundControllerObserver::TSoundControllerEvent iPreviousSoundEvent; |
|
283 |
|
284 /** |
|
285 * The time when normal sound behaviour should be resumed. |
|
286 */ |
|
287 TTime iTimeToReturnToNormalSoundTimingBehaviour; |
|
288 |
|
289 /** |
|
290 * Internal flags |
|
291 */ |
|
292 TBitFlags iSoundControllerFlags; |
|
293 |
|
294 /** |
|
295 * The server wide data handle |
|
296 */ |
|
297 CASSrvServerWideData& iServerWideData; |
|
298 |
|
299 /** |
|
300 * The observer of this class, in this case, the notification |
|
301 * co-ordinator |
|
302 */ |
|
303 MASSrvSoundControllerObserver& iObserver; |
|
304 |
|
305 /** |
|
306 * UTC offset when the last request involving time was made |
|
307 */ |
|
308 |
|
309 TTimeIntervalSeconds iPreviousUTCOffset; |
|
310 }; |
|
311 |
|
312 #endif |