VLink  2.0.0
A high-performance communication middleware
ddsr_conf.h
Go to the documentation of this file.
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 transport.
27  *
28  * @details
29  * @c DdsrConf binds the @c ddsr:// URL scheme to RTI Connext DDS, the commercial
30  * DDS stack widely used in safety-critical avionics, automotive ADAS, and industrial
31  * automation deployments where deterministic real-time behaviour and certified
32  * tooling are required. The API surface mirrors @c DdsConf so an application can
33  * switch between Fast-DDS and Connext by changing only the URL scheme.
34  *
35  * @par Supported Node Types
36  *
37  * | Publisher | Subscriber | Server | Client | Getter | Setter |
38  * | :-------: | :--------: | :----: | :----: | :----: | :----: |
39  * | yes | yes | yes | yes | yes | yes |
40  *
41  * @par URL Format
42  * @code
43  * ddsr://<topic>[?domain=<N>&depth=<N>&qos=<profile>]
44  * ddsr://<topic>[?domain=<N>&part=<v>&topic=<v>&pub=<v>&sub=<v>&writer=<v>&reader=<v>]
45  * @endcode
46  *
47  * | Component | Description |
48  * | ---------- | ---------------------------------------------------------------------------- |
49  * | @c topic | RTI Connext topic name (URL host concatenated with path) |
50  * | @c domain | DDS Domain ID (@c ?domain=); defaults from the @c VLINK_DDS_DOMAIN env var |
51  * | @c depth | Optional history-depth override; @c 0 keeps the QoS-selected depth |
52  * | @c qos | Named QoS profile registered via @c register_qos() (@c ?qos=) |
53  * | @c qos_ext | Remaining query keys after @c domain, @c depth and @c qos are removed |
54  *
55  * @par Backend-Specific Options
56  *
57  * | Option | Purpose | Default |
58  * | ---------------------- | ------------------------------------------------------ | ------- |
59  * | XML QoS Library/Profile| Per-entity overrides via @c qos_ext keys | none |
60  * | RPC reply suffix | Auto-derived response topic name | ___resp |
61  * | Domain ID | DomainParticipant Domain joined by readers and writers | 0 |
62  *
63  * @par Example
64  * @code
65  * vlink::Qos qos;
66  * qos.reliability.kind = vlink::Qos::Reliability::kReliable;
67  * vlink::DdsrConf::register_qos("rtps_reliable", qos);
68  *
69  * auto pub = vlink::Publisher<MyMsg>::create_unique("ddsr://control/cmd?domain=3&qos=rtps_reliable");
70  * auto sub = vlink::Subscriber<MyMsg>::create_unique("ddsr://control/cmd?domain=3&qos=rtps_reliable");
71  * @endcode
72  *
73  * @note Compiled only when @c VLINK_SUPPORT_DDSR is defined.
74  * @note @c qos and @c qos_ext are mutually exclusive on the same instance.
75  * @note RPC reply topics are derived by appending @c "___resp" to the topic name.
76  */
77 
78 #pragma once
79 
80 #ifdef VLINK_SUPPORT_DDSR
81 
82 #include <cstdint>
83 #include <functional>
84 #include <map>
85 #include <shared_mutex>
86 #include <string>
87 
88 #include "../extension/qos.h"
89 #include "../impl/conf.h"
90 
91 namespace vlink {
92 
93 /**
94  * @struct DdsrConf
95  * @brief Concrete @c Conf describing an RTI Connext DDS endpoint addressed by a @c ddsr:// URL.
96  *
97  * @details
98  * Holds the topic name, Domain ID, optional history-depth override, and either a
99  * named QoS profile or a per-entity property map.
100  */
101 struct VLINK_EXPORT DdsrConf final : public Conf {
102  std::string topic; ///< RTI Connext topic name (URL host concatenated with path).
103  int32_t domain{0}; ///< DDS Domain ID joined by the underlying DomainParticipant.
104  int32_t depth{0}; ///< Optional history-depth override; @c 0 keeps the QoS-selected depth.
105  std::string qos; ///< Named QoS profile key registered via @c register_qos().
106  PropertiesMap qos_ext; ///< Per-entity property map; populated from query keys outside @c domain / @c depth / @c qos.
107 
108  /**
109  * @brief Builds a @c DdsrConf from topic, Domain, depth, and optional named QoS profile.
110  *
111  * @param _topic RTI Connext topic name.
112  * @param _domain Domain ID; defaults to @c 0.
113  * @param _depth History-depth override; defaults to @c 0 (use QoS depth).
114  * @param _qos Named QoS profile key; empty by default.
115  */
116  explicit DdsrConf(const std::string& _topic, int32_t _domain = 0, int32_t _depth = 0, const std::string& _qos = "");
117 
118  /**
119  * @brief Builds a @c DdsrConf from topic, Domain, and an explicit per-entity QoS map.
120  *
121  * @param _topic RTI Connext topic name.
122  * @param _domain Domain ID.
123  * @param _qos_ext Property map carrying per-entity QoS overrides.
124  */
125  explicit DdsrConf(const std::string& _topic, int32_t _domain, const PropertiesMap& _qos_ext);
126 
127  /**
128  * @brief Component-wise equality on all configuration fields.
129  *
130  * @param conf Configuration to compare with.
131  * @return @c true when @c topic, @c domain, @c depth, @c qos and @c qos_ext all match.
132  */
133  [[nodiscard]] bool operator==(const DdsrConf& conf) const noexcept;
134 
135  /**
136  * @brief Logical negation of @c operator==.
137  *
138  * @param conf Configuration to compare with.
139  * @return @c true when any field differs from @p conf.
140  */
141  [[nodiscard]] bool operator!=(const DdsrConf& conf) const noexcept;
142 
143  /**
144  * @brief Reports this object's transport tag.
145  *
146  * @return @c TransportType::kDdsr.
147  */
148  [[nodiscard]] TransportType get_transport_type() const override;
149 
150  /**
151  * @brief Registers a named QoS profile that endpoints may reference via @c ?qos=.
152  *
153  * @details
154  * Profile names share a global namespace. Collisions with DDS-reserved tokens
155  * (@c part, @c topic, @c pub, @c sub, @c writer, @c reader, @c depth) or with an
156  * already registered profile abort with a fatal log entry.
157  *
158  * @param name Unique profile key; must not collide with any reserved token.
159  * @param qos @c Qos value associated with the key.
160  */
161  static void register_qos(const std::string& name, const Qos& qos);
162 
163  private:
164  static void register_qos_internal(const std::string& name, const Qos& qos);
165 
166  static const Qos& find_qos(const std::string& name);
167 
168  friend class DdsrFactory;
169  static std::map<std::string, Qos> qos_map_;
170  static std::shared_mutex mtx_;
171  static constexpr const char* kRespSuffix{"___resp"};
172 #ifndef VLINK_ENABLE_C_INTERFACE
174 #endif
176  VLINK_CONF_IMPL(DdsrConf)
177 };
178 
179 ////////////////////////////////////////////////////////////////
180 /// Details
181 ////////////////////////////////////////////////////////////////
182 
183 inline DdsrConf::DdsrConf(const std::string& _topic, int32_t _domain, int32_t _depth, const std::string& _qos)
184  : topic(_topic), domain(_domain), depth(_depth), qos(_qos) {}
185 
186 inline DdsrConf::DdsrConf(const std::string& _topic, int32_t _domain, const PropertiesMap& _qos_ext)
187  : topic(_topic), domain(_domain), qos_ext(_qos_ext) {}
188 
189 inline bool DdsrConf::operator==(const DdsrConf& conf) const noexcept {
190  return topic == conf.topic && domain == conf.domain && depth == conf.depth && qos == conf.qos &&
191  qos_ext == conf.qos_ext;
192 }
193 
194 inline bool DdsrConf::operator!=(const DdsrConf& conf) const noexcept { return !(*this == conf); }
195 
196 inline TransportType DdsrConf::get_transport_type() const { return TransportType::kDdsr; }
197 
198 } // namespace vlink
199 
200 #endif
#define VLINK_CONF_IMPL(classname)
Convenience macro that emits the standard concrete conf boilerplate.
Definition: conf.h:251
#define VLINK_DECLARE_GLOBAL_PROPERTY()
Declares per-transport static configuration storage and access helpers.
Definition: conf.h:309
#define VLINK_ALLOW_IMPL_TYPE(type)
Records the bitmask of ImplType values supported by a conf.
Definition: conf.h:292
#define VLINK_EXPORT
Definition: macros.h:81