VLink 2.0.0
A high-performance communication middleware
Loading...
Searching...
No Matches
intra_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 intra_conf.h
26 * @brief Transport configuration for the @c intra:// in-process messaging backend.
27 *
28 * @details
29 * @c IntraConf configures the in-process message queue transport, which delivers
30 * messages between publishers and subscribers running in the same OS process
31 * without any serialisation or inter-process overhead.
32 *
33 * @par Supported Node Types
34 * @c intra:// supports all six node types: @c kPublisher, @c kSubscriber,
35 * @c kServer, @c kClient, @c kSetter, and @c kGetter.
36 *
37 * @par URL Format
38 * @code
39 * intra://<address>[?event=<event_name>[&pipeline=<N>]][#<type>]
40 * @endcode
41 *
42 * | Component | Description |
43 * | ------------------ | ------------------------------------------------------ |
44 * | @c address | Topic name; formed from @c host + @c "/" + @c path |
45 * | @c event | Optional secondary filter string (@c ?event=) |
46 * | @c pipeline | Queue pipeline depth (@c ?pipeline=N, default 0) |
47 * | @c type | Delivery mode: @c "queue" or @c "direct" (fragment) |
48 *
49 * @par Example
50 * @code
51 * // In-process pub/sub (queue mode, default):
52 * vlink::Publisher<MyMsg> pub("intra://my_topic");
53 * vlink::Subscriber<MyMsg> sub("intra://my_topic");
54 *
55 * // Direct delivery (bypasses queue):
56 * vlink::Publisher<MyMsg> pub("intra://my_topic#direct");
57 *
58 * // With secondary event filter and pipeline depth:
59 * vlink::Publisher<MyMsg> pub("intra://my_service?event=my_event&pipeline=4");
60 * @endcode
61 *
62 * @note This header is compiled only when @c VLINK_SUPPORT_INTRA is defined.
63 * @note The @c address string must not be empty.
64 */
65
66#pragma once
67
68#ifdef VLINK_SUPPORT_INTRA
69
70#include <cstdint>
71#include <string>
72
73#include "../impl/conf.h"
74
75namespace vlink {
76
77/**
78 * @struct IntraConf
79 * @brief Configuration for the @c intra:// in-process transport.
80 *
81 * @details
82 * Can be constructed directly or parsed from a URL string via @c Url.
83 * When parsed from a URL, @c address is derived from the host and path components,
84 * @c event from @c ?event=, @c pipeline from @c ?pipeline=, and @c type from the
85 * URL fragment (@c #queue or @c #direct).
86 */
87struct VLINK_EXPORT IntraConf final : public Conf {
88 std::string address; ///< Topic address (host + "/" + path from URL); must not be empty.
89 std::string event; ///< Optional secondary event filter string.
90 int32_t pipeline{0}; ///< Pipeline queue depth; 0 means no pipelining.
91 std::string type{"queue"}; ///< Delivery mode: @c "queue" (buffered) or @c "direct" (bypass queue).
92
93 /**
94 * @brief Constructs an @c IntraConf with explicit parameters.
95 *
96 * @param _address Topic address string; must not be empty.
97 * @param _event Optional secondary event filter; empty by default.
98 * @param _pipeline Pipeline queue depth; default 0 (disabled).
99 * @param _type Delivery mode: @c "queue" or @c "direct"; default @c "queue".
100 */
101 explicit IntraConf(const std::string& _address, const std::string& _event = "", int _pipeline = 0,
102 const std::string& _type = "queue");
103
104 /**
105 * @brief Returns @c true if all fields of this configuration are equal to @p conf.
106 *
107 * @param conf Configuration to compare.
108 * @return @c true if @c address, @c event, @c pipeline, and @c type all match.
109 */
110 [[nodiscard]] bool operator==(const IntraConf& conf) const noexcept;
111
112 /**
113 * @brief Returns @c true if any field differs from @p conf.
114 *
115 * @param conf Configuration to compare.
116 * @return Logical negation of @c operator==.
117 */
118 [[nodiscard]] bool operator!=(const IntraConf& conf) const noexcept;
119
120 /**
121 * @brief Returns @c TransportType::kIntra identifying this transport.
122 *
123 * @return @c TransportType::kIntra.
124 */
125 [[nodiscard]] TransportType get_transport_type() const override;
126
127#ifndef VLINK_ENABLE_C_INTERFACE
129#endif
130 VLINK_ALLOW_IMPL_TYPE(kServer | kClient | kPublisher | kSubscriber | kSetter | kGetter)
131 VLINK_CONF_IMPL(IntraConf)
132};
133
134////////////////////////////////////////////////////////////////
135/// Details
136////////////////////////////////////////////////////////////////
137
138inline IntraConf::IntraConf(const std::string& _address, const std::string& _event, int _pipeline,
139 const std::string& _type)
140 : address(_address), event(_event), pipeline(_pipeline), type(_type) {}
141
142inline bool IntraConf::operator==(const IntraConf& conf) const noexcept {
143 return address == conf.address && event == conf.event && pipeline == conf.pipeline && type == conf.type;
144}
145
146inline bool IntraConf::operator!=(const IntraConf& conf) const noexcept { return !(*this == conf); }
147
148inline TransportType IntraConf::get_transport_type() const { return TransportType::kIntra; }
149
150} // namespace vlink
151
152#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