mirror of
https://github.com/h2zero/esp-nimble-cpp.git
synced 2026-02-06 07:05:05 +01:00
Refactor service changed handling
This makes the services changes notification more accurate by waiting until the changes have taken effect and the server re-started before indicating the change.
This commit is contained in:
@@ -153,13 +153,12 @@ NimBLEAdvertising* NimBLEServer::getAdvertising() const {
|
||||
# endif
|
||||
|
||||
/**
|
||||
* @brief Sends a service changed notification and resets the GATT server.
|
||||
* @brief Called when the services are added/removed and sets a flag to indicate they should be reloaded.
|
||||
* @details This has no effect if the GATT server was not already started.
|
||||
*/
|
||||
void NimBLEServer::serviceChanged() {
|
||||
if (m_gattsStarted) {
|
||||
m_svcChanged = true;
|
||||
ble_svc_gatt_changed(0x0001, 0xffff);
|
||||
resetGATT();
|
||||
}
|
||||
} // serviceChanged
|
||||
|
||||
@@ -205,6 +204,12 @@ void NimBLEServer::start() {
|
||||
}
|
||||
}
|
||||
|
||||
// If the services have changed indicate it now
|
||||
if (m_svcChanged) {
|
||||
m_svcChanged = false;
|
||||
ble_svc_gatt_changed(0x0001, 0xffff);
|
||||
}
|
||||
|
||||
m_gattsStarted = true;
|
||||
} // start
|
||||
|
||||
@@ -876,7 +881,6 @@ void NimBLEServer::resetGATT() {
|
||||
++it;
|
||||
}
|
||||
|
||||
m_svcChanged = false;
|
||||
m_gattsStarted = false;
|
||||
} // resetGATT
|
||||
|
||||
|
||||
Reference in New Issue
Block a user