|
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: The header contains class declaration for alarm queue class used |
|
14 // for holding all the alarms in the alarm server. |
|
15 // |
|
16 |
|
17 #ifndef __ASSRVALARMQUEUE_H__ |
|
18 #define __ASSRVALARMQUEUE_H__ |
|
19 |
|
20 // User Includes |
|
21 #include "ASSrvDefs.h" |
|
22 #include "ASSrvAlarm.h" |
|
23 #include "ASSrvStaticUtils.h" |
|
24 #include "ASSrvTimerObserver.h" |
|
25 #include "ASSrvAlarmObserver.h" |
|
26 #include "ASSrvAlarmQueueObserver.h" |
|
27 #include "ASSrvEnvironmentChangeObserver.h" |
|
28 |
|
29 #ifdef SYMBIAN_SYSTEM_STATE_MANAGEMENT |
|
30 #include <ssm/ssmadaptationcli.h> |
|
31 #endif |
|
32 |
|
33 #ifdef SYMBIAN_ENABLE_SPLIT_HEADERS |
|
34 #include <ASShdAlarmCal.h> |
|
35 #endif |
|
36 |
|
37 // Classes Referenced |
|
38 class MASSrvAlarmObserver; |
|
39 class CASSrvServerWideData; |
|
40 class CASSrvDSTChange; |
|
41 |
|
42 |
|
43 /** |
|
44 * The overall container class for all alarms maintained within the Alarm Server. |
|
45 */ |
|
46 class CASSrvAlarmQueue : public CBase, public MASSrvEnvironmentChangeObserver |
|
47 { |
|
48 public: |
|
49 static CASSrvAlarmQueue* NewL(CASSrvServerWideData& aServerWideData); |
|
50 ~CASSrvAlarmQueue(); |
|
51 |
|
52 private: |
|
53 CASSrvAlarmQueue(CASSrvServerWideData& aServerWideData); |
|
54 void ConstructL(); |
|
55 |
|
56 private: |
|
57 // from MASSrvEnvironmentChangeObserver |
|
58 void MEnvChangeHandleEvent(TInt aChanges, TUint aWorkdays, TBool aWorkdaysChanged); |
|
59 |
|
60 public: |
|
61 // from MASSrvAlarmInfoProvider |
|
62 TInt ASSrvAlarmInfoCount() const; |
|
63 void ASSrvAlarmInfoAt(TInt aIndex, TASSrvAlarm& aAlarm) const; |
|
64 |
|
65 public: |
|
66 // Notification Management |
|
67 void NotificationPoolChangeL(MASSrvAlarmQueueObserver& aObserver); |
|
68 void NotificationPoolChangeCancel(MASSrvAlarmQueueObserver& aObserver); |
|
69 |
|
70 public: |
|
71 // Access - Alarm Observation |
|
72 void RequestAlarmObservationEventsL(MASSrvAlarmObserver& aObserver); |
|
73 void RequestAlarmObservationEventsCancel(MASSrvAlarmObserver& aObserver); |
|
74 void RequestAlarmObservationEventsEnabled(MASSrvAlarmObserver& aObserver, TBool aEnabled); |
|
75 |
|
76 public: |
|
77 // Queue Access |
|
78 TInt QueueAlarmCount() const; |
|
79 TASSrvAlarm& QueueAlarmAt(TInt aIndex); |
|
80 const TASSrvAlarm& QueueAlarmAt(TInt aIndex) const; |
|
81 TInt QueueAlarmById(TAlarmId aId, TASSrvAlarm& aAlarm) const; |
|
82 TASSrvAlarm* QueueAlarmById(TAlarmId aId); |
|
83 const TASSrvAlarm* QueueAlarmById(TAlarmId aId) const; |
|
84 TASSrvAlarm& QueueAlarmByIdL(TAlarmId aId); |
|
85 const TASSrvAlarm& QueueAlarmByIdL(TAlarmId aId) const; |
|
86 |
|
87 public: |
|
88 // Access |
|
89 void QueueAlarmAndAllocateIdL(TASSrvAlarm& aAlarm, TAlarmId aSpecificAlarmId = KNullAlarmId); |
|
90 void DeQueueAlarm(const TASSrvAlarm& aAlarm); |
|
91 const TASSrvAlarm* HeadAlarm() const; |
|
92 |
|
93 #ifdef SYMBIAN_SKIPPED_CALENDAR_ALARMS |
|
94 TAlarmId HeadCalendarAlarmId() const; |
|
95 #endif |
|
96 |
|
97 #ifdef SYMBIAN_SYSTEM_STATE_MANAGEMENT |
|
98 TAlarmId HeadWakeupAlarmId() const; |
|
99 #endif |
|
100 |
|
101 TAlarmId HeadAlarmId() const; |
|
102 void RemoveAllSessionAlarmsBySessionId(TASSrvSessionId aSessionId); |
|
103 TAlarmId NextFreeAlarmId(); |
|
104 TBool HaveAdditionalAlarmsToNotify(); |
|
105 TInt NumberOfAlarmsPendingNotification(); |
|
106 TASSrvAlarm& NextAlarmWaitingForNotification(); |
|
107 |
|
108 public: |
|
109 // Store Framework |
|
110 void InternalizeL(RReadStream& aStream); |
|
111 void ExternalizeL(RWriteStream& aStream) const; |
|
112 |
|
113 #ifdef SYMBIAN_SKIPPED_CALENDAR_ALARMS |
|
114 void InternalizeLastAlarmedInstanceParamsL(RReadStream& aStream); |
|
115 void ExternalizeLastAlarmedInstanceParamsL(RWriteStream& aStream) const; |
|
116 #endif |
|
117 |
|
118 public: |
|
119 // Support for store framework |
|
120 |
|
121 /** |
|
122 * The next/current Alarm Store operation |
|
123 */ |
|
124 enum TStoreOperation |
|
125 { |
|
126 /** |
|
127 * No-op state |
|
128 */ |
|
129 EStoreIdle = 0, |
|
130 |
|
131 /** |
|
132 * Attempt to Internalize after system start |
|
133 */ |
|
134 EStoreInternalizeStartup, |
|
135 |
|
136 /** |
|
137 * Attempt to Internalize after a backup restore |
|
138 */ |
|
139 EStoreInternalizeRestore, |
|
140 |
|
141 /** |
|
142 * Externalize (e.g. Alarms have changed, Alarm Sound Settings have changed |
|
143 * or Alarm Server shutdown) |
|
144 */ |
|
145 EStoreExternalize, |
|
146 |
|
147 /** |
|
148 * Backup - Read access to AlarmServer.ini file requested for backup |
|
149 * (by backup/synchronisation app.) |
|
150 */ |
|
151 EStoreBackup, |
|
152 |
|
153 /** |
|
154 * Restore - Exclusive Write access to AlarmServer.ini file requested for Restore |
|
155 * (by backup/synchronisation app.) |
|
156 */ |
|
157 EStoreRestore |
|
158 }; |
|
159 |
|
160 TInt StartAlarmStoreOperation(TStoreOperation aStoreOperation); |
|
161 void EndAlarmStoreOperation(TInt aError); |
|
162 |
|
163 /** |
|
164 * Check that Alarm and Alarm Data is writable. |
|
165 */ |
|
166 void CheckAlarmQueueWritableL(); |
|
167 |
|
168 public: |
|
169 // Event Handlers - called by TASSrvAlarm |
|
170 void HandleAlarmStatusChanged(TAlarmId aAlarmThatChangedStatus, TAlarmStatus aOldStatus); |
|
171 void HandleAlarmStateChanged(TAlarmId aAlarmThatChangedState, TAlarmState aOldState); |
|
172 void HandleAlarmCharacteristicsChanged(TAlarmId aAlarmThatChangedCharacteristics, TAlarmCharacteristicsFlags aOldCharacteristics); |
|
173 |
|
174 #ifdef SYMBIAN_SYSTEM_STATE_MANAGEMENT |
|
175 void HandleWakeupChanged(TAlarmId aAlarmThatChangedWakeup); |
|
176 #endif |
|
177 |
|
178 #ifdef SYMBIAN_ALARM_REPEAT_EXTENSIONS |
|
179 void HandleAlarmDaysChanged(TAlarmId aAlarmThatChangedDays); |
|
180 #endif |
|
181 |
|
182 void HandleAlarmDataChanged(TAlarmId aAlarmThatChangedData); |
|
183 |
|
184 #ifdef SYMBIAN_SYSTEM_STATE_MANAGEMENT |
|
185 public: |
|
186 |
|
187 void HandleNextDSTChangeEventL(); |
|
188 void UpdateRTC(); |
|
189 #endif |
|
190 |
|
191 |
|
192 private: |
|
193 // Internal |
|
194 inline CASSrvServerWideData& ServerData() const { return iServerWideData; } |
|
195 TBool AlarmIdIsInUse(TAlarmId aAlarmId) const; |
|
196 void RemoveDeadAlarms(); |
|
197 void NotifyAlarmObserverEvent(MASSrvAlarmObserver::TObserverEvent aEvent, const TASSrvAlarm& aAlarm, TInt aEventSpecificData); |
|
198 void NotifyEvent(MASSrvAlarmQueueObserver::TASSrvAlarmQueueEvent aEvent, TAlarmId aAlarmId); |
|
199 void ReplaceQueueWithInternalizedQueue(); |
|
200 void ApplyInternalizedData(TBool aUseNewData); |
|
201 void UpdateFloatingDueTimes(); |
|
202 void PublishSkippedAlarm(TBool aSkippedCalAlarm); |
|
203 |
|
204 #ifdef SYMBIAN_SKIPPED_CALENDAR_ALARMS |
|
205 void PublishAlarmedInstanceParams(const TTime& aFirstSkippedAlarmLocalTime, TBool aSystemTimeChange); |
|
206 void PublishAlarmedInstanceParams(const TASShdAlarmedInstanceParams& aAlarmedInstanceParams); |
|
207 #endif |
|
208 |
|
209 private: |
|
210 // Internal Classes |
|
211 /** |
|
212 * A mapping between alarm observers and enabled states. Allows an observer |
|
213 * to temporarily disable notification events without being removed from |
|
214 * the observer array. This prevents OOM problems since observers don't |
|
215 * have to run the risk of a leave (due to no memory) when re-requesting |
|
216 * observations. |
|
217 */ |
|
218 class TASSrvAlarmObserverMapplet |
|
219 { |
|
220 public: |
|
221 inline TASSrvAlarmObserverMapplet(MASSrvAlarmObserver& aObserver) : iEnabled(ETrue), iObserver(&aObserver) { } |
|
222 /** |
|
223 * Access the observer. |
|
224 */ |
|
225 |
|
226 inline MASSrvAlarmObserver& Observer() { return *iObserver; } |
|
227 /** |
|
228 * Does this observer want to receive notification events? |
|
229 */ |
|
230 |
|
231 inline TBool IsEnabled() const { return iEnabled; } |
|
232 /** |
|
233 * Change the enabled status of the observer. |
|
234 */ |
|
235 |
|
236 inline void SetEnabled(TBool aEnabled) { iEnabled = aEnabled; } |
|
237 |
|
238 private: |
|
239 /** |
|
240 * Wehther or not the observer wants to receive notifications. |
|
241 */ |
|
242 TBool iEnabled; |
|
243 |
|
244 /** |
|
245 * The observer itself. |
|
246 */ |
|
247 MASSrvAlarmObserver* iObserver; |
|
248 }; |
|
249 |
|
250 private: |
|
251 /** |
|
252 * The server wide data. |
|
253 */ |
|
254 CASSrvServerWideData& iServerWideData; |
|
255 /** |
|
256 * The next free alarm Id. |
|
257 */ |
|
258 TAlarmId iNextFreeAlarmId; |
|
259 /** |
|
260 * The array of alarm observers. |
|
261 */ |
|
262 RArray<TASSrvAlarmObserverMapplet> iAlarmObservers; |
|
263 /** |
|
264 * The list of all alarms within the server. |
|
265 */ |
|
266 RPointerArray<TASSrvAlarm> iAlarms; |
|
267 /** |
|
268 * A list of observes who are interested in queue change notifications. |
|
269 */ |
|
270 RPointerArray<MASSrvAlarmQueueObserver> iNotificationList; |
|
271 |
|
272 /** |
|
273 * Type of Alarm Store operation being performed |
|
274 */ |
|
275 TStoreOperation iStoreOperation; |
|
276 |
|
277 /** |
|
278 * Internalize buffers for data. used/discarded by ApplyInternalizedData() method |
|
279 */ |
|
280 TAlarmId iInternalizeNextFreeAlarmId; |
|
281 RPointerArray<TASSrvAlarm> iInternalizeAlarmQueue; |
|
282 |
|
283 /** |
|
284 * The previous UTC offset for checking whether it has changed while the Alarm |
|
285 * Server was down. |
|
286 */ |
|
287 TTimeIntervalSeconds iPreviousUtcOffset; |
|
288 |
|
289 /** |
|
290 * Details about the next DST change. |
|
291 */ |
|
292 CASSrvDSTChange* iASSrvDSTChange; |
|
293 |
|
294 #ifdef SYMBIAN_SYSTEM_STATE_MANAGEMENT |
|
295 /** |
|
296 * Handle to the real-time-clock so that we can set wakeup alarms. |
|
297 */ |
|
298 RSsmRtcAdaptation iSsmRtcAdaptation; |
|
299 #endif |
|
300 |
|
301 #ifdef SYMBIAN_SKIPPED_CALENDAR_ALARMS |
|
302 /** |
|
303 * Stores the last published value of the skipped alarm data. |
|
304 */ |
|
305 TASShdAlarmedInstanceParams iLastAlarmedInstanceParams; |
|
306 #endif |
|
307 }; |
|
308 |
|
309 |
|
310 #endif |