mtpdataproviders/mtpplaybackcontroldp/src/cmtppbcgetdevicepropvalue.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 #include <mtp/tmtptyperequest.h>
       
    24 
       
    25 #include "cmtppbcgetdevicepropvalue.h"
       
    26 #include "mtpplaybackcontroldpconst.h"
       
    27 #include "cmtpplaybackcontroldp.h"
       
    28 #include "cmtpplaybackproperty.h"
       
    29 #include "cmtpplaybackcommand.h"
       
    30 #include "mtpplaybackcontrolpanic.h"
       
    31 
       
    32 
       
    33 // Class constants.
       
    34 __FLOG_STMT(_LIT8(KComponent,"GetPlaybackDevicePropValue");)
       
    35 
       
    36 /**
       
    37 Two-phase constructor.
       
    38 @param aPlugin  The data provider plugin
       
    39 @param aFramework The data provider framework
       
    40 @param aConnection The connection from which the request comes
       
    41 @return a pointer to the created request processor object.
       
    42 */  
       
    43 MMTPRequestProcessor* CMTPPbcGetDevicePropValue::NewL(MMTPDataProviderFramework& aFramework, 
       
    44                                                    MMTPConnection& aConnection, 
       
    45                                                    CMTPPlaybackControlDataProvider& aDataProvider)
       
    46     {
       
    47     CMTPPbcGetDevicePropValue* self = new (ELeave) CMTPPbcGetDevicePropValue(aFramework, aConnection, aDataProvider);
       
    48     return self;
       
    49     }
       
    50 
       
    51 /**
       
    52 Destructor.
       
    53 */    
       
    54 CMTPPbcGetDevicePropValue::~CMTPPbcGetDevicePropValue()
       
    55     {
       
    56     __FLOG(_L8("~CMTPPbcGetDevicePropValue - Entry"));
       
    57     delete iPbCmd;
       
    58     __FLOG(_L8("~CMTPPbcGetDevicePropValue - Exit"));
       
    59     __FLOG_CLOSE;
       
    60     }
       
    61 
       
    62 /**
       
    63 Constructor.
       
    64 */    
       
    65 CMTPPbcGetDevicePropValue::CMTPPbcGetDevicePropValue(MMTPDataProviderFramework& aFramework, 
       
    66                                                 MMTPConnection& aConnection,
       
    67                                                 CMTPPlaybackControlDataProvider& aDataProvider):
       
    68     CMTPRequestProcessor(aFramework, aConnection, 0, NULL),
       
    69     iPlaybackControlDp(aDataProvider)
       
    70     {
       
    71     //Open the log system
       
    72     __FLOG_OPEN(KMTPSubsystem, KComponent);
       
    73     }
       
    74 
       
    75 /**
       
    76 CMTPPbcGetDevicePropValue request validator.
       
    77 @return EMTPRespCodeOK if request is verified, otherwise one of the error response codes
       
    78 */
       
    79 TMTPResponseCode CMTPPbcGetDevicePropValue::CheckRequestL()
       
    80     {
       
    81     __FLOG(_L8("CheckRequestL - Entry"));
       
    82     TMTPResponseCode respCode = CMTPRequestProcessor::CheckRequestL();
       
    83     if(respCode == EMTPRespCodeOK)
       
    84         {
       
    85         respCode = EMTPRespCodeDevicePropNotSupported;
       
    86         TUint32 propCode = Request().Uint32(TMTPTypeRequest::ERequestParameter1);
       
    87         const TInt count = sizeof(KMTPPlaybackControlDpSupportedProperties) / 
       
    88                            sizeof(KMTPPlaybackControlDpSupportedProperties[0]);
       
    89         for (TUint i(0); (i < count); i++)
       
    90             {
       
    91             if (propCode == KMTPPlaybackControlDpSupportedProperties[i])
       
    92                 {
       
    93                 respCode = EMTPRespCodeOK;
       
    94                 break;
       
    95                 }
       
    96             }
       
    97         }
       
    98     __FLOG(_L8("CheckRequestL - Exit"));
       
    99     return respCode;
       
   100     }
       
   101 
       
   102 /**
       
   103 CMTPPbcGetDevicePropValue request handler.
       
   104 */   
       
   105 void CMTPPbcGetDevicePropValue::ServiceL()
       
   106     {
       
   107     __FLOG(_L8("ServiceL - Entry"));
       
   108     //Destroy the previous playback command.
       
   109     delete iPbCmd;
       
   110     iPbCmd = NULL;
       
   111     
       
   112     //Get the device property code
       
   113     TMTPDevicePropertyCode propCode(static_cast<TMTPDevicePropertyCode>(Request().
       
   114                                     Uint32(TMTPTypeRequest::ERequestParameter1)));
       
   115     
       
   116     TMTPPbCtrlData data;
       
   117     data.iOptCode = EMTPOpCodeGetDevicePropValue;
       
   118     data.iDevPropCode = propCode;
       
   119 
       
   120     //Get a new playback command.
       
   121     CMTPPlaybackMap& map(iPlaybackControlDp.GetPlaybackMap());
       
   122     TInt result = map.GetPlaybackControlCommand(data, &iPbCmd);
       
   123 
       
   124     if(KErrNone == result)
       
   125         {
       
   126         MMTPPlaybackControl& control(iPlaybackControlDp.GetPlaybackControlL());
       
   127         TRAPD(err, control.CommandL(*iPbCmd, this));
       
   128         __ASSERT_ALWAYS((err == KErrNone), SendResponseL(EMTPRespCodeParameterNotSupported));
       
   129         }
       
   130     else if(KErrNotSupported == result)
       
   131         {
       
   132         SendResponseL(EMTPRespCodeDevicePropNotSupported);
       
   133         }
       
   134     else
       
   135         {
       
   136         SendResponseL(EMTPRespCodeParameterNotSupported);
       
   137         }
       
   138     __FLOG(_L8("ServiceL - Exit"));
       
   139     }
       
   140 
       
   141 void CMTPPbcGetDevicePropValue::HandlePlaybackCommandCompleteL(CMTPPlaybackCommand* aCmd, TInt aErr)
       
   142     {
       
   143     __FLOG(_L8("HandlePlaybackCommandCompleteL - Entry"));
       
   144     __FLOG_1(_L8("aErr %d"), aErr);
       
   145 
       
   146     //Handle the error
       
   147     TBool useDefault = EFalse;
       
   148     switch(aErr)
       
   149         {
       
   150         case KPlaybackErrNone:
       
   151             {
       
   152             __ASSERT_DEBUG((aCmd != NULL), Panic(EMTPPBDataNullErr));
       
   153             __ASSERT_DEBUG((aCmd->PlaybackCommand() == iPbCmd->PlaybackCommand()), Panic(EMTPPBArgumentErr));
       
   154             __ASSERT_ALWAYS((aCmd != NULL), User::Leave(KErrArgument));
       
   155             __ASSERT_ALWAYS((aCmd->PlaybackCommand() == iPbCmd->PlaybackCommand()), User::Leave(KErrArgument));
       
   156             __FLOG_1(_L8("aCmd %d"), aCmd->PlaybackCommand());
       
   157             }
       
   158             break;
       
   159         case KPlaybackErrContextInvalid:
       
   160             {
       
   161             useDefault = ETrue;
       
   162             }
       
   163             break;
       
   164         case KPlaybackErrDeviceUnavailable:
       
   165             {
       
   166             iPlaybackControlDp.RequestToResetPbCtrl();
       
   167             SendResponseL(EMTPRespCodeDeviceBusy);
       
   168             }
       
   169             return;
       
   170         default:
       
   171             {
       
   172             SendResponseL(EMTPRespCodeDeviceBusy);
       
   173             }
       
   174             return;
       
   175         }
       
   176 
       
   177     CMTPPlaybackProperty& property(iPlaybackControlDp.GetPlaybackProperty());
       
   178     TMTPDevicePropertyCode propCode(static_cast<TMTPDevicePropertyCode>
       
   179                                    (Request().Uint32(TMTPTypeRequest::ERequestParameter1)));
       
   180    
       
   181     switch(propCode)
       
   182         {
       
   183     case EMTPDevicePropCodePlaybackRate:
       
   184         {
       
   185         CMTPPlaybackMap& map(iPlaybackControlDp.GetPlaybackMap());
       
   186         TInt32 val;
       
   187         if(useDefault)
       
   188             {
       
   189             property.GetDefaultPropertyValueL(propCode, val);
       
   190             }
       
   191         else
       
   192             {
       
   193             TMTPPlaybackState state = static_cast<TMTPPlaybackState>(aCmd->ParamL().Uint32L());
       
   194             val = map.PlaybackRateL(state);
       
   195             }
       
   196         iInt32.Set(val);
       
   197         SendDataL(iInt32);
       
   198         }
       
   199         break;
       
   200 
       
   201     case EMTPDevicePropCodePlaybackObject:
       
   202         {
       
   203         CMTPPlaybackMap& map(iPlaybackControlDp.GetPlaybackMap());
       
   204         TUint32 val;
       
   205         if(useDefault)
       
   206             {
       
   207             property.GetDefaultPropertyValueL(propCode, val);
       
   208             }
       
   209         else
       
   210             {
       
   211             val = map.ObjectHandleL(aCmd->ParamL().SuidSetL().Suid());
       
   212             }
       
   213         iUint32.Set(val);
       
   214         SendDataL(iUint32);
       
   215         }
       
   216         break;
       
   217 
       
   218     case EMTPDevicePropCodeVolume:
       
   219     case EMTPDevicePropCodePlaybackContainerIndex:
       
   220     case EMTPDevicePropCodePlaybackPosition:
       
   221         {
       
   222         TUint32 val;
       
   223         if(useDefault)
       
   224             {
       
   225             property.GetDefaultPropertyValueL(propCode, val);
       
   226             }
       
   227         else
       
   228             {
       
   229             val = aCmd->ParamL().Uint32L();
       
   230             }
       
   231         iUint32.Set(val);
       
   232         SendDataL(iUint32);
       
   233         }
       
   234         break;
       
   235 
       
   236     default:
       
   237         SendResponseL(EMTPRespCodeDevicePropNotSupported);
       
   238         break;             
       
   239         }
       
   240     __FLOG(_L8("HandlePlaybackCommandCompleteL - Exit"));
       
   241     }
       
   242