contentpublishingsrv/contentpublishingserver/cpserver/src/cpserverdatamanager.cpp
branchRCL_3
changeset 19 edd621764147
parent 16 b276298d5729
equal deleted inserted replaced
16:b276298d5729 19:edd621764147
    45 
    45 
    46 // ---------------------------------------------------------------------------
    46 // ---------------------------------------------------------------------------
    47 // 
    47 // 
    48 // ---------------------------------------------------------------------------
    48 // ---------------------------------------------------------------------------
    49 //
    49 //
    50 CCPDataManager* CCPDataManager::NewL( TBool aBool )
    50 CCPDataManager* CCPDataManager::NewL(TLiwVariant& aDataMapCache, TBool aBool)
    51     {
    51     {
    52     CCPDataManager* self = CCPDataManager::NewLC( aBool );
    52     CCPDataManager* self = CCPDataManager::NewLC( aDataMapCache, aBool );
    53     CleanupStack::Pop( self );
    53     CleanupStack::Pop( self );
    54     return self;
    54     return self;
    55     }
    55     }
    56 
    56 
    57 // ---------------------------------------------------------------------------
    57 // ---------------------------------------------------------------------------
    58 // 
    58 // 
    59 // ---------------------------------------------------------------------------
    59 // ---------------------------------------------------------------------------
    60 //
    60 //
    61 CCPDataManager* CCPDataManager::NewLC( TBool aBool )
    61 CCPDataManager* CCPDataManager::NewLC(TLiwVariant& aDataMapCache, TBool aBool)
    62     {
    62     {
    63     CCPDataManager* self = new( ELeave ) CCPDataManager;
    63     CCPDataManager* self = new( ELeave ) CCPDataManager();
    64     CleanupStack::PushL( self );
    64     CleanupStack::PushL( self );
    65     self->ConstructL( aBool );
    65     self->ConstructL( aDataMapCache, aBool );
    66     return self;
    66     return self;
    67     }
    67     }
    68 
    68 
    69 // ---------------------------------------------------------------------------
    69 // ---------------------------------------------------------------------------
    70 // C++ constructor.
    70 // C++ constructor.
    71 // ---------------------------------------------------------------------------
    71 // ---------------------------------------------------------------------------
    72 //
    72 //
    73 CCPDataManager::CCPDataManager()
    73 CCPDataManager::CCPDataManager() 
    74     {
    74     {
    75 
    75 
    76     }
    76     }
    77 
    77 
    78 // ---------------------------------------------------------------------------
    78 // ---------------------------------------------------------------------------
    79 // Standard 2nd phase constructor.
    79 // Standard 2nd phase constructor.
    80 // ---------------------------------------------------------------------------
    80 // ---------------------------------------------------------------------------
    81 //
    81 //
    82 void CCPDataManager::ConstructL( TBool aBool )
    82 void CCPDataManager::ConstructL(TLiwVariant& aDataMapCache, TBool aBool)
    83     {
    83     {
    84     CP_DEBUG( _L8("CCPDataManager::ConstructL()") );
    84     CP_DEBUG( _L8("CCPDataManager::ConstructL()") );
    85     if ( !aBool )
    85     if ( !aBool )
    86         {
    86         {
    87         iStorage = StorageFactory::NewDatabaseL( );
    87         iStorage = StorageFactory::NewDatabaseL( aDataMapCache );
    88         }
    88         }
    89     iActionDataCache = CCPActionDataCache::NewL();
    89     iActionDataCache = CCPActionDataCache::NewL();
    90     }
    90     }
    91 
    91 
    92 // ---------------------------------------------------------------------------
    92 // ---------------------------------------------------------------------------
   181             iActionDataCache->GetL( &aMap, paramList );
   181             iActionDataCache->GetL( &aMap, paramList );
   182             }
   182             }
   183         else 
   183         else 
   184             {
   184             {
   185             TRAP( result, iStorage->GetListL( &aMap, *paramList ) );
   185             TRAP( result, iStorage->GetListL( &aMap, *paramList ) );
   186             if ( aEnableCache && cacheable && result == KErrNone )
   186             if ( aEnableCache && cacheable )
   187                 {
   187                 {
   188                 iActionDataCache->AppendL(paramList);
   188                 if ( result == KErrNone )
       
   189                     {   
       
   190                     iActionDataCache->AppendL(paramList);
       
   191                     }
       
   192                 else if ( result == KErrNotFound )
       
   193                     {
       
   194                     iActionDataCache->AppendEmptyL(&aMap);
       
   195                     }
   189                 }
   196                 }
   190             }
   197             }
   191         
   198         
   192         const TLiwGenericParam* param;
   199         const TLiwGenericParam* param;
   193     	TInt pos( 0);
   200     	TInt pos( 0);
   200         	}
   207         	}
   201         
   208         
   202         //iteration through paramList items
   209         //iteration through paramList items
   203     	while ( param && pos != KErrNotFound )
   210     	while ( param && pos != KErrNotFound )
   204     		{
   211     		{
   205     		BuildChangeInfoL( &aMap, actionTriggers, param, 
   212     	    RBuf8 actionBinaries;
   206     		        aNotificationList );
   213     	    actionBinaries.CleanupClosePushL();
   207     		FillActionParamListL( aOutParamList, param, actionTriggers );
   214     	    ExtractActionL( param, actionBinaries );
   208     		param = paramList->FindNext( pos, KListMap );
   215     	    RDesReadStream str(actionBinaries);
       
   216     	    CleanupClosePushL( str );
       
   217     	    CLiwDefaultMap* actionMap = CLiwDefaultMap::NewLC( str );
       
   218             BuildChangeInfoL( &aMap, actionTriggers, param, actionMap,
       
   219                     aNotificationList );
       
   220             FillActionParamListL( aOutParamList, actionMap, actionTriggers );
       
   221             param = paramList->FindNext( pos, KListMap );
       
   222             CleanupStack::PopAndDestroy( actionMap );
       
   223             CleanupStack::PopAndDestroy( &str );
       
   224             CleanupStack::PopAndDestroy( &actionBinaries );
   209     		}
   225     		}
       
   226         if (aNotificationList->Count() == 0)
       
   227             {
       
   228             User::Leave(KErrNotFound);
       
   229             }
   210         }
   230         }
   211     else
   231     else
   212         {
   232         {
   213         User::Leave( KErrNotFound );
   233         User::Leave( KErrNotFound );
   214         }
   234         }
   223 // 
   243 // 
   224 // ---------------------------------------------------------------------------
   244 // ---------------------------------------------------------------------------
   225 //
   245 //
   226 void CCPDataManager::FillActionParamListL( 
   246 void CCPDataManager::FillActionParamListL( 
   227 		CLiwGenericParamList& aOutParamList, 
   247 		CLiwGenericParamList& aOutParamList, 
   228 		const TLiwGenericParam* aParam,
   248 		const CLiwDefaultMap* aActionMap,
   229 		const CLiwDefaultList* aActionTriggers)
   249 		const CLiwDefaultList* aActionTriggers)
   230 	{
   250 	{
   231     CP_DEBUG( _L8("CCPDataManager::FillActionParamListL()") );
   251     CP_DEBUG( _L8("CCPDataManager::FillActionParamListL()") );
   232     __ASSERT_DEBUG( iStorage , User::Panic( _L("cpserver"), 0 ) );
   252     __ASSERT_DEBUG( iStorage , User::Panic( _L("cpserver"), 0 ) );
   233 		
       
   234 	RBuf8 actionBinaries;
       
   235 	actionBinaries.CleanupClosePushL();
       
   236 	ExtractActionL(  aParam, actionBinaries );
       
   237 
       
   238 	RDesReadStream str(actionBinaries);
       
   239 	CleanupClosePushL( str );
       
   240 	CLiwDefaultMap* actionMap = CLiwDefaultMap::NewLC( str );
       
   241 
       
   242     TLiwVariant trigger;
   253     TLiwVariant trigger;
   243     trigger.PushL();
   254     trigger.PushL();
   244     TInt count = aActionTriggers->Count();
   255     TInt count = aActionTriggers->Count();
   245 	for ( TInt i = 0; i<count; i++ )
   256 	for ( TInt i = 0; i<count; i++ )
   246 	    {
   257 	    {
   247 	    trigger.Reset();
   258 	    trigger.Reset();
   248 	    aActionTriggers->AtL( i,trigger );
   259 	    aActionTriggers->AtL( i,trigger );
   249 	    ExtractTriggerL( aOutParamList, actionMap, trigger.AsData());
   260 	    ExtractTriggerL( aOutParamList, aActionMap, trigger.AsData());
   250 	    }
   261 	    }
   251     CleanupStack::PopAndDestroy(&trigger);
   262     CleanupStack::PopAndDestroy(&trigger);
   252 
       
   253 	CleanupStack::PopAndDestroy( actionMap );
       
   254 	CleanupStack::PopAndDestroy( &str );
       
   255 	CleanupStack::PopAndDestroy( &actionBinaries );
       
   256 	}
   263 	}
   257 
   264 
   258 // ---------------------------------------------------------------------------
   265 // ---------------------------------------------------------------------------
   259 // 
   266 // 
   260 // ---------------------------------------------------------------------------
   267 // ---------------------------------------------------------------------------
   280     TLiwVariant variant;
   287     TLiwVariant variant;
   281     variant.PushL( );
   288     variant.PushL( );
   282     if ( aMap->FindL( aTrigger, variant ) )
   289     if ( aMap->FindL( aTrigger, variant ) )
   283         {
   290         {
   284         targetMap->InsertL( KActionMap, variant );
   291         targetMap->InsertL( KActionMap, variant );
   285         }
   292         TLiwGenericParam result( KListMap, TLiwVariant( targetMap ));
   286     else
   293         aOutParamList.AppendL( result );
   287         {
   294         }
   288         User::Leave( KErrNotFound );
       
   289         }
       
   290 
       
   291     TLiwGenericParam result( KListMap, TLiwVariant( targetMap ));
       
   292     aOutParamList.AppendL( result );
       
   293     CleanupStack::PopAndDestroy( &variant );
   295     CleanupStack::PopAndDestroy( &variant );
   294     CleanupStack::PopAndDestroy( targetMap );
   296     CleanupStack::PopAndDestroy( targetMap );
   295     }
   297     }
   296 
   298 
   297 // ---------------------------------------------------------------------------
   299 // ---------------------------------------------------------------------------
   372 
   374 
   373 // ---------------------------------------------------------------------------
   375 // ---------------------------------------------------------------------------
   374 //
   376 //
   375 // ---------------------------------------------------------------------------
   377 // ---------------------------------------------------------------------------
   376 //
   378 //
   377 void CCPDataManager::OpenDatabaseL()
   379 void CCPDataManager::OpenDatabaseL(TLiwVariant& aDataMapCache)
   378     {
   380     {
   379     CP_DEBUG( _L8("CCPDataManager::OpenDatabaseL()") );
   381     CP_DEBUG( _L8("CCPDataManager::OpenDatabaseL()") );
   380     if ( !iStorage )
   382     if ( !iStorage )
   381         {
   383         {
   382         iStorage = StorageFactory::NewDatabaseL( );
   384         iStorage = StorageFactory::NewDatabaseL( aDataMapCache );
   383         
   385         
   384         // Restore storage observers
   386         // Restore storage observers
   385         if ( iNotificationsArray.Count() > 0 )
   387         if ( iNotificationsArray.Count() > 0 )
   386             {
   388             {
   387             iStorage->SetCallback( this );
   389             iStorage->SetCallback( this );
   488 // -----------------------------------------------------------------------------
   490 // -----------------------------------------------------------------------------
   489 //    
   491 //    
   490 void CCPDataManager::BuildChangeInfoL( const CCPLiwMap* aMap, 
   492 void CCPDataManager::BuildChangeInfoL( const CCPLiwMap* aMap, 
   491         const CLiwDefaultList* aActionTriggers,
   493         const CLiwDefaultList* aActionTriggers,
   492 		const TLiwGenericParam* aParam,	
   494 		const TLiwGenericParam* aParam,	
       
   495 		const CLiwDefaultMap* aActionMap,
   493 		CLiwDefaultList* aChangeInfoList )
   496 		CLiwDefaultList* aChangeInfoList )
   494 	{
   497 	{
   495 	TLiwVariant resultVar = aParam->Value();
   498 	TLiwVariant resultVar = aParam->Value();
   496     resultVar.PushL();
   499     resultVar.PushL();
   497 	if ( resultVar.TypeId() == EVariantTypeMap )
   500 	if ( resultVar.TypeId() == EVariantTypeMap )
   498         {
   501         {
   499         for ( TInt i = 0; i<aActionTriggers->Count(); i++ )
   502         for ( TInt i = 0; i<aActionTriggers->Count(); i++ )
   500             {
   503             {
   501             CLiwDefaultMap* changeInfoMap = CLiwDefaultMap::NewLC(); 
   504             TLiwVariant dummyVariant;
   502         
   505             dummyVariant.PushL();
   503             CopyVariantL(KId, resultVar.AsMap(), changeInfoMap );
       
   504             CopyVariantL(KPublisherId, resultVar.AsMap(), changeInfoMap );
       
   505             CopyVariantL(KContentType, resultVar.AsMap(), changeInfoMap );
       
   506             CopyVariantL(KContentId, resultVar.AsMap(), changeInfoMap );
       
   507             CopyVariantL(KFlag, resultVar.AsMap(), changeInfoMap );
       
   508             CopyVariantL(KType, aMap, changeInfoMap );
       
   509     
       
   510             TLiwVariant trigger;
   506             TLiwVariant trigger;
   511             trigger.PushL();
   507             trigger.PushL();
   512             aActionTriggers->AtL(i,trigger);
   508             aActionTriggers->AtL(i,trigger);
   513             changeInfoMap->InsertL(KActionTrigger, trigger);
   509             if (aActionMap->FindL( trigger.AsData(), dummyVariant ))
   514             CopyActionTrigger16L(trigger,changeInfoMap);
   510                 {
       
   511                 CLiwDefaultMap* changeInfoMap = CLiwDefaultMap::NewLC();
       
   512                 CopyVariantL(KId, resultVar.AsMap(), changeInfoMap);
       
   513                 CopyVariantL(KPublisherId, resultVar.AsMap(), changeInfoMap);
       
   514                 CopyVariantL(KContentType, resultVar.AsMap(), changeInfoMap);
       
   515                 CopyVariantL(KContentId, resultVar.AsMap(), changeInfoMap);
       
   516                 CopyVariantL(KFlag, resultVar.AsMap(), changeInfoMap);
       
   517                 CopyVariantL(KType, aMap, changeInfoMap);
       
   518                 changeInfoMap->InsertL(KActionTrigger, trigger);
       
   519                 CopyActionTrigger16L(trigger, changeInfoMap);
       
   520                 changeInfoMap->InsertL(KOperation, TLiwVariant(
       
   521                         KOperationExecute));
       
   522                 aChangeInfoList->AppendL(TLiwVariant(changeInfoMap));
       
   523                 CleanupStack::PopAndDestroy(changeInfoMap);
       
   524                 }
   515             CleanupStack::PopAndDestroy(&trigger);
   525             CleanupStack::PopAndDestroy(&trigger);
   516             
   526             CleanupStack::PopAndDestroy(&dummyVariant);
   517             changeInfoMap->InsertL( KOperation, TLiwVariant( KOperationExecute ) );
       
   518         
       
   519             aChangeInfoList->AppendL( TLiwVariant( changeInfoMap ) );
       
   520             CleanupStack::PopAndDestroy( changeInfoMap );
       
   521             }
   527             }
   522         }
   528         }
   523     CleanupStack::PopAndDestroy( &resultVar );
   529     CleanupStack::PopAndDestroy( &resultVar );
   524 	}
   530 	}
   525 
       
   526 
   531 
   527 // -----------------------------------------------------------------------------
   532 // -----------------------------------------------------------------------------
   528 // 
   533 // 
   529 // -----------------------------------------------------------------------------
   534 // -----------------------------------------------------------------------------
   530 //    
   535 //