bluetoothappprofiles/avrcp/remconbeareravrcp/src/browsecommand.cpp
changeset 0 f63038272f30
equal deleted inserted replaced
-1:000000000000 0:f63038272f30
       
     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 // avrcpcommands.cpp
       
    15 //
       
    16 
       
    17 
       
    18 
       
    19 /**
       
    20  @file
       
    21  @internalComponent
       
    22  @released
       
    23 */
       
    24 
       
    25 #include <e32base.h>
       
    26 #include <remcon/remconbearerobserver.h>
       
    27 #include <remcon/remconconverterplugin.h>
       
    28 #include <remcon/messagetype.h>
       
    29 #include <remconbeareravrcp.h>
       
    30 
       
    31 #include "browsecommand.h"
       
    32 #include "avrcpinternalinterface.h"
       
    33 #include "avrcplog.h"
       
    34 #include "avrcputils.h"
       
    35 #include "browsingframe.h"
       
    36 #include "mediabrowse.h"
       
    37 #include "nowplaying.h"
       
    38 							
       
    39 
       
    40 //---------------------------------------------------------------------
       
    41 // Incoming command construction
       
    42 //---------------------------------------------------------------------
       
    43 
       
    44 /** Factory function.
       
    45 
       
    46 @param aFrame The frame this command is to represent.
       
    47 @param aRemConId The RemCon transaction label.
       
    48 @param aTransLabel The AVCTP transaction label.
       
    49 @param aAddr The bluetooth address to send this command to.
       
    50 @return A fully constructed CBrowseCommand.
       
    51 @leave System wide error codes.
       
    52 */
       
    53 CBrowseCommand* CBrowseCommand::NewL(const TDesC8& aMessageInformation, 
       
    54 	TUint aRemConId, 
       
    55 	SymbianAvctp::TTransactionLabel aTransLabel, 
       
    56 	const TBTDevAddr& aAddr,
       
    57 	CAvrcpPlayerInfoManager* aPlayerInfoManager)
       
    58 	{
       
    59 	LOG_STATIC_FUNC
       
    60 	CBrowseCommand* command = new(ELeave)CBrowseCommand(aRemConId, aTransLabel, aAddr, aPlayerInfoManager);
       
    61 	CleanupStack::PushL(command);
       
    62 	command->ConstructL(aMessageInformation);
       
    63 	CleanupStack::Pop(command);
       
    64 	return command;
       
    65 	}
       
    66 
       
    67 /** Constructor.
       
    68 
       
    69 @param aFrame The AV/C frame this command is to represent.
       
    70 @param aRemConId The RemCon transaction label.
       
    71 @param aTransLabel The AVCTP transaction label.
       
    72 @param aAddr The bluetooth address to send this command to.
       
    73 @return A partially constructed CBrowseCommand.
       
    74 @leave System wide error codes.
       
    75 */	
       
    76 CBrowseCommand::CBrowseCommand(TUint aRemConId, 
       
    77 	SymbianAvctp::TTransactionLabel aTransLabel, 
       
    78 	const TBTDevAddr& aAddr,
       
    79 	CAvrcpPlayerInfoManager* aPlayerInfoManager)
       
    80 	: CAvrcpCommand(aRemConId, aTransLabel, aAddr)
       
    81 	{
       
    82 	LOG_FUNC
       
    83 	iPlayerInfoManager = aPlayerInfoManager;
       
    84 	}
       
    85 
       
    86 /** Destructor.
       
    87 */
       
    88 CBrowseCommand::~CBrowseCommand()
       
    89 	{
       
    90 	LOG_FUNC
       
    91 	__ASSERT_DEBUG(iUsers == 0, AvrcpUtils::Panic(EAvrcpCommandStillInUse));
       
    92 	iFrame.Close();
       
    93 	iCommandData.Close();
       
    94 	}
       
    95 
       
    96 /** Second phase construction.
       
    97 */
       
    98 void CBrowseCommand::ConstructL(const TDesC8& aMessageInformation)
       
    99 	{
       
   100 	iFrame.CreateL(aMessageInformation);
       
   101 	}
       
   102 
       
   103 //------------------------------------------------------------------------------------
       
   104 // Called by router
       
   105 //------------------------------------------------------------------------------------
       
   106 
       
   107 SymbianAvctp::TMessageType CBrowseCommand::MessageType() const
       
   108 	{
       
   109 	return SymbianAvctp::EResponse;
       
   110 	}
       
   111 	
       
   112 //------------------------------------------------------------------------------------
       
   113 // Called by handlers
       
   114 //------------------------------------------------------------------------------------
       
   115 	
       
   116 /** Fills in command info from iFrame.
       
   117 
       
   118 This must be called by the command handler before processing this
       
   119 command.
       
   120 
       
   121 This functions sets iInterfaceUid, iOperationId and iCommandData
       
   122 to the correct values according to iFrame.  The format of iCommandData
       
   123 is defined by RemCon and is dependent on iInterfaceUid and iOperationId.
       
   124 
       
   125 @return KErrNone				If the frame has been parsed successfully.
       
   126 @return KErrNotSupported		This frame represents a command for which a
       
   127 								RemCon converter or client side interface
       
   128 								cannot be found.
       
   129 @return KErrAvrcpInvalidCType	The CType specified in this frame is invalid.
       
   130 @return KErrCorrupt	        	If the frame is corrupted(e.g invalid Operation Id).
       
   131 @return	System wide error code.
       
   132 */
       
   133 TInt CBrowseCommand::ProcessIncomingCommandL(TInt aMaxResponse)
       
   134 	{
       
   135 	LOG_FUNC
       
   136 	TInt result = KErrNotSupported;
       
   137 	iMaxResponse = aMaxResponse-5;
       
   138 
       
   139 	// This command has already been verified as containing at least a header
       
   140 	// and an accurate length field
       
   141 	switch(AvrcpBrowsing::BrowsingFrame::PduId(iFrame)) // PDU ID
       
   142 		{
       
   143 	case AvrcpBrowsing::ESetBrowsedPlayer:
       
   144 		{
       
   145 		result = HandleSetBrowsedPlayer();
       
   146 		break;
       
   147 		}
       
   148 	case AvrcpBrowsing::EGetFolderItems:
       
   149 		{
       
   150 		result = HandleGetFolderItems();
       
   151 		break;
       
   152 		}
       
   153 	case AvrcpBrowsing::EChangePath:
       
   154 		{
       
   155 		result = HandleChangePath();
       
   156 		break;
       
   157 		}
       
   158 	case AvrcpBrowsing::EGetItemAttributes:
       
   159 		{
       
   160 		result = HandleGetItemAttributes();
       
   161 		break;
       
   162 		}
       
   163 	case AvrcpBrowsing::ESearch:
       
   164 		{
       
   165 		result = HandleSearch();
       
   166 		break;
       
   167 		}
       
   168 	case AvrcpBrowsing::EGeneralReject:
       
   169 		// We only support the target role for browsing, so we should
       
   170 		// never receive a General Reject
       
   171 		// fallthrough
       
   172 	default:
       
   173 		{
       
   174 		result = HandleUnknownPdu();
       
   175 		}
       
   176 		};
       
   177 	return result;
       
   178 	}
       
   179 	
       
   180 
       
   181 /** Processes an outgoing response.
       
   182 
       
   183 This should only be called for vendor dependent commands as
       
   184 we respond to passthrough commands internally.
       
   185 
       
   186 @param aFrame The command data for the response.
       
   187 */
       
   188 void CBrowseCommand::ProcessOutgoingResponse(RBuf8& aCommandData)
       
   189 	{
       
   190 	__ASSERT_DEBUG(( (iInterfaceUid == TUid::Uid(KRemConMediaBrowseApiUid)) 
       
   191 				|| (iInterfaceUid == TUid::Uid(KRemConNowPlayingApiUid))
       
   192 				|| (iInterfaceUid == TUid::Uid(KUidAvrcpInternalInterface))),
       
   193 				AvrcpUtils::Panic(EAvrcpResponseToUnknownCommand));
       
   194 	
       
   195 	iFrame.Close();
       
   196 	iFrame.Assign(aCommandData);
       
   197 	TInt length = aCommandData.Length() - 3;
       
   198 	iFrame[1] = length >> 8;
       
   199 	iFrame[2] = length;
       
   200 	aCommandData.Assign(NULL);
       
   201 	}
       
   202 
       
   203 /** Set the response type in the AV/C frame.
       
   204 
       
   205 @param aErr The result of processing the operation. KErrNone if 
       
   206 			successful. KErrNotsupported if this operation is not
       
   207 			implemented, eg because no converter was found.
       
   208 */
       
   209 void CBrowseCommand::SetResult(TInt aErr)
       
   210 	{
       
   211 	LOG_FUNC
       
   212 	switch(aErr)
       
   213 		{
       
   214 		case KErrNone:
       
   215 			break;
       
   216 		case KErrCorrupt:
       
   217 		case EAvrcpResponseToUnknownCommand:
       
   218 		case KErrAvrcpAirInvalidCommand:
       
   219 		case KErrAvrcpAirInvalidParameter:
       
   220 		case KErrAvrcpAirParameterNotFound:
       
   221 		case KErrAvrcpAirInternalError:
       
   222 		case KErrAvrcpAirSuccess:
       
   223 		case KErrAvrcpAirUidChanged:
       
   224 		case KErrAvrcpAirReserved:
       
   225 		case KErrAvrcpAirInvalidDirection:
       
   226 		case KErrAvrcpAirNotADirectory:
       
   227 		case KErrAvrcpAirDoesNotExist:
       
   228 		case KErrAvrcpAirInvalidScope:
       
   229 		case KErrAvrcpAirRangeOutOfBounds:
       
   230 		case KErrAvrcpAirUidIsADirectory:
       
   231 		case KErrAvrcpAirMediaInUse:
       
   232 		case KErrAvrcpAirNowPlayingListFull:
       
   233 		case KErrAvrcpAirSearchNotSupported:
       
   234 		case KErrAvrcpAirSearchInProgress:
       
   235 		case KErrAvrcpAirInvalidPlayerId:
       
   236 		case KErrAvrcpAirPlayerNotBrowesable:
       
   237 		case KErrAvrcpAirPlayerNotAddressed:
       
   238 		case KErrAvrcpAirNoValidSearchResults:
       
   239 		case KErrAvrcpAirNoAvailablePlayers:
       
   240 		case KErrAvrcpAirAddressedPlayerChanged:
       
   241 		case KErrAvrcpInvalidScope:
       
   242 			{
       
   243 			// If this fails we can't send the error response - just give up
       
   244 			TRAPD(err, GenerateRejectPayloadL(aErr));
       
   245 			err = err; // Avoid warning about not using it.
       
   246 			break;
       
   247 			}
       
   248 		}
       
   249 	}
       
   250 
       
   251 /** Gets this command's frame.
       
   252 @return the browse frame for this command
       
   253 */	
       
   254 const TDesC8& CBrowseCommand::Data() const
       
   255 	{
       
   256 	LOG_FUNC
       
   257 	return iFrame;
       
   258 	}
       
   259 
       
   260 const TDesC8& CBrowseCommand::CommandData() const
       
   261 	{
       
   262 	LOG_FUNC
       
   263 	return iCommandData;
       
   264 	}
       
   265 
       
   266 void CBrowseCommand::GenerateRejectPayloadL(TInt aErr)
       
   267 	{
       
   268 	LOG_FUNC;
       
   269 	
       
   270 	TUint8 pduId = AvrcpBrowsing::BrowsingFrame::PduId(iFrame);
       
   271 	RRemConMediaErrorResponse errResponse;		
       
   272 	errResponse.iPduId = pduId;
       
   273 	errResponse.iStatus = RAvrcpIPC::SymbianErrToStatus(aErr);
       
   274 	
       
   275 	RBuf8 frame;
       
   276 	frame.CreateL(KBrowseResponseBaseLength);
       
   277 	CleanupClosePushL(frame);
       
   278 	errResponse.WriteL(frame);
       
   279 	CleanupStack::Pop(&frame);
       
   280 	
       
   281 	iFrame.Close();
       
   282 	iFrame.Assign(frame);
       
   283 	}
       
   284 
       
   285