VLink 2.0.0
A high-performance communication middleware
载入中...
搜索中...
未找到
url.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 url.h
26 * @brief URL-based transport configuration dispatcher for VLink nodes.
27 *
28 * @details
29 * This header provides two types that together implement the "one API, multiple
30 * transports" core promise of VLink:
31 *
32 * @par Protocol
33 * A plain-data struct that holds the parsed components of a VLink URL (transport,
34 * host, path, query dictionary, fragment). It is constructed from a URL string
35 * and is used by @c Url::init_target_internal() to select the correct @c Conf
36 * subclass. @c Protocol is only constructible by @c Url (private constructor,
37 * @c friend struct Url).
38 *
39 * @par Url
40 * A concrete @c Conf subclass that wraps a @c Protocol and delegates all
41 * @c Conf virtual methods to the underlying transport @c Conf (@c target_).
42 * On construction it calls @c init_target_internal() which selects the correct
43 * @c *Conf class based on the transport prefix in the URL and compile-time feature flags.
44 *
45 * @par Transport Selection at Construction
46 * @code
47 * Url url("dds://vehicle/speed?domain_id=1");
48 * // Internally creates a DdsConf and calls:
49 * // url.parse(kSubscriber) -> target_->parse(kSubscriber)
50 * // url.create_subscriber() -> target_->create_subscriber()
51 * @endcode
52 *
53 * @par URL Remapping
54 * When the @c VLINK_URL_USE_REMAP preprocessor flag is set, the @c Protocol
55 * constructor checks the @c VLINK_URL_REMAP environment variable and rewrites
56 * the URL before transport detection, enabling zero-code transport switching.
57 *
58 * @par Dynamic Plugin Transport Loading
59 * When the @c VLINK_URL_USE_PLUGIN flag is set, @c Url::load_for_plugin()
60 * searches dynamically loaded @c ConfPluginInterface plugins (from
61 * @c VLINK_URL_PLUGINS env var) for a matching transport when built-in transports are
62 * not found.
63 *
64 * @par Transport Enable Flags
65 * The @c TransportEnableFlag bitmask controls which transports are initialised via
66 * @c global_init() and @c init_plugins(). This allows embedding environments
67 * (e.g. Android, QNX) to exclude unsupported transports at runtime.
68 *
69 * @note This file includes all @c *_conf.h module headers and all @c *_impl.h
70 * headers. It is the single aggregation point for the VLink transport
71 * abstraction layer.
72 */
73
74#pragma once
75
76#include <map>
77#include <memory>
78#include <string>
79#include <utility>
80
81#include "../base/logger.h"
82#include "./conf.h"
83
84// NOLINTBEGIN
85#include "../modules/dds_conf.h"
92#include "../modules/qnx_conf.h"
94#include "../modules/shm_conf.h"
97//
98#include "./client_impl.h"
99#include "./getter_impl.h"
100#include "./publisher_impl.h"
101#include "./server_impl.h"
102#include "./setter_impl.h"
103#include "./subscriber_impl.h"
104// NOLINTEND
105
106namespace vlink {
107
108/**
109 * @struct Protocol
110 * @brief Parsed URL components used to select and configure a transport @c Conf.
111 *
112 * @details
113 * Produced by @c Protocol(const std::string& address) which runs the URL through
114 * @c UrlParser, applies any @c VLINK_URL_REMAP remapping, and resolves the
115 * @c TransportType from the transport string. Only @c Url may construct a @c Protocol
116 * (private constructor, friend @c Url).
117 *
118 * @note The @c str field always holds the canonical URL string after any remap
119 * has been applied, not the raw input.
120 */
121struct VLINK_EXPORT Protocol final {
122 std::string str; ///< Canonical URL string (post-remap).
123 TransportType transport; ///< Resolved transport backend.
124 std::string host; ///< Hostname or IP address component.
125 std::string path; ///< Topic path component.
126 std::map<std::string, std::string> dictionary; ///< Parsed query key-value pairs.
127 std::string fragment; ///< Fragment identifier (after @c #).
128
129 private:
130 friend struct Url;
131 explicit Protocol(const std::string& address);
132};
133
134/**
135 * @struct Url
136 * @brief URL-based @c Conf dispatcher that routes to the correct transport backend.
137 *
138 * @details
139 * @c Url is the user-facing transport configuration type. It is constructed from a
140 * URL string, parses it into a @c Protocol, then creates the matching transport
141 * @c Conf (@c target_) in @c init_target_internal(). All @c Conf virtual methods
142 * are forwarded to @c target_.
143 *
144 * @par Full Lifecycle
145 * @code
146 * // 1. Construct with URL string:
147 * Url url("dds://vehicle/speed");
148 * // -> Protocol("dds://vehicle/speed") -> transport = kDds
149 * // -> init_target_internal() -> target_ = make_unique<DdsConf>()
150 *
151 * // 2. Parse for a specific node type:
152 * url.parse(kSubscriber);
153 * // -> target_->parse(kSubscriber)
154 * // -> target_->parse_protocol(&protocol_)
155 *
156 * // 3. Create transport implementation:
157 * auto impl = url.create_subscriber();
158 * // -> target_->create_subscriber()
159 * @endcode
160 */
161struct Url final : public Conf {
162 /**
163 * @enum TransportEnableFlag
164 * @brief Bitmask controlling which transport backends are active at runtime.
165 *
166 * @details
167 * Passed to @c global_init() and @c init_plugins() to selectively initialise
168 * only the transports that are compiled in and needed for the current process.
169 * The bits correspond directly to the @c TransportType enumeration values.
170 *
171 * | Flag | Bit Position | Transport |
172 * | -------------- | ------------ | -------------- |
173 * | kEnableIntra | 15 | intra:// |
174 * | kEnableShm | 14 | shm:// |
175 * | kEnableShm2 | 13 | shm2:// |
176 * | kEnableZenoh | 12 | zenoh:// |
177 * | kEnableDds | 11 | dds:// |
178 * | kEnableDdsc | 10 | ddsc:// |
179 * | kEnableDdsr | 9 | ddsr:// |
180 * | kEnableDdst | 8 | ddst:// |
181 * | kEnableSomeip | 7 | someip:// |
182 * | kEnableMqtt | 6 | mqtt:// |
183 * | kEnableFdbus | 5 | fdbus:// |
184 * | kEnableQnx | 4 | qnx:// |
185 * | kEnableAll | all bits set | all transports |
186 */
187 enum TransportEnableFlag : uint16_t {
188 kEnableEmpty = 0b0000'0000'0000'0000, ///< No transport enabled.
189 kEnableIntra = 0b1000'0000'0000'0000, ///< Enable intra:// transport.
190 kEnableShm = 0b0100'0000'0000'0000, ///< Enable shm:// (Iceoryx) transport.
191 kEnableShm2 = 0b0010'0000'0000'0000, ///< Enable shm2:// (Iceoryx2) transport.
192 kEnableZenoh = 0b0001'0000'0000'0000, ///< Enable zenoh:// transport.
193 kEnableDds = 0b0000'1000'0000'0000, ///< Enable dds:// (Fast-DDS) transport.
194 kEnableDdsc = 0b0000'0100'0000'0000, ///< Enable ddsc:// (CycloneDDS) transport.
195 kEnableDdsr = 0b0000'0010'0000'0000, ///< Enable ddsr:// (RTI DDS) transport.
196 kEnableDdst = 0b0000'0001'0000'0000, ///< Enable ddst:// (TravoDDS) transport.
197 kEnableSomeip = 0b0000'0000'1000'0000, ///< Enable someip:// transport.
198 kEnableMqtt = 0b0000'0000'0100'0000, ///< Enable mqtt:// transport.
199 kEnableFdbus = 0b0000'0000'0010'0000, ///< Enable fdbus:// transport.
200 kEnableQnx = 0b0000'0000'0001'0000, ///< Enable qnx:// transport (QNX only).
201 kEnableAll = 0b1111'1111'1111'1111, ///< Enable all transports.
202 };
203
204 /**
205 * @brief Constructs a @c Url from a transport address string.
206 *
207 * @details
208 * Parses @p str into a @c Protocol, then calls @c init_target_internal() to
209 * create the matching @c Conf subclass. Logs a fatal error if no transport
210 * backend matches the URL.
211 *
212 * @param str VLink URL string, e.g. @c "dds://vehicle/speed".
213 */
214 explicit Url(const std::string& str);
215
216 /**
217 * @brief Copy constructor.
218 *
219 * @details
220 * Copies the @c Protocol from @p url and rebuilds @c target_ via
221 * @c init_target_internal(). The new object gets a fresh transport @c Conf
222 * rather than sharing the same instance.
223 *
224 * @param url Source @c Url to copy.
225 */
226 Url(const Url& url);
227
228 /**
229 * @brief Move constructor.
230 *
231 * @details
232 * Transfers @c protocol_ and @c target_ from @p url without rebuilding.
233 *
234 * @param url Source @c Url to move from.
235 */
236 Url(Url&& url) noexcept;
237
238 /**
239 * @brief Destructor.
240 */
241 ~Url() override;
242
243 /**
244 * @brief Copy-assignment operator.
245 *
246 * @details
247 * Copies @c protocol_ and reinitialises @c target_ via @c init_target_internal().
248 *
249 * @param url Source @c Url.
250 * @return Reference to @c *this.
251 */
252 Url& operator=(const Url& url);
253
254 /**
255 * @brief Move-assignment operator.
256 *
257 * @param url Source @c Url.
258 * @return Reference to @c *this.
259 */
260 Url& operator=(Url&& url) noexcept;
261
262 /**
263 * @brief Returns the original (or remapped) URL string.
264 *
265 * @return Const reference to the canonical URL string stored in @c Protocol::str.
266 */
267 [[nodiscard]] const std::string& get_str() const;
268
269 /**
270 * @brief Returns a pointer to the underlying transport @c Conf, or @c nullptr.
271 *
272 * @details
273 * Allows callers to inspect or downcast the concrete transport configuration
274 * (e.g. to a @c DdsConf to set DDS-specific QoS).
275 *
276 * @return Pointer to the active transport @c Conf; @c nullptr if the URL was invalid.
277 */
278 [[nodiscard]] const Conf* get_target() const;
279
280 /**
281 * @brief Parses the URL for the given node type, delegating to @c target_.
282 *
283 * @details
284 * Calls @c Conf::parse(impl_type), @c target_->parse(impl_type), and
285 * @c target_->parse_protocol() in sequence. Returns @c false if @c target_
286 * is null or any step fails.
287 *
288 * @param impl_type Bitmask of @c ImplType roles (e.g. @c kSubscriber).
289 * @return @c true if all parse steps succeed; @c false otherwise.
290 */
291 bool parse(ImplType impl_type) const override;
292
293 /**
294 * @brief Returns @c true if the underlying @c target_ @c Conf is valid.
295 *
296 * @details
297 * Delegates to @c target_->is_valid(). Returns @c false if @c target_ is null.
298 *
299 * @return @c true if the transport conf is valid and ready for use.
300 */
301 [[nodiscard]] bool is_valid() const override;
302
303 /**
304 * @brief Returns the @c ImplType resolved by the underlying @c target_ @c Conf.
305 *
306 * @details
307 * Delegates to @c target_->get_impl_type(). Returns @c kUnknownImplType if
308 * @c target_ is null or @c parse() has not been called yet.
309 *
310 * @return The @c ImplType for this URL, or @c kUnknownImplType.
311 */
312 [[nodiscard]] ImplType get_impl_type() const override;
313
314 /**
315 * @brief Returns the transport backend resolved from the URL.
316 *
317 * @details
318 * Delegates to @c target_->get_transport_type(). Returns @c TransportType::kUnknown
319 * if @c target_ is null.
320 *
321 * @return The @c TransportType for this URL.
322 */
323 [[nodiscard]] TransportType get_transport_type() const override;
324
325 /**
326 * @brief Loads and registers @c ConfPluginInterface plugins for the enabled transports.
327 *
328 * @details
329 * Searches for plugin shared libraries listed in the @c VLINK_URL_PLUGINS
330 * environment variable and registers any that advertise a transport in
331 * @p transport_enable_flags. This is called automatically when a @c Url is first
332 * constructed; explicit calls are only needed in unusual initialisation order.
333 *
334 * @param transport_enable_flags Bitmask of @c TransportEnableFlag values; default 0
335 * (no plugins searched unless env var is set).
336 */
337 VLINK_EXPORT static void init_plugins(uint16_t transport_enable_flags = 0);
338
339 /**
340 * @brief Searches loaded plugins for a @c Conf factory matching @p type.
341 *
342 * @details
343 * Iterates over all loaded @c ConfPluginInterface instances and returns the first
344 * one whose @c get_transport_type() matches @p type. Returns @c nullptr if no
345 * matching plugin is found.
346 *
347 * @param type Transport backend to search for.
348 * @return A new @c Conf instance from the plugin, or @c nullptr.
349 */
350 [[nodiscard]] VLINK_EXPORT static std::unique_ptr<Conf> load_for_plugin(TransportType type);
351
352 /**
353 * @brief Returns a numeric sort index for the transport backend used by a URL.
354 *
355 * @details
356 * Used to order multiple URLs by transport priority. Local transports
357 * (@c intra://, @c shm://) return lower indices than network transports.
358 *
359 * @param url URL string to classify.
360 * @return Non-negative sort index; lower values = higher priority.
361 */
362 [[nodiscard]] VLINK_EXPORT static int get_sort_index(std::string_view url);
363
364 /**
365 * @brief Returns @c true if the URL refers to a local (same-machine) transport.
366 *
367 * @details
368 * A URL is considered local if its transport is @c intra://, @c shm://, or
369 * @c shm2://.
370 *
371 * @param url URL string to classify.
372 * @return @c true for local transports; @c false for network transports.
373 */
374 [[nodiscard]] VLINK_EXPORT static bool is_local_type(std::string_view url);
375
376 /**
377 * @brief Returns @c true if the URL uses the @c intra:// in-process transport.
378 *
379 * @param url URL string to classify.
380 * @return @c true only for @c intra:// URLs.
381 */
382 [[nodiscard]] VLINK_EXPORT static bool is_intra_type(std::string_view url);
383
384 /**
385 * @brief Returns @c true if the URL uses a shared-memory transport (@c shm:// or @c shm2://).
386 *
387 * @param url URL string to classify.
388 * @return @c true for @c shm:// and @c shm2:// URLs.
389 */
390 [[nodiscard]] VLINK_EXPORT static bool is_shm_type(std::string_view url);
391
392 /**
393 * @brief Initialises the global state for all enabled transport backends.
394 *
395 * @details
396 * Calls @c NodeImpl::global_init() and then @c *Conf::global_init() for each
397 * transport whose bit is set in @p transport_enable_flags. Must be called once
398 * before creating any @c Url objects if fine-grained transport control is needed.
399 * If not called explicitly, transports are lazily initialised on first use.
400 *
401 * @param transport_enable_flags Bitmask of @c TransportEnableFlag values. Passing
402 * @c 0 (the default) expands to all compiled-in transports.
403 */
404 static void global_init(uint16_t transport_enable_flags = 0);
405
406 /**
407 * @brief Returns a bitmask of all compile-time-enabled transport backends.
408 *
409 * @details
410 * Built at compile time from the @c VLINK_SUPPORT_* preprocessor flags. The
411 * result can be passed to @c global_init() to initialise exactly the available
412 * transports.
413 *
414 * @return @c TransportEnableFlag bitmask of supported transports.
415 */
416 [[nodiscard]] static uint16_t get_transport_enable_flags();
417
418 /**
419 * @brief Creates the @c target_ @c Conf for a given @c Protocol.
420 *
421 * @details
422 * Called by constructors and assignment operators. Switches on
423 * @c Protocol::transport and instantiates the corresponding @c *Conf class.
424 * Falls back to @c load_for_plugin() if no built-in transport matches. Logs a
425 * fatal error if neither path succeeds.
426 *
427 * @param protocol Parsed URL information used to select the transport.
428 * @param target Output: receives the newly created @c Conf instance.
429 */
430 static void init_target_internal(const Protocol& protocol, std::unique_ptr<Conf>& target);
431
432 private:
433 std::unique_ptr<ServerImpl> create_server() const override;
434
435 std::unique_ptr<ClientImpl> create_client() const override;
436
437 std::unique_ptr<PublisherImpl> create_publisher() const override;
438
439 std::unique_ptr<SubscriberImpl> create_subscriber() const override;
440
441 std::unique_ptr<SetterImpl> create_setter() const override;
442
443 std::unique_ptr<GetterImpl> create_getter() const override;
444
445 VLINK_EXPORT friend std::ostream& operator<<(std::ostream& ostream, const Url& conf) noexcept;
446
447 mutable Protocol protocol_;
448 std::unique_ptr<Conf> target_;
450 VLINK_ALLOW_IMPL_TYPE(kServer | kClient | kPublisher | kSubscriber | kSetter | kGetter);
451};
452
453////////////////////////////////////////////////////////////////
454/// Details
455////////////////////////////////////////////////////////////////
456
457inline Url::Url(const std::string& str) : protocol_(str) { init_target_internal(protocol_, target_); }
458
459// NOLINTNEXTLINE(bugprone-copy-constructor-init)
460inline Url::Url(const Url& url) : protocol_(url.protocol_) { init_target_internal(protocol_, target_); }
461
462inline Url::Url(Url&& url) noexcept : protocol_(std::move(url.protocol_)), target_(std::move(url.target_)) {}
463
464inline Url::~Url() = default;
465
466inline Url& Url::operator=(const Url& url) {
467 if VUNLIKELY (this == &url) {
468 return *this;
469 }
470
471 protocol_ = url.protocol_;
472
473 init_target_internal(protocol_, target_);
474
475 return *this;
476}
477
478inline Url& Url::operator=(Url&& url) noexcept {
479 if VUNLIKELY (this == &url) {
480 return *this;
481 }
482
483 protocol_ = std::move(url.protocol_);
484 target_ = std::move(url.target_);
485
486 return *this;
487}
488
489inline const std::string& Url::get_str() const { return protocol_.str; }
490
491inline const Conf* Url::get_target() const { return target_.get(); }
492
493inline bool Url::parse(ImplType impl_type) const {
494 if VUNLIKELY (!target_) {
495 return false;
496 }
497
498 if VUNLIKELY (!Conf::parse(impl_type) || !target_->parse(impl_type)) {
499 return false;
500 }
501
502 return target_->parse_protocol(&protocol_);
503}
504
505inline bool Url::is_valid() const {
506 if VUNLIKELY (!target_) {
507 return false;
508 }
509
510 return target_->is_valid();
511}
512
514 if VUNLIKELY (!target_) {
515 return kUnknownImplType;
516 }
517
518 return target_->get_impl_type();
519}
520
522 if VUNLIKELY (!target_) {
524 }
525
526 return target_->get_transport_type();
527}
528
529inline void Url::global_init(uint16_t transport_enable_flags) {
530 if (transport_enable_flags == 0) {
531 transport_enable_flags = get_transport_enable_flags();
532 }
533
534 (void)transport_enable_flags;
535
537
538#ifndef VLINK_ENABLE_C_INTERFACE
539
540#ifdef VLINK_SUPPORT_INTRA
541 if (transport_enable_flags & kEnableIntra) {
542 IntraConf::global_init();
543 }
544#endif
545
546#ifdef VLINK_SUPPORT_SHM
547 if (transport_enable_flags & kEnableShm) {
548 ShmConf::global_init();
549 }
550#endif
551
552#ifdef VLINK_SUPPORT_SHM2
553 if (transport_enable_flags & kEnableShm2) {
554 Shm2Conf::global_init();
555 }
556#endif
557
558#ifdef VLINK_SUPPORT_ZENOH
559 if (transport_enable_flags & kEnableZenoh) {
560 ZenohConf::global_init();
561 }
562#endif
563
564#ifdef VLINK_SUPPORT_DDS
565 if (transport_enable_flags & kEnableDds) {
566 DdsConf::global_init();
567 }
568#endif
569
570#ifdef VLINK_SUPPORT_DDSC
571 if (transport_enable_flags & kEnableDdsc) {
572 DdscConf::global_init();
573 }
574#endif
575
576#ifdef VLINK_SUPPORT_DDSR
577 if (transport_enable_flags & kEnableDdsr) {
578 DdsrConf::global_init();
579 }
580#endif
581
582#ifdef VLINK_SUPPORT_DDST
583 if (transport_enable_flags & kEnableDdst) {
584 DdstConf::global_init();
585 }
586#endif
587
588#ifdef VLINK_SUPPORT_SOMEIP
589 if (transport_enable_flags & kEnableSomeip) {
590 SomeipConf::global_init();
591 }
592#endif
593
594#ifdef VLINK_SUPPORT_MQTT
595 if (transport_enable_flags & kEnableMqtt) {
596 MqttConf::global_init();
597 }
598#endif
599
600#ifdef VLINK_SUPPORT_FDBUS
601 if (transport_enable_flags & kEnableFdbus) {
602 FdbusConf::global_init();
603 }
604#endif
605
606#ifdef VLINK_SUPPORT_QNX
607 if (transport_enable_flags & kEnableQnx) {
608 QnxConf::global_init();
609 }
610#endif
611
612#endif
613}
614
616 uint16_t flags = 0;
617
618#ifdef VLINK_SUPPORT_INTRA
619 flags |= kEnableIntra;
620#endif
621
622#ifdef VLINK_SUPPORT_SHM
623 flags |= kEnableShm;
624#endif
625
626#ifdef VLINK_SUPPORT_SHM2
627 flags |= kEnableShm2;
628#endif
629
630#ifdef VLINK_SUPPORT_ZENOH
631 flags |= kEnableZenoh;
632#endif
633
634#ifdef VLINK_SUPPORT_DDS
635 flags |= kEnableDds;
636#endif
637
638#ifdef VLINK_SUPPORT_DDSC
639 flags |= kEnableDdsc;
640#endif
641
642#ifdef VLINK_SUPPORT_DDSR
643 flags |= kEnableDdsr;
644#endif
645
646#ifdef VLINK_SUPPORT_DDST
647 flags |= kEnableDdst;
648#endif
649
650#ifdef VLINK_SUPPORT_SOMEIP
651 flags |= kEnableSomeip;
652#endif
653
654#ifdef VLINK_SUPPORT_MQTT
655 flags |= kEnableMqtt;
656#endif
657
658#ifdef VLINK_SUPPORT_FDBUS
659 flags |= kEnableFdbus;
660#endif
661
662#ifdef VLINK_SUPPORT_QNX
663 flags |= kEnableQnx;
664#endif
665
666 return flags;
667}
668
669inline void Url::init_target_internal(const Protocol& protocol, std::unique_ptr<Conf>& target) {
670 static auto transport_enable_flags = get_transport_enable_flags();
671
672 Url::init_plugins(transport_enable_flags);
673
674 // NOLINTBEGIN
675 switch (protocol.transport) {
676#ifdef VLINK_SUPPORT_INTRA
678 target = std::make_unique<IntraConf>();
679 break;
680#endif
681
682#ifdef VLINK_SUPPORT_SHM
684 target = std::make_unique<ShmConf>();
685 break;
686#endif
687
688#ifdef VLINK_SUPPORT_SHM2
690 target = std::make_unique<Shm2Conf>();
691 break;
692#endif
693
694#ifdef VLINK_SUPPORT_ZENOH
696 target = std::make_unique<ZenohConf>();
697 break;
698#endif
699
700#ifdef VLINK_SUPPORT_DDS
702 target = std::make_unique<DdsConf>();
703 break;
704#endif
705
706#ifdef VLINK_SUPPORT_DDSC
708 target = std::make_unique<DdscConf>();
709 break;
710#endif
711
712#ifdef VLINK_SUPPORT_DDSR
714 target = std::make_unique<DdsrConf>();
715 break;
716#endif
717
718#ifdef VLINK_SUPPORT_DDST
720 target = std::make_unique<DdstConf>();
721 break;
722#endif
723
724#ifdef VLINK_SUPPORT_SOMEIP
726 target = std::make_unique<SomeipConf>();
727 break;
728#endif
729
730#ifdef VLINK_SUPPORT_MQTT
732 target = std::make_unique<MqttConf>();
733 break;
734#endif
735
736#ifdef VLINK_SUPPORT_FDBUS
738 target = std::make_unique<FdbusConf>();
739 break;
740#endif
741
742#ifdef VLINK_SUPPORT_QNX
744 target = std::make_unique<QnxConf>();
745 break;
746#endif
747
748 default:
749 break;
750 }
751 // NOLINTEND
752
753 if (!target) {
754 target = Url::load_for_plugin(protocol.transport);
755 }
756
757 if VUNLIKELY (!target) {
758 CLOG_F("Unsupported url[%s].", protocol.str.c_str());
759 }
760}
761
762inline std::unique_ptr<ServerImpl> Url::create_server() const {
763 if VUNLIKELY (!target_) {
764 return nullptr;
765 }
766
767 return target_->create_server();
768}
769
770inline std::unique_ptr<ClientImpl> Url::create_client() const {
771 if VUNLIKELY (!target_) {
772 return nullptr;
773 }
774
775 return target_->create_client();
776}
777
778inline std::unique_ptr<PublisherImpl> Url::create_publisher() const {
779 if VUNLIKELY (!target_) {
780 return nullptr;
781 }
782
783 return target_->create_publisher();
784}
785
786inline std::unique_ptr<SubscriberImpl> Url::create_subscriber() const {
787 if VUNLIKELY (!target_) {
788 return nullptr;
789 }
790
791 return target_->create_subscriber();
792}
793
794inline std::unique_ptr<SetterImpl> Url::create_setter() const {
795 if VUNLIKELY (!target_) {
796 return nullptr;
797 }
798
799 return target_->create_setter();
800}
801
802inline std::unique_ptr<GetterImpl> Url::create_getter() const {
803 if VUNLIKELY (!target_) {
804 return nullptr;
805 }
806
807 return target_->create_getter();
808}
809
810} // namespace vlink
Abstract base class for all transport-specific client (RPC caller) implementations.
Abstract transport configuration base class and associated helper macros.
#define VLINK_DECLARE_CONF_FRIEND()
Macro Definitions
定义 conf.h:199
Transport configuration for the dds:// Fast-DDS RTPS backend.
Transport configuration for the ddsc:// CycloneDDS backend.
Transport configuration for the ddsr:// RTI Connext DDS backend.
Transport configuration for the ddst:// TravoDDS backend.
Transport configuration for the fdbus:// FDBus IPC backend.
Abstract base class for all transport-specific getter (field reader) implementations.
Transport configuration for the intra:// in-process messaging backend.
Global singleton logger with three output styles and pluggable backends.
#define CLOG_F(...)
定义 logger.h:868
#define VUNLIKELY(...)
Shorthand alias for VLINK_UNLIKELY. Hints that the expression is unlikely true.
定义 macros.h:302
#define VLINK_EXPORT
定义 macros.h:85
Transport configuration for the mqtt:// MQTT protocol backend.
STL namespace
Abstract base class for all transport-specific publisher implementations.
Transport configuration for the qnx:// QNX IPC backend.
Abstract base class for all transport-specific server (RPC responder) implementations.
Abstract base class for all transport-specific setter (field writer) implementations.
Transport configuration for the shm2:// Iceoryx2 shared-memory backend.
Transport configuration for the shm:// Iceoryx shared-memory backend.
Transport configuration for the someip:// SOME/IP (vsomeip) backend.
Abstract base class for all transport-specific subscriber implementations.
Transport configuration for the zenoh:// Zenoh protocol backend.