⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 bluetoothserviceadvertiser.cpp.svn-base

📁 qaSDQDaca<FCSASDAVCASC SDVFDSVDF
💻 SVN-BASE
字号:
 /*
============================================================================================
 Name		: BluetoothServiceAdvertiser.cpp
 Author	    : BluetoothAPI is a initiative of Embedded LAB - http://www.embedded.ufcg.edu.br/
 			  OpenC/SymbianC++ - http://efforts.embedded.ufcg.edu.br/symbiancpp	
 Version	 :
 Copyright   : This file is part of BluetoothAPI.
               BluetoothAPI is free software: you can redistribute it and/or modify
               it under the terms of the GNU Lesser General Public License as published by
               the Free Software Foundation, either version 3 of the License, or
               (at your option) any later version.

               BluetoothAPI is distributed in the hope that it will be useful,
               but WITHOUT ANY WARRANTY; without even the implied warranty of
               MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
               GNU Lesser General Public License for more details.

               You should have received a copy of the GNU Lesser General Public License
               along with BluetoothAPI. If not, see <http://www.gnu.org/licenses/>.
 
 Description : BluetoothServiceAdvertiser.cpp implementation
===========================================================================================
*/


#include "BluetoothServiceAdvertiser.h"

CBluetoothServiceAdvertiser::CBluetoothServiceAdvertiser()
{
	// No implementation required
}


CBluetoothServiceAdvertiser::~CBluetoothServiceAdvertiser()
{
}

CBluetoothServiceAdvertiser* CBluetoothServiceAdvertiser::NewLC()
{
	CBluetoothServiceAdvertiser* self = new (ELeave)CBluetoothServiceAdvertiser();
	CleanupStack::PushL(self);
	self->ConstructL();
	return self;
}

CBluetoothServiceAdvertiser* CBluetoothServiceAdvertiser::NewL()
{
	CBluetoothServiceAdvertiser* self=CBluetoothServiceAdvertiser::NewLC();
	CleanupStack::Pop(); // self;
	return self;
}

void CBluetoothServiceAdvertiser::ConstructL()
{

}

void CBluetoothServiceAdvertiser::StartAdvertisingL(TInt aChannel, 
		TUint32 aBTServiceUUID, TDesC16 aBTServiceName )
{
	User::LeaveIfError(iSdp.Connect());
	User::LeaveIfError(iSdpDatabase.Open(iSdp));
	
	iSdpDatabase.CreateServiceRecordL(TUUID(aBTServiceUUID), iSdpServRecordHandle);
	
	CSdpAttrValueDES* sdpAttrValueDescriptors = CSdpAttrValueDES::NewDESL(NULL);
	CleanupStack::PushL(sdpAttrValueDescriptors);
	TBuf8<1> channel;
	channel.Append((TChar)(aChannel%10));
	
	sdpAttrValueDescriptors->StartListL()->BuildDESL()->StartListL()
		->BuildUUIDL(KL2CAP)->EndListL()->BuildDESL()->StartListL()
		->BuildUUIDL(KRFCOMM)->BuildUintL(channel)->EndListL()->EndListL();

	iSdpDatabase.UpdateAttributeL(iSdpServRecordHandle,
		KSdpAttrIdProtocolDescriptorList, *sdpAttrValueDescriptors);
	
	CleanupStack::PopAndDestroy(sdpAttrValueDescriptors);

	iSdpDatabase.UpdateAttributeL(iSdpServRecordHandle,
			KSdpAttrIdBasePrimaryLanguage + KSdpAttrIdOffsetServiceName,
			aBTServiceName);
	
	iSdpDatabase.UpdateAttributeL(iSdpServRecordHandle,KSdpAttrIdBasePrimaryLanguage
			+ KSdpAttrIdOffsetServiceDescription, aBTServiceName);

	iSdpDatabase.UpdateAttributeL(iSdpServRecordHandle,
			KSdpAttrIdServiceAvailability, 0xFF);

	iSdpDatabase.UpdateAttributeL(iSdpServRecordHandle, 
			KSdpAttrIdServiceRecordState, 1);
}

void CBluetoothServiceAdvertiser::StartAdvertisingL(TInt aChannel,
		TUint32 aBTServiceUUID1, TUint32 aBTServiceUUID2, TUint32 aBTServiceUUID3,
		TUint32 aBTServiceUUID4, TDesC16 aBTServiceName )
	{
		User::LeaveIfError(iSdp.Connect());
		User::LeaveIfError(iSdpDatabase.Open(iSdp));
		
		iSdpDatabase.CreateServiceRecordL(TUUID(aBTServiceUUID1, aBTServiceUUID2,
			aBTServiceUUID3, aBTServiceUUID4), iSdpServRecordHandle);
		
		CSdpAttrValueDES* sdpAttrValueDescriptors = CSdpAttrValueDES::NewDESL(NULL);
		CleanupStack::PushL(sdpAttrValueDescriptors);
		TBuf8<1> channel;
		channel.Append((TChar)(aChannel%10));
		
		sdpAttrValueDescriptors->StartListL()->BuildDESL()->StartListL()
			->BuildUUIDL(KL2CAP)->EndListL()->BuildDESL()->StartListL()
			->BuildUUIDL(KRFCOMM)->BuildUintL(channel)->EndListL()->EndListL();

		iSdpDatabase.UpdateAttributeL(iSdpServRecordHandle,
			KSdpAttrIdProtocolDescriptorList, *sdpAttrValueDescriptors);
		
		CleanupStack::PopAndDestroy(sdpAttrValueDescriptors);

		iSdpDatabase.UpdateAttributeL(iSdpServRecordHandle,
				KSdpAttrIdBasePrimaryLanguage + KSdpAttrIdOffsetServiceName,
				aBTServiceName);
		
		iSdpDatabase.UpdateAttributeL(iSdpServRecordHandle,KSdpAttrIdBasePrimaryLanguage
				+ KSdpAttrIdOffsetServiceDescription, aBTServiceName);

		iSdpDatabase.UpdateAttributeL(iSdpServRecordHandle,
				KSdpAttrIdServiceAvailability, 0xFF);

		iSdpDatabase.UpdateAttributeL(iSdpServRecordHandle, 
				KSdpAttrIdServiceRecordState, 1);
	}

void CBluetoothServiceAdvertiser::StopAdvertisingL()
{
	if (iSdpServRecordHandle != NULL)
	{
		iSdpDatabase.DeleteRecordL(iSdpServRecordHandle);
		iSdpDatabase.Close();
		iSdpServRecordHandle = NULL;
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -