18#ifndef NIMBLE_CPP_REMOTE_VALUE_ATTRIBUTE_H_
19#define NIMBLE_CPP_REMOTE_VALUE_ATTRIBUTE_H_
22#if defined(CONFIG_BT_ENABLED) && defined(CONFIG_BT_NIMBLE_ROLE_CENTRAL)
24# if defined(CONFIG_NIMBLE_CPP_IDF)
25# include <host/ble_gatt.h>
27# include <nimble/nimble/host/include/host/ble_gatt.h>
35# include "NimBLEAttribute.h"
36# include "NimBLEAttValue.h"
53 size_t getLength()
const {
return m_value.size(); }
74 bool writeValue(
const uint8_t* data,
size_t length,
bool response =
false)
const;
83 bool writeValue(
const char* str,
size_t length = 0,
bool response =
false)
const {
84 return writeValue(
reinterpret_cast<const uint8_t*
>(str), length ? length : strlen(str), response);
87# if __cplusplus < 201703L
99 typename std::enable_if<!std::is_pointer<T>::value && !Has_c_str_length<T>::value && !Has_data_size<T>::value,
bool>::type
101 writeValue(
const T& v,
bool response =
false)
const {
102 return writeValue(
reinterpret_cast<const uint8_t*
>(&v),
sizeof(T), response);
111 template <
typename T>
115 typename std::enable_if<Has_c_str_length<T>::value && !Has_data_size<T>::value,
bool>::type
117 writeValue(
const T& s,
bool response =
false)
const {
118 return writeValue(
reinterpret_cast<const uint8_t*
>(s.c_str()), s.length(), response);
127 template <
typename T>
131 typename std::enable_if<Has_data_size<T>::value,
bool>::type
133 writeValue(
const T& v,
bool response =
false)
const {
134 return writeValue(
reinterpret_cast<const uint8_t*
>(v.data()), v.size(), response);
144 template <
typename T>
145 typename std::enable_if<!std::is_pointer<T>::value,
bool>::type writeValue(
const T& v,
bool response =
false)
const {
146 if constexpr (Has_data_size<T>::value) {
147 return writeValue(
reinterpret_cast<const uint8_t*
>(v.data()), v.size(), response);
148 }
else if constexpr (Has_c_str_length<T>::value) {
149 return writeValue(
reinterpret_cast<const uint8_t*
>(v.c_str()), v.length(), response);
151 return writeValue(
reinterpret_cast<const uint8_t*
>(&v),
sizeof(v), response);
165 template <
typename T>
166 T getValue(time_t* timestamp =
nullptr,
bool skipSizeCheck =
false)
const {
167 return m_value.getValue<T>(timestamp, skipSizeCheck);
179 template <
typename T>
180 T readValue(time_t* timestamp =
nullptr,
bool skipSizeCheck =
false)
const {
182 return m_value.getValue<T>(timestamp, skipSizeCheck);
194 virtual ~NimBLERemoteValueAttribute() =
default;
196 static int onReadCB(uint16_t conn_handle,
const ble_gatt_error* error, ble_gatt_attr* attr,
void* arg);
197 static int onWriteCB(uint16_t conn_handle,
const ble_gatt_error* error, ble_gatt_attr* attr,
void* arg);
A specialized container class to hold BLE attribute values.
Definition NimBLEAttValue.h:72
A base class for BLE attributes.
Definition NimBLEAttribute.h:29
A model of a BLE client.
Definition NimBLEClient.h:49