~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/plugin.h

  • Committer: Monty Taylor
  • Date: 2008-10-20 08:48:34 UTC
  • mfrom: (520.1.22 drizzle)
  • Revision ID: monty@inaugust.com-20081020084834-xpb3w01vkcp55o02
Merged trunk.

Show diffs side-by-side

added added

removed removed

Lines of Context:
22
22
 
23
23
#include <drizzled/global.h>
24
24
 
25
 
class THD;
 
25
class Session;
26
26
class Item;
27
27
 
28
28
#define DRIZZLE_XIDDATASIZE 128
53
53
#define DRIZZLE_STORAGE_ENGINE_PLUGIN  1  /* Storage Engine */
54
54
#define DRIZZLE_INFORMATION_SCHEMA_PLUGIN  2  /* Information Schema */
55
55
#define DRIZZLE_UDF_PLUGIN             3  /* User-Defined Function */
56
 
#define DRIZZLE_UDA_PLUGIN             4  /* User-Defined Aggregate function */
 
56
#define DRIZZLE_UDA_PLUGIN             4  /* User-Defined Aggregate Function */
57
57
#define DRIZZLE_AUDIT_PLUGIN           5  /* Audit */
58
 
#define DRIZZLE_LOGGER_PLUGIN          6  /* Logging */
59
 
#define DRIZZLE_AUTH_PLUGIN            7  /* Authorization */
 
58
#define DRIZZLE_LOGGER_PLUGIN          6  /* Query Logging */
 
59
#define DRIZZLE_ERRMSG_PLUGIN          7  /* Error Messages */
 
60
#define DRIZZLE_AUTH_PLUGIN            8  /* Authorization */
 
61
#define DRIZZLE_CONFIGVAR_PLUGIN       9  /* Configuration Variables */
 
62
#define DRIZZLE_QCACHE_PLUGIN         10  /* Query Cache */
60
63
 
61
 
#define DRIZZLE_MAX_PLUGIN_TYPE_NUM    8  /* The number of plugin types */
 
64
#define DRIZZLE_MAX_PLUGIN_TYPE_NUM   11  /* The number of plugin types */
62
65
 
63
66
/* We use the following strings to define licenses for plugins */
64
67
#define PLUGIN_LICENSE_PROPRIETARY 0
108
111
 
109
112
 
110
113
#define SHOW_VAR_FUNC_BUFF_SIZE 1024
111
 
typedef int (*mysql_show_var_func)(THD *, struct st_mysql_show_var *, char *);
 
114
typedef int (*mysql_show_var_func)(Session *, struct st_mysql_show_var *, char *);
112
115
 
113
116
struct st_show_var_func_container {
114
117
  mysql_show_var_func func;
126
129
#define PLUGIN_VAR_ENUM         0x0006
127
130
#define PLUGIN_VAR_SET          0x0007
128
131
#define PLUGIN_VAR_UNSIGNED     0x0080
129
 
#define PLUGIN_VAR_THDLOCAL     0x0100 /* Variable is per-connection */
 
132
#define PLUGIN_VAR_SessionLOCAL     0x0100 /* Variable is per-connection */
130
133
#define PLUGIN_VAR_READONLY     0x0200 /* Server variable is read only */
131
134
#define PLUGIN_VAR_NOSYSVAR     0x0400 /* Not a server variable */
132
135
#define PLUGIN_VAR_NOCMDOPT     0x0800 /* Not a command line option */
141
144
/*
142
145
  SYNOPSIS
143
146
    (*mysql_var_check_func)()
144
 
      thd               thread handle
 
147
      session               thread handle
145
148
      var               dynamic variable being altered
146
149
      save              pointer to temporary storage
147
150
      value             user provided value
157
160
  automatically at the end of the statement.
158
161
*/
159
162
 
160
 
typedef int (*mysql_var_check_func)(THD *thd,
 
163
typedef int (*mysql_var_check_func)(Session *session,
161
164
                                    struct st_mysql_sys_var *var,
162
165
                                    void *save, struct st_mysql_value *value);
163
166
 
164
167
/*
165
168
  SYNOPSIS
166
169
    (*mysql_var_update_func)()
167
 
      thd               thread handle
 
170
      session               thread handle
168
171
      var               dynamic variable being altered
169
172
      var_ptr           pointer to dynamic variable
170
173
      save              pointer to temporary storage
175
178
   and persist it in the provided pointer to the dynamic variable.
176
179
   For example, strings may require memory to be allocated.
177
180
*/
178
 
typedef void (*mysql_var_update_func)(THD *thd,
 
181
typedef void (*mysql_var_update_func)(Session *session,
179
182
                                      struct st_mysql_sys_var *var,
180
183
                                      void *var_ptr, const void *save);
181
184
 
226
229
  TYPELIB *typelib;             \
227
230
} DRIZZLE_SYSVAR_NAME(name)
228
231
 
229
 
#define DECLARE_THDVAR_FUNC(type) \
230
 
  type *(*resolve)(THD *thd, int offset)
 
232
#define DECLARE_SessionVAR_FUNC(type) \
 
233
  type *(*resolve)(Session *session, int offset)
231
234
 
232
 
#define DECLARE_DRIZZLE_THDVAR_BASIC(name, type) struct { \
 
235
#define DECLARE_DRIZZLE_SessionVAR_BASIC(name, type) struct { \
233
236
  DRIZZLE_PLUGIN_VAR_HEADER;      \
234
237
  int offset;                   \
235
238
  const type def_val;           \
236
 
  DECLARE_THDVAR_FUNC(type);    \
 
239
  DECLARE_SessionVAR_FUNC(type);    \
237
240
} DRIZZLE_SYSVAR_NAME(name)
238
241
 
239
 
#define DECLARE_DRIZZLE_THDVAR_SIMPLE(name, type) struct { \
 
242
#define DECLARE_DRIZZLE_SessionVAR_SIMPLE(name, type) struct { \
240
243
  DRIZZLE_PLUGIN_VAR_HEADER;      \
241
244
  int offset;                   \
242
245
  type def_val; type min_val;   \
243
246
  type max_val; type blk_sz;    \
244
 
