From 55496b91d2b144c5b8aafd20a8c8332aee4607ab Mon Sep 17 00:00:00 2001 From: "Javier S. Pedro" Date: Sat, 7 Dec 2013 01:51:59 +0100 Subject: add a method to retrieve a known device from a manager --- gatocentralmanager.cpp | 31 ++++++++++++++++++++++++++++++- gatocentralmanager.h | 3 +++ gatoperipheral.cpp | 6 ++++++ gatoperipheral.h | 1 + gatouuid.cpp | 4 ++-- 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(), 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& 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 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(); } -- cgit v1.2.3