diff --git a/include/hsmcpp/hsm.hpp b/include/hsmcpp/hsm.hpp index d12d771..9a2d7b3 100644 --- a/include/hsmcpp/hsm.hpp +++ b/include/hsmcpp/hsm.hpp @@ -437,6 +437,15 @@ class HierarchicalStateMachine { */ bool isStateActive(const StateID_t state) const; + /** + * @brief Called whenever a change state occurs. + * @details Overwrite this function to get informed when a new state is activated. + * + * @param state ID of the new state + * + */ + virtual void onStateChanged(const StateID_t state) const { } + /** * @brief Trigger a transition in the HSM. * @details This function sends event to HSM to trigger a potential transition. The transition is executed asynchronously, diff --git a/src/HsmImpl.cpp b/src/HsmImpl.cpp index b00c921..93ca06f 100644 --- a/src/HsmImpl.cpp +++ b/src/HsmImpl.cpp @@ -720,6 +720,8 @@ void HierarchicalStateMachine::Impl::onStateChanged(const StateID_t state, const } else { HSM_TRACE_WARNING("no callback registered for state <%s>", getStateName(state).c_str()); } + // notify parent + if (mParent) mParent->onStateChanged(state); } void HierarchicalStateMachine::Impl::executeStateAction(const StateID_t state, const StateActionTrigger actionTrigger) {