SMACC2
Public Member Functions | Protected Member Functions | Private Member Functions | Private Attributes | List of all members
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 onOrthogonalAllocation ()
 
virtual ~SmaccAsyncClientBehavior ()
 
template<typename TCallback , typename T >
boost::signals2::connection onSuccess (TCallback callback, T *object)
 
template<typename TCallback , typename T >
boost::signals2::connection onFinished (TCallback callback, T *object)
 
template<typename TCallback , typename T >
boost::signals2::connection onFailure (TCallback callback, T *object)
 
- Public Member Functions inherited from smacc2::ISmaccClientBehavior
 ISmaccClientBehavior ()
 
virtual ~ISmaccClientBehavior ()
 
ISmaccStateMachinegetStateMachine ()
 
std::string getName () const
 
template<typename SmaccClientType >
void requiresClient (SmaccClientType *&storage)
 
template<typename SmaccComponentType >
void requiresComponent (SmaccComponentType *&storage)
 

Protected Member Functions

void postSuccessEvent ()
 
void postFailureEvent ()
 
virtual void dispose () override
 
bool isShutdownRequested ()
 
- Protected Member Functions inherited from smacc2::ISmaccClientBehavior
virtual void runtimeConfigure ()
 
virtual void onEntry ()
 
virtual void onExit ()
 
template<typename EventType >
void postEvent (const EventType &ev)
 
template<typename EventType >
void postEvent ()
 
ISmaccStategetCurrentState ()
 
virtual void dispose ()
 
virtual rclcpp::Node::SharedPtr getNode ()
 
virtual rclcpp::Logger getLogger ()
 

Private Member Functions

void waitFutureIfNotFinished (std::future< int > &threadfut)
 
void executeOnEntry () override
 
void executeOnExit () override
 

Private Attributes

std::future< int > onEntryThread_
 
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_
 
bool isShutdownRequested_
 

Detailed Description

Definition at line 56 of file smacc_asynchronous_client_behavior.hpp.

Constructor & Destructor Documentation

◆ ~SmaccAsyncClientBehavior()

smacc2::SmaccAsyncClientBehavior::~SmaccAsyncClientBehavior ( )
virtual

Definition at line 112 of file smacc_client_async_behavior.cpp.

112{}

Member Function Documentation

◆ dispose()

void smacc2::SmaccAsyncClientBehavior::dispose ( )
overrideprotectedvirtual

Reimplemented from smacc2::ISmaccClientBehavior.

Definition at line 89 of file smacc_client_async_behavior.cpp.

90{
91 RCLCPP_DEBUG_STREAM(
92 getLogger(),
93 "[" << getName()
94 << "] Destroying client behavior- Waiting finishing of asynchronous onExit thread");
95 try
96 {
97 this->onExitThread_.get();
98 }
99 catch (...)
100 {
101 RCLCPP_DEBUG(
102 getLogger(),
103 "[SmaccAsyncClientBehavior] trying to Join onExit function, but it was already finished.");
104 }
105
106 RCLCPP_DEBUG_STREAM(
107 getLogger(),
108 "[" << getName()
109 << "] Destroying client behavior- onExit thread finished. Proccedding destruction.");
110}

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

Here is the call graph for this function:

◆ executeOnEntry()

void smacc2::SmaccAsyncClientBehavior::executeOnEntry ( )
overrideprivatevirtual

Reimplemented from smacc2::ISmaccClientBehavior.

Definition at line 27 of file smacc_client_async_behavior.cpp.

28{
29 RCLCPP_INFO_STREAM(getLogger(), "[" << getName() << "] Creating asynchronous onEntry thread");
30 this->onEntryThread_ = std::async(std::launch::async, [=] {
31 this->onEntry();
32 this->postFinishEventFn_();
33 RCLCPP_INFO_STREAM(
34 getLogger(), "[" << getName() << "] onEntry asynchronous thread was finished.");
35 return 0;
36 });
37}

References smacc2::ISmaccClientBehavior::getLogger(), smacc2::ISmaccClientBehavior::getName(), smacc2::ISmaccClientBehavior::onEntry(), onEntryThread_, and postFinishEventFn_.

Here is the call graph for this function:

◆ executeOnExit()

void smacc2::SmaccAsyncClientBehavior::executeOnExit ( )
overrideprivatevirtual

Reimplemented from smacc2::ISmaccClientBehavior.

Definition at line 75 of file smacc_client_async_behavior.cpp.

76{
77 RCLCPP_INFO_STREAM(getLogger(), "[" << getName() << "] onExit - join async onEntry thread");
78
80
81 RCLCPP_INFO_STREAM(
82 getLogger(), "[" << getName() << "] onExit - Creating asynchronous onExit thread");
83 this->onExitThread_ = std::async(std::launch::async, [=] {
84 this->onExit();
85 return 0;
86 });
87}
void waitFutureIfNotFinished(std::future< int > &threadfut)

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

Here is the call graph for this function:

◆ isShutdownRequested()

