aboutsummaryrefslogtreecommitdiff
path: root/ble/BluetoothImpl.h
diff options
context:
space:
mode:
Diffstat (limited to 'ble/BluetoothImpl.h')
-rw-r--r--ble/BluetoothImpl.h73
1 files changed, 37 insertions, 36 deletions
diff --git a/ble/BluetoothImpl.h b/ble/BluetoothImpl.h
index ef9a733..c9ba80c 100644
--- a/ble/BluetoothImpl.h
+++ b/ble/BluetoothImpl.h
@@ -2,6 +2,7 @@
#define BLUETOOTH_IMPL_H
#include "Bluetooth.h"
+#include "log.h"
#include <boost/uuid/uuid_io.hpp>
#include <cstring>
@@ -94,14 +95,14 @@ public:
characteristics.push_back(characteristic);
}
- virtual const o<BluetoothGattCharacteristic *> findCharacteristic(uuid_t uuid) const {
+ virtual const o<BluetoothGattCharacteristic &> findCharacteristic(uuid_t uuid) const {
for (auto c: characteristics) {
if (memcmp(c->getUuid().data, uuid.data, 16) == 0) {
- return o<BluetoothGattCharacteristic *>(c);
+ return o<BluetoothGattCharacteristic &>(*c);
}
}
- return o<BluetoothGattCharacteristic *>();
+ return o<BluetoothGattCharacteristic &>();
}
protected:
@@ -120,25 +121,37 @@ protected:
}
};
-template<class A>
-class DefaultBluetoothDevice : public BluetoothDevice {
+template<class _D>
+class DefaultBluetoothGatt : public BluetoothGatt {
public:
+ virtual _D &getDevice() const {
+ return device;
+ }
- virtual Mac const &getMac() override {
- return mac;
+ virtual const vector<BluetoothGattService *> getServices() const {
+ return services;
+ };
+
+ virtual const o<BluetoothGattService &> findService(uuid_t uuid) const {
+ for (auto s: services) {
+ if (memcmp(s->getUuid().data, uuid.data, 16) == 0) {
+ return o<BluetoothGattService &>(*s);
+ }
+ }
+
+ return o<BluetoothGattService &>();
}
- virtual A &getAdapter() override {
- return adapter;
+ virtual void addService(BluetoothGattService *service) {
+ services.push_back(service);
}
protected:
- DefaultBluetoothDevice(A &adapter, Mac &mac) :
- adapter(adapter), mac(mac) {
+ DefaultBluetoothGatt(_D &device) : device(device) {
DF;
}
- virtual ~DefaultBluetoothDevice() {
+ virtual ~DefaultBluetoothGatt() {
DF;
removeServices();
}
@@ -150,42 +163,29 @@ protected:
services.clear();
}
- A &adapter;
- Mac &mac;
+ _D &device;
vector<BluetoothGattService *> services;
};
-template<class _D>
-class DefaultBluetoothGatt : public BluetoothGatt {
+template<class A>
+class DefaultBluetoothDevice : public BluetoothDevice {
public:
- virtual _D &getDevice() const {
- return device;
- }
-
- virtual const vector<BluetoothGattService *> getServices() const {
- return services;
- };
-
- virtual const o<BluetoothGattService *> findService(uuid_t uuid) const {
- for (auto s: services) {
- if (memcmp(s->getUuid().data, uuid.data, 16) == 0) {
- return o<BluetoothGattService *>(s);
- }
- }
- return o<BluetoothGattService *>();
+ virtual Mac const &getMac() override {
+ return mac;
}
- virtual void addService(BluetoothGattService *service) {
- services.push_back(service);
+ virtual A &getAdapter() override {
+ return adapter;
}
protected:
- DefaultBluetoothGatt(_D &device) : device(device) {
+ DefaultBluetoothDevice(A &adapter, Mac &mac) :
+ adapter(adapter), mac(mac) {
DF;
}
- virtual ~DefaultBluetoothGatt() {
+ virtual ~DefaultBluetoothDevice() {
DF;
removeServices();
}
@@ -197,7 +197,8 @@ protected:
services.clear();
}
- _D &device;
+ A &adapter;
+ Mac &mac;
vector<BluetoothGattService *> services;
};