Call onSubscribe() after adding connection to subscribedVector

This allows for sending BLE messages in the onSubscribe() handler
This commit is contained in:
Bascy 2021-05-19 22:27:32 -06:00 committed by h2zero
parent 9fa9531e50
commit 7815d89dbf

View file

@ -307,7 +307,6 @@ void NimBLECharacteristic::setSubscribe(struct ble_gap_event *event) {
NimBLEDevice::getServer()->clearIndicateWait(event->subscribe.conn_handle); NimBLEDevice::getServer()->clearIndicateWait(event->subscribe.conn_handle);
} }
m_pCallbacks->onSubscribe(this, &desc, subVal);
auto it = m_subscribedVec.begin(); auto it = m_subscribedVec.begin();
for(;it != m_subscribedVec.end(); ++it) { for(;it != m_subscribedVec.end(); ++it) {
@ -319,14 +318,14 @@ void NimBLECharacteristic::setSubscribe(struct ble_gap_event *event) {
if(subVal > 0) { if(subVal > 0) {
if(it == m_subscribedVec.end()) { if(it == m_subscribedVec.end()) {
m_subscribedVec.push_back({event->subscribe.conn_handle, subVal}); m_subscribedVec.push_back({event->subscribe.conn_handle, subVal});
return; } else {
}
(*it).second = subVal; (*it).second = subVal;
}
} else if(it != m_subscribedVec.end()) { } else if(it != m_subscribedVec.end()) {
m_subscribedVec.erase(it); m_subscribedVec.erase(it);
} }
m_pCallbacks->onSubscribe(this, &desc, subVal);
} }