SMACC2
Loading...
Searching...
No Matches
smacc2::ISmaccOrthogonal Class Reference

#include <smacc_orthogonal.hpp>

Inheritance diagram for smacc2::ISmaccOrthogonal:
Inheritance graph
Collaboration diagram for smacc2::ISmaccOrthogonal:
Collaboration graph

Public Member Functions

 ISmaccOrthogonal ()=default
 
virtual ~ISmaccOrthogonal ()=default
 
 ISmaccOrthogonal (const ISmaccOrthogonal &)=delete
 
ISmaccOrthogonal & operator= (const ISmaccOrthogonal &)=delete
 
 ISmaccOrthogonal (ISmaccOrthogonal &&)=delete
 
ISmaccOrthogonal & operator= (ISmaccOrthogonal &&)=delete
 
void setStateMachine (ISmaccStateMachine *value)
 
ISmaccStateMachine * getStateMachine ()
 
void initState (ISmaccState *state)
 
void addClientBehavior (std::shared_ptr< smacc2::ISmaccClientBehavior > clBehavior)
 
void runtimeConfigure ()
 
void onEntry ()
 
void onExit ()
 
void onDispose ()
 
virtual std::string getName () const
 
template<typename SmaccComponentType >
void requiresComponent (SmaccComponentType *&storage)
 
template<typename SmaccClientType >
bool requiresClient (SmaccClientType *&storage)
 
const std::vector< std::shared_ptr< smacc2::ISmaccClient > > & getClients ()
 
const std::vector< std::vector< std::shared_ptr< smacc2::ISmaccClientBehavior > > > & getClientBehaviors () const
 
template<typename T >
void setGlobalSMData (const std::string &name, T value)
 
template<typename T >
bool getGlobalSMData (const std::string &name, T &ret)
 
template<typename TClientBehavior >
TClientBehavior * getClientBehavior (int index=0)
 
rclcpp::Node::SharedPtr getNode ()
 
rclcpp::Logger getLogger ()
 

Protected Member Functions

virtual void onInitialize ()
 
void initializeClients ()
 
template<typename TOrthogonal , typename TClient >
void assignClientToOrthogonal (TClient *client)
 

Protected Attributes

std::vector< std::shared_ptr< smacc2::ISmaccClient > > clients_
 

Private Member Functions

std::vector< std::shared_ptr< smacc2::ISmaccClientBehavior > > currentClientBehaviors ()
 

Private Attributes

ISmaccStateMachine * stateMachine_ = nullptr
 
std::vector< std::vector< std::shared_ptr< smacc2::ISmaccClientBehavior > > > clientBehaviors_
 
std::mutex mutex_
 

Friends

class ISmaccStateMachine
 

Detailed Description

Definition at line 27 of file smacc_orthogonal.hpp.

Constructor & Destructor Documentation

◆ ISmaccOrthogonal() [1/3]

smacc2::ISmaccOrthogonal::ISmaccOrthogonal ( )
default

◆ ~ISmaccOrthogonal()

virtual smacc2::ISmaccOrthogonal::~ISmaccOrthogonal ( )
virtualdefault

◆ ISmaccOrthogonal() [2/3]

smacc2::ISmaccOrthogonal::ISmaccOrthogonal ( const ISmaccOrthogonal & )
delete

◆ ISmaccOrthogonal() [3/3]

smacc2::ISmaccOrthogonal::ISmaccOrthogonal ( ISmaccOrthogonal && )
delete

Member Function Documentation

◆ addClientBehavior()

void smacc2::ISmaccOrthogonal::addClientBehavior ( std::shared_ptr< smacc2::ISmaccClientBehavior > clBehavior)

Definition at line 49 of file orthogonal.cpp.

