Loading...
Searching...
No Matches
as_module.h
Go to the documentation of this file.
1/*
2 * Copyright 2008-2023 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
20#include <aerospike/as_stream.h>
21#include <aerospike/as_result.h>
22#include <aerospike/as_std.h>
23#include <aerospike/as_types.h>
25
26#ifdef __cplusplus
27extern "C" {
28#endif
29
30//---------------------------------
31// Types
32//---------------------------------
33
34struct as_module_s;
35
36/**
37 * Module events.
38 *
39 * as_module_event e;
40 * e.type = AS_MODULE_CONFIGURE;
41 * e.data.config = my_config;
42 */
50
51typedef struct as_module_event_data_s {
52 void* config;
53 const char* filename;
55
60
61typedef struct as_module_error_s {
62 uint8_t scope;
63 uint32_t code;
64 char message[1024];
65 char file[256];
66 uint32_t line;
67 char func[256];
69
70/**
71 * Module Interface
72 * Provide functions which interface with a module.
73 */
74typedef struct as_module_hooks_s {
75 /**
76 * Free resources used by the module.
77 */
78 int (*destroy)(struct as_module_s* m);
79
80 /**
81 * Dispatch an event to the module.
82 */
83 int (*update)(struct as_module_s* m, as_module_event* e);
84
85 /**
86 * Apply a functio to a record
87 */
88 int (*validate)(struct as_module_s* m, as_aerospike* as, const char* filename,
89 const char* content, uint32_t size, as_module_error* err);
90
91 /**
92 * Apply a function to a record
93 */
94 int (*apply_record)(struct as_module_s* m, as_udf_context* ctx, const char* filename,
95 const char* function, as_rec* rec, as_list* args, as_result* res);
96
97 /**
98 * Apply a function to a stream.
99 */
100 int (*apply_stream)(struct as_module_s* m, as_udf_context* ctx, const char* filename,
101 const char* function, as_stream* istream, as_list* args, as_stream* ostream,
102 as_result* res);
104
105/**
106 * Module Structure. Contains pointer to module specific data and a pointer to the
107 * hooks that interface with the module.
108 */
109typedef struct as_module_s {
110 const void* source;
112} as_module;
113
114//---------------------------------
115// Functions
116//---------------------------------
117
118/**
119 * Get the source of the module.
120 *
121 * @param m the module to get the source from.
122 */
123void*
125
126/**
127 * Module Destroyer.
128 * This frees up the resources used by the module.
129 *
130 * Proxies to `m->hooks->destroy(m, ...)`
131 *
132 * @param m the module being initialized.
133 * @return 0 on success, otherwise 1
134 */
135int
137
138/**
139 * Module Configurator.
140 * This configures and reconfigures the module. This can be called an
141 * arbitrary number of times during the lifetime of the server.
142 *
143 * Proxies to `m->hooks->configure(m, ...)`
144 *
145 * @param m the module being configured.
146 * @param c the new configurations.
147 * @return 0 on success, otherwise 1
148 */
149int
151
152/**
153 * Update a Module.
154 *
155 * Proxies to `m->hooks->update(m, ...)`
156 *
157 * @param m the module being initialized.
158 * @param e the module event.
159 * @return 0 on success, otherwise 1
160 */
161int
163
164/**
165 * Validates a UDF provided by a string.
166 *
167 * @param m Module from which the fqn will be resolved.
168 * @param as aerospike object to be used.
169 * @param filename The name of the udf module to be validated.
170 * @param content The content of the udf module to be validated.
171 * @param size The size of the udf module to be validated.
172 * @param error The error string (1024 bytes). Should be preallocated. Will be an empty string if no error occurred.
173 *
174 * @return 0 on success, otherwise 1 on error.
175 */
176int as_module_validate(as_module* m, as_aerospike* as, const char* filename, const char* content, uint32_t size, as_module_error* error);
177
178/**
179 * Applies a UDF to a stream with provided arguments.
180 *
181 * @param m Module from which the fqn will be resolved.
182 * @param ctx aerospike udf execution context
183 * @param filename The name of the udf module containing the function to be executed.
184 * @param function The name of the udf function to be executed.
185 * @param r record to apply to the function.
186 * @param args list of arguments for the function represented as vals
187 * @param res pointer to a val that will be populated with the result.
188 *
189 * @return 0 on success, otherwise 1
190 */
191int
193 const char* function, as_rec* r, as_list* args, as_result* res);
194
195/**
196 * Applies function to a stream and set of arguments. Pushes the results into an output stream.
197 *
198 * Proxies to `m->hooks->apply_stream(m, ...)`
199 *
200 * @param m Module from which the fqn will be resolved.
201 * @param ctx aerospike udf execution context
202 * @param filename The name of the udf module containing the function to be executed.
203 * @param function The name of the udf function to be executed.
204 * @param istream pointer to a readable stream, that will provides values.
205 * @param args list of arguments for the function represented as vals
206 * @param ostream pointer to a writable stream, that will be populated with results.
207 * @param res pointer to a val that will be populated with the result.
208 *
209 * @return 0 on success, otherwise 1
210 */
211int
213 const char* function, as_stream* istream, as_list* args, as_stream* ostream, as_result* res);
214
215/**
216 * Return lua error in string format when error code is passed in
217 *
218 * @param e The error code
219 */
220char*
222
223#ifdef __cplusplus
224} // end extern "C"
225#endif
int as_module_destroy(as_module *m)
int as_module_apply_stream(as_module *m, as_udf_context *ctx, const char *filename, const char *function, as_stream *istream, as_list *args, as_stream *ostream, as_result *res)
int as_module_validate(as_module *m, as_aerospike *as, const char *filename, const char *content, uint32_t size, as_module_error *error)
void * as_module_source(as_module *m)
int as_module_apply_record(as_module *m, as_udf_context *ctx, const char *filename, const char *function, as_rec *r, as_list *args, as_result *res)
char * as_module_err_string(int e)
as_module_event_type
Definition as_module.h:43
@ AS_MODULE_EVENT_FILE_REMOVE
Definition as_module.h:47
@ AS_MODULE_EVENT_CLEAR_CACHE
Definition as_module.h:48
@ AS_MODULE_EVENT_FILE_SCAN
Definition as_module.h:45
@ AS_MODULE_EVENT_CONFIGURE
Definition as_module.h:44
@ AS_MODULE_EVENT_FILE_ADD
Definition as_module.h:46
int as_module_update(as_module *m, as_module_event *e)
int as_module_configure(as_module *m, void *c)
as_msg m
Definition as_proto.h:1
uint8_t scope
Definition as_module.h:62
uint32_t line
Definition as_module.h:66
uint32_t code
Definition as_module.h:63
const char * filename
Definition as_module.h:53
as_module_event_type type
Definition as_module.h:57
as_module_event_data data
Definition as_module.h:58
const void * source
Definition as_module.h:110
const as_module_hooks * hooks
Definition as_module.h:111