1 /* -*- c-basic-offset: 2 -*- */
2 /*
3   Copyright(C) 2010-2017 Brazil
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 version 2.1 as published by the Free Software Foundation.
8 
9   This library is distributed in the hope that it will be useful,
10   but WITHOUT ANY WARRANTY; without even the implied warranty of
11   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12   Lesser General Public License for more details.
13 
14   You should have received a copy of the GNU Lesser General Public
15   License along with this library; if not, write to the Free Software
16   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
17 */
18 module groonga_d.plugin;
19 
20 
21 private static import groonga_d.groonga;
22 
23 extern(C):
24 nothrow @nogc:
25 
26 /+
27 #include <stddef.h>
28 
29 #include <groonga.h>
30 
31 # define GRN_PLUGIN_IMPL_NAME_RAW(type) grn_plugin_impl_ ## type
32 # define GRN_PLUGIN_IMPL_NAME_TAGGED(type, tag) GRN_PLUGIN_IMPL_NAME_RAW(type ## _ ## tag)
33 # define GRN_PLUGIN_IMPL_NAME_TAGGED_EXPANDABLE(type, tag) GRN_PLUGIN_IMPL_NAME_TAGGED(type, tag)
34 
35 #ifdef GRN_PLUGIN_FUNCTION_TAG
36 	# define GRN_PLUGIN_IMPL_NAME(type) GRN_PLUGIN_IMPL_NAME_TAGGED_EXPANDABLE(type, GRN_PLUGIN_FUNCTION_TAG)
37 #else
38 	# define GRN_PLUGIN_IMPL_NAME(type) GRN_PLUGIN_IMPL_NAME_RAW(type)
39 #endif
40 
41 #define GRN_PLUGIN_INIT     GRN_PLUGIN_IMPL_NAME(init)
42 #define GRN_PLUGIN_REGISTER GRN_PLUGIN_IMPL_NAME(register)
43 #define GRN_PLUGIN_FIN      GRN_PLUGIN_IMPL_NAME(fin)
44 
45 #if defined(_WIN32) || defined(_WIN64)
46 	#  define GRN_PLUGIN_EXPORT __declspec(dllexport)
47 #else
48 	#  define GRN_PLUGIN_EXPORT
49 #endif
50 +/
51 
52 //GRN_PLUGIN_EXPORT
53 export groonga_d.groonga.grn_rc GRN_PLUGIN_INIT(groonga_d.groonga.grn_ctx* ctx);
54 
55 //GRN_PLUGIN_EXPORT
56 export groonga_d.groonga.grn_rc GRN_PLUGIN_REGISTER(groonga_d.groonga.grn_ctx* ctx);
57 
58 //GRN_PLUGIN_EXPORT
59 export groonga_d.groonga.grn_rc GRN_PLUGIN_FIN(groonga_d.groonga.grn_ctx* ctx);
60 
61 /+
62 #define GRN_PLUGIN_DECLARE_FUNCTIONS(tag) extern groonga_d.groonga.grn_rc GRN_PLUGIN_IMPL_NAME_TAGGED(init, tag)(groonga_d.groonga.grn_ctx *ctx); extern groonga_d.groonga.grn_rc GRN_PLUGIN_IMPL_NAME_TAGGED(register, tag)(groonga_d.groonga.grn_ctx *ctx); extern groonga_d.groonga.grn_rc GRN_PLUGIN_IMPL_NAME_TAGGED(fin, tag)(groonga_d.groonga.grn_ctx *ctx)
63 +/
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  */
69 
70 /+
71 //GRN_API
72 void* grn_plugin_malloc(groonga_d.groonga.grn_ctx* ctx, size_t size, const (char)* file, int line, const (char)* func) GRN_ATTRIBUTE_ALLOC_SIZE(2);
73 
74 //GRN_API
75 void* grn_plugin_calloc(groonga_d.groonga.grn_ctx* ctx, size_t size, const (char)* file, int line, const (char)* func) GRN_ATTRIBUTE_ALLOC_SIZE(2);
76 
77 //GRN_API
78 void* grn_plugin_realloc(groonga_d.groonga.grn_ctx* ctx, void* ptr_, size_t size, const (char)* file, int line, const (char)* func) GRN_ATTRIBUTE_ALLOC_SIZE(3);
79 
80 //GRN_API
81 void grn_plugin_free(groonga_d.groonga.grn_ctx* ctx, void* ptr_, const (char)* file, int line, const (char)* func);
82 +/
83 
84 /+
85 #define GRN_PLUGIN_MALLOC(ctx, size) grn_plugin_malloc((ctx), (size), __FILE__, __LINE__, __FUNCTION__)
86 #define GRN_PLUGIN_MALLOCN(ctx, type, n) ((type *)(grn_plugin_malloc((ctx), type.sizeof * (n), __FILE__, __LINE__, __FUNCTION__)))
87 #define GRN_PLUGIN_CALLOC(ctx, size) grn_plugin_calloc((ctx), (size), __FILE__, __LINE__, __FUNCTION__)
88 #define GRN_PLUGIN_REALLOC(ctx, ptr_, size) grn_plugin_realloc((ctx), (ptr_), (size), __FILE__, __LINE__, __FUNCTION__)
89 #define GRN_PLUGIN_FREE(ctx, ptr_) grn_plugin_free((ctx), (ptr_), __FILE__, __LINE__, __FUNCTION__)
90 
91 #define GRN_PLUGIN_LOG(ctx, level, ...) groonga_d.groonga.GRN_LOG((ctx), (level), __VA_ARGS__)
92 +/
93 
94 /*
95   Don't call grn_plugin_set_error() directly. This function is used in
96   GRN_PLUGIN_SET_ERROR().
97  */
98 
99 /+
100 //GRN_API
101 void grn_plugin_set_error(groonga_d.groonga.grn_ctx* ctx, groonga_d.groonga.grn_log_level level, groonga_d.groonga.grn_rc error_code, const (char)* file, int line, const (char)* func, const (char)* format, ...) GRN_ATTRIBUTE_PRINTF(7);
102 +/
103 
104 //GRN_API
105 void grn_plugin_clear_error(groonga_d.groonga.grn_ctx* ctx);
106 
107 /*
108   Don't call these functions directly. grn_plugin_backtrace() and
109   grn_plugin_logtrace() are used in GRN_PLUGIN_SET_ERROR().
110  */
111 
112 //GRN_API
113 void grn_plugin_backtrace(groonga_d.groonga.grn_ctx* ctx);
114 
115 //GRN_API
116 void grn_plugin_logtrace(groonga_d.groonga.grn_ctx* ctx, groonga_d.groonga.grn_log_level level);
117 
118 /*
119   Don't use GRN_PLUGIN_SET_ERROR() directly. This macro is used in
120   GRN_PLUGIN_ERROR().
121  */
122 /+
123 #define GRN_PLUGIN_SET_ERROR(ctx, level, error_code, ...) grn_plugin_set_error(ctx, level, error_code, __FILE__, __LINE__, __FUNCTION__, __VA_ARGS__);
124 
125 #define GRN_PLUGIN_ERROR(ctx, error_code, ...) GRN_PLUGIN_SET_ERROR(ctx, groonga_d.groonga.grn_log_level.GRN_LOG_ERROR, error_code, __VA_ARGS__)
126 
127 #define GRN_PLUGIN_CLEAR_ERROR(ctx) grn_plugin_clear_error((ctx));
128 +/
129 
130 extern struct _grn_plugin_mutex;
131 alias grn_plugin_mutex = _grn_plugin_mutex;
132 
133 //GRN_API
134 grn_plugin_mutex* grn_plugin_mutex_open(groonga_d.groonga.grn_ctx* ctx);
135 
136 /*
137   grn_plugin_mutex_create() is deprecated. Use grn_plugin_mutex_open()
138   instead.
139 */
140 
141 //GRN_API
142 grn_plugin_mutex* grn_plugin_mutex_create(groonga_d.groonga.grn_ctx* ctx);
143 
144 //GRN_API
145 void grn_plugin_mutex_close(groonga_d.groonga.grn_ctx* ctx, grn_plugin_mutex* mutex);
146 
147 /*
148   grn_plugin_mutex_destroy() is deprecated. Use grn_plugin_mutex_close()
149   instead.
150 */
151 
152 //GRN_API
153 void grn_plugin_mutex_destroy(groonga_d.groonga.grn_ctx* ctx, grn_plugin_mutex* mutex);
154 
155 //GRN_API
156 void grn_plugin_mutex_lock(groonga_d.groonga.grn_ctx* ctx, grn_plugin_mutex* mutex);
157 
158 //GRN_API
159 void grn_plugin_mutex_unlock(groonga_d.groonga.grn_ctx* ctx, grn_plugin_mutex* mutex);
160 
161 //GRN_API
162 groonga_d.groonga.grn_obj* grn_plugin_proc_alloc(groonga_d.groonga.grn_ctx* ctx, groonga_d.groonga.grn_user_data* user_data, groonga_d.groonga.grn_id domain, ubyte flags);
163 
164 //GRN_API
165 groonga_d.groonga.grn_obj* grn_plugin_proc_get_vars(groonga_d.groonga.grn_ctx* ctx, groonga_d.groonga.grn_user_data* user_data);
166 
167 //GRN_API
168 groonga_d.groonga.grn_obj* grn_plugin_proc_get_var(groonga_d.groonga.grn_ctx* ctx, groonga_d.groonga.grn_user_data* user_data, const (char)* name, int name_size);
169 
170 //GRN_API
171 groonga_d.groonga.grn_bool grn_plugin_proc_get_var_bool(groonga_d.groonga.grn_ctx* ctx, groonga_d.groonga.grn_user_data* user_data, const (char)* name, int name_size, groonga_d.groonga.grn_bool default_value);
172 
173 //GRN_API
174 int grn_plugin_proc_get_var_int32(groonga_d.groonga.grn_ctx* ctx, groonga_d.groonga.grn_user_data* user_data, const (char)* name, int name_size, int default_value);
175 
176 //GRN_API
177 const (char)* grn_plugin_proc_get_var_string(groonga_d.groonga.grn_ctx* ctx, groonga_d.groonga.grn_user_data* user_data, const (char)* name, int name_size, size_t* size);
178 
179 //GRN_API
180 groonga_d.groonga.grn_content_type grn_plugin_proc_get_var_content_type(groonga_d.groonga.grn_ctx* ctx, groonga_d.groonga.grn_user_data* user_data, const (char)* name, int name_size, groonga_d.groonga.grn_content_type default_value);
181 
182 //GRN_API
183 groonga_d.groonga.grn_obj* grn_plugin_proc_get_var_by_offset(groonga_d.groonga.grn_ctx* ctx, groonga_d.groonga.grn_user_data* user_data, uint offset);
184 
185 //GRN_API
186 groonga_d.groonga.grn_obj* grn_plugin_proc_get_caller(groonga_d.groonga.grn_ctx* ctx, groonga_d.groonga.grn_user_data* user_data);
187 
188 /* Deprecated since 5.0.9. Use grn_plugin_windows_base_dir() instead. */
189 
190 //GRN_API
191 const (char)* grn_plugin_win32_base_dir();
192 
193 //GRN_API
194 const (char)* grn_plugin_windows_base_dir();
195 
196 //GRN_API
197 int grn_plugin_charlen(groonga_d.groonga.grn_ctx* ctx, const (char)* str_ptr, uint str_length, groonga_d.groonga.grn_encoding encoding);
198 
199 //GRN_API
200 int grn_plugin_isspace(groonga_d.groonga.grn_ctx* ctx, const (char)* str_ptr, uint str_length, groonga_d.groonga.grn_encoding encoding);
201 
202 //GRN_API
203 groonga_d.groonga.grn_rc grn_plugin_expr_var_init(groonga_d.groonga.grn_ctx* ctx, groonga_d.groonga.grn_expr_var* var, const (char)* name, int name_size);
204 
205 //GRN_API
206 groonga_d.groonga.grn_obj* grn_plugin_command_create(groonga_d.groonga.grn_ctx* ctx, const (char)* name, int name_size, groonga_d.groonga.grn_proc_func func, uint n_vars, groonga_d.groonga.grn_expr_var* vars);
207 
208 //GRN_API
209 bool grn_plugin_proc_get_value_bool(groonga_d.groonga.grn_ctx* ctx, groonga_d.groonga.grn_obj* value, bool default_value, const (char)* tag);
210 
211 //GRN_API
212 long grn_plugin_proc_get_value_int64(groonga_d.groonga.grn_ctx* ctx, groonga_d.groonga.grn_obj* value, long default_value_raw, const (char)* tag);
213 
214 //GRN_API
215 groonga_d.groonga.grn_operator grn_plugin_proc_get_value_mode(groonga_d.groonga.grn_ctx* ctx, groonga_d.groonga.grn_obj* value, groonga_d.groonga.grn_operator default_mode, const (char)* tag);
216 
217 //GRN_API
218 groonga_d.groonga.grn_operator grn_plugin_proc_get_value_operator(groonga_d.groonga.grn_ctx* ctx, groonga_d.groonga.grn_obj* value, groonga_d.groonga.grn_operator default_oeprator, const (char)* tag);
219