🆘 Adds helper function

This commit is contained in:
Rune Harlyk
2024-11-23 12:56:54 +01:00
parent 8792c06e8a
commit e109f3584a
@@ -104,10 +104,7 @@ class StatefulService {
beginTransaction(); beginTransaction();
StateUpdateResult result = stateUpdater(_state); StateUpdateResult result = stateUpdater(_state);
endTransaction(); endTransaction();
callHookHandlers(originId, result); notifyStateChange(originId, result);
if (result == StateUpdateResult::CHANGED) {
callUpdateHandlers(originId);
}
return result; return result;
} }
@@ -122,10 +119,7 @@ class StatefulService {
beginTransaction(); beginTransaction();
StateUpdateResult result = stateUpdater(jsonObject, _state); StateUpdateResult result = stateUpdater(jsonObject, _state);
endTransaction(); endTransaction();
callHookHandlers(originId, result); notifyStateChange(originId, result);
if (result == StateUpdateResult::CHANGED) {
callUpdateHandlers(originId);
}
return result; return result;
} }
@@ -168,6 +162,13 @@ class StatefulService {
inline void beginTransaction() { xSemaphoreTakeRecursive(_accessMutex, portMAX_DELAY); } inline void beginTransaction() { xSemaphoreTakeRecursive(_accessMutex, portMAX_DELAY); }
inline void endTransaction() { xSemaphoreGiveRecursive(_accessMutex); } inline void endTransaction() { xSemaphoreGiveRecursive(_accessMutex); }
void notifyStateChange(const String &originId, StateUpdateResult &result) {
callHookHandlers(originId, result);
if (result == StateUpdateResult::CHANGED) {
callUpdateHandlers(originId);
}
}
SemaphoreHandle_t _accessMutex; SemaphoreHandle_t _accessMutex;
std::list<StateUpdateHandlerInfo_t> _updateHandlers; std::list<StateUpdateHandlerInfo_t> _updateHandlers;
std::list<StateHookHandlerInfo_t> _hookHandlers; std::list<StateHookHandlerInfo_t> _hookHandlers;