Flow-IPC 1.0.2
Flow-IPC project: Full implementation reference.
classic_fwd.hpp
Go to the documentation of this file.
1/* Flow-IPC: Shared Memory
2 * Copyright 2023 Akamai Technologies, Inc.
3 *
4 * Licensed under the Apache License, Version 2.0 (the
5 * "License"); you may not use this file except in
6 * compliance with the License. You may obtain a copy
7 * of the License at
8 *
9 * https://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in
12 * writing, software distributed under the License is
13 * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
14 * CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing
16 * permissions and limitations under the License. */
17
18/// @file
19#pragma once
20
21#include "ipc/session/schema/common.capnp.h"
23
24/**
25 * Support for SHM-backed ipc::session sessions and session-servers with the SHM-classic
26 * (ipc::shm::classic::Pool_arena) provider. See the doc header for the general ipc::session::shm namespace.
27 */
29{
30
31// Types.
32
33// Find doc headers near the bodies of these compound types.
34
35template<typename Session_t>
36class Session_mv;
37
38template<typename Server_session_impl_t>
40template<typename Client_session_impl_t>
42
43template<schema::MqType S_MQ_TYPE_OR_NONE, bool S_TRANSMIT_NATIVE_HANDLES, typename Mdt_payload = ::capnp::Void>
44class Server_session;
45
46template<schema::MqType S_MQ_TYPE_OR_NONE, bool S_TRANSMIT_NATIVE_HANDLES, typename Mdt_payload = ::capnp::Void>
47class Session_server;
48
49/**
50 * This is to session::Client_session what shm::classic::Server_session is to session::Server_session. In
51 * terms of additional (to that of #Client_session) public behavior, from the public API user's point of
52 * view, this class template alias is simply ~exactly identical/symmetrical to shm::classic::Server_session.
53 * See its doc header. That is during PEER state.
54 *
55 * The only difference is shm::classic::Server_session::app_shm() and `shm::classic::Client_session::app_shm()`
56 * (actually Session_mv::app_shm() = both) differ in terms of how one views the lifetime of the
57 * underlying SHM areas. This is reflected in the latter's doc header.
58 * Essentially, though, the `Arena*` returned by the former can be used beyond
59 * the returning `*this` being destroyed, as long as its parent shm::classic::Session_server is alive (which
60 * is typical). In contrast that is not true of that returned by `shm::classic::Client_session::app_shm()`; but
61 * since the destruction of a #Client_session implies either the process is itself going down, or the
62 * opposing server process (and thus shm::classic::Session_server) is going down/has gone down, this should not
63 * be relevant, as those objects should never be accessed again anyway.
64 *
65 * @internal
66 * ### Implementation ###
67 * First see the Implementation section of shm::classic::Server_session. It gives a detailed description of the
68 * overall design -- both its own side and this (client) side too. So read it; then come back here.
69 *
70 * That said, shm::classic::Client_session is a much simpler situation. It is not inter-operating with
71 * any server object; and (as explained in the referenced doc header) all it needs to do is open the pools
72 * guaranteed to exist by the time the vanilla #Client_session enters PEER state (just past log-in response receipt).
73 *
74 * So all we have to do is provide a modified `async_connect()` which:
75 * - executes vanilla session::Client_session_impl::async_connect(); once that triggers the on-done handler:
76 * - open the 2 SHM pools (a synchronous op);
77 * - invoke the user's original on-done handler.
78 *
79 * In `*this`, mechanically: the true implementation of the needed setup and accessors (explained above) is in
80 * shm::classic::Client_session_impl, and the vanilla core of that is in its super-class session::Client_session_impl.
81 * That's the key; then Client_session_mv adds movability around that guy; and lastly this type sub-classes *that*
82 * and completes the puzzle by pImpl-forwarding to the added (SHM-focused) API.
83 *
84 * The last and most boring piece of the puzzle are the pImpl-lite wrappers around the SHM-specific API
85 * that shm::classic::Client_session adds to super-class Client_session_mv: `session_shm()` and so on.
86 * Just see same spot in shm::classic::Server_session doc header; it explains both client and server sides.
87 * @endinternal
88 *
89 * @tparam S_MQ_TYPE_OR_NONE
90 * Identical to session::Client_session.
91 * @tparam S_TRANSMIT_NATIVE_HANDLES
92 * Identical to session::Client_session.
93 * @tparam Mdt_payload
94 * Identical to session::Client_session.
95 */
96template<schema::MqType S_MQ_TYPE_OR_NONE, bool S_TRANSMIT_NATIVE_HANDLES, typename Mdt_payload = ::capnp::Void>
101
102// Free functions.
103
104/**
105 * Prints string representation of the given `Session_mv` to the given `ostream`.
106 *
107 * @relatesalso Session_mv
108 *
109 * @param os
110 * Stream to which to write.
111 * @param val
112 * Object to serialize.
113 * @return `os`.
114 */
115template<typename Session_t>
116std::ostream& operator<<(std::ostream& os, const Session_mv<Session_t>& val);
117
118/**
119 * Prints string representation of the given `Server_session` to the given `ostream`.
120 *
121 * @relatesalso Server_session
122 *
123 * @param os
124 * Stream to which to write.
125 * @param val
126 * Object to serialize.
127 * @return `os`.
128 */
129template<schema::MqType S_MQ_TYPE_OR_NONE, bool S_TRANSMIT_NATIVE_HANDLES,
130 typename Mdt_payload>
131std::ostream& operator<<(std::ostream& os,
132 const Server_session
133 <S_MQ_TYPE_OR_NONE, S_TRANSMIT_NATIVE_HANDLES, Mdt_payload>& val);
134
135/**
136 * Prints string representation of the given `Session_server` to the given `ostream`.
137 *
138 * @relatesalso Session_server
139 *
140 * @param os
141 * Stream to which to write.
142 * @param val
143 * Object to serialize.
144 * @return `os`.
145 */
146template<schema::MqType S_MQ_TYPE_OR_NONE, bool S_TRANSMIT_NATIVE_HANDLES,
147 typename Mdt_payload>
148std::ostream& operator<<(std::ostream& os,
149 const Session_server
150 <S_MQ_TYPE_OR_NONE, S_TRANSMIT_NATIVE_HANDLES, Mdt_payload>& val);
151
152} // namespace ipc::session::shm::classic
Implements Session concept on the Client_app end: a Session_mv that first achieves PEER state by conn...
Core internally-used implementation of shm::classic::Client_session: it is to the latter what its pub...
Identical to session::Server_session in every way, except that it makes available two SHM arenas,...
Implements the SHM-related API common to shm::classic::Server_session and shm::classic::Client_sessio...
Definition: session.hpp:44
This is to vanilla Session_server what shm::classic::Server_session is to vanilla Server_session: it ...
Support for SHM-backed ipc::session sessions and session-servers with the SHM-classic (ipc::shm::clas...
Definition: classic_fwd.hpp:24
std::ostream & operator<<(std::ostream &os, const Session_impl< Session_impl_t > &val)
Prints string representation of the given Session_impl to the given ostream.