aboutsummaryrefslogtreecommitdiff
path: root/ble/BluetoothImpl.h
diff options
context:
space:
mode:
authorTrygve Laugstøl <trygvis@inamo.no>2015-02-21 10:28:00 +0100
committerTrygve Laugstøl <trygvis@inamo.no>2015-02-21 10:28:00 +0100
commit7c9f266cdb37e215279208198dfe009dc66c5daa (patch)
tree131334cd6e14c5d14e2a07c06aff9920744fb246 /ble/BluetoothImpl.h
parent9c095ce3c2165ae9fb976b007ba5c14602d06a0b (diff)
downloadble-toys-7c9f266cdb37e215279208198dfe009dc66c5daa.tar.gz
ble-toys-7c9f266cdb37e215279208198dfe009dc66c5daa.tar.bz2
ble-toys-7c9f266cdb37e215279208198dfe009dc66c5daa.tar.xz
ble-toys-7c9f266cdb37e215279208198dfe009dc66c5daa.zip
o Creating a class to access GATT.
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();
}