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: Content Publisher Server Session |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 // INCLUDE FILES |
|
20 #include <s32mem.h> |
|
21 // for CleanupResetAndDestroyPushL |
|
22 #include <mmf/common/mmfcontrollerpluginresolver.h> |
|
23 #include <liwgenericparam.h> |
|
24 |
|
25 #include "cpserversession.h" |
|
26 #include "cpliwmap.h" |
|
27 #include "cpublisherregistrymap.h" |
|
28 #include "cpsecuritypolicy.h" |
|
29 #include "cpserverdef.h" |
|
30 #include "cpdebug.h" |
|
31 #include "cpserver.h" |
|
32 #include "cpserverdatamanager.h" |
|
33 #include "cpactionhandlerthread.h" |
|
34 #include "cpnotificationhandler.h" |
|
35 |
|
36 |
|
37 using namespace LIW; |
|
38 |
|
39 // ================= MEMBER FUNCTIONS ======================= |
|
40 |
|
41 // ----------------------------------------------------------------------------- |
|
42 // CCPServerSession::NewL |
|
43 // Two-phased constructor. |
|
44 // ----------------------------------------------------------------------------- |
|
45 // |
|
46 CCPServerSession* CCPServerSession::NewL( TPointersForSession& aPasser ) |
|
47 { |
|
48 CCPServerSession* self = CCPServerSession::NewLC( aPasser ); |
|
49 CleanupStack::Pop( self ) ; |
|
50 return self; |
|
51 } |
|
52 |
|
53 // ----------------------------------------------------------------------------- |
|
54 // CCPServerSession::NewLC |
|
55 // Two-phased constructor. |
|
56 // ----------------------------------------------------------------------------- |
|
57 // |
|
58 CCPServerSession* CCPServerSession::NewLC( TPointersForSession& aPasser ) |
|
59 { |
|
60 CCPServerSession* self = new ( ELeave ) CCPServerSession(); |
|
61 CleanupStack::PushL( self ); |
|
62 self->ConstructL( aPasser ) ; |
|
63 return self; |
|
64 } |
|
65 |
|
66 // ----------------------------------------------------------------------------- |
|
67 // CCPServerSession::~CCPServerSession |
|
68 // Destructor. |
|
69 // ----------------------------------------------------------------------------- |
|
70 // |
|
71 CCPServerSession::~CCPServerSession() |
|
72 { |
|
73 if ( isRegister && iNotificationHandler ) |
|
74 { |
|
75 //remove notification handler from an array of sessions in data manager |
|
76 if ( iDataManager ) |
|
77 { |
|
78 iDataManager->RemoveObserver( iNotificationHandler ); |
|
79 } |
|
80 iNotificationHandler->ErrorComplete( KErrCancel ); |
|
81 } |
|
82 if ( iServer ) |
|
83 { |
|
84 iServer->RemoveSession( ); |
|
85 } |
|
86 delete iNotificationHandler; |
|
87 delete iParamList; |
|
88 } |
|
89 |
|
90 // ----------------------------------------------------------------------------- |
|
91 // CCPServerSession::CCPServerSession |
|
92 // C++ default constructor can NOT contain any code, that |
|
93 // might leave. |
|
94 // ----------------------------------------------------------------------------- |
|
95 // |
|
96 CCPServerSession::CCPServerSession() : |
|
97 CSession2() |
|
98 { |
|
99 |
|
100 } |
|
101 |
|
102 // ----------------------------------------------------------------------------- |
|
103 // CCPServerSession::ConstructL |
|
104 // Symbian 2nd phase constructor can leave. |
|
105 // ----------------------------------------------------------------------------- |
|
106 // |
|
107 void CCPServerSession::ConstructL( TPointersForSession& aPasser ) |
|
108 { |
|
109 CP_DEBUG( _L8("CCPServerSession::ConstructL()") ); |
|
110 iDataManager = aPasser.iDataManager; |
|
111 iServer = aPasser.iServer; |
|
112 iActionHandlerThread = aPasser.iActionHandlerThread; |
|
113 iServer->AddSession( ); |
|
114 isRegister = EFalse; |
|
115 } |
|
116 |
|
117 // ----------------------------------------------------------------------------- |
|
118 // CCPServerSession::ServiceL |
|
119 // Handle client requests. |
|
120 // ----------------------------------------------------------------------------- |
|
121 // |
|
122 void CCPServerSession::ServiceL( const RMessage2& aMessage ) |
|
123 { |
|
124 CP_DEBUG( _L8("CCPServerSession::ServiceL()" ) ); |
|
125 TBool serverLocked = GetServerLock( aMessage ); |
|
126 if ( serverLocked ) |
|
127 { |
|
128 aMessage.Complete( KErrLocked ); |
|
129 } |
|
130 else |
|
131 { |
|
132 TInt err(KErrNone); |
|
133 TBool panicedClient(EFalse); |
|
134 TRAP( err , DispatchMessageL( aMessage, panicedClient ) ); |
|
135 if ( (!(aMessage.Function( ) == ECpServerRegisterObserver ) |
|
136 || err == KErrInUse) && !panicedClient ) |
|
137 { |
|
138 aMessage.Complete( err ); |
|
139 } |
|
140 } |
|
141 } |
|
142 |
|
143 // ----------------------------------------------------------------------------- |
|
144 // CCPServerSession::ServiceL |
|
145 // Handle client requests. |
|
146 // ----------------------------------------------------------------------------- |
|
147 // |
|
148 void CCPServerSession::DispatchMessageL( const RMessage2& aMessage, TBool& aPanicedClient ) |
|
149 { |
|
150 CP_DEBUG( _L8("CCPServerSession::DispatchMessageL()" ) ); |
|
151 switch ( aMessage.Function( ) ) |
|
152 { |
|
153 case ECpServerAddData: |
|
154 AddDataL( aMessage ); |
|
155 break; |
|
156 case ECpServerGetListSize: |
|
157 GetListSizeL( aMessage ); |
|
158 break; |
|
159 case ECpServerGetListData: |
|
160 GetListDataL( aMessage ); |
|
161 break; |
|
162 case ECpServerRemoveData: |
|
163 RemoveDataL( aMessage ); |
|
164 break; |
|
165 case ECpServerRegisterObserver: |
|
166 RegisterObserverL( aMessage ); |
|
167 break; |
|
168 case ECpServerAddObserver: |
|
169 AddObserverL( aMessage ); |
|
170 break; |
|
171 case ECpServerRemoveObserver: |
|
172 RemoveObserverL( aMessage ); |
|
173 break; |
|
174 case ECpServerUnRegisterObserver: |
|
175 UnregisterObserverL( ); |
|
176 break; |
|
177 case ECpServerGetChangeInfoData: |
|
178 GetChangeInfoDataL( aMessage ); |
|
179 break; |
|
180 case ECpServerExecuteAction: |
|
181 ExecuteActionL( aMessage ); |
|
182 break; |
|
183 default: |
|
184 iServer->PanicClient( aMessage, ECPServerBadRequest ); |
|
185 aPanicedClient = ETrue; |
|
186 break; |
|
187 } |
|
188 } |
|
189 |
|
190 // ----------------------------------------------------------------------------- |
|
191 // CCPServerSession::AddDataL |
|
192 // --------------- -------------------------------------------------------------- |
|
193 // |
|
194 void CCPServerSession::AddDataL( const RMessage2& aMessage ) |
|
195 { |
|
196 CP_DEBUG( _L8("CCPServerSession::AddDataL()" ) ); |
|
197 CCPLiwMap* map = UnpackFromClientLC( aMessage ); |
|
198 map->SetSecurityL( aMessage ); |
|
199 TBool activateSupport = map->ActivateActionSupport( ); |
|
200 TUint id( 0 ); |
|
201 id = iDataManager->AddDataL( *map ); |
|
202 TPckg<TUint> idData(id); |
|
203 aMessage.WriteL( KReturnPosition, idData ); |
|
204 if(activateSupport) |
|
205 { |
|
206 CLiwDefaultList* list = CLiwDefaultList::NewLC( ); |
|
207 // execute activation or deactivation action for publisher |
|
208 TRAP_IGNORE( GetAndExecuteActionL( map, list ) ); |
|
209 TRAP_IGNORE( SendNotificationL( map, list ) ); |
|
210 CleanupStack::PopAndDestroy( list ); |
|
211 } |
|
212 CleanupStack::PopAndDestroy( map ); |
|
213 } |
|
214 |
|
215 // ----------------------------------------------------------------------------- |
|
216 // CCPServerSession::GetListL |
|
217 // --------------- -------------------------------------------------------------- |
|
218 // |
|
219 void CCPServerSession::GetListSizeL( const RMessage2& aMessage ) |
|
220 { |
|
221 CP_DEBUG( _L8("CCPServerSession::GetListSizeL()" ) ); |
|
222 CCPLiwMap* map = UnpackFromClientLC( aMessage ); |
|
223 map->SetSecurityL( aMessage ); |
|
224 delete iParamList; |
|
225 iParamList = NULL; |
|
226 iParamList = CLiwGenericParamList::NewL( ); |
|
227 iDataManager->GetListL( *map, *iParamList ); |
|
228 TPckg<TInt> sizeDes(iParamList->Size( ) ); |
|
229 aMessage.WriteL( KReturnPosition, sizeDes ); |
|
230 CleanupStack::PopAndDestroy( map ); |
|
231 } |
|
232 |
|
233 // ----------------------------------------------------------------------------- |
|
234 // CCPServerSession::GetListDataL |
|
235 // --------------- -------------------------------------------------------------- |
|
236 // |
|
237 void CCPServerSession::GetListDataL( const RMessage2& aMessage ) |
|
238 { |
|
239 CP_DEBUG( _L8("CCPServerSession::GetListDataL()" ) ); |
|
240 if( iParamList ) |
|
241 { |
|
242 ExternalizeAndWriteToClientL( aMessage, iParamList ); |
|
243 delete iParamList; |
|
244 } |
|
245 iParamList = NULL; |
|
246 } |
|
247 |
|
248 // ----------------------------------------------------------------------------- |
|
249 // CCPServerSession::RemoveDataL |
|
250 // --------------- -------------------------------------------------------------- |
|
251 // |
|
252 void CCPServerSession::RemoveDataL( const RMessage2& aMessage ) |
|
253 { |
|
254 CP_DEBUG( _L8("CCPServerSession::RemoveDataL()" ) ); |
|
255 CCPLiwMap* map = UnpackFromClientLC( aMessage ); |
|
256 map->SetSecurityL( aMessage ); |
|
257 iDataManager->RemoveDataL( *map ); |
|
258 CleanupStack::PopAndDestroy( map ); |
|
259 } |
|
260 |
|
261 // ----------------------------------------------------------------------------- |
|
262 // CCPServerSession::ExecuteActionL |
|
263 // --------------- -------------------------------------------------------------- |
|
264 // |
|
265 void CCPServerSession::ExecuteActionL( const RMessage2& aMessage ) |
|
266 { |
|
267 TInt error(KErrNone); |
|
268 CP_DEBUG( _L8("CCPServerSession::ExecuteActionSizeL()" ) ); |
|
269 CCPLiwMap* map = UnpackFromClientLC( aMessage ); |
|
270 CLiwGenericParamList* paramList = CLiwGenericParamList::NewLC( ); |
|
271 CLiwDefaultList* list = CLiwDefaultList::NewLC(); |
|
272 error = iDataManager->GetActionL( *map, *paramList, list ); |
|
273 //we notify apart from action execution result. So in fact |
|
274 //notification means there was an attempt to execute action |
|
275 iDataManager->HandleChangeL( list ); |
|
276 User::LeaveIfError( error ); |
|
277 ExecuteL( *paramList ); |
|
278 CleanupStack::PopAndDestroy( list ); |
|
279 CleanupStack::PopAndDestroy( paramList ); |
|
280 CleanupStack::PopAndDestroy( map ); |
|
281 } |
|
282 |
|
283 // ----------------------------------------------------------------------------- |
|
284 // CCPServerSession::ExecuteL |
|
285 // --------------- -------------------------------------------------------------- |
|
286 // |
|
287 void CCPServerSession::ExecuteL( |
|
288 const CLiwGenericParamList& aActionParams ) |
|
289 { |
|
290 for ( TInt i = 0; i < aActionParams.Count(); i++ ) |
|
291 { |
|
292 TLiwGenericParam param; |
|
293 param.PushL(); |
|
294 aActionParams.AtL( i, param ); |
|
295 CLiwGenericParamList* singleAction = CLiwGenericParamList::NewLC(); |
|
296 singleAction->AppendL( param ); |
|
297 TRAP_IGNORE( iActionHandlerThread->ExecuteL( *singleAction ) ); |
|
298 CleanupStack::PopAndDestroy( singleAction ); |
|
299 CleanupStack::PopAndDestroy( ¶m ); |
|
300 } |
|
301 } |
|
302 |
|
303 // ----------------------------------------------------------------------------- |
|
304 // CCPServerSession::RegisterObserverL |
|
305 // --------------- -------------------------------------------------------------- |
|
306 // |
|
307 void CCPServerSession::RegisterObserverL( const RMessage2& aMessage ) |
|
308 { |
|
309 CP_DEBUG( _L8("CCPServerSession::RegisterObserverL()" ) ); |
|
310 if ( !isRegister ) |
|
311 { |
|
312 if (aMessage.Int3() != KErrAlreadyExists && |
|
313 aMessage.GetDesLength( KDescriptorPosition) < KErrNone ) |
|
314 { |
|
315 iServer->PanicClient( aMessage, ECPServerBadRequest ); |
|
316 User::Leave( KErrGeneral ); |
|
317 } |
|
318 if ( !iNotificationHandler ) |
|
319 { |
|
320 iNotificationHandler = CCPNotificationHandler::NewL( |
|
321 iServer->GetNotifications()); |
|
322 iDataManager->AddObserverL( iNotificationHandler ); |
|
323 } |
|
324 iNotificationHandler->SaveMessageL( aMessage ); |
|
325 isRegister = ETrue; |
|
326 } |
|
327 else |
|
328 { |
|
329 User::Leave( KErrInUse ); |
|
330 } |
|
331 } |
|
332 |
|
333 // ----------------------------------------------------------------------------- |
|
334 // CCPServerSession::AddObserverL |
|
335 // --------------- -------------------------------------------------------------- |
|
336 // |
|
337 void CCPServerSession::AddObserverL( const RMessage2& aMessage ) |
|
338 { |
|
339 CP_DEBUG( _L8("CCPServerSession::AddObserverL()" ) ); |
|
340 if( iNotificationHandler ) |
|
341 { |
|
342 iNotificationHandler->AddObserverL( aMessage ); |
|
343 } |
|
344 } |
|
345 |
|
346 // ----------------------------------------------------------------------------- |
|
347 // CCPServerSession::RemoveObserverL |
|
348 // --------------- -------------------------------------------------------------- |
|
349 // |
|
350 void CCPServerSession::RemoveObserverL( const RMessage2& aMessage ) |
|
351 { |
|
352 CP_DEBUG( _L8("CCPServerSession::RemoveObserverL()" ) ); |
|
353 if( iNotificationHandler ) |
|
354 { |
|
355 iNotificationHandler->RemoveObserverL( aMessage ); |
|
356 } |
|
357 } |
|
358 |
|
359 |
|
360 // ----------------------------------------------------------------------------- |
|
361 // CCPServerSession::UnregisterObserverL |
|
362 // --------------- -------------------------------------------------------------- |
|
363 // |
|
364 void CCPServerSession::UnregisterObserverL() |
|
365 { |
|
366 CP_DEBUG( _L8("CCPServerSession::UnregisterObserverL()" ) ); |
|
367 if ( isRegister ) |
|
368 { |
|
369 //remove notification handler from an array of sessions in data manager |
|
370 iDataManager->RemoveObserver( iNotificationHandler ); |
|
371 //reset filter for this session |
|
372 iNotificationHandler->ErrorComplete( KErrCancel ); |
|
373 delete iNotificationHandler; |
|
374 iNotificationHandler = NULL; |
|
375 isRegister = EFalse; |
|
376 } |
|
377 else |
|
378 { |
|
379 User::Leave( KErrNotFound ); |
|
380 } |
|
381 } |
|
382 |
|
383 // ----------------------------------------------------------------------------- |
|
384 // CCPServerSession::GetChangeInfoDataL |
|
385 // ----------------------------------------------------------------------------- |
|
386 // |
|
387 void CCPServerSession::GetChangeInfoDataL( const RMessage2& aMessage ) |
|
388 { |
|
389 CP_DEBUG( _L8("CCPServerSession::GetChangeInfoData()" ) ); |
|
390 if( iNotificationHandler ) |
|
391 { |
|
392 isRegister = EFalse; |
|
393 ExternalizeAndWriteToClientL( aMessage, |
|
394 iNotificationHandler->GetPointerToChangeInfoList( ) ); |
|
395 iNotificationHandler->Reset( ); |
|
396 } |
|
397 } |
|
398 |
|
399 // ----------------------------------------------------------------------------- |
|
400 // CCPServerSession::ExternalizeAndWriteToClient |
|
401 // ----------------------------------------------------------------------------- |
|
402 // |
|
403 void CCPServerSession::ExternalizeAndWriteToClientL( |
|
404 const RMessage2& aMessage, const CLiwGenericParamList* outParamList ) |
|
405 { |
|
406 CP_DEBUG( _L8("CCPServerSession::ExternalizeAndWriteToClientL()" ) ); |
|
407 HBufC8* buf = HBufC8::NewLC( outParamList->Size( ) ); |
|
408 TPtr8 des = buf->Des( ); |
|
409 RDesWriteStream writeStream(des); |
|
410 CleanupClosePushL( writeStream ); |
|
411 outParamList->ExternalizeL( writeStream ); |
|
412 writeStream.CommitL( ); |
|
413 aMessage.WriteL( KDescriptorPosition, des ); |
|
414 CleanupStack::PopAndDestroy( &writeStream ); |
|
415 CleanupStack::PopAndDestroy( buf ); |
|
416 } |
|
417 |
|
418 // ----------------------------------------------------------------------------- |
|
419 // |
|
420 // ----------------------------------------------------------------------------- |
|
421 // |
|
422 CCPLiwMap* CCPServerSession::UnpackFromClientLC( const RMessage2& aMessage ) |
|
423 { |
|
424 CP_DEBUG( _L8("CCPServerSession::UnpackFromClientLC()") ); |
|
425 TInt deslen = aMessage.GetDesLengthL( KDescriptorPosition ); |
|
426 HBufC8* buffer = HBufC8::NewLC( deslen ); |
|
427 TPtr8 tempDes = buffer->Des( ); |
|
428 aMessage.Read( KDescriptorPosition, tempDes ); |
|
429 RDesReadStream datastrm( *buffer); |
|
430 CleanupClosePushL( datastrm ); |
|
431 CCPLiwMap* inParamList = CCPLiwMap::NewL( datastrm ); |
|
432 CleanupStack::PopAndDestroy( &datastrm ); |
|
433 CleanupStack::PopAndDestroy( buffer ); |
|
434 inParamList->PushL( ); |
|
435 return inParamList; |
|
436 } |
|
437 |
|
438 // ----------------------------------------------------------------------------- |
|
439 // CCPServerSession::SendNotificationL |
|
440 // ----------------------------------------------------------------------------- |
|
441 // |
|
442 void CCPServerSession::SendNotificationL( CCPLiwMap* aMap, |
|
443 CLiwDefaultList* aNotificationList ) |
|
444 { |
|
445 RBuf8 trigger; |
|
446 trigger.CleanupClosePushL(); |
|
447 aMap->GetPropertyL( KActionTrigger, trigger ); |
|
448 if( ( trigger == KActivateTrigger ) || ( trigger == KDeactivateTrigger ) ) |
|
449 { |
|
450 iDataManager->HandleChangeL( aNotificationList ); |
|
451 } |
|
452 CleanupStack::PopAndDestroy( &trigger ); |
|
453 } |
|
454 |
|
455 // ----------------------------------------------------------------------------- |
|
456 // CCPServerSession::GetAndExecuteActionL |
|
457 // --------------- -------------------------------------------------------------- |
|
458 // |
|
459 void CCPServerSession::GetAndExecuteActionL( CCPLiwMap* aMap, |
|
460 CLiwDefaultList* aNotificationList, TBool aInsertTrigger ) |
|
461 { |
|
462 if (aInsertTrigger) |
|
463 { |
|
464 aMap->InsertL( KActionTrigger, TLiwVariant( KActivateTrigger ) ); |
|
465 } |
|
466 CLiwGenericParamList* paramList = CLiwGenericParamList::NewLC(); |
|
467 iDataManager->GetActionL( *aMap, *paramList, aNotificationList ); |
|
468 iActionHandlerThread->ExecuteL( *paramList ); |
|
469 CleanupStack::PopAndDestroy( paramList ); |
|
470 } |
|
471 |
|
472 // ----------------------------------------------------------------------------- |
|
473 // CCPServerSession::GetServerLock |
|
474 // --------------- -------------------------------------------------------------- |
|
475 // |
|
476 TBool CCPServerSession::GetServerLock( const RMessage2& aMessage ) |
|
477 { |
|
478 // Allways allow to unregister |
|
479 return ( (aMessage.Function() != ECpServerUnRegisterObserver) |
|
480 && iServer->GetLock() ); |
|
481 |
|
482 } |
|
483 // End of File |
|