JULEA
jbackend-operation.h
Go to the documentation of this file.
1 /*
2  * JULEA - Flexible storage framework
3  * Copyright (C) 2019 Benjamin Warnke
4  * Copyright (C) 2019-2024 Michael Kuhn
5  *
6  * This program is free software: you can redistribute it and/or modify
7  * it under the terms of the GNU Lesser General Public License as published by
8  * the Free Software Foundation, either version 3 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public License
17  * along with this program. If not, see <http://www.gnu.org/licenses/>.
18  */
19 
24 #ifndef JULEA_BACKEND_OPERATION_H
25 #define JULEA_BACKEND_OPERATION_H
26 
27 #if !defined(JULEA_H) && !defined(JULEA_COMPILATION)
28 #error "Only <julea.h> can be included directly."
29 #endif
30 
31 #include <glib.h>
32 #include <gmodule.h>
33 
34 #include <bson.h>
35 
36 #include <core/jbackend.h>
37 #include <core/jmessage.h>
38 
39 G_BEGIN_DECLS
40 
50 {
55 };
56 
58 
60 {
61  // Only for temporary static storage
62  union
63  {
64  struct
65  {
66  bson_t bson;
67  };
68 
69  struct
70  {
71  GError error;
72 
73  GError* error_ptr;
74 
75  const gchar* error_quark_string;
76  };
77  };
78 
79  union
80  {
81  gconstpointer ptr_const;
82  gpointer ptr;
83  };
84 
85  // Length of ptr data
86  gint len;
87 
89 
91  gboolean bson_initialized;
92 };
93 
95 
98 {
99  // Input parameters
101  // Output parameters
102  // The last out parameter must be of type 'J_BACKEND_OPERATION_PARAM_TYPE_ERROR'
104 
105  gboolean (*backend_func)(struct JBackend*, gpointer, struct JBackendOperation*);
106 
107  //refcounting objects which are required for transmission - unref those after use
108  GDestroyNotify unref_funcs[5];
109  gpointer unref_values[5];
110 
114 };
115 
116 typedef struct JBackendOperation JBackendOperation;
117 
118 G_END_DECLS
119 
120 #include <core/jmessage.h>
121 
122 G_BEGIN_DECLS
123 
131 
132 /*
133  * this function is called only on the client side of the backend
134  * the return value of this function is the same as the return value of the original function call
135 */
136 gboolean j_backend_operation_to_message(JMessage* message, JBackendOperationParam* data, guint len);
137 gboolean j_backend_operation_from_message(JMessage* message, JBackendOperationParam* data, guint len);
138 
139 /*
140  * this function is called server side. This assumes 'message' is valid as long as the returned array is used
141  * the return value of this function is the same as the return value of the original function call
142  */
143 gboolean j_backend_operation_from_message_static(JMessage* message, JBackendOperationParam* data, guint len);
144 
145 static const JBackendOperation j_backend_operation_db_schema_create = {
146  .in_param = {
149  {
151  .bson_initialized = TRUE,
152  },
153  },
154  .out_param = {
155  {
157  },
158  },
160  .in_param_count = 3,
161  .out_param_count = 1,
162 };
163 
164 static const JBackendOperation j_backend_operation_db_schema_get = {
165  .in_param = {
168  },
169  .out_param = {
170  {
172  .bson_initialized = TRUE,
173  },
175  },
177  .in_param_count = 2,
178  .out_param_count = 2,
179 };
180 
181 static const JBackendOperation j_backend_operation_db_schema_delete = {
182  .in_param = {
185  },
186  .out_param = {
188  },
190  .in_param_count = 2,
191  .out_param_count = 1,
192 };
193 
194 static const JBackendOperation j_backend_operation_db_insert = {
195  .in_param = {
198  {
200  .bson_initialized = TRUE,
201  },
202  },
203  .out_param = {
204  {
206  .bson_initialized = TRUE,
207  },
209  },
210  .backend_func = j_backend_operation_unwrap_db_insert,
211  .in_param_count = 3,
212  .out_param_count = 2,
213 };
214 
215 static const JBackendOperation j_backend_operation_db_update = {
216  .in_param = {
219  {
221  .bson_initialized = TRUE,
222  },
223  {
225  .bson_initialized = TRUE,
226  },
227  },
228  .out_param = {
230  },
231  .backend_func = j_backend_operation_unwrap_db_update,
232  .in_param_count = 4,
233  .out_param_count = 1,
234 };
235 
236 static const JBackendOperation j_backend_operation_db_delete = {
237  .in_param = {
240  {
242  .bson_initialized = TRUE,
243  },
244  },
245  .out_param = {
247  },
248  .backend_func = j_backend_operation_unwrap_db_delete,
249  .in_param_count = 3,
250  .out_param_count = 1,
251 };
252 
253 static const JBackendOperation j_backend_operation_db_query = {
254  .in_param = {
257  {
259  .bson_initialized = TRUE,
260  },
261  },
262  .out_param = {
263  {
265  .bson_initialized = TRUE,
266  },
268  },
269  .backend_func = j_backend_operation_unwrap_db_query,
270  .in_param_count = 3,
271  .out_param_count = 2,
272 };
273 
278 G_END_DECLS
279 
280 #endif
gboolean j_backend_operation_from_message(JMessage *message, JBackendOperationParam *data, guint len)
Definition: jbackend-operation.c:262
gboolean j_backend_operation_unwrap_db_schema_delete(JBackend *, gpointer, JBackendOperation *)
Definition: jbackend-operation.c:56
gboolean j_backend_operation_unwrap_db_query(JBackend *, gpointer, JBackendOperation *)
Definition: jbackend-operation.c:103
gboolean j_backend_operation_unwrap_db_insert(JBackend *, gpointer, JBackendOperation *)
Definition: jbackend-operation.c:64
gboolean j_backend_operation_unwrap_db_delete(JBackend *, gpointer, JBackendOperation *)
Definition: jbackend-operation.c:94
G_END_DECLS G_BEGIN_DECLS gboolean j_backend_operation_unwrap_db_schema_create(JBackend *, gpointer, JBackendOperation *)
Definition: jbackend-operation.c:40
gboolean j_backend_operation_unwrap_db_update(JBackend *, gpointer, JBackendOperation *)
Definition: jbackend-operation.c:86
JBackendOperationParamType
Definition: jbackend-operation.h:50
gboolean j_backend_operation_from_message_static(JMessage *message, JBackendOperationParam *data, guint len)
Definition: jbackend-operation.c:338
gboolean j_backend_operation_unwrap_db_schema_get(JBackend *, gpointer, JBackendOperation *)
Definition: jbackend-operation.c:48
gboolean j_backend_operation_to_message(JMessage *message, JBackendOperationParam *data, guint len)
Definition: jbackend-operation.c:147
@ J_BACKEND_OPERATION_PARAM_TYPE_STR
Definition: jbackend-operation.h:51
@ J_BACKEND_OPERATION_PARAM_TYPE_ERROR
Definition: jbackend-operation.h:54
@ J_BACKEND_OPERATION_PARAM_TYPE_BLOB
Definition: jbackend-operation.h:52
@ J_BACKEND_OPERATION_PARAM_TYPE_BSON
Definition: jbackend-operation.h:53
Definition: jbackend-operation.h:60
gpointer ptr
Definition: jbackend-operation.h:82
gint len
Definition: jbackend-operation.h:86
GError * error_ptr
Definition: jbackend-operation.h:73
bson_t bson
Definition: jbackend-operation.h:66
gboolean bson_initialized
Definition: jbackend-operation.h:91
JBackendOperationParamType type
Definition: jbackend-operation.h:88
GError error
Definition: jbackend-operation.h:71
gconstpointer ptr_const
Definition: jbackend-operation.h:81
const gchar * error_quark_string
Definition: jbackend-operation.h:75
Definition: jbackend-operation.h:98
guint out_param_count
Definition: jbackend-operation.h:112
GDestroyNotify unref_funcs[5]
Definition: jbackend-operation.h:108
guint unref_func_count
Definition: jbackend-operation.h:113
JBackendOperationParam in_param[5]
Definition: jbackend-operation.h:100
gpointer unref_values[5]
Definition: jbackend-operation.h:109
JBackendOperationParam out_param[5]
Definition: jbackend-operation.h:103
guint in_param_count
Definition: jbackend-operation.h:111
gboolean(* backend_func)(struct JBackend *, gpointer, struct JBackendOperation *)
Definition: jbackend-operation.h:105
Definition: jbackend.h:132
Definition: jmessage.c:121