mtpdataproviders/mtpplaybackcontroldp/src/cmtppbcgetdevicepropdesc.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/cmtptypedevicepropdesc.h>
       
    22 
       
    23 #include "cmtppbcgetdevicepropdesc.h"
       
    24 #include "mtpplaybackcontroldpconst.h"
       
    25 #include "cmtpplaybackcontroldp.h"
       
    26 #include "cmtpplaybackproperty.h"
       
    27 #include "cmtpplaybackmap.h"
       
    28 #include "cmtpplaybackcommand.h"
       
    29 #include "mtpplaybackcontrolpanic.h"
       
    30 
       
    31 // Class constants.
       
    32 __FLOG_STMT(_LIT8(KComponent,"GetPlaybackDevicePropDesc");)
       
    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* CMTPPbcGetDevicePropDesc::NewL(MMTPDataProviderFramework& aFramework,
       
    42                                                 MMTPConnection& aConnection, 
       
    43                                                 CMTPPlaybackControlDataProvider& aDataProvider)
       
    44     {
       
    45     CMTPPbcGetDevicePropDesc* self = new (ELeave) CMTPPbcGetDevicePropDesc(aFramework, aConnection, aDataProvider);
       
    46     return self;
       
    47     }
       
    48 
       
    49 /**
       
    50 Destructor.
       
    51 */    
       
    52 CMTPPbcGetDevicePropDesc::~CMTPPbcGetDevicePropDesc()
       
    53     {    
       
    54     __FLOG(_L8("~CMTPPbcGetDevicePropDesc - Entry"));
       
    55     delete iPropDesc;
       
    56     delete iPbCmd;
       
    57     __FLOG(_L8("~CMTPPbcGetDevicePropDesc - Exit"));
       
    58     __FLOG_CLOSE;
       
    59     }
       
    60 
       
    61 /**
       
    62 Constructor.
       
    63 */    
       
    64 CMTPPbcGetDevicePropDesc::CMTPPbcGetDevicePropDesc(MMTPDataProviderFramework& aFramework,
       
    65                                             MMTPConnection& aConnection, 
       
    66                                             CMTPPlaybackControlDataProvider& aDataProvider) :
       
    67     CMTPRequestProcessor(aFramework, aConnection, 0, NULL),
       
    68     iPlaybackControlDp(aDataProvider)
       
    69     {
       
    70     //Open the log system
       
    71     __FLOG_OPEN(KMTPSubsystem, KComponent);
       
    72     }
       
    73     
       
    74 /**
       
    75 GetDevicePropDesc request validator.
       
    76 @return EMTPRespCodeOK if request is verified, otherwise one of the error response codes
       
    77 */
       
    78 TMTPResponseCode CMTPPbcGetDevicePropDesc::CheckRequestL()
       
    79     {
       
    80     __FLOG(_L8("CheckRequestL - Entry"));
       
    81     TMTPResponseCode respCode = CMTPRequestProcessor::CheckRequestL();
       
    82     if(respCode == EMTPRespCodeOK)
       
    83         {
       
    84         respCode = EMTPRespCodeDevicePropNotSupported;
       
    85         TUint32 propCode = Request().Uint32(TMTPTypeRequest::ERequestParameter1);
       
    86         const TInt count = sizeof(KMTPPlaybackControlDpSupportedProperties) / sizeof(KMTPPlaybackControlDpSupportedProperties[0]);
       
    87         for (TUint i(0); (i < count); i++)
       
    88             {
       
    89             if (propCode == KMTPPlaybackControlDpSupportedProperties[i])
       
    90                 {
       
    91                 respCode = EMTPRespCodeOK;
       
    92                 break;
       
    93                 }
       
    94             }
       
    95         }
       
    96 
       
    97     __FLOG(_L8("CheckRequestL - Exit"));
       
    98     return respCode;
       
    99     }
       
   100 
       
   101 /**
       
   102 GetDevicePropDesc request handler.
       
   103 */    
       
   104 void CMTPPbcGetDevicePropDesc::ServiceL()
       
   105     {
       
   106     __FLOG(_L8("ServiceL - Entry"));
       
   107     //Destroy the previous playback command.
       
   108     delete iPbCmd;
       
   109     iPbCmd = NULL;
       
   110     
       
   111     //Get the device property code
       
   112     TMTPDevicePropertyCode propCode(static_cast<TMTPDevicePropertyCode>(Request().
       
   113                                     Uint32(TMTPTypeRequest::ERequestParameter1)));
       
   114     
       
   115     TMTPPbCtrlData data;
       
   116     data.iOptCode = EMTPOpCodeGetDevicePropDesc;
       
   117     data.iDevPropCode = propCode;
       
   118 
       
   119     //Get a new playback command.
       
   120     CMTPPlaybackMap& map(iPlaybackControlDp.GetPlaybackMap());
       
   121     TInt result = map.GetPlaybackControlCommand(data, &iPbCmd);
       
   122 
       
   123     if(KErrNone == result)
       
   124         {
       
   125         MMTPPlaybackControl& control(iPlaybackControlDp.GetPlaybackControlL());
       
   126         TRAPD(err, control.CommandL(*iPbCmd, this));
       
   127         __ASSERT_ALWAYS((err == KErrNone), SendResponseL(EMTPRespCodeParameterNotSupported));
       
   128         }
       
   129     else if(KErrNotSupported == result)
       
   130         {
       
   131         SendResponseL(EMTPRespCodeDevicePropNotSupported);
       
   132         }
       
   133     else
       
   134         {
       
   135         SendResponseL(EMTPRespCodeParameterNotSupported);
       
   136         }
       
   137 
       
   138     __FLOG(_L8("ServiceL - Exit"));
       
   139     }
       
   140 
       
   141 void CMTPPbcGetDevicePropDesc::HandlePlaybackCommandCompleteL(CMTPPlaybackCommand* aCmd, TInt aErr)
       
   142     {
       
   143     __FLOG(_L8("HandlePlaybackCommandCompleteL - Entry"));
       
   144     __FLOG_1(_L8("aErr %d"), aErr);
       
   145 
       
   146     TBool useDefault = EFalse;
       
   147     switch(aErr)
       
   148         {
       
   149         case KPlaybackErrNone:
       
   150             {
       
   151             __ASSERT_DEBUG((aCmd != NULL), Panic(EMTPPBDataNullErr));
       
   152             __ASSERT_DEBUG((aCmd->PlaybackCommand() == iPbCmd->PlaybackCommand()), Panic(EMTPPBArgumentErr));
       
   153             __ASSERT_ALWAYS((aCmd != NULL), User::Leave(KErrArgument));
       
   154             __ASSERT_ALWAYS((aCmd->PlaybackCommand() == iPbCmd->PlaybackCommand()), User::Leave(KErrArgument));
       
   155             __FLOG_1(_L8("aCmd %d"), aCmd->PlaybackCommand());
       
   156             }
       
   157             break;
       
   158         case KPlaybackErrContextInvalid:
       
   159             {
       
   160             useDefault = ETrue;
       
   161             }
       
   162             break;
       
   163         case KPlaybackErrDeviceUnavailable:
       
   164             {
       
   165             iPlaybackControlDp.RequestToResetPbCtrl();
       
   166             SendResponseL(EMTPRespCodeDeviceBusy);
       
   167             }
       
   168             return;
       
   169 
       
   170         default:
       
   171             {
       
   172             SendResponseL(EMTPRespCodeDeviceBusy);
       
   173             }
       
   174             return;
       
   175         }
       
   176 
       
   177     delete iPropDesc;
       
   178     iPropDesc = NULL;
       
   179     
       
   180     CMTPPlaybackProperty& property(iPlaybackControlDp.GetPlaybackProperty());
       
   181     TMTPDevicePropertyCode propCode = static_cast<TMTPDevicePropertyCode>
       
   182                                       (Request().Uint32(TMTPTypeRequest::ERequestParameter1));
       
   183 
       
   184     switch (propCode)
       
   185         {
       
   186         case EMTPDevicePropCodeVolume:
       
   187             {
       
   188             TMTPPbDataVolume volSet(1,0,1,1,1);
       
   189             if(useDefault)
       
   190                 {
       
   191                  property.GetDefaultVolSet(volSet);
       
   192                 }
       
   193             else
       
   194                 {
       
   195                 volSet = aCmd->ParamL().VolumeSetL();
       
   196                 property.SetDefaultVolSetL(volSet);
       
   197                 }
       
   198 
       
   199             CMTPTypeDevicePropDescRangeForm* form = CMTPTypeDevicePropDescRangeForm::NewLC(EMTPTypeUINT32);
       
   200             form->SetUint32L(CMTPTypeDevicePropDescRangeForm::EMaximumValue, volSet.MaxVolume());
       
   201             form->SetUint32L(CMTPTypeDevicePropDescRangeForm::EMinimumValue, volSet.MinVolume());
       
   202             form->SetUint32L(CMTPTypeDevicePropDescRangeForm::EStepSize, volSet.Step());
       
   203             iPropDesc = CMTPTypeDevicePropDesc::NewL(propCode,
       
   204                                                      CMTPTypeDevicePropDesc::EReadWrite, 
       
   205                                                      CMTPTypeDevicePropDesc::ERangeForm,
       
   206                                                      form);
       
   207 
       
   208             iPropDesc->SetUint32L(CMTPTypeDevicePropDesc::EFactoryDefaultValue, volSet.DefaultVolume());
       
   209             iPropDesc->SetUint32L(CMTPTypeDevicePropDesc::ECurrentValue, volSet.CurrentVolume());
       
   210             CleanupStack::PopAndDestroy(form);
       
   211             SendDataL(*iPropDesc); 
       
   212             }
       
   213             break;
       
   214 
       
   215         case EMTPDevicePropCodePlaybackRate:
       
   216             {
       
   217             CMTPTypeDevicePropDescEnumerationForm* form = CMTPTypeDevicePropDescEnumerationForm::
       
   218                                                           NewLC(EMTPTypeINT32);
       
   219             CMTPPlaybackMap& map(iPlaybackControlDp.GetPlaybackMap());
       
   220 
       
   221             TInt32 val = map.PlaybackRateL(EPlayStateBackwardSeeking);
       
   222             TMTPTypeInt32 value(val);
       
   223             form->AppendSupportedValueL(value);
       
   224             
       
   225             val = map.PlaybackRateL(EPlayStatePaused);
       
   226             value.Set(val);
       
   227             form->AppendSupportedValueL(value);
       
   228             
       
   229             val = map.PlaybackRateL(EPlayStatePlaying);
       
   230             value.Set(val);
       
   231             form->AppendSupportedValueL(value);
       
   232             
       
   233             val = map.PlaybackRateL(EPlayStateForwardSeeking);
       
   234             value.Set(val);
       
   235             form->AppendSupportedValueL(value);
       
   236 
       
   237             iPropDesc = CMTPTypeDevicePropDesc::NewL(propCode,
       
   238                                                      CMTPTypeDevicePropDesc::EReadWrite, 
       
   239                                                      CMTPTypeDevicePropDesc::EEnumerationForm,
       
   240                                                      form);
       
   241 
       
   242             property.GetDefaultPropertyValueL(propCode, val);
       
   243             iPropDesc->SetInt32L(CMTPTypeDevicePropDesc::EFactoryDefaultValue, val);
       
   244 
       
   245             if(!useDefault)
       
   246                 {
       
   247                 TMTPPlaybackState state = static_cast<TMTPPlaybackState>(aCmd->ParamL().Uint32L());
       
   248                 val = map.PlaybackRateL(state);
       
   249                 }
       
   250             iPropDesc->SetInt32L(CMTPTypeDevicePropDesc::ECurrentValue, val);
       
   251             CleanupStack::PopAndDestroy(form);
       
   252 
       
   253             SendDataL(*iPropDesc); 
       
   254             }
       
   255             break;
       
   256         
       
   257         case EMTPDevicePropCodePlaybackObject:
       
   258             {
       
   259             iPropDesc = CMTPTypeDevicePropDesc::NewL(propCode);
       
   260             TUint32 val = 0;
       
   261             property.GetDefaultPropertyValueL(propCode, val);
       
   262             iPropDesc->SetUint32L(CMTPTypeDevicePropDesc::EFactoryDefaultValue, val);
       
   263             CMTPPlaybackMap& map(iPlaybackControlDp.GetPlaybackMap());
       
   264             if(!useDefault)
       
   265                 {
       
   266                 val = map.ObjectHandleL(aCmd->ParamL().SuidSetL().Suid());                
       
   267                 }
       
   268             iPropDesc->SetUint32L(CMTPTypeDevicePropDesc::ECurrentValue, val);
       
   269             SendDataL(*iPropDesc); 
       
   270             }
       
   271             break;
       
   272 
       
   273         case EMTPDevicePropCodePlaybackContainerIndex:
       
   274             {
       
   275             iPropDesc = CMTPTypeDevicePropDesc::NewL(propCode);
       
   276             TUint32 val = 0;
       
   277             property.GetDefaultPropertyValueL(propCode, val);
       
   278             iPropDesc->SetUint32L(CMTPTypeDevicePropDesc::EFactoryDefaultValue, val);
       
   279             if(!useDefault)
       
   280                 {
       
   281                 val = aCmd->ParamL().Uint32L();                
       
   282                 }
       
   283             iPropDesc->SetUint32L(CMTPTypeDevicePropDesc::ECurrentValue, val);
       
   284             SendDataL(*iPropDesc); 
       
   285             }
       
   286             break;
       
   287 
       
   288         case EMTPDevicePropCodePlaybackPosition:
       
   289             {
       
   290             iPropDesc = CMTPTypeDevicePropDesc::NewL(propCode);
       
   291             TUint32 val = 0;
       
   292             CMTPPlaybackProperty& property(iPlaybackControlDp.GetPlaybackProperty());
       
   293             property.GetDefaultPropertyValueL(propCode, val);
       
   294             iPropDesc->SetUint32L(CMTPTypeDevicePropDesc::EFactoryDefaultValue, val);
       
   295             if(!useDefault)
       
   296                 {
       
   297                 val = aCmd->ParamL().Uint32L();                
       
   298                 }
       
   299             iPropDesc->SetUint32L(CMTPTypeDevicePropDesc::ECurrentValue, val);
       
   300             SendDataL(*iPropDesc);
       
   301             }
       
   302             break;
       
   303         
       
   304         default:
       
   305             {
       
   306             User::Leave(KErrArgument);
       
   307             } 
       
   308             break;
       
   309         }
       
   310 
       
   311     __FLOG(_L8("HandlePlaybackCommandCompleteL - Exit"));
       
   312     }