···11+// Copyright 2021-2024, Collabora, Ltd.
22+// SPDX-License-Identifier: BSL-1.0
33+/*!
44+ * @file
55+ * @brief An implementation of a callback collection for the Android lifecycle.
66+ * @author Rylie Pavlik <rylie.pavlik@collabora.com>
77+ * @ingroup aux_android
88+ */
99+1010+#pragma once
1111+1212+#include <xrt/xrt_config_os.h>
1313+#include <xrt/xrt_android.h>
1414+1515+#ifdef __cplusplus
1616+extern "C" {
1717+#endif
1818+1919+struct xrt_instance_android;
2020+2121+/*!
2222+ * @class android_lifecycle_callbacks
2323+ * @brief An object handling a collection of callbacks for the Android lifecycle.
2424+ */
2525+struct android_lifecycle_callbacks;
2626+2727+/*!
2828+ * Create an @ref android_lifecycle_callbacks object.
2929+ *
3030+ * @param xinst_android The instance that will be passed to all callbacks.
3131+ *
3232+ * @public @memberof android_lifecycle_callbacks
3333+ */
3434+struct android_lifecycle_callbacks *
3535+android_lifecycle_callbacks_create(struct xrt_instance_android *xinst_android);
3636+3737+/*!
3838+ * Destroy an @ref android_lifecycle_callbacks object.
3939+ * @public @memberof android_lifecycle_callbacks
4040+ */
4141+void
4242+android_lifecycle_callbacks_destroy(struct android_lifecycle_callbacks **ptr_callbacks);
4343+4444+/*!
4545+ * Register a lifecycle event callback.
4646+ *
4747+ * @param alc Pointer to self
4848+ * @param callback Function pointer for callback
4949+ * @param event_mask bitwise-OR of one or more values from @ref xrt_android_lifecycle_event
5050+ * @param userdata An opaque pointer for use by the callback. Whatever you pass here will be passed to the
5151+ * callback when invoked.
5252+ *
5353+ * @return 0 on success, <0 on error.
5454+ * @public @memberof android_lifecycle_callbacks
5555+ */
5656+int
5757+android_lifecycle_callbacks_register_callback(struct android_lifecycle_callbacks *alc,
5858+ xrt_android_lifecycle_event_handler_t callback,
5959+ enum xrt_android_lifecycle_event event_mask,
6060+ void *userdata);
6161+6262+/*!
6363+ * Remove a lifecycle event callback that matches the supplied parameters.
6464+ *
6565+ * @param alc Pointer to self
6666+ * @param callback Function pointer for callback
6767+ * @param event_mask bitwise-OR of one or more values from @ref xrt_android_lifecycle_event
6868+ * @param userdata An opaque pointer for use by the callback, must match the one originally supplied
6969+ *
7070+ * @return number of callbacks removed (typically 1) on success, <0 on error.
7171+ * @public @memberof android_lifecycle_callbacks
7272+ */
7373+int
7474+android_lifecycle_callbacks_remove_callback(struct android_lifecycle_callbacks *alc,
7575+ xrt_android_lifecycle_event_handler_t callback,
7676+ enum xrt_android_lifecycle_event event_mask,
7777+ void *userdata);
7878+7979+8080+/*!
8181+ * Invoke all lifecycle event callbacks that match a given event.
8282+ *
8383+ * @param alc Pointer to self
8484+ * @param event The event from @ref xrt_android_lifecycle_event
8585+ *
8686+ * @return the number of invoked callbacks on success, <0 on error.
8787+ * @public @memberof android_lifecycle_callbacks
8888+ */
8989+int
9090+android_lifecycle_callbacks_invoke(struct android_lifecycle_callbacks *alc, enum xrt_android_lifecycle_event event);
9191+9292+9393+#ifdef __cplusplus
9494+} // extern "C"
9595+#endif