50{
51 std::lock_guard<std::mutex> lock(this->mutex_);
52
53 if (clBehavior != nullptr)
54 {
55 RCLCPP_INFO(
56 getLogger(), "[Orthogonal: %s] Adding client behavior: %s.", this->getName().c_str(),
57 clBehavior->getName().c_str());
58 clBehavior->stateMachine_ = this->getStateMachine();
59 clBehavior->currentOrthogonal = this;
60 clBehavior->currentState = clBehavior->stateMachine_->getCurrentState();
61
62 clientBehaviors_.back().push_back(clBehavior);
63 }
64 else
65 {
66 RCLCPP_INFO(
67 getLogger(), "[Orthogonal: %s] No client behaviors in this state.", this->getName().c_str());
68 }
69}
ISmaccStateMachine * getStateMachine()
std::vector< std::vector< std::shared_ptr< smacc2::ISmaccClientBehavior > > > clientBehaviors_
virtual std::string getName() const

References clientBehaviors_, getLogger(), getName(), getStateMachine(), and mutex_.

Here is the call graph for this function:

◆ assignClientToOrthogonal()

template<typename TOrthogonal , typename TClient >
void smacc2::ISmaccOrthogonal::assignClientToOrthogonal ( TClient * client)
protected

Definition at line 83 of file smacc_orthogonal_impl.hpp.

84{
85 client->setStateMachine(getStateMachine());
86 client->setOrthogonal(this);
87
88 client->template onStateOrthogonalAllocation<TOrthogonal, TClient>();
89}

References getStateMachine().

Referenced by smacc2::Orthogonal< TOrthogonal >::createClient().

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

◆ currentClientBehaviors()

std::vector< std::shared_ptr< smacc2::ISmaccClientBehavior > > smacc2::ISmaccOrthogonal::currentClientBehaviors ( )
private

Definition at line 88 of file orthogonal.cpp.

89{
90 std::lock_guard<std::mutex> lock(this->mutex_);
91 return clientBehaviors_.back();
92}

References clientBehaviors_, and mutex_.

Referenced by onEntry(), onExit(), and runtimeConfigure().

Here is the caller graph for this function:

◆ getClientBehavior()

template<typename TClientBehavior >
TClientBehavior * smacc2::ISmaccOrthogonal::getClientBehavior ( int index = 0)

Definition at line 92 of file smacc_orthogonal_impl.hpp.

93{
94 int i = 0;
95 for (auto & cb : this->clientBehaviors_.back())
96 {
97 auto * ret = dynamic_cast<TClientBehavior *>(cb.get());
98 if (ret != nullptr)
99 {
100 if (i == index)
101 return ret;
102 else
103 i++;
104 }
105 }
106
107 return nullptr;
108}

References clientBehaviors_.

◆ getClientBehaviors()

const std::vector< std::vector< std::shared_ptr< smacc2::ISmaccClientBehavior > > > & smacc2::ISmaccOrthogonal::getClientBehaviors ( ) const
inline

Definition at line 115 of file smacc_orthogonal_impl.hpp.

116{
117 return this->clientBehaviors_;
118}

References clientBehaviors_.

◆ getClients()

const std::vector< std::shared_ptr< smacc2::ISmaccClient > > & smacc2::ISmaccOrthogonal::getClients ( )
inline

Definition at line 109 of file smacc_orthogonal_impl.hpp.

110{
111 return clients_;
112}
std::vector< std::shared_ptr< smacc2::ISmaccClient > > clients_

References clients_.

◆ getGlobalSMData()

template<typename T >
bool smacc2::ISmaccOrthogonal::getGlobalSMData ( const std::string & name,
T & ret )

Definition at line 127 of file smacc_orthogonal_impl.hpp.

128{
129 return this->getStateMachine()->getGlobalSMData(name, ret);
130}
bool getGlobalSMData(const std::string &name, T &ret)

References smacc2::ISmaccStateMachine::getGlobalSMData(), and getStateMachine().

Here is the call graph for this function:

◆ getLogger()

rclcpp::Logger smacc2::ISmaccOrthogonal::getLogger ( )
inline

Definition at line 81 of file smacc_orthogonal.hpp.

81{ return getNode()->get_logger(); }
rclcpp::Node::SharedPtr getNode()

