~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/plugin.h

  • Committer: Monty Taylor
  • Date: 2008-10-09 22:38:27 UTC
  • mto: This revision was merged to the branch mainline in revision 497.
  • Revision ID: monty@inaugust.com-20081009223827-bc9gvpiplsmvpwyq
Moved test() to its own file.
Made a new function to possibly replace int10_to_str.

Show diffs side-by-side

added added

removed removed

Lines of Context:
17
17
 *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
18
18
 */
19
19
 
20
 
#ifndef DRIZZLED_PLUGIN_H
21
 
#define DRIZZLED_PLUGIN_H
22
 
 
23
 
#include "drizzled/module/manifest.h"
24
 
#include "drizzled/module/module.h"
25
 
#include "drizzled/plugin/version.h"
26
 
#include "drizzled/module/context.h"
27
 
#include "drizzled/definitions.h"
28
 
 
29
 
#include "drizzled/lex_string.h"
30
 
#include "drizzled/xid.h"
31
 
#include <boost/program_options.hpp>
32
 
 
33
 
namespace drizzled
34
 
{
35
 
 
36
 
class Session;
 
20
#ifndef _my_plugin_h
 
21
#define _my_plugin_h
 
22
 
 
23
#include <drizzled/global.h>
 
24
 
 
25
#ifdef __cplusplus
 
26
class THD;
37
27
class Item;
38
 
struct charset_info_st;
 
28
#define DRIZZLE_THD THD*
 
29
#else
 
30
#define DRIZZLE_THD void*
 
31
#endif
 
32
 
 
33
#define DRIZZLE_XIDDATASIZE 128
 
34
/**
 
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
 
39
 
 
40
  @see XID in sql/handler.h
 
41
*/
 
42
struct st_mysql_xid {
 
43
  long formatID;
 
44
  long gtrid_length;
 
45
  long bqual_length;
 
46
  char data[DRIZZLE_XIDDATASIZE];  /* Not \0-terminated */
 
47
};
 
48
typedef struct st_mysql_xid DRIZZLE_XID;
39
49
 
40
50
/*************************************************************************
41
51
  Plugin API. Common for all plugin types.
42
52
*/
43
53
 
44
 
 
45
 
class sys_var;
46
 
typedef drizzle_lex_string LEX_STRING;
47
 
struct option;
48
 
 
49
 
extern char *opt_plugin_dir_ptr;
50
 
extern char opt_plugin_dir[FN_REFLEN];
51
 
 
52
 
namespace plugin { class StorageEngine; }
53
 
 
54
 
/*
55
 
  Macros for beginning and ending plugin declarations. Between
56
 
  DRIZZLE_DECLARE_PLUGIN and DRIZZLE_DECLARE_PLUGIN_END there should
57
 
  be a module::Manifest for each plugin to be declared.
58
 
*/
59
 
 
60
 
 
61
 
#define PANDORA_CPP_NAME(x) _drizzled_ ## x ## _plugin_
62
 
#define PANDORA_PLUGIN_NAME(x) PANDORA_CPP_NAME(x)
63
 
#define DRIZZLE_DECLARE_PLUGIN \
64
 
  ::drizzled::module::Manifest PANDORA_PLUGIN_NAME(PANDORA_MODULE_NAME)= 
65
 
 
66
 
 
67
 
#define DRIZZLE_DECLARE_PLUGIN_END
68
 
#define DRIZZLE_PLUGIN(init,system,options) \
69
 
  DRIZZLE_DECLARE_PLUGIN \
70
 
  { \
71
 
    DRIZZLE_VERSION_ID, \
72
 
    STRINGIFY_ARG(PANDORA_MODULE_NAME), \
73
 
    STRINGIFY_ARG(PANDORA_MODULE_VERSION), \
74
 
    STRINGIFY_ARG(PANDORA_MODULE_AUTHOR), \
75
 
    STRINGIFY_ARG(PANDORA_MODULE_TITLE), \
76
 
    PANDORA_MODULE_LICENSE, \
77
 
    init, system, options \
78
 
  } 
79
 
 
 
54
/*
 
55
  The allowable types of plugins
 
56
*/
 
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 */
 
65
 
 
66
#define DRIZZLE_MAX_PLUGIN_TYPE_NUM    8  /* The number of plugin types */
 
67
 
 
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
 
72
 
 
73
#define PLUGIN_LICENSE_PROPRIETARY_STRING "PROPRIETARY"
 
74
#define PLUGIN_LICENSE_GPL_STRING "GPL"
 
75
#define PLUGIN_LICENSE_BSD_STRING "BSD"
 
76
 
 
77
/*
 
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.
 
81
*/
 
82
 
 
83
 
 
84
#ifndef DRIZZLE_DYNAMIC_PLUGIN
 
85
#define __DRIZZLE_DECLARE_PLUGIN(NAME, DECLS) \
 
86
struct st_mysql_plugin DECLS[]= {
 
87
#else
 
88
#define __DRIZZLE_DECLARE_PLUGIN(NAME, DECLS) \
 
89
struct st_mysql_plugin _mysql_plugin_declarations_[]= {
 
90
#endif
 
91
 
 
92
#define mysql_declare_plugin(NAME) \
 
93
__DRIZZLE_DECLARE_PLUGIN(NAME, \
 
94
                 builtin_ ## NAME ## _plugin)
 
95
 
 
96
#define mysql_declare_plugin_end ,{0,0,0,0,0,0,0,0,0,0,0}}
80
97
 
81
98
/*
82
99
  declarations for SHOW STATUS support in plugins
85
102
{
86
103
  SHOW_UNDEF, SHOW_BOOL, SHOW_INT, SHOW_LONG,
87
104
  SHOW_LONGLONG, SHOW_CHAR, SHOW_CHAR_PTR,
88
 
  SHOW_FUNC,
89
 
  SHOW_LONG_STATUS, SHOW_DOUBLE_STATUS,
90
 
  SHOW_MY_BOOL, SHOW_HA_ROWS, SHOW_SYS, SHOW_INT_NOFLUSH,
91
 
  SHOW_LONGLONG_STATUS, SHOW_DOUBLE, SHOW_SIZE
 
105
  SHOW_ARRAY, SHOW_FUNC, SHOW_DOUBLE
92
106
};
93
107
 
94
 
struct drizzle_show_var {
 
108
struct st_mysql_show_var {
95
109
  const char *name;
96
110
  char *value;
97
111
  enum enum_mysql_show_type type;
98
112
};
99
113
 
100
 
typedef enum enum_mysql_show_type SHOW_TYPE;
101
 
 
102
114
 
103
115
#define SHOW_VAR_FUNC_BUFF_SIZE 1024
104
 
typedef int (*mysql_show_var_func)(drizzle_show_var *, char *);
 
116
typedef int (*mysql_show_var_func)(DRIZZLE_THD, struct st_mysql_show_var*, char *);
105
117
 
106
118
struct st_show_var_func_container {
107
119
  mysql_show_var_func func;
116
128
#define PLUGIN_VAR_LONG         0x0003
117
129
#define PLUGIN_VAR_LONGLONG     0x0004
118
130
#define PLUGIN_VAR_STR          0x0005
 
131
#define PLUGIN_VAR_ENUM         0x0006
 
132
#define PLUGIN_VAR_SET          0x0007
119
133
#define PLUGIN_VAR_UNSIGNED     0x0080
120
 
#define PLUGIN_VAR_SessionLOCAL     0x0100 /* Variable is per-connection */
 
134
#define PLUGIN_VAR_THDLOCAL     0x0100 /* Variable is per-connection */
121
135
#define PLUGIN_VAR_READONLY     0x0200 /* Server variable is read only */
122
136
#define PLUGIN_VAR_NOSYSVAR     0x0400 /* Not a server variable */
123
137
#define PLUGIN_VAR_NOCMDOPT     0x0800 /* Not a command line option */
126
140
#define PLUGIN_VAR_OPCMDARG     0x2000 /* Argument optional for cmd line */
127
141
#define PLUGIN_VAR_MEMALLOC     0x8000 /* String needs memory allocated */
128
142
 
129
 
struct drizzle_sys_var;
130
 
struct drizzle_value;
 
143
struct st_mysql_sys_var;
 
144
struct st_mysql_value;
131
145
 
132
146
/*
133
147
  SYNOPSIS
134
148
    (*mysql_var_check_func)()
135
 
      session               thread handle
 
149
      thd               thread handle
136
150
      var               dynamic variable being altered
137
151
      save              pointer to temporary storage
138
152
      value             user provided value
139
153
  RETURN
140
154
    0   user provided value is OK and the update func may be called.
141
155
    any other value indicates error.
142
 
 
 
156
  
143
157
  This function should parse the user provided value and store in the
144
158
  provided temporary storage any data as required by the update func.
145
159
  There is sufficient space in the temporary storage to store a double.
148
162
  automatically at the end of the statement.
149
163
*/
150
164
 
151
 
typedef int (*mysql_var_check_func)(Session *session,
152
 
                                    drizzle_sys_var *var,
153
 
                                    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);
154
168
 
155
169
/*
156
170
  SYNOPSIS
157
171
    (*mysql_var_update_func)()
158
 
      session               thread handle
 
172
      thd               thread handle
159
173
      var               dynamic variable being altered
160
174
      var_ptr           pointer to dynamic variable
161
175
      save              pointer to temporary storage
162
176
   RETURN
163
177
     NONE
164
 
 
 
178
   
165
179
   This function should use the validated value stored in the temporary store
166
180
   and persist it in the provided pointer to the dynamic variable.
167
181
   For example, strings may require memory to be allocated.
168
182
*/
169
 
typedef void (*mysql_var_update_func)(Session *session,
170
 
                                      drizzle_sys_var *var,
 
183
typedef void (*mysql_var_update_func)(DRIZZLE_THD thd,
 
184
                                      struct st_mysql_sys_var *var,
171
185
                                      void *var_ptr, const void *save);
172
186
 
173
187
 
186
200
  mysql_var_check_func check;   \
187
201
  mysql_var_update_func update
188
202
 
189
 
#define DRIZZLE_SYSVAR_NAME(name) drizzle_sysvar_ ## name
 
203
#define DRIZZLE_SYSVAR_NAME(name) mysql_sysvar_ ## name
190
204
#define DRIZZLE_SYSVAR(name) \
191
 
  ((drizzle_sys_var *)(&(DRIZZLE_SYSVAR_NAME(name))))
 
205
  ((struct st_mysql_sys_var *)&(DRIZZLE_SYSVAR_NAME(name)))
192
206
 
193
207
/*
194
208
  for global variables, the value pointer is the first
196
210
  for thread variables, the value offset is the first
197
211
  element after the header, the default value is the second.
198
212
*/
199
 
 
 
213
   
200
214
 
201
215
#define DECLARE_DRIZZLE_SYSVAR_BASIC(name, type) struct { \
202
216
  DRIZZLE_PLUGIN_VAR_HEADER;      \
211
225
  type blk_sz;                  \
212
226
} DRIZZLE_SYSVAR_NAME(name)
213
227
 
214
 
#define DECLARE_SessionVAR_FUNC(type) \
215
 
  type *(*resolve)(Session *session, int offset)
216
 
 
217
 
#define DECLARE_DRIZZLE_SessionVAR_BASIC(name, type) struct { \
 
228
#define DECLARE_DRIZZLE_SYSVAR_TYPELIB(name, type) struct { \
 
229
  DRIZZLE_PLUGIN_VAR_HEADER;      \
 
230
  type *value; type def_val;    \
 
231
  TYPELIB *typelib;             \
 
232
} DRIZZLE_SYSVAR_NAME(name)
 
233
 
 
234
#define DECLARE_THDVAR_FUNC(type) \
 
235
  type *(*resolve)(DRIZZLE_THD thd, int offset)
 
236
 
 
237
#define DECLARE_DRIZZLE_THDVAR_BASIC(name, type) struct { \
218
238
  DRIZZLE_PLUGIN_VAR_HEADER;      \
219
239
  int offset;                   \
220
240
  const type def_val;           \
221
 
  DECLARE_SessionVAR_FUNC(type);    \
 
241
  DECLARE_THDVAR_FUNC(type);    \
222
242
} DRIZZLE_SYSVAR_NAME(name)
223
243
 
224
 
#define DECLARE_DRIZZLE_SessionVAR_SIMPLE(name, type) struct { \
 
244
#define DECLARE_DRIZZLE_THDVAR_SIMPLE(name, type) struct { \
225
245
  DRIZZLE_PLUGIN_VAR_HEADER;      \
226
246
  int offset;                   \
227
247
  type def_val; type min_val;   \
228
248
  type max_val; type blk_sz;    \
229
 
  DECLARE_SessionVAR_FUNC(type);    \
 
249
  DECLARE_THDVAR_FUNC(type);    \
230
250
} DRIZZLE_SYSVAR_NAME(name)
231
251
 
232
 
#define DECLARE_DRIZZLE_SessionVAR_TYPELIB(name, type) struct { \
 
252
#define DECLARE_DRIZZLE_THDVAR_TYPELIB(name, type) struct { \
233
253
  DRIZZLE_PLUGIN_VAR_HEADER;      \
234
254
  int offset;                   \
235
255
  type def_val;                 \
236
 
  DECLARE_SessionVAR_FUNC(type);    \
 
256
  DECLARE_THDVAR_FUNC(type);    \
237
257
  TYPELIB *typelib;             \
238
258
} DRIZZLE_SYSVAR_NAME(name)
239
259
 
