The open source OpenXR runtime
1// Copyright 2021-2024, Collabora, Ltd.
2// SPDX-License-Identifier: BSL-1.0
3/*!
4 * @file
5 * @brief An implementation of a callback collection for the Android lifecycle.
6 * @author Rylie Pavlik <rylie.pavlik@collabora.com>
7 * @ingroup aux_android
8 */
9
10#pragma once
11
12#include <xrt/xrt_config_os.h>
13#include <xrt/xrt_android.h>
14
15#ifdef __cplusplus
16extern "C" {
17#endif
18
19struct xrt_instance_android;
20
21/*!
22 * @class android_lifecycle_callbacks
23 * @brief An object handling a collection of callbacks for the Android lifecycle.
24 */
25struct android_lifecycle_callbacks;
26
27/*!
28 * Create an @ref android_lifecycle_callbacks object.
29 *
30 * @param xinst_android The instance that will be passed to all callbacks.
31 *
32 * @public @memberof android_lifecycle_callbacks
33 */
34struct android_lifecycle_callbacks *
35android_lifecycle_callbacks_create(struct xrt_instance_android *xinst_android);
36
37/*!
38 * Destroy an @ref android_lifecycle_callbacks object.
39 * @public @memberof android_lifecycle_callbacks
40 */
41void
42android_lifecycle_callbacks_destroy(struct android_lifecycle_callbacks **ptr_callbacks);
43
44/*!
45 * Register a lifecycle event callback.
46 *
47 * @param alc Pointer to self
48 * @param callback Function pointer for callback
49 * @param event_mask bitwise-OR of one or more values from @ref xrt_android_lifecycle_event
50 * @param userdata An opaque pointer for use by the callback. Whatever you pass here will be passed to the
51 * callback when invoked.
52 *
53 * @return 0 on success, <0 on error.
54 * @public @memberof android_lifecycle_callbacks
55 */
56int
57android_lifecycle_callbacks_register_callback(struct android_lifecycle_callbacks *alc,
58 xrt_android_lifecycle_event_handler_t callback,
59 enum xrt_android_lifecycle_event event_mask,
60 void *userdata);
61
62/*!
63 * Remove a lifecycle event callback that matches the supplied parameters.
64 *
65 * @param alc Pointer to self
66 * @param callback Function pointer for callback
67 * @param event_mask bitwise-OR of one or more values from @ref xrt_android_lifecycle_event
68 * @param userdata An opaque pointer for use by the callback, must match the one originally supplied
69 *
70 * @return number of callbacks removed (typically 1) on success, <0 on error.
71 * @public @memberof android_lifecycle_callbacks
72 */
73int
74android_lifecycle_callbacks_remove_callback(struct android_lifecycle_callbacks *alc,
75 xrt_android_lifecycle_event_handler_t callback,
76 enum xrt_android_lifecycle_event event_mask,
77 void *userdata);
78
79#ifdef __cplusplus
80} // extern "C"
81#endif