📄 bluetoothdevicesearcher.cpp
字号:
/**
*
* @brief Definition of CBluetoothDeviceSearcher
*
* Copyright (c) EMCC Software Ltd 2003
* @version 1.0
*/
// Includes
#include "BluetoothDeviceSearcher.h"
#include "BluetoothDefinitions.h"
#include "BluetoothObserver.h"
/**
* Factory Constructor.
* Only available way to construct class.
* This function can leave L, returning value is on Cleanup Stack C
* @param none
* @return new instance of the CBluetoothDeviceSearcher on Cleanup stack
*/
CBluetoothDeviceSearcher* CBluetoothDeviceSearcher::NewLC(MBluetoothObserver &aBluetoothObserver)
{
CBluetoothDeviceSearcher* self = new (ELeave) CBluetoothDeviceSearcher(aBluetoothObserver);
CleanupStack::PushL(self);
self->ConstructL();
return self;
}
/**
* Factory Constructor.
* Only available way to construct class.
* This function can leave L
* @param none
* @return new instance of the CBluetoothDeviceSearcher
*/
CBluetoothDeviceSearcher* CBluetoothDeviceSearcher::NewL(MBluetoothObserver &aBluetoothObserver)
{
CBluetoothDeviceSearcher* self = CBluetoothDeviceSearcher::NewLC(aBluetoothObserver);
CleanupStack::Pop(self);
return self;
}
/**
* Constructor.
* Private constructor.
* @see NewL
* @see NewLC
* @param none
* @return none
**/
CBluetoothDeviceSearcher::CBluetoothDeviceSearcher(MBluetoothObserver &aBluetoothObserver)
: CActive(0), iObserver(aBluetoothObserver)
{
}
/**
* Destructor.
*
* @param none
* @return none
**/
CBluetoothDeviceSearcher::~CBluetoothDeviceSearcher()
{
Deque();
}
/**
* Second Stage Constructor.
* This function can leave L
* @param none
* @see NewL
* @see NewLC
* @param none
* @return none
*/
void CBluetoothDeviceSearcher::ConstructL()
{
CActiveScheduler::Add(this);
}
/**
* Select Device.
*
* RNotifier performs a search of local piconet, and provides a Selection List of all devices found, so that,
* the User may select one to begin communication with
*
* @param aResponse parameter is populated with remote device information
* @return errorcode
**/
void CBluetoothDeviceSearcher::SelectDeviceL(TBTDeviceResponseParamsPckg& aResponse)
{
iResponse = &aResponse; // store a pointer to the response buffer
TUUID targetServiceClass(KServiceClass);
TBTDeviceClass deviceClass(KServiceClass);
TBTDeviceSelectionParams selectionFilter;
selectionFilter.SetUUID(targetServiceClass);
selectionFilter.SetDeviceClass(deviceClass);
// These filtering methods do not work at the time of writing,
// and ALL Bluetooth devices in range are returned
TBTDeviceSelectionParamsPckg selectionParams(selectionFilter);
User::LeaveIfError(iNotifier.Connect());
iNotifier.StartNotifierAndGetResponse(iStatus, KDeviceSelectionNotifierUid, selectionParams, aResponse);
SetActive();
}
/**
* RunL.
*
* Called when device selection process is completed. Notifies the observer
* that a device has been selected.
*
* @param none
* @return none
**/
void CBluetoothDeviceSearcher::RunL()
{
TInt retVal = iStatus.Int();
if (retVal == KErrNone)
{
if ((*iResponse)().IsValidDeviceName())
{
retVal = KErrNone;
}
}
iNotifier.CancelNotifier(KDeviceSelectionNotifierUid);
iNotifier.Close();
iObserver.DeviceFoundL(retVal);
}
/**
* DoCancel.
*
* Called by active object framework when this object is cancelled
*
* @param none
* @return none
**/
void CBluetoothDeviceSearcher::DoCancel()
{
iNotifier.CancelNotifier(KDeviceSelectionNotifierUid);
iNotifier.Close();
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -