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

📄 trfcommserviceseeker.cpp

📁 S60系统下的蓝牙GPS连接程序 包括client和server端的连接方式
💻 CPP
字号:
/*****************************************************************************
 COPYRIGHT All rights reserved Sony Ericsson Mobile Communications AB 2003.

 The software is the copyrighted work of Sony Ericsson Mobile Communications AB.
 The use of the software is subject to the terms of the end-user license
 agreement which accompanies or is included with the software. The software is
 provided "as is" and Sony Ericsson specifically disclaim any warranty or
 condition whatsoever regarding merchantability or fitness for a specific
 purpose, title or non-infringement. No warranty of any kind is made in
 relation to the condition, suitability, availability, accuracy, reliability,
 merchantability and/or non-infringement of the software provided herein.

 *****************************************************************************/

#include "trfcommserviceseeker.h"

CRFCOMMServiceFinder* CRFCOMMServiceFinder::NewL(	const TUUID& aServiceClass,
													const TBTDevAddr& aDevAddr,
													MRFCOMMServiceSeeker& aSeeker)
	{
	CRFCOMMServiceFinder* self=new (ELeave) CRFCOMMServiceFinder(aServiceClass, aSeeker);
	CleanupStack::PushL(self);
	self->ConstructL(aDevAddr, aServiceClass);
	CleanupStack::Pop(self);
	return self;
	}

CRFCOMMServiceFinder::CRFCOMMServiceFinder(	const TUUID& aServiceClass,
											MRFCOMMServiceSeeker& aSeeker)
:	iServiceClassUUID(aServiceClass), iSeeker(aSeeker)
	{
	}

	//	Destruction
CRFCOMMServiceFinder::~CRFCOMMServiceFinder()
	{
	delete iAgent;
	delete iPattern;
	}

void CRFCOMMServiceFinder::ConstructL(const TBTDevAddr& aDevAddr, const TUUID& aServiceClass)
	{
	iPattern=CSdpSearchPattern::NewL();
	iPattern->AddL(aServiceClass);
	iAgent=CSdpAgent::NewL(*this, aDevAddr);
	}

void CRFCOMMServiceFinder::FindPortL()
	{
	iPort=0xFF;	//0xFF will never be returned from a query, 
			//because RFCOMM server channels only
			//go up to 30.
	iAgent->SetRecordFilterL(*iPattern);
	iAgent->NextRecordRequestL();
	}

void CRFCOMMServiceFinder::NextRecordRequestComplete(TInt aError, TSdpServRecordHandle aHandle, TInt /*aTotalRecordsCount*/) 
	{
	if(aError)
		iSeeker.SearchResult(aError,0);
	else
		{
		//We have the record, kick off the attribute request
		TRAPD(err,iAgent->AttributeRequestL(this,
				aHandle,KSdpAttrIdProtocolDescriptorList)); 
		if(err)
			iSeeker.SearchResult(err,0);
		}
	}

// avbryter h鋜na...
void CRFCOMMServiceFinder::AttributeRequestComplete(TSdpServRecordHandle /*aHandle*/, TInt aError)
	{
	if(aError || iPort==0xFF)
		iSeeker.SearchResult(KErrNotFound,0);
	else
		iSeeker.SearchResult(KErrNone,iPort);
		
	}

MSdpElementBuilder* CRFCOMMServiceFinder::BuildUintL(const TDesC8& aUint)
	{
	if(iFoundRFCOMMUUID=ETrue && iPort==0xFF && aUint.Length()==1)
		// We already found RFCOMM, and have not yet got the port, 
		// and have found a 1 byte Uint...
		{
		iPort=aUint[0];
//		return 0; // stops the results process
		}
	return this;
	}

MSdpElementBuilder* CRFCOMMServiceFinder::BuildUUIDL(const TUUID& aUUID)
	{
	if(aUUID== iServiceClassUUID && iPort==0xFF)	
		// We just found RFCOMM, and have not yet got the port
		iFoundRFCOMMUUID=ETrue;
	return this;				
	}

CActiveRFCOMMPortFinder* CActiveRFCOMMPortFinder::NewL(	const TUUID& aServiceClass,
											const TBTDevAddr& aDevAddr)
	{
	CActiveRFCOMMPortFinder* self=new(ELeave) CActiveRFCOMMPortFinder();
	CleanupStack::PushL(self);
	self->ConstructL(aServiceClass, aDevAddr);
	CleanupStack::Pop(self);
	return self;
	}

CActiveRFCOMMPortFinder::CActiveRFCOMMPortFinder()
:	CActive(EPriorityStandard),	iState(EPFStateInitiating), iFoundPort(0xFF)
	{
	}

void CActiveRFCOMMPortFinder::ConstructL(	const TUUID& aServiceClass,
											const TBTDevAddr& aDevAddr)
	{
	iFinder=CRFCOMMServiceFinder::NewL(	aServiceClass, aDevAddr, *this);
	CActiveScheduler::Add(this);
	TRequestStatus* stat=&iStatus;
	User::RequestComplete(stat, KErrNone);
	SetActive();
	}

void CActiveRFCOMMPortFinder::RunL()
	{
	if(iState==EPFStateInitiating)
		{
		TRAPD(err,iFinder->FindPortL());	//	Kick off the search
		ASSERT(!err);
		iState=EPFStateFinding;
		SetActive();
		}
	else	//	Pretty much has to be EPFStateFinding
		{
		CActiveScheduler::Stop();	//	Return to procedural world
		}
	}

void CActiveRFCOMMPortFinder::DoCancel()
	{
	delete iFinder;	//	Should do all the appropriate shutdown stuff
	iFinder=NULL;
	}


void CActiveRFCOMMPortFinder::SearchResult(TInt aError, TUint8 aPort)
	//	Called when the job has been done.
	{
	iFoundPort=aPort;
	TRequestStatus* stat=&iStatus;
	User::RequestComplete(stat, aError);	
	}

CActiveRFCOMMPortFinder::~CActiveRFCOMMPortFinder()
	{
	Cancel();
	delete iFinder;
	}

⌨️ 快捷键说明

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