SMACC2
Loading...
Searching...
No Matches
smacc_state_machine_info.cpp
Go to the documentation of this file.
1// Copyright 2021 RobosoftAI Inc.
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15/*****************************************************************************************************************
16 *
17 * Authors: Pablo Inigo Blasco, Brett Aldrich
18 *
19 ******************************************************************************************************************/
20
23
24namespace smacc2
25{
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}
219} // namespace smacc2
const std::map< std::string, std::shared_ptr< smacc2::ISmaccOrthogonal > > & getOrthogonals() const
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::map< std::string, std::shared_ptr< SmaccStateInfo > > states
std::vector< smacc2_msgs::msg::SmaccState > stateMsgs
std::string demangleSymbol()
void transitionInfoToMsg(const SmaccTransitionInfo &transition, smacc2_msgs::msg::SmaccTransition &transitionMsg)
Definition: reflection.cpp:30