aboutsummaryrefslogtreecommitdiff
path: root/ble/BluetoothImpl.h
diff options
context:
space:
mode:
Diffstat (limited to 'ble/BluetoothImpl.h')
-rw-r--r--ble/BluetoothImpl.h57
1 files changed, 51 insertions, 6 deletions
diff --git a/ble/BluetoothImpl.h b/ble/BluetoothImpl.h
index 69fac6e..7801771 100644
--- a/ble/BluetoothImpl.h
+++ b/ble/BluetoothImpl.h
@@ -18,7 +18,7 @@ namespace trygvis {
namespace bluetooth {
typedef boost::uuids::uuid uuid_t;
-template <class t>
+template<class t>
using o = boost::optional<t>;
class DefaultBluetoothGattCharacteristic : public BluetoothGattCharacteristic {
@@ -94,6 +94,16 @@ public:
characteristics.push_back(characteristic);
}
+ 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 *>();
+ }
+
protected:
BluetoothDevice &device;
const uuid_t uuid;
@@ -110,20 +120,55 @@ protected:
}
};
+template<class A>
class DefaultBluetoothDevice : public BluetoothDevice {
public:
+
+ virtual Mac const &getMac() override {
+ return mac;
+ }
+
+ virtual A &getAdapter() override {
+ return adapter;
+ }
+
+protected:
+ DefaultBluetoothDevice(A adapter, Mac &mac) :
+ adapter(adapter), mac(mac) {
+ DF;
+ }
+
+ virtual ~DefaultBluetoothDevice() {
+ DF;
+ removeServices();
+ }
+
+ void removeServices() {
+ for (auto s: services) {
+ delete s;
+ }
+ services.clear();
+ }
+
+ A adapter;
+ Mac &mac;
+ vector<BluetoothGattService *> services;
+};
+
+class DefaultBluetoothGatt : public BluetoothGatt {
+public:
virtual const vector<BluetoothGattService *> getServices() const {
return services;
};
- virtual const o<BluetoothGattService*> findService(boost::uuids::uuid uuid) const {
+ 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 *>(s);
}
}
- return o<BluetoothGattService*>();
+ return o<BluetoothGattService *>();
}
virtual void addService(BluetoothGattService *service) {
@@ -131,11 +176,11 @@ public:
}
protected:
- DefaultBluetoothDevice() {
+ DefaultBluetoothGatt() {
DF;
}
- virtual ~DefaultBluetoothDevice() {
+ virtual ~DefaultBluetoothGatt() {
DF;
removeServices();
}