SMACC2
Loading...
Searching...
No Matches
smacc2::SmaccAsyncClientBehavior Class Reference

#include <smacc_asynchronous_client_behavior.hpp>

Inheritance diagram for smacc2::SmaccAsyncClientBehavior:
Inheritance graph
Collaboration diagram for smacc2::SmaccAsyncClientBehavior:
Collaboration graph

Public Member Functions

template<typename TOrthogonal , typename TSourceObject >
void onStateOrthogonalAllocation ()
 
 SmaccAsyncClientBehavior ()=default
 
 ~SmaccAsyncClientBehavior () override
 
 SmaccAsyncClientBehavior (const SmaccAsyncClientBehavior &)=delete
 
SmaccAsyncClientBehavior & operator= (const SmaccAsyncClientBehavior &)=delete
 
 SmaccAsyncClientBehavior (SmaccAsyncClientBehavior &&)=delete
 
SmaccAsyncClientBehavior & operator= (SmaccAsyncClientBehavior &&)=delete
 
template<typename TCallback , typename T >
smacc2::SmaccSignalConnection onSuccess (TCallback callback, T *object)
 
template<typename TCallback , typename T >
smacc2::SmaccSignalConnection onFinished (TCallback callback, T *object)
 
template<typename TCallback , typename T >
smacc2::SmaccSignalConnection onFailure (TCallback callback, T *object)
 
void requestForceFinish ()
 
void executeOnEntry () override
 
void executeOnExit () override
 
void waitOnEntryThread (bool requestFinish)
 
template<typename TCallbackMethod , typename T >
smacc2::SmaccSignalConnection onSuccess (TCallbackMethod callback, T *object)
 
template<typename TCallbackMethod , typename T >
smacc2::SmaccSignalConnection onFinished (TCallbackMethod callback, T *object)
 
template<typename TCallbackMethod , typename T >
smacc2::SmaccSignalConnection onFailure (TCallbackMethod callback, T *object)
 
- Public Member Functions inherited from smacc2::ISmaccClientBehavior
 ISmaccClientBehavior ()
 
virtual ~ISmaccClientBehavior ()
 
 ISmaccClientBehavior (const ISmaccClientBehavior &)=delete
 
ISmaccClientBehavior & operator= (const ISmaccClientBehavior &)=delete
 
 ISmaccClientBehavior (ISmaccClientBehavior &&)=delete
 
ISmaccClientBehavior & operator= (ISmaccClientBehavior &&)=delete
 
ISmaccStateMachine * getStateMachine ()
 
std::string getName () const
 
template<typename SmaccClientType >
void requiresClient (SmaccClientType *&storage)
 
template<typename SmaccComponentType >
void requiresComponent (SmaccComponentType *&storage, ComponentRequirement requirementType=ComponentRequirement::SOFT)
 
template<typename SmaccComponentType >
void requiresComponent (const std::string &name, SmaccComponentType *&storage, ComponentRequirement requirementType=ComponentRequirement::SOFT)
 
virtual void onEntry ()
 
virtual void onExit ()
 

Protected Member Functions

void postSuccessEvent ()
 
void postFailureEvent ()
 
void dispose () override
 
bool isShutdownRequested ()
 onEntry is executed in a new thread. However the current state cannot be left until the onEntry thread finishes. This flag can be checked from the onEntry thread to force finishing the thread.
 
- Protected Member Functions inherited from smacc2::ISmaccClientBehavior
virtual void runtimeConfigure ()
 
template<typename EventType >
void postEvent (const EventType &ev)
 
template<typename EventType >
void postEvent ()
 
ISmaccState * getCurrentState ()
 
void postInitializationFailureEvent (const std::string &what)
 
virtual rclcpp::Node::SharedPtr getNode () const
 
virtual rclcpp::Logger getLogger () const
 
std::string getTraceStateName () const
 
std::string getTraceOrthogonalName () const
 

Private Member Functions

void waitFutureIfNotFinished (std::optional< std::future< int > > &threadfut, bool requestFinish)
 