282
302
  PLUGIN_VAR_LONGLONG | PLUGIN_VAR_UNSIGNED | ((opt) & PLUGIN_VAR_MASK), \
283
303
  #name, comment, check, update, &varname, def, min, max, blk }
284
304
 
285
 
#define DRIZZLE_SessionVAR_BOOL(name, opt, comment, check, update, def) \
286
 
DECLARE_DRIZZLE_SessionVAR_BASIC(name, char) = { \
287
 
  PLUGIN_VAR_BOOL | PLUGIN_VAR_SessionLOCAL | ((opt) & PLUGIN_VAR_MASK), \
288
 
  #name, comment, check, update, -1, def, NULL}
289
 
 
290
 
#define DRIZZLE_SessionVAR_STR(name, opt, comment, check, update, def) \
291
 
DECLARE_DRIZZLE_SessionVAR_BASIC(name, char *) = { \
292
 
  PLUGIN_VAR_STR | PLUGIN_VAR_SessionLOCAL | ((opt) & PLUGIN_VAR_MASK), \
293
 
  #name, comment, check, update, -1, def, NULL}
294
 
 
295
 
#define DRIZZLE_SessionVAR_INT(name, opt, comment, check, update, def, min, max, blk) \
296
 
DECLARE_DRIZZLE_SessionVAR_SIMPLE(name, int) = { \
297
 
  PLUGIN_VAR_INT | PLUGIN_VAR_SessionLOCAL | ((opt) & PLUGIN_VAR_MASK), \
298
 
  #name, comment, check, update, -1, def, min, max, blk, NULL }
299
 
 
300
 
#define DRIZZLE_SessionVAR_UINT(name, opt, comment, check, update, def, min, max, blk) \
301
 
DECLARE_DRIZZLE_SessionVAR_SIMPLE(name, unsigned int) = { \
302
 
  PLUGIN_VAR_INT | PLUGIN_VAR_SessionLOCAL | PLUGIN_VAR_UNSIGNED | ((opt) & PLUGIN_VAR_MASK), \
303
 
  #name, comment, check, update, -1, def, min, max, blk, NULL }
304
 
 
305
 
#define DRIZZLE_SessionVAR_LONG(name, opt, comment, check, update, def, min, max, blk) \
306
 
DECLARE_DRIZZLE_SessionVAR_SIMPLE(name, long) = { \
307
 
  PLUGIN_VAR_LONG | PLUGIN_VAR_SessionLOCAL | ((opt) & PLUGIN_VAR_MASK), \
308
 
  #name, comment, check, update, -1, def, min, max, blk, NULL }
309
 
 
310
 
#define DRIZZLE_SessionVAR_ULONG(name, opt, comment, check, update, def, min, max, blk) \
311
 
DECLARE_DRIZZLE_SessionVAR_SIMPLE(name, unsigned long) = { \
312
 
  PLUGIN_VAR_LONG | PLUGIN_VAR_SessionLOCAL | PLUGIN_VAR_UNSIGNED | ((opt) & PLUGIN_VAR_MASK), \
313
 
  #name, comment, check, update, -1, def, min, max, blk, NULL }
314
 
 
315
 
#define DRIZZLE_SessionVAR_LONGLONG(name, opt, comment, check, update, def, min, max, blk) \
316
 
DECLARE_DRIZZLE_SessionVAR_SIMPLE(name, int64_t) = { \
317
 
  PLUGIN_VAR_LONGLONG | PLUGIN_VAR_SessionLOCAL | ((opt) & PLUGIN_VAR_MASK), \
318
 
  #name, comment, check, update, -1, def, min, max, blk, NULL }
319
 
 
320
 
#define DRIZZLE_SessionVAR_ULONGLONG(name, opt, comment, check, update, def, min, max, blk) \
321
 
DECLARE_DRIZZLE_SessionVAR_SIMPLE(name, uint64_t) = { \
322
 
  PLUGIN_VAR_LONGLONG | PLUGIN_VAR_SessionLOCAL | PLUGIN_VAR_UNSIGNED | ((opt) & PLUGIN_VAR_MASK), \
323
 
  #name, comment, check, update, -1, def, min, max, blk, NULL }
 
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 }
 
309
 
 
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 }
 
314
 
 
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}
 
319
 
 
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}
 
324
 
 
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 }
 
329
 
 
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 }
 
334
 
 
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 }
 
339
 
 
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 }
 
