SMACC
Loading...
Searching...
No Matches
Public Member Functions | Public Attributes | List of all members
smacc::introspection::SmaccStateMachineInfo Class Reference

#include <smacc_state_machine_info.h>

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

Public Member Functions

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 ()
 
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< smacc_msgs::SmaccState > stateMsgs
 

Detailed Description

Definition at line 23 of file smacc_state_machine_info.h.

Member Function Documentation

◆ addState()

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

Definition at line 435 of file smacc_state_machine_info.h.

436{
437 states[state->fullStateName] = state;
438}
std::map< std::string, std::shared_ptr< SmaccStateInfo > > states

References states.

Referenced by createState().

Here is the caller graph for this function:

◆ assembleSMStructureMessage()

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

Definition at line 6 of file smacc_state_machine_info.cpp.

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

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

Here is the call graph for this function:

◆ buildStateMachineInfo()

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

Definition at line 404 of file smacc_state_machine_info.h.

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

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

Here is the call graph for this function:

◆ containsState()

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

Definition at line 37 of file smacc_state_machine_info.h.

38 {
39 auto typeNameStr = typeid(StateType).name();
40
41 return states.count(typeNameStr) > 0;
42 }

References states.

◆ createState()

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

Definition at line 411 of file smacc_state_machine_info.h.

412{
413 auto thisptr = this->shared_from_this();
414 auto *statetid = &(typeid(StateType));
415
416 auto demangledName = demangledTypeName<StateType>();
417 ROS_INFO_STREAM("Creating State Info: " << demangledName);
418
419 auto state = std::make_shared<SmaccStateInfo>(statetid, parent, thisptr);
420 state->demangledStateName = demangledName;
421 state->fullStateName = typeid(StateType).name();
422 state->stateIndex_ = states.size();
423
424 if (parent != nullptr)
425 {
426 parent->children_.push_back(state);
427 }
428
429 this->addState(state);
430
431 return state;
432}
void addState(std::shared_ptr< StateType > &state)

References addState(), and states.

Here is the call graph for this function:

◆ getState()

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

Definition at line 45 of file smacc_state_machine_info.h.

46 {
47 if (this->containsState<StateType>())
48 {
49 return states[typeid(StateType).name()];
50 }
51 return nullptr;
52 }

References states.

Member Data Documentation

◆ stateMsgs

std::vector<smacc_msgs::SmaccState> smacc::introspection::SmaccStateMachineInfo::stateMsgs

Definition at line 28 of file smacc_state_machine_info.h.

Referenced by assembleSMStructureMessage().

◆ states

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

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