Private Attributes

std::optional< std::future< int > > onEntryThread_
 
std::optional< std::future< int > > onExitThread_
 
std::function< void()> postFinishEventFn_
 
std::function< void()> postSuccessEventFn_
 
std::function< void()> postFailureEventFn_
 
SmaccSignal< void()> onFinished_
 
SmaccSignal< void()> onSuccess_
 
SmaccSignal< void()> onFailure_
 
std::atomic< bool > isShutdownRequested_ {false}
 

Detailed Description

Definition at line 56 of file smacc_asynchronous_client_behavior.hpp.

Constructor & Destructor Documentation

◆ SmaccAsyncClientBehavior() [1/3]

smacc2::SmaccAsyncClientBehavior::SmaccAsyncClientBehavior ( )
default

◆ ~SmaccAsyncClientBehavior()

smacc2::SmaccAsyncClientBehavior::~SmaccAsyncClientBehavior ( )
override

Definition at line 242 of file smacc_client_async_behavior.cpp.

243{
244 // Last line of defense: every release path joins the threads first; if one is missed, join here
245 // before the members the thread uses are destroyed, rather than let ~future block after them.
246 if (this->onEntryThread_ && this->onEntryThread_->valid())
247 {
248 RCLCPP_ERROR_STREAM(
249 getLogger(), "[" << getName() << "] destroyed with a live onEntry thread; joining it");
250 this->waitOnEntryThread(true);
251 }
252 if (this->onExitThread_ && this->onExitThread_->valid())
253 {
254 RCLCPP_ERROR_STREAM(
255 getLogger(), "[" << getName() << "] destroyed with a live onExit thread; joining it");
256 try
257 {
258 this->onExitThread_->get();
259 }
260 catch (const std::exception & e)
261 {
262 RCLCPP_ERROR_STREAM(getLogger(), "[" << getName() << "] onExit thread threw: " << e.what());
263 }
264 catch (...)
265 {
266 RCLCPP_ERROR_STREAM(
267 getLogger(), "[" << getName() << "] onExit thread threw a non-standard exception");
268 }
269 }
270}
virtual rclcpp::Logger getLogger() const
std::optional< std::future< int > > onExitThread_
std::optional< std::future< int > > onEntryThread_

References smacc2::ISmaccClientBehavior::getLogger(), smacc2::ISmaccClientBehavior::getName(), onEntryThread_, onExitThread_, and waitOnEntryThread().

Here is the call graph for this function:

◆ SmaccAsyncClientBehavior() [2/3]

smacc2::SmaccAsyncClientBehavior::SmaccAsyncClientBehavior ( const SmaccAsyncClientBehavior & )
delete

◆ SmaccAsyncClientBehavior() [3/3]

smacc2::SmaccAsyncClientBehavior::SmaccAsyncClientBehavior ( SmaccAsyncClientBehavior && )
delete

Member Function Documentation

◆ dispose()

void smacc2::SmaccAsyncClientBehavior::dispose ( )
overrideprotectedvirtual

Reimplemented from smacc2::ISmaccClientBehavior.

Definition at line 211 of file smacc_client_async_behavior.cpp.

212{
213 RCLCPP_DEBUG_STREAM(
214 getLogger(), "[" << getName()
215 << "] Destroying client behavior- Waiting finishing of asynchronous onExit "
216 "thread");
217 try
218 {
219 if (this->onExitThread_)
220 {
221 this->onExitThread_->get();
222 }
223 }
224 catch (const std::exception & e)
225 {
226 logThreadException(getLogger(), getName(), "onExit", e.what());
227 }
228 catch (...)
229 {
230 logThreadException(getLogger(), getName(), "onExit", "non-standard exception");
231 }
232
233 // Backstop: no behavior may be released with its onEntry thread live.
234 this->waitOnEntryThread(true);
235
236 RCLCPP_DEBUG_STREAM(
237 getLogger(), "[" << getName()
238 << "] Destroying client behavior- onExit thread finished. Proccedding "
239 "destruction.");
240}
static void logThreadException(const rclcpp::Logger &logger, const std::string &name, const char *thread, const char *what)