References getNode().

Referenced by addClientBehavior(), smacc2::Orthogonal< TOrthogonal >::createClient(), initState(), onEntry(), onExit(), requiresClient(), requiresComponent(), and runtimeConfigure().

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

◆ getName()

std::string smacc2::ISmaccOrthogonal::getName ( ) const
virtual

Definition at line 81 of file orthogonal.cpp.

81{ return demangleSymbol(typeid(*this).name()); }
std::string demangleSymbol()

References smacc2::introspection::demangleSymbol().

Referenced by addClientBehavior(), smacc2::ISmaccClientBehavior::getTraceOrthogonalName(), initState(), and runtimeConfigure().

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

◆ getNode()

rclcpp::Node::SharedPtr smacc2::ISmaccOrthogonal::getNode ( )

Definition at line 47 of file orthogonal.cpp.

47{ return this->stateMachine_->getNode(); }
ISmaccStateMachine * stateMachine_
rclcpp::Node::SharedPtr getNode()

References smacc2::ISmaccStateMachine::getNode(), and stateMachine_.

Referenced by getLogger().

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

◆ getStateMachine()

ISmaccStateMachine * smacc2::ISmaccOrthogonal::getStateMachine ( )
inline

Definition at line 133 of file smacc_orthogonal_impl.hpp.

133{ return this->stateMachine_; }

References stateMachine_.

Referenced by addClientBehavior(), assignClientToOrthogonal(), getGlobalSMData(), onDispose(), requiresClient(), and setGlobalSMData().

Here is the caller graph for this function:

◆ initializeClients()

void smacc2::ISmaccOrthogonal::initializeClients ( )
protected

Definition at line 39 of file orthogonal.cpp.

40{
41 for (auto & c : this->clients_)
42 {
43 c->initialize();
44 }
45}

References clients_.

Referenced by setStateMachine().

Here is the caller graph for this function:

◆ initState()

void smacc2::ISmaccOrthogonal::initState ( ISmaccState * state)

Definition at line 73 of file orthogonal.cpp.

74{
75 RCLCPP_INFO(
76 getLogger(), "[Orthogonal: %s] InitState: %s.", this->getName().c_str(),
77 state->getClassName().c_str());
78 clientBehaviors_.push_back(std::vector<std::shared_ptr<smacc2::ISmaccClientBehavior>>());
79}

References clientBehaviors_, smacc2::ISmaccState::getClassName(), getLogger(), and getName().

Here is the call graph for this function:

◆ onDispose()

void smacc2::ISmaccOrthogonal::onDispose ( )

Definition at line 192 of file orthogonal.cpp.

193{
194 for (auto & clBehavior : clientBehaviors_.back())
195 {
196 clBehavior->dispose();
197 // No cast: the typed overload normalizes the key to the complete object's address.
198 this->getStateMachine()->disconnectSmaccSignalObject(clBehavior.get());
199 }
200
201 clientBehaviors_.back().clear();
202 clientBehaviors_.pop_back();
203}
void disconnectSmaccSignalObject(void *object_ptr)

References clientBehaviors_, smacc2::ISmaccStateMachine::disconnectSmaccSignalObject(), and getStateMachine().

Here is the call graph for this function:

◆ onEntry()

void smacc2::ISmaccOrthogonal::onEntry ( )

Definition at line 121 of file orthogonal.cpp.

