mtpdataproviders/mtpplaybackcontroldp/src/cmtppbcskip.cpp
branchRCL_3
changeset 20 4a793f564d72
parent 19 0aa8cc770c8a
child 21 74aa6861c87d
equal deleted inserted replaced
19:0aa8cc770c8a 20:4a793f564d72
     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 "cmtppbcskip.h"
       
    26 #include "mtpplaybackcontroldpconst.h"
       
    27 #include "cmtpplaybackmap.h"
       
    28 #include "cmtpplaybackcontroldp.h"
       
    29 #include "cmtpplaybackproperty.h"
       
    30 #include "cmtpplaybackcommand.h"
       
    31 #include "mtpplaybackcontrolpanic.h"
       
    32 
       
    33 
       
    34 // Class constants.
       
    35 __FLOG_STMT(_LIT8(KComponent,"Skip");)
       
    36 
       
    37 /**
       
    38 Two-phase constructor.
       
    39 @param aPlugin  The data provider plugin
       
    40 @param aFramework The data provider framework
       
    41 @param aConnection The connection from which the request comes
       
    42 @return a pointer to the created request processor object.
       
    43 */  
       
    44 MMTPRequestProcessor* CMTPPbcSkip::NewL(MMTPDataProviderFramework& aFramework,
       
    45                                      MMTPConnection& aConnection,
       
    46                                      CMTPPlaybackControlDataProvider& aDataProvider)
       
    47     {
       
    48     CMTPPbcSkip* self = new (ELeave) CMTPPbcSkip(aFramework, aConnection, aDataProvider);
       
    49     return self;
       
    50     }
       
    51 
       
    52 /**
       
    53 Destructor.
       
    54 */    
       
    55 CMTPPbcSkip::~CMTPPbcSkip()
       
    56     {
       
    57     __FLOG(_L8("CMTPPbcSkip - Entry"));
       
    58     delete iPbCmd;
       
    59     __FLOG(_L8("CMTPPbcSkip - Exit"));
       
    60     __FLOG_CLOSE;
       
    61     }
       
    62 
       
    63 /**
       
    64 Constructor.
       
    65 */    
       
    66 CMTPPbcSkip::CMTPPbcSkip(MMTPDataProviderFramework& aFramework,
       
    67                    MMTPConnection& aConnection,
       
    68                    CMTPPlaybackControlDataProvider& aDataProvider):
       
    69                    CMTPRequestProcessor(aFramework, aConnection, 0, NULL),
       
    70                    iPlaybackControlDp(aDataProvider)
       
    71     {
       
    72     //Open the log system
       
    73     __FLOG_OPEN(KMTPSubsystem, KComponent);
       
    74     }
       
    75 
       
    76 /**
       
    77 CheckRequestL
       
    78 */
       
    79 TMTPResponseCode CMTPPbcSkip::CheckRequestL()
       
    80     {
       
    81     __FLOG(_L8("CheckRequestL - Entry"));
       
    82     TMTPResponseCode respCode = CMTPRequestProcessor::CheckRequestL();
       
    83     if(respCode == EMTPRespCodeOK)
       
    84         {
       
    85         respCode = EMTPRespCodeInvalidParameter;
       
    86         TUint32 step = Request().Uint32(TMTPTypeRequest::ERequestParameter1);
       
    87         if(step != 0)
       
    88             {
       
    89             respCode = EMTPRespCodeOK;
       
    90             }
       
    91         }
       
    92     __FLOG(_L8("CheckRequestL - Exit"));
       
    93     return respCode;
       
    94     }
       
    95 
       
    96 /**
       
    97 CMTPPbcSkip request handler.
       
    98 */   
       
    99 void CMTPPbcSkip::ServiceL()
       
   100     {
       
   101     __FLOG(_L8("ServiceL - Entry"));
       
   102     CMTPPlaybackMap& map(iPlaybackControlDp.GetPlaybackMap());
       
   103     MMTPPlaybackControl& control(iPlaybackControlDp.GetPlaybackControlL());
       
   104 
       
   105     TMTPPbCtrlData data;
       
   106     data.iOptCode = EMTPOpCodeSkip;
       
   107     data.iPropValInt32 = static_cast<TInt32>(Request().Uint32(TMTPTypeRequest::ERequestParameter1));
       
   108 
       
   109     TInt result = map.GetPlaybackControlCommand(data, &iPbCmd);
       
   110     
       
   111     if(KErrNone == result)
       
   112         {
       
   113         TRAPD(err, control.CommandL(*iPbCmd, this));
       
   114         __ASSERT_ALWAYS((err == KErrNone), SendResponseL(EMTPRespCodeInvalidParameter));
       
   115         }
       
   116     else
       
   117         {
       
   118         SendResponseL(EMTPRespCodeInvalidParameter);
       
   119         }
       
   120     __FLOG(_L8("ServiceL - Exit"));
       
   121     }
       
   122 
       
   123 void CMTPPbcSkip::HandlePlaybackCommandCompleteL(CMTPPlaybackCommand* aCmd, TInt aErr)
       
   124     {
       
   125     __FLOG(_L8("HandlePlaybackCommandCompleteL - Entry"));
       
   126     __FLOG_1(_L8("aErr %d"), aErr);
       
   127 
       
   128     //Handle error response.
       
   129     TMTPResponseCode response;
       
   130     switch(aErr)
       
   131         {
       
   132         case KPlaybackErrNone:
       
   133             {
       
   134             response = EMTPRespCodeOK;            
       
   135             }
       
   136             break;
       
   137         case KPlaybackErrDeviceBusy:
       
   138             {
       
   139             response = EMTPRespCodeDeviceBusy;            
       
   140             }
       
   141             break;
       
   142         case KPlaybackErrDeviceUnavailable:
       
   143             {
       
   144             response = EMTPRespCodeDeviceBusy;
       
   145             iPlaybackControlDp.RequestToResetPbCtrl();
       
   146             }
       
   147             break;
       
   148         default:
       
   149             {
       
   150             response = EMTPRespCodeInvalidParameter;
       
   151             }
       
   152             break;
       
   153         }
       
   154 
       
   155     SendResponseL(response);
       
   156     
       
   157     if(aCmd != NULL)
       
   158         {
       
   159         __ASSERT_DEBUG((aCmd->PlaybackCommand() == iPbCmd->PlaybackCommand()), Panic(EMTPPBArgumentErr));
       
   160         __FLOG_1(_L8("aCmd %d"), aCmd->PlaybackCommand());
       
   161         }
       
   162 
       
   163     __FLOG(_L8("HandlePlaybackCommandCompleteL - Exit"));
       
   164     }