bluetoothappprofiles/avrcp/groupnavigationapi/src/groupnavigationapi.cpp
changeset 70 f5508c13dfe0
parent 67 16e4b9007960
child 71 083fd884d7dd
equal deleted inserted replaced
67:16e4b9007960 70:f5508c13dfe0
     1 // Copyright (c) 2008-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 <remcongroupnavigationtarget.h>
       
    24 #include <remcongroupnavigationtargetobserver.h>
       
    25 
       
    26 #include <remconinterfaceselector.h>
       
    27 
       
    28 #include <avcframe.h>
       
    29 
       
    30 #include "remcongroupnavigation.h"
       
    31 
       
    32 #ifdef __FLOG_ACTIVE
       
    33 _LIT8(KLogComponent, LOG_COMPONENT_AVRCP_GROUP_NAVIGATION);
       
    34 #endif
       
    35 
       
    36 EXPORT_C CRemConGroupNavigationApiTarget* CRemConGroupNavigationApiTarget::NewL(CRemConInterfaceSelector& aInterfaceSelector, 
       
    37 		MRemConGroupNavigationTargetObserver& aObserver)
       
    38 	{
       
    39 	LOG_STATIC_FUNC
       
    40 
       
    41 	CRemConGroupNavigationApiTarget* self = new(ELeave) CRemConGroupNavigationApiTarget(aInterfaceSelector, aObserver);
       
    42 	CleanupStack::PushL(self);
       
    43 	self->ConstructL();
       
    44 	CleanupStack::Pop(self);
       
    45 	return self;
       
    46 	}
       
    47 
       
    48 EXPORT_C CRemConGroupNavigationApiTarget* CRemConGroupNavigationApiTarget::NewL(CRemConInterfaceSelector& aInterfaceSelector, 
       
    49 		MRemConGroupNavigationTargetObserver& aObserver,TBool aNextGroupSupported, TBool aPreviousGroupSupported)
       
    50 	{
       
    51 	LOG_STATIC_FUNC
       
    52 
       
    53 	CRemConGroupNavigationApiTarget* self = new(ELeave) CRemConGroupNavigationApiTarget(aInterfaceSelector, aObserver);
       
    54 	CleanupStack::PushL(self);
       
    55 	self->ConstructL(aNextGroupSupported,aPreviousGroupSupported);
       
    56 	CleanupStack::Pop(self);
       
    57 	return self;
       
    58 	}
       
    59 CRemConGroupNavigationApiTarget::CRemConGroupNavigationApiTarget(CRemConInterfaceSelector& aInterfaceSelector, 
       
    60 		MRemConGroupNavigationTargetObserver& aObserver)
       
    61 :	CRemConInterfaceBase(TUid::Uid(KRemConGroupNavigationApiUid), 
       
    62 						 KMaxSizeRemConGroupNavigationMsg, 
       
    63 						 aInterfaceSelector,
       
    64 						 ERemConClientTypeTarget), 
       
    65 	iObserver(aObserver), iPtr(0,0,0)
       
    66 	{
       
    67 	}
       
    68 	
       
    69 void CRemConGroupNavigationApiTarget::ConstructL()
       
    70 	{
       
    71 	// Create a output buffer (arbitrary value of 32 for granularity of buffer expansion)
       
    72 	iOutData = CBufFlat::NewL(32);
       
    73 	iOutData->SetReserveL(sizeof(TPckg<TRemConGroupNavigationResponse>)); 
       
    74 	BaseConstructL();
       
    75 	}
       
    76 void CRemConGroupNavigationApiTarget::ConstructL(TBool aNextGroupSupported, TBool aPreviousGroupSupported)
       
    77 	{
       
    78 	// Create a output buffer (arbitrary value of 32 for granularity of buffer expansion)
       
    79 	iOutData = CBufFlat::NewL(32);
       
    80 	iOutData->SetReserveL(sizeof(TPckg<TRemConGroupNavigationResponse>));
       
    81 	
       
    82 	RRemConInterfaceFeatures features;
       
    83 	User::LeaveIfError(features.Open());
       
    84 	CleanupClosePushL(features);
       
    85 	
       
    86 	if(aNextGroupSupported)
       
    87 		{
       
    88 		features.AddOperationL(ENextGroup);
       
    89 		}
       
    90 	
       
    91 	if(aPreviousGroupSupported)
       
    92 		{
       
    93 		features.AddOperationL(EPreviousGroup);
       
    94 		}
       
    95 	
       
    96 	BaseConstructL(features);
       
    97 	CleanupStack::PopAndDestroy(&features);
       
    98 	}
       
    99 	
       
   100 
       
   101 /** Destructor.
       
   102 
       
   103 @publishedAll
       
   104 @released
       
   105 */
       
   106 EXPORT_C CRemConGroupNavigationApiTarget::~CRemConGroupNavigationApiTarget()
       
   107 	{
       
   108 	delete iOutData;
       
   109 	iStream.Close();
       
   110 	}
       
   111 
       
   112 /** Gets a pointer to a specific interface version.
       
   113 
       
   114 @return A pointer to the interface, NULL if not supported.
       
   115 @internalComponent
       
   116 @released
       
   117 */
       
   118 TAny* CRemConGroupNavigationApiTarget::GetInterfaceIf(TUid aUid)
       
   119 	{
       
   120 	TAny* ret = NULL;
       
   121 	if ( aUid == TUid::Uid(KRemConInterfaceIf1) )
       
   122 		{
       
   123 		ret = reinterpret_cast<TAny*>(
       
   124 			static_cast<MRemConInterfaceIf*>(this)
       
   125 			);
       
   126 		}
       
   127 
       
   128 	return ret;
       
   129 	}
       
   130 
       
   131 EXPORT_C void CRemConGroupNavigationApiTarget::NextGroupResponse(TRequestStatus*& aStatus, TInt aError)
       
   132 	{
       
   133 	SendGroupResponse(ENextGroup, aStatus, aError);
       
   134 	}
       
   135 
       
   136 EXPORT_C void CRemConGroupNavigationApiTarget::PreviousGroupResponse(TRequestStatus*& aStatus, TInt aError)
       
   137 	{
       
   138 	SendGroupResponse(EPreviousGroup, aStatus, aError);
       
   139 	}
       
   140 
       
   141 void CRemConGroupNavigationApiTarget::SendGroupResponse(TGroupNavigationPassthroughOperationIds aId, TRequestStatus*& aStatus, TInt aError)
       
   142 	{
       
   143 	// format data to be sent
       
   144   	TRAPD(error, iOutData->ResizeL(sizeof(TRemConGroupNavigationResponse)));
       
   145   	if (error != KErrNone)
       
   146   		{
       
   147   		// if this fails, then silently drop response
       
   148   		return;
       
   149   		}
       
   150   		
       
   151 	TRemConGroupNavigationResponse response;
       
   152 	response.iError = aError;
       
   153 	iOutData->Write(0,TPckg<TRemConGroupNavigationResponse>(response));
       
   154 	iPtr.Set(iOutData->Ptr(0));
       
   155 
       
   156 	// if a TRequestStatus has been supplied
       
   157 	if (aStatus)
       
   158 		{
       
   159 		InterfaceSelector().Send(*aStatus, TUid::Uid(KRemConGroupNavigationApiUid), aId, iNumRemotes, ERemConResponse, iPtr);
       
   160 		}
       
   161 	else
       
   162 		{
       
   163 		InterfaceSelector().SendUnreliable(TUid::Uid(KRemConGroupNavigationApiUid), aId, ERemConResponse, iPtr);
       
   164 		}
       
   165 	}
       
   166 
       
   167 // from MRemConInterfaceIf
       
   168 void CRemConGroupNavigationApiTarget::MrcibNewMessage(TUint aOperationId, const TDesC8& aData)
       
   169 	{
       
   170 	LOG1(_L("\taOperationId = 0x%02x"), aOperationId);
       
   171 	LOG1(_L("\taData.Length = %d"), aData.Length());
       
   172 
       
   173 	/* Decode the get GroupNavigation message */
       
   174 	TGroupNavigationPassthroughOperationIds currentOp = static_cast<TGroupNavigationPassthroughOperationIds>(aOperationId);
       
   175   	TRemConCoreApiButtonAction button = static_cast<TRemConCoreApiButtonAction>(aData.Ptr()[0]);
       
   176 
       
   177 	switch (currentOp)
       
   178 		{
       
   179 		case ENextGroup:
       
   180 			{
       
   181 			iObserver.MrcgntoNextGroup( button );
       
   182 			break;
       
   183 			}
       
   184 		case EPreviousGroup:
       
   185 			{
       
   186 			iObserver.MrcgntoPreviousGroup( button );
       
   187 			break;
       
   188 			}		
       
   189 		default:
       
   190 			break;
       
   191 
       
   192 		}
       
   193 	}
       
   194