VLink  2.1.0
A high-performance communication middleware
vlink.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 vlink.h
26  * @brief Single umbrella entry point for the public VLink communication SDK.
27  *
28  * @details
29  * Including @c <vlink/vlink.h> pulls in every primitive of the three VLink
30  * communication models together with the @c MessageLoop dispatcher and a small
31  * set of base utilities. Application code should rarely need to include any
32  * other VLink header directly; transport-specific configuration types are
33  * brought in transitively through the primitive headers.
34  *
35  * @par Pulled-in Headers and Mapped Primitives
36  * | Header | Public Primitive(s) | Model | Role |
37  * | ----------------------- | ---------------------------------- | --------- | -------------------------- |
38  * | @c client.h | @c Client<ReqT,RespT> | Method | RPC caller side |
39  * | @c server.h | @c Server<ReqT,RespT> | Method | RPC handler side |
40  * | @c publisher.h | @c Publisher<MsgT> | Event | Topic emitter |
41  * | @c subscriber.h | @c Subscriber<MsgT> | Event | Topic listener |
42  * | @c getter.h | @c Getter<ValueT> | Field | Latest-value reader |
43  * | @c setter.h | @c Setter<ValueT> | Field | Latest-value writer |
44  * | @c base/message_loop.h | @c MessageLoop | Dispatch | Callback re-routing |
45  * | @c base/utils.h | @c sleep_for, env helpers, etc. | Utilities | General-purpose helpers |
46  *
47  * @par Three Communication Models Side-by-side
48  * @verbatim
49  * +----------------------+ +-----------------------+ +-------------------------+
50  * | EVENT MODEL | | METHOD MODEL | | FIELD MODEL |
51  * | (pub/sub stream) | | (request/response) | | (latest-value sync) |
52  * +----------------------+ +-----------------------+ +-------------------------+
53  * | Publisher<MsgT> | | Client<Req,Resp> | | Setter<ValueT> |
54  * | | | | | | | | |
55  * | v publish() | | v invoke() | | v set() |
56  * | transport | | transport | | transport |
57  * | | | | | | | (retains latest) |
58  * | v | | v | | | |
59  * | Subscriber<MsgT> | | Server<Req,Resp> | | v |
60  * | on each msg | | handler fills resp | | Getter<ValueT> |
61  * | | | | | | get() / listen() |
62  * | | | v reply | | |
63  * | | | Client receives | | |
64  * +----------------------+ +-----------------------+ +-------------------------+
65  * @endverbatim
66  *
67  * @par Transport Selection via URL Prefix
68  * The transport back-end is selected by the URL scheme. All API calls remain
69  * identical when the prefix is changed; this is the central design tenet of
70  * VLink.
71  *
72  * | Prefix | Back-end | Typical use case |
73  * | -------------- | --------------------------------- | -------------------------------------- |
74  * | @c intra:// | In-process pub/sub | Same-process zero-copy fan-out |
75  * | @c shm:// | Iceoryx shared memory | Inter-process zero-copy on one host |
76  * | @c shm2:// | Native VLink shared memory | Lightweight inter-process IPC |
77  * | @c dds:// | FastDDS (CDR) | Standards-compliant DDS distribution |
78  * | @c ddsc:// | CycloneDDS | CycloneDDS-based deployments |
79  * | @c ddsr:// | RTI Connext DDS | RTI-licensed deployments |
80  * | @c zenoh:// | Eclipse Zenoh | Pub/sub and query/reply, edge to cloud |
81  * | @c someip:// | SOME/IP | Automotive AUTOSAR adaptive services |
82  * | @c fdbus:// | FDBus | Linux/Android service bus |
83  * | @c mqtt:// | MQTT | Telemetry to cloud brokers |
84  *
85  * @par Quick-start Example -- one process, three models
86  * @code
87  * #include <vlink/vlink.h>
88  *
89  * // ---- Event model ---------------------------------------------------------
90  * vlink::Subscriber<MyMsg> sub("dds://vehicle/speed");
91  * sub.listen([](const MyMsg& msg) { handle_event(msg); });
92  *
93  * vlink::Publisher<MyMsg> pub("dds://vehicle/speed");
94  * pub.publish(MyMsg{100});
95  *
96  * // ---- Method model (synchronous RPC) -------------------------------------
97  * vlink::Server<Req, Resp> svr("dds://compute/sum");
98  * svr.listen([](const Req& q, Resp& r) { r.value = q.a + q.b; });
99  *
100  * vlink::Client<Req, Resp> cli("dds://compute/sum");
101  * Resp r;
102  * if (cli.invoke(Req{1, 2}, r)) { use(r); }
103  *
104  * // ---- Field model (latest-value sync) ------------------------------------
105  * vlink::Setter<int> setter("shm://vehicle/gear");
106  * setter.set(3);
107  *
108  * vlink::Getter<int> getter("shm://vehicle/gear");
109  * if (auto gear = getter.get()) { use(*gear); }
110  * @endcode
111  *
112  * @note Each primitive has a @c Security* counterpart (@c SecurityPublisher,
113  * @c SecuritySubscriber, @c SecurityClient, @c SecurityServer,
114  * @c SecuritySetter, @c SecurityGetter) that transparently encrypts and
115  * decrypts the payload using a @c Security::Config aggregate.
116  *
117  * @see publisher.h, subscriber.h, client.h, server.h, getter.h, setter.h
118  */
119 
120 #pragma once
121 
122 // NOLINTBEGIN
123 
124 // method
125 #include "./client.h"
126 #include "./server.h"
127 
128 // event
129 #include "./publisher.h"
130 #include "./subscriber.h"
131 
132 // field
133 #include "./getter.h"
134 #include "./setter.h"
135 
136 // message_loop
137 #include "./base/message_loop.h"
138 
139 // utils
140 #include "./base/utils.h"
141 
142 // NOLINTEND
Caller-side primitive of the VLink method (RPC) communication model.
Read-side primitive of the VLink field communication model.
Single-threaded task dispatcher with three queue backends, timers and scheduling envelopes.
Write-side primitive of the VLink event communication model.
Handler-side primitive of the VLink method (RPC) communication model.
Write-side primitive of the VLink field communication model.
Read-side primitive of the VLink event communication model.
Portable host-system utility surface used across the VLink runtime.