1 /* |
|
2 * Copyright (c) 2008 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: server implementation for Events Handler Server |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include "evthandlerclientserver.h" |
|
20 #include "evthandlerserversession.h" |
|
21 #include "evthandlerserverconsts.h" |
|
22 #include "evtnotifierhandler.h" |
|
23 #include "evtmgmtuiengine.h" |
|
24 #include "evtevent.h" |
|
25 #include "evtdebug.h" |
|
26 |
|
27 #include "evthandlerserver.h" |
|
28 |
|
29 #include <AknGlobalNote.h> // CAknGlobalNote |
|
30 #include <w32std.h> |
|
31 #include <apgtask.h> |
|
32 #include <apgcli.h> |
|
33 #include <apacmdln.h> |
|
34 #include <bacline.h> |
|
35 |
|
36 static const TInt KHandlerAppUid = 0x2001E668; |
|
37 _LIT(KHandlerEXE, "evthandler.exe"); |
|
38 _LIT( KDelimiter, ":"); |
|
39 |
|
40 // --------------------------------------------------------------------------- |
|
41 // CEvtHandlerServer::CEvtHandlerServer() |
|
42 // --------------------------------------------------------------------------- |
|
43 // |
|
44 inline CEvtHandlerServer::CEvtHandlerServer() |
|
45 :CServer2( 0, ESharableSessions ), |
|
46 iEventsQueue( KEvtItemArrayGranularity ) |
|
47 {} |
|
48 |
|
49 // --------------------------------------------------------------------------- |
|
50 // CEvtHandlerServer::~CEvtHandlerServer() |
|
51 // --------------------------------------------------------------------------- |
|
52 // |
|
53 CEvtHandlerServer::~CEvtHandlerServer() |
|
54 { |
|
55 EVTUIDEBUG( "+ CEvtHandlerServer::~CEvtHandlerServer()" ); |
|
56 if( iEvtSnoozeHandler ) |
|
57 { |
|
58 delete iEvtSnoozeHandler; |
|
59 } |
|
60 |
|
61 if( iEvtNotifierHandler ) |
|
62 { |
|
63 delete iEvtNotifierHandler; |
|
64 } |
|
65 |
|
66 iEventsQueue.Close(); |
|
67 |
|
68 EVTUIDEBUG( "- CEvtHandlerServer::~CEvtHandlerServer()" ); |
|
69 } |
|
70 |
|
71 // --------------------------------------------------------------------------- |
|
72 // CEvtHandlerServer::NewLC() |
|
73 // --------------------------------------------------------------------------- |
|
74 // |
|
75 CServer2* CEvtHandlerServer::NewLC() |
|
76 { |
|
77 EVTUIDEBUG( "+ CEvtHandlerServer::NewLC()" ); |
|
78 CEvtHandlerServer* self = new ( ELeave ) CEvtHandlerServer; |
|
79 CleanupStack::PushL( self ); |
|
80 self->ConstructL(); |
|
81 EVTUIDEBUG( "- CEvtHandlerServer::NewLC()" ); |
|
82 return self; |
|
83 } |
|
84 |
|
85 // --------------------------------------------------------------------------- |
|
86 // CEvtHandlerServer::ConstructL() |
|
87 // --------------------------------------------------------------------------- |
|
88 // |
|
89 void CEvtHandlerServer::ConstructL() |
|
90 /* |
|
91 * 2nd phase construction - ensure the timer and server objects are running |
|
92 */ |
|
93 { |
|
94 EVTUIDEBUG( "+ CEvtHandlerServer::ConstructL()" ); |
|
95 StartL( KEvtHandlerServerName ); |
|
96 iShutdownTimer.ConstructL(); |
|
97 iEvtSnoozeHandler = CEvtSnoozeHandler::NewL( *this ); |
|
98 EVTUIDEBUG( "- CEvtHandlerServer::ConstructL()" ); |
|
99 } |
|
100 |
|
101 // --------------------------------------------------------------------------- |
|
102 // CEvtHandlerServer::NewSessionL() |
|
103 // --------------------------------------------------------------------------- |
|
104 // |
|
105 CSession2* CEvtHandlerServer::NewSessionL( const TVersion&, const RMessage2& ) const |
|
106 /* |
|
107 * Cretae a new client session. This should really check the version number. |
|
108 */ |
|
109 { |
|
110 EVTUIDEBUG( "+ CEvtHandlerServer::NewSessionL()" ); |
|
111 return new ( ELeave ) CEvtHandlerServerSession(); |
|
112 } |
|
113 |
|
114 // --------------------------------------------------------------------------- |
|
115 // CEvtHandlerServer::HandleNewEventL() |
|
116 // --------------------------------------------------------------------------- |
|
117 // |
|
118 void CEvtHandlerServer::HandleNewEventL( const TEvtEventId aEventId, const TInt aAccuracy ) |
|
119 { |
|
120 EVTUIDEBUG2("+ CEvtHandlerServer::HandleNewEventL() - EventId = %d, Accuracy = %d", aEventId, aAccuracy); |
|
121 iShutdownTimer.Cancel(); |
|
122 |
|
123 // Stop any running request |
|
124 delete iEvtNotifierHandler; |
|
125 iEvtNotifierHandler = NULL; |
|
126 |
|
127 // Remove if it was present in Snooze Que |
|
128 TTime time; |
|
129 time.HomeTime(); |
|
130 TEvtSnoozeItem snoozeItem( aEventId, static_cast<TEvtFireAccuracy>(aAccuracy), time ); |
|
131 iEvtSnoozeHandler->RemoveIfPresent( snoozeItem ); |
|
132 |
|
133 // Create an Event Info structure |
|
134 TEvtEventInfo evtInfo( aEventId, static_cast<TEvtFireAccuracy>(aAccuracy), ETrue, ETrue ); |
|
135 |
|
136 TIdentityRelation<TEvtEventInfo> matcher(TEvtEventInfo::Match); |
|
137 TInt index = iEventsQueue.Find(evtInfo,matcher); |
|
138 |
|
139 // Remove if it was present in Notifier Que |
|
140 if( index != KErrNotFound ) |
|
141 { |
|
142 iEventsQueue.Remove( index ); |
|
143 } |
|
144 |
|
145 // Append this element to the front of queue |
|
146 iEventsQueue.Insert( evtInfo, 0 ); |
|
147 |
|
148 // Restart the request handling process |
|
149 HandleNextEventL(); |
|
150 EVTUIDEBUG("- CEvtHandlerServer::HandleNewEventL()"); |
|
151 } |
|
152 |
|
153 // --------------------------------------------------------------------------- |
|
154 // CEvtHandlerServer::HandleNextEventL() |
|
155 // --------------------------------------------------------------------------- |
|
156 // |
|
157 void CEvtHandlerServer::HandleNextEventL() |
|
158 { |
|
159 EVTUIDEBUG( "+ CEvtHandlerServer::HandleNextEventL()") |
|
160 TInt evtCount = iEventsQueue.Count(); |
|
161 if( evtCount ) |
|
162 { |
|
163 EVTUIDEBUG1( "EventId = %d", iEventsQueue[ 0 ].iEventId ); |
|
164 iEvtNotifierHandler = CEvtNotifierHandler::NewL( *this, iEventsQueue[ 0 ] ); |
|
165 |
|
166 // Check if the Event is Launchable - Is it present and Active |
|
167 if( iEvtNotifierHandler->IsLaunchable() ) |
|
168 { |
|
169 iEvtNotifierHandler->StartEvtNotifierL(); |
|
170 |
|
171 // Set the tone play to False So that it does not play tone next time. |
|
172 if( iEventsQueue[ 0 ].iPlayTone ) |
|
173 iEventsQueue[ 0 ].iPlayTone = EFalse; |
|
174 } |
|
175 else |
|
176 { |
|
177 delete iEvtNotifierHandler; |
|
178 iEvtNotifierHandler = NULL; |
|
179 |
|
180 iEventsQueue.Remove( 0 ); |
|
181 evtCount = iEventsQueue.Count(); |
|
182 } |
|
183 } |
|
184 |
|
185 if( !evtCount ) |
|
186 { |
|
187 if( iEvtSnoozeHandler->IsSnoozeQueEmpty() ) |
|
188 { |
|
189 EVTUIDEBUG( "Handler Server shutdown") |
|
190 iShutdownTimer.Start(); |
|
191 } |
|
192 } |
|
193 EVTUIDEBUG( "- CEvtHandlerServer::HandleNextEventL()" ); |
|
194 } |
|
195 |
|
196 // --------------------------------------------------------------------------- |
|
197 // CEvtHandlerServer::SnoozeCompleteL() |
|
198 // |
|
199 // Derived from MEvtSnoozeObserver |
|
200 // --------------------------------------------------------------------------- |
|
201 // |
|
202 void CEvtHandlerServer::SnoozeCompleteL( |
|
203 TEvtSnoozeItem& aSnoozeItem, |
|
204 TBool aSnoozeAgain ) |
|
205 { |
|
206 EVTUIDEBUG2("+ CEvtHandlerServer::SnoozeCompleteL() - EventId = %d, Snooze = %d", |
|
207 aSnoozeItem.iEventId, aSnoozeAgain); |
|
208 |
|
209 // Stop any running request |
|
210 delete iEvtNotifierHandler; |
|
211 iEvtNotifierHandler = NULL; |
|
212 |
|
213 // Create an Event Info structure |
|
214 TEvtEventInfo evtInfo( aSnoozeItem.iEventId, aSnoozeItem.iAccuracy, ETrue, aSnoozeAgain ); |
|
215 |
|
216 // Append this element to the front of queue |
|
217 iEventsQueue.Insert( evtInfo, 0 ); |
|
218 |
|
219 // Restart the request handling process |
|
220 HandleNextEventL(); |
|
221 EVTUIDEBUG("- CEvtHandlerServer::SnoozeCompleteL()"); |
|
222 } |
|
223 |
|
224 // --------------------------------------------------------------------------- |
|
225 // CEvtHandlerServer::HandlerCompleteL() |
|
226 // |
|
227 // Derived from MEvtNotifierObserver |
|
228 // --------------------------------------------------------------------------- |
|
229 // |
|
230 void CEvtHandlerServer::HandlerCompleteL( |
|
231 TEvtInfoNoteResult aResult, |
|
232 CEvtEvent* aEvent ) |
|
233 { |
|
234 EVTUIDEBUG2( "+ CEvtHandlerServer::HandlerCompleteL() - EventId = %d, Notifier Action = %d", iEventsQueue[ 0 ].iEventId, aResult ); |
|
235 |
|
236 TEvtEventId evtId = aEvent->EventId(); |
|
237 TBool repeat = aEvent->Repeat(); |
|
238 |
|
239 // Delete the previous running instance of the server |
|
240 delete iEvtNotifierHandler; |
|
241 iEvtNotifierHandler = NULL; |
|
242 |
|
243 switch( aResult ) |
|
244 { |
|
245 case EOpenTrigger: |
|
246 case EShowDetails: |
|
247 { |
|
248 EVTUIDEBUG( "Open Event" ); |
|
249 |
|
250 TBuf8< KEvtCommandMessageLength > buffer; |
|
251 buffer.AppendNum( evtId ); |
|
252 buffer.Append( KDelimiter ); |
|
253 buffer.AppendNum( aResult ); |
|
254 buffer.Append( KDelimiter ); |
|
255 |
|
256 // Create a session to Windows server to check the running of |
|
257 // handler ui |
|
258 RWsSession ws; |
|
259 User::LeaveIfError( ws.Connect() ); |
|
260 CleanupClosePushL( ws ); // pushing to cleanupstack |
|
261 |
|
262 // Check if Handler Application is already running. Incase its |
|
263 // send the command message to the application |
|
264 TApaTaskList taskList( ws ); |
|
265 TApaTask task = taskList.FindApp( TUid::Uid( KHandlerAppUid ) ); |
|
266 if ( task.Exists() ) |
|
267 { |
|
268 // Bring the task to the foreground and send a message to it. |
|
269 task.BringToForeground(); |
|
270 User::LeaveIfError( task.SendMessage( TUid::Uid( KUidApaMessageSwitchOpenFileValue ), buffer )); |
|
271 } |
|
272 else |
|
273 { |
|
274 |
|
275 // Start and instance of the new application |
|
276 LaunchAppL( TUid::Uid( KHandlerAppUid), buffer ); |
|
277 } |
|
278 CleanupStack::PopAndDestroy(); // ws |
|
279 |
|
280 // Remove if it was present in Snooze Que |
|
281 TTime time; |
|
282 time.HomeTime(); |
|
283 TEvtSnoozeItem snoozeItem( iEventsQueue[0].iEventId, iEventsQueue[0].iAccuracy, time ); |
|
284 iEvtSnoozeHandler->RemoveIfPresent( snoozeItem ); |
|
285 break; |
|
286 } |
|
287 case ESnoozeTrigger: |
|
288 { |
|
289 EVTUIDEBUG( "Snooze Event" ); |
|
290 TTime time; |
|
291 time.HomeTime(); |
|
292 TEvtSnoozeItem snoozeItem( iEventsQueue[0].iEventId, iEventsQueue[0].iAccuracy, time ); |
|
293 iEvtSnoozeHandler->Snooze( snoozeItem ); |
|
294 break; |
|
295 } |
|
296 case ECloseInfoNote: |
|
297 { |
|
298 EVTUIDEBUG( "Closing Note" ); |
|
299 |
|
300 // Update State if needed. |
|
301 if( !repeat ) |
|
302 ChangeStateL( evtId ); |
|
303 |
|
304 // Remove if it was present in Snooze Que |
|
305 TTime time; |
|
306 time.HomeTime(); |
|
307 TEvtSnoozeItem snoozeItem( iEventsQueue[0].iEventId, iEventsQueue[0].iAccuracy, time ); |
|
308 iEvtSnoozeHandler->RemoveIfPresent( snoozeItem ); |
|
309 break; |
|
310 } |
|
311 default: |
|
312 { |
|
313 // Remove if it was present in Snooze Que |
|
314 TTime time; |
|
315 time.HomeTime(); |
|
316 TEvtSnoozeItem snoozeItem( iEventsQueue[0].iEventId, iEventsQueue[0].iAccuracy, time ); |
|
317 iEvtSnoozeHandler->RemoveIfPresent( snoozeItem ); |
|
318 break; |
|
319 } |
|
320 } |
|
321 |
|
322 // The note has been handled. Remove the note from the queue |
|
323 iEventsQueue.Remove( 0 ); |
|
324 |
|
325 HandleNextEventL(); |
|
326 EVTUIDEBUG( "- CEvtHandlerServer::HandlerCompleteL()" ); |
|
327 } |
|
328 |
|
329 // --------------------------------------------------------------------------- |
|
330 // CEvtHandlerServer::ChangeStateL() |
|
331 // --------------------------------------------------------------------------- |
|
332 // |
|
333 void CEvtHandlerServer::ChangeStateL( TEvtEventId aEvtId ) |
|
334 { |
|
335 EVTUIDEBUG1( "Change State of %d", aEvtId ); |
|
336 TBuf16< KEvtCommandMessageLength > buffer; |
|
337 buffer.AppendNum( EEvtActionChangeState ); |
|
338 buffer.Append( KDelimiter ); |
|
339 buffer.AppendNum( aEvtId ); |
|
340 |
|
341 RProcess proc; |
|
342 TInt retVal = proc.Create( KHandlerEXE(), buffer); |
|
343 if(retVal == KErrNone) |
|
344 { |
|
345 proc.Resume(); |
|
346 } |
|
347 proc.Close(); |
|
348 } |
|
349 |
|
350 // --------------------------------------------------------------------------- |
|
351 // CEvtHandlerServer::LaunchAppL() |
|
352 // --------------------------------------------------------------------------- |
|
353 // |
|
354 void CEvtHandlerServer::LaunchAppL( |
|
355 TUid aApplicationUid, |
|
356 const TDesC8& aCmdLineArg ) |
|
357 { |
|
358 DEBUG("+ CEvtHandlerServer::LaunchAppL"); |
|
359 |
|
360 // Create the Session handle and connect to the Application architecture |
|
361 // server. This is required to obtain the details of the application from |
|
362 // the Application UID. |
|
363 RApaLsSession lsSession; |
|
364 User::LeaveIfError( lsSession.Connect() ); |
|
365 CleanupClosePushL( lsSession ); |
|
366 |
|
367 DEBUG("+ CEvtHandlerServer::LaunchAppL - Get the Application Information"); |
|
368 // Get the Application Information. |
|
369 TApaAppInfo appInfo; |
|
370 TInt error = lsSession.GetAppInfo( appInfo, aApplicationUid ); |
|
371 if ( error ) |
|
372 { |
|
373 EVTUIDEBUG1("Get the Application Information Error : %d", error ); |
|
374 User::Leave( error ); |
|
375 } |
|
376 |
|
377 DEBUG("+ CEvtHandlerServer::LaunchAppL - Fill the command line argument structure"); |
|
378 // Fill the command line argument structure |
|
379 CApaCommandLine* cmdLine = CApaCommandLine::NewLC(); |
|
380 |
|
381 DEBUG("+ CEvtHandlerServer::LaunchAppL - Set the Application name"); |
|
382 // Set the Application name. |
|
383 TFileName appName = appInfo.iFullName; |
|
384 cmdLine->SetExecutableNameL( appName ); |
|
385 |
|
386 DEBUG("+ CEvtHandlerServer::LaunchAppL - Set the Command"); |
|
387 // Set the Command |
|
388 cmdLine->SetCommandL( EApaCommandRun ); |
|
389 |
|
390 DEBUG("+ CEvtHandlerServer::LaunchAppL - Set the Command line arguments"); |
|
391 // Set the Command line arguments. |
|
392 if ( aCmdLineArg.Length()) |
|
393 { |
|
394 // These arguments would be sent as Tail end arguments to the launched |
|
395 // Application. Its left to the application to handle those |
|
396 HBufC8* tailEnd = HBufC8::NewLC( aCmdLineArg.Length()); |
|
397 tailEnd->Des().Copy( aCmdLineArg ); |
|
398 |
|
399 // The Tail end buffer is copied to the Command line structure. Hence, |
|
400 // can delete this variable after the set operation succeeds. |
|
401 cmdLine->SetTailEndL( tailEnd->Des()); |
|
402 |
|
403 CleanupStack::PopAndDestroy( tailEnd ); |
|
404 } |
|
405 |
|
406 DEBUG("+ CEvtHandlerServer::LaunchAppL - Start the Application"); |
|
407 // Start the Application |
|
408 User::LeaveIfError( lsSession.StartApp( *cmdLine )); |
|
409 |
|
410 // Clean up all the allocated heap variables. |
|
411 CleanupStack::PopAndDestroy( cmdLine ); |
|
412 CleanupStack::PopAndDestroy(); //lsSession |
|
413 |
|
414 DEBUG("- CEvtHandlerServer::LaunchAppL"); |
|
415 } |
|
416 // End of File |
|