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: |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include <liwcommon.h> |
|
20 #include <s32mem.h> |
|
21 #include <escapeutils.h> |
|
22 |
|
23 #include "cpserverdatamanager.h" |
|
24 #include "ccontentmap.h" |
|
25 #include "cpublisherregistrymap.h" |
|
26 #include "cpstorage.h" |
|
27 #include "cpdebug.h" |
|
28 #include "cpstoragefactory.h" |
|
29 #include "cpglobals.h" |
|
30 #include "cpserversession.h" |
|
31 #include "cpnotificationhandler.h" |
|
32 |
|
33 using namespace LIW; |
|
34 |
|
35 // --------------------------------------------------------------------------- |
|
36 // C++ destructor |
|
37 // --------------------------------------------------------------------------- |
|
38 // |
|
39 CCPDataManager::~CCPDataManager() |
|
40 { |
|
41 iNotificationsArray.Close( ); |
|
42 delete iStorage; |
|
43 } |
|
44 |
|
45 // --------------------------------------------------------------------------- |
|
46 // |
|
47 // --------------------------------------------------------------------------- |
|
48 // |
|
49 CCPDataManager* CCPDataManager::NewL( TBool aBool ) |
|
50 { |
|
51 CCPDataManager* self = CCPDataManager::NewLC( aBool ); |
|
52 CleanupStack::Pop( self ); |
|
53 return self; |
|
54 } |
|
55 |
|
56 // --------------------------------------------------------------------------- |
|
57 // |
|
58 // --------------------------------------------------------------------------- |
|
59 // |
|
60 CCPDataManager* CCPDataManager::NewLC( TBool aBool ) |
|
61 { |
|
62 CCPDataManager* self = new( ELeave ) CCPDataManager; |
|
63 CleanupStack::PushL( self ); |
|
64 self->ConstructL( aBool ); |
|
65 return self; |
|
66 } |
|
67 |
|
68 // --------------------------------------------------------------------------- |
|
69 // C++ constructor. |
|
70 // --------------------------------------------------------------------------- |
|
71 // |
|
72 CCPDataManager::CCPDataManager() |
|
73 { |
|
74 |
|
75 } |
|
76 |
|
77 // --------------------------------------------------------------------------- |
|
78 // Standard 2nd phase constructor. |
|
79 // --------------------------------------------------------------------------- |
|
80 // |
|
81 void CCPDataManager::ConstructL( TBool aBool ) |
|
82 { |
|
83 CP_DEBUG( _L8("CCPDataManager::ConstructL()") ); |
|
84 if ( !aBool ) |
|
85 { |
|
86 iStorage = StorageFactory::NewDatabaseL( ); |
|
87 } |
|
88 } |
|
89 |
|
90 // --------------------------------------------------------------------------- |
|
91 // |
|
92 // --------------------------------------------------------------------------- |
|
93 // |
|
94 TUint CCPDataManager::AddDataL( CCPLiwMap& aMap ) |
|
95 { |
|
96 CP_DEBUG( _L8("CCPDataManager::AddDataL()") ); |
|
97 __ASSERT_DEBUG( iStorage , User::Panic( _L("cpserver"), 0 ) ); |
|
98 |
|
99 CCPLiwMap* getlistmap = CreateMapForGetlistLC( aMap ); |
|
100 |
|
101 TBool activateMap = aMap.GetActivateInfo(); |
|
102 TBool activateDB ( EFalse ); |
|
103 TBool activateSupport =aMap.ActivateActionSupport( ); |
|
104 |
|
105 if( activateSupport ) |
|
106 { |
|
107 activateDB = GetActivateInfoL( getlistmap ); |
|
108 } |
|
109 |
|
110 TInt id = iStorage->AddL( &aMap ); |
|
111 |
|
112 if( activateSupport ) |
|
113 { |
|
114 if ( activateMap && !activateDB ) |
|
115 { |
|
116 // append action trigger for activate |
|
117 aMap.InsertL( KActionTrigger, TLiwVariant( KActivateTrigger ) ); |
|
118 } |
|
119 if ( !activateMap && activateDB ) |
|
120 { |
|
121 // append action trigger for deactivate |
|
122 aMap.InsertL( KActionTrigger, TLiwVariant( KDeactivateTrigger ) ); |
|
123 } |
|
124 //remove flag from map ( needed because map will be used in getlist |
|
125 //operation ) |
|
126 aMap.Remove( KFlag ); |
|
127 } |
|
128 |
|
129 CleanupStack::PopAndDestroy( getlistmap ); |
|
130 |
|
131 return id; |
|
132 } |
|
133 |
|
134 // --------------------------------------------------------------------------- |
|
135 // |
|
136 // --------------------------------------------------------------------------- |
|
137 // |
|
138 void CCPDataManager::GetListL( const CCPLiwMap& aMap, |
|
139 CLiwGenericParamList& aOutParamList ) |
|
140 { |
|
141 CP_DEBUG( _L8("CCPDataManager::GetListL()") ); |
|
142 __ASSERT_DEBUG( iStorage , User::Panic( _L("cpserver"), 0 ) ); |
|
143 iStorage->GetListL( &aMap, aOutParamList ); |
|
144 } |
|
145 // --------------------------------------------------------------------------- |
|
146 // |
|
147 // --------------------------------------------------------------------------- |
|
148 // |
|
149 TInt CCPDataManager::GetActionL( const CCPLiwMap& aMap, |
|
150 CLiwGenericParamList& aOutParamList, CLiwDefaultList* aNotificationList ) |
|
151 { |
|
152 CP_DEBUG( _L8("CCPDataManager::GetActionL()") ); |
|
153 __ASSERT_DEBUG( iStorage , User::Panic( _L("cpserver"), 0 ) ); |
|
154 |
|
155 CLiwGenericParamList* paramList = CLiwGenericParamList::NewLC( ); |
|
156 TInt result( KErrNone ); |
|
157 TRAP( result, iStorage->GetListL( &aMap, *paramList ) ); |
|
158 RBuf8 actionTrigger; |
|
159 actionTrigger.CleanupClosePushL(); |
|
160 |
|
161 if ( aMap.GetPropertyL( KActionTrigger, actionTrigger ) ) |
|
162 { |
|
163 const TLiwGenericParam* param; |
|
164 TInt pos( 0); |
|
165 |
|
166 param = paramList->FindFirst( pos, KListMap ); |
|
167 //at least one param should be valid to preceed |
|
168 if ( !param || pos == KErrNotFound ) |
|
169 { |
|
170 BuildDefaultChangeInfoL(&aMap, aNotificationList); |
|
171 } |
|
172 |
|
173 //iteration through paramList items |
|
174 while ( param && pos != KErrNotFound ) |
|
175 { |
|
176 BuildChangeInfoL( &aMap, param, aNotificationList ); |
|
177 FillActionParamListL( aOutParamList, param, actionTrigger ); |
|
178 param = paramList->FindNext( pos, KListMap ); |
|
179 } |
|
180 } |
|
181 else |
|
182 { |
|
183 User::Leave( KErrNotFound ); |
|
184 } |
|
185 CleanupStack::PopAndDestroy( &actionTrigger ); |
|
186 CleanupStack::PopAndDestroy( paramList ); |
|
187 return result; |
|
188 } |
|
189 |
|
190 |
|
191 // --------------------------------------------------------------------------- |
|
192 // |
|
193 // --------------------------------------------------------------------------- |
|
194 // |
|
195 void CCPDataManager::FillActionParamListL( |
|
196 CLiwGenericParamList& aOutParamList, |
|
197 const TLiwGenericParam* aParam, |
|
198 RBuf8 & aActionTrigger) |
|
199 { |
|
200 CP_DEBUG( _L8("CCPDataManager::FillActionParamListL()") ); |
|
201 __ASSERT_DEBUG( iStorage , User::Panic( _L("cpserver"), 0 ) ); |
|
202 |
|
203 RBuf8 actionBinaries; |
|
204 actionBinaries.CleanupClosePushL(); |
|
205 ExtractActionL( aParam, actionBinaries ); |
|
206 |
|
207 RDesReadStream str(actionBinaries); |
|
208 CleanupClosePushL( str ); |
|
209 CLiwDefaultMap* actionMap = CLiwDefaultMap::NewLC( str ); |
|
210 ExtractTriggerL( aOutParamList, actionMap, aActionTrigger ); |
|
211 |
|
212 CleanupStack::PopAndDestroy( actionMap ); |
|
213 CleanupStack::PopAndDestroy( &str ); |
|
214 CleanupStack::PopAndDestroy( &actionBinaries ); |
|
215 } |
|
216 |
|
217 // --------------------------------------------------------------------------- |
|
218 // |
|
219 // --------------------------------------------------------------------------- |
|
220 // |
|
221 void CCPDataManager::GetActivePublishersL( CLiwGenericParamList* aResultList ) |
|
222 { |
|
223 CCPLiwMap *map = CPublisherRegistryMap::NewLC(); |
|
224 map->InsertL( KFlag, TLiwVariant( TUint( 0 | EActivate ) ) ); |
|
225 iStorage->GetListL( map, *aResultList ); |
|
226 CleanupStack::PopAndDestroy(map); |
|
227 } |
|
228 |
|
229 |
|
230 // --------------------------------------------------------------------------- |
|
231 // |
|
232 // --------------------------------------------------------------------------- |
|
233 // |
|
234 void CCPDataManager::ExtractTriggerL( CLiwGenericParamList& aOutParamList, |
|
235 const CLiwDefaultMap* aMap, const TDesC8& aTrigger ) |
|
236 { |
|
237 CP_DEBUG( _L8("CCPDataManager::GetActionL()") ); |
|
238 CLiwDefaultMap* targetMap = CLiwDefaultMap::NewLC( ); |
|
239 TLiwVariant variant; |
|
240 variant.PushL( ); |
|
241 if ( aMap->FindL( aTrigger, variant ) ) |
|
242 { |
|
243 targetMap->InsertL( KActionMap, variant ); |
|
244 } |
|
245 else |
|
246 { |
|
247 User::Leave( KErrNotFound ); |
|
248 } |
|
249 |
|
250 TLiwGenericParam result( KListMap, TLiwVariant( targetMap )); |
|
251 aOutParamList.AppendL( result ); |
|
252 CleanupStack::PopAndDestroy( &variant ); |
|
253 CleanupStack::PopAndDestroy( targetMap ); |
|
254 } |
|
255 |
|
256 // --------------------------------------------------------------------------- |
|
257 // |
|
258 // --------------------------------------------------------------------------- |
|
259 // |
|
260 void CCPDataManager::RemoveDataL( const CCPLiwMap& aMap ) |
|
261 { |
|
262 CP_DEBUG( _L8("CCPDataManager::RemoveData()") ); |
|
263 __ASSERT_DEBUG( iStorage , User::Panic( _L("cpserver"), 0 ) ); |
|
264 iStorage->RemoveL( &aMap ); |
|
265 } |
|
266 |
|
267 // --------------------------------------------------------------------------- |
|
268 // |
|
269 // --------------------------------------------------------------------------- |
|
270 // |
|
271 void CCPDataManager::AddObserverL( |
|
272 CCPNotificationHandler* aNotificationHandler ) |
|
273 { |
|
274 CP_DEBUG( _L8("CCPDataManager::AddObserverL()") ); |
|
275 __ASSERT_DEBUG( iStorage , User::Panic( _L("cpserver"), 0 ) ); |
|
276 iNotificationsArray.AppendL( aNotificationHandler ); |
|
277 if ( iNotificationsArray.Count( ) == 1 ) |
|
278 { |
|
279 iStorage->SetCallback( this ); |
|
280 } |
|
281 } |
|
282 |
|
283 // --------------------------------------------------------------------------- |
|
284 // |
|
285 // --------------------------------------------------------------------------- |
|
286 // |
|
287 void CCPDataManager::RemoveObserver( |
|
288 CCPNotificationHandler* aNotificationHandler ) |
|
289 { |
|
290 CP_DEBUG( _L8("CCPDataManager::RemoveObserver()") ); |
|
291 TInt index = iNotificationsArray.Find( aNotificationHandler ); |
|
292 __ASSERT_DEBUG( index >= 0 , User::Panic( _L("cpserver"), 0 ) ); |
|
293 iNotificationsArray.Remove( index ); |
|
294 if ( iNotificationsArray.Count( ) == 0 ) |
|
295 { |
|
296 iStorage->SetCallback( 0 ); |
|
297 } |
|
298 } |
|
299 |
|
300 // --------------------------------------------------------------------------- |
|
301 // |
|
302 // --------------------------------------------------------------------------- |
|
303 // |
|
304 void CCPDataManager::HandleChangeL( CLiwDefaultList* aListOfMaps ) |
|
305 { |
|
306 CP_DEBUG( _L8("CCPDataManager::HandleChangeL()") ); |
|
307 //for every session |
|
308 for ( TInt i = 0; i<iNotificationsArray.Count( ); i++ ) |
|
309 { |
|
310 TRAPD(error, SendNotificationL(aListOfMaps, i)); |
|
311 if ( error ) |
|
312 { |
|
313 iNotificationsArray[i]->ErrorComplete( error ); |
|
314 } |
|
315 } |
|
316 } |
|
317 |
|
318 // --------------------------------------------------------------------------- |
|
319 // |
|
320 // --------------------------------------------------------------------------- |
|
321 // |
|
322 void CCPDataManager::CloseDatabase() |
|
323 { |
|
324 CP_DEBUG( _L8("CCPDataManager::CloseDatabase()") ); |
|
325 delete iStorage; |
|
326 iStorage = NULL; |
|
327 } |
|
328 |
|
329 // --------------------------------------------------------------------------- |
|
330 // |
|
331 // --------------------------------------------------------------------------- |
|
332 // |
|
333 void CCPDataManager::OpenDatabaseL() |
|
334 { |
|
335 CP_DEBUG( _L8("CCPDataManager::OpenDatabaseL()") ); |
|
336 if ( !iStorage ) |
|
337 { |
|
338 iStorage = StorageFactory::NewDatabaseL( ); |
|
339 |
|
340 // Restore storage observers |
|
341 if ( iNotificationsArray.Count() > 0 ) |
|
342 { |
|
343 iStorage->SetCallback( this ); |
|
344 } |
|
345 } |
|
346 } |
|
347 // --------------------------------------------------------------------------- |
|
348 // |
|
349 // --------------------------------------------------------------------------- |
|
350 // |
|
351 void CCPDataManager::SendNotificationL( CLiwDefaultList* aListOfMaps, |
|
352 TInt aIndex ) |
|
353 { |
|
354 CP_DEBUG( _L8("CCPDataManager::SendNotificationL()") ); |
|
355 iNotificationsArray[aIndex]->SendNotificationL( aListOfMaps ); |
|
356 } |
|
357 |
|
358 // --------------------------------------------------------------------------- |
|
359 // |
|
360 // --------------------------------------------------------------------------- |
|
361 // |
|
362 void CCPDataManager::ExtractActionL( const TLiwGenericParam* aParam, RBuf8& aAction ) |
|
363 { |
|
364 CP_DEBUG( _L8("CCPDataManager::ExtractActionL()") ); |
|
365 CLiwDefaultMap* map = CLiwDefaultMap::NewLC( ); |
|
366 if ( !aParam->Value().Get( *map ) ) |
|
367 { |
|
368 User::Leave( KErrArgument ); |
|
369 } |
|
370 |
|
371 TLiwVariant variant; variant.PushL( ); |
|
372 TPtrC8 tempBuf( KNullDesC8 ); |
|
373 if ( map->FindL( KActionMap, variant ) |
|
374 && variant.Get( tempBuf ) ) |
|
375 { |
|
376 aAction.CreateL( tempBuf ); |
|
377 } |
|
378 else |
|
379 { |
|
380 User::Leave( KErrArgument ); |
|
381 } |
|
382 |
|
383 CleanupStack::PopAndDestroy( &variant ); |
|
384 CleanupStack::PopAndDestroy( map ); |
|
385 } |
|
386 |
|
387 // ----------------------------------------------------------------------------- |
|
388 // |
|
389 // ----------------------------------------------------------------------------- |
|
390 // |
|
391 CCPLiwMap* CCPDataManager::CreateMapForGetlistLC( const CCPLiwMap& aMap ) |
|
392 { |
|
393 CCPLiwMap *resultmap = CPublisherRegistryMap::NewLC(); |
|
394 RBuf publisher; |
|
395 publisher.CleanupClosePushL(); |
|
396 RBuf content_type; |
|
397 content_type.CleanupClosePushL(); |
|
398 RBuf content_id; |
|
399 content_id.CleanupClosePushL(); |
|
400 aMap.GetPropertyL( KContentType, content_type ); |
|
401 aMap.GetPropertyL( KContentId, content_id ); |
|
402 aMap.GetPropertyL( KPublisherId, publisher ); |
|
403 resultmap->InsertL( KPublisherId, TLiwVariant( publisher )); |
|
404 resultmap->InsertL( KContentId, TLiwVariant( content_id )); |
|
405 resultmap->InsertL( KContentType, TLiwVariant( content_type )); |
|
406 CleanupStack::PopAndDestroy( &content_id ); |
|
407 CleanupStack::PopAndDestroy( &content_type ); |
|
408 CleanupStack::PopAndDestroy( &publisher ); |
|
409 return resultmap; |
|
410 } |
|
411 |
|
412 // ----------------------------------------------------------------------------- |
|
413 // |
|
414 // ----------------------------------------------------------------------------- |
|
415 // |
|
416 TBool CCPDataManager::GetActivateInfoL( const CCPLiwMap* aMap ) |
|
417 { |
|
418 TBool result( EFalse ); |
|
419 CLiwGenericParamList* outList = CLiwGenericParamList::NewLC(); |
|
420 TRAPD(err,GetListL(*aMap,*outList)); |
|
421 if (err == KErrNone) |
|
422 { |
|
423 TInt pos( 0 ); |
|
424 outList->FindFirst( pos, KListMap ); |
|
425 if( pos != KErrNotFound ) |
|
426 { |
|
427 TLiwVariant variant = (*outList)[pos].Value(); |
|
428 CLiwDefaultMap *map = CLiwDefaultMap::NewLC(); |
|
429 variant.Get( *map ); |
|
430 if (map->FindL( KFlag, variant )) |
|
431 { |
|
432 TUint flag; |
|
433 variant.Get( flag ); |
|
434 result = flag & EActivate; |
|
435 } |
|
436 CleanupStack::PopAndDestroy( map ); |
|
437 variant.Reset(); |
|
438 } |
|
439 } |
|
440 CleanupStack::PopAndDestroy( outList ); |
|
441 return result; |
|
442 } |
|
443 |
|
444 // ----------------------------------------------------------------------------- |
|
445 // |
|
446 // ----------------------------------------------------------------------------- |
|
447 // |
|
448 void CCPDataManager::BuildChangeInfoL( const CCPLiwMap* aMap, |
|
449 const TLiwGenericParam* aParam, |
|
450 CLiwDefaultList* aChangeInfoList ) |
|
451 { |
|
452 TLiwVariant resultVar = aParam->Value(); |
|
453 resultVar.PushL(); |
|
454 CLiwDefaultMap* changeInfoMap = CLiwDefaultMap::NewLC(); |
|
455 CLiwDefaultMap* resultMap = CLiwDefaultMap::NewLC(); |
|
456 resultVar.Get( *resultMap ); |
|
457 |
|
458 CopyVariantL(KId, resultMap, changeInfoMap ); |
|
459 CopyVariantL(KPublisherId, resultMap, changeInfoMap ); |
|
460 CopyVariantL(KContentType, resultMap, changeInfoMap ); |
|
461 CopyVariantL(KContentId, resultMap, changeInfoMap ); |
|
462 CopyVariantL(KFlag, resultMap, changeInfoMap ); |
|
463 CopyVariantL(KType, aMap, changeInfoMap ); |
|
464 CopyVariantL(KActionTrigger, aMap, changeInfoMap ); |
|
465 CopyActionTrigger16L( aMap, changeInfoMap ); |
|
466 |
|
467 changeInfoMap->InsertL( KOperation, TLiwVariant( KOperationExecute ) ); |
|
468 |
|
469 aChangeInfoList->AppendL( TLiwVariant( changeInfoMap ) ); |
|
470 CleanupStack::PopAndDestroy( resultMap ); |
|
471 CleanupStack::PopAndDestroy( changeInfoMap ); |
|
472 CleanupStack::PopAndDestroy( &resultVar ); |
|
473 } |
|
474 |
|
475 |
|
476 // ----------------------------------------------------------------------------- |
|
477 // |
|
478 // ----------------------------------------------------------------------------- |
|
479 // |
|
480 void CCPDataManager::BuildDefaultChangeInfoL( const CCPLiwMap* aMap, |
|
481 CLiwDefaultList* aChangeInfoList ) |
|
482 { |
|
483 CLiwDefaultMap* changeInfoMap = CLiwDefaultMap::NewLC(); |
|
484 |
|
485 CopyVariantL(KId, aMap, changeInfoMap ); |
|
486 CopyVariantL(KPublisherId, aMap, changeInfoMap ); |
|
487 CopyVariantL(KContentType, aMap, changeInfoMap ); |
|
488 CopyVariantL(KContentId, aMap, changeInfoMap ); |
|
489 CopyVariantL(KFlag, aMap, changeInfoMap ); |
|
490 CopyVariantL(KType, aMap, changeInfoMap ); |
|
491 CopyVariantL(KActionTrigger, aMap, changeInfoMap ); |
|
492 CopyActionTrigger16L( aMap, changeInfoMap ); |
|
493 |
|
494 changeInfoMap->InsertL( KOperation, TLiwVariant( KOperationExecute ) ); |
|
495 |
|
496 aChangeInfoList->AppendL( TLiwVariant( changeInfoMap ) ); |
|
497 CleanupStack::PopAndDestroy( changeInfoMap ); |
|
498 } |
|
499 |
|
500 // ----------------------------------------------------------------------------- |
|
501 // |
|
502 // ----------------------------------------------------------------------------- |
|
503 // |
|
504 void CCPDataManager::CopyVariantL(const TDesC8& aKey, |
|
505 const CLiwMap* aInMap, CLiwDefaultMap* aOutMap ) |
|
506 { |
|
507 TLiwVariant variant; |
|
508 variant.PushL(); |
|
509 if ( aInMap->FindL( aKey, variant ) ) |
|
510 { |
|
511 aOutMap->InsertL( aKey, variant ); |
|
512 } |
|
513 CleanupStack::PopAndDestroy( &variant ); |
|
514 } |
|
515 |
|
516 // ----------------------------------------------------------------------------- |
|
517 // |
|
518 // ----------------------------------------------------------------------------- |
|
519 // |
|
520 void CCPDataManager::CopyActionTrigger16L( |
|
521 const CLiwMap* aInMap, CLiwDefaultMap* aOutMap ) |
|
522 { |
|
523 TLiwVariant variant; |
|
524 variant.PushL(); |
|
525 if ( aInMap->FindL( KActionTrigger(), variant ) ) |
|
526 { |
|
527 |
|
528 TPtrC8 result8( KNullDesC8 ); |
|
529 if( variant.Get( result8 ) ) |
|
530 { |
|
531 RBuf actionTrigger; |
|
532 actionTrigger.CleanupClosePushL(); |
|
533 actionTrigger.Assign( |
|
534 EscapeUtils::ConvertToUnicodeFromUtf8L( result8 ) ); |
|
535 |
|
536 variant.Reset(); |
|
537 variant.Set( actionTrigger ); |
|
538 CleanupStack::PopAndDestroy( &actionTrigger ); |
|
539 } |
|
540 |
|
541 aOutMap->InsertL( KActionTrigger16(), variant ); |
|
542 } |
|
543 CleanupStack::PopAndDestroy( &variant ); |
|
544 } |
|
545 |
|