344
 
 
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 }
 
349
 
 
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 }
 
354
 
 
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 }
 
359
 
 
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 }
324
364
 
325
365
/* accessor macros */
326
366
 
327
367
#define SYSVAR(name) \
328
368
  (*(DRIZZLE_SYSVAR_NAME(name).value))
329
369
 
330
 
/* when session == null, result points to global value */
331
 
#define SessionVAR(session, name) \
332
 
  (*(DRIZZLE_SYSVAR_NAME(name).resolve(session, DRIZZLE_SYSVAR_NAME(name).offset)))
 
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)))
 
373
 
 
374
 
 
375
/*
 
376
  Plugin description structure.
 
377
*/
 
378
 
 
379
struct st_mysql_plugin
 
380
{
 
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             */
 
392
};
 
393
 
 
394
struct handlerton;
333
395
 
334
396
 
335
397
/*************************************************************************
336
 
  drizzle_value struct for reading values from mysqld.
 
398
  st_mysql_value struct for reading values from mysqld.
337
399
  Used by server variables framework to parse user-provided values.
338
400
  Will be used for arguments when implementing UDFs.
339
401
 
346
408
#define DRIZZLE_VALUE_TYPE_REAL   1
347
409
#define DRIZZLE_VALUE_TYPE_INT    2
348
410
 
349
 
/*
350
 
  skeleton of a plugin variable - portion of structure common to all.
351
 
*/
352
 
