aboutsummaryrefslogtreecommitdiff
path: root/include/ble/Bluetooth.h
diff options
context:
space:
mode:
Diffstat (limited to 'include/ble/Bluetooth.h')
-rw-r--r--include/ble/Bluetooth.h38
1 files changed, 24 insertions, 14 deletions
diff --git a/include/ble/Bluetooth.h b/include/ble/Bluetooth.h
index 914dc26..5f7cd17 100644
--- a/include/ble/Bluetooth.h
+++ b/include/ble/Bluetooth.h
@@ -10,6 +10,7 @@
#include <map>
#include <functional>
#include <cstring>
+#include <chrono>
#include "ble/ByteBuffer.h"
#include "ble/att.h"
@@ -17,7 +18,6 @@
namespace trygvis {
namespace bluetooth {
-using std::shared_ptr;
using std::string;
using std::vector;
using std::map;
@@ -33,10 +33,12 @@ class BluetoothGattService;
class BluetoothGattCharacteristic;
class BluetoothGattDescriptor;
-typedef shared_ptr<BluetoothGatt> BluetoothGattPtr;
-typedef shared_ptr<BluetoothGattService> BluetoothGattServicePtr;
-typedef shared_ptr<BluetoothGattCharacteristic> BluetoothGattCharacteristicPtr;
-typedef shared_ptr<BluetoothGattDescriptor> BluetoothGattDescriptorPtr;
+typedef std::shared_ptr<BluetoothGatt> BluetoothGattPtr;
+typedef std::shared_ptr<BluetoothGattService> BluetoothGattServicePtr;
+typedef std::shared_ptr<BluetoothGattCharacteristic> BluetoothGattCharacteristicPtr;
+typedef std::shared_ptr<BluetoothGattDescriptor> BluetoothGattDescriptorPtr;
+typedef std::shared_ptr<BluetoothDevice> BluetoothDevicePtr;
+typedef std::shared_ptr<BluetoothAdapter> BluetoothAdapterPtr;
class Mac {
public:
@@ -65,6 +67,12 @@ private:
uint8_t bytes[6];
};
+class BluetoothCallback {
+ virtual ~BluetoothCallback() = default;
+
+ virtual void onCharacteristicChanged(BluetoothGattPtr& gatt, BluetoothGattCharacteristicPtr& characteristic) = 0;
+};
+
class BluetoothGattDescriptor {
public:
static const uint8_t DISABLE_NOTIFICATION_VALUE[2];
@@ -104,9 +112,9 @@ public:
virtual uint16_t getValueHandle() const = 0;
- virtual shared_ptr<BluetoothGattDescriptor> getDescriptor(Uuid uuid) const = 0;
+ virtual BluetoothGattDescriptorPtr getDescriptor(Uuid uuid) const = 0;
- virtual shared_ptr<BluetoothGattDescriptor> getDescriptor(ShortUuid uuid) const {
+ virtual BluetoothGattDescriptorPtr getDescriptor(ShortUuid uuid) const {
return getDescriptor(uuid.toLong());
};
};
@@ -123,7 +131,7 @@ public:
virtual uint16_t getEndGroupHandle() const = 0;
- virtual vector<shared_ptr<BluetoothGattCharacteristic>> getCharacteristics() const = 0;
+ virtual vector<BluetoothGattCharacteristicPtr> getCharacteristics() const = 0;
virtual o<BluetoothGattCharacteristicPtr> findCharacteristic(Uuid uuid) = 0;
@@ -155,7 +163,9 @@ public:
virtual void discoverServices() = 0;
- virtual vector<shared_ptr<BluetoothGattService>> getServices() const = 0;
+ virtual void process(std::chrono::system_clock::duration max_duration) = 0;
+
+ virtual vector<BluetoothGattServicePtr> getServices() const = 0;
virtual o<BluetoothGattServicePtr> findService(Uuid uuid) = 0;
@@ -174,7 +184,7 @@ public:
virtual BluetoothAdapter &getAdapter() = 0;
- virtual shared_ptr<BluetoothGatt> connectGatt() = 0;
+ virtual BluetoothGattPtr connectGatt(BluetoothCallback* callback = nullptr) = 0;
};
class BluetoothAdapter {
@@ -185,9 +195,9 @@ public:
virtual void stopScan() = 0;
- virtual void runScan(std::function<void(const shared_ptr<BluetoothDevice> &device)>) = 0;
+ virtual void runScan(std::function<void(const BluetoothDevicePtr &device)>) = 0;
- virtual shared_ptr<BluetoothDevice> getDevice(Mac &mac) = 0;
+ virtual BluetoothDevicePtr getDevice(Mac &mac) = 0;
protected:
BluetoothAdapter();
@@ -206,10 +216,10 @@ public:
~BluetoothSystem();
- shared_ptr<BluetoothAdapter> getAdapter(string name);
+ BluetoothAdapterPtr getAdapter(string name);
private:
- map<string, shared_ptr<BluetoothAdapter>> adapters;
+ map<string, BluetoothAdapterPtr> adapters;
};
} // namespace bluetooth