From 2ca532122d60cff4dbdc7f24fbc5783bcc5ad68d Mon Sep 17 00:00:00 2001 From: Trygve Laugstøl Date: Tue, 12 Apr 2016 20:06:47 +0200 Subject: Soil Moisture: Adding support for controlling lights. Bluetooth: refectorying, trying to be more c++ idiomatic and modern. SM/Diller: adding bluetooth to Diller bridge. --- include/ble/Bluetooth.h | 49 +++++++++++++++++++++++++++++++++---------------- 1 file changed, 33 insertions(+), 16 deletions(-) (limited to 'include') diff --git a/include/ble/Bluetooth.h b/include/ble/Bluetooth.h index 8da602f..f2b5b13 100644 --- a/include/ble/Bluetooth.h +++ b/include/ble/Bluetooth.h @@ -2,7 +2,7 @@ #define BLUETOOTH_H #include -#include +#include #include #include #include @@ -15,6 +15,8 @@ namespace trygvis { namespace bluetooth { using namespace std; +template +using o = std::experimental::optional; struct SpecUuid { public: @@ -38,18 +40,21 @@ class BluetoothGattService; class BluetoothGattCharacteristic; +typedef shared_ptr BluetoothGattCharacteristicPtr; +typedef shared_ptr BluetoothGattServicePtr; + class BluetoothException : public runtime_error { public: BluetoothException(const BluetoothAdapter *adapter, string const &what) : - runtime_error(what), adapter(adapter), device(nullptr) { + runtime_error(what), adapter(adapter), device(nullptr) { } BluetoothException(const BluetoothDevice *device, string const &what) : - runtime_error(what), adapter(nullptr), device(device) { + runtime_error(what), adapter(nullptr), device(device) { } BluetoothException(string const &what) : - runtime_error(what), adapter(nullptr), device(nullptr) { + runtime_error(what), adapter(nullptr), device(nullptr) { } const BluetoothAdapter *adapter; @@ -83,12 +88,26 @@ private: uint8_t bytes[6]; }; +template +class Iterator { +public: +private: +}; + +template +class Collection { +public: + Iterator begin(); + + Iterator end(); +}; + class BluetoothGattCharacteristic { public: virtual ~BluetoothGattCharacteristic() { }; - virtual BluetoothGattService &getService() const = 0; + virtual BluetoothGattServicePtr getService() const = 0; virtual uint16_t getHandle() const = 0; @@ -112,11 +131,9 @@ public: virtual uint16_t getEndGroupHandle() const = 0; - virtual const vector getCharacteristics() const = 0; - - virtual void addCharacteristic(BluetoothGattCharacteristic *characteristic) = 0; + virtual vector> getCharacteristics() const = 0; - virtual const boost::optional findCharacteristic(boost::uuids::uuid uuid) const = 0; + virtual o findCharacteristic(boost::uuids::uuid uuid) = 0; }; class BluetoothGatt { @@ -126,23 +143,23 @@ public: virtual ~BluetoothGatt(); // No copying - BluetoothGatt(const BluetoothGatt&) = delete; + BluetoothGatt(const BluetoothGatt &) = delete; - BluetoothGatt& operator=(const BluetoothGatt&) = delete; + BluetoothGatt &operator=(const BluetoothGatt &) = delete; virtual BluetoothDevice &getDevice() const = 0; virtual bool isConnected() const = 0; - virtual void writeValue(const BluetoothGattCharacteristic &c, const ByteBuffer &bytes) = 0; + virtual void writeValue(const BluetoothGattCharacteristicPtr &c, const ByteBuffer &bytes) = 0; - virtual ByteBuffer readValue(const BluetoothGattCharacteristic &c) = 0; + virtual ByteBuffer readValue(const BluetoothGattCharacteristicPtr &c) = 0; virtual void discoverServices() = 0; - virtual const vector getServices() const = 0; + virtual vector> getServices() const = 0; - virtual const boost::optional findService(boost::uuids::uuid uuid) const = 0; + virtual o findService(boost::uuids::uuid uuid) = 0; }; class BluetoothDevice { @@ -168,7 +185,7 @@ public: virtual void runScan(std::function &device)>) = 0; - virtual shared_ptr getDevice(Mac &mac) = 0; + virtual shared_ptr getDevice(Mac &mac) = 0; protected: BluetoothAdapter(); -- cgit v1.2.3