~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/plugin.h

  • Committer: Brian Aker
  • Date: 2010-04-05 23:46:43 UTC
  • Revision ID: brian@gaz-20100405234643-0he3xnj902rc70r8
Fixing tests to work with PBXT.

Show diffs side-by-side

added added

removed removed

Lines of Context:
22
22
 
23
23
#include <drizzled/lex_string.h>
24
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"
 
29
#include "drizzled/plugin/context.h"
 
30
 
 
31
 
 
32
namespace drizzled
 
33
{
25
34
 
26
35
class Session;
27
36
class Item;
32
41
*/
33
42
 
34
43
 
 
44
class sys_var;
 
45
typedef drizzle_lex_string LEX_STRING;
 
46
struct option;
 
47
 
 
48
extern char *opt_plugin_add;
 
49
extern char *opt_plugin_remove;
 
50
extern char *opt_plugin_load;
 
51
extern char *opt_plugin_dir_ptr;
 
52
extern char opt_plugin_dir[FN_REFLEN];
 
53
 
 
54
namespace plugin { class StorageEngine; }
 
55
 
35
56
/*
36
57
  Macros for beginning and ending plugin declarations. Between
37
 
  drizzle_declare_plugin and drizzle_declare_plugin_end there should
38
 
  be a drizzled::plugin::Manifest for each plugin to be declared.
39
 
*/
40
 
 
41
 
 
42
 
#ifndef PANDORA_DYNAMIC_PLUGIN
43
 
#define __DRIZZLE_DECLARE_PLUGIN(NAME, DECLS) \
44
 
drizzled::plugin::Manifest DECLS[]= {
45
 
#else
46
 
#define __DRIZZLE_DECLARE_PLUGIN(NAME, DECLS) \
47
 
drizzled::plugin::Manifest _drizzled_plugin_declaration_[]= {
48
 
#endif
49
 
 
50
 
#define drizzle_declare_plugin(NAME) \
51
 
__DRIZZLE_DECLARE_PLUGIN(NAME, \
52
 
                 builtin_ ## NAME ## _plugin)
53
 
 
54
 
#define drizzle_declare_plugin_end ,{0,0,0,0,PLUGIN_LICENSE_GPL,0,0,0,0,0}}
55
 
 
56
 
 
57
 
 
58
 
/*
59
 
  the following flags are valid for plugin_init()
60
 
*/
61
 
#define PLUGIN_INIT_SKIP_DYNAMIC_LOADING 1
62
 
#define PLUGIN_INIT_SKIP_PLUGIN_TABLE    2
63
 
#define PLUGIN_INIT_SKIP_INITIALIZATION  4
64
 
 
65
 
#define INITIAL_LEX_PLUGIN_LIST_SIZE    16
 
58
  DRIZZLE_DECLARE_PLUGIN and DRIZZLE_DECLARE_PLUGIN_END there should
 
59
  be a plugin::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::plugin::Manifest PANDORA_PLUGIN_NAME(PANDORA_MODULE_NAME)= 
 
67
 
 
68
 
 
69
#define DRIZZLE_DECLARE_PLUGIN_END
 
70
#define DRIZZLE_PLUGIN(init,system) \
 
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, NULL \
 
80
  } 
 
81
 
66
82
 
67
83
/*
68
84
  declarations for SHOW STATUS support in plugins
71
87
{
72
88
  SHOW_UNDEF, SHOW_BOOL, SHOW_INT, SHOW_LONG,
73
89
  SHOW_LONGLONG, SHOW_CHAR, SHOW_CHAR_PTR,
74
 
  SHOW_ARRAY, SHOW_FUNC, SHOW_KEY_CACHE_LONG, SHOW_KEY_CACHE_LONGLONG,
75
 
  SHOW_LONG_STATUS, SHOW_DOUBLE_STATUS, SHOW_HAVE, 
 
90
  SHOW_FUNC, SHOW_KEY_CACHE_LONG, SHOW_KEY_CACHE_LONGLONG,
 
91
  SHOW_LONG_STATUS, SHOW_DOUBLE_STATUS,
76
92
  SHOW_MY_BOOL, SHOW_HA_ROWS, SHOW_SYS, SHOW_INT_NOFLUSH,
77
93
  SHOW_LONGLONG_STATUS, SHOW_DOUBLE, SHOW_SIZE
78
94
};
79
95
 
80
 
struct st_mysql_show_var {
 
96
struct drizzle_show_var {
81
97
  const char *name;
82
98
  char *value;
83
99
  enum enum_mysql_show_type type;
84
100
};
85
101
 
86
102
typedef enum enum_mysql_show_type SHOW_TYPE;
87
 
typedef struct st_mysql_show_var SHOW_VAR;
88
103
 
89
104
 
90
105
#define SHOW_VAR_FUNC_BUFF_SIZE 1024
91
 
typedef int (*mysql_show_var_func)(struct st_mysql_show_var *, char *);
 
106
typedef int (*mysql_show_var_func)(drizzle_show_var *, char *);
92
107
 
93
108
struct st_show_var_func_container {
94
109
  mysql_show_var_func func;
103
118
#define PLUGIN_VAR_LONG         0x0003
104
119
#define PLUGIN_VAR_LONGLONG     0x0004
105
120
#define PLUGIN_VAR_STR          0x0005
106
 
#define PLUGIN_VAR_ENUM         0x0006
107
 
#define PLUGIN_VAR_SET          0x0007
108
121
#define PLUGIN_VAR_UNSIGNED     0x0080
109
122
#define PLUGIN_VAR_SessionLOCAL     0x0100 /* Variable is per-connection */
110
123
#define PLUGIN_VAR_READONLY     0x0200 /* Server variable is read only */
115
128
#define PLUGIN_VAR_OPCMDARG     0x2000 /* Argument optional for cmd line */
116
129
#define PLUGIN_VAR_MEMALLOC     0x8000 /* String needs memory allocated */
117
130
 
118
 
struct st_mysql_sys_var;
119
 
struct st_mysql_value;
 
131
struct drizzle_sys_var;
 
132
struct drizzle_value;
120
133
 
121
134
/*
122
135
  SYNOPSIS
138
151
*/
139
152
 
140
153
typedef int (*mysql_var_check_func)(Session *session,
141
 
                                    struct st_mysql_sys_var *var,
142
 
                                    void *save, struct st_mysql_value *value);
 
154
                                    drizzle_sys_var *var,
 
155
                                    void *save, drizzle_value *value);
143
156
 
144
157
/*
145
158
  SYNOPSIS
156
169
   For example, strings may require memory to be allocated.
157
170
*/
158
171
typedef void (*mysql_var_update_func)(Session *session,
159
 
                                      struct st_mysql_sys_var *var,
 
172
                                      drizzle_sys_var *var,
160
173
                                      void *var_ptr, const void *save);
161
174
 
162
175
 
177
190
 
178
191
#define DRIZZLE_SYSVAR_NAME(name) mysql_sysvar_ ## name
179
192
#define DRIZZLE_SYSVAR(name) \
180
 
  ((struct st_mysql_sys_var *)&(DRIZZLE_SYSVAR_NAME(name)))
 
193
  ((drizzle_sys_var *)(&(DRIZZLE_SYSVAR_NAME(name))))
181
194
 
182
195
/*
183
196
  for global variables, the value pointer is the first
200
213
  type blk_sz;                  \
201
214
} DRIZZLE_SYSVAR_NAME(name)
202
215
 
203
 
#define DECLARE_DRIZZLE_SYSVAR_TYPELIB(name, type) struct { \
204
 
  DRIZZLE_PLUGIN_VAR_HEADER;      \
205
 
  type *value; type def_val;    \
206
 
  TYPELIB *typelib;             \
207
 
} DRIZZLE_SYSVAR_NAME(name)
208
 
 
209
216
#define DECLARE_SessionVAR_FUNC(type) \
210
217
  type *(*resolve)(Session *session, int offset)
211
218
 
277
284
  PLUGIN_VAR_LONGLONG | PLUGIN_VAR_UNSIGNED | ((opt) & PLUGIN_VAR_MASK), \
278
285
  #name, comment, check, update, &varname, def, min, max, blk }
279
286
 
280
 
#define DRIZZLE_SYSVAR_ENUM(name, varname, opt, comment, check, update, def, typelib) \
281
 
DECLARE_DRIZZLE_SYSVAR_TYPELIB(name, unsigned long) = { \
282
 
  PLUGIN_VAR_ENUM | ((opt) & PLUGIN_VAR_MASK), \
283
 
  #name, comment, check, update, &varname, def, typelib }
284
 
 
285
 
#define DRIZZLE_SYSVAR_SET(name, varname, opt, comment, check, update, def, typelib) \
286
 
DECLARE_DRIZZLE_SYSVAR_TYPELIB(name, uint64_t) = { \
287
 
  PLUGIN_VAR_SET | ((opt) & PLUGIN_VAR_MASK), \
288
 
  #name, comment, check, update, &varname, def, typelib }
289
 
 
290
287
#define DRIZZLE_SessionVAR_BOOL(name, opt, comment, check, update, def) \
291
288
DECLARE_DRIZZLE_SessionVAR_BASIC(name, char) = { \
292
289
  PLUGIN_VAR_BOOL | PLUGIN_VAR_SessionLOCAL | ((opt) & PLUGIN_VAR_MASK), \
327
324
  PLUGIN_VAR_LONGLONG | PLUGIN_VAR_SessionLOCAL | PLUGIN_VAR_UNSIGNED | ((opt) & PLUGIN_VAR_MASK), \
328
325
  #name, comment, check, update, -1, def, min, max, blk, NULL }
329
326
 
330
 
#define DRIZZLE_SessionVAR_ENUM(name, opt, comment, check, update, def, typelib) \
331
 
DECLARE_DRIZZLE_SessionVAR_TYPELIB(name, unsigned long) = { \
332
 
  PLUGIN_VAR_ENUM | PLUGIN_VAR_SessionLOCAL | ((opt) & PLUGIN_VAR_MASK), \
333
 
  #name, comment, check, update, -1, def, NULL, typelib }
334
 
 
335
 
#define DRIZZLE_SessionVAR_SET(name, opt, comment, check, update, def, typelib) \
336
 
DECLARE_DRIZZLE_SessionVAR_TYPELIB(name, uint64_t) = { \
337
 
  PLUGIN_VAR_SET | PLUGIN_VAR_SessionLOCAL | ((opt) & PLUGIN_VAR_MASK), \
338
 
  #name, comment, check, update, -1, def, NULL, typelib }
339
 
 
340
327
/* accessor macros */
341
328
 
342
329
#define SYSVAR(name) \
347
334
  (*(DRIZZLE_SYSVAR_NAME(name).resolve(session, DRIZZLE_SYSVAR_NAME(name).offset)))
348
335
 
349
336
 
350
 
struct StorageEngine;
351
 
 
352
 
 
353
 
class Plugin
354
 
{
355
 
private:
356
 
  std::string name;
357
 
  std::string version;
358
 
  std::string author;
359
 
  std::string description;
360
 
 
361
 
public:
362
 
  Plugin(std::string in_name, std::string in_version,
363
 
         std::string in_author, std::string in_description)
364
 
    : name(in_name), version(in_version),
365
 
    author(in_author), description(in_description)
366
 
  {}
367
 
 
368
 
  virtual ~Plugin() {}
369
 
 
370
 
  virtual void add_functions() {}
371
 
 
372
 
};
373
 
 
374
337
/*************************************************************************
375
 
  st_mysql_value struct for reading values from mysqld.
 
338
  drizzle_value struct for reading values from mysqld.
376
339
  Used by server variables framework to parse user-provided values.
377
340
  Will be used for arguments when implementing UDFs.
378
341
 
385
348
#define DRIZZLE_VALUE_TYPE_REAL   1
386
349
#define DRIZZLE_VALUE_TYPE_INT    2
387
350
 
388
 
struct st_mysql_value
389
 
{
390
 
  int (*value_type)(struct st_mysql_value *);
391
 
  const char *(*val_str)(struct st_mysql_value *, char *buffer, int *length);
392
 
  int (*val_real)(struct st_mysql_value *, double *realbuf);
393
 
  int (*val_int)(struct st_mysql_value *, int64_t *intbuf);
 
351
/*
 
352
  skeleton of a plugin variable - portion of structure common to all.
 
353
*/
 
354
struct drizzle_sys_var
 
355
{
 
356
  DRIZZLE_PLUGIN_VAR_HEADER;
 
357
};
 
358
 
 
359
void plugin_opt_set_limits(option *options, const drizzle_sys_var *opt);
 
360
 
 
361
struct drizzle_value
 
362
{
 
363
  int (*value_type)(drizzle_value *);
 
364
  const char *(*val_str)(drizzle_value *, char *buffer, int *length);
 
365
  int (*val_real)(drizzle_value *, double *realbuf);
 
366
  int (*val_int)(drizzle_value *, int64_t *intbuf);
394
367
};
395
368
 
396
369
 
402
375
extern "C" {
403
376
#endif
404
377
 
 
378
extern bool plugin_init(plugin::Registry &registry,
 
379
                        int *argc, char **argv,
 
380
                        bool skip_init);
 
381
extern void plugin_shutdown(plugin::Registry &plugins);
 
382
extern void my_print_help_inc_plugins(option *options);
 
383
extern bool plugin_is_ready(const LEX_STRING *name, int type);
 
384
extern void plugin_sessionvar_init(Session *session);
 
385
extern void plugin_sessionvar_cleanup(Session *session);
 
386
extern sys_var *intern_find_sys_var(const char *str, uint32_t, bool no_error);
 
387
 
405
388
int session_in_lock_tables(const Session *session);
406
389
int session_tablespace_op(const Session *session);
407
390
void set_session_proc_info(Session *session, const char *info);
408
391
const char *get_session_proc_info(Session *session);
409
392
int64_t session_test_options(const Session *session, int64_t test_options);
410
393
int session_sql_command(const Session *session);
411
 
void **session_ha_data(const Session *session, const struct StorageEngine *engine);
412
394
int session_tx_isolation(const Session *session);
413
 
/* Increments the row counter, see Session::row_count */
414
 
void session_inc_row_count(Session *session);
415
 
 
416
 
LEX_STRING *session_make_lex_string(Session *session, LEX_STRING *lex_str,
417
 
                                    const char *str, unsigned int size,
418
 
                                    int allocate_lex_string);
419
395
 
420
396
 
421
397
 
429
405
 
430
406
  @param prefix  prefix for temporary file name
431
407
  @retval -1    error
432
 
  @retval >= 0  a file handle that can be passed to dup or my_close
 
408
  @retval >= 0  a file handle that can be passed to dup or internal::my_close
433
409
*/
434
410
int mysql_tmpfile(const char *prefix);
435
411
 
459
435
unsigned long session_get_thread_id(const Session *session);
460
436
 
461
437
const charset_info_st *session_charset(Session *session);
462
 
char **session_query(Session *session);
463
438
int session_non_transactional_update(const Session *session);
464
439
void session_mark_transaction_to_rollback(Session *session, bool all);
465
440
 
518
493
}
519
494
#endif
520
495
 
521
 
#ifdef __cplusplus
522
 
/**
523
 
  Provide a handler data getter to simplify coding
524
 
*/
525
 
inline
526
 
void *
527
 
session_get_ha_data(const Session *session, const struct StorageEngine *engine)
528
 
{
529
 
  return *session_ha_data(session, engine);
530
 
}
531
 
 
532
 
/**
533
 
  Provide a handler data setter to simplify coding
534
 
*/
535
 
inline
536
 
void
537
 
session_set_ha_data(const Session *session, const struct StorageEngine *engine,
538
 
                const void *ha_data)
539
 
{
540
 
  *session_ha_data(session, engine)= (void*) ha_data;
541
 
}
542
 
#endif
543
 
 
544
 
#endif /* _my_plugin_h */
 
496
} /* namespace drizzled */
 
497
 
 
498
#endif /* DRIZZLED_PLUGIN_H */
545
499