mtpdataproviders/mtpplaybackcontroldp/mtpplaybackmpximplementation/src/cmtpplaybackcommandchecker.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 "cmtpplaybackcommandchecker.h"
       
    22 #include "cmtpplaybackcontrolimpl.h"
       
    23 
       
    24 // Constants
       
    25 __FLOG_STMT(_LIT8(KComponent,"PlaybackCommandChecker");)
       
    26 
       
    27 // ======== MEMBER FUNCTIONS ========
       
    28 
       
    29 // ---------------------------------------------------------------------------
       
    30 // CMTPPlaybackCommandChecker::NewL
       
    31 // ---------------------------------------------------------------------------
       
    32 //
       
    33 CMTPPlaybackCommandChecker* CMTPPlaybackCommandChecker::NewL(
       
    34             CMTPPlaybackControlImpl& aControlImpl )
       
    35     {
       
    36     CMTPPlaybackCommandChecker* self = new ( ELeave ) 
       
    37                         CMTPPlaybackCommandChecker( aControlImpl );
       
    38     return self;
       
    39     }
       
    40 
       
    41 // ---------------------------------------------------------------------------
       
    42 // CMTPPlaybackCommandChecker::~CMTPPlaybackCommandChecker
       
    43 // ---------------------------------------------------------------------------
       
    44 //
       
    45 CMTPPlaybackCommandChecker::~CMTPPlaybackCommandChecker()
       
    46     {
       
    47     __FLOG(_L8("+CMTPPlaybackCommandChecker::~CMTPPlaybackCommandChecker"));
       
    48     __FLOG(_L8("-CMTPPlaybackCommandChecker::~CMTPPlaybackCommandChecker"));
       
    49     __FLOG_CLOSE;
       
    50     }
       
    51 
       
    52 // ---------------------------------------------------------------------------
       
    53 // CMTPPlaybackCommandChecker::CheckPlaybackCommandContextL
       
    54 // ---------------------------------------------------------------------------
       
    55 //
       
    56 void CMTPPlaybackCommandChecker::CheckPlaybackCommandContextL( TMTPPlaybackCommand aMTPPBCommand )
       
    57     {
       
    58     __FLOG(_L8("+CMTPPlaybackCommandChecker::CheckPlaybackCommandContextL"));
       
    59     
       
    60     MTPPlaybackControlImpl().SetMTPPBCmd( aMTPPBCommand );
       
    61     
       
    62     switch ( aMTPPBCommand )
       
    63         {
       
    64         case EPlaybackCmdInitObject:
       
    65         case EPlaybackCmdGetVolumeSet:
       
    66         case EPlaybackCmdGetVolume:
       
    67         case EPlaybackCmdGetState:
       
    68         case EPlaybackCmdSetVolume:
       
    69             {
       
    70             __FLOG(_L8("no context check for init object command"));
       
    71             }
       
    72             break;
       
    73         case EPlaybackCmdInitIndex:
       
    74         case EPlaybackCmdSkip:
       
    75         case EPlaybackCmdGetIndex:
       
    76             {
       
    77             if ( MTPPlaybackControlImpl().SongCount() < 0 )
       
    78                 {
       
    79                 User::Leave( KPlaybackErrContextInvalid );
       
    80                 }
       
    81             }
       
    82             break;
       
    83         case EPlaybackCmdPlay:
       
    84         case EPlaybackCmdPause:
       
    85         case EPlaybackCmdStop:
       
    86         case EPlaybackCmdSeekForward:
       
    87         case EPlaybackCmdSeekBackward:
       
    88         case EPlaybackCmdGetObject:
       
    89         case EPlaybackCmdSetPosition:
       
    90         case EPlaybackCmdGetPosition:
       
    91             {
       
    92             switch ( MTPPlaybackControlImpl().CurrentState())
       
    93                 {
       
    94                 case EPbStateNotInitialised:
       
    95                     {
       
    96                     User::Leave( KPlaybackErrContextInvalid );
       
    97                     }
       
    98                 default:
       
    99                     break;
       
   100                 }
       
   101             }
       
   102             break;
       
   103         default:
       
   104             {
       
   105             __FLOG(_L8("Not support command!"));
       
   106             User::Leave( KPlaybackErrParamInvalid );
       
   107             }
       
   108             break;
       
   109         }
       
   110     
       
   111     __FLOG(_L8("-CMTPPlaybackCommandChecker::CheckPlaybackCommandContextL"));
       
   112     }
       
   113 
       
   114 // ---------------------------------------------------------------------------
       
   115 // CMTPPlaybackCommandChecker::CheckAndUpdatePlaybackParamL
       
   116 // ---------------------------------------------------------------------------
       
   117 //
       
   118 void CMTPPlaybackCommandChecker::CheckAndUpdatePlaybackParamL( CMTPPlaybackCommand& aMTPPPBSourceCmd, 
       
   119                 CMTPPbCmdParam** aMTPPPBTargetParam )
       
   120     {
       
   121     __FLOG(_L8("+CMTPPlaybackCommandChecker::CheckAndUpdatePlaybackParamL"));
       
   122     
       
   123     delete *aMTPPPBTargetParam;
       
   124     *aMTPPPBTargetParam = NULL;
       
   125     
       
   126     switch ( aMTPPPBSourceCmd.PlaybackCommand())
       
   127         {
       
   128         case EPlaybackCmdInitObject:
       
   129             {
       
   130             const TMTPPbCategory category = aMTPPPBSourceCmd.ParamL().SuidSetL().Category();
       
   131             TFileName suid = aMTPPPBSourceCmd.ParamL().SuidSetL().Suid();
       
   132             *aMTPPPBTargetParam = CMTPPbCmdParam::NewL( category, suid );
       
   133             }
       
   134             break;
       
   135         case EPlaybackCmdInitIndex:
       
   136             {
       
   137             TUint32 songIndex = aMTPPPBSourceCmd.ParamL().Uint32L();
       
   138             if ( songIndex > ( MTPPlaybackControlImpl().SongCount()-1 ))
       
   139                 {
       
   140                 User::Leave( KPlaybackErrParamInvalid );
       
   141                 }
       
   142             *aMTPPPBTargetParam = CMTPPbCmdParam::NewL( songIndex );
       
   143             }
       
   144             break;
       
   145         case EPlaybackCmdSkip:
       
   146             {
       
   147             TInt32 songIndex = MTPPlaybackControlImpl().SongIndex() + aMTPPPBSourceCmd.ParamL().Int32L();
       
   148             TUint32 songCount = MTPPlaybackControlImpl().SongCount();
       
   149             
       
   150             if ( songIndex < 0 )
       
   151                 {
       
   152                 songIndex = ( - songIndex ) % songCount;
       
   153                 songIndex = ( songCount - songIndex ) % songCount;
       
   154                 }
       
   155             else
       
   156                 {
       
   157                 songIndex = songIndex % songCount;
       
   158                 }
       
   159             
       
   160             *aMTPPPBTargetParam = CMTPPbCmdParam::NewL( songIndex);
       
   161             }
       
   162             break;
       
   163         case EPlaybackCmdSetVolume:
       
   164             {
       
   165             TUint32 volume = aMTPPPBSourceCmd.ParamL().Uint32L();
       
   166             if( volume > KPbPlaybackVolumeLevelMax )
       
   167                 {
       
   168                 User::Leave( KPlaybackErrParamInvalid );
       
   169                 }
       
   170             *aMTPPPBTargetParam = CMTPPbCmdParam::NewL( volume );
       
   171             }
       
   172             break;
       
   173         case EPlaybackCmdSetPosition:
       
   174             {
       
   175             TUint32 position= aMTPPPBSourceCmd.ParamL().Uint32L();
       
   176             *aMTPPPBTargetParam = CMTPPbCmdParam::NewL( position );
       
   177             }
       
   178             break;
       
   179         default:
       
   180             {
       
   181             __FLOG(_L8("No param, just cache command"));
       
   182             }
       
   183             break;
       
   184         }
       
   185     
       
   186     __FLOG(_L8("-CMTPPlaybackCommandChecker::CheckAndUpdatePlaybackParamL"));
       
   187     }
       
   188 
       
   189 // ---------------------------------------------------------------------------
       
   190 // CMTPPlaybackCommandChecker::CMTPPlaybackCommandChecker
       
   191 // ---------------------------------------------------------------------------
       
   192 //
       
   193 CMTPPlaybackCommandChecker::CMTPPlaybackCommandChecker( 
       
   194         CMTPPlaybackControlImpl& aControlImpl )
       
   195                 : iMTPPlaybackControl( aControlImpl )
       
   196     {
       
   197     __FLOG_OPEN(KMTPSubsystem, KComponent);
       
   198     }
       
   199 
       
   200 // ---------------------------------------------------------------------------
       
   201 // CMTPPlaybackCommandChecker::MTPPlaybackControlImpl
       
   202 // ---------------------------------------------------------------------------
       
   203 //
       
   204 CMTPPlaybackControlImpl& CMTPPlaybackCommandChecker::MTPPlaybackControlImpl()
       
   205     {
       
   206     return iMTPPlaybackControl;
       
   207     }
       
   208 
       
   209