SMACC2
Loading...
Searching...
No Matches
smacc_component_impl.hpp
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
21#pragma once
22
23#include <string>
24
25#include <smacc2/component.hpp>
27
28namespace smacc2
29{
30template <typename EventType>
31void ISmaccComponent::postEvent(const EventType & ev)
32{
34}
35
36template <typename EventType>
41
42template <typename TComponent>
44 TComponent *& requiredComponentStorage, ComponentRequirement requirementType)
45{
46 requiredComponentStorage = this->owner_->getComponent<TComponent>();
47
48 if (requiredComponentStorage == nullptr && requirementType == ComponentRequirement::HARD)
49 {
50 RCLCPP_DEBUG_STREAM(
51 this->getLogger(), std::string("Required component ") +
52 demangleSymbol(typeid(TComponent).name()) +
53 " not found. Available components:");
54
55 std::vector<std::shared_ptr<ISmaccComponent>> components;
56 this->owner_->getComponents(components);
57
58 for (auto c : components)
59 {
60 RCLCPP_DEBUG(this->getLogger(), "- Component %s", c->getName().c_str());
61 }
62
63 throw std::runtime_error(
64 std::string("Component ") + demangleSymbol(typeid(TComponent).name()) + " not found");
65 }
66}
67
68template <typename TComponent>
70 const std::string & name, TComponent *& requiredComponentStorage,
71 ComponentRequirement requirementType)
72{
73 requiredComponentStorage = this->owner_->getComponent<TComponent>(name);
74
75 if (requiredComponentStorage == nullptr && requirementType == ComponentRequirement::HARD)
76 {
77 RCLCPP_DEBUG_STREAM(
78 this->getLogger(), std::string("Required component with name: '") + name + "'" +
79 demangleSymbol(typeid(TComponent).name()) +
80 " not found. Available components:");
81
82 std::vector<std::shared_ptr<ISmaccComponent>> components;
83 this->owner_->getComponents(components);
84
85 for (auto c : components)
86 {
87 RCLCPP_DEBUG(this->getLogger(), " - Component %s", c->getName().c_str());
88 }
89
90 throw std::runtime_error(
91 std::string("Component ") + demangleSymbol(typeid(TComponent).name()) +
92 std::string(" not found"));
93 }
94}
95
96template <typename TClient>
97void ISmaccComponent::requiresClient(TClient *& requiredClientStorage)
98{
99 this->owner_->requiresClient(requiredClientStorage);
100}
101
102template <typename SmaccComponentType, typename TOrthogonal, typename TClient, typename... TArgs>
103SmaccComponentType * ISmaccComponent::createSiblingComponent(const TArgs &... targs)
104{
105 return this->owner_->createComponent<SmaccComponentType, TOrthogonal, TClient>(targs...);
106}
107
108template <typename SmaccComponentType, typename TOrthogonal, typename TClient, typename... TArgs>
110 const std::string & name, const TArgs &... targs)
111{
112 return this->owner_->createNamedComponent<SmaccComponentType, TOrthogonal, TClient>(
113 name, targs...);
114}
115
116template <typename TOrthogonal, typename TClient>
120
121} // namespace smacc2
SmaccComponentType * createComponent(const TArgs &... targs)
SmaccComponentType * createNamedComponent(const std::string &name, const TArgs &... targs)
void requiresClient(SmaccClientType *&storage)
void getComponents(std::vector< std::shared_ptr< ISmaccComponent > > &components)
Definition client.cpp:34
ISmaccClient * owner_
Definition component.hpp:96
void requiresClient(TClient *&requiredClientStorage)
SmaccComponentType * createSiblingNamedComponent(const std::string &name, const TArgs &... targs)
SmaccComponentType * createSiblingComponent(const TArgs &... targs)
rclcpp::Logger getLogger() const
ISmaccStateMachine * stateMachine_
Definition component.hpp:94
void requiresComponent(TComponent *&requiredComponentStorage, ComponentRequirement requirementType=ComponentRequirement::SOFT)
void postEvent(EventType *ev, EventLifeTime evlifetime=EventLifeTime::ABSOLUTE)
std::string demangleSymbol()
boost::intrusive_ptr< EventType > makeEvent(Args &&... args)
ComponentRequirement
Definition common.hpp:82