data/publisherif/src/hspublisherimpl.cpp
changeset 0 b856a9924bbc
equal deleted inserted replaced
-1:000000000000 0:b856a9924bbc
       
     1 /*
       
     2 * Copyright (c) {Year(s)} {Copyright owner}.
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of the "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.symbianfoundation.org/legal/sfl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * {Name} {Company} ? Initial contribution
       
    11 *
       
    12 * Contributors:
       
    13 * {Name} {Company} ? {{Description of contribution}}
       
    14 *
       
    15 * Description:
       
    16 * {{Description of the file}}
       
    17 *
       
    18 */
       
    19 
       
    20 // System includes  
       
    21 #include <liwservicehandler.h>
       
    22 #include <liwvariant.h>
       
    23 #include <liwgenericparam.h>
       
    24 #include <fbs.h>
       
    25 
       
    26 // User includes
       
    27 #include "transaction.h"
       
    28 #include "hswidgetobserver.h"
       
    29 #include "hspublisherimpl.h"  
       
    30 
       
    31 // Constants
       
    32 _LIT8( KCPSConfigurationIf, "IContentPublishing" );
       
    33 _LIT8( KCPS, "Service.ContentPublishing" );
       
    34 
       
    35 _LIT( KCpData, "cp_data" );
       
    36 
       
    37 _LIT( KHsWidget, "hswidget" );
       
    38 _LIT( KPublisher, "publisher" );
       
    39 _LIT( KAll, "all" );
       
    40 
       
    41 _LIT( KDataAndPublisher, "cp_data:publisher" );
       
    42 
       
    43 _LIT8( KAdd, "add" );
       
    44 _LIT8( KType, "type" );
       
    45 _LIT8( KFilter, "filter" );
       
    46 _LIT8( KFlag, "flag" );
       
    47 _LIT8( KErrorCode, "ErrorCode" );
       
    48 _LIT8( KDataMap, "data_map" );
       
    49 _LIT8( KItem, "item" );
       
    50 _LIT8( KDelete, "Delete" );
       
    51 _LIT8( KPublisherId, "publisher" );
       
    52 _LIT8( KContentType, "content_type" );
       
    53 _LIT8( KContentId, "content_id" );
       
    54 _LIT8( KOperation, "operation" );
       
    55 _LIT8( KExecute, "execute" );
       
    56     
       
    57 _LIT8( KRequestNotification, "RequestNotification" );
       
    58 _LIT8( KChangeInfo, "change_info" );
       
    59 _LIT8( KActionTrigger, "action_trigger" );
       
    60 
       
    61 _LIT8( KActionMap, "action_map" );
       
    62 _LIT8( KActive, "active" );
       
    63 
       
    64 _LIT8( KSuspend, "suspend" );
       
    65 _LIT8( KResume, "resume" );
       
    66 _LIT8( KOnline, "online" );
       
    67 _LIT8( KOffline, "offline" );
       
    68 
       
    69 _LIT8( KSystemStartup, "systemstartup" );
       
    70 _LIT8( KPageStartup, "pagestartup" );
       
    71 _LIT8( KWidgetStartup, "pluginstartup" );
       
    72 
       
    73 _LIT8( KSystemShutdown, "systemshutdown" );
       
    74 _LIT8( KPageShutdown, "pageshutdown" );
       
    75 _LIT8( KWidgetShutdown, "pluginshutdown" );
       
    76 
       
    77 const TUint KDisablePersist( 0x1000 );
       
    78 
       
    79 // Type definitions 
       
    80 typedef TBuf< 256 > TVariantBuf;
       
    81 typedef TBuf8< 256 > TVariantBuf8;
       
    82 
       
    83 
       
    84 // ============================= LOCAL FUNCTIONS ===============================
       
    85 
       
    86 // ============================ MEMBER FUNCTIONS ===============================
       
    87 // -----------------------------------------------------------------------------
       
    88 // CHsPublisherImpl::NewLC()
       
    89 // Two-phased constructor
       
    90 // -----------------------------------------------------------------------------
       
    91 //
       
    92 CHsPublisherImpl* CHsPublisherImpl::NewLC( MHsWidgetObserver& aObserver, 
       
    93     TBool aEnablePersist )    
       
    94     {
       
    95     CHsPublisherImpl* self = new ( ELeave ) 
       
    96         CHsPublisherImpl( aObserver, aEnablePersist );
       
    97     
       
    98     CleanupStack::PushL( self );
       
    99     self->ConstructL();
       
   100     return self;    
       
   101     }
       
   102 
       
   103 // -----------------------------------------------------------------------------
       
   104 // CHsPublisherImpl::NewL()
       
   105 // Two-phased constructor
       
   106 // -----------------------------------------------------------------------------
       
   107 //
       
   108 CHsPublisherImpl* CHsPublisherImpl::NewL( MHsWidgetObserver& aObserver, 
       
   109     TBool aEnablePersist )   
       
   110     {
       
   111     CHsPublisherImpl* self = 
       
   112         CHsPublisherImpl::NewLC( aObserver, aEnablePersist );
       
   113     CleanupStack::Pop( self );
       
   114     return self;
       
   115     }
       
   116 
       
   117 // -----------------------------------------------------------------------------
       
   118 // CHsPublisherImpl::CHsPublisherImpl()
       
   119 // C++ default constructor
       
   120 // -----------------------------------------------------------------------------
       
   121 //
       
   122 CHsPublisherImpl::CHsPublisherImpl( MHsWidgetObserver& aObserver, 
       
   123     TBool aEnablePersist )
       
   124     : iObserver( aObserver ), 
       
   125       iEnablePersist( aEnablePersist )             
       
   126     {
       
   127     }
       
   128 
       
   129 // -----------------------------------------------------------------------------
       
   130 // CHsPublisherImpl::ConstructL()
       
   131 // 2nd phase constructor
       
   132 // -----------------------------------------------------------------------------
       
   133 //
       
   134 void CHsPublisherImpl::ConstructL()
       
   135     {
       
   136     AttachL();
       
   137     }
       
   138 
       
   139 // -----------------------------------------------------------------------------
       
   140 // CHsPublisherImpl::~CHsPublisherImpl()
       
   141 // Destructor
       
   142 // -----------------------------------------------------------------------------
       
   143 //
       
   144 CHsPublisherImpl::~CHsPublisherImpl()
       
   145     {
       
   146     iTransactions.ResetAndDestroy();
       
   147            
       
   148     TRAP_IGNORE( DetachL() );    
       
   149     }
       
   150 
       
   151 // ---------------------------------------------------------------------------
       
   152 // CHsPublisherImpl::AttachL
       
   153 //
       
   154 // ---------------------------------------------------------------------------
       
   155 //
       
   156 void CHsPublisherImpl::AttachL()
       
   157     {            
       
   158     // Attach to CPS service
       
   159     RCriteriaArray interestList;
       
   160     CleanupClosePushL( interestList );
       
   161            
       
   162     iServiceHandler = CLiwServiceHandler::NewL();
       
   163                     
       
   164     iCpsService = CLiwCriteriaItem::NewL( 1, KCPSConfigurationIf, KCPS ); 
       
   165                   
       
   166     iCpsService->SetServiceClass( TUid::Uid( KLiwClassBase ) );
       
   167     
       
   168     interestList.AppendL( iCpsService );
       
   169     iServiceHandler->AttachL( interestList );
       
   170 
       
   171     CLiwGenericParamList& inParamList( iServiceHandler->InParamListL() );
       
   172     CLiwGenericParamList& outParamList( iServiceHandler->OutParamListL() );
       
   173     
       
   174     iServiceHandler->ExecuteServiceCmdL(
       
   175           *iCpsService,
       
   176           inParamList,
       
   177           outParamList );
       
   178     
       
   179     TInt pos( 0 );
       
   180            
       
   181     outParamList.FindFirst( pos, KCPSConfigurationIf );
       
   182            
       
   183     if ( pos != KErrNotFound )
       
   184         {
       
   185         iCpsInterface = outParamList[pos].Value().AsInterface();                       
       
   186         }
       
   187     
       
   188     inParamList.Reset();
       
   189     outParamList.Reset();
       
   190     
       
   191     if ( !iCpsInterface )
       
   192         {
       
   193         User::Leave( KErrNotFound );
       
   194         }
       
   195         
       
   196     const TDesC& publisherId( iObserver.Identity() );
       
   197     
       
   198     // Register Observer       
       
   199     CLiwDefaultMap* reqmap = CLiwDefaultMap::NewLC();
       
   200         
       
   201     reqmap->InsertL( KPublisherId, TLiwVariant( publisherId  ) );
       
   202     reqmap->InsertL( KContentType, TLiwVariant( KAll ) );
       
   203     reqmap->InsertL( KContentId, TLiwVariant( KAll ) );
       
   204     reqmap->InsertL( KOperation, TLiwVariant( KExecute ) );
       
   205 
       
   206     inParamList.AppendL( TLiwGenericParam( 
       
   207         KType, TLiwVariant( KDataAndPublisher ) ) );        
       
   208         
       
   209     inParamList.AppendL( TLiwGenericParam( 
       
   210         KFilter, TLiwVariant( reqmap ) ) );
       
   211         
       
   212     iCpsInterface->ExecuteCmdL( 
       
   213         KRequestNotification, inParamList, outParamList, 0, this ); 
       
   214 
       
   215     const TLiwGenericParam* outparam( NULL );
       
   216     
       
   217     pos = 0;
       
   218     
       
   219     outparam = outParamList.FindFirst( pos, KErrorCode );
       
   220     
       
   221     TInt err( KErrNone );
       
   222     
       
   223     if ( outparam )
       
   224         {                     
       
   225         if ( outparam->Value().AsTInt32() )
       
   226             {
       
   227             err = KErrGeneral;
       
   228             }
       
   229         }
       
   230 
       
   231     inParamList.Reset();
       
   232     outParamList.Reset();
       
   233         
       
   234     User::LeaveIfError( err );            
       
   235 
       
   236     CleanupStack::PopAndDestroy( reqmap ); 
       
   237         
       
   238     // Register Publisher                           
       
   239     CLiwDefaultMap* datamap = CLiwDefaultMap::NewLC();
       
   240     CLiwDefaultMap* actionmap = CLiwDefaultMap::NewLC();
       
   241     
       
   242     datamap->InsertL( KPublisherId, TLiwVariant( publisherId ) );
       
   243     datamap->InsertL( KContentType, TLiwVariant( KAll ) );
       
   244     datamap->InsertL( KContentId, TLiwVariant( KAll ) );
       
   245             
       
   246     actionmap->InsertL( KActive, TLiwVariant() );
       
   247         
       
   248     datamap->InsertL( KActionMap, TLiwVariant( actionmap ) );
       
   249 
       
   250     inParamList.AppendL( TLiwGenericParam( 
       
   251         KType, TLiwVariant( KPublisher ) ) );       
       
   252         
       
   253     inParamList.AppendL( TLiwGenericParam( 
       
   254         KItem, TLiwVariant( datamap ) ) );
       
   255     
       
   256     iCpsInterface->ExecuteCmdL( KAdd, inParamList, outParamList );
       
   257         
       
   258     outparam = NULL;
       
   259     
       
   260     pos = 0;
       
   261            
       
   262     outparam = outParamList.FindFirst( pos, KErrorCode );
       
   263     
       
   264     err = KErrNone;
       
   265     
       
   266     if ( outparam )
       
   267         {
       
   268         if ( outparam->Value().AsTInt32() )
       
   269             {
       
   270             err = KErrGeneral;
       
   271             }
       
   272         }
       
   273                 
       
   274     inParamList.Reset();
       
   275     outParamList.Reset();
       
   276     
       
   277     User::LeaveIfError( err );        
       
   278     
       
   279     CleanupStack::PopAndDestroy( 2, datamap ); // actionmap
       
   280                                             
       
   281     CleanupStack::PopAndDestroy( &interestList );
       
   282     
       
   283     iCpServiceAvailable = ETrue;       
       
   284     }
       
   285 
       
   286 // ---------------------------------------------------------------------------
       
   287 // CHsPublisherImpl::DetachL
       
   288 //
       
   289 // ---------------------------------------------------------------------------
       
   290 //
       
   291 void CHsPublisherImpl::DetachL()
       
   292     {     
       
   293     if ( iServiceHandler && iCpsInterface )
       
   294         {
       
   295         CLiwGenericParamList& inParamList( iServiceHandler->InParamListL() );
       
   296         CLiwGenericParamList& outParamList( iServiceHandler->OutParamListL() );
       
   297     
       
   298         // Remove widget data
       
   299         CLiwDefaultMap* cpdatamap = CLiwDefaultMap::NewLC();
       
   300         
       
   301         const TDesC& publisherId( iObserver.Identity() );
       
   302         
       
   303         cpdatamap->InsertL( KPublisherId, TLiwVariant( publisherId ) );
       
   304         cpdatamap->InsertL( KContentType, TLiwVariant( KAll ) );
       
   305         cpdatamap->InsertL( KContentId, TLiwVariant( KAll ) );
       
   306               
       
   307         inParamList.AppendL( TLiwGenericParam( 
       
   308             KType, TLiwVariant( KCpData ) ) );
       
   309         
       
   310         inParamList.AppendL( TLiwGenericParam( 
       
   311             KItem, TLiwVariant( cpdatamap ) ) );
       
   312         
       
   313         TRAP_IGNORE( iCpsInterface->ExecuteCmdL( 
       
   314             KDelete, inParamList, outParamList ) );
       
   315         
       
   316         inParamList.Reset();
       
   317         outParamList.Reset();
       
   318               
       
   319         CleanupStack::PopAndDestroy( cpdatamap );
       
   320 
       
   321         // Unregister Observer                 
       
   322         TRAP_IGNORE( iCpsInterface->ExecuteCmdL( 
       
   323                 KRequestNotification,
       
   324                 inParamList,
       
   325                 outParamList,
       
   326                 KLiwOptCancel,
       
   327                 this ) );
       
   328         
       
   329         // Detach from CPS service
       
   330         if ( iCpsInterface )
       
   331            {
       
   332            // Close interface
       
   333            iCpsInterface->Close();
       
   334            }
       
   335         
       
   336         iCpsInterface = NULL;
       
   337         
       
   338         if ( iServiceHandler && iCpsService )
       
   339             {                   
       
   340             // Detach services from the handler       
       
   341             RCriteriaArray list;
       
   342                  
       
   343             list.Append( iCpsService );
       
   344            
       
   345             TRAP_IGNORE( iServiceHandler->DetachL( list ) );    
       
   346             
       
   347             list.Reset();
       
   348             }        
       
   349         }    
       
   350     
       
   351     delete iCpsService;
       
   352     iCpsService = NULL;
       
   353     
       
   354     delete iServiceHandler;
       
   355     iServiceHandler = NULL;                    
       
   356        
       
   357     iCpServiceAvailable = EFalse;
       
   358     }
       
   359 
       
   360 // ---------------------------------------------------------------------------
       
   361 // CHsPublisherImpl::HandleNotifyL
       
   362 //
       
   363 // ---------------------------------------------------------------------------
       
   364 //
       
   365 TInt CHsPublisherImpl::HandleNotifyL( TInt /*aCmdId*/, TInt /*aEventId*/,               
       
   366     CLiwGenericParamList& aEventParamList,
       
   367     const CLiwGenericParamList& /*aInParamList*/ )
       
   368     {           
       
   369     TInt pos( 0 );
       
   370        
       
   371     aEventParamList.FindFirst( pos, KChangeInfo );
       
   372 
       
   373     if ( pos == KErrNotFound )
       
   374         {        
       
   375         return pos;
       
   376         }
       
   377     
       
   378     const TDesC& publisherId( iObserver.Identity() );
       
   379     
       
   380     // Get list of maps
       
   381     TLiwVariant listvariant( aEventParamList[pos].Value() );
       
   382     listvariant.PushL();
       
   383     
       
   384     const CLiwList* list( listvariant.AsList() );
       
   385             
       
   386     // Iterate through list 
       
   387     for ( TInt i = 0; i < list->Count(); i++ )
       
   388         {
       
   389         TVariantBuf publisher;
       
   390         TVariantBuf contenttype;
       
   391         TVariantBuf widgetid;
       
   392         
       
   393         TVariantBuf8 operation;
       
   394         TVariantBuf8 trigger;
       
   395                 
       
   396         TLiwVariant variant;
       
   397         variant.PushL();
       
   398         
       
   399         if ( list->AtL( i, variant ) ) 
       
   400             {
       
   401             const CLiwMap* map( variant.AsMap() ); 
       
   402         
       
   403             if( map->FindL( KPublisherId, variant ) )
       
   404                 {
       
   405                 variant.Get( publisher );
       
   406                 }
       
   407                     
       
   408             if ( publisher != publisherId )
       
   409                 {
       
   410                 // Not targeted to this publisher
       
   411                 continue;
       
   412                 }
       
   413             
       
   414             // Check what triggered a notification
       
   415             if ( map->FindL( KOperation, variant ) )
       
   416                 {
       
   417                 variant.Get( operation );
       
   418                 }
       
   419                                    
       
   420             if ( operation == KExecute() )
       
   421                 {                 
       
   422                 if ( map->FindL( KActionTrigger, variant ) )
       
   423                     {
       
   424                     variant.Get( trigger );
       
   425                     }
       
   426                 
       
   427                 if ( map->FindL( KContentId, variant ) )
       
   428                     {
       
   429                     variant.Get( widgetid );
       
   430                     }                               
       
   431                 
       
   432                 if ( map->FindL( KContentType, variant ) )
       
   433                     {
       
   434                     variant.Get( contenttype );
       
   435                     }
       
   436                 
       
   437                 if ( contenttype == KHsWidget() )
       
   438                     {
       
   439                     // HS specific notification    
       
   440                     ProcessEvent( widgetid, trigger );                    
       
   441                     }
       
   442                 else
       
   443                     {
       
   444                     // Widget specific notification                    
       
   445                     HBufC* param = HBufC::NewLC( trigger.Length() );                                       
       
   446                     param->Des().Copy( trigger );
       
   447                     
       
   448                     iObserver.NotifyWidgetEvent( 
       
   449                         widgetid, contenttype, *param );
       
   450                     
       
   451                     CleanupStack::PopAndDestroy( param );
       
   452                     }                
       
   453                 }                      
       
   454             
       
   455             CleanupStack::PopAndDestroy(); // variant
       
   456             }
       
   457         }                            
       
   458     
       
   459     CleanupStack::PopAndDestroy(); // listvariant       
       
   460     
       
   461     return KErrNone;
       
   462     }
       
   463 
       
   464 // -----------------------------------------------------------------------------
       
   465 // CHsPublisherImpl::ProcessEvent()
       
   466 // 
       
   467 // -----------------------------------------------------------------------------
       
   468 //
       
   469 void CHsPublisherImpl::ProcessEvent( const TDesC& aWidgetId, 
       
   470     const TDesC8& aEvent ) const
       
   471     {
       
   472     if ( aEvent == KResume() )
       
   473         {
       
   474         iObserver.NotifyWidgetState( 
       
   475             aWidgetId, MHsWidgetObserver::EAlive );
       
   476         }
       
   477     else if ( aEvent == KSuspend() )
       
   478         {
       
   479         iObserver.NotifyWidgetState( 
       
   480             aWidgetId, MHsWidgetObserver::ESuspend );
       
   481         }
       
   482     else if ( aEvent == KOnline() )
       
   483         {
       
   484         iObserver.NotifyWidgetState( 
       
   485             aWidgetId, MHsWidgetObserver::EOnline );
       
   486         }
       
   487     else if ( aEvent == KOffline() )
       
   488         {
       
   489         iObserver.NotifyWidgetState( 
       
   490             aWidgetId, MHsWidgetObserver::EOffline );
       
   491         }
       
   492     else if ( aEvent == KSystemStartup() )
       
   493         {
       
   494         iObserver.NotifyWidgetStarted( 
       
   495             aWidgetId, MHsWidgetObserver::ESystemStart );
       
   496         }
       
   497     else if ( aEvent == KPageStartup() )
       
   498         {
       
   499         iObserver.NotifyWidgetStarted( 
       
   500             aWidgetId, MHsWidgetObserver::EPageStart );    
       
   501         }
       
   502     else if ( aEvent == KWidgetStartup() )
       
   503         {
       
   504         iObserver.NotifyWidgetStarted( 
       
   505             aWidgetId, MHsWidgetObserver::EWidgetStart );    
       
   506         }
       
   507     else if ( aEvent == KSystemShutdown() )
       
   508         {
       
   509         iObserver.NotifyWidgetStopped( 
       
   510             aWidgetId, MHsWidgetObserver::ESystemStop );
       
   511         }
       
   512     else if ( aEvent == KPageShutdown() )
       
   513         {
       
   514         iObserver.NotifyWidgetStopped( 
       
   515             aWidgetId, MHsWidgetObserver::EPageStop );    
       
   516         }
       
   517     else if ( aEvent == KWidgetShutdown() )
       
   518         {
       
   519         iObserver.NotifyWidgetStopped( 
       
   520             aWidgetId, MHsWidgetObserver::EWidgetStop );    
       
   521         }
       
   522     }
       
   523 
       
   524 // -----------------------------------------------------------------------------
       
   525 // CHsPublisherImpl::PublishTextL()
       
   526 // 
       
   527 // -----------------------------------------------------------------------------
       
   528 //
       
   529 void CHsPublisherImpl::PublishTextL( const TDesC& aWidgetId,         
       
   530     const TDesC8& aElementId, const TDesC& aText )
       
   531     {
       
   532     __ASSERT_ALWAYS( iCpServiceAvailable, User::Invariant() );
       
   533     
       
   534     CTransaction* tr( Transaction( aWidgetId ) );
       
   535     
       
   536     if ( !tr )
       
   537         {
       
   538         // Transaction not started 
       
   539         User::Leave( KErrNotReady );
       
   540         }
       
   541     
       
   542     CTextTransactionItem* item = 
       
   543         new ( ELeave ) CTextTransactionItem( aElementId, aText ); 
       
   544 
       
   545     CleanupStack::PushL( item );
       
   546      
       
   547     tr->AppendL( item );
       
   548     CleanupStack::Pop( item );      
       
   549     }
       
   550   
       
   551 // -----------------------------------------------------------------------------
       
   552 // CHsPublisherImpl::PublishImageL()
       
   553 // 
       
   554 // -----------------------------------------------------------------------------
       
   555 //
       
   556 void CHsPublisherImpl::PublishImageL( const TDesC& aWidgetId,      
       
   557     const TDesC8& aElementId, const CFbsBitmap* aImage, const CFbsBitmap* aMask )
       
   558     {
       
   559     __ASSERT_ALWAYS( iCpServiceAvailable, User::Invariant() );
       
   560     
       
   561     TInt imageHandle( KErrBadHandle );
       
   562     TInt maskHandle( KErrBadHandle );
       
   563     
       
   564     if ( aImage )
       
   565         {
       
   566         imageHandle = aImage->Handle();
       
   567         }
       
   568     
       
   569     if ( aMask )
       
   570         {
       
   571         maskHandle = aMask->Handle();
       
   572         }
       
   573     
       
   574     PublishImageL( aWidgetId, aElementId, imageHandle, maskHandle );
       
   575     }
       
   576 
       
   577 // -----------------------------------------------------------------------------
       
   578 // CHsPublisherImpl::PublishImageL()
       
   579 // 
       
   580 // -----------------------------------------------------------------------------
       
   581 //
       
   582 void CHsPublisherImpl::PublishImageL( const TDesC& aWidgetId,      
       
   583     const TDesC8& aElementId, TInt aImageHandle, TInt aMaskHandle )
       
   584     {
       
   585     __ASSERT_ALWAYS( iCpServiceAvailable, User::Invariant() );
       
   586     
       
   587     CTransaction* tr( Transaction( aWidgetId ) );
       
   588     
       
   589     if ( !tr )
       
   590         {
       
   591         // Transaction not started 
       
   592         User::Leave( KErrNotReady );
       
   593         }
       
   594     
       
   595     CImageTransactionItem* item = 
       
   596         new ( ELeave ) CImageTransactionItem( 
       
   597             aElementId, aImageHandle, aMaskHandle );
       
   598     
       
   599     CleanupStack::PushL( item );
       
   600     
       
   601     tr->AppendL( item );
       
   602     CleanupStack::Pop( item );        
       
   603     }
       
   604 
       
   605 // -----------------------------------------------------------------------------
       
   606 // CHsPublisherImpl::PublishImageL()
       
   607 // 
       
   608 // -----------------------------------------------------------------------------
       
   609 //
       
   610 void CHsPublisherImpl::PublishImageL( const TDesC& aWidgetId,           
       
   611     const TDesC8& aElementId, const TDesC& aSource )
       
   612     {
       
   613     __ASSERT_ALWAYS( iCpServiceAvailable, User::Invariant() );
       
   614     
       
   615     CTransaction* tr( Transaction( aWidgetId ) );
       
   616     
       
   617     if ( !tr )
       
   618         {
       
   619         // Transaction not started 
       
   620         User::Leave( KErrNotReady );
       
   621         }
       
   622     
       
   623     CImageTransactionItem* item = 
       
   624         new ( ELeave ) CImageTransactionItem( aElementId, aSource );
       
   625     CleanupStack::PushL( item );
       
   626     
       
   627     tr->AppendL( item );
       
   628     CleanupStack::Pop( item );    
       
   629     }
       
   630     
       
   631 // -----------------------------------------------------------------------------
       
   632 // CHsPublisherImpl::PublishStreamL()
       
   633 // 
       
   634 // -----------------------------------------------------------------------------
       
   635 //
       
   636 void CHsPublisherImpl::PublishStreamL( const TDesC& aWidgetId,    
       
   637     const TDesC8& aElementId, const TDesC8& aStream )
       
   638     {
       
   639     CTransaction* tr( Transaction( aWidgetId ) );
       
   640     
       
   641     if ( !tr )
       
   642         {
       
   643         // Transaction not started 
       
   644         User::Leave( KErrNotReady );
       
   645         }
       
   646     
       
   647     CDataTransactionItem* item = 
       
   648         new ( ELeave ) CDataTransactionItem( aElementId, aStream );
       
   649     CleanupStack::PushL( item );
       
   650     
       
   651     tr->AppendL( item );
       
   652     CleanupStack::Pop( item );        
       
   653     }
       
   654 
       
   655 // -----------------------------------------------------------------------------
       
   656 // CHsPublisherImpl::CleanTextL()
       
   657 // 
       
   658 // -----------------------------------------------------------------------------
       
   659 //
       
   660 void CHsPublisherImpl::CleanTextL( const TDesC& aWidgetId,    
       
   661     const TDesC8& aElementId )
       
   662     {
       
   663     CTransaction* tr( Transaction( aWidgetId ) );
       
   664     
       
   665     if ( !tr )
       
   666         {
       
   667         // Transaction not started 
       
   668         User::Leave( KErrNotReady );
       
   669         }
       
   670     
       
   671     CTextTransactionItem* item = 
       
   672         new ( ELeave ) CTextTransactionItem( aElementId, KNullDesC() ); 
       
   673     CleanupStack::PushL( item );
       
   674      
       
   675     tr->AppendL( item );
       
   676     CleanupStack::Pop( item );          
       
   677     }
       
   678 
       
   679 // -----------------------------------------------------------------------------
       
   680 // CHsPublisherImpl::CleanImageL()
       
   681 // 
       
   682 // -----------------------------------------------------------------------------
       
   683 //
       
   684 void CHsPublisherImpl::CleanImageL( const TDesC& aWidgetId,    
       
   685     const TDesC8& aElementId )
       
   686     {
       
   687     CTransaction* tr( Transaction( aWidgetId ) );
       
   688     
       
   689     if ( !tr )
       
   690         {
       
   691         // Transaction not started 
       
   692         User::Leave( KErrNotReady );
       
   693         }
       
   694     
       
   695     CImageTransactionItem* item = 
       
   696         new ( ELeave ) CImageTransactionItem( 
       
   697             aElementId, KErrBadHandle, KErrBadHandle );    
       
   698     CleanupStack::PushL( item );
       
   699     
       
   700     tr->AppendL( item );
       
   701     CleanupStack::Pop( item );            
       
   702     }
       
   703 
       
   704 // -----------------------------------------------------------------------------
       
   705 // CHsPublisherImpl::StartTransactionL()
       
   706 // 
       
   707 // -----------------------------------------------------------------------------
       
   708 //
       
   709 void CHsPublisherImpl::StartTransactionL( const TDesC& aWidgetId )
       
   710     {
       
   711     __ASSERT_ALWAYS( iCpServiceAvailable, User::Invariant() );
       
   712         
       
   713     CTransaction* tr( Transaction( aWidgetId ) );
       
   714     
       
   715     if ( tr )
       
   716         {
       
   717         // Transaction already started
       
   718         User::Leave( KErrAlreadyExists );    
       
   719         }
       
   720     
       
   721     // Create new transaction for this widget instance
       
   722     tr = new ( ELeave ) CTransaction( aWidgetId );
       
   723     CleanupStack::PushL( tr );
       
   724     
       
   725     iTransactions.AppendL( tr );
       
   726     CleanupStack::Pop( tr );
       
   727     }
       
   728 
       
   729 // -----------------------------------------------------------------------------
       
   730 // CHsPublisherImpl::CommitTransactionL()
       
   731 // 
       
   732 // -----------------------------------------------------------------------------
       
   733 //
       
   734 void CHsPublisherImpl::CommitTransactionL( const TDesC& aWidgetId )
       
   735     {
       
   736     __ASSERT_ALWAYS( iCpServiceAvailable, User::Invariant() );
       
   737 
       
   738     CTransaction* tr( Transaction( aWidgetId ) );
       
   739     
       
   740     if ( !tr )
       
   741         {
       
   742         // Transaction not started 
       
   743         User::Leave( KErrNotReady );
       
   744         }
       
   745     
       
   746     // Remove transaction
       
   747     iTransactions.Remove( iTransactions.Find( tr ) );
       
   748     
       
   749     // Transaction will be destroyed
       
   750     CleanupStack::PushL( tr );
       
   751     
       
   752     const RPointerArray< CTransactionItem >& items( tr->Items() );
       
   753     
       
   754     if ( items.Count() == 0 )
       
   755         {
       
   756         // Nothing to publish   
       
   757         CleanupStack::PopAndDestroy( tr );    
       
   758         return;
       
   759         }
       
   760     
       
   761     CLiwGenericParamList& inParamList( iServiceHandler->InParamListL() );
       
   762     CLiwGenericParamList& outParamList( iServiceHandler->OutParamListL() );
       
   763 
       
   764     inParamList.AppendL( TLiwGenericParam(  
       
   765         KType, TLiwVariant( KCpData ) ) );
       
   766     
       
   767     CLiwDefaultMap* cpdatamap = CLiwDefaultMap::NewLC();
       
   768 
       
   769     const TDesC& publisherId( iObserver.Identity() );
       
   770     
       
   771     cpdatamap->InsertL( KPublisherId, TLiwVariant( publisherId ) );
       
   772     cpdatamap->InsertL( KContentType, TLiwVariant( KAll ) );
       
   773     cpdatamap->InsertL( KContentId, TLiwVariant( aWidgetId ) );
       
   774        
       
   775     CLiwDefaultMap* datamap = CLiwDefaultMap::NewLC();
       
   776              
       
   777     for ( TInt i = 0; i < items.Count(); i++ )
       
   778         {
       
   779         CTransactionItem* item( items[i] );
       
   780         
       
   781         CImageTransactionItem* image = 
       
   782             dynamic_cast< CImageTransactionItem* >( item );
       
   783         
       
   784         CTextTransactionItem* text =
       
   785             dynamic_cast< CTextTransactionItem* >( item );
       
   786         
       
   787         CDataTransactionItem* data =
       
   788             dynamic_cast< CDataTransactionItem* >( item );
       
   789         
       
   790         if ( image )
       
   791             {
       
   792             const TDesC& source( image->Path() );
       
   793             
       
   794             if ( source != KNullDesC )
       
   795                 {
       
   796                 datamap->InsertL( image->ElementId(), 
       
   797                     TLiwVariant( source ) );                      
       
   798                 }
       
   799             else
       
   800                 {
       
   801                 datamap->InsertL( image->ElementId(),  
       
   802                     TLiwVariant( TInt32( image->ImageHandle() ) ) );
       
   803                 
       
   804                 datamap->InsertL( image->ElementId(),  
       
   805                     TLiwVariant( TInt32( image->MaskHandle() ) ) );                
       
   806                 }                        
       
   807             }
       
   808         else if ( text )
       
   809             {                                                        
       
   810             datamap->InsertL( text->ElementId(), 
       
   811                 TLiwVariant( text->Text() ) );                
       
   812             }
       
   813         else if ( data )
       
   814             {
       
   815             datamap->InsertL( data->ElementId(), 
       
   816                 TLiwVariant( data->Data() ) );                        
       
   817             }
       
   818         }   
       
   819     
       
   820     cpdatamap->InsertL( KDataMap, TLiwVariant( datamap ) );
       
   821                       
       
   822     inParamList.AppendL( TLiwGenericParam(  
       
   823         KItem, TLiwVariant( cpdatamap ) ) );
       
   824     
       
   825     iCpsInterface->ExecuteCmdL( KAdd, inParamList, outParamList,           
       
   826         iEnablePersist ? 0 : KDisablePersist );
       
   827           
       
   828     inParamList.Reset();
       
   829     outParamList.Reset();
       
   830     
       
   831     CleanupStack::PopAndDestroy( 3, tr ); // cpdatamap, datamap
       
   832     }
       
   833 
       
   834 // -----------------------------------------------------------------------------
       
   835 // CHsPublisherImpl::Transaction()
       
   836 // 
       
   837 // -----------------------------------------------------------------------------
       
   838 //
       
   839 CTransaction* CHsPublisherImpl::Transaction( 
       
   840     const TDesC& aWidgetId ) const
       
   841     {
       
   842     CTransaction* tr( NULL );
       
   843     
       
   844     for ( TInt i = 0; i < iTransactions.Count(); i++ )
       
   845         {
       
   846         if ( *iTransactions[i] == aWidgetId )
       
   847             {   
       
   848             tr = iTransactions[i];
       
   849             break;
       
   850             }
       
   851         }
       
   852     
       
   853     return tr;
       
   854     }
       
   855 
       
   856 // End of file