The open source OpenXR runtime
1// Copyright 2020-2023, Collabora, Ltd.
2// Copyright 2024-2025, 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 */
35struct ipc_server_main_info
36{
37 //! Information passed onto the debug gui.
38 struct u_debug_gui_create_info udgci;
39
40 //! Flag whether runtime should exit on app disconnect.
41 bool exit_on_disconnect;
42
43 //! Disable listening on stdin for server stop.
44 bool no_stdin;
45};
46
47/*!
48 *
49 * @ingroup ipc_server
50 */
51struct ipc_server_callbacks
52{
53 /*!
54 * The IPC server failed to init.
55 *
56 * @param[in] xret The error code generated during init.
57 * @param[in] data User data given passed into the main function.
58 */
59 void (*init_failed)(xrt_result_t xret, void *data);
60
61 /*!
62 * The service has completed init and is entering its mainloop.
63 *
64 * @param[in] s The IPC server.
65 * @param[in] xinst Instance that was created by the IPC server.
66 * @param[in] data User data given passed into the main function.
67 */
68 void (*mainloop_entering)(struct ipc_server *s, struct xrt_instance *xinst, void *data);
69
70 /*!
71 * The service is leaving the mainloop, after this callback returns the
72 * IPC server will destroy all resources created.
73 *
74 * @param[in] s The IPC server.
75 * @param[in] xinst Instance that was created by the IPC server.
76 * @param[in] data User data given passed into the main function.
77 */
78 void (*mainloop_leaving)(struct ipc_server *s, struct xrt_instance *xinst, void *data);
79
80 /*!
81 * A new client has connected to the IPC server.
82 *
83 * param s The IPC server.
84 * param client_id The ID of the newly connected client.
85 * param data User data given passed into the main function.
86 */
87 void (*client_connected)(struct ipc_server *s, uint32_t client_id, void *data);
88
89 /*!
90 * A client has disconnected from the IPC server.
91 *
92 * param s The IPC server.
93 * param client_id The ID of the newly connected client.
94 * param data User data given passed into the main function.
95 */
96 void (*client_disconnected)(struct ipc_server *s, uint32_t client_id, void *data);
97};
98
99/*!
100 * Common main function for starting the IPC service.
101 *
102 * @ingroup ipc_server
103 */
104int
105ipc_server_main_common(const struct ipc_server_main_info *ismi, const struct ipc_server_callbacks *iscb, void *data);
106
107/*!
108 * Asks the server to shut down, this call is asynchronous and will return
109 * immediately. Use callbacks to be notified when the server stops.
110 *
111 * @memberof ipc_server
112 */
113int
114ipc_server_stop(struct ipc_server *s);
115
116#ifndef XRT_OS_ANDROID
117
118/*!
119 * Main entrypoint to the compositor process.
120 *
121 * @ingroup ipc_server
122 */
123int
124ipc_server_main(int argc, char **argv, const struct ipc_server_main_info *ismi);
125
126#endif
127
128
129#ifdef __cplusplus
130}
131#endif