aboutsummaryrefslogtreecommitdiff
path: root/ble/BluetoothImpl.h
diff options
context:
space:
mode:
authorTrygve Laugstøl <trygvis@inamo.no>2015-02-21 23:58:39 +0100
committerTrygve Laugstøl <trygvis@inamo.no>2015-02-21 23:58:39 +0100
commit5926b05afa21eaac36c185e7fc458710efa30b02 (patch)
tree1d835b53fcb3dbc44b07084155a37874ce8325dc /ble/BluetoothImpl.h
parenta76e09808905d280282a81958cb4c68f71f18ca4 (diff)
downloadble-toys-5926b05afa21eaac36c185e7fc458710efa30b02.tar.gz
ble-toys-5926b05afa21eaac36c185e7fc458710efa30b02.tar.bz2
ble-toys-5926b05afa21eaac36c185e7fc458710efa30b02.tar.xz
ble-toys-5926b05afa21eaac36c185e7fc458710efa30b02.zip
o Support for reading and writing characteristics.
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;
};