References smacc2::ISmaccClientBehavior::getLogger(), smacc2::ISmaccClientBehavior::getName(), smacc2::logThreadException(), onExitThread_, and waitOnEntryThread().

Here is the call graph for this function:

◆ executeOnEntry()

void smacc2::SmaccAsyncClientBehavior::executeOnEntry ( )
overridevirtual

Reimplemented from smacc2::ISmaccClientBehavior.

Definition at line 90 of file smacc_client_async_behavior.cpp.

91{
92 RCLCPP_INFO_STREAM(getLogger(), "[" << getName() << "] asynchronous onEntry thread started");
93 // Copied here, on the state machine thread: the behavior's thread must not ask an exiting state.
94 const AsyncTraceNames names{getTraceStateName(), getTraceOrthogonalName(), getName()};
95 this->onEntryThread_ = std::async(
96 std::launch::async,
97 [this, names]
98 {
99 // An exception is reported when it happens, not when the state exits and joins this thread.
100 try
101 {
102 AsyncTraceScope trace(true, names);
103 this->onEntry();
104 }
105 catch (const std::exception & e)
106 {
107 logThreadException(getLogger(), getName(), "onEntry", e.what());
108 if (rclcpp::ok()) this->postInitializationFailureEvent(e.what());
109 return 0;
110 }
111 catch (...)
112 {
113 logThreadException(getLogger(), getName(), "onEntry", "non-standard exception");
114 if (rclcpp::ok()) this->postInitializationFailureEvent("non-standard exception");
115 return 0;
116 }
117 this->postFinishEventFn_();
118 RCLCPP_INFO_STREAM(getLogger(), "[" << getName() << "] asynchronous onEntry thread finished");
119 return 0;
120 });
121}
void postInitializationFailureEvent(const std::string &what)

References smacc2::ISmaccClientBehavior::getLogger(), smacc2::ISmaccClientBehavior::getName(), smacc2::ISmaccClientBehavior::getTraceOrthogonalName(), smacc2::ISmaccClientBehavior::getTraceStateName(), smacc2::logThreadException(), smacc2::ISmaccClientBehavior::onEntry(), onEntryThread_, postFinishEventFn_, and smacc2::ISmaccClientBehavior::postInitializationFailureEvent().

Here is the call graph for this function:

◆ executeOnExit()

void smacc2::SmaccAsyncClientBehavior::executeOnExit ( )
overridevirtual

Reimplemented from smacc2::ISmaccClientBehavior.

Definition at line 190 of file smacc_client_async_behavior.cpp.

191{
192 RCLCPP_INFO_STREAM(getLogger(), "[" << getName() << "] onExit - join async onEntry thread");
193 this->waitOnEntryThread(true);
194
195 RCLCPP_INFO_STREAM(
196 getLogger(), "[" << getName() << "] onExit - Creating asynchronous onExit thread");
197 const AsyncTraceNames names{getTraceStateName(), getTraceOrthogonalName(), getName()};
198 this->onExitThread_ = std::async(
199 std::launch::async,
200 [this, names]
201 {
202 {
203 AsyncTraceScope trace(false, names);
204 this->onExit();
205 }
206 RCLCPP_INFO_STREAM(getLogger(), "[" << getName() << "] asynchronous onExit done.");
207 return 0;
208 });
209}

References smacc2::ISmaccClientBehavior::getLogger(), smacc2::ISmaccClientBehavior::getName(), smacc2::ISmaccClientBehavior::getTraceOrthogonalName(), smacc2::ISmaccClientBehavior::getTraceStateName(), smacc2::ISmaccClientBehavior::onExit(), onExitThread_, and waitOnEntryThread().

Here is the call graph for this function:

◆ isShutdownRequested()

bool smacc2::SmaccAsyncClientBehavior::isShutdownRequested ( )
protected

onEntry is executed in a new thread. However the current state cannot be left until the onEntry thread finishes. This flag can be checked from the onEntry thread to force finishing the thread.

