forked from h2zero/esp-nimble-cpp
Refactor attributes to reduce code duplication and improve maintainability. * Add attribute base classes to provide common code. * Add const where possible to functions and parameters. * `NimBLECharacteristic::notify` no longer takes a `bool is_notification` parameter, instead `indicate()` should be called to send indications. * `NimBLECharacteristic::indicate` now takes the same parameters as `notify`. * `NimBLECharacteristicCallbacks` and `NimBLEDescriptorCallbacks` methods now take `const NimBLEConnInfo&` instead of non-const. * `NimBLECharacteristic::onNotify` callback removed as unnecessary, the library does not call notify without app input. * `NimBLERemoteCharacteristic::getRemoteService` now returns a `const NimBLERemoteService*` instead of non-const. * Add NimBLEUUID constructor that takes a reference to `ble_uuid_any_t`. * `NimBLERemoteService::getCharacteristics` now returns a `const std::vector<NimBLERemoteCharacteristic*>&` instead of non-const `std::vector<NimBLERemoteCharacteristic*>*` * `NimBLERemoteService::getValue` now returns `NimBLEAttValue` instead of `std::string` * `NimBLEService::getCharacteristics` now returns a `const std::vector<NimBLECharacteristic*>&` instead of a copy of std::vector<NimBLECharacteristic *>. * Remove const requirement for NimBLEConnInfo parameter in callbacks. Const is unnecessary as the data can't be changed by application code. * Change NimBLERemoteCharacteristic::getRemoteService to return const pointer.
49 lines
1.1 KiB
C++
49 lines
1.1 KiB
C++
/*
|
|
* NimBLELocalAttribute.cpp
|
|
*
|
|
* Created: on July 28 2024
|
|
* Author H2zero
|
|
*/
|
|
|
|
#ifndef NIMBLE_CPP_LOCAL_ATTRIBUTE_H_
|
|
#define NIMBLE_CPP_LOCAL_ATTRIBUTE_H_
|
|
|
|
#include "nimconfig.h"
|
|
#if defined(CONFIG_BT_ENABLED) && defined(CONFIG_BT_NIMBLE_ROLE_PERIPHERAL)
|
|
|
|
# include "NimBLEAttribute.h"
|
|
|
|
/**
|
|
* @brief A base class for local BLE attributes.
|
|
*/
|
|
class NimBLELocalAttribute : public NimBLEAttribute {
|
|
public:
|
|
/**
|
|
* @brief Get the removed flag.
|
|
* @return The removed flag.
|
|
*/
|
|
uint8_t getRemoved() const { return m_removed; }
|
|
|
|
protected:
|
|
/**
|
|
* @brief Construct a local attribute.
|
|
*/
|
|
NimBLELocalAttribute(const NimBLEUUID& uuid, uint16_t handle) : NimBLEAttribute{uuid, handle}, m_removed{0} {}
|
|
|
|
/**
|
|
* @brief Destroy the local attribute.
|
|
*/
|
|
~NimBLELocalAttribute() = default;
|
|
|
|
/**
|
|
* @brief Set the removed flag.
|
|
* @param [in] removed The removed flag.
|
|
*/
|
|
void setRemoved(uint8_t removed) { m_removed = removed; }
|
|
|
|
uint8_t m_removed{0};
|
|
};
|
|
|
|
#endif // CONFIG_BT_ENABLED && CONFIG_BT_NIMBLE_ROLE_PERIPHERAL
|
|
#endif // NIMBLE_CPP_LOCAL_ATTRIBUTE_H_
|