Skip to content

Commit

Permalink
logs for cancel state
Browse files Browse the repository at this point in the history
  • Loading branch information
mgonzs13 committed Oct 31, 2024
1 parent a075b80 commit 8440876
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 3 deletions.
6 changes: 5 additions & 1 deletion yasmin/include/yasmin/state.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
#include <cxxabi.h>

#include "yasmin/blackboard/blackboard.hpp"
#include "yasmin/logs.hpp"

namespace yasmin {

Expand All @@ -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<std::string> const &get_outcomes();
Expand Down
2 changes: 1 addition & 1 deletion yasmin/src/yasmin/state_machine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,7 @@ StateMachine::execute(std::shared_ptr<blackboard::Blackboard> blackboard) {
std::string outcome;
std::string old_outcome;

while (true) {
while (!this->is_canceled()) {

this->current_state_mutex->lock();

Expand Down
1 change: 1 addition & 0 deletions yasmin/yasmin/state.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion yasmin/yasmin/state_machine.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down

0 comments on commit 8440876

Please sign in to comment.