taskswitcher/contextengine/tsfswserver/engine/src/tscpsnotifier.cpp
branchRCL_3
changeset 30 b8fae6b8a148
child 34 d05a55b217df
equal deleted inserted replaced
16:9674c1a575e9 30:b8fae6b8a148
       
     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 the License "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:  Internal class definition for WidgetUI application.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include "tscpsnotifier.h"
       
    20 #include "tsfswengine.h"
       
    21 #include <LiwServiceHandler.h>
       
    22 #include <LiwVariant.h>
       
    23 #include <LiwGenericParam.h>
       
    24 #include <Liwcommon.h>
       
    25 #include <liwcommon.hrh>
       
    26 
       
    27 _LIT8( KCPService, "Service.ContentPublishing" );
       
    28 _LIT8( KCPInterface, "IDataSource" );
       
    29 
       
    30 _LIT8( KType, "type" );
       
    31 _LIT( KCpData, "cp_data" );
       
    32 
       
    33 _LIT8( KPublisherId, "publisher" );
       
    34 _LIT8( KContentType, "content_type" );
       
    35 _LIT8( KContentId, "content_id" );
       
    36 
       
    37 _LIT8( KGetList, "GetList");
       
    38 _LIT8( KDataMap, "data_map" );
       
    39 _LIT8( KWidgetId, "widget_id");
       
    40 _LIT8( KBitmapHandle, "bitmap_handle");
       
    41 
       
    42 _LIT( KWidgetUi, "widget_ui");
       
    43 _LIT( KScreenshot, "screenshot");
       
    44 
       
    45 _LIT8( KFilter, "filter" );
       
    46 _LIT8( KResults,      "results");
       
    47 _LIT8( KOperation, "operation" );
       
    48 _LIT8( KRequestNotification, "RequestNotification" );
       
    49 _LIT( KUpdate, "update" );
       
    50 _LIT( K16Add, "add" );
       
    51 _LIT( KAddUpdate, "add:update" );
       
    52 _LIT8( KChangeInfo, "change_info" );
       
    53 
       
    54 _LIT( KAll, "all");
       
    55 
       
    56 // ================= MEMBER FUNCTIONS =======================
       
    57 
       
    58 // --------------------------------------------------------------------------
       
    59 // CTSCpsNotifier::NewL
       
    60 // --------------------------------------------------------------------------
       
    61 //
       
    62 CTSCpsNotifier* CTSCpsNotifier::NewL(CTsFswEngine& aEngine )
       
    63     {
       
    64     CTSCpsNotifier* self = new (ELeave) CTSCpsNotifier(aEngine);
       
    65     CleanupStack::PushL( self );
       
    66     self->ConstructL();
       
    67     CleanupStack::Pop();
       
    68     return self;
       
    69     }
       
    70 
       
    71 // --------------------------------------------------------------------------
       
    72 // CTSCpsNotifier::~CTSCpsNotifier
       
    73 // --------------------------------------------------------------------------
       
    74 //
       
    75 CTSCpsNotifier::~CTSCpsNotifier()
       
    76     {
       
    77     TRAP_IGNORE(ExecuteRegistrationCommandL( KLiwOptCancel ));
       
    78     
       
    79     if( iCpsInterface )
       
    80         {
       
    81         iCpsInterface->Close();
       
    82         iCpsInterface = NULL;
       
    83         }
       
    84     if( iServiceHandler )
       
    85         {
       
    86         iServiceHandler->Reset();
       
    87         delete iServiceHandler;
       
    88         iServiceHandler = NULL;
       
    89         }
       
    90     }
       
    91 
       
    92 // --------------------------------------------------------------------------
       
    93 // CTSCpsNotifier::CTSCpsNotifier
       
    94 // --------------------------------------------------------------------------
       
    95 //
       
    96 CTSCpsNotifier::CTSCpsNotifier(CTsFswEngine& aEngine):
       
    97     iEngine(aEngine)
       
    98     {
       
    99     }
       
   100 
       
   101 // --------------------------------------------------------------------------
       
   102 // CTSCpsNotifier::ConstructL
       
   103 // --------------------------------------------------------------------------
       
   104 //
       
   105 void CTSCpsNotifier::ConstructL()
       
   106     {
       
   107     InitCpsInterfaceL();
       
   108     ExecuteRegistrationCommandL( 0 );
       
   109     }
       
   110 
       
   111 // --------------------------------------------------------------------------
       
   112 // CTSCpsNotifier::WidgetFilterLC
       
   113 // --------------------------------------------------------------------------
       
   114 //
       
   115 CLiwDefaultMap* CTSCpsNotifier::WidgetFilterLC()
       
   116     {
       
   117     //Create filter criteria for requested entries in form of LIW map:
       
   118     CLiwDefaultMap* filter = CLiwDefaultMap::NewLC();
       
   119     filter->InsertL( KPublisherId, TLiwVariant(  KWidgetUi ));
       
   120     filter->InsertL( KContentType, TLiwVariant( KScreenshot ));
       
   121     return filter;
       
   122     }
       
   123 
       
   124 // --------------------------------------------------------------------------
       
   125 // CTSCpsNotifier::ExecuteRegistrationCommandL
       
   126 // --------------------------------------------------------------------------
       
   127 //
       
   128 void CTSCpsNotifier::ExecuteRegistrationCommandL( 
       
   129     TUint aOption )
       
   130     {
       
   131     CLiwDefaultMap* filter = WidgetFilterLC();
       
   132     filter->InsertL( KContentId, TLiwVariant( KAll ));
       
   133     filter->InsertL( KOperation, TLiwVariant( KAddUpdate ));
       
   134     
       
   135     CLiwGenericParamList& inParamList = iServiceHandler->InParamListL();
       
   136     CLiwGenericParamList& outParamList = iServiceHandler->OutParamListL();
       
   137         
       
   138     // Fill in input list for RequestNotification command
       
   139     inParamList.AppendL( TLiwGenericParam( KType, TLiwVariant( KCpData )));
       
   140     inParamList.AppendL( TLiwGenericParam( KFilter, TLiwVariant( filter )));
       
   141         
       
   142     iCpsInterface->ExecuteCmdL( 
       
   143                 KRequestNotification,
       
   144                 inParamList,
       
   145                 outParamList,
       
   146                 aOption,
       
   147                 this );
       
   148     
       
   149     outParamList.Reset();
       
   150     inParamList.Reset(); 
       
   151     CleanupStack::PopAndDestroy( filter );
       
   152     }
       
   153 
       
   154 // --------------------------------------------------------------------------
       
   155 // CTSCpsNotifier::HandleNotifyL
       
   156 // --------------------------------------------------------------------------
       
   157 //
       
   158 TInt CTSCpsNotifier::HandleNotifyL(
       
   159     TInt /*aCmdId*/,
       
   160     TInt /*aEventId*/,
       
   161     CLiwGenericParamList& aEventParamList,
       
   162     const CLiwGenericParamList& /*aInParamList*/ )
       
   163     {
       
   164     TInt pos(0);
       
   165     aEventParamList.FindFirst( pos, KChangeInfo );
       
   166     if (pos != KErrNotFound)
       
   167         {
       
   168         // Get list of maps
       
   169         TLiwVariant variant = ( aEventParamList )[pos].Value();
       
   170         variant.PushL();
       
   171         const CLiwList* changeMapsList = variant.AsList();
       
   172 
       
   173         TPtrC operation;
       
   174         // Iter through list content
       
   175         for (TInt i = 0; i < changeMapsList->Count(); ++i)
       
   176             {
       
   177              if ( changeMapsList->AtL( i, variant )) 
       
   178                  {
       
   179                  const CLiwMap* changeMap  = variant.AsMap();
       
   180                  // Check what triggered a notification
       
   181                  if ( changeMap->FindL( KOperation, variant ))
       
   182                      {
       
   183                      operation.Set( variant.AsDes());
       
   184                      }
       
   185                  if (!operation.Compare(KUpdate) || !operation.Compare(K16Add))
       
   186                      {
       
   187                      HandleWidgetUpdateL( *changeMap );
       
   188                      }
       
   189                  }
       
   190             }
       
   191         CleanupStack::PopAndDestroy( &variant );
       
   192         }
       
   193     return KErrNone;
       
   194     }
       
   195 
       
   196 // --------------------------------------------------------------------------
       
   197 // CTSCpsNotifier::InitCpsInterfaceL
       
   198 // --------------------------------------------------------------------------
       
   199 //
       
   200 void CTSCpsNotifier::InitCpsInterfaceL()
       
   201     {
       
   202     if( !iServiceHandler )
       
   203         {
       
   204         iServiceHandler = CLiwServiceHandler::NewL();
       
   205         }
       
   206     
       
   207     CLiwGenericParamList& inParam = iServiceHandler->InParamListL();
       
   208     CLiwGenericParamList& outParam = iServiceHandler->OutParamListL();
       
   209     
       
   210     CLiwCriteriaItem* crit = CLiwCriteriaItem::NewLC( KLiwCmdAsStr, KCPInterface,
       
   211         KCPService  );
       
   212     crit->SetServiceClass( TUid::Uid(KLiwClassBase) );
       
   213     
       
   214     RCriteriaArray a;
       
   215     a.AppendL(crit);    
       
   216     iServiceHandler->AttachL( a );
       
   217 	CleanupStack::Pop(crit);
       
   218     iServiceHandler->ExecuteServiceCmdL( *crit, inParam, outParam ); 
       
   219     delete crit;
       
   220     a.Reset();
       
   221         
       
   222     // find service interface
       
   223     TInt pos = 0;
       
   224     MLiwInterface* msgInterface = NULL;
       
   225     outParam.FindFirst( pos, KCPInterface );
       
   226     if ( pos != KErrNotFound ) 
       
   227         {
       
   228         msgInterface = (outParam)[pos].Value().AsInterface(); 
       
   229         }
       
   230     
       
   231     outParam.Reset();
       
   232     inParam.Reset();    
       
   233     iCpsInterface = msgInterface;
       
   234     }
       
   235 
       
   236 // --------------------------------------------------------------------------
       
   237 // CTSCpsNotifier::HandleWidgetUpdateL
       
   238 // --------------------------------------------------------------------------
       
   239 //
       
   240 void CTSCpsNotifier::HandleWidgetUpdateL(const CLiwMap& aChangeMap)
       
   241     {
       
   242     //ectract content_id which is widget bundled name
       
   243     TPtrC contentid;
       
   244     TLiwVariant contentIdVar;
       
   245     contentIdVar.PushL();
       
   246     if (aChangeMap.FindL(KContentId, contentIdVar))
       
   247         {
       
   248         contentid.Set( contentIdVar.AsDes());
       
   249         }
       
   250     
       
   251     TInt widgetId(0);
       
   252     TInt bitmapHandle(0);
       
   253     GetWidgetDataL(contentid, widgetId, bitmapHandle);
       
   254     iEngine.HandleWidgetUpdateL(widgetId, bitmapHandle );
       
   255     CleanupStack::PopAndDestroy( &contentIdVar );
       
   256     }
       
   257 
       
   258 // --------------------------------------------------------------------------
       
   259 // CTSCpsNotifier::GetWidgetData
       
   260 // --------------------------------------------------------------------------
       
   261 //
       
   262 void CTSCpsNotifier::GetWidgetDataL(const TDesC& aContentId, TInt& aWidgetId,
       
   263         TInt& aBitmapHandle)
       
   264     {
       
   265     CLiwGenericParamList* inParamList  = &iServiceHandler->InParamListL();
       
   266     CLiwGenericParamList* outParamList = &iServiceHandler->OutParamListL();
       
   267 
       
   268     TLiwGenericParam type( KType, TLiwVariant( KCpData ) );
       
   269     inParamList->AppendL( type );
       
   270     
       
   271     //append filter to input param
       
   272     CLiwDefaultMap* filter = WidgetFilterLC();
       
   273     filter->InsertL(KContentId, TLiwVariant(aContentId));
       
   274     TLiwGenericParam item( KFilter, filter);
       
   275     inParamList->AppendL( item );
       
   276      
       
   277     // It is assumed that interface is already initiated
       
   278     iCpsInterface->ExecuteCmdL( KGetList, *inParamList, *outParamList);
       
   279 
       
   280     type.Reset();
       
   281     item.Reset();
       
   282     inParamList->Reset();
       
   283     
       
   284     //extracts data map
       
   285     TInt pos = 0;
       
   286     outParamList->FindFirst( pos, KResults );
       
   287     if( pos != KErrNotFound )
       
   288         // results present
       
   289         {
       
   290         //extract iterator on results list
       
   291         TLiwVariant variant = (*outParamList)[pos].Value();
       
   292         CLiwIterable* iterable = variant.AsIterable();
       
   293         iterable->Reset();
       
   294         
       
   295         //get next result
       
   296         if( iterable->NextL( variant ) )
       
   297             {
       
   298             //extract content map
       
   299             CLiwDefaultMap *map = CLiwDefaultMap::NewLC();
       
   300             variant.Get( *map );
       
   301             if( map && map->FindL( KDataMap, variant) )
       
   302                 {
       
   303                 CLiwDefaultMap *dataMap = CLiwDefaultMap::NewLC();
       
   304                 variant.Get( *dataMap );
       
   305                 if( dataMap )
       
   306                     {
       
   307                     GetWidgetDataFromDataMapL(*dataMap, aWidgetId, aBitmapHandle);
       
   308                     }
       
   309                 CleanupStack::PopAndDestroy( dataMap );
       
   310                 }
       
   311             variant.Reset();
       
   312             CleanupStack::PopAndDestroy( map );
       
   313             }
       
   314         iterable->Reset();
       
   315         }
       
   316     outParamList->Reset();
       
   317     CleanupStack::PopAndDestroy( filter );
       
   318     }
       
   319 
       
   320 // --------------------------------------------------------------------------
       
   321 // CTSCpsNotifier::GetWidgetDataFromDataMap
       
   322 // --------------------------------------------------------------------------
       
   323 //
       
   324 void CTSCpsNotifier::GetWidgetDataFromDataMapL(const CLiwMap& aDataMap, 
       
   325         TInt& aWidgetId, TInt& aBitmapHandle)
       
   326     {
       
   327     TLiwVariant bitmapHandleVar;
       
   328     bitmapHandleVar.PushL();
       
   329     if( aDataMap.FindL( KBitmapHandle, bitmapHandleVar ))
       
   330         {
       
   331         aBitmapHandle = bitmapHandleVar.AsTInt32();
       
   332         }
       
   333     CleanupStack::PopAndDestroy(&bitmapHandleVar);
       
   334 
       
   335     TLiwVariant widgetIdVar;
       
   336     widgetIdVar.PushL();
       
   337     if( aDataMap.FindL( KWidgetId, widgetIdVar ))
       
   338         {
       
   339         aWidgetId = widgetIdVar.AsTInt32();
       
   340         }
       
   341     CleanupStack::PopAndDestroy(&widgetIdVar);
       
   342     }
       
   343 
       
   344 // END OF FILE
       
   345 
       
   346 
       
   347     
       
   348