Skip to content

Commit 11e705f

Browse files
committed
Remove recursive calling when fetching remote attributes.
1 parent aeaa432 commit 11e705f

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
@@ -618,15 +618,23 @@ NimBLERemoteService* NimBLEClient::getService(const NimBLEUUID &uuid) {
618618
{
619619
NimBLEUUID uuid128(uuid);
620620
uuid128.to128();
621-
return getService(uuid128);
621+
if(retrieveServices(&uuid128)) {
622+
if(m_servicesVector.size() > prev_size) {
623+
return m_servicesVector.back();
624+
}
625+
}
622626
} else {
623627
// If the request was successful but the 128 bit uuid not found
624628
// try again with the 16 bit uuid.
625629
NimBLEUUID uuid16(uuid);
626630
uuid16.to16();
627631
// if the uuid was 128 bit but not of the BLE base type this check will fail
628632
if (uuid16.bitSize() == BLE_UUID_TYPE_16) {
629-
return getService(uuid16);
633+
if(retrieveServices(&uuid16)) {
634+
if(m_servicesVector.size() > prev_size) {
635+
return m_servicesVector.back();
636+
}
637+
}
630638
}
631639
}
632640
}

src/NimBLERemoteCharacteristic.cpp

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

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)