services/terminalmodeservice/src/upnptmclientprofileservice.cpp
branchRCL_3
changeset 10 594d15129e2c
parent 9 5c72fd91570d
equal deleted inserted replaced
9:5c72fd91570d 10:594d15129e2c
     1 /**
       
     2 * Copyright (c) 2010 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: CUpnpTmClientProfileService class implementation.
       
    15 *
       
    16 */
       
    17 
       
    18 // System includes
       
    19 #include <upnpdevice.h>
       
    20 #include <upnpservice.h>
       
    21 
       
    22 //User includes
       
    23 #include "upnptmclientprofileservice.h"
       
    24 #include "upnptmserverdevice.h"
       
    25 #include "upnptmserverimpl.h"
       
    26 #include "OstTraceDefinitions.h"
       
    27 #ifdef OST_TRACE_COMPILER_IN_USE
       
    28 #include "upnptmclientprofileserviceTraces.h"
       
    29 #endif
       
    30 
       
    31 
       
    32 //Defines different action names ,their arguments and their related state variables
       
    33 _LIT8(KGetMaxNumProfiles,              "GetMaxNumProfiles");
       
    34 _LIT8(KSetClientProfile,               "SetClientProfile");
       
    35 _LIT8(KGetClientProfile,               "GetClientProfile");
       
    36 _LIT8(KProfileId,                      "profileID");
       
    37 _LIT8(KClientProfile ,                 "clientProfile");
       
    38 _LIT8(KResultProfile ,                 "resultProfile");
       
    39 _LIT8(KNumProfilesAllowed ,            "numProfilesAllowed");
       
    40 _LIT8(KArgTypeUnusedProfileIds,        "UnusedProfileIDs");
       
    41 _LIT8(KArgTypeClientProfile,           "A_ARG_TYPE_ClientProfile");
       
    42 _LIT8(KArgTypeMaxProfiles,             "MaxNumProfiles");
       
    43 _LIT8(KArgTypeProfileId,               "A_ARG_TYPE_ProfileID");
       
    44 
       
    45 
       
    46 // ================= MEMBER FUNCTIONS ==============================================
       
    47 
       
    48 // ---------------------------------------------------------------------------------
       
    49 // CUpnpTmClientProfileService::CUpnpTmClientProfileService
       
    50 // C++ default constructor can NOT contain any code, that
       
    51 // might leave.
       
    52 // ---------------------------------------------------------------------------------
       
    53 //
       
    54 CUpnpTmClientProfileService::CUpnpTmClientProfileService( CUpnpDevice& aUpnpDevice,CUpnpTmServerImpl& aTmServerImpl )
       
    55     :CUpnpServiceImplementation(aUpnpDevice),iUpnpDevice(aUpnpDevice), iTmServerImpl(aTmServerImpl)
       
    56     {
       
    57     OstTraceFunctionEntry0( CUPNPTMCLIENTPROFILESERVICE_CUPNPTMCLIENTPROFILESERVICE_ENTRY );
       
    58     
       
    59     OstTraceFunctionExit0( CUPNPTMCLIENTPROFILESERVICE_CUPNPTMCLIENTPROFILESERVICE_EXIT );
       
    60     }
       
    61 
       
    62 // ---------------------------------------------------------------------------------
       
    63 // CUpnpTmClientProfileService::~CUpnpTmClientProfileService
       
    64 // C++ default destructor
       
    65 // ---------------------------------------------------------------------------------
       
    66 //
       
    67 CUpnpTmClientProfileService::~CUpnpTmClientProfileService()
       
    68     {
       
    69 
       
    70     }
       
    71 
       
    72 // ---------------------------------------------------------------------------------
       
    73 // CUpnpTmClientProfileService::ConstructL
       
    74 // Two-phased constructor.
       
    75 // Initialize variables, set parent service and create XML reader.
       
    76 // ---------------------------------------------------------------------------------
       
    77 //
       
    78 void CUpnpTmClientProfileService::ConstructL(const TDesC& aDescriptionPath )
       
    79     {
       
    80     OstTraceFunctionEntry0( CUPNPTMCLIENTPROFILESERVICE_CONSTRUCTL_ENTRY );
       
    81     _LIT8( KServiceType, "TmClientProfile:1" );
       
    82     BaseConstructL( aDescriptionPath, KServiceType);
       
    83 
       
    84     SetStateVariableL( KArgTypeUnusedProfileIds, KEmptyString, EFalse );
       
    85     SetStateVariableL( KArgTypeClientProfile, KEmptyString, EFalse );
       
    86     SetStateVariableL( KArgTypeMaxProfiles, KEmptyString, EFalse );
       
    87     SetStateVariableL( KArgTypeProfileId, KEmptyString, EFalse );
       
    88     OstTraceFunctionExit0( CUPNPTMCLIENTPROFILESERVICE_CONSTRUCTL_EXIT );
       
    89     }
       
    90 
       
    91 // ---------------------------------------------------------------------------------
       
    92 // CUpnpTmClientProfileService::NewL
       
    93 // Two-phased constructor.
       
    94 // ---------------------------------------------------------------------------------
       
    95 //
       
    96 CUpnpTmClientProfileService* CUpnpTmClientProfileService::NewL(CUpnpDevice& aUpnpDevice, const TDesC& aDescriptionPath, CUpnpTmServerImpl& aTmServerImp )
       
    97     {
       
    98     OstTraceFunctionEntry0( CUPNPTMCLIENTPROFILESERVICE_NEWL_ENTRY );
       
    99     CUpnpTmClientProfileService* clientProfileService = new (ELeave) CUpnpTmClientProfileService(aUpnpDevice, aTmServerImp);
       
   100     CleanupStack::PushL( clientProfileService );
       
   101     clientProfileService->ConstructL( aDescriptionPath );
       
   102     CleanupStack::Pop( clientProfileService );
       
   103     OstTraceFunctionExit0( CUPNPTMCLIENTPROFILESERVICE_NEWL_EXIT );
       
   104     return clientProfileService;
       
   105     }
       
   106 
       
   107 // ---------------------------------------------------------------------------------
       
   108 // CUpnpTmClientProfileService::ActionReceivedLD
       
   109 // @param aAction action received from the client
       
   110 // ---------------------------------------------------------------------------------
       
   111 //
       
   112 void CUpnpTmClientProfileService::ActionReceivedLD( CUpnpAction* aAction )
       
   113     {
       
   114     OstTraceFunctionEntry0( CUPNPTMCLIENTPROFILESERVICE_ACTIONRECEIVEDLD_ENTRY );
       
   115     if ( !aAction )
       
   116         {
       
   117         User::Leave( KErrNotFound );
       
   118         }
       
   119     CleanupStack::PushL( aAction );
       
   120     TUpnpErrorCode eCode = EHttpOk;
       
   121     
       
   122     // Get the name, saves calls in the if-else statements
       
   123     TPtrC8 name( aAction->Name() );
       
   124     // Verify the action and do the operation(s)
       
   125     if ( name.Compare( KGetMaxNumProfiles ) == 0 )
       
   126         {
       
   127         eCode = GetMaxNumProfilesActionL( aAction );
       
   128         }
       
   129     else if ( name.Compare( KSetClientProfile ) == 0 )
       
   130         {
       
   131         eCode = SetClientProfileActionL( aAction );
       
   132         }
       
   133     else if ( name.Compare( KGetClientProfile ) == 0 )
       
   134         {
       
   135         eCode = GetClientProfileActionL ( aAction );
       
   136         }
       
   137     else
       
   138         {
       
   139         eCode = EInvalidAction;
       
   140         }
       
   141     SendL( aAction, eCode );
       
   142     CleanupStack::PopAndDestroy( aAction );
       
   143     OstTraceFunctionExit0( CUPNPTMCLIENTPROFILESERVICE_ACTIONRECEIVEDLD_EXIT );
       
   144     }
       
   145 
       
   146 // ---------------------------------------------------------------------------------
       
   147 // CUpnpTmClientProfileService::GetMaxNumProfilesActionL
       
   148 // @param aAction pointer to action object
       
   149 // @return Returns upnp error code
       
   150 // ---------------------------------------------------------------------------------
       
   151 //
       
   152 TUpnpErrorCode CUpnpTmClientProfileService::GetMaxNumProfilesActionL( CUpnpAction* aAction )
       
   153    {
       
   154    OstTraceFunctionEntry0( CUPNPTMCLIENTPROFILESERVICE_GETMAXNUMPROFILESACTIONL_ENTRY );
       
   155    TUint profileCount;
       
   156    TTerminalModeErrorCode ret = iTmServerImpl.GetMaxNumProfiles( profileCount );
       
   157    if ( ret != ETerminalModeSuccess ) 
       
   158        {
       
   159        OstTrace0( TRACE_ERROR, DUP1_CUPNPTMCLIENTPROFILESERVICE_GETMAXNUMPROFILESACTIONL, "CUpnpTmClientProfileService::GetMaxNumProfilesActionL" );
       
   160        return TUpnpErrorCode( ret );       
       
   161        } 
       
   162    OstTrace1( TRACE_NORMAL, CUPNPTMCLIENTPROFILESERVICE_GETMAXNUMPROFILESACTIONL, "CUpnpTmClientProfileService::GetMaxNumProfilesActionL;profileCount=%d", profileCount );      
       
   163    TBuf8<UpnpString::KMaxTUintLength> countBuf;
       
   164    countBuf.Num(profileCount);
       
   165    
       
   166    aAction->SetArgumentL( KNumProfilesAllowed, countBuf ); 
       
   167    OstTraceFunctionExit0( CUPNPTMCLIENTPROFILESERVICE_GETMAXNUMPROFILESACTIONL_EXIT );
       
   168    return EHttpOk;
       
   169    }
       
   170 
       
   171 // -------------------------------------------------------------------------------------
       
   172 // CUpnpTmClientProfileService::SetClientProfileActionL
       
   173 // @param aAction  Pointer to UPnP action object
       
   174 // @return Returns upnp error code
       
   175 // ---------------------------------------------------------------------------------
       
   176 //
       
   177 TUpnpErrorCode CUpnpTmClientProfileService::SetClientProfileActionL( CUpnpAction* aAction )
       
   178     {
       
   179     OstTraceFunctionEntry0( CUPNPTMCLIENTPROFILESERVICE_SETCLIENTPROFILEACTIONL_ENTRY );
       
   180     TUint profileIdInt;
       
   181     // Fetch the value for profile ID argument
       
   182     TLex8 lex( aAction->ArgumentValue(KProfileId) );
       
   183     lex.Val(profileIdInt);
       
   184     OstTrace1( TRACE_ERROR, CUPNPTMCLIENTPROFILESERVICE_SETCLIENTPROFILEACTIONL, "CUpnpTmClientProfileService::SetClientProfileActionL;profileIdInt=%d", profileIdInt );      
       
   185     
       
   186     // Fetch the value for client profile argument
       
   187     const TDesC8& clientProfile = aAction->ArgumentValue(KClientProfile);
       
   188     
       
   189     RBuf8 resultProfileBuf;
       
   190     TTerminalModeErrorCode ret = iTmServerImpl.SetClientProfile( profileIdInt,clientProfile,resultProfileBuf );
       
   191     if ( ret != ETerminalModeSuccess )
       
   192        {
       
   193        resultProfileBuf.Close();
       
   194        OstTrace0( TRACE_ERROR, DUP1_CUPNPTMCLIENTPROFILESERVICE_SETCLIENTPROFILEACTIONL, "CUpnpTmClientProfileService::SetClientProfileActionL" );
       
   195        return TUpnpErrorCode( ret );
       
   196        }
       
   197     CleanupClosePushL(resultProfileBuf);
       
   198     aAction->SetArgumentL( KResultProfile , resultProfileBuf );
       
   199     CleanupStack::PopAndDestroy(&resultProfileBuf);
       
   200     OstTraceFunctionExit0( CUPNPTMCLIENTPROFILESERVICE_SETCLIENTPROFILEACTIONL_EXIT );
       
   201     return EHttpOk;  
       
   202     }
       
   203 
       
   204 // ---------------------------------------------------------------------------------
       
   205 // CUpnpTmClientProfileService::GetClientProfileActionL
       
   206 // @param aAction pointer to action object
       
   207 // @return Returns upnp error code
       
   208 // ---------------------------------------------------------------------------------
       
   209 //
       
   210 TUpnpErrorCode CUpnpTmClientProfileService::GetClientProfileActionL( CUpnpAction* aAction )
       
   211     { 
       
   212     OstTraceFunctionEntry0( CUPNPTMCLIENTPROFILESERVICE_GETCLIENTPROFILEACTIONL_ENTRY );
       
   213     TUint profileIdInt;
       
   214     // Fetch the value for profile ID argument
       
   215     TLex8 lex( aAction->ArgumentValue(KProfileId) );
       
   216     lex.Val(profileIdInt);
       
   217     OstTrace1( TRACE_ERROR, CUPNPTMCLIENTPROFILESERVICE_GETCLIENTPROFILEACTIONL, "CUpnpTmClientProfileService::GetClientProfileActionL;profileIdInt=%d", profileIdInt );        
       
   218 
       
   219     RBuf8 resultProfileBuf;
       
   220     TTerminalModeErrorCode ret = iTmServerImpl.GetClientProfile(profileIdInt,resultProfileBuf );
       
   221     
       
   222     if ( ret != ETerminalModeSuccess )
       
   223        {
       
   224        resultProfileBuf.Close();
       
   225        OstTrace0( TRACE_ERROR, DUP1_CUPNPTMCLIENTPROFILESERVICE_GETCLIENTPROFILEACTIONL, "CUpnpTmClientProfileService::GetClientProfileActionL" ); 
       
   226        return TUpnpErrorCode( ret );
       
   227        }
       
   228     CleanupClosePushL(resultProfileBuf);
       
   229     aAction->SetArgumentL( KClientProfile,resultProfileBuf ); 
       
   230     CleanupStack::PopAndDestroy(&resultProfileBuf);
       
   231     OstTraceFunctionExit0( CUPNPTMCLIENTPROFILESERVICE_GETCLIENTPROFILEACTIONL_EXIT );
       
   232     return EHttpOk;   
       
   233     }
       
   234 
       
   235 // ---------------------------------------------------------------------------------
       
   236 // CUpnpTmAppServerService::UnusedProfileIdEventL
       
   237 // Notifies the client about the status updates.
       
   238 // @param aUnusedProfileIdBuffer Buffer holding the unused profile IDs information.
       
   239 // ---------------------------------------------------------------------------------
       
   240 //
       
   241 void CUpnpTmClientProfileService::UnUsedProfileIdEventL(const TDesC8& aUnusedProfileIdBuffer)
       
   242     {
       
   243     OstTraceFunctionEntry0( CUPNPTMCLIENTPROFILESERVICE_UNUSEDPROFILEIDEVENTL_ENTRY );
       
   244     SetStateVariableL( KArgTypeUnusedProfileIds, aUnusedProfileIdBuffer, EFalse);
       
   245     OstTraceFunctionExit0( CUPNPTMCLIENTPROFILESERVICE_UNUSEDPROFILEIDEVENTL_EXIT );
       
   246     }
       
   247 
       
   248 //End of File