Definition at line 284 of file smacc_client_async_behavior.cpp.

References isShutdownRequested_.

Referenced by cl_gcalcli::CbWaitConnection::onEntry(), cl_lifecycle_node::CbActivate::onEntry(), cl_lifecycle_node::CbCleanup::onEntry(), cl_lifecycle_node::CbConfigure::onEntry(), cl_lifecycle_node::CbDeactivate::onEntry(), cl_lifecycle_node::CbShutdown::onEntry(), cl_nav2z::CbAbortNavigation::onEntry(), cl_nav2z::CbActiveStop::onEntry(), cl_nav2z::CbPositionControlFreeSpace::onEntry(), cl_nav2z::CbPureSpinning::onEntry(), cl_px4_mr::CbConnectMicroRosAgent::onEntry(), cl_px4_mr::CbWaitForHeadingStable::onEntry(), cl_rgb::CbSurveyTable::onEntry(), smacc2::client_behaviors::CbRosLaunch2::onEntry(), smacc2::client_behaviors::CbSequence::onEntry(), smacc2::client_behaviors::CbServiceCall< ServiceType >::onEntry(), smacc2::client_behaviors::CbSleepFor::onEntry(), smacc2::client_behaviors::CbWaitActionServer2< ActionT >::onEntry(), smacc2::client_behaviors::CbWaitActionServer::onEntry(), smacc2::client_behaviors::CbWaitNode::onEntry(), smacc2::client_behaviors::CbWaitTopic::onEntry(), cl_lifecycle_node::CbDeactivateOnExit::onExit(), smacc2::client_behaviors::CbSequence::recursiveConsumeNext(), and smacc2::client_behavior_bases::CbActionClientBehaviorBase< TAction >::trackGoal().

Here is the caller graph for this function:

◆ onFailure() [1/2]

template<typename TCallback , typename T >
smacc2::SmaccSignalConnection smacc2::SmaccAsyncClientBehavior::onFailure ( TCallback callback,
T * object )

◆ onFailure() [2/2]

template<typename TCallbackMethod , typename T >
smacc2::SmaccSignalConnection smacc2::SmaccAsyncClientBehavior::onFailure ( TCallbackMethod callback,
T * object )

Definition at line 77 of file smacc_asynchronous_client_behavior_impl.hpp.

79{
80 return this->getStateMachine()->createSignalConnection(onFailure_, callback, object);
81}
smacc2::SmaccSignalConnection createSignalConnection(TSmaccSignal &signal, TMemberFunctionPrototype callback, TSmaccObjectType *object)

References smacc2::ISmaccStateMachine::createSignalConnection(), smacc2::ISmaccClientBehavior::getStateMachine(), and onFailure_.

Here is the call graph for this function:

◆ onFinished() [1/2]

template<typename TCallback , typename T >
smacc2::SmaccSignalConnection smacc2::SmaccAsyncClientBehavior::onFinished ( TCallback callback,
T * object )

◆ onFinished() [2/2]

template<typename TCallbackMethod , typename T >
smacc2::SmaccSignalConnection smacc2::SmaccAsyncClientBehavior::onFinished ( TCallbackMethod callback,
T * object )

◆ onStateOrthogonalAllocation()

template<typename TOrthogonal , typename TSourceObject >
void smacc2::SmaccAsyncClientBehavior::onStateOrthogonalAllocation ( )

Definition at line 29 of file smacc_asynchronous_client_behavior_impl.hpp.

30{
32 {
33 RCLCPP_WARN(
34 getLogger(),
35 "SmaccAsyncClientBehavior already has event posting functions assigned. Skipping "
36 "re-assignment. This could be a problem if you are using the same behavior in multiple "
37 "states. This may be related with the deprecation of onStateOrthogonalAllocation in favor of "
38 "onStateOrthogonalAllocation.");
39
40 return;
41 }
42
43 postFinishEventFn_ = [this]
44 {
45 this->onFinished_();
47 };
48
49 postSuccessEventFn_ = [this]
50 {
51 this->onSuccess_();
53 };
54
55 postFailureEventFn_ = [this]
56 {
57 this->onFailure_();
59 };
60}

