SMACC2
Loading...
Searching...
No Matches
Public Member Functions | Private Member Functions | Private Attributes | List of all members
smacc2::client_behaviors::CbSequence Class Reference

#include <cb_sequence.hpp>

Inheritance diagram for smacc2::client_behaviors::CbSequence:
Inheritance graph
Collaboration diagram for smacc2::client_behaviors::CbSequence:
Collaboration graph

Public Member Functions

 CbSequence ()
 
void onEntry () override
 
void onExit () override
 
template<typename TOrthogonal , typename TBehavior , typename... Args>
CbSequencethen (Args &&... args)
 
- Public Member Functions inherited from smacc2::SmaccAsyncClientBehavior
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)
 
void requestForceFinish ()
 
void executeOnEntry () override
 
void executeOnExit () override
 
void waitOnEntryThread (bool requestFinish)
 
template<typename TCallbackMethod , typename T >
boost::signals2::connection onSuccess (TCallbackMethod callback, T *object)
 
template<typename TCallbackMethod , typename T >
boost::signals2::connection onFinished (TCallbackMethod callback, T *object)
 
template<typename TCallbackMethod , typename T >
boost::signals2::connection onFailure (TCallbackMethod 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, bool throwExceptionIfNotExist=false)
 
virtual void onEntry ()
 
virtual void onExit ()
 
virtual void executeOnEntry ()
 
virtual void executeOnExit ()
 

Private Member Functions

void onSubNodeSuccess ()
 
void onSubNodeAbort ()
 
void recursiveConsumeNext ()
 

Private Attributes

std::list< std::function< std::shared_ptr< smacc2::SmaccAsyncClientBehavior >()> > sequenceNodes_
 
boost::signals2::connection conn_
 
boost::signals2::connection conn2_
 
std::shared_ptr< smacc2::SmaccAsyncClientBehaviorbh_
 
std::atomic< int > consume_ {0}
 

Additional Inherited Members

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

Detailed Description

Definition at line 31 of file cb_sequence.hpp.

Constructor & Destructor Documentation

◆ CbSequence()

smacc2::client_behaviors::CbSequence::CbSequence ( )

Definition at line 30 of file cb_sequence.cpp.

30{}

Member Function Documentation

◆ onEntry()

void smacc2::client_behaviors::CbSequence::onEntry ( )
overridevirtual

Reimplemented from smacc2::ISmaccClientBehavior.

Definition at line 60 of file cb_sequence.cpp.

61{
63 while (!sequenceNodes_.empty())
64 {
65 bool is_shutdown_requested = this->isShutdownRequested();
66 if (is_shutdown_requested)
67 {
68 break;
69 }
70
71 rclcpp::sleep_for(std::chrono::milliseconds(200));
72 RCLCPP_INFO_THROTTLE(
73 getLogger(), *(getNode()->get_clock()), 1000,
74 "[CbSequence %ld] Waiting for subnodes to finish %ld. Current head Behavior: %s ", (long)this,
75 sequenceNodes_.size(), demangleType(&typeid(*bh_)).c_str());
76
77 if (consume_)
78 {
79 // bh_->waitOnEntryThread();
80 this->conn_.disconnect();
81 this->conn2_.disconnect();
82
83 sequenceNodes_.pop_front();
84 consume_--;
85
86 if (sequenceNodes_.size() > 0)
87 {
89 }
90 }
91 }
92
93 if (sequenceNodes_.empty())
94 {
95 RCLCPP_INFO(getLogger(), "[CbSequence %ld] All subnodes finished", (long)this);
96 this->postSuccessEvent();
97 }
98 else
99 {
100 RCLCPP_INFO(getLogger(), "[CbSequence %ld] Aborting", (long)this);
101 this->postFailureEvent();
102 }
103}
virtual rclcpp::Logger getLogger() const
virtual rclcpp::Node::SharedPtr getNode() const
boost::signals2::connection conn_
Definition: cb_sequence.hpp:85
boost::signals2::connection conn2_
Definition: cb_sequence.hpp:86
std::list< std::function< std::shared_ptr< smacc2::SmaccAsyncClientBehavior >()> > sequenceNodes_
Definition: cb_sequence.hpp:84
std::shared_ptr< smacc2::SmaccAsyncClientBehavior > bh_
Definition: cb_sequence.hpp:88
std::string demangleType(const std::type_info *tinfo)

References bh_, conn2_, conn_, consume_, smacc2::introspection::demangleType(), smacc2::ISmaccClientBehavior::getLogger(), smacc2::ISmaccClientBehavior::getNode(), smacc2::SmaccAsyncClientBehavior::isShutdownRequested(), smacc2::SmaccAsyncClientBehavior::postFailureEvent(), smacc2::SmaccAsyncClientBehavior::postSuccessEvent(), recursiveConsumeNext(), and sequenceNodes_.

Here is the call graph for this function:

◆ onExit()

void smacc2::client_behaviors::CbSequence::onExit ( )
inlineoverridevirtual

Reimplemented from smacc2::ISmaccClientBehavior.

Definition at line 55 of file cb_sequence.hpp.

55{ sequenceNodes_.clear(); }

References sequenceNodes_.

◆ onSubNodeAbort()

void smacc2::client_behaviors::CbSequence::onSubNodeAbort ( )
private

Definition at line 112 of file cb_sequence.cpp.

