Drizzled Public API Documentation

status.cc
00001 /* - mode: c; c-basic-offset: 2; indent-tabs-mode: nil; -*-
00002  *  vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
00003  *
00004  *  Copyright (C) 2010 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; either version 2 of the License, or
00009  *  (at your option) any later version.
00010  *
00011  *  This program is distributed in the hope that it will be useful,
00012  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014  *  GNU General Public License for more details.
00015  *
00016  *  You should have received a copy of the GNU General Public License
00017  *  along with this program; if not, write to the Free Software
00018  *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
00019  */
00020 
00021 #include <config.h>
00022 
00023 #include <plugin/status_dictionary/dictionary.h>
00024 
00025 #include <drizzled/pthread_globals.h>
00026 #include <drizzled/internal/m_string.h>
00027 #include <drizzled/definitions.h>
00028 #include <drizzled/status_helper.h>
00029 #include <drizzled/sql_lex.h>
00030 
00031 #include <vector>
00032 #include <string>
00033 #include <sstream>
00034 
00035 using namespace std;
00036 using namespace drizzled;
00037 
00038 StateTool::StateTool(const char *arg, bool global) :
00039   plugin::TableFunction("DATA_DICTIONARY", arg),
00040   option_type(global ? OPT_GLOBAL : OPT_SESSION)
00041 {
00042   add_field("VARIABLE_NAME");
00043   add_field("VARIABLE_VALUE", 1024);
00044 }
00045 
00046 StateTool::Generator::Generator(Field **arg, sql_var_t option_arg,
00047                                 drizzle_show_var *variables_args)
00048                                 :
00049   plugin::TableFunction::Generator(arg),
00050   option_type(option_arg),
00051   variables(variables_args)
00052 {
00053 }
00054 
00055 StateTool::Generator::~Generator()
00056 {
00057 }
00058 
00059 bool StateTool::Generator::populate()
00060 {
00061   while (variables && variables->name)
00062   {
00063     drizzle_show_var *var;
00064     MY_ALIGNED_BYTE_ARRAY(buff_data, SHOW_VAR_FUNC_BUFF_SIZE, int64_t);
00065     char * const buff= (char *) &buff_data;
00066 
00067     /*
00068       if var->type is SHOW_FUNC, call the function.
00069       Repeat as necessary, if new var is again SHOW_FUNC
00070     */
00071     {
00072       drizzle_show_var tmp;
00073 
00074       for (var= variables; var->type == SHOW_FUNC; var= &tmp)
00075         ((drizzle_show_var_func)((st_show_var_func_container *)var->value)->func)(&tmp, buff);
00076     }
00077 
00078     if (isWild(variables->name))
00079     {
00080       variables++;
00081       continue;
00082     }
00083 
00084     fill(variables->name, var->value, var->type);
00085 
00086     variables++;
00087 
00088     return true;
00089   }
00090 
00091   return false;
00092 }
00093 
00094 void StateTool::Generator::fill(const std::string &name, char *value, SHOW_TYPE show_type)
00095 {
00096   std::ostringstream oss;
00097   std::string return_value;
00098 
00099   {
00100     boost::mutex::scoped_lock scopedLock(getSession().catalog().systemVariableLock());
00101 
00102     if (show_type == SHOW_SYS)
00103     {
00104       show_type= ((sys_var*) value)->show_type();
00105       value= (char*) ((sys_var*) value)->value_ptr(&(getSession()), option_type,
00106                                                    &null_lex_str);
00107     }
00108 
00109     return_value= StatusHelper::fillHelper(NULL, value, show_type); 
00110   }
00111   push(name);
00112 
00113   if (return_value.length())
00114     push(return_value);
00115   else 
00116     push(" ");
00117 }