122{
123 const auto behaviors = this->currentClientBehaviors();
124
125 if (behaviors.size() > 0)
126 {
127 for (auto & clBehavior : behaviors)
128 {
129 RCLCPP_INFO(
130 getLogger(), "[Orthogonal: %s] OnEntry, current Behavior: %s", orthogonalName, cbName);
131
132 try
133 {
134 TRACETOOLS_TRACEPOINT(
136 clBehavior->executeOnEntry();
137 }
138 catch (const std::exception & e)
139 {
140 RCLCPP_ERROR(
141 getLogger(),
142 "[ClientBehavior: %s] Exception on Entry - continuing with next client behavior. "
143 "Exception info: "
144 "%s",
145 cbName, e.what());
146 clBehavior->postInitializationFailureEvent(e.what());
147 }
149 }
150 }
151 else
152 {
153 RCLCPP_INFO(
154 getLogger(), "[Orthogonal: %s] OnEntry -> empty orthogonal (no client behavior).",
156 }
157}
std::vector< std::shared_ptr< smacc2::ISmaccClientBehavior > > currentClientBehaviors()
#define orthogonalName
#define statename
#define cbName
smacc2_client_behavior_on_entry_start
smacc2_client_behavior_on_entry_end

References cbName, currentClientBehaviors(), getLogger(), orthogonalName, smacc2_client_behavior_on_entry_end, smacc2_client_behavior_on_entry_start, and statename.

Here is the call graph for this function:

◆ onExit()

void smacc2::ISmaccOrthogonal::onExit ( )

Definition at line 159 of file orthogonal.cpp.

160{
161 const auto behaviors = this->currentClientBehaviors();
162
163 if (behaviors.size() > 0)
164 {
165 for (auto & clBehavior : behaviors)
166 {
167 RCLCPP_INFO(
168 getLogger(), "[Orthogonal: %s] OnExit, current Behavior: %s", orthogonalName, cbName);
169 try
170 {
171 TRACETOOLS_TRACEPOINT(
173 clBehavior->executeOnExit();
174 }
175 catch (const std::exception & e)
176 {
177 RCLCPP_ERROR(
178 getLogger(),
179 "[ClientBehavior: %s] Exception onExit - continuing with next client behavior. Exception "
180 "info: %s",
181 cbName, e.what());
182 }
184 }
185 }
186 else
187 {
188 RCLCPP_INFO(getLogger(), "[Orthogonal %s] OnExit().", orthogonalName);
189 }
190}
smacc2_client_behavior_on_exit_end
smacc2_client_behavior_on_exit_start

References cbName, currentClientBehaviors(), getLogger(), orthogonalName, smacc2_client_behavior_on_exit_end, smacc2_client_behavior_on_exit_start, and statename.

Here is the call graph for this function:

◆ onInitialize()

void smacc2::ISmaccOrthogonal::onInitialize ( )
protectedvirtual

Definition at line 71 of file orthogonal.cpp.

71{}

Referenced by setStateMachine().

Here is the caller graph for this function:

◆ operator=() [1/2]

ISmaccOrthogonal & smacc2::ISmaccOrthogonal::operator= ( const ISmaccOrthogonal & )
delete

◆ operator=() [2/2]

ISmaccOrthogonal & smacc2::ISmaccOrthogonal::operator= ( ISmaccOrthogonal && )
delete

◆ requiresClient()

template<typename SmaccClientType >
bool smacc2::ISmaccOrthogonal::requiresClient ( SmaccClientType *& storage)

Definition at line 30 of file smacc_orthogonal_impl.hpp.

31{
32 for (auto & client : clients_)
33 {
34 storage = dynamic_cast<SmaccClientType *>(client.get());
35 if (storage != nullptr) return true;
36 }
37
38 auto requiredClientName = demangledTypeName<SmaccClientType>();
39 RCLCPP_WARN_STREAM(
40 getLogger(), "Required client ["
41 << requiredClientName
42 << "] not found in current orthogonal. Searching in other orthogonals.");
43
44 for (auto & orthoentry : this->getStateMachine()->getOrthogonals())
45 {
46 for (auto & client : orthoentry.second->getClients())
47 {
48 storage = dynamic_cast<SmaccClientType *>(client.get());
49 if (storage != nullptr)
50 {
51 RCLCPP_WARN_STREAM(
52 getLogger(),
53 "Required client [" << requiredClientName << "] found in other orthogonal.");
54 return true;
55 }
56 }
57 }
58
59 RCLCPP_ERROR_STREAM(
60 getLogger(), "Required client ["
61 << requiredClientName
62 << "] not found even in other orthogonals. Returning null pointer. If the "
63 "requested client is used may result in a segmentation fault.");
64 return false;
65}
std::string demangledTypeName()

References clients_, smacc2::introspection::demangledTypeName(), getLogger(), and getStateMachine().

Referenced by smacc2::ISmaccClient::requiresClient(), and smacc2::ISmaccClientBehavior::requiresClient().

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

◆ requiresComponent()

template<typename SmaccComponentType >
void smacc2::ISmaccOrthogonal::requiresComponent ( SmaccComponentType *& storage)

Definition at line 68 of file smacc_orthogonal_impl.hpp.

69{
70 if (stateMachine_ == nullptr)
71 {
72 RCLCPP_ERROR(
73 getLogger(),
74 "Cannot use the requiresComponent functionality from an orthogonal before onInitialize");
75 }
76 else
77 {
79 }
80}
void requiresComponent(SmaccComponentType *&storage, ComponentRequirement requirementType, ISmaccOrthogonal *first=nullptr)

References getLogger(), smacc2::ISmaccStateMachine::requiresComponent(), smacc2::SOFT, and stateMachine_.

Here is the call graph for this function:

◆ runtimeConfigure()

void smacc2::ISmaccOrthogonal::runtimeConfigure ( )

Definition at line 94 of file orthogonal.cpp.

95{
96 const auto behaviors = this->currentClientBehaviors();
97
98 for (auto & clBehavior : behaviors)
99 {
100 RCLCPP_INFO(
101 getLogger(), "[Orthogonal: %s] runtimeConfigure(), current behavior: %s.",
102 this->getName().c_str(), clBehavior->getName().c_str());
103
104 try
105 {
106 clBehavior->runtimeConfigure();
107 }
108 catch (const std::exception & e)
109 {
110 RCLCPP_ERROR(
111 getLogger(),
112 "[ClientBehavior: %s] Exception in runtimeConfigure - continuing with next client "
113 "behavior. "
114 "Exception info: %s",
115 clBehavior->getName().c_str(), e.what());
116 clBehavior->postInitializationFailureEvent(e.what());
117 }
118 }
119}

References currentClientBehaviors(), getLogger(), and getName().

Here is the call graph for this function:

◆ setGlobalSMData()

template<typename T >
void smacc2::ISmaccOrthogonal::setGlobalSMData ( const std::string & name,
T value )

Definition at line 121 of file smacc_orthogonal_impl.hpp.

122{
123 this->getStateMachine()->setGlobalSMData(name, value);
124}
void setGlobalSMData(const std::string &name, T value)

References getStateMachine(), and smacc2::ISmaccStateMachine::setGlobalSMData().

Here is the call graph for this function:

◆ setStateMachine()

void smacc2::ISmaccOrthogonal::setStateMachine ( ISmaccStateMachine * value)

Definition at line 32 of file orthogonal.cpp.

33{
34 this->stateMachine_ = value;
35 this->onInitialize();
36 this->initializeClients();
37}
virtual void onInitialize()

References initializeClients(), onInitialize(), and stateMachine_.

Here is the call graph for this function:

Friends And Related Symbol Documentation

◆ ISmaccStateMachine

friend class ISmaccStateMachine
friend

Definition at line 98 of file smacc_orthogonal.hpp.

Member Data Documentation

◆ clientBehaviors_

std::vector<std::vector<std::shared_ptr<smacc2::ISmaccClientBehavior> > > smacc2::ISmaccOrthogonal::clientBehaviors_
private

◆ clients_

◆ mutex_

std::mutex smacc2::ISmaccOrthogonal::mutex_
private

Definition at line 107 of file smacc_orthogonal.hpp.

Referenced by addClientBehavior(), and currentClientBehaviors().

◆ stateMachine_

ISmaccStateMachine* smacc2::ISmaccOrthogonal::stateMachine_ = nullptr
private

Definition at line 95 of file smacc_orthogonal.hpp.

Referenced by getNode(), getStateMachine(), requiresComponent(), and setStateMachine().


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