idlefw/plugins/sapidataplugin/src/sapidataobserver.cpp
changeset 0 79c6a41cd166
child 1 844b978f8d5e
equal deleted inserted replaced
-1:000000000000 0:79c6a41cd166
       
     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:  Plug-in main class
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include <LiwServiceHandler.h>
       
    20 #include <LiwVariant.h>
       
    21 #include <LiwGenericParam.h>
       
    22 #include "sapidata.h"
       
    23 #include "sapidataobserver.h"
       
    24 #include "sapidatapluginconst.h"
       
    25 // ---------------------------------------------------------------------------
       
    26 // Constructor
       
    27 // ---------------------------------------------------------------------------
       
    28 //
       
    29 CSapiDataObserver::CSapiDataObserver ()
       
    30     {
       
    31 
       
    32     }
       
    33         
       
    34 // ---------------------------------------------------------------------------
       
    35 // Destructor
       
    36 // ---------------------------------------------------------------------------
       
    37 //
       
    38 CSapiDataObserver ::~CSapiDataObserver ()
       
    39     {
       
    40     iInterface = NULL;
       
    41     iData = NULL;
       
    42     }
       
    43 
       
    44 // ---------------------------------------------------------------------------
       
    45 // Register for notifications
       
    46 // ---------------------------------------------------------------------------
       
    47 //
       
    48 void CSapiDataObserver::RegisterL( CLiwDefaultMap* aFilter, const TDesC& aRegistry )
       
    49     {
       
    50     CLiwGenericParamList* inParamList = CLiwGenericParamList::NewL();
       
    51     CleanupStack::PushL( inParamList );
       
    52     CLiwGenericParamList* outParamList = CLiwGenericParamList::NewL();
       
    53     CleanupStack::PushL( outParamList );
       
    54         
       
    55     // Fill in input list for RequestNotification command
       
    56     inParamList->AppendL(TLiwGenericParam(KType,TLiwVariant(aRegistry)));
       
    57     inParamList->AppendL(TLiwGenericParam(KFilter ,TLiwVariant(aFilter)));
       
    58         
       
    59     iError = KErrNone;
       
    60     TRAP( iError, iInterface->ExecuteCmdL( 
       
    61                 KRequestNotification,
       
    62                 *inParamList,
       
    63                 *outParamList,
       
    64                 0,
       
    65                 this ) );
       
    66     
       
    67     CleanupStack::PopAndDestroy( outParamList );
       
    68     CleanupStack::PopAndDestroy( inParamList ); 
       
    69     }
       
    70 
       
    71 // ---------------------------------------------------------------------------
       
    72 // Sing off to notification
       
    73 // ---------------------------------------------------------------------------
       
    74 //
       
    75 void CSapiDataObserver ::ReleaseL()
       
    76     {
       
    77     if( iInterface )
       
    78         {
       
    79         CLiwGenericParamList* inParamList = CLiwGenericParamList::NewL();
       
    80         CleanupStack::PushL( inParamList );
       
    81         CLiwGenericParamList* outParamList = CLiwGenericParamList::NewL();
       
    82         CleanupStack::PushL( outParamList );
       
    83         
       
    84         TInt err(KErrNone);
       
    85         TRAP(err, iInterface->ExecuteCmdL( 
       
    86                 KRequestNotification,
       
    87                 *inParamList,
       
    88                 *outParamList,
       
    89                 KLiwOptCancel,
       
    90                 this ));
       
    91         
       
    92         CleanupStack::PopAndDestroy( outParamList );
       
    93         CleanupStack::PopAndDestroy( inParamList );
       
    94         }
       
    95     }
       
    96 
       
    97 // ---------------------------------------------------------------------------
       
    98 // Factory method construction
       
    99 // ---------------------------------------------------------------------------
       
   100 //
       
   101 CSapiDataObserver * CSapiDataObserver::NewL( MLiwInterface* aInterface, CSapiData* aData )
       
   102     {
       
   103     CSapiDataObserver * self = new (ELeave) CSapiDataObserver();
       
   104     CleanupStack::PushL( self );
       
   105     self->ConstructL( aInterface, aData );
       
   106     CleanupStack::Pop( self );
       
   107     return self;    
       
   108     }
       
   109         
       
   110 // ---------------------------------------------------------------------------
       
   111 // 2n phase constructor
       
   112 // ---------------------------------------------------------------------------
       
   113 //
       
   114 void CSapiDataObserver::ConstructL( MLiwInterface* aInterface, CSapiData* aData )
       
   115     {
       
   116     iData = aData;
       
   117     iInterface = aInterface;
       
   118     }
       
   119 
       
   120 // ---------------------------------------------------------------------------
       
   121 // Handles Published content notification
       
   122 // ---------------------------------------------------------------------------
       
   123 //
       
   124 TInt CSapiDataObserver::HandleNotifyL(
       
   125         TInt aErrorCode,
       
   126         TInt /*aEventId*/,
       
   127         CLiwGenericParamList& aEventParamList,
       
   128         const CLiwGenericParamList& /*aInParamList*/ )
       
   129     {
       
   130      
       
   131     // Is plugin active to refresh the published data
       
   132 	iError = aErrorCode;        
       
   133 	TInt count(0);
       
   134 	TInt pos(0);
       
   135 	const TLiwGenericParam* param(NULL);
       
   136 	CLiwDefaultList* listOfMaps = CLiwDefaultList::NewLC();
       
   137 	param = aEventParamList.FindFirst(pos,KChangeInfo);
       
   138 	if( param )
       
   139 		{
       
   140 		 User::LeaveIfError( param->Value().Get( *listOfMaps ) );
       
   141 		 count = listOfMaps->Count();
       
   142 		}
       
   143 	TLiwVariant variant;
       
   144 	// Extract the data from the map 
       
   145 	for(TInt i = 0;i < count; i++)
       
   146 		{
       
   147 		listOfMaps->AtL(i,variant);
       
   148 		HBufC* operation = NULL;
       
   149 
       
   150 		CLiwDefaultMap *map = CLiwDefaultMap::NewLC();
       
   151 		variant.Get( *map );
       
   152 		TBool found;
       
   153 		found = map->FindL( KOperation, variant );
       
   154 		if (found)
       
   155 		   {
       
   156 		   operation = variant.AsDes().AllocLC();
       
   157 		   }
       
   158 		variant.Reset();
       
   159 		if( operation->Des() != KOperationExecute )
       
   160 		   {
       
   161 		   // Nothing to update for execute action
       
   162 		   HBufC* publisher = NULL; 
       
   163 		   HBufC* contentType = NULL;
       
   164 		   HBufC* contentId = NULL;
       
   165 		   found = map->FindL( KPublisherId, variant );
       
   166 		   if (found)
       
   167 			   {
       
   168 			   publisher = variant.AsDes().AllocLC();
       
   169 			   }
       
   170 		   variant.Reset();
       
   171 		   found = map->FindL( KFLAG, variant );
       
   172 		   if ( found)
       
   173 			   {
       
   174 			   // notification from publisher registry
       
   175 			  if ( operation->Des() !=  KOperationDelete )
       
   176 				  {
       
   177 				  iData->UpdatePublisherStatusL( *publisher );
       
   178 				  }
       
   179 			   }
       
   180 		   else if ( iData->IsPluginActive() ) 
       
   181 			   { 
       
   182 			   // notification from content registry
       
   183 			   found = map->FindL( KContentType, variant );
       
   184 			   if (found)
       
   185 				  {
       
   186 				  contentType = variant.AsDes().AllocLC();
       
   187 				  }
       
   188 			   variant.Reset();
       
   189 			   found = map->FindL( KContentId, variant );
       
   190 			   if (found)
       
   191 				  {
       
   192 				  contentId = variant.AsDes().AllocLC();
       
   193 				  }
       
   194 			   variant.Reset();
       
   195 			   iData->RefreshL( *publisher, *contentType, *contentId, *operation );
       
   196 			   
       
   197 			   if ( contentId )
       
   198 				   {
       
   199 				   CleanupStack::PopAndDestroy( contentId );
       
   200 				   }
       
   201 			  if ( contentType )
       
   202 				   {
       
   203 				   CleanupStack::PopAndDestroy( contentType );
       
   204 				   }
       
   205 			   }
       
   206 		   else
       
   207 			   {
       
   208 			   // remember update if plugin is in suspend mode
       
   209 			   iData->SetUpdateNeeded( ETrue );
       
   210 			   }
       
   211 			variant.Reset();
       
   212 			 if ( publisher )
       
   213 			   {
       
   214 			   CleanupStack::PopAndDestroy( publisher );
       
   215 			   }
       
   216 		   }
       
   217 		if ( operation )
       
   218 			{
       
   219 			CleanupStack::PopAndDestroy( operation );
       
   220 			}
       
   221 		CleanupStack::PopAndDestroy( map );
       
   222 		}
       
   223 	CleanupStack::PopAndDestroy( listOfMaps );
       
   224 	
       
   225     return aErrorCode;
       
   226     }
       
   227