ascii-chat
Binary v0.16.114-28-gf5913657f
Library lib/v0.3.2-3302-gf5913657f
Video chat in your terminal
Loading...
Searching...
No Matches
app_callbacks.h
Go to the documentation of this file.
1
8
9#ifndef APP_CALLBACKS_H
10#define APP_CALLBACKS_H
11
12#include <stdbool.h>
13#include <stddef.h>
14#include <stdint.h>
15
16#ifdef __cplusplus
17extern "C" {
18#endif
19
20typedef void (*app_debug_write_fn)(const char *text, void *context);
21
22typedef struct {
23 // Exit signals
24 bool (*should_exit)(void);
25 void (*signal_exit)(void);
26
27 // Platform timing / wait helpers
29 void (*platform_sleep_ms)(unsigned int ms);
30 void (*platform_pump_events)(void);
31
32 // Audio
33 void (*audio_stop_thread)(void);
34
42
48
53
54/* ============================================================================
55 * Convenience Macros for Safe Callback Invocation
56 * ============================================================================
57 */
58
63#define APP_CALLBACK_VOID(callback_name) \
64 do { \
65 const app_callbacks_t *__cb = app_callbacks_get(); \
66 if (__cb && __cb->callback_name) { \
67 __cb->callback_name(); \
68 } \
69 } while (0)
70
75#if defined(_MSC_VER)
76static inline bool app_callback_bool(bool (*callback)(void)) {
77 return callback ? callback() : false;
78}
79
80static inline uint64_t app_callback_uint64(uint64_t (*callback)(void)) {
81 return callback ? callback() : 0ULL;
82}
83
84#define APP_CALLBACK_BOOL(callback_name) \
85 app_callback_bool(app_callbacks_get() ? app_callbacks_get()->callback_name \
86 : NULL)
87
88#define APP_CALLBACK_UINT64(callback_name) \
89 app_callback_uint64(app_callbacks_get() ? app_callbacks_get()->callback_name \
90 : NULL)
91#else
92#define APP_CALLBACK_BOOL(callback_name) \
93 ({ \
94 const app_callbacks_t *__cb = app_callbacks_get(); \
95 (__cb && __cb->callback_name) ? __cb->callback_name() : false; \
96 })
97
102#define APP_CALLBACK_UINT64(callback_name) \
103 ({ \
104 const app_callbacks_t *__cb = app_callbacks_get(); \
105 (__cb && __cb->callback_name) ? __cb->callback_name() : 0ULL; \
106 })
107#endif
108
113#define APP_CALLBACK_VOID_UINT(callback_name, value) \
114 do { \
115 const app_callbacks_t *__cb = app_callbacks_get(); \
116 if (__cb && __cb->callback_name) { \
117 __cb->callback_name(value); \
118 } \
119 } while (0)
120
121#endif
122
123#ifdef __cplusplus
124}
125#endif
const app_callbacks_t * app_callbacks_get(void)
void app_callbacks_register(const app_callbacks_t *callbacks)
Callbacks and operations used by app callbacks. Register application callbacks.
void(* app_debug_write_fn)(const char *text, void *context)
unsigned long long uint64_t
void(* signal_exit)(void)
void(* audio_stop_thread)(void)
app_debug_write_fn write_memory_report
void(* platform_pump_events)(void)
app_debug_write_fn write_backtrace
void(* platform_sleep_ms)(unsigned int ms)
app_debug_write_fn write_sync_state
uint64_t(* platform_get_monotonic_time_us)(void)
bool(* should_exit)(void)