17
17
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
20
#ifndef DRIZZLED_PLUGIN_H
21
#define DRIZZLED_PLUGIN_H
23
#include <boost/program_options.hpp>
24
#include <boost/filesystem.hpp>
26
#include <drizzled/module/manifest.h>
27
#include <drizzled/module/module.h>
28
#include <drizzled/plugin/version.h>
29
#include <drizzled/module/context.h>
30
#include <drizzled/definitions.h>
32
#include <drizzled/lex_string.h>
33
#include <drizzled/sys_var.h>
34
#include <drizzled/xid.h>
36
#include <drizzled/visibility.h>
23
#include <drizzled/global.h>
43
struct charset_info_st;
28
#define DRIZZLE_THD THD*
30
#define DRIZZLE_THD void*
33
#define DRIZZLE_XIDDATASIZE 128
35
struct st_mysql_xid is binary compatible with the XID structure as
36
in the X/Open CAE Specification, Distributed Transaction Processing:
37
The XA Specification, X/Open Company Ltd., 1991.
38
http://www.opengroup.org/bookstore/catalog/c193.htm
40
@see XID in sql/handler.h
46
char data[DRIZZLE_XIDDATASIZE]; /* Not \0-terminated */
48
typedef struct st_mysql_xid DRIZZLE_XID;
45
50
/*************************************************************************
46
51
Plugin API. Common for all plugin types.
53
extern boost::filesystem::path plugin_dir;
55
namespace plugin { class StorageEngine; }
58
Macros for beginning and ending plugin declarations. Between
59
DRIZZLE_DECLARE_PLUGIN and DRIZZLE_DECLARE_PLUGIN_END there should
60
be a module::Manifest for each plugin to be declared.
64
#define PANDORA_CPP_NAME(x) _drizzled_ ## x ## _plugin_
65
#define PANDORA_PLUGIN_NAME(x) PANDORA_CPP_NAME(x)
66
#define DRIZZLE_DECLARE_PLUGIN \
67
DRIZZLED_API ::drizzled::module::Manifest PANDORA_PLUGIN_NAME(PANDORA_MODULE_NAME)=
70
#define DRIZZLE_DECLARE_PLUGIN_END
71
#define DRIZZLE_PLUGIN(init,system,options) \
72
DRIZZLE_DECLARE_PLUGIN \
75
STRINGIFY_ARG(PANDORA_MODULE_NAME), \
76
STRINGIFY_ARG(PANDORA_MODULE_VERSION), \
77
STRINGIFY_ARG(PANDORA_MODULE_AUTHOR), \
78
STRINGIFY_ARG(PANDORA_MODULE_TITLE), \
79
PANDORA_MODULE_LICENSE, \
81
STRINGIFY_ARG(PANDORA_MODULE_DEPENDENCIES), \
55
The allowable types of plugins
57
#define DRIZZLE_DAEMON_PLUGIN 0 /* Daemon / Raw */
58
#define DRIZZLE_STORAGE_ENGINE_PLUGIN 1 /* Storage Engine */
59
#define DRIZZLE_INFORMATION_SCHEMA_PLUGIN 2 /* Information Schema */
60
#define DRIZZLE_UDF_PLUGIN 3 /* User-Defined Function */
61
#define DRIZZLE_UDA_PLUGIN 4 /* User-Defined Aggregate function */
62
#define DRIZZLE_AUDIT_PLUGIN 5 /* Audit */
63
#define DRIZZLE_LOGGER_PLUGIN 6 /* Logging */
64
#define DRIZZLE_AUTH_PLUGIN 7 /* Authorization */
66
#define DRIZZLE_MAX_PLUGIN_TYPE_NUM 8 /* The number of plugin types */
68
/* We use the following strings to define licenses for plugins */
69
#define PLUGIN_LICENSE_PROPRIETARY 0
70
#define PLUGIN_LICENSE_GPL 1
71
#define PLUGIN_LICENSE_BSD 2
73
#define PLUGIN_LICENSE_PROPRIETARY_STRING "PROPRIETARY"
74
#define PLUGIN_LICENSE_GPL_STRING "GPL"
75
#define PLUGIN_LICENSE_BSD_STRING "BSD"
78
Macros for beginning and ending plugin declarations. Between
79
mysql_declare_plugin and mysql_declare_plugin_end there should
80
be a st_mysql_plugin struct for each plugin to be declared.
84
#ifndef DRIZZLE_DYNAMIC_PLUGIN
85
#define __DRIZZLE_DECLARE_PLUGIN(NAME, DECLS) \
86
struct st_mysql_plugin DECLS[]= {
88
#define __DRIZZLE_DECLARE_PLUGIN(NAME, DECLS) \
89
struct st_mysql_plugin _mysql_plugin_declarations_[]= {
92
#define mysql_declare_plugin(NAME) \
93
__DRIZZLE_DECLARE_PLUGIN(NAME, \
94
builtin_ ## NAME ## _plugin)
96
#define mysql_declare_plugin_end ,{0,0,0,0,0,0,0,0,0,0,0}}
99
declarations for SHOW STATUS support in plugins
101
enum enum_mysql_show_type
103
SHOW_UNDEF, SHOW_BOOL, SHOW_INT, SHOW_LONG,
104
SHOW_LONGLONG, SHOW_CHAR, SHOW_CHAR_PTR,
105
SHOW_ARRAY, SHOW_FUNC, SHOW_DOUBLE
108
struct st_mysql_show_var {
111
enum enum_mysql_show_type type;
115
#define SHOW_VAR_FUNC_BUFF_SIZE 1024
116
typedef int (*mysql_show_var_func)(DRIZZLE_THD, struct st_mysql_show_var*, char *);
118
struct st_show_var_func_container {
119
mysql_show_var_func func;
87
122
declarations for server variables and command line options
125
162
automatically at the end of the statement.
128
typedef int (*var_check_func)(Session *session,
129
drizzle_sys_var *var,
130
void *save, drizzle_value *value);
165
typedef int (*mysql_var_check_func)(DRIZZLE_THD thd,
166
struct st_mysql_sys_var *var,
167
void *save, struct st_mysql_value *value);
135
session thread handle
171
(*mysql_var_update_func)()
136
173
var dynamic variable being altered
137
174
var_ptr pointer to dynamic variable
138
175
save pointer to temporary storage
142
179
This function should use the validated value stored in the temporary store
143
180
and persist it in the provided pointer to the dynamic variable.
144
181
For example, strings may require memory to be allocated.
146
typedef void (*var_update_func)(Session *session,
147
drizzle_sys_var *var,
183
typedef void (*mysql_var_update_func)(DRIZZLE_THD thd,
184
struct st_mysql_sys_var *var,
148
185
void *var_ptr, const void *save);
153
skeleton of a plugin variable - portion of structure common to all.
155
struct drizzle_sys_var
188
/* the following declarations are for internal use only */
191
#define PLUGIN_VAR_MASK \
192
(PLUGIN_VAR_READONLY | PLUGIN_VAR_NOSYSVAR | \
193
PLUGIN_VAR_NOCMDOPT | PLUGIN_VAR_NOCMDARG | \
194
PLUGIN_VAR_OPCMDARG | PLUGIN_VAR_RQCMDARG | PLUGIN_VAR_MEMALLOC)
196
#define DRIZZLE_PLUGIN_VAR_HEADER \
199
const char *comment; \
200
mysql_var_check_func check; \
201
mysql_var_update_func update
203
#define DRIZZLE_SYSVAR_NAME(name) mysql_sysvar_ ## name
204
#define DRIZZLE_SYSVAR(name) \
205
((struct st_mysql_sys_var *)&(DRIZZLE_SYSVAR_NAME(name)))
208
for global variables, the value pointer is the first
209
element after the header, the default value is the second.
210
for thread variables, the value offset is the first
211
element after the header, the default value is the second.
215
#define DECLARE_DRIZZLE_SYSVAR_BASIC(name, type) struct { \
216
DRIZZLE_PLUGIN_VAR_HEADER; \
218
const type def_val; \
219
} DRIZZLE_SYSVAR_NAME(name)
221
#define DECLARE_DRIZZLE_SYSVAR_SIMPLE(name, type) struct { \
222
DRIZZLE_PLUGIN_VAR_HEADER; \
223
type *value; type def_val; \
224
type min_val; type max_val; \
226
} DRIZZLE_SYSVAR_NAME(name)
228
#define DECLARE_DRIZZLE_SYSVAR_TYPELIB(name, type) struct { \
229
DRIZZLE_PLUGIN_VAR_HEADER; \
230
type *value; type def_val; \
232
} DRIZZLE_SYSVAR_NAME(name)
234
#define DECLARE_THDVAR_FUNC(type) \
235
type *(*resolve)(DRIZZLE_THD thd, int offset)
237
#define DECLARE_DRIZZLE_THDVAR_BASIC(name, type) struct { \
238
DRIZZLE_PLUGIN_VAR_HEADER; \
240
const type def_val; \
241
DECLARE_THDVAR_FUNC(type); \
242
} DRIZZLE_SYSVAR_NAME(name)
244
#define DECLARE_DRIZZLE_THDVAR_SIMPLE(name, type) struct { \
245
DRIZZLE_PLUGIN_VAR_HEADER; \
247
type def_val; type min_val; \
248
type max_val; type blk_sz; \
249
DECLARE_THDVAR_FUNC(type); \
250
} DRIZZLE_SYSVAR_NAME(name)
252
#define DECLARE_DRIZZLE_THDVAR_TYPELIB(name, type) struct { \
253
DRIZZLE_PLUGIN_VAR_HEADER; \
256
DECLARE_THDVAR_FUNC(type); \
258
} DRIZZLE_SYSVAR_NAME(name)
262
the following declarations are for use by plugin implementors
265
#define DRIZZLE_SYSVAR_BOOL(name, varname, opt, comment, check, update, def) \
266
DECLARE_DRIZZLE_SYSVAR_BASIC(name, bool) = { \
267
PLUGIN_VAR_BOOL | ((opt) & PLUGIN_VAR_MASK), \
268
#name, comment, check, update, &varname, def}
270
#define DRIZZLE_SYSVAR_STR(name, varname, opt, comment, check, update, def) \
271
DECLARE_DRIZZLE_SYSVAR_BASIC(name, char *) = { \
272
PLUGIN_VAR_STR | ((opt) & PLUGIN_VAR_MASK), \
273
#name, comment, check, update, &varname, def}
275
#define DRIZZLE_SYSVAR_INT(name, varname, opt, comment, check, update, def, min, max, blk) \
276
DECLARE_DRIZZLE_SYSVAR_SIMPLE(name, int) = { \
277
PLUGIN_VAR_INT | ((opt) & PLUGIN_VAR_MASK), \
278
#name, comment, check, update, &varname, def, min, max, blk }
280
#define DRIZZLE_SYSVAR_UINT(name, varname, opt, comment, check, update, def, min, max, blk) \
281
DECLARE_DRIZZLE_SYSVAR_SIMPLE(name, unsigned int) = { \
282
PLUGIN_VAR_INT | PLUGIN_VAR_UNSIGNED | ((opt) & PLUGIN_VAR_MASK), \
283
#name, comment, check, update, &varname, def, min, max, blk }
285
#define DRIZZLE_SYSVAR_LONG(name, varname, opt, comment, check, update, def, min, max, blk) \
286
DECLARE_DRIZZLE_SYSVAR_SIMPLE(name, long) = { \
287
PLUGIN_VAR_LONG | ((opt) & PLUGIN_VAR_MASK), \
288
#name, comment, check, update, &varname, def, min, max, blk }
290
#define DRIZZLE_SYSVAR_ULONG(name, varname, opt, comment, check, update, def, min, max, blk) \
291
DECLARE_DRIZZLE_SYSVAR_SIMPLE(name, unsigned long) = { \
292
PLUGIN_VAR_LONG | PLUGIN_VAR_UNSIGNED | ((opt) & PLUGIN_VAR_MASK), \
293
#name, comment, check, update, &varname, def, min, max, blk }
295
#define DRIZZLE_SYSVAR_LONGLONG(name, varname, opt, comment, check, update, def, min, max, blk) \
296
DECLARE_DRIZZLE_SYSVAR_SIMPLE(name, int64_t) = { \
297
PLUGIN_VAR_LONGLONG | ((opt) & PLUGIN_VAR_MASK), \
298
#name, comment, check, update, &varname, def, min, max, blk }
300
#define DRIZZLE_SYSVAR_ULONGLONG(name, varname, opt, comment, check, update, def, min, max, blk) \
301
DECLARE_DRIZZLE_SYSVAR_SIMPLE(name, uint64_t) = { \
302
PLUGIN_VAR_LONGLONG | PLUGIN_VAR_UNSIGNED | ((opt) & PLUGIN_VAR_MASK), \
303
#name, comment, check, update, &varname, def, min, max, blk }
305
#define DRIZZLE_SYSVAR_ENUM(name, varname, opt, comment, check, update, def, typelib) \
306
DECLARE_DRIZZLE_SYSVAR_TYPELIB(name, unsigned long) = { \
307
PLUGIN_VAR_ENUM | ((opt) & PLUGIN_VAR_MASK), \
308
#name, comment, check, update, &varname, def, typelib }
310
#define DRIZZLE_SYSVAR_SET(name, varname, opt, comment, check, update, def, typelib) \
311
DECLARE_DRIZZLE_SYSVAR_TYPELIB(name, uint64_t) = { \
312
PLUGIN_VAR_SET | ((opt) & PLUGIN_VAR_MASK), \
313
#name, comment, check, update, &varname, def, typelib }
315
#define DRIZZLE_THDVAR_BOOL(name, opt, comment, check, update, def) \
316
DECLARE_DRIZZLE_THDVAR_BASIC(name, char) = { \
317
PLUGIN_VAR_BOOL | PLUGIN_VAR_THDLOCAL | ((opt) & PLUGIN_VAR_MASK), \
318
#name, comment, check, update, -1, def, NULL}
320
#define DRIZZLE_THDVAR_STR(name, opt, comment, check, update, def) \
321
DECLARE_DRIZZLE_THDVAR_BASIC(name, char *) = { \
322
PLUGIN_VAR_STR | PLUGIN_VAR_THDLOCAL | ((opt) & PLUGIN_VAR_MASK), \
323
#name, comment, check, update, -1, def, NULL}
325
#define DRIZZLE_THDVAR_INT(name, opt, comment, check, update, def, min, max, blk) \
326
DECLARE_DRIZZLE_THDVAR_SIMPLE(name, int) = { \
327
PLUGIN_VAR_INT | PLUGIN_VAR_THDLOCAL | ((opt) & PLUGIN_VAR_MASK), \
328
#name, comment, check, update, -1, def, min, max, blk, NULL }
330
#define DRIZZLE_THDVAR_UINT(name, opt, comment, check, update, def, min, max, blk) \
331
DECLARE_DRIZZLE_THDVAR_SIMPLE(name, unsigned int) = { \
332
PLUGIN_VAR_INT | PLUGIN_VAR_THDLOCAL | PLUGIN_VAR_UNSIGNED | ((opt) & PLUGIN_VAR_MASK), \
333
#name, comment, check, update, -1, def, min, max, blk, NULL }
335
#define DRIZZLE_THDVAR_LONG(name, opt, comment, check, update, def, min, max, blk) \
336
DECLARE_DRIZZLE_THDVAR_SIMPLE(name, long) = { \
337
PLUGIN_VAR_LONG | PLUGIN_VAR_THDLOCAL | ((opt) & PLUGIN_VAR_MASK), \
338
#name, comment, check, update, -1, def, min, max, blk, NULL }
340
#define DRIZZLE_THDVAR_ULONG(name, opt, comment, check, update, def, min, max, blk) \
341
DECLARE_DRIZZLE_THDVAR_SIMPLE(name, unsigned long) = { \
342
PLUGIN_VAR_LONG | PLUGIN_VAR_THDLOCAL | PLUGIN_VAR_UNSIGNED | ((opt) & PLUGIN_VAR_MASK), \
343
#name, comment, check, update, -1, def, min, max, blk, NULL }
345
#define DRIZZLE_THDVAR_LONGLONG(name, opt, comment, check, update, def, min, max, blk) \
346
DECLARE_DRIZZLE_THDVAR_SIMPLE(name, int64_t) = { \
347
PLUGIN_VAR_LONGLONG | PLUGIN_VAR_THDLOCAL | ((opt) & PLUGIN_VAR_MASK), \
348
#name, comment, check, update, -1, def, min, max, blk, NULL }
350
#define DRIZZLE_THDVAR_ULONGLONG(name, opt, comment, check, update, def, min, max, blk) \
351
DECLARE_DRIZZLE_THDVAR_SIMPLE(name, uint64_t) = { \
352
PLUGIN_VAR_LONGLONG | PLUGIN_VAR_THDLOCAL | PLUGIN_VAR_UNSIGNED | ((opt) & PLUGIN_VAR_MASK), \
353
#name, comment, check, update, -1, def, min, max, blk, NULL }
355
#define DRIZZLE_THDVAR_ENUM(name, opt, comment, check, update, def, typelib) \
356
DECLARE_DRIZZLE_THDVAR_TYPELIB(name, unsigned long) = { \
357
PLUGIN_VAR_ENUM | PLUGIN_VAR_THDLOCAL | ((opt) & PLUGIN_VAR_MASK), \
358
#name, comment, check, update, -1, def, NULL, typelib }
360
#define DRIZZLE_THDVAR_SET(name, opt, comment, check, update, def, typelib) \
361
DECLARE_DRIZZLE_THDVAR_TYPELIB(name, uint64_t) = { \
362
PLUGIN_VAR_SET | PLUGIN_VAR_THDLOCAL | ((opt) & PLUGIN_VAR_MASK), \
363
#name, comment, check, update, -1, def, NULL, typelib }
365
/* accessor macros */
367
#define SYSVAR(name) \
368
(*(DRIZZLE_SYSVAR_NAME(name).value))
370
/* when thd == null, result points to global value */
371
#define THDVAR(thd, name) \
372
(*(DRIZZLE_SYSVAR_NAME(name).resolve(thd, DRIZZLE_SYSVAR_NAME(name).offset)))
376
Plugin description structure.
379
struct st_mysql_plugin
381
int type; /* the plugin type (a DRIZZLE_XXX_PLUGIN value) */
382
const char *name; /* plugin name (for SHOW PLUGINS) */
383
const char *version; /* plugin version (for SHOW PLUGINS) */
384
const char *author; /* plugin author (for SHOW PLUGINS) */
385
const char *descr; /* general descriptive text (for SHOW PLUGINS ) */
386
int license; /* the plugin license (PLUGIN_LICENSE_XXX) */
387
int (*init)(void *); /* the function to invoke when plugin is loaded */
388
int (*deinit)(void *);/* the function to invoke when plugin is unloaded */
389
struct st_mysql_show_var *status_vars;
390
struct st_mysql_sys_var **system_vars;
391
void * __reserved1; /* reserved for dependency checking */
159
void plugin_opt_set_limits(option *options, const drizzle_sys_var *opt);
397
/*************************************************************************
398
st_mysql_value struct for reading values from mysqld.
399
Used by server variables framework to parse user-provided values.
400
Will be used for arguments when implementing UDFs.
402
Note that val_str() returns a string in temporary memory
403
that will be freed at the end of statement. Copy the string
404
if you need it to persist.
407
#define DRIZZLE_VALUE_TYPE_STRING 0
408
#define DRIZZLE_VALUE_TYPE_REAL 1
409
#define DRIZZLE_VALUE_TYPE_INT 2
411
struct st_mysql_value
163
int (*value_type)(drizzle_value *);
164
const char *(*val_str)(drizzle_value *, char *buffer, int *length);
165
int (*val_real)(drizzle_value *, double *realbuf);
166
int (*val_int)(drizzle_value *, int64_t *intbuf);
413
int (*value_type)(struct st_mysql_value *);
414
const char *(*val_str)(struct st_mysql_value *, char *buffer, int *length);
415
int (*val_real)(struct st_mysql_value *, double *realbuf);
416
int (*val_int)(struct st_mysql_value *, int64_t *intbuf);