  DECLARE_THDVAR_FUNC(type);    \
 
247
  DECLARE_SessionVAR_FUNC(type);    \
245
248
} DRIZZLE_SYSVAR_NAME(name)
246
249
 
247
 
#define DECLARE_DRIZZLE_THDVAR_TYPELIB(name, type) struct { \
 
250
#define DECLARE_DRIZZLE_SessionVAR_TYPELIB(name, type) struct { \
248
251
  DRIZZLE_PLUGIN_VAR_HEADER;      \
249
252
  int offset;                   \
250
253
  type def_val;                 \
251
 
  DECLARE_THDVAR_FUNC(type);    \
 
254
  DECLARE_SessionVAR_FUNC(type);    \
252
255
  TYPELIB *typelib;             \
253
256
} DRIZZLE_SYSVAR_NAME(name)
254
257
 
307
310
  PLUGIN_VAR_SET | ((opt) & PLUGIN_VAR_MASK), \
308
311
  #name, comment, check, update, &varname, def, typelib }
309
312
 
310
 
#define DRIZZLE_THDVAR_BOOL(name, opt, comment, check, update, def) \
311
 
DECLARE_DRIZZLE_THDVAR_BASIC(name, char) = { \
312
 
  PLUGIN_VAR_BOOL | PLUGIN_VAR_THDLOCAL | ((opt) & PLUGIN_VAR_MASK), \
313
 
  #name, comment, check, update, -1, def, NULL}
314
 
 
315
 
#define DRIZZLE_THDVAR_STR(name, opt, comment, check, update, def) \
316
 
DECLARE_DRIZZLE_THDVAR_BASIC(name, char *) = { \
317
 
  PLUGIN_VAR_STR | PLUGIN_VAR_THDLOCAL | ((opt) & PLUGIN_VAR_MASK), \
318
 
  #name, comment, check, update, -1, def, NULL}
319
 
 
320
 
#define DRIZZLE_THDVAR_INT(name, opt, comment, check, update, def, min, max, blk) \
321
 
DECLARE_DRIZZLE_THDVAR_SIMPLE(name, int) = { \
322
 
  PLUGIN_VAR_INT | PLUGIN_VAR_THDLOCAL | ((opt) & PLUGIN_VAR_MASK), \
323
 
  #name, comment, check, update, -1, def, min, max, blk, NULL }
324
 
 
325
 
#define DRIZZLE_THDVAR_UINT(name, opt, comment, check, update, def, min, max, blk) \
326
 
DECLARE_DRIZZLE_THDVAR_SIMPLE(name, unsigned int) = { \
327
 
  PLUGIN_VAR_INT | PLUGIN_VAR_THDLOCAL | PLUGIN_VAR_UNSIGNED | ((opt) & PLUGIN_VAR_MASK), \
328
 
  #name, comment, check, update, -1, def, min, max, blk, NULL }
329
 
 
330
 
#define DRIZZLE_THDVAR_LONG(name, opt, comment, check, update, def, min, max, blk) \
331
 
DECLARE_DRIZZLE_THDVAR_SIMPLE(name, long) = { \
332
 
  PLUGIN_VAR_LONG | PLUGIN_VAR_THDLOCAL | ((opt) & PLUGIN_VAR_MASK), \
333
 
  #name, comment, check, update, -1, def, min, max, blk, NULL }
334
 
 
335
 
#define DRIZZLE_THDVAR_ULONG(name, opt, comment, check, update, def, min, max, blk) \
336
 
DECLARE_DRIZZLE_THDVAR_SIMPLE(name, unsigned long) = { \
337
 
  PLUGIN_VAR_LONG | PLUGIN_VAR_THDLOCAL | PLUGIN_VAR_UNSIGNED | ((opt) & PLUGIN_VAR_MASK), \
338
 
  #name, comment, check, update, -1, def, min, max, blk, NULL }
339
 
 
340
 
#define DRIZZLE_THDVAR_LONGLONG(name, opt, comment, check, update, def, min, max, blk) \
341
 
DECLARE_DRIZZLE_THDVAR_SIMPLE(name, int64_t) = { \
342
 
  PLUGIN_VAR_LONGLONG | PLUGIN_VAR_THDLOCAL | ((opt) & PLUGIN_VAR_MASK), \
343
 
  #name, comment, check, update, -1, def, min, max, blk, NULL }
344
 
 
345
 
#define DRIZZLE_THDVAR_ULONGLONG(name, opt, comment, check, update, def, min, max, blk) \
346
 
DECLARE_DRIZZLE_THDVAR_SIMPLE(name, uint64_t) = { \
347
 
  PLUGIN_VAR_LONGLONG | PLUGIN_VAR_THDLOCAL | PLUGIN_VAR_UNSIGNED | ((opt) & PLUGIN_VAR_MASK), \
348
 
  #name, comment, check, update, -1, def, min, max, blk, NULL }
349
 
 
350
 
#define DRIZZLE_THDVAR_ENUM(name, opt, comment, check, update, def, typelib) \
351
 
DECLARE_DRIZZLE_THDVAR_TYPELIB(name, unsigned long) = { \
352
 
  PLUGIN_VAR_ENUM | PLUGIN_VAR_THDLOCAL | ((opt) & PLUGIN_VAR_MASK), \
 
313
#define DRIZZLE_SessionVAR_BOOL(name, opt, comment, check, update, def) \
 
314
DECLARE_DRIZZLE_SessionVAR_BASIC(name, char) = { \
 
315
  PLUGIN_VAR_BOOL | PLUGIN_VAR_SessionLOCAL | ((opt) & PLUGIN_VAR_MASK), \
 
316
  #name, comment, check, update, -1, def, NULL}
 
317
 
 
318
#define DRIZZLE_SessionVAR_STR(name, opt, comment, check, update, def) \
 
319
DECLARE_DRIZZLE_SessionVAR_BASIC(name, char *) = { \
 
320
  PLUGIN_VAR_STR | PLUGIN_VAR_SessionLOCAL | ((opt) & PLUGIN_VAR_MASK), \
 
321
  #name, comment, check, update, -1, def, NULL}
 
322
 
 
323
#define DRIZZLE_SessionVAR_INT(name, opt, comment, check, update, def, min, max, blk) \
 
324
DECLARE_DRIZZLE_SessionVAR_SIMPLE(name, int) = { \
 
325
  PLUGIN_VAR_INT | PLUGIN_VAR_SessionLOCAL | ((opt) & PLUGIN_VAR_MASK), \
 
326
  #name, comment, check, update, -1, def, min, max, blk, NULL }
 
327
 
 
328
#define DRIZZLE_SessionVAR_UINT(name, opt, comment, check, update, def, min, max, blk) \
 
329
DECLARE_DRIZZLE_SessionVAR_SIMPLE(name, unsigned int) = { \
 
330
  PLUGIN_VAR_INT | PLUGIN_VAR_SessionLOCAL | PLUGIN_VAR_UNSIGNED | ((opt) & PLUGIN_VAR_MASK), \
 
331
  #name, comment, check, update, -1, def, min, max, blk, NULL }
 
332
 
 
333
#define DRIZZLE_SessionVAR_LONG(name, opt, comment, check, update, def, min, max, blk) \
 
334
DECLARE_DRIZZLE_SessionVAR_SIMPLE(name, long) = { \
 
335
  PLUGIN_VAR_LONG | PLUGIN_VAR_SessionLOCAL | ((opt) & PLUGIN_VAR_MASK), \
 
336
  #name, comment, check, update, -1, def, min, max, blk, NULL }
 
337
 
 
338
#define DRIZZLE_SessionVAR_ULONG(name, opt, comment, check, update, def, min, max, blk) \
 
339
DECLARE_DRIZZLE_SessionVAR_SIMPLE(name, unsigned long) = { \
 
340
  PLUGIN_VAR_LONG | PLUGIN_VAR_SessionLOCAL | PLUGIN_VAR_UNSIGNED | ((opt) & PLUGIN_VAR_MASK), \
 
341
  #name, comment, check, update, -1, def, min, max, blk, NULL }
 
342
 
 
343
#define DRIZZLE_SessionVAR_LONGLONG(name, opt, comment, check, update, def, min, max, blk) \
 
344
DECLARE_DRIZZLE_SessionVAR_SIMPLE(name, int64_t) = { \
 
345
  PLUGIN_VAR_LONGLONG | PLUGIN_VAR_SessionLOCAL | ((opt) & PLUGIN_VAR_MASK), \
 
346
  #name, comment, check, update, -1, def, min, max, blk, NULL }
 
347
 
 
348
#define DRIZZLE_SessionVAR_ULONGLONG(name, opt, comment, check, update, def, min, max, blk) \
 
349
DECLARE_DRIZZLE_SessionVAR_SIMPLE(name, uint64_t) = { \
 
350
  PLUGIN_VAR_LONGLONG | PLUGIN_VAR_SessionLOCAL | PLUGIN_VAR_UNSIGNED | ((opt) & PLUGIN_VAR_MASK), \
 
351
  #name, comment, check, update, -1, def, min, max, blk, NULL }
 
352
 
 
353
#define DRIZZLE_SessionVAR_ENUM(name, opt, comment, check, update, def, typelib) \
 
354
DECLARE_DRIZZLE_SessionVAR_TYPELIB(name, unsigned long) = { \
 
355
  PLUGIN_VAR_ENUM | PLUGIN_VAR_SessionLOCAL | ((opt) & PLUGIN_VAR_MASK), \
353
356
  #name, comment, check, update, -1, def, NULL, typelib }
354
357
 
355
 
#define DRIZZLE_THDVAR_SET(name, opt, comment, check, update, def, typelib) \
356
 
DECLARE_DRIZZLE_THDVAR_TYPELIB(name, uint64_t) = { \
357
 
  PLUGIN_VAR_SET | PLUGIN_VAR_THDLOCAL | ((opt) & PLUGIN_VAR_MASK), \
 
358
#define DRIZZLE_SessionVAR_SET(name, opt, comment, check, update, def, typelib) \
 
359
DECLARE_DRIZZLE_SessionVAR_TYPELIB(name, uint64_t) = { \
 
360
  PLUGIN_VAR_SET | PLUGIN_VAR_SessionLOCAL | ((opt) & PLUGIN_VAR_MASK), \
358
361
  #name, comment, check, update, -1, def, NULL, typelib }
359
362
 
360
363
/* accessor macros */
362
365
#define SYSVAR(name) \
363
366
  (*(DRIZZLE_SYSVAR_NAME(name).value))
364
367
 
365
 
/* when thd == null, result points to global value */
366
 
#define THDVAR(thd, name) \
367
 
  (*(DRIZZLE_SYSVAR_NAME(name).resolve(thd, DRIZZLE_SYSVAR_NAME(name).offset)))
 
368
/* when session == null, result points to global value */
 
369
#define SessionVAR(session, name) \
 
370
  (*(DRIZZLE_SYSVAR_NAME(name).resolve(session, DRIZZLE_SYSVAR_NAME(name).offset)))
368
371
 
369
372
 
370
373
/*
420
423
extern "C" {
421
424
#endif
422
425
 
423
 
int thd_in_lock_tables(const THD *thd);
424
 
int thd_tablespace_op(const THD *thd);
425
 
int64_t thd_test_options(const THD *thd, int64_t test_options);
426
 
int thd_sql_command(const THD *thd);
427
 
void **thd_ha_data(const THD *thd, const struct handlerton *hton);
428
 
int thd_tx_isolation(const THD *thd);
429
 
/* Increments the row counter, see THD::row_count */
430
 
void thd_inc_row_count(THD *thd);
 
426
int session_in_lock_tables(const Session *session);
 
427
int session_tablespace_op(const Session *session);
 
428
int64_t session_test_options(const Session *session, int64_t test_options);
 
429
int session_sql_command(const Session *session);
 
430
void **session_ha_data(const Session *session, const struct handlerton *hton);
 
431
int session_tx_isolation(const Session *session);
 
432
/* Increments the row counter, see Session::row_count */
 
433
void session_inc_row_count(Session *session);
431
434
 
432
435
/**
433
436
  Create a temporary file.
453
456
  time-consuming loops, and gracefully abort the operation if it is
454
457
  non-zero.
455
458
 
456
 
  @param thd  user thread connection handle
 
459
  @param session  user thread connection handle
457
460
  @retval 0  the connection is active
458
461
  @retval 1  the connection has been killed
459
462
*/
460
 
int thd_killed(const THD *thd);
 
463
int session_killed(const Session *session);
461
464
 
462
465
 
463
466
/**
464
467
  Return the thread id of a user thread
465
468
 
466
 
  @param thd  user thread connection handle
 
469
  @param session  user thread connection handle
467
470
  @return  thread id
468
471
*/
469
 
unsigned long thd_get_thread_id(const THD *thd);
 
472
unsigned long session_get_thread_id(const Session *session);
470
473
 
471
474
 
472
475
/**
481
484
 
482
485
  @see alloc_root()
483
486
*/
484
 
void *thd_alloc(THD *thd, unsigned int size);
485
 
/**
486
 
  @see thd_alloc()
487
 
*/
488
 
void *thd_calloc(THD *thd, unsigned int size);
489
 
/**
490
 
  @see thd_alloc()
491
 
*/
492
 
char *thd_strdup(THD *thd, const char *str);
493
 
/**
494
 
  @see thd_alloc()
495
 
*/
496
 
char *thd_strmake(THD *thd, const char *str, unsigned int size);
497
 
/**
498
 
  @see thd_alloc()
499
 
*/
500
 
void *thd_memdup(THD *thd, const void* str, unsigned int size);
 
487
void *session_alloc(Session *session, unsigned int size);
 
488
/**
 
489
  @see session_alloc()
 
490
*/
 
491
void *session_calloc(Session *session, unsigned int size);
 
492
/**
 
493
  @see session_alloc()
 
494
*/
 
495
char *session_strdup(Session *session, const char *str);
 
496
/**
 
497
  @see session_alloc()
 
498
*/
 
499
char *session_strmake(Session *session, const char *str, unsigned int size);
 
500
/**
 
501
  @see session_alloc()
 
502
*/
 
503
void *session_memdup(Session *session, const void* str, unsigned int size);
501
504
 
502
505
/**
503
506
  Get the XID for this connection's transaction
504
507
 
505
 
  @param thd  user thread connection handle
 
508
  @param session  user thread connection handle
506
509
  @param xid  location where identifier is stored
507
510
*/
508
 
void thd_get_xid(const THD *thd, DRIZZLE_XID *xid);
 
511
void session_get_xid(const Session *session, DRIZZLE_XID *xid);
509
512
 
510
513
/**
511
514
  Invalidate the query cache for a given table.
512
515
 
513
 
  @param thd         user thread connection handle
 
516
  @param session         user thread connection handle
514
517
  @param key         databasename\\0tablename\\0
515
518
  @param key_length  length of key in bytes, including the NUL bytes
516
519
  @param using_trx   flag: TRUE if using transactions, FALSE otherwise
517
520
*/
518
 
void mysql_query_cache_invalidate4(THD *thd,
 
521
void mysql_query_cache_invalidate4(Session *session,
519
522
                                   const char *key, unsigned int key_length,
520
523
                                   int using_trx);
521
524
 
529
532
*/
530
533
inline
531
534
void *
532
 
thd_get_ha_data(const THD *thd, const struct handlerton *hton)
 
535
session_get_ha_data(const Session *session, const struct handlerton *hton)
533
536
{
534
 
  return *thd_ha_data(thd, hton);
 
537
  return *session_ha_data(session, hton);
535
538
}
536
539
 
537
540
/**
539
542
*/
540
543
inline
541
544
void
542
 
thd_set_ha_data(const THD *thd, const struct handlerton *hton,
 
545
session_set_ha_data(const Session *session, const struct handlerton *hton,
543
546
                const void *ha_data)
544
547
{
545
 
  *thd_ha_data(thd, hton)= (void*) ha_data;
 
548
  *session_ha_data(session, hton)= (void*) ha_data;
546
549
}
547
550
#endif
548
551