summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--gatocentralmanager.cpp31
-rw-r--r--gatocentralmanager.h3
-rw-r--r--gatoperipheral.cpp6
-rw-r--r--gatoperipheral.h1
-rw-r--r--gatouuid.cpp4
5 files changed, 42 insertions, 3 deletions
diff --git a/gatocentralmanager.cpp b/gatocentralmanager.cpp
index 00dd531..0d3efd9 100644
--- a/gatocentralmanager.cpp
+++ b/gatocentralmanager.cpp
@@ -51,6 +51,20 @@ GatoCentralManager::~GatoCentralManager()
delete d_ptr;
}
+GatoPeripheral * GatoCentralManager::getPeripheral(const GatoAddress &address)
+{
+ Q_D(GatoCentralManager);
+
+ GatoPeripheral *peripheral = d->peripherals.value(address);
+ if (peripheral) {
+ return peripheral;
+ } else {
+ peripheral = new GatoPeripheral(address, this);
+ d->peripherals.insert(address, peripheral);
+ return peripheral;
+ }
+}
+
void GatoCentralManager::scanForPeripherals(PeripheralScanOptions options)
{
scanForPeripheralsWithServices(QList<GatoUUID>(), options);
@@ -215,5 +229,20 @@ void GatoCentralManagerPrivate::handleAdvertising(le_advertising_info *info, int
peripheral->parseEIR(info->data, info->length);
}
- emit q->discoveredPeripheral(peripheral, rssi);
+ bool passes_filter;
+ if (filter_uuids.isEmpty()) {
+ passes_filter = true;
+ } else {
+ passes_filter = false;
+ foreach (const GatoUUID & filter_uuid, filter_uuids) {
+ if (peripheral->advertisesService(filter_uuid)) {
+ passes_filter = true;
+ break;
+ }
+ }
+ }
+
+ if (passes_filter) {
+ emit q->discoveredPeripheral(peripheral, rssi);
+ }
}
diff --git a/gatocentralmanager.h b/gatocentralmanager.h
index 00225a0..857b9cc 100644
--- a/gatocentralmanager.h
+++ b/gatocentralmanager.h
@@ -6,6 +6,7 @@
#include "gatouuid.h"
class GatoPeripheral;
+class GatoAddress;
class GatoCentralManagerPrivate;
class LIBGATO_EXPORT GatoCentralManager : public QObject
@@ -24,6 +25,8 @@ public:
explicit GatoCentralManager(QObject *parent = 0);
~GatoCentralManager();
+ GatoPeripheral *getPeripheral(const GatoAddress& address);
+
public slots:
void scanForPeripherals(PeripheralScanOptions options = 0);
void scanForPeripheralsWithServices(const QList<GatoUUID>& uuids, PeripheralScanOptions options = 0);
diff --git a/gatoperipheral.cpp b/gatoperipheral.cpp
index 50e1bd3..0a1f723 100644
--- a/gatoperipheral.cpp
+++ b/gatoperipheral.cpp
@@ -138,6 +138,12 @@ void GatoPeripheral::parseEIR(quint8 data[], int len)
assert(pos == len);
}
+bool GatoPeripheral::advertisesService(const GatoUUID &uuid) const
+{
+ Q_D(const GatoPeripheral);
+ return d->service_uuids.contains(uuid);
+}
+
void GatoPeripheral::connectPeripheral()
{
Q_D(GatoPeripheral);
diff --git a/gatoperipheral.h b/gatoperipheral.h
index d16ac9c..4b757df 100644
--- a/gatoperipheral.h
+++ b/gatoperipheral.h
@@ -41,6 +41,7 @@ public:
QList<GatoService> services() const;
void parseEIR(quint8 data[], int len);
+ bool advertisesService(const GatoUUID &uuid) const;
public slots:
void connectPeripheral();
diff --git a/gatouuid.cpp b/gatouuid.cpp
index f87831a..9a2be76 100644
--- a/gatouuid.cpp
+++ b/gatouuid.cpp
@@ -165,13 +165,13 @@ QDebug operator<<(QDebug debug, const GatoUUID &uuid)
uuid16 = uuid.toUInt16(&ok);
if (ok) {
- debug.nospace() << "0x" << uuid16;
+ debug.nospace() << "0x" << hex << uuid16 << dec;
return debug.space();
}
uuid32 = uuid.toUInt32(&ok);
if (ok) {
- debug.nospace() << "0x" << uuid32;
+ debug.nospace() << "0x" << hex << uuid32 << dec;
return debug.space();
}