Flow-IPC 1.0.0
Flow-IPC project: Full implementation reference.
session_shared_name.hpp
Go to the documentation of this file.
1/* Flow-IPC: Sessions
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
23
24namespace ipc::session
25{
26
27/* Normally we'd put these prototypes into detail/session_fwd.hpp nearby; but there are some minor subtleties
28 * preventing this. For one there's a reference to Shared_name::S_SENTINEL as a defaul arg, which means
29 * #include "ipc/util/shared_name.hpp" would be needed -- not cool in a _fwd.hpp. Secondly there's the
30 * many references to Shared_name -- which session_fwd.hpp aliases to util::Shared_name -- but session_fwd.hpp
31 * needs detail/session_fwd.hpp for other reasons; so this creates a circular issue. Because of these,
32 * it's not in detail/session_fwd.hpp; nor in some kind of seaparate session_shared_name_fwd.hpp either.
33 *
34 * It's not really a huge deal, but it *is* a break from the recommended _fwd.hpp convention; seemed worth
35 * explaining. */
36
37// Free functions.
38
39/**
40 * Builds an absolute name according to the path convention explained in Shared_name class doc header;
41 * this overload applies to non-global-scope resources within the ipc::session paradigm. Typically one
42 * would then add a util::Shared_name::S_SEPARATOR and then purpose-specific path component(s) (via `/=` or
43 * similar).
44 *
45 * Behavior is undefined if a path fragment argument is empty (assertion may trip).
46 *
47 * @param resource_type
48 * Resource type constant. Typically it is available as a `S_RESOURCE_TYPE_ID` constant in some class;
49 * otherwise as a `Shared_name::S_RESOURCE_TYPE_ID_*` constant.
50 * @param srv_app_name
51 * Session-server application name; typically from Server_app::m_name.
52 * @param srv_namespace
53 * The server namespace, uniquely identifying the server application *instance* (process) across all time,
54 * for the given `srv_app_name`. (I.e., it need only be unique given the particular `resource_type` and
55 * `srv_app_name`.)
56 * @param cli_app_name
57 * Session-client application name; typically from Client_app::m_name.
58 * @param cli_namespace_or_sentinel
59 * The client namespace, uniquely identifying the client application *instance* (process), for the given
60 * set of values in preceding args. (I.e., it need only be unique given the particular values combo in
61 * the preceding args.) If the name applies to all instances of `cli_app_name` this shall be
62 * util::Shared_name::S_SENTINEL.
63 * @return Absolute path not ending in `S_SEPARATOR`, typically to be appended with a `S_SEPARATOR` and more
64 * component(s) by the caller.
65 */
66Shared_name build_conventional_shared_name(const Shared_name& resource_type, const Shared_name& srv_app_name,
67 const Shared_name& srv_namespace, const Shared_name& cli_app_name,
68 const Shared_name& cli_namespace_or_sentinel
70
71/**
72 * Builds an absolute name according to the path convention explained in Shared_name class doc header;
73 * this overload applies to global-scope resources within the ipc::session paradigm. Typically one
74 * would then add a util::Shared_name::S_SEPARATOR and then purpose-specific path component(s)
75 * (via `/=` or similar). Note that this overload supports both of the following situations:
76 * - Applicable to a particular Server_app *instance* (process).
77 * - Applicable to *all* such instances (processes). Then set `srv_namespace_or_sentinel = S_SENTINEL`.
78 *
79 * Arguably the former is more common.
80 *
81 * Behavior is undefined if a path fragment argument is empty (assertion may trip).
82 *
83 * @param resource_type
84 * Resource type constant. Typically it is available as a `S_RESOURCE_TYPE_ID` constant in some class;
85 * otherwise as a `Shared_name::S_RESOURCE_TYPE_ID_*` constant.
86 * @param srv_app_name
87 * Session-server application name; typically from Server_app::m_name.
88 * @param srv_namespace_or_sentinel
89 * The server namespace, uniquely identifying the server application *instance* (process) across all time,
90 * for the given `srv_app_name`. (I.e., it need only be unique given the particular `resource_type` and
91 * `srv_app_name`.) Alternatively it may equal `S_SENTINEL`, indicating the resource applies to
92 * *all* instances of `srv_app_name` (unique Server_app).
93 * @return Absolute path not ending in `S_SEPARATOR`, typically to be appended with a `S_SEPARATOR` and more
94 * component(s) by the caller.
95 */
96Shared_name build_conventional_shared_name(const Shared_name& resource_type, const Shared_name& srv_app_name,
97 const Shared_name& srv_namespace_or_sentinel
99
100/**
101 * Decomposes a Shared_name built as-if by build_conventional_shared_name() overload 1 (non-global-scope); setting
102 * the various component values as out-args; or returning `false` if the name does not follow the
103 * conventions of that build_conventional_shared_name() overload.
104 *
105 * Important: In order for this to return `true` (and thus optionally set any out-args), `name` must
106 * be as-if it is a concatenation of:
107 * - The build_conventional_shared_name() (overload 1/non-global-scope) result.
108 * - `S_SEPARATOR`.
109 * - 0 or more characters (which are placed into `*the_rest` if not-null).
110 *
111 * I.e., `name` cannot be the result of build_conventional_shared_name() alone but also a separator and possibly
112 * more characters.
113 *
114 * @param name
115 * Name to check/decompose.
116 * @param resource_type
117 * If not-null, pointee is set to `resource_type` as-if given to build_conventional_shared_name() overload 1
118 * (non-global-scope). If null ignored.
119 * @param srv_app_name
120 * If not-null, pointee is set to `srv_app_name` as-if given to build_conventional_shared_name() overload 1
121 * (non-global-scope). If null ignored.
122 * @param srv_namespace
123 * If not-null, pointee is set to `srv_namespace` as-if given to build_conventional_shared_name() overload 1
124 * (non-global-scope). If null ignored. This will never equal `S_SENTINEL`.
125 * @param cli_app_name
126 * If not-null, pointee is set to `cli_app_name` as-if given to build_conventional_shared_name() overload 1
127 * (non-global-scope). If null ignored.
128 * @param cli_namespace_or_sentinel
129 * If not-null, pointee is set to `cli_namespace_or_sentinel` as-if given to build_conventional_shared_name()
130 * overload 1 (non-global-scope). If null ignored. This may equal `S_SENTINEL`.
131 * @param the_rest
132 * If not-null, pointee is set to whatever follows the above components (even if some or all of their out-args
133 * were null) and the `S_SEPARATOR` immediately following the last of the above components.
134 * To be clear: that `S_SEPARATOR` itself is not included as the leading character of `*the_rest`.
135 * If null ignored. This may be `.empty()`.
136 * @return `true` if and only if the name could be decomposed, meaning it was built as described above.
137 */
139 Shared_name* resource_type, Shared_name* srv_app_name,
140 Shared_name* srv_namespace, Shared_name* cli_app_name,
141 Shared_name* cli_namespace_or_sentinel, Shared_name* the_rest);
142
143/**
144 * Decomposes a Shared_name built as-if by build_conventional_shared_name() overload 2 (global-scope); setting
145 * the various component values as out-args; or returning `false` if the name does not follow the
146 * conventions of that build_conventional_shared_name() overload.
147 *
148 * Important: In order for this to return `true` (and thus optionally set any out-args), `name` must
149 * be as-if it is a concatenation of:
150 * - The build_conventional_shared_name() (overload 2/global-scope) result.
151 * - `S_SEPARATOR`.
152 * - 0 or more characters (which are placed into `*the_rest` if not-null).
153 *
154 * I.e., `name` cannot be the result of build_conventional_shared_name() alone but also a separator and possibly
155 * more characters.
156 *
157 * @param name
158 * Name to check/decompose.
159 * @param resource_type
160 * If not-null, pointee is set to `resource_type` as-if given to build_conventional_shared_name() overload 2
161 * (global-scope). If null ignored.
162 * @param srv_app_name
163 * If not-null, pointee is set to `srv_app_name` as-if given to build_conventional_shared_name() overload 2
164 * (global-scope). If null ignored.
165 * @param srv_namespace_or_sentinel
166 * If not-null, pointee is set to `srv_namespace_or_sentinel` as-if given to build_conventional_shared_name()
167 * overload 2 (global-scope). If null ignored. This will may equal `S_SENTINEL`.
168 * @param the_rest
169 * If not-null, pointee is set to whatever follows the above components (even if some or all of their out-args
170 * were null), the `S_SENTINEL`, and the `S_SEPARATOR` immediately following the last of the above components.
171 * To be clear: that `S_SEPARATOR` itself is not included as the leading character of `*the_rest`.
172 * If null ignored. This may be `.empty()`.
173 * @return `true` if and only if the name could be decomposed, meaning it was built as described above.
174 * If `false` none of the out-args are touched.
175 */
177 Shared_name* resource_type, Shared_name* srv_app_name,
178 Shared_name* srv_namespace_or_sentinel, Shared_name* the_rest);
179
180/**
181 * Return the prefix common to all calls to either build_conventional_shared_name() overload with
182 * the args `resource_type` and `srv_app_name`. For example one can use a value built by this function as the
183 * util::remove_each_persistent_with_name_prefix() prefix arg.
184 *
185 * Note that the returned value *always* ends with `S_SEPARATOR`.
186 *
187 * @param resource_type
188 * See build_conventional_shared_name() (either overload).
189 * @param srv_app_name
190 * See build_conventional_shared_name() (either overload).
191 * @return Absolute path prefix ending `S_SEPARATOR`.
192 */
193Shared_name build_conventional_shared_name_prefix(const Shared_name& resource_type, const Shared_name& srv_app_name);
194
195} // namespace ipc::session
static const Shared_name S_SENTINEL
A Shared_name fragment, with no S_SEPARATOR characters inside, that represents a path component that ...
Flow-IPC module providing the broad lifecycle and shared-resource organization – via the session conc...
Definition: app.cpp:27
Shared_name build_conventional_shared_name(const Shared_name &resource_type, const Shared_name &srv_app_name, const Shared_name &srv_namespace, const Shared_name &cli_app_name, const Shared_name &cli_namespace_or_sentinel)
Builds an absolute name according to the path convention explained in Shared_name class doc header; t...
Shared_name build_conventional_shared_name_prefix(const Shared_name &resource_type, const Shared_name &srv_app_name)
Return the prefix common to all calls to either build_conventional_shared_name() overload with the ar...
util::Shared_name Shared_name
Convenience alias for the commonly used type util::Shared_name.
bool decompose_conventional_shared_name(const Shared_name &name, Shared_name *resource_type, Shared_name *srv_app_name, Shared_name *srv_namespace, Shared_name *cli_app_name, Shared_name *cli_namespace_or_sentinel, Shared_name *the_rest)
Decomposes a Shared_name built as-if by build_conventional_shared_name() overload 1 (non-global-scope...