Monado OpenXR Runtime
Loading...
Searching...
No Matches
ipc_server_interface.h
Go to the documentation of this file.
1// Copyright 2020-2023, Collabora, Ltd.
2// Copyright 2024-2026, NVIDIA CORPORATION.
3// SPDX-License-Identifier: BSL-1.0
4/*!
5 * @file
6 * @brief Interface for IPC server code.
7 * @author Pete Black <pblack@collabora.com>
8 * @author Jakob Bornecrantz <jakob@collabora.com>
9 * @author Rylie Pavlik <rylie.pavlik@collabora.com>
10 * @ingroup ipc_server
11 */
12
13#pragma once
14
15#include "xrt/xrt_config_os.h"
16#include "xrt/xrt_results.h"
17
18#include "util/u_debug_gui.h"
19
20
21#ifdef __cplusplus
22extern "C" {
23#endif
24
25
26struct xrt_instance;
27struct ipc_server;
28
29/*!
30 * Information passed into the IPC server main function, used for customization
31 * of the IPC server.
32 *
33 * @ingroup ipc_server
34 */
36{
37 //! Information passed onto the debug gui.
39
40 //! Flag whether runtime should exit on app disconnect.
42
43 //! Disable listening on stdin for server stop.
45
46 /*!
47 * Socket filename (named pipe name on Windows) in the runtime dir. Required except on Android, where it is
48 * ignored. Not used when systemd starts the service with an already listening socket.
49 */
50 const char *socket_filename;
51
52 /*!
53 * Pidfile name in the runtime dir, used to refuse a second instance. Required except on Android, where it is
54 * ignored, and only takes effect when built with libbsd.
55 *
56 * The pidfile also guards the socket: while holding it the service treats an existing socket file as stale and
57 * replaces it. Services that share a socket_filename must therefore also share the pid_filename.
58 */
59 const char *pid_filename;
60};
61
62/*!
63 *
64 * @ingroup ipc_server
65 */
67{
68 /*!
69 * The IPC server failed to init.
70 *
71 * @param[in] xret The error code generated during init.
72 * @param[in] data User data given passed into the main function.
73 */
74 void (*init_failed)(xrt_result_t xret, void *data);
75
76 /*!
77 * The service has completed init and is entering its mainloop.
78 *
79 * @param[in] s The IPC server.
80 * @param[in] xinst Instance that was created by the IPC server.
81 * @param[in] data User data given passed into the main function.
82 */
83 void (*mainloop_entering)(struct ipc_server *s, struct xrt_instance *xinst, void *data);
84
85 /*!
86 * The service is leaving the mainloop, after this callback returns the
87 * IPC server will destroy all resources created.
88 *
89 * @param[in] s The IPC server.
90 * @param[in] xinst Instance that was created by the IPC server.
91 * @param[in] data User data given passed into the main function.
92 */
93 void (*mainloop_leaving)(struct ipc_server *s, struct xrt_instance *xinst, void *data);
94
95 /*!
96 * A new client has connected to the IPC server.
97 *
98 * param s The IPC server.
99 * param client_id The ID of the newly connected client.
100 * param data User data given passed into the main function.
101 */
102 void (*client_connected)(struct ipc_server *s, uint32_t client_id, void *data);
103
104 /*!
105 * A client has disconnected from the IPC server.
106 *
107 * param s The IPC server.
108 * param client_id The ID of the newly connected client.
109 * param data User data given passed into the main function.
110 */
111 void (*client_disconnected)(struct ipc_server *s, uint32_t client_id, void *data);
112};
113
114/*!
115 * Common main function for starting the IPC service.
116 *
117 * Except on Android, @p ismi must have both socket_filename and pid_filename set, otherwise
118 * @ref ipc_server_callbacks::init_failed is called with XRT_ERROR_INVALID_ARGUMENT and -1 is returned.
119 *
120 * @ingroup ipc_server
121 */
122int
123ipc_server_main_common(const struct ipc_server_main_info *ismi, const struct ipc_server_callbacks *iscb, void *data);
124
125/*!
126 * Asks the server to shut down, this call is asynchronous and will return
127 * immediately. Use callbacks to be notified when the server stops.
128 *
129 * @memberof ipc_server
130 */
131int
132ipc_server_stop(struct ipc_server *s);
133
134#ifndef XRT_OS_ANDROID
135
136/*!
137 * Main entrypoint to the compositor process.
138 *
139 * Both socket_filename and pid_filename in @p ismi must be set, otherwise this fails and returns -1.
140 *
141 * @ingroup ipc_server
142 */
143int
144ipc_server_main(int argc, char **argv, const struct ipc_server_main_info *ismi);
145
146#endif
147
148
149#ifdef __cplusplus
150}
151#endif
int ipc_server_main(int argc, char **argv, const struct ipc_server_main_info *ismi)
Main entrypoint to the compositor process.
Definition ipc_server_process.c:1265
int ipc_server_main_common(const struct ipc_server_main_info *ismi, const struct ipc_server_callbacks *iscb, void *data)
Common main function for starting the IPC service.
Definition ipc_server_process.c:1132
enum xrt_result xrt_result_t
Result type used across Monado.
Definition ipc_server_interface.h:67
void(* client_disconnected)(struct ipc_server *s, uint32_t client_id, void *data)
A client has disconnected from the IPC server.
Definition ipc_server_interface.h:111
void(* mainloop_leaving)(struct ipc_server *s, struct xrt_instance *xinst, void *data)
The service is leaving the mainloop, after this callback returns the IPC server will destroy all reso...
Definition ipc_server_interface.h:93
void(* init_failed)(xrt_result_t xret, void *data)
The IPC server failed to init.
Definition ipc_server_interface.h:74
void(* client_connected)(struct ipc_server *s, uint32_t client_id, void *data)
A new client has connected to the IPC server.
Definition ipc_server_interface.h:102
void(* mainloop_entering)(struct ipc_server *s, struct xrt_instance *xinst, void *data)
The service has completed init and is entering its mainloop.
Definition ipc_server_interface.h:83
Information passed into the IPC server main function, used for customization of the IPC server.
Definition ipc_server_interface.h:36
bool exit_on_disconnect
Flag whether runtime should exit on app disconnect.
Definition ipc_server_interface.h:41
bool no_stdin
Disable listening on stdin for server stop.
Definition ipc_server_interface.h:44
const char * pid_filename
Pidfile name in the runtime dir, used to refuse a second instance.
Definition ipc_server_interface.h:59
struct u_debug_gui_create_info udgci
Information passed onto the debug gui.
Definition ipc_server_interface.h:38
const char * socket_filename
Socket filename (named pipe name on Windows) in the runtime dir.
Definition ipc_server_interface.h:50
Main IPC object for the server.
Definition ipc_server.h:398
int ipc_server_stop(struct ipc_server *s)
Asks the server to shut down, this call is asynchronous and will return immediately.
Definition ipc_server_process.c:1220
Argument to the function u_debug_gui_create.
Definition u_debug_gui.h:49
This interface acts as a root object for Monado.
Definition xrt_instance.h:124
SDL2 Debug UI implementation.
Auto detect OS and certain features.
Internal result type for XRT.