SMACC2
Loading...
Searching...
No Matches
smacc_state.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
23
24namespace smacc2
25{
26std::string ISmaccState::getClassName() { return demangleSymbol(typeid(*this).name()); }
27
29{
30 RCLCPP_INFO_STREAM(getLogger(), "TRANSITION RULE TRIGGERED: " << transitionType->getFullName());
31
32 auto currstateinfo = this->stateInfo_;
33
34 if (currstateinfo != nullptr)
35 {
36 //RCLCPP_ERROR_STREAM(getLogger(),"CURRENT STATE INFO: " << currstateinfo->fullStateName);
37 for (auto & transition : currstateinfo->transitions_)
38 {
39 std::string transitionCandidateName = transition.transitionTypeInfo->getFullName();
40 //RCLCPP_ERROR_STREAM(getLogger(),"candidate transition: " << transitionCandidateName);
41
42 if (transitionType->getFullName() == transitionCandidateName)
43 {
44 this->getStateMachine().publishTransition(transition);
45 return;
46 }
47 }
48
49 // debug information if not found
50 RCLCPP_ERROR_STREAM(
51 getLogger(),
52 "Transition happened, from current state "
53 << currstateinfo->getDemangledFullName()
54 << " but there is not any transitioninfo match available to publish transition: "
55 << transitionType->getFullName());
56 std::stringstream ss;
57
58 auto stateinfo = currstateinfo;
59
60 for (auto & transition : currstateinfo->transitions_)
61 {
62 std::string transitionCandidateName = transition.transitionTypeInfo->getFullName();
63 RCLCPP_ERROR_STREAM(getLogger(), "- candidate transition: " << transitionCandidateName);
64 }
65
66 RCLCPP_ERROR(getLogger(), "Ancestors candidates: ");
67
68 std::list<const SmaccStateInfo *> ancestors;
69 stateinfo->getAncestors(ancestors);
70
71 for (auto & ancestor : ancestors)
72 {
73 RCLCPP_ERROR_STREAM(getLogger(), " * Ancestor " << ancestor->getDemangledFullName() << ":");
74 for (auto & transition : ancestor->transitions_)
75 {
76 std::string transitionCandidateName = transition.transitionTypeInfo->getFullName();
77 RCLCPP_ERROR_STREAM(getLogger(), "- candidate transition: " << transitionCandidateName);
78 if (transitionType->getFullName() == transitionCandidateName)
79 {
80 RCLCPP_ERROR(getLogger(), "GOTCHA");
81 }
82 }
83 }
84 }
85 else
86 {
87 RCLCPP_ERROR_STREAM(
88 getLogger(), "Transition happened, but current state was not set. Transition candidates:");
89 }
90}
91
92} // namespace smacc2
void publishTransition(const SmaccTransitionInfo &transitionInfo)
rclcpp::Logger getLogger()
virtual std::string getClassName()
virtual ISmaccStateMachine & getStateMachine()=0
const smacc2::introspection::SmaccStateInfo * stateInfo_
void notifyTransitionFromTransitionTypeInfo(std::shared_ptr< smacc2::introspection::TypeInfo > &transitionTypeInfo)
std::shared_ptr< TypeInfo > Ptr
std::string demangleSymbol()