~drizzle-trunk/drizzle/development

1144.5.4 by Padraig O'Sullivan
Updated the licence to be BSD since I don't see why this would need to be GPL.
1
/* 
2
 * Copyright (c) 2009, Padraig O'Sullivan
3
 * All rights reserved.
4
 *
5
 * Redistribution and use in source and binary forms, with or without
6
 * modification, are permitted provided that the following conditions are met:
7
 *
8
 *   * Redistributions of source code must retain the above copyright notice,
9
 *     this list of conditions and the following disclaimer.
10
 *   * Redistributions in binary form must reproduce the above copyright notice,
11
 *     this list of conditions and the following disclaimer in the documentation
12
 *     and/or other materials provided with the distribution.
1144.5.7 by Padraig O'Sullivan
Updated the BSD header to actually have my name instead of capttofu's!
13
 *   * Neither the name of Padraig O'Sullivan nor the names of its contributors
1144.5.4 by Padraig O'Sullivan
Updated the licence to be BSD since I don't see why this would need to be GPL.
14
 *     may be used to endorse or promote products derived from this software
15
 *     without specific prior written permission.
16
 *
17
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
18
 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20
 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
21
 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22
 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23
 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24
 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25
 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26
 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
27
 * THE POSSIBILITY OF SUCH DAMAGE.
1144.5.1 by Padraig O'Sullivan
Created plugin which simply adds I_S tables for querying memcached stats.
28
 */
29
1241.9.36 by Monty Taylor
ZOMG. I deleted drizzled/server_includes.h.
30
#include "config.h"
1144.5.1 by Padraig O'Sullivan
Created plugin which simply adds I_S tables for querying memcached stats.
31
#include "drizzled/show.h"
32
#include "drizzled/gettext.h"
1660.8.1 by Vijay Samuel
Merge refactored commandline for memcached_stats using boost::program_options
33
#include <boost/program_options.hpp>
34
#include <drizzled/module/option_map.h>
1144.5.1 by Padraig O'Sullivan
Created plugin which simply adds I_S tables for querying memcached stats.
35
#include "stats_table.h"
1144.5.2 by Padraig O'Sullivan
Added another I_S table for memcached. This time added an I_S table for
36
#include "analysis_table.h"
1144.5.3 by Padraig O'Sullivan
Added support for system variables to set the memcached servers whose
37
#include "sysvar_holder.h"
1144.5.1 by Padraig O'Sullivan
Created plugin which simply adds I_S tables for querying memcached stats.
38
39
#include <string>
40
#include <map>
41
1660.8.1 by Vijay Samuel
Merge refactored commandline for memcached_stats using boost::program_options
42
namespace po=boost::program_options;
1144.5.1 by Padraig O'Sullivan
Created plugin which simply adds I_S tables for querying memcached stats.
43
using namespace std;
44
using namespace drizzled;
45
46
/*
1300.2.2 by Joe Daly
port memcached stats plugin to use data_dictionary
47
 * DATA_DICTIONARY tables.
48
 */
49
static AnalysisTableTool *analysis_table_tool; 
50
51
static StatsTableTool *stats_table_tool;
1144.5.1 by Padraig O'Sullivan
Created plugin which simply adds I_S tables for querying memcached stats.
52
53
/*
54
 * System variable related variables.
55
 */
56
static char *sysvar_memcached_servers= NULL;
57
58
/**
59
 * Initialize the memcached stats plugin.
60
 *
61
 * @param[in] registry the drizzled::plugin::Registry singleton
62
 * @return false on success; true on failure.
63
 */
