1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
//! `CheckpointStore` factory functions (redb + valkey). Phase R4 Agent C.
//!
//! Constructs a [`crate::persist::BlazenCheckpointStore`] handle from one of
//! the upstream persistence backends. These are the only entry points
//! foreign callers have for minting a store — every method on
//! [`crate::persist::BlazenCheckpointStore`] consumes a pointer produced
//! here.
//!
//! # Ownership conventions
//!
//! - All input strings are BORROWED — caller keeps them alive only for the
//! duration of the cabi call. The factories internally copy whatever they
//! need to retain.
//! - On success, `*out_store` receives a caller-owned
//! `*mut BlazenCheckpointStore`. Free with
//! [`crate::persist::blazen_checkpoint_store_free`].
//! - On failure, `*out_err` receives a caller-owned `*mut BlazenError`. Free
//! with [`crate::error::blazen_error_free`].
use c_char;
use BlazenError as InnerError;
use crateBlazenError;
use crateBlazenCheckpointStore;
use cratecstr_to_str;
// ---------------------------------------------------------------------------
// Shared error-out helpers
// ---------------------------------------------------------------------------
/// Writes `e` to the out-param if non-null and returns `-1`.
///
/// # Safety
///
/// `out_err` must be null OR a valid destination for a single
/// `*mut BlazenError` write.
unsafe
/// Writes a synthesised `Internal` error to the out-param and returns `-1`.
/// Used for null-pointer / UTF-8 input failures where there isn't an
/// originating `InnerError`.
///
/// # Safety
///
/// Same contract as [`write_error`].
unsafe
// ---------------------------------------------------------------------------
// redb
// ---------------------------------------------------------------------------
/// Build an embedded redb-backed checkpoint store rooted at `path`.
///
/// The database file is created if it does not exist. Re-opening an
/// existing file is safe and preserves prior checkpoints.
///
/// Returns `0` on success and writes a fresh
/// `*mut BlazenCheckpointStore` into `*out_store`. Returns `-1` on backend
/// failure (writing the inner error to `*out_err`), or `-2` when `path` is
/// null or not valid UTF-8 (also written to `*out_err` as an `Internal`
/// variant).
///
/// # Safety
///
/// - `path` must be null OR a valid NUL-terminated UTF-8 buffer that
/// remains live for the duration of the call.
/// - `out_store` must be null OR a writable pointer to a
/// `*mut BlazenCheckpointStore` slot. When null the freshly built store
/// is dropped immediately to avoid a leak (the call still reports the
/// success status).
/// - `out_err` must be null OR a writable pointer to a `*mut BlazenError`
/// slot.
pub unsafe extern "C"
// ---------------------------------------------------------------------------
// valkey
// ---------------------------------------------------------------------------
/// Build a Redis/ValKey-backed checkpoint store connected to `url`.
///
/// `url` is in the form `redis://host:port/db` (or `rediss://` for TLS).
/// When `ttl_seconds >= 0` every saved checkpoint will auto-expire after
/// that many seconds; pass `-1` for no TTL.
///
/// The initial connection is established eagerly on the shared Tokio
/// runtime (the underlying constructor is async); subsequent reconnections
/// are handled automatically by the connection manager.
///
/// Returns `0` on success and writes a fresh
/// `*mut BlazenCheckpointStore` into `*out_store`. Returns `-1` on backend
/// failure (writing the inner error to `*out_err`), or `-2` when `url` is
/// null or not valid UTF-8.
///
/// # Safety
///
/// - `url` must be null OR a valid NUL-terminated UTF-8 buffer that
/// remains live for the duration of the call.
/// - `out_store` must be null OR a writable pointer to a
/// `*mut BlazenCheckpointStore` slot. When null the freshly built store
/// is dropped immediately to avoid a leak.
/// - `out_err` must be null OR a writable pointer to a `*mut BlazenError`
/// slot.
pub unsafe extern "C"