musichomescreen/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 //#include <cpglobals.h> // CPS string definitions.
       
    30 
       
    31 // TODO Take these from some common header file!
       
    32 // CONTANTS
       
    33 /*
       
    34 _LIT( KPubData, "publisher" );
       
    35 _LIT8( KChangeInfo, "change_info" );
       
    36 _LIT8( KType, "type");
       
    37 _LIT8( KFilter, "filter" );
       
    38 _LIT8( KRequestNotification, "RequestNotification" );
       
    39 _LIT8( KContentId,   "content_id" );
       
    40 _LIT8( KOperation, "operation" );
       
    41 _LIT8( KActionTrigger, "action_trigger" );
       
    42 */
       
    43 /**
       
    44  * Maximum length for the content name
       
    45  */
       
    46  /*
       
    47 const TInt KSAPIContentNameMaxLength = 255;
       
    48 
       
    49 */
       
    50 //_LIT8( KCPInterface, "IDataSource" );
       
    51 _LIT8( KCPContentInterface, "IContentPublishing" );
       
    52 _LIT8( KCPService, "Service.ContentPublishing" );
       
    53 _LIT( KMyOperationExecute, "execute" );
       
    54 
       
    55 // =============================================================================
       
    56 // --------------------------------------------------------------------------
       
    57 // Cleanup utility for RPointerArray
       
    58 // --------------------------------------------------------------------------
       
    59 //
       
    60 static void DoCleanup( TAny* aPtr )
       
    61     {
       
    62     __ASSERT_DEBUG( aPtr, User::Invariant() );
       
    63     static_cast< RCriteriaArray* >( aPtr )->ResetAndDestroy();
       
    64     }
       
    65 
       
    66 // ============================ MEMBER FUNCTIONS ==============================
       
    67 
       
    68 // ----------------------------------------------------------------------------
       
    69 // Constructor
       
    70 // ----------------------------------------------------------------------------
       
    71 //
       
    72 CMCPHarvesterPublisherObserver::CMCPHarvesterPublisherObserver( CMusicContentPublisher* aHarvester )
       
    73     : iHarvester( aHarvester )
       
    74 	{
       
    75 	}
       
    76 
       
    77 // ----------------------------------------------------------------------------
       
    78 // Two-phased constructor.
       
    79 // ----------------------------------------------------------------------------
       
    80 //
       
    81 CMCPHarvesterPublisherObserver* CMCPHarvesterPublisherObserver::NewL(
       
    82         CMusicContentPublisher* aHarvester )
       
    83     {
       
    84     CMCPHarvesterPublisherObserver* self = CMCPHarvesterPublisherObserver::NewLC( aHarvester ) ;
       
    85     CleanupStack::Pop( self );
       
    86     return self;
       
    87     }
       
    88 
       
    89 // ----------------------------------------------------------------------------
       
    90 CMCPHarvesterPublisherObserver* CMCPHarvesterPublisherObserver::NewLC( 
       
    91         CMusicContentPublisher* aHarvester )
       
    92     {
       
    93     CMCPHarvesterPublisherObserver* self( 
       
    94         new( ELeave ) CMCPHarvesterPublisherObserver( aHarvester ) );
       
    95         
       
    96     CleanupStack::PushL( self );
       
    97     self->ConstructL();
       
    98     return self;
       
    99     }
       
   100 
       
   101 // ---------------------------------------------------------------------------
       
   102 // Destructor
       
   103 // ---------------------------------------------------------------------------
       
   104 //
       
   105 CMCPHarvesterPublisherObserver::~CMCPHarvesterPublisherObserver()
       
   106     {
       
   107     // TODO automatic releasing.
       
   108     ReleaseLiw();
       
   109     }
       
   110 
       
   111 // ----------------------------------------------------------------------------
       
   112 // Symbian 2nd phase constructor can leave.
       
   113 // ----------------------------------------------------------------------------
       
   114 //
       
   115 void CMCPHarvesterPublisherObserver::ConstructL()
       
   116     {
       
   117     InitLiwL();
       
   118     }
       
   119 
       
   120 // ---------------------------------------------------------------------------
       
   121 // Handles Published content notification
       
   122 // ---------------------------------------------------------------------------
       
   123 //
       
   124 TInt CMCPHarvesterPublisherObserver::HandleNotifyL( 
       
   125     TInt /*aErrorCode */, 
       
   126     TInt /*aEventId*/,
       
   127     CLiwGenericParamList& aEventParamList, 
       
   128     const CLiwGenericParamList& /*aInParamList*/ )
       
   129     {
       
   130     //__UHEAP_MARK;
       
   131     TInt pos(0);
       
   132 
       
   133     aEventParamList.FindFirst(pos, KChangeInfo);
       
   134     if (pos != KErrNotFound)
       
   135         {
       
   136         // Get list of maps
       
   137         TLiwVariant variant = (aEventParamList)[pos].Value();
       
   138         variant.PushL();
       
   139         const CLiwList* changeMapsList = variant.AsList();
       
   140         
       
   141         TPtrC publisher;
       
   142         TPtrC operation;
       
   143         TPtrC8 trigger;
       
   144 
       
   145         // Iter through list content
       
   146         for (TInt i = 0; i < changeMapsList->Count(); ++i)
       
   147             {
       
   148              if ( changeMapsList->AtL( i, variant )) 
       
   149                  {
       
   150                  const CLiwMap* map  = variant.AsMap();
       
   151                  
       
   152                  // Check what triggered a notification
       
   153                  variant.Reset();
       
   154                  if ( map->FindL( KOperation, variant ))
       
   155                      {
       
   156                      operation.Set( variant.AsDes()); 
       
   157                      }
       
   158                  if ( operation == KMyOperationExecute )
       
   159                      {
       
   160                      variant.Reset();
       
   161                      if( map->FindL( KActionTrigger, variant ))
       
   162                          {
       
   163                          trigger.Set( variant.AsData()); 
       
   164                          }
       
   165                      TLiwVariant pubVariant;
       
   166                      if( map->FindL( KContentId, pubVariant) )
       
   167                          {
       
   168                          publisher.Set( pubVariant.AsDes());
       
   169                          }
       
   170                      pubVariant.PushL();
       
   171                      if( publisher.Length() && trigger.Length())
       
   172                          {
       
   173                          iHarvester->HandlePublisherNotificationL( publisher, trigger );
       
   174                          }
       
   175                      CleanupStack::PopAndDestroy( &pubVariant );
       
   176                      }
       
   177                  }
       
   178             }
       
   179         CleanupStack::PopAndDestroy( &variant );
       
   180         }
       
   181     //__UHEAP_MARKEND;
       
   182     return KErrNone;
       
   183 
       
   184     }
       
   185 
       
   186 // ---------------------------------------------------------------------------
       
   187 // Register for notifications
       
   188 // ---------------------------------------------------------------------------
       
   189 //
       
   190 void CMCPHarvesterPublisherObserver::RegisterL( CLiwDefaultMap* aFilter )
       
   191     {
       
   192     CLiwGenericParamList* inParamList( CLiwGenericParamList::NewLC() );
       
   193     CLiwGenericParamList* outParamList( CLiwGenericParamList::NewLC() );
       
   194     
       
   195     // Fill in input list for RequestNotification command
       
   196     inParamList->AppendL(TLiwGenericParam(KType,TLiwVariant( KPubData )));
       
   197     inParamList->AppendL(TLiwGenericParam(KFilter ,TLiwVariant( aFilter )));
       
   198         
       
   199     iError = KErrNone;
       
   200     TRAP( iError, iInterface->ExecuteCmdL( 
       
   201                 KRequestNotification,
       
   202                 *inParamList,
       
   203                 *outParamList,
       
   204                 0,
       
   205                 this ) );
       
   206     
       
   207     CleanupStack::PopAndDestroy( outParamList );
       
   208     CleanupStack::PopAndDestroy( inParamList ); 
       
   209     }
       
   210 
       
   211 // ---------------------------------------------------------------------------
       
   212 // Sing off to notification
       
   213 // ---------------------------------------------------------------------------
       
   214 //
       
   215 void CMCPHarvesterPublisherObserver::ReleaseL()
       
   216     {
       
   217     if( iInterface )
       
   218         {
       
   219         CLiwGenericParamList* inParamList = CLiwGenericParamList::NewL();
       
   220         CleanupStack::PushL( inParamList );
       
   221         CLiwGenericParamList* outParamList = CLiwGenericParamList::NewL();
       
   222         CleanupStack::PushL( outParamList );
       
   223         
       
   224         TInt err(KErrNone);
       
   225         TRAP(err, iInterface->ExecuteCmdL( 
       
   226                 KRequestNotification,
       
   227                 *inParamList,
       
   228                 *outParamList,
       
   229                 KLiwOptCancel,
       
   230                 this ));
       
   231         
       
   232         CleanupStack::PopAndDestroy( outParamList );
       
   233         CleanupStack::PopAndDestroy( inParamList );
       
   234         }
       
   235     }
       
   236 
       
   237 
       
   238 // ------------------------------------------------------------------------
       
   239 // CWidgetUiWindowManager::FindObserver
       
   240 //
       
   241 // Init LIW interface.
       
   242 // ------------------------------------------------------------------------
       
   243 void CMCPHarvesterPublisherObserver::InitLiwL()
       
   244     {
       
   245     if ( !iLiwHandler )
       
   246         {
       
   247         TInt error( KErrNone );
       
   248         CLiwGenericParamList* in( NULL );
       
   249         CLiwGenericParamList* out( NULL );
       
   250         CLiwCriteriaItem* criterion( NULL );
       
   251         MLiwInterface* liwIface( NULL );
       
   252 
       
   253         RCriteriaArray array( 1 );
       
   254         TCleanupItem cleanup( DoCleanup, &array );
       
   255         CleanupStack::PushL( cleanup );
       
   256 
       
   257         // Do the basic initialization.
       
   258         iLiwHandler = CLiwServiceHandler::NewL();
       
   259 
       
   260         // Get iCPSIface.
       
   261         in = CLiwGenericParamList::NewLC();
       
   262         out = CLiwGenericParamList::NewLC();
       
   263 
       
   264         criterion = CLiwCriteriaItem::NewL( 
       
   265             KLiwCmdAsStr,
       
   266             KCPContentInterface, 
       
   267             KCPService );
       
   268             
       
   269         error = array.Append( criterion );
       
   270         if ( error )
       
   271             {
       
   272             delete criterion; criterion = NULL;
       
   273             User::Leave( error );
       
   274             }
       
   275 
       
   276         criterion->SetServiceClass( TUid::Uid( KLiwClassBase ) );
       
   277             
       
   278         iLiwHandler->AttachL( array );
       
   279         iLiwHandler->ExecuteServiceCmdL( *criterion, *in, *out ); 
       
   280 
       
   281         out->FindFirst( error, KCPContentInterface );
       
   282         User::LeaveIfError( error );
       
   283 
       
   284         iInterface = (*out)[ error ].Value().AsInterface();
       
   285 
       
   286         CleanupStack::PopAndDestroy( 3 );
       
   287         }
       
   288     }
       
   289 
       
   290 void CMCPHarvesterPublisherObserver::ReleaseLiw()
       
   291     {    
       
   292     if ( iInterface )
       
   293         {
       
   294         iInterface->Close();
       
   295         iInterface = NULL;
       
   296         }
       
   297         
       
   298     delete iLiwHandler;
       
   299     iLiwHandler = NULL;
       
   300     }
       
   301  //  End of File
       
   302