hwrmhaptics/examples/hapticstestapp/inc/hapticstesteffectdatahandler.h
changeset 76 cb32bcc88bad
equal deleted inserted replaced
73:d38941471f1c 76:cb32bcc88bad
       
     1 /*
       
     2 * Copyright (c) 2007 Nokia Corporation and/or its subsidiary(-ies). 
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of the License "Symbian Foundation License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.symbianfoundation.org/legal/sfl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:  Handles and stores effect related data.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #ifndef __HAPTICSTEST_EFFECTDATAHANDLER_H__
       
    20 #define __HAPTICSTEST_EFFECTDATAHANDLER_H__
       
    21 
       
    22 #include <e32base.h>
       
    23 #include <hwrmhaptics.h>
       
    24 
       
    25 // values used for modifying effects
       
    26 const TInt KEffectMagnitude25 = 0.25 * KHWRMHapticsMaxMagnitude;
       
    27 const TInt KEffectMagnitude50 = 0.50 * KHWRMHapticsMaxMagnitude;
       
    28 const TInt KEffectMagnitude75 = 0.75 * KHWRMHapticsMaxMagnitude;
       
    29 const TInt KEffectDuration1 = 1000;
       
    30 const TInt KEffectDuration5 = 5000;
       
    31 const TInt KEffectDuration10 = 10000;
       
    32 const TInt KEffectDuration30 = 30000;
       
    33 const TInt KEffectDuration60 = 60000;
       
    34 const TInt KEffectAttackTime02 = 200;
       
    35 const TInt KEffectAttackTime1 = 1000;
       
    36 const TInt KEffectAttackTime5 = 5000;
       
    37 const TInt KEffectAttackTime10 = 10000;
       
    38 const TInt KEffectAttackTime30 = 30000;
       
    39 const TInt KEffectAttackTime60 = 60000;
       
    40 const TInt KEffectFadeTime02 = 200;
       
    41 const TInt KEffectFadeTime1 = 1000;
       
    42 const TInt KEffectFadeTime5 = 5000;
       
    43 const TInt KEffectFadeTime10 = 10000;
       
    44 const TInt KEffectFadeTime30 = 30000;
       
    45 const TInt KEffectFadeTime60 = 60000;
       
    46 const TInt KEffectPeriod50 = 50;
       
    47 const TInt KEffectPeriod100 = 100;
       
    48 const TInt KEffectPeriod300 = 300;
       
    49 const TInt KEffectPeriod600 = 600;
       
    50 const TInt KEffectPeriod1000 = 1000;
       
    51 const TInt KEffectPeriod3000 = 3000;
       
    52 
       
    53 /**
       
    54  * Handles effect data storage of both history data of 
       
    55  * played effects (array) and single effect data of the 
       
    56  * effect, which can be modified during runtime.
       
    57  */
       
    58 class CHapticsTestEffectDataHandler : public CBase
       
    59     {
       
    60 public:
       
    61 
       
    62     /**
       
    63      * Symbian two-phased construction.
       
    64      *
       
    65      * @return Pointer to the created instance.
       
    66      */
       
    67     static CHapticsTestEffectDataHandler* NewL();
       
    68 
       
    69     /**
       
    70      * Symbian two-phased construction. Leaves the pointer
       
    71      * onto the cleanupstack.
       
    72      *
       
    73      * @return Pointer to the created instance.
       
    74      */
       
    75     static CHapticsTestEffectDataHandler* NewLC();
       
    76 
       
    77     /**
       
    78      * Destructor.
       
    79      */
       
    80     virtual ~CHapticsTestEffectDataHandler();
       
    81 
       
    82 public: // effect history array related
       
    83 
       
    84     /**
       
    85      * Adds effect data to effect history array.
       
    86      * 
       
    87      * @param aEffectHandle Handle to the effect just played.
       
    88      * @param aFileHandle Handle to IVT-file used for the effect. The 
       
    89      * default value KErrNotFound indicates that an IVT-file was not used.
       
    90      * @param aIndex Index of the effect in the effect file. The default
       
    91      * value KErrNotFound indicates that an IVT-file was not used.
       
    92      */
       
    93     void AddEffectInfo( TInt aEffectHandle,
       
    94                         TInt aFileHandle = KErrNotFound,
       
    95                         TInt aIndex = KErrNotFound );
       
    96 
       
    97     /**
       
    98      * Deletest all effect info items from the list that have the 
       
    99      * given filehandle in their data. This method is used, when deleting
       
   100      * IVT-data, i.e. that data is no longer available.
       
   101      * 
       
   102      * @param aFileHandle Handle to IVT-file used for the effect.
       
   103      */
       
   104     void DeleteEffectInfo( TInt aFileHandle );
       
   105 
       
   106     /**
       
   107      * Returns the amount of effect data stored in the history data array.
       
   108      */
       
   109     TInt Count() const;
       
   110 
       
   111     /**
       
   112      * Returns the effect handle of the given effect data item.
       
   113      *
       
   114      * @param aIndex Index of the effect data in the history array.
       
   115      * @return The effect handle of the effect.
       
   116      */
       
   117     TInt EffectHandle( TInt aIndex ) const;
       
   118 
       
   119     /**
       
   120      * Returns the file handle of the given effect data item.
       
   121      *
       
   122      * @param aIndex Index of the effect data in the history array.
       
   123      * @return The file handle of the effect.
       
   124      */
       
   125     TInt FileHandle( TInt aIndex ) const;
       
   126 
       
   127     /**
       
   128      * Returns the effect index of the given effect data item.
       
   129      *
       
   130      * @param aIndex Index of the effect data in the history array.
       
   131      * @return The effect index of the effect.
       
   132      */
       
   133     TInt EffectIndex( TInt aIndex ) const;
       
   134 
       
   135 public: // modifiable effect related
       
   136 
       
   137     /**
       
   138      * Resets the modifiable effect data with the data received in the
       
   139      * given magsweep effect.
       
   140      *
       
   141      * @param aMagSweep MagSweep effect data.
       
   142      * @param aEffectHandle Effect handle to this effect.
       
   143      * @param aHaptics Haptics client instance.
       
   144      */
       
   145     void ResetModifiableMagSweepEffectL( const CHWRMHaptics::THWRMHapticsMagSweepEffect& aMagSweep,
       
   146                                          TInt aEffectHandle,
       
   147                                          CHWRMHaptics* aHaptics );
       
   148 
       
   149     /**
       
   150      * Resets the modifiable effect data with the data received in the
       
   151      * given periodic effect.
       
   152      *
       
   153      * @param aPeriodic Periodic effect data.
       
   154      * @param aEffectHandle Effect handle to this effect.
       
   155      * @param aHaptics Haptics client instance.
       
   156      */
       
   157     void ResetModifiablePeriodicEffectL( const CHWRMHaptics::THWRMHapticsPeriodicEffect& aPeriodic,
       
   158                                          TInt aEffectHandle,
       
   159                                          CHWRMHaptics* aHaptics );
       
   160 
       
   161     /**
       
   162      * Starts the timer, which calls the ModifyPlayingEffect() callback
       
   163      * after a certain time period for modifying the last stored effect
       
   164      * using ResetModifiableEffectL().
       
   165      *
       
   166      * @param aFunction Callback method for the started timer.
       
   167      */
       
   168     void StartModifiableEffectTimerL( TInt (*aFunction)(TAny* aPtr) );
       
   169 
       
   170     /**
       
   171      * Stops and deletes the auto-modifiable effect timer.
       
   172      */
       
   173     void ResetModifiableEffectTimer();
       
   174     
       
   175     /**
       
   176      * Returns whether or not a modifiable effect exists.
       
   177      */
       
   178     TBool ModifiableEffectExists() const;
       
   179 
       
   180     /**
       
   181      * Returns whether or not the currently stored effect is a 
       
   182      * magsweep effect.
       
   183      */
       
   184     TBool ModifiableEffectIsMagSweep() const;
       
   185 
       
   186     /**
       
   187      * Returns whether or not the currently stored effect is a 
       
   188      * periodic effect.
       
   189      */
       
   190     TBool ModifiableEffectIsPeriodic() const;
       
   191     
       
   192     /**
       
   193      * Returns the effect handle of the modifiable effect.
       
   194      */
       
   195     TInt ModifiableEffectHandle() const;
       
   196     
       
   197     /**
       
   198      * Returns the amount of times the current modifiable effect
       
   199      * has been modified already.
       
   200      */
       
   201     TInt ModifyCount() const;
       
   202     
       
   203     /**
       
   204      * Returns the pointer to the haptics client instance, which
       
   205      * has been set to the effect modification data.
       
   206      */
       
   207     CHWRMHaptics* Haptics() const;
       
   208     
       
   209     /**
       
   210      * Fills in default magsweep effect data into the given structure.
       
   211      * 
       
   212      * @param aMagSweep MagSweep effect data structure for the method to fill.
       
   213      * @param aInfinite Whether or not the duration should be infinite.
       
   214      * @param aAutoModifiable Whether or not the created data is used 
       
   215      * for automatic modification using a timer.
       
   216      * @param aHaptics Haptics client instance.
       
   217      */
       
   218     void FillDefaultMagSweepData( CHWRMHaptics::THWRMHapticsMagSweepEffect& aMagSweep,
       
   219                                   TBool aInfinite, TBool aAutoModifiable,
       
   220                                   CHWRMHaptics* aHaptics ) const;
       
   221 
       
   222     /**
       
   223      * Fills in default periodic effect data into the given structure.
       
   224      * 
       
   225      * @param aPeriodic Periodic effect data structure for the method to fill.
       
   226      * @param aInfinite Whether or not the duration should be infinite.
       
   227      * @param aAutoModifiable Whether or not the created data is used 
       
   228      * for automatic modification using a timer.
       
   229      * @param aHaptics Haptics client instance.
       
   230      */
       
   231     void FillDefaultPeriodicData( CHWRMHaptics::THWRMHapticsPeriodicEffect& aPeriodic,
       
   232                                   TBool aInfinite, TBool aAutoModifiable,
       
   233                                   CHWRMHaptics* aHaptics ) const;
       
   234 
       
   235     /**
       
   236      * Fills in the modifiable effect data into the given magsweep structure.
       
   237      *
       
   238      * @param aMagSweep MagSweep effect data structure for the method to fill.
       
   239      */
       
   240     void FillModifiableMagSweepData( CHWRMHaptics::THWRMHapticsMagSweepEffect& aMagSweep ) const;
       
   241 
       
   242     /**
       
   243      * Fills in the modifiable effect data into the given periodic structure.
       
   244      *
       
   245      * @param aPeriodic Periodic effect data structure for the method to fill.
       
   246      */
       
   247     void FillModifiablePeriodicData( CHWRMHaptics::THWRMHapticsPeriodicEffect& aPeriodic ) const;
       
   248 
       
   249     /**
       
   250      * Sets the modifiable effect's modify count.
       
   251      */
       
   252     void SetModifyCount( TInt aModifyCount );
       
   253 
       
   254     /**
       
   255      * Sets the modifiable effect's duration value.
       
   256      */
       
   257     void SetDuration( TInt aDuration );
       
   258 
       
   259     /**
       
   260      * Sets the modifiable effect's magnitude value.
       
   261      */
       
   262     void SetMagnitude( TInt aMagnitude );
       
   263 
       
   264     /**
       
   265      * Sets the modifiable effect's style value.
       
   266      */
       
   267     void SetStyle( CHWRMHaptics::THWRMHapticsEffectStyles aStyle );
       
   268 
       
   269     /**
       
   270      * Sets the modifiable effect's attack level value.
       
   271      */
       
   272     void SetAttackLevel( TInt aAttackLevel );
       
   273 
       
   274     /**
       
   275      * Sets the modifiable effect's fade level value.
       
   276      */
       
   277     void SetFadeLevel( TInt aFadeLevel );
       
   278 
       
   279     /**
       
   280      * Sets the modifiable effect's attack time value.
       
   281      */
       
   282     void SetAttackTime( TInt aAttackTime );
       
   283 
       
   284     /**
       
   285      * Sets the modifiable effect's fade time value.
       
   286      */
       
   287     void SetFadeTime( TInt aFadeTime );
       
   288 
       
   289     /**
       
   290      * Sets the modifiable effect's period value.
       
   291      */
       
   292     void SetPeriod( TInt aPeriod );
       
   293 
       
   294 public: // submenu handling for effect data related submenus
       
   295 
       
   296     /**
       
   297      * Creates all submenu items for a change effect state submenu
       
   298      * (pause, resume, stop). Fetches all the names of the effects
       
   299      * from currently loaded IVT-data.
       
   300      *
       
   301      * @param aMenuPane Menu object to which menu items are added.
       
   302      * @param aCommandId Id of an options menu command to be used
       
   303      * for all items.
       
   304      * @param aHaptics Haptics client instance used for fetching effect names.
       
   305      */
       
   306     void DynInitChangeEffectStateSubmenuL( CEikMenuPane* aMenuPane, 
       
   307                                            TInt aCommandId,
       
   308                                            CHWRMHaptics* aHaptics );
       
   309          
       
   310     /**
       
   311      * Creates the checkmark to the duration, which is currently in use
       
   312      * in the duration modification submenu.
       
   313      */
       
   314     void DynInitDurationSubmenu( CEikMenuPane* aMenuPane ) const;
       
   315 
       
   316     /**
       
   317      * Creates the checkmark to the magnitude, which is currently in use
       
   318      * in the magnitude modification submenu.
       
   319      */
       
   320     void DynInitMagnitudeSubmenu( CEikMenuPane* aMenuPane ) const;
       
   321 
       
   322     /**
       
   323      * Creates the checkmark to the style, which is currently in use
       
   324      * in the style modification submenu.
       
   325      */
       
   326     void DynInitStyleSubmenu( CEikMenuPane* aMenuPane ) const;
       
   327 
       
   328     /**
       
   329      * Creates the checkmark to the attack level, which is currently in use
       
   330      * in the attack level modification submenu.
       
   331      */
       
   332     void DynInitAttackLevelSubmenu( CEikMenuPane* aMenuPane ) const;
       
   333 
       
   334     /**
       
   335      * Creates the checkmark to the fade level, which is currently in use
       
   336      * in the fade level modification submenu.
       
   337      */
       
   338     void DynInitFadeLevelSubmenu( CEikMenuPane* aMenuPane ) const;
       
   339 
       
   340     /**
       
   341      * Creates the checkmark to the attack time, which is currently in use
       
   342      * in the attack time modification submenu.
       
   343      */
       
   344     void DynInitAttackTimeSubmenu( CEikMenuPane* aMenuPane ) const;
       
   345 
       
   346     /**
       
   347      * Creates the checkmark to the fade time, which is currently in use
       
   348      * in the fade time modification submenu.
       
   349      */
       
   350     void DynInitFadeTimeSubmenu( CEikMenuPane* aMenuPane ) const;
       
   351 
       
   352     /**
       
   353      * Creates the checkmark to the period, which is currently in use
       
   354      * in the period modification submenu.
       
   355      */
       
   356     void DynInitPeriodSubmenu( CEikMenuPane* aMenuPane ) const;
       
   357 
       
   358 private:
       
   359     
       
   360     /**
       
   361      * Internal structure for maintaining information about played
       
   362      * effect. The data is used, when pausing, stopping and resuming
       
   363      * effect play.
       
   364      */
       
   365     struct TPlayedEffect
       
   366         {
       
   367         /**
       
   368          * Handle to IVT-data file, from which the effect has been played.
       
   369          * Needed for fetching effect related information.
       
   370          */
       
   371         TInt iFileHandle;
       
   372 
       
   373         /**
       
   374          * Index of the effect in the effect file. Needed for fetching
       
   375          * effect related information.
       
   376          */
       
   377         TInt iEffectIndex;
       
   378 
       
   379         /**
       
   380          * Handle to the effect itself.
       
   381          */
       
   382         TInt iEffectHandle;
       
   383         }; 
       
   384 
       
   385     /**
       
   386      * Internal structure for maintaining information about an effect, 
       
   387      * which can be modified during application execution.
       
   388      */
       
   389     struct TModifyEffect
       
   390         {
       
   391         /**
       
   392          * Haptics client instance. Not owned.
       
   393          * The pointer is included in this data so that the 
       
   394          * timer callback method is able to access haptics.
       
   395          */
       
   396         CHWRMHaptics* iHaptics;
       
   397         
       
   398         /**
       
   399          * Type of the effect being modified.
       
   400          */
       
   401         CHWRMHaptics::THWRMHapticsEffectTypes iEffectType;
       
   402 
       
   403         /**
       
   404          * Handle to the effect itself.
       
   405          */
       
   406         TInt iEffectHandle;
       
   407         
       
   408         /**
       
   409          * Keeps track on how many modifications have been done.
       
   410          */
       
   411         TInt iModifyCount;
       
   412         
       
   413         /**
       
   414          * Duration value used for the effect.
       
   415          */
       
   416         TInt iDuration;
       
   417         
       
   418         /**
       
   419          * Magnitude value used for the effect.
       
   420          */
       
   421         TInt iMagnitude;
       
   422 
       
   423         /**
       
   424          * Style of the effect.
       
   425          */
       
   426         TInt iStyle;
       
   427 
       
   428         /**
       
   429          * Attack level value used for the effect.
       
   430          */
       
   431         TInt iAttackLevel;
       
   432 
       
   433         /**
       
   434          * Fade level value used for the effect.
       
   435          */
       
   436         TInt iFadeLevel;
       
   437 
       
   438         /**
       
   439          * Attack time value used for the effect.
       
   440          */
       
   441         TInt iAttackTime;
       
   442 
       
   443         /**
       
   444          * Fade time value used for the effect.
       
   445          */
       
   446         TInt iFadeTime;
       
   447 
       
   448         /**
       
   449          * Period value used for the (periodic) effect.
       
   450          */
       
   451         TInt iPeriod;
       
   452         };
       
   453 
       
   454 private:
       
   455 
       
   456     /**
       
   457      * C++ constructor.
       
   458      */
       
   459     CHapticsTestEffectDataHandler();
       
   460 
       
   461     /**
       
   462      * Second phase construction.
       
   463      */
       
   464     void ConstructL();
       
   465 
       
   466 private:
       
   467 
       
   468     /**
       
   469      * Array containing history data of effect play. Used for
       
   470      * pausing, resuming and stopping effects.
       
   471      */
       
   472     RArray<TPlayedEffect> iPlayedEffectArray;
       
   473 
       
   474     /**
       
   475      * Timer used for constant modification of an effect.
       
   476      */
       
   477     CPeriodic* iModifyTimer;
       
   478 
       
   479     /**
       
   480      * Effect data stored for effect modification.
       
   481      */
       
   482     TModifyEffect* iModifyEffect;
       
   483     };
       
   484 
       
   485 
       
   486 #endif // __HAPTICSTEST_EFFECTDATAHANDLER_H__