hwrmhaptics/tsrc/hapticstestplugins/src/hwrmhapticstestplugin.cpp
changeset 76 cb32bcc88bad
equal deleted inserted replaced
73:d38941471f1c 76:cb32bcc88bad
       
     1 /*
       
     2 * Copyright (c) 2008 Nokia Corporation and/or its subsidiary(-ies). 
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of the License "Symbian Foundation License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.symbianfoundation.org/legal/sfl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:  Haptics adaptation test plugin implementation.
       
    15 *
       
    16 */
       
    17 
       
    18 #include <s32mem.h>
       
    19 #include <hwrmhapticscommands.h>
       
    20 
       
    21 #include "hwrmhapticstestplugin.h"
       
    22 #include "hwrmhapticstrace.h"
       
    23 #include "hwrmhapticsvibeconstants.h"
       
    24 #include "plugintimer.h"
       
    25 
       
    26 // -----------------------------------------------------------------------------
       
    27 // Enumeration for special test case in which it is tested that HapticsClient 
       
    28 // correctly converts VibeStatus codes to Symbian/S60 error codes.
       
    29 // -----------------------------------------------------------------------------
       
    30 //
       
    31 enum vibestatustests
       
    32     {
       
    33     SUCCESS_TEST = 100,
       
    34     ALREADY_INITIALIZED_TEST,
       
    35     NOT_INITIALIZED_TEST,
       
    36     INVALID_ARGUMENT_TEST,
       
    37     FAIL_TEST,
       
    38     INCOMPATIBLE_EFFECT_TYPE_TEST,
       
    39     INCOMPATIBLE_CAPABILITY_TYPE_TEST,
       
    40     INCOMPATIBLE_PROPERTY_TYPE_TEST,
       
    41     DEVICE_NEEDS_LICENSE_TEST,
       
    42     NOT_ENOUGH_MEMORY_TEST,
       
    43     SERVICE_NOT_RUNNING_TEST,
       
    44     INSUFFICIENT_PRIORITY_TEST,
       
    45     SERVICE_BUSY_TEST,
       
    46     WRN_NOT_PLAYING_TEST,
       
    47     WRN_INSUFFICIENT_PRIORITY_TEST
       
    48     };
       
    49 
       
    50 // -----------------------------------------------------------------------------
       
    51 // CHWRMHapticsTestPlugin::NewL
       
    52 // Static instantiation method. Allocates mem and constructs new test plugin object.
       
    53 // -----------------------------------------------------------------------------
       
    54 //
       
    55 CHWRMHapticsTestPlugin* CHWRMHapticsTestPlugin::NewL( 
       
    56                                     MHWRMHapticsPluginCallback* aCallback )
       
    57     {
       
    58     COMPONENT_TRACE( ( _L("CHWRMHapticsTestPlugin::NewL()") ) );
       
    59     CHWRMHapticsTestPlugin* self = 
       
    60         new ( ELeave ) CHWRMHapticsTestPlugin( aCallback );
       
    61     CleanupStack::PushL( self );
       
    62     self->ConstructL();
       
    63     CleanupStack::Pop( self );
       
    64     return self;
       
    65     }
       
    66 
       
    67 // -----------------------------------------------------------------------------
       
    68 // CHWRMHapticsTestPlugin::~CHWRMHapticsTestPlugin
       
    69 // Destructor
       
    70 // -----------------------------------------------------------------------------
       
    71 //
       
    72 CHWRMHapticsTestPlugin::~CHWRMHapticsTestPlugin()
       
    73     {
       
    74     COMPONENT_TRACE( ( _L("CHWRMHapticsTestPlugin::~CFmtxPlugin()") ) );
       
    75     
       
    76     iStorage.Close();
       
    77     
       
    78     iTimers.ResetAndDestroy();
       
    79     iVibeCmdPacket = NULL;
       
    80  #ifdef PUBLISH_STATE_INFO
       
    81     iCmdProperty.Close();
       
    82     iDataProperty.Close();
       
    83     iVibeCmdProperty.Close();
       
    84 #endif /* PUBLISH_STATE_INFO */
       
    85     }
       
    86 
       
    87 // -----------------------------------------------------------------------------
       
    88 // CHWRMHapticsTestPlugin::CHWRMHapticsTestPlugin
       
    89 // Constructor
       
    90 // -----------------------------------------------------------------------------
       
    91 //
       
    92 CHWRMHapticsTestPlugin::CHWRMHapticsTestPlugin( 
       
    93     MHWRMHapticsPluginCallback* aCallback )
       
    94     {
       
    95     COMPONENT_TRACE( ( _L("CHWRMHapticsTestPlugin::CHWRMHapticsTestPlugin()") ) );
       
    96     iResponseCallback = aCallback;
       
    97     }
       
    98 
       
    99 // -----------------------------------------------------------------------------
       
   100 // CHWRMHapticsTestPlugin::ConstructL
       
   101 // Two-phase construction ConstructL that can leave.
       
   102 // -----------------------------------------------------------------------------
       
   103 //
       
   104 void CHWRMHapticsTestPlugin::ConstructL()
       
   105     {
       
   106     COMPONENT_TRACE( ( _L("CHWRMHapticsTestPlugin::ConstructL") ) );
       
   107     
       
   108     // Create response data buffer
       
   109     iStorage.Create( KHWRMHapticsRespMaxSize );
       
   110     
       
   111     // Read in response file contents
       
   112     RFs fileServer;
       
   113     User::LeaveIfError( fileServer.Connect() );
       
   114     
       
   115     RFile file;
       
   116     TInt err = file.Open( fileServer, KStubResponseFile, EFileRead );
       
   117     if( err !=KErrNone )
       
   118         COMPONENT_TRACE( _L("HWRM HapticsPlugin: Couldn't open file successfully") );
       
   119     
       
   120     file.Read( iFileData );
       
   121     
       
   122     file.Close();
       
   123     fileServer.Close();
       
   124     
       
   125 #ifdef PUBLISH_STATE_INFO
       
   126     RProperty::Define( KPSUidHWResourceNotification, KHWRMTestHapticsCommand, RProperty::EInt );
       
   127     RProperty::Define( KPSUidHWResourceNotification, KHWRMTestHapticsDataPckg, RProperty::EByteArray, 512 );
       
   128     RProperty::Define( KPSUidHWResourceNotification, KHWRMTestVibCmdData, RProperty::EInt );
       
   129     iCmdProperty.Attach( KPSUidHWResourceNotification, KHWRMTestHapticsCommand );
       
   130     iDataProperty.Attach( KPSUidHWResourceNotification, KHWRMTestHapticsDataPckg );
       
   131     iVibeCmdProperty.Attach( KPSUidHWResourceNotification, KHWRMTestVibCmdData );
       
   132 #endif /* PUBLISH_STATE_INFO */
       
   133     
       
   134     // inform haptics of the plugin state
       
   135     iResponseCallback->PluginEnabled( EHWRMLogicalActuatorAny, ETrue );
       
   136     iResponseCallback->PluginEnabled( EHWRMLogicalActuatorDevice, ETrue );
       
   137     }
       
   138 
       
   139 
       
   140 // -----------------------------------------------------------------------------
       
   141 // CHWRMHapticsTestPlugin::ProcessCommandL
       
   142 // Implementation of CHWRMHapticsPluginService::ProcessCommandL. 
       
   143 // This method processes the haptics command in adaptation layer. In this test
       
   144 // plugin simply a timer instance is created with the given data and later, after
       
   145 // the timer expiry, the semi-hard-coded response is created in GenericTimerFired
       
   146 // method below. 
       
   147 // -----------------------------------------------------------------------------
       
   148 //     
       
   149 void CHWRMHapticsTestPlugin::ProcessCommandL( TInt aCommandId,
       
   150                                               TUint8 aTransId,
       
   151                                               TDesC8& aData )
       
   152     {
       
   153     COMPONENT_TRACE( ( _L("HWRM HapticsPlugin: Processing command: 0x%x, TransId: 0x%x" ), aCommandId, aTransId ) );
       
   154     
       
   155     TInt retVal( KErrNone );
       
   156     
       
   157     switch ( aCommandId )
       
   158         {
       
   159         case HWRMHapticsCommand::EHapticsCmdId :
       
   160             {
       
   161             COMPONENT_TRACE( _L("HWRM HapticsPlugin: Processed EHapticsCmdId") );
       
   162             }
       
   163             break;
       
   164         default :
       
   165             {
       
   166             COMPONENT_TRACE( ( _L("HWRM HapticsPlugin: Unknown Command: 0x%x" ), aCommandId ) );
       
   167 #ifdef _DEBUG
       
   168             User::Invariant(); // panic here to notice the problem early
       
   169 #endif
       
   170             }
       
   171             break;
       
   172         }
       
   173     
       
   174     
       
   175     iVibeCmdPacket = reinterpret_cast<TVibePacket*>( const_cast<TUint8*>( aData.Ptr() ) ); 
       
   176     // check for NULL pointer
       
   177     if ( NULL == iVibeCmdPacket )
       
   178         {
       
   179         User::Leave( KErrBadDescriptor );
       
   180         }
       
   181     
       
   182     TInt timeout( KTimeOut );
       
   183     
       
   184     _LIT8 ( KTestPluginMgrTransTimerExpires, "KTestPluginMgrTransTimerExpires" );
       
   185     if ( aData.FindF ( KTestPluginMgrTransTimerExpires ) != KErrNotFound )
       
   186         {
       
   187 		COMPONENT_TRACE( ( _L("HWRM HapticsPlugin: set the timeout that is more than plug-in manager transaction generic timer time-out period") ) );
       
   188         // set the timeout that is more than plug-in manager transaction generic timer time-out period i.e. > KDefaultPluginTimeout
       
   189         timeout = 4000000;
       
   190         }
       
   191 
       
   192 #ifdef PUBLISH_STATE_INFO
       
   193     // publish
       
   194     iCmdProperty.Set( aCommandId );
       
   195     iDataProperty.Set( aData );
       
   196     iVibeCmdProperty.Set( iVibeCmdPacket->iSimpleRsp.iCmdCode );
       
   197 #endif /* PUBLISH_STATE_INFO */
       
   198 
       
   199     // create new timer and append it to the timer (pointer) array
       
   200     CPluginTimer* timer = CPluginTimer::NewL( timeout, iResponseCallback, aCommandId, aTransId, retVal, this );
       
   201     CleanupStack::PushL( timer );
       
   202     iTimers.AppendL( timer );
       
   203     CleanupStack::Pop( timer );
       
   204     
       
   205     COMPONENT_TRACE( ( _L("HWRM HapticsPlugin: Processing command - return") ) );
       
   206     }
       
   207 
       
   208 
       
   209 // -----------------------------------------------------------------------------
       
   210 // CHWRMHapticsTestPlugin::CancelCommandL
       
   211 // Implementation of CHWRMHapticsPluginService::CancelCommandL.
       
   212 // Method for cancelling ongoing (emulated) command execution. In practice 
       
   213 // removes the timer that was started in order to emulate the given command.
       
   214 // -----------------------------------------------------------------------------
       
   215 // 
       
   216 void CHWRMHapticsTestPlugin::CancelCommandL(
       
   217     TUint8 aTransId, 
       
   218     TInt /*aCommandId*/ )
       
   219     {
       
   220     COMPONENT_TRACE( ( _L("HWRM HapticsPlugin: Cancelling command - iTimers.Count(): %d " ), iTimers.Count() ) );
       
   221 
       
   222     for( TInt i = 0; i < iTimers.Count(); i++ )
       
   223         {
       
   224         if ( iTimers[i]->TransId() == aTransId )
       
   225             {
       
   226             delete iTimers[i];
       
   227             iTimers.Remove( i );
       
   228             break;
       
   229             }
       
   230         }
       
   231     }
       
   232 
       
   233 // -----------------------------------------------------------------------------
       
   234 // CHWRMHapticsTestPlugin::GenericTimerFired
       
   235 // Callback method that is called from the CPluginTimer after timer expiry. 
       
   236 // This method emulates reception of response from the ISA layer to a haptics
       
   237 // command. The actual response is read from a file, converted to binary and 
       
   238 // then the Haptics plugin manager's callback method (ProcessResponseL) is 
       
   239 // called with that binary data.
       
   240 // -----------------------------------------------------------------------------
       
   241 // 
       
   242 void CHWRMHapticsTestPlugin::GenericTimerFired(
       
   243     MHWRMHapticsPluginCallback* aService,
       
   244     TInt aCommandId,
       
   245     TUint8 aTransId,
       
   246     TInt aRetVal )
       
   247     {
       
   248     COMPONENT_TRACE( ( _L("HWRM HapticsPlugin: GenericTimerFired (0x%x, 0x%x, %d)" ), aCommandId, aTransId, aRetVal ) );
       
   249 
       
   250     __ASSERT_ALWAYS( aService != NULL, User::Invariant() );
       
   251     
       
   252     TInt err = KErrNone;
       
   253     TBuf8<KHWRMHapticsRespMaxSize> binRespData;
       
   254     if ( NULL != iVibeCmdPacket )
       
   255         {
       
   256         TBool jumpCases = EFalse;
       
   257         
       
   258         // Special case for vibeStatus to S60 err code manipulations:
       
   259         if ( iVibeCmdPacket->iSimpleRsp.iCmdCode == KVibeCmdPlayIVTEffectNoData )
       
   260             {
       
   261             TVibePacketPlayIVTEffectRequest* playReq = reinterpret_cast<TVibePacketPlayIVTEffectRequest*>( iVibeCmdPacket );
       
   262             if ( playReq )
       
   263                 {
       
   264                 jumpCases = ETrue;
       
   265                 
       
   266                 // the repeat value is used to indicate which sub-case is ongoing.. 
       
   267                 // values between 100...114 are treated as special values.
       
   268                 switch ( playReq->iRepeat )
       
   269                     {
       
   270                     case SUCCESS_TEST:
       
   271                         {
       
   272                         COMPONENT_TRACE( ( _L("HWRM HapticsPlugin: Returning status VIBE_S_SUCCESS") ) );
       
   273                         this->GetBinRespCode( iFileData.Find( KVibraCmdStatusCaseSuccess ), binRespData );
       
   274                         break;
       
   275                         }
       
   276                     case ALREADY_INITIALIZED_TEST:
       
   277                         {
       
   278                         COMPONENT_TRACE( ( _L("HWRM HapticsPlugin: Returning status VIBE_E_ALREADY_INITIALIZED") ) );
       
   279                         this->GetBinRespCode( iFileData.Find( KVibraCmdStatusCaseAlreadyInit ), binRespData );
       
   280                         break;
       
   281                         }                        
       
   282                     case NOT_INITIALIZED_TEST:
       
   283                         {
       
   284                         COMPONENT_TRACE( ( _L("HWRM HapticsPlugin: Returning status VIBE_E_NOT_INITIALIZED") ) );
       
   285                         this->GetBinRespCode( iFileData.Find( KVibraCmdStatusCaseNotInit ), binRespData );
       
   286                         break;
       
   287                         }
       
   288                     case INVALID_ARGUMENT_TEST:
       
   289                         {
       
   290                         COMPONENT_TRACE( ( _L("HWRM HapticsPlugin: Returning status VIBE_E_INVALID_ARGUMENT") ) );
       
   291                         this->GetBinRespCode( iFileData.Find( KVibraCmdStatusCaseInvalidArg ), binRespData );
       
   292                         break;
       
   293                         }        
       
   294                     case FAIL_TEST:
       
   295                         {
       
   296                         COMPONENT_TRACE( ( _L("HWRM HapticsPlugin: Returning status VIBE_E_FAIL") ) );
       
   297                         this->GetBinRespCode( iFileData.Find( KVibraCmdStatusCaseFail ), binRespData );
       
   298                         break;
       
   299                         }
       
   300                     case INCOMPATIBLE_EFFECT_TYPE_TEST:
       
   301                         {
       
   302                         COMPONENT_TRACE( ( _L("HWRM HapticsPlugin: Returning status VIBE_E_INCOMPATIBLE_EFFECT_TYPE") ) );
       
   303                         this->GetBinRespCode( iFileData.Find( KVibraCmdStatusCaseIncompEffType ), binRespData );
       
   304                         break;
       
   305                         }                        
       
   306                     case INCOMPATIBLE_CAPABILITY_TYPE_TEST:
       
   307                         {
       
   308                         COMPONENT_TRACE( ( _L("HWRM HapticsPlugin: Returning status VIBE_E_INCOMPATIBLE_CAPABILITY_TYPE") ) );
       
   309                         this->GetBinRespCode( iFileData.Find( KVibraCmdStatusCaseIncompCapaType ), binRespData );
       
   310                         break;
       
   311                         }
       
   312                     case INCOMPATIBLE_PROPERTY_TYPE_TEST:
       
   313                         {
       
   314                         COMPONENT_TRACE( ( _L("HWRM HapticsPlugin: Returning status VIBE_E_INCOMPATIBLE_PROPERTY_TYPE") ) );
       
   315                         this->GetBinRespCode( iFileData.Find( KVibraCmdStatusCaseIncompPropType ), binRespData );
       
   316                         break;
       
   317                         }                 
       
   318                     case DEVICE_NEEDS_LICENSE_TEST:
       
   319                         {
       
   320                         COMPONENT_TRACE( ( _L("HWRM HapticsPlugin: Returning status VIBE_E_DEVICE_NEEDS_LICENSE") ) );
       
   321                         this->GetBinRespCode( iFileData.Find( KVibraCmdStatusCaseDevNeedsLicense ), binRespData );
       
   322                         break;
       
   323                         }
       
   324                     case NOT_ENOUGH_MEMORY_TEST:
       
   325                         {
       
   326                         COMPONENT_TRACE( ( _L("HWRM HapticsPlugin: Returning status VIBE_E_NOT_ENOUGH_MEMORY") ) );
       
   327                         this->GetBinRespCode( iFileData.Find( KVibraCmdStatusCaseNotEnoughMem ), binRespData );
       
   328                         break;
       
   329                         }                        
       
   330                     case SERVICE_NOT_RUNNING_TEST:
       
   331                         {
       
   332                         COMPONENT_TRACE( ( _L("HWRM HapticsPlugin: Returning status VIBE_E_SERVICE_NOT_RUNNING") ) );
       
   333                         this->GetBinRespCode( iFileData.Find( KVibraCmdStatusCaseSrvNotRunning ), binRespData );
       
   334                         break;
       
   335                         }
       
   336                     case INSUFFICIENT_PRIORITY_TEST:
       
   337                         {
       
   338                         COMPONENT_TRACE( ( _L("HWRM HapticsPlugin: Returning status VIBE_E_INSUFFICIENT_PRIORITY") ) );
       
   339                         this->GetBinRespCode( iFileData.Find( KVibraCmdStatusCaseErrInsuffPriority ), binRespData );
       
   340                         break;
       
   341                         } 
       
   342                     case SERVICE_BUSY_TEST:
       
   343                         {
       
   344                         COMPONENT_TRACE( ( _L("HWRM HapticsPlugin: Returning status VIBE_E_SERVICE_BUSY") ) );
       
   345                         this->GetBinRespCode( iFileData.Find( KVibraCmdStatusCaseSrvBusy ), binRespData );
       
   346                         break;
       
   347                         }
       
   348                     case WRN_NOT_PLAYING_TEST:
       
   349                         {
       
   350                         COMPONENT_TRACE( ( _L("HWRM HapticsPlugin: Returning status VIBE_W_NOT_PLAYING") ) );
       
   351                         this->GetBinRespCode( iFileData.Find( KVibraCmdStatusCaseWrnNotPlaying ), binRespData );
       
   352                         break;
       
   353                         }                        
       
   354                     case WRN_INSUFFICIENT_PRIORITY_TEST:
       
   355                         {
       
   356                         COMPONENT_TRACE( ( _L("HWRM HapticsPlugin: Returning status VIBE_W_INSUFFICIENT_PRIORITY") ) );
       
   357                         this->GetBinRespCode( iFileData.Find( KVibraCmdStatusCaseWrnInsuffPriority ), binRespData );
       
   358                         break;
       
   359                         }
       
   360                     default:
       
   361                         {
       
   362                         jumpCases = EFalse;
       
   363                         break;    
       
   364                         }
       
   365                     }
       
   366                 if ( jumpCases )
       
   367                     {
       
   368                     iEffectState = ENotPlaying; 
       
   369                     }
       
   370                 }
       
   371             }
       
   372             
       
   373         if ( !jumpCases )
       
   374             {
       
   375             // Other cases..
       
   376             switch( iVibeCmdPacket->iSimpleRsp.iCmdCode )
       
   377                 {
       
   378             
       
   379                 case KVibeCmdInitialize:
       
   380                     {
       
   381                     COMPONENT_TRACE( ( _L("HWRM HapticsPlugin: VIBEPKT_CMD_INITIALIZE command: 0x%x" ), iVibeCmdPacket->iSimpleRsp.iCmdCode ) );    
       
   382                     TInt pos = iFileData.Find( KVibraCmdInitialize );
       
   383                     iEffectState = ENotPlaying;
       
   384                     this->GetBinRespCode( pos, binRespData );
       
   385                     break;
       
   386                     }
       
   387                 case KVibeCmdOpenDevice:
       
   388                     {
       
   389                     COMPONENT_TRACE( ( _L("HWRM HapticsPlugin: VIBEPKT_CMD_OPENDEVICE command: 0x%x" ), iVibeCmdPacket->iSimpleRsp.iCmdCode ) );
       
   390                     TInt pos = iFileData.Find( KVibraCmdOpenDevice );
       
   391                     iEffectState = ENotPlaying; 
       
   392                     this->GetBinRespCode( pos, binRespData );
       
   393                     break;
       
   394                     }
       
   395                 case KVibeCmdSetDeviceProperty:
       
   396                     {
       
   397                      COMPONENT_TRACE( ( _L("HWRM HapticsPlugin: VIBEPKT_CMD_SETDEVICEPROPERTY command: 0x%x" ), iVibeCmdPacket->iSimpleRsp.iCmdCode ) );
       
   398                      TInt pos = iFileData.Find( KVibraCmdSetDeviceProperty );
       
   399                      this->GetBinRespCode( pos, binRespData );
       
   400                      break;
       
   401                     }
       
   402                 case KVibeCmdPlayMagSweepEffect:
       
   403                     {
       
   404                     COMPONENT_TRACE( ( _L("HWRM HapticsPlugin: VIBEPKT_CMD_PLAYMAGSWEEPEFFECT command: 0x%x" ), iVibeCmdPacket->iSimpleRsp.iCmdCode ) ); 
       
   405                     TInt pos = iFileData.Find( KVibraCmdPlayMagSweepEffect );
       
   406                     iEffectState = EPlaying;
       
   407                     this->GetBinRespCode( pos, binRespData );
       
   408                     break;
       
   409                     }
       
   410                 case KVibeCmdCloseDevice:
       
   411                     {
       
   412                      COMPONENT_TRACE( ( _L("HWRM HapticsPlugin: VIBEPKT_CMD_CLOSEDEVICE command: 0x%x" ), iVibeCmdPacket->iSimpleRsp.iCmdCode ) );
       
   413                      TInt pos = iFileData.Find( KVibraCmdCloseDevice );
       
   414                      iEffectState = ENotPlaying;
       
   415                      this->GetBinRespCode( pos, binRespData );
       
   416                      break;
       
   417                     }
       
   418                 case KVibeCmdDeviceCount:
       
   419                     {
       
   420                     COMPONENT_TRACE( ( _L("HWRM HapticsPlugin: VIBEPKT_CMD_DEVICE_COUNT command: 0x%x" ), iVibeCmdPacket->iSimpleRsp.iCmdCode ) ); 
       
   421                     TInt pos = iFileData.Find( KVibraCmdDeviceCount );
       
   422                     this->GetBinRespCode( pos, binRespData );
       
   423                     break;
       
   424                     }
       
   425                 case KVibeCmdGetDeviceProperty:
       
   426                     {
       
   427                     COMPONENT_TRACE( ( _L("HWRM HapticsPlugin: VIBEPKT_CMD_GETDEVICEPROPERTY command: 0x%x" ), iVibeCmdPacket->iSimpleRsp.iCmdCode ) );
       
   428                     TInt pos = 0;
       
   429                     switch (iVibeCmdPacket->iGetDevicePropertyReq.iPropertyValueType)
       
   430                         {
       
   431                         case KVibeValuetypeInt32:
       
   432                             pos = iFileData.Find( KVibraCmdGetDevicePropertyInteger );
       
   433                             break;
       
   434                         case KVibeValuetypeString:
       
   435                             pos = iFileData.Find( KVibraCmdGetDevicePropertyString );
       
   436                             break;                        
       
   437                         case KVibeValuetypeBool:
       
   438                             pos = iFileData.Find( KVibraCmdGetDevicePropertyBool );
       
   439                             break;                        
       
   440                         default:
       
   441 #ifdef _DEBUG                        
       
   442                             User::Invariant(); // wrong value type
       
   443 #endif                            
       
   444                             ;
       
   445                         }
       
   446                     this->GetBinRespCode( pos, binRespData );
       
   447                     break;
       
   448                     }
       
   449                 case KVibeCmdGetDeviceState:
       
   450                     {
       
   451                      COMPONENT_TRACE( ( _L("HWRM HapticsPlugin: VIBEPKT_CMD_GETDEVICESTATE command: 0x%x" ), iVibeCmdPacket->iSimpleRsp.iCmdCode ) );
       
   452                      TInt pos = iFileData.Find( KVibraCmdGetDeviceState );
       
   453                      this->GetBinRespCode( pos, binRespData );
       
   454                      break;
       
   455                     }
       
   456                 case KVibeCmdGetDeviceCapabilities:
       
   457                     {
       
   458                     COMPONENT_TRACE( ( _L("HWRM HapticsPlugin: VIBEPKT_CMD_GETDEVICECAPABILITIES command: 0x%x" ), iVibeCmdPacket->iSimpleRsp.iCmdCode ) ); 
       
   459                     TInt pos = 0;
       
   460                     switch (iVibeCmdPacket->iGetDeviceCapsReq.iCapabilityValueType)
       
   461                         {
       
   462                         case KVibeValuetypeInt32:
       
   463                             pos = iFileData.Find( KVibraCmdGetDeviceCapabilitiesInteger );
       
   464                             break;
       
   465                         case KVibeValuetypeString:
       
   466                             pos = iFileData.Find( KVibraCmdGetDeviceCapabilitiesString );
       
   467                             break;
       
   468                         default:
       
   469 #ifdef _DEBUG                        
       
   470                             User::Invariant(); // wrong value type
       
   471 #endif                            
       
   472                             ;
       
   473                         }
       
   474                     this->GetBinRespCode( pos, binRespData );
       
   475                     break;
       
   476                     }
       
   477                 case KVibeCmdPlayPeriodicEffect:
       
   478                     {
       
   479                     COMPONENT_TRACE( ( _L("HWRM HapticsPlugin: VIBEPKT_CMD_PLAYPERIODICEFFECT command: 0x%x" ), iVibeCmdPacket->iSimpleRsp.iCmdCode ) );
       
   480                     TInt pos = iFileData.Find( KVibraCmdPlayPeriodicEffect );
       
   481                     iEffectState = EPlaying;
       
   482                     this->GetBinRespCode( pos, binRespData );
       
   483                     break;
       
   484                     }
       
   485                 case KVibeCmdPlayIVTEffectIncludeData:
       
   486                     {
       
   487                     COMPONENT_TRACE( ( _L("HWRM HapticsPlugin: VIBEPKT_CMD_PLAYIVTEFFECT_INCLUDEIVTDATA command: 0x%x" ), iVibeCmdPacket->iSimpleRsp.iCmdCode ) ); 
       
   488                     TInt pos = iFileData.Find( KVibraCmdPlayIVTEffectIncludeIVTData );
       
   489                     iEffectState = EPlaying;
       
   490                     this->GetBinRespCode( pos, binRespData );
       
   491                     break;
       
   492                     }
       
   493                 case KVibeCmdPlayIVTEffectNoData:
       
   494                     {
       
   495                     COMPONENT_TRACE( ( _L("HWRM HapticsPlugin: VIBEPKT_CMD_PLAYIVTEFFECT_NOIVTDATA command: 0x%x" ), iVibeCmdPacket->iSimpleRsp.iCmdCode ) );
       
   496                     TInt pos = iFileData.Find( KVibraCmdPlayIVTEffectNoIVTData );
       
   497                     iEffectState = EPlaying;
       
   498                     this->GetBinRespCode( pos, binRespData );
       
   499                     break;
       
   500                     }
       
   501                 case KVibeCmdStopEffect:
       
   502                     {
       
   503                     COMPONENT_TRACE( ( _L("HWRM HapticsPlugin: VIBEPKT_CMD_STOPEFFECT command: 0x%x" ), iVibeCmdPacket->iSimpleRsp.iCmdCode ) );
       
   504                     TInt pos = iFileData.Find( KVibraCmdStopEffect );
       
   505                     iEffectState = ENotPlaying;
       
   506                     this->GetBinRespCode( pos, binRespData );
       
   507                     break;
       
   508                     }
       
   509                 case KVibeCmdStopAllEffects:
       
   510                     {
       
   511                     COMPONENT_TRACE( ( _L("HWRM HapticsPlugin: VIBEPKT_CMD_STOPALLEFFECTS command: 0x%x" ), iVibeCmdPacket->iSimpleRsp.iCmdCode ) ); 
       
   512                     TInt pos = iFileData.Find( KVibraCmdStopAllEffects );
       
   513                     iEffectState = ENotPlaying;
       
   514                     this->GetBinRespCode( pos, binRespData );
       
   515                     break;
       
   516                     }
       
   517                 case KVibeCmdPlayStreamingSample:
       
   518                     {
       
   519                     COMPONENT_TRACE( ( _L("HWRM HapticsPlugin: VIBEPKT_CMD_PLAYSTREAMINGSAMPLE command: 0x%x" ), iVibeCmdPacket->iSimpleRsp.iCmdCode ) );
       
   520                     TInt pos = iFileData.Find( KVibraCmdPlayStreamingSample );
       
   521                     iEffectState = EPlaying;
       
   522                     this->GetBinRespCode( pos, binRespData );
       
   523                     break;
       
   524                     }
       
   525             
       
   526                 case KVibeCmdCreateStreamingEffect:
       
   527                     {
       
   528                     COMPONENT_TRACE( ( _L("HWRM HapticsPlugin: VIBEPKT_CMD_CREATESTREAMINGEFFECT command: 0x%x" ), iVibeCmdPacket->iSimpleRsp.iCmdCode ) );
       
   529                     TInt pos = iFileData.Find( KVibraCmdCreateStreamingEffect );
       
   530                     this->GetBinRespCode( pos, binRespData );
       
   531                     break;
       
   532                     }
       
   533                 case KVibeCmdDestroyStreamingEffect:
       
   534                     {
       
   535                     COMPONENT_TRACE( ( _L("HWRM HapticsPlugin: VIBEPKT_CMD_DESTROYSTREAMINGEFFECT command: 0x%x" ), iVibeCmdPacket->iSimpleRsp.iCmdCode ) ); 
       
   536                     TInt pos = iFileData.Find( KVibraCmdDestroyStreamingEffect );
       
   537                     this->GetBinRespCode( pos, binRespData );
       
   538                     break;
       
   539                     }
       
   540                 case KVibeCmdModifyPlayingMagSweepEffect:
       
   541                     {
       
   542                     COMPONENT_TRACE( ( _L("HWRM HapticsPlugin: VIBEPKT_CMD_MODIFYPLAYINGMAGSWEEPEFFECT command: 0x%x" ), iVibeCmdPacket->iSimpleRsp.iCmdCode ) );
       
   543                     TInt pos = iFileData.Find( KVibraCmdModifyPlayingMagSweepEffect );
       
   544                     this->GetBinRespCode( pos, binRespData );
       
   545                     break;
       
   546                     }
       
   547                 case KVibeCmdModifyPlayingPeriodicEffect:
       
   548                     {
       
   549                     COMPONENT_TRACE( ( _L("HWRM HapticsPlugin: VIBEPKT_CMD_MODIFYPLAYINGPERIODICEFFECT: 0x%x" ), iVibeCmdPacket->iSimpleRsp.iCmdCode ) );
       
   550                     TInt pos = iFileData.Find( KVibraCmdModifyPlayingPeriodicEffect );
       
   551                     this->GetBinRespCode( pos, binRespData );
       
   552                     break;
       
   553                     }
       
   554                 case KVibeCmdPausePlayingEffect:
       
   555                     {
       
   556                     COMPONENT_TRACE( ( _L("HWRM HapticsPlugin: VIBEPKT_CMD_PAUSEPLAYINGEFFECT command: 0x%x" ), iVibeCmdPacket->iSimpleRsp.iCmdCode ) ); 
       
   557                     TInt pos = iFileData.Find( KVibraCmdPausePlayingEffect );
       
   558                     iEffectState = EPaused;
       
   559                     this->GetBinRespCode( pos, binRespData );
       
   560                     break;
       
   561                     }
       
   562                 case KVibeCmdResumePausedEffect:
       
   563                     {
       
   564                     COMPONENT_TRACE( ( _L("HWRM HapticsPlugin: VIBEPKT_CMD_RESUMEPAUSEDEFFECT command: 0x%x" ), iVibeCmdPacket->iSimpleRsp.iCmdCode ) );
       
   565                     TInt pos = iFileData.Find( KVibraCmdResumePausedEffect );
       
   566                     iEffectState = EPlaying; 
       
   567                     this->GetBinRespCode( pos, binRespData );
       
   568                     break;
       
   569                     }
       
   570             
       
   571                 case KVibeCmdGetEffectState:
       
   572                     {
       
   573                     COMPONENT_TRACE( ( _L("HWRM HapticsPlugin: VIBEPKT_CMD_GETEFFECTSTATE command: 0x%x" ), iVibeCmdPacket->iSimpleRsp.iCmdCode ) );
       
   574                     TInt pos;
       
   575                     if ( iEffectState == ENotPlaying ) 
       
   576                         {
       
   577                         pos = iFileData.Find( KVibraCmdGetEffectStateNotPlaying );
       
   578                         }
       
   579                     else if ( iEffectState == EPlaying ) 
       
   580                         {   
       
   581                         pos = iFileData.Find( KVibraCmdGetEffectStatePlaying );
       
   582                         }
       
   583                     else
       
   584                         {
       
   585                         pos = iFileData.Find( KVibraCmdGetEffectStatePaused );
       
   586                         }
       
   587                     this->GetBinRespCode( pos, binRespData );
       
   588                     break;
       
   589                     }
       
   590                 case KVibeCmdSetKernelParameter:
       
   591                     {
       
   592                     COMPONENT_TRACE( ( _L("HWRM HapticsPlugin: VIBEPKT_CMD_SETKERNELPARAMETER command: 0x%x" ), iVibeCmdPacket->iSimpleRsp.iCmdCode ) ); 
       
   593                     TInt pos = iFileData.Find( KVibraCmdSetKernelParameter );
       
   594                     this->GetBinRespCode( pos, binRespData );
       
   595                     break;
       
   596                     }
       
   597                 case KVibeCmdGetKernelParameter:
       
   598                     {
       
   599                     COMPONENT_TRACE( ( _L("HWRM HapticsPlugin: VIBEPKT_CMD_GETKERNELPARAMETER command: 0x%x" ), iVibeCmdPacket->iSimpleRsp.iCmdCode ) );
       
   600                     TInt pos = iFileData.Find( KVibraCmdGetKernelParameter );
       
   601                     this->GetBinRespCode( pos, binRespData );
       
   602                     break;
       
   603                     }
       
   604                 case KVibeCmdSetLicense:
       
   605                     {
       
   606                     COMPONENT_TRACE( ( _L("HWRM HapticsPlugin: VIBEPKT_CMD_SETLICENSE command: 0x%x" ), iVibeCmdPacket->iSimpleRsp.iCmdCode ) );
       
   607                     TInt pos = iFileData.Find( KVibraCmdSetLicense );
       
   608                     this->GetBinRespCode( pos, binRespData );
       
   609                     break;
       
   610                     }
       
   611                 default:
       
   612                     {
       
   613                     // do panic --> packetized message not recognized
       
   614                     break;
       
   615                     }    
       
   616                 }//switch
       
   617             }
       
   618 
       
   619             CHWRMHapticsRespData* respData;
       
   620             TInt32 errorCode( KErrNone );
       
   621             respData = CHWRMHapticsRespData::NewLC( errorCode, binRespData );
       
   622             RDesWriteStream writer( iStorage );
       
   623             CleanupClosePushL( writer );
       
   624             // write to resp data
       
   625             writer << *respData;
       
   626             // remove from stack , it will commit the actual data to the stoarage.
       
   627             CleanupStack::PopAndDestroy( &writer ); 
       
   628             CleanupStack::PopAndDestroy( respData ); 
       
   629             
       
   630         } // if block end for pRsp check
       
   631     
       
   632     
       
   633     TRAP( err, aService->ProcessResponseL( aCommandId, aTransId, iStorage ) );               
       
   634     // delete obsolete timers
       
   635     for( TInt i = ( iTimers.Count()-1 ); i > -1 ; i-- )
       
   636         {
       
   637         if ( !iTimers[i]->IsActive() )
       
   638             {
       
   639             delete iTimers[i];
       
   640             iTimers.Remove( i );            
       
   641             COMPONENT_TRACE( ( _L("HWRM HapticsPlugin: GenericTimerFired - Removed obsolete timer") ) );
       
   642             }
       
   643         }
       
   644     }
       
   645 
       
   646 
       
   647 // -----------------------------------------------------------------------------
       
   648 // CHWRMHapticsTestPlugin::Hex2Bin
       
   649 // Converts hexadecimal string given as first parameter to binary data that is 
       
   650 // stored to the object referenced by the second parameter.
       
   651 // -----------------------------------------------------------------------------
       
   652 // 
       
   653 void CHWRMHapticsTestPlugin::Hex2Bin( const TDesC8& aSrcBuffer, TDes8& aDstBuffer )
       
   654      {
       
   655      TInt len = aSrcBuffer.Length();
       
   656      aDstBuffer.SetLength( len >> 1 );
       
   657      for ( TInt n=0; n<len; n+=2 )
       
   658          {
       
   659          TUint8 hiNibble = ( (aSrcBuffer[n] > '9' ) ? aSrcBuffer[n] - 'A' + 10: aSrcBuffer[n] - '0' );
       
   660          TUint8 loNibble = ( (aSrcBuffer[n+1] > '9' ) ? aSrcBuffer[n+1] - 'A' + 10: aSrcBuffer[n+1] - '0' );
       
   661  
       
   662          aDstBuffer[n>>1] = static_cast<TUint8>( ( ( hiNibble << 4 ) + loNibble ) );
       
   663          }
       
   664      }
       
   665 
       
   666 
       
   667 // -----------------------------------------------------------------------------
       
   668 // CHWRMHapticsTestPlugin::GetBinRespCode
       
   669 // Helper method that gets the response data string from given position (line)
       
   670 // of the (buffered in) response data file, and with the above Hex2Bin method
       
   671 // converts the string into binary data that is then stored to the TDes8 object
       
   672 // whose reference is given as second param (aBinRespData).
       
   673 // -----------------------------------------------------------------------------
       
   674 // 
       
   675 void CHWRMHapticsTestPlugin::GetBinRespCode( TInt aCmdPosition, TDes8& aBinRespData )
       
   676     {
       
   677      TBuf8<KRespFileData> tempFileData;
       
   678      TBuf8<KHexRespCode>  hexRespCode;
       
   679      
       
   680      tempFileData.Copy( iFileData.Mid( aCmdPosition ) );
       
   681      TInt pos2 = tempFileData.Locate( '"' );
       
   682      TInt pos3 = tempFileData.Locate( '\r' );
       
   683      TInt respCodeLength = ( pos3-2 ) - pos2;
       
   684      
       
   685      hexRespCode.Copy( tempFileData.Mid( pos2+1, respCodeLength ) );
       
   686      
       
   687      CHWRMHapticsTestPlugin::Hex2Bin( hexRespCode, aBinRespData );     
       
   688     }
       
   689 
       
   690 
       
   691