References smacc2::ISmaccClientBehavior::getLogger(), onFailure_, onFinished_, onSuccess_, smacc2::ISmaccClientBehavior::postEvent(), postFailureEventFn_, postFinishEventFn_, and postSuccessEventFn_.

Referenced by cl_lifecycle_node::CbActivate::onStateOrthogonalAllocation(), cl_lifecycle_node::CbCleanup::onStateOrthogonalAllocation(), cl_lifecycle_node::CbConfigure::onStateOrthogonalAllocation(), cl_lifecycle_node::CbDeactivate::onStateOrthogonalAllocation(), cl_lifecycle_node::CbDeactivateOnExit::onStateOrthogonalAllocation(), cl_lifecycle_node::CbShutdown::onStateOrthogonalAllocation(), cl_mission_tracker::CbBatteryDecission::onStateOrthogonalAllocation(), cl_modbus_tcp_relay::CbAllRelaysOff::onStateOrthogonalAllocation(), cl_modbus_tcp_relay::CbAllRelaysOn::onStateOrthogonalAllocation(), cl_modbus_tcp_relay::CbRelayOff::onStateOrthogonalAllocation(), cl_modbus_tcp_relay::CbRelayOn::onStateOrthogonalAllocation(), cl_modbus_tcp_relay::CbRelayStatus::onStateOrthogonalAllocation(), cl_moveit2z::CbMoveit2zClientBehaviorBase::onStateOrthogonalAllocation(), cl_nav2z::CbAbortNavigation::onStateOrthogonalAllocation(), cl_nav2z::CbNavigateNextWaypointUntilReached::onStateOrthogonalAllocation(), cl_nav2z::CbWaitPose::onStateOrthogonalAllocation(), cl_nav2z::CbWaitTransform::onStateOrthogonalAllocation(), cl_px4_mr::CbPx4ClientBehaviorBase::onStateOrthogonalAllocation(), cl_rgb::CbRgbClientBehaviorBase::onStateOrthogonalAllocation(), smacc2::client_behavior_bases::CbActionClientBehaviorBase< TAction >::onStateOrthogonalAllocation(), smacc2::client_behaviors::CbRosLaunch2::onStateOrthogonalAllocation(), smacc2::client_behaviors::CbRosStop2::onStateOrthogonalAllocation(), smacc2::client_behaviors::CbWaitActionServer2< ActionT >::onStateOrthogonalAllocation(), smacc2::client_behaviors::CbWaitActionServer::onStateOrthogonalAllocation(), and smacc2::client_behaviors::CbSequence::then().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ onSuccess() [1/2]

template<typename TCallback , typename T >
smacc2::SmaccSignalConnection smacc2::SmaccAsyncClientBehavior::onSuccess ( TCallback callback,
T * object )

Referenced by cl_nav2z::CbNavigateNextWaypointFree::onEntry().

Here is the caller graph for this function:

◆ onSuccess() [2/2]

template<typename TCallbackMethod , typename T >
smacc2::SmaccSignalConnection smacc2::SmaccAsyncClientBehavior::onSuccess ( TCallbackMethod callback,
T * object )

Definition at line 63 of file smacc_asynchronous_client_behavior_impl.hpp.

65{
66 return this->getStateMachine()->createSignalConnection(onSuccess_, callback, object);
67}

References smacc2::ISmaccStateMachine::createSignalConnection(), smacc2::ISmaccClientBehavior::getStateMachine(), and onSuccess_.

Here is the call graph for this function:

◆ operator=() [1/2]

SmaccAsyncClientBehavior & smacc2::SmaccAsyncClientBehavior::operator= ( const SmaccAsyncClientBehavior & )
delete

◆ operator=() [2/2]

SmaccAsyncClientBehavior & smacc2::SmaccAsyncClientBehavior::operator= ( SmaccAsyncClientBehavior && )
delete

◆ postFailureEvent()

