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-2016 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
23 extern "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  */
87 typedef struct as_udf_call_s {
88 
89  /**
90  * @private
91  * If true, then as_udf_call_destroy() will free this instance.
92  */
93  bool _free;
94 
95  /**
96  * UDF Module containing the function to be called.
97  */
98  as_udf_module_name module;
99 
100  /**
101  * UDF Function to be called
102  */
103  as_udf_function_name function;
104 
105  /**
106  * Argument List
107  */
109 
110 } as_udf_call;
111 
112 /**
113  * Enumeration of UDF types
114  */
115 typedef enum as_udf_type_e {
116 
117  /**
118  * Lua
119  */
121 
122 } as_udf_type;
123 
124 /**
125  * UDF File
126  */
127 typedef struct as_udf_file_s {
128 
129  /**
130  * @private
131  * If true, then as_udf_file_destroy() will free this instance.
132  */
133  bool _free;
134 
135  /**
136  * Name of the UDF file
137  */
139 
140  /**
141  * Hash value of the file contents
142  */
143  uint8_t hash[AS_UDF_FILE_HASH_SIZE+1];
144 
145  /**
146  * The type of UDF
147  */
149 
150  /**
151  * UDF File contents
152  */
153  struct {
154 
155  /**
156  * @private
157  * If true, then as_udf_file_destroy() will free bytes()
158  */
159  bool _free;
160 
161  /**
162  * Number of bytes allocated to bytes.
163  */
164  uint32_t capacity;
165 
166  /**
167  * Number of bytes used in bytes.
168  */
169  uint32_t size;
170 
171  /**
172  * Sequence of bytes
173  */
174  uint8_t * bytes;
175 
176  } content;
177 
178 } as_udf_file;
179 
180 /**
181  * Sequence of UDF Files
182  */
183 typedef struct as_udf_files_s {
184 
185  /**
186  * @private
187  * If true, then as_udf_list_destroy() will free this instance.
188  */
189  bool _free;
190 
191  /**
192  * Number of file entries allocated to files.
193  */
194  uint32_t capacity;
195 
196  /**
197  * Number of used file entries in files.
198  */
199  uint32_t size;
200 
201  /**
202  * Sequence of files.
203  */
205 
206 } as_udf_files;
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  */
222 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);
223 
224 /**
225  * Creates a new heap allocated as_udf_call.
226  * @param module The UDF module.
227  * @param function The UDF function.
228  * @param arglist The UDF argument list.
229  *
230  * @return The newly allocated call on success. Otherwise NULL.
231  */
232 as_udf_call * as_udf_call_new(const as_udf_module_name module, const as_udf_function_name function, as_list * arglist);
233 
234 /**
235  * Destroy an as_udf_call.
236  */
237 void as_udf_call_destroy(as_udf_call * call);
238 
239 /******************************************************************************
240  * UDF FILE FUNCTIONS
241  *****************************************************************************/
242 
243 /**
244  * Initialize a stack allocated as_udf_file.
245  *
246  * @returns The initialized udf file on success. Otherwise NULL.
247  */
249 
250 /**
251  * Creates a new heap allocated as_udf_file.
252  *
253  * @returns The newly allocated udf file on success. Otherwise NULL.
254  */
256 
257 /**
258  * Destroy an as_udf_file.
259  */
260 void as_udf_file_destroy(as_udf_file * file);
261 
262 /******************************************************************************
263  * UDF LIST FUNCTIONS
264  *****************************************************************************/
265 
266 /**
267  * Initialize a stack allocated as_udf_files.
268  *
269  * @returns The initialized udf list on success. Otherwise NULL.
270  */
271 as_udf_files * as_udf_files_init(as_udf_files * files, uint32_t capacity);
272 
273 /**
274  * Creates a new heap allocated as_udf_files.
275  *
276  * @returns The newly allocated udf list on success. Otherwise NULL.
277  */
278 as_udf_files * as_udf_files_new(uint32_t capacity);
279 
280 /**
281  * Destroy an as_udf_files.
282  */
283 void as_udf_files_destroy(as_udf_files * files);
284 
285 #ifdef __cplusplus
286 } // end extern "C"
287 #endif
char as_udf_module_name[AS_UDF_MODULE_MAX_SIZE]
Definition: as_udf.h:77
bool _free
Definition: as_udf.h:189
as_udf_module_name module
Definition: as_udf.h:98
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:148
char as_udf_function_name[AS_UDF_FUNCTION_MAX_SIZE]
Definition: as_udf.h:82
as_udf_file * as_udf_file_init(as_udf_file *file)
uint32_t capacity
Definition: as_udf.h:194
uint32_t capacity
Definition: as_udf.h:164
as_list * arglist
Definition: as_udf.h:108
#define AS_UDF_FILE_NAME_SIZE
Definition: as_udf.h:58
uint32_t size
Definition: as_udf.h:199
as_udf_file * as_udf_file_new()
bool _free
Definition: as_udf.h:93
as_udf_file * entries
Definition: as_udf.h:204
void as_udf_files_destroy(as_udf_files *files)
#define AS_UDF_FILE_HASH_SIZE
Definition: as_udf.h:68
as_udf_type
Definition: as_udf.h:115
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:43
uint8_t * bytes
Definition: as_udf.h:174
uint32_t size
Definition: as_udf.h:169
#define AS_UDF_MODULE_MAX_SIZE
Definition: as_udf.h:33
bool _free
Definition: as_udf.h:133
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)