SMACC2
Public Member Functions | Public Attributes | Private Attributes | List of all members
smacc2::introspection::SmaccStateMachineInfo Class Reference

#include <smacc_state_machine_info.hpp>

Inheritance diagram for smacc2::introspection::SmaccStateMachineInfo:
Inheritance graph
Collaboration diagram for smacc2::introspection::SmaccStateMachineInfo:
Collaboration graph

Public Member Functions

 SmaccStateMachineInfo (rclcpp::Node::SharedPtr nh)
 
template<typename InitialStateType >
void buildStateMachineInfo ()
 
template<typename StateType >
std::shared_ptr< SmaccStateInfocreateState (std::shared_ptr< SmaccStateInfo > parentState)
 
template<typename StateType >
bool containsState ()
 
template<typename StateType >
std::shared_ptr< SmaccStateInfogetState ()
 
rclcpp::Node::SharedPtr getNode ()
 
rclcpp::Logger getLogger ()
 
template<typename StateType >
void addState (std::shared_ptr< StateType > &state)
 
void assembleSMStructureMessage (ISmaccStateMachine *sm)
 

Public Attributes

std::map< std::string, std::shared_ptr< SmaccStateInfo > > states
 
std::vector< smacc2_msgs::msg::SmaccState > stateMsgs
 

Private Attributes

rclcpp::Node::SharedPtr nh_
 

Detailed Description

Definition at line 44 of file smacc_state_machine_info.hpp.

Constructor & Destructor Documentation

◆ SmaccStateMachineInfo()

smacc2::introspection::SmaccStateMachineInfo::SmaccStateMachineInfo ( rclcpp::Node::SharedPtr  nh)
inlineexplicit

Definition at line 47 of file smacc_state_machine_info.hpp.

Member Function Documentation

◆ addState()

template<typename StateType >
void smacc2::introspection::SmaccStateMachineInfo::addState ( std::shared_ptr< StateType > &  state)

Definition at line 499 of file smacc_state_machine_info.hpp.

500{
501 states[state->fullStateName] = state;
502}
std::map< std::string, std::shared_ptr< SmaccStateInfo > > states

References states.

Referenced by createState().

Here is the caller graph for this function:

◆ assembleSMStructureMessage()

void smacc2::SmaccStateMachineInfo::assembleSMStructureMessage ( ISmaccStateMachine sm)

Definition at line 26 of file smacc_state_machine_info.cpp.

