~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to plugin/memcached_stats/memcached_stats.cc

  • Committer: brian
  • Date: 2008-06-25 05:29:13 UTC
  • Revision ID: brian@localhost.localdomain-20080625052913-6upwo0jsrl4lnapl
clean slate

Show diffs side-by-side

added added

removed removed

Lines of Context:
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.
13
 
 *   * Neither the name of Padraig O'Sullivan nor the names of its contributors
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.
28
 
 */
29
 
 
30
 
#include "config.h"
31
 
#include "drizzled/show.h"
32
 
#include "drizzled/gettext.h"
33
 
#include "drizzled/plugin/info_schema_table.h"
34
 
 
35
 
#include "stats_table.h"
36
 
#include "analysis_table.h"
37
 
#include "sysvar_holder.h"
38
 
 
39
 
#include <string>
40
 
#include <map>
41
 
 
42
 
using namespace std;
43
 
using namespace drizzled;
44
 
 
45
 
/*
46
 
 * DATA_DICTIONARY tables.
47
 
 */
48
 
static AnalysisTableTool *analysis_table_tool; 
49
 
 
50
 
static StatsTableTool *stats_table_tool;
51
 
 
52
 
/*
53
 
 * System variable related variables.
54
 
 */
55
 
static char *sysvar_memcached_servers= NULL;
56
 
 
57
 
/**
58
 
 * Initialize the memcached stats plugin.
59
 
 *
60
 
 * @param[in] registry the drizzled::plugin::Registry singleton
61
 
 * @return false on success; true on failure.
62
 
 */
63
 
static int init(plugin::Registry &registry)
64
 
{
65
 
 
66
 
  SysvarHolder &sysvar_holder= SysvarHolder::singleton();
67
 
  sysvar_holder.setServersString(sysvar_memcached_servers);
68
 
 
69
 
  /* we are good to go */
70
 
  stats_table_tool= new(std::nothrow)StatsTableTool; 
71
 
  registry.add(stats_table_tool);
72
 
 
73
 
  analysis_table_tool= new(std::nothrow)AnalysisTableTool;
74
 
  registry.add(analysis_table_tool);
75
 
 
76
 
  return 0;
77
 
}
78
 
 
79
 
/**
80
 
 * Clean up the memcached stats plugin.
81
 
 *
82
 
 * @param[in] registry the drizzled::plugin::Registry singleton
83
 
 * @return false on success; true on failure
84
 
 */
85
 
static int deinit(plugin::Registry &registry)
86
 
{
87
 
  registry.remove(stats_table_tool);
88
 
  delete stats_table_tool;
89
 
  registry.remove(analysis_table_tool);
90
 
  delete analysis_table_tool;
91
 
  return 0;
92
 
}
93
 
 
94
 
static int check_memc_servers(Session *,
95
 
                              drizzle_sys_var *,
96
 
                              void *save,
97
 
                              drizzle_value *value)
98
 
{
99
 
  char buff[STRING_BUFFER_USUAL_SIZE];
100
 
  int len= sizeof(buff);
101
 
  const char *input= value->val_str(value, buff, &len);
102
 
 
103
 
  if (input)
104
 
  {
105
 
    SysvarHolder &sysvar_holder= SysvarHolder::singleton();
106
 
    sysvar_holder.setServersStringVar(input);
107
 
    *(bool *) save= (bool) true;
108
 
    return 0;
109
 
  }
110
 
 
111
 
  *(bool *) save= (bool) false;
112
 
  return 1;
113
 
}
114
 
 
115
 
static void set_memc_servers(Session *,
116
 
                             drizzle_sys_var *,
117
 
                             void *var_ptr,
118
 
                             const void *save)
119
 
{
120
 
  if (*(bool *) save != false)
121
 
  {
122
 
    SysvarHolder &sysvar_holder= SysvarHolder::singleton();
123
 
    sysvar_holder.updateServersSysvar((const char **) var_ptr);
124
 
  }
125
 
}
126
 
 
127
 
static DRIZZLE_SYSVAR_STR(servers,
128
 
                          sysvar_memcached_servers,
129
 
                          PLUGIN_VAR_OPCMDARG,
130
 
                          N_("List of memcached servers."),
131
 
                          check_memc_servers, /* check func */
132
 
                          set_memc_servers, /* update func */
133
 
                          ""); /* default value */
134
 
 
135
 
static drizzle_sys_var *system_variables[]=
136
 
{
137
 
  DRIZZLE_SYSVAR(servers),
138
 
  NULL
139
 
};
140
 
 
141
 
DRIZZLE_DECLARE_PLUGIN
142
 
{
143
 
  DRIZZLE_VERSION_ID,
144
 
  "memcached_stats",
145
 
  "1.0",
146
 
  "Padraig O'Sullivan",
147
 
  N_("Memcached Stats as I_S tables"),
148
 
  PLUGIN_LICENSE_BSD,
149
 
  init,   /* Plugin Init      */
150
 
  deinit, /* Plugin Deinit    */
151
 
  system_variables, /* system variables */
152
 
  NULL    /* config options   */
153
 
}
154
 
DRIZZLE_DECLARE_PLUGIN_END;