mirror of
https://github.com/h2zero/esp-nimble-cpp.git
synced 2025-01-22 17:30:50 +01:00
fix: Use double pointer
This commit is contained in:
parent
60b4dc1cfa
commit
05bb0774f3
7 changed files with 28 additions and 26 deletions
|
@ -632,8 +632,8 @@ NimBLERemoteService* NimBLEClient::getService(const NimBLEUUID& uuid) {
|
|||
NIMBLE_LOGD(LOG_TAG, ">> getService: uuid: %s", uuid.toString().c_str());
|
||||
NimBLERemoteService *pSvc = nullptr;
|
||||
|
||||
NimBLEUtils::getAttr(uuid, pSvc, m_svcVec, [this](const NimBLEUUID* u, void* arg) {
|
||||
return retrieveServices(u, static_cast<NimBLERemoteService*>(arg));
|
||||
NimBLEUtils::getAttr<NimBLERemoteService>(uuid, &pSvc, m_svcVec, [this](const NimBLEUUID* u, NimBLERemoteService** arg) {
|
||||
return retrieveServices(u, arg);
|
||||
});
|
||||
|
||||
NIMBLE_LOGD(LOG_TAG, "<< getService: %sfound", !pSvc ? "not " : "");
|
||||
|
@ -690,7 +690,7 @@ bool NimBLEClient::discoverAttributes() {
|
|||
* * Here we ask the server for its set of services and wait until we have received them all.
|
||||
* @return true on success otherwise false if an error occurred
|
||||
*/
|
||||
bool NimBLEClient::retrieveServices(const NimBLEUUID* uuidFilter, NimBLERemoteService *out) {
|
||||
bool NimBLEClient::retrieveServices(const NimBLEUUID* uuidFilter, NimBLERemoteService **out) {
|
||||
if (!isConnected()) {
|
||||
NIMBLE_LOGE(LOG_TAG, "Disconnected, could not retrieve services -aborting");
|
||||
return false;
|
||||
|
@ -719,7 +719,7 @@ bool NimBLEClient::retrieveServices(const NimBLEUUID* uuidFilter, NimBLERemoteSe
|
|||
return false;
|
||||
}
|
||||
|
||||
out = m_svcVec.back();
|
||||
*out = m_svcVec.back();
|
||||
NIMBLE_LOGD(LOG_TAG, "<< retrieveServices(): found %d services.", m_svcVec.size());
|
||||
return true;
|
||||
} // getServices
|
||||
|
|
|
@ -116,10 +116,10 @@ class NimBLEClient {
|
|||
NimBLEClient(const NimBLEClient&) = delete;
|
||||
NimBLEClient& operator=(const NimBLEClient&) = delete;
|
||||
|
||||
bool retrieveServices(const NimBLEUUID* uuidFilter = nullptr);
|
||||
bool retrieveServices(const NimBLEUUID* uuidFilter = nullptr, NimBLERemoteService **out = nullptr);
|
||||
static int handleGapEvent(struct ble_gap_event* event, void* arg);
|
||||
static int exchangeMTUCb(uint16_t conn_handle, const ble_gatt_error* error, uint16_t mtu, void* arg);
|
||||
static int serviceDiscoveredCB(uint16_t connHandle,
|
||||
static int exchangeMTUCB(uint16_t connHandle, const ble_gatt_error* error, uint16_t mtu, void* arg);
|
||||
static int serviceDiscCB(uint16_t connHandle,
|
||||
const struct ble_gatt_error* error,
|
||||
const struct ble_gatt_svc* service,
|
||||
void* arg);
|
||||
|
|
|
@ -95,7 +95,7 @@ int NimBLERemoteCharacteristic::descriptorDiscCB(uint16_t connHandle,
|
|||
* @param [in] filter Structure containing pointers to descriptor, UUID, and task data.
|
||||
* @return True if successfully retrieved, success = BLE_HS_EDONE.
|
||||
*/
|
||||
bool NimBLERemoteCharacteristic::retrieveDescriptors(const NimBLEUUID* uuidFilter, NimBLERemoteDescriptor* out) const {
|
||||
bool NimBLERemoteCharacteristic::retrieveDescriptors(const NimBLEUUID* uuidFilter, NimBLERemoteDescriptor** out) const {
|
||||
NIMBLE_LOGD(LOG_TAG, ">> retrieveDescriptors() for characteristic: %s", getUUID().toString().c_str());
|
||||
|
||||
NimBLETaskData taskData(const_cast<NimBLERemoteCharacteristic*>(this));
|
||||
|
@ -126,7 +126,7 @@ bool NimBLERemoteCharacteristic::retrieveDescriptors(const NimBLEUUID* uuidFilte
|
|||
return false;
|
||||
}
|
||||
|
||||
out = m_vDescriptors.back();
|
||||
*out = m_vDescriptors.back();
|
||||
NIMBLE_LOGD(LOG_TAG, "<< retrieveDescriptors(): found %d descriptors.", m_vDescriptors.size());
|
||||
return true;
|
||||
} // retrieveDescriptors
|
||||
|
@ -140,8 +140,8 @@ NimBLERemoteDescriptor* NimBLERemoteCharacteristic::getDescriptor(const NimBLEUU
|
|||
NIMBLE_LOGD(LOG_TAG, ">> getDescriptor: uuid: %s", uuid.toString().c_str());
|
||||
NimBLERemoteDescriptor* pDsc = nullptr;
|
||||
|
||||
NimBLEUtils::getAttr(uuid, pDsc, m_vDescriptors, [this](const NimBLEUUID* u, void* arg) {
|
||||
return retrieveDescriptors(u, static_cast<NimBLERemoteDescriptor*>(arg));
|
||||
NimBLEUtils::getAttr<NimBLERemoteDescriptor>(uuid, &pDsc, m_vDescriptors, [this](const NimBLEUUID* u, NimBLERemoteDescriptor** arg) {
|
||||
return retrieveDescriptors(u, arg);
|
||||
});
|
||||
|
||||
NIMBLE_LOGD(LOG_TAG, "<< getDescriptor: %sfound", !pDsc ? "not " : "");
|
||||
|
|
|
@ -65,10 +65,11 @@ class NimBLERemoteCharacteristic : public NimBLERemoteValueAttribute {
|
|||
~NimBLERemoteCharacteristic();
|
||||
|
||||
bool setNotify(uint16_t val, notify_callback notifyCallback = nullptr, bool response = true) const;
|
||||
bool retrieveDescriptors(const NimBLEUUID* uuidFilter = nullptr) const;
|
||||
bool retrieveDescriptors(const NimBLEUUID* uuidFilter = nullptr,
|
||||
NimBLERemoteDescriptor** out = nullptr) const;
|
||||
|
||||
static int descriptorDiscCB(
|
||||
uint16_t conn_handle, const ble_gatt_error* error, uint16_t chr_val_handle, const ble_gatt_dsc* dsc, void* arg);
|
||||
uint16_t connHandle, const ble_gatt_error* error, uint16_t chrHandle, const ble_gatt_dsc* dsc, void* arg);
|
||||
|
||||
const NimBLERemoteService* m_pRemoteService{nullptr};
|
||||
uint8_t m_properties{0};
|
||||
|
|
|
@ -78,8 +78,8 @@ NimBLERemoteCharacteristic* NimBLERemoteService::getCharacteristic(const NimBLEU
|
|||
NIMBLE_LOGD(LOG_TAG, ">> getCharacteristic: uuid: %s", uuid.toString().c_str());
|
||||
NimBLERemoteCharacteristic* pChar = nullptr;
|
||||
|
||||
NimBLEUtils::getAttr(uuid, pChar, m_vChars, [this](const NimBLEUUID* u, void* arg) {
|
||||
return retrieveCharacteristics(u, static_cast<NimBLERemoteCharacteristic*>(arg));
|
||||
NimBLEUtils::getAttr<NimBLERemoteCharacteristic>(uuid, &pChar, m_vChars, [this](const NimBLEUUID* u, NimBLERemoteCharacteristic** arg) {
|
||||
return retrieveCharacteristics(u, arg);
|
||||
});
|
||||
|
||||
NIMBLE_LOGD(LOG_TAG, "<< getCharacteristic: %sfound", !pChar ? "not " : "");
|
||||
|
@ -135,7 +135,7 @@ int NimBLERemoteService::characteristicDiscCB(uint16_t connHandle,
|
|||
* This function will not return until we have all the characteristics.
|
||||
* @return True if successfully retrieved, success = BLE_HS_EDONE.
|
||||
*/
|
||||
bool NimBLERemoteService::retrieveCharacteristics(const NimBLEUUID* uuidFilter, NimBLERemoteCharacteristic* out) const {
|
||||
bool NimBLERemoteService::retrieveCharacteristics(const NimBLEUUID* uuidFilter, NimBLERemoteCharacteristic** out) const {
|
||||
NIMBLE_LOGD(LOG_TAG, ">> retrieveCharacteristics()");
|
||||
NimBLETaskData taskData(const_cast<NimBLERemoteService*>(this));
|
||||
int rc = 0;
|
||||
|
@ -167,7 +167,7 @@ bool NimBLERemoteService::retrieveCharacteristics(const NimBLEUUID* uuidFilter,
|
|||
return false;
|
||||
}
|
||||
|
||||
out = m_vChars.back();
|
||||
*out = m_vChars.back();
|
||||
NIMBLE_LOGD(LOG_TAG, "<< retrieveCharacteristics(): found %d characteristics.", m_vChars.size());
|
||||
return true;
|
||||
} // retrieveCharacteristics
|
||||
|
|
|
@ -53,8 +53,9 @@ class NimBLERemoteService : public NimBLEAttribute {
|
|||
|
||||
NimBLERemoteService(NimBLEClient* pClient, const struct ble_gatt_svc* service);
|
||||
~NimBLERemoteService();
|
||||
bool retrieveCharacteristics(const NimBLEUUID* uuidFilter = nullptr) const;
|
||||
static int characteristicDiscCB(uint16_t conn_handle,
|
||||
bool retrieveCharacteristics(const NimBLEUUID* uuidFilter = nullptr,
|
||||
NimBLERemoteCharacteristic** out = nullptr) const;
|
||||
static int characteristicDiscCB(uint16_t connHandle,
|
||||
const struct ble_gatt_error* error,
|
||||
const struct ble_gatt_chr* chr,
|
||||
void* arg);
|
||||
|
|
|
@ -56,18 +56,18 @@ class NimBLEUtils {
|
|||
static bool taskWait(const NimBLETaskData& taskData, uint32_t timeout);
|
||||
static void taskRelease(const NimBLETaskData& taskData, int rc = 0);
|
||||
|
||||
template <typename T, typename S>
|
||||
static void getAttr(const NimBLEUUID& uuid, T* attr, const std::vector<S*>& vec, const std::function<bool(const NimBLEUUID*, void*)>& getter) {
|
||||
template <typename T>
|
||||
static void getAttr(const NimBLEUUID& uuid, T** attr, const std::vector<T*>& vec, const std::function<bool(const NimBLEUUID*, T**)>& getter) {
|
||||
// Check if already exists.
|
||||
for (const auto& v : vec) {
|
||||
if (v->getUUID() == uuid) {
|
||||
attr = v;
|
||||
*attr = v;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// Exit if request failed or uuid was found.
|
||||
if (!getter(&uuid, attr) || attr) {
|
||||
if (!getter(&uuid, attr) || *attr) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue