diff --git a/yasmin/include/yasmin/state.hpp b/yasmin/include/yasmin/state.hpp index 80b5ee7..ea0bf80 100644 --- a/yasmin/include/yasmin/state.hpp +++ b/yasmin/include/yasmin/state.hpp @@ -24,6 +24,7 @@ #include #include "yasmin/blackboard/blackboard.hpp" +#include "yasmin/logs.hpp" namespace yasmin { @@ -46,7 +47,10 @@ class State { return ""; } - virtual void cancel_state() { this->canceled.store(true); }; + virtual void cancel_state() { + YASMIN_LOG_INFO("Canceling state '%s'", this->to_string()); + this->canceled.store(true); + }; bool is_canceled() const; std::vector const &get_outcomes(); diff --git a/yasmin/src/yasmin/state_machine.cpp b/yasmin/src/yasmin/state_machine.cpp index 0914fe2..7bf2b9d 100644 --- a/yasmin/src/yasmin/state_machine.cpp +++ b/yasmin/src/yasmin/state_machine.cpp @@ -275,7 +275,7 @@ StateMachine::execute(std::shared_ptr blackboard) { std::string outcome; std::string old_outcome; - while (true) { + while (!this->is_canceled()) { this->current_state_mutex->lock(); diff --git a/yasmin/yasmin/state.py b/yasmin/yasmin/state.py index 742d5b0..68db563 100644 --- a/yasmin/yasmin/state.py +++ b/yasmin/yasmin/state.py @@ -58,6 +58,7 @@ def __str__(self) -> str: return self.__class__.__name__ def cancel_state(self) -> None: + yasmin.YASMIN_LOG_INFO(f"Canceling state '{self}'") self._canceled = True def is_canceled(self) -> bool: diff --git a/yasmin/yasmin/state_machine.py b/yasmin/yasmin/state_machine.py index f514ca4..4fb8727 100644 --- a/yasmin/yasmin/state_machine.py +++ b/yasmin/yasmin/state_machine.py @@ -203,7 +203,7 @@ def execute(self, blackboard: Blackboard) -> str: with self.__current_state_lock: self.__current_state = self._start_state - while True: + while not self.is_canceled(): with self.__current_state_lock: state = self._states[self.__current_state]