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