~drizzle-trunk/drizzle/development

1 by brian
clean slate
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 _sql_plugin_h
17
#define _sql_plugin_h
18
19
class sys_var;
20
21
/*
22
  the following flags are valid for plugin_init()
23
*/
24
#define PLUGIN_INIT_SKIP_DYNAMIC_LOADING 1
25
#define PLUGIN_INIT_SKIP_PLUGIN_TABLE    2
26
#define PLUGIN_INIT_SKIP_INITIALIZATION  4
27
28
#define INITIAL_LEX_PLUGIN_LIST_SIZE    16
29
30
/*
31
  the following #define adds server-only members to enum_mysql_show_type,
32
  that is defined in plugin.h
33
*/
34
#define SHOW_FUNC    SHOW_FUNC, SHOW_KEY_CACHE_LONG, SHOW_KEY_CACHE_LONGLONG, \
35
                     SHOW_LONG_STATUS, SHOW_DOUBLE_STATUS, SHOW_HAVE,   \
36
                     SHOW_MY_BOOL, SHOW_HA_ROWS, SHOW_SYS, SHOW_LONG_NOFLUSH, \
37
                     SHOW_LONGLONG_STATUS
38
#include <mysql/plugin.h>
39
#undef SHOW_FUNC
40
typedef enum enum_mysql_show_type SHOW_TYPE;
41
typedef struct st_mysql_show_var SHOW_VAR;
42
43
#define MYSQL_ANY_PLUGIN         -1
44
45
/*
46
  different values of st_plugin_int::state
47
  though they look like a bitmap, plugin may only
48
  be in one of those eigenstates, not in a superposition of them :)
49
  It's a bitmap, because it makes it easier to test
50
  "whether the state is one of those..."
51
*/
52
#define PLUGIN_IS_FREED         1
53
#define PLUGIN_IS_DELETED       2
54
#define PLUGIN_IS_UNINITIALIZED 4
55
#define PLUGIN_IS_READY         8
56
#define PLUGIN_IS_DYING         16
57
58
/* A handle for the dynamic library containing a plugin or plugins. */
59
60
struct st_plugin_dl
61
{
62
  LEX_STRING dl;
63
  void *handle;
64
  struct st_mysql_plugin *plugins;
65
  int version;
66
  uint ref_count;            /* number of plugins loaded from the library */
67
};
68
69
/* A handle of a plugin */
70
71
struct st_plugin_int
72
{
73
  LEX_STRING name;
74
  struct st_mysql_plugin *plugin;
75
  struct st_plugin_dl *plugin_dl;
76
  uint state;
77
  uint ref_count;               /* number of threads using the plugin */
78
  void *data;                   /* plugin type specific, e.g. handlerton */
79
  MEM_ROOT mem_root;            /* memory for dynamic plugin structures */
80
  sys_var *system_vars;         /* server variables for this plugin */
81
};
82
83
84
/*
85
  See intern_plugin_lock() for the explanation for the
86
  conditionally defined plugin_ref type
87
*/
88
typedef struct st_plugin_int **plugin_ref;
89
#define plugin_decl(pi) ((pi)[0]->plugin)
90
#define plugin_dlib(pi) ((pi)[0]->plugin_dl)
91
#define plugin_data(pi,cast) ((cast)((pi)[0]->data))
92
#define plugin_name(pi) (&((pi)[0]->name))
93
#define plugin_state(pi) ((pi)[0]->state)
94
#define plugin_equals(p1,p2) ((p1) && (p2) && (p1)[0] == (p2)[0])
95
96
typedef int (*plugin_type_init)(struct st_plugin_int *);
97
98
extern char *opt_plugin_load;
99
extern char *opt_plugin_dir_ptr;
100
extern char opt_plugin_dir[FN_REFLEN];
101
extern const LEX_STRING plugin_type_names[];
102
103
extern int plugin_init(int *argc, char **argv, int init_flags);
104
extern void plugin_shutdown(void);
105
extern void my_print_help_inc_plugins(struct my_option *options, uint size);
106
extern bool plugin_is_ready(const LEX_STRING *name, int type);
107
#define my_plugin_lock_by_name(A,B,C) plugin_lock_by_name(A,B,C CALLER_INFO)
108
#define my_plugin_lock_by_name_ci(A,B,C) plugin_lock_by_name(A,B,C ORIG_CALLER_INFO)
109
#define my_plugin_lock(A,B) plugin_lock(A,B CALLER_INFO)
110
#define my_plugin_lock_ci(A,B) plugin_lock(A,B ORIG_CALLER_INFO)
111
extern plugin_ref plugin_lock(THD *thd, plugin_ref *ptr CALLER_INFO_PROTO);
112
extern plugin_ref plugin_lock_by_name(THD *thd, const LEX_STRING *name,
113
                                      int type CALLER_INFO_PROTO);
114
extern void plugin_unlock(THD *thd, plugin_ref plugin);
115
extern void plugin_unlock_list(THD *thd, plugin_ref *list, uint count);
116
extern bool mysql_install_plugin(THD *thd, const LEX_STRING *name,
117
                                 const LEX_STRING *dl);
118
extern bool mysql_uninstall_plugin(THD *thd, const LEX_STRING *name);
119
extern bool plugin_register_builtin(struct st_mysql_plugin *plugin);
120
extern void plugin_thdvar_init(THD *thd);
121
extern void plugin_thdvar_cleanup(THD *thd);
122
149 by Brian Aker
More bool conversion.
123
typedef bool (plugin_foreach_func)(THD *thd,
124
                                   plugin_ref plugin,
125
                                   void *arg);
1 by brian
clean slate
126
#define plugin_foreach(A,B,C,D) plugin_foreach_with_mask(A,B,C,PLUGIN_IS_READY,D)
127
extern bool plugin_foreach_with_mask(THD *thd, plugin_foreach_func *func,
128
                                     int type, uint state_mask, void *arg);
129
#endif