Flow-IPC 3.0.0
Flow-IPC project: Full implementation reference.
msg_impl.hpp
Go to the documentation of this file.
1/* Flow-IPC: Structured Transport
2 * Copyright (c) 2023 Akamai Technologies, Inc.; and other contributors.
3 * Each commit is copyright by its respective author or author's employer.
4 *
5 * Licensed under the MIT License:
6 *
7 * Permission is hereby granted, free of charge, to any person obtaining a copy
8 * of this software and associated documentation files (the "Software"), to deal
9 * in the Software without restriction, including without limitation the rights
10 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11 * copies of the Software, and to permit persons to whom the Software is
12 * furnished to do so, subject to the following conditions:
13 *
14 * The above copyright notice and this permission notice shall be included in
15 * all copies or substantial portions of the Software.
16 *
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
23 * THE SOFTWARE. */
24
25/// @file
26#pragma once
27
29#include <boost/move/unique_ptr.hpp>
30
32{
33
34// Types.
35
36/**
37 * This is the `friend` facade of Msg_out that exposes `private` APIs hidden from public user by providing
38 * public access to them; this is used internally by struc::sync_io::Channel at least. The background is
39 * briefly explained in the impl section of Msg_out doc header.
40 *
41 * @tparam Base_t
42 * The type of object whose specific `private` API to expose.
43 */
44template<typename Base_t>
46{
47 // Types.
48
49 /// Short-hand for wrapped class.
50 using Base = Base_t;
51
52 // Data.
53
54 /// Direct-initializable wrapped object. Access `public` API through this reference; `private` API via `*this`.
56
57 // Methods.
58
59 /**
60 * See #Base counterpart.
61 * @param args
62 * See #Base counterpart.
63 */
64 template<typename... Args>
65 void emit_serialization(Args&&... args);
66}; // struct Msg_out_impl
67
68/**
69 * This is the `friend` facade of Msg_in that exposes `private` APIs hidden from public user by providing
70 * public access to them; this is used internally by struc::sync_io::Channel at least. The background is
71 * briefly explained in the impl section of Msg_in doc header.
72 *
73 * @todo Some of the methods in Msg_in_impl forward an arbitrary args list while others match the Msg_in
74 * signature exactly; probably we should do the former in all of them. At least if there are 1+ args for a given
75 * method, might as well. (When there are none... more of a toss-up... it's more code now but better for
76 * ease of potential maintenance.)
77 *
78 * @tparam Base_t
79 * The type of object whose specific `private` API to expose.
80 */
81template<typename Base_t>
83{
84 // Types.
85
86 /// Short-hand for wrapped class.
87 using Base = Base_t;
88
89 /// See #Base counterpart.
90 using Internal_msg_body_reader = typename Base::Internal_msg_body_reader;
91
92 /// See #Base counterpart.
93 using Mdt_reader = typename Base::Mdt_reader;
94
95 // Data.
96
97 /// Direct-initializable wrapped object. Access `public` API through this reference; `private` API via `*this`.
99
100 // Methods.
101
102 /**
103 * Forwards to #Base ctor(s).
104 * @param ctor_args
105 * See above.
106 * @return New #Base.
107 */
108 template<typename... Ctor_args>
109 static auto ct_base(Ctor_args&&... ctor_args) -> boost::movelib::unique_ptr<Base>;
110 // @todo See definition for reason for the odd signature form (Doxygen). --^
111
112 /**
113 * See #Base counterpart.
114 * @param native_handle_or_null
115 * See #Base counterpart.
116 */
117 void store_native_handle_or_null(Native_handle&& native_handle_or_null);
118
119 /**
120 * See #Base counterpart.
121 * @param blob
122 * See #Base counterpart.
123 */
125
126 /**
127 * See #Base counterpart.
128 * @param args
129 * See #Base counterpart.
130 * @return See #Base counterpart.
131 */
132 template<typename... Args>
133 size_t deserialize_mdt(Args&&... args);
134
135 /**
136 * See #Base counterpart.
137 * @param args
138 * See #Base counterpart.
139 */
140 template<typename... Args>
141 void deserialize_body(Args&&... args);
142
143 /**
144 * See #Base counterpart.
145 * @return See #Base counterpart.
146 */
147 msg_id_t id_or_none() const;
148
149 /**
150 * See #Base counterpart.
151 * @return See #Base counterpart.
152 */
154
155 /**
156 * See #Base counterpart.
157 * @return See #Base counterpart.
158 */
160
161 /**
162 * See #Base counterpart.
163 * @return See #Base counterpart.
164 */
165 const Session_token& session_token() const;
166
167 /**
168 * See #Base counterpart.
169 * @return See #Base counterpart.
170 */
171 const Mdt_reader& mdt_root() const;
172}; // struct Msg_in_impl
173
174// Template implementations.
175
176template<typename Base_t>
177template<typename... Args>
179{
180 m_base.emit_serialization(std::forward<Args>(args)...);
181}
182
183template<typename Base_t>
184template<typename... Ctor_args>
185auto Msg_in_impl<Base_t>::ct_base(Ctor_args&&... ctor_args) -> boost::movelib::unique_ptr<Base_t>
186// Doxygen 1.9.4 gets confused here otherwise; the `->` form is a work-around for that. @todo Revisit with later ver.
187{
188 using boost::movelib::unique_ptr;
189
190 // Out of abundance of caution: Avoid initializer-list pitfalls in this generic code: (), not {} here.
191 return unique_ptr<Base>(new Base(std::forward<Ctor_args>(ctor_args)...));
192}
193
194template<typename Base_t>
196{
197 m_base.store_native_handle_or_null(std::move(native_handle_or_null));
198}
199
200template<typename Base_t>
202{
203 return m_base.add_serialization_segment(std::move(blob));
204}
205
206template<typename Base_t>
207template<typename... Args>
209{
210 return m_base.deserialize_mdt(std::forward<Args>(args)...);
211}
212
213template<typename Base_t>
214template<typename... Args>
216{
217 m_base.deserialize_body(std::forward<Args>(args)...);
218}
219
220template<typename Base_t>
222{
223 return m_base.id_or_none();
224}
225
226template<typename Base_t>
228{
229 return m_base.originating_msg_id_or_none();
230}
231
232template<typename Base_t>
234{
235 return m_base.internal_msg_body_root();
236}
237
238template<typename Base_t>
240{
241 return m_base.session_token();
242}
243
244template<typename Base_t>
246{
247 return m_base.mdt_root();
248}
249
250} // namespace ipc::transport::struc
Sub-module of Flow-IPC module ipc::transport providing transmission of structured messages specifical...
Definition: channel.cpp:31
boost::uuids::uuid Session_token
A type used by struc::Channel for internal safety/security/auth needs.
Definition: struc_fwd.hpp:121
flow::util::Blob_sans_log_context Segment_blob_in
Short-hand for a high-performance blob structure that represents an IPC-incoming (sub-)segment 1+ of ...
Definition: struc_fwd.hpp:192
uint64_t msg_id_t
Message ID uniquely identifying outgoing message (Msg_out, among all other Msg_outs),...
Definition: struc_fwd.hpp:215
This is the friend facade of Msg_in that exposes private APIs hidden from public user by providing pu...
Definition: msg_impl.hpp:83
const Mdt_reader & mdt_root() const
See Base counterpart.
Definition: msg_impl.hpp:245
msg_id_t id_or_none() const
See Base counterpart.
Definition: msg_impl.hpp:221
Internal_msg_body_reader internal_msg_body_root() const
See Base counterpart.
Definition: msg_impl.hpp:233
void add_serialization_segment(Segment_blob_in &&blob)
See Base counterpart.
Definition: msg_impl.hpp:201
void store_native_handle_or_null(Native_handle &&native_handle_or_null)
See Base counterpart.
Definition: msg_impl.hpp:195
Base & m_base
Direct-initializable wrapped object. Access public API through this reference; private API via *this.
Definition: msg_impl.hpp:98
static auto ct_base(Ctor_args &&... ctor_args) -> boost::movelib::unique_ptr< Base >
Forwards to Base ctor(s).
Definition: msg_impl.hpp:185
Base_t Base
Short-hand for wrapped class.
Definition: msg_impl.hpp:87
size_t deserialize_mdt(Args &&... args)
See Base counterpart.
Definition: msg_impl.hpp:208
typename Base::Internal_msg_body_reader Internal_msg_body_reader
See Base counterpart.
Definition: msg_impl.hpp:90
msg_id_t originating_msg_id_or_none() const
See Base counterpart.
Definition: msg_impl.hpp:227
const Session_token & session_token() const
See Base counterpart.
Definition: msg_impl.hpp:239
typename Base::Mdt_reader Mdt_reader
See Base counterpart.
Definition: msg_impl.hpp:93
void deserialize_body(Args &&... args)
See Base counterpart.
Definition: msg_impl.hpp:215
This is the friend facade of Msg_out that exposes private APIs hidden from public user by providing p...
Definition: msg_impl.hpp:46
void emit_serialization(Args &&... args)
See Base counterpart.
Definition: msg_impl.hpp:178
Base & m_base
Direct-initializable wrapped object. Access public API through this reference; private API via *this.
Definition: msg_impl.hpp:55
Base_t Base
Short-hand for wrapped class.
Definition: msg_impl.hpp:50
A monolayer-thin wrapper around a native handle, a/k/a descriptor a/k/a FD.