27{
28 std::stringstream ss;
29
30 ss << "----------- PRINT STATE MACHINE STRUCTURE -------------------" << std::endl;
31 stateMsgs.clear();
32 for (auto & val : this->states)
33 {
34 smacc2_msgs::msg::SmaccState stateMsg;
35 auto state = val.second;
36 stateMsg.index = state->stateIndex_;
37
38 ss << "**** State: " << demangleSymbol(val.first.c_str()) << std::endl;
39
40 stateMsg.name = state->getDemangledFullName();
41 stateMsg.level = (int)state->getStateLevel();
42
43 ss << "Index: " << stateMsg.index << std::endl;
44 ss << "StateLevel: " << stateMsg.level << std::endl;
45
46 ss << " Childstates:" << std::endl;
47
48 for (auto & child : state->children_)
49 {
50 auto childStateName = child->getDemangledFullName();
51 stateMsg.children_states.push_back(childStateName);
52
53 ss << " - " << childStateName << std::endl;
54 }
55
56 ss << " Transitions:" << std::endl;
57
58 for (auto & transition : state->transitions_)
59 {
60 smacc2_msgs::msg::SmaccTransition transitionMsg;
61
62 transitionInfoToMsg(transition, transitionMsg);
63
64 ss << " - Transition. " << std::endl;
65 ss << " - Index: " << transitionMsg.index << std::endl;
66 ss << " - Transition Name: " << transitionMsg.transition_name << std::endl;
67 ss << " - Transition Type: " << transitionMsg.transition_type << std::endl;
68 ss << " - Event Type :" << transitionMsg.event.event_type << std::endl;
69 ss << " - Event Source: " << transitionMsg.event.event_source << std::endl;
70 ss << " - Event ObjectTag: " << transitionMsg.event.event_object_tag << std::endl;
71 ss << " - Event Label: " << transitionMsg.event.label << std::endl;
72 ss << " - Destiny State: " << transitionMsg.destiny_state_name << std::endl;
73 ss << " - Owner State: " << transitionMsg.destiny_state_name << std::endl;
74 ss << " - Is History Node: " << std::to_string(transitionMsg.history_node) << std::endl;
75 ss << " - TransitionC++Type: " << transition.transitionTypeInfo->getFullName()
76 << std::endl;
77 ss << " - EventC++Type: " << transition.eventInfo->eventType->getFullName() << std::endl;
78
79 stateMsg.transitions.push_back(transitionMsg);
80 }
81
82 const std::type_info * statetid = state->tid_;
83
84 std::map<const std::type_info *, std::vector<smacc2::ClientBehaviorInfoEntry *>>
85 smaccBehaviorInfoMappingByOrthogonalType;
86
87 ss << " Orthogonals:" << std::endl;
88 if (SmaccStateInfo::staticBehaviorInfo.count(statetid) > 0)
89 {
90 for (auto & bhinfo : SmaccStateInfo::staticBehaviorInfo[statetid])
91 {
92 if (smaccBehaviorInfoMappingByOrthogonalType.count(bhinfo.orthogonalType) == 0)
93 {
94 smaccBehaviorInfoMappingByOrthogonalType[bhinfo.orthogonalType] =
95 std::vector<smacc2::ClientBehaviorInfoEntry *>();
96 }
97
98 smaccBehaviorInfoMappingByOrthogonalType[bhinfo.orthogonalType].push_back(&bhinfo);
99 }
100 }
101
102 auto & runtimeOrthogonals = sm->getOrthogonals();
103
104 for (auto & orthogonal : runtimeOrthogonals)
105 {
106 smacc2_msgs::msg::SmaccOrthogonal orthogonalMsg;
107
108 const auto * orthogonaltid = &typeid(*(orthogonal.second));
109 orthogonalMsg.name = demangleSymbol(orthogonaltid->name());
110
111 ss << " - orthogonal: " << orthogonalMsg.name << std::endl;
112
113 if (smaccBehaviorInfoMappingByOrthogonalType[orthogonaltid].size() > 0)
114 {
115 auto & behaviors = smaccBehaviorInfoMappingByOrthogonalType[orthogonaltid];
116 for (auto & bhinfo : behaviors)
117 {
118 auto ClientBehaviorName = demangleSymbol(bhinfo->behaviorType->name());
119 orthogonalMsg.client_behavior_names.push_back(ClientBehaviorName);
120 ss << " - client behavior: " << ClientBehaviorName << std::endl;
121 }
122 }
123 else
124 {
125 ss << " - NO CLIENT BEHAVIORS -" << std::endl;
126 }
127
128 auto & clients = orthogonal.second->getClients();
129 if (clients.size() > 0)
130 {
131 for (auto & client : clients)
132 {
133 auto clientTid = client->getType();
134 auto clientName = clientTid->getNonTemplatedTypeName();
135 orthogonalMsg.client_names.push_back(clientName);
136 ss << " - client: " << clientName << std::endl;
137 }
138 }
139 else
140 {
141 ss << " - NO CLIENTS - " << std::endl;
142 }
143 stateMsg.orthogonals.push_back(orthogonalMsg);
144 }
145
146 ss << " State event generators:" << std::endl;
147 if (SmaccStateInfo::eventGeneratorsInfo.count(statetid) > 0)
148 {
149 int k = 0;
150 for (auto & eginfo : SmaccStateInfo::eventGeneratorsInfo[statetid])
151 {
152 smacc2_msgs::msg::SmaccEventGenerator eventGeneratorMsg;
153 eventGeneratorMsg.index = k++;
154 eventGeneratorMsg.type_name = eginfo->eventGeneratorType->getFullName();
155
156 ss << " - event generator: " << eventGeneratorMsg.type_name << std::endl;
157 if (eginfo->objectTagType != nullptr)
158 {
159 eventGeneratorMsg.object_tag = eginfo->objectTagType->getFullName();
160 ss << " - object tag: " << eventGeneratorMsg.object_tag << std::endl;
161 }
162 stateMsg.event_generators.push_back(eventGeneratorMsg);
163 }
164 }
165
166 ss << " State reactors:" << std::endl;
167 if (SmaccStateInfo::stateReactorsInfo.count(statetid) > 0)
168 {
169 int k = 0;
170 for (auto & srinfo : SmaccStateInfo::stateReactorsInfo[statetid])
171 {
172 smacc2_msgs::msg::SmaccStateReactor stateReactorMsg;
173 stateReactorMsg.index = k++;
174 stateReactorMsg.type_name = srinfo->stateReactorType->getFullName();
175
176 ss << " - state reactor: " << stateReactorMsg.type_name << std::endl;
177 if (srinfo->objectTagType != nullptr)
178 {
179 stateReactorMsg.object_tag = srinfo->objectTagType->getFullName();
180 ss << " - object tag: " << stateReactorMsg.object_tag << std::endl;
181 }
182
183 for (auto & tev : srinfo->sourceEventTypes)
184 {
185 // WE SHOULD CREATE A SMACC_EVENT_INFO TYPE, also using in typewalker transition
186 auto eventTypeName = tev->getEventTypeName();
187 smacc2_msgs::msg::SmaccEvent event;
188
189 ss << " - triggering event: " << tev->getEventTypeName() << std::endl;
190 event.event_type = eventTypeName;
191
192 event.event_source = tev->getEventSourceName();
193 ss << " - source type: " << event.event_source << std::endl;
194
195 event.event_object_tag = tev->getOrthogonalName();
196 ss << " - source object: " << event.event_object_tag << std::endl;
197
198 event.label = tev->label;
199 ss << " - event label: " << event.label << std::endl;
200
201 stateReactorMsg.event_sources.push_back(event);
202 }
203
204 stateMsg.state_reactors.push_back(stateReactorMsg);
205 }
206 }
207 else
208 {
209 ss << "- NO STATE REACTORS - " << std::endl;
210 }
211
212 ss << "----------------------------------------------------------" << std::endl;
213
214 auto resumeMsg = ss.str();
215 RCLCPP_INFO(getLogger(), "%s", resumeMsg.c_str());
216 stateMsgs.push_back(stateMsg);
217 }
218}
static std::map< const std::type_info *, std::vector< std::shared_ptr< SmaccStateReactorInfo > > > stateReactorsInfo
static std::map< const std::type_info *, std::vector< std::shared_ptr< SmaccEventGeneratorInfo > > > eventGeneratorsInfo
static std::map< const std::type_info *, std::vector< ClientBehaviorInfoEntry > > staticBehaviorInfo
std::vector< smacc2_msgs::msg::SmaccState > stateMsgs
std::string demangleSymbol(const std::string &name)
void transitionInfoToMsg(const SmaccTransitionInfo &transition, smacc2_msgs::msg::SmaccTransition &transitionMsg)
Definition: reflection.cpp:30

