hwrmhaptics/hapticsclient/src/hwrmhapticsimpl.cpp
changeset 0 4e1aa6a622a0
child 41 c87e5f80c17d
equal deleted inserted replaced
-1:000000000000 0:4e1aa6a622a0
       
     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 "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:  Implementation of haptics client.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include <hwrmhapticspacketizer.h>
       
    20 #include <hwrmhapticseffectdatagetter.h>
       
    21 
       
    22 #include "hwrmhapticsimpl.h"
       
    23 #include "hwrmhapticstrace.h"
       
    24 #include "hwrmhapticssession.h" // common SendReceive
       
    25 #include "hwrmhapticsclientserver.h"  // Cmd Ids
       
    26 #include "hwrmhapticsivtdatacache.h"
       
    27 #include "hwrmhapticsstatusobserver.h"
       
    28 #include "hwrmhapticsclientserver.h"
       
    29 
       
    30 #if defined(_DEBUG)
       
    31 _LIT( KPanic, "HWRMHapticsClient" );
       
    32 #endif
       
    33 
       
    34 // ---------------------------------------------------------------------------
       
    35 // C++ constructor
       
    36 // ---------------------------------------------------------------------------
       
    37 //
       
    38 CHWRMHapticsImpl::CHWRMHapticsImpl()
       
    39     : iDeviceHandle( 0 ), iOpenedActuator( EHWRMLogicalActuatorLast ),
       
    40       iEffectHandlePckg( 0 )
       
    41     {
       
    42     COMPONENT_TRACE( ( _L( "CHWRMHapticsImpl::CHWRMHapticsImpl()" ) ) );
       
    43     }
       
    44 
       
    45 // ---------------------------------------------------------------------------
       
    46 // Symbian 2nd phase constructor.
       
    47 // ---------------------------------------------------------------------------
       
    48 //
       
    49 void CHWRMHapticsImpl::ConstructL( 
       
    50     MHWRMHapticsObserver* aHapticsCallback, 
       
    51     MHWRMHapticsActuatorObserver* aActuatorCallback )
       
    52     {
       
    53     COMPONENT_TRACE( ( _L( "CHWRMHapticsImpl::ConstructL()" ) ) );
       
    54 
       
    55     User::LeaveIfError( iClient.Connect() );
       
    56     
       
    57     FinalizeL( aHapticsCallback, aActuatorCallback );
       
    58 
       
    59     COMPONENT_TRACE( ( _L( "CHWRMHapticsImpl::ConstructL() - return" ) ) );    
       
    60     }
       
    61     
       
    62 // ---------------------------------------------------------------------------
       
    63 // Asynchronous construction.
       
    64 // ---------------------------------------------------------------------------
       
    65 //
       
    66 void CHWRMHapticsImpl::ConstructL(
       
    67     MHWRMHapticsObserver* aHapticsCallback,
       
    68     MHWRMHapticsActuatorObserver* aActuatorCallback,
       
    69     TRequestStatus& aStatus )
       
    70     {
       
    71     COMPONENT_TRACE( ( _L( "CHWRMHapticsImpl::ConstructL() - ASYNC" ) ) );
       
    72 
       
    73     iClient.Connect( aStatus );
       
    74 
       
    75     FinalizeL( aHapticsCallback, aActuatorCallback );
       
    76 
       
    77     COMPONENT_TRACE( ( _L( "CHWRMHapticsImpl::ConstructL() - ASYNC - return" ) ) );
       
    78     }
       
    79 
       
    80 // ---------------------------------------------------------------------------
       
    81 // Destructor
       
    82 // ---------------------------------------------------------------------------
       
    83 //
       
    84 CHWRMHapticsImpl::~CHWRMHapticsImpl()
       
    85     {
       
    86     COMPONENT_TRACE( ( _L( "CHWRMHapticsImpl::~CHWRMHapticsImpl()" ) ) );
       
    87 
       
    88     if( iEffectDataGetter )
       
    89         {
       
    90         delete iEffectDataGetter;
       
    91         iEffectDataGetter = NULL;
       
    92         } 
       
    93 
       
    94     if( iPacketizer )
       
    95         {
       
    96         delete iPacketizer;
       
    97         iPacketizer = NULL;
       
    98         } 
       
    99 
       
   100     if ( iIVTDataCache )
       
   101         {
       
   102         delete iIVTDataCache;
       
   103         iIVTDataCache = NULL;
       
   104         }
       
   105 
       
   106     iReqData.Close();
       
   107     
       
   108     // Inform session that we are cleaning up now. Trace errors.
       
   109     if ( iClient.Handle() )
       
   110         {
       
   111         TInt err = iClient.ExecuteOperation( EHWRMHapticsCleanup );
       
   112         
       
   113         COMPONENT_TRACE( ( _L( "CHWRMHapticsImpl::~CHWRMHapticsImpl - Cleanup error code: %d" ), err ) );
       
   114         }
       
   115 
       
   116     // destroy observer after cleanup command, since it may receive
       
   117     // a response from the server during cleanup command execution
       
   118     if ( iStatusObserver )
       
   119         {
       
   120         delete iStatusObserver; // will also cancel active object
       
   121         iStatusObserver = NULL;
       
   122         }
       
   123 
       
   124     iClient.Close();
       
   125     
       
   126     REComSession::FinalClose();
       
   127 
       
   128     COMPONENT_TRACE( ( _L( "CHWRMHapticsImpl::~CHWRMHapticsImpl - return" ) ) );
       
   129     }
       
   130  
       
   131 // ---------------------------------------------------------------------------
       
   132 // Opens an actuator using the given logical actuator type.
       
   133 // ---------------------------------------------------------------------------
       
   134 //
       
   135 void CHWRMHapticsImpl::OpenActuatorL( THWRMLogicalActuators aActuator )
       
   136     {
       
   137     API_TRACE( ( _L( "e_HWRMHAPTICS_CLIENT_OPENACTUATORL 1" ) ) );
       
   138     API_TRACE( ( _L( "CHWRMHapticsImpl::OpenActuatorL() - aActuator(%d)" ), aActuator ) );
       
   139 
       
   140     // check that aActuator contains one of enumeration value
       
   141     TBool validActuator = EFalse;
       
   142     for ( TInt n = EHWRMLogicalActuatorAny; n < EHWRMLogicalActuatorLast && !validActuator; n <<= 1 )
       
   143         {
       
   144         if ( aActuator == n )
       
   145             {
       
   146             validActuator = ETrue;
       
   147             }
       
   148         }
       
   149     if ( !validActuator )
       
   150         {
       
   151         User::Leave( KErrArgument );
       
   152         }
       
   153 
       
   154     // leave if some actuator is already opened
       
   155     if ( iOpenedActuator != EHWRMLogicalActuatorLast )
       
   156         {
       
   157         if ( aActuator == iOpenedActuator )
       
   158             {
       
   159             User::Leave( KErrAlreadyExists );
       
   160             }
       
   161         else
       
   162             {
       
   163             User::Leave( KErrInUse );
       
   164             }
       
   165         }
       
   166 
       
   167     if( iPacketizer )
       
   168         {
       
   169         delete iPacketizer;
       
   170         iPacketizer = NULL;
       
   171         }
       
   172 
       
   173     // create the packetizer instance
       
   174     iPacketizer = CHWRMHapticsPacketizer::NewL( aActuator );
       
   175 
       
   176     // get request data for opening an actuator
       
   177     iReqData.Close();
       
   178     User::LeaveIfError( iPacketizer->EncOpenDeviceReq( aActuator, iReqData ) );
       
   179     
       
   180     // initialize device handle before command execution
       
   181     iDeviceHandle = 0;
       
   182 
       
   183     // device handle is out-param to command
       
   184     TPckg<TInt> deviceHandlePckg( iDeviceHandle );
       
   185 
       
   186     User::LeaveIfError( iClient.ExecuteOperation( 
       
   187                     EHWRMHapticsOpenActuator, 
       
   188                     TIpcArgs( &iReqData, &deviceHandlePckg, aActuator ) ) );
       
   189     
       
   190     // opened actuator successfully, store the actuator type
       
   191     iOpenedActuator = aActuator;
       
   192     
       
   193     API_TRACE( _L( "CHWRMHapticsImpl::OpenActuatorL() - return" ) );
       
   194     API_TRACE( ( _L( "e_HWRMHAPTICS_CLIENT_OPENACTUATORL 0" ) ) );
       
   195     }
       
   196 
       
   197 // ---------------------------------------------------------------------------
       
   198 // Fetches the supported logical actuator types.
       
   199 // ---------------------------------------------------------------------------
       
   200 //
       
   201 TInt CHWRMHapticsImpl::SupportedActuators( TUint32& aActuators )
       
   202     {
       
   203     API_TRACE( ( _L( "CHWRMHapticsImpl::SupportedActuators() - aActuators(%d)" ), aActuators ) );
       
   204     
       
   205     // data package, which should include the fetched data on return
       
   206     TPckg<TUint32> actuatorInfoPckg( aActuators );
       
   207 
       
   208     // send command to server
       
   209     TInt err = iClient.ExecuteOperation( EHWRMHapticsSuppActuators,
       
   210                                          TIpcArgs( &actuatorInfoPckg ) );
       
   211 
       
   212     API_TRACE( ( _L( "CHWRMHapticsImpl::iSupportedActuators - %d" ), aActuators ) );
       
   213     API_TRACE( ( _L( "CHWRMHapticsImpl::SupportedActuators() - return %d" ), err ) );
       
   214 
       
   215     return err;
       
   216     }
       
   217 
       
   218 // ---------------------------------------------------------------------------
       
   219 // Reserves haptics feature exclusively for this client.
       
   220 // This is a convenience frontend to the below ReserveHapticsL
       
   221 // with TBool argument overload.
       
   222 // ---------------------------------------------------------------------------
       
   223 //
       
   224 void CHWRMHapticsImpl::ReserveHapticsL()
       
   225     {
       
   226     ReserveHapticsL( EFalse );
       
   227     }
       
   228 
       
   229 // ---------------------------------------------------------------------------
       
   230 // Reserves haptics feature exclusively for this client.
       
   231 // ---------------------------------------------------------------------------
       
   232 //
       
   233 void CHWRMHapticsImpl::ReserveHapticsL( TBool aForceNoCCoeEnv )
       
   234     {
       
   235     API_TRACE( ( _L( "CHWRMHapticsImpl::ReserveHapticsL(0x%x)" ), aForceNoCCoeEnv ) );
       
   236     
       
   237     // We have not used CONE solution here because it is on middleware
       
   238     // layer. While hwrmhaptics is on OS layer.  We shall find OS layer
       
   239     // replacement for observing foreground/background events.
       
   240 
       
   241     /* 
       
   242     if ( !aForceNoCCoeEnv )
       
   243         {
       
   244         // Check that CCoeEnv exists
       
   245         CCoeEnv* env = CCoeEnv::Static();
       
   246         if ( env )
       
   247             {
       
   248             // Check that we are on foreground (i.e. we have keyboard focus.)
       
   249             // There can be windows on top of our application that 
       
   250             // have explicitly disabled keyboard focus,
       
   251             // but then again the foreground/background observer will not 
       
   252             // kick in in those cases either.
       
   253             // -> We can use focus to determine foreground status here.
       
   254             if ( env->WsSession().GetFocusWindowGroup() != 
       
   255                  env->RootWin().Identifier() )
       
   256                 {
       
   257                 COMPONENT_TRACE( ( _L( "CHWRMHapticsImpl::ReserveHapticsL - Application not focused, reserve denied." ) ) );
       
   258                 User::Leave( KErrNotReady );
       
   259                 }
       
   260             }
       
   261         else
       
   262             {
       
   263             COMPONENT_TRACE( ( _L( "CHWRMHapticsImpl::ReserveHapticsL - No CCoeEnv available" ) ) );
       
   264             User::Leave( KErrBadHandle );
       
   265             }
       
   266         }
       
   267     */
       
   268 
       
   269     // Do the actual reservation
       
   270     User::LeaveIfError( DoReserveHaptics( aForceNoCCoeEnv ) );
       
   271 
       
   272     API_TRACE( ( _L( "CHWRMHapticsImpl::ReserveHapticsL - return" ) ) );
       
   273     }
       
   274 
       
   275 // ---------------------------------------------------------------------------
       
   276 // Releases haptics feature if it was previously reserved for this client.
       
   277 // ---------------------------------------------------------------------------
       
   278 //
       
   279 void CHWRMHapticsImpl::ReleaseHaptics()
       
   280     {
       
   281     API_TRACE( ( _L( "CHWRMHapticsImpl::ReleaseHaptics()" ) ) );
       
   282     
       
   283     DoReleaseHaptics();
       
   284     iAutoReserve = EFalse;
       
   285 
       
   286     API_TRACE( ( _L( "CHWRMHapticsImpl::ReleaseHaptics - return" ) ) );
       
   287     }
       
   288 
       
   289 // ---------------------------------------------------------------------------
       
   290 // Returns the current haptics status.
       
   291 // ---------------------------------------------------------------------------
       
   292 //
       
   293 MHWRMHapticsObserver::THWRMHapticsStatus 
       
   294 CHWRMHapticsImpl::HapticsStatus() const
       
   295     {
       
   296     API_TRACE( ( _L( "CHWRMHapticsImpl::HapticsStatus()" )) );
       
   297     
       
   298     MHWRMHapticsObserver::THWRMHapticsStatus status = 
       
   299         MHWRMHapticsObserver::EHWRMHapticsStatusAvailable;
       
   300     
       
   301     if ( iStatusObserver )
       
   302         {
       
   303         // ask the current status from the observer
       
   304         status = iStatusObserver->CurrentStatus();
       
   305         }
       
   306     else
       
   307         {
       
   308         TPckg<MHWRMHapticsObserver::THWRMHapticsStatus> statusPckg( status );
       
   309         
       
   310         // no observer available, request status from the server
       
   311         iClient.ExecuteOperation( EHWRMHapticsGetStatus,
       
   312                                   TIpcArgs( &statusPckg ) );
       
   313         }
       
   314     
       
   315     API_TRACE( ( _L( "CHWRMHapticsImpl::HapticsStatus - return 0x%x" ), status ) );
       
   316     
       
   317     return status;
       
   318     }
       
   319 
       
   320 // ---------------------------------------------------------------------------
       
   321 // SetDeviceProperty() - TInt overload for aDevicePropertyValue parameter
       
   322 // ---------------------------------------------------------------------------
       
   323 //
       
   324 TInt CHWRMHapticsImpl::SetDeviceProperty( TInt aDevicePropertyType, 
       
   325                                           TInt aDevicePropertyValue )
       
   326     {
       
   327     __ASSERT_DEBUG( iPacketizer, User::Panic( KPanic, EPanicNotReady ) );
       
   328     if ( !iPacketizer )
       
   329         {
       
   330         return EPanicNotReady;
       
   331         }
       
   332     API_TRACE( ( _L( "CHWRMHapticsImpl::SetDeviceProperty() - TInt overloaded - aDevicePropertyType(%d), aDevicePropertyValue(%d)" ), aDevicePropertyType, aDevicePropertyValue ) );
       
   333 
       
   334     TInt err( KErrNone );
       
   335     switch ( aDevicePropertyType )
       
   336         {
       
   337         case CHWRMHaptics::EHWRMHapticsPriority:
       
   338             if ( aDevicePropertyValue < KHWRMHapticsMinDevicePriority ||
       
   339                  aDevicePropertyValue > KHWRMHapticsMaxDevicePriority )
       
   340                 {
       
   341                 API_TRACE( ( _L( "CHWRMHapticsImpl::SetDeviceProperty() - argument is not in range (EHWRMHapticsPriority)" ) ) );
       
   342                 err = KErrArgument;
       
   343                 }
       
   344             break;    
       
   345         case CHWRMHaptics::EHWRMHapticsDisableEffects:
       
   346             // any value is accepted
       
   347             break;
       
   348         case CHWRMHaptics::EHWRMHapticsStrength: // flow through
       
   349         case CHWRMHaptics::EHWRMHapticsMasterStrength:
       
   350             if ( aDevicePropertyValue < KHWRMHapticsMinStrength || 
       
   351                  aDevicePropertyValue > KHWRMHapticsMaxStrength )
       
   352                 {
       
   353                 API_TRACE( ( _L( "CHWRMHapticsImpl::SetDeviceProperty() - argument is not in range (EHWRMHaptics(Master)Strength)" ) ) );
       
   354                 err = KErrArgument;
       
   355                 }
       
   356             break;    
       
   357         default:             
       
   358             API_TRACE( ( _L( "CHWRMHapticsImpl::SetDeviceProperty() - invalid property type" ) ) );
       
   359             err = KErrArgument;
       
   360         }
       
   361     
       
   362     iReqData.Close(); 
       
   363     
       
   364     // encode request package
       
   365     if ( KErrNone == err )
       
   366         {
       
   367         if ( aDevicePropertyType == CHWRMHaptics::EHWRMHapticsDisableEffects )
       
   368             {
       
   369             err = iPacketizer->EncSetDevicePropertyBoolReq( 
       
   370                     iDeviceHandle, aDevicePropertyValue,
       
   371                     aDevicePropertyType, iReqData );
       
   372             }
       
   373         else
       
   374             {
       
   375             err = iPacketizer->EncSetDevicePropertyIntReq( 
       
   376                     iDeviceHandle, aDevicePropertyValue,
       
   377                     aDevicePropertyType, iReqData );
       
   378             }
       
   379     
       
   380         // send command to haptics server
       
   381         if ( KErrNone == err )
       
   382             {
       
   383             err = iClient.ExecuteOperation( EHWRMHaptics, 
       
   384                                             TIpcArgs( &iReqData ) );
       
   385             }
       
   386         }
       
   387     
       
   388     API_TRACE( ( _L( "CHWRMHapticsImpl::SetDeviceProperty() - return %d" ), err ) );    
       
   389 
       
   390     return err;
       
   391     }
       
   392 
       
   393 // ---------------------------------------------------------------------------
       
   394 // SetDeviceProperty() - TDesC8 overload for aDevicePropertyValue parameter
       
   395 // ---------------------------------------------------------------------------
       
   396 //
       
   397 TInt CHWRMHapticsImpl::SetDeviceProperty( TInt aDevicePropertyType, 
       
   398                                           const TDesC8& aDevicePropertyValue )
       
   399     {
       
   400     __ASSERT_DEBUG( iPacketizer, User::Panic( KPanic, EPanicNotReady ) );
       
   401     if ( !iPacketizer )
       
   402         {
       
   403         return EPanicNotReady;
       
   404         }
       
   405     API_TRACE( ( _L( "CHWRMHapticsImpl::SetDeviceProperty() - const TDesC8 overloaded - aDevicePropertyType(%d), aDevicePropertyValue( 0x%x)" ), aDevicePropertyType, &aDevicePropertyValue ) );
       
   406 
       
   407     TInt err( KErrNone );
       
   408 
       
   409     // check property type, only license key setting supported (for
       
   410     // string value type properties)
       
   411     if( CHWRMHaptics::EHWRMHapticsLicensekey != aDevicePropertyType )
       
   412         {
       
   413         API_TRACE( ( _L( "CHWRMHapticsImpl::SetDeviceProperty() - invalid property type" ) ) );
       
   414         err = KErrArgument;
       
   415         }
       
   416     
       
   417     
       
   418     if ( KErrNone == err )
       
   419         {
       
   420         // encode request package
       
   421         iReqData.Close(); 
       
   422         err = iPacketizer->EncSetDevicePropertyStringReq(
       
   423                                     iDeviceHandle,
       
   424                                     aDevicePropertyValue,
       
   425                                     aDevicePropertyType,
       
   426                                     iReqData );
       
   427 
       
   428         // send command to haptics server
       
   429         if ( KErrNone == err )
       
   430             {
       
   431             if( aDevicePropertyType == EHWRMHapticsLicensekey )
       
   432                 {
       
   433                 err = iClient.ExecuteOperation( 
       
   434                        EHWRMHapticsSetLicenseProp, 
       
   435                        TIpcArgs( &iReqData, aDevicePropertyValue.Length() ) );
       
   436                 }
       
   437             else
       
   438                 {
       
   439                 err = iClient.ExecuteOperation( EHWRMHaptics,  
       
   440                                                 TIpcArgs( &iReqData ) );
       
   441                 }
       
   442             }
       
   443          
       
   444         }
       
   445     
       
   446     API_TRACE( ( _L( "CHWRMHapticsImpl::SetDeviceProperty() - const TDesC8 overloaded - return %d" ), err ) );
       
   447     
       
   448     return err;
       
   449     }
       
   450 
       
   451 // ---------------------------------------------------------------------------
       
   452 // GetDeviceProperty() - TInt overload for aDevicePropertyValue parameter
       
   453 // ---------------------------------------------------------------------------
       
   454 //
       
   455 TInt CHWRMHapticsImpl::GetDeviceProperty( TInt aDevicePropertyType, 
       
   456                                           TInt& aDevicePropertyValue )
       
   457     {
       
   458     __ASSERT_DEBUG( iPacketizer, User::Panic( KPanic, EPanicNotReady ) );
       
   459     if ( !iPacketizer )
       
   460         {
       
   461         return EPanicNotReady;
       
   462         }
       
   463     API_TRACE( ( _L( "CHWRMHapticsImpl::GetDeviceProperty() - TInt overloaded - aDevicePropertyType(%d), aDevicePropertyValue(%d)" ), aDevicePropertyType, aDevicePropertyValue ) );
       
   464 
       
   465     TInt err( KErrNone );
       
   466     iReqData.Close();
       
   467 
       
   468     if ( aDevicePropertyType == CHWRMHaptics::EHWRMHapticsDisableEffects )
       
   469         {
       
   470         err = iPacketizer->EncGetDevicePropertyBoolReq( 
       
   471                    iDeviceHandle, aDevicePropertyType, iReqData );
       
   472         }
       
   473     else
       
   474         {
       
   475         err = iPacketizer->EncGetDevicePropertyIntReq( 
       
   476                    iDeviceHandle, aDevicePropertyType, iReqData );
       
   477         }    
       
   478        
       
   479     if ( KErrNone == err )
       
   480         {
       
   481         TPckg<TInt> devicePropertyValuePckg( aDevicePropertyValue );
       
   482         
       
   483         err = iClient.ExecuteOperation( 
       
   484             EHWRMHaptics, 
       
   485             TIpcArgs( &iReqData, &devicePropertyValuePckg ) );
       
   486         }
       
   487 
       
   488     API_TRACE( ( _L( "CHWRMHapticsImpl::GetDeviceProperty() - TInt overloaded - return %d" ), err ) );
       
   489     
       
   490     return err;
       
   491     }
       
   492 
       
   493 // ---------------------------------------------------------------------------
       
   494 // GetDeviceProperty() - TDes8 overload for aDevicePropertyValue parameter
       
   495 // ---------------------------------------------------------------------------
       
   496 //
       
   497 TInt CHWRMHapticsImpl::GetDeviceProperty( TInt aDevicePropertyType, 
       
   498                                           TDes8& aDevicePropertyValue )
       
   499     {
       
   500     __ASSERT_DEBUG( iPacketizer, User::Panic( KPanic, EPanicNotReady ) );
       
   501     if ( !iPacketizer )
       
   502         {
       
   503         return EPanicNotReady;
       
   504         }
       
   505     API_TRACE( ( _L( "CHWRMHapticsImpl::GetDeviceProperty() - TDes8 overloaded - aDevicePropertyType(%d), aDevicePropertyValue(0x%x)" ), aDevicePropertyType, &aDevicePropertyValue ) );
       
   506 
       
   507     TInt err( KErrNone );
       
   508 
       
   509     if( aDevicePropertyValue.MaxLength() < MaxPropertyStringLength() ) 
       
   510         {
       
   511         err = KErrArgument;
       
   512         }
       
   513     
       
   514     if ( KErrNone == err )
       
   515         {
       
   516         // encode the request
       
   517         iReqData.Close();
       
   518         err = iPacketizer->EncGetDevicePropertyStringReq( 
       
   519                     iDeviceHandle, aDevicePropertyType, iReqData );
       
   520     
       
   521         if ( KErrNone == err )
       
   522             {
       
   523             err = iClient.ExecuteOperation( 
       
   524                     EHWRMHaptics, 
       
   525                     TIpcArgs( &iReqData, &aDevicePropertyValue ) );
       
   526             }
       
   527         }
       
   528     
       
   529     API_TRACE( ( _L( "CHWRMHapticsImpl::GetDeviceProperty() - TDes8 overloaded - return %d" ), err ) );
       
   530     
       
   531     return err;
       
   532     }
       
   533 
       
   534 // ---------------------------------------------------------------------------
       
   535 // GetDeviceCapability() - TInt overload for aDeviceCapabilityValue parameter
       
   536 // ---------------------------------------------------------------------------
       
   537 //
       
   538 TInt CHWRMHapticsImpl::GetDeviceCapability( TInt aDeviceCapabilityType, 
       
   539                                             TInt& aDeviceCapabilityValue )
       
   540     {
       
   541     __ASSERT_DEBUG( iPacketizer, User::Panic( KPanic, EPanicNotReady ) );
       
   542     if ( !iPacketizer )
       
   543         {
       
   544         return EPanicNotReady;
       
   545         }
       
   546     API_TRACE( ( _L( "CHWRMHapticsImpl::GetDeviceCapability() - aDeviceCapabilityType(%d), aDeviceCapabilityValue(%d)" ), aDeviceCapabilityType, aDeviceCapabilityValue ) );
       
   547     
       
   548     // default return value in case actuator has not been opened
       
   549     TInt err = KErrNotReady;
       
   550     
       
   551     if ( iOpenedActuator != EHWRMLogicalActuatorLast )
       
   552         {
       
   553         iReqData.Close();
       
   554         err = iPacketizer->EncGetDeviceCapabilityIntReq(
       
   555                  iOpenedActuator, aDeviceCapabilityType, iReqData );
       
   556         
       
   557         TPckg<TInt> deviceCapabilityValuePckg( aDeviceCapabilityValue );
       
   558         
       
   559         if ( KErrNone == err )
       
   560             {
       
   561             err = iClient.ExecuteOperation( 
       
   562                 EHWRMHaptics, 
       
   563                 TIpcArgs( &iReqData, &deviceCapabilityValuePckg ) );
       
   564             }
       
   565         }
       
   566     
       
   567     API_TRACE( ( _L( "CHWRMHapticsImpl::GetDeviceCapability() - return %d" ), err ) );
       
   568 
       
   569     return err;
       
   570     }
       
   571 
       
   572 // ---------------------------------------------------------------------------
       
   573 // GetDeviceCapability() - TDes8 overload for aDeviceCapabilityValue parameter
       
   574 // ---------------------------------------------------------------------------
       
   575 //
       
   576 TInt CHWRMHapticsImpl::GetDeviceCapability( TInt aDeviceCapabilityType, 
       
   577                                             TDes8& aDeviceCapabilityValue )
       
   578     {
       
   579     API_TRACE( ( _L( "CHWRMHapticsImpl::GetDeviceCapability() - aDeviceCapabilityType(%d), aDeviceCapabilityValue(0x%x)" ), aDeviceCapabilityType, &aDeviceCapabilityValue ) );
       
   580     
       
   581     // default return value in case actuator has not been opened
       
   582     TInt err = KErrNotReady;
       
   583     
       
   584     if ( iOpenedActuator != EHWRMLogicalActuatorLast )
       
   585         {
       
   586         if( aDeviceCapabilityValue.MaxLength() < MaxCapabilityStringLength() ) 
       
   587             {
       
   588             err = KErrArgument;
       
   589             }
       
   590         else
       
   591             {
       
   592             iReqData.Close();
       
   593             err = iPacketizer->EncGetDeviceCapabilityStringReq( 
       
   594                     iOpenedActuator, aDeviceCapabilityType, iReqData );
       
   595             
       
   596             if ( KErrNone == err )
       
   597                 {
       
   598                 err = iClient.ExecuteOperation( 
       
   599                         EHWRMHaptics, 
       
   600                         TIpcArgs( &iReqData, &aDeviceCapabilityValue ) );
       
   601                 }
       
   602             }
       
   603         }
       
   604     
       
   605     API_TRACE( ( _L( "CHWRMHapticsImpl::GetDeviceCapability() - TInt overloaded - return %d" ), err ) );
       
   606     
       
   607     return err;
       
   608     }
       
   609 
       
   610 // ---------------------------------------------------------------------------
       
   611 // Retrieves the status of an effect (playing, not playing, paused).
       
   612 // ---------------------------------------------------------------------------
       
   613 //
       
   614 TInt CHWRMHapticsImpl::GetEffectState( TInt aEffectHandle, 
       
   615                                        TInt& aEffectState )
       
   616     {
       
   617     __ASSERT_DEBUG( iPacketizer, User::Panic( KPanic, EPanicNotReady ) );
       
   618     if ( !iPacketizer )
       
   619         {
       
   620         return EPanicNotReady;
       
   621         }
       
   622     API_TRACE( ( _L( "CHWRMHapticsImpl::GetEffectState() - aEffectHandle(%d) - aEffectState(%d)" ), aEffectHandle, aEffectState ) );
       
   623 
       
   624     TInt err( KErrNone ); 
       
   625 
       
   626     iReqData.Close();
       
   627     err = iPacketizer->EncGetEffectStateReq( 
       
   628             iDeviceHandle, aEffectHandle, iReqData );
       
   629     
       
   630     if ( KErrNone == err ) 
       
   631         {
       
   632         TPckg<TInt> effectStatePckg( aEffectState );
       
   633         err = iClient.ExecuteOperation( EHWRMHaptics, 
       
   634                                         TIpcArgs( &iReqData, 
       
   635                                                   &effectStatePckg ) );
       
   636         }
       
   637     
       
   638     API_TRACE( ( _L( "CHWRMHapticsImpl::GetEffectState() - return" ) ) );
       
   639     
       
   640     return err;
       
   641     }
       
   642 
       
   643 // ---------------------------------------------------------------------------
       
   644 // Creates a new streaming effect and returns a new handle for it.
       
   645 // ---------------------------------------------------------------------------
       
   646 //
       
   647 TInt CHWRMHapticsImpl::CreateStreamingEffect( TInt& aEffectHandle )
       
   648     {
       
   649     __ASSERT_DEBUG( iPacketizer, User::Panic( KPanic, EPanicNotReady ) );
       
   650     if ( !iPacketizer )
       
   651         {
       
   652         return EPanicNotReady;
       
   653         }
       
   654     API_TRACE( ( _L( "e_HWRMHAPTICS_CLIENT_CREATESTREAMING 1" ) ) );
       
   655     API_TRACE( ( _L( "CHWRMHapticsImpl::CreateStreamingEffect() - aEffectHandle(%d)" ), aEffectHandle ) );
       
   656 
       
   657     TInt err( KErrNone );
       
   658 
       
   659     iReqData.Close();
       
   660     err = iPacketizer->EncCreateStreamingEffectReq( iDeviceHandle, iReqData );
       
   661     
       
   662     if ( KErrNone == err )
       
   663         {
       
   664         TPckg<TInt> effectHandlePckg( aEffectHandle );
       
   665         err = iClient.ExecuteOperation( EHWRMHaptics, 
       
   666                                         TIpcArgs( &iReqData, 
       
   667                                                   &effectHandlePckg ) );
       
   668         }
       
   669         
       
   670     API_TRACE( ( _L( "CHWRMHapticsImpl::CreateStreamingEffect() - return %d" ), err ) );
       
   671     API_TRACE( ( _L( "e_HWRMHAPTICS_CLIENT_CREATESTREAMING 0" ) ) );
       
   672     
       
   673     return err;
       
   674     }
       
   675 
       
   676 // ---------------------------------------------------------------------------
       
   677 // Plays a streaming sample given the buffer defining the effect.
       
   678 // ---------------------------------------------------------------------------
       
   679 //
       
   680 TInt CHWRMHapticsImpl::PlayStreamingSample( TInt aEffectHandle, 
       
   681                                             const TDesC8& aStreamingSample )
       
   682     {
       
   683     __ASSERT_DEBUG( iPacketizer, User::Panic( KPanic, EPanicNotReady ) );
       
   684     if ( !iPacketizer )
       
   685         {
       
   686         return EPanicNotReady;
       
   687         }
       
   688     API_TRACE( ( _L( "e_HWRMHAPTICS_CLIENT_PLAYSTREAMINGSAMPLE_SYNC 1" ) ) );
       
   689     API_TRACE( ( _L( "CHWRMHapticsImpl::PlayStreamingSample() - SYNC - aEffectHandle(%d), aStreamingSample(0x%x)" ), aEffectHandle, &aStreamingSample ) );
       
   690 
       
   691     TInt err( KErrNone );
       
   692     if( aStreamingSample.Size() > MaxStreamingSampleSize() )
       
   693         {
       
   694         err = KErrArgument;
       
   695         }
       
   696     
       
   697     iReqData.Close();
       
   698     
       
   699     if ( KErrNone == err ) 
       
   700         {
       
   701         err = iPacketizer->EncPlayStreamingSampleReq( 
       
   702                 iDeviceHandle, aStreamingSample, aEffectHandle, iReqData );
       
   703         }
       
   704 
       
   705     if ( KErrNone == err ) 
       
   706         {
       
   707         err = iClient.ExecuteOperation( EHWRMHapticsPlayEffect, 
       
   708                                         TIpcArgs( &iReqData ) );
       
   709         }
       
   710     
       
   711     API_TRACE( ( _L( "CHWRMHapticsImpl::PlayStreamingSample() - SYNC - return %d" ), err ) );
       
   712     API_TRACE( ( _L( "e_HWRMHAPTICS_CLIENT_PLAYSTREAMINGSAMPLE_SYNC 0" ) ) );
       
   713     
       
   714     return err;
       
   715     }
       
   716 
       
   717 // ---------------------------------------------------------------------------
       
   718 // Plays a streaming sample given the buffer defining the effect. Async.
       
   719 // ---------------------------------------------------------------------------
       
   720 //
       
   721 void CHWRMHapticsImpl::PlayStreamingSample( TInt aEffectHandle, 
       
   722                                             const TDesC8& aStreamingSample, 
       
   723                                             TRequestStatus& aStatus )
       
   724     {
       
   725     __ASSERT_DEBUG( iPacketizer, User::Panic( KPanic, EPanicNotReady ) );
       
   726     if ( !iPacketizer )
       
   727         {
       
   728         TRequestStatus* tmp = &aStatus;
       
   729         User::RequestComplete( tmp, EPanicNotReady );
       
   730 
       
   731         return;
       
   732         }
       
   733 
       
   734     API_TRACE( ( _L( "e_HWRMHAPTICS_CLIENT_PLAYSTREAMINGSAMPLE_ASYNC 1" ) ) );
       
   735     API_TRACE( ( _L( "CHWRMHapticsImpl::PlayStreamingSample() - ASYNC -aEffectHandle(%d), aStreamingSample(0x%x), aStatus(%d)" ), aEffectHandle, &aStreamingSample, aStatus.Int() ) );
       
   736 
       
   737     if( aStreamingSample.Size() > MaxStreamingSampleSize() )
       
   738         {
       
   739         TRequestStatus* status = &aStatus;
       
   740         User::RequestComplete( status, KErrArgument );
       
   741         }
       
   742     else
       
   743         {
       
   744         iReqData.Close();
       
   745             
       
   746         if ( KErrNone == iPacketizer->EncPlayStreamingSampleReq( 
       
   747              iDeviceHandle, aStreamingSample, aEffectHandle, iReqData ) )
       
   748             {
       
   749             iClient.ExecuteAsyncOperation( EHWRMHapticsPlayEffect, 
       
   750                                            TIpcArgs( &iReqData ),
       
   751                                            aStatus );
       
   752             }
       
   753         }
       
   754     
       
   755     API_TRACE( ( _L( "CHWRMHapticsImpl::PlayStreamingSample() - ASYNC - return" ) ) );
       
   756     API_TRACE( ( _L( "e_HWRMHAPTICS_CLIENT_PLAYSTREAMINGSAMPLE_ASYNC 0" ) ) );
       
   757     }
       
   758 
       
   759 // ---------------------------------------------------------------------------
       
   760 // Plays a streaming sample with a time offset given the parameters.
       
   761 // ---------------------------------------------------------------------------
       
   762 //
       
   763 TInt CHWRMHapticsImpl::PlayStreamingSampleWithOffset( 
       
   764                                             TInt aEffectHandle, 
       
   765                                             const TDesC8& aStreamingSample,
       
   766                                             TInt aOffsetTime )
       
   767     {
       
   768     __ASSERT_DEBUG( iPacketizer, User::Panic( KPanic, EPanicNotReady ) );
       
   769     if ( !iPacketizer )
       
   770         {
       
   771         return EPanicNotReady;
       
   772         }
       
   773     API_TRACE( ( _L( "e_HWRMHAPTICS_CLIENT_PLAYSTREAMINGSAMPLEWITHOFFSET_SYNC 1" ) ) );
       
   774     API_TRACE( ( _L( "CHWRMHapticsImpl::PlayStreamingSampleWithOffset() - SYNC - aEffectHandle(%d), aStreamingSample(0x%x), aOffsetTime(%d)" ), aEffectHandle, &aStreamingSample, aOffsetTime ) );
       
   775 
       
   776     TInt err( KErrNone );
       
   777     if( aStreamingSample.Size() > MaxStreamingSampleSize() )
       
   778         {
       
   779         err = KErrArgument;
       
   780         }
       
   781     else 
       
   782         {
       
   783         iReqData.Close();
       
   784         err = iPacketizer->EncPlayStreamingSampleWithOffsetReq( 
       
   785                 iDeviceHandle, aStreamingSample, aOffsetTime, 
       
   786                 aEffectHandle, iReqData );
       
   787     
       
   788         if ( KErrNone == err )
       
   789             {
       
   790             err = iClient.ExecuteOperation( EHWRMHapticsPlayEffect, 
       
   791                                             TIpcArgs( &iReqData ) );
       
   792             }
       
   793         }
       
   794     
       
   795     API_TRACE( ( _L( "CHWRMHapticsImpl::PlayStreamingSampleWithOffset() - SYNC - return %d" ), err ) );
       
   796     API_TRACE( ( _L( "e_HWRMHAPTICS_CLIENT_PLAYSTREAMINGSAMPLEWITHOFFSET_SYNC 0" ) ) );
       
   797     
       
   798     return err;
       
   799     }
       
   800 
       
   801 // ---------------------------------------------------------------------------
       
   802 // Plays a streaming sample with a time offset given the parameters. Async.
       
   803 // ---------------------------------------------------------------------------
       
   804 //
       
   805 void CHWRMHapticsImpl::PlayStreamingSampleWithOffset( 
       
   806                                             TInt aEffectHandle, 
       
   807                                             const TDesC8& aStreamingSample,
       
   808                                             TInt aOffsetTime, 
       
   809                                             TRequestStatus& aStatus )
       
   810     {
       
   811     __ASSERT_DEBUG( iPacketizer, User::Panic( KPanic, EPanicNotReady ) );
       
   812     if ( !iPacketizer )
       
   813         {
       
   814         TRequestStatus* tmp = &aStatus;
       
   815         User::RequestComplete( tmp, EPanicNotReady );
       
   816 
       
   817         return;
       
   818         }
       
   819 
       
   820     API_TRACE( ( _L( "e_HWRMHAPTICS_CLIENT_PLAYSTREAMINGSAMPLEWITHOFFSET_ASYNC 1" ) ) );
       
   821     API_TRACE( ( _L( "CHWRMHapticsImpl::PlayStreamingSampleWithOffset() - ASYNC - aEffectHandle(%d), aStreamingSample(0x%x), aOffsetTime(%d), aStatus(%d)" ), aEffectHandle, &aStreamingSample, aOffsetTime, aStatus.Int() ) );
       
   822     
       
   823     if( aStreamingSample.Size() > MaxStreamingSampleSize() )
       
   824         {
       
   825         TRequestStatus* status = &aStatus;
       
   826         User::RequestComplete( status, KErrArgument );
       
   827         }
       
   828     else
       
   829         {
       
   830         iReqData.Close();
       
   831 
       
   832         if ( KErrNone == iPacketizer->EncPlayStreamingSampleWithOffsetReq( 
       
   833                             iDeviceHandle, aStreamingSample, aOffsetTime, 
       
   834                             aEffectHandle, iReqData ) )
       
   835             {
       
   836             iClient.ExecuteAsyncOperation( EHWRMHapticsPlayEffect, 
       
   837                                            TIpcArgs( &iReqData ),
       
   838                                            aStatus );
       
   839             }
       
   840         }
       
   841     
       
   842     API_TRACE( ( _L( "CHWRMHapticsImpl::PlayStreamingSampleWithOffset() - ASYNC - return" ) ) );
       
   843     API_TRACE( ( _L( "e_HWRMHAPTICS_CLIENT_PLAYSTREAMINGSAMPLEWITHOFFSET_ASYNC 0" ) ) );
       
   844     }
       
   845 
       
   846 // ---------------------------------------------------------------------------
       
   847 // Destroys the streaming effect so it is not recognized by the API.
       
   848 // ---------------------------------------------------------------------------
       
   849 //
       
   850 TInt CHWRMHapticsImpl::DestroyStreamingEffect( TInt aEffectHandle )
       
   851     {
       
   852     __ASSERT_DEBUG( iPacketizer, User::Panic( KPanic, EPanicNotReady ) );
       
   853     if ( !iPacketizer )
       
   854         {
       
   855         return EPanicNotReady;
       
   856         }
       
   857     API_TRACE( ( _L( "e_HWRMHAPTICS_CLIENT_DESTROYSTREAMING 1" ) ) );
       
   858     API_TRACE( ( _L( "CHWRMHapticsImpl::DestroyStreamingEffect() - aEffectHandle(%d)" ), aEffectHandle ) );
       
   859 
       
   860     TInt err( KErrNone );
       
   861     iReqData.Close(); 
       
   862     err = iPacketizer->EncDestroyStreamingEffectReq( 
       
   863                 iDeviceHandle, aEffectHandle, iReqData );
       
   864     
       
   865     if ( KErrNone == err )
       
   866         {
       
   867         err = iClient.ExecuteOperation( EHWRMHaptics,
       
   868                                         TIpcArgs( &iReqData ) );
       
   869         }
       
   870     
       
   871     API_TRACE( ( _L( "CHWRMHapticsImpl::DestroyStreamingEffect() - return %d" ), err ) );
       
   872     API_TRACE( ( _L( "e_HWRMHAPTICS_CLIENT_DESTROYSTREAMING 0" ) ) );
       
   873     
       
   874     return err;
       
   875     }
       
   876 
       
   877 // ---------------------------------------------------------------------------
       
   878 // Modifies playing MagSweep type effect. Sync version.
       
   879 // ---------------------------------------------------------------------------
       
   880 //
       
   881 TInt CHWRMHapticsImpl::ModifyPlayingMagSweepEffect( 
       
   882         TInt aEffectHandle, 
       
   883         const THWRMHapticsMagSweepEffect& aEffect )
       
   884     {
       
   885     __ASSERT_DEBUG( iPacketizer, User::Panic( KPanic, EPanicNotReady ) );
       
   886     if ( !iPacketizer )
       
   887         {
       
   888         return EPanicNotReady;
       
   889         }
       
   890     API_TRACE( ( _L( "e_HWRMHAPTICS_CLIENT_MODIFYMAGSWEEP_SYNC 1" ) ) );
       
   891     API_TRACE( ( _L( "CHWRMHapticsImpl::ModifyPlayingMagSweepEffect() - SYNC - aEffectHandle(%d)" ), aEffectHandle ) );
       
   892 
       
   893     iReqData.Close();
       
   894     TInt err = iPacketizer->EncModifyPlayingMagSweepEffectReq( 
       
   895                 iDeviceHandle, aEffectHandle, aEffect, iReqData );
       
   896     
       
   897     if ( KErrNone == err )
       
   898         {
       
   899         err = iClient.ExecuteOperation( EHWRMHaptics,
       
   900                                         TIpcArgs( &iReqData ) );
       
   901         }
       
   902     
       
   903     API_TRACE( ( _L( "CHWRMHapticsImpl::ModifyPlayingMagSweepEffect() - SYNC - return %d" ), err ) );
       
   904     API_TRACE( ( _L( "e_HWRMHAPTICS_CLIENT_MODIFYMAGSWEEP_SYNC 0" ) ) );
       
   905     
       
   906     return err;
       
   907     }
       
   908 
       
   909 // ---------------------------------------------------------------------------
       
   910 // Modifies playing MagSweep type effect. Async version.
       
   911 // ---------------------------------------------------------------------------
       
   912 //
       
   913 void CHWRMHapticsImpl::ModifyPlayingMagSweepEffect( 
       
   914         TInt aEffectHandle, 
       
   915         const THWRMHapticsMagSweepEffect& aEffect, 
       
   916         TRequestStatus& aStatus )
       
   917     {
       
   918     __ASSERT_DEBUG( iPacketizer, User::Panic( KPanic, EPanicNotReady ) );
       
   919     if ( !iPacketizer )
       
   920         {
       
   921         TRequestStatus* tmp = &aStatus;
       
   922         User::RequestComplete( tmp, EPanicNotReady );
       
   923 
       
   924         return;
       
   925         }
       
   926 
       
   927     API_TRACE( ( _L( "e_HWRMHAPTICS_CLIENT_MODIFYMAGSWEEP_ASYNC 1" ) ) );
       
   928     API_TRACE( ( _L( "CHWRMHapticsImpl::ModifyPlayingMagSweepEffect() - ASYNC - aEffectHandle(%d), aStatus(%d)" ), aEffectHandle, aStatus.Int() ) );
       
   929    
       
   930     iReqData.Close();
       
   931     TInt err = iPacketizer->EncModifyPlayingMagSweepEffectReq( 
       
   932                 iDeviceHandle, aEffectHandle, aEffect, iReqData );
       
   933 
       
   934     if ( KErrNone == err )
       
   935         {
       
   936         iClient.ExecuteAsyncOperation( EHWRMHaptics,
       
   937                                        TIpcArgs( &iReqData ),
       
   938                                        aStatus );
       
   939         }
       
   940     
       
   941     API_TRACE( ( _L( "CHWRMHapticsImpl::ModifyPlayingMagSweepEffect() - ASYNC - return" ) ) );
       
   942     API_TRACE( ( _L( "e_HWRMHAPTICS_CLIENT_MODIFYMAGSWEEP_ASYNC 0" ) ) );
       
   943     }
       
   944 
       
   945 // ---------------------------------------------------------------------------
       
   946 // Modifies playing Periodic type effect. Sync version.
       
   947 // ---------------------------------------------------------------------------
       
   948 //
       
   949 TInt CHWRMHapticsImpl::ModifyPlayingPeriodicEffect( 
       
   950         TInt aEffectHandle, 
       
   951         const THWRMHapticsPeriodicEffect& aEffect )
       
   952     {
       
   953     __ASSERT_DEBUG( iPacketizer, User::Panic( KPanic, EPanicNotReady ) );
       
   954     if ( !iPacketizer )
       
   955         {
       
   956         return EPanicNotReady;
       
   957         }
       
   958     API_TRACE( ( _L( "e_HWRMHAPTICS_CLIENT_MODIFYPERIODIC_SYNC 1" ) ) );
       
   959     API_TRACE( ( _L( "CHWRMHapticsImpl::ModifyPlayingPeriodicEffect() - SYNC - aEffectHandle(%d)" ), aEffectHandle ) );
       
   960 
       
   961     iReqData.Close();
       
   962     TInt err = iPacketizer->EncModifyPlayingPeriodicEffectReq(
       
   963                 iDeviceHandle, aEffectHandle, aEffect, iReqData );
       
   964 
       
   965     if ( KErrNone == err )
       
   966         {
       
   967         err = iClient.ExecuteOperation( EHWRMHaptics,
       
   968                                         TIpcArgs( &iReqData ) );
       
   969         }
       
   970 
       
   971     API_TRACE( ( _L( "CHWRMHapticsImpl::ModifyPlayingPeriodicEffect() - SYNC - return %d" ), err ) );
       
   972     API_TRACE( ( _L( "e_HWRMHAPTICS_CLIENT_MODIFYPERIODIC_SYNC 0" ) ) );
       
   973 
       
   974     return err;
       
   975     }
       
   976  
       
   977 // ---------------------------------------------------------------------------
       
   978 // Modifies playing Periodic type effect. Async version.
       
   979 // ---------------------------------------------------------------------------
       
   980 //
       
   981 void CHWRMHapticsImpl::ModifyPlayingPeriodicEffect( 
       
   982         TInt aEffectHandle, 
       
   983         const THWRMHapticsPeriodicEffect& aEffect, 
       
   984         TRequestStatus& aStatus )
       
   985     {
       
   986     __ASSERT_DEBUG( iPacketizer, User::Panic( KPanic, EPanicNotReady ) );
       
   987     if ( !iPacketizer )
       
   988         {
       
   989         TRequestStatus* tmp = &aStatus;
       
   990         User::RequestComplete( tmp, EPanicNotReady );
       
   991 
       
   992         return;
       
   993         }
       
   994 
       
   995     API_TRACE( ( _L( "e_HWRMHAPTICS_CLIENT_MODIFYPERIODIC_ASYNC 1" ) ) );
       
   996     API_TRACE( ( _L( "CHWRMHapticsImpl::ModifyPlayingPeriodicEffect() - ASYNC - aEffectHandle(%d), aStatus(%d)" ), aEffectHandle, aStatus.Int() ) );
       
   997     
       
   998     iReqData.Close();
       
   999     TInt err = iPacketizer->EncModifyPlayingPeriodicEffectReq( 
       
  1000                 iDeviceHandle, aEffectHandle, aEffect, iReqData );
       
  1001     
       
  1002     if ( KErrNone == err )
       
  1003         {
       
  1004         iClient.ExecuteAsyncOperation( EHWRMHaptics, 
       
  1005                                        TIpcArgs( &iReqData ),
       
  1006                                        aStatus );
       
  1007         }
       
  1008     
       
  1009     API_TRACE( ( _L( "CHWRMHapticsImpl::ModifyPlayingPeriodicEffect() - ASYNC - return" ) ) );
       
  1010     API_TRACE( ( _L( "e_HWRMHAPTICS_CLIENT_MODIFYPERIODIC_ASYNC 0" ) ) );
       
  1011     }
       
  1012  
       
  1013 // ---------------------------------------------------------------------------
       
  1014 // Loads the given data buffer to be used for playing effects. Returns 
       
  1015 // a filehandle, which can be used to reference to that data. If the data has
       
  1016 // already been loaded before, the data is already located in the cache, and
       
  1017 // it is not loaded again. The filehandle of the data is returned in any
       
  1018 // successful case.
       
  1019 // ---------------------------------------------------------------------------
       
  1020 //
       
  1021 TInt CHWRMHapticsImpl::LoadEffectData( const TDesC8& aData, TInt& aFileHandle )
       
  1022     {
       
  1023     API_TRACE( ( _L( "CHWRMHapticsImpl::LoadEffectData()" ) ) );
       
  1024 
       
  1025     TInt err = KErrNone;
       
  1026     aFileHandle = iIVTDataCache->ClientFileHandle( aData );
       
  1027     if ( aFileHandle <= 0 )
       
  1028         {
       
  1029         // store effect data to cache
       
  1030         err = iIVTDataCache->AddCacheItem( aData, aFileHandle );
       
  1031         }
       
  1032 
       
  1033     API_TRACE( ( _L( "CHWRMHapticsImpl::LoadEffectData() - return %d" ), err ) );
       
  1034 
       
  1035     return err;
       
  1036     }
       
  1037 
       
  1038 // ---------------------------------------------------------------------------
       
  1039 // Delete effect data from internal data cache referenced by file handle.
       
  1040 // ---------------------------------------------------------------------------
       
  1041 //
       
  1042 TInt CHWRMHapticsImpl::DeleteEffectData( TInt aFileHandle )
       
  1043     {
       
  1044     API_TRACE( ( _L( "CHWRMHapticsImpl::DeleteEffectData()" ) ) );
       
  1045     
       
  1046     TInt err = iIVTDataCache->RemoveCacheItem( aFileHandle );
       
  1047     
       
  1048     API_TRACE( ( _L( "CHWRMHapticsImpl::DeleteEffectData() - return %d" ), err ) );
       
  1049 
       
  1050     return err;
       
  1051     }
       
  1052 
       
  1053 // ---------------------------------------------------------------------------
       
  1054 // Delete all effect datas from internal data cache.
       
  1055 // ---------------------------------------------------------------------------
       
  1056 //
       
  1057 TInt CHWRMHapticsImpl::DeleteAllEffectData()
       
  1058     {
       
  1059     API_TRACE( ( _L( "CHWRMHapticsImpl::DeleteAllEffectData()" ) ) );
       
  1060     
       
  1061     iIVTDataCache->Reset();
       
  1062     
       
  1063     API_TRACE( ( _L( "CHWRMHapticsImpl::DeleteAllEffectData() - return" ) ) );
       
  1064 
       
  1065     return KErrNone;
       
  1066     }
       
  1067  
       
  1068 // ---------------------------------------------------------------------------
       
  1069 // Plays an effect defined in loaded effect data buffer.
       
  1070 // ---------------------------------------------------------------------------
       
  1071 //
       
  1072 TInt CHWRMHapticsImpl::PlayEffect( TInt aFileHandle, TInt aEffectIndex, 
       
  1073                                    TInt& aEffectHandle )
       
  1074     {
       
  1075     __ASSERT_DEBUG( iPacketizer, User::Panic( KPanic, EPanicNotReady ) );
       
  1076     if ( !iPacketizer )
       
  1077         {
       
  1078         return EPanicNotReady;
       
  1079         }
       
  1080     API_TRACE( ( _L( "e_HWRMHAPTICS_CLIENT_PLAYEFFECT_HANDLE_SYNC 1" ) ) );
       
  1081     API_TRACE( ( _L( "CHWRMHapticsImpl::PlayEffect() - SYNC - NO_IVT_DATA - aEffectIndex(%d), aEffectHandle(%d)" ), aEffectIndex, aEffectHandle ) );
       
  1082 
       
  1083     TInt err( KErrNone );
       
  1084     TBool alreadyLoaded( iIVTDataCache->IsLoaded( aFileHandle ) );
       
  1085     iReqData.Close();
       
  1086 
       
  1087     // load data, if not currently loaded
       
  1088     if( alreadyLoaded )
       
  1089         {
       
  1090         err = iPacketizer->EncPlayEffectNoDataReq( iDeviceHandle,
       
  1091                                                    aEffectIndex, 
       
  1092                                                    iReqData );
       
  1093         }
       
  1094     else
       
  1095         {
       
  1096         const HBufC8* cachedIVTData = iIVTDataCache->IVTData( aFileHandle );
       
  1097         if ( cachedIVTData )
       
  1098             {
       
  1099             err = iPacketizer->EncPlayEffectIncludeEffectDataReq(
       
  1100                     iDeviceHandle, *cachedIVTData, aEffectIndex, iReqData );
       
  1101             }
       
  1102          else
       
  1103             {
       
  1104             err = KErrBadHandle;
       
  1105             }
       
  1106         }
       
  1107 
       
  1108     if ( KErrNone == err )
       
  1109         {
       
  1110         TPckg<TInt> effectHandlePckg( aEffectHandle );
       
  1111         err = iClient.ExecuteOperation( EHWRMHapticsPlayEffect, 
       
  1112                                         TIpcArgs( &iReqData,
       
  1113                                                   &effectHandlePckg ) );
       
  1114         }
       
  1115 
       
  1116     if ( KErrNone == err && !alreadyLoaded )
       
  1117         {
       
  1118         // loaded new data to player
       
  1119         iIVTDataCache->UpdateCacheItem( aFileHandle, ETrue );
       
  1120         }
       
  1121 
       
  1122     API_TRACE( ( _L( "CHWRMHapticsImpl::PlayEffect() - SYNC - NO_IVT_DATA - return %d" ), err ) );
       
  1123     API_TRACE( ( _L( "e_HWRMHAPTICS_CLIENT_PLAYEFFECT_HANDLE_SYNC 0" ) ) );
       
  1124     
       
  1125     return err;
       
  1126     }
       
  1127  
       
  1128 // ---------------------------------------------------------------------------
       
  1129 // Plays an effect defined in loaded data data buffer. Async.
       
  1130 // ---------------------------------------------------------------------------
       
  1131 //
       
  1132 void CHWRMHapticsImpl::PlayEffect( TInt aFileHandle, TInt aEffectIndex, 
       
  1133                                    TInt& aEffectHandle, 
       
  1134                                    TRequestStatus& aStatus )
       
  1135     {
       
  1136     __ASSERT_DEBUG( iPacketizer, User::Panic( KPanic, EPanicNotReady ) );
       
  1137     if ( !iPacketizer )
       
  1138         {
       
  1139         TRequestStatus* tmp = &aStatus;
       
  1140         User::RequestComplete( tmp, EPanicNotReady );
       
  1141 
       
  1142         return;
       
  1143         }
       
  1144 
       
  1145     API_TRACE( ( _L( "e_HWRMHAPTICS_CLIENT_PLAYEFFECT_HANDLE_ASYNC 1" ) ) );
       
  1146     API_TRACE( ( _L( "CHWRMHapticsImpl::PlayEffect() - ASYNC - NO_IVT_DATA - aEffectIndex(%d), aEffectHandle(%d), aStatus(%d)" ), aEffectIndex, aEffectHandle, aStatus.Int() ) );
       
  1147 
       
  1148     TInt err( KErrNone );
       
  1149     TBool alreadyLoaded( iIVTDataCache->IsLoaded( aFileHandle ) );
       
  1150     iReqData.Close();
       
  1151     
       
  1152     // load data, if not currently loaded
       
  1153     if( alreadyLoaded )
       
  1154         {
       
  1155         err = iPacketizer->EncPlayEffectNoDataReq( iDeviceHandle,
       
  1156                                                    aEffectIndex, 
       
  1157                                                    iReqData );
       
  1158         }
       
  1159     else
       
  1160         {
       
  1161         const HBufC8* cachedIVTData = iIVTDataCache->IVTData( aFileHandle );
       
  1162         if ( cachedIVTData )
       
  1163             {
       
  1164             err = iPacketizer->EncPlayEffectIncludeEffectDataReq(
       
  1165                     iDeviceHandle,*cachedIVTData, aEffectIndex, iReqData );
       
  1166             }
       
  1167          else
       
  1168             {
       
  1169             err = KErrBadHandle;
       
  1170             }
       
  1171         }
       
  1172         
       
  1173     if ( KErrNone == err )
       
  1174         {
       
  1175         // reset effect handle package
       
  1176         ResetIntPckg( aEffectHandle );
       
  1177         TIpcArgs ipcArgs( &iReqData, &iEffectHandlePckg );
       
  1178         
       
  1179         if ( alreadyLoaded ||
       
  1180              !iIVTDataCache->UpdateCacheItemListener( 
       
  1181                 aFileHandle, aStatus, &iClient, ipcArgs ) )
       
  1182             {
       
  1183             // make async call with the client's status
       
  1184             iClient.ExecuteAsyncOperation( EHWRMHapticsPlayEffect,
       
  1185                                            ipcArgs,
       
  1186                                            aStatus );
       
  1187             }
       
  1188         }
       
  1189         
       
  1190     // complete request, if error occured
       
  1191     if ( err )
       
  1192         {
       
  1193         TRequestStatus* tmp = &aStatus;
       
  1194         User::RequestComplete( tmp, err );
       
  1195         }
       
  1196 
       
  1197     API_TRACE( ( _L( "CHWRMHapticsImpl::PlayEffect() - ASYNC - NO_IVT_DATA - return" ) ) );
       
  1198     API_TRACE( ( _L( "e_HWRMHAPTICS_CLIENT_PLAYEFFECT_HANDLE_ASYNC 0" ) ) );
       
  1199     }
       
  1200  
       
  1201 // ---------------------------------------------------------------------------
       
  1202 // Repeatedly plays a Timeline effect defined in loaded effect data buffer.
       
  1203 // ---------------------------------------------------------------------------
       
  1204 //
       
  1205 TInt CHWRMHapticsImpl::PlayEffectRepeat( TInt aFileHandle, 
       
  1206                                          TInt aEffectIndex, 
       
  1207                                          TUint8 aRepeat, 
       
  1208                                          TInt& aEffectHandle )
       
  1209     {
       
  1210     __ASSERT_DEBUG( iPacketizer, User::Panic( KPanic, EPanicNotReady ) );
       
  1211     if ( !iPacketizer )
       
  1212         {
       
  1213         return EPanicNotReady;
       
  1214         }
       
  1215     API_TRACE( ( _L( "e_HWRMHAPTICS_CLIENT_PLAYEFFECTREPEAT_HANDLE_SYNC 1" ) ) );
       
  1216     API_TRACE( ( _L( "CHWRMHapticsImpl::PlayEffectRepeat() - SYNC - NO_IVT_DATA - aEffectIndex(%d), aRepeat(%d), aEffectHandle(%d)" ), aEffectIndex, aRepeat, aEffectHandle ) );
       
  1217 
       
  1218     TInt err( KErrNone );
       
  1219     TBool alreadyLoaded( iIVTDataCache->IsLoaded( aFileHandle ) );
       
  1220     iReqData.Close();
       
  1221     
       
  1222     // load data, if not currently loaded
       
  1223     if( alreadyLoaded )
       
  1224         {
       
  1225         err = iPacketizer->EncPlayEffectRepeatNoDataReq( iDeviceHandle,
       
  1226                                                          aEffectIndex,
       
  1227                                                          aRepeat, 
       
  1228                                                          iReqData );
       
  1229         }
       
  1230     else
       
  1231         {
       
  1232         const HBufC8* cachedIVTData = iIVTDataCache->IVTData( aFileHandle );
       
  1233         if ( cachedIVTData )
       
  1234             {
       
  1235             err = iPacketizer->EncPlayEffectRepeatIncludeEffectDataReq( 
       
  1236              iDeviceHandle, *cachedIVTData, aEffectIndex, aRepeat, iReqData );
       
  1237             }
       
  1238          else
       
  1239             {
       
  1240             err = KErrBadHandle;
       
  1241             }
       
  1242         }
       
  1243 
       
  1244     if ( KErrNone == err )
       
  1245         {
       
  1246         TPckg<TInt> effectHandlePckg( aEffectHandle );
       
  1247         err = iClient.ExecuteOperation( EHWRMHapticsPlayEffect,
       
  1248                                         TIpcArgs( &iReqData,
       
  1249                                                   &effectHandlePckg ) );
       
  1250         }
       
  1251      
       
  1252     if ( KErrNone == err && !alreadyLoaded )
       
  1253         {
       
  1254         // loaded new data to player
       
  1255         iIVTDataCache->UpdateCacheItem( aFileHandle, ETrue );
       
  1256         }
       
  1257             
       
  1258     API_TRACE( ( _L( "CHWRMHapticsImpl::PlayEffectRepeat() - SYNC - NO_IVT_DATA - return %d" ), err ) );
       
  1259     API_TRACE( ( _L( "e_HWRMHAPTICS_CLIENT_PLAYEFFECTREPEAT_HANDLE_SYNC 0" ) ) );
       
  1260     
       
  1261     return err;
       
  1262     }
       
  1263  
       
  1264 // ---------------------------------------------------------------------------
       
  1265 // Repeatedly plays a Timeline effect defined in loaded effect data buffer.
       
  1266 // Async.
       
  1267 // ---------------------------------------------------------------------------
       
  1268 //
       
  1269 void CHWRMHapticsImpl::PlayEffectRepeat( TInt aFileHandle, 
       
  1270                                          TInt aEffectIndex, 
       
  1271                                          TUint8 aRepeat, 
       
  1272                                          TInt& aEffectHandle, 
       
  1273                                          TRequestStatus& aStatus )
       
  1274     {
       
  1275     __ASSERT_DEBUG( iPacketizer, User::Panic( KPanic, EPanicNotReady ) );
       
  1276     if ( !iPacketizer )
       
  1277         {
       
  1278         TRequestStatus* tmp = &aStatus;
       
  1279         User::RequestComplete( tmp, EPanicNotReady );
       
  1280 
       
  1281         return;
       
  1282         }
       
  1283 
       
  1284     API_TRACE( ( _L( "e_HWRMHAPTICS_CLIENT_PLAYEFFECTREPEAT_HANDLE_ASYNC 1" ) ) );
       
  1285     API_TRACE( ( _L( "CHWRMHapticsImpl::PlayEffectRepeat() - ASYNC - NO_IVT_DATA - aEffectIndex(%d), aRepeat(%d), aEffectHandle(%d), aStatus(%d)" ), aEffectIndex, aRepeat, aEffectHandle, aStatus.Int() ) );
       
  1286 
       
  1287     TInt err( KErrNone );
       
  1288     TBool alreadyLoaded( iIVTDataCache->IsLoaded( aFileHandle ) );
       
  1289     iReqData.Close();
       
  1290 
       
  1291     // load data, if not currently loaded
       
  1292     if( alreadyLoaded )        
       
  1293         {
       
  1294         err = iPacketizer->EncPlayEffectRepeatNoDataReq( iDeviceHandle,
       
  1295                                                          aEffectIndex,
       
  1296                                                          aRepeat,
       
  1297                                                          iReqData );
       
  1298         }
       
  1299     else
       
  1300         {
       
  1301         const HBufC8* cachedIVTData = iIVTDataCache->IVTData( aFileHandle );
       
  1302         if ( cachedIVTData )
       
  1303             {
       
  1304             err = iPacketizer->EncPlayEffectRepeatIncludeEffectDataReq(
       
  1305              iDeviceHandle, *cachedIVTData, aEffectIndex, aRepeat, iReqData );
       
  1306             }
       
  1307         else
       
  1308             {
       
  1309             err = KErrBadHandle;
       
  1310             }
       
  1311         }    
       
  1312 
       
  1313     if ( KErrNone == err )
       
  1314         {
       
  1315         // reset effect handle package
       
  1316         ResetIntPckg( aEffectHandle );
       
  1317         TIpcArgs ipcArgs( &iReqData, &iEffectHandlePckg );
       
  1318         
       
  1319         if ( alreadyLoaded ||
       
  1320              !iIVTDataCache->UpdateCacheItemListener( 
       
  1321                 aFileHandle, aStatus, &iClient, ipcArgs ) )
       
  1322             {
       
  1323             // make async call if packages were created successfully
       
  1324             iClient.ExecuteAsyncOperation( EHWRMHapticsPlayEffect,
       
  1325                                            ipcArgs,
       
  1326                                            aStatus );
       
  1327             }
       
  1328         }
       
  1329 
       
  1330     if ( err )
       
  1331         {
       
  1332         TRequestStatus* tmp = &aStatus;
       
  1333         User::RequestComplete( tmp, err );
       
  1334         }
       
  1335         
       
  1336     API_TRACE( ( _L( "CHWRMHapticsImpl::PlayEffectRepeat() - ASYNC - NO_IVT_DATA - return" ) ) );
       
  1337     API_TRACE( ( _L( "e_HWRMHAPTICS_CLIENT_PLAYEFFECTREPEAT_HANDLE_ASYNC 0" ) ) );
       
  1338     }
       
  1339 
       
  1340 // ---------------------------------------------------------------------------
       
  1341 // Plays an effect defined in effect data buffer.
       
  1342 // ---------------------------------------------------------------------------
       
  1343 //
       
  1344 TInt CHWRMHapticsImpl::PlayEffect( const TDesC8& aData, 
       
  1345                                    TInt aEffectIndex, 
       
  1346                                    TInt& aEffectHandle )
       
  1347     {
       
  1348     __ASSERT_DEBUG( iPacketizer, User::Panic( KPanic, EPanicNotReady ) );
       
  1349     if ( !iPacketizer )
       
  1350         {
       
  1351         return EPanicNotReady;
       
  1352         }
       
  1353     API_TRACE( ( _L( "e_HWRMHAPTICS_CLIENT_PLAYEFFECT_DATA_SYNC 1" ) ) );
       
  1354     API_TRACE( ( _L( "CHWRMHapticsImpl::PlayEffect() - SYNC - aData(0x%x), aEffectIndex(%d), aEffectHandle(%d)" ), &aData, aEffectIndex, aEffectHandle ) );
       
  1355 
       
  1356     iReqData.Close();
       
  1357     TInt err = iPacketizer->EncPlayEffectIncludeEffectDataReq(
       
  1358                     iDeviceHandle, aData, aEffectIndex, iReqData );
       
  1359     
       
  1360     if ( KErrNone == err )
       
  1361         {
       
  1362         TPckg<TInt> effectHandlePckg( aEffectHandle );
       
  1363         err = iClient.ExecuteOperation( EHWRMHapticsPlayEffect,
       
  1364                                         TIpcArgs( &iReqData, 
       
  1365                                                   &effectHandlePckg ) );
       
  1366         }
       
  1367     
       
  1368     API_TRACE( ( _L( "CHWRMHapticsImpl::PlayEffect() - SYNC - return %d" ), err ) );
       
  1369     API_TRACE( ( _L( "e_HWRMHAPTICS_CLIENT_PLAYEFFECT_DATA_SYNC 0" ) ) );
       
  1370     
       
  1371     return err;
       
  1372     }
       
  1373  
       
  1374 // ---------------------------------------------------------------------------
       
  1375 // Plays an effect defined in effect data buffer. Async.
       
  1376 // ---------------------------------------------------------------------------
       
  1377 //
       
  1378 void CHWRMHapticsImpl::PlayEffect( const TDesC8& aData, 
       
  1379                                    TInt aEffectIndex, 
       
  1380                                    TInt& aEffectHandle, 
       
  1381                                    TRequestStatus& aStatus )
       
  1382     {
       
  1383     __ASSERT_DEBUG( iPacketizer, User::Panic( KPanic, EPanicNotReady ) );
       
  1384     if ( !iPacketizer )
       
  1385         {
       
  1386         TRequestStatus* tmp = &aStatus;
       
  1387         User::RequestComplete( tmp, EPanicNotReady );
       
  1388 
       
  1389         return;
       
  1390         }
       
  1391 
       
  1392     API_TRACE( ( _L( "e_HWRMHAPTICS_CLIENT_PLAYEFFECT_DATA_ASYNC 1" ) ) );
       
  1393     API_TRACE( ( _L( "CHWRMHapticsImpl::PlayIVTEffect() - ASYNC - aData(0x%x), aEffectIndex(%d), aEffectHandle(%d), aStatus(%d)" ), &aData, aEffectIndex, aEffectHandle, aStatus.Int() ) );
       
  1394     
       
  1395     iReqData.Close();
       
  1396     TInt err = iPacketizer->EncPlayEffectIncludeEffectDataReq( 
       
  1397                     iDeviceHandle, aData, aEffectIndex, iReqData );
       
  1398     
       
  1399     if ( KErrNone == err )
       
  1400         {
       
  1401         // reset effect handle package
       
  1402         ResetIntPckg( aEffectHandle );
       
  1403         
       
  1404         // make async call if packages were created successfully
       
  1405         iClient.ExecuteAsyncOperation( EHWRMHapticsPlayEffect,
       
  1406                                        TIpcArgs( &iReqData,
       
  1407                                                  &iEffectHandlePckg ),
       
  1408                                        aStatus );
       
  1409         }
       
  1410     
       
  1411     API_TRACE( ( _L( "CHWRMHapticsImpl::PlayEffect() - ASYNC - return" ) ) );
       
  1412     API_TRACE( ( _L( "e_HWRMHAPTICS_CLIENT_PLAYEFFECT_DATA_ASYNC 0" ) ) );
       
  1413     }
       
  1414  
       
  1415 // ---------------------------------------------------------------------------
       
  1416 // Repeatedly plays a Timeline effect defined in effect data buffer.
       
  1417 // ---------------------------------------------------------------------------
       
  1418 //
       
  1419 TInt CHWRMHapticsImpl::PlayEffectRepeat( const TDesC8& aData, 
       
  1420                                          TInt aEffectIndex, 
       
  1421                                          TUint8 aRepeat, 
       
  1422                                          TInt& aEffectHandle )
       
  1423     {
       
  1424     __ASSERT_DEBUG( iPacketizer, User::Panic( KPanic, EPanicNotReady ) );
       
  1425     if ( !iPacketizer )
       
  1426         {
       
  1427         return EPanicNotReady;
       
  1428         }
       
  1429     API_TRACE( ( _L( "e_HWRMHAPTICS_CLIENT_PLAYEFFECTREPEAT_DATA_SYNC 1" ) ) );
       
  1430     API_TRACE( ( _L( "CHWRMHapticsImpl::PlayEffectRepeat() - SYNC - aData(0x%x), aEffectIndex(%d), aRepeat(%d), aEffectHandle(%d)" ), &aData, aEffectIndex, aRepeat, aEffectHandle ) );
       
  1431 
       
  1432     iReqData.Close();
       
  1433     TInt err = iPacketizer->EncPlayEffectRepeatIncludeEffectDataReq( 
       
  1434                 iDeviceHandle, aData, aEffectIndex, aRepeat, iReqData );
       
  1435     
       
  1436     if ( KErrNone == err )
       
  1437         {
       
  1438         TPckg<TInt> effectHandlePckg( aEffectHandle );
       
  1439         err = iClient.ExecuteOperation( EHWRMHapticsPlayEffect,
       
  1440                                         TIpcArgs( &iReqData, 
       
  1441                                                   &effectHandlePckg ) );
       
  1442         }
       
  1443     
       
  1444     API_TRACE( ( _L( "CHWRMHapticsImpl::PlayEffectRepeat() - SYNC - return %d" ), err ) );
       
  1445     API_TRACE( ( _L( "e_HWRMHAPTICS_CLIENT_PLAYEFFECTREPEAT_DATA_SYNC 0" ) ) );
       
  1446     
       
  1447     return err;
       
  1448     }
       
  1449  
       
  1450 // ---------------------------------------------------------------------------
       
  1451 // Repeatedly plays a Timeline effect defined in effect data buffer. Async.
       
  1452 // ---------------------------------------------------------------------------
       
  1453 //
       
  1454 void CHWRMHapticsImpl::PlayEffectRepeat( const TDesC8& aData, 
       
  1455                                          TInt aEffectIndex, 
       
  1456                                          TUint8 aRepeat, 
       
  1457                                          TInt& aEffectHandle, 
       
  1458                                          TRequestStatus& aStatus )
       
  1459     {
       
  1460     __ASSERT_DEBUG( iPacketizer, User::Panic( KPanic, EPanicNotReady ) );
       
  1461     if ( !iPacketizer )
       
  1462         {
       
  1463         TRequestStatus* tmp = &aStatus;
       
  1464         User::RequestComplete( tmp, EPanicNotReady );
       
  1465 
       
  1466         return;
       
  1467         }
       
  1468 
       
  1469     API_TRACE( ( _L( "e_HWRMHAPTICS_CLIENT_PLAYEFFECTREPEAT_DATA_ASYNC 1" ) ) );
       
  1470     API_TRACE( ( _L( "CHWRMHapticsImpl::PlayEffectRepeat() - ASYNC - aData(0x%x), aEffectIndex(%d), aRepeat(%d), aEffectHandle(%d), aStatus(%d)" ), &aData, aEffectIndex, aRepeat, aEffectHandle, aStatus.Int() ) );
       
  1471 
       
  1472     iReqData.Close();
       
  1473     TInt err = iPacketizer->EncPlayEffectRepeatIncludeEffectDataReq(
       
  1474                 iDeviceHandle, aData, aEffectIndex, aRepeat, iReqData );
       
  1475         
       
  1476     if ( KErrNone == err )
       
  1477         {
       
  1478         // reset effect handle package
       
  1479         ResetIntPckg( aEffectHandle );
       
  1480         
       
  1481         // make async call if packages were created successfully
       
  1482         iClient.ExecuteAsyncOperation( EHWRMHapticsPlayEffect,
       
  1483                                        TIpcArgs( &iReqData,
       
  1484                                                  &iEffectHandlePckg ),
       
  1485                                        aStatus );
       
  1486         }
       
  1487 
       
  1488     API_TRACE( ( _L( "CHWRMHapticsImpl::PlayEffectRepeat() - ASYNC - return" ) ) );
       
  1489     API_TRACE( ( _L( "e_HWRMHAPTICS_CLIENT_PLAYEFFECTREPEAT_DATA_ASYNC 0" ) ) );
       
  1490     }
       
  1491  
       
  1492 // ---------------------------------------------------------------------------
       
  1493 // Plays a MagSweep effect given the parameters defining the effect.
       
  1494 // ---------------------------------------------------------------------------
       
  1495 //
       
  1496 TInt CHWRMHapticsImpl::PlayMagSweepEffect( 
       
  1497         const THWRMHapticsMagSweepEffect& aEffect, 
       
  1498         TInt& aEffectHandle )
       
  1499     {
       
  1500     __ASSERT_DEBUG( iPacketizer, User::Panic( KPanic, EPanicNotReady ) );
       
  1501     if ( !iPacketizer )
       
  1502         {
       
  1503         return EPanicNotReady;
       
  1504         }
       
  1505     API_TRACE( ( _L( "e_HWRMHAPTICS_CLIENT_PLAYMAGSWEEP_SYNC 1" ) ) );
       
  1506     API_TRACE( ( _L( "CHWRMHapticsImpl::PlayMagSweepEffect() - SYNC - aEffectHandle(%d)" ), aEffectHandle ) );
       
  1507     
       
  1508     iReqData.Close();
       
  1509     TInt err = iPacketizer->EncPlayMagSweepEffectReq( 
       
  1510                     iDeviceHandle, aEffect, iReqData );
       
  1511  
       
  1512     if ( KErrNone == err )
       
  1513         {
       
  1514         TPckg<TInt> effectHandlePckg( aEffectHandle );
       
  1515         err = iClient.ExecuteOperation( EHWRMHapticsPlayEffect, 
       
  1516                                         TIpcArgs( &iReqData, 
       
  1517                                                   &effectHandlePckg ) );
       
  1518         }
       
  1519     
       
  1520     API_TRACE( ( _L( "CHWRMHapticsImpl::PlayMagSweepEffect() - SYNC - return %d" ), err ) );
       
  1521     API_TRACE( ( _L( "e_HWRMHAPTICS_CLIENT_PLAYMAGSWEEP_SYNC 0" ) ) );
       
  1522     
       
  1523     return err;
       
  1524     }
       
  1525  
       
  1526 // ---------------------------------------------------------------------------
       
  1527 // Plays a MagSweep effect given the parameters defining the effect. Async.
       
  1528 // ---------------------------------------------------------------------------
       
  1529 //
       
  1530 void CHWRMHapticsImpl::PlayMagSweepEffect( 
       
  1531         const THWRMHapticsMagSweepEffect& aEffect,
       
  1532         TInt& aEffectHandle, 
       
  1533         TRequestStatus& aStatus )
       
  1534     {
       
  1535     __ASSERT_DEBUG( iPacketizer, User::Panic( KPanic, EPanicNotReady ) );
       
  1536     if ( !iPacketizer )
       
  1537         {
       
  1538         TRequestStatus* tmp = &aStatus;
       
  1539         User::RequestComplete( tmp, EPanicNotReady );
       
  1540 
       
  1541         return;
       
  1542         }
       
  1543 
       
  1544     API_TRACE( ( _L( "e_HWRMHAPTICS_CLIENT_PLAYMAGSWEEP_ASYNC 1" ) ) );
       
  1545     API_TRACE( ( _L( "CHWRMHapticsImpl::PlayMagSweepEffect() - ASYNC - aEffectHandle(%d), aStatus(%d)" ), aEffectHandle, aStatus.Int() ) );
       
  1546     
       
  1547     iReqData.Close();
       
  1548     TInt err = iPacketizer->EncPlayMagSweepEffectReq( 
       
  1549                     iDeviceHandle, aEffect, iReqData );
       
  1550 
       
  1551     if ( KErrNone == err )
       
  1552         {
       
  1553         // reset effect handle package
       
  1554         ResetIntPckg( aEffectHandle );
       
  1555         
       
  1556         // make async call if packages were created successfully
       
  1557         iClient.ExecuteAsyncOperation( EHWRMHapticsPlayEffect,
       
  1558                                        TIpcArgs( &iReqData,
       
  1559                                                  &iEffectHandlePckg ),
       
  1560                                        aStatus );
       
  1561         }
       
  1562     
       
  1563     API_TRACE( ( _L( "CHWRMHapticsImpl::PlayMagSweepEffect() - ASYNC - return" ) ) );
       
  1564     API_TRACE( ( _L( "e_HWRMHAPTICS_CLIENT_PLAYMAGSWEEP_ASYNC 0" ) ) );
       
  1565     }
       
  1566  
       
  1567 // ---------------------------------------------------------------------------
       
  1568 // Plays a Periodic effect given the parameters defining the effect.
       
  1569 // ---------------------------------------------------------------------------
       
  1570 //
       
  1571 TInt CHWRMHapticsImpl::PlayPeriodicEffect( 
       
  1572         const THWRMHapticsPeriodicEffect& aEffect,
       
  1573         TInt& aEffectHandle )
       
  1574     {
       
  1575     __ASSERT_DEBUG( iPacketizer, User::Panic( KPanic, EPanicNotReady ) );
       
  1576     if ( !iPacketizer )
       
  1577         {
       
  1578         return EPanicNotReady;
       
  1579         }
       
  1580     API_TRACE( ( _L( "e_HWRMHAPTICS_CLIENT_PLAYPERIODIC_SYNC 1" ) ) );
       
  1581     API_TRACE( ( _L( "CHWRMHapticsImpl::PlayPeriodicEffect() - SYNC - aEffectHandle(%d)" ), aEffectHandle ) );
       
  1582     
       
  1583     iReqData.Close();
       
  1584     TInt err = iPacketizer->EncPlayPeriodicEffectReq( 
       
  1585                         iDeviceHandle, aEffect, iReqData );
       
  1586     
       
  1587     if ( KErrNone == err)
       
  1588         {
       
  1589         TPckg<TInt> effectHandlePckg( aEffectHandle );
       
  1590         err = iClient.ExecuteOperation( EHWRMHapticsPlayEffect,
       
  1591                                         TIpcArgs( &iReqData, 
       
  1592                                                   &effectHandlePckg ) );
       
  1593         }
       
  1594     
       
  1595     API_TRACE( ( _L( "CHWRMHapticsImpl::PlayPeriodicEffect() - SYNC - return %d"), err ) );
       
  1596     API_TRACE( ( _L( "e_HWRMHAPTICS_CLIENT_PLAYPERIODIC_SYNC 0" ) ) );
       
  1597     
       
  1598     return err;
       
  1599     }
       
  1600  
       
  1601 // ---------------------------------------------------------------------------
       
  1602 // Plays a Periodic effect given the parameters defining the effect. Async.
       
  1603 // ---------------------------------------------------------------------------
       
  1604 //
       
  1605 void CHWRMHapticsImpl::PlayPeriodicEffect( 
       
  1606         const THWRMHapticsPeriodicEffect& aEffect,
       
  1607         TInt& aEffectHandle, 
       
  1608         TRequestStatus& aStatus )
       
  1609     {
       
  1610     __ASSERT_DEBUG( iPacketizer, User::Panic( KPanic, EPanicNotReady ) );
       
  1611     if ( !iPacketizer )
       
  1612         {
       
  1613         TRequestStatus* tmp = &aStatus;
       
  1614         User::RequestComplete( tmp, EPanicNotReady );
       
  1615 
       
  1616         return;
       
  1617         }
       
  1618 
       
  1619     API_TRACE( ( _L( "e_HWRMHAPTICS_CLIENT_PLAYPERIODIC_ASYNC 1" ) ) );
       
  1620     API_TRACE( ( _L( "CHWRMHapticsImpl::PlayPeriodicEffect() - ASYNC - aEffectHandle(%d), aStatus(%d)" ), aEffectHandle, aStatus.Int() ) );
       
  1621     
       
  1622     iReqData.Close();
       
  1623     TInt err = iPacketizer->EncPlayPeriodicEffectReq( 
       
  1624                     iDeviceHandle, aEffect, iReqData );
       
  1625     
       
  1626     if ( KErrNone == err )
       
  1627         {
       
  1628         // reset effect handle package
       
  1629         ResetIntPckg( aEffectHandle );
       
  1630         
       
  1631         // make async call if packages were created successfully
       
  1632         iClient.ExecuteAsyncOperation( EHWRMHapticsPlayEffect,
       
  1633                                        TIpcArgs( &iReqData, 
       
  1634                                                  &iEffectHandlePckg ),
       
  1635                                        aStatus );
       
  1636         }
       
  1637     
       
  1638     API_TRACE( ( _L( "CHWRMHapticsImpl::PlayPeriodicEffect() - ASYNC - return" ) ) );
       
  1639     API_TRACE( ( _L( "e_HWRMHAPTICS_CLIENT_PLAYPERIODIC_ASYNC 0" ) ) );
       
  1640     }
       
  1641  
       
  1642 // ---------------------------------------------------------------------------
       
  1643 // Pauses an effect, which is currently playing. The effect is identified
       
  1644 // using the given effect handle.
       
  1645 // ---------------------------------------------------------------------------
       
  1646 //
       
  1647 TInt CHWRMHapticsImpl::PausePlayingEffect( TInt aEffectHandle )
       
  1648     {
       
  1649     __ASSERT_DEBUG( iPacketizer, User::Panic( KPanic, EPanicNotReady ) );
       
  1650     if ( !iPacketizer )
       
  1651         {
       
  1652         return EPanicNotReady;
       
  1653         }
       
  1654     API_TRACE( ( _L( "CHWRMHapticsImpl::PausePlayingEffect() - aEffectHandle(%d)" ), aEffectHandle ) );
       
  1655     API_TRACE( ( _L( "e_HWRMHAPTICS_CLIENT_PAUSEEFFECT 1" ) ) );
       
  1656 
       
  1657     iReqData.Close();
       
  1658     TInt err = iPacketizer->EncPausePlayingEffectReq(
       
  1659                         iDeviceHandle, aEffectHandle, iReqData );
       
  1660     
       
  1661     if ( KErrNone == err )
       
  1662         {
       
  1663         err = iClient.ExecuteOperation( EHWRMHaptics,
       
  1664                                         TIpcArgs( &iReqData ) );
       
  1665         }
       
  1666     
       
  1667     API_TRACE( ( _L( "CHWRMHapticsImpl::PausePlayingEffect() - return %d" ), err ) );
       
  1668     API_TRACE( ( _L( "e_HWRMHAPTICS_CLIENT_PAUSEEFFECT 0" ) ) );
       
  1669     
       
  1670     return err;
       
  1671     }
       
  1672  
       
  1673 // ---------------------------------------------------------------------------
       
  1674 // Resumes playing a paused effect. The effect is identified using the 
       
  1675 // given effect handle.
       
  1676 // ---------------------------------------------------------------------------
       
  1677 //
       
  1678 TInt CHWRMHapticsImpl::ResumePausedEffect( TInt aEffectHandle )
       
  1679     {
       
  1680     __ASSERT_DEBUG( iPacketizer, User::Panic( KPanic, EPanicNotReady ) );
       
  1681     if ( !iPacketizer )
       
  1682         {
       
  1683         return EPanicNotReady;
       
  1684         }
       
  1685     API_TRACE( ( _L( "e_HWRMHAPTICS_CLIENT_RESUMEEFFECT 1" ) ) );
       
  1686     API_TRACE( ( _L( "CHWRMHapticsImpl::ResumePausedEffect() - aEffectHandle(%d)" ), aEffectHandle ) );
       
  1687 
       
  1688     iReqData.Close();
       
  1689     TInt err = iPacketizer->EncResumePausedEffectReq( 
       
  1690                     iDeviceHandle, aEffectHandle, iReqData );
       
  1691     
       
  1692     if ( KErrNone == err )
       
  1693         {
       
  1694         err = iClient.ExecuteOperation( EHWRMHaptics, 
       
  1695                                         TIpcArgs( &iReqData ) );
       
  1696         }
       
  1697     
       
  1698     API_TRACE( ( _L( "CHWRMHapticsImpl::ResumePausedEffect() - return %d" ), err ) );
       
  1699     API_TRACE( ( _L( "e_HWRMHAPTICS_CLIENT_RESUMEEFFECT 0" ) ) );
       
  1700     
       
  1701     return err;
       
  1702     }
       
  1703 
       
  1704 // ---------------------------------------------------------------------------
       
  1705 // Stops playing an effect, which is currently playing (or paused). 
       
  1706 // The effect is identified using the given effect handle.
       
  1707 // ---------------------------------------------------------------------------
       
  1708 //
       
  1709 TInt CHWRMHapticsImpl::StopPlayingEffect( TInt aEffectHandle )
       
  1710     {
       
  1711     __ASSERT_DEBUG( iPacketizer, User::Panic( KPanic, EPanicNotReady ) );
       
  1712     if ( !iPacketizer )
       
  1713         {
       
  1714         return EPanicNotReady;
       
  1715         }
       
  1716     API_TRACE( ( _L( "e_HWRMHAPTICS_CLIENT_STOPEFFECT 1" ) ) );
       
  1717     API_TRACE( ( _L( "CHWRMHapticsImpl::StopPlayingEffect() - aEffectHandle(%d)" ), aEffectHandle ) );
       
  1718     
       
  1719     iReqData.Close();
       
  1720     TInt err = iPacketizer->EncStopPlayingEffectReq( 
       
  1721                     iDeviceHandle, aEffectHandle, iReqData );
       
  1722     
       
  1723     if ( KErrNone == err )
       
  1724         {
       
  1725         err = iClient.ExecuteOperation( EHWRMHaptics,
       
  1726                                         TIpcArgs( &iReqData ) );
       
  1727         }
       
  1728     
       
  1729     API_TRACE( ( _L( "CHWRMHapticsImpl::StopPlayingEffect() - return %d" ), err ) );
       
  1730     API_TRACE( ( _L( "e_HWRMHAPTICS_CLIENT_STOPEFFECT 0" ) ) );
       
  1731     
       
  1732     return err;
       
  1733     }
       
  1734 
       
  1735 // ---------------------------------------------------------------------------
       
  1736 // Stops all effects, which are currently playing (or in paused state) by this
       
  1737 // haptics client.
       
  1738 // ---------------------------------------------------------------------------
       
  1739 //
       
  1740 TInt CHWRMHapticsImpl::StopAllPlayingEffects()
       
  1741     {
       
  1742     __ASSERT_DEBUG( iPacketizer, User::Panic( KPanic, EPanicNotReady ) );
       
  1743     if ( !iPacketizer )
       
  1744         {
       
  1745         return EPanicNotReady;
       
  1746         }
       
  1747     API_TRACE( ( _L( "e_HWRMHAPTICS_CLIENT_STOPALLEFFECTS 1" ) ) );
       
  1748     API_TRACE( ( _L( "CHWRMHapticsImpl::StopAllPlayingEffects()" ) ) );
       
  1749     
       
  1750     iReqData.Close();
       
  1751     TInt err = iPacketizer->EncStopAllPlayingEffectsReq( iDeviceHandle, 
       
  1752                                                          iReqData );
       
  1753     
       
  1754     if ( KErrNone == err )
       
  1755         {
       
  1756         err = iClient.ExecuteOperation( EHWRMHaptics, 
       
  1757                                         TIpcArgs( &iReqData ) );
       
  1758         }
       
  1759     
       
  1760     API_TRACE( ( _L( "CHWRMHapticsImpl::StopAllPlayingEffects() - return %d" ), err ) );
       
  1761     API_TRACE( ( _L( "e_HWRMHAPTICS_CLIENT_STOPALLEFFECTS 0" ) ) );
       
  1762     
       
  1763     return err;
       
  1764     }
       
  1765  
       
  1766 // ---------------------------------------------------------------------------
       
  1767 // Get number of effects from loaded effect data buffer.
       
  1768 // ---------------------------------------------------------------------------
       
  1769 //
       
  1770 TInt CHWRMHapticsImpl::GetEffectCount( TInt aFileHandle, TInt& aCount ) const
       
  1771     {
       
  1772     API_TRACE( ( _L( "CHWRMHapticsImpl::GetEffectCount()" ) ) );
       
  1773     
       
  1774     TInt err = KErrBadHandle;
       
  1775         
       
  1776     const HBufC8* cachedIVTData = iIVTDataCache->IVTData( aFileHandle );
       
  1777     if ( cachedIVTData )
       
  1778         {
       
  1779         // get the effect count
       
  1780         err = iEffectDataGetter->GetEffectCount( *cachedIVTData, aCount );
       
  1781         }
       
  1782 
       
  1783     API_TRACE( ( _L( "CHWRMHapticsImpl::GetEffectCount() - return %d" ), err ) );
       
  1784     
       
  1785     return err;
       
  1786     }
       
  1787 
       
  1788 // ---------------------------------------------------------------------------
       
  1789 // Get duration of an effect defined in effect data buffer.
       
  1790 // ---------------------------------------------------------------------------
       
  1791 //
       
  1792 TInt CHWRMHapticsImpl::GetEffectDuration( TInt aFileHandle,
       
  1793                                           TInt aEffectIndex,
       
  1794                                           TInt& aEffectDuration ) const
       
  1795     {
       
  1796     API_TRACE( ( _L( "CHWRMHapticsImpl::GetEffectDuration()" ) ) );
       
  1797     
       
  1798     TInt err = KErrBadHandle;
       
  1799     
       
  1800     const HBufC8* cachedIVTData = iIVTDataCache->IVTData( aFileHandle );
       
  1801     if ( cachedIVTData )
       
  1802         {
       
  1803         // get the effect duration
       
  1804         err = iEffectDataGetter->GetEffectDuration( *cachedIVTData,
       
  1805                                                      aEffectIndex,
       
  1806                                                      aEffectDuration );
       
  1807         }
       
  1808 
       
  1809     API_TRACE( ( _L( "CHWRMHapticsImpl::GetEffectDuration() - return %d" ), err ) );
       
  1810     
       
  1811     return err;
       
  1812     }
       
  1813 
       
  1814 // ---------------------------------------------------------------------------
       
  1815 // Gets the index of an effect defined in effect data buffer
       
  1816 // given the name of the effect.
       
  1817 // ---------------------------------------------------------------------------
       
  1818 //
       
  1819 TInt CHWRMHapticsImpl::GetEffectIndexFromName ( TInt aFileHandle,
       
  1820                                                 const TDesC8& aEffectName,
       
  1821                                                 TInt& aEffectIndex ) const
       
  1822     {
       
  1823     API_TRACE( ( _L( "CHWRMHapticsImpl::GetEffectIndexFromName()" ) ) );
       
  1824     
       
  1825     TInt err = KErrBadHandle;
       
  1826     
       
  1827     const HBufC8* cachedIVTData = iIVTDataCache->IVTData( aFileHandle );
       
  1828     if ( cachedIVTData )
       
  1829         {
       
  1830             // get the effect index
       
  1831             err = iEffectDataGetter->GetEffectIndexFromName( *cachedIVTData,
       
  1832                                                              aEffectName,
       
  1833                                                              aEffectIndex );
       
  1834         }
       
  1835 
       
  1836     API_TRACE( ( _L( "CHWRMHapticsImpl::GetEffectIndexFromName() - return %d" ), err ) );
       
  1837     
       
  1838     return err;
       
  1839     }
       
  1840 
       
  1841 // ---------------------------------------------------------------------------
       
  1842 // Gets the type of an effect defined in effect data buffer.
       
  1843 // ---------------------------------------------------------------------------
       
  1844 //
       
  1845 TInt CHWRMHapticsImpl::GetEffectType( TInt aFileHandle,
       
  1846                                       TInt aEffectIndex,
       
  1847                                       TInt& aEffectType ) const
       
  1848     {
       
  1849     API_TRACE( ( _L( "CHWRMHapticsImpl::GetEffectType()" ) ) );
       
  1850     
       
  1851     TInt err = KErrBadHandle;
       
  1852     
       
  1853     const HBufC8* cachedIVTData = iIVTDataCache->IVTData( aFileHandle );
       
  1854     if ( cachedIVTData )
       
  1855         {
       
  1856         // get the effect type
       
  1857         err = iEffectDataGetter->GetEffectType( *cachedIVTData, 
       
  1858                                                 aEffectIndex,
       
  1859                                                 aEffectType );
       
  1860         }
       
  1861 
       
  1862     API_TRACE( ( _L( "CHWRMHapticsImpl::GetEffectType() - return %d" ), err ) );
       
  1863     
       
  1864     return err;
       
  1865     }
       
  1866 
       
  1867 // ---------------------------------------------------------------------------
       
  1868 // Gets the name of an effect defined in effect data buffer.
       
  1869 // ---------------------------------------------------------------------------
       
  1870 //
       
  1871 TInt CHWRMHapticsImpl::GetEffectName( TInt aFileHandle,
       
  1872                                       TInt aEffectIndex,
       
  1873                                       TDes8& aEffectName ) const
       
  1874     {
       
  1875     API_TRACE( ( _L( "CHWRMHapticsImpl::GetEffectName()" ) ) );
       
  1876     
       
  1877     TInt err = KErrBadHandle;
       
  1878     
       
  1879     const HBufC8* cachedIVTData = iIVTDataCache->IVTData( aFileHandle );
       
  1880     if ( cachedIVTData )
       
  1881         {
       
  1882         // get the effect name
       
  1883         err = iEffectDataGetter->GetEffectName( *cachedIVTData, 
       
  1884                                                 aEffectIndex,
       
  1885                                                 aEffectName );
       
  1886         }
       
  1887 
       
  1888     API_TRACE( ( _L( "CHWRMHapticsImpl::GetEffectName() - return %d" ), err ) );
       
  1889     
       
  1890     return err;
       
  1891     }
       
  1892 
       
  1893 // ---------------------------------------------------------------------------
       
  1894 // Gets the parameters of a MagSweep effect defined in effect data buffer.
       
  1895 // ---------------------------------------------------------------------------
       
  1896 //
       
  1897 TInt CHWRMHapticsImpl::GetMagSweepEffectDefinition( 
       
  1898         TInt aFileHandle,
       
  1899         TInt aEffectIndex,
       
  1900         THWRMHapticsMagSweepEffect& aEffect ) const
       
  1901     {
       
  1902     API_TRACE( ( _L( "CHWRMHapticsImpl::GetMagSweepEffectDefinition()" ) ) );
       
  1903     
       
  1904     TInt err = KErrBadHandle;
       
  1905     
       
  1906     const HBufC8* cachedIVTData = iIVTDataCache->IVTData( aFileHandle );
       
  1907     if ( cachedIVTData )
       
  1908         {
       
  1909         // get the effect definition
       
  1910         err = iEffectDataGetter->GetMagSweepEffectDefinition( *cachedIVTData, 
       
  1911                                                               aEffectIndex,
       
  1912                                                               aEffect );
       
  1913         }
       
  1914 
       
  1915     API_TRACE( ( _L( "CHWRMHapticsImpl::GetMagSweepEffectDefinition() - return %d" ), err ) );
       
  1916     
       
  1917     return err;
       
  1918     }
       
  1919 
       
  1920 // ---------------------------------------------------------------------------
       
  1921 // Gets the parameters of a Periodic effect defined in effect data buffer.
       
  1922 // ---------------------------------------------------------------------------
       
  1923 //
       
  1924 TInt CHWRMHapticsImpl::GetPeriodicEffectDefinition( 
       
  1925         TInt aFileHandle,
       
  1926         TInt aEffectIndex,
       
  1927         THWRMHapticsPeriodicEffect& aEffect ) const
       
  1928     {
       
  1929     API_TRACE( ( _L( "CHWRMHapticsImpl::GetPeriodicEffectDefinition()" ) ) );
       
  1930     
       
  1931     TInt err = KErrBadHandle;
       
  1932     
       
  1933     const HBufC8* cachedIVTData = iIVTDataCache->IVTData( aFileHandle );
       
  1934     if ( cachedIVTData )
       
  1935         {
       
  1936         // get the effect definition
       
  1937         err = iEffectDataGetter->GetPeriodicEffectDefinition( *cachedIVTData, 
       
  1938                                                               aEffectIndex,
       
  1939                                                               aEffect );
       
  1940         }
       
  1941 
       
  1942     API_TRACE( ( _L( "CHWRMHapticsImpl::GetPeriodicEffectDefinition() - return %d" ), err ) );
       
  1943   
       
  1944     return err;
       
  1945     }
       
  1946 
       
  1947 // ---------------------------------------------------------------------------
       
  1948 // Getter for the value used for representing infinite repeats
       
  1949 // ---------------------------------------------------------------------------
       
  1950 //
       
  1951 TInt CHWRMHapticsImpl::InfiniteRepeat() const
       
  1952     {
       
  1953     TInt retValue = KErrNotReady;
       
  1954     
       
  1955     if ( iPacketizer )
       
  1956         {
       
  1957         retValue = iPacketizer->InfiniteRepeat();
       
  1958         }
       
  1959     
       
  1960     return retValue;
       
  1961     }
       
  1962 
       
  1963 // ---------------------------------------------------------------------------
       
  1964 // Getter for the value used for representing infinite duration
       
  1965 // ---------------------------------------------------------------------------
       
  1966 //
       
  1967 TInt CHWRMHapticsImpl::InfiniteDuration() const
       
  1968     {
       
  1969     TInt retValue = KErrNotReady;
       
  1970     
       
  1971     if ( iPacketizer )
       
  1972         {
       
  1973         retValue = iPacketizer->InfiniteDuration();
       
  1974         }
       
  1975     
       
  1976     return retValue;
       
  1977     }
       
  1978 
       
  1979 // ---------------------------------------------------------------------------
       
  1980 // Getter for maximum effect name length
       
  1981 // ---------------------------------------------------------------------------
       
  1982 //
       
  1983 TInt CHWRMHapticsImpl::MaxEffectNameLength() const
       
  1984     {
       
  1985     TInt retValue = KErrNotReady;
       
  1986     
       
  1987     if ( iPacketizer )
       
  1988         {
       
  1989         retValue = iPacketizer->MaxEffectNameLength();
       
  1990         }
       
  1991     
       
  1992     return retValue;
       
  1993     }
       
  1994 
       
  1995 // ---------------------------------------------------------------------------
       
  1996 // Getter for maximum device name length
       
  1997 // ---------------------------------------------------------------------------
       
  1998 //
       
  1999 TInt CHWRMHapticsImpl::MaxDeviceNameLength() const
       
  2000     {
       
  2001     TInt retValue = KErrNotReady;
       
  2002     
       
  2003     if ( iPacketizer )
       
  2004         {
       
  2005         retValue = iPacketizer->MaxDeviceNameLength();
       
  2006         }
       
  2007     
       
  2008     return retValue;
       
  2009     }
       
  2010 
       
  2011 // ---------------------------------------------------------------------------
       
  2012 // Getter for maximum capability string length
       
  2013 // ---------------------------------------------------------------------------
       
  2014 //
       
  2015 TInt CHWRMHapticsImpl::MaxCapabilityStringLength() const
       
  2016     {
       
  2017     TInt retValue = KErrNotReady;
       
  2018     
       
  2019     if ( iPacketizer )
       
  2020         {
       
  2021         retValue = iPacketizer->MaxCapabilityStringLength();
       
  2022         }
       
  2023     
       
  2024     return retValue;
       
  2025     }
       
  2026 
       
  2027 // ---------------------------------------------------------------------------
       
  2028 // Getter for maximum property string length
       
  2029 // ---------------------------------------------------------------------------
       
  2030 //
       
  2031 TInt CHWRMHapticsImpl::MaxPropertyStringLength() const
       
  2032     {
       
  2033     TInt retValue = KErrNotReady;
       
  2034     
       
  2035     if ( iPacketizer )
       
  2036         {
       
  2037         retValue = iPacketizer->MaxPropertyStringLength();
       
  2038         }
       
  2039     
       
  2040     return retValue;
       
  2041     }
       
  2042 
       
  2043 // ---------------------------------------------------------------------------
       
  2044 // Getter for maximum streaming sample size
       
  2045 // ---------------------------------------------------------------------------
       
  2046 //
       
  2047 TInt CHWRMHapticsImpl::MaxStreamingSampleSize() const
       
  2048     {
       
  2049     TInt retValue = KErrNotReady;
       
  2050     
       
  2051     if ( iPacketizer )
       
  2052         {
       
  2053         retValue = iPacketizer->MaxStreamingSampleSize();
       
  2054         }
       
  2055     
       
  2056     return retValue;
       
  2057     }
       
  2058 
       
  2059 // ---------------------------------------------------------------------------
       
  2060 // Getter for default device priority
       
  2061 // ---------------------------------------------------------------------------
       
  2062 //
       
  2063 TInt CHWRMHapticsImpl::DefaultDevicePriority() const
       
  2064     {
       
  2065     TInt retValue = KErrNotReady;
       
  2066     
       
  2067     if ( iPacketizer )
       
  2068         {
       
  2069         retValue = iPacketizer->DefaultDevicePriority();
       
  2070         }
       
  2071     
       
  2072     return retValue;
       
  2073     }
       
  2074 
       
  2075 // ---------------------------------------------------------------------------
       
  2076 // Reserve haptics resource.
       
  2077 // ---------------------------------------------------------------------------
       
  2078 //
       
  2079 TInt CHWRMHapticsImpl::DoReserveHaptics( TBool aForceNoCCoeEnv )
       
  2080     {
       
  2081     COMPONENT_TRACE( ( _L( "CHWRMHapticsImpl::DoReserveHaptics(0x%x)" ), aForceNoCCoeEnv ) );
       
  2082     
       
  2083     TInt err = KErrNone;
       
  2084     
       
  2085     // reserve only if not reserved already
       
  2086     if ( !iReserved )
       
  2087         {
       
  2088         // Execute reservation
       
  2089         err = iClient.ExecuteOperation( EHWRMHapticsReserve, 
       
  2090                                         TIpcArgs( aForceNoCCoeEnv ) );
       
  2091 
       
  2092         // Reserve successful, mark as reserved
       
  2093         iReserved = ETrue;
       
  2094         }
       
  2095     
       
  2096     if ( !aForceNoCCoeEnv )
       
  2097         {
       
  2098         iAutoReserve = ETrue;
       
  2099         }
       
  2100     
       
  2101     COMPONENT_TRACE( _L( "CHWRMHapticsImpl::DoReserveHaptics - return" ) );
       
  2102     
       
  2103     return err;
       
  2104     }
       
  2105 
       
  2106 // ---------------------------------------------------------------------------
       
  2107 // Releases haptics by sending corresponding command to haptics server.
       
  2108 // ---------------------------------------------------------------------------
       
  2109 //
       
  2110 void CHWRMHapticsImpl::DoReleaseHaptics()
       
  2111     {  
       
  2112     // Only release if reserved
       
  2113     if ( iReserved )
       
  2114         {
       
  2115         // Execute release
       
  2116         TInt err = iClient.ExecuteOperation( EHWRMHapticsRelease );
       
  2117         
       
  2118         COMPONENT_TRACE( ( _L( "CHWRMHapticsImpl::DoReleaseHaptics - ipc ret: %d" ), err ) );
       
  2119         if ( KErrNone == err )
       
  2120             {
       
  2121             iReserved = EFalse;
       
  2122             }
       
  2123         }    
       
  2124     }
       
  2125 
       
  2126 // ---------------------------------------------------------------------------
       
  2127 // Recreates the given integer package using the given value.
       
  2128 // ---------------------------------------------------------------------------
       
  2129 //
       
  2130 void CHWRMHapticsImpl::ResetIntPckg( TInt& aNewValue )
       
  2131     {
       
  2132     // re-construct the buffer
       
  2133     (void) new (&iEffectHandlePckg) TPckg<TInt>( aNewValue );
       
  2134     }
       
  2135 
       
  2136 // ---------------------------------------------------------------------------
       
  2137 // Finalizes the construction.
       
  2138 // ---------------------------------------------------------------------------
       
  2139 //
       
  2140 void CHWRMHapticsImpl::FinalizeL(
       
  2141                         MHWRMHapticsObserver* aHapticsCallback,
       
  2142                         MHWRMHapticsActuatorObserver* aActuatorCallback )
       
  2143     {
       
  2144     // create status observer only if a callback for it has been received
       
  2145     if ( aHapticsCallback || aActuatorCallback )
       
  2146         {
       
  2147         iStatusObserver = CHWRMHapticsStatusObserver::NewL( aHapticsCallback,
       
  2148                                                             aActuatorCallback,
       
  2149                                                             &iClient );
       
  2150         }
       
  2151     
       
  2152     // create IVT-data cache
       
  2153     iIVTDataCache = CHWRMHapticsIVTDataCache::NewL();
       
  2154 
       
  2155     // create effect data getter
       
  2156     iEffectDataGetter = CHWRMHapticsEffectDataGetter::NewL();
       
  2157     }
       
  2158 
       
  2159 // End of file