Groonga
Loading...
Searching...
No Matches
plugin.h
Go to the documentation of this file.
1/*
2 Copyright (C) 2010-2017 Brazil
3 Copyright (C) 2022-2025 Sutou Kouhei <kou@clear-code.com>
4
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
9
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
14
15 You should have received a copy of the GNU Lesser General Public
16 License along with this library; if not, write to the Free Software
17 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18*/
19
20#pragma once
21
22#include <stddef.h>
23
24#include <groonga.h>
25
26#ifdef __cplusplus
27extern "C" {
28#endif
29
30#define GRN_PLUGIN_IMPL_NAME_RAW(type) grn_plugin_impl_##type
31#define GRN_PLUGIN_IMPL_NAME_TAGGED(type, tag) \
32 GRN_PLUGIN_IMPL_NAME_RAW(type##_##tag)
33#define GRN_PLUGIN_IMPL_NAME_TAGGED_EXPANDABLE(type, tag) \
34 GRN_PLUGIN_IMPL_NAME_TAGGED(type, tag)
35
36#ifdef GRN_PLUGIN_FUNCTION_TAG
37# define GRN_PLUGIN_IMPL_NAME(type) \
38 GRN_PLUGIN_IMPL_NAME_TAGGED_EXPANDABLE(type, GRN_PLUGIN_FUNCTION_TAG)
39#else /* GRN_PLUGIN_FUNCTION_TAG */
40# define GRN_PLUGIN_IMPL_NAME(type) GRN_PLUGIN_IMPL_NAME_RAW(type)
41#endif /* GRN_PLUGIN_FUNCTION_TAG */
42
43#define GRN_PLUGIN_INIT GRN_PLUGIN_IMPL_NAME(init)
44#define GRN_PLUGIN_REGISTER GRN_PLUGIN_IMPL_NAME(register)
45#define GRN_PLUGIN_FIN GRN_PLUGIN_IMPL_NAME(fin)
46
47#if defined(_WIN32) || defined(_WIN64)
48# define GRN_PLUGIN_EXPORT __declspec(dllexport)
49#else /* defined(_WIN32) || defined(_WIN64) */
50# define GRN_PLUGIN_EXPORT
51#endif /* defined(_WIN32) || defined(_WIN64) */
52
59
60#define GRN_PLUGIN_DECLARE_FUNCTIONS(tag) \
61 extern grn_rc GRN_PLUGIN_IMPL_NAME_TAGGED(init, tag)(grn_ctx * ctx); \
62 extern grn_rc GRN_PLUGIN_IMPL_NAME_TAGGED(register, tag)(grn_ctx * ctx); \
63 extern grn_rc GRN_PLUGIN_IMPL_NAME_TAGGED(fin, tag)(grn_ctx * ctx)
64
65/*
66 Don't call these functions directly. Use GRN_PLUGIN_MALLOC(),
67 GRN_PLUGIN_CALLOC(), GRN_PLUGIN_REALLOC() and GRN_PLUGIN_FREE() instead.
68 */
69GRN_API void *
71 grn_ctx *ctx, size_t size, const char *file, int line, const char *func)
73GRN_API void *
75 grn_ctx *ctx, size_t size, const char *file, int line, const char *func)
77GRN_API void *
79 void *ptr,
80 size_t size,
81 const char *file,
82 int line,
83 const char *func) GRN_ATTRIBUTE_ALLOC_SIZE(3);
84GRN_API void
86 grn_ctx *ctx, void *ptr, const char *file, int line, const char *func);
87
88#define GRN_PLUGIN_MALLOC(ctx, size) \
89 grn_plugin_malloc((ctx), (size), __FILE__, __LINE__, __FUNCTION__)
90#define GRN_PLUGIN_MALLOCN(ctx, type, n) \
91 ((type *)(grn_plugin_malloc((ctx), \
92 sizeof(type) * (n), \
93 __FILE__, \
94 __LINE__, \
95 __FUNCTION__)))
96#define GRN_PLUGIN_CALLOC(ctx, size) \
97 grn_plugin_calloc((ctx), (size), __FILE__, __LINE__, __FUNCTION__)
98#define GRN_PLUGIN_REALLOC(ctx, ptr, size) \
99 grn_plugin_realloc((ctx), (ptr), (size), __FILE__, __LINE__, __FUNCTION__)
100#define GRN_PLUGIN_FREE(ctx, ptr) \
101 grn_plugin_free((ctx), (ptr), __FILE__, __LINE__, __FUNCTION__)
102
103#define GRN_PLUGIN_LOG(ctx, level, ...) GRN_LOG((ctx), (level), __VA_ARGS__)
104
105/*
106 Don't call grn_plugin_set_error() directly. This function is used in
107 GRN_PLUGIN_SET_ERROR().
108 */
109GRN_API void
111 grn_log_level level,
112 grn_rc error_code,
113 const char *file,
114 int line,
115 const char *func,
116 const char *format,
117 ...) GRN_ATTRIBUTE_PRINTF(7);
118GRN_API void
120
121/*
122 Don't call these functions directly. grn_plugin_backtrace() and
123 grn_plugin_logtrace() are used in GRN_PLUGIN_SET_ERROR().
124 */
125GRN_API void
127GRN_API void
129
130/*
131 Don't use GRN_PLUGIN_SET_ERROR() directly. This macro is used in
132 GRN_PLUGIN_ERROR().
133 */
134#define GRN_PLUGIN_SET_ERROR(ctx, level, error_code, ...) \
135 do { \
136 grn_plugin_set_error(ctx, \
137 level, \
138 error_code, \
139 __FILE__, \
140 __LINE__, \
141 __FUNCTION__, \
142 __VA_ARGS__); \
143 } while (0)
144
145#define GRN_PLUGIN_ERROR(ctx, error_code, ...) \
146 GRN_PLUGIN_SET_ERROR(ctx, GRN_LOG_ERROR, error_code, __VA_ARGS__)
147
148#define GRN_PLUGIN_CLEAR_ERROR(ctx) \
149 do { \
150 grn_plugin_clear_error((ctx)); \
151 } while (0)
152
153typedef struct _grn_plugin_mutex grn_plugin_mutex;
154
170
171/*
172 grn_plugin_mutex_create() is deprecated. Use grn_plugin_mutex_open()
173 instead.
174*/
177
178GRN_API void
180
181/*
182 grn_plugin_mutex_destroy() is deprecated. Use grn_plugin_mutex_close()
183 instead.
184*/
185GRN_API void
187
188GRN_API void
190
191GRN_API void
193
196 grn_user_data *user_data,
197 grn_id domain,
198 unsigned char flags);
199
202
205 grn_user_data *user_data,
206 const char *name,
207 int name_size);
208GRN_API bool
210 grn_user_data *user_data,
211 const char *name,
212 int name_size,
213 bool default_value);
214GRN_API int32_t
216 grn_user_data *user_data,
217 const char *name,
218 int name_size,
219 int32_t default_value);
220GRN_API double
222 grn_user_data *user_data,
223 const char *name,
224 int name_size,
225 double default_value);
226GRN_API const char *
228 grn_user_data *user_data,
229 const char *name,
230 int name_size,
231 size_t *size);
234 grn_user_data *user_data,
235 const char *name,
236 int name_size,
237 grn_content_type default_value);
261 grn_user_data *user_data,
262 const char *name,
263 int name_size,
264 grn_log_level default_value);
265
268 grn_user_data *user_data,
269 unsigned int offset);
270
273
274/* Deprecated since 5.0.9. Use grn_plugin_windows_base_dir() instead. */
275GRN_API const char *
277GRN_API const char *
279
280GRN_API int
282 const char *str_ptr,
283 unsigned int str_length,
284 grn_encoding encoding);
285
286GRN_API int
288 const char *str_ptr,
289 unsigned int str_length,
290 grn_encoding encoding);
291
294 grn_expr_var *var,
295 const char *name,
296 int name_size);
297
300 const char *name,
301 int name_size,
302 grn_proc_func func,
303 unsigned int n_vars,
304 grn_expr_var *vars);
305
306GRN_API bool
308 grn_obj *value,
309 bool default_value,
310 const char *tag);
311GRN_API int32_t
313 grn_obj *value,
314 int32_t default_value_raw,
315 const char *tag);
316GRN_API int64_t
318 grn_obj *value,
319 int64_t default_value_raw,
320 const char *tag);
321GRN_API double
323 grn_obj *value,
324 double default_value_raw,
325 const char *tag);
328 grn_obj *value,
329 grn_operator default_mode,
330 const char *tag);
333 grn_obj *value,
334 grn_operator default_oeprator,
335 const char *tag);
336
337#ifdef __cplusplus
338}
339#endif
grn_rc
Definition groonga.h:61
grn_obj * grn_proc_func(grn_ctx *ctx, int nargs, grn_obj **args, grn_user_data *user_data)
Definition groonga.h:346
uint32_t grn_id
Definition groonga.h:44
#define GRN_API
Definition groonga.h:39
grn_operator
Definition groonga.h:1149
grn_log_level
Definition groonga.h:192
#define GRN_ATTRIBUTE_PRINTF(fmt_pos)
Definition groonga.h:2426
grn_content_type
The input/output content format.
Definition groonga.h:225
#define GRN_ATTRIBUTE_ALLOC_SIZE(size)
Definition groonga.h:2443
grn_encoding
Definition groonga.h:163
GRN_API const char * grn_plugin_proc_get_var_string(grn_ctx *ctx, grn_user_data *user_data, const char *name, int name_size, size_t *size)
GRN_API void grn_plugin_set_error(grn_ctx *ctx, grn_log_level level, grn_rc error_code, const char *file, int line, const char *func, const char *format,...) GRN_ATTRIBUTE_PRINTF(7)
GRN_API int grn_plugin_isspace(grn_ctx *ctx, const char *str_ptr, unsigned int str_length, grn_encoding encoding)
GRN_API int32_t grn_plugin_proc_get_value_int32(grn_ctx *ctx, grn_obj *value, int32_t default_value_raw, const char *tag)
GRN_API void grn_plugin_backtrace(grn_ctx *ctx)
#define GRN_PLUGIN_FIN
Definition plugin.h:45
GRN_API grn_obj * grn_plugin_proc_get_var(grn_ctx *ctx, grn_user_data *user_data, const char *name, int name_size)
#define GRN_PLUGIN_EXPORT
Definition plugin.h:50
GRN_API grn_operator grn_plugin_proc_get_value_operator(grn_ctx *ctx, grn_obj *value, grn_operator default_oeprator, const char *tag)
#define GRN_PLUGIN_REGISTER
Definition plugin.h:44
GRN_API void grn_plugin_mutex_unlock(grn_ctx *ctx, grn_plugin_mutex *mutex)
GRN_API void grn_plugin_mutex_destroy(grn_ctx *ctx, grn_plugin_mutex *mutex)
GRN_API grn_obj * grn_plugin_proc_get_vars(grn_ctx *ctx, grn_user_data *user_data)
GRN_API void grn_plugin_mutex_lock(grn_ctx *ctx, grn_plugin_mutex *mutex)
GRN_API grn_obj * grn_plugin_command_create(grn_ctx *ctx, const char *name, int name_size, grn_proc_func func, unsigned int n_vars, grn_expr_var *vars)
GRN_API const char * grn_plugin_win32_base_dir(void)
GRN_API grn_obj * grn_plugin_proc_get_var_by_offset(grn_ctx *ctx, grn_user_data *user_data, unsigned int offset)
GRN_API void grn_plugin_mutex_close(grn_ctx *ctx, grn_plugin_mutex *mutex)
GRN_API void * grn_plugin_calloc(grn_ctx *ctx, size_t size, const char *file, int line, const char *func) GRN_ATTRIBUTE_ALLOC_SIZE(2)
GRN_API const char * grn_plugin_windows_base_dir(void)
GRN_API void grn_plugin_free(grn_ctx *ctx, void *ptr, const char *file, int line, const char *func)
GRN_API grn_obj * grn_plugin_proc_get_caller(grn_ctx *ctx, grn_user_data *user_data)
GRN_API int32_t grn_plugin_proc_get_var_int32(grn_ctx *ctx, grn_user_data *user_data, const char *name, int name_size, int32_t default_value)
GRN_API grn_plugin_mutex * grn_plugin_mutex_open(grn_ctx *ctx)
Create a new object of grn_plugin_mutex.
GRN_API int64_t grn_plugin_proc_get_value_int64(grn_ctx *ctx, grn_obj *value, int64_t default_value_raw, const char *tag)
GRN_API grn_plugin_mutex * grn_plugin_mutex_create(grn_ctx *ctx)
GRN_API grn_content_type grn_plugin_proc_get_var_content_type(grn_ctx *ctx, grn_user_data *user_data, const char *name, int name_size, grn_content_type default_value)
GRN_API void * grn_plugin_realloc(grn_ctx *ctx, void *ptr, size_t size, const char *file, int line, const char *func) GRN_ATTRIBUTE_ALLOC_SIZE(3)
GRN_API double grn_plugin_proc_get_value_double(grn_ctx *ctx, grn_obj *value, double default_value_raw, const char *tag)
GRN_API void grn_plugin_logtrace(grn_ctx *ctx, grn_log_level level)
GRN_API int grn_plugin_charlen(grn_ctx *ctx, const char *str_ptr, unsigned int str_length, grn_encoding encoding)
struct _grn_plugin_mutex grn_plugin_mutex
Definition plugin.h:153
GRN_API grn_operator grn_plugin_proc_get_value_mode(grn_ctx *ctx, grn_obj *value, grn_operator default_mode, const char *tag)
GRN_API bool grn_plugin_proc_get_value_bool(grn_ctx *ctx, grn_obj *value, bool default_value, const char *tag)
GRN_API grn_rc grn_plugin_expr_var_init(grn_ctx *ctx, grn_expr_var *var, const char *name, int name_size)
#define GRN_PLUGIN_INIT
Definition plugin.h:43
GRN_API void grn_plugin_clear_error(grn_ctx *ctx)
GRN_API grn_obj * grn_plugin_proc_alloc(grn_ctx *ctx, grn_user_data *user_data, grn_id domain, unsigned char flags)
GRN_API void * grn_plugin_malloc(grn_ctx *ctx, size_t size, const char *file, int line, const char *func) GRN_ATTRIBUTE_ALLOC_SIZE(2)
GRN_API double grn_plugin_proc_get_var_double(grn_ctx *ctx, grn_user_data *user_data, const char *name, int name_size, double default_value)
GRN_API bool grn_plugin_proc_get_var_bool(grn_ctx *ctx, grn_user_data *user_data, const char *name, int name_size, bool default_value)
GRN_API grn_log_level grn_plugin_proc_get_var_log_level(grn_ctx *ctx, grn_user_data *user_data, const char *name, int name_size, grn_log_level default_value)
Get the specified command argument value as grn_log_level.
Definition groonga.h:351
Definition groonga.h:919
Definition groonga.h:1139
Definition groonga.h:339