diff options
Diffstat (limited to 'BluetoothImpl.h')
-rw-r--r-- | BluetoothImpl.h | 88 |
1 files changed, 67 insertions, 21 deletions
diff --git a/BluetoothImpl.h b/BluetoothImpl.h index 0263da5..3fad164 100644 --- a/BluetoothImpl.h +++ b/BluetoothImpl.h @@ -20,52 +20,75 @@ typedef boost::uuids::uuid uuid_t; class DefaultBluetoothGattCharacteristic : public BluetoothGattCharacteristic { public: - DefaultBluetoothGattCharacteristic(BluetoothGattService& service, uuid_t uuid) : service(service), uuid(uuid) { + DefaultBluetoothGattCharacteristic(BluetoothGattService &service, uint16_t handle, uuid_t uuid, uint8_t properties, uint16_t valueHandle) + : service(service), handle(handle), uuid(uuid), properties(properties), valueHandle(valueHandle) { } virtual ~DefaultBluetoothGattCharacteristic() { } + BluetoothGattService &getService() const { + return service; + } + + uint16_t getHandle() const { + return handle; + } + const uuid_t getUuid() const { return uuid; - }; + } - BluetoothGattService& getService() const { - return service; - }; + uint8_t getProperties() const { + return properties; + } + + uint16_t getValueHandle() const { + return valueHandle; + } protected: - BluetoothGattService& service; + BluetoothGattService &service; + uint16_t handle; uuid_t uuid; + uint8_t properties; + uint16_t valueHandle; }; class DefaultBluetoothGattService : public BluetoothGattService { public: - DefaultBluetoothGattService(BluetoothDevice& device, const uuid_t uuid, const uint16_t handle, const uint16_t endGroupHandle) : - device(device), uuid(uuid), handle(handle), endGroupHandle(endGroupHandle) { + DefaultBluetoothGattService(BluetoothDevice &device, const uuid_t uuid, const uint16_t handle, const uint16_t endGroupHandle) + : device(device), uuid(uuid), handle(handle), endGroupHandle(endGroupHandle) { + DF; } virtual ~DefaultBluetoothGattService() { + DF; + removeCharacteristics(); } - BluetoothDevice& getDevice() const { + virtual BluetoothDevice &getDevice() const { return device; } - uuid_t getUuid() const { + virtual uuid_t getUuid() const { return uuid; } - uint16_t getHandle() const { - return handle; + virtual uint16_t getHandle() const { + return handle; } - uint16_t getEndGroupHandle() const { - return endGroupHandle; - } + virtual uint16_t getEndGroupHandle() const { + return endGroupHandle; + } + + virtual const vector<BluetoothGattCharacteristic *> getCharacteristics() const { + return characteristics; + } - vector<BluetoothGattCharacteristic* >::const_iterator getCharacteristics() const { - return characteristics.begin(); + virtual void addCharacteristic(BluetoothGattCharacteristic *characteristic) { + characteristics.push_back(characteristic); } protected: @@ -73,22 +96,45 @@ protected: const uuid_t uuid; const uint16_t handle; const uint16_t endGroupHandle; - const vector<BluetoothGattCharacteristic*> characteristics; + vector<BluetoothGattCharacteristic *> characteristics; + + void removeCharacteristics() { + DF; + for (auto &c: characteristics) { + delete c; + } + characteristics.clear(); + } }; class DefaultBluetoothDevice : public BluetoothDevice { public: - virtual vector<BluetoothGattService*>::const_iterator getServices() const { - return services.begin(); + virtual const vector<BluetoothGattService *> getServices() const { + return services; }; + virtual void addService(BluetoothGattService *service) { + services.push_back(service); + } + protected: + DefaultBluetoothDevice() { + DF; + } + virtual ~DefaultBluetoothDevice() { + DF; + removeServices(); + } + + void removeServices() { for (auto s: services) { delete s; } + services.clear(); } - vector<BluetoothGattService*> services; + + vector<BluetoothGattService *> services; }; BluetoothAdapter &getAdapterImpl(int hciDevice); |