My Project
sql_plugin.h
00001 /* Copyright (c) 2005, 2013, Oracle and/or its affiliates. All rights reserved.
00002 
00003    This program is free software; you can redistribute it and/or modify
00004    it under the terms of the GNU General Public License as published by
00005    the Free Software Foundation; version 2 of the License.
00006 
00007    This program is distributed in the hope that it will be useful,
00008    but WITHOUT ANY WARRANTY; without even the implied warranty of
00009    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00010    GNU General Public License for more details.
00011 
00012    You should have received a copy of the GNU General Public License
00013    along with this program; if not, write to the Free Software Foundation,
00014    51 Franklin Street, Suite 500, Boston, MA 02110-1335 USA */
00015 
00016 #ifndef _sql_plugin_h
00017 #define _sql_plugin_h
00018 
00019 #include <my_global.h>
00020 #include <vector>
00021 
00026 #define SHOW_always_last SHOW_KEY_CACHE_LONG, \
00027             SHOW_KEY_CACHE_LONGLONG, SHOW_LONG_STATUS, SHOW_DOUBLE_STATUS, \
00028             SHOW_HAVE, SHOW_MY_BOOL, SHOW_HA_ROWS, SHOW_SYS, \
00029             SHOW_LONG_NOFLUSH, SHOW_LONGLONG_STATUS, SHOW_LEX_STRING, \
00030             SHOW_SIGNED_LONG
00031 #include <mysql/plugin.h>
00032 #undef SHOW_always_last
00033 
00034 #include "m_string.h"                       /* LEX_STRING */
00035 #include "my_alloc.h"                       /* MEM_ROOT */
00036 #include "my_getopt.h"                      /* my_option */
00037 
00038 class sys_var;
00039 enum SHOW_COMP_OPTION { SHOW_OPTION_YES, SHOW_OPTION_NO, SHOW_OPTION_DISABLED};
00040 enum enum_plugin_load_option { PLUGIN_OFF, PLUGIN_ON, PLUGIN_FORCE,
00041   PLUGIN_FORCE_PLUS_PERMANENT };
00042 extern const char *global_plugin_typelib_names[];
00043 extern mysql_mutex_t LOCK_plugin_delete;
00044 
00045 #include <my_sys.h>
00046 #include "sql_list.h"
00047 
00048 #ifdef DBUG_OFF
00049 #define plugin_ref_to_int(A) A
00050 #define plugin_int_to_ref(A) A
00051 #else
00052 #define plugin_ref_to_int(A) (A ? A[0] : NULL)
00053 #define plugin_int_to_ref(A) &(A)
00054 #endif
00055 
00056 /*
00057   the following flags are valid for plugin_init()
00058 */
00059 #define PLUGIN_INIT_SKIP_DYNAMIC_LOADING 1
00060 #define PLUGIN_INIT_SKIP_PLUGIN_TABLE    2
00061 #define PLUGIN_INIT_SKIP_INITIALIZATION  4
00062 
00063 #define INITIAL_LEX_PLUGIN_LIST_SIZE    16
00064 
00065 typedef enum enum_mysql_show_type SHOW_TYPE;
00066 typedef struct st_mysql_show_var SHOW_VAR;
00067 typedef struct st_mysql_lex_string LEX_STRING;
00068 
00069 #define MYSQL_ANY_PLUGIN         -1
00070 
00071 /*
00072   different values of st_plugin_int::state
00073   though they look like a bitmap, plugin may only
00074   be in one of those eigenstates, not in a superposition of them :)
00075   It's a bitmap, because it makes it easier to test
00076   "whether the state is one of those..."
00077 */
00078 #define PLUGIN_IS_FREED         1
00079 #define PLUGIN_IS_DELETED       2
00080 #define PLUGIN_IS_UNINITIALIZED 4
00081 #define PLUGIN_IS_READY         8
00082 #define PLUGIN_IS_DYING         16
00083 #define PLUGIN_IS_DISABLED      32
00084 
00085 /* A handle for the dynamic library containing a plugin or plugins. */
00086 
00087 struct st_plugin_dl
00088 {
00089   LEX_STRING dl;
00090   void *handle;
00091   struct st_mysql_plugin *plugins;
00092   int version;
00093   uint ref_count;            /* number of plugins loaded from the library */
00094 };
00095 
00096 /* A handle of a plugin */
00097 
00098 struct st_plugin_int
00099 {
00100   LEX_STRING name;
00101   struct st_mysql_plugin *plugin;
00102   struct st_plugin_dl *plugin_dl;
00103   uint state;
00104   uint ref_count;               /* number of threads using the plugin */
00105   void *data;                   /* plugin type specific, e.g. handlerton */
00106   MEM_ROOT mem_root;            /* memory for dynamic plugin structures */
00107   sys_var *system_vars;         /* server variables for this plugin */
00108   enum enum_plugin_load_option load_option; /* OFF, ON, FORCE, F+PERMANENT */
00109 };
00110 
00111 
00112 /*
00113   See intern_plugin_lock() for the explanation for the
00114   conditionally defined plugin_ref type
00115 */
00116 #ifdef DBUG_OFF
00117 typedef struct st_plugin_int *plugin_ref;
00118 #define plugin_decl(pi) ((pi)->plugin)
00119 #define plugin_dlib(pi) ((pi)->plugin_dl)
00120 #define plugin_data(pi,cast) ((cast)((pi)->data))
00121 #define plugin_name(pi) (&((pi)->name))
00122 #define plugin_state(pi) ((pi)->state)
00123 #define plugin_load_option(pi) ((pi)->load_option)
00124 #define plugin_equals(p1,p2) ((p1) == (p2))
00125 #else
00126 typedef struct st_plugin_int **plugin_ref;
00127 #define plugin_decl(pi) ((pi)[0]->plugin)
00128 #define plugin_dlib(pi) ((pi)[0]->plugin_dl)
00129 #define plugin_data(pi,cast) ((cast)((pi)[0]->data))
00130 #define plugin_name(pi) (&((pi)[0]->name))
00131 #define plugin_state(pi) ((pi)[0]->state)
00132 #define plugin_load_option(pi) ((pi)[0]->load_option)
00133 #define plugin_equals(p1,p2) ((p1) && (p2) && (p1)[0] == (p2)[0])
00134 #endif
00135 
00136 typedef int (*plugin_type_init)(struct st_plugin_int *);
00137 
00138 extern I_List<i_string> *opt_plugin_load_list_ptr;
00139 extern char *opt_plugin_dir_ptr;
00140 extern char opt_plugin_dir[FN_REFLEN];
00141 extern const LEX_STRING plugin_type_names[];
00142 
00143 extern int plugin_init(int *argc, char **argv, int init_flags);
00144 extern void plugin_shutdown(void);
00145 extern void memcached_shutdown(void);
00146 void add_plugin_options(std::vector<my_option> *options, MEM_ROOT *mem_root);
00147 extern bool plugin_is_ready(const LEX_STRING *name, int type);
00148 #define my_plugin_lock_by_name(A,B,C) plugin_lock_by_name(A,B,C)
00149 #define my_plugin_lock_by_name_ci(A,B,C) plugin_lock_by_name(A,B,C)
00150 #define my_plugin_lock(A,B) plugin_lock(A,B)
00151 #define my_plugin_lock_ci(A,B) plugin_lock(A,B)
00152 extern plugin_ref plugin_lock(THD *thd, plugin_ref *ptr);
00153 extern plugin_ref plugin_lock_by_name(THD *thd, const LEX_STRING *name,
00154                                       int type);
00155 extern void plugin_unlock(THD *thd, plugin_ref plugin);
00156 extern void plugin_unlock_list(THD *thd, plugin_ref *list, uint count);
00157 extern bool mysql_install_plugin(THD *thd, const LEX_STRING *name,
00158                                  const LEX_STRING *dl);
00159 extern bool mysql_uninstall_plugin(THD *thd, const LEX_STRING *name);
00160 extern bool plugin_register_builtin(struct st_mysql_plugin *plugin);
00161 extern void plugin_thdvar_init(THD *thd, bool enable_plugins);
00162 extern void plugin_thdvar_cleanup(THD *thd);
00163 extern SHOW_COMP_OPTION plugin_status(const char *name, size_t len, int type);
00164 extern bool check_valid_path(const char *path, size_t length);
00165 
00166 typedef my_bool (plugin_foreach_func)(THD *thd,
00167                                       plugin_ref plugin,
00168                                       void *arg);
00169 #define plugin_foreach(A,B,C,D) plugin_foreach_with_mask(A,B,C,PLUGIN_IS_READY,D)
00170 extern bool plugin_foreach_with_mask(THD *thd, plugin_foreach_func *func,
00171                                      int type, uint state_mask, void *arg);
00172 
00173 /* interface to randomly access plugin data */
00174 struct st_plugin_int *plugin_find_by_type(LEX_STRING *plugin, int type);
00175 int lock_plugin_data();
00176 int unlock_plugin_data();
00177 #endif
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines