summaryrefslogtreecommitdiff
path: root/storage/mroonga/vendor/groonga/include/groonga/plugin.h
blob: d241444549ff8327aa9597e38400b57341a8153a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
/* -*- c-basic-offset: 2 -*- */
/*
  Copyright(C) 2010-2017 Brazil

  This library is free software; you can redistribute it and/or
  modify it under the terms of the GNU Lesser General Public
  License version 2.1 as published by the Free Software Foundation.

  This library is distributed in the hope that it will be useful,
  but WITHOUT ANY WARRANTY; without even the implied warranty of
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  Lesser General Public License for more details.

  You should have received a copy of the GNU Lesser General Public
  License along with this library; if not, write to the Free Software
  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
*/

#pragma once

#include <stddef.h>

#include <groonga.h>

#ifdef __cplusplus
extern "C" {
#endif

# define GRN_PLUGIN_IMPL_NAME_RAW(type)         \
  grn_plugin_impl_ ## type
# define GRN_PLUGIN_IMPL_NAME_TAGGED(type, tag) \
  GRN_PLUGIN_IMPL_NAME_RAW(type ## _ ## tag)
# define GRN_PLUGIN_IMPL_NAME_TAGGED_EXPANDABLE(type, tag)      \
  GRN_PLUGIN_IMPL_NAME_TAGGED(type, tag)

#ifdef GRN_PLUGIN_FUNCTION_TAG
# define GRN_PLUGIN_IMPL_NAME(type)                             \
  GRN_PLUGIN_IMPL_NAME_TAGGED_EXPANDABLE(type, GRN_PLUGIN_FUNCTION_TAG)
#else /* GRN_PLUGIN_FUNCTION_TAG */
# define GRN_PLUGIN_IMPL_NAME(type)             \
  GRN_PLUGIN_IMPL_NAME_RAW(type)
#endif /* GRN_PLUGIN_FUNCTION_TAG */

#define GRN_PLUGIN_INIT     GRN_PLUGIN_IMPL_NAME(init)
#define GRN_PLUGIN_REGISTER GRN_PLUGIN_IMPL_NAME(register)
#define GRN_PLUGIN_FIN      GRN_PLUGIN_IMPL_NAME(fin)

#if defined(_WIN32) || defined(_WIN64)
#  define GRN_PLUGIN_EXPORT __declspec(dllexport)
#else /* defined(_WIN32) || defined(_WIN64) */
#  define GRN_PLUGIN_EXPORT
#endif /* defined(_WIN32) || defined(_WIN64) */

GRN_PLUGIN_EXPORT grn_rc GRN_PLUGIN_INIT(grn_ctx *ctx);
GRN_PLUGIN_EXPORT grn_rc GRN_PLUGIN_REGISTER(grn_ctx *ctx);
GRN_PLUGIN_EXPORT grn_rc GRN_PLUGIN_FIN(grn_ctx *ctx);

#define GRN_PLUGIN_DECLARE_FUNCTIONS(tag)                               \
  extern grn_rc GRN_PLUGIN_IMPL_NAME_TAGGED(init, tag)(grn_ctx *ctx);   \
  extern grn_rc GRN_PLUGIN_IMPL_NAME_TAGGED(register, tag)(grn_ctx *ctx); \
  extern grn_rc GRN_PLUGIN_IMPL_NAME_TAGGED(fin, tag)(grn_ctx *ctx)

/*
  Don't call these functions directly. Use GRN_PLUGIN_MALLOC(),
  GRN_PLUGIN_CALLOC(), GRN_PLUGIN_REALLOC() and GRN_PLUGIN_FREE() instead.
 */
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 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 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 void grn_plugin_free(grn_ctx *ctx, void *ptr, const char *file,
                             int line, const char *func);

#define GRN_PLUGIN_MALLOC(ctx, size) \
  grn_plugin_malloc((ctx), (size), __FILE__, __LINE__, __FUNCTION__)
#define GRN_PLUGIN_MALLOCN(ctx, type, n) \
  ((type *)(grn_plugin_malloc((ctx), sizeof(type) * (n), \
                              __FILE__, __LINE__, __FUNCTION__)))
#define GRN_PLUGIN_CALLOC(ctx, size) \
  grn_plugin_calloc((ctx), (size), __FILE__, __LINE__, __FUNCTION__)
#define GRN_PLUGIN_REALLOC(ctx, ptr, size) \
  grn_plugin_realloc((ctx), (ptr), (size), __FILE__, __LINE__, __FUNCTION__)
#define GRN_PLUGIN_FREE(ctx, ptr) \
  grn_plugin_free((ctx), (ptr), __FILE__, __LINE__, __FUNCTION__)

#define GRN_PLUGIN_LOG(ctx, level, ...) \
  GRN_LOG((ctx), (level), __VA_ARGS__)

/*
  Don't call grn_plugin_set_error() directly. This function is used in
  GRN_PLUGIN_SET_ERROR().
 */
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 void grn_plugin_clear_error(grn_ctx *ctx);


/*
  Don't call these functions directly. grn_plugin_backtrace() and
  grn_plugin_logtrace() are used in GRN_PLUGIN_SET_ERROR().
 */
GRN_API void grn_plugin_backtrace(grn_ctx *ctx);
GRN_API void grn_plugin_logtrace(grn_ctx *ctx, grn_log_level level);

/*
  Don't use GRN_PLUGIN_SET_ERROR() directly. This macro is used in
  GRN_PLUGIN_ERROR().
 */
#define GRN_PLUGIN_SET_ERROR(ctx, level, error_code, ...) do { \
  grn_plugin_set_error(ctx, level, error_code, \
                       __FILE__, __LINE__, __FUNCTION__, __VA_ARGS__); \
} while (0)

#define GRN_PLUGIN_ERROR(ctx, error_code, ...) \
  GRN_PLUGIN_SET_ERROR(ctx, GRN_LOG_ERROR, error_code, __VA_ARGS__)

#define GRN_PLUGIN_CLEAR_ERROR(ctx) do { \
  grn_plugin_clear_error((ctx)); \
} while (0)

