1 module fdb.fdb_c;
2 
3 import
4     fdb.fdb_c_options;
5 
6 immutable uint FDB_API_VERSION = 300;
7 
8 struct FDBCluster {}
9 alias ClusterHandle     = FDBCluster *;
10 
11 struct FDBDatabase {}
12 alias DatabaseHandle    = FDBDatabase *;
13 
14 struct FDBFuture {}
15 alias FutureHandle      = FDBFuture *;
16 
17 struct FDBTransaction {}
18 alias TransactionHandle = FDBTransaction *;
19 
20 alias fdb_error_t = int;
21 alias fdb_bool_t  = int;
22 
23 alias Key   = ubyte[];
24 alias Value = ubyte[];
25 
26 struct keyvalue
27 {
28     align (4):
29         void * key;
30         int    key_length;
31         void * value;
32         int    value_length;
33 }
34 alias FDBKeyValue = keyvalue;
35 
36 fdb_error_t     fdb_select_api_version(int runtime_version)
37 {
38     return fdb_select_api_version_impl(runtime_version, FDB_API_VERSION);
39 }
40 
41 ////////////////////// functions implemented in libfdb_c ///////////////////////
42 extern (C):
43 
44 alias FDBCallback = void function(
45     FDBFuture *                 future,
46     void *                      callback_parameter);
47 
48 char *          fdb_get_error(
49     fdb_error_t                 code);
50 
51 fdb_error_t     fdb_network_set_option(
52     const NetworkOption         option,
53     immutable char *            value,
54     int                         value_length);
55 
56 fdb_error_t     fdb_setup_network();
57 
58 fdb_error_t     fdb_run_network();
59 
60 fdb_error_t     fdb_stop_network();
61 
62 void            fdb_future_cancel(
63     const FDBFuture *           f);
64 
65 void            fdb_future_release_memory(
66     const FDBFuture *           f);
67 
68 void            fdb_future_destroy(
69     const FDBFuture *           f);
70 
71 fdb_error_t     fdb_future_block_until_ready(
72     const FDBFuture *           f);
73 
74 fdb_bool_t      fdb_future_is_ready(
75     const FDBFuture *           f);
76 
77 fdb_error_t     fdb_future_set_callback(
78     const FDBFuture *           f,
79     FDBCallback                 callback,
80     void *                      callback_parameter);
81 
82 fdb_error_t     fdb_future_get_error(
83     const FDBFuture *           f);
84 
85 fdb_error_t     fdb_future_get_version(
86     const FDBFuture *           f,
87     long *                      out_version);
88 
89 fdb_error_t     fdb_future_get_key(
90     const FDBFuture *           f,
91     ubyte **                    out_key,
92     int *                       out_key_length);
93 
94 fdb_error_t     fdb_future_get_cluster(
95     const FDBFuture *           f,
96     FDBCluster **               out_cluster);
97 
98 fdb_error_t     fdb_future_get_database(
99     const FDBFuture *           f,
100     FDBDatabase **              out_database);
101 
102 fdb_error_t     fdb_future_get_value(
103     const FDBFuture *           f,
104     fdb_bool_t *                out_present,
105     ubyte **                    out_value,
106     int *                       out_value_length);
107 
108 fdb_error_t     fdb_future_get_keyvalue_array(
109     const FDBFuture *           f,
110     keyvalue **                 out_kv,
111     int *                       out_count,
112     fdb_bool_t *                out_more);
113 
114 fdb_error_t     fdb_future_get_string_array(
115     const FDBFuture *           f,
116     char ***                    out_strings,
117     int *                       out_count);
118 
119 FDBFuture *     fdb_create_cluster(
120     immutable char *            cluster_file_path);
121 
122 void            fdb_cluster_destroy(
123     const FDBCluster *          c);
124 
125 fdb_error_t     fdb_cluster_set_option(
126     const FDBCluster *          c,
127     const ClusterOption         option,
128     immutable char *            value,
129     const int                   value_length);
130 
131 FDBFuture *     fdb_cluster_create_database(
132     const FDBCluster *          c,
133     immutable char *            db_name,
134     const int                   db_name_length);
135 
136 void            fdb_database_destroy(
137     const FDBDatabase *         d);
138 
139 fdb_error_t     fdb_database_set_option(
140     const FDBDatabase *         d,
141     const DatabaseOption        option,
142     immutable char *            value,
143     const int                   value_length);
144 
145 fdb_error_t     fdb_database_create_transaction(
146     const FDBDatabase *         d,
147     FDBTransaction **           out_transaction);
148 
149 void            fdb_transaction_destroy(
150     const FDBTransaction *      tr);
151 
152 void            fdb_transaction_cancel(
153     const FDBTransaction *      tr);
154 
155 fdb_error_t     fdb_transaction_set_option(
156     const FDBTransaction *      tr,
157     const TransactionOption     option,
158     immutable char  *           value,
159     const int                   value_length);
160 
161 void            fdb_transaction_set_read_version(
162     const FDBTransaction *      tr,
163     const long                  versionNumber);
164 
165 FDBFuture *     fdb_transaction_get_read_version(
166     const FDBTransaction *      tr);
167 
168 FDBFuture *     fdb_transaction_get(
169     const FDBTransaction *      tr,
170     const ubyte *               key_name,
171     const int                   key_name_length,
172     const fdb_bool_t            snapshot);
173 
174 FDBFuture *     fdb_transaction_get_key(
175     const FDBTransaction *      tr,
176     const ubyte *               key_name,
177     const int                   key_name_length,
178     const fdb_bool_t            or_equal,
179     const int                   offset,
180     const fdb_bool_t            snapshot);
181 
182 FDBFuture *     fdb_transaction_get_addresses_for_key(
183     const FDBTransaction *      tr,
184     const ubyte *               key_name,
185     const int                   key_name_length);
186 
187 FDBFuture *     fdb_transaction_get_range(
188     const FDBTransaction *      tr,
189     const ubyte *               begin_key_name,
190     const int                   begin_key_name_length,
191     const fdb_bool_t            begin_or_equal,
192     const int                   begin_offset,
193     const ubyte *               end_key_name,
194     const int                   end_key_name_length,
195     const fdb_bool_t            end_or_equal,
196     const int                   end_offset,
197     const int                   limit,
198     const int                   target_bytes,
199     const StreamingMode         mode,
200     const int                   iteration,
201     const fdb_bool_t            snapshot,
202     const fdb_bool_t            reverse);
203 
204 void            fdb_transaction_set(
205     const FDBTransaction *      tr,
206     const ubyte *               key_name,
207     const int                   key_name_length,
208     const ubyte *               value,
209     const int                   value_length);
210 
211 void            fdb_transaction_atomic_op(
212     const FDBTransaction *      tr,
213     const ubyte *               key_name,
214     const int                   key_name_length,
215     const ubyte *               param,
216     const int                   param_length,
217     const MutationType          operation_type);
218 
219 void            fdb_transaction_clear(
220     const FDBTransaction *      tr,
221     const ubyte *               key_name,
222     const int                   key_name_length);
223 
224 void            fdb_transaction_clear_range(
225     const FDBTransaction *      tr,
226     const ubyte *               begin_key_name,
227     const int                   begin_key_name_length,
228     const ubyte *               end_key_name,
229     const int                   end_key_name_length);
230 
231 FDBFuture *     fdb_transaction_watch(
232     const FDBTransaction *      tr,
233     const ubyte *               key_name,
234     const int                   key_name_length);
235 
236 FDBFuture *     fdb_transaction_commit(
237     const FDBTransaction *      tr);
238 
239 fdb_error_t     fdb_transaction_get_committed_version(
240     const FDBTransaction *      tr,
241     const long *                out_version);
242 
243 FDBFuture *     fdb_transaction_on_error(
244     const FDBTransaction *      tr,
245     const fdb_error_t           error);
246 
247 void            fdb_transaction_reset(
248     const FDBTransaction *      tr);
249 
250 fdb_error_t     fdb_transaction_add_conflict_range(
251     const FDBTransaction *      tr,
252     const ubyte *               begin_key_name,
253     const int                   begin_key_name_length,
254     const ubyte *               end_key_name,
255     const int                   end_key_name_length,
256     const ConflictRangeType     type);
257 
258 fdb_error_t     fdb_select_api_version_impl(
259     int                         runtime_version,
260     int                         header_version);
261 
262 int             fdb_get_max_api_version();