All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
as_udf.h
Go to the documentation of this file.
1 /******************************************************************************
2  * Copyright 2008-2013 by Aerospike.
3  *
4  * Permission is hereby granted, free of charge, to any person obtaining a copy
5  * of this software and associated documentation files (the "Software"), to
6  * deal in the Software without restriction, including without limitation the
7  * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
8  * sell copies of the Software, and to permit persons to whom the Software is
9  * furnished to do so, subject to the following conditions:
10  *
11  * The above copyright notice and this permission notice shall be included in
12  * all copies or substantial portions of the Software.
13  *
14  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
19  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
20  * IN THE SOFTWARE.
21  *****************************************************************************/
22 
23 #pragma once
24 
25 #include <aerospike/as_bytes.h>
26 #include <aerospike/as_list.h>
27 
28 /******************************************************************************
29  * MACROS
30  *****************************************************************************/
31 
32 /**
33  * Maximum number of bytes in UDF module name.
34  */
35 #define AS_UDF_MODULE_MAX_SIZE 64
36 
37 /**
38  * Maximum number of chars allows in UDF module name.
39  */
40 #define AS_UDF_MODULE_MAX_LEN (AS_UDF_MODULE_MAX_SIZE - 1)
41 
42 /**
43  * Maximum number of bytes in UDF module name.
44  */
45 #define AS_UDF_FUNCTION_MAX_SIZE 64
46 
47 /**
48  * Maximum number of chars allows in UDF function name.
49  */
50 #define AS_UDF_FUNCTION_MAX_LEN (AS_UDF_FUNCTION_MAX_SIZE - 1)
51 
52 /**
53  * The size of a UDF file name
54  */
55 #define AS_UDF_FILE_NAME_SIZE 128
56 
57 /**
58  * The size of a UDF file name
59  */
60 #define AS_UDF_FILE_NAME_SIZE 128
61 
62 /**
63  * The maxium string length of the UDF file name
64  */
65 #define AS_UDF_FILE_NAME_LEN AS_UDF_FILE_NAME_SIZE - 1
66 
67 /**
68  * The size of a UDF hash value
69  */
70 #define AS_UDF_FILE_HASH_SIZE 20
71 
72 /******************************************************************************
73  * TYPES
74  *****************************************************************************/
75 
76 /**
77  * UDF Module Name
78  */
80 
81 /**
82  * UDF Function Name
83  */
85 
86 /**
87  * Defines a call to a UDF
88  */
89 typedef struct as_udf_call_s {
90 
91  /**
92  * @private
93  * If true, then as_udf_call_destroy() will free this instance.
94  */
95  bool _free;
96 
97  /**
98  * UDF Module containing the function to be called.
99  */
101 
102  /**
103  * UDF Function to be called
104  */
106 
107  /**
108  * Argument List
109  */
111 
112 } as_udf_call;
113 
114 /**
115  * Enumeration of UDF types
116  */
117 typedef enum as_udf_type_e {
118 
119  /**
120  * Lua
121  */
123 
124 } as_udf_type;
125 
126 /**
127  * UDF File
128  */
129 typedef struct as_udf_file_s {
130 
131  /**
132  * @private
133  * If true, then as_udf_file_destroy() will free this instance.
134  */
135  bool _free;
136 
137  /**
138  * Name of the UDF file
139  */
141 
142  /**
143  * Hash value of the file contents
144  */
145  uint8_t hash[AS_UDF_FILE_HASH_SIZE];
146 
147  /**
148  * The type of UDF
149  */
151 
152  /**
153  * UDF File contents
154  */
155  struct {
156 
157  /**
158  * @private
159  * If true, then as_udf_file_destroy() will free bytes()
160  */
161  bool _free;
162 
163  /**
164  * Number of bytes allocated to bytes.
165  */
166  uint32_t capacity;
167 
168  /**
169  * Number of bytes used in bytes.
170  */
171  uint32_t size;
172 
173  /**
174  * Sequence of bytes
175  */
176  uint8_t * bytes;
177 
178  } content;
179 
180 } as_udf_file;
181 
182 /**
183  * Sequence of UDF Files
184  */
185 typedef struct as_udf_files_s {
186 
187  /**
188  * @private
189  * If true, then as_udf_list_destroy() will free this instance.
190  */
191  bool _free;
192 
193  /**
194  * Number of file entries allocated to files.
195  */
196  uint32_t capacity;
197 
198  /**
199  * Number of used file entries in files.
200  */
201  uint32_t size;
202 
203  /**
204  * Sequence of files.
205  */
207 
208 } as_udf_files;
209 
210 /******************************************************************************
211  * UDF CALL FUNCTIONS
212  *****************************************************************************/
213 
214 /**
215  * Initialize a stack allocated as_udf_call.
216  *
217  * @param call The call to initialize.
218  * @param module The UDF module.
219  * @param function The UDF function.
220  * @param arglist The UDF argument list.
221  *
222  * @return The initialized call on success. Otherwise NULL.
223  */
224 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);
225 
226 /**
227  * Creates a new heap allocated as_udf_call.
228  * @param module The UDF module.
229  * @param function The UDF function.
230  * @param arglist The UDF argument list.
231  *
232  * @return The newly allocated call on success. Otherwise NULL.
233  */
234 as_udf_call * as_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  */
239 void as_udf_call_destroy(as_udf_call * call);
240 
241 /******************************************************************************
242  * UDF FILE FUNCTIONS
243  *****************************************************************************/
244 
245 /**
246  * Initialize a stack allocated as_udf_file.
247  *
248  * @returns The initialized udf file on success. Otherwise NULL.
249  */
251 
252 /**
253  * Creates a new heap allocated as_udf_file.
254  *
255  * @returns The newly allocated udf file on success. Otherwise NULL.
256  */
258 
259 /**
260  * Destroy an as_udf_file.
261  */
262 void as_udf_file_destroy(as_udf_file * file);
263 
264 /******************************************************************************
265  * UDF LIST FUNCTIONS
266  *****************************************************************************/
267 
268 /**
269  * Initialize a stack allocated as_udf_files.
270  *
271  * @returns The initialized udf list on success. Otherwise NULL.
272  */
273 as_udf_files * as_udf_files_init(as_udf_files * files, uint32_t capacity);
274 
275 /**
276  * Creates a new heap allocated as_udf_files.
277  *
278  * @returns The newly allocated udf list on success. Otherwise NULL.
279  */
280 as_udf_files * as_udf_files_new(uint32_t capacity);
281 
282 /**
283  * Destroy an as_udf_files.
284  */
285 void as_udf_files_destroy(as_udf_files * files);
char as_udf_module_name[AS_UDF_MODULE_MAX_SIZE]
Definition: as_udf.h:79
bool _free
Definition: as_udf.h:191
as_udf_module_name module
Definition: as_udf.h:100
void as_udf_file_destroy(as_udf_file *file)
as_udf_files * as_udf_files_init(as_udf_files *files, uint32_t capacity)
as_udf_type type
Definition: as_udf.h:150
char as_udf_function_name[AS_UDF_FUNCTION_MAX_SIZE]
Definition: as_udf.h:84
as_udf_file * as_udf_file_init(as_udf_file *file)
uint32_t capacity
Definition: as_udf.h:196
uint32_t capacity
Definition: as_udf.h:166
as_list * arglist
Definition: as_udf.h:110
#define AS_UDF_FILE_NAME_SIZE
Definition: as_udf.h:60
uint32_t size
Definition: as_udf.h:201
as_udf_file * as_udf_file_new()
bool _free
Definition: as_udf.h:95
as_udf_file * entries
Definition: as_udf.h:206
void as_udf_files_destroy(as_udf_files *files)
#define AS_UDF_FILE_HASH_SIZE
Definition: as_udf.h:70
as_udf_type
Definition: as_udf.h:117
as_udf_files * as_udf_files_new(uint32_t capacity)
as_udf_call * as_udf_call_new(const as_udf_module_name module, const as_udf_function_name function, as_list *arglist)
void as_udf_call_destroy(as_udf_call *call)
#define AS_UDF_FUNCTION_MAX_SIZE
Definition: as_udf.h:45
uint8_t * bytes
Definition: as_udf.h:176
uint32_t size
Definition: as_udf.h:171
#define AS_UDF_MODULE_MAX_SIZE
Definition: as_udf.h:35
bool _free
Definition: as_udf.h:135
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)