doom_fish_utils/ffi_callbacks.rs
1//! Common `extern "C"` callback type aliases used across the doom-fish family.
2//!
3//! These callback signatures recur in many crates' Swift / Obj-C bridges.
4//! Centralising them here eliminates duplicate definitions and makes
5//! cross-crate FFI signatures interchangeable.
6
7use core::ffi::{c_char, c_void};
8
9/// Callback that delivers a JSON-encoded payload as a heap-owned C string.
10///
11/// The receiver is responsible for freeing `json` (typically by passing it back
12/// into a Swift bridge `free_*` helper or via the consuming wrapper's Drop impl).
13pub type JsonCallback = unsafe extern "C" fn(json: *mut c_char, user_data: *mut c_void);
14
15/// Callback that fires when a one-shot async operation completes.
16///
17/// `status` is the operation's exit code (0 = ok, non-zero = error code).
18/// `error` is an optional `NSError` JSON payload (may be null on success).
19pub type AsyncCallback =
20 unsafe extern "C" fn(status: i32, error: *mut c_char, user_data: *mut c_void);
21
22/// Fire-and-forget callback with no payload other than the `user_data` pointer.
23pub type SimpleCallback = unsafe extern "C" fn(user_data: *mut c_void);
24
25/// Drop notification — fires when the Swift side releases the bridged context.
26/// Use this to clean up Rust state (typically `Box::from_raw(user_data)`).
27pub type DropCallback = unsafe extern "C" fn(user_data: *mut c_void);
28
29/// Stream-style callback that fires for each event in an ongoing subscription.
30///
31/// `event_json` is a heap-owned JSON-encoded event payload (caller-owned).
32pub type StreamEventCallback =
33 unsafe extern "C" fn(event_json: *mut c_char, user_data: *mut c_void);
34
35/// Async callback variant used by avassetwriter / weatherkit / webkit bridges
36/// that deliver a (`status`, `result_json`, `error`, `user_data`) tuple.
37pub type AsyncCb = unsafe extern "C" fn(
38 status: i32,
39 result_json: *mut c_char,
40 error: *mut c_char,
41 user_data: *mut c_void,
42);