CARLA
Toggle main menu visibility
Loading...
Searching...
No Matches
LibCarla
source
carla
ros2
middleware
Middleware.h
Go to the documentation of this file.
1
// Copyright (c) 2026 Computer Vision Center (CVC) at the Universitat Autonoma de Barcelona (UAB).
2
// This work is licensed under the terms of the MIT license.
3
// For a copy, see <https://opensource.org/licenses/MIT>.
4
5
#pragma once
6
7
#include <string>
8
9
namespace
carla
{
10
namespace
ros2
{
11
12
/// Enumeration of available middleware implementations.
13
/// Passed to ROS2::Enable() to select the middleware at startup.
14
/// Once set, the middleware cannot be changed without restarting.
15
enum class
Middleware
{
16
FastDDS
,
17
CycloneDDS
,
18
Zenoh
19
};
20
21
/// Convert a Middleware enum value to a readable string.
22
inline
const
char
*
MiddlewareToString
(
Middleware
middleware) {
23
switch
(middleware) {
24
case
Middleware::FastDDS
:
25
return
"FastDDS"
;
26
case
Middleware::CycloneDDS
:
27
return
"CycloneDDS"
;
28
case
Middleware::Zenoh
:
29
return
"Zenoh"
;
30
}
31
return
"Unknown"
;
32
}
33
34
/// Result of parsing a middleware name string.
35
struct
MiddlewareParseResult
{
36
bool
valid
;
37
Middleware
middleware
;
38
};
39
40
/// Parse a middleware name string (lowercase). Returns {true, middleware} on match,
41
/// {false, FastDDS} for unrecognized values.
42
inline
MiddlewareParseResult
MiddlewareFromString
(
const
std::string& name) {
43
if
(name ==
"fastdds"
) {
44
return
{
true
,
Middleware::FastDDS
};
45
}
46
if
(name ==
"cyclonedds"
) {
47
return
{
true
,
Middleware::CycloneDDS
};
48
}
49
if
(name ==
"zenoh"
) {
50
return
{
true
,
Middleware::Zenoh
};
51
}
52
return
{
false
,
Middleware::FastDDS
};
53
}
54
55
/// Return a readable list of middleware implementations compiled into this binary.
56
inline
std::string
GetAvailableMiddlewareString
() {
57
std::string result;
58
#if defined(CARLA_ROS2_MIDDLEWARE_FASTDDS)
59
result +=
"FastDDS"
;
60
#endif
61
#if defined(CARLA_ROS2_MIDDLEWARE_CYCLONEDDS)
62
if
(!result.empty()) {
63
result +=
", "
;
64
}
65
result +=
"CycloneDDS"
;
66
#endif
67
#if defined(CARLA_ROS2_MIDDLEWARE_ZENOH)
68
if
(!result.empty()) {
69
result +=
", "
;
70
}
71
result +=
"Zenoh"
;
72
#endif
73
if
(result.empty()) {
74
result =
"none"
;
75
}
76
return
result;
77
}
78
79
/// Mangle a type name into the ROS2-compatible format.
80
/// "sensor_msgs::msg::Image" becomes "sensor_msgs::msg::dds_::Image_".
81
/// A bare name like "Image" becomes "dds_::Image_".
82
inline
std::string
ToROS2TypeName
(
const
std::string& type_name) {
83
auto
pos = type_name.rfind(
"::"
);
84
if
(pos == std::string::npos) {
85
return
"dds_::"
+ type_name +
"_"
;
86
}
87
return
type_name.substr(0, pos) +
88
"::dds_::"
+ type_name.substr(pos + 2) +
"_"
;
89
}
90
91
}
// namespace ros2
92
}
// namespace carla
carla::ros2
Definition
AutowareSteeringCompensation.h:15
carla::ros2::MiddlewareToString
const char * MiddlewareToString(Middleware middleware)
Convert a Middleware enum value to a readable string.
Definition
Middleware.h:22
carla::ros2::Middleware
Middleware
Enumeration of available middleware implementations.
Definition
Middleware.h:15
carla::ros2::Middleware::FastDDS
@ FastDDS
Definition
Middleware.h:16
carla::ros2::Middleware::CycloneDDS
@ CycloneDDS
Definition
Middleware.h:17
carla::ros2::Middleware::Zenoh
@ Zenoh
Definition
Middleware.h:18
carla::ros2::GetAvailableMiddlewareString
std::string GetAvailableMiddlewareString()
Return a readable list of middleware implementations compiled into this binary.
Definition
Middleware.h:56
carla::ros2::ToROS2TypeName
std::string ToROS2TypeName(const std::string &type_name)
Mangle a type name into the ROS2-compatible format.
Definition
Middleware.h:82
carla::ros2::MiddlewareFromString
MiddlewareParseResult MiddlewareFromString(const std::string &name)
Parse a middleware name string (lowercase).
Definition
Middleware.h:42
carla
This file contains definitions of common data structures used in traffic manager.
Definition
SignComponent.h:21
carla::ros2::MiddlewareParseResult
Result of parsing a middleware name string.
Definition
Middleware.h:35
carla::ros2::MiddlewareParseResult::valid
bool valid
Definition
Middleware.h:36
carla::ros2::MiddlewareParseResult::middleware
Middleware middleware
Definition
Middleware.h:37
Generated by
1.18.0