~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/plugin.h

Cleanup of time code (moved into mysys)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2
 
 *  vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
3
 
 *
4
 
 *  Copyright (C) 2008 Sun Microsystems
5
 
 *
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.
9
 
 *
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.
14
 
 *
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
18
 
 */
19
 
 
20
 
#ifndef DRIZZLED_PLUGIN_H
21
 
#define DRIZZLED_PLUGIN_H
22
 
 
23
 
#include <boost/program_options.hpp>
24
 
#include <boost/filesystem.hpp>
25
 
 
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"
31
 
 
32
 
#include "drizzled/lex_string.h"
33
 
#include "drizzled/sys_var.h"
34
 
#include "drizzled/xid.h"
35
 
 
36
 
namespace drizzled
37
 
{
38
 
 
39
 
class Session;
 
1
/* Copyright (C) 2005 MySQL AB
 
2
 
 
3
   This program is free software; you can redistribute it and/or modify
 
4
   it under the terms of the GNU General Public License as published by
 
5
   the Free Software Foundation; version 2 of the License.
 
6
 
 
7
   This program is distributed in the hope that it will be useful,
 
8
   but WITHOUT ANY WARRANTY; without even the implied warranty of
 
9
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
10
   GNU General Public License for more details.
 
11
 
 
12
   You should have received a copy of the GNU General Public License
 
13
   along with this program; if not, write to the Free Software
 
14
   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA */
 
15
 
 
16
#ifndef _my_plugin_h
 
17
#define _my_plugin_h
 
18
 
 
19
#include <drizzled/global.h>
 
20
 
 
21
#ifdef __cplusplus
 
22
class THD;
40
23
class Item;
41
 
struct charset_info_st;
 
24
#define DRIZZLE_THD THD*
 
25
#else
 
26
#define DRIZZLE_THD void*
 
27
#endif
 
28
 
 
29
 
 
30
#ifndef _m_string_h
 
31
/* This definition must match the one given in m_string.h */
 
32
struct st_mysql_lex_string
 
33
{
 
34
  char *str;
 
35
  unsigned int length;
 
36
};
 
37
#endif /* _m_string_h */
 
38
typedef struct st_mysql_lex_string DRIZZLE_LEX_STRING;
 
39
 
 
40
#define DRIZZLE_XIDDATASIZE 128
 
41
/**
 
42
  struct st_mysql_xid is binary compatible with the XID structure as
 
43
  in the X/Open CAE Specification, Distributed Transaction Processing:
 
44
  The XA Specification, X/Open Company Ltd., 1991.
 
45
  http://www.opengroup.org/bookstore/catalog/c193.htm
 
46
 
 
47
  @see XID in sql/handler.h
 
48
*/
 
49
struct st_mysql_xid {
 
50
  long formatID;
 
51
  long gtrid_length;
 
52
  long bqual_length;
 
53
  char data[DRIZZLE_XIDDATASIZE];  /* Not \0-terminated */
 
54
};
 
55
typedef struct st_mysql_xid DRIZZLE_XID;
42
56
 
43
57
/*************************************************************************
44
58
  Plugin API. Common for all plugin types.
45
59
*/
46
60
 
47
 
 
48
 
class sys_var;
49
 
typedef drizzle_lex_string LEX_STRING;
50
 
struct option;
51
 
 
52
 
extern boost::filesystem::path plugin_dir;
53
 
 
54
 
namespace plugin { class StorageEngine; }
55
 
 
56
 
/*
57
 
  Macros for beginning and ending plugin declarations. Between
58
 
  DRIZZLE_DECLARE_PLUGIN and DRIZZLE_DECLARE_PLUGIN_END there should
59
 
  be a module::Manifest for each plugin to be declared.
60
 
*/
61
 
 
62
 
 
63
 
#define PANDORA_CPP_NAME(x) _drizzled_ ## x ## _plugin_
64
 
#define PANDORA_PLUGIN_NAME(x) PANDORA_CPP_NAME(x)
65
 
#define DRIZZLE_DECLARE_PLUGIN \
66
 
  ::drizzled::module::Manifest PANDORA_PLUGIN_NAME(PANDORA_MODULE_NAME)= 
67
 
 
68
 
 
69
 
#define DRIZZLE_DECLARE_PLUGIN_END
70
 
#define DRIZZLE_PLUGIN(init,system,options) \
71
 
  DRIZZLE_DECLARE_PLUGIN \
72
 
  { \
73
 
    DRIZZLE_VERSION_ID, \
74
 
    STRINGIFY_ARG(PANDORA_MODULE_NAME), \
75
 
    STRINGIFY_ARG(PANDORA_MODULE_VERSION), \
76
 
    STRINGIFY_ARG(PANDORA_MODULE_AUTHOR), \
77
 
    STRINGIFY_ARG(PANDORA_MODULE_TITLE), \
78
 
    PANDORA_MODULE_LICENSE, \
79
 
    init, system, options \
80
 
  } 
81
 
 
82
 
 
 
61
/*
 
62
  The allowable types of plugins
 
63
*/
 
64
#define DRIZZLE_DAEMON_PLUGIN          0  /* Daemon / Raw */
 
65
#define DRIZZLE_STORAGE_ENGINE_PLUGIN  1  /* Storage Engine */
 
66
#define DRIZZLE_INFORMATION_SCHEMA_PLUGIN  2  /* Information Schema */
 
67
#define DRIZZLE_UDF_PLUGIN             3  /* User-Defined Function */
 
68
#define DRIZZLE_UDA_PLUGIN             4  /* User-Defined Aggregate function */
 
69
#define DRIZZLE_AUDIT_PLUGIN           5  /* Audit */
 
70
#define DRIZZLE_LOGGER_PLUGIN          6  /* Logging */
 
71
#define DRIZZLE_AUTH_PLUGIN            7  /* Authorization */
 
72
 
 
73
#define DRIZZLE_MAX_PLUGIN_TYPE_NUM    8  /* The number of plugin types */
 
74
 
 
75
/* We use the following strings to define licenses for plugins */
 
76
#define PLUGIN_LICENSE_PROPRIETARY 0
 
77
#define PLUGIN_LICENSE_GPL 1
 
78
#define PLUGIN_LICENSE_BSD 2
 
79
 
 
80
#define PLUGIN_LICENSE_PROPRIETARY_STRING "PROPRIETARY"
 
81
#define PLUGIN_LICENSE_GPL_STRING "GPL"
 
82
#define PLUGIN_LICENSE_BSD_STRING "BSD"
 
83
 
 
84
/*
 
85
  Macros for beginning and ending plugin declarations.  Between
 
86
  mysql_declare_plugin and mysql_declare_plugin_end there should
 
87
  be a st_mysql_plugin struct for each plugin to be declared.
 
88
*/
 
89
 
 
90
 
 
91
#ifndef DRIZZLE_DYNAMIC_PLUGIN
 
92
#define __DRIZZLE_DECLARE_PLUGIN(NAME, DECLS) \
 
93
struct st_mysql_plugin DECLS[]= {
 
94
#else
 
95
#define __DRIZZLE_DECLARE_PLUGIN(NAME, DECLS) \
 
96
struct st_mysql_plugin _mysql_plugin_declarations_[]= {
 
97
#endif
 
98
 
 
99
#define mysql_declare_plugin(NAME) \
 
100
__DRIZZLE_DECLARE_PLUGIN(NAME, \
 
101
                 builtin_ ## NAME ## _plugin)
 
102
 
 
103
#define mysql_declare_plugin_end ,{0,0,0,0,0,0,0,0,0,0,0}}
 
104
 
 
105
/*
 
106
  declarations for SHOW STATUS support in plugins
 
107
*/
 
108
enum enum_mysql_show_type
 
109
{
 
110
  SHOW_UNDEF, SHOW_BOOL, SHOW_INT, SHOW_LONG,
 
111
  SHOW_LONGLONG, SHOW_CHAR, SHOW_CHAR_PTR,
 
112
  SHOW_ARRAY, SHOW_FUNC, SHOW_DOUBLE
 
113
};
 
114
 
 
115
struct st_mysql_show_var {
 
116
  const char *name;
 
117
  char *value;
 
118
  enum enum_mysql_show_type type;
 
119
};
 
120
 
 
121
 
 
122
#define SHOW_VAR_FUNC_BUFF_SIZE 1024
 
123
typedef int (*mysql_show_var_func)(DRIZZLE_THD, struct st_mysql_show_var*, char *);
 
124
 
 
125
struct st_show_var_func_container {
 
126
  mysql_show_var_func func;
 
127
};
83
128
/*
84
129
  declarations for server variables and command line options
85
130
*/
90
135
#define PLUGIN_VAR_LONG         0x0003
91
136
#define PLUGIN_VAR_LONGLONG     0x0004
92
137
#define PLUGIN_VAR_STR          0x0005
 
138
#define PLUGIN_VAR_ENUM         0x0006
 
139
#define PLUGIN_VAR_SET          0x0007
93
140
#define PLUGIN_VAR_UNSIGNED     0x0080
94
 
#define PLUGIN_VAR_SessionLOCAL     0x0100 /* Variable is per-connection */
 
141
#define PLUGIN_VAR_THDLOCAL     0x0100 /* Variable is per-connection */
95
142
#define PLUGIN_VAR_READONLY     0x0200 /* Server variable is read only */
96
143
#define PLUGIN_VAR_NOSYSVAR     0x0400 /* Not a server variable */
97
144
#define PLUGIN_VAR_NOCMDOPT     0x0800 /* Not a command line option */
100
147
#define PLUGIN_VAR_OPCMDARG     0x2000 /* Argument optional for cmd line */
101
148
#define PLUGIN_VAR_MEMALLOC     0x8000 /* String needs memory allocated */
102
149
 
103
 
struct drizzle_sys_var;
104
 
struct drizzle_value;
 
150
struct st_mysql_sys_var;
 
151
struct st_mysql_value;
105
152
 
106
153
/*
107
154
  SYNOPSIS
108
155
    (*mysql_var_check_func)()
109
 
      session               thread handle
 
156
      thd               thread handle
110
157
      var               dynamic variable being altered
111
158
      save              pointer to temporary storage
112
159
      value             user provided value
113
160
  RETURN
114
161
    0   user provided value is OK and the update func may be called.
115
162
    any other value indicates error.
116
 
 
 
163
  
117
164
  This function should parse the user provided value and store in the
118
165
  provided temporary storage any data as required by the update func.
119
166
  There is sufficient space in the temporary storage to store a double.
122
169
  automatically at the end of the statement.
123
170
*/
124
171
 
125
 
typedef int (*mysql_var_check_func)(Session *session,
126
 
                                    drizzle_sys_var *var,
127
 
                                    void *save, drizzle_value *value);
 
172
typedef int (*mysql_var_check_func)(DRIZZLE_THD thd,
 
173
                                    struct st_mysql_sys_var *var,
 
174
                                    void *save, struct st_mysql_value *value);
128
175
 
129
176
/*
130
177
  SYNOPSIS
131
178
    (*mysql_var_update_func)()
132
 
      session               thread handle
 
179
      thd               thread handle
133
180
      var               dynamic variable being altered
134
181
      var_ptr           pointer to dynamic variable
135
182
      save              pointer to temporary storage
136
183
   RETURN
137
184
     NONE
138
 
 
 
185
   
139
186
   This function should use the validated value stored in the temporary store
140
187
   and persist it in the provided pointer to the dynamic variable.
141
188
   For example, strings may require memory to be allocated.
142
189
*/
143
 
typedef void (*mysql_var_update_func)(Session *session,
144
 
                                      drizzle_sys_var *var,
 
190
typedef void (*mysql_var_update_func)(DRIZZLE_THD thd,
 
191
                                      struct st_mysql_sys_var *var,
145
192
                                      void *var_ptr, const void *save);
146
193
 
147
194
 
148
 
 
149
 
/*
150
 
  skeleton of a plugin variable - portion of structure common to all.
151
 
*/
152
 
struct drizzle_sys_var
 
195
/* the following declarations are for internal use only */
 
196
 
 
197
 
 
198
#define PLUGIN_VAR_MASK \
 
199
        (PLUGIN_VAR_READONLY | PLUGIN_VAR_NOSYSVAR | \
 
200
         PLUGIN_VAR_NOCMDOPT | PLUGIN_VAR_NOCMDARG | \
 
201
         PLUGIN_VAR_OPCMDARG | PLUGIN_VAR_RQCMDARG | PLUGIN_VAR_MEMALLOC)
 
202
 
 
203
#define DRIZZLE_PLUGIN_VAR_HEADER \
 
204
  int flags;                    \
 
205
  const char *name;             \
 
206
  const char *comment;          \
 
207
  mysql_var_check_func check;   \
 
208
  mysql_var_update_func update
 
209
 
 
210
#define DRIZZLE_SYSVAR_NAME(name) mysql_sysvar_ ## name
 
211
#define DRIZZLE_SYSVAR(name) \
 
212
  ((struct st_mysql_sys_var *)&(DRIZZLE_SYSVAR_NAME(name)))
 
213
 
 
214
/*
 
215
  for global variables, the value pointer is the first
 
216
  element after the header, the default value is the second.
 
217
  for thread variables, the value offset is the first
 
218
  element after the header, the default value is the second.
 
219
*/
 
220
   
 
221
 
 
222
#define DECLARE_DRIZZLE_SYSVAR_BASIC(name, type) struct { \
 
223
  DRIZZLE_PLUGIN_VAR_HEADER;      \
 
224
  type *value;                  \
 
225
  const type def_val;           \
 
226
} DRIZZLE_SYSVAR_NAME(name)
 
227
 
 
228
#define DECLARE_DRIZZLE_SYSVAR_SIMPLE(name, type) struct { \
 
229
  DRIZZLE_PLUGIN_VAR_HEADER;      \
 
230
  type *value; type def_val;    \
 
231
  type min_val; type max_val;   \
 
232
  type blk_sz;                  \
 
233
} DRIZZLE_SYSVAR_NAME(name)
 
234
 
 
235
#define DECLARE_DRIZZLE_SYSVAR_TYPELIB(name, type) struct { \
 
236
  DRIZZLE_PLUGIN_VAR_HEADER;      \
 
237
  type *value; type def_val;    \
 
238
  TYPELIB *typelib;             \
 
239
} DRIZZLE_SYSVAR_NAME(name)
 
240
 
 
241
#define DECLARE_THDVAR_FUNC(type) \
 
242
  type *(*resolve)(DRIZZLE_THD thd, int offset)
 
243
 
 
244
#define DECLARE_DRIZZLE_THDVAR_BASIC(name, type) struct { \
 
245
  DRIZZLE_PLUGIN_VAR_HEADER;      \
 
246
  int offset;                   \
 
247
  const type def_val;           \
 
248
  DECLARE_THDVAR_FUNC(type);    \
 
249
} DRIZZLE_SYSVAR_NAME(name)
 
250
 
 
251
#define DECLARE_DRIZZLE_THDVAR_SIMPLE(name, type) struct { \
 
252
  DRIZZLE_PLUGIN_VAR_HEADER;      \
 
253
  int offset;                   \
 
254
  type def_val; type min_val;   \
 
255
  type max_val; type blk_sz;    \
 
256
  DECLARE_THDVAR_FUNC(type);    \
 
257
} DRIZZLE_SYSVAR_NAME(name)
 