struct drizzle_sys_var
353
 
{
354
 
  DRIZZLE_PLUGIN_VAR_HEADER;
355
 
};
356
 
 
357
 
void plugin_opt_set_limits(option *options, const drizzle_sys_var *opt);
358
 
 
359
 
struct drizzle_value
360
 
{
361
 
  int (*value_type)(drizzle_value *);
362
 
  const char *(*val_str)(drizzle_value *, char *buffer, int *length);
363
 
  int (*val_real)(drizzle_value *, double *realbuf);
364
 
  int (*val_int)(drizzle_value *, int64_t *intbuf);
 
411
struct st_mysql_value
 
412
{
 
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);
365
417
};
366
418
 
367
419
 
369
421
  Miscellaneous functions for plugin implementors
370
422
*/
371
423
 
372
 
extern bool plugin_init(module::Registry &registry,
373
 
                        boost::program_options::options_description &long_options);
374
 
extern void plugin_finalize(module::Registry &registry);
375
 
extern void my_print_help_inc_plugins(option *options);
376
 
extern bool plugin_is_ready(const LEX_STRING *name, int type);
377
 
extern void plugin_sessionvar_init(Session *session);
378
 
extern void plugin_sessionvar_cleanup(Session *session);
379
 
extern sys_var *intern_find_sys_var(const char *str, uint32_t, bool no_error);
380
 
 
381
 
