VLink  2.0.0
A high-performance communication middleware
url.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 url.h
26  * @brief URL-driven configuration dispatcher that selects and forwards to a transport @c Conf.
27  *
28  * @details
29  * This is an internal implementation header used by every public node template
30  * to translate a URL string into a concrete transport backend. It also re-exports
31  * all transport @c *Conf headers and the @c *Impl headers so the impl layer can
32  * be pulled in with a single include. Two types are introduced:
33  *
34  * @par Protocol
35  * A small plain-data struct populated by the @c UrlParser pipeline. It owns
36  * the URL string (after any @c VLINK_URL_REMAP rewriting) plus the resolved
37  * @c TransportType and the parsed host, path, query dictionary and fragment.
38  * Only @c Url may construct a @c Protocol -- the constructor is private and
39  * @c Url is its only friend.
40  *
41  * @par Url
42  * A concrete @c Conf subclass that wraps a @c Protocol, builds the matching
43  * transport @c Conf in @c init_target_internal() and forwards every virtual
44  * @c Conf hook to that target. Constructing a @c Url is the entry point used
45  * by every public Node<> template to set up its transport backend.
46  *
47  * @par Protocol struct fields
48  * | Field | Meaning |
49  * | -------------- | -------------------------------------------------------- |
50  * | @c str | Full URL string after any @c VLINK_URL_REMAP rewrite. |
51  * | @c transport | Resolved transport backend identifier. |
52  * | @c host | Hostname or IP component, if any. |
53  * | @c path | Topic path component. |
54  * | @c dictionary | Query parameters parsed into a @c std::map. |
55  * | @c fragment | Fragment identifier following @c #. |
56  *
57  * @par Transport prefix to backend
58  * | URL prefix | Conf class created in @c init_target_internal() |
59  * | ------------- | ----------------------------------------------- |
60  * | @c intra:// | @c IntraConf |
61  * | @c shm:// | @c ShmConf |
62  * | @c shm2:// | @c Shm2Conf |
63  * | @c zenoh:// | @c ZenohConf |
64  * | @c dds:// | @c DdsConf |
65  * | @c ddsc:// | @c DdscConf |
66  * | @c ddsr:// | @c DdsrConf |
67  * | @c ddst:// | @c DdstConf |
68  * | @c someip:// | @c SomeipConf |
69  * | @c mqtt:// | @c MqttConf |
70  * | @c fdbus:// | @c FdbusConf |
71  * | @c qnx:// | @c QnxConf |
72  * | other | Unsupported; custom schemes are not registered. |
73  *
74  * @par Construction flow
75  * @code
76  * URL string -> UrlParser -> Protocol -> init_target_internal() -> *Conf
77  * |
78  * v
79  * parse(impl_type)
80  * |
81  * v
82  * create_publisher() / create_subscriber() / ...
83  * |
84  * v
85  * NodeImpl backend instance
86  * @endcode
87  *
88  * @par URL Remapping
89  * When @c VLINK_URL_USE_REMAP is enabled, the @c Protocol constructor inspects
90  * the @c VLINK_URL_REMAP environment variable and rewrites the URL before the
91  * transport is resolved. This enables transport switching without touching
92  * application code.
93  *
94  * @par Plugin loading
95  * When @c VLINK_URL_USE_PLUGIN is enabled, @c Url::init_plugins() loads shared
96  * libraries listed in the @c VLINK_URL_PLUGINS environment variable. Each
97  * library name must map to an existing @c TransportType; loaded
98  * @c ConfPluginInterface entries are consulted only for recognized transports
99  * whose backend is not linked in. @c TransportType::kUnknown is not passed to
100  * plugins, so arbitrary URL schemes cannot be added through this mechanism.
101  *
102  * @par Transport enable flags
103  * @c TransportEnableFlag is a bitmask that selects which built-in transports
104  * participate in @c global_init() and @c init_plugins(). Embedding
105  * environments (Android, QNX, etc.) use it to skip transports they cannot
106  * support at runtime.
107  *
108  * @par Example
109  * @code
110  * vlink::Url url("dds://vehicle/speed?domain=1");
111  *
112  * if (url.parse(vlink::kSubscriber)) {
113  * auto impl = url.get_target() != nullptr
114  * ? std::unique_ptr<vlink::SubscriberImpl>{}
115  * : nullptr;
116  * // Public Subscriber<T> template performs this call internally.
117  * auto sub = vlink::Subscriber<MyMsg>::create_unique(url.get_str());
118  * }
119  * @endcode
120  *
121  * @note This file is the single aggregation point for the VLink impl layer; it
122  * transitively includes every transport @c *_conf.h header and every
123  * @c *_impl.h header.
124  */
125 
126 #pragma once
127 
128 #include <map>
129 #include <memory>
130 #include <string>
131 #include <utility>
132 
133 #include "../base/logger.h"
134 #include "./conf.h"
135 
136 // NOLINTBEGIN
137 #include "../modules/dds_conf.h"
138 #include "../modules/ddsc_conf.h"
139 #include "../modules/ddsr_conf.h"
140 #include "../modules/ddst_conf.h"
141 #include "../modules/fdbus_conf.h"
142 #include "../modules/intra_conf.h"
143 #include "../modules/mqtt_conf.h"
144 #include "../modules/qnx_conf.h"
145 #include "../modules/shm2_conf.h"
146 #include "../modules/shm_conf.h"
147 #include "../modules/someip_conf.h"
148 #include "../modules/zenoh_conf.h"
149 //
150 #include "./client_impl.h"
151 #include "./getter_impl.h"
152 #include "./publisher_impl.h"
153 #include "./server_impl.h"
154 #include "./setter_impl.h"
155 #include "./subscriber_impl.h"
156 // NOLINTEND
157 
158 namespace vlink {
159 
160 /**
161  * @struct Protocol
162  * @brief Plain-data record describing the parsed components of a VLink URL.
163  *
164  * @details
165  * Built by @c Protocol(const std::string& address), which feeds the URL through
166  * @c UrlParser, applies any @c VLINK_URL_REMAP rewriting and resolves the
167  * @c TransportType from the URI scheme. Only @c Url may construct a
168  * @c Protocol (the constructor is private and @c Url is the sole friend).
169  *
170  * @note The @c str field is the URL string after remap, not a reconstruction
171  * from the other fields.
172  */
173 struct VLINK_EXPORT Protocol final {
174  std::string str; ///< URL string after remap, if any.
175  TransportType transport; ///< Resolved transport backend identifier.
176  std::string host; ///< Hostname or IP component, if any.
177  std::string path; ///< Topic path component.
178  std::map<std::string, std::string> dictionary; ///< Query parameters parsed into a key/value dictionary.
179  std::string fragment; ///< Fragment identifier (after @c #).
180 
181  private:
182  friend struct Url;
183  explicit Protocol(const std::string& address);
184 };
185 
186 /**
187  * @struct Url
188  * @brief @c Conf subclass that routes virtual calls to the transport selected by a URL string.
189  *
190  * @details
191  * Construction parses the URL into a @c Protocol and then runs
192  * @c init_target_internal() to instantiate the matching transport @c Conf
193  * (@c target_). Every @c Conf virtual hook is forwarded to @c target_; the
194  * caller need only build one @c Url instance per topic.
195  *
196  * @par Full lifecycle
197  * @code
198  * // 1. Construct with URL string:
199  * Url url("dds://vehicle/speed");
200  * // -> Protocol("dds://vehicle/speed") -> transport == kDds
201  * // -> init_target_internal() -> target_ = make_unique<DdsConf>()
202  *
203  * // 2. Parse for a specific node role:
204  * url.parse(kSubscriber);
205  * // -> target_->parse(kSubscriber)
206  * // -> target_->parse_protocol(&protocol_)
207  *
208  * // 3. Create the transport implementation:
209  * auto impl = url.create_subscriber();
210  * // -> target_->create_subscriber()
211  * @endcode
212  */
213 struct Url final : public Conf {
214  /**
215  * @enum TransportEnableFlag
216  * @brief Bitmask that selects which transports participate in @c global_init() / @c init_plugins().
217  *
218  * @details
219  * Embedding environments (e.g. Android, QNX) pass a subset of these flags to
220  * skip transports they cannot support at runtime. Bit positions are
221  * independent of the numeric @c TransportType values.
222  *
223  * | Flag | Bit position | Transport |
224  * | ---------------- | ------------ | --------------- |
225  * | @c kEnableIntra | 15 | @c intra:// |
226  * | @c kEnableShm | 14 | @c shm:// |
227  * | @c kEnableShm2 | 13 | @c shm2:// |
228  * | @c kEnableZenoh | 12 | @c zenoh:// |
229  * | @c kEnableDds | 11 | @c dds:// |
230  * | @c kEnableDdsc | 10 | @c ddsc:// |
231  * | @c kEnableDdsr | 9 | @c ddsr:// |
232  * | @c kEnableDdst | 8 | @c ddst:// |
233  * | @c kEnableSomeip | 7 | @c someip:// |
234  * | @c kEnableMqtt | 6 | @c mqtt:// |
235  * | @c kEnableFdbus | 5 | @c fdbus:// |
236  * | @c kEnableQnx | 4 | @c qnx:// |
237  * | @c kEnableAll | all bits set | Every transport |
238  */
239  enum TransportEnableFlag : uint16_t {
240  kEnableEmpty = 0b0000'0000'0000'0000, ///< No transport enabled.
241  kEnableIntra = 0b1000'0000'0000'0000, ///< Enable the @c intra:// transport.
242  kEnableShm = 0b0100'0000'0000'0000, ///< Enable the @c shm:// (Iceoryx) transport.
243  kEnableShm2 = 0b0010'0000'0000'0000, ///< Enable the @c shm2:// (Iceoryx2) transport.
244  kEnableZenoh = 0b0001'0000'0000'0000, ///< Enable the @c zenoh:// transport.
245  kEnableDds = 0b0000'1000'0000'0000, ///< Enable the @c dds:// (Fast-DDS) transport.
246  kEnableDdsc = 0b0000'0100'0000'0000, ///< Enable the @c ddsc:// (CycloneDDS) transport.
247  kEnableDdsr = 0b0000'0010'0000'0000, ///< Enable the @c ddsr:// (RTI DDS) transport.
248  kEnableDdst = 0b0000'0001'0000'0000, ///< Enable the @c ddst:// (TravoDDS) transport.
249  kEnableSomeip = 0b0000'0000'1000'0000, ///< Enable the @c someip:// transport.
250  kEnableMqtt = 0b0000'0000'0100'0000, ///< Enable the @c mqtt:// transport.
251  kEnableFdbus = 0b0000'0000'0010'0000, ///< Enable the @c fdbus:// transport.
252  kEnableQnx = 0b0000'0000'0001'0000, ///< Enable the @c qnx:// transport (QNX only).
253  kEnableAll = 0b1111'1111'1111'1111, ///< Enable every transport.
254  };
255 
256  /**
257  * @brief Builds a @c Url from a transport address string.
258  *
259  * @details
260  * Parses @p str into a @c Protocol, then delegates to
261  * @c init_target_internal() to allocate the matching transport @c Conf.
262  * Triggers a fatal log entry when no transport backend matches the URL.
263  *
264  * @param str VLink URL string (e.g. @c "dds://vehicle/speed").
265  */
266  explicit Url(const std::string& str);
267 
268  /**
269  * @brief Copy constructor.
270  *
271  * @details
272  * Copies the @c Protocol from @p url and rebuilds a fresh @c target_ via
273  * @c init_target_internal(), so the two @c Url objects do not share the
274  * same transport @c Conf instance.
275  *
276  * @param url Source @c Url to copy.
277  */
278  Url(const Url& url);
279 
280  /**
281  * @brief Move constructor.
282  *
283  * @details
284  * Transfers both @c protocol_ and @c target_ from @p url; no rebuild is
285  * performed.
286  *
287  * @param url Source @c Url to move from.
288  */
289  Url(Url&& url) noexcept;
290 
291  /**
292  * @brief Destructor.
293  */
294  ~Url() override;
295 
296  /**
297  * @brief Copy assignment.
298  *
299  * @details
300  * Copies @c protocol_ and re-runs @c init_target_internal() to rebuild
301  * @c target_.
302  *
303  * @param url Source @c Url.
304  * @return Reference to @c *this.
305  */
306  Url& operator=(const Url& url);
307 
308  /**
309  * @brief Move assignment.
310  *
311  * @param url Source @c Url.
312  * @return Reference to @c *this.
313  */
314  Url& operator=(Url&& url) noexcept;
315 
316  /**
317  * @brief Returns the stored URL string (after any @c VLINK_URL_REMAP rewrite).
318  *
319  * @return Reference to the string stored inside @c Protocol::str.
320  */
321  [[nodiscard]] const std::string& get_str() const;
322 
323  /**
324  * @brief Returns the underlying transport @c Conf or @c nullptr.
325  *
326  * @details
327  * Lets callers downcast the active transport conf for transport-specific
328  * inspection (for example to a @c DdsConf for native DDS QoS).
329  *
330  * @return Pointer to the cached transport @c Conf; @c nullptr when the URL
331  * was invalid or @c init_target_internal() failed.
332  */
333  [[nodiscard]] const Conf* get_target() const;
334 
335  /**
336  * @brief Parses the URL for @p impl_type by delegating to @c target_.
337  *
338  * @details
339  * Chains @c Conf::parse(impl_type), @c target_->parse(impl_type) and
340  * @c target_->parse_protocol(); returns @c false on @c target_ being null
341  * or any step failing.
342  *
343  * @param impl_type Bitmask of @c ImplType roles to validate.
344  * @return @c true when every step succeeds; @c false otherwise.
345  */
346  bool parse(ImplType impl_type) const override;
347 
348  /**
349  * @brief Reports whether the underlying @c target_ conf is valid.
350  *
351  * @return Result of @c target_->is_valid(), or @c false when @c target_ is null.
352  */
353  [[nodiscard]] bool is_valid() const override;
354 
355  /**
356  * @brief Returns the @c ImplType cached by the most recent @c target_->parse().
357  *
358  * @return Cached @c ImplType, or @c kUnknownImplType when @c target_ is null.
359  */
360  [[nodiscard]] ImplType get_impl_type() const override;
361 
362  /**
363  * @brief Returns the transport backend identifier resolved from the URL.
364  *
365  * @return @c TransportType value, or @c TransportType::kUnknown when no transport was resolved.
366  */
367  [[nodiscard]] TransportType get_transport_type() const override;
368 
369  /**
370  * @brief Loads recognized transport plugins from @c VLINK_URL_PLUGINS.
371  *
372  * @details
373  * Entries in @c VLINK_URL_PLUGINS must map to existing VLink transport module
374  * names such as @c zenoh or @c ddsc; unknown names are rejected before the
375  * shared library loader is called. This API loads alternate implementations
376  * for known transports, not arbitrary new URL schemes.
377  *
378  * Discovered plugins whose @c TransportType already appears in
379  * @p transport_enable_flags are skipped so that linked transports continue
380  * to take precedence. The first @c Url construction triggers this call
381  * automatically; explicit invocations are only needed for unusual
382  * initialisation sequences.
383  *
384  * @param transport_enable_flags Bitmask of built-in transports already
385  * available; matching plugins are ignored.
386  */
387  VLINK_EXPORT static void init_plugins(uint16_t transport_enable_flags = 0);
388 
389  /**
390  * @brief Asks loaded plugins for a @c Conf factory matching @p type.
391  *
392  * @details
393  * Looks up a previously registered @c ConfPluginInterface whose
394  * @c get_transport_type() returns @p type and invokes @c create() on it.
395  *
396  * @param type Transport backend to look up.
397  * @return Newly created @c Conf, or @c nullptr when no plugin matches.
398  */
399  [[nodiscard]] VLINK_EXPORT static std::unique_ptr<Conf> load_for_plugin(TransportType type);
400 
401  /**
402  * @brief Returns a numeric sort index for the transport backend of @p url.
403  *
404  * @details
405  * Used to order URLs by transport priority. Local transports
406  * (@c intra://, @c shm://) yield lower indices than network transports.
407  * Empty URLs return @c -1, while non-empty URLs whose transport is unknown
408  * still return @c 0 so they can participate in low-priority sorting.
409  *
410  * @param url URL string to classify.
411  * @return Sort index; lower values mean higher priority.
412  */
413  [[nodiscard]] VLINK_EXPORT static int get_sort_index(std::string_view url);
414 
415  /**
416  * @brief Returns whether @p url designates a same-machine transport.
417  *
418  * @details
419  * A URL is local when it uses @c intra://, @c shm:// or @c shm2://.
420  *
421  * @param url URL string to classify.
422  * @return @c true for local transports; @c false for network ones.
423  */
424  [[nodiscard]] VLINK_EXPORT static bool is_local_type(std::string_view url);
425 
426  /**
427  * @brief Returns whether @p url designates the @c intra:// in-process transport.
428  *
429  * @param url URL string to classify.
430  * @return @c true only for @c intra:// URLs.
431  */
432  [[nodiscard]] VLINK_EXPORT static bool is_intra_type(std::string_view url);
433 
434  /**
435  * @brief Returns whether @p url uses a shared-memory transport.
436  *
437  * @param url URL string to classify.
438  * @return @c true for both @c shm:// and @c shm2:// URLs.
439  */
440  [[nodiscard]] VLINK_EXPORT static bool is_shm_type(std::string_view url);
441 
442  /**
443  * @brief Initialises the process-wide state for every enabled transport.
444  *
445  * @details
446  * Calls @c NodeImpl::global_init() first and then each @c *Conf::global_init()
447  * whose bit appears in @p transport_enable_flags. Passing @c 0 expands to
448  * all compiled-in transports. Must run once before any @c Url is created
449  * when fine-grained transport selection is required; otherwise the
450  * transports are lazily initialised on first use.
451  *
452  * @param transport_enable_flags Bitmask of @c TransportEnableFlag values.
453  */
454  static void global_init(uint16_t transport_enable_flags = 0);
455 
456  /**
457  * @brief Returns a bitmask of all compile-time-enabled transports.
458  *
459  * @details
460  * Computed from the @c VLINK_SUPPORT_* preprocessor flags. The result can
461  * be passed to @c global_init() to initialise the available transports
462  * exactly.
463  *
464  * @return Bitmask of @c TransportEnableFlag values.
465  */
466  [[nodiscard]] static uint16_t get_transport_enable_flags();
467 
468  /**
469  * @brief Builds @c target_ for the resolved transport in @p protocol.
470  *
471  * @details
472  * Switches on @c Protocol::transport, allocates the matching @c *Conf class,
473  * and falls back to @c load_for_plugin() when no built-in backend matches.
474  * Logs a fatal entry when neither path succeeds.
475  *
476  * @param protocol Parsed URL information used to select the transport.
477  * @param target Output: receives the newly created @c Conf instance.
478  */
479  static void init_target_internal(const Protocol& protocol, std::unique_ptr<Conf>& target);
480 
481  private:
482  std::unique_ptr<ServerImpl> create_server() const override;
483 
484  std::unique_ptr<ClientImpl> create_client() const override;
485 
486  std::unique_ptr<PublisherImpl> create_publisher() const override;
487 
488  std::unique_ptr<SubscriberImpl> create_subscriber() const override;
489 
490  std::unique_ptr<SetterImpl> create_setter() const override;
491 
492  std::unique_ptr<GetterImpl> create_getter() const override;
493 
494  VLINK_EXPORT friend std::ostream& operator<<(std::ostream& ostream, const Url& conf) noexcept;
495 
496  mutable Protocol protocol_;
497  std::unique_ptr<Conf> target_;
499  VLINK_ALLOW_IMPL_TYPE(kServer | kClient | kPublisher | kSubscriber | kSetter | kGetter);
500 };
501 
502 ////////////////////////////////////////////////////////////////
503 /// Details
504 ////////////////////////////////////////////////////////////////
505 
506 inline Url::Url(const std::string& str) : protocol_(str) { init_target_internal(protocol_, target_); }
507 
508 // NOLINTNEXTLINE(bugprone-copy-constructor-init)
509 inline Url::Url(const Url& url) : protocol_(url.protocol_) { init_target_internal(protocol_, target_); }
510 
511 inline Url::Url(Url&& url) noexcept : protocol_(std::move(url.protocol_)), target_(std::move(url.target_)) {}
512 
513 inline Url::~Url() = default;
514 
515 inline Url& Url::operator=(const Url& url) {
516  if VUNLIKELY (this == &url) {
517  return *this;
518  }
519 
520  protocol_ = url.protocol_;
521 
522  init_target_internal(protocol_, target_);
523 
524  return *this;
525 }
526 
527 inline Url& Url::operator=(Url&& url) noexcept {
528  if VUNLIKELY (this == &url) {
529  return *this;
530  }
531 
532  protocol_ = std::move(url.protocol_);
533  target_ = std::move(url.target_);
534 
535  return *this;
536 }
537 
538 inline const std::string& Url::get_str() const { return protocol_.str; }
539 
540 inline const Conf* Url::get_target() const { return target_.get(); }
541 
542 inline bool Url::parse(ImplType impl_type) const {
543  if VUNLIKELY (!target_) {
544  return false; // LCOV_EXCL_LINE GCOVR_EXCL_LINE
545  }
546 
547  if VUNLIKELY (!Conf::parse(impl_type) || !target_->parse(impl_type)) {
548  return false; // LCOV_EXCL_LINE GCOVR_EXCL_LINE
549  }
550 
551  return target_->parse_protocol(&protocol_);
552 }
553 
554 inline bool Url::is_valid() const {
555  if VUNLIKELY (!target_) {
556  return false; // LCOV_EXCL_LINE GCOVR_EXCL_LINE
557  }
558 
559  return target_->is_valid();
560 }
561 
562 inline ImplType Url::get_impl_type() const {
563  if VUNLIKELY (!target_) {
564  return kUnknownImplType; // LCOV_EXCL_LINE GCOVR_EXCL_LINE
565  }
566 
567  return target_->get_impl_type();
568 }
569 
571  if VUNLIKELY (!target_) {
572  return TransportType::kUnknown; // LCOV_EXCL_LINE GCOVR_EXCL_LINE
573  }
574 
575  return target_->get_transport_type();
576 }
577 
578 inline void Url::global_init(uint16_t transport_enable_flags) {
579  if (transport_enable_flags == 0) {
580  transport_enable_flags = get_transport_enable_flags(); // LCOV_EXCL_LINE GCOVR_EXCL_LINE
581  }
582 
583  (void)transport_enable_flags;
584 
586 
587 #ifndef VLINK_ENABLE_C_INTERFACE
588 
589 #ifdef VLINK_SUPPORT_INTRA
590 
591  if (transport_enable_flags & kEnableIntra) {
592  IntraConf::global_init();
593  }
594 #endif
595 
596 #ifdef VLINK_SUPPORT_SHM
597 
598  if (transport_enable_flags & kEnableShm) {
599  ShmConf::global_init(); // LCOV_EXCL_LINE GCOVR_EXCL_LINE
600  }
601 #endif
602 
603 #ifdef VLINK_SUPPORT_SHM2
604 
605  if (transport_enable_flags & kEnableShm2) {
606  Shm2Conf::global_init(); // LCOV_EXCL_LINE GCOVR_EXCL_LINE
607  }
608 #endif
609 
610 #ifdef VLINK_SUPPORT_ZENOH
611 
612  if (transport_enable_flags & kEnableZenoh) {
613  ZenohConf::global_init(); // LCOV_EXCL_LINE GCOVR_EXCL_LINE
614  }
615 #endif
616 
617 #ifdef VLINK_SUPPORT_DDS
618 
619  if (transport_enable_flags & kEnableDds) {
620  DdsConf::global_init(); // LCOV_EXCL_LINE GCOVR_EXCL_LINE
621  }
622 #endif
623 
624 #ifdef VLINK_SUPPORT_DDSC
625 
626  if (transport_enable_flags & kEnableDdsc) {
627  DdscConf::global_init(); // LCOV_EXCL_LINE GCOVR_EXCL_LINE
628  }
629 #endif
630 
631 #ifdef VLINK_SUPPORT_DDSR
632 
633  if (transport_enable_flags & kEnableDdsr) {
634  DdsrConf::global_init();
635  }
636 #endif
637 
638 #ifdef VLINK_SUPPORT_DDST
639 
640  if (transport_enable_flags & kEnableDdst) {
641  DdstConf::global_init();
642  }
643 #endif
644 
645 #ifdef VLINK_SUPPORT_SOMEIP
646 
647  if (transport_enable_flags & kEnableSomeip) {
648  SomeipConf::global_init(); // LCOV_EXCL_LINE GCOVR_EXCL_LINE
649  }
650 #endif
651 
652 #ifdef VLINK_SUPPORT_MQTT
653 
654  if (transport_enable_flags & kEnableMqtt) {
655  MqttConf::global_init(); // LCOV_EXCL_LINE GCOVR_EXCL_LINE
656  }
657 #endif
658 
659 #ifdef VLINK_SUPPORT_FDBUS
660 
661  if (transport_enable_flags & kEnableFdbus) {
662  FdbusConf::global_init(); // LCOV_EXCL_LINE GCOVR_EXCL_LINE
663  }
664 #endif
665 
666 #ifdef VLINK_SUPPORT_QNX
667 
668  if (transport_enable_flags & kEnableQnx) {
669  QnxConf::global_init();
670  }
671 #endif
672 
673 #endif
674 }
675 
677  uint16_t flags = 0;
678 
679 #ifdef VLINK_SUPPORT_INTRA
680  flags |= kEnableIntra;
681 #endif
682 
683 #ifdef VLINK_SUPPORT_SHM
684  flags |= kEnableShm;
685 #endif
686 
687 #ifdef VLINK_SUPPORT_SHM2
688  flags |= kEnableShm2;
689 #endif
690 
691 #ifdef VLINK_SUPPORT_ZENOH
692  flags |= kEnableZenoh;
693 #endif
694 
695 #ifdef VLINK_SUPPORT_DDS
696  flags |= kEnableDds;
697 #endif
698 
699 #ifdef VLINK_SUPPORT_DDSC
700  flags |= kEnableDdsc;
701 #endif
702 
703 #ifdef VLINK_SUPPORT_DDSR
704  flags |= kEnableDdsr;
705 #endif
706 
707 #ifdef VLINK_SUPPORT_DDST
708  flags |= kEnableDdst;
709 #endif
710 
711 #ifdef VLINK_SUPPORT_SOMEIP
712  flags |= kEnableSomeip;
713 #endif
714 
715 #ifdef VLINK_SUPPORT_MQTT
716  flags |= kEnableMqtt;
717 #endif
718 
719 #ifdef VLINK_SUPPORT_FDBUS
720  flags |= kEnableFdbus;
721 #endif
722 
723 #ifdef VLINK_SUPPORT_QNX
724  flags |= kEnableQnx;
725 #endif
726 
727  return flags;
728 }
729 
730 inline void Url::init_target_internal(const Protocol& protocol, std::unique_ptr<Conf>& target) {
731  static auto transport_enable_flags = get_transport_enable_flags();
732 
733  Url::init_plugins(transport_enable_flags);
734 
735  // NOLINTBEGIN
736  switch (protocol.transport) {
737 #ifdef VLINK_SUPPORT_INTRA
739  target = std::make_unique<IntraConf>();
740  break;
741 #endif
742 
743 #ifdef VLINK_SUPPORT_SHM
744  case TransportType::kShm:
745  target = std::make_unique<ShmConf>();
746  break;
747 #endif
748 
749 #ifdef VLINK_SUPPORT_SHM2
751  target = std::make_unique<Shm2Conf>();
752  break;
753 #endif
754 
755 #ifdef VLINK_SUPPORT_ZENOH
757  target = std::make_unique<ZenohConf>();
758  break;
759 #endif
760 
761 #ifdef VLINK_SUPPORT_DDS
762  case TransportType::kDds:
763  target = std::make_unique<DdsConf>();
764  break;
765 #endif
766 
767 #ifdef VLINK_SUPPORT_DDSC
769  target = std::make_unique<DdscConf>();
770  break;
771 #endif
772 
773 #ifdef VLINK_SUPPORT_DDSR
775  target = std::make_unique<DdsrConf>();
776  break;
777 #endif
778 
779 #ifdef VLINK_SUPPORT_DDST
781  target = std::make_unique<DdstConf>();
782  break;
783 #endif
784 
785 #ifdef VLINK_SUPPORT_SOMEIP
787  target = std::make_unique<SomeipConf>();
788  break;
789 #endif
790 
791 #ifdef VLINK_SUPPORT_MQTT
793  target = std::make_unique<MqttConf>();
794  break;
795 #endif
796 
797 #ifdef VLINK_SUPPORT_FDBUS
799  target = std::make_unique<FdbusConf>();
800  break;
801 #endif
802 
803 #ifdef VLINK_SUPPORT_QNX
804  case TransportType::kQnx:
805  target = std::make_unique<QnxConf>();
806  break;
807 #endif
808 
809  default:
810  break;
811  }
812  // NOLINTEND
813 
814  if VUNLIKELY (!target) {
815  target = Url::load_for_plugin(protocol.transport);
816  }
817 
818  if VUNLIKELY (!target) {
819  CLOG_F("Unsupported url[%s].", protocol.str.c_str());
820  }
821 }
822 
823 inline std::unique_ptr<ServerImpl> Url::create_server() const {
824  if VUNLIKELY (!target_) {
825  return nullptr; // LCOV_EXCL_LINE GCOVR_EXCL_LINE
826  }
827 
828  return target_->create_server();
829 }
830 
831 inline std::unique_ptr<ClientImpl> Url::create_client() const {
832  if VUNLIKELY (!target_) {
833  return nullptr; // LCOV_EXCL_LINE GCOVR_EXCL_LINE
834  }
835 
836  return target_->create_client();
837 }
838 
839 inline std::unique_ptr<PublisherImpl> Url::create_publisher() const {
840  if VUNLIKELY (!target_) {
841  return nullptr; // LCOV_EXCL_LINE GCOVR_EXCL_LINE
842  }
843 
844  return target_->create_publisher();
845 }
846 
847 inline std::unique_ptr<SubscriberImpl> Url::create_subscriber() const {
848  if VUNLIKELY (!target_) {
849  return nullptr; // LCOV_EXCL_LINE GCOVR_EXCL_LINE
850  }
851 
852  return target_->create_subscriber();
853 }
854 
855 inline std::unique_ptr<SetterImpl> Url::create_setter() const {
856  if VUNLIKELY (!target_) {
857  return nullptr; // LCOV_EXCL_LINE GCOVR_EXCL_LINE
858  }
859 
860  return target_->create_setter();
861 }
862 
863 inline std::unique_ptr<GetterImpl> Url::create_getter() const {
864  if VUNLIKELY (!target_) {
865  return nullptr; // LCOV_EXCL_LINE GCOVR_EXCL_LINE
866  }
867 
868  return target_->create_getter();
869 }
870 
871 } // namespace vlink
Transport-neutral backbone shared by every method-model client implementation.
Transport-configuration base contract and the supporting boilerplate macros.
#define VLINK_DECLARE_CONF_FRIEND()
Macro Definitions.
Definition: conf.h:226
Transport-neutral base for field-model getter (latest-value reader) implementations.
#define CLOG_F(...)
Definition: logger.h:803
#define VUNLIKELY(...)
Short alias for VLINK_UNLIKELY.
Definition: macros.h:289
#define VLINK_EXPORT
Definition: macros.h:81
Transport-neutral base class for every event-model publisher implementation.
Transport-neutral base class for every method-model server implementation.
Transport-neutral base class for every field-model setter (latest-value writer).
Transport-neutral base class for every event-model subscriber implementation.