accessoryservices/remotecontrolfw/client/sidekeyapi/src/sidekeytarget.cpp
changeset 70 653a8b91b95e
equal deleted inserted replaced
64:61992147389a 70:653a8b91b95e
       
     1 // Copyright (c) 2004-2010 Nokia Corporation and/or its subsidiary(-ies).
       
     2 // All rights reserved.
       
     3 // This component and the accompanying materials are made available
       
     4 // under the terms of "Eclipse Public License v1.0"
       
     5 // which accompanies this distribution, and is available
       
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     7 //
       
     8 // Initial Contributors:
       
     9 // Nokia Corporation - initial contribution.
       
    10 //
       
    11 // Contributors:
       
    12 //
       
    13 // Description:
       
    14 //
       
    15 
       
    16 /**
       
    17  @file
       
    18  @internalComponent
       
    19 */
       
    20 
       
    21 #include <bluetooth/logger.h>
       
    22 #include <e32base.h>
       
    23 #include <remcon/remconsidekeyapi.h>
       
    24 #include <remcon/remconsidekeytarget.h>
       
    25 #include <remcon/remconsidekeytargetobserver.h>
       
    26 #include <remconinterfaceselector.h>
       
    27 #include "remconsidekeyapipaniccodes.h"
       
    28 
       
    29 #ifdef __FLOG_ACTIVE
       
    30 _LIT8(KLogComponent, "RemconSideKeyApi");
       
    31 #endif
       
    32 
       
    33 #ifdef _DEBUG
       
    34 // only called via __ASSERT_DEBUG statements
       
    35 static void Panic(TSideKeyApiPanicCat aCode)
       
    36 	{
       
    37 	User::Panic(KSideKeyPanicCat, aCode);
       
    38 	}
       
    39 #endif
       
    40 
       
    41 EXPORT_C CRemConSideKeyTarget* CRemConSideKeyTarget::NewL(CRemConInterfaceSelector& aInterfaceSelector, 
       
    42 																	MRemConSideKeyTargetObserver& aObserver)
       
    43 	{
       
    44 	LOG_STATIC_FUNC
       
    45 
       
    46 	CRemConSideKeyTarget* self = new(ELeave) CRemConSideKeyTarget(aInterfaceSelector, aObserver);
       
    47 	CleanupStack::PushL(self);
       
    48 	self->BaseConstructL();
       
    49 	CleanupStack::Pop(self);
       
    50 	return self;
       
    51 	}
       
    52 
       
    53 CRemConSideKeyTarget::CRemConSideKeyTarget(CRemConInterfaceSelector& aInterfaceSelector, 
       
    54 													 MRemConSideKeyTargetObserver& aObserver)
       
    55 :	CRemConInterfaceBase(TUid::Uid(KRemConSideKeyApiUid), 
       
    56 						 KMaxOperationDataSize,
       
    57 						 aInterfaceSelector,
       
    58 						 ERemConClientTypeTarget),
       
    59 	iObserver(aObserver)
       
    60 	{
       
    61 	}
       
    62 
       
    63 EXPORT_C CRemConSideKeyTarget::~CRemConSideKeyTarget()
       
    64 	{
       
    65 	LOG_FUNC
       
    66 	}
       
    67 
       
    68 TAny* CRemConSideKeyTarget::GetInterfaceIf(TUid aUid)
       
    69 	{
       
    70 	LOG_FUNC
       
    71 	TAny* ret = NULL;
       
    72 	if ( aUid == TUid::Uid(KRemConInterfaceIf1) )
       
    73 		{
       
    74 		ret = reinterpret_cast<TAny*>(
       
    75 			static_cast<MRemConInterfaceIf*>(this)
       
    76 			);
       
    77 		}
       
    78 
       
    79 	return ret;
       
    80 	}
       
    81 
       
    82 void CRemConSideKeyTarget::MrcibNewMessage(TUint aOperationId, const TDesC8& aData)
       
    83 	{
       
    84 	LOG_FUNC
       
    85 	LOG1(_L("\taOperationId = 0x%02x"), aOperationId);
       
    86 	LOG1(_L("\taData.Length = %d"), aData.Length());
       
    87 
       
    88 	// Get the button action
       
    89 	if ( aData.Length() < KRemConSideKeyApiButtonDataLength )
       
    90 		{
       
    91 		// The bearer sent us incorrect data. We cannot panic the bearer
       
    92 		// from here, so we panic ourselves in udeb mode only instead.
       
    93 		__ASSERT_DEBUG(EFalse,Panic(ESideKeyMissingButtonData));
       
    94 		LOG(_L("\tdropping command because button data not found"));
       
    95 		return; // ditch malformed messages
       
    96 		}
       
    97 	TRemConSideKeyApiButtonAction action = static_cast<TRemConSideKeyApiButtonAction>(aData.Ptr()[0]);
       
    98 
       
    99 	switch ( aOperationId )
       
   100 		{
       
   101 	case ERemConSideKeyUp:
       
   102 		iObserver.MrcsktoSideKeyUp(action);
       
   103 		break;
       
   104 
       
   105 	case ERemConSideKeyDown:
       
   106 		iObserver.MrcsktoSideKeyDown(action);
       
   107 		break;
       
   108 
       
   109 	default:
       
   110 		// The bearer sent us incorrect data. We cannot panic the bearer
       
   111 		// from here, so we panic ourselves in udeb mode only instead.
       
   112 		__ASSERT_DEBUG(EFalse,Panic(ESideKeyInvalidOperationId));
       
   113 		break;
       
   114 		}
       
   115 	}
       
   116 
       
   117 EXPORT_C void CRemConSideKeyTarget::SideKeyUpResponse(TInt aError)
       
   118 	{
       
   119 	LOG_FUNC
       
   120 
       
   121 	iOutData.Copy((TUint8*)&aError, KRemConSideKeyApiResultDataLength);
       
   122 	
       
   123 	InterfaceSelector().SendUnreliable( 
       
   124 		TUid::Uid(KRemConSideKeyApiUid), 
       
   125 		(TUint)ERemConSideKeyUp, 
       
   126 		ERemConResponse,
       
   127 		iOutData);
       
   128 	}
       
   129 
       
   130 EXPORT_C void CRemConSideKeyTarget::SideKeyDownResponse(TInt aError)
       
   131 	{
       
   132 	LOG_FUNC
       
   133 
       
   134 	iOutData.Copy((TUint8*)&aError, KRemConSideKeyApiResultDataLength);
       
   135 	
       
   136 	InterfaceSelector().SendUnreliable(
       
   137 		TUid::Uid(KRemConSideKeyApiUid), 
       
   138 		(TUint)ERemConSideKeyDown, 
       
   139 		ERemConResponse,
       
   140 		iOutData);
       
   141 	}