|
1 /* |
|
2 * Copyright (c) 2002-2009 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: The Sat Server session manages a connection to a client and |
|
15 * handles client requests. |
|
16 * |
|
17 */ |
|
18 |
|
19 |
|
20 #include <fbs.h> |
|
21 #include "MSatUtils.h" |
|
22 #include "CSatIconHandler.h" |
|
23 #include "CSatSSession.h" |
|
24 #include "CSatSUiSubSession.h" |
|
25 #include "CSatSServer.h" |
|
26 #include "EnginePanic.h" |
|
27 #include "SatLog.h" |
|
28 #include "TSatEventMediator.h" |
|
29 #include "SatSOpcodes.h" |
|
30 #include "MSatApi.h" |
|
31 #include "MSatUtils.h" |
|
32 #include "CSatSRefreshSubSession.h" |
|
33 #include "MThreadDeathNotifier.h" |
|
34 #include "CSatSIconSubSession.h" |
|
35 |
|
36 const TUint8 KHandleParam( 3 ); |
|
37 |
|
38 // ======== MEMBER FUNCTIONS ======== |
|
39 |
|
40 // ----------------------------------------------------------------------------- |
|
41 // Class constructor |
|
42 // ----------------------------------------------------------------------------- |
|
43 // |
|
44 CSatSSession::CSatSSession( |
|
45 CSatSServer* aServer, |
|
46 TSatEventMediator& aEventMediator, |
|
47 MSatApi& aSatApi, |
|
48 MThreadDeathNotifier& aThreadDeathNotifier ) : |
|
49 CSession2(), |
|
50 iSatServer( aServer ), |
|
51 iEventMediator( aEventMediator ), |
|
52 iSatApi( aSatApi ), |
|
53 iThreadDeathNotifier( aThreadDeathNotifier ) |
|
54 { |
|
55 LOG( SIMPLE, "SATENGINE: CSatSSession::CSatSSession calling-exiting" ) |
|
56 } |
|
57 |
|
58 // ----------------------------------------------------------------------------- |
|
59 // Two-phased constructor |
|
60 // ----------------------------------------------------------------------------- |
|
61 // |
|
62 CSatSSession* CSatSSession::NewL( |
|
63 CSatSServer* aServer, |
|
64 TSatEventMediator& aEventMediator, |
|
65 MSatApi& aSatApi, |
|
66 MThreadDeathNotifier& aThreadDeathNotifier ) |
|
67 { |
|
68 LOG( SIMPLE, "SATENGINE: CSatSSession::NewL calling" ) |
|
69 |
|
70 // Perform construction. |
|
71 CSatSSession* self = |
|
72 new ( ELeave ) CSatSSession( |
|
73 aServer, |
|
74 aEventMediator, |
|
75 aSatApi, |
|
76 aThreadDeathNotifier ); |
|
77 |
|
78 CleanupStack::PushL( self ); |
|
79 self->ConstructL(); |
|
80 CleanupStack::Pop( self ); |
|
81 |
|
82 LOG( SIMPLE, "SATENGINE: CSatSSession::NewL exiting" ) |
|
83 return self; |
|
84 } |
|
85 |
|
86 // ----------------------------------------------------------------------------- |
|
87 // Destructor |
|
88 // ----------------------------------------------------------------------------- |
|
89 // |
|
90 CSatSSession::~CSatSSession() |
|
91 { |
|
92 LOG( SIMPLE, "SATENGINE: CSatSSession::~CSatSSession calling" ) |
|
93 |
|
94 delete iSubSessionIx; |
|
95 delete iSubSessionCon; |
|
96 |
|
97 iSatServer = NULL; |
|
98 iUiSubSession = NULL; |
|
99 |
|
100 LOG( SIMPLE, "SATENGINE: CSatSSession::~CSatSSession exiting" ) |
|
101 } |
|
102 |
|
103 // ----------------------------------------------------------------------------- |
|
104 // CSatSSession::ConstructL |
|
105 // ----------------------------------------------------------------------------- |
|
106 // |
|
107 void CSatSSession::ConstructL() |
|
108 { |
|
109 LOG( SIMPLE, "SATENGINE: CSatSSession::ConstructL calling" ) |
|
110 |
|
111 iSubSessionCon = iSatServer->CreateNewContainerL(); |
|
112 iSubSessionIx = CObjectIx::NewL(); |
|
113 |
|
114 LOG( SIMPLE, "SATENGINE: CSatSSession::ConstructL exiting" ) |
|
115 } |
|
116 |
|
117 // ----------------------------------------------------------------------------- |
|
118 // CSatSSession::UiSubSession |
|
119 // ----------------------------------------------------------------------------- |
|
120 // |
|
121 MSatUiSession* CSatSSession::UiSubSession() |
|
122 { |
|
123 LOG( DETAILED, "SATENGINE: CSatSSession::UiSubSession calling" ) |
|
124 |
|
125 MSatUiSession* session = iUiSubSession; |
|
126 |
|
127 LOG( DETAILED, "SATENGINE: CSatSSession::UiSubSession exiting" ) |
|
128 return session; |
|
129 } |
|
130 |
|
131 // ----------------------------------------------------------------------------- |
|
132 // CSatSSession::CloseSubSession |
|
133 // ----------------------------------------------------------------------------- |
|
134 TBool CSatSSession::CloseSubSession( const RMessage2& aMessage ) |
|
135 { |
|
136 LOG( SIMPLE, "SATENGINE: CSatSSession::CloseSubSession calling" ) |
|
137 |
|
138 // If subssession exists, return TRUE. Otherwise, return FALSE |
|
139 TInt result = ETrue; |
|
140 // Read the handle from client. |
|
141 const TInt handle( aMessage.Int3() ); |
|
142 |
|
143 // Check that subsession exists before deleting the subsession |
|
144 if ( iSubSessionIx->At( handle ) ) |
|
145 { |
|
146 LOG( |
|
147 SIMPLE, "SATENGINE: CSatSSession::CloseSubSession subsession exists" ) |
|
148 // Delete the sub-session. |
|
149 iSubSessionIx->Remove( handle ); |
|
150 } |
|
151 else |
|
152 { |
|
153 LOG( SIMPLE, |
|
154 "SATENGINE: CSatSSession::CloseSubSession subsession doesn't exist" ) |
|
155 // Sub-session handle was not valid. |
|
156 PanicClient( aMessage, ESatSBadDescriptor ); |
|
157 result = EFalse; |
|
158 } |
|
159 |
|
160 LOG( SIMPLE, "SATENGINE: CSatSSession::CloseSubSession exiting" ) |
|
161 return result; |
|
162 } |
|
163 |
|
164 // ----------------------------------------------------------------------------- |
|
165 // CSatSSession::GetSubSessionFromHandle |
|
166 // Returns the subsession which handle is aHandle. |
|
167 // ----------------------------------------------------------------------------- |
|
168 CSatSSubSession* CSatSSession::GetSubSessionFromHandle( TInt aHandle ) const |
|
169 { |
|
170 LOG( DETAILED, "SATENGINE: CSatSSession::GetSubSessionFromHandle calling" ) |
|
171 |
|
172 CSatSSubSession* session = |
|
173 static_cast<CSatSSubSession*>( iSubSessionIx->At( aHandle ) ); |
|
174 |
|
175 LOG( DETAILED, "SATENGINE: CSatSSession::GetSubSessionFromHandle exiting" ) |
|
176 return session; |
|
177 } |
|
178 |
|
179 // ----------------------------------------------------------------------------- |
|
180 // CSatSSession::AddSubSessionL |
|
181 // ----------------------------------------------------------------------------- |
|
182 void CSatSSession::AddSubSessionL( |
|
183 CSatSSubSession* aSubSession, |
|
184 const RMessage2& aMessage ) |
|
185 { |
|
186 LOG( SIMPLE, "SATENGINE: CSatSSession::AddSubSessionL calling" ) |
|
187 |
|
188 __ASSERT_ALWAYS( aSubSession, PanicSatEngine( ESatEngineNullPointer ) ); |
|
189 |
|
190 CleanupStack::PushL( aSubSession ); |
|
191 iSubSessionCon->AddL( aSubSession ); |
|
192 const TInt handle( iSubSessionIx->AddL( aSubSession ) ); |
|
193 CleanupStack::Pop( aSubSession ); |
|
194 |
|
195 // Send the handle to client. |
|
196 TPckg<TInt> handlePckg( handle ); |
|
197 TRAPD( err, aMessage.WriteL( KHandleParam, handlePckg ) ); |
|
198 |
|
199 if ( KErrNone != err ) |
|
200 { |
|
201 // Remove the handle, will also cause destruction |
|
202 // of session. |
|
203 iSubSessionIx->Remove( handle ); |
|
204 LOG2( SIMPLE, |
|
205 "SATENGINE: CSatSSession::AddSubSessionL panic: %i", err ) |
|
206 PanicClient( aMessage, ESatSBadDescriptor ); |
|
207 User::Leave( err ); |
|
208 } |
|
209 |
|
210 LOG( SIMPLE, "SATENGINE: CSatSSession::AddSubSessionL exiting" ) |
|
211 } |
|
212 |
|
213 // ----------------------------------------------------------------------------- |
|
214 // CSatSSession::ServiceL |
|
215 // Dispatches the commands to their appropriate handlers. For asynchronous |
|
216 // messages, the message object is save for future processing. |
|
217 // ----------------------------------------------------------------------------- |
|
218 // |
|
219 void CSatSSession::ServiceL( const RMessage2& aMessage ) |
|
220 { |
|
221 LOG( SIMPLE, "SATENGINE: CSatSSession::ServiceL calling" ) |
|
222 |
|
223 if ( !aMessage.HasCapability( ECapabilityReadDeviceData ) ) |
|
224 { |
|
225 // Legal client should at least have ReadDeviceData capability |
|
226 LOG( SIMPLE, "SATENGINE: CSatSSession::ServiceL client \ |
|
227 has no ReadDeviceData capability. Panic it" ) |
|
228 PanicClient( aMessage, ESatSBadDescriptor ); |
|
229 } |
|
230 else |
|
231 { |
|
232 // Client has enough capability |
|
233 |
|
234 LOG2( NORMAL, "SATENGINE: CSatSSession::ServiceL \ |
|
235 aMessage.Function is %d", aMessage.Function() ) |
|
236 |
|
237 switch ( aMessage.Function() ) |
|
238 { |
|
239 // Ui Sub-session indicator. |
|
240 case ESatSOpenUiSubSession: |
|
241 { |
|
242 LOG( SIMPLE, |
|
243 "SATENGINE: CSatSSession::ServiceL ESatSOpenUiSubSession" ) |
|
244 CSatSUiSubSession* subsession = CSatSUiSubSession::NewL( |
|
245 *this, |
|
246 iSatApi, |
|
247 iEventMediator ); |
|
248 |
|
249 TRAPD( err, AddSubSessionL( subsession, aMessage ) ); |
|
250 if ( KErrNone == err ) |
|
251 { |
|
252 // Store the ui clients thread handle. |
|
253 RThread uiClientThread; |
|
254 User::LeaveIfError( aMessage.Client( uiClientThread ) ); |
|
255 |
|
256 iUiSubSession = subsession; |
|
257 |
|
258 // Start observing threads state |
|
259 TThreadId threadId = uiClientThread.Id(); |
|
260 iThreadDeathNotifier.SetObserveredThread( threadId ); |
|
261 iThreadDeathNotifier.StartObservingThread(); |
|
262 uiClientThread.Close(); |
|
263 |
|
264 // Complete message before notifying SAT Server since notifying may |
|
265 // be very time consuming operation dependening on the situation |
|
266 aMessage.Complete( KErrNone ); |
|
267 |
|
268 // Event has to be send after the iUiSubSession has been set. |
|
269 // Otherwise NULL pointer error in commandhandlers. |
|
270 iEventMediator.Notify( MSatUtils::ESatUiLaunched ); |
|
271 } |
|
272 break; |
|
273 } |
|
274 |
|
275 case ESatSOpenRefreshSubSession: |
|
276 { |
|
277 LOG( SIMPLE, |
|
278 "SATENGINE: CSatSSession::ServiceL ESatSOpenRefreshSubSession" ) |
|
279 CSatSRefreshSubSession* subsession = CSatSRefreshSubSession::NewL( |
|
280 *this, |
|
281 iEventMediator ); |
|
282 |
|
283 TRAPD( err, AddSubSessionL( subsession, aMessage ) ); |
|
284 if ( KErrNone == err ) |
|
285 { |
|
286 aMessage.Complete( KErrNone ); |
|
287 } |
|
288 break; |
|
289 } |
|
290 |
|
291 case ESatSOpenIconSubSession: |
|
292 { |
|
293 LOG( SIMPLE, |
|
294 "SATENGINE: CSatSSession::ServiceL ESatSOpenIconSubSession" ) |
|
295 CSatSIconSubSession* subsession = CSatSIconSubSession::NewL( |
|
296 *this, |
|
297 iEventMediator ); |
|
298 |
|
299 TRAPD( err, AddSubSessionL( subsession, aMessage ) ); |
|
300 if ( KErrNone == err ) |
|
301 { |
|
302 aMessage.Complete( KErrNone ); |
|
303 } |
|
304 break; |
|
305 } |
|
306 |
|
307 case ESatSCloseUiSubSession: |
|
308 { |
|
309 LOG( SIMPLE, |
|
310 "SATENGINE: CSatSSession::ServiceL ESatSCloseUiSubSession" ) |
|
311 iEventMediator.Notify( MSatUtils::ESatUiClosed ); |
|
312 iSatUiSubSessionClosed = ETrue; |
|
313 iUiSubSession = NULL; |
|
314 if ( CloseSubSession( aMessage ) ) |
|
315 { |
|
316 aMessage.Complete( KErrNone ); |
|
317 } |
|
318 break; |
|
319 } |
|
320 |
|
321 case ESatSCloseRefreshSubSession: |
|
322 { |
|
323 LOG( SIMPLE, |
|
324 "SATENGINE: CSatSSession::ServiceL ESatSCloseRefreshSubSession" ) |
|
325 if ( CloseSubSession( aMessage ) ) |
|
326 { |
|
327 aMessage.Complete( KErrNone ); |
|
328 } |
|
329 break; |
|
330 } |
|
331 |
|
332 case ESatSCloseIconSubSession: |
|
333 { |
|
334 LOG( SIMPLE, |
|
335 "SATENGINE: CSatSSession::ServiceL ESatSCloseIconSubSession" ) |
|
336 if ( CloseSubSession( aMessage ) ) |
|
337 { |
|
338 aMessage.Complete( KErrNone ); |
|
339 } |
|
340 break; |
|
341 } |
|
342 |
|
343 default: |
|
344 { |
|
345 LOG( SIMPLE, "SATENGINE: CSatSSession::ServiceL others" ) |
|
346 CSatSSubSession* subsession = |
|
347 GetSubSessionFromHandle( aMessage.Int3() ); |
|
348 |
|
349 if ( NULL != subsession ) |
|
350 { |
|
351 LOG( SIMPLE, |
|
352 "SATENGINE: CSatSSession::ServiceL NULL != subsession" ) |
|
353 subsession->HandleCommandL( aMessage ); |
|
354 } |
|
355 else |
|
356 { |
|
357 PanicClient( aMessage, ESatSBadDescriptor ); |
|
358 } |
|
359 } |
|
360 } |
|
361 } |
|
362 LOG( SIMPLE, "SATENGINE: CSatSSession::ServiceL exiting" ) |
|
363 } |
|
364 |
|
365 // ----------------------------------------------------------------------------- |
|
366 // CSatSSession::PanicClient |
|
367 // Panics the client. |
|
368 // ----------------------------------------------------------------------------- |
|
369 // |
|
370 void CSatSSession::PanicClient( const RMessage2& aMessage, TInt aPanic ) const |
|
371 { |
|
372 LOG( SIMPLE, "SATENGINE: CSatSSession::PanicClient calling" ) |
|
373 |
|
374 _LIT( KTxtServer, "SatS server" ); |
|
375 aMessage.Panic( KTxtServer, aPanic ); |
|
376 |
|
377 LOG( SIMPLE, "SATENGINE: CSatSSession::PanicClient exiting" ) |
|
378 } |
|
379 |
|
380 // ----------------------------------------------------------------------------- |
|
381 // CSatSSession::NotifyThreadDeathMonitor |
|
382 // Notifies ThreadDeathMonitor for thread is dying |
|
383 // ----------------------------------------------------------------------------- |
|
384 // |
|
385 void CSatSSession::NotifyThreadDeathMonitor() |
|
386 { |
|
387 LOG( SIMPLE, "SATENGINE: CSatSSession::NotifyThreadDeathMonitor calling" ) |
|
388 |
|
389 iThreadDeathNotifier.NotifyThreadDeath(); |
|
390 |
|
391 LOG( SIMPLE, "SATENGINE: CSatSSession::NotifyThreadDeathMonitor exiting" ) |
|
392 } |
|
393 |
|
394 // ----------------------------------------------------------------------------- |
|
395 // CSatSSession::SatServer |
|
396 // Returns pointer to SatServer - class |
|
397 // ----------------------------------------------------------------------------- |
|
398 // |
|
399 CSatSServer* CSatSSession::SatServer() |
|
400 { |
|
401 LOG( SIMPLE, "SATENGINE: CSatSSession::SatServer calling-exiting" ) |
|
402 return iSatServer; |
|
403 } |
|
404 |
|
405 // ----------------------------------------------------------------------------- |
|
406 // CSatSSession::UiSessionClosed |
|
407 // Notifies SatEngine that UI session has closed |
|
408 // ----------------------------------------------------------------------------- |
|
409 // |
|
410 void CSatSSession::UiSessionClosed() |
|
411 { |
|
412 LOG( SIMPLE, "SATENGINE: CSatSSession::UiSessionClosed calling" ) |
|
413 |
|
414 if ( !iSatUiSubSessionClosed ) |
|
415 { |
|
416 LOG( SIMPLE, "SATENGINE: CSatSSession::UiSessionClosed close satui" ) |
|
417 iEventMediator.Notify( MSatUtils::ESatUiClosed ); |
|
418 iSatUiSubSessionClosed = ETrue; |
|
419 } |
|
420 |
|
421 LOG( SIMPLE, "SATENGINE: CSatSSession::UiSessionClosed exiting" ) |
|
422 } |
|
423 |
|
424 // ----------------------------------------------------------------------------- |
|
425 // CSatSSession::CreateIconHandlerL |
|
426 // Creates and returns CSatIconHandler |
|
427 // ----------------------------------------------------------------------------- |
|
428 // |
|
429 MSatSIconAPI* CSatSSession::CreateIconHandlerL() |
|
430 { |
|
431 LOG( SIMPLE, "SATENGINE: CSatSSession::CreateIconHandlerL calling-exiting" ) |
|
432 return new( ELeave ) CSatIconHandler( iSatApi ); |
|
433 } |