SMACC2
Loading...
Searching...
No Matches
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 118 of file smacc_client_async_behavior.cpp.

118{}

Member Function Documentation

◆ dispose()

void smacc2::SmaccAsyncClientBehavior::dispose ( )
overrideprotectedvirtual

Reimplemented from smacc2::ISmaccClientBehavior.

Definition at line 95 of file smacc_client_async_behavior.cpp.

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

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(
31 std::launch::async,
32 [=]
33 {
34 this->onEntry();
35 this->postFinishEventFn_();
36 RCLCPP_INFO_STREAM(
37 getLogger(), "[" << getName() << "] onEntry asynchronous thread was finished.");
38 return 0;
39 });
40}

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 78 of file smacc_client_async_behavior.cpp.

79{
80 RCLCPP_INFO_STREAM(getLogger(), "[" << getName() << "] onExit - join async onEntry thread");
81
83
84 RCLCPP_INFO_STREAM(
85 getLogger(), "[" << getName() << "] onExit - Creating asynchronous onExit thread");
86 this->onExitThread_ = std::async(
87 std::launch::async,
88 [=]
89 {
90 this->onExit();
91 return 0;
92 });
93}
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 62 of file smacc_asynchronous_client_behavior_impl.hpp.

63{
64 return this->getStateMachine()->createSignalConnection(onFailure_, callback, object);
65}
boost::signals2::connection 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()

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 {
32 this->onFinished_();
33 this->postEvent<EvCbFinished<TSourceObject, TOrthogonal>>();
34 };
35
36 postSuccessEventFn_ = [this]
37 {
38 this->onSuccess_();
39 this->postEvent<EvCbSuccess<TSourceObject, TOrthogonal>>();
40 };
41
42 postFailureEventFn_ = [this]
43 {
44 this->onFailure_();
45 this->postEvent<EvCbFailure<TSourceObject, TOrthogonal>>();
46 };
47}

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

◆ onSuccess()

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

Definition at line 50 of file smacc_asynchronous_client_behavior_impl.hpp.

51{
52 return this->getStateMachine()->createSignalConnection(onSuccess_, callback, object);
53}

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

Here is the call graph for this function:

◆ postFailureEvent()

void smacc2::SmaccAsyncClientBehavior::postFailureEvent ( )
protected

Definition at line 122 of file smacc_client_async_behavior.cpp.

References postFailureEventFn_.

Referenced by smacc2::client_behaviors::CbWaitActionServer::onEntry(), and smacc2::client_behaviors::CbWaitNode::onEntry().

Here is the caller graph for this function:

◆ postSuccessEvent()

void smacc2::SmaccAsyncClientBehavior::postSuccessEvent ( )
protected

◆ waitFutureIfNotFinished()

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

Definition at line 42 of file smacc_client_async_behavior.cpp.

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