bluetoothappprofiles/avrcp/statusclient/statusapicontroller.cpp
changeset 70 f5508c13dfe0
parent 67 16e4b9007960
child 71 083fd884d7dd
equal deleted inserted replaced
67:16e4b9007960 70:f5508c13dfe0
     1 // Copyright (c) 2004-2009 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  @publishedAll
       
    19  @released
       
    20 */
       
    21 
       
    22 #include <bluetooth/logger.h>
       
    23 #include <remconstatusapicontroller.h>
       
    24 #include <remconstatusapicontrollerobserver.h>
       
    25 #include <remconinterfaceselector.h>
       
    26 #include "remconstatusapi.h"
       
    27 
       
    28 #ifdef __FLOG_ACTIVE
       
    29 _LIT8(KLogComponent, LOG_COMPONENT_AVRCP_STATUS);
       
    30 #endif
       
    31 
       
    32 /** Creates new Status Api Controller.
       
    33 
       
    34 @param aInterfaceSelector An interface selector for use with this interface.
       
    35 @param aObserver An observer to be notified of responses to commands issued
       
    36 				to this interface.
       
    37 @return A fully constructed CRemConStatusApiController
       
    38 */
       
    39 EXPORT_C CRemConStatusApiController* CRemConStatusApiController::NewL(CRemConInterfaceSelector& aInterfaceSelector, 
       
    40 											  MRemConStatusApiControllerObserver& aObserver)
       
    41 	{
       
    42 	LOG_STATIC_FUNC
       
    43 
       
    44 	CRemConStatusApiController* self = new(ELeave) CRemConStatusApiController(aInterfaceSelector, aObserver);
       
    45 	CleanupStack::PushL(self);
       
    46 	self->BaseConstructL();
       
    47 	CleanupStack::Pop(self);
       
    48 	return self;
       
    49 	}
       
    50 
       
    51 /** Constructs this interface.
       
    52 
       
    53 @param aInterfaceSelector An interface selector for use with this interface.
       
    54 @param aObserver An observer to be notified of responses to commands issued
       
    55 				to this interface.
       
    56 @internalComponent
       
    57 @released
       
    58 */
       
    59 CRemConStatusApiController::CRemConStatusApiController(CRemConInterfaceSelector& aInterfaceSelector, 
       
    60 							   MRemConStatusApiControllerObserver& aObserver)
       
    61 :	CRemConInterfaceBase(TUid::Uid(KRemConStatusApiUid), 
       
    62 						 KRemConStatusApiMaxOperationSpecificDataSize, 
       
    63 						 aInterfaceSelector,
       
    64 						 ERemConClientTypeController),
       
    65 	iObserver(aObserver)
       
    66 	{
       
    67 	iOutData.Assign(NULL);
       
    68 	}
       
    69 
       
    70 /** Destructor.
       
    71 */
       
    72 EXPORT_C CRemConStatusApiController::~CRemConStatusApiController()
       
    73 	{
       
    74 	}
       
    75 
       
    76 /** Gets a pointer to a specific interface version.
       
    77 
       
    78 @return A pointer to the interface, NULL if not supported.
       
    79 @internalComponent
       
    80 @released
       
    81 */
       
    82 TAny* CRemConStatusApiController::GetInterfaceIf(TUid aUid)
       
    83 	{
       
    84 	TAny* ret = NULL;
       
    85 	if ( aUid == TUid::Uid(KRemConInterfaceIf1) )
       
    86 		{
       
    87 		ret = reinterpret_cast<TAny*>(
       
    88 			static_cast<MRemConInterfaceIf*>(this)
       
    89 			);
       
    90 		}
       
    91 
       
    92 	return ret;
       
    93 	}
       
    94 
       
    95 /** New message from RemCon.
       
    96 
       
    97 @internalComponent
       
    98 @released
       
    99 */
       
   100 void CRemConStatusApiController::MrcibNewMessage(TUint aOperationId, const TDesC8& aData)
       
   101 	{
       
   102 	LOG_FUNC
       
   103 
       
   104 	switch ( aOperationId )
       
   105 		{
       
   106 	case ERemConStatusApiUnitInfo:
       
   107 		{
       
   108 		TInt vendorId, unit, unitType, extendedUnitType;
       
   109 		SetUnitInfoResponseData(aData, vendorId, unit, unitType, extendedUnitType);
       
   110 		
       
   111 		iObserver.MrcsacoUnitInfoResponse(vendorId, unit, unitType, extendedUnitType);
       
   112 		break;
       
   113 		}
       
   114 	case ERemConStatusApiSubunitInfo:
       
   115 		{
       
   116 		TInt page, extension;
       
   117 		TPtrC8 pageData;
       
   118 		SetSubunitInfoResponseData(aData, page, extension, pageData);
       
   119 		
       
   120 		iObserver.MrcsacoSubunitInfoResponse(page, extension, pageData);
       
   121 		break;
       
   122 		}
       
   123 	default:
       
   124 		break;
       
   125 		}
       
   126 	}
       
   127 
       
   128 /** Parses command data from the buffer.
       
   129 
       
   130 @param aCommandData The buffer from which to read the data.
       
   131 @param aVendorId On return, the vendor id
       
   132 @param aUnit On return, the unit
       
   133 @param aUnitType On return, the unit type 
       
   134 @param aExtendedUnitType On return, the extended unit type
       
   135 
       
   136 @internalComponent
       
   137 @released
       
   138 */
       
   139 void CRemConStatusApiController::SetUnitInfoResponseData(const TDesC8& aCommandData,
       
   140 	TInt& aVendorId, TInt& aUnit, TInt& aUnitType, TInt& aExtendedUnitType)
       
   141 	{
       
   142 	if(aCommandData.Length())
       
   143 		{
       
   144 		ReadCommandDataToInt(aCommandData, KRemConStatusApiVendorIdOffset, 
       
   145 			KRemConStatusApiVendorIdLength, aVendorId);
       
   146 		ReadCommandDataToInt(aCommandData, KRemConStatusApiUnitOffset, 
       
   147 			KRemConStatusApiUnitLength, aUnit);
       
   148 		ReadCommandDataToInt(aCommandData, KRemConStatusApiUnitTypeOffset, 
       
   149 			KRemConStatusApiUnitTypeLength, aUnitType);
       
   150 		ReadCommandDataToInt(aCommandData, KRemConStatusApiExtendedUnitTypeOffset, 
       
   151 			KRemConStatusApiExtendedUnitTypeLength, aExtendedUnitType);
       
   152 		}
       
   153 	else
       
   154 		{
       
   155 		// On error set all fields to 0
       
   156 		aVendorId = aUnit = aUnitType = aExtendedUnitType = 0;
       
   157 		}
       
   158 	}
       
   159 
       
   160 /** Parses command data from the buffer.
       
   161 
       
   162 @param aCommandData The buffer from which to read the data.
       
   163 @param aPage On return, the page
       
   164 @param aExtension On return, the extension
       
   165 @param aPageData On return, the page data
       
   166 
       
   167 @internalComponent
       
   168 @released
       
   169 */
       
   170 void CRemConStatusApiController::SetSubunitInfoResponseData(const TDesC8& aCommandData,
       
   171 	TInt& aPage, TInt& aExtension, TPtrC8& aPageData)
       
   172 	{
       
   173 	if(aCommandData.Length())
       
   174 		{
       
   175 		ReadCommandDataToInt(aCommandData, KRemConStatusApiPageOffset, 
       
   176 			KRemConStatusApiPageLength, aPage);
       
   177 		ReadCommandDataToInt(aCommandData, KRemConStatusApiExtensionOffset, 
       
   178 			KRemConStatusApiExtensionLength, aExtension);
       
   179 
       
   180 		aPageData.Set(aCommandData.Mid(KRemConStatusApiPageDataOffset));
       
   181 		}
       
   182 	else
       
   183 		{
       
   184 		// On error set all fields to 0
       
   185 		aPage = aExtension = 0;
       
   186 		aPageData.Set(KNullDesC8());
       
   187 		}
       
   188 	}
       
   189 	
       
   190 /** Reads command data from the buffer to an int.
       
   191 
       
   192 @param aCommandData The buffer from which to read the data.
       
   193 @param aOffset The offset within aCommandData read from.
       
   194 @param aLength The length of data to read.  This must not be
       
   195 				more than 4.
       
   196 @param aValue On return, the value of the specified data section.
       
   197 
       
   198 @internalComponent
       
   199 @released
       
   200 */	
       
   201 void CRemConStatusApiController::ReadCommandDataToInt(const TDesC8& aCommandData, 
       
   202 	TInt aOffset, TInt aLength, TInt& aValue)
       
   203 	{
       
   204 	__ASSERT_ALWAYS(aLength <= 4, CRemConStatusApiController::Panic(EStatusApiCommandDataSectionTooLong));
       
   205 	
       
   206 	aValue = 0;
       
   207 	
       
   208 	for(TInt i = 0 ; i < aLength; i++)
       
   209 		{
       
   210 		aValue |= aCommandData[i+aOffset]<<(8*i);
       
   211 		}
       
   212 	}
       
   213 
       
   214 /** Issue UnitInfo command.
       
   215 Only one command per controller session can be outstanding at any one time.
       
   216 @param aStatus Status to be completed with the result of issuing this command.
       
   217 @param aNumRemotes On completion, the number of remotes this command was issued to.
       
   218 */
       
   219 EXPORT_C void CRemConStatusApiController::UnitInfo(TRequestStatus& aStatus, TUint& aNumRemotes)
       
   220 	{
       
   221 	LOG_FUNC
       
   222 
       
   223 	InterfaceSelector().Send(aStatus, 
       
   224 		TUid::Uid(KRemConStatusApiUid),
       
   225 		(TUint)ERemConStatusApiUnitInfo, 
       
   226 		aNumRemotes,
       
   227 		ERemConCommand,
       
   228 		iOutData);
       
   229 	}
       
   230 
       
   231 /** Issue SubUnitInfo command.
       
   232 Only one command per controller session can be outstanding at any one time.
       
   233 @param aStatus Status to be completed with the result of issuing this command.
       
   234 @param aNumRemotes On completion, the number of remotes this command was issued to.
       
   235 */
       
   236 EXPORT_C void CRemConStatusApiController::SubunitInfo(TRequestStatus& aStatus, TUint& aNumRemotes)
       
   237 	{
       
   238 	LOG_FUNC
       
   239 
       
   240 	InterfaceSelector().Send(aStatus, 
       
   241 		TUid::Uid(KRemConStatusApiUid), 
       
   242 		(TUint)ERemConStatusApiSubunitInfo, 
       
   243 		aNumRemotes,
       
   244 		ERemConCommand);
       
   245 	}
       
   246 	
       
   247 /** Utility Status Converter panic function.
       
   248 
       
   249 @param aPanic The panic number.
       
   250 @internalComponent
       
   251 @released
       
   252 */
       
   253 void CRemConStatusApiController::Panic(TStatusApiPanic aPanic)
       
   254 	{
       
   255 	User::Panic(KStatusApiPanicName, aPanic);
       
   256 	}
       
   257 
       
   258 //
       
   259 // End of file