void smacc2::SmaccAsyncClientBehavior::postFailureEvent ( )
protected

Definition at line 274 of file smacc_client_async_behavior.cpp.

References postFailureEventFn_.

Referenced by cl_moveit2z::CbMoveEndEffectorTrajectory::executeJointSpaceTrajectory(), smacc2::client_behavior_bases::CbActionClientBehaviorBase< TAction >::onActionAbort(), cl_gcalcli::CbDetectCalendarEvent::onEntry(), cl_gcalcli::CbEventDetect::onEntry(), cl_gcalcli::CbQuickAdd::onEntry(), cl_gcalcli::CbWaitConnection::onEntry(), cl_lifecycle_node::CbActivate::onEntry(), cl_lifecycle_node::CbCleanup::onEntry(), cl_lifecycle_node::CbConfigure::onEntry(), cl_lifecycle_node::CbDeactivate::onEntry(), cl_lifecycle_node::CbShutdown::onEntry(), cl_modbus_tcp_relay::CbAllRelaysOff::onEntry(), cl_modbus_tcp_relay::CbAllRelaysOn::onEntry(), cl_modbus_tcp_relay::CbRelayOff::onEntry(), cl_modbus_tcp_relay::CbRelayOn::onEntry(), cl_moveit2z::CbAttachObject::onEntry(), cl_moveit2z::CbDetachObject::onEntry(), cl_moveit2z::CbMoveEndEffectorTrajectory::onEntry(), cl_nav2z::CbAbortNavigation::onEntry(), cl_nav2z::CbLoadWaypointsFile::onEntry(), cl_nav2z::CbNavigateNamedWaypoint::onEntry(), cl_nav2z::CbNavigateNextWaypoint::onEntry(), cl_nav2z::CbWaitNav2Nodes::onEntry(), cl_nav2z::CbWaitPose::onEntry(), cl_nav2z::CbWaitTransform::onEntry(), smacc2::client_behaviors::CbSequence::onEntry(), smacc2::client_behaviors::CbServiceCall< ServiceType >::onEntry(), smacc2::client_behaviors::CbWaitActionServer2< ActionT >::onEntry(), smacc2::client_behaviors::CbWaitActionServer::onEntry(), smacc2::client_behaviors::CbWaitNode::onEntry(), smacc2::client_behaviors::CbWaitTopic::onEntry(), cl_nav2z::CbNav2ZClientBehaviorBase::onNavigationActionAbort(), smacc2::client_behaviors::CbSequence::onSubNodeAbort(), cl_lifecycle_node::CbActivate::onTransitionFailure(), cl_lifecycle_node::CbCleanup::onTransitionFailure(), cl_lifecycle_node::CbConfigure::onTransitionFailure(), cl_lifecycle_node::CbDeactivate::onTransitionFailure(), cl_lifecycle_node::CbDeactivateOnExit::onTransitionFailure(), cl_lifecycle_node::CbShutdown::onTransitionFailure(), cl_moveit2z::CbMoveit2zClientBehaviorBase::postMotionFailure(), cl_px4_mr::CbPx4ClientBehaviorBase::postPx4Failure(), cl_rgb::CbRgbClientBehaviorBase::postRgbFailure(), cl_modbus_tcp_relay::CbRelayStatus::readAllChannels(), cl_modbus_tcp_relay::CbRelayStatus::readSingleChannel(), smacc2::client_behavior_bases::CbActionClientBehaviorBase< TAction >::sendGoal(), and smacc2::client_behavior_bases::CbActionClientBehaviorBase< TAction >::trackGoal().

Here is the caller graph for this function:

◆ postSuccessEvent()

void smacc2::SmaccAsyncClientBehavior::postSuccessEvent ( )
protected

Definition at line 272 of file smacc_client_async_behavior.cpp.

References postSuccessEventFn_.

