Skip to content

Commit 658339b

Browse files
authored
Remove recursive calling when fetching remote attributes. (h2zero#355)
1 parent 4bb3930 commit 658339b

File tree

3 files changed

+30
-6
lines changed

3 files changed

+30
-6
lines changed

src/NimBLEClient.cpp

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -620,15 +620,23 @@ NimBLERemoteService* NimBLEClient::getService(const NimBLEUUID &uuid) {
620620
{
621621
NimBLEUUID uuid128(uuid);
622622
uuid128.to128();
623-
return getService(uuid128);
623+
if(retrieveServices(&uuid128)) {
624+
if(m_servicesVector.size() > prev_size) {
625+
return m_servicesVector.back();
626+
}
627+
}
624628
} else {
625629
// If the request was successful but the 128 bit uuid not found
626630
// try again with the 16 bit uuid.
627631
NimBLEUUID uuid16(uuid);
628632
uuid16.to16();
629633
// if the uuid was 128 bit but not of the BLE base type this check will fail
630634
if (uuid16.bitSize() == BLE_UUID_TYPE_16) {
631-
return getService(uuid16);
635+
if(retrieveServices(&uuid16)) {
636+
if(m_servicesVector.size() > prev_size) {
637+
return m_servicesVector.back();
638+
}
639+
}
632640
}
633641
}
634642
}

src/NimBLERemoteCharacteristic.cpp

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -323,15 +323,23 @@ NimBLERemoteDescriptor* NimBLERemoteCharacteristic::getDescriptor(const NimBLEUU
323323
{
324324
NimBLEUUID uuid128(uuid);
325325
uuid128.to128();
326-
return getDescriptor(uuid128);
326+
if(retrieveDescriptors(&uuid128)) {
327+
if(m_descriptorVector.size() > prev_size) {
328+
return m_descriptorVector.back();
329+
}
330+
}
327331
} else {
328332
// If the request was successful but the 128 bit uuid not found
329333
// try again with the 16 bit uuid.
330334
NimBLEUUID uuid16(uuid);
331335
uuid16.to16();
332336
// if the uuid was 128 bit but not of the BLE base type this check will fail
333337
if (uuid16.bitSize() == BLE_UUID_TYPE_16) {
334-
return getDescriptor(uuid16);
338+
if(retrieveDescriptors(&uuid16)) {
339+
if(m_descriptorVector.size() > prev_size) {
340+
return m_descriptorVector.back();
341+
}
342+
}
335343
}
336344
}
337345
}

src/NimBLERemoteService.cpp

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,15 +116,23 @@ NimBLERemoteCharacteristic* NimBLERemoteService::getCharacteristic(const NimBLEU
116116
{
117117
NimBLEUUID uuid128(uuid);
118118
uuid128.to128();
119-
return getCharacteristic(uuid128);
119+
if (retrieveCharacteristics(&uuid128)) {
120+
if(m_characteristicVector.size() > prev_size) {
121+
return m_characteristicVector.back();
122+
}
123+
}
120124
} else {
121125
// If the request was successful but the 128 bit uuid not found
122126
// try again with the 16 bit uuid.
123127
NimBLEUUID uuid16(uuid);
124128
uuid16.to16();
125129
// if the uuid was 128 bit but not of the BLE base type this check will fail
126130
if (uuid16.bitSize() == BLE_UUID_TYPE_16) {
127-
return getCharacteristic(uuid16);
131+
if(retrieveCharacteristics(&uuid16)) {
132+
if(m_characteristicVector.size() > prev_size) {
133+
return m_characteristicVector.back();
134+
}
135+
}
128136
}
129137
}
130138
}

0 commit comments

Comments
 (0)