VLink 2.0.0
A high-performance communication middleware
载入中...
搜索中...
未找到
ddst_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 ddst_conf.h
26 * @brief Transport configuration for the @c ddst:// TravoDDS backend.
27 *
28 * @details
29 * @c DdstConf configures the TravoDDS transport. TravoDDS is a domestic
30 * (open-source, https://gitee.com/agiros/travodds) DDS implementation; its API
31 * surface exposed by VLink is identical to @c DdsConf (Fast-DDS), but the
32 * underlying runtime is provided by TravoDDS.
33 *
34 * @par Supported Node Types
35 * @c ddst:// 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 * ddst://<topic>[?domain=<N>&depth=<N>&qos=<name>]
41 * ddst://<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 | TravoDDS 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 * @par Global QoS File
53 * @code
54 * vlink::DdstConf::load_global_qos_file("/etc/vlink/ddst_profile.xml");
55 * @endcode
56 *
57 * @note This header is compiled only when @c VLINK_SUPPORT_DDST is defined.
58 * @note @c qos and @c qos_ext are mutually exclusive; setting both causes
59 * @c is_valid() to return @c false.
60 * @note Response topics for RPC are stored with a @c "___resp" suffix.
61 */
62
63#pragma once
64
65#ifdef VLINK_SUPPORT_DDST
66
67#include <cstdint>
68#include <functional>
69#include <map>
70#include <shared_mutex>
71#include <string>
72#include <tuple>
73#include <vector>
74
75#include "../extension/qos.h"
76#include "../impl/conf.h"
77
78namespace vlink {
79
80/**
81 * @struct DdstConf
82 * @brief Configuration for the @c ddst:// TravoDDS transport.
83 *
84 * @details
85 * Can be constructed directly or parsed from a URL string via @c Url.
86 */
87struct VLINK_EXPORT DdstConf final : public Conf {
88 std::string topic; ///< TravoDDS topic name (host + "/" + path from URL).
89 int32_t domain{0}; ///< DDS Domain Participant ID (non-negative).
90 int32_t depth{0}; ///< DDS history depth for the endpoint; 0 means transport default.
91 std::string qos; ///< Named QoS profile key registered via @c register_qos().
92 PropertiesMap
93 qos_ext; ///< Extended per-entity QoS map (keys: @c part, @c topic, @c pub, @c sub, @c writer, @c reader).
94
95 /**
96 * @brief Constructs a @c DdstConf with topic, domain, depth, and named QoS.
97 *
98 * @param _topic TravoDDS topic name.
99 * @param _domain Domain ID; default 0.
100 * @param _depth History depth; default 0.
101 * @param _qos Named QoS profile key; empty by default.
102 */
103 explicit DdstConf(const std::string& _topic, int32_t _domain = 0, int32_t _depth = 0, const std::string& _qos = "");
104
105 /**
106 * @brief Constructs a @c DdstConf with topic, domain, and extended QoS map.
107 *
108 * @param _topic TravoDDS topic name.
109 * @param _domain Domain ID.
110 * @param _qos_ext Per-entity QoS properties map.
111 */
112 explicit DdstConf(const std::string& _topic, int32_t _domain, const PropertiesMap& _qos_ext);
113
114 /**
115 * @brief Returns @c true if all fields equal those of @p conf.
116 *
117 * @param conf Configuration to compare.
118 * @return @c true if @c topic, @c domain, @c depth, @c qos, and @c qos_ext all match.
119 */
120 [[nodiscard]] bool operator==(const DdstConf& conf) const noexcept;
121
122 /**
123 * @brief Returns @c true if any field differs from @p conf.
124 *
125 * @param conf Configuration to compare.
126 * @return Logical negation of @c operator==.
127 */
128 [[nodiscard]] bool operator!=(const DdstConf& conf) const noexcept;
129
130 /**
131 * @brief Returns @c TransportType::kDdst identifying this transport.
132 *
133 * @return @c TransportType::kDdst.
134 */
135 [[nodiscard]] TransportType get_transport_type() const override;
136
137 /**
138 * @brief Returns the list of currently discovered topics on the given domain.
139 *
140 * @details
141 * Queries @c DdstFactory for live topic discovery information. Each entry is
142 * a @c (topic_name, type_name) pair.
143 *
144 * @param _domain DDS domain ID to query.
145 * @return Vector of @c (topic_name, type_name) tuples; may be empty.
146 */
147 [[nodiscard]] static std::vector<std::tuple<std::string, std::string>> get_discovered_topics(int32_t _domain);
148
149 /**
150 * @brief Loads a TravoDDS XML QoS profile file as the global default.
151 *
152 * @details
153 * Must be called before any @c ddst:// participants are created.
154 *
155 * @param filepath Path to the XML QoS profile file.
156 * @return @c true if loaded successfully; @c false otherwise.
157 */
158 static bool load_global_qos_file(const std::string& filepath);
159
160 /**
161 * @brief Registers a named QoS profile for use by @c ddst:// nodes.
162 *
163 * @details
164 * The @p name is associated with the @p qos object and can be referenced in URL
165 * query strings as @c ?qos=name. Reserved keys (@c part, @c topic, @c pub,
166 * @c sub, @c writer, @c reader, @c depth) and duplicate names are rejected
167 * with a fatal log.
168 *
169 * @param name Unique profile name; must not conflict with reserved keys.
170 * @param qos @c Qos object describing the quality-of-service settings.
171 */
172 static void register_qos(const std::string& name, const Qos& qos);
173
174 private:
175 static void register_qos_internal(const std::string& name, const Qos& qos);
176
177 static const Qos& find_qos(const std::string& name);
178
179 friend class DdstFactory;
180 static std::map<std::string, std::function<void*()>> type_support_map_;
181 static std::map<std::string, Qos> qos_map_;
182 static std::shared_mutex mtx_;
183 static constexpr const char* kRespSuffix{"___resp"};
184#ifndef VLINK_ENABLE_C_INTERFACE
186#endif
187 VLINK_ALLOW_IMPL_TYPE(kServer | kClient | kPublisher | kSubscriber | kSetter | kGetter)
188 VLINK_CONF_IMPL(DdstConf)
189};
190
191////////////////////////////////////////////////////////////////
192/// Details
193////////////////////////////////////////////////////////////////
194
195inline DdstConf::DdstConf(const std::string& _topic, int32_t _domain, int32_t _depth, const std::string& _qos)
196 : topic(_topic), domain(_domain), depth(_depth), qos(_qos) {}
197
198inline DdstConf::DdstConf(const std::string& _topic, int32_t _domain, const PropertiesMap& _qos_ext)
199 : topic(_topic), domain(_domain), qos_ext(_qos_ext) {}
200
201inline bool DdstConf::operator==(const DdstConf& conf) const noexcept {
202 return topic == conf.topic && domain == conf.domain && depth == conf.depth && qos == conf.qos &&
203 qos_ext == conf.qos_ext;
204}
205
206inline bool DdstConf::operator!=(const DdstConf& conf) const noexcept { return !(*this == conf); }
207
208inline TransportType DdstConf::get_transport_type() const { return TransportType::kDdst; }
209
210} // namespace vlink
211
212#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.