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 #include <drizzled/catalog/instance.h>
00031 
00032 #include <vector>
00033 #include <string>
00034 #include <sstream>
00035 
00036 using namespace std;
00037 using namespace drizzled;
00038 
00039 StateTool::StateTool(const char *arg, bool global) :
00040   plugin::TableFunction("DATA_DICTIONARY", arg),
00041   option_type(global ? OPT_GLOBAL : OPT_SESSION)
00042 {
00043   add_field("VARIABLE_NAME");
00044   add_field("VARIABLE_VALUE", 1024);
00045 }
00046 
00047 StateTool::Generator::Generator(Field **arg, sql_var_t option_arg, drizzle_show_var *variables_args) :
00048   plugin::TableFunction::Generator(arg),
00049   option_type(option_arg),
00050   variables(variables_args)
00051 {
00052 }
00053 
00054 bool StateTool::Generator::populate()
00055 {
00056   while (variables && variables->name)
00057   {
00058     drizzle_show_var *var;
00059     MY_ALIGNED_BYTE_ARRAY(buff_data, SHOW_VAR_FUNC_BUFF_SIZE, int64_t);
00060     char* buff= (char *) &buff_data;
00061 
00062     /*
00063       if var->type is SHOW_FUNC, call the function.
00064       Repeat as necessary, if new var is again SHOW_FUNC
00065     */
00066     {
00067       drizzle_show_var tmp;
00068 
00069       for (var= variables; var->type == SHOW_FUNC; var= &tmp)
00070         ((drizzle_show_var_func)((st_show_var_func_container *)var->value)->func)(&tmp, buff);
00071     }
00072 
00073     if (isWild(variables->name))
00074     {
00075       variables++;
00076       continue;
00077     }
00078 
00079     fill(variables->name, var->value, var->type);
00080 
00081     variables++;
00082 
00083     return true;
00084   }
00085 
00086   return false;
00087 }
00088 
00089 void StateTool::Generator::fill(const std::string &name, const char *value, SHOW_TYPE show_type)
00090 {
00091   boost::mutex::scoped_lock lock(getSession().catalog().systemVariableLock());
00092 
00093   if (show_type == SHOW_SYS)
00094   {
00095     show_type= ((sys_var*) value)->show_type();
00096     value= (const char*) ((sys_var*) value)->value_ptr(&(getSession()), option_type);
00097   }
00098 
00099   std::string return_value= StatusHelper::fillHelper(NULL, value, show_type); 
00100   push(name);
00101   push(return_value.empty() ? " " : return_value);
00102 }