23using namespace std::chrono_literals;
29 RCLCPP_INFO_STREAM(
getLogger(),
"[" <<
getName() <<
"] asynchronous onEntry thread started");
36 RCLCPP_INFO_STREAM(
getLogger(),
"[" <<
getName() <<
"] asynchronous onEntry thread finished");
42 std::optional<std::future<int>> & threadfut,
bool requestFinish)
49 if (threadfut && threadfut->valid())
51 auto status = threadfut->wait_for(std::chrono::milliseconds(20));
52 if (status == std::future_status::ready)
64 <<
"] fut valid but waiting for asynchronous onEntry thread to finish: state: "
73 <<
"] waiting future onEntryThread. It was not even created. Skipping wait.");
76 rclcpp::sleep_for(100ms);
79 "[%s] waiting for finishing client behavior, before leaving the state. Is the client "
80 "behavior stuck? requesting force finish",
86 catch (
const std::exception & e)
90 "[SmaccAsyncClientBehavior] trying to join function, but it was already finished.");
101 RCLCPP_INFO_STREAM(
getLogger(),
"[" <<
getName() <<
"] onExit - join async onEntry thread");
105 getLogger(),
"[" <<
getName() <<
"] onExit - Creating asynchronous onExit thread");
111 RCLCPP_INFO_STREAM(
getLogger(),
"[" <<
getName() <<
"] asynchronous onExit done.");
120 <<
"] Destroying client behavior- Waiting finishing of asynchronous onExit "
133 "[SmaccAsyncClientBehavior] trying to Join onExit function, but it was already "
139 <<
"] Destroying client behavior- onExit thread finished. Proccedding "
151 RCLCPP_FATAL_STREAM_THROTTLE(
153 "[" <<
getName() <<
"] " << ((uint64_t)
this) <<
" requestForceFinish");
159 std::string shut =
"";
std::string getName() const
virtual rclcpp::Logger getLogger() const
virtual rclcpp::Node::SharedPtr getNode() const
virtual ~SmaccAsyncClientBehavior()
bool isShutdownRequested_
std::function< void()> postSuccessEventFn_
std::function< void()> postFinishEventFn_
void executeOnEntry() override
bool isShutdownRequested()
onEntry is executed in a new thread. However the current state cannot be left until the onEntry threa...
virtual void dispose() override
std::optional< std::future< int > > onExitThread_
std::optional< std::future< int > > onEntryThread_
void waitFutureIfNotFinished(std::optional< std::future< int > > &threadfut, bool requestFinish)
void requestForceFinish()
void executeOnExit() override
std::function< void()> postFailureEventFn_
void waitOnEntryThread(bool requestFinish)