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 |
#ifdef DBUG_OFF
|
|
89 |
typedef struct st_plugin_int *plugin_ref; |
|
90 |
#define plugin_decl(pi) ((pi)->plugin)
|
|
91 |
#define plugin_dlib(pi) ((pi)->plugin_dl)
|
|
92 |
#define plugin_data(pi,cast) ((cast)((pi)->data))
|
|
93 |
#define plugin_name(pi) (&((pi)->name))
|
|
94 |
#define plugin_state(pi) ((pi)->state)
|
|
95 |
#define plugin_equals(p1,p2) ((p1) == (p2))
|
|
96 |
#else
|
|
97 |
typedef struct st_plugin_int **plugin_ref; |
|
98 |
#define plugin_decl(pi) ((pi)[0]->plugin)
|
|
99 |
#define plugin_dlib(pi) ((pi)[0]->plugin_dl)
|
|
100 |
#define plugin_data(pi,cast) ((cast)((pi)[0]->data))
|
|
101 |
#define plugin_name(pi) (&((pi)[0]->name))
|
|
102 |
#define plugin_state(pi) ((pi)[0]->state)
|
|
103 |
#define plugin_equals(p1,p2) ((p1) && (p2) && (p1)[0] == (p2)[0])
|
|
104 |
#endif
|
|
105 |
||
106 |
typedef int (*plugin_type_init)(struct st_plugin_int *); |
|
107 |
||
108 |
extern char *opt_plugin_load; |
|
109 |
extern char *opt_plugin_dir_ptr; |
|
110 |
extern char opt_plugin_dir[FN_REFLEN]; |
|
111 |
extern const LEX_STRING plugin_type_names[]; |
|
112 |
||
113 |
extern int plugin_init(int *argc, char **argv, int init_flags); |
|
114 |
extern void plugin_shutdown(void); |
|
115 |
extern void my_print_help_inc_plugins(struct my_option *options, uint size); |
|
116 |
extern bool plugin_is_ready(const LEX_STRING *name, int type); |
|
117 |
#define my_plugin_lock_by_name(A,B,C) plugin_lock_by_name(A,B,C CALLER_INFO)
|
|
118 |
#define my_plugin_lock_by_name_ci(A,B,C) plugin_lock_by_name(A,B,C ORIG_CALLER_INFO)
|
|
119 |
#define my_plugin_lock(A,B) plugin_lock(A,B CALLER_INFO)
|
|
120 |
#define my_plugin_lock_ci(A,B) plugin_lock(A,B ORIG_CALLER_INFO)
|
|
121 |
extern plugin_ref plugin_lock(THD *thd, plugin_ref *ptr CALLER_INFO_PROTO); |
|
122 |
extern plugin_ref plugin_lock_by_name(THD *thd, const LEX_STRING *name, |
|
123 |
int type CALLER_INFO_PROTO); |
|
124 |
extern void plugin_unlock(THD *thd, plugin_ref plugin); |
|
125 |
extern void plugin_unlock_list(THD *thd, plugin_ref *list, uint count); |
|
126 |
extern bool mysql_install_plugin(THD *thd, const LEX_STRING *name, |
|
127 |
const LEX_STRING *dl); |
|
128 |
extern bool mysql_uninstall_plugin(THD *thd, const LEX_STRING *name); |
|
129 |
extern bool plugin_register_builtin(struct st_mysql_plugin *plugin); |
|
130 |
extern void plugin_thdvar_init(THD *thd); |
|
131 |
extern void plugin_thdvar_cleanup(THD *thd); |
|
132 |
||
133 |
typedef my_bool (plugin_foreach_func)(THD *thd, |
|
134 |
plugin_ref plugin, |
|
135 |
void *arg); |
|
136 |
#define plugin_foreach(A,B,C,D) plugin_foreach_with_mask(A,B,C,PLUGIN_IS_READY,D)
|
|
137 |
extern bool plugin_foreach_with_mask(THD *thd, plugin_foreach_func *func, |
|
138 |
int type, uint state_mask, void *arg); |
|
139 |
#endif
|