summaryrefslogtreecommitdiffstats
path: root/src/bluetooth/qbluetoothdevicediscoveryagent_osx.mm
diff options
context:
space:
mode:
authorAlex Blasche <alexander.blasche@theqtcompany.com>2016-07-08 14:27:00 +0200
committerTimur Pocheptsov <timur.pocheptsov@theqtcompany.com>2016-07-13 09:50:41 +0000
commit1de888375e3bafb44c9cc8dafce68e2b6b4f7a48 (patch)
treed7245429a761fb8ed744c6187d3a4c6706368a38 /src/bluetooth/qbluetoothdevicediscoveryagent_osx.mm
parent5ce6ed270db4a693f62c14347203d7b367a56488 (diff)
Permit selection of discovery mode (btle vs classic)
This change introduces the new API but does not yet implement the specific selection. In any case BlueZ does not need any specific implementation as classic and BTLE devices are found using the same method. iOS does not need any specific implementation as it only supports BTLE discovery. Task-number: QTBUG-46253 Change-Id: Ie6365966091effe5f3a68f8a283657c7cb43b692 Reviewed-by: Timur Pocheptsov <timur.pocheptsov@theqtcompany.com>
Diffstat (limited to 'src/bluetooth/qbluetoothdevicediscoveryagent_osx.mm')
-rw-r--r--src/bluetooth/qbluetoothdevicediscoveryagent_osx.mm39
1 files changed, 34 insertions, 5 deletions
diff --git a/src/bluetooth/qbluetoothdevicediscoveryagent_osx.mm b/src/bluetooth/qbluetoothdevicediscoveryagent_osx.mm
index 02a45f18..ba74da97 100644
--- a/src/bluetooth/qbluetoothdevicediscoveryagent_osx.mm
+++ b/src/bluetooth/qbluetoothdevicediscoveryagent_osx.mm
@@ -95,7 +95,7 @@ public:
bool isValid() const;
bool isActive() const;
- void start();
+ void start(QBluetoothDeviceDiscoveryAgent::DiscoveryMethods m);
void startLE();
void stop();
@@ -149,6 +149,7 @@ private:
DevicesList discoveredDevices;
int lowEnergySearchTimeout;
+ QBluetoothDeviceDiscoveryAgent::DiscoveryMethods requestedMethods;
};
QBluetoothDeviceDiscoveryAgentPrivate::QBluetoothDeviceDiscoveryAgentPrivate(const QBluetoothAddress &adapter,
@@ -217,13 +218,16 @@ bool QBluetoothDeviceDiscoveryAgentPrivate::isActive() const
return agentState != NonActive;
}
-void QBluetoothDeviceDiscoveryAgentPrivate::start()
+void QBluetoothDeviceDiscoveryAgentPrivate::start(QBluetoothDeviceDiscoveryAgent::DiscoveryMethods methods)
{
Q_ASSERT_X(isValid(), Q_FUNC_INFO, "called on invalid device discovery agent");
Q_ASSERT_X(!isActive(), Q_FUNC_INFO, "called on active device discovery agent");
Q_ASSERT_X(lastError != QBluetoothDeviceDiscoveryAgent::InvalidBluetoothAdapterError,
Q_FUNC_INFO, "called with an invalid Bluetooth adapter");
+ //TODO Implement discovery method handling (see input parameter)
+ requestedMethods = methods;
+
if (stopPending) {
startPending = true;
return;
@@ -340,7 +344,7 @@ void QBluetoothDeviceDiscoveryAgentPrivate::inquiryFinished(IOBluetoothDeviceInq
} else if (startPending) {
startPending = false;
stopPending = false;
- start();
+ start(requestedMethods);
} else {
// We can be here _only_ if a classic scan
// finished in a normal way (not cancelled).
@@ -473,7 +477,7 @@ void QBluetoothDeviceDiscoveryAgentPrivate::LEinquiryFinished()
} else if (startPending) {
startPending = false;
stopPending = false;
- start(); //Start from a classic scan again.
+ start(requestedMethods); //Start again.
} else {
emit q_ptr->finished();
}
@@ -543,12 +547,17 @@ QList<QBluetoothDeviceInfo> QBluetoothDeviceDiscoveryAgent::discoveredDevices()
return d_ptr->discoveredDevices;
}
+QBluetoothDeviceDiscoveryAgent::DiscoveryMethods QBluetoothDeviceDiscoveryAgent::supportedDiscoveryMethods()
+{
+ return (ClassicMethod | LowEnergyMethod);
+}
+
void QBluetoothDeviceDiscoveryAgent::start()
{
if (d_ptr->lastError != InvalidBluetoothAdapterError) {
if (d_ptr->isValid()) {
if (!isActive())
- d_ptr->start();
+ d_ptr->start(supportedDiscoveryMethods());
} else {
// We previously failed to initialize d_ptr correctly:
// either some memory allocation problem or
@@ -559,6 +568,26 @@ void QBluetoothDeviceDiscoveryAgent::start()
}
}
+void QBluetoothDeviceDiscoveryAgent::start(DiscoveryMethods methods)
+{
+ if (methods == NoMethod)
+ return;
+
+ DiscoveryMethods supported =
+ QBluetoothDeviceDiscoveryAgent::supportedDiscoveryMethods();
+
+ Q_D(QBluetoothDeviceDiscoveryAgent);
+ if (!((supported & methods) == methods)) {
+ d_ptr->lastError = UnsupportedDiscoveryMethod;
+ d_ptr->errorString = QBluetoothDeviceDiscoveryAgent::tr("One or more device discovery methods "
+ "are not supported on this platform");
+ emit error(d_ptr->lastError);
+ }
+
+ if (!isActive() && d_ptr->lastError != InvalidBluetoothAdapterError)
+ d_ptr->start(methods);
+}
+
void QBluetoothDeviceDiscoveryAgent::stop()
{
if (d_ptr->isValid()) {