20
20
#ifndef DRIZZLED_PLUGIN_H
21
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/lex_string.h>
24
#include <drizzled/xid.h>
43
struct charset_info_st;
45
29
/*************************************************************************
46
30
Plugin API. Common for all plugin types.
53
extern boost::filesystem::path plugin_dir;
55
namespace plugin { class StorageEngine; }
58
35
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), \
36
drizzle_declare_plugin and drizzle_declare_plugin_end there should
37
be a drizzled::plugin::Manifest for each plugin to be declared.
41
#ifndef DRIZZLE_DYNAMIC_PLUGIN
42
#define __DRIZZLE_DECLARE_PLUGIN(NAME, DECLS) \
43
drizzled::plugin::Manifest DECLS[]= {
45
#define __DRIZZLE_DECLARE_PLUGIN(NAME, DECLS) \
46
drizzled::plugin::Manifest _drizzled_plugin_declaration_[]= {
49
#define drizzle_declare_plugin(NAME) \
50
__DRIZZLE_DECLARE_PLUGIN(NAME, \
51
builtin_ ## NAME ## _plugin)
53
#define drizzle_declare_plugin_end ,{0,0,0,0,PLUGIN_LICENSE_GPL,0,0,0,0,0}}
58
the following flags are valid for plugin_init()
60
#define PLUGIN_INIT_SKIP_DYNAMIC_LOADING 1
61
#define PLUGIN_INIT_SKIP_PLUGIN_TABLE 2
62
#define PLUGIN_INIT_SKIP_INITIALIZATION 4
64
#define INITIAL_LEX_PLUGIN_LIST_SIZE 16
67
declarations for SHOW STATUS support in plugins
69
enum enum_mysql_show_type
71
SHOW_UNDEF, SHOW_BOOL, SHOW_INT, SHOW_LONG,
72
SHOW_LONGLONG, SHOW_CHAR, SHOW_CHAR_PTR,
73
SHOW_ARRAY, SHOW_FUNC, SHOW_KEY_CACHE_LONG, SHOW_KEY_CACHE_LONGLONG,
74
SHOW_LONG_STATUS, SHOW_DOUBLE_STATUS, SHOW_HAVE,
75
SHOW_MY_BOOL, SHOW_HA_ROWS, SHOW_SYS, SHOW_INT_NOFLUSH,
76
SHOW_LONGLONG_STATUS, SHOW_DOUBLE, SHOW_SIZE
79
struct st_mysql_show_var {
82
enum enum_mysql_show_type type;
85
typedef enum enum_mysql_show_type SHOW_TYPE;
86
typedef struct st_mysql_show_var SHOW_VAR;
89
#define SHOW_VAR_FUNC_BUFF_SIZE 1024
90
typedef int (*mysql_show_var_func)(struct st_mysql_show_var *, char *);
92
struct st_show_var_func_container {
93
mysql_show_var_func func;
87
96
declarations for server variables and command line options
143
154
and persist it in the provided pointer to the dynamic variable.
144
155
For example, strings may require memory to be allocated.
146
typedef void (*var_update_func)(Session *session,
147
drizzle_sys_var *var,
157
typedef void (*mysql_var_update_func)(Session *session,
158
struct st_mysql_sys_var *var,
148
159
void *var_ptr, const void *save);
153
skeleton of a plugin variable - portion of structure common to all.
155
struct drizzle_sys_var
162
/* the following declarations are for internal use only */
165
#define PLUGIN_VAR_MASK \
166
(PLUGIN_VAR_READONLY | PLUGIN_VAR_NOSYSVAR | \
167
PLUGIN_VAR_NOCMDOPT | PLUGIN_VAR_NOCMDARG | \
168
PLUGIN_VAR_OPCMDARG | PLUGIN_VAR_RQCMDARG | PLUGIN_VAR_MEMALLOC)
170
#define DRIZZLE_PLUGIN_VAR_HEADER \
173
const char *comment; \
174
mysql_var_check_func check; \
175
mysql_var_update_func update
177
#define DRIZZLE_SYSVAR_NAME(name) mysql_sysvar_ ## name
178
#define DRIZZLE_SYSVAR(name) \
179
((struct st_mysql_sys_var *)&(DRIZZLE_SYSVAR_NAME(name)))
182
for global variables, the value pointer is the first
183
element after the header, the default value is the second.
184
for thread variables, the value offset is the first
185
element after the header, the default value is the second.
189
#define DECLARE_DRIZZLE_SYSVAR_BASIC(name, type) struct { \
190
DRIZZLE_PLUGIN_VAR_HEADER; \
192
const type def_val; \
193
} DRIZZLE_SYSVAR_NAME(name)
195
#define DECLARE_DRIZZLE_SYSVAR_SIMPLE(name, type) struct { \
196
DRIZZLE_PLUGIN_VAR_HEADER; \
197
type *value; type def_val; \
198
type min_val; type max_val; \
200
} DRIZZLE_SYSVAR_NAME(name)
202
#define DECLARE_DRIZZLE_SYSVAR_TYPELIB(name, type) struct { \
203
DRIZZLE_PLUGIN_VAR_HEADER; \
204
type *value; type def_val; \
206
} DRIZZLE_SYSVAR_NAME(name)
208
#define DECLARE_SessionVAR_FUNC(type) \
209
type *(*resolve)(Session *session, int offset)
211
#define DECLARE_DRIZZLE_SessionVAR_BASIC(name, type) struct { \
212
DRIZZLE_PLUGIN_VAR_HEADER; \
214
const type def_val; \
215
DECLARE_SessionVAR_FUNC(type); \
216
} DRIZZLE_SYSVAR_NAME(name)
218
#define DECLARE_DRIZZLE_SessionVAR_SIMPLE(name, type) struct { \
219
DRIZZLE_PLUGIN_VAR_HEADER; \
221
type def_val; type min_val; \
222
type max_val; type blk_sz; \
223
DECLARE_SessionVAR_FUNC(type); \
224
} DRIZZLE_SYSVAR_NAME(name)
226
#define DECLARE_DRIZZLE_SessionVAR_TYPELIB(name, type) struct { \
227
DRIZZLE_PLUGIN_VAR_HEADER; \
230
DECLARE_SessionVAR_FUNC(type); \
232
} DRIZZLE_SYSVAR_NAME(name)
236
the following declarations are for use by plugin implementors
239
#define DRIZZLE_SYSVAR_BOOL(name, varname, opt, comment, check, update, def) \
240
DECLARE_DRIZZLE_SYSVAR_BASIC(name, bool) = { \
241
PLUGIN_VAR_BOOL | ((opt) & PLUGIN_VAR_MASK), \
242
#name, comment, check, update, &varname, def}
244
#define DRIZZLE_SYSVAR_STR(name, varname, opt, comment, check, update, def) \
245
DECLARE_DRIZZLE_SYSVAR_BASIC(name, char *) = { \
246
PLUGIN_VAR_STR | ((opt) & PLUGIN_VAR_MASK), \
247
#name, comment, check, update, &varname, def}
249
#define DRIZZLE_SYSVAR_INT(name, varname, opt, comment, check, update, def, min, max, blk) \
250
DECLARE_DRIZZLE_SYSVAR_SIMPLE(name, int) = { \
251
PLUGIN_VAR_INT | ((opt) & PLUGIN_VAR_MASK), \
252
#name, comment, check, update, &varname, def, min, max, blk }
254
#define DRIZZLE_SYSVAR_UINT(name, varname, opt, comment, check, update, def, min, max, blk) \
255
DECLARE_DRIZZLE_SYSVAR_SIMPLE(name, unsigned int) = { \
256
PLUGIN_VAR_INT | PLUGIN_VAR_UNSIGNED | ((opt) & PLUGIN_VAR_MASK), \
257
#name, comment, check, update, &varname, def, min, max, blk }
259
#define DRIZZLE_SYSVAR_LONG(name, varname, opt, comment, check, update, def, min, max, blk) \
260
DECLARE_DRIZZLE_SYSVAR_SIMPLE(name, long) = { \
261
PLUGIN_VAR_LONG | ((opt) & PLUGIN_VAR_MASK), \
262
#name, comment, check, update, &varname, def, min, max, blk }
264
#define DRIZZLE_SYSVAR_ULONG(name, varname, opt, comment, check, update, def, min, max, blk) \
265
DECLARE_DRIZZLE_SYSVAR_SIMPLE(name, unsigned long) = { \
266
PLUGIN_VAR_LONG | PLUGIN_VAR_UNSIGNED | ((opt) & PLUGIN_VAR_MASK), \
267
#name, comment, check, update, &varname, def, min, max, blk }
269
#define DRIZZLE_SYSVAR_LONGLONG(name, varname, opt, comment, check, update, def, min, max, blk) \
270
DECLARE_DRIZZLE_SYSVAR_SIMPLE(name, int64_t) = { \
271
PLUGIN_VAR_LONGLONG | ((opt) & PLUGIN_VAR_MASK), \
272
#name, comment, check, update, &varname, def, min, max, blk }
274
#define DRIZZLE_SYSVAR_ULONGLONG(name, varname, opt, comment, check, update, def, min, max, blk) \
275
DECLARE_DRIZZLE_SYSVAR_SIMPLE(name, uint64_t) = { \
276
PLUGIN_VAR_LONGLONG | PLUGIN_VAR_UNSIGNED | ((opt) & PLUGIN_VAR_MASK), \
277
#name, comment, check, update, &varname, def, min, max, blk }
279
#define DRIZZLE_SYSVAR_ENUM(name, varname, opt, comment, check, update, def, typelib) \
280
DECLARE_DRIZZLE_SYSVAR_TYPELIB(name, unsigned long) = { \
281
PLUGIN_VAR_ENUM | ((opt) & PLUGIN_VAR_MASK), \
282
#name, comment, check, update, &varname, def, typelib }
284
#define DRIZZLE_SYSVAR_SET(name, varname, opt, comment, check, update, def, typelib) \
285
DECLARE_DRIZZLE_SYSVAR_TYPELIB(name, uint64_t) = { \
286
PLUGIN_VAR_SET | ((opt) & PLUGIN_VAR_MASK), \
287
#name, comment, check, update, &varname, def, typelib }
289
#define DRIZZLE_SessionVAR_BOOL(name, opt, comment, check, update, def) \
290
DECLARE_DRIZZLE_SessionVAR_BASIC(name, char) = { \
291
PLUGIN_VAR_BOOL | PLUGIN_VAR_SessionLOCAL | ((opt) & PLUGIN_VAR_MASK), \
292
#name, comment, check, update, -1, def, NULL}
294
#define DRIZZLE_SessionVAR_STR(name, opt, comment, check, update, def) \
295
DECLARE_DRIZZLE_SessionVAR_BASIC(name, char *) = { \
296
PLUGIN_VAR_STR | PLUGIN_VAR_SessionLOCAL | ((opt) & PLUGIN_VAR_MASK), \
297
#name, comment, check, update, -1, def, NULL}
299
#define DRIZZLE_SessionVAR_INT(name, opt, comment, check, update, def, min, max, blk) \
300
DECLARE_DRIZZLE_SessionVAR_SIMPLE(name, int) = { \
301
PLUGIN_VAR_INT | PLUGIN_VAR_SessionLOCAL | ((opt) & PLUGIN_VAR_MASK), \
302
#name, comment, check, update, -1, def, min, max, blk, NULL }
304
#define DRIZZLE_SessionVAR_UINT(name, opt, comment, check, update, def, min, max, blk) \
305
DECLARE_DRIZZLE_SessionVAR_SIMPLE(name, unsigned int) = { \
306
PLUGIN_VAR_INT | PLUGIN_VAR_SessionLOCAL | PLUGIN_VAR_UNSIGNED | ((opt) & PLUGIN_VAR_MASK), \
307
#name, comment, check, update, -1, def, min, max, blk, NULL }
309
#define DRIZZLE_SessionVAR_LONG(name, opt, comment, check, update, def, min, max, blk) \
310
DECLARE_DRIZZLE_SessionVAR_SIMPLE(name, long) = { \
311
PLUGIN_VAR_LONG | PLUGIN_VAR_SessionLOCAL | ((opt) & PLUGIN_VAR_MASK), \
312
#name, comment, check, update, -1, def, min, max, blk, NULL }
314
#define DRIZZLE_SessionVAR_ULONG(name, opt, comment, check, update, def, min, max, blk) \
315
DECLARE_DRIZZLE_SessionVAR_SIMPLE(name, unsigned long) = { \
316
PLUGIN_VAR_LONG | PLUGIN_VAR_SessionLOCAL | PLUGIN_VAR_UNSIGNED | ((opt) & PLUGIN_VAR_MASK), \
317
#name, comment, check, update, -1, def, min, max, blk, NULL }
319
#define DRIZZLE_SessionVAR_LONGLONG(name, opt, comment, check, update, def, min, max, blk) \
320
DECLARE_DRIZZLE_SessionVAR_SIMPLE(name, int64_t) = { \
321
PLUGIN_VAR_LONGLONG | PLUGIN_VAR_SessionLOCAL | ((opt) & PLUGIN_VAR_MASK), \
322
#name, comment, check, update, -1, def, min, max, blk, NULL }
324
#define DRIZZLE_SessionVAR_ULONGLONG(name, opt, comment, check, update, def, min, max, blk) \
325
DECLARE_DRIZZLE_SessionVAR_SIMPLE(name, uint64_t) = { \
326
PLUGIN_VAR_LONGLONG | PLUGIN_VAR_SessionLOCAL | PLUGIN_VAR_UNSIGNED | ((opt) & PLUGIN_VAR_MASK), \
327
#name, comment, check, update, -1, def, min, max, blk, NULL }
329
#define DRIZZLE_SessionVAR_ENUM(name, opt, comment, check, update, def, typelib) \
330
DECLARE_DRIZZLE_SessionVAR_TYPELIB(name, unsigned long) = { \
331
PLUGIN_VAR_ENUM | PLUGIN_VAR_SessionLOCAL | ((opt) & PLUGIN_VAR_MASK), \
332
#name, comment, check, update, -1, def, NULL, typelib }
334
#define DRIZZLE_SessionVAR_SET(name, opt, comment, check, update, def, typelib) \
335
DECLARE_DRIZZLE_SessionVAR_TYPELIB(name, uint64_t) = { \
336
PLUGIN_VAR_SET | PLUGIN_VAR_SessionLOCAL | ((opt) & PLUGIN_VAR_MASK), \
337
#name, comment, check, update, -1, def, NULL, typelib }
339
/* accessor macros */
341
#define SYSVAR(name) \
342
(*(DRIZZLE_SYSVAR_NAME(name).value))
344
/* when session == null, result points to global value */
345
#define SessionVAR(session, name) \
346
(*(DRIZZLE_SYSVAR_NAME(name).resolve(session, DRIZZLE_SYSVAR_NAME(name).offset)))
349
struct StorageEngine;
358
std::string description;
361
Plugin(std::string in_name, std::string in_version,
362
std::string in_author, std::string in_description)
363
: name(in_name), version(in_version),
364
author(in_author), description(in_description)
369
virtual void add_functions() {}
159
void plugin_opt_set_limits(option *options, const drizzle_sys_var *opt);
373
/*************************************************************************
374
st_mysql_value struct for reading values from mysqld.
375
Used by server variables framework to parse user-provided values.
376
Will be used for arguments when implementing UDFs.
378
Note that val_str() returns a string in temporary memory
379
that will be freed at the end of statement. Copy the string
380
if you need it to persist.
383
#define DRIZZLE_VALUE_TYPE_STRING 0
384
#define DRIZZLE_VALUE_TYPE_REAL 1
385
#define DRIZZLE_VALUE_TYPE_INT 2
387
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);
389
int (*value_type)(struct st_mysql_value *);
390
const char *(*val_str)(struct st_mysql_value *, char *buffer, int *length);
391
int (*val_real)(struct st_mysql_value *, double *realbuf);
392
int (*val_int)(struct st_mysql_value *, int64_t *intbuf);
198
429
@param prefix prefix for temporary file name
200
@retval >= 0 a file handle that can be passed to dup or internal::my_close
202
DRIZZLED_API int tmpfile(const char *prefix);
204
} /* namespace drizzled */
206
#endif /* DRIZZLED_PLUGIN_H */
431
@retval >= 0 a file handle that can be passed to dup or my_close
433
int mysql_tmpfile(const char *prefix);
436
Check the killed state of a connection
439
In MySQL support for the KILL statement is cooperative. The KILL
440
statement only sets a "killed" flag. This function returns the value
441
of that flag. A thread should check it often, especially inside
442
time-consuming loops, and gracefully abort the operation if it is
445
@param session user thread connection handle
446
@retval 0 the connection is active
447
@retval 1 the connection has been killed
449
int session_killed(const Session *session);
453
Return the thread id of a user thread
455
@param session user thread connection handle
458
unsigned long session_get_thread_id(const Session *session);
460
const charset_info_st *session_charset(Session *session);
461
char **session_query(Session *session);
462
int session_non_transactional_update(const Session *session);
463
void session_mark_transaction_to_rollback(Session *session, bool all);
467
Allocate memory in the connection's local memory pool
470
When properly used in place of @c malloc(), this can significantly
471
improve concurrency. Don't use this or related functions to allocate
472
large chunks of memory. Use for temporary storage only. The memory
473
will be freed automatically at the end of the statement; no explicit
474
code is required to prevent memory leaks.
478
void *session_alloc(Session *session, unsigned int size);
482
void *session_calloc(Session *session, unsigned int size);
486
char *session_strdup(Session *session, const char *str);
490
char *session_strmake(Session *session, const char *str, unsigned int size);
494
void *session_memdup(Session *session, const void* str, unsigned int size);
497
Get the XID for this connection's transaction
499
@param session user thread connection handle
500
@param xid location where identifier is stored
502
void session_get_xid(const Session *session, DRIZZLE_XID *xid);
505
Invalidate the query cache for a given table.
507
@param session user thread connection handle
508
@param key databasename\\0tablename\\0
509
@param key_length length of key in bytes, including the NUL bytes
510
@param using_trx flag: TRUE if using transactions, FALSE otherwise
512
void mysql_query_cache_invalidate4(Session *session,
513
const char *key, unsigned int key_length,
522
Provide a handler data getter to simplify coding
526
session_get_ha_data(const Session *session, const struct StorageEngine *engine)
528
return *session_ha_data(session, engine);
532
Provide a handler data setter to simplify coding
536
session_set_ha_data(const Session *session, const struct StorageEngine *engine,
539
*session_ha_data(session, engine)= (void*) ha_data;
543
#endif /* _my_plugin_h */