VLink 2.0.0
A high-performance communication middleware
Loading...
Searching...
No Matches
ddsc_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 ddsc_conf.h
26 * @brief Transport configuration for the @c ddsc:// CycloneDDS backend.
27 *
28 * @details
29 * @c DdscConf configures the Eclipse CycloneDDS transport, an open-source
30 * DDS implementation that targets both embedded and cloud deployments.
31 * It provides the same VLink API as @c DdsConf (Fast-DDS) but delegates to
32 * CycloneDDS internally.
33 *
34 * @par Supported Node Types
35 * @c ddsc:// 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 * ddsc://<topic>[?domain=<N>&depth=<N>&qos=<name>]
41 * @endcode
42 *
43 * | Component | Description |
44 * | --------- | ------------------------------------------------------------------------- |
45 * | @c topic | CycloneDDS topic name; formed from @c host + @c "/" + @c path |
46 * | @c domain | DDS Domain ID (@c ?domain=, default from @c VLINK_DDS_DOMAIN env var) |
47 * | @c depth | History depth for the endpoint (@c ?depth=, default 0) |
48 * | @c qos | Named QoS profile registered via @c register_qos() (@c ?qos=) |
49 *
50 * @par QoS Registration
51 * @code
52 * vlink::Qos my_qos;
53 * my_qos.reliability = vlink::Reliability::kReliable;
54 * vlink::DdscConf::register_qos("my_profile", my_qos);
55 *
56 * vlink::Subscriber<MyMsg> sub("ddsc://my_topic?qos=my_profile");
57 * @endcode
58 *
59 * @note This header is compiled only when @c VLINK_SUPPORT_DDSC is defined.
60 * @note Unlike @c DdsConf, @c DdscConf does not support @c register_topic() or
61 * extended QoS maps (@c qos_ext).
62 */
63
64#pragma once
65
66#ifdef VLINK_SUPPORT_DDSC
67
68#include <cstdint>
69#include <functional>
70#include <map>
71#include <shared_mutex>
72#include <string>
73
74#include "../extension/qos.h"
75#include "../impl/conf.h"
76
77namespace vlink {
78
79/**
80 * @struct DdscConf
81 * @brief Configuration for the @c ddsc:// CycloneDDS transport.
82 *
83 * @details
84 * Can be constructed directly or parsed from a URL string via @c Url.
85 */
86struct VLINK_EXPORT DdscConf final : public Conf {
87 std::string topic; ///< CycloneDDS topic name (host + "/" + path from URL).
88 int32_t domain{0}; ///< DDS Domain Participant ID (non-negative).
89 int32_t depth{0}; ///< DDS history depth for the endpoint; 0 means transport default.
90 std::string qos; ///< Named QoS profile key registered via @c register_qos().
91
92 /**
93 * @brief Constructs a @c DdscConf with explicit parameters.
94 *
95 * @param _topic CycloneDDS topic name.
96 * @param _domain Domain ID; default 0.
97 * @param _depth History depth; default 0.
98 * @param _qos Named QoS profile key; empty by default.
99 */
100 explicit DdscConf(const std::string& _topic, int32_t _domain = 0, int32_t _depth = 0, const std::string& _qos = "");
101
102 /**
103 * @brief Returns @c true if all fields equal those of @p conf.
104 *
105 * @param conf Configuration to compare.
106 * @return @c true if @c topic, @c domain, @c depth, and @c qos all match.
107 */
108 [[nodiscard]] bool operator==(const DdscConf& conf) const noexcept;
109
110 /**
111 * @brief Returns @c true if any field differs from @p conf.
112 *
113 * @param conf Configuration to compare.
114 * @return Logical negation of @c operator==.
115 */
116 [[nodiscard]] bool operator!=(const DdscConf& conf) const noexcept;
117
118 /**
119 * @brief Returns @c TransportType::kDdsc identifying this transport.
120 *
121 * @return @c TransportType::kDdsc.
122 */
123 [[nodiscard]] TransportType get_transport_type() const override;
124
125 /**
126 * @brief Registers a named QoS profile for use by @c ddsc:// nodes.
127 *
128 * @details
129 * The @p name is associated with the @p qos object and can be referenced in URL
130 * query strings as @c ?qos=name. Names that conflict with reserved keys
131 * (@c part, @c topic, @c pub, @c sub, @c writer, @c reader, @c depth) or that
132 * are already registered cause a fatal log and are rejected.
133 *
134 * @param name Unique profile name; must not be one of the reserved keys.
135 * @param qos @c Qos object describing the quality-of-service settings.
136 */
137 static void register_qos(const std::string& name, const Qos& qos);
138
139 private:
140 static void register_qos_internal(const std::string& name, const Qos& qos);
141
142 static const Qos& find_qos(const std::string& name);
143
144 friend class DdscFactory;
145 static std::map<std::string, Qos> qos_map_;
146 static std::shared_mutex mtx_;
147 static constexpr const char* kRespSuffix{"___resp"};
148#ifndef VLINK_ENABLE_C_INTERFACE
150#endif
151 VLINK_ALLOW_IMPL_TYPE(kServer | kClient | kPublisher | kSubscriber | kSetter | kGetter)
152 VLINK_CONF_IMPL(DdscConf)
153};
154
155////////////////////////////////////////////////////////////////
156/// Details
157////////////////////////////////////////////////////////////////
158
159inline DdscConf::DdscConf(const std::string& _topic, int32_t _domain, int32_t _depth, const std::string& _qos)
160 : topic(_topic), domain(_domain), depth(_depth), qos(_qos) {}
161
162inline bool DdscConf::operator==(const DdscConf& conf) const noexcept {
163 return topic == conf.topic && domain == conf.domain && depth == conf.depth && qos == conf.qos;
164}
165
166inline bool DdscConf::operator!=(const DdscConf& conf) const noexcept { return !(*this == conf); }
167
168inline TransportType DdscConf::get_transport_type() const { return TransportType::kDdsc; }
169
170} // namespace vlink
171
172#endif
Abstract transport configuration base class and associated helper macros.
#define VLINK_CONF_IMPL(classname)
Standard boilerplate for concrete Conf subclass declarations.
Definition conf.h:227
#define VLINK_DECLARE_GLOBAL_PROPERTY()
Declares per-transport global state: thread count and property storage.
Definition conf.h:292
#define VLINK_ALLOW_IMPL_TYPE(type)
Declares a static constexpr bitmask of supported ImplType values.
Definition conf.h:268
#define VLINK_EXPORT
Definition macros.h:85
Quality of Service (QoS) policy aggregate for VLink publishers and subscribers.