1530.2.6 by Monty Taylor
Moved plugin::Context to module::Context.
64
static int init(module::Context &context)
1144.5.1 by Padraig O'Sullivan
Created plugin which simply adds I_S tables for querying memcached stats.
65
{
1660.8.1 by Vijay Samuel
Merge refactored commandline for memcached_stats using boost::program_options
66
  const module::option_map &vm= context.getOptions();
67
68
  if(vm.count("servers"))
69
  {
70
    sysvar_memcached_servers= strdup(vm["servers"].as<string>().c_str());
71
  }
72
73
  else
74
  {
1666.4.19 by Monty Taylor
Free strdup'd option strings.
75
    sysvar_memcached_servers= strdup("");
1660.8.1 by Vijay Samuel
Merge refactored commandline for memcached_stats using boost::program_options
76
  }
1144.5.1 by Padraig O'Sullivan
Created plugin which simply adds I_S tables for querying memcached stats.
77
1144.5.3 by Padraig O'Sullivan
Added support for system variables to set the memcached servers whose
78
  SysvarHolder &sysvar_holder= SysvarHolder::singleton();
79
  sysvar_holder.setServersString(sysvar_memcached_servers);
1666.4.19 by Monty Taylor
Free strdup'd option strings.
80
  sysvar_holder.setMemoryPtr(sysvar_memcached_servers);
1144.5.3 by Padraig O'Sullivan
Added support for system variables to set the memcached servers whose
81
1144.5.1 by Padraig O'Sullivan
Created plugin which simply adds I_S tables for querying memcached stats.
82
  /* we are good to go */
1300.2.2 by Joe Daly
port memcached stats plugin to use data_dictionary
83
  stats_table_tool= new(std::nothrow)StatsTableTool; 
1324.2.2 by Monty Taylor
Use the plugin::Context everywhere.
84
  context.add(stats_table_tool);
1300.2.2 by Joe Daly
port memcached stats plugin to use data_dictionary
85
86
  analysis_table_tool= new(std::nothrow)AnalysisTableTool;
1324.2.2 by Monty Taylor
Use the plugin::Context everywhere.
87
  context.add(analysis_table_tool);
1144.5.1 by Padraig O'Sullivan
Created plugin which simply adds I_S tables for querying memcached stats.
88
1144.5.8 by Padraig O'Sullivan
Updating the init and deinit method to return the correct type (int instead
89
  return 0;
1144.5.1 by Padraig O'Sullivan
Created plugin which simply adds I_S tables for querying memcached stats.
90
}
91
1144.5.3 by Padraig O'Sullivan
Added support for system variables to set the memcached servers whose
92
static int check_memc_servers(Session *,
1228.1.5 by Monty Taylor
Merged in some naming things.
93
                              drizzle_sys_var *,
1144.5.14 by Padraig O'Sullivan
Fixed the issue with system variables on Fedora. Turns out the save variable
94
                              void *save,
1228.1.5 by Monty Taylor
Merged in some naming things.
95
                              drizzle_value *value)
1144.5.3 by Padraig O'Sullivan
Added support for system variables to set the memcached servers whose
96
{
97
  char buff[STRING_BUFFER_USUAL_SIZE];
98
  int len= sizeof(buff);
99
  const char *input= value->val_str(value, buff, &len);
100
101
  if (input)
102
  {
103
    SysvarHolder &sysvar_holder= SysvarHolder::singleton();
104
    sysvar_holder.setServersStringVar(input);
1144.5.14 by Padraig O'Sullivan
Fixed the issue with system variables on Fedora. Turns out the save variable
105
    *(bool *) save= (bool) true;
1144.5.3 by Padraig O'Sullivan
Added support for system variables to set the memcached servers whose
106
    return 0;
107
  }
108
1144.5.14 by Padraig O'Sullivan
Fixed the issue with system variables on Fedora. Turns out the save variable
109
  *(bool *) save= (bool) false;
1144.5.3 by Padraig O'Sullivan
Added support for system variables to set the memcached servers whose
110
  return 1;
111
}
112
113
static void set_memc_servers(Session *,
1228.1.5 by Monty Taylor
Merged in some naming things.
114
                             drizzle_sys_var *,
1144.5.3 by Padraig O'Sullivan
Added support for system variables to set the memcached servers whose
115
                             void *var_ptr,
116
                             const void *save)
117
{
1144.5.14 by Padraig O'Sullivan
Fixed the issue with system variables on Fedora. Turns out the save variable
118
  if (*(bool *) save != false)
1144.5.3 by Padraig O'Sullivan
Added support for system variables to set the memcached servers whose
119
  {
120
    SysvarHolder &sysvar_holder= SysvarHolder::singleton();
121
    sysvar_holder.updateServersSysvar((const char **) var_ptr);
122
  }
123
}
124
1144.5.1 by Padraig O'Sullivan
Created plugin which simply adds I_S tables for querying memcached stats.
125
static DRIZZLE_SYSVAR_STR(servers,
126
                          sysvar_memcached_servers,
127
                          PLUGIN_VAR_OPCMDARG,
128
                          N_("List of memcached servers."),
1144.5.3 by Padraig O'Sullivan
Added support for system variables to set the memcached servers whose
129
                          check_memc_servers, /* check func */
130
                          set_memc_servers, /* update func */
1144.5.5 by Padraig O'Sullivan
Updated the default value for the memcached servers to be the empty string.
131
                          ""); /* default value */
1144.5.1 by Padraig O'Sullivan
Created plugin which simply adds I_S tables for querying memcached stats.
132
1660.8.1 by Vijay Samuel
Merge refactored commandline for memcached_stats using boost::program_options
133
static void init_options(drizzled::module::option_context &context)
134
{
135
  context("servers",
136
          po::value<string>(),
137
          N_("List of memcached servers."));
138
}
139
1228.1.5 by Monty Taylor
Merged in some naming things.
140
static drizzle_sys_var *system_variables[]=
1144.5.1 by Padraig O'Sullivan
Created plugin which simply adds I_S tables for querying memcached stats.
141
{
142
  DRIZZLE_SYSVAR(servers),
143
  NULL
144
};
145
1228.1.5 by Monty Taylor
Merged in some naming things.
146
DRIZZLE_DECLARE_PLUGIN
1144.5.1 by Padraig O'Sullivan
Created plugin which simply adds I_S tables for querying memcached stats.
147
{
1241.10.2 by Monty Taylor
Added support for embedding the drizzle version number in the plugin file.
148
  DRIZZLE_VERSION_ID,
1144.5.1 by Padraig O'Sullivan
Created plugin which simply adds I_S tables for querying memcached stats.
149
  "memcached_stats",
1144.5.4 by Padraig O'Sullivan
Updated the licence to be BSD since I don't see why this would need to be GPL.
150
  "1.0",
1144.5.1 by Padraig O'Sullivan
Created plugin which simply adds I_S tables for querying memcached stats.
151
  "Padraig O'Sullivan",
152
  N_("Memcached Stats as I_S tables"),
1144.5.4 by Padraig O'Sullivan
Updated the licence to be BSD since I don't see why this would need to be GPL.
153
  PLUGIN_LICENSE_BSD,
1144.5.1 by Padraig O'Sullivan
Created plugin which simply adds I_S tables for querying memcached stats.
154
  init,   /* Plugin Init      */
155
  system_variables, /* system variables */
1660.8.1 by Vijay Samuel
Merge refactored commandline for memcached_stats using boost::program_options
156
  init_options    /* config options   */
1144.5.1 by Padraig O'Sullivan
Created plugin which simply adds I_S tables for querying memcached stats.
157
}
1228.1.5 by Monty Taylor
Merged in some naming things.
158
DRIZZLE_DECLARE_PLUGIN_END;