17#ifndef CYBER_MESSAGE_CONVERTER_H_
18#define CYBER_MESSAGE_CONVERTER_H_
29#include "cyber/ros_bridge/proto/converter_conf.pb.h"
37#if __has_include("rclcpp/rclcpp.hpp")
38#include "message_filters/subscriber.h"
39#include "message_filters/sync_policies/approximate_time.h"
40#include "message_filters/synchronizer.h"
41#include "rclcpp/rclcpp.hpp"
42#include "ros_adapter/ros_distro.h"
55 if (
init_.exchange(
true)) {
61#ifdef RCLCPP__RCLCPP_HPP_
62 ros_node_ = std::make_shared<::rclcpp::Node>(
65 std::make_shared<::rclcpp::executors::SingleThreadedExecutor>();
70#ifdef RCLCPP__RCLCPP_HPP_
72 ros_node_exec_->add_node(std::shared_ptr<rclcpp::Node>(ros_node_));
73 ros_node_exec_->spin();
82 std::string class_name =
83 abi::__cxa_demangle(
typeid(*this).name(), 0, 0, &status);
84 std::string delimiter =
"::";
85 std::string sub_class_name;
86 std::string conf_file_prefix;
88 auto pos = class_name.rfind(delimiter);
89 if (pos == std::string::npos) {
90 sub_class_name = class_name;
92 sub_class_name = class_name.substr(pos + delimiter.length());
95 for (
int i = 0; i < sub_class_name.length(); i++) {
96 if (std::isupper(sub_class_name[i]) && i > 0) {
97 conf_file_prefix.push_back(
'_');
99 conf_file_prefix.push_back(std::tolower(sub_class_name[i]));
102 std::string config_path =
105 class_name,
"conf/" + conf_file_prefix +
".pb.txt");
109 class_name, std::string(
"conf/default.pb.txt"));
113 AERROR <<
"Load config of " << class_name <<
" failed!";
116 AINFO <<
"Load the [" << class_name
117 <<
"] config file successfully, file path: " << config_path;
124 std::vector<std::shared_ptr<apollo::cyber::proto::RoleAttributes>>
128#ifdef RCLCPP__RCLCPP_HPP_
129 std::vector<std::shared_ptr<::rclcpp::PublisherBase>> ros_publishers_;
130 std::vector<std::shared_ptr<::rclcpp::SubscriptionBase>> ros_subscriptions_;
131#if defined(ROS_DISTRO_FOXY) || defined(ROS_DISTRO_GALACTIC)
132 std::vector<std::shared_ptr<::message_filters::SubscriberBase>>
134 std::vector<std::shared_ptr<::message_filters::SubscriberBase<rclcpp::Node>>>
137 std::shared_ptr<::rclcpp::Node> ros_node_ =
nullptr;
138 std::shared_ptr<::rclcpp::executors::SingleThreadedExecutor> ros_node_exec_ =
140 std::shared_ptr<std::thread> ros_spin_thread_;
const std::string node_name_
std::atomic< bool > init_
virtual ~MessageConverter()
std::unique_ptr< apollo::cyber::Node > cyber_node_
std::vector< std::shared_ptr< apollo::cyber::proto::RoleAttributes > > apollo_attrs_
std::vector< std::shared_ptr< apollo::cyber::ReaderBase > > apollo_readers_
std::vector< std::shared_ptr< apollo::cyber::WriterBase > > apollo_writers_
ConverterConf converter_conf_
bool LoadConfig(ConverterConf *config)
std::string GetPluginConfPath(const std::string &class_name, const std::string &conf_name)
get plugin configuration file location
static PluginManager * Instance()
get singleton instance of PluginManager
bool PathExists(const std::string &path)
Check if the path exists.
bool GetProtoFromFile(const std::string &file_name, google::protobuf::Message *message)
Parses the content of the file specified by the file_name as a representation of protobufs,...
std::unique_ptr< Node > CreateNode(const std::string &node_name, const std::string &name_space)