diff --git a/src/NimBLEClient.cpp b/src/NimBLEClient.cpp index ee90b27..5d82e91 100644 --- a/src/NimBLEClient.cpp +++ b/src/NimBLEClient.cpp @@ -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, NimBLERemoteService** arg) { - return retrieveServices(u, arg); + NimBLEUtils::getAttr(uuid, &pSvc, m_svcVec, [this](const NimBLEUUID* u, NimBLERemoteService** svc) { + return retrieveServices(u, svc); }); NIMBLE_LOGD(LOG_TAG, "<< getService: %sfound", !pSvc ? "not " : ""); diff --git a/src/NimBLERemoteCharacteristic.cpp b/src/NimBLERemoteCharacteristic.cpp index f3a552c..6b877de 100644 --- a/src/NimBLERemoteCharacteristic.cpp +++ b/src/NimBLERemoteCharacteristic.cpp @@ -27,10 +27,10 @@ # include -struct desc_filter_t { - const NimBLEUUID* uuid; - void* taskData; -}; +typedef struct { + const NimBLEUUID* uuid; + void* taskData; +} desc_filter_t; static const char* LOG_TAG = "NimBLERemoteCharacteristic"; @@ -99,7 +99,7 @@ bool NimBLERemoteCharacteristic::retrieveDescriptors(const NimBLEUUID* uuidFilte NIMBLE_LOGD(LOG_TAG, ">> retrieveDescriptors() for characteristic: %s", getUUID().toString().c_str()); NimBLETaskData taskData(const_cast(this)); - desc_filter_t filter = {uuidFilter, &taskData}; + desc_filter_t filter = {uuidFilter, &taskData}; const uint16_t handle = getHandle(); const uint16_t svcHandle = getRemoteService()->getEndHandle(); @@ -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, NimBLERemoteDescriptor** arg) { - return retrieveDescriptors(u, arg); + NimBLEUtils::getAttr(uuid, &pDsc, m_vDescriptors, [this](const NimBLEUUID* u, NimBLERemoteDescriptor** dsc) { + return retrieveDescriptors(u, dsc); }); NIMBLE_LOGD(LOG_TAG, "<< getDescriptor: %sfound", !pDsc ? "not " : ""); diff --git a/src/NimBLERemoteService.cpp b/src/NimBLERemoteService.cpp index 3ca75ed..a19a346 100644 --- a/src/NimBLERemoteService.cpp +++ b/src/NimBLERemoteService.cpp @@ -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, NimBLERemoteCharacteristic** arg) { - return retrieveCharacteristics(u, arg); + NimBLEUtils::getAttr(uuid, &pChar, m_vChars, [this](const NimBLEUUID* u, NimBLERemoteCharacteristic** chr) { + return retrieveCharacteristics(u, chr); }); NIMBLE_LOGD(LOG_TAG, "<< getCharacteristic: %sfound", !pChar ? "not " : ""); diff --git a/src/NimBLEUtils.cpp b/src/NimBLEUtils.cpp index ec9817f..d5911b0 100644 --- a/src/NimBLEUtils.cpp +++ b/src/NimBLEUtils.cpp @@ -578,6 +578,13 @@ NimBLEAddress NimBLEUtils::generateAddr(bool nrpa) { return NimBLEAddress{addr}; } // generateAddr +/** + * @brief Get an attribute matching a uuid. + * @param [in] uuid Search for this uuid. + * @param [in] attr Pointer to hold result. + * @param [in] vec Vector to search through before trying to get attribute. + * @param [in] getter Attribute getter function to call. + */ template void NimBLEUtils::getAttr(const NimBLEUUID& uuid, T** attr, const std::vector& vec, const std::function& getter) { // Check if already exists. @@ -587,12 +594,10 @@ void NimBLEUtils::getAttr(const NimBLEUUID& uuid, T** attr, const std::vector # include # include @@ -56,9 +56,9 @@ class NimBLEUtils { static NimBLEAddress generateAddr(bool nrpa); static bool taskWait(const NimBLETaskData& taskData, uint32_t timeout); static void taskRelease(const NimBLETaskData& taskData, int rc = 0); - template - static void getAttr(const NimBLEUUID& uuid, T** attr, const std::vector& vec, const std::function& getter); + static void getAttr(const NimBLEUUID& uuid, T** attr, const std::vector& vec, + const std::function& getter); }; #endif // CONFIG_BT_ENABLED