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

📄 btservicesearcher.cpp

📁 symbian平台蓝牙程序,功能实现:搜索设备,指定时间间隔搜索,对指定的设备发送信息,也可指定时间间隔发送,日志操作,可通过mms,红外,蓝牙发送日志等
💻 CPP
字号:
/* Copyright (c) 2002, Nokia Mobile Phones. All rights reserved */

#include "BTServiceSearcher.h"
#include "BTServiceSearcher.pan"

//
#include "eikenv.h"

CBTServiceSearcher::CBTServiceSearcher(/*MLog& aLog*/)
:  iIsDeviceSelectorConnected(EFalse)//,
   //iLog(aLog)
    {
    }

CBTServiceSearcher::~CBTServiceSearcher()
    {
    if (iIsDeviceSelectorConnected)
        {
        iDeviceSelector.CancelNotifier(KDeviceSelectionNotifierUid);
        iDeviceSelector.Close();
        }
    delete iSdpSearchPattern;
    iSdpSearchPattern = NULL;

    delete iAgent;
    iAgent = NULL;
    }

void CBTServiceSearcher::SelectDeviceByDiscoveryL(TRequestStatus& aObserverRequestStatus)
    {
    if (!iIsDeviceSelectorConnected)
        {
        User::LeaveIfError(iDeviceSelector.Connect());
        iIsDeviceSelectorConnected = ETrue;
        }

//  Request a device selection 
    TBTDeviceSelectionParamsPckg selectionFilter;
    selectionFilter().SetUUID(ServiceClass());

    iDeviceSelector.StartNotifierAndGetResponse(
        aObserverRequestStatus, 
        KDeviceSelectionNotifierUid, 
        selectionFilter, 
        iResponse);

// 鋘dern


/*	//
		TBTDevAddr iAutoConnectAddress;
		TBuf8<54> settingsBuf;
		settingsBuf.Copy(_L("000 006 171 128 083 070")); //flo
			
		TLex8 lex(settingsBuf);
			for (TInt i = 0; i < 6; i++)
			{
			TInt tempByte;
			lex.Val(tempByte);
			iAutoConnectAddress[i] = (TUint8) tempByte;
			lex.SkipSpace();
			}


	//iResponse().SetDeviceAddress(iAutoConnectAddress);

*/
    }


void CBTServiceSearcher::FindServiceL(TRequestStatus& aObserverRequestStatus)
    {
    if (!iResponse().IsValidBDAddr())
        {
        User::Leave(KErrNotFound);
        }
    iHasFoundService = EFalse;

    // delete any existing agent and search pattern
    delete iSdpSearchPattern;
    iSdpSearchPattern = NULL;

    delete iAgent;
    iAgent = NULL;

	//
/*		//
		TBTDevAddr iAutoConnectAddress;
		TBuf8<54> settingsBuf;
		settingsBuf.Copy(_L("000 006 171 128 083 070")); //flo
			
		TLex8 lex(settingsBuf);
			for (TInt i = 0; i < 6; i++)
			{
			TInt tempByte;
			lex.Val(tempByte);
			iAutoConnectAddress[i] = (TUint8) tempByte;
			lex.SkipSpace();
			}
*/

iAgent = CSdpAgent::NewL(*this, BTDevAddr());
			//iAgent = CSdpAgent::NewL(*this, iAutoConnectAddress);

//========================================== bei bluejacking hier direkt mac id 黚ergeben

//========================================== bei bluejacking hier direkt mac id 黚ergeben

    iSdpSearchPattern = CSdpSearchPattern::NewL();
   
    iSdpSearchPattern->AddL(ServiceClass()); 
    // return code is the position in the list that the UUID is inserted at 
    // and is intentionally ignored
  
    iAgent->SetRecordFilterL(*iSdpSearchPattern);

    iStatusObserver = &aObserverRequestStatus;

    iAgent->NextRecordRequestL();
    }

void CBTServiceSearcher::NextRecordRequestComplete(
    TInt aError, 
    TSdpServRecordHandle aHandle, 
    TInt aTotalRecordsCount)
    {
    TRAPD(error,
        NextRecordRequestCompleteL(aError, aHandle, aTotalRecordsCount);
    );

    if (error != KErrNone) 
        {
        Panic(EBTServiceSearcherNextRecordRequestComplete);
        }
    }

void CBTServiceSearcher::NextRecordRequestCompleteL(
    TInt aError, 
    TSdpServRecordHandle aHandle, 
    TInt aTotalRecordsCount
)
    {
    if (aError == KErrEof)
        {
        Finished();
        return;
        }

    if (aError != KErrNone)
        {
        Finished(aError);
        return;
        }

    if (aTotalRecordsCount == 0)
        {
        Finished(KErrNotFound);
        return;
        }

    //  Request its attributes
    iAgent->AttributeRequestL(aHandle, KSdpAttrIdProtocolDescriptorList);
    }

void CBTServiceSearcher::AttributeRequestResult(
    TSdpServRecordHandle aHandle, 
    TSdpAttributeID aAttrID, 
    CSdpAttrValue* aAttrValue
)
    {
    TRAPD(error,
        AttributeRequestResultL(aHandle, aAttrID, aAttrValue);
    );
    if (error != KErrNone)
        {
        Panic(EBTServiceSearcherAttributeRequestResult);
        }
    }

void CBTServiceSearcher::AttributeRequestResultL(
    TSdpServRecordHandle /*aHandle*/, 
    TSdpAttributeID aAttrID, 
    CSdpAttrValue* aAttrValue
)
    {
    ASSERT(aAttrID == KSdpAttrIdProtocolDescriptorList);

    TSdpAttributeParser parser(ProtocolList(), *this);

    // Validate the attribute value, and extract the RFCOMM channel
    aAttrValue->AcceptVisitorL(parser);

    if (parser.HasFinished())
        {
        // Found a suitable record so change state
        iHasFoundService = ETrue;
        }
    }

void CBTServiceSearcher::AttributeRequestComplete(TSdpServRecordHandle aHandle, TInt aError)
    {
    TRAPD(error,
        AttributeRequestCompleteL(aHandle, aError);
    );
    if (error != KErrNone)
        {
        Panic(EBTServiceSearcherAttributeRequestComplete);
        }
    }

void CBTServiceSearcher::AttributeRequestCompleteL(TSdpServRecordHandle /*aHandle*/, TInt aError)
    {
    if (aError != KErrNone)
        {
        }
    else if (!HasFinishedSearching())
        {
        // have not found a suitable record so request another
        iAgent->NextRecordRequestL();
        }
    else
        {
        Finished();
        }
    }

void CBTServiceSearcher::Finished(TInt aError /* default = KErrNone */)
    {
    if (aError == KErrNone && !HasFoundService())
        {
        aError = KErrNotFound;
        }
    User::RequestComplete(iStatusObserver, aError);
    }

TBool CBTServiceSearcher::HasFinishedSearching() const
    {
    return EFalse;
    }

const TBTDevAddr& CBTServiceSearcher::BTDevAddr()
    {
    return iResponse().BDAddr();
    }

const TBTDeviceResponseParams& CBTServiceSearcher::ResponseParams()
    {
    return iResponse();
    }

TBool CBTServiceSearcher::HasFoundService() const
    {
    return iHasFoundService;
    }

⌨️ 快捷键说明

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