/* * GENERATED from `src/ffi.rs` by `tests/header.rs` (cbindgen) — do not edit by * hand. Run `pnpm gen:ffi`; `cargo test -p * cotton-ffi` fails the build when this file and the source drift. * * The ABI is six functions and stays six for the life of the app: every * capability is a method NAME inside `cotton_call`, so adding one never touches * this file, the module map or the build. */#ifndef COTTON_FFI_H#define COTTON_FFI_H/** The open core. Opaque: a C caller holds the pointer and nothing else. */typedefstructCottonHandleCottonHandle;#ifdef __cplusplusextern"C" {#endif// __cplusplus/** * Open the core: prepare the data directory, build the runtime, hand back the * handle. * * Answers `NULL` and writes a JSON object into `out_error` * (`{ "code", "title", "message" }`, owned by the caller, freed with * `cotton_string_free`) when it cannot. * * # Safety * `config_json` must be a NUL-terminated UTF-8 string. `out_error`, when not * null, must point at a writable `char *`. */CottonHandle *cotton_open(constchar *config_json, char **out_error);/** * Close the core. Idempotent from the caller's side in the only way that * matters: a null pointer is ignored. * * **It ALWAYS comes back.** `CottonHandle::close` stops the server and lets go * of the replica first and then gives the runtime's blocking pool a deadline, * because this call blocks the thread Swift made it on and that thread was a * cooperative-pool one the night a hung close parked a whole CI runner * (Cotton note "Repo landmines — why the build's rules exist"). A step that will not finish is left * to the operating system with a line in the log; it never becomes the * caller's problem. * * # Safety * `handle` must be a pointer `cotton_open` returned and not already closed. */void cotton_close(CottonHandle *handle);/** * Ask the core something. Always answers one JSON object, owned by the caller: * * ```json * { "ok": true, "data": … } * { "ok": false, "error": { "code", "message", "details" } } * ``` * * # Safety * `handle` must be a live pointer from `cotton_open`; `method` and * `request_json` must be NUL-terminated UTF-8 or null. */char *cotton_call(CottonHandle *handle, constchar *method, constchar *request_json);/** * Register the ONE subscriber for the event stream, and replay whatever was * buffered before it arrived. * * `ctx` is handed back to the callback untouched; a null `on_event` clears the * subscription. The line the callback receives is borrowed for the duration of * the call — copy it, do not free it. * * # Safety * `handle` must be a live pointer from `cotton_open`, and `ctx` must stay valid * until the subscription is cleared or the core is closed. */void cotton_subscribe(CottonHandle *handle, void *ctx, void (*on_event)(void*, constchar*));/** * The core's version — the crate's own, which is the app's core version — * with the commit it was built from as build metadata (`0.1.0+1a2b3c4d5`, * `.dirty` after it when crates/ held edits; `crate::build_commit`). * Owned by the caller. */char *cotton_version(void);/** * Free a string this ABI handed out. Ignores null. * * # Safety * `text` must be a pointer this library returned, freed exactly once. */void cotton_string_free(char *text);#ifdef __cplusplus} // extern "C"#endif// __cplusplus#endif/* COTTON_FFI_H */