homescreensrv_plat/sapi_contentpublishing/src/cdatasourceinterface.cpp
changeset 73 4bc7b118b3df
parent 66 32469d7d46ff
child 80 397d00875918
child 81 5ef31a21fdd5
equal deleted inserted replaced
66:32469d7d46ff 73:4bc7b118b3df
     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:  
       
    15  *
       
    16 */
       
    17 
       
    18 
       
    19 #include <mmf/common/mmfcontrollerpluginresolver.h>
       
    20 
       
    21 #include "cdatasourceinterface.h"
       
    22 #include "cpdebug.h"
       
    23 #include "cpglobals.h"
       
    24 #include "cpclient.h"
       
    25 #include "serviceerrno.h"
       
    26 #include "cpclientiterable.h"
       
    27 
       
    28 using namespace LIW;
       
    29 
       
    30 // ---------------------------------------------------------------------------
       
    31 //
       
    32 // ---------------------------------------------------------------------------
       
    33 //
       
    34 CDataSourceInterface* CDataSourceInterface::NewL()
       
    35     {
       
    36     CDataSourceInterface* self = CDataSourceInterface::NewLC( );
       
    37     CleanupStack::Pop( self );
       
    38     return self;
       
    39     }
       
    40 
       
    41 // ---------------------------------------------------------------------------
       
    42 //
       
    43 // ---------------------------------------------------------------------------
       
    44 //
       
    45 CDataSourceInterface* CDataSourceInterface::NewLC()
       
    46     {
       
    47     CDataSourceInterface* self = new( ELeave ) CDataSourceInterface;
       
    48     CleanupStack::PushL( self );
       
    49     self->ConstructL( );
       
    50     return self;
       
    51     }
       
    52 
       
    53 // ---------------------------------------------------------------------------
       
    54 // 
       
    55 // ---------------------------------------------------------------------------
       
    56 //
       
    57 CDataSourceInterface::~CDataSourceInterface()
       
    58     {
       
    59     CP_DEBUG( _L8("CDataSourceInterface::~CDataSourceInterface") );
       
    60     delete iCPClient;
       
    61     }
       
    62 
       
    63 // ---------------------------------------------------------------------------
       
    64 //  Executes the SAPI as per params
       
    65 // ---------------------------------------------------------------------------
       
    66 //
       
    67 void CDataSourceInterface::ExecuteCmdL( const TDesC8& aCmdName,
       
    68     const CLiwGenericParamList& aInParamList,
       
    69     CLiwGenericParamList& aOutParamList, TUint aCmdOptions,
       
    70     MLiwNotifyCallback* aCallback )
       
    71     {
       
    72     CP_DEBUG( _L8("CCPClientInterface::ExecuteCmdL") );
       
    73     TInt errCode(KErrNone);
       
    74     aOutParamList.AppendL( TLiwGenericParam( EGenericParamError,
       
    75         TLiwVariant( ErrCodeConversion( KErrNone ) ) ) );
       
    76     aOutParamList.AppendL( TLiwGenericParam( KErrorCode,
       
    77         TLiwVariant( ErrCodeConversion( KErrNone ) ) ) );
       
    78     // Check the command name
       
    79     TRAP( errCode , ProcessCommandL( aCmdName, aInParamList,
       
    80                     aOutParamList,
       
    81                     aCmdOptions,
       
    82                     aCallback ) );
       
    83     if ( errCode != KErrNone )
       
    84         {
       
    85        aOutParamList.Reset( );
       
    86         aOutParamList.AppendL( TLiwGenericParam( EGenericParamError,
       
    87             TLiwVariant( ErrCodeConversion( errCode ) ) ) );
       
    88         aOutParamList.AppendL( TLiwGenericParam( KErrorCode,
       
    89             TLiwVariant( ErrCodeConversion( errCode ) ) ) );
       
    90         }
       
    91     }
       
    92 
       
    93 // ---------------------------------------------------------------------------
       
    94 // Closes the interface
       
    95 // ---------------------------------------------------------------------------
       
    96 //
       
    97 void CDataSourceInterface::Close()
       
    98     {
       
    99     delete this;
       
   100     }
       
   101 
       
   102 // ---------------------------------------------------------------------------
       
   103 // 
       
   104 // ---------------------------------------------------------------------------
       
   105 //
       
   106 CDataSourceInterface::CDataSourceInterface()
       
   107     {
       
   108 
       
   109     }
       
   110 
       
   111 // ---------------------------------------------------------------------------
       
   112 // 
       
   113 // ---------------------------------------------------------------------------
       
   114 //
       
   115 void CDataSourceInterface::ConstructL()
       
   116     {
       
   117     iCPClient = CCPClient::NewL( );
       
   118     CP_DEBUG( _L8("CDataSourceInterface::ConstructL") );
       
   119     }
       
   120 
       
   121 // ---------------------------------------------------------------------------
       
   122 //  
       
   123 // ---------------------------------------------------------------------------
       
   124 //
       
   125 void CDataSourceInterface::ProcessCommandL( const TDesC8& aCmdName,
       
   126     const CLiwGenericParamList& aInParamList,
       
   127     CLiwGenericParamList& aOutParamList, TUint aCmdOptions,
       
   128     MLiwNotifyCallback* aCallback )
       
   129     {
       
   130     CP_DEBUG( _L8("CCPClientInterface::ProcessCommandL") );
       
   131     TInt32 transactionId( -1 );
       
   132     if ( aCmdName.CompareF( KGetList ) == 0 )
       
   133         {
       
   134         CLiwGenericParamList* list = CLiwGenericParamList::NewL( );
       
   135         CleanupStack::PushL( list );
       
   136         iCPClient->GetListL( aInParamList, *list );
       
   137         CCPClientIterable* iterable = CCPClientIterable::NewL( list );
       
   138         CleanupStack::Pop( list );
       
   139         iterable->PushL( );
       
   140         aOutParamList.AppendL( TLiwGenericParam( KResults,
       
   141             TLiwVariant( iterable ) ) );
       
   142         CleanupStack::PopAndDestroy( iterable );
       
   143         }
       
   144     else if ( aCmdName.CompareF( KAdd ) == 0 )
       
   145         {
       
   146         iCPClient->AddL( aInParamList, aOutParamList );
       
   147         }
       
   148     else if ( aCmdName.CompareF( KDelete ) == 0 )
       
   149         {
       
   150         iCPClient->DeleteL( aInParamList );
       
   151         }
       
   152     else if ( aCmdName.CompareF( KRequestNotification ) == 0 )
       
   153         {
       
   154         if ( !(aCmdOptions & KLiwOptCancel) )
       
   155             {
       
   156             if ( !aCallback )
       
   157             	{
       
   158             	User::Leave( KErrPathNotFound );
       
   159             	}
       
   160             transactionId = aCallback->GetTransactionID();
       
   161             iCPClient->RegisterObserverL( aCallback, aInParamList, transactionId );
       
   162             }
       
   163         else
       
   164             {
       
   165             iCPClient->UnregisterObserversL( aInParamList );
       
   166             }
       
   167         }
       
   168     else if ( aCmdName.CompareF( KCmdCancel ) == 0 )
       
   169         {
       
   170         if ( aCmdOptions & KLiwOptCancel )
       
   171             {
       
   172             iCPClient->UnregisterObserversL( aInParamList );
       
   173             }
       
   174         }
       
   175     else
       
   176         {
       
   177         User::Leave( KErrNotSupported );
       
   178         }
       
   179     if ( transactionId != -1 )
       
   180         {
       
   181         aOutParamList.AppendL( TLiwGenericParam( KTransactionID,
       
   182             TLiwVariant( TInt32( transactionId ) ) ) );
       
   183         }
       
   184     }
       
   185 
       
   186 // ---------------------------------------------------------------------------
       
   187 // ErrCode Conversion
       
   188 // ---------------------------------------------------------------------------
       
   189 //
       
   190 TInt32 CDataSourceInterface::ErrCodeConversion( TInt code )
       
   191     {
       
   192     TInt32 err;
       
   193     switch ( code )
       
   194         {
       
   195         case KErrCancel:
       
   196             // Returning KErrNone incase of KErrCancel
       
   197         case KErrNone:
       
   198             err= SErrNone;
       
   199             break;
       
   200 
       
   201         case KErrNotFound:
       
   202             err= SErrNotFound;
       
   203             break;
       
   204 
       
   205         case KErrNoMemory:
       
   206             err = SErrNoMemory;
       
   207             break;
       
   208 
       
   209         case KErrInUse:
       
   210             err = SErrServiceInUse;
       
   211             break;
       
   212 
       
   213         case KErrNotSupported:
       
   214             err = SErrServiceNotSupported;
       
   215             break;
       
   216 
       
   217         case KErrBadName:
       
   218             err = SErrBadArgumentType;
       
   219             break;
       
   220 
       
   221         case KErrArgument:
       
   222             err = SErrInvalidServiceArgument;
       
   223             break;
       
   224 
       
   225         case KErrPermissionDenied:
       
   226             err = SErrAccessDenied;
       
   227             break;
       
   228             
       
   229         case KErrPathNotFound:
       
   230             err = SErrMissingArgument;
       
   231             break;
       
   232 
       
   233         default:
       
   234             err = SErrGeneralError;
       
   235             break;
       
   236         }
       
   237     return err;
       
   238     }