SMACC2
Loading...
Searching...
No Matches
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 onStateOrthogonalAllocation ()
 
virtual ~SmaccAsyncClientBehavior ()
 
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 ()
 
ISmaccStateMachinegetStateMachine ()
 
std::string getName () const
 
template<typename SmaccClientType >
void requiresClient (SmaccClientType *&storage)
 
template<typename SmaccComponentType >
void requiresComponent (SmaccComponentType *&storage, ComponentRequirement requirementType=ComponentRequirement::SOFT)
 

Private Member Functions

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

Private Attributes

std::list< std::function< std::shared_ptr< smacc2::SmaccAsyncClientBehavior >()> > sequenceNodes_
 
smacc2::SmaccSignalConnection conn_
 
smacc2::SmaccSignalConnection 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 ()
 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 ()
 
ISmaccStategetCurrentState ()
 
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 this->conn_.disconnect();
80 this->conn2_.disconnect();
81
82 sequenceNodes_.pop_front();
83 consume_--;
84
85 if (sequenceNodes_.size() > 0)
86 {
88 }
89 }
90 }
91
92 if (sequenceNodes_.empty())
93 {
94 RCLCPP_INFO(getLogger(), "[CbSequence %ld] All subnodes finished", (long)this);
95 this->postSuccessEvent();
96 }
97 else
98 {
99 RCLCPP_INFO(getLogger(), "[CbSequence %ld] Aborting", (long)this);
100 this->postFailureEvent();
101 }
102}
virtual rclcpp::Logger getLogger() const
virtual rclcpp::Node::SharedPtr getNode() const
bool isShutdownRequested()
onEntry is executed in a new thread. However the current state cannot be left until the onEntry threa...
smacc2::SmaccSignalConnection conn_
smacc2::SmaccSignalConnection conn2_
std::list< std::function< std::shared_ptr< smacc2::SmaccAsyncClientBehavior >()> > sequenceNodes_
std::shared_ptr< smacc2::SmaccAsyncClientBehavior > bh_
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 38 of file cb_sequence.hpp.

38{ sequenceNodes_.clear(); }

References sequenceNodes_.

◆ onSubNodeAbort()

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

Definition at line 111 of file cb_sequence.cpp.

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

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 104 of file cb_sequence.cpp.

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

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 41 of file cb_sequence.hpp.

42 {
43 std::function<std::shared_ptr<smacc2::SmaccAsyncClientBehavior>()> delayedCBFactoryFn =
44 [this, args...]()
45 {
46 RCLCPP_INFO(
47 getLogger(), "[CbSequence] then creating new sub behavior %s ",
49 auto createdBh = std::shared_ptr<TBehavior>(new TBehavior(args...));
50
51 this->getCurrentState()->getOrthogonal<TOrthogonal>()->addClientBehavior(createdBh);
53
54 return createdBh;
55 };
56
57 sequenceNodes_.push_back(delayedCBFactoryFn);
58
59 return this;
60 }
TOrthogonal * getOrthogonal()
std::string demangleSymbol()

References smacc2::introspection::demangleSymbol(), smacc2::ISmaccClientBehavior::getCurrentState(), smacc2::ISmaccClientBehavior::getLogger(), smacc2::ISmaccState::getOrthogonal(), smacc2::SmaccAsyncClientBehavior::onStateOrthogonalAllocation(), 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 71 of file cb_sequence.hpp.

Referenced by onEntry(), and recursiveConsumeNext().

◆ conn2_

smacc2::SmaccSignalConnection smacc2::client_behaviors::CbSequence::conn2_
private

Definition at line 69 of file cb_sequence.hpp.

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

◆ conn_

smacc2::SmaccSignalConnection smacc2::client_behaviors::CbSequence::conn_
private

Definition at line 68 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 72 of file cb_sequence.hpp.

72{0};

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: