Flow-IPC 1.0.2
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
31{
32
33// Types.
34
35/**
36 * Internally used (data-free) addendum on-top of Msg_out which makes the `protected` API public instead.
37 * See the implementation notes in Msg_out doc header regarding this design.
38 */
39template<typename Message_body, typename Struct_builder>
40class Msg_out_impl : public Msg_out<Message_body, Struct_builder>
41{
42public:
43 // Types.
44
45 /// Short-hand for base class.
47
48 // Methods.
49
50 /**
51 * See super-class.
52 *
53 * @param target_blobs
54 * See super-class.
55 * @param session
56 * See super-class.
57 * @param err_code
58 * See super-class.
59 */
60 void emit_serialization(Segment_ptrs* target_blobs, const typename Base::Builder::Session& session,
61 Error_code* err_code) const;
62
63 /**
64 * See super-class.
65 * @return See super-class.
66 */
67 size_t n_serialization_segments() const;
68}; // class Msg_out_impl
69
70/**
71 * Internally used (data-free) addendum on-top of Msg_in which makes the `protected` API public instead.
72 * See the implementation notes in Msg_in doc header regarding this design.
73 *
74 * @todo Msg_in_impl is pretty wordy; maybe `friend` would have been stylistically acceptable after all?
75 * It's so much briefer, and we could simply resolve to only access the `protected` APIs and not `private` stuff....
76 */
77template<typename Message_body, typename Struct_reader_config>
78class Msg_in_impl : public Msg_in<Message_body, Struct_reader_config>
79{
80public:
81 // Types.
82
83 /// Short-hand for base class.
85
86 /// See super-class.
88
89 /// See super-class.
90 using Mdt_reader = typename Base::Mdt_reader;
91
92 // Constructors.
93
94 /**
95 * See super-class.
96 *
97 * @param struct_reader_config
98 * See super-class.
99 */
100 explicit Msg_in_impl(const typename Base::Reader_config& struct_reader_config);
101
102 /**
103 * See super-class.
104 *
105 * @param native_handle_or_null
106 * See super-class.
107 */
109
110 /**
111 * See super-class.
112 *
113 * @param max_sz
114 * See super-class.
115 * @return See super-class.
116 */
117 flow::util::Blob* add_serialization_segment(size_t max_sz);
118
119 /**
120 * See super-class.
121 *
122 * @param logger_ptr
123 * See super-class.
124 * @param err_code
125 * See super-class.
126 * @return See super-class.
127 */
128 size_t deserialize_mdt(flow::log::Logger* logger_ptr, Error_code* err_code);
129
130 /**
131 * See super-class.
132 * @param err_code
133 * See super-class.
134 */
135 void deserialize_body(Error_code* err_code);
136
137 /**
138 * See super-class.
139 * @return See super-class.
140 */
141 msg_id_t id_or_none() const;
142
143 /**
144 * See super-class.
145 * @return See super-class.
146 */
148
149 /**
150 * See super-class.
151 * @return See super-class.
152 */
154
155 /**
156 * See super-class.
157 * @return See super-class.
158 */
159 const Session_token& session_token() const;
160
161 /**
162 * See super-class.
163 * @return See super-class.
164 */
165 const Mdt_reader& mdt_root() const;
166}; // class Msg_in_impl
167
168// Msg_out_impl template implementations.
169
170template<typename Message_body, typename Struct_builder_config>
171void
173 const typename Base::Builder::Session& session,
174 Error_code* err_code) const
175{
176 Base::emit_serialization(target_blobs, session, err_code);
177}
178
179template<typename Message_body, typename Struct_builder_config>
181{
182 return Base::n_serialization_segments();
183}
184
185// Msg_in_impl template implementations.
186
187template<typename Message_body, typename Struct_reader_config>
189 (const typename Base::Reader_config& struct_reader_config) :
190 Base(struct_reader_config)
191{
192 // Yeah.
193}
194
195template<typename Message_body, typename Struct_reader_config>
197 (Native_handle&& native_handle_or_null)
198{
199 Base::store_native_handle_or_null(std::move(native_handle_or_null));
200}
201
202template<typename Message_body, typename Struct_reader_config>
204{
205 return Base::add_serialization_segment(max_sz);
206}
207
208template<typename Message_body, typename Struct_reader_config>
210 Error_code* err_code)
211{
212 return Base::deserialize_mdt(logger_ptr, err_code);
213}
214
215template<typename Message_body, typename Struct_reader_config>
217{
218 Base::deserialize_body(err_code);
219}
220
221template<typename Message_body, typename Struct_reader_config>
223{
224 return Base::id_or_none();
225}
226
227template<typename Message_body, typename Struct_reader_config>
229{
230 return Base::originating_msg_id_or_none();
231}
232
233template<typename Message_body, typename Struct_reader_config>
236{
237 return Base::internal_msg_body_root();
238}
239
240template<typename Message_body, typename Struct_reader_config>
242{
243 return Base::session_token();
244}
245
246template<typename Message_body, typename Struct_reader_config>
249{
250 return Base::mdt_root();
251}
252
253} // namespace ipc::transport::struc
Internally used (data-free) addendum on-top of Msg_in which makes the protected API public instead.
Definition: msg_impl.hpp:79
size_t deserialize_mdt(flow::log::Logger *logger_ptr, Error_code *err_code)
See super-class.
Definition: msg_impl.hpp:209
typename Base::Internal_msg_body_reader Internal_msg_body_reader
See super-class.
Definition: msg_impl.hpp:87
msg_id_t originating_msg_id_or_none() const
See super-class.
Definition: msg_impl.hpp:228
Msg_in_impl(const typename Base::Reader_config &struct_reader_config)
See super-class.
Definition: msg_impl.hpp:189
const Mdt_reader & mdt_root() const
See super-class.
Definition: msg_impl.hpp:248
Internal_msg_body_reader internal_msg_body_root() const
See super-class.
Definition: msg_impl.hpp:235
const Session_token & session_token() const
See super-class.
Definition: msg_impl.hpp:241
typename Base::Mdt_reader Mdt_reader
See super-class.
Definition: msg_impl.hpp:90
msg_id_t id_or_none() const
See super-class.
Definition: msg_impl.hpp:222
void store_native_handle_or_null(Native_handle &&native_handle_or_null)
See super-class.
Definition: msg_impl.hpp:197
flow::util::Blob * add_serialization_segment(size_t max_sz)
See super-class.
Definition: msg_impl.hpp:203
void deserialize_body(Error_code *err_code)
See super-class.
Definition: msg_impl.hpp:216
A structured in-message instance suitable as received and emittable (to user) by struc::Channel.
Definition: msg.hpp:547
typename Mdt::Reader Mdt_reader
Same as Msg_mdt_out::Body_builder but the Reader instead.
Definition: msg.hpp:645
Native_handle native_handle_or_null() const
The Native_handle – potentially null meaning none – embedded in this message.
Definition: msg.hpp:1330
Struct_reader_config Reader_config
See struc::Channel::Reader_config.
Definition: msg.hpp:558
typename schema::detail::StructuredMessage::InternalMessageBody::Reader Internal_msg_body_reader
Reader counterpart to Msg_mdt_out::Internal_msg_body_builder.
Definition: msg.hpp:639
Internally used (data-free) addendum on-top of Msg_out which makes the protected API public instead.
Definition: msg_impl.hpp:41
void emit_serialization(Segment_ptrs *target_blobs, const typename Base::Builder::Session &session, Error_code *err_code) const
See super-class.
Definition: msg_impl.hpp:172
size_t n_serialization_segments() const
See super-class.
Definition: msg_impl.hpp:180
A structured out-message suitable to be sent via struc::Channel::send() (et al).
Definition: msg.hpp:154
unspecified Session
Type objects of which specify to emit_serialization() the opposing recipient for which the serializat...
Definition: serializer.hpp:248
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:113
std::vector< flow::util::Blob * > Segment_ptrs
Sequence of 1+ Blob pointers to blobs which must stay alive while these pointers may be dereferenced,...
Definition: struc_fwd.hpp:122
uint64_t msg_id_t
Message ID uniquely identifying outgoing message (Msg_out, among all other Msg_outs),...
Definition: struc_fwd.hpp:145
flow::Error_code Error_code
Short-hand for flow::Error_code which is very common.
Definition: common.hpp:298
A monolayer-thin wrapper around a native handle, a/k/a descriptor a/k/a FD.