113{
114 RCLCPP_INFO(
115 getLogger(), "[CbSequence %ld] Abort NextCbSequence %ld", (long)this, sequenceNodes_.size());
116 // bh_->waitOnEntryThread();
117 this->conn_.disconnect();
118 this->conn2_.disconnect();
119
120 this->postFailureEvent();
121 RCLCPP_INFO(
122 getLogger(), "[CbSequence %ld] Abort NextCbSequence requesting for force finish", (long)this);
123 this->requestForceFinish();
124 consume_++;
125}

References conn2_, conn_, consume_, smacc2::ISmaccClientBehavior::getLogger(), smacc2::SmaccAsyncClientBehavior::postFailureEvent(), smacc2::SmaccAsyncClientBehavior::requestForceFinish(), and sequenceNodes_.

Referenced by recursiveConsumeNext().

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

◆ onSubNodeSuccess()

void smacc2::client_behaviors::CbSequence::onSubNodeSuccess ( )
private

Definition at line 105 of file cb_sequence.cpp.

106{
107 RCLCPP_INFO(
108 getLogger(), "[CbSequence %ld] Success NextCbSequence %ld", (long)this, sequenceNodes_.size());
109 consume_++;
110}

References consume_, smacc2::ISmaccClientBehavior::getLogger(), and sequenceNodes_.

Referenced by recursiveConsumeNext().

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

◆ recursiveConsumeNext()

void smacc2::client_behaviors::CbSequence::recursiveConsumeNext ( )
private

Definition at line 32 of file cb_sequence.cpp.

33{
34 RCLCPP_INFO(
35 getLogger(), "[SequenceNode %ld] next onEntry: %ld", (long)this, sequenceNodes_.size());
36
37 auto first = sequenceNodes_.front();
38 auto onDelayedConfigureFn = first;
39
40 RCLCPP_INFO(getLogger(), "[SequenceNode %ld] Behavior on delayed sequence configure", (long)this);
41 bh_ = onDelayedConfigureFn();
42 std::string currentNodeName = bh_->getName();
43
44 RCLCPP_INFO(getLogger(), "[SequenceNode %ld] Subscribing OnSuccess", (long)this);
45 this->conn_ = bh_->onSuccess(&CbSequence::onSubNodeSuccess, this);
46 this->conn2_ = bh_->onFailure(&CbSequence::onSubNodeAbort, this);
47
48 RCLCPP_INFO(
49 getLogger(), "[SequenceNode %ld] subnode %s on entry", (long)this, currentNodeName.c_str());
50 bh_->executeOnEntry();
51 RCLCPP_INFO(
52 getLogger(), "[SequenceNode %ld] subnode %s on entry finished", (long)this,
53 currentNodeName.c_str());
54 bh_->waitOnEntryThread(false); // we do not request to finish to keep on subscriptions
55 RCLCPP_INFO(
56 getLogger(), "[SequenceNode %ld] subnode %s thread finished", (long)this,
57 currentNodeName.c_str());
58}

References bh_, conn2_, conn_, smacc2::ISmaccClientBehavior::getLogger(), onSubNodeAbort(), onSubNodeSuccess(), and sequenceNodes_.

Referenced by onEntry().

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

◆ then()

template<typename TOrthogonal , typename TBehavior , typename... Args>
CbSequence * smacc2::client_behaviors::CbSequence::then ( Args &&...  args)
inline

Definition at line 58 of file cb_sequence.hpp.

59 {
60 std::function<std::shared_ptr<smacc2::SmaccAsyncClientBehavior>()> delayedCBFactoryFn =
61 [this, args...]()
62 {
63 RCLCPP_INFO(
64 getLogger(), "[CbSequence] then creating new sub behavior %s ",
65 demangleSymbol<TBehavior>().c_str());
66 auto createdBh = std::shared_ptr<TBehavior>(new TBehavior(args...));
67
68 this->getCurrentState()->getOrthogonal<TOrthogonal>()->addClientBehavior(createdBh);
69 createdBh->template onOrthogonalAllocation<TOrthogonal, TBehavior>();
70
71 return createdBh;
72 };
73
74 sequenceNodes_.push_back(delayedCBFactoryFn);
75
76 return this;
77 }
TOrthogonal * getOrthogonal()

References smacc2::ISmaccClientBehavior::getCurrentState(), smacc2::ISmaccClientBehavior::getLogger(), smacc2::ISmaccState::getOrthogonal(), and sequenceNodes_.

Here is the call graph for this function:

Member Data Documentation

◆ bh_

std::shared_ptr<smacc2::SmaccAsyncClientBehavior> smacc2::client_behaviors::CbSequence::bh_
private

Definition at line 88 of file cb_sequence.hpp.

Referenced by onEntry(), and recursiveConsumeNext().

◆ conn2_

boost::signals2::connection smacc2::client_behaviors::CbSequence::conn2_
private

Definition at line 86 of file cb_sequence.hpp.

Referenced by onEntry(), onSubNodeAbort(), and recursiveConsumeNext().

◆ conn_

boost::signals2::connection smacc2::client_behaviors::CbSequence::conn_
private

Definition at line 85 of file cb_sequence.hpp.

Referenced by onEntry(), onSubNodeAbort(), and recursiveConsumeNext().

◆ consume_

std::atomic<int> smacc2::client_behaviors::CbSequence::consume_ {0}
private

Definition at line 89 of file cb_sequence.hpp.

Referenced by onEntry(), onSubNodeAbort(), and onSubNodeSuccess().

◆ sequenceNodes_

std::list<std::function<std::shared_ptr<smacc2::SmaccAsyncClientBehavior>()> > smacc2::client_behaviors::CbSequence::sequenceNodes_
private

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