commands/btservices/btservices.cpp
changeset 0 7f656887cf89
equal deleted inserted replaced
-1:000000000000 0:7f656887cf89
       
     1 // btservices.cpp
       
     2 // 
       
     3 // Copyright (c) 2009 - 2010 Accenture. All rights reserved.
       
     4 // This component and the accompanying materials are made available
       
     5 // under the terms of the "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 // Accenture - Initial contribution
       
    11 //
       
    12 
       
    13 #include <e32std.h>
       
    14 #include <BTExtNotifiers.h>
       
    15 
       
    16 #include <fshell/common.mmh>
       
    17 #include <fshell/ioutils.h>
       
    18 using namespace IoUtils;
       
    19 
       
    20 #include "BtServicesEng.h"
       
    21 #include "BtServiceView.h"
       
    22 
       
    23 class CBTEngSettings;
       
    24 
       
    25 #if FSHELL_PLATFORM_S60 >= 5
       
    26 // This is an S60-only API
       
    27 #define SUPPORT_ONOFF
       
    28 #endif
       
    29 
       
    30 #ifdef SUPPORT_ONOFF
       
    31 #include <btengsettings.h>
       
    32 #endif
       
    33 
       
    34 CBtServiceView::CBtServiceView()
       
    35 	{
       
    36 	}
       
    37 
       
    38 CBtServiceView::~CBtServiceView()
       
    39 	{
       
    40 	}
       
    41 
       
    42 void CBtServiceView::PrintTextMsg(TInt /*aVerboseLevel*/, const TDesC& /*aMsg*/)
       
    43 	{
       
    44 	}
       
    45 
       
    46 void CBtServiceView::AsyncCompleted()
       
    47 	{
       
    48 	}
       
    49 
       
    50 class CCmdBtsvc : public CCommandBase, public CBtServiceView 
       
    51 	{
       
    52 public:
       
    53 	static CCommandBase* NewLC();
       
    54 	~CCmdBtsvc();
       
    55 private:
       
    56 	CCmdBtsvc();
       
    57 	void DoScanDeviceL();
       
    58 	void DoListServiceL();
       
    59 	void DoAttributeL();
       
    60 	void DoLocalL();
       
    61 	void DoListUuidFilterL();
       
    62 	void SelectBTDeviceL(TBTDeviceName& aName, TBTDevAddr& aBDAddr, TBTDeviceClass& aDevClass);
       
    63 	TBool GetBTDevClassFromRegistryL(TBTDevAddr& aBDAddr, TBTDeviceClass& aDevClass);
       
    64 
       
    65 #ifdef SUPPORT_ONOFF
       
    66 	void SetEnabledL(TBool aEnable);
       
    67 	void ShowStatusL();
       
    68 	TBool GetPowerStateL();
       
    69 #endif
       
    70 
       
    71 private: // From CCommandBase.
       
    72 	virtual const TDesC& Name() const;
       
    73 	virtual void DoRunL();
       
    74 	virtual void ArgumentsL(RCommandArgumentList& aArguments);
       
    75 	virtual void OptionsL(RCommandOptionList& aOptions);
       
    76 	
       
    77 private:
       
    78 	virtual void PrintTextMsg(TInt aVerboseLevel, const TDesC& aMsg);
       
    79 	virtual void AsyncCompleted();
       
    80 
       
    81 private:
       
    82 	CBtServicesEng* iEngine; 
       
    83 	CActiveSchedulerWait* iActiveWait;
       
    84 	RArray<TBool> iVerbose;
       
    85 	
       
    86 	HBufC* iOptBTAddr;
       
    87 	HBufC* iOptSvcHandle;	//service handle
       
    88 	HBufC* iOptUuidFilter;	//uuid filter
       
    89 	
       
    90 	enum TBtSvcCmd
       
    91 		{
       
    92 		ECmdDevice,
       
    93 		ECmdService,
       
    94 		ECmdAttribute,
       
    95 		ECmdLocal,
       
    96 		ECmdUuid,
       
    97 		ECmdStatus,
       
    98 		ECmdEnable,
       
    99 		ECmdDisable,
       
   100 		};
       
   101 	
       
   102 	TBtSvcCmd iCommand;
       
   103 
       
   104 	CBTEngSettings* iSettings;
       
   105 	};
       
   106 
       
   107 CCommandBase* CCmdBtsvc::NewLC()
       
   108 	{
       
   109 	CCmdBtsvc* self = new(ELeave) CCmdBtsvc();
       
   110 	CleanupStack::PushL(self);
       
   111 	self->BaseConstructL();
       
   112 	return self;
       
   113 	}
       
   114 
       
   115 CCmdBtsvc::CCmdBtsvc()
       
   116 	{
       
   117 	iActiveWait = new (ELeave) CActiveSchedulerWait;
       
   118 	}
       
   119 
       
   120 
       
   121 CCmdBtsvc::~CCmdBtsvc()
       
   122 	{
       
   123 #ifdef SUPPORT_ONOFF
       
   124 	delete iSettings;
       
   125 #endif
       
   126 
       
   127 	delete iOptBTAddr;
       
   128 	delete iOptSvcHandle;
       
   129 	delete iOptUuidFilter;
       
   130 	delete iActiveWait;
       
   131 	delete iEngine;
       
   132 	iVerbose.Close();
       
   133 	}
       
   134 
       
   135 void CCmdBtsvc::PrintTextMsg(TInt aVerboseLevel, const TDesC& aMsg)
       
   136 	{
       
   137 	TInt VerboseLevel = iVerbose.Count();
       
   138 	if (aVerboseLevel <= VerboseLevel)
       
   139 		Printf(aMsg);
       
   140 	}
       
   141 
       
   142 void CCmdBtsvc::AsyncCompleted()
       
   143 	{
       
   144 	if (iActiveWait->IsStarted())
       
   145 		{
       
   146 		iActiveWait->AsyncStop();
       
   147 		}
       
   148 	}
       
   149 
       
   150 const TDesC& CCmdBtsvc::Name() const
       
   151 	{
       
   152 	_LIT(KName, "btservices");
       
   153 	return KName;
       
   154 	}
       
   155 
       
   156 void CCmdBtsvc::ArgumentsL(RCommandArgumentList& aArguments)
       
   157 	{
       
   158 	_LIT(KArgCommand, "command");
       
   159 	aArguments.AppendEnumL((TInt&)iCommand, KArgCommand);
       
   160 	}
       
   161 
       
   162 void CCmdBtsvc::OptionsL(RCommandOptionList& aOptions)
       
   163 	{		
       
   164 	aOptions.AppendStringL(iOptBTAddr, _L("address"));
       
   165 	aOptions.AppendStringL(iOptSvcHandle, _L("record"));
       
   166 	aOptions.AppendStringL(iOptUuidFilter, _L("uuid"));		
       
   167 	aOptions.AppendBoolL(iVerbose, _L("verbose"));
       
   168 	}
       
   169 
       
   170 void CCmdBtsvc::DoRunL()
       
   171 	{
       
   172 	switch (iCommand)
       
   173 		{
       
   174 		case ECmdDevice:
       
   175 			DoScanDeviceL();
       
   176 			break;
       
   177 		case ECmdService:
       
   178 			DoListServiceL();
       
   179 			break;
       
   180 		case ECmdAttribute:
       
   181 			DoAttributeL();
       
   182 			break;
       
   183 		case ECmdLocal:
       
   184 			DoLocalL();
       
   185 			break;
       
   186 		case ECmdUuid:
       
   187 			DoListUuidFilterL();
       
   188 			break;
       
   189 #ifdef SUPPORT_ONOFF
       
   190 		case ECmdStatus:
       
   191 			ShowStatusL();
       
   192 			break;
       
   193 		case ECmdEnable:
       
   194 			SetEnabledL(ETrue);
       
   195 			break;
       
   196 		case ECmdDisable:
       
   197 			SetEnabledL(EFalse);
       
   198 			break;
       
   199 #endif
       
   200 		default:	
       
   201 			LeaveIfErr(KErrArgument, _L("Invalid command"));
       
   202 		}
       
   203 	}
       
   204 
       
   205 void CCmdBtsvc::DoAttributeL()
       
   206 	{
       
   207 	TInt err;
       
   208 		
       
   209 	//if want to query full attribute set of one particular service,
       
   210 	//call CBtServicesEng::GetAttributesL()
       
   211 	if (iOptSvcHandle && iOptSvcHandle->Length())
       
   212 		{
       
   213 		iEngine = CBtServicesEng::NewL();
       
   214 		iEngine->SetView(this);
       
   215 		
       
   216 		iEngine->CancelSdpAgent();
       
   217 		iEngine->DeleteSdpAgent();
       
   218 		
       
   219 		err = iEngine->BluetoothReady();
       
   220 		LeaveIfErr(err, _L("Bluetooth not ready"));
       
   221 				
       
   222 		TBTDeviceName Name; 
       
   223 		TBTDevAddr BDAddr;
       
   224 		TBTDeviceClass DevClass;
       
   225 			
       
   226 		//iOptSvcHandle should begin with "0x" (hex)
       
   227 		if ((iOptSvcHandle->Left(2))==_L("0x"))
       
   228 			{
       
   229 			TSdpServRecordHandle Handle;
       
   230 			TLex lex(*iOptSvcHandle);
       
   231 			lex.SkipAndMark(2);
       
   232 			err = lex.Val(Handle, EHex);
       
   233 			LeaveIfErr(err, _L("Service Handle:\"%S\" is not in valid format"), iOptSvcHandle);
       
   234 		
       
   235 			SelectBTDeviceL(Name, BDAddr, DevClass);
       
   236 			Printf(_L("==============================================\r\n"));
       
   237 			
       
   238 			iEngine->GetDeviceAttributesL(BDAddr, Name, Handle);
       
   239 			
       
   240 			//wait for results
       
   241 			iActiveWait->Start();
       
   242 									
       
   243 			}
       
   244 		else
       
   245 			LeaveIfErr(KErrArgument, _L("Service Handle:\"%S\" is not in valid format"), iOptSvcHandle);		
       
   246 		}
       
   247 	else
       
   248 		LeaveIfErr(KErrArgument, _L("use -r to specify a service record handle"));
       
   249 	}
       
   250 
       
   251 
       
   252 //do a BT device scan with RHostResolver,
       
   253 //and make a list of BT addresses, device name, and device class
       
   254 //
       
   255 void CCmdBtsvc::DoScanDeviceL()
       
   256 	{
       
   257 	TInt err;
       
   258 	TInt ItemsFound = 0;
       
   259 	TBTDevAddr BDAddr;
       
   260 	TBTDeviceName Name;
       
   261 	TBTDeviceClass DevClass;
       
   262 	
       
   263 	Printf(_L("Scanning for BT devices ...\r\n"));
       
   264 		
       
   265 	RSocketServ SktSrv;
       
   266 	CleanupClosePushL(SktSrv);
       
   267 	
       
   268 	err = SktSrv.Connect();
       
   269 	LeaveIfErr(err, _L("Could not connect to socket server"));
       
   270 	
       
   271 	RHostResolver Host;
       
   272 	CleanupClosePushL(Host);
       
   273 	RHostResolver HostForName;
       
   274 	CleanupClosePushL(HostForName);
       
   275 	
       
   276 	TProtocolDesc ProtocolInfo;
       
   277 	err = SktSrv.FindProtocol(_L("BTLinkManager"), ProtocolInfo);
       
   278 	User::LeaveIfError(err);
       
   279 	
       
   280 	err = Host.Open(SktSrv, ProtocolInfo.iAddrFamily , ProtocolInfo.iProtocol);
       
   281 	LeaveIfErr(err, _L("Could not open host resolver"));
       
   282 	err = HostForName.Open(SktSrv, ProtocolInfo.iAddrFamily , ProtocolInfo.iProtocol);
       
   283 	LeaveIfErr(err, _L("Could not open host resolver"));
       
   284 	
       
   285 	TInquirySockAddr Inq;	
       
   286 	Inq.SetIAC(KGIAC);
       
   287 	Inq.SetAction(KHostResInquiry/*|KHostResIgnoreCache*/);
       
   288 	
       
   289 	
       
   290 	TNameEntry Result;
       
   291 	err = Host.GetByAddress(Inq, Result);
       
   292 	
       
   293 	//this is for querying name
       
   294 	TInquirySockAddr InqName;	
       
   295 	InqName.SetAction(KHostResName);
       
   296 	TNameEntry ResultName;
       
   297 	
       
   298 	Printf(_L("========================================================\r\n"));
       
   299 	Printf(_L("BTAddr         | DeviceClass| Name\r\n"));
       
   300 	Printf(_L("========================================================\r\n"));
       
   301 	
       
   302 	while(1)
       
   303 		{
       
   304 		if (err == KErrNone)
       
   305 			{
       
   306 			ItemsFound++;
       
   307 			TInquirySockAddr& sa = TInquirySockAddr::Cast(Result().iAddr);
       
   308 			const TBTDevAddr& bdaddr = sa.BTAddr();
       
   309 			BDAddr = bdaddr;
       
   310 			Name = Result().iName;
       
   311 			
       
   312 			TUint16 MajorServiceClass = sa.MajorServiceClass(); 
       
   313 			DevClass = TBTDeviceClass(
       
   314 					MajorServiceClass, sa.MajorClassOfDevice(), sa.MinorClassOfDevice() );
       
   315 			
       
   316 			TBuf<128> BTReadAddress;
       
   317 			BDAddr.GetReadable(BTReadAddress);
       
   318 			
       
   319 			//query its name
       
   320 			InqName.SetBTAddr(bdaddr);
       
   321 			err = HostForName.GetByAddress(InqName, ResultName);			
       
   322 			if (err==KErrNone)
       
   323 				Name = ResultName().iName;
       
   324 			else
       
   325 				Name.Format(_L("Unable to get the name, err=%d"), err);
       
   326 			
       
   327 			Printf(_L("0x%S | 0x%08x | \"%S\" \r\n"), 
       
   328 					&BTReadAddress, DevClass.DeviceClass(), &Name);
       
   329 								
       
   330 			err = Host.Next(Result);
       
   331 			}
       
   332 		else if (err == KErrEof)
       
   333 			{
       
   334 			break;
       
   335 			}
       
   336 		else
       
   337 			LeaveIfErr(err, _L("Resolving address failed"));
       
   338 		}
       
   339 	CleanupStack::PopAndDestroy();
       
   340 	CleanupStack::PopAndDestroy();
       
   341 	CleanupStack::PopAndDestroy();
       
   342 	
       
   343 	Printf(_L("%d devices found\r\n"),ItemsFound);
       
   344 	}
       
   345 
       
   346 //NOT TESTED YET, do not use
       
   347 //aBDAddr:[in]
       
   348 //aDevClass:[out]	
       
   349 TBool CCmdBtsvc::GetBTDevClassFromRegistryL(TBTDevAddr& aBDAddr, TBTDeviceClass& aDevClass)
       
   350 	{
       
   351 	TInt err;
       
   352 	
       
   353 	TBuf<128> buf;
       
   354 	aBDAddr.GetReadable(buf);
       
   355 	Printf(_L("Query DeviceClass for BTAddr:0x%S\r\n"), &buf);
       
   356 	
       
   357 	RBTRegServ Srv;
       
   358 	CleanupClosePushL(Srv);
       
   359 	err = Srv.Connect();
       
   360 	User::LeaveIfError(err);
       
   361 	
       
   362 	RBTRegistry Reg;
       
   363 	CleanupClosePushL(Reg);
       
   364 	err = Reg.Open(Srv);
       
   365 	User::LeaveIfError(err);
       
   366 
       
   367 	TBTNamelessDevice Dev;
       
   368 	Dev.SetAddress(aBDAddr);
       
   369 	
       
   370 	TRequestStatus status;
       
   371 	Reg.GetDevice(Dev, status);
       
   372 	User::WaitForRequest(status);
       
   373 	
       
   374 	err = status.Int();
       
   375 	User::LeaveIfError(err);
       
   376 	
       
   377 	if (err == KErrNone )
       
   378 		{
       
   379 		aDevClass = Dev.DeviceClass();		
       
   380 		}
       
   381 	
       
   382 	CleanupStack::PopAndDestroy();	
       
   383 	CleanupStack::PopAndDestroy();	
       
   384 	
       
   385 	return ETrue;
       
   386 	}
       
   387 
       
   388 //select a BT device either from RNotifier, 
       
   389 //or using BT address string if it is specified
       
   390 //aName: [out]
       
   391 //aBDAddr: [out]
       
   392 //aDevClass: [out]
       
   393 void CCmdBtsvc::SelectBTDeviceL(TBTDeviceName& aName, TBTDevAddr& aBDAddr, TBTDeviceClass& aDevClass)
       
   394 	{
       
   395 	TInt err;
       
   396 	if (iOptBTAddr && iOptBTAddr->Length()>0)
       
   397 		//use RHostResolver to get name and device class
       
   398 		{
       
   399 		Printf(_L("Querying name for \"%S\"...\r\n"), iOptBTAddr);
       
   400 			
       
   401 		RSocketServ SktSrv;
       
   402 		CleanupClosePushL(SktSrv);
       
   403 		
       
   404 		err = SktSrv.Connect();
       
   405 		LeaveIfErr(err, _L("Could not connect to socket server"));
       
   406 		
       
   407 		RHostResolver Host;
       
   408 		CleanupClosePushL(Host);
       
   409 		
       
   410 		TProtocolDesc ProtocolInfo;
       
   411 		err = SktSrv.FindProtocol(_L("BTLinkManager"), ProtocolInfo);
       
   412 		User::LeaveIfError(err);
       
   413 		
       
   414 		err = Host.Open(SktSrv, ProtocolInfo.iAddrFamily , ProtocolInfo.iProtocol);
       
   415 		LeaveIfErr(err, _L("Could not open host resolver"));
       
   416 		
       
   417 		TBTDevAddr Addr;
       
   418 		err = Addr.SetReadable(*iOptBTAddr);
       
   419 		LeaveIfErr(err, _L("User-input BT address invalid"));
       
   420 				
       
   421 		TInquirySockAddr Inq;	
       
   422 		Inq.SetAction(KHostResName);
       
   423 		Inq.SetBTAddr(Addr);	
       
   424 		
       
   425 		TNameEntry Result;
       
   426 		err = Host.GetByAddress(Inq, Result);
       
   427 		if (err == KErrNone)
       
   428 			{
       
   429 			TInquirySockAddr& sa = TInquirySockAddr::Cast(Result().iAddr);
       
   430 			const TBTDevAddr& bdaddr = sa.BTAddr();
       
   431 			aBDAddr = bdaddr;
       
   432 			aName = Result().iName;
       
   433 						
       
   434 			TUint16 MajorServiceClass = sa.MajorServiceClass(); 
       
   435 			aDevClass = TBTDeviceClass(
       
   436 					MajorServiceClass, sa.MajorClassOfDevice(), sa.MinorClassOfDevice() );			
       
   437 			}
       
   438 		else
       
   439 			LeaveIfErr(err, _L("Resolving address failed"));		
       
   440 		
       
   441 		CleanupStack::PopAndDestroy();
       
   442 		CleanupStack::PopAndDestroy();
       
   443 		
       
   444 		TBuf<128> AddressStr;
       
   445 		aBDAddr.GetReadable(AddressStr);
       
   446 		Printf(_L("Device \"%S\" BTAddr:0x%S\r\n"), 
       
   447 				&aName, &AddressStr);		
       
   448 		}
       
   449 	else
       
   450 		//use RNotifier to select a BT device
       
   451 		{
       
   452 		//about the search device, prompting user about curret status
       
   453 		Printf(_L("Searching Bluetooth device through RNotifier,\r\nplease go to main UI screen to select a device...\r\n"));
       
   454 		
       
   455 		////////////////////////////////////////////
       
   456 		RNotifier noti;
       
   457 		User::LeaveIfError(noti.Connect());
       
   458 
       
   459 		// 2. Start the device selection plug-in
       
   460 		TBTDeviceSelectionParams selectionFilter;
       
   461 		//TUUID targetServiceClass(0x2345);
       
   462 		//selectionFilter.SetUUID(targetServiceClass);
       
   463 		TBTDeviceSelectionParamsPckg pckg(selectionFilter);
       
   464 		TBTDeviceResponseParams result;
       
   465 		TBTDeviceResponseParamsPckg resultPckg(result);
       
   466 		TRequestStatus status;
       
   467 		noti.StartNotifierAndGetResponse(status, KDeviceSelectionNotifierUid, pckg, resultPckg);
       
   468 		User::After(2000000);
       
   469 
       
   470 		// 3. Extract device name if it was returned
       
   471 		User::WaitForRequest(status);
       
   472 
       
   473 		if (status.Int() == KErrNone)
       
   474 		    {
       
   475 		    if (resultPckg().IsValidDeviceName() &&
       
   476 		    	resultPckg().IsValidBDAddr() &&
       
   477 		    	resultPckg().IsValidDeviceClass()
       
   478 		    	)
       
   479 		        {
       
   480 		        aName = (resultPckg().DeviceName());	        
       
   481 		        aBDAddr = resultPckg().BDAddr();
       
   482 		        aDevClass = resultPckg().DeviceClass();
       
   483 		        
       
   484 		        }
       
   485 		    }
       
   486 		    
       
   487 		    
       
   488 		// 4. Clean up
       
   489 		noti.CancelNotifier(KDeviceSelectionNotifierUid);
       
   490 		noti.Close();		
       
   491 		
       
   492 		TBuf<128> AddressStr;
       
   493 		aBDAddr.GetReadable(AddressStr);
       
   494 		Printf(_L("Device \"%S\" BTAddr:0x%S DeviceClass:0x%08X\r\n"), 
       
   495 				&aName, &AddressStr, aDevClass.DeviceClass());		
       
   496 		
       
   497 		}	
       
   498 	}
       
   499 
       
   500 
       
   501 //search and make a list of results
       
   502 void CCmdBtsvc::DoListServiceL()
       
   503 	{
       
   504 	TInt VerboseLevel = iVerbose.Count();
       
   505 	
       
   506 	if (VerboseLevel >= 2)
       
   507 		Printf(_L("calling CBtServicesEng::NewL() ...\r\n"));
       
   508 	
       
   509 	iEngine = CBtServicesEng::NewL();
       
   510 	
       
   511 	
       
   512 	if (VerboseLevel >= 2)
       
   513 		Printf(_L("calling CBtServicesEng::SetView()... iEngine=0x%08x\r\n"), 
       
   514 				iEngine);
       
   515 	
       
   516 	iEngine->SetView(this);
       
   517 	
       
   518 	if (VerboseLevel >= 2)
       
   519 		Printf(_L("calling CBtServicesEng::CancelSdpAgent()...\r\n"));
       
   520 	iEngine->CancelSdpAgent();
       
   521 
       
   522 	if (VerboseLevel >= 2)
       
   523 		Printf(_L("calling CBtServicesEng::DeleteSdpAgent()...\r\n"));	
       
   524 	iEngine->DeleteSdpAgent();
       
   525 	
       
   526 	TInt err = iEngine->BluetoothReady();
       
   527 	LeaveIfErr(err, _L("Bluetooth not ready"));
       
   528 
       
   529 	TBTDeviceName Name; 
       
   530 	TBTDevAddr BDAddr;
       
   531 	TBTDeviceClass DevClass;
       
   532 	
       
   533 	SelectBTDeviceL(Name, BDAddr, DevClass);
       
   534 	
       
   535 	//see if user has specified a UUID filter
       
   536 	if (iOptUuidFilter && iOptUuidFilter->Length())
       
   537 		{
       
   538 		TUint32 uuid;
       
   539 		if ((iOptUuidFilter->Left(2))==_L("0x"))
       
   540 			{
       
   541 			TLex lex(*iOptUuidFilter);
       
   542 			lex.SkipAndMark(2);
       
   543 			err = lex.Val(uuid, EHex);
       
   544 			if (err==KErrNone)
       
   545 				{
       
   546 				iEngine->SetUUIDFilterL(uuid);
       
   547 				goto QueryService;
       
   548 				}
       
   549 			}
       
   550 		
       
   551 			//the UUID could be in string form.
       
   552 			TBool Match = iEngine->StringToUUID(*iOptUuidFilter, uuid);
       
   553 			if (Match==EFalse)
       
   554 				{
       
   555 				Printf(_L("UUID filter not recognised. Ignored\r\n"));
       
   556 				}
       
   557 		}
       
   558 		
       
   559 QueryService:	
       
   560 	iEngine->NewDeviceSelectedL(BDAddr, Name);		
       
   561 	iActiveWait->Start();
       
   562 	
       
   563 	iEngine->MakeTextServiceList();	
       
   564 	
       
   565 	//test code: just to test if attributes query is OK	
       
   566 	//iEngine->GetAttributesL(0);
       
   567 	//iActiveWait->Start();
       
   568 	
       
   569 	}
       
   570 
       
   571 void CCmdBtsvc::DoLocalL()
       
   572 	{
       
   573 	TInt err;
       
   574 	iEngine = CBtServicesEng::NewL();
       
   575 	iEngine->SetView(this);
       
   576 	
       
   577 	iEngine->CancelSdpAgent();
       
   578 	iEngine->DeleteSdpAgent();
       
   579 	
       
   580 	err = iEngine->BluetoothReady();
       
   581 	LeaveIfErr(err, _L("Bluetooth not ready"));
       
   582 	
       
   583 	iEngine->DisplayLocalInfoL();
       
   584 	
       
   585 	}
       
   586 
       
   587 
       
   588 //make a list of UUID filters, values and strings  
       
   589 void CCmdBtsvc::DoListUuidFilterL()
       
   590 	{
       
   591 	TInt err;
       
   592 	iEngine = CBtServicesEng::NewL();
       
   593 	iEngine->SetView(this);
       
   594 	
       
   595 	iEngine->CancelSdpAgent();
       
   596 	iEngine->DeleteSdpAgent();
       
   597 	
       
   598 	err = iEngine->BluetoothReady();
       
   599 	LeaveIfErr(err, _L("Bluetooth not ready"));
       
   600 	
       
   601 	
       
   602 	iEngine->MakeTextUUIDList();
       
   603 	}
       
   604 
       
   605 	
       
   606 EXE_BOILER_PLATE(CCmdBtsvc)
       
   607 
       
   608 #ifdef SUPPORT_ONOFF
       
   609 
       
   610 TBool CCmdBtsvc::GetPowerStateL()
       
   611 	{
       
   612 	if (!iSettings)
       
   613 		{
       
   614 		TRAPL(iSettings = CBTEngSettings::NewL(NULL), _L("Couldn't construct CBTEngSettings"));
       
   615 		}
       
   616 	TBTPowerStateValue state;
       
   617 	LeaveIfErr(iSettings->GetPowerState(state), _L("Couldn't read BT power state"));
       
   618 	return state == EBTPowerOn;
       
   619 	}
       
   620 
       
   621 void CCmdBtsvc::ShowStatusL()
       
   622 	{
       
   623 	if (GetPowerStateL())
       
   624 		{
       
   625 		Printf(_L("Bluetooth is enabled.\r\n"));
       
   626 		}
       
   627 	else
       
   628 		{
       
   629 		Printf(_L("Bluetooth is disabled.\r\n"));
       
   630 		}
       
   631 	}
       
   632 
       
   633 void CCmdBtsvc::SetEnabledL(TBool aEnable)
       
   634 	{
       
   635 	TBool on = GetPowerStateL();
       
   636 	if (on && !aEnable)
       
   637 		{
       
   638 		LeaveIfErr(iSettings->SetPowerState(EBTPowerOff), _L("Couldn't set power state"));
       
   639 		}
       
   640 	else if (!on && aEnable)
       
   641 		{
       
   642 		LeaveIfErr(iSettings->SetPowerState(EBTPowerOn), _L("Couldn't set power state"));
       
   643 		}
       
   644 	}
       
   645 
       
   646 #endif