1 | /* |
2 | * udf.h |
3 | * |
4 | * Copyright (C) 2016 Aerospike, Inc. |
5 | * |
6 | * Portions may be licensed to Aerospike, Inc. under one or more contributor |
7 | * license agreements. |
8 | * |
9 | * This program is free software: you can redistribute it and/or modify it under |
10 | * the terms of the GNU Affero General Public License as published by the Free |
11 | * Software Foundation, either version 3 of the License, or (at your option) any |
12 | * later version. |
13 | * |
14 | * This program is distributed in the hope that it will be useful, but WITHOUT |
15 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS |
16 | * FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more |
17 | * details. |
18 | * |
19 | * You should have received a copy of the GNU Affero General Public License |
20 | * along with this program. If not, see http://www.gnu.org/licenses/ |
21 | */ |
22 | |
23 | #pragma once |
24 | |
25 | //========================================================== |
26 | // Includes. |
27 | // |
28 | |
29 | #include <stdint.h> |
30 | |
31 | #include "aerospike/as_aerospike.h" |
32 | #include "aerospike/as_list.h" |
33 | #include "citrusleaf/alloc.h" |
34 | |
35 | #include "base/predexp.h" |
36 | #include "base/transaction.h" |
37 | |
38 | |
39 | //========================================================== |
40 | // Forward declarations. |
41 | // |
42 | |
43 | struct as_transaction_s; |
44 | struct cl_msg_s; |
45 | struct predexp_eval_base_s; |
46 | |
47 | |
48 | //========================================================== |
49 | // Typedefs & constants. |
50 | // |
51 | |
52 | typedef enum { |
53 | UDF_OPTYPE_NONE, |
54 | UDF_OPTYPE_WAITING, |
55 | UDF_OPTYPE_READ, |
56 | UDF_OPTYPE_WRITE, |
57 | UDF_OPTYPE_DELETE |
58 | } udf_optype; |
59 | |
60 | #define UDF_MAX_STRING_SZ 128 |
61 | |
62 | typedef struct udf_def_s { |
63 | char filename[UDF_MAX_STRING_SZ]; |
64 | char function[UDF_MAX_STRING_SZ]; |
65 | as_list* arglist; |
66 | uint8_t type; |
67 | } udf_def; |
68 | |
69 | typedef void (*iudf_cb)(void* udata, int result); |
70 | |
71 | typedef struct iudf_origin_s { |
72 | udf_def def; |
73 | struct cl_msg_s* msgp; |
74 | struct predexp_eval_base_s* predexp; |
75 | iudf_cb cb; |
76 | void* udata; |
77 | } iudf_origin; |
78 | |
79 | |
80 | //========================================================== |
81 | // Public API. |
82 | // |
83 | |
84 | static inline void |
85 | iudf_origin_destroy(iudf_origin* origin) |
86 | { |
87 | if (origin->def.arglist) { |
88 | as_list_destroy(origin->def.arglist); |
89 | } |
90 | |
91 | predexp_destroy(origin->predexp); |
92 | cf_free(origin->msgp); |
93 | } |
94 | |
95 | void as_udf_init(); |
96 | udf_def* udf_def_init_from_msg(udf_def* def, const struct as_transaction_s* tr); |
97 | |
98 | transaction_status as_udf_start(struct as_transaction_s* tr); |
99 | |
100 | extern as_aerospike g_as_aerospike; |
101 | |