Drizzled Public API Documentation

plugin.h
00001 /* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
00002  *  vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
00003  *
00004  *  Copyright (C) 2008 Sun Microsystems, Inc.
00005  *
00006  *  This program is free software; you can redistribute it and/or modify
00007  *  it under the terms of the GNU General Public License as published by
00008  *  the Free Software Foundation; version 2 of the License.
00009  *
00010  *  This program is distributed in the hope that it will be useful,
00011  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00012  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013  *  GNU General Public License for more details.
00014  *
00015  *  You should have received a copy of the GNU General Public License
00016  *  along with this program; if not, write to the Free Software
00017  *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
00018  */
00019 
00020 #pragma once
00021 
00022 #include <boost/program_options.hpp>
00023 #include <boost/filesystem.hpp>
00024 
00025 #include <drizzled/module/manifest.h>
00026 #include <drizzled/module/module.h>
00027 #include <drizzled/plugin/version.h>
00028 #include <drizzled/module/context.h>
00029 #include <drizzled/definitions.h>
00030 
00031 #include <drizzled/lex_string.h>
00032 #include <drizzled/sys_var.h>
00033 
00034 #include <drizzled/visibility.h>
00035 
00036 namespace drizzled {
00037 
00038 /*************************************************************************
00039   Plugin API. Common for all plugin types.
00040 */
00041 
00042 extern boost::filesystem::path plugin_dir;
00043 
00044 /*
00045   Macros for beginning and ending plugin declarations. Between
00046   DRIZZLE_DECLARE_PLUGIN and DRIZZLE_DECLARE_PLUGIN_END there should
00047   be a module::Manifest for each plugin to be declared.
00048 */
00049 
00050 
00051 #define PANDORA_CPP_NAME(x) _drizzled_ ## x ## _plugin_
00052 #define PANDORA_PLUGIN_NAME(x) PANDORA_CPP_NAME(x)
00053 #define DRIZZLE_DECLARE_PLUGIN \
00054   DRIZZLED_API ::drizzled::module::Manifest PANDORA_PLUGIN_NAME(PANDORA_MODULE_NAME)= 
00055 
00056 
00057 #define DRIZZLE_DECLARE_PLUGIN_END
00058 #define DRIZZLE_PLUGIN(init,system,options) \
00059   DRIZZLE_DECLARE_PLUGIN \
00060   { \
00061     DRIZZLE_VERSION_ID, \
00062     STRINGIFY_ARG(PANDORA_MODULE_NAME), \
00063     STRINGIFY_ARG(PANDORA_MODULE_VERSION), \
00064     STRINGIFY_ARG(PANDORA_MODULE_AUTHOR), \
00065     STRINGIFY_ARG(PANDORA_MODULE_TITLE), \
00066     PANDORA_MODULE_LICENSE, \
00067     init, \
00068     STRINGIFY_ARG(PANDORA_MODULE_DEPENDENCIES), \
00069     options \
00070   } 
00071 
00072 
00073 /*
00074   declarations for server variables and command line options
00075 */
00076 
00077 
00078 #define PLUGIN_VAR_READONLY     0x0200 /* Server variable is read only */
00079 #define PLUGIN_VAR_OPCMDARG     0x2000 /* Argument optional for cmd line */
00080 #define PLUGIN_VAR_MEMALLOC     0x8000 /* String needs memory allocated */
00081 
00082 struct drizzle_sys_var;
00083 struct drizzle_value;
00084 
00085 /*
00086   SYNOPSIS
00087     (*var_check_func)()
00088       session               thread handle
00089       var               dynamic variable being altered
00090       save              pointer to temporary storage
00091       value             user provided value
00092   RETURN
00093     0   user provided value is OK and the update func may be called.
00094     any other value indicates error.
00095 
00096   This function should parse the user provided value and store in the
00097   provided temporary storage any data as required by the update func.
00098   There is sufficient space in the temporary storage to store a double.
00099   Note that the update func may not be called if any other error occurs
00100   so any memory allocated should be thread-local so that it may be freed
00101   automatically at the end of the statement.
00102 */
00103 
00104 typedef int (*var_check_func)(Session*, drizzle_sys_var*, void* save, drizzle_value*);
00105 
00106 /*
00107   SYNOPSIS
00108     (*var_update_func)()
00109       session               thread handle
00110       var               dynamic variable being altered
00111       var_ptr           pointer to dynamic variable
00112       save              pointer to temporary storage
00113    RETURN
00114      NONE
00115 
00116    This function should use the validated value stored in the temporary store
00117    and persist it in the provided pointer to the dynamic variable.
00118    For example, strings may require memory to be allocated.
00119 */
00120 typedef void (*var_update_func)(Session*, drizzle_sys_var*, void*, const void* save);
00121 
00122 
00123 
00124 /*
00125   skeleton of a plugin variable - portion of structure common to all.
00126 */
00127 struct drizzle_sys_var
00128 {
00129 };
00130 
00131 void plugin_opt_set_limits(option *options, const drizzle_sys_var *opt);
00132 
00133 struct drizzle_value
00134 {
00135   int (*value_type)(drizzle_value *);
00136   const char *(*val_str)(drizzle_value *, char *buffer, int *length);
00137   int (*val_real)(drizzle_value *, double *realbuf);
00138   int (*val_int)(drizzle_value *, int64_t *intbuf);
00139 };
00140 
00141 
00142 /*************************************************************************
00143   Miscellaneous functions for plugin implementors
00144 */
00145 
00146 extern bool plugin_init(module::Registry&, boost::program_options::options_description &long_options);
00147 extern bool plugin_finalize(module::Registry&);
00148 extern void plugin_startup_window(module::Registry&, drizzled::Session&);
00149 extern void my_print_help_inc_plugins(option* options);
00150 extern void plugin_sessionvar_init(Session*);
00151 extern void plugin_sessionvar_cleanup(Session*);
00152 
00153 DRIZZLED_API int64_t session_test_options(const Session*, int64_t test_options);
00154 void compose_plugin_add(const std::vector<std::string>& options);
00155 void compose_plugin_remove(const std::vector<std::string>& options);
00156 void notify_plugin_load(const std::string& in_plugin_load);
00157 
00158 
00171 DRIZZLED_API int tmpfile(const char *prefix);
00172 
00173 } /* namespace drizzled */