References smacc2::introspection::demangleSymbol(), smacc2::introspection::SmaccStateInfo::eventGeneratorsInfo, getLogger(), smacc2::ISmaccStateMachine::getOrthogonals(), stateMsgs, smacc2::introspection::SmaccStateInfo::stateReactorsInfo, states, smacc2::introspection::SmaccStateInfo::staticBehaviorInfo, and smacc2::introspection::transitionInfoToMsg().

Here is the call graph for this function:

◆ buildStateMachineInfo()

template<typename InitialStateType >
void smacc2::introspection::SmaccStateMachineInfo::buildStateMachineInfo

Definition at line 467 of file smacc_state_machine_info.hpp.

468{
469 auto initialState = this->createState<InitialStateType>(nullptr);
471}
static void walkStates(std::shared_ptr< SmaccStateInfo > &currentState, bool rootInitialNode)

References smacc2::introspection::WalkStatesExecutor< InitialStateType >::walkStates().

Here is the call graph for this function:

◆ containsState()

template<typename StateType >
bool smacc2::introspection::SmaccStateMachineInfo::containsState ( )
inline

Definition at line 60 of file smacc_state_machine_info.hpp.

61 {
62 auto typeNameStr = typeid(StateType).name();
63
64 return states.count(typeNameStr) > 0;
65 }

References states.

◆ createState()

template<typename StateType >
std::shared_ptr< SmaccStateInfo > smacc2::introspection::SmaccStateMachineInfo::createState ( std::shared_ptr< SmaccStateInfo parentState)

Definition at line 474 of file smacc_state_machine_info.hpp.

476{
477 auto thisptr = this->shared_from_this();
478 auto * statetid = &(typeid(StateType));
479
480 auto demangledName = demangledTypeName<StateType>();
481 RCLCPP_INFO_STREAM(getLogger(), "Creating State Info: " << demangledName);
482
483 auto state = std::make_shared<SmaccStateInfo>(statetid, parent, thisptr);
484 state->demangledStateName = demangledName;
485 state->fullStateName = typeid(StateType).name();
486 state->stateIndex_ = states.size();
487
488 if (parent != nullptr)
489 {
490 parent->children_.push_back(state);
491 }
492
493 this->addState(state);
494
495 return state;
496}
void addState(std::shared_ptr< StateType > &state)

References addState(), getLogger(), and states.

Here is the call graph for this function:

◆ getLogger()

rclcpp::Logger smacc2::introspection::SmaccStateMachineInfo::getLogger ( )
inline

Definition at line 79 of file smacc_state_machine_info.hpp.

79{ return nh_->get_logger(); }

References nh_.

Referenced by assembleSMStructureMessage(), and createState().

Here is the caller graph for this function:

◆ getNode()

rclcpp::Node::SharedPtr smacc2::introspection::SmaccStateMachineInfo::getNode ( )
inline

Definition at line 77 of file smacc_state_machine_info.hpp.

77{ return nh_; }

References nh_.

◆ getState()

template<typename StateType >
std::shared_ptr< SmaccStateInfo > smacc2::introspection::SmaccStateMachineInfo::getState ( )
inline

Definition at line 68 of file smacc_state_machine_info.hpp.

69 {
70 if (this->containsState<StateType>())
71 {
72 return states[typeid(StateType).name()];
73 }
74 return nullptr;
75 }

References states.

Member Data Documentation

◆ nh_

rclcpp::Node::SharedPtr smacc2::introspection::SmaccStateMachineInfo::nh_
private

Definition at line 86 of file smacc_state_machine_info.hpp.

Referenced by getLogger(), and getNode().

◆ stateMsgs

std::vector<smacc2_msgs::msg::SmaccState> smacc2::introspection::SmaccStateMachineInfo::stateMsgs

Definition at line 51 of file smacc_state_machine_info.hpp.

Referenced by assembleSMStructureMessage().

◆ states

std::map<std::string, std::shared_ptr<SmaccStateInfo> > smacc2::introspection::SmaccStateMachineInfo::states

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