homescreensrv_plat/sapi_contentpublishing/src/cpclient.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 <liwgenericparam.h>
       
    20 
       
    21 #include "cpliwmap.h"
       
    22 #include "cpclient.h"
       
    23 #include "cpserverdef.h"
       
    24 #include "cpdebug.h"
       
    25 #include "cpclientactivenotifier.h"
       
    26 
       
    27 // ======== MEMBER FUNCTIONS ========
       
    28 
       
    29 // -----------------------------------------------------------------------------
       
    30 // 
       
    31 // -----------------------------------------------------------------------------
       
    32 // 
       
    33 CCPClient::CCPClient()
       
    34     {
       
    35     }
       
    36 
       
    37 // -----------------------------------------------------------------------------
       
    38 // 
       
    39 // -----------------------------------------------------------------------------
       
    40 // 
       
    41 void CCPClient::ConstructL()
       
    42     {
       
    43 
       
    44 #ifdef CONTENT_PUBLISHER_DEBUG
       
    45     if(!CCPDebug::Enable())
       
    46         {
       
    47         iDebug = CCPDebug::NewL( KCPDebugFileName );
       
    48         }
       
    49 #endif
       
    50     CP_DEBUG( _L8("CCPClient::ConstructL()") );
       
    51     User::LeaveIfError( iServerClient.Connect( ) );
       
    52     }
       
    53 
       
    54 // -----------------------------------------------------------------------------
       
    55 // 
       
    56 // -----------------------------------------------------------------------------
       
    57 //
       
    58 CCPClient* CCPClient::NewL()
       
    59     {
       
    60     CCPClient* self = CCPClient::NewLC( );
       
    61     CleanupStack::Pop( self );
       
    62     return self;
       
    63     }
       
    64 
       
    65 // -----------------------------------------------------------------------------
       
    66 // 
       
    67 // -----------------------------------------------------------------------------
       
    68 //    
       
    69 CCPClient* CCPClient::NewLC()
       
    70     {
       
    71     CCPClient* self = new( ELeave ) CCPClient;
       
    72     CleanupStack::PushL( self );
       
    73     self->ConstructL( );
       
    74     return self;
       
    75     }
       
    76 
       
    77 // -----------------------------------------------------------------------------
       
    78 // 
       
    79 // -----------------------------------------------------------------------------
       
    80 //
       
    81 CCPClient::~CCPClient()
       
    82     {
       
    83     CP_DEBUG( _L8("CCPClient::~CCPClient()") );
       
    84     delete iActiveNotifier;
       
    85     iServerClient.Close( );
       
    86 #ifdef CONTENT_PUBLISHER_DEBUG
       
    87     delete iDebug;
       
    88 #endif
       
    89     }
       
    90 
       
    91 // -----------------------------------------------------------------------------
       
    92 // 
       
    93 // -----------------------------------------------------------------------------
       
    94 //       
       
    95 void CCPClient::GetListL( const CLiwGenericParamList& aInParamList,
       
    96     CLiwGenericParamList& aOutParamList )
       
    97     {
       
    98     CP_DEBUG( _L8("CCPClient::GetListL()") );
       
    99     CheckMapL( aInParamList, KFilter );
       
   100     CCPLiwMap* inMapForServer = CCPLiwMap::NewL( aInParamList );
       
   101     inMapForServer->PushL( );
       
   102     inMapForServer->IsValidForGetListL( );
       
   103     iServerClient.GetListL( *inMapForServer, aOutParamList );
       
   104     CleanupStack::PopAndDestroy( inMapForServer );
       
   105     }
       
   106 
       
   107 // -----------------------------------------------------------------------------
       
   108 // 
       
   109 // -----------------------------------------------------------------------------
       
   110 //     
       
   111 void CCPClient::AddL( const CLiwGenericParamList& aInParamList,
       
   112     CLiwGenericParamList& aOutParamList )
       
   113     {
       
   114     CP_DEBUG( _L8("CCPClient::AddL()") );
       
   115     CheckMapL( aInParamList, KItem );
       
   116     CCPLiwMap* inMapForServer = CCPLiwMap::NewL( aInParamList ) ;
       
   117     inMapForServer->PushL( );
       
   118     inMapForServer->IsValidForAddL( );
       
   119     iServerClient.AddL( *inMapForServer, aOutParamList );
       
   120     CleanupStack::PopAndDestroy( inMapForServer );
       
   121     }
       
   122 
       
   123 // -----------------------------------------------------------------------------
       
   124 // 
       
   125 // -----------------------------------------------------------------------------
       
   126 //     
       
   127 void CCPClient::DeleteL( const CLiwGenericParamList& aInParamList )
       
   128     {
       
   129     CP_DEBUG( _L8("CCPClient::DeleteL()") );
       
   130     CheckMapL( aInParamList, KData );
       
   131     CCPLiwMap* inMapForServer = CCPLiwMap::NewL( aInParamList );
       
   132     inMapForServer->PushL( );
       
   133     inMapForServer->IsValidForDeleteL( );
       
   134     iServerClient.DeleteL( *inMapForServer );
       
   135     CleanupStack::PopAndDestroy( inMapForServer );
       
   136     }
       
   137 
       
   138 // -----------------------------------------------------------------------------
       
   139 // 
       
   140 // -----------------------------------------------------------------------------
       
   141 //    
       
   142 void CCPClient::RegisterObserverL( MLiwNotifyCallback* aObserver,
       
   143     const CLiwGenericParamList& aInParamList, TInt32 aTransactionId )
       
   144     {
       
   145     CP_DEBUG( _L8("CCPClient::RegisterObserverL()") );
       
   146     CheckMapL( aInParamList, KFilter );
       
   147     CCPLiwMap* inMapForServer = CCPLiwMap::NewL( aInParamList );
       
   148     inMapForServer->PushL( );
       
   149     inMapForServer->IsValidForNotificationL( );
       
   150     if ( !iActiveNotifier )
       
   151         {
       
   152         iActiveNotifier = CCPActiveNotifier::NewL( iServerClient );
       
   153         }
       
   154     iActiveNotifier->RegisterL( aObserver, aTransactionId, inMapForServer );
       
   155     CleanupStack::PopAndDestroy( inMapForServer );
       
   156     }
       
   157 
       
   158 // -----------------------------------------------------------------------------
       
   159 // 
       
   160 // -----------------------------------------------------------------------------
       
   161 //     
       
   162 void CCPClient::UnregisterObserversL( const CLiwGenericParamList& aInParamList )
       
   163     {
       
   164     CP_DEBUG( _L8("CCPClient::UnregisterObservers()") );
       
   165     if ( !iActiveNotifier )
       
   166         {
       
   167         User::Leave( KErrNotFound );
       
   168         }  
       
   169     TInt32 transactionId( -1 );
       
   170     const TLiwGenericParam* param = NULL;
       
   171     TInt pos( 0 );
       
   172     param = aInParamList.FindFirst( pos, KTransactionID );
       
   173     if( !param ||
       
   174 		pos == KErrNotFound ||
       
   175 		!param->Value().Get( transactionId ) ||
       
   176 		transactionId < 0 )
       
   177     	{
       
   178     	iActiveNotifier->UnregisterAllL(  );
       
   179         delete iActiveNotifier;
       
   180         iActiveNotifier = NULL;
       
   181     	}
       
   182     else
       
   183     	{
       
   184     	if( iActiveNotifier->UnregisterL( transactionId ) )
       
   185     		{
       
   186     		//delete only if it was the last observer
       
   187     	    delete iActiveNotifier;
       
   188     	    iActiveNotifier = NULL;
       
   189     		}
       
   190     	}
       
   191     }
       
   192 
       
   193 // -----------------------------------------------------------------------------
       
   194 // 
       
   195 // -----------------------------------------------------------------------------
       
   196 //    
       
   197 void CCPClient::ExecuteActionL( const CLiwGenericParamList& aInParamList )
       
   198     {
       
   199     CP_DEBUG( _L8("CCPClient::RegisterObserverL()") );
       
   200     CheckMapL( aInParamList, KFilter );
       
   201     CCPLiwMap* inMapForServer = CCPLiwMap::NewL( aInParamList );
       
   202     inMapForServer->PushL( );
       
   203     inMapForServer->IsValidForActionL( );
       
   204     iServerClient.ExecuteActionL( *inMapForServer );
       
   205     CleanupStack::PopAndDestroy( inMapForServer );
       
   206     }
       
   207 
       
   208 // -----------------------------------------------------------------------------
       
   209 // 
       
   210 // -----------------------------------------------------------------------------
       
   211 //    
       
   212 void CCPClient::CheckMapL( const CLiwGenericParamList& aInParamList, 
       
   213         const TDesC8& aKey )
       
   214     {
       
   215     const TLiwGenericParam* param = NULL;
       
   216     TInt pos( 0 );
       
   217     param = aInParamList.FindFirst( pos, aKey );
       
   218     if( pos !=KErrNotFound )
       
   219         {
       
   220         if( param->Value().TypeId( ) != LIW::EVariantTypeMap )
       
   221             {
       
   222             User::Leave( KErrBadName );
       
   223             }
       
   224         }
       
   225     }