VLink  2.0.0
A high-performance communication middleware
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 / zero-copy transport.
27  *
28  * @details
29  * @c IntraConf binds the @c intra:// URL scheme to VLink's in-process message bus.
30  * Publishers and subscribers that share the same OS process exchange messages
31  * directly through an in-memory queue without crossing kernel or network
32  * boundaries. When the payload is an @c IntraDataType (a shared-pointer wrapper
33  * around the message), serialisation is bypassed entirely and the pointer is
34  * handed off zero-copy; all other types take the normal @c Serializer path.
35  *
36  * @par Zero-Copy Hand-off Path
37  * @code
38  * Publisher MessageBus Subscriber
39  * --------- ---------- ----------
40  * IntraDataType<T> ----enqueue-> ring buffer (shared_ptr only) -> IntraDataType<T>
41  * pod / proto / etc --serialize-> Bytes -------------------------> deserialize -> T
42  * @endcode
43  *
44  * @par Supported Node Types
45  *
46  * | Publisher | Subscriber | Server | Client | Getter | Setter |
47  * | :-------: | :--------: | :----: | :----: | :----: | :----: |
48  * | yes | yes | yes | yes | yes | yes |
49  *
50  * @par URL Format
51  * @code
52  * intra://<address>[?event=<name>&pipeline=<id>][#<type>]
53  * @endcode
54  *
55  * | Component | Description |
56  * | ----------- | ------------------------------------------------------------------------ |
57  * | @c address | In-process topic name (URL host concatenated with path); not empty |
58  * | @c event | Optional secondary event filter (@c ?event=) |
59  * | @c pipeline | Queue-mode pipeline ID (@c ?pipeline=); @c 0 selects the default pipe |
60  * | @c type | URL fragment; @c "queue" (buffered) or @c "direct" (inline dispatch) |
61  *
62  * @par Delivery Modes
63  *
64  * | Mode | Wakeup latency | Threading | Use case |
65  * | ---------- | -------------- | ------------------------------- | ------------------------- |
66  * | @c queue | Bounded | Subscriber loop drains the bus | Default; decoupled timing |
67  * | @c direct | Synchronous | Caller thread invokes callback | Hot loops, low latency |
68  *
69  * @par Example
70  * @code
71  * auto pub = vlink::Publisher<MyMsg>::create_unique("intra://sensors/imu");
72  * auto sub = vlink::Subscriber<MyMsg>::create_unique("intra://sensors/imu");
73  * auto fast = vlink::Publisher<MyMsg>::create_unique("intra://control/cmd#direct");
74  * auto pipe = vlink::Publisher<MyMsg>::create_unique("intra://svc?event=ev&pipeline=4");
75  * @endcode
76  *
77  * @note Compiled only when @c VLINK_SUPPORT_INTRA is defined.
78  * @note @c address must not be empty; @c is_valid() additionally requires @c type
79  * to be either @c "queue" or @c "direct".
80  */
81 
82 #pragma once
83 
84 #ifdef VLINK_SUPPORT_INTRA
85 
86 #include <cstdint>
87 #include <string>
88 
89 #include "../impl/conf.h"
90 
91 namespace vlink {
92 
93 /**
94  * @struct IntraConf
95  * @brief Concrete @c Conf describing an in-process endpoint addressed by an @c intra:// URL.
96  *
97  * @details
98  * Fields map one-to-one onto the URL components: @c address from host plus path,
99  * @c event from @c ?event=, @c pipeline from @c ?pipeline=, and @c type from the
100  * URL fragment (@c "queue" or @c "direct").
101  */
102 struct VLINK_EXPORT IntraConf final : public Conf {
103  std::string address; ///< In-process topic address (URL host concatenated with path); must not be empty.
104  std::string event; ///< Optional secondary event filter string.
105  int32_t pipeline{0}; ///< Queue-mode pipeline identifier; @c 0 selects the default pipe.
106  std::string type{"queue"}; ///< Delivery mode; @c "queue" (buffered) or @c "direct" (inline dispatch).
107 
108  /**
109  * @brief Builds an @c IntraConf from its four logical fields.
110  *
111  * @param _address Topic address string; must not be empty.
112  * @param _event Optional secondary event filter; empty by default.
113  * @param _pipeline Queue-mode pipeline ID; defaults to @c 0.
114  * @param _type Delivery mode; @c "queue" or @c "direct"; defaults to @c "queue".
115  */
116  explicit IntraConf(const std::string& _address, const std::string& _event = "", int _pipeline = 0,
117  const std::string& _type = "queue");
118 
119  /**
120  * @brief Component-wise equality on all configuration fields.
121  *
122  * @param conf Configuration to compare with.
123  * @return @c true when @c address, @c event, @c pipeline and @c type all match.
124  */
125  [[nodiscard]] bool operator==(const IntraConf& 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 any field differs from @p conf.
132  */
133  [[nodiscard]] bool operator!=(const IntraConf& conf) const noexcept;
134 
135  /**
136  * @brief Reports this object's transport tag.
137  *
138  * @return @c TransportType::kIntra.
139  */
140  [[nodiscard]] TransportType get_transport_type() const override;
141 
142 #ifndef VLINK_ENABLE_C_INTERFACE
144 #endif
146  VLINK_CONF_IMPL(IntraConf)
147 };
148 
149 ////////////////////////////////////////////////////////////////
150 /// Details
151 ////////////////////////////////////////////////////////////////
152 
153 inline IntraConf::IntraConf(const std::string& _address, const std::string& _event, int _pipeline,
154  const std::string& _type)
155  : address(_address), event(_event), pipeline(_pipeline), type(_type) {}
156 
157 inline bool IntraConf::operator==(const IntraConf& conf) const noexcept {
158  return address == conf.address && event == conf.event && pipeline == conf.pipeline && type == conf.type;
159 }
160 
161 inline bool IntraConf::operator!=(const IntraConf& conf) const noexcept { return !(*this == conf); }
162 
163 inline TransportType IntraConf::get_transport_type() const { return TransportType::kIntra; }
164 
165 } // namespace vlink
166 
167 #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