mediakeys/MMKeyBearer/src/MMKeyBearerImplementation.cpp
changeset 0 2e3d3ce01487
child 12 7645e9ce10dc
child 21 c4cbaa4fb734
equal deleted inserted replaced
-1:000000000000 0:2e3d3ce01487
       
     1 /*
       
     2 * Copyright (c) 2005-2008 Nokia Corporation and/or its subsidiary(-ies). 
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:  Bearer plugin API Implementation file
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 // INCLUDE FILES
       
    20 #include <e32def.h>
       
    21 #include <remcon/remconbearerobserver.h>
       
    22 #include <remcon/remconconverterplugin.h>
       
    23 #include <remconaddress.h>
       
    24 #include <remconcoreapi.h>
       
    25 #include <mediakeysinternalpskeys.h>
       
    26 #include <UsbWatcherInternalPSKeys.h>
       
    27 #include <usbpersonalityids.h>
       
    28 #include <PSVariables.h>   // Property values
       
    29 
       
    30 // Include this once it is exported
       
    31 // #include <RemConExtensionApi.h>
       
    32 
       
    33 #include "MMKeyBearerImplementation.h"
       
    34 #include "MMKeyBearerObserverPS.h"
       
    35 #include "mmkeybearerscancodes.h"
       
    36 #include "trace.h"
       
    37 
       
    38 #define SET_MEDIAKEY_OPID(eNum, opId, remconEvent) \
       
    39 case eNum:                                          \
       
    40 	iOperationId = opId;                            \
       
    41     iData.Format(KFormatString,remconEvent);        \
       
    42     break;
       
    43 
       
    44 //Constants
       
    45 _LIT8(KFormatString,"%c");
       
    46 
       
    47 // ---------------------------------------------------------
       
    48 // CMMKeyBearer::NewL()
       
    49 // Description: Factory function.
       
    50 // return: Ownership of a new CMMKeyBearer.
       
    51 // ---------------------------------------------------------
       
    52 //
       
    53 CMMKeyBearer* CMMKeyBearer::NewL(TBearerParams& aParams)
       
    54     {
       
    55     FUNC_LOG;
       
    56 
       
    57     CMMKeyBearer* self = new(ELeave) CMMKeyBearer(aParams);
       
    58     CleanupStack::PushL(self);
       
    59     self->ConstructL();
       
    60     CleanupStack::Pop(self);
       
    61     return self;
       
    62     }
       
    63 
       
    64 // ---------------------------------------------------------
       
    65 // CMMKeyBearer::~CMMKeyBearer()
       
    66 // Destructor.
       
    67 // ---------------------------------------------------------
       
    68 //
       
    69 CMMKeyBearer::~CMMKeyBearer()
       
    70     {
       
    71     FUNC_LOG;
       
    72 
       
    73     delete iMMKeyBearerObserver;
       
    74     delete iMediaKeyObserver;
       
    75     delete iAccessoryVolKeyObserver;
       
    76     delete iUSBFileTransferObserver;
       
    77     iAknServer.Close();
       
    78     }
       
    79 
       
    80 // ---------------------------------------------------------
       
    81 // CMMKeyBearer::CMMKeyBearer()
       
    82 // construction.
       
    83 // ---------------------------------------------------------
       
    84 //
       
    85 CMMKeyBearer::CMMKeyBearer(TBearerParams& aParams)
       
    86 :   CRemConBearerPlugin(aParams),
       
    87     iUSBFileTransfer(KUsbWatcherSelectedPersonalityNone),
       
    88     iAknServerConnected(EFalse)
       
    89     {
       
    90     FUNC_LOG;
       
    91 
       
    92     //Pass
       
    93     }
       
    94 
       
    95 // ---------------------------------------------------------
       
    96 // CMMKeyBearer::ConstructL()
       
    97 // 2nd-phase construction.
       
    98 // ---------------------------------------------------------
       
    99 //
       
   100 void CMMKeyBearer::ConstructL()
       
   101     {
       
   102     FUNC_LOG;
       
   103 
       
   104     // throw an indication up to RemCon.
       
   105     TRemConAddress addr;
       
   106     addr.BearerUid() = Uid();
       
   107     TInt err = Observer().ConnectIndicate(addr);
       
   108 
       
   109     // Start Active object for listening key events from P&S
       
   110     TRAP_AND_LEAVE(
       
   111         iMMKeyBearerObserver = CMMKeyBearerObserver::NewL(*this, ESideVolumeKeys),
       
   112         "Volume key observer init failed" );
       
   113 
       
   114     TRAP_AND_LEAVE(
       
   115         iMediaKeyObserver = CMMKeyBearerObserver::NewL(*this, EMediaKeys),
       
   116         "Media key observer init failed" );
       
   117 
       
   118     TRAP_AND_LEAVE(
       
   119         iAccessoryVolKeyObserver = CMMKeyBearerObserver::NewL(*this, EAccessoryVolumeKeys),
       
   120         "Accessory key observer init failed" );
       
   121 
       
   122     TRAP_AND_LEAVE(
       
   123         iUSBFileTransferObserver = CMMKeyBearerObserver::NewL(*this, EFileTransferStatus),
       
   124         "USB observer init failed" );
       
   125     }
       
   126 // ---------------------------------------------------------
       
   127 // CMMKeyBearer::ConnectRequest()
       
   128 // Rem Con server send connect request to Bearer Plugin
       
   129 // ---------------------------------------------------------
       
   130 //
       
   131 void CMMKeyBearer::ConnectRequest(const TRemConAddress& /*aAddr*/)
       
   132     {
       
   133     FUNC_LOG;
       
   134 
       
   135     // Pass
       
   136     }
       
   137 // ---------------------------------------------------------
       
   138 // CMMKeyBearer::DisconnectRequest()
       
   139 // Rem Con server send disconnect request to Bearer Plugin
       
   140 // ---------------------------------------------------------
       
   141 //
       
   142 void CMMKeyBearer::DisconnectRequest(const TRemConAddress& /*aAddr*/)
       
   143     {
       
   144     FUNC_LOG;
       
   145 
       
   146     // Pass
       
   147     }
       
   148 // ---------------------------------------------------------
       
   149 // CMMKeyBearer::SendResponse()
       
   150 //
       
   151 // ---------------------------------------------------------
       
   152 //
       
   153 TInt CMMKeyBearer::SendResponse(TUid /* aInterfaceUid */,
       
   154         TUint /*aOperationId*/,
       
   155         TUint /*aTransactionId*/, // we don't care about this transaction ID
       
   156         RBuf8&  aData ,
       
   157         const TRemConAddress& /*aAddr*/)
       
   158     {
       
   159     FUNC_LOG;
       
   160 
       
   161     aData.Close();
       
   162     return KErrNone;
       
   163     }
       
   164 // ---------------------------------------------------------
       
   165 // CMMKeyBearer::SendCommand()
       
   166 //
       
   167 // ---------------------------------------------------------
       
   168 //
       
   169 TInt CMMKeyBearer::SendCommand(TUid /* aInterfaceUid */ ,
       
   170         TUint /* aOperationId */,
       
   171         TUint /* aTransactionId */,
       
   172         RBuf8& /* aData */,
       
   173         const TRemConAddress& /*aAddr*/)
       
   174     {
       
   175     FUNC_LOG;
       
   176 
       
   177     return KErrNone;
       
   178     }
       
   179 // ---------------------------------------------------------
       
   180 // CMMKeyBearer::GetResponse()
       
   181 //
       
   182 // ---------------------------------------------------------
       
   183 //
       
   184 TInt CMMKeyBearer::GetResponse(TUid& /* aInterfaceUid */,
       
   185         TUint& /* aTransactionId*/,
       
   186         TUint& /* aOperationId */,
       
   187         RBuf8& /* aData */,
       
   188         TRemConAddress& /*aAddr */)
       
   189     {
       
   190     FUNC_LOG;
       
   191 
       
   192     return KErrNone;
       
   193     }
       
   194 // ---------------------------------------------------------
       
   195 // CMMKeyBearer::GetCommand()
       
   196 //
       
   197 // ---------------------------------------------------------
       
   198 //
       
   199 TInt CMMKeyBearer::GetCommand(TUid& aInterfaceUid ,
       
   200         TUint& aTransactionId,
       
   201         TUint& aOperationId,
       
   202         RBuf8& aData,
       
   203         TRemConAddress& aAddr)
       
   204     {
       
   205     FUNC_LOG;
       
   206 
       
   207     aInterfaceUid = iInterfaceUid;
       
   208     aOperationId = iOperationId;
       
   209 
       
   210     // Pass ownership of this to RemCon.
       
   211     TRAPD_ERR( err, aData.CreateL(iData) );
       
   212     ERROR( err, "Remcon ownership change failed" );
       
   213 
       
   214     aAddr.BearerUid() = Uid();
       
   215     aAddr.Addr() = KNullDesC8();
       
   216 
       
   217     aTransactionId = iTransactionId;
       
   218 
       
   219     return KErrNone;
       
   220     }
       
   221 // ---------------------------------------------------------
       
   222 // CMMKeyBearer::SetSVKOperationIdAndData()
       
   223 //
       
   224 // ---------------------------------------------------------
       
   225 //
       
   226 void CMMKeyBearer::SetSVKOperationIdAndData(TInt aEnumValue)
       
   227     {
       
   228     FUNC_LOG;
       
   229 
       
   230     INFO_1( "SetSVKOperationIdAndData: enumValue = %d", aEnumValue );
       
   231 
       
   232     switch (aEnumValue)
       
   233         {
       
   234         case KPSVolumeUpPressed:
       
   235             iOperationId = ERemConCoreApiVolumeUp;
       
   236             iData.Format(KFormatString,ERemConCoreApiButtonPress);
       
   237             break;
       
   238         case KPSVolumeUpReleased:
       
   239             iOperationId = ERemConCoreApiVolumeUp;
       
   240             iData.Format(KFormatString,ERemConCoreApiButtonRelease);
       
   241             break;
       
   242         case KPSVolumeUpClicked:
       
   243             iOperationId = ERemConCoreApiVolumeUp;
       
   244             iData.Format(KFormatString,ERemConCoreApiButtonClick);
       
   245             break;
       
   246         case KPSVolumeDownPressed:
       
   247             iOperationId = ERemConCoreApiVolumeDown;
       
   248             iData.Format(KFormatString,ERemConCoreApiButtonPress);
       
   249             break;
       
   250         case KPSVolumeDownReleased:
       
   251             iOperationId = ERemConCoreApiVolumeDown;
       
   252             iData.Format(KFormatString,ERemConCoreApiButtonRelease);
       
   253             break;
       
   254         case KPSVolumeDownClicked:
       
   255             iOperationId = ERemConCoreApiVolumeDown;
       
   256             iData.Format(KFormatString,ERemConCoreApiButtonClick);
       
   257             break;
       
   258 
       
   259         case KPSVolumeNoKey:  // This should never execute
       
   260         default:
       
   261             iOperationId = aEnumValue;
       
   262             iData.Format(KFormatString,ERemConCoreApiButtonClick);
       
   263             break;
       
   264 
       
   265         }
       
   266 
       
   267     }
       
   268 // ---------------------------------------------------------
       
   269 // CMMKeyBearer::SetMediaKeyOperationIdAndData()
       
   270 //
       
   271 // ---------------------------------------------------------
       
   272 //
       
   273 void CMMKeyBearer::SetMediaKeyOperationIdAndData(TInt aEnumValue)
       
   274     {
       
   275     FUNC_LOG;
       
   276 
       
   277     INFO_1( "SetMediaKeyOperationIdAndData: enumValue = %d", aEnumValue );
       
   278 
       
   279     switch (aEnumValue)
       
   280         {
       
   281 
       
   282         SET_MEDIAKEY_OPID (EPlayReleased, ERemConCoreApiPausePlayFunction,
       
   283                            ERemConCoreApiButtonRelease);
       
   284         SET_MEDIAKEY_OPID (EPlayPressed,  ERemConCoreApiPausePlayFunction,
       
   285                            ERemConCoreApiButtonPress);
       
   286         SET_MEDIAKEY_OPID (EPlayClicked,  ERemConCoreApiPausePlayFunction,
       
   287                            ERemConCoreApiButtonClick);
       
   288 
       
   289         SET_MEDIAKEY_OPID (EStopReleased, ERemConCoreApiStop,
       
   290                            ERemConCoreApiButtonRelease);
       
   291         SET_MEDIAKEY_OPID (EStopPressed,  ERemConCoreApiStop,
       
   292                            ERemConCoreApiButtonPress);
       
   293         SET_MEDIAKEY_OPID (EStopClicked,  ERemConCoreApiStop,
       
   294                            ERemConCoreApiButtonClick);
       
   295 
       
   296         SET_MEDIAKEY_OPID (EForwardReleased, ERemConCoreApiForward,
       
   297                            ERemConCoreApiButtonRelease);
       
   298         SET_MEDIAKEY_OPID (EForwardPressed,  ERemConCoreApiForward,
       
   299                            ERemConCoreApiButtonPress);
       
   300         SET_MEDIAKEY_OPID (EForwardClicked,  ERemConCoreApiForward,
       
   301                            ERemConCoreApiButtonClick);
       
   302 
       
   303         SET_MEDIAKEY_OPID (ERewindReleased, ERemConCoreApiRewind,
       
   304                            ERemConCoreApiButtonRelease);
       
   305         SET_MEDIAKEY_OPID (ERewindPressed,  ERemConCoreApiRewind,
       
   306                            ERemConCoreApiButtonPress);
       
   307         SET_MEDIAKEY_OPID (ERewindClicked,  ERemConCoreApiRewind,
       
   308                            ERemConCoreApiButtonClick);
       
   309 
       
   310         SET_MEDIAKEY_OPID (EFastForwardReleased, ERemConCoreApiFastForward,
       
   311                            ERemConCoreApiButtonRelease);
       
   312         SET_MEDIAKEY_OPID (EFastForwardPressed,  ERemConCoreApiFastForward,
       
   313                            ERemConCoreApiButtonPress);
       
   314         SET_MEDIAKEY_OPID (EFastForwardClicked,  ERemConCoreApiFastForward,
       
   315                            ERemConCoreApiButtonClick);
       
   316 
       
   317         SET_MEDIAKEY_OPID (EBackwardReleased, ERemConCoreApiBackward,
       
   318                            ERemConCoreApiButtonRelease);
       
   319         SET_MEDIAKEY_OPID (EBackwardPressed,  ERemConCoreApiBackward,
       
   320                            ERemConCoreApiButtonPress);
       
   321         SET_MEDIAKEY_OPID (EBackwardClicked,  ERemConCoreApiBackward,
       
   322                            ERemConCoreApiButtonClick);
       
   323 
       
   324 
       
   325         // This should never execute
       
   326         default:
       
   327             iOperationId = aEnumValue;
       
   328             iData.Format(KFormatString,ERemConCoreApiButtonClick);
       
   329             break;
       
   330 
       
   331         }
       
   332     }
       
   333 // ---------------------------------------------------------
       
   334 // CMMKeyBearer::ReceivedKeyEvent()
       
   335 //
       
   336 // ---------------------------------------------------------
       
   337 //
       
   338 void CMMKeyBearer::ReceivedKeyEvent(TInt aEnumValue, TInt aKeyType)
       
   339     {
       
   340     FUNC_LOG;
       
   341 
       
   342     INFO_3( "Received key: enumValue = %d, keyType = %d, usbFileTransfer = %d",
       
   343         aEnumValue, aKeyType, iUSBFileTransfer );
       
   344 
       
   345     // Mediakeys must be disabled when MTP (Music Transfer) is happening.
       
   346     if (aKeyType == EFileTransferStatus)
       
   347         {
       
   348         iUSBFileTransferObserver->Start(); // Ensure first that no status change gets missed
       
   349         iUSBFileTransfer = iUSBFileTransferObserver->GetValue(); // Read the MTP status
       
   350         return;
       
   351         }
       
   352     if ((aKeyType == EMediaKeys) &&
       
   353         (iUSBFileTransfer == KUsbPersonalityIdMTP ||
       
   354          iUSBFileTransfer == KUsbPersonalityIdPCSuiteMTP))
       
   355         {
       
   356         iMediaKeyObserver->Start();
       
   357         return;
       
   358         }
       
   359 
       
   360     // Check for keypadlock if the events are from device keypad
       
   361     // If events are from accessory device,then do not check for keypadlock
       
   362     if (aKeyType != EAccessoryVolumeKeys)
       
   363         {
       
   364         TBool keysLocked = EFalse;
       
   365         if (!(iAknServerConnected))  // Connect to server for first time
       
   366             {
       
   367             if(iAknServer.Connect() == KErrNone)
       
   368                 {
       
   369                 iAknServerConnected = ETrue;
       
   370                 }
       
   371             else                   // If connection fails, then return
       
   372                 {
       
   373                 //Start the listener once again
       
   374                if (aKeyType == ESideVolumeKeys)
       
   375                     {
       
   376                     iMMKeyBearerObserver->Start();
       
   377                     }
       
   378                 if (aKeyType == EMediaKeys)
       
   379                     {
       
   380                     iMediaKeyObserver->Start();
       
   381                     }
       
   382                 return ;
       
   383                 }
       
   384             }
       
   385         iAknServer.ShowKeysLockedNote(keysLocked);
       
   386 
       
   387         if (keysLocked)
       
   388             {
       
   389             // Device is locked , Discard the key event
       
   390 
       
   391             //Start the listener once again
       
   392             if (aKeyType == ESideVolumeKeys)
       
   393                 {
       
   394                 iMMKeyBearerObserver->Start();
       
   395                 }
       
   396             if (aKeyType == EMediaKeys)
       
   397                 {
       
   398                 iMediaKeyObserver->Start();
       
   399                 }
       
   400 
       
   401             return;
       
   402             }
       
   403         }
       
   404 
       
   405     /* To keep the background light on */
       
   406     User::ResetInactivityTime();
       
   407 
       
   408     // 1. Interface ID is required when Getcommand is called
       
   409     iInterfaceUid = TUid::Uid(KRemConCoreApiUid); // from Remconcoreapi.h
       
   410 
       
   411     // 2. Transaction ID
       
   412     iTransactionId = Observer().NewTransactionId();
       
   413 
       
   414     // 3. Addr
       
   415     TRemConAddress addr;
       
   416     addr.BearerUid() = Uid();
       
   417     addr.Addr() = KNullDesC8();
       
   418 
       
   419     // 4 & 5. Operation ID and Data
       
   420     if ((aKeyType == ESideVolumeKeys) || (aKeyType == EAccessoryVolumeKeys))
       
   421         {
       
   422         SetSVKOperationIdAndData(aEnumValue);
       
   423         }
       
   424     else
       
   425         {
       
   426         SetMediaKeyOperationIdAndData(aEnumValue);
       
   427         }
       
   428 
       
   429     // Msgtype  is ERemConCommand
       
   430     TInt aError = Observer().NewCommand(addr);
       
   431 
       
   432     //Start the listener once again
       
   433     if (aKeyType == ESideVolumeKeys)
       
   434         {
       
   435         iMMKeyBearerObserver->Start();
       
   436         }
       
   437     else if (aKeyType == EMediaKeys)
       
   438         {
       
   439         iMediaKeyObserver->Start();
       
   440         }
       
   441     else if (aKeyType == EAccessoryVolumeKeys)
       
   442         {
       
   443         iAccessoryVolKeyObserver->Start();
       
   444         }
       
   445     }
       
   446 // ---------------------------------------------------------
       
   447 // CMMKeyBearer::SecurityPolicy()
       
   448 //
       
   449 // ---------------------------------------------------------
       
   450 //
       
   451 TSecurityPolicy CMMKeyBearer::SecurityPolicy() const
       
   452     {
       
   453     FUNC_LOG;
       
   454 
       
   455     return TSecurityPolicy(ECapabilityLocalServices);
       
   456     }
       
   457 // ---------------------------------------------------------
       
   458 // CMMKeyBearer::ClientStatus()
       
   459 //
       
   460 // ---------------------------------------------------------
       
   461 //
       
   462 void CMMKeyBearer::ClientStatus(TBool /*aControllerPresent*/,
       
   463                                 TBool /*aTargetPresent*/)
       
   464     {
       
   465     FUNC_LOG;
       
   466 
       
   467     //Pass
       
   468     }
       
   469 // ---------------------------------------------------------
       
   470 // CMMKeyBearer::GetInterface()
       
   471 //
       
   472 // ---------------------------------------------------------
       
   473 //
       
   474 TAny* CMMKeyBearer::GetInterface(TUid aUid)
       
   475     {
       
   476     FUNC_LOG;
       
   477 
       
   478     TAny* ret = NULL;
       
   479     if ( aUid == TUid::Uid(KRemConBearerInterface1) )
       
   480         {
       
   481         ret = reinterpret_cast<TAny*>(
       
   482                     static_cast<MRemConBearerInterface*>(this)
       
   483                     );
       
   484         }
       
   485     return ret;
       
   486 
       
   487     }
       
   488 
       
   489 
       
   490 // End of file