localconnectivityservice/headset/inc/headset.h
branchRCL_3
changeset 19 0aa8cc770c8a
equal deleted inserted replaced
18:453dfc402455 19:0aa8cc770c8a
       
     1 /*
       
     2 * Copyright (c) 2004-2010 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:  Hid headset driver 
       
    15  *
       
    16 */
       
    17 
       
    18 
       
    19 #ifndef C_HIDHEADSETDRIVER_H
       
    20 #define C_HIDHEADSETDRIVER_H
       
    21 
       
    22 #include <e32std.h>
       
    23 #include <asclisession.h>
       
    24 #include <mpxplaybackutility.h>
       
    25 #include <mpxplaybackobserver.h>
       
    26 #include <mpxmessage.h>
       
    27 #include <hidinterfaces.h>
       
    28 #include <hidtranslate.h>
       
    29 #include "keypresstimer.h"
       
    30 
       
    31 class CField;
       
    32 class CHidHeadsetDriver;
       
    33 class CTelephony;
       
    34 
       
    35 /**
       
    36  *  Scan status
       
    37  */
       
    38 enum TScanStatus
       
    39     {
       
    40     EScanNotPressed, EScanPressed, EScanLongPress
       
    41     };
       
    42 
       
    43 /**
       
    44  * HID headset driver class
       
    45  *
       
    46  * HidDriver interface for handlign headset related 
       
    47  * functionality.
       
    48  *
       
    49  */
       
    50 
       
    51 class CHidHeadsetDriver : public CHidDriver,
       
    52         public MTimerNotifier,
       
    53         public MMPXPlaybackObserver
       
    54     {
       
    55 
       
    56 private:
       
    57     /**
       
    58      *  Initialisation states 
       
    59      */
       
    60     enum THeadsetDriverState
       
    61         {
       
    62         EUninitialised, // Driver has not been initialised 
       
    63         EInitialised, // Driver is initialised 
       
    64         EDisabled
       
    65         // The driver will not respond to interrupt data 
       
    66         };
       
    67 
       
    68     /**
       
    69      * Hook handling
       
    70      */
       
    71     enum THookHandling
       
    72         {
       
    73         EOnHook, EOffHook, ENoHook
       
    74         };
       
    75 public:
       
    76 
       
    77     /**
       
    78      * Two-phased constructor.
       
    79      * @param aHid The generic HID layer that requested the driver     
       
    80      */
       
    81     static CHidHeadsetDriver* NewL( MDriverAccess* aHid );
       
    82 
       
    83     /**
       
    84      * Two-phased constructor.
       
    85      * @param aHid The generic HID layer that requested the driver     
       
    86      */
       
    87     static CHidHeadsetDriver* NewLC( MDriverAccess* aHid );
       
    88 
       
    89     /**
       
    90      * Destructor
       
    91      */
       
    92     virtual ~CHidHeadsetDriver();
       
    93 
       
    94 private:
       
    95 
       
    96     // from base class CHidDriver
       
    97     /**     
       
    98      * From class CHidDriver
       
    99      * Called by the Generic HID layer to see if the driver can is able to
       
   100      * use reports from a newly-connected device. Supported hid fields van 
       
   101      * be later request with SupportedFieldCount function
       
   102      *  
       
   103      * @param aReportRoot HID report descriptor
       
   104      * @return KErrNone The driver will handle reports from the report 
       
   105      *         descriptor and KErrHidUnrecognised The driver cannot 
       
   106      *         handle reports from the device
       
   107      */
       
   108     TInt CanHandleReportL( CReportRoot* aReportRoot );
       
   109 
       
   110     /**     
       
   111      * From class CHidDriver
       
   112      * Called by the Generic HID layer when a device has been removed, prior
       
   113      * to the driver being removed.  This allows the driver to notify any 
       
   114      * applications of disconnection, if required
       
   115      *     
       
   116      * @param aReason The reason for device disconnection     
       
   117      */
       
   118     void Disconnected( TInt aReason );
       
   119 
       
   120     /**     
       
   121      * From class CHidDriver
       
   122      * Called by the Generic HID layer when data has been received from the 
       
   123      * device handled by this driver. 
       
   124      *     
       
   125      * @param aChannel The channel on which the data was received 
       
   126      *                                   (as defined by the transport layer)
       
   127      * @param aPayload A pointer to the data buffer     
       
   128      */
       
   129     TInt DataIn( CHidTransport::THidChannelType aChannel,
       
   130             const TDesC8& aPayload );
       
   131 
       
   132     /**     
       
   133      * From class CHidDriver
       
   134      * Called by the transport layers to inform the generic HID of the 
       
   135      * success of the last Set... command. 
       
   136      *     
       
   137      * @param aCmdAck Status of the last Set... command     
       
   138      */
       
   139     void CommandResult( TInt aCmdAck );
       
   140 
       
   141     /**     
       
   142      * From class CHidDriver
       
   143      * Called after a driver is sucessfully created by the Generic HID, when 
       
   144      * a device is connected 
       
   145      *     
       
   146      * @param aConnectionId An number used to identify the device in
       
   147      *                      subsequent calls from the driver to the 
       
   148      *                      generic HI     
       
   149      */
       
   150     void InitialiseL( TInt aConnectionId );
       
   151 
       
   152     /**     
       
   153      * From class CHidDriver
       
   154      * Resets the internal state of the driver (any pressed keys are released) 
       
   155      * and enables the driver  
       
   156      *     
       
   157      * @param aConnectionId An number used to identify the device in
       
   158      *                      subsequent calls from the driver to the 
       
   159      *                      generic HI     
       
   160      */
       
   161     void StartL( TInt aConnectionId );
       
   162 
       
   163     /**     
       
   164      * From class CHidDriver
       
   165      * Cancels all pressed keys and disables the driver (so it will not
       
   166      * process interrupt data)  
       
   167      *
       
   168      */
       
   169     void Stop();
       
   170 
       
   171     /**
       
   172      * From class CHidDriver
       
   173      * Return count of supported fields
       
   174      *          
       
   175      * @return Number of supported fields
       
   176      */
       
   177     TInt SupportedFieldCount();
       
   178 
       
   179     /**
       
   180      * From class CHidDriver
       
   181      * Set input handling registy 
       
   182      *          
       
   183      * @param aHandlingReg  a Input handling registry     
       
   184      */
       
   185     void SetInputHandlingReg( CHidInputDataHandlingReg* aHandlingReg );
       
   186 
       
   187     // from base class MTimerNotifier    
       
   188     /**     
       
   189      * From class MTimerNotifier
       
   190      * The function to be called when a timeout occurs.
       
   191      *     
       
   192      * @param aTimerType a Type of timer
       
   193      */
       
   194     void TimerExpired( TTimerType aTimerType );
       
   195 
       
   196     /**
       
   197      *  From class MMPXPlaybackObserver
       
   198      *  Handle playback message.    
       
   199      *   
       
   200      *  @param aMsg playback message, ownership not transferred. 
       
   201      *         Please check aMsg is not NULL before using it. If aErr is not 
       
   202      *         KErrNone, plugin might still call back with more info in the 
       
   203      *         aMsg.
       
   204      *  @param aErr system error code.
       
   205      */
       
   206     void HandlePlaybackMessage( CMPXMessage* aMsg, TInt /*aErr*/);
       
   207 
       
   208 private:
       
   209     /**
       
   210      * Constructor
       
   211      * @param aHid The generic HID layer that requested the driver 
       
   212      */
       
   213     CHidHeadsetDriver( MDriverAccess* aHid );
       
   214     /**
       
   215      * ConstructL
       
   216      */
       
   217     void ConstructL();
       
   218 
       
   219 private:
       
   220 
       
   221     /**
       
   222      * Called from within DataIn to handle interrupt and control channel data
       
   223      *
       
   224      * @param aPayload a Payload data
       
   225      * @return error if data can't be handled
       
   226      */
       
   227     TInt InterruptData( const TDesC8& aPayload );
       
   228 
       
   229     /**
       
   230      * Handles the report
       
   231      *
       
   232      * @param aReport HID report descriptor
       
   233      * @param aField HID field
       
   234      * @return KErrNotSupported if report can't be handled
       
   235      */
       
   236     TInt HandleReport( const TDesC8& aReport, const CField* aField );
       
   237 
       
   238     /**
       
   239      * Handles the report
       
   240      *
       
   241      * @param aReportTranslator Report Translator
       
   242      */
       
   243     void ReleasePressedKeys( TReportTranslator& aReportTranslator );
       
   244 
       
   245     /**
       
   246      * Handle hook key pres
       
   247      *     
       
   248      * @param aStatus Hook key status
       
   249      */
       
   250     void HookKeyPres( TBool aStatus );
       
   251 
       
   252     /**
       
   253      * Release hook key 
       
   254      *
       
   255      */
       
   256     void ReleaseHookKey();
       
   257 
       
   258     /**
       
   259      * Get Hook Status
       
   260      *     
       
   261      * @return hook handling status. 
       
   262      */
       
   263     THookHandling HookStatus();
       
   264 
       
   265     /**
       
   266      * Get alarm status
       
   267      *     
       
   268      * @return ETrue if ui is showing alarm, EFalse if not. 
       
   269      */
       
   270     TBool AlarmStatus();
       
   271 
       
   272     /**
       
   273      * MusicPlayingStatus
       
   274      *    
       
   275      * @return ETrue if plyaer is playing, EFalse if not. 
       
   276      */
       
   277     TBool MusicPlayingStatus();
       
   278 
       
   279     /**
       
   280      * HandleNoneHookPress
       
   281      * Handle hook press when there are phone call is in idle state
       
   282      *      
       
   283      */
       
   284     void HandleNoneHookPressL();
       
   285 
       
   286     /**
       
   287      * ReleasePressedVolumeKeys
       
   288      * Release volume keys if they are pressed
       
   289      *     
       
   290      * @param aReportTranslator HID report translator
       
   291      */
       
   292     void ReleasePressedVolumeKeys( TReportTranslator& aReportTranslator );
       
   293 
       
   294     /**
       
   295      * ReleasePressedScanKeys
       
   296      * Release scan keys if they are pressed
       
   297      *     
       
   298      * @param aReportTranslator HID report report translator     
       
   299      */
       
   300     void ReleasePressedScanKeys( TReportTranslator& aReportTranslator );
       
   301     /**
       
   302      * HandleAlarmHookReleaseL
       
   303      * Handle hook release when phone is alarming
       
   304      *     
       
   305      */
       
   306     void HandleAlarmHookReleaseL();
       
   307 
       
   308     /**
       
   309      * HandleIdleHookReleaseL
       
   310      * Handle hook release when phone is not alarming 
       
   311      * and call is in idle state
       
   312      *  
       
   313      */
       
   314     void HandleIdleHookReleaseL();
       
   315 
       
   316     /**
       
   317      * Handle doubleclick timer expiration
       
   318      *      
       
   319      */
       
   320     void ExpiredDoubleClickTimer();
       
   321 
       
   322     /**
       
   323      * Handle long press timer expiration
       
   324      *      
       
   325      */
       
   326     void ExpiredLongClickTimer();
       
   327 
       
   328     /**
       
   329      * Handle scan next pressed
       
   330      *      
       
   331      */
       
   332     void HandleScanNextPressL();
       
   333 
       
   334     /**
       
   335      * Handle scan prev pressed
       
   336      *      
       
   337      */
       
   338     void HandleScanPrevPressL();
       
   339 
       
   340     /**
       
   341      * Handle scan next release  
       
   342      *   
       
   343      * @param aKeyCode a Key id
       
   344      * @param aValue  a Key value      
       
   345      */
       
   346     void HandleScanNextRelease( TUint& aKeyCode, TInt& aValue );
       
   347 
       
   348     /**
       
   349      * Handle scan previous release  
       
   350      *    
       
   351      * @param aKeyCode a Key id
       
   352      * @param aValue a Key value    
       
   353      */
       
   354     void HandleScanPreviousRelease( TUint& aKeyCode, TInt& aValue );
       
   355 
       
   356     /**
       
   357      * Handle telephony usage page
       
   358      *   
       
   359      * @param aReport a Report translator
       
   360      * @return KErrNone if report can be handled.  
       
   361      */
       
   362     TInt HandleTelephonyUsage( TReportTranslator& aReport );
       
   363 
       
   364     /**
       
   365      * Handle controller usage page
       
   366      *    
       
   367      * @param aReport a Report translator
       
   368      * @return KErrNone if report can be handled.  
       
   369      */
       
   370     TInt HandleControlUsage( TReportTranslator& aReport );
       
   371 
       
   372     /**
       
   373      * Handle volume usage
       
   374      *    
       
   375      * @param aReport a Report translator
       
   376      * @return KErrNone if report can be handled.  
       
   377      */
       
   378     TInt HandleVolumeUsage( TReportTranslator& aReport );
       
   379 
       
   380 private:
       
   381 
       
   382     /**
       
   383      * The Generic HID layer
       
   384      * Not own.
       
   385      */
       
   386     MDriverAccess *iGenericHid;
       
   387 
       
   388     /**
       
   389      * Field list array
       
   390      * Own. 
       
   391      */
       
   392     RPointerArray<CField> iFieldList;
       
   393 
       
   394     /**
       
   395      * Driver state
       
   396      */
       
   397     THeadsetDriverState iDriverState;
       
   398 
       
   399     /**
       
   400      * Connection id
       
   401      */
       
   402     TInt iConnectionId;
       
   403 
       
   404     /**
       
   405      * Application menu id 
       
   406      */
       
   407     TInt iAppMenuId;
       
   408 
       
   409     /**
       
   410      * On hook status 
       
   411      */
       
   412     TBool iOnHookPressed;
       
   413 
       
   414     /**
       
   415      * Off hook 
       
   416      */
       
   417     TBool iOffHookPressed;
       
   418 
       
   419     /**
       
   420      * No active calls
       
   421      */
       
   422     TBool iNoneHookPressed;
       
   423 
       
   424     /**
       
   425      * Telephony service
       
   426      * Own.
       
   427      */
       
   428     CTelephony* iTelephony;
       
   429 
       
   430     /**
       
   431      * Double click timer
       
   432      * Own.
       
   433      */
       
   434     CKeyPressTimer* iDoubleClicktimer;
       
   435 
       
   436     /**
       
   437      * Long click timer
       
   438      * Own.
       
   439      */
       
   440     CKeyPressTimer* iLongClicktimer;
       
   441 
       
   442     /**
       
   443      * Long click timer     
       
   444      */
       
   445     TBool iLongPress;
       
   446 
       
   447     /**
       
   448      * Alarm server session     
       
   449      */
       
   450     RASCliSession iAlarmServerSession;
       
   451 
       
   452     /**
       
   453      * Incoming call status
       
   454      */
       
   455      TBool iIncomingCallStatus;
       
   456 
       
   457     /**
       
   458      * Alarm statusd     
       
   459      */
       
   460     TBool iAlarmStatus;
       
   461 
       
   462     /**
       
   463      * Music player utility
       
   464      * Own.     
       
   465      */
       
   466     MMPXPlaybackUtility* iMusicPlayer;
       
   467 
       
   468     /**
       
   469      * Playing status     
       
   470      */
       
   471     TBool iPlayingStatus;
       
   472 
       
   473     /**
       
   474      * Double next Click  status
       
   475      */
       
   476     TBool iDoubleNextClick;
       
   477 
       
   478     /**
       
   479      * Count of supported fields
       
   480      */
       
   481     TInt iSupportedFieldCount;
       
   482 
       
   483     /**
       
   484      * Volume up key pressed down
       
   485      */
       
   486     TBool iVolumeUpPressed;
       
   487 
       
   488     /**
       
   489      * Volume down key pressed down
       
   490      */
       
   491     TBool iVolumeDownPressed;
       
   492 
       
   493     /**
       
   494      * Forward press status
       
   495      */
       
   496     TScanStatus iForwardStatus;
       
   497 
       
   498     /**
       
   499      * Backward press status
       
   500      */
       
   501     TScanStatus iBackwardStatus;
       
   502 
       
   503     /**
       
   504      * Scan next timer
       
   505      * Own.
       
   506      */
       
   507     CKeyPressTimer* iScanNextTimer;
       
   508 
       
   509     /**
       
   510      * Scan previous timer
       
   511      * Own.
       
   512      */
       
   513     CKeyPressTimer* iScanPreviousTimer;
       
   514 
       
   515     /**
       
   516      * Input handling reg
       
   517      * Not own.
       
   518      */
       
   519     CHidInputDataHandlingReg* iInputHandlingReg;
       
   520 
       
   521     };
       
   522 
       
   523 #endif