SMACC
Loading...
Searching...
No Matches
Public Member Functions | Protected Member Functions | Private Attributes | List of all members
smacc::SmaccAsyncClientBehavior Class Reference

#include <smacc_asynchronous_client_behavior.h>

Inheritance diagram for smacc::SmaccAsyncClientBehavior:
Inheritance graph
Collaboration diagram for smacc::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 smacc::ISmaccClientBehavior
 ISmaccClientBehavior ()
 
virtual ~ISmaccClientBehavior ()
 
ISmaccStateMachinegetStateMachine ()
 
std::string getName () const
 
template<typename SmaccClientType >
void requiresClient (SmaccClientType *&storage)
 
template<typename SmaccComponentType >
void requiresComponent (SmaccComponentType *&storage)
 
ros::NodeHandle getNode ()
 

Protected Member Functions

virtual void executeOnEntry () override
 
virtual void executeOnExit () override
 
void postSuccessEvent ()
 
void postFailureEvent ()
 
virtual void dispose () override
 
- Protected Member Functions inherited from smacc::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 executeOnEntry ()
 
virtual void executeOnExit ()
 
virtual void dispose ()
 

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_
 

Detailed Description

Definition at line 42 of file smacc_asynchronous_client_behavior.h.

Constructor & Destructor Documentation

◆ ~SmaccAsyncClientBehavior()

smacc::SmaccAsyncClientBehavior::~SmaccAsyncClientBehavior ( )
virtual

Definition at line 69 of file smacc_client_async_behavior.cpp.

70 {
71 }

Member Function Documentation

◆ dispose()

void smacc::SmaccAsyncClientBehavior::dispose ( )
overrideprotectedvirtual

Reimplemented from smacc::ISmaccClientBehavior.

Definition at line 54 of file smacc_client_async_behavior.cpp.

55 {
56 ROS_DEBUG_STREAM("[" << getName() << "] Destroying client behavior- Waiting finishing of asynchronous onExit thread");
57 try
58 {
59 this->onExitThread_.get();
60 }
61 catch (...)
62 {
63 ROS_DEBUG("[SmaccAsyncClientBehavior] trying to Join onExit function, but it was already finished.");
64 }
65
66 ROS_DEBUG_STREAM("[" << getName() << "] Destroying client behavior- onExit thread finished. Proccedding destruction.");
67 }

References smacc::ISmaccClientBehavior::getName(), and onExitThread_.

Here is the call graph for this function:

◆ executeOnEntry()

void smacc::SmaccAsyncClientBehavior::executeOnEntry ( )
overrideprotectedvirtual

Reimplemented from smacc::ISmaccClientBehavior.

Definition at line 5 of file smacc_client_async_behavior.cpp.

6 {
7 ROS_INFO_STREAM("[" << getName() << "] Creating asynchronous onEntry thread");
8 this->onEntryThread_ = std::async(std::launch::async,
9 [=] {
10 this->onEntry();
11 this->postFinishEventFn_();
12 return 0;
13 });
14 }

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

Here is the call graph for this function:

◆ executeOnExit()

void smacc::SmaccAsyncClientBehavior::executeOnExit ( )
overrideprotectedvirtual

Reimplemented from smacc::ISmaccClientBehavior.

Definition at line 16 of file smacc_client_async_behavior.cpp.

17 {
18 ROS_INFO_STREAM("[" << getName() << "] onExit - join async onEntry thread");
19
20 try
21 {
22 ros::Rate r(200);
23 while (ros::ok())
24 {
25 bool valid = this->onEntryThread_.valid();
26 if (valid)
27 {
28 auto status = this->onEntryThread_.wait_for(std::chrono::milliseconds(20));
29 if (status == std::future_status::ready)
30 {
31 this->onEntryThread_.get();
32 break;
33 }
34 }
35
36 r.sleep();
37 ros::spinOnce();
38 ROS_DEBUG("waiting for finishing client behavior");
39 }
40 }
41 catch (const std::exception &e)
42 {
43 ROS_DEBUG("[SmaccAsyncClientBehavior] trying to Join onEntry function, but it was already finished.");
44 }
45
46 ROS_INFO_STREAM("[" << getName() << "] onExit - Creating asynchronous onExit thread");
47 this->onExitThread_ = std::async(std::launch::async,
48 [=] {
49 this->onExit();
50 return 0;
51 });
52 }

References smacc::ISmaccClientBehavior::getName(), onEntryThread_, smacc::ISmaccClientBehavior::onExit(), and onExitThread_.

Here is the call graph for this function:

◆ onFailure()

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

Definition at line 46 of file smacc_asynchronous_client_behavior_impl.h.

47 {
48 return this->getStateMachine()->createSignalConnection(onFailure_, callback, object);
49 }
ISmaccStateMachine * getStateMachine()
boost::signals2::connection createSignalConnection(TSmaccSignal &signal, TMemberFunctionPrototype callback, TSmaccObjectType *object)

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

Here is the call graph for this function:

◆ onFinished()

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

Definition at line 40 of file smacc_asynchronous_client_behavior_impl.h.

41 {
42 return this->getStateMachine()->createSignalConnection(onFinished_, callback, object);
43 }

References smacc::ISmaccStateMachine::createSignalConnection(), smacc::ISmaccClientBehavior::getStateMachine(), and onFinished_.

Here is the call graph for this function:

◆ onOrthogonalAllocation()

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

Definition at line 15 of file smacc_asynchronous_client_behavior_impl.h.

16 {
17 postFinishEventFn_ = [=] {
18 this->onFinished_();
19 this->postEvent<EvCbFinished<TSourceObject, TOrthogonal>>();
20 };
21
23 this->onSuccess_();
24 this->postEvent<EvCbSuccess<TSourceObject, TOrthogonal>>();
25 };
26
28 this->onFailure_();
29 this->postEvent<EvCbFailure<TSourceObject, TOrthogonal>>();
30 };
31 }

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

◆ onSuccess()

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

Definition at line 34 of file smacc_asynchronous_client_behavior_impl.h.

35 {
36 return this->getStateMachine()->createSignalConnection(onSuccess_, callback, object);
37 }

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

Here is the call graph for this function:

◆ postFailureEvent()

void smacc::SmaccAsyncClientBehavior::postFailureEvent ( )
protected

◆ postSuccessEvent()

void smacc::SmaccAsyncClientBehavior::postSuccessEvent ( )
protected

Member Data Documentation

◆ onEntryThread_

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

Definition at line 69 of file smacc_asynchronous_client_behavior.h.

Referenced by executeOnEntry(), and executeOnExit().

◆ onExitThread_

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

Definition at line 70 of file smacc_asynchronous_client_behavior.h.

Referenced by dispose(), and executeOnExit().

◆ onFailure_

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

Definition at line 78 of file smacc_asynchronous_client_behavior.h.

Referenced by onFailure(), and onOrthogonalAllocation().

◆ onFinished_

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

Definition at line 76 of file smacc_asynchronous_client_behavior.h.

Referenced by onFinished(), and onOrthogonalAllocation().

◆ onSuccess_

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

Definition at line 77 of file smacc_asynchronous_client_behavior.h.

Referenced by onOrthogonalAllocation(), and onSuccess().

◆ postFailureEventFn_

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

◆ postFinishEventFn_

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

Definition at line 72 of file smacc_asynchronous_client_behavior.h.

Referenced by executeOnEntry(), and onOrthogonalAllocation().

◆ postSuccessEventFn_

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

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