bluetoothapitest/bluetoothsvs/T_BTUserAPI/src/T_BluetoothSynchronousLinkData.cpp
changeset 0 29b1cd4cb562
equal deleted inserted replaced
-1:000000000000 0:29b1cd4cb562
       
     1 /*
       
     2 * Copyright (c) 2005-2009 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:
       
    15 *
       
    16 */
       
    17 
       
    18 #include "T_BluetoothSynchronousLinkData.h"
       
    19 #include "T_BTDevAddrData.h"
       
    20 #include "T_BTSyncBandWidthData.h"
       
    21 #include "T_BTUtil.h"
       
    22 #include "T_TBTSockAddrChild.h"
       
    23 
       
    24 /*@{*/
       
    25 //Parameters
       
    26 _LIT(KRSocketServ,												"socketserv");
       
    27 _LIT(KTBTDevAddr,												"tbtdevaddr");
       
    28 _LIT(KIntDevAddr,												"integerdevaddr");
       
    29 _LIT(KPacketType,												"packettype");
       
    30 _LIT(KSyncPacket,												"syncpacket");
       
    31 _LIT(KData,														"data");
       
    32 _LIT(KVoiceSetting,												"voicesetting");
       
    33 _LIT(KSyncBandwidth,											"syncbandwidth");
       
    34 _LIT(KLatency,													"latency");
       
    35 _LIT(KRetransmissionType,										"retransmissiontype");
       
    36 _LIT(KUseAlternateNotifier,										"usealternatenotifier");
       
    37 _LIT(KUid,														"uid");
       
    38 _LIT(KExpectNull,												"expectnull");
       
    39 _LIT(KExpected, 												"expected");
       
    40 _LIT(KErrForSetupConnection,									"errforsetupconnection");
       
    41 _LIT(KErrForSend,												"errforsend");
       
    42 _LIT(KErrForReceive,											"errforreceive");
       
    43 _LIT(KErrForAcceptConnection,									"errforacceptconnection");
       
    44 _LIT(KErrForDisconnect,											"errfordisconnect");
       
    45 _LIT(KIncOutstanding,											"incoutstanding");
       
    46 
       
    47 //Commands
       
    48 _LIT(KCmdNewL,													"NewL");
       
    49 _LIT(KCmdNewLC,													"NewLC");
       
    50 _LIT(KCmdSetupConnection,										"SetupConnection");
       
    51 _LIT(KCmdCancelSetup,											"CancelSetup");
       
    52 _LIT(KCmdDisconnect,											"Disconnect");
       
    53 _LIT(KCmdSend,													"Send");
       
    54 _LIT(KCmdCancelSend,											"CancelSend");
       
    55 _LIT(KCmdReceive,												"Receive");
       
    56 _LIT(KCmdCancelReceive,											"CancelReceive");
       
    57 _LIT(KCmdAcceptConnection,										"AcceptConnection");
       
    58 _LIT(KCmdCancelAccept,											"CancelAccept");
       
    59 _LIT(KCmdSetCoding,												"SetCoding");
       
    60 _LIT(KCmdCoding,												"Coding");
       
    61 _LIT(KCmdSetMaxBandwidth,										"SetMaxBandwidth");
       
    62 _LIT(KCmdBandwidth,												"Bandwidth");
       
    63 _LIT(KCmdSetMaxLatency,											"SetMaxLatency");
       
    64 _LIT(KCmdLatency,												"Latency");
       
    65 _LIT(KCmdSetRetransmissionEffort,								"SetRetransmissionEffort");
       
    66 _LIT(KCmdRetransmissionEffort,									"RetransmissionEffort");
       
    67 _LIT(KCmdRemoteName,											"RemoteName");
       
    68 _LIT(KCmdSetNotifier,											"SetNotifier");
       
    69 _LIT(KCmdDestructor,											"~");
       
    70 _LIT(KCmdMBSLN_ExtensionInterfaceL,								"MBSLN_ExtensionInterfaceL");
       
    71 
       
    72 //	Logging
       
    73 _LIT(KLogMissingParameters,			"Missing parameters '%S' or '%S'");
       
    74 _LIT(KLogMissingParameter,			"Missing parameter '%S'");
       
    75 /*@}*/
       
    76 
       
    77 //////////////////////////////////////////////////////////////////////
       
    78 // Construction/Destruction
       
    79 //////////////////////////////////////////////////////////////////////
       
    80 
       
    81 CT_BluetoothSynchronousLinkData* CT_BluetoothSynchronousLinkData::NewL()
       
    82 	{
       
    83 	CT_BluetoothSynchronousLinkData*	ret=new (ELeave) CT_BluetoothSynchronousLinkData();
       
    84 	CleanupStack::PushL(ret);
       
    85 	ret->ConstructL();
       
    86 	CleanupStack::Pop(ret);
       
    87 	return ret;
       
    88 	}
       
    89 
       
    90 CT_BluetoothSynchronousLinkData::CT_BluetoothSynchronousLinkData()
       
    91 :	iData(NULL)
       
    92 ,	iErrForSetupConnection(0)
       
    93 ,	iErrForSend(0)
       
    94 ,	iErrForReceive(0)
       
    95 ,	iErrForAcceptConnection(0)
       
    96 ,	iErrForDisconnect(0)
       
    97 ,	ibtSyncPackets(NULL)
       
    98 ,	iSetupIndex(0)
       
    99 ,	iDisconnectionIndex(0)
       
   100 ,	iAcceptIndex(0)
       
   101 ,	iSendIndex(0)
       
   102 ,	iReceiveIndex(0)
       
   103 	{
       
   104 	}
       
   105 
       
   106 void CT_BluetoothSynchronousLinkData::ConstructL()
       
   107 	{
       
   108 	}
       
   109 
       
   110 CT_BluetoothSynchronousLinkData::~CT_BluetoothSynchronousLinkData()
       
   111 	{
       
   112 	DestroyData();
       
   113 	}
       
   114 
       
   115 //	Service methods
       
   116 TAny* CT_BluetoothSynchronousLinkData::GetObject()
       
   117 	{
       
   118 	return iData;
       
   119 	}
       
   120 
       
   121 void CT_BluetoothSynchronousLinkData::SetObjectL(TAny* aObject)
       
   122 	{
       
   123 	//called when loading up persistent data
       
   124 	DestroyData();
       
   125 	iData = static_cast<CBluetoothSynchronousLink*>(aObject);
       
   126 	}
       
   127 
       
   128 void CT_BluetoothSynchronousLinkData::DisownObjectL()
       
   129 	{
       
   130 	iData=NULL;
       
   131 	}
       
   132 
       
   133 void CT_BluetoothSynchronousLinkData::DestroyData()
       
   134 	{
       
   135 	delete iData;
       
   136 	iData = NULL;
       
   137 	if ( ibtSyncPackets )
       
   138 		{
       
   139 		ibtSyncPackets = NULL;
       
   140 		}
       
   141 	}
       
   142 
       
   143 inline TCleanupOperation CT_BluetoothSynchronousLinkData::CleanupOperation()
       
   144 	{
       
   145 	return CleanupOperation;
       
   146 	}
       
   147 
       
   148 void CT_BluetoothSynchronousLinkData::CleanupOperation(TAny* aAny)
       
   149 	{
       
   150 	CBluetoothSynchronousLink* arg=static_cast<CBluetoothSynchronousLink*>(aAny);
       
   151 	delete arg;
       
   152 	}
       
   153 
       
   154 void CT_BluetoothSynchronousLinkData::HandleSetupConnectionCompleteL(TInt aError)
       
   155 	{
       
   156 	INFO_PRINTF2(_L("MBluetoothSynchronousLinkNotifier::HandleSetupConnectionCompleteL Status (%d)"), aError);
       
   157 	
       
   158 	DecOutstanding();
       
   159 	if ( aError!=iErrForSetupConnection )
       
   160 		{
       
   161 		ERR_PRINTF2(_L("HandleSetupConnectionCompleteL Call failed: aError = %d"),aError);
       
   162 		SetAsyncError(iSetupIndex, aError);
       
   163 		}
       
   164 	else
       
   165 		{
       
   166 		INFO_PRINTF1(_L("HandleSetupConnectionCompleteL successful" ));
       
   167 		}
       
   168 	}
       
   169 
       
   170 void CT_BluetoothSynchronousLinkData::HandleDisconnectionCompleteL(TInt aError)
       
   171 	{
       
   172 	INFO_PRINTF2(_L("MBluetoothSynchronousLinkNotifier::HandleDisconnectionCompleteL Status (%d)"), aError);
       
   173 	
       
   174 	DecOutstanding();
       
   175 	if ( aError!=iErrForDisconnect) 
       
   176 		{
       
   177 		 ERR_PRINTF2(_L("HandleDisconnectionCompleteL Call failed: aError = %d"),aError);
       
   178 		 SetAsyncError(iDisconnectionIndex, aError);
       
   179 		}
       
   180 	else
       
   181 		{
       
   182 		 INFO_PRINTF1(_L("HandleDisconnectionCompleteL successful" ));
       
   183 		}
       
   184 	}
       
   185 
       
   186 void CT_BluetoothSynchronousLinkData::HandleAcceptConnectionCompleteL(TInt aError)
       
   187 	{
       
   188 	INFO_PRINTF2(_L("MBluetoothSynchronousLinkNotifier::HandleAcceptConnectionCompleteL Status (%d)"), aError);
       
   189 	
       
   190 	DecOutstanding();
       
   191 	if ( aError!=iErrForAcceptConnection) 
       
   192 		{
       
   193 		ERR_PRINTF2(_L("HandleAcceptConnectionCompleteL Call failed: aError = %d"),aError);
       
   194 		SetAsyncError(iAcceptIndex, aError);
       
   195 		}
       
   196 	else
       
   197 		{
       
   198 		INFO_PRINTF1(_L("HandleAcceptConnectionCompleteL successful" ));
       
   199 		}
       
   200 	}
       
   201 
       
   202 void CT_BluetoothSynchronousLinkData::HandleSendCompleteL(TInt aError)
       
   203 	{
       
   204 	INFO_PRINTF2(_L("MBluetoothSynchronousLinkNotifier::HandleSendCompleteL Status (%d)"), aError);
       
   205 	
       
   206 	DecOutstanding();
       
   207 	if ( aError!=iErrForSend )
       
   208 		{
       
   209 		ERR_PRINTF2(_L("HandleSendCompleteL Call failed: aError = %d"),aError);
       
   210 		SetAsyncError(iSendIndex, aError);
       
   211 		}
       
   212 	else
       
   213 		{
       
   214 		INFO_PRINTF1(_L("HandleSendCompleteL successful" ));
       
   215 		}
       
   216 	}
       
   217 
       
   218 void CT_BluetoothSynchronousLinkData::HandleReceiveCompleteL(TInt aError)
       
   219 	{
       
   220 	INFO_PRINTF2(_L("MBluetoothSynchronousLinkNotifier::HandleReceiveCompleteL Status (%d)"), aError);
       
   221 	
       
   222 	DecOutstanding();
       
   223 	if ( aError!=iErrForReceive )
       
   224 		{
       
   225 		ERR_PRINTF2(_L("HandleReceiveCompleteL Call failed: aError = %d"),aError);
       
   226 		SetAsyncError(iReceiveIndex, aError);
       
   227 		}
       
   228 	else
       
   229 		{
       
   230 		INFO_PRINTF1(_L("HandleReceiveCompleteL successful" ));
       
   231 		}
       
   232 	}
       
   233 
       
   234 TBool CT_BluetoothSynchronousLinkData::DoCommandL(const TTEFFunction& aCommand, const TTEFSectionName& aSection, const TInt aAsyncErrorIndex)
       
   235 	{
       
   236 	TBool	ret = ETrue;
       
   237 
       
   238 	if ( aCommand==KCmdNewL )
       
   239 		{
       
   240 		DoCmdNewL(aSection);
       
   241 		}
       
   242 	else if ( aCommand==KCmdNewLC )
       
   243 		{
       
   244 		DoCmdNewLC(aSection);
       
   245 		}
       
   246 	else if ( aCommand==KCmdSetupConnection )
       
   247 		{
       
   248 		DoCmdSetupConnection(aSection, aAsyncErrorIndex);
       
   249 		}
       
   250 	else if ( aCommand==KCmdCancelSetup )
       
   251 		{
       
   252 		DoCmdCancelSetup();
       
   253 		}
       
   254 	else if ( aCommand==KCmdDisconnect )
       
   255 		{
       
   256 		DoCmdDisconnect(aSection, aAsyncErrorIndex);
       
   257 		}
       
   258 	else if ( aCommand==KCmdSend )
       
   259 		{
       
   260 		DoCmdSend(aSection, aAsyncErrorIndex);
       
   261 		}
       
   262 	else if ( aCommand==KCmdCancelSend )
       
   263 		{
       
   264 		DoCmdCancelSend();
       
   265 		}
       
   266 	else if ( aCommand==KCmdReceive )
       
   267 		{
       
   268 		DoCmdReceive(aSection, aAsyncErrorIndex);
       
   269 		}
       
   270 	else if ( aCommand==KCmdCancelReceive )
       
   271 		{
       
   272 		DoCmdCancelReceive();
       
   273 		}
       
   274 	else if ( aCommand==KCmdAcceptConnection )
       
   275 		{
       
   276 		DoCmdAcceptConnection(aSection, aAsyncErrorIndex);
       
   277 		}
       
   278 	else if ( aCommand==KCmdCancelAccept )
       
   279 		{
       
   280 		DoCmdCancelAccept();
       
   281 		}
       
   282 	else if ( aCommand==KCmdSetCoding )
       
   283 		{
       
   284 		DoCmdSetCoding(aSection);
       
   285 		}
       
   286 	else if ( aCommand==KCmdCoding )
       
   287 		{
       
   288 		DoCmdCoding(aSection);
       
   289 		}
       
   290 	else if ( aCommand==KCmdSetMaxBandwidth )
       
   291 		{
       
   292 		DoCmdSetMaxBandwidth(aSection);
       
   293 		}
       
   294 	else if ( aCommand==KCmdBandwidth )
       
   295 		{
       
   296 		DoCmdBandwidth();
       
   297 		}
       
   298 	else if ( aCommand==KCmdSetMaxLatency )
       
   299 		{
       
   300 		DoCmdSetMaxLatency(aSection);
       
   301 		}
       
   302 	else if ( aCommand==KCmdLatency )
       
   303 		{
       
   304 		DoCmdLatency(aSection);
       
   305 		}
       
   306 	else if ( aCommand==KCmdSetRetransmissionEffort )
       
   307 		{
       
   308 		DoCmdSetRetransmissionEffort(aSection);
       
   309 		}
       
   310 	else if ( aCommand==KCmdRetransmissionEffort )
       
   311 		{
       
   312 		DoCmdRetransmissionEffort(aSection);
       
   313 		}
       
   314 	else if ( aCommand==KCmdRemoteName )
       
   315 		{
       
   316 		DoCmdRemoteName(aSection);
       
   317 		}
       
   318 	else if ( aCommand==KCmdSetNotifier )
       
   319 		{
       
   320 		DoCmdSetNotifier(aSection);
       
   321 		}
       
   322 	else if ( aCommand==KCmdDestructor )
       
   323 		{
       
   324 		DoCmdDestructor();
       
   325 		}
       
   326 	else if ( aCommand==KCmdMBSLN_ExtensionInterfaceL )
       
   327 		{
       
   328 		DoCmdMBSLN_ExtensionInterfaceL(aSection);
       
   329 		}
       
   330 	else
       
   331 		{
       
   332 		ret=EFalse;
       
   333 		}
       
   334 
       
   335 	return ret;
       
   336 	}
       
   337 
       
   338 
       
   339 /**
       
   340 Test NewL()
       
   341 */
       
   342 void CT_BluetoothSynchronousLinkData::DoCmdNewL(const TDesC& aSection)
       
   343 	{
       
   344 	INFO_PRINTF1(_L("CBluetoothSynchronousLink NewL Call"));
       
   345 	DestroyData();
       
   346 	
       
   347 	TPtrC	socketServName;
       
   348 	if(GetStringFromConfig(aSection, KRSocketServ(), socketServName))
       
   349 		{
       
   350 		RSocketServ* socketServ=static_cast<RSocketServ*>(GetDataObjectL(socketServName));
       
   351 		TRAPD(err, iData = CBluetoothSynchronousLink::NewL(*this, *socketServ));
       
   352 		if( err!=KErrNone )
       
   353 			{
       
   354 			INFO_PRINTF2(_L("CBluetoothSynchronousLink Standard Constructor NewL err=%d" ),err);
       
   355 			SetError(err);
       
   356 			}
       
   357 		}
       
   358 	else
       
   359 		{
       
   360 		ERR_PRINTF2(KLogMissingParameter, &KRSocketServ());
       
   361 		SetBlockResult(EFail);
       
   362 		}
       
   363 	}
       
   364 
       
   365 
       
   366 /**
       
   367 Test NewLC()
       
   368 */
       
   369 void CT_BluetoothSynchronousLinkData::DoCmdNewLC(const TDesC& aSection)
       
   370 	{
       
   371 	INFO_PRINTF1(_L("CBluetoothSynchronousLink NewLC Call"));
       
   372 	DestroyData();
       
   373 	
       
   374 	TPtrC	socketServName;
       
   375 	if(GetStringFromConfig(aSection, KRSocketServ(), socketServName))
       
   376 		{
       
   377 		RSocketServ* socketServ=static_cast<RSocketServ*>(GetDataObjectL(socketServName));
       
   378 		TRAPD(err, iData = CBluetoothSynchronousLink::NewLC(*this, *socketServ); CleanupStack::Pop(););
       
   379 		if( err!=KErrNone )
       
   380 			{
       
   381 			INFO_PRINTF2(_L("CBluetoothSynchronousLink Standard Constructor NewLC err=%d" ),err);
       
   382 			SetError(err);
       
   383 			}
       
   384 		}
       
   385 	else
       
   386 		{
       
   387 		ERR_PRINTF2(KLogMissingParameter, &KRSocketServ());
       
   388 		SetBlockResult(EFail);
       
   389 		}
       
   390 	}
       
   391 
       
   392 
       
   393 /**
       
   394 Test SetupConnection()
       
   395 */
       
   396 void CT_BluetoothSynchronousLinkData::DoCmdSetupConnection(const TDesC& aSection, const TInt aAsyncErrorIndex)
       
   397 	{
       
   398 	INFO_PRINTF1(_L("CBluetoothSynchronousLink SetupConnection Call"));
       
   399 	
       
   400 	TBool	foundTBTDevAddr = EFalse;
       
   401 	TPtrC	tbtDevAddrName;
       
   402 	CT_BTDevAddrData* tbtDevAddrData = NULL;
       
   403 	if(GetStringFromConfig(aSection, KTBTDevAddr(), tbtDevAddrName))
       
   404 		{
       
   405 		foundTBTDevAddr = ETrue;
       
   406 		tbtDevAddrData = static_cast<CT_BTDevAddrData*>(GetDataWrapperL(tbtDevAddrName));
       
   407 		}
       
   408 	
       
   409 	TBool	foundIntDevAddr = EFalse;
       
   410 	TInt	intBtDevAddr = 0;
       
   411 	if(GetIntFromConfig(aSection, KIntDevAddr(), intBtDevAddr))
       
   412 		{
       
   413 		foundIntDevAddr = ETrue;
       
   414 		}
       
   415 	
       
   416 	if( !foundTBTDevAddr & !foundIntDevAddr )
       
   417 		{
       
   418 		ERR_PRINTF3(KLogMissingParameters, &KTBTDevAddr(), &KIntDevAddr());
       
   419 		SetBlockResult(EFail);
       
   420 		}
       
   421 	
       
   422 	TInt err = 0;
       
   423 	//SetupConnection()2
       
   424 	TBool	foundPackType = EFalse;
       
   425 	TPtrC	packetTypeName;
       
   426 	TInt	packetTypeValue;
       
   427 	if(GetStringFromConfig(aSection, KPacketType(), packetTypeName))
       
   428 		{
       
   429 		if ( CT_BTUtil::GetPacketTypeIntValue(packetTypeName, packetTypeValue) )
       
   430 			{
       
   431 			INFO_PRINTF2(_L("CBluetoothSynchronousLink SetupConnection: packetTypeValue = %d"), packetTypeValue);
       
   432 			foundPackType = ETrue;
       
   433 			if( foundTBTDevAddr )
       
   434 				{
       
   435 				const TBTDevAddr* btDevAddr = tbtDevAddrData->GetAddress();
       
   436 				err = iData->SetupConnection(*btDevAddr, packetTypeValue);
       
   437 				}
       
   438 			else
       
   439 				{
       
   440 				const TBTDevAddr intDevAddr(intBtDevAddr);
       
   441 				iBTDeveAddr = intDevAddr;
       
   442 				err = iData->SetupConnection(iBTDeveAddr, packetTypeValue);
       
   443 				}
       
   444 			}
       
   445 		else
       
   446 			{
       
   447 			ERR_PRINTF1(_L("Unknow input for PacketType"));
       
   448 			SetBlockResult(EFail);
       
   449 			}
       
   450 		}
       
   451 	
       
   452 	//SetupConnection()3
       
   453 	TBool	foundSyncPack = EFalse;
       
   454 	TPtrC	syncPacketName;
       
   455 	if (GetStringFromConfig(aSection, KSyncPacket(), syncPacketName) )
       
   456 		{
       
   457 		TBTSyncPackets*	tbtSyncPackets = static_cast<TBTSyncPackets*>(GetDataObjectL(syncPacketName));
       
   458 		foundSyncPack = ETrue;
       
   459 		if( foundTBTDevAddr )
       
   460 			{
       
   461 			const TBTDevAddr* btDevAddr = tbtDevAddrData->GetAddress();
       
   462 			err = iData->SetupConnection(*btDevAddr, *tbtSyncPackets);
       
   463 			}
       
   464 		else
       
   465 			{
       
   466 			const TBTDevAddr intDevAddr(intBtDevAddr);
       
   467 			iBTDeveAddr = intDevAddr;
       
   468 			err = iData->SetupConnection(iBTDeveAddr, *tbtSyncPackets);
       
   469 			}
       
   470 		}
       
   471 	
       
   472 	//SetupConnection()1
       
   473 	if( !foundPackType & !foundSyncPack )
       
   474 		{
       
   475 		if( foundTBTDevAddr )
       
   476 			{
       
   477 			const TBTDevAddr* btDevAddr = tbtDevAddrData->GetAddress();
       
   478 			err = iData->SetupConnection(*btDevAddr);
       
   479 			}
       
   480 		else
       
   481 			{
       
   482 			const TBTDevAddr intDevAddr(intBtDevAddr);
       
   483 			iBTDeveAddr = intDevAddr;
       
   484 			err = iData->SetupConnection(iBTDeveAddr);
       
   485 			}
       
   486 		}
       
   487 	
       
   488 	if(err != KErrNone)
       
   489 		{
       
   490 		ERR_PRINTF2(_L("CBluetoothSynchronousLink SetupConnection failed with error %d"), err);
       
   491 		SetError(err);
       
   492 		}
       
   493 	else
       
   494 		{
       
   495 		IncOutstanding();
       
   496 		iSetupIndex = aAsyncErrorIndex;
       
   497 		
       
   498 		}
       
   499 	
       
   500 	if( !GetIntFromConfig(aSection, KErrForSetupConnection(), iErrForSetupConnection))
       
   501 		{
       
   502 		ERR_PRINTF2(KLogMissingParameter, &KErrForSetupConnection());
       
   503 		SetBlockResult(EFail);
       
   504 		}
       
   505 	}
       
   506 
       
   507 
       
   508 /**
       
   509 Test CancelSetup()
       
   510 */
       
   511 void CT_BluetoothSynchronousLinkData::DoCmdCancelSetup()
       
   512 	{
       
   513 	INFO_PRINTF1(_L("CBluetoothSynchronousLink CancelSetup Call"));
       
   514 	iData->CancelSetup();
       
   515 	DecOutstanding();
       
   516 	}
       
   517 
       
   518 
       
   519 /**
       
   520 Test Disconnect()
       
   521 */
       
   522 void CT_BluetoothSynchronousLinkData::DoCmdDisconnect(const TDesC& aSection, const TInt aAsyncErrorIndex)
       
   523 	{
       
   524 	INFO_PRINTF1(_L("CBluetoothSynchronousLink Disconnect Call"));
       
   525 	
       
   526 	TInt err = iData->Disconnect();
       
   527 	if(err != KErrNone)
       
   528 		{
       
   529 		ERR_PRINTF2(_L("CBluetoothSynchronousLink Disconnect failed with error %d"), err);
       
   530 		SetError(err);
       
   531 		}
       
   532 	else
       
   533 		{
       
   534 		IncOutstanding();
       
   535 		iDisconnectionIndex = aAsyncErrorIndex;
       
   536 		}
       
   537 	
       
   538 	if( !GetIntFromConfig(aSection, KErrForDisconnect(), iErrForDisconnect))
       
   539 		{
       
   540 		ERR_PRINTF2(KLogMissingParameter, &KErrForDisconnect());
       
   541 		SetBlockResult(EFail);
       
   542 		}
       
   543 	}
       
   544 
       
   545 
       
   546 /**
       
   547 Test Send()
       
   548 */
       
   549 void CT_BluetoothSynchronousLinkData::DoCmdSend(const TDesC& aSection, const TInt aAsyncErrorIndex)
       
   550 	{
       
   551 	INFO_PRINTF1(_L("CBluetoothSynchronousLink Send Call"));
       
   552 	
       
   553 	TPtrC	dataToSend;
       
   554 	if(GetStringFromConfig(aSection, KData(), dataToSend))
       
   555 		{
       
   556 		TBuf8<KDataSize>	dataToSend8(_L8(""));
       
   557 		dataToSend8.Copy(dataToSend);
       
   558 		
       
   559 		TInt err = iData->Send(dataToSend8);
       
   560 		if(err != KErrNone)
       
   561 			{
       
   562 			ERR_PRINTF2(_L("CBluetoothSynchronousLink Send failed with error %d"), err);
       
   563 			SetError(err);
       
   564 			}
       
   565 		}
       
   566 	else
       
   567 		{
       
   568 		ERR_PRINTF2(KLogMissingParameter, &KData());
       
   569 		SetBlockResult(EFail);
       
   570 		}
       
   571 	IncOutstanding();
       
   572 	iSendIndex = aAsyncErrorIndex;
       
   573 	
       
   574 	if( !GetIntFromConfig(aSection, KErrForSend(), iErrForSend))
       
   575 		{
       
   576 		ERR_PRINTF2(KLogMissingParameter, &KErrForSend());
       
   577 		SetBlockResult(EFail);
       
   578 		}
       
   579 	}
       
   580 
       
   581 
       
   582 /**
       
   583 Test CancelSend()
       
   584 */
       
   585 void CT_BluetoothSynchronousLinkData::DoCmdCancelSend()
       
   586 	{
       
   587 	INFO_PRINTF1(_L("CBluetoothSynchronousLink CancelSend Call"));
       
   588 	iData->CancelSend();
       
   589 	DecOutstanding();
       
   590 	}
       
   591 
       
   592 
       
   593 /**
       
   594 Test Receive()
       
   595 */
       
   596 void CT_BluetoothSynchronousLinkData::DoCmdReceive(const TDesC& aSection, const TInt aAsyncErrorIndex)
       
   597 	{
       
   598 	INFO_PRINTF1(_L("CBluetoothSynchronousLink Receive Call"));
       
   599 	
       
   600 	TPtrC	dataToReceive;
       
   601 	if(GetStringFromConfig(aSection, KData(), dataToReceive))
       
   602 		{
       
   603 		TBuf8<KDataSize>	dataToReceive8(_L8(""));
       
   604 		dataToReceive8.Copy(dataToReceive);
       
   605 		
       
   606 		TInt err = iData->Receive(dataToReceive8);
       
   607 		if(err != KErrNone)
       
   608 			{
       
   609 			ERR_PRINTF2(_L("CBluetoothSynchronousLink Receive failed with error %d"), err);
       
   610 			SetError(err);
       
   611 			}
       
   612 		}
       
   613 	else
       
   614 		{
       
   615 		ERR_PRINTF2(KLogMissingParameter, &KData());
       
   616 		SetBlockResult(EFail);
       
   617 		}
       
   618 	IncOutstanding();
       
   619 	iReceiveIndex = aAsyncErrorIndex;
       
   620 
       
   621 	if( !GetIntFromConfig(aSection, KErrForReceive(), iErrForReceive))
       
   622 		{
       
   623 		ERR_PRINTF2(KLogMissingParameter, &KErrForReceive());
       
   624 		SetBlockResult(EFail);
       
   625 		}
       
   626 	}
       
   627 
       
   628 
       
   629 /**
       
   630 Test CancelReceive()
       
   631 */
       
   632 void CT_BluetoothSynchronousLinkData::DoCmdCancelReceive()
       
   633 	{
       
   634 	INFO_PRINTF1(_L("CBluetoothSynchronousLink CancelReceive Call"));
       
   635 	iData->CancelReceive();
       
   636 	DecOutstanding();
       
   637 	}
       
   638 
       
   639 
       
   640 /**
       
   641 Test AcceptConnection()
       
   642 */
       
   643 void CT_BluetoothSynchronousLinkData::DoCmdAcceptConnection(const TDesC& aSection, const TInt aAsyncErrorIndex)
       
   644 	{
       
   645 	INFO_PRINTF1(_L("CBluetoothSynchronousLink AcceptConnection Call"));
       
   646 	
       
   647 	TInt err = 0;
       
   648 	TPtrC	syncPacketName;
       
   649 	if (GetStringFromConfig(aSection, KSyncPacket(), syncPacketName) )
       
   650 		{
       
   651 		ibtSyncPackets = static_cast<TBTSyncPackets*>(GetDataObjectL(syncPacketName));
       
   652 		err = iData->AcceptConnection(*ibtSyncPackets);
       
   653 		}
       
   654 	else
       
   655 		{
       
   656 		err = iData->AcceptConnection();
       
   657 		}
       
   658 	
       
   659 	if(err != KErrNone)
       
   660 		{
       
   661 		ERR_PRINTF2(_L("CBluetoothSynchronousLink AcceptConnection failed with error %d"), err);
       
   662 		SetError(err);
       
   663 		}
       
   664 	else
       
   665 		{
       
   666         TBool incoutstanding = ETrue;
       
   667         // if in ini file, incoutstanding = false, this case is a unconnected case and will not expect a callback, so do not IncOutstanding().
       
   668         if ( (GetBoolFromConfig(aSection, KIncOutstanding(), incoutstanding)) &&  (incoutstanding == EFalse) ) 
       
   669             {
       
   670             INFO_PRINTF1(_L("incoutstanding is false, do not IncOutstanding()"));
       
   671             }
       
   672         else
       
   673             {
       
   674             IncOutstanding();
       
   675     		iAcceptIndex = aAsyncErrorIndex;
       
   676             }
       
   677 		}
       
   678 	
       
   679 	if( !GetIntFromConfig(aSection, KErrForAcceptConnection(), iErrForAcceptConnection))
       
   680 		{
       
   681 		ERR_PRINTF2(KLogMissingParameter, &KErrForAcceptConnection());
       
   682 		SetBlockResult(EFail);
       
   683 		}
       
   684 	}
       
   685 
       
   686 
       
   687 /**
       
   688 Test CancelAccept()
       
   689 */
       
   690 void CT_BluetoothSynchronousLinkData::DoCmdCancelAccept()
       
   691 	{
       
   692 	INFO_PRINTF1(_L("CBluetoothSynchronousLink CancelAccept Call"));
       
   693 	iData->CancelAccept();
       
   694 	DecOutstanding();
       
   695 	}
       
   696 
       
   697 
       
   698 /**
       
   699 Test SetCoding()
       
   700 */
       
   701 void CT_BluetoothSynchronousLinkData::DoCmdSetCoding(const TDesC& aSection)
       
   702 	{
       
   703 	INFO_PRINTF1(_L("CBluetoothSynchronousLink SetCoding Call"));
       
   704 	
       
   705 	TInt	voiceSetting;
       
   706 	if(GetIntFromConfig(aSection, KVoiceSetting(), voiceSetting))
       
   707 		{
       
   708 		iData->SetCoding(voiceSetting);
       
   709 		}
       
   710 	else
       
   711 		{
       
   712 		ERR_PRINTF2(KLogMissingParameter, &KVoiceSetting());
       
   713 		SetBlockResult(EFail);
       
   714 		}
       
   715 	}
       
   716 
       
   717 
       
   718 /**
       
   719 Test Coding()
       
   720 */
       
   721 void CT_BluetoothSynchronousLinkData::DoCmdCoding(const TDesC& aSection)
       
   722 	{
       
   723 	INFO_PRINTF1(_L("CBluetoothSynchronousLink Coding Call"));
       
   724 	
       
   725 	TUint16 voiceSetting = iData->Coding();
       
   726 	INFO_PRINTF2(_L("CBluetoothSynchronousLink Coding result: actual = %d"), voiceSetting);
       
   727 	
       
   728 	TInt	expected;
       
   729 	if(GetIntFromConfig(aSection, KExpected(), expected))
       
   730 		{
       
   731 		if( expected != voiceSetting )
       
   732 			{
       
   733 			ERR_PRINTF1(_L("Coding not as expected!"));
       
   734 			SetBlockResult(EFail);
       
   735 			}
       
   736 		}
       
   737 	else
       
   738 		{
       
   739 		ERR_PRINTF2(KLogMissingParameter, &KExpected());
       
   740 		SetBlockResult(EFail);
       
   741 		}
       
   742 	}
       
   743 
       
   744 
       
   745 /**
       
   746 Test SetMaxBandwidth()
       
   747 */
       
   748 void CT_BluetoothSynchronousLinkData::DoCmdSetMaxBandwidth(const TDesC& aSection)
       
   749 	{
       
   750 	INFO_PRINTF1(_L("CBluetoothSynchronousLink SetMaxBandwidth Call"));
       
   751 	
       
   752 	TPtrC	bandwidthName;
       
   753 	if(GetStringFromConfig(aSection, KSyncBandwidth(), bandwidthName))
       
   754 		{
       
   755 		TBTSyncBandwidth*	tbtSyncBandwidth = static_cast<TBTSyncBandwidth*>(GetDataObjectL(bandwidthName));
       
   756 		iData->SetMaxBandwidth(*tbtSyncBandwidth);
       
   757 		}
       
   758 	else
       
   759 		{
       
   760 		ERR_PRINTF2(KLogMissingParameter, &KSyncBandwidth());
       
   761 		SetBlockResult(EFail);
       
   762 		}
       
   763 	}
       
   764 
       
   765 
       
   766 /**
       
   767 Test Bandwidth()
       
   768 */
       
   769 void CT_BluetoothSynchronousLinkData::DoCmdBandwidth()
       
   770 	{
       
   771 	INFO_PRINTF1(_L("CBluetoothSynchronousLink Bandwidth Call"));
       
   772 	
       
   773 	TBTSyncBandwidth bandwidth = iData->Bandwidth();
       
   774 	
       
   775 	INFO_PRINTF1(_L("CBluetoothSynchronousLink Bandwidth result"));
       
   776 	INFO_PRINTF2(_L("iTransmit = %d"), bandwidth.iTransmit);
       
   777 	INFO_PRINTF2(_L("iReceive = %d"), bandwidth.iReceive);
       
   778 	}
       
   779 
       
   780 
       
   781 /**
       
   782 Test SetMaxLatency()
       
   783 */
       
   784 void CT_BluetoothSynchronousLinkData::DoCmdSetMaxLatency(const TDesC& aSection)
       
   785 	{
       
   786 	INFO_PRINTF1(_L("CBluetoothSynchronousLink SetMaxLatency Call"));
       
   787 	
       
   788 	TInt	latency = 0;
       
   789 	if(GetIntFromConfig(aSection, KLatency(), latency))
       
   790 		{
       
   791 		iData->SetMaxLatency((TUint16)latency);
       
   792 		}
       
   793 	else
       
   794 		{
       
   795 		ERR_PRINTF2(KLogMissingParameter, &KLatency());
       
   796 		SetBlockResult(EFail);
       
   797 		}
       
   798 	}
       
   799 
       
   800 
       
   801 /**
       
   802 Test Latency()
       
   803 */
       
   804 void CT_BluetoothSynchronousLinkData::DoCmdLatency(const TDesC& aSection)
       
   805 	{
       
   806 	INFO_PRINTF1(_L("CBluetoothSynchronousLink Latency Call"));
       
   807 	
       
   808 	TUint16 latency = iData->Latency();
       
   809 	INFO_PRINTF2(_L("CBluetoothSynchronousLink Latency result: actual = %d"), latency);
       
   810 	
       
   811 	TInt	expected;
       
   812 	if(GetIntFromConfig(aSection, KExpected(), expected))
       
   813 		{
       
   814 		if( expected != latency )
       
   815 			{
       
   816 			ERR_PRINTF1(_L("Latency not as expected!"));
       
   817 			SetBlockResult(EFail);
       
   818 			}
       
   819 		}
       
   820 	else
       
   821 		{
       
   822 		ERR_PRINTF2(KLogMissingParameter, &KExpected());
       
   823 		SetBlockResult(EFail);
       
   824 		}
       
   825 	}
       
   826 
       
   827 
       
   828 /**
       
   829 Test SetRetransmissionEffort()
       
   830 */
       
   831 void CT_BluetoothSynchronousLinkData::DoCmdSetRetransmissionEffort(const TDesC& aSection)
       
   832 	{
       
   833 	INFO_PRINTF1(_L("CBluetoothSynchronousLink SetRetransmissionEffort Call"));
       
   834 	
       
   835 	TBTeSCORetransmissionTypes	retransmissionType;
       
   836 	if ( CT_BTUtil::ReadTBTeSCORetransmissionTypes(*this, retransmissionType, aSection, KRetransmissionType()) )
       
   837 		{
       
   838 		INFO_PRINTF2(_L("CBluetoothSynchronousLink SetRetransmissionEffort: retransmissionType = %d"), retransmissionType);
       
   839 		iData->SetRetransmissionEffort(retransmissionType);
       
   840 		}
       
   841 	else 
       
   842 		{
       
   843 		ERR_PRINTF1(_L("Missing parameter, TBTeSCORetransmissionTypes"));
       
   844 		SetBlockResult(EFail);
       
   845 		}
       
   846 	}
       
   847 
       
   848 
       
   849 /**
       
   850 Test RetransmissionEffort()
       
   851 */
       
   852 void CT_BluetoothSynchronousLinkData::DoCmdRetransmissionEffort(const TDesC& aSection)
       
   853 	{
       
   854 	INFO_PRINTF1(_L("CBluetoothSynchronousLink RetransmissionEffort Call"));
       
   855 	
       
   856 	TUint8 retransmissionType = iData->RetransmissionEffort();
       
   857 	INFO_PRINTF2(_L("CBluetoothSynchronousLink RetransmissionEffort result: actual = %d"), retransmissionType);
       
   858 
       
   859 	TBTeSCORetransmissionTypes	expected;
       
   860 	if ( CT_BTUtil::ReadTBTeSCORetransmissionTypes(*this, expected, aSection, KExpected()) )
       
   861 		{
       
   862 		if( expected != retransmissionType )
       
   863 			{
       
   864 			ERR_PRINTF1(_L("RetransmissionEffort not as expected!"));
       
   865 			SetBlockResult(EFail);
       
   866 			}
       
   867 		}
       
   868 	else 
       
   869 		{
       
   870 		ERR_PRINTF1(_L("Missing parameter, TBTeSCORetransmissionTypes"));
       
   871 		SetBlockResult(EFail);		
       
   872 		}
       
   873 	}
       
   874 
       
   875 
       
   876 /**
       
   877 Test RemoteName()
       
   878 */
       
   879 void CT_BluetoothSynchronousLinkData::DoCmdRemoteName(const TDesC& aSection)
       
   880 	{
       
   881 	INFO_PRINTF1(_L("CBluetoothSynchronousLink RemoteName Call"));
       
   882 	
       
   883 	T_TBTSockAddrChild addr;
       
   884 	iData->RemoteName(addr);
       
   885 	
       
   886 	TBTDevAddr currentAddr = addr.BTAddr();
       
   887 	TBuf<KMaxSockAddrSize> tmpBuf;
       
   888 	currentAddr.GetReadable(tmpBuf);
       
   889 	INFO_PRINTF2(_L("RemoteName() = 0x%S"),&tmpBuf);
       
   890 
       
   891 	TPtrC	myTBTDevAddrName;
       
   892 	if(GetStringFromConfig(aSection, KTBTDevAddr(), myTBTDevAddrName))
       
   893 		{
       
   894 		CT_BTDevAddrData* myTBTDevAddrData=static_cast<CT_BTDevAddrData*>(GetDataWrapperL(myTBTDevAddrName));
       
   895 		TBTDevAddr btDevAddr = *myTBTDevAddrData->GetAddress();
       
   896 		TBuf<KMaxSockAddrSize> tmpBuf2;
       
   897 		btDevAddr.GetReadable(tmpBuf2);
       
   898 		if (tmpBuf2 != tmpBuf)
       
   899 			{
       
   900 			ERR_PRINTF3(_L("Expected address (%S) != actual address (%S)"),&tmpBuf2,&tmpBuf);
       
   901 			SetBlockResult(EFail);
       
   902 			}
       
   903 		}
       
   904 	else
       
   905 		{
       
   906 		ERR_PRINTF2(KLogMissingParameter, &KTBTDevAddr());
       
   907 		SetBlockResult(EFail);
       
   908 		}
       
   909 	}
       
   910 
       
   911 
       
   912 /**
       
   913 Test SetNotifier
       
   914 */
       
   915 void CT_BluetoothSynchronousLinkData::DoCmdSetNotifier(const TDesC& aSection)
       
   916 	{
       
   917 	INFO_PRINTF1(_L("CBluetoothSynchronousLink SetNotifier Call"));
       
   918 	
       
   919 	MBluetoothSynchronousLinkNotifier* theNotifier = this;
       
   920 	TBool	useAlternate =EFalse;
       
   921 	if(GetBoolFromConfig(aSection, KUseAlternateNotifier(), useAlternate) )
       
   922 		{
       
   923 		if (useAlternate)
       
   924 			{
       
   925 			theNotifier=this;
       
   926 			}
       
   927 		}
       
   928 	else
       
   929 		{
       
   930 		ERR_PRINTF2(KLogMissingParameter, &KUseAlternateNotifier());
       
   931 		SetBlockResult(EFail);
       
   932 		}
       
   933 	iData->SetNotifier(*theNotifier);
       
   934 	}
       
   935 
       
   936 
       
   937 /**
       
   938 Test Destructor
       
   939 */
       
   940 void CT_BluetoothSynchronousLinkData::DoCmdDestructor()
       
   941 	{
       
   942 	DestroyData();
       
   943 	}
       
   944 
       
   945 
       
   946 /**
       
   947 Test MBSLN_ExtensionInterfaceL()
       
   948 */
       
   949 void CT_BluetoothSynchronousLinkData::DoCmdMBSLN_ExtensionInterfaceL(const TDesC& aSection)
       
   950 	{
       
   951 	TInt tmp = 0;
       
   952 	void* theExtensionObjectPtr;
       
   953 
       
   954 	if(GetIntFromConfig(aSection, KUid(), tmp))
       
   955 		{
       
   956 		TUid uid=TUid::Uid(tmp);
       
   957 		
       
   958 		TBool expectNull = EFalse;
       
   959 		if(GetBoolFromConfig(aSection, KExpectNull(), expectNull))
       
   960 			{
       
   961 			TRAPD(err, this->MBSLN_ExtensionInterfaceL(uid, theExtensionObjectPtr));
       
   962 			if( err!=KErrNone )
       
   963 				{
       
   964 				ERR_PRINTF2(_L("MBSLN_ExtensionInterfaceL err=%d"),err);
       
   965 				SetError(err);
       
   966 				}
       
   967 			
       
   968 			if (expectNull)
       
   969 				{
       
   970 				//Fail if not NULL
       
   971 				if (theExtensionObjectPtr!=NULL)
       
   972 					{
       
   973 					ERR_PRINTF1(_L("Expected Null pointer but object found"));
       
   974 					SetBlockResult(EFail);
       
   975 					}
       
   976 				}
       
   977 			else
       
   978 				{
       
   979 				//Fail if NULL
       
   980 				if (theExtensionObjectPtr==NULL)
       
   981 					{
       
   982 					ERR_PRINTF1(_L("Expected object but found NULL"));
       
   983 					SetBlockResult(EFail);
       
   984 					}
       
   985 				}
       
   986 			}
       
   987 		else
       
   988 			{
       
   989 			ERR_PRINTF2(KLogMissingParameter, &KExpectNull());
       
   990 			SetBlockResult(EFail);
       
   991 			}
       
   992 		}
       
   993 	else
       
   994 		{
       
   995 		ERR_PRINTF2(KLogMissingParameter, &KUid());
       
   996 		SetBlockResult(EFail);
       
   997 		}
       
   998 	}
       
   999