ros2_foxglove_bridge/src/param_utils.cpp
Go to the documentation of this file.
1 
2 
4 #include <foxglove_bridge/param_utils.hpp>
5 
6 namespace foxglove_bridge {
7 
8 void declareParameters(rclcpp::Node* node) {
9  auto portDescription = rcl_interfaces::msg::ParameterDescriptor{};
10  portDescription.name = PARAM_PORT;
11  portDescription.type = rcl_interfaces::msg::ParameterType::PARAMETER_INTEGER;
12  portDescription.description = "The TCP port to bind the WebSocket server to";
13  portDescription.read_only = true;
14  portDescription.additional_constraints =
15  "Must be a valid TCP port number, or 0 to use a random port";
16  portDescription.integer_range.resize(1);
17  portDescription.integer_range[0].from_value = 0;
18  portDescription.integer_range[0].to_value = 65535;
19  portDescription.integer_range[0].step = 1;
20  node->declare_parameter(PARAM_PORT, DEFAULT_PORT, portDescription);
21 
22  auto addressDescription = rcl_interfaces::msg::ParameterDescriptor{};
23  addressDescription.name = PARAM_ADDRESS;
24  addressDescription.type = rcl_interfaces::msg::ParameterType::PARAMETER_STRING;
25  addressDescription.description = "The host address to bind the WebSocket server to";
26  addressDescription.read_only = true;
27  node->declare_parameter(PARAM_ADDRESS, DEFAULT_ADDRESS, addressDescription);
28 
29  auto sendBufferLimitDescription = rcl_interfaces::msg::ParameterDescriptor{};
30  sendBufferLimitDescription.name = PARAM_SEND_BUFFER_LIMIT;
31  sendBufferLimitDescription.type = rcl_interfaces::msg::ParameterType::PARAMETER_INTEGER;
32  sendBufferLimitDescription.description =
33  "Connection send buffer limit in bytes. Messages will be dropped when a connection's send "
34  "buffer reaches this limit to avoid a queue of outdated messages building up.";
35  sendBufferLimitDescription.integer_range.resize(1);
36  sendBufferLimitDescription.integer_range[0].from_value = 0;
37  sendBufferLimitDescription.integer_range[0].to_value = std::numeric_limits<int64_t>::max();
38  sendBufferLimitDescription.read_only = true;
39  node->declare_parameter(PARAM_SEND_BUFFER_LIMIT, DEFAULT_SEND_BUFFER_LIMIT,
40  sendBufferLimitDescription);
41 
42  auto useTlsDescription = rcl_interfaces::msg::ParameterDescriptor{};
43  useTlsDescription.name = PARAM_USETLS;
44  useTlsDescription.type = rcl_interfaces::msg::ParameterType::PARAMETER_BOOL;
45  useTlsDescription.description = "Use Transport Layer Security for encrypted communication";
46  useTlsDescription.read_only = true;
47  node->declare_parameter(PARAM_USETLS, false, useTlsDescription);
48 
49  auto certfileDescription = rcl_interfaces::msg::ParameterDescriptor{};
50  certfileDescription.name = PARAM_CERTFILE;
51  certfileDescription.type = rcl_interfaces::msg::ParameterType::PARAMETER_STRING;
52  certfileDescription.description = "Path to the certificate to use for TLS";
53  certfileDescription.read_only = true;
54  node->declare_parameter(PARAM_CERTFILE, "", certfileDescription);
55 
56  auto keyfileDescription = rcl_interfaces::msg::ParameterDescriptor{};
57  keyfileDescription.name = PARAM_KEYFILE;
58  keyfileDescription.type = rcl_interfaces::msg::ParameterType::PARAMETER_STRING;
59  keyfileDescription.description = "Path to the private key to use for TLS";
60  keyfileDescription.read_only = true;
61  node->declare_parameter(PARAM_KEYFILE, "", keyfileDescription);
62 
63  auto minQosDepthDescription = rcl_interfaces::msg::ParameterDescriptor{};
64  minQosDepthDescription.name = PARAM_MIN_QOS_DEPTH;
65  minQosDepthDescription.type = rcl_interfaces::msg::ParameterType::PARAMETER_INTEGER;
66  minQosDepthDescription.description = "Minimum depth used for the QoS profile of subscriptions.";
67  minQosDepthDescription.read_only = true;
68  minQosDepthDescription.additional_constraints = "Must be a non-negative integer";
69  minQosDepthDescription.integer_range.resize(1);
70  minQosDepthDescription.integer_range[0].from_value = 0;
71  minQosDepthDescription.integer_range[0].to_value = INT32_MAX;
72  minQosDepthDescription.integer_range[0].step = 1;
73  node->declare_parameter(PARAM_MIN_QOS_DEPTH, DEFAULT_MIN_QOS_DEPTH, minQosDepthDescription);
74 
75  auto maxQosDepthDescription = rcl_interfaces::msg::ParameterDescriptor{};
76  maxQosDepthDescription.name = PARAM_MAX_QOS_DEPTH;
77  maxQosDepthDescription.type = rcl_interfaces::msg::ParameterType::PARAMETER_INTEGER;
78  maxQosDepthDescription.description = "Maximum depth used for the QoS profile of subscriptions.";
79  maxQosDepthDescription.read_only = true;
80  maxQosDepthDescription.additional_constraints = "Must be a non-negative integer";
81  maxQosDepthDescription.integer_range.resize(1);
82  maxQosDepthDescription.integer_range[0].from_value = 0;
83  maxQosDepthDescription.integer_range[0].to_value = INT32_MAX;
84  maxQosDepthDescription.integer_range[0].step = 1;
85  node->declare_parameter(PARAM_MAX_QOS_DEPTH, DEFAULT_MAX_QOS_DEPTH, maxQosDepthDescription);
86 
87  auto topicWhiteListDescription = rcl_interfaces::msg::ParameterDescriptor{};
88  topicWhiteListDescription.name = PARAM_TOPIC_WHITELIST;
89  topicWhiteListDescription.type = rcl_interfaces::msg::ParameterType::PARAMETER_STRING_ARRAY;
90  topicWhiteListDescription.description =
91  "List of regular expressions (ECMAScript) of whitelisted topic names.";
92  topicWhiteListDescription.read_only = true;
93  node->declare_parameter(PARAM_TOPIC_WHITELIST, std::vector<std::string>({".*"}),
94  topicWhiteListDescription);
95 
96  auto serviceWhiteListDescription = rcl_interfaces::msg::ParameterDescriptor{};
97  serviceWhiteListDescription.name = PARAM_SERVICE_WHITELIST;
98  serviceWhiteListDescription.type = rcl_interfaces::msg::ParameterType::PARAMETER_STRING_ARRAY;
99  serviceWhiteListDescription.description =
100  "List of regular expressions (ECMAScript) of whitelisted service names.";
101  serviceWhiteListDescription.read_only = true;
102  node->declare_parameter(PARAM_SERVICE_WHITELIST, std::vector<std::string>({".*"}),
103  serviceWhiteListDescription);
104 
105  auto paramWhiteListDescription = rcl_interfaces::msg::ParameterDescriptor{};
106  paramWhiteListDescription.name = PARAM_PARAMETER_WHITELIST;
107  paramWhiteListDescription.type = rcl_interfaces::msg::ParameterType::PARAMETER_STRING_ARRAY;
108  paramWhiteListDescription.description =
109  "List of regular expressions (ECMAScript) of whitelisted parameter names.";
110  paramWhiteListDescription.read_only = true;
111  node->declare_parameter(PARAM_PARAMETER_WHITELIST, std::vector<std::string>({".*"}),
112  paramWhiteListDescription);
113 
114  auto useCompressionDescription = rcl_interfaces::msg::ParameterDescriptor{};
115  useCompressionDescription.name = PARAM_USE_COMPRESSION;
116  useCompressionDescription.type = rcl_interfaces::msg::ParameterType::PARAMETER_BOOL;
117  useCompressionDescription.description =
118  "Use websocket compression (permessage-deflate). Suited for connections with smaller bandwith, "
119  "at the cost of additional CPU load.";
120  useCompressionDescription.read_only = true;
121  node->declare_parameter(PARAM_USE_COMPRESSION, false, useCompressionDescription);
122 
123  auto paramCapabilities = rcl_interfaces::msg::ParameterDescriptor{};
124  paramCapabilities.name = PARAM_CAPABILITIES;
125  paramCapabilities.type = rcl_interfaces::msg::ParameterType::PARAMETER_STRING_ARRAY;
126  paramCapabilities.description = "Server capabilities";
127  paramCapabilities.read_only = true;
128  node->declare_parameter(
130  std::vector<std::string>(std::vector<std::string>(foxglove::DEFAULT_CAPABILITIES.begin(),
132  paramCapabilities);
133 
134  auto clientTopicWhiteListDescription = rcl_interfaces::msg::ParameterDescriptor{};
135  clientTopicWhiteListDescription.name = PARAM_CLIENT_TOPIC_WHITELIST;
136  clientTopicWhiteListDescription.type = rcl_interfaces::msg::ParameterType::PARAMETER_STRING_ARRAY;
137  clientTopicWhiteListDescription.description =
138  "List of regular expressions (ECMAScript) of whitelisted client-published topic names.";
139  clientTopicWhiteListDescription.read_only = true;
140  node->declare_parameter(PARAM_CLIENT_TOPIC_WHITELIST, std::vector<std::string>({".*"}),
141  paramWhiteListDescription);
142 
143  auto includeHiddenDescription = rcl_interfaces::msg::ParameterDescriptor{};
144  includeHiddenDescription.name = PARAM_INCLUDE_HIDDEN;
145  includeHiddenDescription.type = rcl_interfaces::msg::ParameterType::PARAMETER_BOOL;
146  includeHiddenDescription.description = "Include hidden topics and services";
147  includeHiddenDescription.read_only = true;
148  node->declare_parameter(PARAM_INCLUDE_HIDDEN, false, includeHiddenDescription);
149 }
150 
151 std::vector<std::regex> parseRegexStrings(rclcpp::Node* node,
152  const std::vector<std::string>& strings) {
153  std::vector<std::regex> regexVector;
154  regexVector.reserve(strings.size());
155 
156  for (const auto& pattern : strings) {
157  try {
158  regexVector.push_back(
159  std::regex(pattern, std::regex_constants::ECMAScript | std::regex_constants::icase));
160  } catch (const std::exception& ex) {
161  RCLCPP_ERROR(node->get_logger(), "Ignoring invalid regular expression '%s': %s",
162  pattern.c_str(), ex.what());
163  }
164  }
165 
166  return regexVector;
167 }
168 
169 } // namespace foxglove_bridge
void declareParameters(rclcpp::Node *node)
std::vector< std::regex > parseRegexStrings(rclcpp::Node *node, const std::vector< std::string > &strings)
constexpr std::array< const char *, 5 > DEFAULT_CAPABILITIES
Definition: common.hpp:20


foxglove_bridge
Author(s): Foxglove
autogenerated on Mon Jul 3 2023 02:12:22