diff options
Diffstat (limited to 'ble/BluetoothImpl.h')
-rw-r--r-- | ble/BluetoothImpl.h | 55 |
1 files changed, 53 insertions, 2 deletions
diff --git a/ble/BluetoothImpl.h b/ble/BluetoothImpl.h index 975a011..5b53cd4 100644 --- a/ble/BluetoothImpl.h +++ b/ble/BluetoothImpl.h @@ -40,6 +40,46 @@ protected: // Shared classes +class DefaultBluetoothGattDescriptor : public BluetoothGattDescriptor { +public: + explicit DefaultBluetoothGattDescriptor(const BluetoothGattCharacteristicPtr& characteristic, uint16_t handle, + const Uuid &uuid) : characteristic(characteristic), handle(handle), uuid(uuid), data() {} + + ~DefaultBluetoothGattDescriptor() override { + delete data.underlying(); + }; + + BluetoothGattCharacteristicPtr getCharacteristic() const { + return characteristic; + }; + + uint16_t getHandle() const override { + return handle; + } + + const Uuid getUuid() const override { + return uuid; + } + + void setValue(const ByteBuffer &buffer) override { + delete[] data.underlying(); + + auto sz = buffer.getSize(); + data = ByteBuffer(new uint8_t[sz], sz); + data.copyFromEntire(buffer); + }; + + ByteBuffer getValue() const override { + return data; + }; + +private: + BluetoothGattCharacteristicPtr characteristic; + uint16_t handle; + Uuid uuid; + ByteBuffer data; +}; + class DefaultBluetoothGattCharacteristic : protected LogSetup, public BluetoothGattCharacteristic { public: DefaultBluetoothGattCharacteristic(const BluetoothGattServicePtr &service, uint16_t handle, Uuid uuid, @@ -62,8 +102,8 @@ public: return uuid; } - uint8_t getProperties() const override { - return properties; + CharacteristicProperties getProperties() const override { + return {properties}; } uint16_t getValueHandle() const override { @@ -71,15 +111,26 @@ public: } shared_ptr<BluetoothGattDescriptor> getDescriptor(Uuid uuid) const override { + for (auto &d: descriptors) { + if (d->getUuid() == uuid) { + return d; + } + } + return {}; } + void addDescriptor(shared_ptr<BluetoothGattDescriptor> &&d) { + descriptors.push_back(std::move(d)); + } + protected: BluetoothGattServicePtr service; uint16_t handle; Uuid uuid; uint8_t properties; uint16_t valueHandle; + vector<BluetoothGattDescriptorPtr> descriptors; }; template<typename DeviceType> |