musichomescreen_multiview/musiccontentpublisher/src/mcpharvesterpublisherobserver.cpp
changeset 0 ff3acec5bc43
equal deleted inserted replaced
-1:000000000000 0:ff3acec5bc43
       
     1 /*
       
     2 * Copyright (c) 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:  Updates CPS storage
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 // INCLUDE FILES
       
    20 
       
    21 #include "mcpharvesterpublisherobserver.h"
       
    22 #include "musiccontentpublisher.h"
       
    23 #include "sapidatapluginconst.h"
       
    24 
       
    25 #include <liwservicehandler.h>
       
    26 #include <liwvariant.h>
       
    27 #include <liwgenericparam.h>
       
    28 
       
    29 
       
    30 _LIT( KPublisher, "publisher" );
       
    31 _LIT8( KCPContentInterface, "IContentPublishing" );
       
    32 _LIT8( KCPService, "Service.ContentPublishing" );
       
    33 _LIT( KMyOperationExecute, "execute" );
       
    34 
       
    35 // =============================================================================
       
    36 // --------------------------------------------------------------------------
       
    37 // Cleanup utility for RPointerArray
       
    38 // --------------------------------------------------------------------------
       
    39 //
       
    40 static void DoCleanup( TAny* aPtr )
       
    41     {
       
    42     __ASSERT_DEBUG( aPtr, User::Invariant() );
       
    43     static_cast< RCriteriaArray* >( aPtr )->ResetAndDestroy();
       
    44     }
       
    45 
       
    46 // ============================ MEMBER FUNCTIONS ==============================
       
    47 
       
    48 // ----------------------------------------------------------------------------
       
    49 // Constructor
       
    50 // ----------------------------------------------------------------------------
       
    51 //
       
    52 CMCPHarvesterPublisherObserver::CMCPHarvesterPublisherObserver( CMusicContentPublisher* aHarvester )
       
    53     : iHarvester( aHarvester )
       
    54 	{
       
    55 	}
       
    56 
       
    57 // ----------------------------------------------------------------------------
       
    58 // Two-phased constructor.
       
    59 // ----------------------------------------------------------------------------
       
    60 //
       
    61 CMCPHarvesterPublisherObserver* CMCPHarvesterPublisherObserver::NewL( 
       
    62         CMusicContentPublisher* aHarvester )
       
    63     {
       
    64     CMCPHarvesterPublisherObserver* self = CMCPHarvesterPublisherObserver::NewLC( aHarvester ) ;
       
    65     CleanupStack::Pop( self );
       
    66     return self;
       
    67     }
       
    68 
       
    69 // ----------------------------------------------------------------------------
       
    70 CMCPHarvesterPublisherObserver* CMCPHarvesterPublisherObserver::NewLC( 
       
    71         CMusicContentPublisher* aHarvester )
       
    72     {
       
    73     CMCPHarvesterPublisherObserver* self( 
       
    74         new( ELeave ) CMCPHarvesterPublisherObserver( aHarvester ) );
       
    75         
       
    76     CleanupStack::PushL( self );
       
    77     self->ConstructL();
       
    78     return self;
       
    79     }
       
    80 
       
    81 // ---------------------------------------------------------------------------
       
    82 // Destructor
       
    83 // ---------------------------------------------------------------------------
       
    84 //
       
    85 CMCPHarvesterPublisherObserver::~CMCPHarvesterPublisherObserver()
       
    86     {
       
    87     ReleaseLiw();
       
    88     }
       
    89 
       
    90 // ----------------------------------------------------------------------------
       
    91 // Symbian 2nd phase constructor can leave.
       
    92 // ----------------------------------------------------------------------------
       
    93 //
       
    94 void CMCPHarvesterPublisherObserver::ConstructL()
       
    95     {
       
    96     InitLiwL();
       
    97     }
       
    98 
       
    99 // ---------------------------------------------------------------------------
       
   100 // Handles Published content notification
       
   101 // ---------------------------------------------------------------------------
       
   102 //
       
   103 TInt CMCPHarvesterPublisherObserver::HandleNotifyL( 
       
   104     TInt /*aErrorCode */, 
       
   105     TInt /*aEventId*/,
       
   106     CLiwGenericParamList& aEventParamList, 
       
   107     const CLiwGenericParamList& /*aInParamList*/ )
       
   108     {
       
   109     //__UHEAP_MARK;
       
   110     TInt pos(0);
       
   111 
       
   112     aEventParamList.FindFirst(pos, KChangeInfo);
       
   113     if (pos != KErrNotFound)
       
   114         {
       
   115         // Get list of maps
       
   116         TLiwVariant variant = (aEventParamList)[pos].Value();
       
   117         variant.PushL();
       
   118         const CLiwList* changeMapsList = variant.AsList();
       
   119         
       
   120         TPtrC publisher;
       
   121         TPtrC operation;
       
   122         TPtrC8 trigger;
       
   123 
       
   124         // Iter through list content
       
   125         for (TInt i = 0; i < changeMapsList->Count(); ++i)
       
   126             {
       
   127              if ( changeMapsList->AtL( i, variant )) 
       
   128                  {
       
   129                  const CLiwMap* map  = variant.AsMap();
       
   130                  
       
   131                  // Check what triggered a notification
       
   132                  variant.Reset();
       
   133                  if ( map->FindL( KOperation, variant ))
       
   134                      {
       
   135                      operation.Set( variant.AsDes()); 
       
   136                      }
       
   137                  if ( operation == KMyOperationExecute )
       
   138                      {
       
   139                      variant.Reset();
       
   140                      if( map->FindL( KActionTrigger, variant ))
       
   141                          {
       
   142                          trigger.Set( variant.AsData()); 
       
   143                          }
       
   144                      TLiwVariant pubVariant;
       
   145                      if( map->FindL( KContentId, pubVariant) )
       
   146                          {
       
   147                          publisher.Set( pubVariant.AsDes());
       
   148                          }
       
   149                      pubVariant.PushL();
       
   150                      if( publisher.Length() && trigger.Length())
       
   151                          {
       
   152                          iHarvester->HandlePublisherNotificationL( publisher, trigger );
       
   153                          }
       
   154                      CleanupStack::PopAndDestroy( &pubVariant );
       
   155                      }
       
   156                  }
       
   157             }
       
   158         CleanupStack::PopAndDestroy( &variant );
       
   159         }
       
   160     //__UHEAP_MARKEND;
       
   161     return KErrNone;
       
   162 
       
   163     }
       
   164 
       
   165 // ---------------------------------------------------------------------------
       
   166 // Register for notifications
       
   167 // ---------------------------------------------------------------------------
       
   168 //
       
   169 void CMCPHarvesterPublisherObserver::RegisterL( CLiwDefaultMap* aFilter )
       
   170     {
       
   171     CLiwGenericParamList* inParamList( CLiwGenericParamList::NewLC() );
       
   172     CLiwGenericParamList* outParamList( CLiwGenericParamList::NewLC() );
       
   173     
       
   174     // Fill in input list for RequestNotification command
       
   175     inParamList->AppendL(TLiwGenericParam(KType,TLiwVariant( KPublisher )));
       
   176     inParamList->AppendL(TLiwGenericParam(KFilter ,TLiwVariant( aFilter )));
       
   177         
       
   178     iError = KErrNone;
       
   179     TRAP( iError, iInterface->ExecuteCmdL( 
       
   180                 KRequestNotification,
       
   181                 *inParamList,
       
   182                 *outParamList,
       
   183                 0,
       
   184                 this ) );
       
   185     
       
   186     CleanupStack::PopAndDestroy( outParamList );
       
   187     CleanupStack::PopAndDestroy( inParamList ); 
       
   188     }
       
   189 
       
   190 // ------------------------------------------------------------------------
       
   191 // CWidgetUiWindowManager::FindObserver
       
   192 //
       
   193 // Init LIW interface.
       
   194 // ------------------------------------------------------------------------
       
   195 void CMCPHarvesterPublisherObserver::InitLiwL()
       
   196     {
       
   197     if ( !iLiwHandler )
       
   198         {
       
   199         TInt error( KErrNone );
       
   200         CLiwGenericParamList* in( NULL );
       
   201         CLiwGenericParamList* out( NULL );
       
   202         CLiwCriteriaItem* criterion( NULL );
       
   203 
       
   204         RCriteriaArray array( 1 );
       
   205         TCleanupItem cleanup( DoCleanup, &array );
       
   206         CleanupStack::PushL( cleanup );
       
   207 
       
   208         // Do the basic initialization.
       
   209         iLiwHandler = CLiwServiceHandler::NewL();
       
   210 
       
   211         // Get iCPSIface.
       
   212         in = CLiwGenericParamList::NewLC();
       
   213         out = CLiwGenericParamList::NewLC();
       
   214 
       
   215         criterion = CLiwCriteriaItem::NewL( 
       
   216             KLiwCmdAsStr,
       
   217             KCPContentInterface, 
       
   218             KCPService );
       
   219             
       
   220         error = array.Append( criterion );
       
   221         if ( error )
       
   222             {
       
   223             delete criterion; criterion = NULL;
       
   224             User::Leave( error );
       
   225             }
       
   226 
       
   227         criterion->SetServiceClass( TUid::Uid( KLiwClassBase ) );
       
   228             
       
   229         iLiwHandler->AttachL( array );
       
   230         iLiwHandler->ExecuteServiceCmdL( *criterion, *in, *out ); 
       
   231 
       
   232         out->FindFirst( error, KCPContentInterface );
       
   233         User::LeaveIfError( error );
       
   234 
       
   235         iInterface = (*out)[ error ].Value().AsInterface();
       
   236 
       
   237         CleanupStack::PopAndDestroy( 3 );
       
   238         }
       
   239     }
       
   240 
       
   241 void CMCPHarvesterPublisherObserver::ReleaseLiw()
       
   242     {    
       
   243     if ( iInterface )
       
   244         {
       
   245         iInterface->Close();
       
   246         iInterface = NULL;
       
   247         }
       
   248         
       
   249     delete iLiwHandler;
       
   250     iLiwHandler = NULL;
       
   251     }
       
   252  //  End of File
       
   253