23 |
23 |
24 //user includes |
24 //user includes |
25 #include "calendarui_debug.h" |
25 #include "calendarui_debug.h" |
26 #include "calennotifier.h" // CalenNotifier |
26 #include "calennotifier.h" // CalenNotifier |
27 #include "calenstatemachine.h" |
27 #include "calenstatemachine.h" |
|
28 #include "OstTraceDefinitions.h" |
|
29 #ifdef OST_TRACE_COMPILER_IN_USE |
|
30 #include "calennotifierTraces.h" |
|
31 #endif |
28 |
32 |
29 const TInt KHashLength = 64; |
33 const TInt KHashLength = 64; |
30 |
34 |
31 // ---------------------------------------------------------------------------- |
35 // ---------------------------------------------------------------------------- |
32 // CalenNotifier::CalenNotifier |
36 // CalenNotifier::CalenNotifier |
35 // ---------------------------------------------------------------------------- |
39 // ---------------------------------------------------------------------------- |
36 // |
40 // |
37 CalenNotifier::CalenNotifier( CCalenStateMachine& aStateMachine ) |
41 CalenNotifier::CalenNotifier( CCalenStateMachine& aStateMachine ) |
38 : iStateMachine( aStateMachine ) |
42 : iStateMachine( aStateMachine ) |
39 { |
43 { |
40 TRACE_ENTRY_POINT; |
44 OstTraceFunctionEntry0( CALENNOTIFIER_CALENNOTIFIER_ENTRY ); |
41 TRACE_EXIT_POINT; |
45 |
|
46 OstTraceFunctionExit0( CALENNOTIFIER_CALENNOTIFIER_EXIT ); |
42 } |
47 } |
43 |
48 |
44 // ---------------------------------------------------------------------------- |
49 // ---------------------------------------------------------------------------- |
45 // CalenNotifier::~CalenNotifier |
50 // CalenNotifier::~CalenNotifier |
46 // Destructor. |
51 // Destructor. |
47 // (other items were commented in a header). |
52 // (other items were commented in a header). |
48 // ---------------------------------------------------------------------------- |
53 // ---------------------------------------------------------------------------- |
49 // |
54 // |
50 CalenNotifier::~CalenNotifier() |
55 CalenNotifier::~CalenNotifier() |
51 { |
56 { |
52 TRACE_ENTRY_POINT; |
57 OstTraceFunctionEntry0( DUP1_CALENNOTIFIER_CALENNOTIFIER_ENTRY ); |
53 |
58 |
54 // Reset the handler array. |
59 // Reset the handler array. |
55 // Before we reset , close hashset for each handler |
60 // Before we reset , close hashset for each handler |
56 for(TInt i = 0 ; i < iHandlers.Count() ; i++) |
61 for(TInt i = 0 ; i < iHandlers.Count() ; i++) |
57 { |
62 { |
58 iHandlers[i].iHashSet.Close(); |
63 iHandlers[i].iHashSet.Close(); |
66 { |
71 { |
67 iEnvChangeNotifier->Cancel(); |
72 iEnvChangeNotifier->Cancel(); |
68 delete iEnvChangeNotifier; |
73 delete iEnvChangeNotifier; |
69 } |
74 } |
70 |
75 |
71 TRACE_EXIT_POINT; |
76 OstTraceFunctionExit0( DUP1_CALENNOTIFIER_CALENNOTIFIER_EXIT ); |
72 } |
77 } |
73 |
78 |
74 // ---------------------------------------------------------------------------- |
79 // ---------------------------------------------------------------------------- |
75 // CalenNotifier::ConstructL |
80 // CalenNotifier::ConstructL |
76 // Symbian 2nd phase of construction. |
81 // Symbian 2nd phase of construction. |
77 // (other items were commented in a header). |
82 // (other items were commented in a header). |
78 // ---------------------------------------------------------------------------- |
83 // ---------------------------------------------------------------------------- |
79 // |
84 // |
80 void CalenNotifier::ConstructL() |
85 void CalenNotifier::ConstructL() |
81 { |
86 { |
82 TRACE_ENTRY_POINT; |
87 OstTraceFunctionEntry0( CALENNOTIFIER_CONSTRUCTL_ENTRY ); |
83 |
88 |
84 // Register for system environment changes |
89 // Register for system environment changes |
85 TCallBack envCallback( EnvChangeCallbackL, this ); |
90 TCallBack envCallback( EnvChangeCallbackL, this ); |
86 iEnvChangeNotifier = |
91 iEnvChangeNotifier = |
87 CEnvironmentChangeNotifier::NewL( EActivePriorityLogonA, envCallback ); |
92 CEnvironmentChangeNotifier::NewL( EActivePriorityLogonA, envCallback ); |
88 iEnvChangeNotifier->Start(); |
93 iEnvChangeNotifier->Start(); |
89 |
94 |
90 iIgnoreFirstLocaleChange = ETrue; |
95 iIgnoreFirstLocaleChange = ETrue; |
91 |
96 |
92 TRACE_EXIT_POINT; |
97 OstTraceFunctionExit0( CALENNOTIFIER_CONSTRUCTL_EXIT ); |
93 } |
98 } |
94 |
99 |
95 // ---------------------------------------------------------------------------- |
100 // ---------------------------------------------------------------------------- |
96 // CalenNotifier::RegisterForNotificationsL |
101 // CalenNotifier::RegisterForNotificationsL |
97 // Adds the passed handler to the handler array. |
102 // Adds the passed handler to the handler array. |
99 // ---------------------------------------------------------------------------- |
104 // ---------------------------------------------------------------------------- |
100 // |
105 // |
101 void CalenNotifier::RegisterForNotificationsL( MCalenNotificationHandler* aHandler, |
106 void CalenNotifier::RegisterForNotificationsL( MCalenNotificationHandler* aHandler, |
102 TCalenNotification aNotification) |
107 TCalenNotification aNotification) |
103 { |
108 { |
104 TRACE_ENTRY_POINT; |
109 OstTraceFunctionEntry0( CALENNOTIFIER_REGISTERFORNOTIFICATIONSL_ENTRY ); |
105 |
110 |
106 TNotificationHandler handler; |
111 TNotificationHandler handler; |
107 handler.iHandler = aHandler; |
112 handler.iHandler = aHandler; |
108 |
113 |
109 //Prepare hash |
114 //Prepare hash |
110 handler.iHashSet.ReserveL(KHashLength); |
115 handler.iHashSet.ReserveL(KHashLength); |
139 // ---------------------------------------------------------------------------- |
144 // ---------------------------------------------------------------------------- |
140 // |
145 // |
141 void CalenNotifier::RegisterForNotificationsL( MCalenNotificationHandler* aHandler, |
146 void CalenNotifier::RegisterForNotificationsL( MCalenNotificationHandler* aHandler, |
142 RArray<TCalenNotification>& aNotifications ) |
147 RArray<TCalenNotification>& aNotifications ) |
143 { |
148 { |
144 TRACE_ENTRY_POINT; |
149 OstTraceFunctionEntry0( DUP1_CALENNOTIFIER_REGISTERFORNOTIFICATIONSL_ENTRY ); |
145 |
150 |
146 TNotificationHandler handler; |
151 TNotificationHandler handler; |
147 handler.iHandler = aHandler; |
152 handler.iHandler = aHandler; |
148 |
153 |
149 //Prepare hash |
154 //Prepare hash |
170 } |
175 } |
171 } |
176 } |
172 |
177 |
173 iHandlers.Append( handler ); |
178 iHandlers.Append( handler ); |
174 |
179 |
175 TRACE_EXIT_POINT; |
180 OstTraceFunctionExit0( DUP1_CALENNOTIFIER_REGISTERFORNOTIFICATIONSL_EXIT ); |
176 } |
181 } |
177 |
182 |
178 // ---------------------------------------------------------------------------- |
183 // ---------------------------------------------------------------------------- |
179 // CalenNotifier::CancelNotifications |
184 // CalenNotifier::CancelNotifications |
180 // Removes the passed handler from the handler array. |
185 // Removes the passed handler from the handler array. |
181 // (other items were commented in a header). |
186 // (other items were commented in a header). |
182 // ---------------------------------------------------------------------------- |
187 // ---------------------------------------------------------------------------- |
183 // |
188 // |
184 void CalenNotifier::CancelNotifications( MCalenNotificationHandler* aHandler ) |
189 void CalenNotifier::CancelNotifications( MCalenNotificationHandler* aHandler ) |
185 { |
190 { |
186 TRACE_ENTRY_POINT; |
191 OstTraceFunctionEntry0( CALENNOTIFIER_CANCELNOTIFICATIONS_ENTRY ); |
187 |
192 |
188 for( TInt x = 0; x < iHandlers.Count(); ++x ) |
193 for( TInt x = 0; x < iHandlers.Count(); ++x ) |
189 { |
194 { |
190 if( iHandlers[x].iHandler == aHandler ) |
195 if( iHandlers[x].iHandler == aHandler ) |
191 { |
196 { |
192 // Mark the notification for deletion by |
197 // Mark the notification for deletion by |
193 // settings the handler to NULL. Actual deletion |
198 // settings the handler to NULL. Actual deletion |
194 // will take place in DoBroadcast |
199 // will take place in DoBroadcast |
195 iHandlers[x].iHashSet.Close(); |
200 iHandlers[x].iHashSet.Close(); |
196 iHandlers[x].iHandler = NULL; |
201 iHandlers[x].iHandler = NULL; |
197 TRACE_EXIT_POINT; |
202 TRACE_EXIT_POINT; |
|
203 OstTraceFunctionExit0( CALENNOTIFIER_CANCELNOTIFICATIONS_EXIT ); |
198 return; |
204 return; |
199 } |
205 } |
200 } |
206 } |
201 |
207 |
202 TRACE_EXIT_POINT; |
208 OstTraceFunctionExit0( DUP1_CALENNOTIFIER_CANCELNOTIFICATIONS_EXIT ); |
203 } |
209 } |
204 |
210 |
205 // ---------------------------------------------------------------------------- |
211 // ---------------------------------------------------------------------------- |
206 // CalenNotifier::ContextChanged |
212 // CalenNotifier::ContextChanged |
207 // From MCalenContextChangeObserver. Called when the context changes. |
213 // From MCalenContextChangeObserver. Called when the context changes. |
208 // (other items were commented in a header). |
214 // (other items were commented in a header). |
209 // ---------------------------------------------------------------------------- |
215 // ---------------------------------------------------------------------------- |
210 // |
216 // |
211 void CalenNotifier::ContextChanged() |
217 void CalenNotifier::ContextChanged() |
212 { |
218 { |
213 TRACE_ENTRY_POINT; |
219 OstTraceFunctionEntry0( CALENNOTIFIER_CONTEXTCHANGED_ENTRY ); |
214 |
220 |
215 BroadcastNotification( ECalenNotifyContextChanged ); |
221 BroadcastNotification( ECalenNotifyContextChanged ); |
216 |
222 |
217 TRACE_EXIT_POINT; |
223 OstTraceFunctionExit0( CALENNOTIFIER_CONTEXTCHANGED_EXIT ); |
218 } |
224 } |
219 |
225 |
220 // ---------------------------------------------------------------------------- |
226 // ---------------------------------------------------------------------------- |
221 // CCalenNotifier::EnvChangeCallbackL |
227 // CCalenNotifier::EnvChangeCallbackL |
222 // CEnvironmentChangeNotifier callback. Calendar is only interested in: |
228 // CEnvironmentChangeNotifier callback. Calendar is only interested in: |
226 // (other items were commented in a header). |
232 // (other items were commented in a header). |
227 // ---------------------------------------------------------------------------- |
233 // ---------------------------------------------------------------------------- |
228 // |
234 // |
229 TInt CalenNotifier::EnvChangeCallbackL( TAny* aThisPtr ) |
235 TInt CalenNotifier::EnvChangeCallbackL( TAny* aThisPtr ) |
230 { |
236 { |
231 TRACE_ENTRY_POINT; |
237 OstTraceFunctionEntry0( CALENNOTIFIER_ENVCHANGECALLBACKL_ENTRY ); |
232 |
238 |
233 TRACE_EXIT_POINT; |
239 OstTraceFunctionExit0( CALENNOTIFIER_ENVCHANGECALLBACKL_EXIT ); |
|
240 |
234 // Return value for functions used as TCallBack objects should be EFalse |
241 // Return value for functions used as TCallBack objects should be EFalse |
235 // unless the function is intended to be called again from a timer. |
242 // unless the function is intended to be called again from a timer. |
236 // return EFalse; |
243 // return EFalse; |
237 return static_cast<CalenNotifier*>(aThisPtr)->DoEnvChange(); |
244 return static_cast<CalenNotifier*>(aThisPtr)->DoEnvChange(); |
238 } |
245 } |
242 // EnvChangeCallbackL calls this function |
249 // EnvChangeCallbackL calls this function |
243 // ---------------------------------------------------------------------------- |
250 // ---------------------------------------------------------------------------- |
244 // |
251 // |
245 TInt CalenNotifier::DoEnvChange() |
252 TInt CalenNotifier::DoEnvChange() |
246 { |
253 { |
247 TRACE_ENTRY_POINT; |
254 OstTraceFunctionEntry0( CALENNOTIFIER_DOENVCHANGE_ENTRY ); |
248 |
255 |
249 if( ((iEnvChangeNotifier->Change() & EChangesMidnightCrossover) |
256 if( ((iEnvChangeNotifier->Change() & EChangesMidnightCrossover) |
250 || (iEnvChangeNotifier->Change() & EChangesSystemTime)) |
257 || (iEnvChangeNotifier->Change() & EChangesSystemTime)) |
251 && !iIgnoreFirstLocaleChange ) |
258 && !iIgnoreFirstLocaleChange ) |
252 { |
259 { |
272 // (other items were commented in a header). |
279 // (other items were commented in a header). |
273 // ---------------------------------------------------------------------------- |
280 // ---------------------------------------------------------------------------- |
274 // |
281 // |
275 void CalenNotifier::BroadcastNotification( TCalenNotification aNotification ) |
282 void CalenNotifier::BroadcastNotification( TCalenNotification aNotification ) |
276 { |
283 { |
277 TRACE_ENTRY_POINT; |
284 OstTraceFunctionEntry0( CALENNOTIFIER_BROADCASTNOTIFICATION_ENTRY ); |
278 |
285 |
279 // Someone has told us to broadcast, or one of our notifiers completed. |
286 // Someone has told us to broadcast, or one of our notifiers completed. |
280 // We run it past the state machine and that may or may not call the |
287 // We run it past the state machine and that may or may not call the |
281 // function to really do the broadcast. |
288 // function to really do the broadcast. |
282 iStateMachine.HandleNotification( aNotification ); |
289 iStateMachine.HandleNotification( aNotification ); |
283 |
290 |
284 TRACE_EXIT_POINT; |
291 OstTraceFunctionExit0( CALENNOTIFIER_BROADCASTNOTIFICATION_EXIT ); |
285 } |
292 } |
286 |
293 |
287 // ---------------------------------------------------------------------------- |
294 // ---------------------------------------------------------------------------- |
288 // CalenNotifier::BroadcastApprovedNotification |
295 // CalenNotifier::BroadcastApprovedNotification |
289 // Issues a notification to all registered handlers |
296 // Issues a notification to all registered handlers |
290 // (other items were commented in a header). |
297 // (other items were commented in a header). |
291 // ---------------------------------------------------------------------------- |
298 // ---------------------------------------------------------------------------- |
292 // |
299 // |
293 void CalenNotifier::BroadcastApprovedNotification( TCalenNotification aNotification ) |
300 void CalenNotifier::BroadcastApprovedNotification( TCalenNotification aNotification ) |
294 { |
301 { |
295 TRACE_ENTRY_POINT; |
302 OstTraceFunctionEntry0( CALENNOTIFIER_BROADCASTAPPROVEDNOTIFICATION_ENTRY ); |
296 |
303 |
297 iBroadcastQueue.Append( aNotification ); |
304 iBroadcastQueue.Append( aNotification ); |
298 |
305 |
299 if( !iBroadcastActive ) |
306 if( !iBroadcastActive ) |
300 { |
307 { |
306 iBroadcastQueue.Remove( 0 ); |
313 iBroadcastQueue.Remove( 0 ); |
307 } |
314 } |
308 iBroadcastActive = EFalse; |
315 iBroadcastActive = EFalse; |
309 } |
316 } |
310 |
317 |
311 TRACE_EXIT_POINT; |
318 OstTraceFunctionExit0( CALENNOTIFIER_BROADCASTAPPROVEDNOTIFICATION_EXIT ); |
312 } |
319 } |
313 |
320 |
314 // ---------------------------------------------------------------------------- |
321 // ---------------------------------------------------------------------------- |
315 // CalenNotifier::DoBroadcast |
322 // CalenNotifier::DoBroadcast |
316 // Issues a notification to all registered handlers |
323 // Issues a notification to all registered handlers |
317 // (other items were commented in a header). |
324 // (other items were commented in a header). |
318 // ---------------------------------------------------------------------------- |
325 // ---------------------------------------------------------------------------- |
319 // |
326 // |
320 void CalenNotifier::DoBroadcast( TCalenNotification aNotification ) |
327 void CalenNotifier::DoBroadcast( TCalenNotification aNotification ) |
321 { |
328 { |
322 TRACE_ENTRY_POINT; |
329 OstTraceFunctionEntry0( CALENNOTIFIER_DOBROADCAST_ENTRY ); |
323 |
330 |
324 for( TInt x = 0; x < iHandlers.Count(); ++x ) |
331 for( TInt x = 0; x < iHandlers.Count(); ++x ) |
325 { |
332 { |
326 TNotificationHandler handler = iHandlers[x]; |
333 TNotificationHandler handler = iHandlers[x]; |
327 if( handler.iHandler ) |
334 if( handler.iHandler ) |
328 { |
335 { |
337 iHandlers.Remove( x ); // remove the entry |
344 iHandlers.Remove( x ); // remove the entry |
338 --x; // decrement the index. |
345 --x; // decrement the index. |
339 } |
346 } |
340 } |
347 } |
341 |
348 |
342 TRACE_EXIT_POINT; |
349 OstTraceFunctionExit0( CALENNOTIFIER_DOBROADCAST_EXIT ); |
343 } |
350 } |
344 |
351 |
345 // ---------------------------------------------------------------------------- |
352 // ---------------------------------------------------------------------------- |
346 // CalenNotifier::TNotificationHandler() |
353 // CalenNotifier::TNotificationHandler() |
347 // TNotificationHandler contructor |
354 // TNotificationHandler contructor |
348 // ---------------------------------------------------------------------------- |
355 // ---------------------------------------------------------------------------- |
349 CalenNotifier::TNotificationHandler::TNotificationHandler() : |
356 CalenNotifier::TNotificationHandler::TNotificationHandler() : |
350 iHashSet(&::HashCalenNotificationFunction,&::HashCalenNotificationIdentityRelation) |
357 iHashSet(&::HashCalenNotificationFunction,&::HashCalenNotificationIdentityRelation) |
351 { |
358 { |
352 TRACE_ENTRY_POINT; |
359 OstTraceFunctionEntry0( TNOTIFICATIONHANDLER_TNOTIFICATIONHANDLER_ENTRY ); |
353 TRACE_EXIT_POINT; |
360 |
|
361 OstTraceFunctionExit0( TNOTIFICATIONHANDLER_TNOTIFICATIONHANDLER_EXIT ); |
354 } |
362 } |
355 |
363 |
356 // End of file |
364 // End of file |