Loading...
Searching...
No Matches
as_udf.h
Go to the documentation of this file.
1/*
2 * Copyright 2008-2022 Aerospike, Inc.
3 *
4 * Portions may be licensed to Aerospike, Inc. under one or more contributor
5 * license agreements.
6 *
7 * Licensed under the Apache License, Version 2.0 (the "License"); you may not
8 * use this file except in compliance with the License. You may obtain a copy of
9 * the License at http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
13 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
14 * License for the specific language governing permissions and limitations under
15 * the License.
16 */
17#pragma once
18
19#include <aerospike/as_bytes.h>
20#include <aerospike/as_list.h>
21
22#ifdef __cplusplus
23extern "C" {
24#endif
25
26/******************************************************************************
27 * MACROS
28 *****************************************************************************/
29
30/**
31 * Maximum number of bytes in UDF module name.
32 */
33#define AS_UDF_MODULE_MAX_SIZE 64
34
35/**
36 * Maximum number of chars allows in UDF module name.
37 */
38#define AS_UDF_MODULE_MAX_LEN (AS_UDF_MODULE_MAX_SIZE - 1)
39
40/**
41 * Maximum number of bytes in UDF module name.
42 */
43#define AS_UDF_FUNCTION_MAX_SIZE 64
44
45/**
46 * Maximum number of chars allows in UDF function name.
47 */
48#define AS_UDF_FUNCTION_MAX_LEN (AS_UDF_FUNCTION_MAX_SIZE - 1)
49
50/**
51 * The size of a UDF file name
52 */
53#define AS_UDF_FILE_NAME_SIZE 128
54
55/**
56 * The size of a UDF file name
57 */
58#define AS_UDF_FILE_NAME_SIZE 128
59
60/**
61 * The maxium string length of the UDF file name
62 */
63#define AS_UDF_FILE_NAME_LEN AS_UDF_FILE_NAME_SIZE - 1
64
65/**
66 * The size of a UDF hash value
67 */
68#define AS_UDF_FILE_HASH_SIZE (20 * 2)
69
70/******************************************************************************
71 * TYPES
72 *****************************************************************************/
73
74/**
75 * UDF Module Name
76 */
78
79/**
80 * UDF Function Name
81 */
83
84/**
85 * Defines a call to a UDF
86 */
87typedef struct as_udf_call_s {
88
89 /**
90 * UDF Module containing the function to be called.
91 */
92 as_udf_module_name module;
93
94 /**
95 * UDF Function to be called
96 */
98
99 /**
100 * Argument List
101 */
103
104 /**
105 * @private
106 * If true, then as_udf_call_destroy() will free this instance.
107 */
108 bool _free;
109
111
112/**
113 * Enumeration of UDF types
114 */
115typedef enum as_udf_type_e {
116
117 /**
118 * Lua
119 */
121
123
124/**
125 * UDF File
126 */
127typedef struct as_udf_file_s {
128
129 /**
130 * Name of the UDF file
131 */
133
134 /**
135 * UDF File contents
136 */
137 struct {
138
139 /**
140 * Sequence of bytes
141 */
142 uint8_t* bytes;
143
144 /**
145 * Number of bytes allocated to bytes.
146 */
147 uint32_t capacity;
148
149 /**
150 * Number of bytes used in bytes.
151 */
152 uint32_t size;
153
154 /**
155 * @private
156 * If true, then as_udf_file_destroy() will free bytes()
157 */
158 bool _free;
159
160 } content;
161
162 /**
163 * The type of UDF
164 */
166
167 /**
168 * Hash value of the file contents
169 */
170 uint8_t hash[AS_UDF_FILE_HASH_SIZE + 1];
171
172 /**
173 * @private
174 * If true, then as_udf_file_destroy() will free this instance.
175 */
176 bool _free;
177
179
180/**
181 * Sequence of UDF Files
182 */
183typedef struct as_udf_files_s {
184
185 /**
186 * Sequence of files.
187 */
189
190 /**
191 * Number of file entries allocated to files.
192 */
193 uint32_t capacity;
194
195 /**
196 * Number of used file entries in files.
197 */
198 uint32_t size;
199
200 /**
201 * @private
202 * If true, then as_udf_list_destroy() will free this instance.
203 */
204 bool _free;
205
207
208/******************************************************************************
209 * UDF CALL FUNCTIONS
210 *****************************************************************************/
211
212/**
213 * Initialize a stack allocated as_udf_call.
214 *
215 * @param call The call to initialize.
216 * @param module The UDF module.
217 * @param function The UDF function.
218 * @param arglist The UDF argument list.
219 *
220 * @return The initialized call on success. Otherwise NULL.
221 */
223as_udf_call_init(as_udf_call* call, const as_udf_module_name module, const as_udf_function_name function, as_list* arglist);
224
225/**
226 * Creates a new heap allocated as_udf_call.
227 * @param module The UDF module.
228 * @param function The UDF function.
229 * @param arglist The UDF argument list.
230 *
231 * @return The newly allocated call on success. Otherwise NULL.
232 */
234as_udf_call_new(const as_udf_module_name module, const as_udf_function_name function, as_list* arglist);
235
236/**
237 * Destroy an as_udf_call.
238 */
239AS_EXTERN void
241
242/******************************************************************************
243 * UDF FILE FUNCTIONS
244 *****************************************************************************/
245
246/**
247 * Initialize a stack allocated as_udf_file.
248 *
249 * @returns The initialized udf file on success. Otherwise NULL.
250 */
253
254/**
255 * Creates a new heap allocated as_udf_file.
256 *
257 * @returns The newly allocated udf file on success. Otherwise NULL.
258 */
261
262/**
263 * Destroy an as_udf_file.
264 */
265AS_EXTERN void
267
268/******************************************************************************
269 * UDF LIST FUNCTIONS
270 *****************************************************************************/
271
272/**
273 * Initialize a stack allocated as_udf_files.
274 *
275 * @returns The initialized udf list on success. Otherwise NULL.
276 */
278as_udf_files_init(as_udf_files* files, uint32_t capacity);
279
280/**
281 * Creates a new heap allocated as_udf_files.
282 *
283 * @returns The newly allocated udf list on success. Otherwise NULL.
284 */
286as_udf_files_new(uint32_t capacity);
287
288/**
289 * Destroy an as_udf_files.
290 */
291AS_EXTERN void
293
294#ifdef __cplusplus
295} // end extern "C"
296#endif
#define AS_EXTERN
Definition as_std.h:25
AS_EXTERN as_udf_files * as_udf_files_init(as_udf_files *files, uint32_t capacity)
AS_EXTERN as_udf_file * as_udf_file_init(as_udf_file *file)
char as_udf_module_name[AS_UDF_MODULE_MAX_SIZE]
Definition as_udf.h:77
#define AS_UDF_FILE_HASH_SIZE
Definition as_udf.h:68
AS_EXTERN as_udf_file * as_udf_file_new(void)
char as_udf_function_name[AS_UDF_FUNCTION_MAX_SIZE]
Definition as_udf.h:82
#define AS_UDF_MODULE_MAX_SIZE
Definition as_udf.h:33
as_udf_type
Definition as_udf.h:115
@ AS_UDF_TYPE_LUA
Definition as_udf.h:120
AS_EXTERN void as_udf_file_destroy(as_udf_file *file)
AS_EXTERN void as_udf_files_destroy(as_udf_files *files)
AS_EXTERN as_udf_call * as_udf_call_new(const as_udf_module_name module, const as_udf_function_name function, as_list *arglist)
AS_EXTERN as_udf_call * as_udf_call_init(as_udf_call *call, const as_udf_module_name module, const as_udf_function_name function, as_list *arglist)
AS_EXTERN void as_udf_call_destroy(as_udf_call *call)
AS_EXTERN as_udf_files * as_udf_files_new(uint32_t capacity)
#define AS_UDF_FUNCTION_MAX_SIZE
Definition as_udf.h:43
#define AS_UDF_FILE_NAME_SIZE
Definition as_udf.h:53
as_udf_module_name as_udf_function_name function
Definition as_udf.h:97
as_list * arglist
Definition as_udf.h:102
as_udf_type type
Definition as_udf.h:165
uint8_t * bytes
Definition as_udf.h:142
uint32_t size
Definition as_udf.h:152
uint32_t capacity
Definition as_udf.h:147
uint32_t size
Definition as_udf.h:198
uint32_t capacity
Definition as_udf.h:193
as_udf_file * entries
Definition as_udf.h:188