Referenced by cl_nav2z::CbAssistedTeleop::onActionAbort(), smacc2::client_behavior_bases::CbActionClientBehaviorBase< TAction >::onActionSuccess(), cl_gcalcli::CbQuickAdd::onEntry(), cl_gcalcli::CbWaitConnection::onEntry(), cl_modbus_tcp_relay::CbAllRelaysOff::onEntry(), cl_modbus_tcp_relay::CbAllRelaysOn::onEntry(), cl_modbus_tcp_relay::CbRelayOff::onEntry(), cl_modbus_tcp_relay::CbRelayOn::onEntry(), cl_moveit2z::CbAttachObject::onEntry(), cl_moveit2z::CbDetachObject::onEntry(), cl_nav2z::CbAbortNavigation::onEntry(), cl_nav2z::CbActiveStop::onEntry(), cl_nav2z::CbLoadWaypointsFile::onEntry(), cl_nav2z::CbPositionControlFreeSpace::onEntry(), cl_nav2z::CbPureSpinning::onEntry(), cl_nav2z::CbSpiralMotion::onEntry(), cl_nav2z::CbWaitPose::onEntry(), cl_nav2z::CbWaitTransform::onEntry(), smacc2::client_behaviors::CbSequence::onEntry(), smacc2::client_behaviors::CbServiceCall< ServiceType >::onEntry(), smacc2::client_behaviors::CbSleepFor::onEntry(), smacc2::client_behaviors::CbWaitActionServer2< ActionT >::onEntry(), smacc2::client_behaviors::CbWaitActionServer::onEntry(), smacc2::client_behaviors::CbWaitNode::onEntry(), smacc2::client_behaviors::CbWaitTopic::onEntry(), cl_gcalcli::CbDetectCalendarEvent::onEventStarted(), cl_gcalcli::CbEventDetect::onEventStarted(), cl_nav2z::CbWaitNav2Nodes::onMessageReceived(), smacc2::client_behaviors::CbWaitTopicMessage< TMessage >::onMessageReceived(), cl_nav2z::CbNav2ZClientBehaviorBase::onNavigationActionSuccess(), cl_nav2z::CbNavigateNextWaypointUntilReached::onNavigationActionSuccess(), cl_lifecycle_node::CbActivate::onTransitionSuccess(), cl_lifecycle_node::CbCleanup::onTransitionSuccess(), cl_lifecycle_node::CbConfigure::onTransitionSuccess(), cl_lifecycle_node::CbDeactivate::onTransitionSuccess(), cl_lifecycle_node::CbDeactivateOnExit::onTransitionSuccess(), cl_lifecycle_node::CbShutdown::onTransitionSuccess(), cl_moveit2z::CbMoveit2zClientBehaviorBase::postMotionSuccess(), cl_px4_mr::CbPx4ClientBehaviorBase::postPx4Success(), cl_rgb::CbRgbClientBehaviorBase::postRgbSuccess(), cl_modbus_tcp_relay::CbRelayStatus::readAllChannels(), and cl_modbus_tcp_relay::CbRelayStatus::readSingleChannel().

Here is the caller graph for this function:

◆ requestForceFinish()

void smacc2::SmaccAsyncClientBehavior::requestForceFinish ( )

Definition at line 276 of file smacc_client_async_behavior.cpp.

277{
278 RCLCPP_FATAL_STREAM_THROTTLE(
279 getLogger(), *(getNode()->get_clock()), 1000,
280 "[" << getName() << "] " << static_cast<const void *>(this) << " requestForceFinish");
282}
virtual rclcpp::Node::SharedPtr getNode() const

References smacc2::ISmaccClientBehavior::getLogger(), smacc2::ISmaccClientBehavior::getName(), smacc2::ISmaccClientBehavior::getNode(), and isShutdownRequested_.

Referenced by smacc2::client_behaviors::CbSequence::onSubNodeAbort(), and waitFutureIfNotFinished().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ waitFutureIfNotFinished()

void smacc2::SmaccAsyncClientBehavior::waitFutureIfNotFinished ( std::optional< std::future< int > > & threadfut,
bool requestFinish )
private

Definition at line 123 of file smacc_client_async_behavior.cpp.