bool smacc2::SmaccAsyncClientBehavior::isShutdownRequested ( )
inlineprotected

Definition at line 79 of file smacc_asynchronous_client_behavior.hpp.

References isShutdownRequested_.

Referenced by smacc2::client_behaviors::CbWaitNode::onEntry().

Here is the caller graph for this function:

◆ onFailure()

template<typename TCallback , typename T >
boost::signals2::connection smacc2::SmaccAsyncClientBehavior::onFailure ( TCallback  callback,
T object 
)

Definition at line 59 of file smacc_asynchronous_client_behavior_impl.hpp.

60{
62}
boost::signals2::connection createSignalConnection(TSmaccSignal &signal, TMemberFunctionPrototype callback, TSmaccObjectType *object)
void callback(const image_tools::ROSCvMatContainer &img)

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

Here is the call graph for this function:

◆ onFinished()

template<typename TCallback , typename T >
boost::signals2::connection smacc2::SmaccAsyncClientBehavior::onFinished ( TCallback  callback,
T object 
)

◆ onOrthogonalAllocation()

template<typename TOrthogonal , typename TSourceObject >
void smacc2::SmaccAsyncClientBehavior::onOrthogonalAllocation

Definition at line 28 of file smacc_asynchronous_client_behavior_impl.hpp.

29{
30 postFinishEventFn_ = [this] {
31 this->onFinished_();
32 this->postEvent<EvCbFinished<TSourceObject, TOrthogonal>>();
33 };
34
35 postSuccessEventFn_ = [this] {
36 this->onSuccess_();
37 this->postEvent<EvCbSuccess<TSourceObject, TOrthogonal>>();
38 };
39
40 postFailureEventFn_ = [this] {
41 this->onFailure_();
42 this->postEvent<EvCbFailure<TSourceObject, TOrthogonal>>();
43 };
44}

References onFailure_, onFinished_, onSuccess_, postFailureEventFn_, postFinishEventFn_, and postSuccessEventFn_.

◆ onSuccess()

template<typename TCallback , typename T >
boost::signals2::connection smacc2::SmaccAsyncClientBehavior::onSuccess ( TCallback  callback,
T object 
)

◆ postFailureEvent()

void smacc2::SmaccAsyncClientBehavior::postFailureEvent ( )
protected

◆ postSuccessEvent()

void smacc2::SmaccAsyncClientBehavior::postSuccessEvent ( )
protected

◆ waitFutureIfNotFinished()

void smacc2::SmaccAsyncClientBehavior::waitFutureIfNotFinished ( std::future< int > &  threadfut)
private

Definition at line 39 of file smacc_client_async_behavior.cpp.

40{
41 try
42 {
43 rclcpp::Rate r(100);
44 while (rclcpp::ok())
45 {
46 bool valid = threadfut.valid();
47 if (valid)
48 {
49 auto status = threadfut.wait_for(std::chrono::milliseconds(20));
50 if (status == std::future_status::ready)
51 {
52 threadfut.get();
53 break;
54 }
55 }
56
57 //r.sleep();
58 rclcpp::sleep_for(100ms);
59 // rclcpp::spin_some(getNode());
60 RCLCPP_WARN_THROTTLE(
61 getLogger(), *(getNode()->get_clock()), 1000,
62 "[%s] waiting for finishing client behavior, before leaving the state. Is the client "
63 "behavior stuck?",
64 demangleType(typeid(*this)).c_str());
65 }
66 }
67 catch (const std::exception & e)
68 {
69 RCLCPP_DEBUG(
70 getLogger(),
71 "[SmaccAsyncClientBehavior] trying to join function, but it was already finished.");
72 }
73}
virtual rclcpp::Node::SharedPtr getNode()
std::string demangleType(const std::type_info *tinfo)

References smacc2::introspection::demangleType(), smacc2::ISmaccClientBehavior::getLogger(), and smacc2::ISmaccClientBehavior::getNode().

Referenced by executeOnExit().

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

Member Data Documentation

◆ isShutdownRequested_

bool smacc2::SmaccAsyncClientBehavior::isShutdownRequested_
private

Definition at line 100 of file smacc_asynchronous_client_behavior.hpp.

Referenced by isShutdownRequested().

◆ onEntryThread_

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

Definition at line 83 of file smacc_asynchronous_client_behavior.hpp.

Referenced by executeOnEntry(), and executeOnExit().

◆ onExitThread_

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

Definition at line 84 of file smacc_asynchronous_client_behavior.hpp.

Referenced by dispose(), and executeOnExit().

◆ onFailure_

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

Definition at line 92 of file smacc_asynchronous_client_behavior.hpp.

Referenced by onFailure(), and onOrthogonalAllocation().

◆ onFinished_

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

Definition at line 90 of file smacc_asynchronous_client_behavior.hpp.

Referenced by onFinished(), and onOrthogonalAllocation().

◆ onSuccess_

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

Definition at line 91 of file smacc_asynchronous_client_behavior.hpp.

Referenced by onOrthogonalAllocation(), and onSuccess().

◆ 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: