🆘 Adds helper function
This commit is contained in:
@@ -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;
|
||||||
|
|||||||
Reference in New Issue
Block a user