From 2034b1bb10720a2f0e6cc97427346f2320c115bc Mon Sep 17 00:00:00 2001 From: Trygve Laugstøl Date: Fri, 23 Nov 2018 09:40:48 +0100 Subject: o Starting to handle notifications and indications Cleaning up: o Using more of the shared_ptr typedefs. o Adding code styles used by CLion. --- ble/BluetoothImpl.h | 40 +++++++++++++++++----------------------- 1 file changed, 17 insertions(+), 23 deletions(-) (limited to 'ble/BluetoothImpl.h') diff --git a/ble/BluetoothImpl.h b/ble/BluetoothImpl.h index 5b53cd4..c41712c 100644 --- a/ble/BluetoothImpl.h +++ b/ble/BluetoothImpl.h @@ -110,7 +110,7 @@ public: return valueHandle; } - shared_ptr getDescriptor(Uuid uuid) const override { + BluetoothGattDescriptorPtr getDescriptor(Uuid uuid) const override { for (auto &d: descriptors) { if (d->getUuid() == uuid) { return d; @@ -120,7 +120,7 @@ public: return {}; } - void addDescriptor(shared_ptr &&d) { + void addDescriptor(BluetoothGattDescriptorPtr &&d) { descriptors.push_back(std::move(d)); } @@ -166,17 +166,17 @@ public: return endGroupHandle; } - vector> getCharacteristics() const override { - vector> cs(characteristics.size()); + vector getCharacteristics() const override { + vector cs(characteristics.size()); std::copy(begin(characteristics), end(characteristics), begin(cs)); return cs; } - virtual void addCharacteristic(shared_ptr &&characteristic) { + virtual void addCharacteristic(BluetoothGattCharacteristicPtr &&characteristic) { characteristics.emplace_back(characteristic); } - o> findCharacteristic(Uuid uuid) override { + o findCharacteristic(Uuid uuid) override { for (auto &c: characteristics) { if (c->getUuid() == uuid) { return {c}; @@ -191,7 +191,7 @@ protected: const Uuid uuid; const uint16_t handle; const uint16_t endGroupHandle; - vector> characteristics; + vector characteristics; }; template @@ -201,12 +201,8 @@ public: return device; } -// virtual Collection getServices() const { -// return CollectionImpl>(services); -// } - - vector> getServices() const override { - vector> ss(services.size()); + vector getServices() const override { + vector ss(services.size()); std::copy(begin(services), end(services), begin(ss)); return ss; } @@ -214,32 +210,30 @@ public: o findService(Uuid uuid) override { for (auto &s: services) { if (s->getUuid() == uuid) { - return o>(s); + return o(s); } } - return o>(); + return {}; } - void addService(shared_ptr<_S> service) { + void addService(std::shared_ptr<_S> service) { services.emplace_back(service); } protected: - explicit DefaultBluetoothGatt(_D &device) : LogSetup("BluetoothGatt"), device(device) { - } + explicit DefaultBluetoothGatt(_D &device, BluetoothCallback *callback) : + LogSetup("BluetoothGatt"), device(device), callback(callback) {} ~DefaultBluetoothGatt() override = default; void removeServices() { -// for (auto s: services) { -// delete s; -// } services.clear(); } _D &device; - vector> services; + vector > services; + BluetoothCallback *callback; }; template @@ -293,7 +287,7 @@ protected: Mac &mac; }; -shared_ptr getAdapterImpl(string name); +BluetoothAdapterPtr getAdapterImpl(string name); template struct overloaded : Ts... { using Ts::operator()...; }; template overloaded(Ts...) -> overloaded; -- cgit v1.2.3