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-2014 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 /******************************************************************************
23  * MACROS
24  *****************************************************************************/
25 
26 /**
27  * Maximum number of bytes in UDF module name.
28  */
29 #define AS_UDF_MODULE_MAX_SIZE 64
30 
31 /**
32  * Maximum number of chars allows in UDF module name.
33  */
34 #define AS_UDF_MODULE_MAX_LEN (AS_UDF_MODULE_MAX_SIZE - 1)
35 
36 /**
37  * Maximum number of bytes in UDF module name.
38  */
39 #define AS_UDF_FUNCTION_MAX_SIZE 64
40 
41 /**
42  * Maximum number of chars allows in UDF function name.
43  */
44 #define AS_UDF_FUNCTION_MAX_LEN (AS_UDF_FUNCTION_MAX_SIZE - 1)
45 
46 /**
47  * The size of a UDF file name
48  */
49 #define AS_UDF_FILE_NAME_SIZE 128
50 
51 /**
52  * The size of a UDF file name
53  */
54 #define AS_UDF_FILE_NAME_SIZE 128
55 
56 /**
57  * The maxium string length of the UDF file name
58  */
59 #define AS_UDF_FILE_NAME_LEN AS_UDF_FILE_NAME_SIZE - 1
60 
61 /**
62  * The size of a UDF hash value
63  */
64 #define AS_UDF_FILE_HASH_SIZE 20
65 
66 /******************************************************************************
67  * TYPES
68  *****************************************************************************/
69 
70 /**
71  * UDF Module Name
72  */
74 
75 /**
76  * UDF Function Name
77  */
79 
80 /**
81  * Defines a call to a UDF
82  */
83 typedef struct as_udf_call_s {
84 
85  /**
86  * @private
87  * If true, then as_udf_call_destroy() will free this instance.
88  */
89  bool _free;
90 
91  /**
92  * UDF Module containing the function to be called.
93  */
95 
96  /**
97  * UDF Function to be called
98  */
100 
101  /**
102  * Argument List
103  */
105 
106 } as_udf_call;
107 
108 /**
109  * Enumeration of UDF types
110  */
111 typedef enum as_udf_type_e {
112 
113  /**
114  * Lua
115  */
117 
118 } as_udf_type;
119 
120 /**
121  * UDF File
122  */
123 typedef struct as_udf_file_s {
124 
125  /**
126  * @private
127  * If true, then as_udf_file_destroy() will free this instance.
128  */
129  bool _free;
130 
131  /**
132  * Name of the UDF file
133  */
135 
136  /**
137  * Hash value of the file contents
138  */
139  uint8_t hash[AS_UDF_FILE_HASH_SIZE];
140 
141  /**
142  * The type of UDF
143  */
145 
146  /**
147  * UDF File contents
148  */
149  struct {
150 
151  /**
152  * @private
153  * If true, then as_udf_file_destroy() will free bytes()
154  */
155  bool _free;
156 
157  /**
158  * Number of bytes allocated to bytes.
159  */
160  uint32_t capacity;
161 
162  /**
163  * Number of bytes used in bytes.
164  */
165  uint32_t size;
166 
167  /**
168  * Sequence of bytes
169  */
170  uint8_t * bytes;
171 
172  } content;
173 
174 } as_udf_file;
175 
176 /**
177  * Sequence of UDF Files
178  */
179 typedef struct as_udf_files_s {
180 
181  /**
182  * @private
183  * If true, then as_udf_list_destroy() will free this instance.
184  */
185  bool _free;
186 
187  /**
188  * Number of file entries allocated to files.
189  */
190  uint32_t capacity;
191 
192  /**
193  * Number of used file entries in files.
194  */
195  uint32_t size;
196 
197  /**
198  * Sequence of files.
199  */
201 
202 } as_udf_files;
203 
204 /******************************************************************************
205  * UDF CALL FUNCTIONS
206  *****************************************************************************/
207 
208 /**
209  * Initialize a stack allocated as_udf_call.
210  *
211  * @param call The call to initialize.
212  * @param module The UDF module.
213  * @param function The UDF function.
214  * @param arglist The UDF argument list.
215  *
216  * @return The initialized call on success. Otherwise NULL.
217  */
218 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);
219 
220 /**
221  * Creates a new heap allocated as_udf_call.
222  * @param module The UDF module.
223  * @param function The UDF function.
224  * @param arglist The UDF argument list.
225  *
226  * @return The newly allocated call on success. Otherwise NULL.
227  */
228 as_udf_call * as_udf_call_new(const as_udf_module_name module, const as_udf_function_name function, as_list * arglist);
229 
230 /**
231  * Destroy an as_udf_call.
232  */
233 void as_udf_call_destroy(as_udf_call * call);
234 
235 /******************************************************************************
236  * UDF FILE FUNCTIONS
237  *****************************************************************************/
238 
239 /**
240  * Initialize a stack allocated as_udf_file.
241  *
242  * @returns The initialized udf file on success. Otherwise NULL.
243  */
245 
246 /**
247  * Creates a new heap allocated as_udf_file.
248  *
249  * @returns The newly allocated udf file on success. Otherwise NULL.
250  */
252 
253 /**
254  * Destroy an as_udf_file.
255  */
256 void as_udf_file_destroy(as_udf_file * file);
257 
258 /******************************************************************************
259  * UDF LIST FUNCTIONS
260  *****************************************************************************/
261 
262 /**
263  * Initialize a stack allocated as_udf_files.
264  *
265  * @returns The initialized udf list on success. Otherwise NULL.
266  */
267 as_udf_files * as_udf_files_init(as_udf_files * files, uint32_t capacity);
268 
269 /**
270  * Creates a new heap allocated as_udf_files.
271  *
272  * @returns The newly allocated udf list on success. Otherwise NULL.
273  */
274 as_udf_files * as_udf_files_new(uint32_t capacity);
275 
276 /**
277  * Destroy an as_udf_files.
278  */
279 void as_udf_files_destroy(as_udf_files * files);