···1010 * @ingroup ipc_server
1111 */
12121313-#include "xrt/xrt_compiler.h"
1313+#pragma once
1414+1415#include "xrt/xrt_config_os.h"
1616+#include "xrt/xrt_results.h"
15171616-#ifndef XRT_OS_ANDROID
1718#include "util/u_debug_gui.h"
1818-#endif
191920202121#ifdef __cplusplus
···2323#endif
242425252626-#ifndef XRT_OS_ANDROID
2626+struct xrt_instance;
2727+struct ipc_server;
27282829/*!
2930 * Information passed into the IPC server main function, used for customization
···3839};
39404041/*!
4141- * Main entrypoint to the compositor process.
4242+ *
4343+ * @ingroup ipc_server
4444+ */
4545+struct ipc_server_callbacks
4646+{
4747+ /*!
4848+ * The IPC server failed to init.
4949+ *
5050+ * @param[in] xret The error code generated during init.
5151+ * @param[in] data User data given passed into the main function.
5252+ */
5353+ void (*init_failed)(xrt_result_t xret, void *data);
5454+5555+ /*!
5656+ * The service has completed init and is entering its mainloop.
5757+ *
5858+ * @param[in] s The IPC server.
5959+ * @param[in] xinst Instance that was created by the IPC server.
6060+ * @param[in] data User data given passed into the main function.
6161+ */
6262+ void (*mainloop_entering)(struct ipc_server *s, struct xrt_instance *xinst, void *data);
6363+6464+ /*!
6565+ * The service is leaving the mainloop, after this callback returns the
6666+ * IPC server will destroy all resources created.
6767+ *
6868+ * @param[in] s The IPC server.
6969+ * @param[in] xinst Instance that was created by the IPC server.
7070+ * @param[in] data User data given passed into the main function.
7171+ */
7272+ void (*mainloop_leaving)(struct ipc_server *s, struct xrt_instance *xinst, void *data);
7373+};
7474+7575+/*!
7676+ * Common main function for starting the IPC service.
4277 *
4378 * @ingroup ipc_server
4479 */
4580int
4646-ipc_server_main(int argc, char **argv, const struct ipc_server_main_info *ismi);
4747-4848-#endif
8181+ipc_server_main_common(const struct ipc_server_main_info *ismi, const struct ipc_server_callbacks *iscb, void *data);
498250835151-#ifdef XRT_OS_ANDROID
8484+#ifndef XRT_OS_ANDROID
52855386/*!
5454- * Main entrypoint to the server process.
5555- *
5656- * @param ps Pointer to populate with the server struct.
5757- * @param startup_complete_callback Function to call upon completing startup
5858- * and populating *ps, but before entering
5959- * the mainloop.
6060- * @param data user data to pass to your callback.
8787+ * Main entrypoint to the compositor process.
6188 *
6289 * @ingroup ipc_server
6390 */
6491int
6565-ipc_server_main_android(struct ipc_server **ps, void (*startup_complete_callback)(void *data), void *data);
9292+ipc_server_main(int argc, char **argv, const struct ipc_server_main_info *ismi);
66936794#endif
6895
+44-40
src/xrt/ipc/server/ipc_server_process.c
···978978 return XRT_SUCCESS;
979979}
980980981981-#ifndef XRT_OS_ANDROID
982981int
983983-ipc_server_main(int argc, char **argv, const struct ipc_server_main_info *ismi)
982982+ipc_server_main_common(const struct ipc_server_main_info *ismi,
983983+ const struct ipc_server_callbacks *callbacks,
984984+ void *data)
984985{
985986 xrt_result_t xret = XRT_SUCCESS;
986987 int ret = -1;
···10081009 xret = init_all(s, log_level);
10091010 U_LOG_CHK_ONLY_PRINT(log_level, xret, "init_all");
10101011 if (xret != XRT_SUCCESS) {
10111011-#ifdef XRT_OS_LINUX
10121012- // Print information how to debug issues.
10131013- print_linux_end_user_failed_information(log_level);
10141014-#endif
10151015-10121012+ // Propegate the failure.
10131013+ callbacks->init_failed(xret, data);
10161014 u_debug_gui_stop(&s->debug_gui);
10171015 free(s);
10181016 return -1;
···10211019 // Start the debug UI now (if enabled).
10221020 u_debug_gui_start(s->debug_gui, s->xinst, s->xsysd);
1023102110241024-#ifdef XRT_OS_LINUX
10251025- // Print a very clear service started message.
10261026- print_linux_end_user_started_information(log_level);
10271027-#endif
10221022+ // Tell the callbacks we are entering the main-loop.
10231023+ callbacks->mainloop_entering(s, s->xinst, data);
10241024+10281025 // Main loop.
10291026 ret = main_loop(s);
1030102710281028+ // Tell the callbacks we are leaving the main-loop.
10291029+ callbacks->mainloop_leaving(s, s->xinst, data);
10301030+10311031 // Stop the UI before tearing everything down.
10321032 u_debug_gui_stop(&s->debug_gui);
10331033···10441044 return ret;
10451045}
1046104610471047-#endif // !XRT_OS_ANDROID
1048104710491049-#ifdef XRT_OS_ANDROID
10501050-int
10511051-ipc_server_main_android(struct ipc_server **ps, void (*startup_complete_callback)(void *data), void *data)
10521052-{
10531053- xrt_result_t xret = XRT_SUCCESS;
10541054- int ret = -1;
10551055-10561056- // Get log level first.
10571057- enum u_logging_level log_level = debug_get_log_option_ipc_log();
10581058-10591059- struct ipc_server *s = U_TYPED_CALLOC(struct ipc_server);
10601060- U_LOG_D("Created IPC server!");
10611061-10621062- xret = init_all(s, log_level);
10631063- U_LOG_CHK_ONLY_PRINT(log_level, xret, "init_all");
10641064- if (xret != XRT_SUCCESS) {
10651065- free(s);
10661066- startup_complete_callback(data);
10671067- return -1;
10681068- }
10481048+#ifndef XRT_OS_ANDROID
1069104910701070- *ps = s;
10711071- startup_complete_callback(data);
10501050+static void
10511051+init_failed(xrt_result_t xret, void *data)
10521052+{
10531053+#ifdef XRT_OS_LINUX
10541054+ // Print information how to debug issues.
10551055+ print_linux_end_user_failed_information(debug_get_log_option_ipc_log());
10561056+#endif
10571057+}
1072105810731073- ret = main_loop(s);
10591059+static void
10601060+mainloop_entering(struct ipc_server *s, struct xrt_instance *xinst, void *data)
10611061+{
10621062+#ifdef XRT_OS_LINUX
10631063+ // Print a very clear service started message.
10641064+ print_linux_end_user_started_information(s->log_level);
10651065+#endif
10661066+}
1074106710751075- teardown_all(s);
10761076- free(s);
10681068+static void
10691069+mainloop_leaving(struct ipc_server *s, struct xrt_instance *xinst, void *data)
10701070+{
10711071+ // No-op
10721072+}
1077107310781078- U_LOG_I("Server exiting '%i'!", ret);
10741074+int
10751075+ipc_server_main(int argc, char **argv, const struct ipc_server_main_info *ismi)
10761076+{
10771077+ const struct ipc_server_callbacks callbacks = {
10781078+ .init_failed = init_failed,
10791079+ .mainloop_entering = mainloop_entering,
10801080+ .mainloop_leaving = mainloop_leaving,
10811081+ };
1079108210801080- return ret;
10831083+ return ipc_server_main_common(ismi, &callbacks, NULL);
10811084}
10821082-#endif // XRT_OS_ANDROID
10851085+10861086+#endif // !XRT_OS_ANDROID