SMACC2
Loading...
Searching...
No Matches
smacc_component_impl.hpp
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
21#pragma once
22
23#include <string>
24
25#include <smacc2/component.hpp>
27
28namespace smacc2
29{
30template <typename EventType>
35
36template <typename EventType>
38{
39 auto ev = new EventType();
41}
42
43template <typename TComponent>
46{
48
50 {
52 this->getLogger(), std::string("Required component ") +
53 demangleSymbol(typeid(TComponent).name()) +
54 " not found. Available components:");
55
56 std::vector<std::shared_ptr<ISmaccComponent>> components;
57 this->owner_->getComponents(components);
58
59 for (auto c : components)
60 {
61 RCLCPP_DEBUG(this->getLogger(), "- Component %s", c->getName().c_str());
62 }
63
64 throw std::runtime_error(
65 std::string("Component ") + demangleSymbol(typeid(TComponent).name()) + " not found");
66 }
67}
68
69template <typename TComponent>
72{
74
76 {
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>
98{
99 this->owner_->requiresClient(requiredClientStorage);
100}
101
102template <typename SmaccComponentType, typename TOrthogonal, typename TClient, typename... TArgs>
107
108template <typename SmaccComponentType, typename TOrthogonal, typename TClient, typename... TArgs>
114
115} // namespace smacc2
SmaccComponentType * createNamedComponent(std::string name, TArgs... targs)
SmaccComponentType * createComponent(TArgs... targs)
void requiresClient(SmaccClientType *&storage)
void getComponents(std::vector< std::shared_ptr< ISmaccComponent > > &components)
Definition client.cpp:34
ISmaccClient * owner_
Definition component.hpp:83
void requiresComponent(TComponent *&requiredComponentStorage, bool throwExceptionIfNotExist=false)
void requiresClient(TClient *&requiredClientStorage)
SmaccComponentType * createSiblingComponent(TArgs... targs)
SmaccComponentType * createSiblingNamedComponent(std::string name, TArgs... targs)
rclcpp::Logger getLogger() const
ISmaccStateMachine * stateMachine_
Definition component.hpp:81
void postEvent(EventType *ev, EventLifeTime evlifetime=EventLifeTime::ABSOLUTE)
std::string demangleSymbol()