1
/* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2
* vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
4
* Copyright (C) 2008 Sun Microsystems
6
* This program is free software; you can redistribute it and/or modify
7
* it under the terms of the GNU General Public License as published by
8
* the Free Software Foundation; version 2 of the License.
10
* This program 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
13
* GNU General Public License for more details.
15
* You should have received a copy of the GNU General Public License
16
* along with this program; if not, write to the Free Software
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 <drizzled/lex_string.h>
24
#include <drizzled/xid.h>
25
#include <drizzled/plugin/manifest.h>
26
#include <drizzled/plugin/module.h>
27
#include "drizzled/plugin/version.h"
28
#include "drizzled/definitions.h"
36
struct charset_info_st;
38
/*************************************************************************
39
Plugin API. Common for all plugin types.
44
typedef drizzle_lex_string LEX_STRING;
47
extern char *opt_plugin_add;
48
extern char *opt_plugin_remove;
49
extern char *opt_plugin_load;
50
extern char *opt_plugin_dir_ptr;
51
extern char opt_plugin_dir[FN_REFLEN];
53
namespace plugin { class StorageEngine; }
56
Macros for beginning and ending plugin declarations. Between
57
DRIZZLE_DECLARE_PLUGIN and DRIZZLE_DECLARE_PLUGIN_END there should
58
be a plugin::Manifest for each plugin to be declared.
62
#define PANDORA_CPP_NAME(x) _drizzled_ ## x ## _plugin_
63
#define PANDORA_PLUGIN_NAME(x) PANDORA_CPP_NAME(x)
64
#define DRIZZLE_DECLARE_PLUGIN \
65
::drizzled::plugin::Manifest PANDORA_PLUGIN_NAME(PANDORA_MODULE_NAME)=
68
#define DRIZZLE_DECLARE_PLUGIN_END
69
#define DRIZZLE_PLUGIN(init,deinit,system) \
70
DRIZZLE_DECLARE_PLUGIN \
73
STRINGIFY_ARG(PANDORA_MODULE_NAME), \
74
STRINGIFY_ARG(PANDORA_MODULE_VERSION), \
75
STRINGIFY_ARG(PANDORA_MODULE_AUTHOR), \
76
STRINGIFY_ARG(PANDORA_MODULE_TITLE), \
77
PANDORA_MODULE_LICENSE, \
78
init, deinit, system, NULL \
83
declarations for SHOW STATUS support in plugins
85
enum enum_mysql_show_type
87
SHOW_UNDEF, SHOW_BOOL, SHOW_INT, SHOW_LONG,
88
SHOW_LONGLONG, SHOW_CHAR, SHOW_CHAR_PTR,
89
SHOW_FUNC, SHOW_KEY_CACHE_LONG, SHOW_KEY_CACHE_LONGLONG,
90
SHOW_LONG_STATUS, SHOW_DOUBLE_STATUS,
91
SHOW_MY_BOOL, SHOW_HA_ROWS, SHOW_SYS, SHOW_INT_NOFLUSH,
92
SHOW_LONGLONG_STATUS, SHOW_DOUBLE, SHOW_SIZE
95
struct drizzle_show_var {
98
enum enum_mysql_show_type type;
101
typedef enum enum_mysql_show_type SHOW_TYPE;
104
#define SHOW_VAR_FUNC_BUFF_SIZE 1024
105
typedef int (*mysql_show_var_func)(drizzle_show_var *, char *);
107
struct st_show_var_func_container {
108
mysql_show_var_func func;
111
declarations for server variables and command line options
115
#define PLUGIN_VAR_BOOL 0x0001
116
#define PLUGIN_VAR_INT 0x0002
117
#define PLUGIN_VAR_LONG 0x0003
118
#define PLUGIN_VAR_LONGLONG 0x0004
119
#define PLUGIN_VAR_STR 0x0005
120
#define PLUGIN_VAR_UNSIGNED 0x0080
121
#define PLUGIN_VAR_SessionLOCAL 0x0100 /* Variable is per-connection */
122
#define PLUGIN_VAR_READONLY 0x0200 /* Server variable is read only */
123
#define PLUGIN_VAR_NOSYSVAR 0x0400 /* Not a server variable */
124
#define PLUGIN_VAR_NOCMDOPT 0x0800 /* Not a command line option */
125
#define PLUGIN_VAR_NOCMDARG 0x1000 /* No argument for cmd line */
126
#define PLUGIN_VAR_RQCMDARG 0x0000 /* Argument required for cmd line */
127
#define PLUGIN_VAR_OPCMDARG 0x2000 /* Argument optional for cmd line */
128
#define PLUGIN_VAR_MEMALLOC 0x8000 /* String needs memory allocated */
130
struct drizzle_sys_var;
131
struct drizzle_value;
135
(*mysql_var_check_func)()
136
session thread handle
137
var dynamic variable being altered
138
save pointer to temporary storage
139
value user provided value
141
0 user provided value is OK and the update func may be called.
142
any other value indicates error.
144
This function should parse the user provided value and store in the
145
provided temporary storage any data as required by the update func.
146
There is sufficient space in the temporary storage to store a double.
147
Note that the update func may not be called if any other error occurs
148
so any memory allocated should be thread-local so that it may be freed
149
automatically at the end of the statement.
152
typedef int (*mysql_var_check_func)(Session *session,
153
drizzle_sys_var *var,
154
void *save, drizzle_value *value);
158
(*mysql_var_update_func)()
159
session thread handle
160
var dynamic variable being altered
161
var_ptr pointer to dynamic variable
162
save pointer to temporary storage
166
This function should use the validated value stored in the temporary store
167
and persist it in the provided pointer to the dynamic variable.
168
For example, strings may require memory to be allocated.
170
typedef void (*mysql_var_update_func)(Session *session,
171
drizzle_sys_var *var,
172
void *var_ptr, const void *save);
175
/* the following declarations are for internal use only */
178
#define PLUGIN_VAR_MASK \
179
(PLUGIN_VAR_READONLY | PLUGIN_VAR_NOSYSVAR | \
180
PLUGIN_VAR_NOCMDOPT | PLUGIN_VAR_NOCMDARG | \
181
PLUGIN_VAR_OPCMDARG | PLUGIN_VAR_RQCMDARG | PLUGIN_VAR_MEMALLOC)
183
#define DRIZZLE_PLUGIN_VAR_HEADER \
186
const char *comment; \
187
mysql_var_check_func check; \
188
mysql_var_update_func update
190
#define DRIZZLE_SYSVAR_NAME(name) mysql_sysvar_ ## name
191
#define DRIZZLE_SYSVAR(name) \
192
((drizzle_sys_var *)(&(DRIZZLE_SYSVAR_NAME(name))))
195
for global variables, the value pointer is the first
196
element after the header, the default value is the second.
197
for thread variables, the value offset is the first
198
element after the header, the default value is the second.
202
#define DECLARE_DRIZZLE_SYSVAR_BASIC(name, type) struct { \
203
DRIZZLE_PLUGIN_VAR_HEADER; \
205
const type def_val; \
206
} DRIZZLE_SYSVAR_NAME(name)
208
#define DECLARE_DRIZZLE_SYSVAR_SIMPLE(name, type) struct { \
209
DRIZZLE_PLUGIN_VAR_HEADER; \
210
type *value; type def_val; \
211
type min_val; type max_val; \
213
} DRIZZLE_SYSVAR_NAME(name)
215
#define DECLARE_SessionVAR_FUNC(type) \
216
type *(*resolve)(Session *session, int offset)
218
#define DECLARE_DRIZZLE_SessionVAR_BASIC(name, type) struct { \
219
DRIZZLE_PLUGIN_VAR_HEADER; \
221
const type def_val; \
222
DECLARE_SessionVAR_FUNC(type); \
223
} DRIZZLE_SYSVAR_NAME(name)
225
#define DECLARE_DRIZZLE_SessionVAR_SIMPLE(name, type) struct { \
226
DRIZZLE_PLUGIN_VAR_HEADER; \
228
type def_val; type min_val; \
229
type max_val; type blk_sz; \
230
DECLARE_SessionVAR_FUNC(type); \
231
} DRIZZLE_SYSVAR_NAME(name)
233
#define DECLARE_DRIZZLE_SessionVAR_TYPELIB(name, type) struct { \
234
DRIZZLE_PLUGIN_VAR_HEADER; \
237
DECLARE_SessionVAR_FUNC(type); \
239
} DRIZZLE_SYSVAR_NAME(name)
243
the following declarations are for use by plugin implementors
246
#define DRIZZLE_SYSVAR_BOOL(name, varname, opt, comment, check, update, def) \
247
DECLARE_DRIZZLE_SYSVAR_BASIC(name, bool) = { \
248
PLUGIN_VAR_BOOL | ((opt) & PLUGIN_VAR_MASK), \
249
#name, comment, check, update, &varname, def}
251
#define DRIZZLE_SYSVAR_STR(name, varname, opt, comment, check, update, def) \
252
DECLARE_DRIZZLE_SYSVAR_BASIC(name, char *) = { \
253
PLUGIN_VAR_STR | ((opt) & PLUGIN_VAR_MASK), \
254
#name, comment, check, update, &varname, def}
256
#define DRIZZLE_SYSVAR_INT(name, varname, opt, comment, check, update, def, min, max, blk) \
257
DECLARE_DRIZZLE_SYSVAR_SIMPLE(name, int) = { \
258
PLUGIN_VAR_INT | ((opt) & PLUGIN_VAR_MASK), \
259
#name, comment, check, update, &varname, def, min, max, blk }
261
#define DRIZZLE_SYSVAR_UINT(name, varname, opt, comment, check, update, def, min, max, blk) \
262
DECLARE_DRIZZLE_SYSVAR_SIMPLE(name, unsigned int) = { \
263
PLUGIN_VAR_INT | PLUGIN_VAR_UNSIGNED | ((opt) & PLUGIN_VAR_MASK), \
264
#name, comment, check, update, &varname, def, min, max, blk }
266
#define DRIZZLE_SYSVAR_LONG(name, varname, opt, comment, check, update, def, min, max, blk) \
267
DECLARE_DRIZZLE_SYSVAR_SIMPLE(name, long) = { \
268
PLUGIN_VAR_LONG | ((opt) & PLUGIN_VAR_MASK), \
269
#name, comment, check, update, &varname, def, min, max, blk }
271
#define DRIZZLE_SYSVAR_ULONG(name, varname, opt, comment, check, update, def, min, max, blk) \
272
DECLARE_DRIZZLE_SYSVAR_SIMPLE(name, unsigned long) = { \
273
PLUGIN_VAR_LONG | PLUGIN_VAR_UNSIGNED | ((opt) & PLUGIN_VAR_MASK), \
274
#name, comment, check, update, &varname, def, min, max, blk }
276
#define DRIZZLE_SYSVAR_LONGLONG(name, varname, opt, comment, check, update, def, min, max, blk) \
277
DECLARE_DRIZZLE_SYSVAR_SIMPLE(name, int64_t) = { \
278
PLUGIN_VAR_LONGLONG | ((opt) & PLUGIN_VAR_MASK), \
279
#name, comment, check, update, &varname, def, min, max, blk }
281
#define DRIZZLE_SYSVAR_ULONGLONG(name, varname, opt, comment, check, update, def, min, max, blk) \
282
DECLARE_DRIZZLE_SYSVAR_SIMPLE(name, uint64_t) = { \
283
PLUGIN_VAR_LONGLONG | PLUGIN_VAR_UNSIGNED | ((opt) & PLUGIN_VAR_MASK), \
284
#name, comment, check, update, &varname, def, min, max, blk }
286
#define DRIZZLE_SessionVAR_BOOL(name, opt, comment, check, update, def) \
287
DECLARE_DRIZZLE_SessionVAR_BASIC(name, char) = { \
288
PLUGIN_VAR_BOOL | PLUGIN_VAR_SessionLOCAL | ((opt) & PLUGIN_VAR_MASK), \
289
#name, comment, check, update, -1, def, NULL}
291
#define DRIZZLE_SessionVAR_STR(name, opt, comment, check, update, def) \
292
DECLARE_DRIZZLE_SessionVAR_BASIC(name, char *) = { \
293
PLUGIN_VAR_STR | PLUGIN_VAR_SessionLOCAL | ((opt) & PLUGIN_VAR_MASK), \
294
#name, comment, check, update, -1, def, NULL}
296
#define DRIZZLE_SessionVAR_INT(name, opt, comment, check, update, def, min, max, blk) \
297
DECLARE_DRIZZLE_SessionVAR_SIMPLE(name, int) = { \
298
PLUGIN_VAR_INT | PLUGIN_VAR_SessionLOCAL | ((opt) & PLUGIN_VAR_MASK), \
299
#name, comment, check, update, -1, def, min, max, blk, NULL }
301
#define DRIZZLE_SessionVAR_UINT(name, opt, comment, check, update, def, min, max, blk) \
302
DECLARE_DRIZZLE_SessionVAR_SIMPLE(name, unsigned int) = { \
303
PLUGIN_VAR_INT | PLUGIN_VAR_SessionLOCAL | PLUGIN_VAR_UNSIGNED | ((opt) & PLUGIN_VAR_MASK), \
304
#name, comment, check, update, -1, def, min, max, blk, NULL }
306
#define DRIZZLE_SessionVAR_LONG(name, opt, comment, check, update, def, min, max, blk) \
307
DECLARE_DRIZZLE_SessionVAR_SIMPLE(name, long) = { \
308
PLUGIN_VAR_LONG | PLUGIN_VAR_SessionLOCAL | ((opt) & PLUGIN_VAR_MASK), \
309
#name, comment, check, update, -1, def, min, max, blk, NULL }
311
#define DRIZZLE_SessionVAR_ULONG(name, opt, comment, check, update, def, min, max, blk) \
312
DECLARE_DRIZZLE_SessionVAR_SIMPLE(name, unsigned long) = { \
313
PLUGIN_VAR_LONG | PLUGIN_VAR_SessionLOCAL | PLUGIN_VAR_UNSIGNED | ((opt) & PLUGIN_VAR_MASK), \
314
#name, comment, check, update, -1, def, min, max, blk, NULL }
316
#define DRIZZLE_SessionVAR_LONGLONG(name, opt, comment, check, update, def, min, max, blk) \
317
DECLARE_DRIZZLE_SessionVAR_SIMPLE(name, int64_t) = { \
318
PLUGIN_VAR_LONGLONG | PLUGIN_VAR_SessionLOCAL | ((opt) & PLUGIN_VAR_MASK), \
319
#name, comment, check, update, -1, def, min, max, blk, NULL }
321
#define DRIZZLE_SessionVAR_ULONGLONG(name, opt, comment, check, update, def, min, max, blk) \
322
DECLARE_DRIZZLE_SessionVAR_SIMPLE(name, uint64_t) = { \
323
PLUGIN_VAR_LONGLONG | PLUGIN_VAR_SessionLOCAL | PLUGIN_VAR_UNSIGNED | ((opt) & PLUGIN_VAR_MASK), \
324
#name, comment, check, update, -1, def, min, max, blk, NULL }
326
/* accessor macros */
328
#define SYSVAR(name) \
329
(*(DRIZZLE_SYSVAR_NAME(name).value))
331
/* when session == null, result points to global value */
332
#define SessionVAR(session, name) \
333
(*(DRIZZLE_SYSVAR_NAME(name).resolve(session, DRIZZLE_SYSVAR_NAME(name).offset)))
336
/*************************************************************************
337
drizzle_value struct for reading values from mysqld.
338
Used by server variables framework to parse user-provided values.
339
Will be used for arguments when implementing UDFs.
341
Note that val_str() returns a string in temporary memory
342
that will be freed at the end of statement. Copy the string
343
if you need it to persist.
346
#define DRIZZLE_VALUE_TYPE_STRING 0
347
#define DRIZZLE_VALUE_TYPE_REAL 1
348
#define DRIZZLE_VALUE_TYPE_INT 2
351
skeleton of a plugin variable - portion of structure common to all.
353
struct drizzle_sys_var
355
DRIZZLE_PLUGIN_VAR_HEADER;
358
void plugin_opt_set_limits(my_option *options, const drizzle_sys_var *opt);
362
int (*value_type)(drizzle_value *);
363
const char *(*val_str)(drizzle_value *, char *buffer, int *length);
364
int (*val_real)(drizzle_value *, double *realbuf);
365
int (*val_int)(drizzle_value *, int64_t *intbuf);
369
/*************************************************************************
370
Miscellaneous functions for plugin implementors
377
extern bool plugin_init(plugin::Registry ®istry,
378
int *argc, char **argv,
380
extern void plugin_shutdown(plugin::Registry &plugins);
381
extern void my_print_help_inc_plugins(my_option *options);
382
extern bool plugin_is_ready(const LEX_STRING *name, int type);
383
extern void plugin_sessionvar_init(Session *session);
384
extern void plugin_sessionvar_cleanup(Session *session);
385
extern sys_var *intern_find_sys_var(const char *str, uint32_t, bool no_error);
387
int session_in_lock_tables(const Session *session);
388
int session_tablespace_op(const Session *session);
389
void set_session_proc_info(Session *session, const char *info);
390
const char *get_session_proc_info(Session *session);
391
int64_t session_test_options(const Session *session, int64_t test_options);
392
int session_sql_command(const Session *session);
393
int session_tx_isolation(const Session *session);
398
Create a temporary file.
401
The temporary file is created in a location specified by the mysql
402
server configuration (--tmpdir option). The caller does not need to
403
delete the file, it will be deleted automatically.
405
@param prefix prefix for temporary file name
407
@retval >= 0 a file handle that can be passed to dup or internal::my_close
409
int mysql_tmpfile(const char *prefix);
412
Check the killed state of a connection
415
In MySQL support for the KILL statement is cooperative. The KILL
416
statement only sets a "killed" flag. This function returns the value
417
of that flag. A thread should check it often, especially inside
418
time-consuming loops, and gracefully abort the operation if it is
421
@param session user thread connection handle
422
@retval 0 the connection is active
423
@retval 1 the connection has been killed
425
int session_killed(const Session *session);
429
Return the thread id of a user thread
431
@param session user thread connection handle
434
unsigned long session_get_thread_id(const Session *session);
436
const charset_info_st *session_charset(Session *session);
437
int session_non_transactional_update(const Session *session);
438
void session_mark_transaction_to_rollback(Session *session, bool all);
442
Allocate memory in the connection's local memory pool
445
When properly used in place of @c malloc(), this can significantly
446
improve concurrency. Don't use this or related functions to allocate
447
large chunks of memory. Use for temporary storage only. The memory
448
will be freed automatically at the end of the statement; no explicit
449
code is required to prevent memory leaks.
453
void *session_alloc(Session *session, unsigned int size);
457
void *session_calloc(Session *session, unsigned int size);
461
char *session_strdup(Session *session, const char *str);
465
char *session_strmake(Session *session, const char *str, unsigned int size);
469
void *session_memdup(Session *session, const void* str, unsigned int size);
472
Get the XID for this connection's transaction
474
@param session user thread connection handle
475
@param xid location where identifier is stored
477
void session_get_xid(const Session *session, DRIZZLE_XID *xid);
480
Invalidate the query cache for a given table.
482
@param session user thread connection handle
483
@param key databasename\\0tablename\\0
484
@param key_length length of key in bytes, including the NUL bytes
485
@param using_trx flag: TRUE if using transactions, FALSE otherwise
487
void mysql_query_cache_invalidate4(Session *session,
488
const char *key, unsigned int key_length,
495
} /* namespace drizzled */
497
#endif /* DRIZZLED_PLUGIN_H */