diff options
Diffstat (limited to 'ble/BluetoothImpl.h')
-rw-r--r-- | ble/BluetoothImpl.h | 77 |
1 files changed, 36 insertions, 41 deletions
diff --git a/ble/BluetoothImpl.h b/ble/BluetoothImpl.h index 8663b20..c660b4b 100644 --- a/ble/BluetoothImpl.h +++ b/ble/BluetoothImpl.h @@ -25,14 +25,13 @@ namespace trygvis { namespace bluetooth { // Utility typedefs -typedef boost::uuids::uuid uuid_t; using namespace log4cplus; // Logging class LogSetup { public: - LogSetup(std::string name) : logger(Logger::getInstance(LOG4CPLUS_TEXT(name))) { + explicit LogSetup(const std::string &name) : logger(Logger::getInstance(LOG4CPLUS_TEXT(name))) { } protected: @@ -61,7 +60,7 @@ struct constify2<T *, U const *> { template<typename A, typename B> class CollectionImpl : public Collection<A> { public: - CollectionImpl(B &b) : b(b) { + explicit CollectionImpl(B &b) : b(b) { } private: @@ -70,47 +69,46 @@ private: class DefaultBluetoothGattCharacteristic : protected LogSetup, public BluetoothGattCharacteristic { public: - DefaultBluetoothGattCharacteristic(const BluetoothGattServicePtr &service, uint16_t handle, uuid_t uuid, + DefaultBluetoothGattCharacteristic(const BluetoothGattServicePtr &service, uint16_t handle, Uuid uuid, uint8_t properties, uint16_t valueHandle) - : LogSetup("BluetoothGattCharacteristic"), service(service), handle(handle), uuid(uuid), - properties(properties), valueHandle(valueHandle) { + : LogSetup("BluetoothGattCharacteristic"), service(service), handle(handle), uuid(uuid), + properties(properties), valueHandle(valueHandle) { } - virtual ~DefaultBluetoothGattCharacteristic() { - } + ~DefaultBluetoothGattCharacteristic() override = default; - BluetoothGattServicePtr getService() const { + BluetoothGattServicePtr getService() const override { return service; } - uint16_t getHandle() const { + uint16_t getHandle() const override { return handle; } - const uuid_t getUuid() const { + const Uuid getUuid() const override { return uuid; } - uint8_t getProperties() const { + uint8_t getProperties() const override { return properties; } - uint16_t getValueHandle() const { + uint16_t getValueHandle() const override { return valueHandle; } protected: BluetoothGattServicePtr service; uint16_t handle; - uuid_t uuid; + Uuid uuid; uint8_t properties; uint16_t valueHandle; }; -template<typename DeviceType, typename CharacteristicType> +template<typename DeviceType> class DefaultBluetoothGattService : public BluetoothGattService { public: - DefaultBluetoothGattService(DeviceType &device, const uuid_t uuid, const uint16_t handle, + DefaultBluetoothGattService(DeviceType &device, const Uuid uuid, const uint16_t handle, const uint16_t endGroupHandle) : device(device), uuid(uuid), handle(handle), endGroupHandle(endGroupHandle) { } @@ -122,48 +120,47 @@ public: endGroupHandle(std::move(o.endGroupHandle)), characteristics(std::move(o.characteristics)) { } - virtual ~DefaultBluetoothGattService() { - } + ~DefaultBluetoothGattService() override = default; - virtual BluetoothDevice &getDevice() const { + BluetoothDevice &getDevice() const override { return device; } - virtual uuid_t getUuid() const { + Uuid getUuid() const override { return uuid; } - virtual uint16_t getHandle() const { + uint16_t getHandle() const override { return handle; } - virtual uint16_t getEndGroupHandle() const { + uint16_t getEndGroupHandle() const override { return endGroupHandle; } - virtual vector<shared_ptr<BluetoothGattCharacteristic>> getCharacteristics() const { + vector<shared_ptr<BluetoothGattCharacteristic>> getCharacteristics() const override { vector<shared_ptr<BluetoothGattCharacteristic>> cs(characteristics.size()); std::copy(begin(characteristics), end(characteristics), begin(cs)); return cs; } - virtual void addCharacteristic(shared_ptr<CharacteristicType> &&characteristic) { + virtual void addCharacteristic(shared_ptr<BluetoothGattCharacteristic> &&characteristic) { characteristics.emplace_back(characteristic); } - virtual o<shared_ptr<BluetoothGattCharacteristic>> findCharacteristic(uuid_t uuid) { + o<shared_ptr<BluetoothGattCharacteristic>> findCharacteristic(Uuid uuid) override { for (auto &c: characteristics) { - if (memcmp(c->getUuid().data, uuid.data, 16) == 0) { - return o<shared_ptr<BluetoothGattCharacteristic>>(c); + if (c->getUuid() == uuid) { + return {c}; } } - return o<shared_ptr<BluetoothGattCharacteristic>>(); + return {}; } protected: DeviceType &device; - const uuid_t uuid; + const Uuid uuid; const uint16_t handle; const uint16_t endGroupHandle; vector<shared_ptr<BluetoothGattCharacteristic>> characteristics; @@ -172,7 +169,7 @@ protected: template<class _D, class _S> class DefaultBluetoothGatt : protected LogSetup, public BluetoothGatt { public: - virtual _D &getDevice() const { + _D &getDevice() const override { return device; } @@ -180,15 +177,15 @@ public: // return CollectionImpl<BluetoothGattService, vector<_S>>(services); // } - virtual vector<shared_ptr<BluetoothGattService>> getServices() const { + vector<shared_ptr<BluetoothGattService>> getServices() const override { vector<shared_ptr<BluetoothGattService>> ss(services.size()); std::copy(begin(services), end(services), begin(ss)); return ss; } - virtual o <BluetoothGattServicePtr> findService(uuid_t uuid) { + o <BluetoothGattServicePtr> findService(Uuid uuid) override { for (auto &s: services) { - if (memcmp(s->getUuid().data, uuid.data, 16) == 0) { + if (s->getUuid() == uuid) { return o<shared_ptr<BluetoothGattService>>(s); } } @@ -201,12 +198,10 @@ public: } protected: - DefaultBluetoothGatt(_D &device) : LogSetup("BluetoothGatt"), device(device) { + explicit DefaultBluetoothGatt(_D &device) : LogSetup("BluetoothGatt"), device(device) { } - virtual ~DefaultBluetoothGatt() { -// removeServices(); - } + ~DefaultBluetoothGatt() override = default; void removeServices() { // for (auto s: services) { @@ -223,11 +218,11 @@ template<class A> class DefaultBluetoothDevice : protected LogSetup, public BluetoothDevice { public: - virtual Mac const &getMac() override { + Mac const &getMac() override { return mac; } - virtual A &getAdapter() override { + A &getAdapter() override { return adapter; } @@ -240,7 +235,7 @@ protected: LogSetup("BluetoothDevice"), adapter(std::move(o.adapter)), mac(std::move(o.mac)) { } - virtual ~DefaultBluetoothDevice() { + ~DefaultBluetoothDevice() override { removeServices(); } @@ -259,7 +254,7 @@ protected: class DefaultBluetoothAdapter : protected LogSetup, public BluetoothAdapter { public: protected: - DefaultBluetoothAdapter(Mac &mac) : + explicit DefaultBluetoothAdapter(Mac &mac) : LogSetup("BluetoothAdapter"), mac(mac) { } |