CORESENSE4home_Architecture
Toggle main menu visibility
Loading...
Searching...
No Matches
cs4home_core
include
cs4home_core
Efferent.hpp
Go to the documentation of this file.
1
// Copyright 2024 Intelligent Robotics Lab
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
#ifndef CS4HOME_CORE__EFFERENT_HPP_
16
#define CS4HOME_CORE__EFFERENT_HPP_
17
18
#include <memory>
19
#include <string>
20
#include <vector>
21
22
#include "rclcpp_lifecycle/lifecycle_node.hpp"
23
#include "rclcpp/macros.hpp"
24
#include "rclcpp/serialization.hpp"
25
26
namespace
cs4home_core
27
{
28
34
class
Efferent
35
{
36
public
:
37
RCLCPP_SMART_PTR_DEFINITIONS(
Efferent
)
38
39
43
explicit
Efferent
(rclcpp_lifecycle::LifecycleNode::SharedPtr parent);
44
49
virtual
bool
configure
() = 0;
50
60
template
<
class
MessageT>
61
void
publish
(std::unique_ptr<MessageT> msg)
62
{
63
rclcpp::Serialization<MessageT> serializer;
64
auto
untyped_msg = rclcpp::SerializedMessage();
65
66
serializer.serialize_message(msg.get(), &untyped_msg);
67
68
for
(
auto
& pub :
pubs_
) {
69
pub->publish(untyped_msg);
70
}
71
}
72
73
protected
:
75
rclcpp_lifecycle::LifecycleNode::SharedPtr
parent_
;
77
std::vector<std::shared_ptr<rclcpp::GenericPublisher>>
pubs_
;
78
85
bool
create_publisher
(
const
std::string & topic,
const
std::string & type);
86
};
87
88
}
// namespace cs4home_core
89
90
#endif
// CS4HOME_CORE__EFFERENT_HPP_
cs4home_core::Efferent::publish
void publish(std::unique_ptr< MessageT > msg)
Publishes a serialized message to all configured publishers.
Definition
Efferent.hpp:61
cs4home_core::Efferent::configure
virtual bool configure()=0
Configures the Efferent component.
cs4home_core::Efferent::parent_
rclcpp_lifecycle::LifecycleNode::SharedPtr parent_
< Shared pointer to the parent lifecycle node.
Definition
Efferent.hpp:75
cs4home_core::Efferent::pubs_
std::vector< std::shared_ptr< rclcpp::GenericPublisher > > pubs_
Definition
Efferent.hpp:77
cs4home_core::Efferent::create_publisher
bool create_publisher(const std::string &topic, const std::string &type)
Creates a publisher for a specified topic and message type.
Definition
Efferent.cpp:40
cs4home_core::Efferent::Efferent
Efferent(rclcpp_lifecycle::LifecycleNode::SharedPtr parent)
Constructs an Efferent object associated with a parent lifecycle node.
Definition
Efferent.cpp:24
cs4home_core
Definition
Afferent.hpp:32
Generated by
1.18.0