VLink 2.0.0
A high-performance communication middleware
载入中...
搜索中...
未找到
shm2_conf.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 shm2_conf.h
26 * @brief Transport configuration for the @c shm2:// Iceoryx2 shared-memory backend.
27 *
28 * @details
29 * @c Shm2Conf configures the Iceoryx2-based shared-memory transport, which is the
30 * next-generation successor to the @c shm:// Iceoryx backend. Like @c ShmConf it
31 * provides zero-copy inter-process communication on the same machine, but uses the
32 * Iceoryx2 API and does not require a separate RouDi daemon process.
33 *
34 * @par Supported Node Types
35 * @c shm2:// supports all six node types: @c kPublisher, @c kSubscriber, @c kServer,
36 * @c kClient, @c kSetter, and @c kGetter.
37 *
38 * @par URL Format
39 * @code
40 * shm2://<address>[?event=<name>&domain=<N>&depth=<N>&history=<N>&wait=<0|1>][#<size>]
41 * @endcode
42 *
43 * | Component | Description |
44 * | ---------- | -------------------------------------------------------------------- |
45 * | @c address | Service/topic name; formed from @c host + @c "/" + @c path |
46 * | @c event | Optional secondary event name (@c ?event=) |
47 * | @c domain | Domain ID (@c ?domain=, default 0) |
48 * | @c depth | History buffer depth (@c ?depth=, default 0) |
49 * | @c history | History count; defaults to 0 for pub/sub and 1 for field nodes |
50 * | @c wait | Blocking-wait mode for pub/sub only (@c ?wait=1) |
51 * | @c size | Shared-memory allocation size from URL fragment (see below) |
52 *
53 * @par Size Fragment Syntax
54 * The URL fragment sets the shared-memory region size per message. Supported
55 * unit suffixes (case-insensitive): @c B, @c K/@c KB, @c M/@c MB, @c G/@c GB.
56 * The value must be in the range @c (0, @c kMaxMemSize].
57 * @code
58 * shm2://my_topic#1M // 1 MiB per message
59 * shm2://my_topic#512K // 512 KiB per message
60 * shm2://my_topic // default: 128 bytes
61 * @endcode
62 *
63 * @note This header is compiled only when @c VLINK_SUPPORT_SHM2 is defined.
64 * @note Address and event strings must not exceed 80 characters each.
65 * @note The @c wait mode is only valid for @c kPublisher / @c kSubscriber nodes.
66 */
67
68#pragma once
69
70#ifdef VLINK_SUPPORT_SHM2
71
72#include <cstdint>
73#include <string>
74
75#include "../impl/conf.h"
76
77namespace vlink {
78
79/**
80 * @struct Shm2Conf
81 * @brief Configuration for the @c shm2:// Iceoryx2 shared-memory transport.
82 *
83 * @details
84 * Extends the @c ShmConf field set with a @c size parameter that controls the
85 * shared-memory allocation granularity per message. Can be constructed directly
86 * or parsed from a URL string via @c Url.
87 */
88struct VLINK_EXPORT Shm2Conf final : public Conf {
89 std::string address; ///< Topic address (host + "/" + path from URL); max 80 characters.
90 std::string event; ///< Optional secondary event name; max 80 characters.
91 int32_t domain{0}; ///< Domain identifier (non-negative).
92 int32_t depth{0}; ///< History buffer depth; 0 means no buffering.
93 int32_t history{0}; ///< History count; defaults to 0 for pub/sub and 1 for field nodes.
94 int32_t wait{0}; ///< Non-zero enables blocking-wait mode (pub/sub only).
95 uint64_t size{kDefaultMemSize}; ///< Per-message shared-memory region size in bytes.
96
97 /**
98 * @brief Constructs a @c Shm2Conf with explicit parameters.
99 *
100 * @param _address Topic address string; max 80 characters.
101 * @param _event Optional event name; max 80 characters; empty by default.
102 * @param _domain Domain identifier; default 0.
103 * @param _depth Buffer depth; default 0.
104 * @param _history History count; default 0.
105 * @param _wait Blocking-wait flag; default 0 (disabled).
106 * @param _size Memory region size in bytes; default @c kDefaultMemSize (128 B).
107 */
108 explicit Shm2Conf(const std::string& _address, const std::string& _event = "", int32_t _domain = 0,
109 int32_t _depth = 0, int32_t _history = 0, int32_t _wait = 0, uint64_t _size = kDefaultMemSize);
110
111 /**
112 * @brief Returns @c true if all fields equal those of @p conf.
113 *
114 * @param conf Configuration to compare.
115 * @return @c true if all seven fields match.
116 */
117 [[nodiscard]] bool operator==(const Shm2Conf& conf) const noexcept;
118
119 /**
120 * @brief Returns @c true if any field differs from @p conf.
121 *
122 * @param conf Configuration to compare.
123 * @return Logical negation of @c operator==.
124 */
125 [[nodiscard]] bool operator!=(const Shm2Conf& conf) const noexcept;
126
127 /**
128 * @brief Returns @c TransportType::kShm2 identifying this transport.
129 *
130 * @return @c TransportType::kShm2.
131 */
132 [[nodiscard]] TransportType get_transport_type() const override;
133
134 static constexpr size_t kDefaultMemSize = 128U; ///< Default memory size per message: 128 bytes.
135 static constexpr size_t kMaxMemSize = 1024UL * 1024UL * 32; ///< Maximum allowed memory size: 32 MiB.
136
137#ifndef VLINK_ENABLE_C_INTERFACE
139#endif
140 VLINK_ALLOW_IMPL_TYPE(kServer | kClient | kPublisher | kSubscriber | kSetter | kGetter)
141 VLINK_CONF_IMPL(Shm2Conf)
142};
143
144////////////////////////////////////////////////////////////////
145/// Details
146////////////////////////////////////////////////////////////////
147
148inline Shm2Conf::Shm2Conf(const std::string& _address, const std::string& _event, int32_t _domain, int32_t _depth,
149 int32_t _history, int32_t _wait, uint64_t _size)
150 : address(_address), event(_event), domain(_domain), depth(_depth), history(_history), wait(_wait), size(_size) {}
151
152inline bool Shm2Conf::operator==(const Shm2Conf& conf) const noexcept {
153 return address == conf.address && event == conf.event && domain == conf.domain && depth == conf.depth &&
154 history == conf.history && wait == conf.wait && size == conf.size;
155}
156
157inline bool Shm2Conf::operator!=(const Shm2Conf& conf) const noexcept { return !(*this == conf); }
158
159inline TransportType Shm2Conf::get_transport_type() const { return TransportType::kShm2; }
160
161} // namespace vlink
162
163#endif
Abstract transport configuration base class and associated helper macros.
#define VLINK_CONF_IMPL(classname)
Standard boilerplate for concrete Conf subclass declarations.
定义 conf.h:227
#define VLINK_DECLARE_GLOBAL_PROPERTY()
Declares per-transport global state: thread count and property storage.
定义 conf.h:292
#define VLINK_ALLOW_IMPL_TYPE(type)
Declares a static constexpr bitmask of supported ImplType values.
定义 conf.h:268
#define VLINK_EXPORT
定义 macros.h:85