typedef struct _grn_plugin_mutex grn_plugin_mutex;

GRN_API grn_plugin_mutex *grn_plugin_mutex_open(grn_ctx *ctx);

/*
  grn_plugin_mutex_create() is deprecated. Use grn_plugin_mutex_open()
  instead.
*/
GRN_API grn_plugin_mutex *grn_plugin_mutex_create(grn_ctx *ctx);

GRN_API void grn_plugin_mutex_close(grn_ctx *ctx, grn_plugin_mutex *mutex);

/*
  grn_plugin_mutex_destroy() is deprecated. Use grn_plugin_mutex_close()
  instead.
*/
GRN_API void grn_plugin_mutex_destroy(grn_ctx *ctx, grn_plugin_mutex *mutex);

GRN_API void grn_plugin_mutex_lock(grn_ctx *ctx, grn_plugin_mutex *mutex);

GRN_API void grn_plugin_mutex_unlock(grn_ctx *ctx, grn_plugin_mutex *mutex);

GRN_API grn_obj *grn_plugin_proc_alloc(grn_ctx *ctx, grn_user_data *user_data,
                                       grn_id domain, unsigned char flags);

GRN_API grn_obj *grn_plugin_proc_get_vars(grn_ctx *ctx, grn_user_data *user_data);

GRN_API grn_obj *grn_plugin_proc_get_var(grn_ctx *ctx, grn_user_data *user_data,
                                         const char *name, int name_size);
GRN_API grn_bool grn_plugin_proc_get_var_bool(grn_ctx *ctx,
                                              grn_user_data *user_data,
                                              const char *name,
                                              int name_size,
                                              grn_bool default_value);
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 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 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 grn_obj *grn_plugin_proc_get_var_by_offset(grn_ctx *ctx,
                                                   grn_user_data *user_data,
                                                   unsigned int offset);

GRN_API grn_obj *grn_plugin_proc_get_caller(grn_ctx *ctx,
                                            grn_user_data *user_data);

/* Deprecated since 5.0.9. Use grn_plugin_windows_base_dir() instead. */
GRN_API const char *grn_plugin_win32_base_dir(void);
GRN_API const char *grn_plugin_windows_base_dir(void);

GRN_API int grn_plugin_charlen(grn_ctx *ctx, const char *str_ptr,
                               unsigned int str_length, grn_encoding encoding);

GRN_API int grn_plugin_isspace(grn_ctx *ctx, const char *str_ptr,
                               unsigned int str_length, grn_encoding encoding);

GRN_API grn_rc grn_plugin_expr_var_init(grn_ctx *ctx,
                                        grn_expr_var *var,
                                        const char *name,
                                        int name_size);

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);


#ifdef __cplusplus
}
#endif