idlefw/plugins/wrtdataplugin/src/wrtdataobserver.cpp
branchRCL_3
changeset 30 a5a39a295112
equal deleted inserted replaced
29:0efa10d348c0 30:a5a39a295112
       
     1 /*
       
     2 * Copyright (c) 2005-2007 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 * Plug-in main class
       
    16 *
       
    17 */
       
    18 
       
    19 
       
    20 // INCLUDE FILES
       
    21 #include <liwservicehandler.h>
       
    22 #include <liwvariant.h>
       
    23 #include <liwgenericparam.h>
       
    24 #include <s32mem.h>
       
    25 #include "wrtdata.h"
       
    26 #include "wrtdataobserver.h"
       
    27 #include "wrtdatapluginconst.h"
       
    28 
       
    29 _LIT8( KErrorCode, "ErrorCode" );
       
    30 _LIT8( KTransactionId, "TransactionID" );
       
    31 
       
    32 // ---------------------------------------------------------------------------
       
    33 // Factory method construction
       
    34 // ---------------------------------------------------------------------------
       
    35 //
       
    36 CWrtDataObserver * CWrtDataObserver::NewL( MLiwInterface* aInterface, CWrtData* aData )
       
    37     {
       
    38     CWrtDataObserver * self = new (ELeave) CWrtDataObserver();
       
    39     CleanupStack::PushL( self );
       
    40     self->ConstructL( aInterface, aData );
       
    41     CleanupStack::Pop( self );
       
    42     return self;    
       
    43     }
       
    44 
       
    45 
       
    46 // ---------------------------------------------------------------------------
       
    47 // 2n phase constructor
       
    48 // ---------------------------------------------------------------------------
       
    49 //
       
    50 void CWrtDataObserver::ConstructL( MLiwInterface* aInterface, CWrtData* aData )
       
    51     {
       
    52     iData = aData;
       
    53     iInterface = aInterface;
       
    54     }
       
    55 
       
    56 // ---------------------------------------------------------------------------
       
    57 // Constructor
       
    58 // ---------------------------------------------------------------------------
       
    59 //
       
    60 CWrtDataObserver::CWrtDataObserver ()
       
    61     {    
       
    62     }
       
    63         
       
    64 // ---------------------------------------------------------------------------
       
    65 // Destructor
       
    66 // ---------------------------------------------------------------------------
       
    67 //
       
    68 CWrtDataObserver ::~CWrtDataObserver ()
       
    69     {
       
    70     TRAP_IGNORE( ReleaseL() );
       
    71     
       
    72     iInterface = NULL;
       
    73     iData = NULL;
       
    74     }
       
    75 
       
    76 // ---------------------------------------------------------------------------
       
    77 // CWrtDataObserver::HandleNotifyL
       
    78 // Handles Published content notification
       
    79 // ---------------------------------------------------------------------------
       
    80 //
       
    81 TInt CWrtDataObserver::HandleNotifyL(
       
    82         TInt aErrorCode,
       
    83         TInt /*aEventId*/,
       
    84         CLiwGenericParamList& aEventParamList,
       
    85         const CLiwGenericParamList& /*aInParamList*/ )
       
    86     {
       
    87      
       
    88     // Is plugin active to refresh the published data
       
    89 	iError = aErrorCode;        
       
    90 	TInt count(0);
       
    91 	TInt pos(0);
       
    92 	const TLiwGenericParam* param(NULL);
       
    93 	CLiwDefaultList* listOfMaps = CLiwDefaultList::NewLC();
       
    94 	param = aEventParamList.FindFirst(pos,KChangeInfo);
       
    95 	if( param )
       
    96 		{
       
    97 		 User::LeaveIfError( param->Value().Get( *listOfMaps ) );
       
    98 		 count = listOfMaps->Count();
       
    99 		}
       
   100 	TLiwVariant variant;
       
   101 	// Extract the data from the map 
       
   102 	for(TInt i = 0;i < count; i++)
       
   103 		{
       
   104 		listOfMaps->AtL(i,variant);
       
   105 		HBufC16* operation = NULL;
       
   106 
       
   107 		CLiwDefaultMap *map = CLiwDefaultMap::NewLC();
       
   108 		variant.Get( *map );
       
   109 		if (map->FindL( KOperation, variant ))
       
   110 		   {
       
   111 		   operation = variant.AsDes().AllocLC();
       
   112 	       variant.Reset();
       
   113             if( operation->Des() != KOperationExecute )
       
   114                {
       
   115                // Nothing to update for execute action
       
   116                if ( map->FindL( KFLAG, variant ))
       
   117                    {
       
   118                    // notification from publisher registry
       
   119                   if ( operation->Des() !=  KOperationDelete )
       
   120                       {
       
   121                       iData->UpdatePublisherStatusL();
       
   122                       }
       
   123                    }
       
   124                // ignore update if plugin is in suspend mode
       
   125                else if ( iData->IsPluginActive() ) 
       
   126                    {
       
   127                    HBufC16* contentId = NULL; 
       
   128                    CLiwDefaultMap* dataMap = NULL;
       
   129                     // Get the data Map if available
       
   130                     if ( map->FindL( KDataMap, variant))
       
   131                         {
       
   132                         TPtrC8 data = variant.AsData();
       
   133                         RDesReadStream datastrm ( data );
       
   134                         dataMap = CLiwDefaultMap::NewLC(datastrm);
       
   135                         }
       
   136                     // Get the content Id
       
   137                    if ( map->FindL( KContentId, variant ))
       
   138                        {
       
   139                        contentId = variant.AsDes().AllocLC();
       
   140                        // Refresh only if contentId is retrieved
       
   141                        iData->RefreshL( *contentId, *operation, dataMap );
       
   142                        CleanupStack::PopAndDestroy( contentId );
       
   143                        }
       
   144 
       
   145                    if ( dataMap )
       
   146                         {
       
   147                         CleanupStack::PopAndDestroy( dataMap );
       
   148                         }
       
   149                    }
       
   150                  variant.Reset();
       
   151                }
       
   152             if ( operation )
       
   153                 {
       
   154                 CleanupStack::PopAndDestroy( operation );
       
   155                 }
       
   156 		     }
       
   157 		CleanupStack::PopAndDestroy( map );
       
   158 		}
       
   159 	CleanupStack::PopAndDestroy( listOfMaps );
       
   160 	
       
   161     return aErrorCode;
       
   162     }
       
   163 
       
   164 // ---------------------------------------------------------------------------
       
   165 // CWrtDataObserver::RegisterL
       
   166 // Register for notifications
       
   167 // ---------------------------------------------------------------------------
       
   168 //
       
   169 void CWrtDataObserver::RegisterL( CLiwDefaultMap* aFilter )
       
   170     {
       
   171     CLiwGenericParamList* inParamList = CLiwGenericParamList::NewL();
       
   172     CleanupStack::PushL( inParamList );
       
   173     
       
   174     CLiwGenericParamList* outParamList = CLiwGenericParamList::NewL();
       
   175     CleanupStack::PushL( outParamList );
       
   176         
       
   177     // Fill in input list for RequestNotification command
       
   178     inParamList->AppendL(
       
   179         TLiwGenericParam( KType, TLiwVariant( KCpData_PubData ) ) );
       
   180     
       
   181     inParamList->AppendL(
       
   182         TLiwGenericParam( KFilter, TLiwVariant( aFilter ) ) );
       
   183         
       
   184     iError = KErrNone;
       
   185     TRAP( iError, iInterface->ExecuteCmdL( 
       
   186                 KRequestNotification,
       
   187                 *inParamList,
       
   188                 *outParamList,
       
   189                 0,
       
   190                 this ) );
       
   191            
       
   192     TInt pos( 0 );
       
   193     
       
   194     const TLiwGenericParam* outParam( 
       
   195         outParamList->FindFirst( pos, KErrorCode ) );
       
   196     
       
   197     if ( outParam )
       
   198         {
       
   199         TInt retval( outParam->Value().AsTInt32() );
       
   200         
       
   201         if( retval == KErrNone )
       
   202             {
       
   203             pos = 0;
       
   204             outParam = outParamList->FindFirst( pos, KTransactionId );
       
   205                     
       
   206             if ( outParam )
       
   207                 {
       
   208                 iTransactionId = outParam->Value().AsTInt32();            
       
   209                 }            
       
   210             }                
       
   211         }
       
   212                
       
   213     CleanupStack::PopAndDestroy( 2, inParamList ); 
       
   214     }
       
   215 
       
   216 // ---------------------------------------------------------------------------
       
   217 // CWrtDataObserver ::ReleaseL
       
   218 // Sing off to notification
       
   219 // ---------------------------------------------------------------------------
       
   220 //
       
   221 void CWrtDataObserver::ReleaseL()
       
   222     {
       
   223     if( !iInterface )
       
   224         {
       
   225         return;
       
   226         }
       
   227     
       
   228     CLiwGenericParamList* inParamList = CLiwGenericParamList::NewL();
       
   229     CleanupStack::PushL( inParamList );
       
   230     
       
   231     CLiwGenericParamList* outParamList = CLiwGenericParamList::NewL();
       
   232     CleanupStack::PushL( outParamList );
       
   233        
       
   234     inParamList->AppendL( TLiwGenericParam( KTransactionId,
       
   235         TLiwVariant( iTransactionId ) ) ); 
       
   236             
       
   237     TRAP_IGNORE( iInterface->ExecuteCmdL( 
       
   238             KRequestNotification,
       
   239             *inParamList,
       
   240             *outParamList,
       
   241             KLiwOptCancel,
       
   242             this ) );
       
   243             
       
   244     CleanupStack::PopAndDestroy( 2, inParamList );
       
   245     }
       
   246 
       
   247 // End of file