VLink 2.0.0
A high-performance communication middleware
Loading...
Searching...
No Matches
fdbus_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 fdbus_conf.h
26 * @brief Transport configuration for the @c fdbus:// FDBus IPC backend.
27 *
28 * @details
29 * @c FdbusConf configures the FDBus IPC transport, a same-machine inter-process
30 * communication framework based on D-Bus-style service registration. FDBus
31 * supports both service-oriented (@c svc) and peer-to-peer IPC (@c ipc) modes.
32 *
33 * @par Supported Node Types
34 * @c fdbus:// supports all six node types: @c kPublisher, @c kSubscriber, @c kServer,
35 * @c kClient, @c kSetter, and @c kGetter.
36 *
37 * @par URL Format
38 * @code
39 * fdbus://<address>[?event=<name>][#<transport>]
40 * @endcode
41 *
42 * | Component | Description |
43 * | ---------- | --------------------------------------------------------------------- |
44 * | @c address | FDBus service/topic address; formed from @c host + @c "/" + @c path |
45 * | @c event | Optional secondary event name (@c ?event=) |
46 * | @c transport | Transport mode: @c "svc" (service, default) or @c "ipc" (fragment) |
47 *
48 * @par Example
49 * @code
50 * // Service-oriented mode (default):
51 * vlink::Publisher<MyMsg> pub("fdbus://my_service");
52 *
53 * // IPC mode via URL fragment:
54 * vlink::Publisher<MyMsg> pub("fdbus://my_service#ipc");
55 *
56 * // Direct construction:
57 * vlink::FdbusConf conf("my_service", "my_event", "svc");
58 * vlink::Publisher<MyMsg> pub(conf);
59 * @endcode
60 *
61 * @note This header is compiled only when @c VLINK_SUPPORT_FDBUS is defined.
62 * @note @c is_valid() returns @c false if @c address is empty or @c transport is
63 * neither @c "svc" nor @c "ipc".
64 */
65
66#pragma once
67
68#ifdef VLINK_SUPPORT_FDBUS
69
70#include <cstdint>
71#include <string>
72
73#include "../impl/conf.h"
74
75namespace vlink {
76
77/**
78 * @struct FdbusConf
79 * @brief Configuration for the @c fdbus:// FDBus IPC transport.
80 *
81 * @details
82 * Can be constructed directly or parsed from a URL string via @c Url.
83 * The URL fragment selects the transport mode (@c "svc" or @c "ipc").
84 */
85struct VLINK_EXPORT FdbusConf final : public Conf {
86 std::string address; ///< FDBus service/topic address (host + "/" + path from URL).
87 std::string event; ///< Optional secondary event name.
88 std::string transport{"svc"}; ///< Transport mode: @c "svc" (service registry) or @c "ipc" (direct IPC).
89
90 /**
91 * @brief Constructs a @c FdbusConf with explicit parameters.
92 *
93 * @param _address Service/topic address string.
94 * @param _event Optional event name; empty by default.
95 * @param _transport Transport mode: @c "svc" or @c "ipc"; default @c "svc".
96 */
97 explicit FdbusConf(const std::string& _address, const std::string& _event = "",
98 const std::string& _transport = "svc");
99
100 /**
101 * @brief Returns @c true if address and event match @p conf.
102 *
103 * @details
104 * Note that @c transport is intentionally excluded from equality comparison.
105 *
106 * @param conf Configuration to compare.
107 * @return @c true if @c address and @c event are equal.
108 */
109 [[nodiscard]] bool operator==(const FdbusConf& conf) const noexcept;
110
111 /**
112 * @brief Returns @c true if address or event differ from @p conf.
113 *
114 * @param conf Configuration to compare.
115 * @return Logical negation of @c operator==.
116 */
117 [[nodiscard]] bool operator!=(const FdbusConf& conf) const noexcept;
118
119 /**
120 * @brief Returns @c TransportType::kFdbus identifying this transport.
121 *
122 * @return @c TransportType::kFdbus.
123 */
124 [[nodiscard]] TransportType get_transport_type() const override;
125
126 /**
127 * @brief Cheap probe for whether the FDBus @c name_server daemon is running.
128 *
129 * @details
130 * Non-invasive check intended for CLI diagnostics, bench preflight and
131 * self-test skip logic. Does NOT create any FDBus endpoint, does NOT open
132 * any connection, and is safe to call repeatedly from any thread.
133 *
134 * @return @c true if a @c name_server process is currently running on this
135 * host, otherwise @c false.
136 */
137 [[nodiscard]] static bool has_name_server();
138
139#ifndef VLINK_ENABLE_C_INTERFACE
141#endif
142 VLINK_ALLOW_IMPL_TYPE(kServer | kClient | kPublisher | kSubscriber | kSetter | kGetter)
143 VLINK_CONF_IMPL(FdbusConf)
144};
145
146////////////////////////////////////////////////////////////////
147/// Details
148////////////////////////////////////////////////////////////////
149
150inline FdbusConf::FdbusConf(const std::string& _address, const std::string& _event, const std::string& _transport)
151 : address(_address), event(_event), transport(_transport) {}
152
153inline bool FdbusConf::operator==(const FdbusConf& conf) const noexcept {
154 return address == conf.address && event == conf.event;
155}
156
157inline bool FdbusConf::operator!=(const FdbusConf& conf) const noexcept { return !(*this == conf); }
158
159inline TransportType FdbusConf::get_transport_type() const { return TransportType::kFdbus; }
160
161} // namespace vlink
162
163#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