int session_in_lock_tables(const Session *session);
382
 
int session_tablespace_op(const Session *session);
383
 
void set_session_proc_info(Session *session, const char *info);
384
 
const char *get_session_proc_info(Session *session);
385
 
int64_t session_test_options(const Session *session, int64_t test_options);
386
 
int session_sql_command(const Session *session);
387
 
enum_tx_isolation session_tx_isolation(const Session *session);
388
 
 
389
 
void compose_plugin_add(std::vector<std::string> options);
390
 
void compose_plugin_remove(std::vector<std::string> options);
391
 
void notify_plugin_load(std::string in_plugin_load);
392
 
 
 
424
#ifdef __cplusplus
 
425
extern "C" {
 
426
#endif
 
427
 
 
428
int thd_in_lock_tables(const DRIZZLE_THD thd);
 
429
int thd_tablespace_op(const DRIZZLE_THD thd);
 
430
int64_t thd_test_options(const DRIZZLE_THD thd, int64_t test_options);
 
431
int thd_sql_command(const DRIZZLE_THD thd);
 
432
void **thd_ha_data(const DRIZZLE_THD thd, const struct handlerton *hton);
 
433
int thd_tx_isolation(const DRIZZLE_THD thd);
 
434
/* Increments the row counter, see THD::row_count */
 
435
void thd_inc_row_count(DRIZZLE_THD thd);
393
436
 
394
437
/**
395
438
  Create a temporary file.
401
444
 
402
445
  @param prefix  prefix for temporary file name
403
446
  @retval -1    error
404
 
  @retval >= 0  a file handle that can be passed to dup or internal::my_close
 
447
  @retval >= 0  a file handle that can be passed to dup or my_close
405
448
*/
406
449
int mysql_tmpfile(const char *prefix);
407
450
 
415
458
  time-consuming loops, and gracefully abort the operation if it is
416
459
  non-zero.
417
460
 
418
 
  @param session  user thread connection handle
 
461
  @param thd  user thread connection handle
419
462
  @retval 0  the connection is active
420
463
  @retval 1  the connection has been killed
421
464
*/
422
 
int session_killed(const Session *session);
423
 
 
424
 
 
425
 
const charset_info_st *session_charset(Session *session);
 
465
int thd_killed(const DRIZZLE_THD thd);
 
466
 
 
467
 
 
468
/**
 
469
  Return the thread id of a user thread
 
470
 
 
471
  @param thd  user thread connection handle
 
472
  @return  thread id
 
473
*/
 
474
unsigned long thd_get_thread_id(const DRIZZLE_THD thd);
 
475
 
 
476
 
 
477
/**
 
478
  Allocate memory in the connection's local memory pool
 
479
 
 
480
  @details
 
481
  When properly used in place of @c my_malloc(), this can significantly
 
482
  improve concurrency. Don't use this or related functions to allocate
 
483
  large chunks of memory. Use for temporary storage only. The memory
 
484
  will be freed automatically at the end of the statement; no explicit
 
485
  code is required to prevent memory leaks.
 
486
 
 
487
  @see alloc_root()
 
488
*/
 
489
void *thd_alloc(DRIZZLE_THD thd, unsigned int size);
 
490
/**
 
491
  @see thd_alloc()
 
492
*/
 
493
void *thd_calloc(DRIZZLE_THD thd, unsigned int size);
 
494
/**
 
495
  @see thd_alloc()
 
496
*/
 
497
char *thd_strdup(DRIZZLE_THD thd, const char *str);
 
498
/**
 
499
  @see thd_alloc()
 
500
*/
 
501
char *thd_strmake(DRIZZLE_THD thd, const char *str, unsigned int size);
 
502
/**
 
503
  @see thd_alloc()
 
504
*/
 
505
void *thd_memdup(DRIZZLE_THD thd, const void* str, unsigned int size);
 
506
 
 
507
/**
 
508
  Get the XID for this connection's transaction
 
509
 
 
510
  @param thd  user thread connection handle
 
511
  @param xid  location where identifier is stored
 
512
*/
 
513
void thd_get_xid(const DRIZZLE_THD thd, DRIZZLE_XID *xid);
426
514
 
427
515
/**
428
516
  Invalidate the query cache for a given table.
429
517
 
430
 
  @param session         user thread connection handle
 
518
  @param thd         user thread connection handle
431
519
  @param key         databasename\\0tablename\\0
432
520
  @param key_length  length of key in bytes, including the NUL bytes
433
521
  @param using_trx   flag: TRUE if using transactions, FALSE otherwise
434
522
*/
435
 
void mysql_query_cache_invalidate4(Session *session,
 
523
void mysql_query_cache_invalidate4(DRIZZLE_THD thd,
436
524
                                   const char *key, unsigned int key_length,
437
525
                                   int using_trx);
438
526
 
439
 
} /* namespace drizzled */
440
 
 
441
 
#endif /* DRIZZLED_PLUGIN_H */
 
527
#ifdef __cplusplus
 
528
}
 
529
#endif
 
530
 
 
531
#ifdef __cplusplus
 
532
/**
 
533
  Provide a handler data getter to simplify coding
 
534
*/
 
535
inline
 
536
void *
 
537
thd_get_ha_data(const DRIZZLE_THD thd, const struct handlerton *hton)
 
538
{
 
539
  return *thd_ha_data(thd, hton);
 
540
}
 
541
 
 
542
/**
 
543
  Provide a handler data setter to simplify coding
 
544
*/
 
545
inline
 
546
void
 
547
thd_set_ha_data(const DRIZZLE_THD thd, const struct handlerton *hton,
 
548
                const void *ha_data)
 
549
{
 
550
  *thd_ha_data(thd, hton)= (void*) ha_data;
 
551
}
 
552
#endif
 
553
 
 
554
#endif
442
555