258
 
 
259
#define DECLARE_DRIZZLE_THDVAR_TYPELIB(name, type) struct { \
 
260
  DRIZZLE_PLUGIN_VAR_HEADER;      \
 
261
  int offset;                   \
 
262
  type def_val;                 \
 
263
  DECLARE_THDVAR_FUNC(type);    \
 
264
  TYPELIB *typelib;             \
 
265
} DRIZZLE_SYSVAR_NAME(name)
 
266
 
 
267
 
 
268
/*
 
269
  the following declarations are for use by plugin implementors
 
270
*/
 
271
 
 
272
#define DRIZZLE_SYSVAR_BOOL(name, varname, opt, comment, check, update, def) \
 
273
DECLARE_DRIZZLE_SYSVAR_BASIC(name, bool) = { \
 
274
  PLUGIN_VAR_BOOL | ((opt) & PLUGIN_VAR_MASK), \
 
275
  #name, comment, check, update, &varname, def}
 
276
 
 
277
#define DRIZZLE_SYSVAR_STR(name, varname, opt, comment, check, update, def) \
 
278
DECLARE_DRIZZLE_SYSVAR_BASIC(name, char *) = { \
 
279
  PLUGIN_VAR_STR | ((opt) & PLUGIN_VAR_MASK), \
 
280
  #name, comment, check, update, &varname, def}
 
281
 
 
282
#define DRIZZLE_SYSVAR_INT(name, varname, opt, comment, check, update, def, min, max, blk) \
 
283
DECLARE_DRIZZLE_SYSVAR_SIMPLE(name, int) = { \
 
284
  PLUGIN_VAR_INT | ((opt) & PLUGIN_VAR_MASK), \
 
285
  #name, comment, check, update, &varname, def, min, max, blk }
 
286
 
 
287
#define DRIZZLE_SYSVAR_UINT(name, varname, opt, comment, check, update, def, min, max, blk) \
 
288
DECLARE_DRIZZLE_SYSVAR_SIMPLE(name, unsigned int) = { \
 
289
  PLUGIN_VAR_INT | PLUGIN_VAR_UNSIGNED | ((opt) & PLUGIN_VAR_MASK), \
 
290
  #name, comment, check, update, &varname, def, min, max, blk }
 
291
 
 
292
#define DRIZZLE_SYSVAR_LONG(name, varname, opt, comment, check, update, def, min, max, blk) \
 
293
DECLARE_DRIZZLE_SYSVAR_SIMPLE(name, long) = { \
 
294
  PLUGIN_VAR_LONG | ((opt) & PLUGIN_VAR_MASK), \
 
295
  #name, comment, check, update, &varname, def, min, max, blk }
 
296
 
 
297
#define DRIZZLE_SYSVAR_ULONG(name, varname, opt, comment, check, update, def, min, max, blk) \
 
298
DECLARE_DRIZZLE_SYSVAR_SIMPLE(name, unsigned long) = { \
 
299
  PLUGIN_VAR_LONG | PLUGIN_VAR_UNSIGNED | ((opt) & PLUGIN_VAR_MASK), \
 
300
  #name, comment, check, update, &varname, def, min, max, blk }
 
301
 
 
302
#define DRIZZLE_SYSVAR_LONGLONG(name, varname, opt, comment, check, update, def, min, max, blk) \
 
303
DECLARE_DRIZZLE_SYSVAR_SIMPLE(name, int64_t) = { \
 
304
  PLUGIN_VAR_LONGLONG | ((opt) & PLUGIN_VAR_MASK), \
 
305
  #name, comment, check, update, &varname, def, min, max, blk }
 
306
 
 
307
#define DRIZZLE_SYSVAR_ULONGLONG(name, varname, opt, comment, check, update, def, min, max, blk) \
 
308
DECLARE_DRIZZLE_SYSVAR_SIMPLE(name, uint64_t) = { \
 
309
  PLUGIN_VAR_LONGLONG | PLUGIN_VAR_UNSIGNED | ((opt) & PLUGIN_VAR_MASK), \
 
310
  #name, comment, check, update, &varname, def, min, max, blk }
 
311
 
 
312
#define DRIZZLE_SYSVAR_ENUM(name, varname, opt, comment, check, update, def, typelib) \
 
313
DECLARE_DRIZZLE_SYSVAR_TYPELIB(name, unsigned long) = { \
 
314
  PLUGIN_VAR_ENUM | ((opt) & PLUGIN_VAR_MASK), \
 
315
  #name, comment, check, update, &varname, def, typelib }
 
316
 
 
317
#define DRIZZLE_SYSVAR_SET(name, varname, opt, comment, check, update, def, typelib) \
 
318
DECLARE_DRIZZLE_SYSVAR_TYPELIB(name, uint64_t) = { \
 
319
  PLUGIN_VAR_SET | ((opt) & PLUGIN_VAR_MASK), \
 
320
  #name, comment, check, update, &varname, def, typelib }
 
321
 
 
322
#define DRIZZLE_THDVAR_BOOL(name, opt, comment, check, update, def) \
 
323
DECLARE_DRIZZLE_THDVAR_BASIC(name, char) = { \
 
324
  PLUGIN_VAR_BOOL | PLUGIN_VAR_THDLOCAL | ((opt) & PLUGIN_VAR_MASK), \
 
325
  #name, comment, check, update, -1, def, NULL}
 
326
 
 
327
#define DRIZZLE_THDVAR_STR(name, opt, comment, check, update, def) \
 
328
DECLARE_DRIZZLE_THDVAR_BASIC(name, char *) = { \
 
329
  PLUGIN_VAR_STR | PLUGIN_VAR_THDLOCAL | ((opt) & PLUGIN_VAR_MASK), \
 
330
  #name, comment, check, update, -1, def, NULL}
 
331
 
 
332
#define DRIZZLE_THDVAR_INT(name, opt, comment, check, update, def, min, max, blk) \
 
333
DECLARE_DRIZZLE_THDVAR_SIMPLE(name, int) = { \
 
334
  PLUGIN_VAR_INT | PLUGIN_VAR_THDLOCAL | ((opt) & PLUGIN_VAR_MASK), \
 
335
  #name, comment, check, update, -1, def, min, max, blk, NULL }
 
336
 
 
337
#define DRIZZLE_THDVAR_UINT(name, opt, comment, check, update, def, min, max, blk) \
 
338
DECLARE_DRIZZLE_THDVAR_SIMPLE(name, unsigned int) = { \
 
339
  PLUGIN_VAR_INT | PLUGIN_VAR_THDLOCAL | PLUGIN_VAR_UNSIGNED | ((opt) & PLUGIN_VAR_MASK), \
 
340
  #name, comment, check, update, -1, def, min, max, blk, NULL }
 
341
 
 
342
#define DRIZZLE_THDVAR_LONG(name, opt, comment, check, update, def, min, max, blk) \
 
343
DECLARE_DRIZZLE_THDVAR_SIMPLE(name, long) = { \
 
344
  PLUGIN_VAR_LONG | PLUGIN_VAR_THDLOCAL | ((opt) & PLUGIN_VAR_MASK), \
 
345
  #name, comment, check, update, -1, def, min, max, blk, NULL }
 
346
 
 
347
#define DRIZZLE_THDVAR_ULONG(name, opt, comment, check, update, def, min, max, blk) \
 
348
DECLARE_DRIZZLE_THDVAR_SIMPLE(name, unsigned long) = { \
 
349
  PLUGIN_VAR_LONG | PLUGIN_VAR_THDLOCAL | PLUGIN_VAR_UNSIGNED | ((opt) & PLUGIN_VAR_MASK), \
 
350
  #name, comment, check, update, -1, def, min, max, blk, NULL }
 
351
 
 
352
#define DRIZZLE_THDVAR_LONGLONG(name, opt, comment, check, update, def, min, max, blk) \
 
353
DECLARE_DRIZZLE_THDVAR_SIMPLE(name, int64_t) = { \
 
354
  PLUGIN_VAR_LONGLONG | PLUGIN_VAR_THDLOCAL | ((opt) & PLUGIN_VAR_MASK), \
 
355
  #name, comment, check, update, -1, def, min, max, blk, NULL }
 
356
 
 
357
#define DRIZZLE_THDVAR_ULONGLONG(name, opt, comment, check, update, def, min, max, blk) \
 
358
DECLARE_DRIZZLE_THDVAR_SIMPLE(name, uint64_t) = { \
 
359
  PLUGIN_VAR_LONGLONG | PLUGIN_VAR_THDLOCAL | PLUGIN_VAR_UNSIGNED | ((opt) & PLUGIN_VAR_MASK), \
 
360
  #name, comment, check, update, -1, def, min, max, blk, NULL }
 
361
 
 
362
#define DRIZZLE_THDVAR_ENUM(name, opt, comment, check, update, def, typelib) \
 
363
DECLARE_DRIZZLE_THDVAR_TYPELIB(name, unsigned long) = { \
 
364
  PLUGIN_VAR_ENUM | PLUGIN_VAR_THDLOCAL | ((opt) & PLUGIN_VAR_MASK), \
 
365
  #name, comment, check, update, -1, def, NULL, typelib }
 
366
 
 
367
#define DRIZZLE_THDVAR_SET(name, opt, comment, check, update, def, typelib) \
 
368
DECLARE_DRIZZLE_THDVAR_TYPELIB(name, uint64_t) = { \
 
369
  PLUGIN_VAR_SET | PLUGIN_VAR_THDLOCAL | ((opt) & PLUGIN_VAR_MASK), \
 
370
  #name, comment, check, update, -1, def, NULL, typelib }
 
371
 
 
372
/* accessor macros */
 
373
 
 
374
#define SYSVAR(name) \
 
375
  (*(DRIZZLE_SYSVAR_NAME(name).value))
 
376
 
 
377
/* when thd == null, result points to global value */
 
378
#define THDVAR(thd, name) \
 
379
  (*(DRIZZLE_SYSVAR_NAME(name).resolve(thd, DRIZZLE_SYSVAR_NAME(name).offset)))
 
380
 
 
381
 
 
382
/*
 
383
  Plugin description structure.
 
384
*/
 
385
 
 
386
struct st_mysql_plugin
153
387
{
 
388
  int type;             /* the plugin type (a DRIZZLE_XXX_PLUGIN value)   */
 
389
  const char *name;     /* plugin name (for SHOW PLUGINS)               */
 
390
  const char *version;  /* plugin version (for SHOW PLUGINS)            */
 
391
  const char *author;   /* plugin author (for SHOW PLUGINS)             */
 
392
  const char *descr;    /* general descriptive text (for SHOW PLUGINS ) */
 
393
  int license;          /* the plugin license (PLUGIN_LICENSE_XXX)      */
 
394
  int (*init)(void *);  /* the function to invoke when plugin is loaded */
 
395
  int (*deinit)(void *);/* the function to invoke when plugin is unloaded */
 
396
  struct st_mysql_show_var *status_vars;
 
397
  struct st_mysql_sys_var **system_vars;
 
398
  void * __reserved1;   /* reserved for dependency checking             */
154
399
};
155
400
 
156
 
void plugin_opt_set_limits(option *options, const drizzle_sys_var *opt);
157
 
 
158
 
struct drizzle_value
 
401
struct handlerton;
 
402
 
 
403
 
 
404
/*************************************************************************
 
405
  st_mysql_value struct for reading values from mysqld.
 
406
  Used by server variables framework to parse user-provided values.
 
407
  Will be used for arguments when implementing UDFs.
 
408
 
 
409
  Note that val_str() returns a string in temporary memory
 
410
  that will be freed at the end of statement. Copy the string
 
411
  if you need it to persist.
 
412
*/
 
413
 
 
414
#define DRIZZLE_VALUE_TYPE_STRING 0
 
415
#define DRIZZLE_VALUE_TYPE_REAL   1
 
416
#define DRIZZLE_VALUE_TYPE_INT    2
 
417
 
 
418
struct st_mysql_value
159
419
{
160
 
  int (*value_type)(drizzle_value *);
161
 
  const char *(*val_str)(drizzle_value *, char *buffer, int *length);
162
 
  int (*val_real)(drizzle_value *, double *realbuf);
163
 
  int (*val_int)(drizzle_value *, int64_t *intbuf);
 
420
  int (*value_type)(struct st_mysql_value *);
 
421
  const char *(*val_str)(struct st_mysql_value *, char *buffer, int *length);
 
422
  int (*val_real)(struct st_mysql_value *, double *realbuf);
 
423
  int (*val_int)(struct st_mysql_value *, int64_t *intbuf);
164
424
};
165
425
 
166
426
 
168
428
  Miscellaneous functions for plugin implementors
169
429
*/
170
430
 
171
 
extern bool plugin_init(module::Registry &registry,
172
 
                        boost::program_options::options_description &long_options);
173
 
extern bool plugin_finalize(module::Registry &registry);
174
 
extern void my_print_help_inc_plugins(option *options);
175
 
extern bool plugin_is_ready(const LEX_STRING *name, int type);
176
 
extern void plugin_sessionvar_init(Session *session);
177
 
extern void plugin_sessionvar_cleanup(Session *session);
178
 
extern sys_var *intern_find_sys_var(const char *str, uint32_t, bool no_error);
179
 
 
180
 
int session_in_lock_tables(const Session *session);
181
 
int session_tablespace_op(const Session *session);
182
 
void set_session_proc_info(Session *session, const char *info);
183
 
const char *get_session_proc_info(Session *session);
184
 
int64_t session_test_options(const Session *session, int64_t test_options);
185
 
int session_sql_command(const Session *session);
186
 
enum_tx_isolation session_tx_isolation(const Session *session);
187
 
 
188
 
void compose_plugin_add(std::vector<std::string> options);
189
 
void compose_plugin_remove(std::vector<std::string> options);
190
 
void notify_plugin_load(std::string in_plugin_load);
191
 
 
 
431
#ifdef __cplusplus
 
432
extern "C" {
 
433
#endif
 
434
 
 
435
int thd_in_lock_tables(const DRIZZLE_THD thd);
 
436
int thd_tablespace_op(const DRIZZLE_THD thd);
 
437
int64_t thd_test_options(const DRIZZLE_THD thd, int64_t test_options);
 
438
int thd_sql_command(const DRIZZLE_THD thd);
 
439
const char *thd_proc_info(DRIZZLE_THD thd, const char *info);
 
440
void **thd_ha_data(const DRIZZLE_THD thd, const struct handlerton *hton);
 
441
int thd_tx_isolation(const DRIZZLE_THD thd);
 
442
/* Increments the row counter, see THD::row_count */
 
443
void thd_inc_row_count(DRIZZLE_THD thd);
192
444
 
193
445
/**
194
446
  Create a temporary file.
200
452
 
201
453
  @param prefix  prefix for temporary file name
202
454
  @retval -1    error
203
 
  @retval >= 0  a file handle that can be passed to dup or internal::my_close
 
455
  @retval >= 0  a file handle that can be passed to dup or my_close
204
456
*/
205
457
int mysql_tmpfile(const char *prefix);
206
458
 
207
 
} /* namespace drizzled */
208
 
 
209
 
#endif /* DRIZZLED_PLUGIN_H */
 
459
/**
 
460
  Check the killed state of a connection
 
461
 
 
462
  @details
 
463
  In MySQL support for the KILL statement is cooperative. The KILL
 
464
  statement only sets a "killed" flag. This function returns the value
 
465
  of that flag.  A thread should check it often, especially inside
 
466
  time-consuming loops, and gracefully abort the operation if it is
 
467
  non-zero.
 
468
 
 
469
  @param thd  user thread connection handle
 
470
  @retval 0  the connection is active
 
471
  @retval 1  the connection has been killed
 
472
*/
 
473
int thd_killed(const DRIZZLE_THD thd);
 
474
 
 
475
 
 
476
/**
 
477
  Return the thread id of a user thread
 
478
 
 
479
  @param thd  user thread connection handle
 
480
  @return  thread id
 
481
*/
 
482
unsigned long thd_get_thread_id(const DRIZZLE_THD thd);
 
483
 
 
484
 
 
485
/**
 
486
  Allocate memory in the connection's local memory pool
 
487
 
 
488
  @details
 
489
  When properly used in place of @c my_malloc(), this can significantly
 
490
  improve concurrency. Don't use this or related functions to allocate
 
491
  large chunks of memory. Use for temporary storage only. The memory
 
492
  will be freed automatically at the end of the statement; no explicit
 
493
  code is required to prevent memory leaks.
 
494
 
 
495
  @see alloc_root()
 
496
*/
 
497
void *thd_alloc(DRIZZLE_THD thd, unsigned int size);
 
498
/**
 
499
  @see thd_alloc()
 
500
*/
 
501
void *thd_calloc(DRIZZLE_THD thd, unsigned int size);
 
502
/**
 
503
  @see thd_alloc()
 
504
*/
 
505
char *thd_strdup(DRIZZLE_THD thd, const char *str);
 
506
/**
 
507
  @see thd_alloc()
 
508
*/
 
509
char *thd_strmake(DRIZZLE_THD thd, const char *str, unsigned int size);
 
510
/**
 
511
  @see thd_alloc()
 
512
*/
 
513
void *thd_memdup(DRIZZLE_THD thd, const void* str, unsigned int size);
 
514
 
 
515
/**
 
516
  Create a LEX_STRING in this connection's local memory pool
 
517
 
 
518
  @param thd      user thread connection handle
 
519
  @param lex_str  pointer to LEX_STRING object to be initialized
 
520
  @param str      initializer to be copied into lex_str
 
521
  @param size     length of str, in bytes
 
522
  @param allocate_lex_string  flag: if TRUE, allocate new LEX_STRING object,
 
523
                              instead of using lex_str value
 
524
  @return  NULL on failure, or pointer to the LEX_STRING object
 
525
 
 
526
  @see thd_alloc()
 
527
*/
 
528
DRIZZLE_LEX_STRING *thd_make_lex_string(DRIZZLE_THD thd, DRIZZLE_LEX_STRING *lex_str,
 
529
                                      const char *str, unsigned int size,
 
530
                                      int allocate_lex_string);
 
531
 
 
532
/**
 
533
  Get the XID for this connection's transaction
 
534
 
 
535
  @param thd  user thread connection handle
 
536
  @param xid  location where identifier is stored
 
537
*/
 
538
void thd_get_xid(const DRIZZLE_THD thd, DRIZZLE_XID *xid);
 
539
 
 
540
/**
 
541
  Invalidate the query cache for a given table.
 
542
 
 
543
  @param thd         user thread connection handle
 
544
  @param key         databasename\\0tablename\\0
 
545
  @param key_length  length of key in bytes, including the NUL bytes
 
546
  @param using_trx   flag: TRUE if using transactions, FALSE otherwise
 
547
*/
 
548
void mysql_query_cache_invalidate4(DRIZZLE_THD thd,
 
549
                                   const char *key, unsigned int key_length,
 
550
                                   int using_trx);
 
551
 
 
552
#ifdef __cplusplus
 
553
}
 
554
#endif
 
555
 
 
556
#ifdef __cplusplus
 
557
/**
 
558
  Provide a handler data getter to simplify coding
 
559
*/
 
560
inline
 
561
void *
 
562
thd_get_ha_data(const DRIZZLE_THD thd, const struct handlerton *hton)
 
563
{
 
564
  return *thd_ha_data(thd, hton);
 
565
}
 
566
 
 
567
/**
 
568
  Provide a handler data setter to simplify coding
 
569
*/
 
570
inline
 
571
void
 
572
thd_set_ha_data(const DRIZZLE_THD thd, const struct handlerton *hton,
 
573
                const void *ha_data)
 
574
{
 
575
  *thd_ha_data(thd, hton)= (void*) ha_data;
 
576
}
 
577
#endif
 
578
 
 
579
#endif
210
580