mtpdataproviders/mtpplaybackcontroldp/src/cmtppbcsetdevicepropvalue.cpp
branchRCL_3
changeset 19 0aa8cc770c8a
equal deleted inserted replaced
18:453dfc402455 19:0aa8cc770c8a
       
     1 // Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
       
     2 // All rights reserved.
       
     3 // This component and the accompanying materials are made available
       
     4 // under the terms of "Eclipse Public License v1.0"
       
     5 // which accompanies this distribution, and is available
       
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     7 //
       
     8 // Initial Contributors:
       
     9 // Nokia Corporation - initial contribution.
       
    10 //
       
    11 // Contributors:
       
    12 //
       
    13 // Description:
       
    14 //
       
    15 
       
    16 /**
       
    17  @file
       
    18  @internalComponent
       
    19 */
       
    20 
       
    21 #include <mtp/mmtpdataproviderframework.h>
       
    22 #include <mtp/mtpprotocolconstants.h>
       
    23 
       
    24 #include "cmtppbcsetdevicepropvalue.h"
       
    25 #include "mtpplaybackcontroldpconst.h"
       
    26 #include "cmtpplaybackcontroldp.h"
       
    27 #include "cmtpplaybackproperty.h"
       
    28 #include "cmtpplaybackcommand.h"
       
    29 #include "mtpplaybackcontrolpanic.h"
       
    30 
       
    31 // Class constants.
       
    32 __FLOG_STMT(_LIT8(KComponent,"SetPlaybackDevicePropValue");)
       
    33 
       
    34 /**
       
    35 Two-phase constructor.
       
    36 @param aPlugin  The data provider plugin
       
    37 @param aFramework The data provider framework
       
    38 @param aConnection The connection from which the request comes
       
    39 @return a pointer to the created request processor object.
       
    40 */
       
    41 MMTPRequestProcessor* CMTPPbcSetDevicePropValue::NewL(MMTPDataProviderFramework& aFramework,
       
    42                                                     MMTPConnection& aConnection, 
       
    43                                                     CMTPPlaybackControlDataProvider& aDataProvider)
       
    44     {
       
    45     CMTPPbcSetDevicePropValue* self = new (ELeave) CMTPPbcSetDevicePropValue(aFramework, aConnection, aDataProvider);
       
    46     return self;
       
    47     }
       
    48 
       
    49 /**
       
    50 Destructor
       
    51 */    
       
    52 CMTPPbcSetDevicePropValue::~CMTPPbcSetDevicePropValue()
       
    53     {    
       
    54     __FLOG(_L8("~CMTPPbcSetDevicePropValue - Entry"));
       
    55     delete iPbCmd;
       
    56     __FLOG(_L8("~CMTPPbcSetDevicePropValue - Exit"));
       
    57     __FLOG_CLOSE;
       
    58     }
       
    59 
       
    60 /**
       
    61 Standard c++ constructor
       
    62 */    
       
    63 CMTPPbcSetDevicePropValue::CMTPPbcSetDevicePropValue(MMTPDataProviderFramework& aFramework,
       
    64                                                MMTPConnection& aConnection,
       
    65                                                CMTPPlaybackControlDataProvider& aDataProvider):
       
    66     CMTPRequestProcessor(aFramework, aConnection, 0, NULL),
       
    67     iPlaybackControlDp(aDataProvider)
       
    68     {
       
    69     //Open the log system
       
    70     __FLOG_OPEN(KMTPSubsystem, KComponent);
       
    71     }
       
    72     
       
    73 /**
       
    74 CMTPPbcSetDevicePropValue request validator.
       
    75 @return EMTPRespCodeOK if request is verified, otherwise one of the error response codes
       
    76 */
       
    77 TMTPResponseCode CMTPPbcSetDevicePropValue::CheckRequestL()
       
    78     {
       
    79     __FLOG(_L8("CheckRequestL - Entry"));
       
    80     TMTPResponseCode respCode = CMTPRequestProcessor::CheckRequestL();
       
    81     if(respCode == EMTPRespCodeOK)
       
    82         {
       
    83         respCode = EMTPRespCodeDevicePropNotSupported;
       
    84         TUint32 propCode = Request().Uint32(TMTPTypeRequest::ERequestParameter1);
       
    85         const TInt count = sizeof(KMTPPlaybackControlDpSupportedProperties) / sizeof(KMTPPlaybackControlDpSupportedProperties[0]);
       
    86         for (TUint i(0); (i < count); i++)
       
    87             {
       
    88             if (propCode == KMTPPlaybackControlDpSupportedProperties[i])
       
    89                 {
       
    90                 respCode = EMTPRespCodeOK;
       
    91                 break;
       
    92                 }
       
    93             }
       
    94         }
       
    95 
       
    96     __FLOG(_L8("CheckRequestL - Exit"));
       
    97     return respCode;
       
    98     }
       
    99 
       
   100 /**
       
   101 Process the transaction response phase.
       
   102 */    
       
   103 TBool CMTPPbcSetDevicePropValue::DoHandleResponsePhaseL()
       
   104     {
       
   105     __FLOG(_L8("DoHandleResponsePhaseL - Entry"));
       
   106 
       
   107     CMTPPlaybackMap& map(iPlaybackControlDp.GetPlaybackMap());
       
   108     //Destroy the previous playback command.
       
   109     delete iPbCmd;
       
   110     iPbCmd = NULL;
       
   111     
       
   112     //Get a new playback command.
       
   113     TInt result = map.GetPlaybackControlCommand(iData, &iPbCmd);
       
   114 
       
   115     if(KErrNone == result)
       
   116         {
       
   117         MMTPPlaybackControl& control(iPlaybackControlDp.GetPlaybackControlL());
       
   118         TRAPD(err, control.CommandL(*iPbCmd, this));
       
   119         __ASSERT_ALWAYS((err == KErrNone), SendResponseL(EMTPRespCodeInvalidDevicePropValue));
       
   120         }
       
   121     else if(KErrNotSupported == result)
       
   122         {
       
   123         SendResponseL(EMTPRespCodeDevicePropNotSupported);
       
   124         }
       
   125     else
       
   126         {
       
   127         SendResponseL(EMTPRespCodeInvalidDevicePropValue);
       
   128         }
       
   129 
       
   130     __FLOG(_L8("DoHandleResponsePhaseL - Exit"));    
       
   131     return EFalse;    
       
   132     }
       
   133     
       
   134 void CMTPPbcSetDevicePropValue::ServiceL()
       
   135     {
       
   136     __FLOG(_L8("ServiceL - Entry"));
       
   137     TMTPDevicePropertyCode propCode(static_cast<TMTPDevicePropertyCode>(Request().
       
   138                                     Uint32(TMTPTypeRequest::ERequestParameter1)));
       
   139     iData.iOptCode = EMTPOpCodeSetDevicePropValue;
       
   140     iData.iDevPropCode = propCode;
       
   141     switch(propCode)
       
   142         {
       
   143     case EMTPDevicePropCodePlaybackRate:
       
   144         {
       
   145         ReceiveDataL(iData.iPropValInt32);
       
   146         }
       
   147         break;
       
   148     case EMTPDevicePropCodeVolume:
       
   149     case EMTPDevicePropCodePlaybackObject:
       
   150     case EMTPDevicePropCodePlaybackContainerIndex:
       
   151     case EMTPDevicePropCodePlaybackPosition:
       
   152         {
       
   153         ReceiveDataL(iData.iPropValUint32);        
       
   154         }
       
   155         break;
       
   156         
       
   157     default:
       
   158         {
       
   159         SendResponseL(EMTPRespCodeDevicePropNotSupported);
       
   160         }
       
   161         break;             
       
   162         }
       
   163     __FLOG(_L8("ServiceL - Exit"));
       
   164     }
       
   165 
       
   166 void CMTPPbcSetDevicePropValue::HandlePlaybackCommandCompleteL(CMTPPlaybackCommand* aCmd, TInt aErr)
       
   167     {
       
   168     __FLOG(_L8("HandlePlaybackCommandCompleteL - Entry"));
       
   169     __FLOG_1(_L8("aErr %d"), aErr);
       
   170     
       
   171     //Handle error response.
       
   172      TMTPResponseCode response;
       
   173      switch(aErr)
       
   174          {
       
   175          case KPlaybackErrNone:
       
   176              {
       
   177              response = EMTPRespCodeOK;            
       
   178              }
       
   179              break;
       
   180          case KPlaybackErrDeviceUnavailable:
       
   181              {
       
   182              response = EMTPRespCodeDeviceBusy;
       
   183              iPlaybackControlDp.RequestToResetPbCtrl();
       
   184              }
       
   185              break;
       
   186          case KPlaybackErrContextInvalid:
       
   187              {
       
   188             CMTPPlaybackProperty& prop(iPlaybackControlDp.GetPlaybackProperty());
       
   189             if(prop.IsDefaultPropertyValueL(iData))
       
   190                 {
       
   191                 response = EMTPRespCodeOK;                
       
   192                 }
       
   193             else
       
   194                 {
       
   195                 response = EMTPRespCodeAccessDenied;    
       
   196                 }   
       
   197              }
       
   198              break;
       
   199          case KPlaybackErrParamInvalid:
       
   200              {
       
   201              response = EMTPRespCodeInvalidDevicePropValue;
       
   202              }
       
   203              break;
       
   204          default:
       
   205              {
       
   206              response = EMTPRespCodeDeviceBusy;
       
   207              }
       
   208              break;
       
   209          }
       
   210      
       
   211      SendResponseL(response);
       
   212      
       
   213      if(aCmd != NULL)
       
   214          {
       
   215          __ASSERT_DEBUG((aCmd->PlaybackCommand() == iPbCmd->PlaybackCommand()), Panic(EMTPPBArgumentErr));
       
   216          __FLOG_1(_L8("aCmd %d"), aCmd->PlaybackCommand());
       
   217          }
       
   218 
       
   219     __FLOG(_L8("HandlePlaybackCommandCompleteL - Exit"));
       
   220     }