contentpublishingsrv/contentpublishingserver/cpserver/src/cpserveractionmanager.cpp
changeset 0 79c6a41cd166
child 12 502e5d91ad42
equal deleted inserted replaced
-1:000000000000 0:79c6a41cd166
       
     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 "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:  
       
    15 *
       
    16 */
       
    17 
       
    18 #include <liwcommon.h>
       
    19 #include <liwservicehandler.h>
       
    20 #include <s32mem.h>
       
    21 
       
    22 #include "cpserveractionmanager.h"
       
    23 #include "cpdebug.h"
       
    24 #include "cpglobals.h"
       
    25 
       
    26 using namespace LIW;
       
    27 
       
    28 // ---------------------------------------------------------------------------
       
    29 // C++ destructor
       
    30 // ---------------------------------------------------------------------------
       
    31 //
       
    32 CCPActionManager::~CCPActionManager()
       
    33     {
       
    34     if ( iInterface )
       
    35         {
       
    36         iInterface->Close( );
       
    37         }
       
    38     delete iServiceHandler;
       
    39     }
       
    40 
       
    41 // ---------------------------------------------------------------------------
       
    42 // 
       
    43 // ---------------------------------------------------------------------------
       
    44 //
       
    45 CCPActionManager* CCPActionManager::NewL()
       
    46     {
       
    47     CCPActionManager* self = CCPActionManager::NewLC( );
       
    48     CleanupStack::Pop( self );
       
    49     return self;
       
    50     }
       
    51 
       
    52 // ---------------------------------------------------------------------------
       
    53 // 
       
    54 // ---------------------------------------------------------------------------
       
    55 //
       
    56 CCPActionManager* CCPActionManager::NewLC()
       
    57     {
       
    58     CCPActionManager* self = new( ELeave ) CCPActionManager;
       
    59     CleanupStack::PushL( self );
       
    60     self->ConstructL( );
       
    61     return self;
       
    62     }
       
    63 
       
    64 // ---------------------------------------------------------------------------
       
    65 // C++ constructor.
       
    66 // ---------------------------------------------------------------------------
       
    67 //
       
    68 CCPActionManager::CCPActionManager()
       
    69     {
       
    70 
       
    71     }
       
    72 
       
    73 // ---------------------------------------------------------------------------
       
    74 // Standard 2nd phase constructor.
       
    75 // ---------------------------------------------------------------------------
       
    76 //
       
    77 void CCPActionManager::ConstructL()
       
    78     {
       
    79     CP_DEBUG( _L8("CCPActionManager::ConstructL()") );
       
    80     iServiceHandler = CLiwServiceHandler::NewL( );
       
    81     }
       
    82 
       
    83 // -----------------------------------------------------------------------------
       
    84 // CCPActionManager::ExecuteL
       
    85 // --------------- --------------------------------------------------------------
       
    86 //  
       
    87 void CCPActionManager::ExecuteL( const CLiwGenericParamList& aList )
       
    88     {
       
    89     CP_DEBUG( _L8("CCPActionManager::ExecuteL()") );
       
    90     if ( !iInterface )
       
    91         {
       
    92         PrepareServiceL( iInterface );
       
    93         }
       
    94     CLiwGenericParamList* inparam = CLiwGenericParamList::NewLC( );
       
    95     CLiwGenericParamList* outparam = CLiwGenericParamList::NewLC( );
       
    96     PrepareInputListL( aList, *inparam );
       
    97 
       
    98     iInterface->ExecuteCmdL( KCmdExecute, *inparam, *outparam ) ;
       
    99     TInt pos(0);
       
   100     outparam->FindFirst( pos, EGenericParamError );
       
   101     if ( pos != KErrNotFound )
       
   102         {
       
   103         User::LeaveIfError( ( *outparam )[pos].Value().AsTInt32( ) );
       
   104         }
       
   105     else
       
   106         {
       
   107         User::Leave( KErrNotFound );
       
   108         }
       
   109     CleanupStack::PopAndDestroy( outparam );
       
   110     CleanupStack::PopAndDestroy( inparam );
       
   111     }
       
   112 
       
   113 // -----------------------------------------------------------------------------
       
   114 // CCPActionManager::ExecuteL
       
   115 // --------------- --------------------------------------------------------------
       
   116 //  
       
   117 void CCPActionManager::PrepareServiceL( MLiwInterface*& aInterface )
       
   118     {
       
   119     CP_DEBUG( _L8("CCPActionManager::PrepareServiceL()") );
       
   120     CLiwGenericParamList* inparam = &(iServiceHandler->InParamListL( ) );
       
   121     CLiwGenericParamList* outparam = &(iServiceHandler->OutParamListL( ) );
       
   122     CLiwCriteriaItem* crit = CLiwCriteriaItem::NewL( 1,
       
   123         KActionHandlerInterface, KActionHandlerService );
       
   124     CleanupStack::PushL( crit );
       
   125     crit->SetServiceClass( TUid::Uid( KLiwClassBase ) );
       
   126     RCriteriaArray array;
       
   127     CleanupClosePushL( array );
       
   128     array.AppendL( crit );
       
   129     iServiceHandler->AttachL( array );
       
   130     iServiceHandler->ExecuteServiceCmdL( *crit, *inparam, *outparam );
       
   131     CleanupStack::PopAndDestroy( &array );
       
   132     CleanupStack::PopAndDestroy( crit );
       
   133     TInt pos = 0;
       
   134     outparam->FindFirst( pos, KActionHandlerInterface );
       
   135     if ( pos != KErrNotFound )
       
   136         {
       
   137         aInterface = ( *outparam )[pos].Value().AsInterface( );
       
   138         }
       
   139     else
       
   140         {
       
   141         User::Leave( KErrNotFound );
       
   142         }
       
   143     }
       
   144 
       
   145 // -----------------------------------------------------------------------------
       
   146 // CCPActionManager::PrepareInputListL
       
   147 // --------------- --------------------------------------------------------------
       
   148 //
       
   149 void CCPActionManager::PrepareInputListL( const CLiwGenericParamList& aList,
       
   150     CLiwGenericParamList& aTarget )
       
   151     {
       
   152     CP_DEBUG( _L8("CCPActionManager::PrepareInputListL()") );
       
   153     const TLiwGenericParam* param= NULL;
       
   154     TInt pos( 0);
       
   155     param = aList.FindFirst( pos, KListMap, EVariantTypeMap );
       
   156     if ( param && pos !=KErrNotFound )
       
   157         {
       
   158         CLiwDefaultMap* map = CLiwDefaultMap::NewLC( );
       
   159         param->Value().Get( *map );
       
   160         ExtractUidAndMapL( *map, aTarget );
       
   161         CleanupStack::PopAndDestroy( map );
       
   162         }
       
   163     else
       
   164         {
       
   165         User::Leave( KErrNotFound );
       
   166         }
       
   167     }
       
   168 
       
   169 // -----------------------------------------------------------------------------
       
   170 // CCPActionManager::ExtractUidAndMapL
       
   171 // --------------- --------------------------------------------------------------
       
   172 //
       
   173 void CCPActionManager::ExtractUidAndMapL( const CLiwDefaultMap& aMap,
       
   174     CLiwGenericParamList& aTarget )
       
   175     {
       
   176     CP_DEBUG( _L8("CCPActionManager::ExtractUidAndMapL()") );
       
   177     TLiwVariant variant;
       
   178     variant.PushL( );
       
   179     if ( aMap.FindL( KActionMap, variant ) )
       
   180         {
       
   181         CLiwDefaultMap* map = CLiwDefaultMap::NewLC( );
       
   182         variant.Get( *map );
       
   183         if ( map->FindL( KDataForActionHandler, variant ) )
       
   184             {
       
   185             TLiwGenericParam param( KDataForActionHandler, variant);
       
   186             aTarget.AppendL( param );
       
   187             }
       
   188         if ( map->FindL( KPluginUid, variant ) )
       
   189             {
       
   190             TLiwGenericParam param( KPluginUid, variant);
       
   191             aTarget.AppendL( param );
       
   192             }
       
   193         CleanupStack::PopAndDestroy( map );
       
   194         }
       
   195 
       
   196     CleanupStack::PopAndDestroy( &variant );
       
   197     }
       
   198