Drizzled Public API Documentation

status.cc
1 /* - mode: c; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2  * vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
3  *
4  * Copyright (C) 2010 Sun Microsystems, Inc.
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19  */
20 
21 #include <config.h>
22 
23 #include <plugin/status_dictionary/dictionary.h>
24 
25 #include <drizzled/pthread_globals.h>
26 #include <drizzled/internal/m_string.h>
27 #include <drizzled/definitions.h>
28 #include <drizzled/status_helper.h>
29 #include <drizzled/sql_lex.h>
30 #include <drizzled/catalog/instance.h>
31 
32 #include <vector>
33 #include <string>
34 #include <sstream>
35 
36 using namespace std;
37 using namespace drizzled;
38 
39 StateTool::StateTool(const char *arg, bool global) :
40  plugin::TableFunction("DATA_DICTIONARY", arg),
41  option_type(global ? OPT_GLOBAL : OPT_SESSION)
42 {
43  add_field("VARIABLE_NAME");
44  add_field("VARIABLE_VALUE", 1024);
45 }
46 
47 StateTool::Generator::Generator(Field **arg, sql_var_t option_arg, drizzle_show_var *variables_args) :
48  plugin::TableFunction::Generator(arg),
49  option_type(option_arg),
50  variables(variables_args)
51 {
52 }
53 
54 bool StateTool::Generator::populate()
55 {
56  while (variables && variables->name)
57  {
59  MY_ALIGNED_BYTE_ARRAY(buff_data, SHOW_VAR_FUNC_BUFF_SIZE, int64_t);
60  char* buff= (char *) &buff_data;
61 
62  /*
63  if var->type is SHOW_FUNC, call the function.
64  Repeat as necessary, if new var is again SHOW_FUNC
65  */
66  {
67  drizzle_show_var tmp;
68 
69  for (var= variables; var->type == SHOW_FUNC; var= &tmp)
70  ((drizzle_show_var_func)((st_show_var_func_container *)var->value)->func)(&tmp, buff);
71  }
72 
73  if (isWild(variables->name))
74  {
75  variables++;
76  continue;
77  }
78 
79  fill(variables->name, var->value, var->type);
80 
81  variables++;
82 
83  return true;
84  }
85 
86  return false;
87 }
88 
89 void StateTool::Generator::fill(const std::string &name, const char *value, SHOW_TYPE show_type)
90 {
91  boost::mutex::scoped_lock lock(getSession().catalog().systemVariableLock());
92 
93  if (show_type == SHOW_SYS)
94  {
95  show_type= ((sys_var*) value)->show_type();
96  value= (const char*) ((sys_var*) value)->value_ptr(&(getSession()), option_type);
97  }
98 
99  std::string return_value= StatusHelper::fillHelper(NULL, value, show_type);
100  push(name);
101  push(return_value.empty() ? " " : return_value);
102 }