125{
126 if (!threadfut || !threadfut->valid())
127 {
128 RCLCPP_DEBUG_STREAM(
129 getLogger(),
130 "[" << getName() << "] onEntry thread not created or already joined. Skipping wait.");
131 return;
132 }
133
134 try
135 {
136 // Never stops at rclcpp shutdown: the thread must be joined before this object is released.
137 while (true)
138 {
139 // A thread that has already returned needs no finish request (the future stays valid until
140 // consumed here); without this check shutdown logged a FATAL requestForceFinish for it.
141 if (threadfut->wait_for(std::chrono::seconds(0)) == std::future_status::ready)
142 {
143 threadfut->get();
144 break;
145 }
146
147 if (requestFinish && !rclcpp::ok())
148 {
150 }
151
152 auto status = threadfut->wait_for(std::chrono::milliseconds(20));
153 if (status == std::future_status::ready)
154 {
155 threadfut->get();
156 break;
157 }
158
159 RCLCPP_INFO_STREAM(
160 getLogger(),
161 "[" << getName()
162 << "] fut valid but waiting for asynchronous onEntry thread to finish: state: "
163 << (int)status);
164
165 rclcpp::sleep_for(100ms);
166 RCLCPP_WARN_THROTTLE(
167 getLogger(), *(getNode()->get_clock()), 1000,
168 "[%s] waiting for finishing client behavior, before leaving the state. Is the client "
169 "behavior stuck? requesting force finish",
170 this->getName().c_str());
171
172 if (requestFinish) requestForceFinish();
173 }
174 }
175 catch (const std::exception & e)
176 {
177 logThreadException(getLogger(), getName(), "onEntry", e.what());
178 }
179 catch (...)
180 {
181 logThreadException(getLogger(), getName(), "onEntry", "non-standard exception");
182 }
183}

References smacc2::ISmaccClientBehavior::getLogger(), smacc2::ISmaccClientBehavior::getName(), smacc2::ISmaccClientBehavior::getNode(), smacc2::logThreadException(), and requestForceFinish().

Referenced by waitOnEntryThread().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ waitOnEntryThread()

void smacc2::SmaccAsyncClientBehavior::waitOnEntryThread ( bool requestFinish)

Definition at line 185 of file smacc_client_async_behavior.cpp.

186{
187 waitFutureIfNotFinished(this->onEntryThread_, requestFinish);
188}
void waitFutureIfNotFinished(std::optional< std::future< int > > &threadfut, bool requestFinish)

References onEntryThread_, and waitFutureIfNotFinished().

Referenced by dispose(), executeOnExit(), and ~SmaccAsyncClientBehavior().

Here is the call graph for this function:
Here is the caller graph for this function:

Member Data Documentation

◆ isShutdownRequested_

std::atomic<bool> smacc2::SmaccAsyncClientBehavior::isShutdownRequested_ {false}
private

Definition at line 123 of file smacc_asynchronous_client_behavior.hpp.

123{false};

Referenced by isShutdownRequested(), and requestForceFinish().

◆ onEntryThread_

std::optional<std::future<int> > smacc2::SmaccAsyncClientBehavior::onEntryThread_
private

◆ onExitThread_

std::optional<std::future<int> > smacc2::SmaccAsyncClientBehavior::onExitThread_
private

◆ onFailure_

SmaccSignal<void()> smacc2::SmaccAsyncClientBehavior::onFailure_
private

◆ onFinished_

SmaccSignal<void()> smacc2::SmaccAsyncClientBehavior::onFinished_
private

◆ onSuccess_

SmaccSignal<void()> smacc2::SmaccAsyncClientBehavior::onSuccess_
private

◆ postFailureEventFn_

std::function<void()> smacc2::SmaccAsyncClientBehavior::postFailureEventFn_
private

◆ postFinishEventFn_

std::function<void()> smacc2::SmaccAsyncClientBehavior::postFinishEventFn_
private

◆ postSuccessEventFn_

std::function<void()> smacc2::SmaccAsyncClientBehavior::postSuccessEventFn_
private

The documentation for this class was generated from the following files: