VLink  2.0.0
A high-performance communication middleware
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 transport.
27  *
28  * @details
29  * @c FdbusConf binds the @c fdbus:// URL scheme to FDBus, a D-Bus-inspired IPC
30  * framework optimised for same-machine, multi-process communication in embedded
31  * Linux systems. FDBus exposes both a service-oriented (broker-mediated) mode and
32  * a peer-to-peer IPC mode; the chosen mode is selected through the URL fragment.
33  * The transport is in-host only -- it does not cross machine boundaries.
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  * fdbus://<address>[?event=<name>][#<transport>]
44  * @endcode
45  *
46  * | Component | Description |
47  * | ------------ | -------------------------------------------------------------------------- |
48  * | @c address | FDBus service/topic address (URL host concatenated with path) |
49  * | @c event | Optional secondary event name selector (@c ?event=) |
50  * | @c transport | URL fragment; @c "svc" (service registry, default) or @c "ipc" (direct) |
51  *
52  * @par Service / Endpoint Model
53  *
54  * | Role | FDBus entity | VLink mapping |
55  * | ----------- | -------------------- | ---------------------------------------------- |
56  * | Publisher | CBaseServer event | Outgoing broadcast on @c address[/event] |
57  * | Subscriber | CBaseClient event | Listens on @c address[/event] |
58  * | Server | CBaseServer method | Handles invokes routed to @c address |
59  * | Client | CBaseClient invoker | Calls @c address request method |
60  * | Setter | CBaseServer property | Publishes latest value to subscribers |
61  * | Getter | CBaseClient watcher | Fetches and caches the latest value |
62  *
63  * @par Example
64  * @code
65  * auto pub_svc = vlink::Publisher<MyMsg>::create_unique("fdbus://my_service");
66  * auto pub_ipc = vlink::Publisher<MyMsg>::create_unique("fdbus://my_service#ipc");
67  *
68  * vlink::FdbusConf conf("my_service", "my_event", "svc");
69  * auto pub_direct = vlink::Publisher<MyMsg>::create_unique(conf);
70  * @endcode
71  *
72  * @note Compiled only when @c VLINK_SUPPORT_FDBUS is defined.
73  * @note @c is_valid() returns @c false when @c address is empty or @c transport is
74  * neither @c "svc" nor @c "ipc".
75  */
76 
77 #pragma once
78 
79 #ifdef VLINK_SUPPORT_FDBUS
80 
81 #include <cstdint>
82 #include <string>
83 
84 #include "../impl/conf.h"
85 
86 namespace vlink {
87 
88 /**
89  * @struct FdbusConf
90  * @brief Concrete @c Conf describing an FDBus IPC endpoint addressed by a @c fdbus:// URL.
91  *
92  * @details
93  * Stores the FDBus service address, an optional secondary event name, and the
94  * transport mode. The fragment of the URL selects @c "svc" (default, service
95  * registry) versus @c "ipc" (direct peer-to-peer). Equality compares only
96  * @c address and @c event so two endpoints sharing a topic but using different
97  * transports remain interchangeable in identity-tracking maps.
98  */
99 struct VLINK_EXPORT FdbusConf final : public Conf {
100  std::string address; ///< FDBus service/topic address (URL host concatenated with path).
101  std::string event; ///< Optional secondary event name selector.
102  std::string transport{"svc"}; ///< Transport mode; @c "svc" (service registry) or @c "ipc" (direct IPC).
103 
104  /**
105  * @brief Builds an @c FdbusConf from its three logical fields.
106  *
107  * @param _address Service/topic address string.
108  * @param _event Optional event name; empty by default.
109  * @param _transport Transport mode; @c "svc" or @c "ipc"; defaults to @c "svc".
110  */
111  explicit FdbusConf(const std::string& _address, const std::string& _event = "",
112  const std::string& _transport = "svc");
113 
114  /**
115  * @brief Identity-style equality that compares @c address and @c event only.
116  *
117  * @details
118  * @c transport is intentionally excluded so the same logical endpoint can be
119  * deduplicated regardless of whether it is reached through the service registry
120  * or directly via IPC.
121  *
122  * @param conf Configuration to compare with.
123  * @return @c true when @c address and @c event are equal.
124  */
125  [[nodiscard]] bool operator==(const FdbusConf& conf) const noexcept;
126 
127  /**
128  * @brief Logical negation of @c operator==.
129  *
130  * @param conf Configuration to compare with.
131  * @return @c true when @c address or @c event differ.
132  */
133  [[nodiscard]] bool operator!=(const FdbusConf& conf) const noexcept;
134 
135  /**
136  * @brief Reports this object's transport tag.
137  *
138  * @return @c TransportType::kFdbus.
139  */
140  [[nodiscard]] TransportType get_transport_type() const override;
141 
142  /**
143  * @brief Cheap, non-invasive probe for the FDBus @c name_server daemon.
144  *
145  * @details
146  * Intended for CLI diagnostics, bench preflight, and self-test skip logic. Does
147  * not create any FDBus endpoint, does not open any connection, and is safe to
148  * call repeatedly from any thread.
149  *
150  * @return @c true when an @c name_server process is currently running on the
151  * local host, @c false otherwise.
152  */
153  [[nodiscard]] static bool has_name_server();
154 
155 #ifndef VLINK_ENABLE_C_INTERFACE
157 #endif
159  VLINK_CONF_IMPL(FdbusConf)
160 };
161 
162 ////////////////////////////////////////////////////////////////
163 /// Details
164 ////////////////////////////////////////////////////////////////
165 
166 inline FdbusConf::FdbusConf(const std::string& _address, const std::string& _event, const std::string& _transport)
167  : address(_address), event(_event), transport(_transport) {}
168 
169 inline bool FdbusConf::operator==(const FdbusConf& conf) const noexcept {
170  return address == conf.address && event == conf.event;
171 }
172 
173 inline bool FdbusConf::operator!=(const FdbusConf& conf) const noexcept { return !(*this == conf); }
174 
175 inline TransportType FdbusConf::get_transport_type() const { return TransportType::kFdbus; }
176 
177 } // namespace vlink
178 
179 #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