SMACC2
Loading...
Searching...
No Matches
reflection.cpp
Go to the documentation of this file.
1// Copyright 2025 Robosoft 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
22#include "rclcpp/rclcpp.hpp"
23
24namespace smacc2
25{
26namespace introspection
27{
28rclcpp::Node::SharedPtr globalNh_;
29
31 const SmaccTransitionInfo & transition, smacc2_msgs::msg::SmaccTransition & transitionMsg)
32{
33 transitionMsg.index = transition.index;
34
35 // The transition holds its states weakly (see smacc_state_info.hpp). An expired pointer leaves
36 // the name empty, as a null pointer did before.
37 auto sourceState = transition.sourceState.lock();
38 if (sourceState != nullptr)
39 {
40 transitionMsg.source_state_name = sourceState->demangledStateName;
41 }
42
43 transitionMsg.transition_name = transition.transitionTag;
44 transitionMsg.transition_type = transition.transitionType;
45
46 if (transition.eventInfo != nullptr)
47 {
48 transitionMsg.event.event_type = transition.eventInfo->getEventTypeName();
49 transitionMsg.event.event_source = transition.eventInfo->getEventSourceName();
50 transitionMsg.event.event_object_tag = transition.eventInfo->getOrthogonalName();
51 transitionMsg.event.label = transition.eventInfo->label;
52 }
53
54 transitionMsg.history_node = transition.historyNode;
55
56 auto destinyState = transition.destinyState.lock();
57 if (destinyState == nullptr)
58 {
59 transitionMsg.destiny_state_name = "";
60 }
61 else if (transition.historyNode)
62 {
63 auto destinyParent = destinyState->getParentState();
64 if (destinyParent != nullptr)
65 {
66 transitionMsg.destiny_state_name = destinyParent->demangledStateName;
67 }
68 else
69 {
70 transitionMsg.destiny_state_name = "";
71 }
72 }
73 else
74 {
75 transitionMsg.destiny_state_name = destinyState->demangledStateName;
76 }
77}
78} // namespace introspection
79} // namespace smacc2
rclcpp::Node::SharedPtr globalNh_
void transitionInfoToMsg(const SmaccTransitionInfo &transition, smacc2_msgs::msg::SmaccTransition &transitionMsg)
std::weak_ptr< const SmaccStateInfo > sourceState
std::shared_ptr< SmaccEventInfo > eventInfo
std::weak_ptr< const SmaccStateInfo > destinyState