JULEA
jbackend.h
Go to the documentation of this file.
1 /*
2  * JULEA - Flexible storage framework
3  * Copyright (C) 2017-2024 Michael Kuhn
4  * Copyright (C) 2018-2019 Michael Straßberger
5  * Copyright (C) 2019 Benjamin Warnke
6  *
7  * This program is free software: you can redistribute it and/or modify
8  * it under the terms of the GNU Lesser General Public License as published by
9  * the Free Software Foundation, either version 3 of the License, or
10  * (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU Lesser General Public License for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public License
18  * along with this program. If not, see <http://www.gnu.org/licenses/>.
19  */
20 
25 #ifndef JULEA_BACKEND_H
26 #define JULEA_BACKEND_H
27 
28 #if !defined(JULEA_H) && !defined(JULEA_COMPILATION)
29 #error "Only <julea.h> can be included directly."
30 #endif
31 
32 #include <glib.h>
33 #include <gmodule.h>
34 
35 #include <bson.h>
36 
37 #include <core/jsemantics.h>
38 
39 G_BEGIN_DECLS
40 
41 #define J_BACKEND_BSON_ERROR j_backend_bson_error_quark()
42 #define J_BACKEND_DB_ERROR j_backend_db_error_quark()
43 #define J_BACKEND_SQL_ERROR j_backend_sql_error_quark()
44 
47 {
71 };
72 
74 
76 {
89 };
90 
91 typedef enum JBackendDBError JBackendDBError;
92 
94 {
103 };
104 
106 
108 {
112 };
113 
114 typedef enum JBackendType JBackendType;
115 
117 {
120 };
121 
123 
125 {
127 };
128 
129 typedef enum JBackendFlags JBackendFlags;
130 
131 struct JBackend
132 {
136 
137  gpointer data;
138 
139  union
140  {
141  struct
142  {
143  gboolean (*backend_init)(gchar const*, gpointer*);
144  void (*backend_fini)(gpointer);
145 
146  gboolean (*backend_create)(gpointer, gchar const*, gchar const*, gpointer*);
147  gboolean (*backend_open)(gpointer, gchar const*, gchar const*, gpointer*);
148 
149  gboolean (*backend_delete)(gpointer, gpointer);
150  gboolean (*backend_close)(gpointer, gpointer);
151 
152  gboolean (*backend_status)(gpointer, gpointer, gint64*, guint64*);
153  gboolean (*backend_sync)(gpointer, gpointer);
154 
155  gboolean (*backend_read)(gpointer, gpointer, gpointer, guint64, guint64, guint64*);
156  gboolean (*backend_write)(gpointer, gpointer, gconstpointer, guint64, guint64, guint64*);
157 
158  gboolean (*backend_get_all)(gpointer, gchar const*, gpointer*);
159  gboolean (*backend_get_by_prefix)(gpointer, gchar const*, gchar const*, gpointer*);
160  gboolean (*backend_iterate)(gpointer, gpointer, gchar const**);
162 
163  struct
164  {
165  gboolean (*backend_init)(gchar const*, gpointer*);
166  void (*backend_fini)(gpointer);
167 
168  gboolean (*backend_batch_start)(gpointer, gchar const*, JSemantics*, gpointer*);
169  gboolean (*backend_batch_execute)(gpointer, gpointer);
170 
171  gboolean (*backend_put)(gpointer, gpointer, gchar const*, gconstpointer, guint32);
172  gboolean (*backend_delete)(gpointer, gpointer, gchar const*);
173  gboolean (*backend_get)(gpointer, gpointer, gchar const*, gpointer*, guint32*);
174 
175  gboolean (*backend_get_all)(gpointer, gchar const*, gpointer*);
176  gboolean (*backend_get_by_prefix)(gpointer, gchar const*, gchar const*, gpointer*);
177  gboolean (*backend_iterate)(gpointer, gpointer, gchar const**, gconstpointer*, guint32*);
178  } kv;
179 
180  struct
181  {
182  gboolean (*backend_init)(gchar const*, gpointer*);
183  void (*backend_fini)(gpointer);
184 
185  gboolean (*backend_batch_start)(gpointer, gchar const*, JSemantics*, gpointer*, GError**);
186  gboolean (*backend_batch_execute)(gpointer, gpointer, GError**);
187 
207  gboolean (*backend_schema_create)(gpointer, gpointer, gchar const*, bson_t const*, GError**);
208 
228  gboolean (*backend_schema_get)(gpointer, gpointer, gchar const*, bson_t*, GError**);
229 
238  gboolean (*backend_schema_delete)(gpointer, gpointer, gchar const*, GError**);
239 
260  gboolean (*backend_insert)(gpointer, gpointer, gchar const*, bson_t const*, bson_t*, GError**);
261 
298  gboolean (*backend_update)(gpointer, gpointer, gchar const*, bson_t const*, bson_t const*, GError**);
299 
329  gboolean (*backend_delete)(gpointer, gpointer, gchar const*, bson_t const*, GError**);
330 
361  gboolean (*backend_query)(gpointer, gpointer, gchar const*, bson_t const*, gpointer*, GError**);
362 
383  gboolean (*backend_iterate)(gpointer, gpointer, bson_t*, GError**);
384  } db;
385  };
386 };
387 
388 typedef struct JBackend JBackend;
389 
390 GQuark j_backend_bson_error_quark(void);
391 GQuark j_backend_db_error_quark(void);
392 GQuark j_backend_sql_error_quark(void);
393 
395 
396 gboolean j_backend_load(gchar const*, JBackendComponent, JBackendType, GModule**, JBackend**);
397 gboolean j_backend_unload(JBackend*, GModule*);
398 
399 gboolean j_backend_object_init(JBackend*, gchar const*);
401 
402 gboolean j_backend_object_create(JBackend*, gchar const*, gchar const*, gpointer*);
403 gboolean j_backend_object_open(JBackend*, gchar const*, gchar const*, gpointer*);
404 
405 gboolean j_backend_object_delete(JBackend*, gpointer);
406 gboolean j_backend_object_close(JBackend*, gpointer);
407 
408 gboolean j_backend_object_status(JBackend*, gpointer, gint64*, guint64*);
409 gboolean j_backend_object_sync(JBackend*, gpointer);
410 
411 gboolean j_backend_object_read(JBackend*, gpointer, gpointer, guint64, guint64, guint64*);
412 gboolean j_backend_object_write(JBackend*, gpointer, gconstpointer, guint64, guint64, guint64*);
413 
414 gboolean j_backend_object_get_all(JBackend*, gchar const*, gpointer*);
415 gboolean j_backend_object_get_by_prefix(JBackend*, gchar const*, gchar const*, gpointer*);
416 gboolean j_backend_object_iterate(JBackend*, gpointer, gchar const**);
417 
418 gboolean j_backend_kv_init(JBackend*, gchar const*);
420 
421 gboolean j_backend_kv_batch_start(JBackend*, gchar const*, JSemantics*, gpointer*);
422 gboolean j_backend_kv_batch_execute(JBackend*, gpointer);
423 
424 gboolean j_backend_kv_put(JBackend*, gpointer, gchar const*, gconstpointer, guint32);
425 gboolean j_backend_kv_delete(JBackend*, gpointer, gchar const*);
426 gboolean j_backend_kv_get(JBackend*, gpointer, gchar const*, gpointer*, guint32*);
427 
428 gboolean j_backend_kv_get_all(JBackend*, gchar const*, gpointer*);
429 gboolean j_backend_kv_get_by_prefix(JBackend*, gchar const*, gchar const*, gpointer*);
430 gboolean j_backend_kv_iterate(JBackend*, gpointer, gchar const**, gconstpointer*, guint32*);
431 
432 gboolean j_backend_db_init(JBackend*, gchar const*);
434 
435 gboolean j_backend_db_batch_start(JBackend*, gchar const*, JSemantics*, gpointer*, GError**);
436 gboolean j_backend_db_batch_execute(JBackend*, gpointer, GError**);
437 
438 gboolean j_backend_db_schema_create(JBackend*, gpointer, gchar const*, bson_t const*, GError**);
439 gboolean j_backend_db_schema_get(JBackend*, gpointer, gchar const*, bson_t*, GError**);
440 gboolean j_backend_db_schema_delete(JBackend*, gpointer, gchar const*, GError**);
441 
442 gboolean j_backend_db_insert(JBackend*, gpointer, gchar const*, bson_t const*, bson_t*, GError**);
443 gboolean j_backend_db_update(JBackend*, gpointer, gchar const*, bson_t const*, bson_t const*, GError**);
444 gboolean j_backend_db_delete(JBackend*, gpointer, gchar const*, bson_t const*, GError**);
445 
446 gboolean j_backend_db_query(JBackend*, gpointer, gchar const*, bson_t const*, gpointer*, GError**);
447 gboolean j_backend_db_iterate(JBackend*, gpointer, bson_t*, GError**);
448 
449 G_END_DECLS
450 
451 #endif
gboolean j_backend_db_query(JBackend *, gpointer, gchar const *, bson_t const *, gpointer *, GError **)
Definition: jbackend.c:935
gboolean j_backend_db_schema_get(JBackend *, gpointer, gchar const *, bson_t *, GError **)
Definition: jbackend.c:826
gboolean j_backend_kv_get_by_prefix(JBackend *, gchar const *, gchar const *, gpointer *)
Definition: jbackend.c:687
gboolean j_backend_db_schema_create(JBackend *, gpointer, gchar const *, bson_t const *, GError **)
Definition: jbackend.c:804
GQuark j_backend_sql_error_quark(void)
Definition: jbackend.c:57
gboolean j_backend_object_iterate(JBackend *, gpointer, gchar const **)
Definition: jbackend.c:410
gboolean j_backend_object_open(JBackend *, gchar const *, gchar const *, gpointer *)
Definition: jbackend.c:330
gboolean j_backend_object_status(JBackend *, gpointer, gint64 *, guint64 *)
Definition: jbackend.c:449
void j_backend_kv_fini(JBackend *)
Definition: jbackend.c:550
gboolean j_backend_db_delete(JBackend *, gpointer, gchar const *, bson_t const *, GError **)
Definition: jbackend.c:914
gboolean j_backend_db_batch_execute(JBackend *, gpointer, GError **)
Definition: jbackend.c:784
gboolean j_backend_db_insert(JBackend *, gpointer, gchar const *, bson_t const *, bson_t *, GError **)
Definition: jbackend.c:868
gboolean j_backend_object_create(JBackend *, gchar const *, gchar const *, gpointer *)
Definition: jbackend.c:309
gboolean j_backend_object_init(JBackend *, gchar const *)
Definition: jbackend.c:276
gboolean j_backend_object_sync(JBackend *, gpointer)
Definition: jbackend.c:470
gboolean j_backend_kv_iterate(JBackend *, gpointer, gchar const **, gconstpointer *, guint32 *)
Definition: jbackend.c:707
gboolean j_backend_kv_init(JBackend *, gchar const *)
Definition: jbackend.c:531
gboolean j_backend_kv_batch_start(JBackend *, gchar const *, JSemantics *, gpointer *)
Definition: jbackend.c:564
gboolean j_backend_db_batch_start(JBackend *, gchar const *, JSemantics *, gpointer *, GError **)
Definition: jbackend.c:762
gboolean j_backend_db_schema_delete(JBackend *, gpointer, gchar const *, GError **)
Definition: jbackend.c:847
gboolean j_backend_load(gchar const *, JBackendComponent, JBackendType, GModule **, JBackend **)
Definition: jbackend.c:65
gboolean j_backend_kv_delete(JBackend *, gpointer, gchar const *)
Definition: jbackend.c:625
void j_backend_db_fini(JBackend *)
Definition: jbackend.c:748
gboolean j_backend_object_write(JBackend *, gpointer, gconstpointer, guint64, guint64, guint64 *)
Definition: jbackend.c:510
gboolean j_backend_kv_batch_execute(JBackend *, gpointer)
Definition: jbackend.c:585
gboolean j_backend_object_get_all(JBackend *, gchar const *, gpointer *)
Definition: jbackend.c:370
gboolean j_backend_kv_get_all(JBackend *, gchar const *, gpointer *)
Definition: jbackend.c:667
gboolean j_backend_db_update(JBackend *, gpointer, gchar const *, bson_t const *, bson_t const *, GError **)
Definition: jbackend.c:891
gboolean j_backend_db_iterate(JBackend *, gpointer, bson_t *, GError **)
Definition: jbackend.c:957
gboolean j_backend_kv_put(JBackend *, gpointer, gchar const *, gconstpointer, guint32)
Definition: jbackend.c:604
gboolean j_backend_object_delete(JBackend *, gpointer)
Definition: jbackend.c:351
GQuark j_backend_bson_error_quark(void)
Definition: jbackend.c:41
gboolean j_backend_unload(JBackend *, GModule *)
Definition: jbackend.c:260
gboolean j_backend_object_get_by_prefix(JBackend *, gchar const *, gchar const *, gpointer *)
Definition: jbackend.c:390
gboolean j_backend_object_read(JBackend *, gpointer, gpointer, guint64, guint64, guint64 *)
Definition: jbackend.c:489
GQuark j_backend_db_error_quark(void)
Definition: jbackend.c:49
void j_backend_object_fini(JBackend *)
Definition: jbackend.c:295
gboolean j_backend_kv_get(JBackend *, gpointer, gchar const *, gpointer *, guint32 *)
Definition: jbackend.c:645
gboolean j_backend_object_close(JBackend *, gpointer)
Definition: jbackend.c:430
gboolean j_backend_db_init(JBackend *, gchar const *)
Definition: jbackend.c:729
JBackendSQLError
Definition: jbackend.h:94
@ J_BACKEND_SQL_ERROR_STEP
Definition: jbackend.h:102
@ J_BACKEND_SQL_ERROR_CONSTRAINT
Definition: jbackend.h:97
@ J_BACKEND_SQL_ERROR_FINALIZE
Definition: jbackend.h:98
@ J_BACKEND_SQL_ERROR_PREPARE
Definition: jbackend.h:100
@ J_BACKEND_SQL_ERROR_FAILED
Definition: jbackend.h:95
@ J_BACKEND_SQL_ERROR_INVALID_TYPE
Definition: jbackend.h:99
@ J_BACKEND_SQL_ERROR_RESET
Definition: jbackend.h:101
@ J_BACKEND_SQL_ERROR_BIND
Definition: jbackend.h:96
JBackendDBError
Definition: jbackend.h:76
@ J_BACKEND_DB_ERROR_THREADING_ERROR
Definition: jbackend.h:87
@ J_BACKEND_DB_ERROR_FAILED
Definition: jbackend.h:77
@ J_BACKEND_DB_ERROR_OPERATOR_INVALID
Definition: jbackend.h:83
@ J_BACKEND_DB_ERROR_ITERATOR_INVALID
Definition: jbackend.h:80
@ J_BACKEND_DB_ERROR_ITERATOR_NO_MORE_ELEMENTS
Definition: jbackend.h:81
@ J_BACKEND_DB_ERROR_NO_VARIABLE_SET
Definition: jbackend.h:82
@ J_BACKEND_DB_ERROR_COMPARATOR_INVALID
Definition: jbackend.h:78
@ J_BACKEND_DB_ERROR_SCHEMA_EMPTY
Definition: jbackend.h:84
@ J_BACKEND_DB_ERROR_SELECTOR_EMPTY
Definition: jbackend.h:86
@ J_BACKEND_DB_ERROR_DB_TYPE_INVALID
Definition: jbackend.h:79
@ J_BACKEND_DB_ERROR_SCHEMA_NOT_FOUND
Definition: jbackend.h:85
@ J_BACKEND_DB_ERROR_VARIABLE_NOT_FOUND
Definition: jbackend.h:88
JBackendComponent
Definition: jbackend.h:117
@ J_BACKEND_COMPONENT_CLIENT
Definition: jbackend.h:118
@ J_BACKEND_COMPONENT_SERVER
Definition: jbackend.h:119
JBackend * backend_info(void)
JBackendType
Definition: jbackend.h:108
@ J_BACKEND_TYPE_OBJECT
Definition: jbackend.h:109
@ J_BACKEND_TYPE_DB
Definition: jbackend.h:111
@ J_BACKEND_TYPE_KV
Definition: jbackend.h:110
JBackendBSONError
Definition: jbackend.h:47
@ J_BACKEND_BSON_ERROR_BSON_COUNT_NULL
Definition: jbackend.h:53
@ J_BACKEND_BSON_ERROR_ITER_KEY_FOUND
Definition: jbackend.h:65
@ J_BACKEND_BSON_ERROR_ITER_KEY_NULL
Definition: jbackend.h:67
@ J_BACKEND_BSON_ERROR_BSON_BUF_NULL
Definition: jbackend.h:52
@ J_BACKEND_BSON_ERROR_FAILED
Definition: jbackend.h:48
@ J_BACKEND_BSON_ERROR_BSON_JSON_NULL
Definition: jbackend.h:56
@ J_BACKEND_BSON_ERROR_BSON_NULL
Definition: jbackend.h:59
@ J_BACKEND_BSON_ERROR_ITER_NULL
Definition: jbackend.h:68
@ J_BACKEND_BSON_ERROR_ITER_TYPE_NULL
Definition: jbackend.h:70
@ J_BACKEND_BSON_ERROR_BSON_NAME_NULL
Definition: jbackend.h:57
@ J_BACKEND_BSON_ERROR_ITER_HAS_NEXT_NULL
Definition: jbackend.h:62
@ J_BACKEND_BSON_ERROR_BSON_APPEND_FAILED
Definition: jbackend.h:51
@ J_BACKEND_BSON_ERROR_BSON_HAS_FIELD_NULL
Definition: jbackend.h:54
@ J_BACKEND_BSON_ERROR_BSON_NOT_ENOUGH_KEYS
Definition: jbackend.h:58
@ J_BACKEND_BSON_ERROR_BSON_VALUE_NULL
Definition: jbackend.h:60
@ J_BACKEND_BSON_ERROR_BSON_APPEND_DOCUMENT_FAILED
Definition: jbackend.h:50
@ J_BACKEND_BSON_ERROR_BSON_INIT_FROM_JSON_FAILED
Definition: jbackend.h:55
@ J_BACKEND_BSON_ERROR_ITER_INIT
Definition: jbackend.h:63
@ J_BACKEND_BSON_ERROR_ITER_INVALID_TYPE
Definition: jbackend.h:64
@ J_BACKEND_BSON_ERROR_ITER_RECOURSE
Definition: jbackend.h:69
@ J_BACKEND_BSON_ERROR_ITER_KEY_NOT_FOUND
Definition: jbackend.h:66
@ J_BACKEND_BSON_ERROR_ITER_EQUALS_NULL
Definition: jbackend.h:61
@ J_BACKEND_BSON_ERROR_BSON_APPEND_ARRAY_FAILED
Definition: jbackend.h:49
JBackendFlags
Definition: jbackend.h:125
@ J_BACKEND_FLAGS_DO_NOT_UNLOAD
Definition: jbackend.h:126
Definition: jbackend.h:132
struct JBackend::@8::@12 db
gboolean(* backend_update)(gpointer, gpointer, gchar const *, bson_t const *, bson_t const *, GError **)
Definition: jbackend.h:298
gboolean(* backend_iterate)(gpointer, gpointer, gchar const **)
Definition: jbackend.h:160
gboolean(* backend_write)(gpointer, gpointer, gconstpointer, guint64, guint64, guint64 *)
Definition: jbackend.h:156
gboolean(* backend_get)(gpointer, gpointer, gchar const *, gpointer *, guint32 *)
Definition: jbackend.h:173
void(* backend_fini)(gpointer)
Definition: jbackend.h:144
gboolean(* backend_create)(gpointer, gchar const *, gchar const *, gpointer *)
Definition: jbackend.h:146
JBackendComponent component
Definition: jbackend.h:134
gboolean(* backend_open)(gpointer, gchar const *, gchar const *, gpointer *)
Definition: jbackend.h:147
gboolean(* backend_schema_create)(gpointer, gpointer, gchar const *, bson_t const *, GError **)
Definition: jbackend.h:207
struct JBackend::@8::@10 object
gpointer data
Definition: jbackend.h:137
gboolean(* backend_batch_start)(gpointer, gchar const *, JSemantics *, gpointer *)
Definition: jbackend.h:168
gboolean(* backend_put)(gpointer, gpointer, gchar const *, gconstpointer, guint32)
Definition: jbackend.h:171
JBackendFlags flags
Definition: jbackend.h:135
gboolean(* backend_get_all)(gpointer, gchar const *, gpointer *)
Definition: jbackend.h:158
gboolean(* backend_status)(gpointer, gpointer, gint64 *, guint64 *)
Definition: jbackend.h:152
gboolean(* backend_schema_get)(gpointer, gpointer, gchar const *, bson_t *, GError **)
Definition: jbackend.h:228
gboolean(* backend_get_by_prefix)(gpointer, gchar const *, gchar const *, gpointer *)
Definition: jbackend.h:159
gboolean(* backend_schema_delete)(gpointer, gpointer, gchar const *, GError **)
Definition: jbackend.h:238
gboolean(* backend_delete)(gpointer, gpointer)
Definition: jbackend.h:149
JBackendType type
Definition: jbackend.h:133
gboolean(* backend_init)(gchar const *, gpointer *)
Definition: jbackend.h:143
gboolean(* backend_close)(gpointer, gpointer)
Definition: jbackend.h:150
gboolean(* backend_query)(gpointer, gpointer, gchar const *, bson_t const *, gpointer *, GError **)
Definition: jbackend.h:361
gboolean(* backend_sync)(gpointer, gpointer)
Definition: jbackend.h:153
gboolean(* backend_read)(gpointer, gpointer, gpointer, guint64, guint64, guint64 *)
Definition: jbackend.h:155
gboolean(* backend_batch_execute)(gpointer, gpointer)
Definition: jbackend.h:169
gboolean(* backend_insert)(gpointer, gpointer, gchar const *, bson_t const *, bson_t *, GError **)
Definition: jbackend.h:260
struct JBackend::@8::@11 kv
Definition: jsemantics.c:42