Flow-IPC 1.0.2
Flow-IPC project: Full implementation reference.
|
A description of an application in this ipc::session inter-process communication universe. More...
#include <app.hpp>
Public Types | |
using | Master_set = boost::unordered_map< std::string, App > |
Suggested type for storing master repository or all Apps s. See App doc header for discussion. More... | |
Public Attributes | |
std::string | m_name |
Brief application name, readable to humans and unique across all other applications' names; used both as a short programmatic key in shared resource naming (including as a folder in Shared_name for kernel-persistent resources and addresses; and in path names – such as PID file name – in the file system). More... | |
fs::path | m_exec_path |
Absolute, lexically normalized canonical path to the executable entity (which is not a directory), as it would appear in a command line or exec() -like invocation when actually invoking the application. More... | |
util::user_id_t | m_user_id |
The application must run as this user ID (UID). Files and other shared resources shall have this owner. More... | |
util::group_id_t | m_group_id |
The application must run as this group ID (GID). Files and other shared resources shall have this owner. More... | |
Related Functions | |
(Note that these are not member functions.) | |
std::ostream & | operator<< (std::ostream &os, const App &val) |
Prints string representation of the given App to the given ostream . More... | |
A description of an application in this ipc::session inter-process communication universe.
An application is, at least roughly speaking, 1-1 with a distinct executable presumably interested in communicating with another such executable. A process is an instance of an application that has begun execution at some point.
An App is a description of an application, and typically used (at least after program initialization, before actual IPC begins) only as supertype of Client_app and/or Server_app, it is possible that 2+ App
s exist but describe one actual application but in different roles. 2+ such App
s must have all members equal to each other respectively. In particular see App::m_name.
This is a data store (and a simple one). The same holds of Client_app and Server_app. As of this writing there are no rigid rules as to the existence of an App/Client_app/Server_app with this or that stored inside. Make them all day long, if you want! More restrictions shall come into play only when passing various App objects and sub-objects (in some form) to ipc::session APIs, most notably the Session concept and buddies.
However, to be useful, we suggest the following convention. Some key ipc::session APIs may rely on it.
set
or unordered_set
(by App::m_name; see its doc header) available in a centrally-available library; or this *set
could simply be a hard-coded C++ extern const
; whatever works.*set
. (The information regarding which apps are clients, too, can be read from JSON/XML/whatever or hard-coded.)*set
of applications.m_allowed_client_apps
.)Thus one would end up with, after initialization of each process wishing to participate in a given IPC universe:
*set
of App
s (global App registry).*set
of Client_app
s (global Client_app registry).*set
of Server_app
s (global Server_app registry), each Server_app listing the m_name
s of Client_app
s referring to the applications that may initiate sessions with it in its immutable Server_app::m_allowed_client_apps.There should be no need, from this moment on, to copy any App, Client_app, or Server_app. It shall be passed by const
reference.
using ipc::session::App::Master_set = boost::unordered_map<std::string, App> |
|
related |
Prints string representation of the given App
to the given ostream
.
os | Stream to which to write. |
val | Object to serialize. |
os
. Definition at line 124 of file app.cpp.
References m_exec_path, m_group_id, m_name, and m_user_id.
fs::path ipc::session::App::m_exec_path |
Absolute, lexically normalized canonical path to the executable entity (which is not a directory), as it would appear in a command line or exec()
-like invocation when actually invoking the application.
Formally (refer to cppreference.com filesystem::path
doc page):
Do note that because of the "as it would appear in a command line..." requirement this indirectly restricts how processes are to be invoked in this system: always via 1, absolute, lexically normal path to the executable. (Do also note this is still not necessary force an unambiguous way to invoke an application installed at a given location: sym-links, at least, introduce an infinite number of ways to refer to the same binary. That said, at least lexical normalization can be done programmatically in fs
, and sym-link following path resolution is also separately supplied by fs
.)
Definition at line 165 of file app.hpp.
Referenced by operator<<().
util::group_id_t ipc::session::App::m_group_id |
The application must run as this group ID (GID). Files and other shared resources shall have this owner.
Definition at line 171 of file app.hpp.
Referenced by ipc::session::ensure_resource_owner_is_app(), operator<<(), and ipc::session::Session_server_impl< Session_server_t, Server_session_t >::Session_server_impl().
std::string ipc::session::App::m_name |
Brief application name, readable to humans and unique across all other applications' names; used both as a short programmatic key in shared resource naming (including as a folder in Shared_name for kernel-persistent resources and addresses; and in path names – such as PID file name – in the file system).
Neither App nor any nearby sub-class or alias of App (Client_app, Server_app) shall be used as the key type in an associative container (e.g., set
, unordered_map
). Instead App::m_name shall be used as the key when lookup by distinct application is desired. Two scenarios come to mind:
set
or unordered_set
(etc.) of std::string m_name
s.map
or unordered_map
, with the keys being std::string m_name
s, while the values are filled-out App objects (or objects of App sub-class) – with the guarantee that M[name].m_name == name
for all name
s in any such M
.Due to these conventions:
std::string
, as applied to App::m_name.Digression regarding rationale: Why use m_name, and not (say) const App*
, as the key in associative lookups? Answer: It was considered. Due to the infrequency of such lookups, combined with the debug-friendliness/expressiveness of referring to a distinct app by its user-readable name, the lookup-by-name convention felt more straightforward and convenient. Plus, the address of an object stored in a container may change while it is being built, which would add an element of brittleness. One could also use an iterator as a key, but then the registry container would be mandated to be iteratator-stable-under-insertion, and that brings an annoying host of worries. Indexing by string name is solid by comparison, if a bit slower.
Must begin with an ASCII alphabetical character and otherwise consist of only ASCII alphanumerics and underscores. While these are partially conventions driven by style (for example, dashes could also be allowed – we just do not want them to be, so that underscores are always the word-separator used consistently), the following is an important guarantee for related Shared_name and fs::path
semantics:
Therefore:
So if m_name is "abc_def" one can do things like "/some/dir/abc_def/some_file" and "/some/dir/abc_def.pid/file" and "/some/dir/prefix.abc_def.3". I.e., m_name can be safely used as a conceptual "token," even when combined with path/name separators and dot-extension naming.
Definition at line 144 of file app.hpp.
Referenced by ipc::session::shm::classic::Session_server< S_MQ_TYPE_OR_NONE, S_TRANSMIT_NATIVE_HANDLES, Mdt_payload >::app_shm(), ipc::session::shm::arena_lend::jemalloc::Session_server< S_MQ_TYPE_OR_NONE, S_TRANSMIT_NATIVE_HANDLES, Mdt_payload >::app_shm_ptr(), ipc::session::shm::classic::Session_server< S_MQ_TYPE_OR_NONE, S_TRANSMIT_NATIVE_HANDLES, Mdt_payload >::init_app_shm_as_needed(), ipc::session::shm::arena_lend::jemalloc::Session_server< S_MQ_TYPE_OR_NONE, S_TRANSMIT_NATIVE_HANDLES, Mdt_payload >::init_app_shm_as_needed(), operator<<(), and ipc::session::Session_server_impl< Session_server_t, Server_session_t >::Session_server_impl().
util::user_id_t ipc::session::App::m_user_id |
The application must run as this user ID (UID). Files and other shared resources shall have this owner.
Definition at line 168 of file app.hpp.
Referenced by ipc::session::ensure_resource_owner_is_app(), operator<<(), and ipc::session::Session_server_impl< Session_server_t, Server_session_t >::Session_server_impl().