VLink 2.0.0
A high-performance communication middleware
载入中...
搜索中...
未找到
ddsr_conf.h
浏览该文件的文档.
1/*
2 * Copyright (C) 2026 by Thun Lu. All rights reserved.
3 * Author: Thun Lu <thun.lu@zohomail.cn>
4 * Repo: https://github.com/thun-res/vlink
5 * _ __ __ _ __
6 * | | / / / / (_) ____ / /__
7 * | | / / / / / / / __ \ / //_/
8 * | |/ / / /___ / / / / / / / ,<
9 * |___/ /_____/ /_/ /_/ /_/ /_/|_|
10 *
11 * Licensed under the Apache License, Version 2.0 (the "License");
12 * you may not use this file except in compliance with the License.
13 * You may obtain a copy of the License at
14 *
15 * http://www.apache.org/licenses/LICENSE-2.0
16 *
17 * Unless required by applicable law or agreed to in writing, software
18 * distributed under the License is distributed on an "AS IS" BASIS,
19 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
20 * See the License for the specific language governing permissions and
21 * limitations under the License.
22 */
23
24/**
25 * @file ddsr_conf.h
26 * @brief Transport configuration for the @c ddsr:// RTI Connext DDS backend.
27 *
28 * @details
29 * @c DdsrConf configures the RTI Connext DDS transport, a commercial-grade DDS
30 * implementation widely used in safety-critical and real-time embedded systems.
31 * It presents the same VLink API as @c DdsConf (Fast-DDS) but delegates to
32 * RTI Connext internally.
33 *
34 * @par Supported Node Types
35 * @c ddsr:// supports all six node types: @c kPublisher, @c kSubscriber, @c kServer,
36 * @c kClient, @c kSetter, and @c kGetter.
37 *
38 * @par URL Format
39 * @code
40 * ddsr://<topic>[?domain=<N>&depth=<N>&qos=<name>]
41 * ddsr://<topic>[?domain=<N>&part=<v>&topic=<v>&pub=<v>&sub=<v>&writer=<v>&reader=<v>]
42 * @endcode
43 *
44 * | Component | Description |
45 * | ---------- | ------------------------------------------------------------------------- |
46 * | @c topic | RTI DDS topic name; formed from @c host + @c "/" + @c path |
47 * | @c domain | DDS Domain ID (@c ?domain=, default from @c VLINK_DDS_DOMAIN env var) |
48 * | @c depth | History depth (@c ?depth=, default 0) |
49 * | @c qos | Named QoS profile registered via @c register_qos() (@c ?qos=) |
50 * | @c qos_ext | Extended QoS map: @c part, @c topic, @c pub, @c sub, @c writer, @c reader |
51 *
52 * @note This header is compiled only when @c VLINK_SUPPORT_DDSR is defined.
53 * @note @c qos and @c qos_ext are mutually exclusive.
54 * @note Response topics for RPC are automatically registered with a @c "___resp" suffix.
55 */
56
57#pragma once
58
59#ifdef VLINK_SUPPORT_DDSR
60
61#include <cstdint>
62#include <functional>
63#include <map>
64#include <shared_mutex>
65#include <string>
66
67#include "../extension/qos.h"
68#include "../impl/conf.h"
69
70namespace vlink {
71
72/**
73 * @struct DdsrConf
74 * @brief Configuration for the @c ddsr:// RTI Connext DDS transport.
75 *
76 * @details
77 * Can be constructed directly or parsed from a URL string via @c Url.
78 */
79struct VLINK_EXPORT DdsrConf final : public Conf {
80 std::string topic; ///< RTI DDS topic name (host + "/" + path from URL).
81 int32_t domain{0}; ///< DDS Domain Participant ID (non-negative).
82 int32_t depth{0}; ///< DDS history depth for the endpoint; 0 means transport default.
83 std::string qos; ///< Named QoS profile key registered via @c register_qos().
84 PropertiesMap
85 qos_ext; ///< Extended per-entity QoS map (keys: @c part, @c topic, @c pub, @c sub, @c writer, @c reader).
86
87 /**
88 * @brief Constructs a @c DdsrConf with topic, domain, depth, and named QoS.
89 *
90 * @param _topic RTI DDS topic name.
91 * @param _domain Domain ID; default 0.
92 * @param _depth History depth; default 0.
93 * @param _qos Named QoS profile key; empty by default.
94 */
95 explicit DdsrConf(const std::string& _topic, int32_t _domain = 0, int32_t _depth = 0, const std::string& _qos = "");
96
97 /**
98 * @brief Constructs a @c DdsrConf with topic, domain, and extended QoS map.
99 *
100 * @param _topic RTI DDS topic name.
101 * @param _domain Domain ID.
102 * @param _qos_ext Per-entity QoS properties map.
103 */
104 explicit DdsrConf(const std::string& _topic, int32_t _domain, const PropertiesMap& _qos_ext);
105
106 /**
107 * @brief Returns @c true if all fields equal those of @p conf.
108 *
109 * @param conf Configuration to compare.
110 * @return @c true if @c topic, @c domain, @c depth, @c qos, and @c qos_ext match.
111 */
112 [[nodiscard]] bool operator==(const DdsrConf& conf) const noexcept;
113
114 /**
115 * @brief Returns @c true if any field differs from @p conf.
116 *
117 * @param conf Configuration to compare.
118 * @return Logical negation of @c operator==.
119 */
120 [[nodiscard]] bool operator!=(const DdsrConf& conf) const noexcept;
121
122 /**
123 * @brief Returns @c TransportType::kDdsr identifying this transport.
124 *
125 * @return @c TransportType::kDdsr.
126 */
127 [[nodiscard]] TransportType get_transport_type() const override;
128
129 /**
130 * @brief Registers a named QoS profile for use by @c ddsr:// nodes.
131 *
132 * @details
133 * The @p name is associated with the @p qos object and can be referenced in URL
134 * query strings as @c ?qos=name. Names that conflict with reserved keys
135 * (@c part, @c topic, @c pub, @c sub, @c writer, @c reader, @c depth) or that
136 * are already registered cause a fatal log and are rejected.
137 *
138 * @param name Unique profile name; must not be one of the reserved keys.
139 * @param qos @c Qos object describing the quality-of-service settings.
140 */
141 static void register_qos(const std::string& name, const Qos& qos);
142
143 private:
144 static void register_qos_internal(const std::string& name, const Qos& qos);
145
146 static const Qos& find_qos(const std::string& name);
147
148 friend class DdsrFactory;
149 static std::map<std::string, Qos> qos_map_;
150 static std::shared_mutex mtx_;
151 static constexpr const char* kRespSuffix{"___resp"};
152#ifndef VLINK_ENABLE_C_INTERFACE
154#endif
155 VLINK_ALLOW_IMPL_TYPE(kServer | kClient | kPublisher | kSubscriber | kSetter | kGetter)
156 VLINK_CONF_IMPL(DdsrConf)
157};
158
159////////////////////////////////////////////////////////////////
160/// Details
161////////////////////////////////////////////////////////////////
162
163inline DdsrConf::DdsrConf(const std::string& _topic, int32_t _domain, int32_t _depth, const std::string& _qos)
164 : topic(_topic), domain(_domain), depth(_depth), qos(_qos) {}
165
166inline DdsrConf::DdsrConf(const std::string& _topic, int32_t _domain, const PropertiesMap& _qos_ext)
167 : topic(_topic), domain(_domain), qos_ext(_qos_ext) {}
168
169inline bool DdsrConf::operator==(const DdsrConf& conf) const noexcept {
170 return topic == conf.topic && domain == conf.domain && depth == conf.depth && qos == conf.qos &&
171 qos_ext == conf.qos_ext;
172}
173
174inline bool DdsrConf::operator!=(const DdsrConf& conf) const noexcept { return !(*this == conf); }
175
176inline TransportType DdsrConf::get_transport_type() const { return TransportType::kDdsr; }
177
178} // namespace vlink
179
180#endif
Abstract transport configuration base class and associated helper macros.
#define VLINK_CONF_IMPL(classname)
Standard boilerplate for concrete Conf subclass declarations.
定义 conf.h:227
#define VLINK_DECLARE_GLOBAL_PROPERTY()
Declares per-transport global state: thread count and property storage.
定义 conf.h:292
#define VLINK_ALLOW_IMPL_TYPE(type)
Declares a static constexpr bitmask of supported ImplType values.
定义 conf.h:268
#define VLINK_EXPORT
定义 macros.h:85
Quality of Service (QoS) policy aggregate for VLink publishers and subscribers.