accessoryservices/accessoryremotecontrol/src/remconextensionapi/RemConCallHandlingTarget.cpp
changeset 0 4e1aa6a622a0
equal deleted inserted replaced
-1:000000000000 0:4e1aa6a622a0
       
     1 /*
       
     2 * Copyright (c) 2002-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:  This class deliveres call handling related operations from 
       
    15 *				 accessories to client that listens to them. It also provides 
       
    16 *				 methods for client to respond to call handling operations.
       
    17 *
       
    18 */
       
    19 
       
    20 
       
    21 // INCLUDE FILES
       
    22 #include "RemConExtensionApi.h"
       
    23 #include "RemConCallHandlingTarget.h"
       
    24 #include "RemConCallHandlingTargetObserver.h"
       
    25 #include "RemConDebug.h"
       
    26 #include "RemConSourceHandler.h"
       
    27 #include <e32base.h>
       
    28 #include <remconinterfaceselector.h>
       
    29 
       
    30 // EXTERNAL DATA STRUCTURES
       
    31 
       
    32 // EXTERNAL FUNCTION PROTOTYPES  
       
    33 
       
    34 // CONSTANTS
       
    35 
       
    36 // MACROS
       
    37 
       
    38 // LOCAL CONSTANTS AND MACROS
       
    39 
       
    40 // MODULE DATA STRUCTURES
       
    41 
       
    42 // LOCAL FUNCTION PROTOTYPES
       
    43 
       
    44 // FORWARD DECLARATIONS
       
    45 
       
    46 
       
    47 // ============================= LOCAL FUNCTIONS ===============================
       
    48 
       
    49 // ============================ MEMBER FUNCTIONS ===============================
       
    50 
       
    51 // -----------------------------------------------------------------------------
       
    52 // CRemConCallHandlingTarget::CRemConCallHandlingTarget
       
    53 // C++ default constructor can NOT contain any code, that
       
    54 // might leave.
       
    55 // -----------------------------------------------------------------------------
       
    56 //
       
    57 CRemConCallHandlingTarget::CRemConCallHandlingTarget(
       
    58 						CRemConInterfaceSelector& aInterfaceSelector, 
       
    59 						MRemConCallHandlingTargetObserver& aObserver)
       
    60 :	CRemConInterfaceBase(TUid::Uid(KRemConExtCallHandlingApiUid), 
       
    61 						 KMaxName,
       
    62 						 aInterfaceSelector,
       
    63 						 ERemConClientTypeTarget),
       
    64 	iObserver(aObserver)
       
    65 	{
       
    66 	}
       
    67 
       
    68 // -----------------------------------------------------------------------------
       
    69 // CRemConCallHandlingTarget::ConstructL
       
    70 // Symbian 2nd phase constructor can leave.
       
    71 // -----------------------------------------------------------------------------
       
    72 //
       
    73 
       
    74 // -----------------------------------------------------------------------------
       
    75 // CRemConCallHandlingTarget::NewL
       
    76 // Two-phased constructor.
       
    77 // -----------------------------------------------------------------------------
       
    78 //
       
    79 EXPORT_C CRemConCallHandlingTarget* CRemConCallHandlingTarget::NewL(
       
    80 					CRemConInterfaceSelector& aInterfaceSelector, 
       
    81 					MRemConCallHandlingTargetObserver& aObserver)
       
    82 	{
       
    83 	COM_TRACE_( "[REMCONEXTAPI] CRemConCallHandlingTarget::NewL() start" );
       
    84 		
       
    85 	CRemConCallHandlingTarget* self = 
       
    86 		new(ELeave) CRemConCallHandlingTarget(aInterfaceSelector, aObserver);
       
    87 	CleanupStack::PushL(self);
       
    88 	self->BaseConstructL();
       
    89 	CleanupStack::Pop(self);
       
    90 	
       
    91 	COM_TRACE_( "[REMCONEXTAPI] CRemConCallHandlingTarget::NewL() end" );
       
    92 	return self;
       
    93 	}
       
    94     
       
    95 // Destructor
       
    96 EXPORT_C CRemConCallHandlingTarget::~CRemConCallHandlingTarget()
       
    97 	{
       
    98 	COM_TRACE_( "[REMCONEXTAPI] ~CRemConCallHandlingTarget()" );
       
    99 	}
       
   100 
       
   101 // -----------------------------------------------------------------------------
       
   102 // CRemConCallHandlingTarget::SendAnyResponse
       
   103 // Sends responses to accessories.
       
   104 // (other items were commented in a header).
       
   105 // -----------------------------------------------------------------------------
       
   106 //
       
   107 void CRemConCallHandlingTarget::SendAnyResponse(
       
   108 									TRequestStatus& aStatus,
       
   109 									TInt aOperationId,
       
   110 									TInt aError)
       
   111 	{
       
   112 	COM_TRACE_2( "[REMCONEXTAPI] CRemConCallHandlingTarget::SendAnyResponse() opId=0x%x, error=0x%x", aOperationId, aError );
       
   113 	
       
   114 	iNumRemotes = 0;
       
   115 	TUint8* parameter = reinterpret_cast<TUint8*>( &aError );
       
   116 	iOutData.Copy( parameter );
       
   117 	
       
   118 	InterfaceSelector().Send(
       
   119 		aStatus, 
       
   120 		TUid::Uid(KRemConExtCallHandlingApiUid),
       
   121 		(TUint)aOperationId, 
       
   122 		iNumRemotes,
       
   123 		ERemConResponse,
       
   124 		iOutData );
       
   125 	
       
   126 	COM_TRACE_1( "[REMCONEXTAPI] CRemConCallHandlingTarget::SendAnyResponse() iNumRemotes=0x%x", iNumRemotes );
       
   127 	}
       
   128 	
       
   129 // -----------------------------------------------------------------------------
       
   130 // CRemConCallHandlingTarget::GetInterfaceIf
       
   131 // Called by Remote Control intermediate client when an operation is sent to 
       
   132 // this API. Intermediate client uses this method to figure out version of 
       
   133 // interface it should call to inform this API about incoming operation.
       
   134 // (other items were commented in a header).
       
   135 // -----------------------------------------------------------------------------
       
   136 //
       
   137 TAny* CRemConCallHandlingTarget::GetInterfaceIf( TUid aUid )
       
   138     {
       
   139     COM_TRACE_2( "[REMCONEXTAPI] CRemConCallHandlingTarget::GetInterfaceIf() this=0x%x, aUid=0x%x", this, aUid );
       
   140 
       
   141 	TAny* ret = NULL;
       
   142 	
       
   143 	// Asked interface version implemented by this API ?
       
   144 	if ( aUid == TUid::Uid( KRemConInterfaceIf3 ) )
       
   145 		{
       
   146 		// Return this interface version
       
   147 		ret = reinterpret_cast< TAny* >( 
       
   148 				static_cast< MRemConInterfaceIf3* >( this ) );
       
   149 		}
       
   150 
       
   151 	COM_TRACE_1( "[REMCONEXTAPI] CRemConCallHandlingTarget::GetInterfaceIf() this=0x%x", ret );
       
   152 	return ret;
       
   153     }
       
   154 		
       
   155 // -----------------------------------------------------------------------------
       
   156 // CRemConCallHandlingTarget::MrcibNewMessage
       
   157 // Called by Remote Control intermediate client when accessory has sent 
       
   158 // call handling related operation.
       
   159 // (other items were commented in a header).
       
   160 // -----------------------------------------------------------------------------
       
   161 //
       
   162 void CRemConCallHandlingTarget::MrcibNewMessage(TUint aOperationId, const TDesC8& aData, TRemConMessageSubType /*aMessageSubType*/, const TRemConAddress& aRemoteAddr)
       
   163 	{
       
   164 	iSourceUID = aRemoteAddr.BearerUid().iUid;
       
   165 	
       
   166 	switch ( aOperationId )
       
   167 		{
       
   168 		case ERemConExtAnswerCall:
       
   169 			{
       
   170 			COM_TRACE_( "[REMCONEXTAPI] AnswerCall()" );
       
   171 		 	iObserver.AnswerCall();
       
   172 			break;
       
   173 			}
       
   174 		
       
   175 		case ERemConExtEndCall:
       
   176 			{
       
   177 			COM_TRACE_( "[REMCONEXTAPI] EndCall()" );
       
   178 		 	iObserver.EndCall();
       
   179 			break;
       
   180 			}
       
   181 			
       
   182 		case ERemConExtAnswerEnd:
       
   183 			{
       
   184 			COM_TRACE_( "[REMCONEXTAPI] AnswerEndCall()" );
       
   185 		 	iObserver.AnswerEndCall();
       
   186 			break;
       
   187 			}
       
   188 			
       
   189 		case ERemConExtVoiceDial:
       
   190 			{
       
   191 			COM_TRACE_( "[REMCONEXTAPI] VoiceDial()" );
       
   192 		 	 	
       
   193 			// Copy active status from aData to TBool
       
   194 			TUint8* ptr = const_cast< TUint8* >( aData.Ptr() ); 
       
   195 	        TPtr8 tptr( ptr, aData.Length(), aData.Length() );
       
   196 	        TLex8 input( tptr );
       
   197 			TBool active( EFalse );
       
   198 			input.Val( active );
       
   199 	        
       
   200 	        COM_TRACE_1( "[REMCONEXTAPI] VoiceDial() active=%d ", active );
       
   201 		
       
   202 	        iObserver.VoiceDial( active );
       
   203 			break;
       
   204 			}
       
   205 			
       
   206 		case ERemConExtLastNumberRedial:
       
   207 			{
       
   208 			COM_TRACE_( "[REMCONEXTAPI] LastNumberRedial()" );
       
   209 		 	iObserver.LastNumberRedial();
       
   210 			break;
       
   211 			}
       
   212 					
       
   213 		case ERemConExtDialCall:
       
   214 			{
       
   215 			COM_TRACE_( "[REMCONEXTAPI] DialCall()" );
       
   216 		 	iObserver.DialCall( aData );
       
   217 			break;
       
   218 			}
       
   219 			
       
   220 		case ERemConExt3WaysCalling:
       
   221 			{
       
   222 			COM_TRACE_( "[REMCONEXTAPI] MultipartyCalling()" );
       
   223 			iObserver.MultipartyCalling( aData );
       
   224 			break;
       
   225 			}
       
   226 			
       
   227 		case ERemConExtGenerateDTMF:
       
   228 			{
       
   229 			
       
   230 	        COM_TRACE_( "[REMCONEXTAPI] GenerateDTMF()" );
       
   231 	                            
       
   232             // Copy DTMF character from aData to TChar
       
   233             TUint8* ptr8 = const_cast< TUint8* >( aData.Ptr() ); 
       
   234             
       
   235             COM_TRACE_1( "[REMCONEXTAPI] data %S", &aData );
       
   236 
       
   237             COM_TRACE_1( "[REMCONEXTAPI] aData.Length %d", aData.Length() );
       
   238             for(TInt i = 0; i<aData.Length(); i++)    
       
   239                 {
       
   240                 COM_TRACE_1( "i=%d", i );
       
   241                 COM_TRACE_1( "[REMCONEXTAPI] GenerateDTMF() ASCII numerical from ptr8=%d", *ptr8 );
       
   242                 TChar ch( *ptr8 );
       
   243                 COM_TRACE_RAW_1( "[REMCONEXTAPI] GenerateDTMF() character from ch=", ch );
       
   244                 iObserver.GenerateDTMF( ch );
       
   245                 ptr8++;
       
   246                 }
       
   247             break;  
       
   248 			
       
   249 			}
       
   250 			
       
   251 		case ERemConExtSpeedDial:
       
   252 			{
       
   253 			COM_TRACE_( "[REMCONEXTAPI] SpeedDial()" );
       
   254 					
       
   255 			// Copy TInt from aData to index
       
   256 			TUint8* ptr = const_cast< TUint8* >( aData.Ptr() ); 
       
   257 	        TPtr8 tptr( ptr, aData.Length(), aData.Length() );
       
   258 	        TLex8 input( tptr );
       
   259 			TInt index( 0 );
       
   260 			input.Val( index );
       
   261 			
       
   262 			COM_TRACE_1( "[REMCONEXTAPI] SpeedDial() index=%d", index );
       
   263 					
       
   264 			iObserver.SpeedDial( index );	
       
   265 			break;
       
   266 			}
       
   267 			
       
   268 		default:
       
   269 			COM_TRACE_( "[REMCONEXTAPI] CRemConCallHandlingTarget::MrcibNewMessage() Operation not identified" );
       
   270 			break;
       
   271 		}
       
   272 	}
       
   273 
       
   274 // -----------------------------------------------------------------------------
       
   275 // CRemConCallHandlingTarget::SendlResponse
       
   276 // Called by client to send a response to accessory's operation after
       
   277 // client has processed operation. 
       
   278 // (other items were commented in a header).
       
   279 // -----------------------------------------------------------------------------
       
   280 //
       
   281 EXPORT_C void CRemConCallHandlingTarget::SendResponse( 
       
   282 											TRequestStatus& aStatus,
       
   283 											TInt aOperationId, 
       
   284 											TInt aError )	
       
   285 	{
       
   286 	SendAnyResponse( aStatus, aOperationId, aError );
       
   287 	}									
       
   288 
       
   289 // -----------------------------------------------------------------------------
       
   290 // CRemConCallHandlingTarget::GetCommandSourceInfo
       
   291 // Method to get the bearer source detail for the last command received
       
   292 // -----------------------------------------------------------------------------
       
   293 //
       
   294 EXPORT_C void CRemConCallHandlingTarget::GetCommandSourceInfo( TRemConExtCmdSource& aSource )
       
   295   {
       
   296   COM_TRACE_( "[REMCONEXTAPI] CRemConCallHandlingTarget::GetCommandSourceInfo()" );
       
   297   GetUIDSource( iSourceUID, aSource );
       
   298   COM_TRACE_1( "[REMCONEXTAPI] CRemConCallHandlingTarget::GetCommandSourceInfo() - source [%d]", aSource );
       
   299   }
       
   300 
       
   301 void CRemConCallHandlingTarget::GetUIDSource( TUint32 aUid, TRemConExtCmdSource& aSource )
       
   302   {
       
   303   COM_TRACE_( "[REMCONEXTAPI] CRemConCallHandlingTarget::GetUIDSource()" );
       
   304   
       
   305   switch ( aUid )
       
   306   {
       
   307   case KRemConExtBTAVRCPBearerID:
       
   308   case KRemConExtBTBearerID:
       
   309       {
       
   310       aSource = ERemConExtCmdSourceBluetooth;
       
   311       }
       
   312       break;
       
   313       
       
   314   case KRemConExtUSBBearerID:
       
   315   case KRemConExtWiredBearerID:
       
   316       {
       
   317       aSource = ERemConExtCmdSourceWired;
       
   318       }
       
   319       break;
       
   320       
       
   321   default:
       
   322       {
       
   323       aSource = ERemConExtCmdSourceUnKnown;
       
   324       }
       
   325       break;
       
   326   }
       
   327   
       
   328   COM_TRACE_1( "[REMCONEXTAPI] CRemConCallHandlingTarget::GetUIDSource() - return %d", aSource );
       
   329   }
       
   330   
       
   331 // ========================== OTHER EXPORTED FUNCTIONS =========================
       
   332 
       
   333 //  End of File