aboutsummaryrefslogtreecommitdiff
path: root/include/ble
diff options
context:
space:
mode:
authorTrygve Laugstøl <trygvis@inamo.no>2016-04-12 20:06:47 +0200
committerTrygve Laugstøl <trygvis@inamo.no>2016-04-12 20:06:47 +0200
commit2ca532122d60cff4dbdc7f24fbc5783bcc5ad68d (patch)
tree19f9ce796886e216a608fa5e938bd2bd4f0d0b55 /include/ble
parentce07550c57172443c10a66957b50085e273d20b3 (diff)
downloadble-toys-2ca532122d60cff4dbdc7f24fbc5783bcc5ad68d.tar.gz
ble-toys-2ca532122d60cff4dbdc7f24fbc5783bcc5ad68d.tar.bz2
ble-toys-2ca532122d60cff4dbdc7f24fbc5783bcc5ad68d.tar.xz
ble-toys-2ca532122d60cff4dbdc7f24fbc5783bcc5ad68d.zip
Soil Moisture: Adding support for controlling lights.
Bluetooth: refectorying, trying to be more c++ idiomatic and modern. SM/Diller: adding bluetooth to Diller bridge.
Diffstat (limited to 'include/ble')
-rw-r--r--include/ble/Bluetooth.h49
1 files changed, 33 insertions, 16 deletions
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 <boost/uuid/uuid.hpp>
-#include <boost/optional.hpp>
+#include <experimental/optional>
#include <iosfwd>
#include <stdexcept>
#include <vector>
@@ -15,6 +15,8 @@ namespace trygvis {
namespace bluetooth {
using namespace std;
+template<typename T>
+using o = std::experimental::optional<T>;
struct SpecUuid {
public:
@@ -38,18 +40,21 @@ class BluetoothGattService;
class BluetoothGattCharacteristic;
+typedef shared_ptr<BluetoothGattCharacteristic> BluetoothGattCharacteristicPtr;
+typedef shared_ptr<BluetoothGattService> 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<typename T>
+class Iterator {
+public:
+private:
+};
+
+template<typename T>
+class Collection {
+public:
+ Iterator<T> begin();
+
+ Iterator<T> 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<BluetoothGattCharacteristic *> getCharacteristics() const = 0;
-
- virtual void addCharacteristic(BluetoothGattCharacteristic *characteristic) = 0;
+ virtual vector<shared_ptr<BluetoothGattCharacteristic>> getCharacteristics() const = 0;
- virtual const boost::optional<const BluetoothGattCharacteristic &> findCharacteristic(boost::uuids::uuid uuid) const = 0;
+ virtual o<BluetoothGattCharacteristicPtr> 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<BluetoothGattService *> getServices() const = 0;
+ virtual vector<shared_ptr<BluetoothGattService>> getServices() const = 0;
- virtual const boost::optional<BluetoothGattService &> findService(boost::uuids::uuid uuid) const = 0;
+ virtual o<BluetoothGattServicePtr> findService(boost::uuids::uuid uuid) = 0;
};
class BluetoothDevice {
@@ -168,7 +185,7 @@ public:
virtual void runScan(std::function<void(const shared_ptr<BluetoothDevice> &device)>) = 0;
- virtual shared_ptr <BluetoothDevice> getDevice(Mac &mac) = 0;
+ virtual shared_ptr<BluetoothDevice> getDevice(Mac &mac) = 0;
protected:
BluetoothAdapter();