localconnectivityservice/headset/src/headset.cpp
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:  Generic hid implementation
       
    15  *
       
    16 */
       
    17 
       
    18 
       
    19 #include <etel3rdparty.h>
       
    20 #include <e32std.h>
       
    21 #include <e32svr.h>
       
    22 #include <coedef.h>
       
    23 #include <eiksvdef.h>
       
    24 #include <apgcli.h>
       
    25 #include <apgtask.h>
       
    26 #include <e32property.h>
       
    27 #ifdef NO101APPDEPFIXES
       
    28 #include <alarmuidomainpskeys.h>
       
    29 #else   //NO101APPDEPFIXES
       
    30 const TUid KPSUidAlarmExtCntl = { 0x102072D4 }; // reusing an AlarmUI dll UID
       
    31 const TUint32 KAlarmStopKey = 0x00000001;
       
    32 enum TAlarmUIStopAlarm
       
    33     {
       
    34     EAlarmUIStopAlarmUninitialized = 0,
       
    35     EAlarmUIStopAlarm
       
    36     };
       
    37 const TUint32 KAlarmSnoozeKey = 0x00000002;
       
    38 enum TAlarmUISnoozeAlarm
       
    39     {
       
    40     EAlarmUISnoozeAlarmUninitialized = 0,
       
    41     EAlarmUISnoozeAlarm
       
    42     };
       
    43 #endif  //NO101APPDEPFIXES
       
    44 
       
    45 #include <mpxplaybackmessage.h>
       
    46 #include <mpxmessagegeneraldefs.h>
       
    47 #include <mpxplaybackmessagedefs.h>
       
    48 
       
    49 #include "hidremconbearerinternalpskeys.h"
       
    50 #include "hidremconbearerscancodes.h"
       
    51 #include "headset.h"
       
    52 #include "finder.h"
       
    53 
       
    54 #include "debug.h"
       
    55 
       
    56 const TInt KHidUndefinedKeyCode = 0;
       
    57 const TInt KHidNotSetKeyValue = 0;
       
    58 const TInt KDoubleClickTimeout = 900000; // 0,9 seconds
       
    59 const TInt KDoubleClickTimeoutRing = 500000; // 0,5 seconds
       
    60 const TInt KScanClickTimeout = 500000; // 0,5 seconds
       
    61 const TInt KLongClickTimeout = 3000000; // 3 seconds
       
    62 
       
    63 // ======== MEMBER FUNCTIONS ========
       
    64 
       
    65 // ---------------------------------------------------------------------------
       
    66 // CHidHeadsetDriver()
       
    67 // ---------------------------------------------------------------------------
       
    68 //
       
    69 CHidHeadsetDriver::CHidHeadsetDriver( MDriverAccess* aGenericHid ) :
       
    70     iGenericHid( aGenericHid ), iFieldList(), iDriverState( EUninitialised ),
       
    71             iConnectionId( 0 ), iSupportedFieldCount( 0 ), iForwardStatus(
       
    72                     EScanNotPressed ), iBackwardStatus( EScanNotPressed )
       
    73     {
       
    74     TRACE_FUNC_ENTRY_THIS
       
    75     TRACE_FUNC_EXIT
       
    76     }
       
    77 
       
    78 // ---------------------------------------------------------------------------
       
    79 // NewLC
       
    80 // ---------------------------------------------------------------------------
       
    81 //
       
    82 CHidHeadsetDriver* CHidHeadsetDriver::NewLC( MDriverAccess* aGenericHid )
       
    83     {
       
    84     TRACE_INFO((_L("[HID]\tCHidHeadsetDriver::NewLC(0x%08x)"), aGenericHid));
       
    85     CHidHeadsetDriver* self = new ( ELeave ) CHidHeadsetDriver( aGenericHid );
       
    86     CleanupStack::PushL( self );
       
    87     self->ConstructL();
       
    88     return self;
       
    89     }
       
    90 
       
    91 // ---------------------------------------------------------------------------
       
    92 // NewL
       
    93 // ---------------------------------------------------------------------------
       
    94 //
       
    95 CHidHeadsetDriver* CHidHeadsetDriver::NewL( MDriverAccess* aGenericHid )
       
    96     {
       
    97     CHidHeadsetDriver* self = CHidHeadsetDriver::NewLC( aGenericHid );
       
    98     CleanupStack::Pop();
       
    99     return self;
       
   100     }
       
   101 
       
   102 // ---------------------------------------------------------------------------
       
   103 // ConstructL()
       
   104 // ---------------------------------------------------------------------------
       
   105 //
       
   106 void CHidHeadsetDriver::ConstructL()
       
   107     {
       
   108     TRACE_FUNC_THIS
       
   109     iTelephony = CTelephony::NewL();
       
   110     User::LeaveIfError( iAlarmServerSession.Connect() );
       
   111     iMusicPlayer = MMPXPlaybackUtility::UtilityL( KPbModeActivePlayer );
       
   112     iMusicPlayer->AddObserverL( *this );
       
   113     }
       
   114 
       
   115 // ---------------------------------------------------------------------------
       
   116 // Destructor
       
   117 // ---------------------------------------------------------------------------
       
   118 //
       
   119 CHidHeadsetDriver::~CHidHeadsetDriver()
       
   120     {
       
   121     TRACE_FUNC_THIS
       
   122     iAlarmServerSession.Close();
       
   123     delete iTelephony;
       
   124     iFieldList.Reset();
       
   125     iFieldList.Close();
       
   126     delete iDoubleClicktimer;
       
   127     if ( iMusicPlayer )
       
   128         {
       
   129         iMusicPlayer->Close();
       
   130         }
       
   131     delete iScanPreviousTimer;
       
   132     delete iScanNextTimer;
       
   133     delete iLongClicktimer;
       
   134     }
       
   135 
       
   136 // ---------------------------------------------------------------------------
       
   137 // From class CHidDriver
       
   138 // StartL()
       
   139 // ---------------------------------------------------------------------------
       
   140 //
       
   141 void CHidHeadsetDriver::StartL( TInt /*aConnectionId*/)
       
   142     {
       
   143     TRACE_FUNC
       
   144     // Ready to process headset events:
       
   145     iDriverState = EInitialised;
       
   146     }
       
   147 
       
   148 // ---------------------------------------------------------------------------
       
   149 // From class CHidDriver
       
   150 // InitialiseL()
       
   151 // ---------------------------------------------------------------------------
       
   152 //
       
   153 void CHidHeadsetDriver::InitialiseL( TInt aConnectionId )
       
   154     {
       
   155     TRACE_FUNC
       
   156     TRACE_INFO((_L("[HID]\tCHidHeadsetDriver::InitialiseL(%d)"),
       
   157                         aConnectionId));
       
   158     // Store the connection ID:
       
   159     iConnectionId = aConnectionId;
       
   160     }
       
   161 
       
   162 // ---------------------------------------------------------------------------
       
   163 // From class CHidDriver
       
   164 // Stop()
       
   165 // ---------------------------------------------------------------------------
       
   166 //
       
   167 void CHidHeadsetDriver::Stop()
       
   168     {
       
   169     TRACE_FUNC
       
   170     iDriverState = EDisabled;
       
   171     }
       
   172 
       
   173 // ---------------------------------------------------------------------------
       
   174 // From class CHidDriver
       
   175 // DataIn()
       
   176 // ---------------------------------------------------------------------------
       
   177 //
       
   178 TInt CHidHeadsetDriver::DataIn( CHidTransport::THidChannelType aChannel,
       
   179         const TDesC8& aPayload )
       
   180     {
       
   181     TInt retVal = KErrNone;
       
   182     switch ( aChannel )
       
   183         {
       
   184         case CHidTransport::EHidChannelInt:
       
   185             if ( EInitialised == iDriverState )
       
   186                 {
       
   187                 retVal = InterruptData( aPayload );
       
   188                 }
       
   189             break;
       
   190 
       
   191         case CHidTransport::EHidChannelCtrl:
       
   192             retVal = KErrNotSupported;
       
   193             break;
       
   194 
       
   195         default:
       
   196             retVal = KErrNotSupported;
       
   197             break;
       
   198         }
       
   199     return retVal;
       
   200     }
       
   201 
       
   202 // ---------------------------------------------------------------------------
       
   203 // From class CHidDriver
       
   204 // CommandResult()
       
   205 // ---------------------------------------------------------------------------
       
   206 //
       
   207 void CHidHeadsetDriver::CommandResult( TInt /*aCmdAck*/)
       
   208     {
       
   209     // No implementation as we don't issue any requests to be acknowledged
       
   210     }
       
   211 
       
   212 // ---------------------------------------------------------------------------
       
   213 // From class CHidDriver
       
   214 // Disconnected()
       
   215 // ---------------------------------------------------------------------------
       
   216 //
       
   217 void CHidHeadsetDriver::Disconnected( TInt aReason )
       
   218     {
       
   219     TRACE_INFO((_L("[HID]\tCHidHeadsetDriver::Disconnected(%d)"), aReason));
       
   220     aReason = aReason;
       
   221     Stop();
       
   222     }
       
   223 
       
   224 // ---------------------------------------------------------------------------
       
   225 // From class CHidDriver
       
   226 // SetInputHandlingReg()
       
   227 // ---------------------------------------------------------------------------
       
   228 //
       
   229 void CHidHeadsetDriver::SetInputHandlingReg(
       
   230         CHidInputDataHandlingReg* aHandlingReg )
       
   231     {
       
   232     iInputHandlingReg = aHandlingReg;
       
   233     }
       
   234 
       
   235 // ---------------------------------------------------------------------------
       
   236 // From class CHidDriver
       
   237 // InterruptData()
       
   238 // ---------------------------------------------------------------------------
       
   239 //
       
   240 TInt CHidHeadsetDriver::InterruptData( const TDesC8& aPayload )
       
   241     {
       
   242     // If the report has a report ID, it is in the first byte.
       
   243     // If not, this value is ignored (see CField::IsInReport()).
       
   244     //
       
   245     TInt retVal = KErrNone;
       
   246     TInt ret = KErrNotSupported;
       
   247     TInt firstByte = aPayload[0];
       
   248 
       
   249     TRACE_INFO((_L("[HID]\tCHidHeadsetDriver::InterruptData(), report \
       
   250             0x%x (%d), length %d"),firstByte, firstByte, aPayload.Length()));
       
   251 
       
   252     if ( iFieldList.Count() == 0 )
       
   253         {
       
   254         retVal = KErrNotSupported;
       
   255         }
       
   256     for ( TInt i = 0; i < iFieldList.Count(); i++ )
       
   257         {
       
   258         if ( iFieldList[i]->IsInReport( firstByte ) )
       
   259             {
       
   260             ret = HandleReport( aPayload, iFieldList[i] );
       
   261             if ( ret == KErrNone )
       
   262                 {
       
   263                 retVal = KErrNone;
       
   264                 }
       
   265             }
       
   266         else
       
   267             {
       
   268             retVal = KErrNotSupported;
       
   269             }
       
   270         }
       
   271     return retVal;
       
   272     }
       
   273 
       
   274 // ---------------------------------------------------------------------------
       
   275 // HandleReport()
       
   276 // ---------------------------------------------------------------------------
       
   277 //
       
   278 TInt CHidHeadsetDriver::HandleReport( const TDesC8& aReport,
       
   279         const CField* aField )
       
   280     {
       
   281     TRACE_FUNC_ENTRY
       
   282     TReportTranslator report( aReport, aField );
       
   283     TInt retVal = KErrNotSupported;
       
   284 
       
   285     // release if key if it pressed and relased
       
   286     ReleasePressedKeys( report );
       
   287 
       
   288     if ( HandleTelephonyUsage( report ) == KErrNone )
       
   289         {
       
   290         retVal = KErrNone;
       
   291         }
       
   292 
       
   293     if ( HandleControlUsage( report ) == KErrNone )
       
   294         {
       
   295         retVal = KErrNone;
       
   296         }
       
   297 
       
   298     if ( HandleVolumeUsage( report ) == KErrNone )
       
   299         {
       
   300         retVal = KErrNone;
       
   301         }
       
   302     TRACE_FUNC_EXIT
       
   303     return retVal;
       
   304     }
       
   305 
       
   306 // ---------------------------------------------------------------------------
       
   307 // HandleTelephonyUsage()
       
   308 // ---------------------------------------------------------------------------
       
   309 //
       
   310 TInt CHidHeadsetDriver::HandleTelephonyUsage( TReportTranslator& aReport )
       
   311     {
       
   312     TRACE_FUNC_ENTRY
       
   313     TInt retVal = KErrNotSupported;
       
   314     TInt hookSwitch = 0;
       
   315     TInt mute = 0;
       
   316     TInt poc = 0;
       
   317 
       
   318     // P&S key variables
       
   319     TUint key = KHidUndefinedKeyCode;
       
   320     TInt value = KHidNotSetKeyValue;
       
   321 
       
   322     if ( aReport.GetValue( mute, ETelephonyUsagePhoneMute ) == KErrNone
       
   323             && mute == 1 )
       
   324         {
       
   325         TRACE_INFO(_L("[HID]\tCHidHeadsetDriver::HandleReport(): Send mute \
       
   326                 command"));
       
   327         if ( iInputHandlingReg->AllowedToHandleEvent( EUsagePageTelephony,
       
   328                 ETelephonyUsagePhoneMute ) )
       
   329             {
       
   330             key = KHidMuteKeyEvent;
       
   331             value = KPSMuteClicked;
       
   332             iInputHandlingReg->AddHandledEvent( EUsagePageTelephony,
       
   333                     ETelephonyUsagePhoneMute );
       
   334             }
       
   335         }
       
   336     else if ( aReport.GetValue( hookSwitch, ETelephonyUsageHookSwitch )
       
   337             == KErrNone && hookSwitch == 1 )
       
   338         {
       
   339         TRACE_INFO(_L("[HID]\tCHidHeadsetDriver::HandleReport(): Send hook \
       
   340                 switch command (disabled)"));
       
   341         if ( iInputHandlingReg->AllowedToHandleEvent( EUsagePageTelephony,
       
   342                 ETelephonyUsageHookSwitch ) )
       
   343             {
       
   344             HookKeyPres( ETrue );
       
   345             iInputHandlingReg->AddHandledEvent( EUsagePageTelephony,
       
   346                     ETelephonyUsageHookSwitch );
       
   347             }
       
   348         }
       
   349     else if ( aReport.GetValue( poc, ETelephonyUsagePoC ) == KErrNone && poc
       
   350             == 1 )
       
   351         {
       
   352         TRACE_INFO(_L("[HID]\tCHidHeadsetDriver::HandleReport(): Send PoC \
       
   353                 command (disabled)"));
       
   354         if ( iInputHandlingReg->AllowedToHandleEvent( EUsagePageTelephony,
       
   355                 ETelephonyUsagePoC ) )
       
   356             {
       
   357             key = KHidMuteKeyEvent;
       
   358             value = KPSMuteClicked;
       
   359             iInputHandlingReg->AddHandledEvent( EUsagePageTelephony,
       
   360                     ETelephonyUsagePoC );
       
   361             }
       
   362         }
       
   363     if ( key != KHidUndefinedKeyCode && value != KHidNotSetKeyValue )
       
   364         {
       
   365         TInt err = RProperty::Set( KPSUidHidEventNotifier, key, value );
       
   366         retVal = KErrNone;
       
   367         }
       
   368 
       
   369     TRACE_FUNC_EXIT
       
   370     return retVal;
       
   371     }
       
   372 
       
   373 // ---------------------------------------------------------------------------
       
   374 // HandleTelephonyUsage()
       
   375 // ---------------------------------------------------------------------------
       
   376 //
       
   377 TInt CHidHeadsetDriver::HandleControlUsage( TReportTranslator& aReport )
       
   378     {
       
   379     TRACE_FUNC_ENTRY
       
   380     TInt retVal = KErrNotSupported;
       
   381     TInt playPause = 0;
       
   382     TInt scanNext = 0;
       
   383     TInt scanPrev = 0;
       
   384     TInt stop = 0;
       
   385 
       
   386     // P&S key variables
       
   387     TUint key = KHidUndefinedKeyCode;
       
   388     TInt value = KHidNotSetKeyValue;
       
   389 
       
   390     if ( aReport.GetValue( playPause, EConsumerUsagePlayPause ) == KErrNone
       
   391             && playPause )
       
   392         {
       
   393         if ( iInputHandlingReg->AllowedToHandleEvent( EUsagePageConsumer,
       
   394                 EConsumerUsagePlayPause ) )
       
   395             {
       
   396             TRACE_INFO(_L("[HID]\tCHidHeadsetDriver::HandleReport(): Send \
       
   397                     play/pause command (currently only play)"));
       
   398             key = KHidControlKeyEvent;
       
   399             value = EPlayClicked;
       
   400             iInputHandlingReg->AddHandledEvent( EUsagePageConsumer,
       
   401                     EConsumerUsagePlayPause );
       
   402             }
       
   403         }
       
   404     else if ( aReport.GetValue( scanNext, EConsumerUsageScanNext )
       
   405             == KErrNone && scanNext )
       
   406         {
       
   407         if ( iInputHandlingReg->AllowedToHandleEvent( EUsagePageConsumer,
       
   408                 EConsumerUsageScanNext ) )
       
   409             {
       
   410             TRACE_INFO(_L("[HID]\tCHidHeadsetDriver::HandleReport(): Send \
       
   411                     scan next command"));
       
   412             TRAP_IGNORE( HandleScanNextPressL() );
       
   413             iInputHandlingReg->AddHandledEvent( EUsagePageConsumer,
       
   414                     EConsumerUsageScanNext );
       
   415             }
       
   416         }
       
   417     else if ( aReport.GetValue( scanPrev, EConsumerUsageScanPrev )
       
   418             == KErrNone && scanPrev )
       
   419         {
       
   420         if ( iInputHandlingReg->AllowedToHandleEvent( EUsagePageConsumer,
       
   421                 EConsumerUsageScanPrev ) )
       
   422             {
       
   423             TRACE_INFO(_L("[HID]\tCHidHeadsetDriver::HandleReport(): Scan \
       
   424                     prev command"));
       
   425             TRAP_IGNORE( HandleScanPrevPressL());
       
   426             iInputHandlingReg->AddHandledEvent( EUsagePageConsumer,
       
   427                     EConsumerUsageScanPrev );
       
   428             }
       
   429         }
       
   430     else if ( aReport.GetValue( stop, EConsumerUsageStop ) == KErrNone
       
   431             && stop )
       
   432         {
       
   433         if ( iInputHandlingReg->AllowedToHandleEvent( EUsagePageConsumer,
       
   434                 EConsumerUsageStop ) )
       
   435             {
       
   436             TRACE_INFO(_L("[HID]\tCHidHeadsetDriver::HandleReport(): Send \
       
   437                     stop command"));
       
   438             key = KHidControlKeyEvent;
       
   439             value = EStopClicked;
       
   440             iInputHandlingReg->AddHandledEvent( EUsagePageConsumer,
       
   441                     EConsumerUsageScanPrev );
       
   442             }
       
   443         }
       
   444     if ( key != KHidUndefinedKeyCode && value != KHidNotSetKeyValue )
       
   445         {
       
   446         TInt err = RProperty::Set( KPSUidHidEventNotifier, key, value );
       
   447         retVal = KErrNone;
       
   448         }
       
   449 
       
   450     TRACE_FUNC_EXIT
       
   451     return retVal;
       
   452     }
       
   453 
       
   454 // ---------------------------------------------------------------------------
       
   455 // HandleVolumeUsage()
       
   456 // ---------------------------------------------------------------------------
       
   457 //
       
   458 TInt CHidHeadsetDriver::HandleVolumeUsage( TReportTranslator& aReport )
       
   459     {
       
   460     TRACE_FUNC_ENTRY
       
   461     TInt retVal = KErrNotSupported;
       
   462 
       
   463     TInt volUp = 0;
       
   464     TInt volDown = 0;
       
   465     TInt speakermute = 0;
       
   466 
       
   467     // P&S key variables
       
   468     TUint key = KHidUndefinedKeyCode;
       
   469     TInt value = KHidNotSetKeyValue;
       
   470 
       
   471     if ( aReport.GetValue( volUp, EConsumerUsageVolumeInc ) == KErrNone
       
   472             && volUp )
       
   473         {
       
   474         if ( iInputHandlingReg->AllowedToHandleEvent( EUsagePageConsumer,
       
   475                 EConsumerUsageVolumeInc ) )
       
   476             {
       
   477             TRACE_INFO(_L("[HID]\tCHidHeadsetDriver::HandleReport(): \
       
   478                     Send volume up command"));
       
   479             key = KHidAccessoryVolumeEvent;
       
   480             iVolumeUpPressed = ETrue;
       
   481             value = KPSVolumeUpPressed;
       
   482             iInputHandlingReg->AddHandledEvent( EUsagePageConsumer,
       
   483                     EConsumerUsageScanPrev );
       
   484             }
       
   485         }
       
   486     else if ( aReport.GetValue( volDown, EConsumerUsageVolumeDec )
       
   487             == KErrNone && volDown )
       
   488         {
       
   489         if ( iInputHandlingReg->AllowedToHandleEvent( EUsagePageConsumer,
       
   490                 EConsumerUsageVolumeDec ) )
       
   491             {
       
   492             TRACE_INFO(_L("[HID]\tCHidHeadsetDriver::HandleReport(): Send \
       
   493                     volume down command"));
       
   494             key = KHidAccessoryVolumeEvent;
       
   495             iVolumeDownPressed = ETrue;
       
   496             value = KPSVolumeDownPressed;
       
   497             iInputHandlingReg->AddHandledEvent( EUsagePageConsumer,
       
   498                     EConsumerUsageVolumeDec );
       
   499             }
       
   500         }
       
   501     else if ( ( aReport.GetValue( speakermute, EConsumerUsageMute )
       
   502             == KErrNone && speakermute == 1 ) )
       
   503         {
       
   504         if ( iInputHandlingReg->AllowedToHandleEvent( EUsagePageConsumer,
       
   505                 EConsumerUsageMute ) )
       
   506             {
       
   507             TRACE_INFO(_L("[HID]\tCHidHeadsetDriver::HandleReport(): Send \
       
   508                     mute command"));
       
   509             key = KHidMuteKeyEvent;
       
   510             value = KPSMuteClicked;
       
   511             iInputHandlingReg->AddHandledEvent( EUsagePageConsumer,
       
   512                     EConsumerUsageMute );
       
   513             }
       
   514         }
       
   515 
       
   516     if ( key != KHidUndefinedKeyCode && value != KHidNotSetKeyValue )
       
   517         {
       
   518         TInt err = RProperty::Set( KPSUidHidEventNotifier, key, value );
       
   519         retVal = KErrNone;
       
   520         }
       
   521 
       
   522     TRACE_FUNC_EXIT
       
   523     return retVal;
       
   524     }
       
   525 
       
   526 // ---------------------------------------------------------------------------
       
   527 // HandleScanNextPressL()
       
   528 // ---------------------------------------------------------------------------
       
   529 //
       
   530 void CHidHeadsetDriver::HandleScanNextPressL()
       
   531     {
       
   532     TRACE_FUNC_ENTRY
       
   533     iForwardStatus = EScanPressed;
       
   534 
       
   535     delete iScanNextTimer;
       
   536     iScanNextTimer = NULL;
       
   537 
       
   538     /**
       
   539      * Scan key has two different behaviour if you are short click buttun or long 
       
   540      * click button. In short press next track command is sent and whit long press
       
   541      * is sending seek forward command. iScanNextTimer is used to detect if click
       
   542      * is long click or short click.
       
   543      */
       
   544 
       
   545     iScanNextTimer = CKeyPressTimer::NewL( this, TTimeIntervalMicroSeconds32(
       
   546             KScanClickTimeout ), EScanNextPressTimer );
       
   547 
       
   548     TRACE_FUNC_EXIT
       
   549     }
       
   550 
       
   551 // ---------------------------------------------------------------------------
       
   552 // HandleScanNextPressL()
       
   553 // ---------------------------------------------------------------------------
       
   554 //
       
   555 void CHidHeadsetDriver::HandleScanPrevPressL()
       
   556     {
       
   557     TRACE_FUNC_ENTRY
       
   558     iBackwardStatus = EScanPressed;
       
   559 
       
   560     delete iScanPreviousTimer;
       
   561     iScanPreviousTimer = NULL;
       
   562 
       
   563     /**
       
   564      * Scan key has two different behaviour if you are short click buttun or 
       
   565      * long click button. In short press previous track command is sent and 
       
   566      * whit long press is sending seek forward command. iScanPreviousTimer 
       
   567      * is used to detect if click is long click or short click.
       
   568      */
       
   569     iScanPreviousTimer = CKeyPressTimer::NewL( this,
       
   570             TTimeIntervalMicroSeconds32( KScanClickTimeout ),
       
   571             EScanPrevPressTimer );
       
   572     TRACE_FUNC_EXIT
       
   573     }
       
   574 
       
   575 // ---------------------------------------------------------------------------
       
   576 // ReleasePressedVolumeKeys
       
   577 // ---------------------------------------------------------------------------
       
   578 //
       
   579 void CHidHeadsetDriver::ReleasePressedVolumeKeys(
       
   580         TReportTranslator& aReportTranslator )
       
   581     {
       
   582     TInt volUp = 0;
       
   583     TInt volDown = 0;
       
   584     TUint key = KHidUndefinedKeyCode;
       
   585     TInt value = KHidNotSetKeyValue;
       
   586 
       
   587     if ( iVolumeUpPressed )
       
   588         {
       
   589         if ( aReportTranslator.GetValue( volUp, EConsumerUsageVolumeInc )
       
   590                 == KErrNone && volDown == 0 )
       
   591             {
       
   592             TRACE_INFO(_L("[HID]\tCHidHeadsetDriver::ReleasepressedKeys(): \
       
   593                     Volume up released"));
       
   594             key = KHidAccessoryVolumeEvent;
       
   595             iVolumeUpPressed = EFalse;
       
   596             value = KPSVolumeUpReleased;
       
   597             }
       
   598         }
       
   599     else if ( iVolumeDownPressed )
       
   600         {
       
   601         if ( aReportTranslator.GetValue( volDown, EConsumerUsageVolumeDec )
       
   602                 == KErrNone && volDown == 0 )
       
   603             {
       
   604             TRACE_INFO(_L("[HID]\tCHidHeadsetDriver::ReleasepressedKeys(): \
       
   605                     Volume downkey realeased"));
       
   606             key = KHidAccessoryVolumeEvent;
       
   607             iVolumeDownPressed = EFalse;
       
   608             value = KPSVolumeDownReleased;
       
   609             }
       
   610         }
       
   611     if ( key != KHidUndefinedKeyCode && value != KHidNotSetKeyValue )
       
   612         {
       
   613         TInt err = RProperty::Set( KPSUidHidEventNotifier, key, value );
       
   614 
       
   615         }
       
   616     }
       
   617 
       
   618 // ---------------------------------------------------------------------------
       
   619 // ReleasePressedScanKeys()
       
   620 // ---------------------------------------------------------------------------
       
   621 //
       
   622 void CHidHeadsetDriver::ReleasePressedScanKeys(
       
   623         TReportTranslator& aReportTranslator )
       
   624     {
       
   625     TInt scanNext = 0;
       
   626     TInt scanPrev = 0;
       
   627     TUint key = KHidUndefinedKeyCode;
       
   628     TInt value = KHidNotSetKeyValue;
       
   629 
       
   630     if ( iForwardStatus != EScanNotPressed )
       
   631         {
       
   632         if ( aReportTranslator.GetValue( scanNext, EConsumerUsageScanNext )
       
   633                 == KErrNone && scanNext == 0 )
       
   634             {
       
   635             TRACE_INFO(_L("[HID]\tCHidHeadsetDriver::HandleReport(): Scan \
       
   636                     next command released"));
       
   637             HandleScanNextRelease( key, value );
       
   638             }
       
   639         }
       
   640     else if ( iBackwardStatus != EScanNotPressed )
       
   641         {
       
   642         if ( aReportTranslator.GetValue( scanPrev, EConsumerUsageScanPrev )
       
   643                 == KErrNone && scanPrev == 0 )
       
   644             {
       
   645             TRACE_INFO(_L("[HID]\tCHidHeadsetDriver::HandleReport(): Scan \
       
   646                     prev command released"));
       
   647             HandleScanPreviousRelease( key, value );
       
   648             }
       
   649         }
       
   650     if ( key != KHidUndefinedKeyCode && value != KHidNotSetKeyValue )
       
   651         {
       
   652         TInt err = RProperty::Set( KPSUidHidEventNotifier, key, value );
       
   653         }
       
   654     }
       
   655 // ---------------------------------------------------------------------------
       
   656 // ReleasePressedKeys()
       
   657 // ---------------------------------------------------------------------------
       
   658 //
       
   659 void CHidHeadsetDriver::ReleasePressedKeys(
       
   660         TReportTranslator& aReportTranslator )
       
   661     {
       
   662     TRACE_FUNC_ENTRY
       
   663 
       
   664     TInt hookSwitch = 0;
       
   665     /*
       
   666      * Check hook key release here, because hook key long press
       
   667      * is handled different way.
       
   668      */
       
   669     if ( iOnHookPressed || iOffHookPressed || iNoneHookPressed )
       
   670         {
       
   671         if ( aReportTranslator.GetValue( hookSwitch,
       
   672                 ETelephonyUsageHookSwitch ) == KErrNone && hookSwitch == 0 )
       
   673             {
       
   674             ReleaseHookKey();
       
   675             }
       
   676         }
       
   677     ReleasePressedVolumeKeys( aReportTranslator );
       
   678 
       
   679     ReleasePressedScanKeys( aReportTranslator );
       
   680 
       
   681     TRACE_FUNC_EXIT
       
   682     }
       
   683 
       
   684 // ---------------------------------------------------------------------------
       
   685 // HandleScanNextRelease()
       
   686 // ---------------------------------------------------------------------------
       
   687 //
       
   688 void CHidHeadsetDriver::HandleScanNextRelease( TUint& aKeyCode, TInt& aValue )
       
   689     {
       
   690     TRACE_FUNC_ENTRY
       
   691     aKeyCode = KHidControlKeyEvent;
       
   692     if ( iForwardStatus == EScanPressed )
       
   693         {
       
   694         aValue = EForwardClicked;
       
   695         }
       
   696     else //long press
       
   697         {
       
   698         aValue = EFastForwardReleased;
       
   699         }
       
   700     iForwardStatus = EScanNotPressed;
       
   701 
       
   702     delete iScanNextTimer;
       
   703     iScanNextTimer = NULL;
       
   704 
       
   705     TRACE_FUNC_EXIT
       
   706     }
       
   707 
       
   708 // ---------------------------------------------------------------------------
       
   709 // HandleScanPreviousRelease()
       
   710 // ---------------------------------------------------------------------------
       
   711 //
       
   712 void CHidHeadsetDriver::HandleScanPreviousRelease( TUint& aKeyCode,
       
   713         TInt& aValue )
       
   714     {
       
   715     TRACE_INFO(_L("[HID]\tCHidHeadsetDriver::HandleReport(): Scan prev \
       
   716             command released"));
       
   717     aKeyCode = KHidControlKeyEvent;
       
   718     if ( iBackwardStatus == EScanPressed )
       
   719         {
       
   720         aValue = EBackwardClicked;
       
   721         }
       
   722     else //long press
       
   723         {
       
   724         aValue = ERewindReleased;
       
   725         }
       
   726     iBackwardStatus = EScanNotPressed;
       
   727 
       
   728     delete iScanPreviousTimer;
       
   729     iScanPreviousTimer = NULL;
       
   730 
       
   731     TRACE_FUNC_EXIT
       
   732     }
       
   733 // ---------------------------------------------------------------------------
       
   734 // HookKeyPres()
       
   735 // ---------------------------------------------------------------------------
       
   736 //
       
   737 void CHidHeadsetDriver::HookKeyPres( TBool aStatus )
       
   738     {
       
   739     TRACE_FUNC_ENTRY
       
   740 
       
   741     THookHandling hookStatus = HookStatus();
       
   742     if ( !iAlarmStatus )
       
   743         {
       
   744         iAlarmStatus = AlarmStatus();
       
   745         }
       
   746 
       
   747     iPlayingStatus = MusicPlayingStatus();
       
   748 
       
   749     if ( aStatus )
       
   750         {
       
   751         switch ( hookStatus )
       
   752             {
       
   753             case EOnHook:
       
   754                 if ( !iIncomingCallStatus )
       
   755                     {
       
   756                     // For the first click, trigger the timer 
       
   757                     // single click is handled in ExpiredDoubleClickTimer
       
   758                     if ( iDoubleClicktimer )
       
   759                         {
       
   760                         delete iDoubleClicktimer;
       
   761                         iDoubleClicktimer = NULL;
       
   762                         }
       
   763                     TRAP_IGNORE( iDoubleClicktimer = CKeyPressTimer::NewL( this,
       
   764                         TTimeIntervalMicroSeconds32( KDoubleClickTimeoutRing ),
       
   765                         EDoubleClickTimer ) );
       
   766                     if ( iDoubleClicktimer )
       
   767                         {
       
   768                         iIncomingCallStatus = ETrue;
       
   769                         }
       
   770                     else // If fail to create timer, handle as single click, 
       
   771                     // for double click case, the next click will hang off
       
   772                         {
       
   773                         iIncomingCallStatus = EFalse;
       
   774                         iOnHookPressed = ETrue;
       
   775                         }
       
   776                     break; // switch
       
   777                     }
       
   778                 else
       
   779                     {
       
   780                     iIncomingCallStatus = EFalse;
       
   781                     if ( iDoubleClicktimer )
       
   782                         {
       
   783                         delete iDoubleClicktimer;
       
   784                         iDoubleClicktimer = NULL;
       
   785                         }
       
   786                     // This is the double click case, handle as EOffHook
       
   787                     }
       
   788                 // No break here
       
   789             case EOffHook:
       
   790                 TRACE_INFO(_L("[HID]\tCHidHeadsetDriver Hook Off Pressed"));
       
   791                 iOffHookPressed = ETrue;
       
   792                 break;
       
   793             case ENoHook:
       
   794                 TRACE_INFO(_L("[HID]\tCHidHeadsetDriver Hook None Pressed")); 
       
   795                 TRAP_IGNORE( HandleNoneHookPressL() );                
       
   796                 break;
       
   797             default:
       
   798                 TRACE_INFO(_L("CHidHeadsetDriver::HookKeyPres : Not \
       
   799                         supported"));                
       
   800             }
       
   801         }
       
   802     else
       
   803         {
       
   804         ReleaseHookKey();
       
   805         }
       
   806     TRACE_FUNC_EXIT
       
   807     }
       
   808 
       
   809 // ---------------------------------------------------------------------------
       
   810 // ReleaseHookKey()
       
   811 // ---------------------------------------------------------------------------
       
   812 //
       
   813 void CHidHeadsetDriver::ReleaseHookKey()
       
   814     {
       
   815     TRACE_FUNC_ENTRY
       
   816 
       
   817     if ( iOnHookPressed )
       
   818         {
       
   819         TRACE_INFO(_L("[HID]\tCHidHeadsetDriver Hook On released"));
       
   820         iOnHookPressed = EFalse;
       
   821         // Incoming call
       
   822         RProperty::Set( KPSUidHidEventNotifier, KHidHookKeyEvent,
       
   823                 KPSAnsweClicked );
       
   824         }
       
   825     if ( iOffHookPressed )
       
   826         {
       
   827         TRACE_INFO(_L("[HID]\tCHidHeadsetDriver Hook Off released"));
       
   828         iOffHookPressed = EFalse;
       
   829         // Disconnect connected call
       
   830         RProperty::Set( KPSUidHidEventNotifier, KHidHookKeyEvent,
       
   831                 KPSHangUpClicked );
       
   832         }
       
   833     if ( iNoneHookPressed && !iAlarmStatus )
       
   834         {
       
   835         TRAP_IGNORE( HandleIdleHookReleaseL() );
       
   836         }
       
   837     if ( iNoneHookPressed && iAlarmStatus )
       
   838         {
       
   839         TRAP_IGNORE( HandleAlarmHookReleaseL() );
       
   840         }
       
   841     if ( iLongClicktimer )
       
   842         {
       
   843         iLongPress = EFalse;
       
   844         }
       
   845     delete iLongClicktimer;
       
   846     iLongClicktimer = NULL;
       
   847     TRACE_FUNC_EXIT
       
   848     }
       
   849 
       
   850 // ---------------------------------------------------------------------------
       
   851 // HandleNoneHook()
       
   852 // ---------------------------------------------------------------------------
       
   853 //
       
   854 void CHidHeadsetDriver::HandleNoneHookPressL()
       
   855     {
       
   856     TRACE_FUNC_ENTRY
       
   857     /**  Start long press timer is alarm is ongoing, or phone
       
   858      *   is not alarming and thre are no hook key press whitout
       
   859      *   release
       
   860      */
       
   861     if ( iAlarmStatus || ( !iNoneHookPressed && !iAlarmStatus ) )
       
   862         {
       
   863         iNoneHookPressed = ETrue;
       
   864         iLongPress = EFalse;
       
   865 
       
   866         delete iLongClicktimer;
       
   867         iLongClicktimer = NULL;
       
   868 
       
   869         iLongClicktimer = CKeyPressTimer::NewL( this,
       
   870                 TTimeIntervalMicroSeconds32( KLongClickTimeout ),
       
   871                 ELongPressTimer );
       
   872         }
       
   873     TRACE_FUNC_EXIT
       
   874     }
       
   875 
       
   876 // ---------------------------------------------------------------------------
       
   877 // HandleAlarmHookReleaseL()
       
   878 // ---------------------------------------------------------------------------
       
   879 //
       
   880 void CHidHeadsetDriver::HandleAlarmHookReleaseL()
       
   881     {
       
   882     TRACE_FUNC_ENTRY
       
   883     TRACE_INFO(_L("[HID]\tCHidHeadsetDriver Hook None released"));
       
   884     /**
       
   885      * Hook key is released when there is active alarm. Start double
       
   886      * click timer for monitoring double click.
       
   887      */
       
   888     if ( !iDoubleClicktimer && !iLongPress )
       
   889         {
       
   890         iDoubleClicktimer = CKeyPressTimer::NewL( this,
       
   891                 TTimeIntervalMicroSeconds32( KDoubleClickTimeout ),
       
   892                 EDoubleClickTimer );
       
   893         }
       
   894     /**
       
   895      * Stot alar when hook key is pressed long time during alarm.
       
   896      */
       
   897     else if ( iLongPress )
       
   898         {
       
   899         TRACE_INFO(_L("[HID]\tCHidHeadsetDriver Stop alarm"));
       
   900         RProperty::Set( KPSUidAlarmExtCntl, KAlarmStopKey, 
       
   901                 EAlarmUIStopAlarm );
       
   902         iAlarmStatus = EFalse;
       
   903         iLongPress = EFalse;
       
   904         }
       
   905     /**
       
   906      * Double click timer exsist and is it not long press, so 
       
   907      * this is double click release. Then snooze alarm.
       
   908      */
       
   909     else if ( !iLongPress )
       
   910         {
       
   911         delete iDoubleClicktimer;
       
   912         iDoubleClicktimer = NULL;
       
   913         iAlarmStatus = EFalse;
       
   914         TRACE_INFO(_L("[HID]\tCHidHeadsetDriver Snooze"));
       
   915         RProperty::Set( KPSUidAlarmExtCntl, KAlarmSnoozeKey,
       
   916                 EAlarmUISnoozeAlarm );
       
   917         }
       
   918     TRACE_FUNC_EXIT
       
   919     }
       
   920 
       
   921 // ---------------------------------------------------------------------------
       
   922 // HandleIdleHookReleaseL
       
   923 // ---------------------------------------------------------------------------
       
   924 //
       
   925 void CHidHeadsetDriver::HandleIdleHookReleaseL()
       
   926     {
       
   927     TRACE_FUNC_ENTRY
       
   928     TRACE_INFO(_L("[HID]\tCHidHeadsetDriver Hook None released"));
       
   929     iNoneHookPressed = EFalse;
       
   930     /**
       
   931      * Hook key is released when there is music playing ongoing. Start double
       
   932      * click timer for monitoring double click.
       
   933      */
       
   934     if ( !iDoubleClicktimer && !iLongPress )
       
   935         {
       
   936         iDoubleClicktimer = CKeyPressTimer::NewL( this,
       
   937                 TTimeIntervalMicroSeconds32( KDoubleClickTimeout ),
       
   938                 EDoubleClickTimer );
       
   939         }
       
   940     /**
       
   941      * Hook key is released when there is not music playing ongoing. 
       
   942      * Because double click timer is active this is second release in
       
   943      * short beriod and redial needs to be issued.
       
   944      */
       
   945     else if ( !iLongPress && !iPlayingStatus )
       
   946         {
       
   947         delete iDoubleClicktimer;
       
   948         iDoubleClicktimer = NULL;
       
   949         TRACE_INFO(_L("[HID]\tCHidHeadsetDriver Redial"));
       
   950         RProperty::Set( KPSUidHidEventNotifier, KHidHookKeyEvent, 
       
   951                 KPSRedial );
       
   952         }
       
   953     /**
       
   954      * Hook key is released when there is music playing ongoing. 
       
   955      * Because double click timer is active, is send forward command sent
       
   956      * and DoubleNextClick set to true for sending next command.
       
   957      */
       
   958     else if ( iPlayingStatus && !iLongPress )
       
   959         {
       
   960         delete iDoubleClicktimer;
       
   961         iDoubleClicktimer = NULL;
       
   962         TRACE_INFO(_L("[HID]\tCHidHeadsetDriver next after next"));
       
   963         if ( !iLongPress )
       
   964             {
       
   965             iDoubleNextClick = ETrue; //set to true and when player change 
       
   966                                       //track press next again 
       
   967             }
       
   968         RProperty::Set( KPSUidHidEventNotifier, KHidControlKeyEvent,
       
   969                 EForwardClicked ); //next after next
       
   970         }
       
   971     /**
       
   972      * Long press release when there are no actie calls, alarms, and music
       
   973      * playing is stopped, activates voice dialing.
       
   974      */
       
   975     else if ( iLongPress )
       
   976         {
       
   977         delete iDoubleClicktimer;
       
   978         iDoubleClicktimer = NULL;
       
   979         TRACE_INFO(_L("[HID]\tCHidHeadsetDriver VoiceDial"));
       
   980         RProperty::Set( KPSUidHidEventNotifier, KHidHookKeyEvent,
       
   981                 KPSVoiceDial );
       
   982         iLongPress = EFalse;
       
   983         }
       
   984     TRACE_FUNC_EXIT
       
   985     }
       
   986 
       
   987 // ---------------------------------------------------------------------------
       
   988 // GetHookStatus()
       
   989 // ---------------------------------------------------------------------------
       
   990 //
       
   991 CHidHeadsetDriver::THookHandling CHidHeadsetDriver::HookStatus()
       
   992     {
       
   993     TRACE_FUNC_ENTRY
       
   994     THookHandling retVal = EOffHook;
       
   995     TInt ret = KErrNone;
       
   996     CTelephony::TCallStatusV1 callStatusV1;
       
   997     CTelephony::TCallStatusV1Pckg callStatusV1Pckg( callStatusV1 );
       
   998     ret = iTelephony->GetLineStatus( CTelephony::EVoiceLine,
       
   999                     callStatusV1Pckg );
       
  1000     if ( ret != KErrNone )
       
  1001         {
       
  1002         retVal = ENoHook;
       
  1003         }
       
  1004     CTelephony::TCallStatus voiceLineStatus = callStatusV1.iStatus;
       
  1005     TRACE_INFO((_L("[HID]\tCHidHeadsetDriver GetHookStatus voiceline \
       
  1006             status %d"), voiceLineStatus));
       
  1007 
       
  1008     if ( voiceLineStatus == CTelephony::EStatusHold || voiceLineStatus
       
  1009             == CTelephony::EStatusRinging )
       
  1010         {
       
  1011             TRACE_INFO(_L("[HID]\tCHidHeadsetDriver GetHookStatus on hook"));
       
  1012         retVal = EOnHook;
       
  1013         }
       
  1014     else if ( voiceLineStatus == CTelephony::EStatusUnknown
       
  1015             || voiceLineStatus == CTelephony::EStatusIdle )
       
  1016         {
       
  1017             TRACE_INFO(_L("[HID]\tCHidHeadsetDriver GetHookStatus no hook"));
       
  1018         retVal = ENoHook;
       
  1019         }
       
  1020         TRACE_FUNC_EXIT
       
  1021     return retVal;
       
  1022     }
       
  1023 
       
  1024 // ---------------------------------------------------------------------------
       
  1025 // From class CHidDriver
       
  1026 // CanHandleReportL()
       
  1027 // ---------------------------------------------------------------------------
       
  1028 //
       
  1029 TInt CHidHeadsetDriver::CanHandleReportL( CReportRoot* aReportRoot )
       
  1030     {
       
  1031     TRACE_INFO((_L("[HID]\tCHidHeadsetDriver::CanHandleReport(0x%08x)"),
       
  1032                         aReportRoot));
       
  1033 
       
  1034     THidFieldSearch search;
       
  1035 
       
  1036     THeadsetFinder headsetFinder;
       
  1037     search.SearchL( aReportRoot, &headsetFinder );
       
  1038 
       
  1039     iSupportedFieldCount = headsetFinder.FieldCount();
       
  1040     for ( TInt i = 0; i < headsetFinder.FieldCount(); i++ )
       
  1041         {
       
  1042         User::LeaveIfError( iFieldList.Append( headsetFinder.GetFieldAtIndex(
       
  1043                 i ) ) );
       
  1044         TRACE_INFO((_L("[HID]\tCHidHeadsetDriver::CanHandleReportL, field \
       
  1045                 pointer: 0x%08x"), iFieldList[i]));
       
  1046         }
       
  1047 
       
  1048     TInt valid = KErrHidUnrecognised;
       
  1049 
       
  1050     if ( headsetFinder.Found() )
       
  1051         {
       
  1052         valid = KErrNone;
       
  1053         }
       
  1054     // empty finder's field list before going out of scope.
       
  1055     headsetFinder.EmptyList();
       
  1056 
       
  1057     TRACE_INFO((_L("[HID]\tCHidHeadsetDriver::CanHandleReport() returning \
       
  1058             %d"), valid));
       
  1059     return valid;
       
  1060     }
       
  1061 
       
  1062 // ---------------------------------------------------------------------------
       
  1063 // From class CHidDriver
       
  1064 // SupportedFieldCount
       
  1065 // ---------------------------------------------------------------------------
       
  1066 //
       
  1067 TInt CHidHeadsetDriver::SupportedFieldCount()
       
  1068     {
       
  1069     return iSupportedFieldCount;
       
  1070     }
       
  1071 // ---------------------------------------------------------------------------
       
  1072 // From class MTimerNotifier
       
  1073 // TimerExpired()
       
  1074 // ---------------------------------------------------------------------------
       
  1075 //
       
  1076 void CHidHeadsetDriver::TimerExpired( TTimerType aTimerType )
       
  1077     {
       
  1078     TRACE_FUNC_ENTRY
       
  1079     switch ( aTimerType )
       
  1080         {
       
  1081         case EDoubleClickTimer:
       
  1082             ExpiredDoubleClickTimer();
       
  1083             break;
       
  1084         case ELongPressTimer:
       
  1085             ExpiredLongClickTimer();
       
  1086             break;
       
  1087         case EScanNextPressTimer:
       
  1088             iForwardStatus = EScanLongPress;
       
  1089             RProperty::Set( KPSUidHidEventNotifier, KHidControlKeyEvent,
       
  1090                     EFastForwardPressed );
       
  1091             break;
       
  1092         case EScanPrevPressTimer:
       
  1093             iBackwardStatus = EScanLongPress;
       
  1094             RProperty::Set( KPSUidHidEventNotifier, KHidControlKeyEvent,
       
  1095                     ERewindPressed );
       
  1096             break;
       
  1097         default:
       
  1098             TRACE_INFO(_L("CHidHeadsetDriver::TimerExpired : Not supported"))
       
  1099             ;
       
  1100         }
       
  1101     TRACE_FUNC_EXIT
       
  1102     }
       
  1103 
       
  1104 // ---------------------------------------------------------------------------
       
  1105 // ExpiredDoubleClickTimer()
       
  1106 // ---------------------------------------------------------------------------
       
  1107 //
       
  1108 void CHidHeadsetDriver::ExpiredDoubleClickTimer()
       
  1109     {
       
  1110     TRACE_FUNC_ENTRY
       
  1111     if ( iDoubleClicktimer )
       
  1112         {
       
  1113         delete iDoubleClicktimer;
       
  1114         iDoubleClicktimer = NULL;
       
  1115         
       
  1116         if ( iIncomingCallStatus )
       
  1117             {
       
  1118             iIncomingCallStatus = EFalse;
       
  1119             iOnHookPressed = ETrue;
       
  1120             ReleaseHookKey();
       
  1121             }
       
  1122         if ( iAlarmStatus )
       
  1123             {
       
  1124             RProperty::Set( KPSUidAlarmExtCntl, KAlarmStopKey,
       
  1125                     EAlarmUIStopAlarm );
       
  1126             iAlarmStatus = EFalse;
       
  1127             }
       
  1128         if ( iPlayingStatus )
       
  1129             {
       
  1130             RProperty::Set( KPSUidHidEventNotifier, KHidControlKeyEvent,
       
  1131                     EForwardClicked );
       
  1132             iPlayingStatus = EFalse;
       
  1133             }
       
  1134         }
       
  1135     TRACE_FUNC_EXIT
       
  1136     }
       
  1137 
       
  1138 // ---------------------------------------------------------------------------
       
  1139 // ExpiredLongClickTimer()
       
  1140 // ---------------------------------------------------------------------------
       
  1141 //
       
  1142 void CHidHeadsetDriver::ExpiredLongClickTimer()
       
  1143     {
       
  1144     TRACE_FUNC_ENTRY
       
  1145     if ( iLongClicktimer )
       
  1146         {
       
  1147         TRACE_INFO(_L("[HID]\tCHidHeadsetDriver::TimerExpired long click"));
       
  1148         delete iLongClicktimer;
       
  1149         iLongClicktimer = NULL;
       
  1150         iLongPress = ETrue;
       
  1151         ReleaseHookKey();
       
  1152         }
       
  1153     TRACE_FUNC_EXIT
       
  1154     }
       
  1155 
       
  1156 // ---------------------------------------------------------------------------
       
  1157 // AlarmStatus()
       
  1158 // ---------------------------------------------------------------------------
       
  1159 //
       
  1160 TBool CHidHeadsetDriver::AlarmStatus()
       
  1161     {
       
  1162     TRACE_FUNC_ENTRY
       
  1163     TInt activealarmcount = 0;
       
  1164     TBool retVal = EFalse;
       
  1165     activealarmcount = iAlarmServerSession.AlarmCountByState(
       
  1166             EAlarmStateNotifying );
       
  1167     if ( activealarmcount > 0 )
       
  1168         {
       
  1169         TRACE_INFO(_L("[HID]\tCHidHeadsetDriver::AlarmStatus active alarms"));
       
  1170         retVal = ETrue;
       
  1171         }
       
  1172     else
       
  1173         {
       
  1174         TRACE_INFO(_L("[HID]\tCHidHeadsetDriver::AlarmStatus no active \
       
  1175                 alarms"));
       
  1176         retVal = EFalse;
       
  1177         }
       
  1178     TRACE_FUNC_EXIT
       
  1179     return retVal;
       
  1180     }
       
  1181 
       
  1182 // ---------------------------------------------------------------------------
       
  1183 // AlarmStatus()
       
  1184 // ---------------------------------------------------------------------------
       
  1185 //
       
  1186 TBool CHidHeadsetDriver::MusicPlayingStatus()
       
  1187     {
       
  1188     TRACE_FUNC_ENTRY
       
  1189     TBool retVal = EFalse;
       
  1190     TMPXPlaybackState state = EPbStateNotInitialised;
       
  1191     TRAPD( err, state = iMusicPlayer->StateL() );
       
  1192     if ( state == EPbStatePlaying && err == KErrNone )
       
  1193         {
       
  1194         TRACE_INFO(_L("[HID]\tCHidHeadsetDriver::MusicPlayingStatus play \
       
  1195                 active"));
       
  1196         retVal = ETrue;
       
  1197         }
       
  1198     TRACE_FUNC_EXIT
       
  1199     return retVal;
       
  1200     }
       
  1201 
       
  1202 // ---------------------------------------------------------------------------
       
  1203 // HandlePlaybackMessage
       
  1204 // ---------------------------------------------------------------------------
       
  1205 //
       
  1206 void CHidHeadsetDriver::HandlePlaybackMessage( CMPXMessage* aMsg, TInt /*aErr*/)
       
  1207     {
       
  1208     TRACE_FUNC_ENTRY
       
  1209 
       
  1210     TMPXMessageId id( aMsg->ValueTObjectL<TMPXMessageId> (
       
  1211             KMPXMessageGeneralId ) );
       
  1212     // send nect track whit double hook click when track is changed
       
  1213     if ( id == KMPXMessagePbMediaChanged && iDoubleNextClick )
       
  1214         {
       
  1215         TRACE_INFO(_L("[HID]\tHandlePlaybackMessage: PbMediaChangeg"));
       
  1216         RProperty::Set( KPSUidHidEventNotifier, KHidControlKeyEvent,
       
  1217                 EForwardClicked );
       
  1218         iDoubleNextClick = EFalse;
       
  1219         }
       
  1220     TRACE_FUNC_EXIT
       
  1221     }
       
  1222