~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to plugin/memcached_stats/memcached_stats.cc

  • Committer: Brian Aker
  • Date: 2010-06-05 00:15:57 UTC
  • mfrom: (1589.1.1 drizzle_events)
  • Revision ID: brian@gaz-20100605001557-j1k41ni5k9mis891
Merge in Barry.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/* 
2
 
 * Copyright (C) 2009, Padraig O'Sullivan
 
2
 * Copyright (c) 2009, Padraig O'Sullivan
3
3
 * All rights reserved.
4
4
 *
5
5
 * Redistribution and use in source and binary forms, with or without
27
27
 * THE POSSIBILITY OF SUCH DAMAGE.
28
28
 */
29
29
 
30
 
#include <config.h>
31
 
#include <drizzled/show.h>
32
 
#include <drizzled/gettext.h>
33
 
#include <boost/program_options.hpp>
34
 
#include <drizzled/module/option_map.h>
 
30
#include "config.h"
 
31
#include "drizzled/show.h"
 
32
#include "drizzled/gettext.h"
 
33
 
35
34
#include "stats_table.h"
36
35
#include "analysis_table.h"
37
36
#include "sysvar_holder.h"
39
38
#include <string>
40
39
#include <map>
41
40
 
42
 
namespace po=boost::program_options;
43
 
 
44
 
namespace drizzle_plugin
45
 
{
46
 
 
 
41
using namespace std;
 
42
using namespace drizzled;
47
43
 
48
44
/*
49
45
 * DATA_DICTIONARY tables.
55
51
/*
56
52
 * System variable related variables.
57
53
 */
58
 
static std::string sysvar_memcached_servers;
 
54
static char *sysvar_memcached_servers= NULL;
59
55
 
60
56
/**
61
57
 * Initialize the memcached stats plugin.
63
59
 * @param[in] registry the drizzled::plugin::Registry singleton
64
60
 * @return false on success; true on failure.
65
61
 */
66
 
static int init(drizzled::module::Context &context)
 
62
static int init(module::Context &context)
67
63
{
68
 
  const drizzled::module::option_map &vm= context.getOptions();
 
64
 
 
65
  SysvarHolder &sysvar_holder= SysvarHolder::singleton();
 
66
  sysvar_holder.setServersString(sysvar_memcached_servers);
69
67
 
70
68
  /* we are good to go */
71
 
  stats_table_tool= new StatsTableTool; 
 
69
  stats_table_tool= new(std::nothrow)StatsTableTool; 
72
70
  context.add(stats_table_tool);
73
71
 
74
 
  analysis_table_tool= new AnalysisTableTool;
 
72
  analysis_table_tool= new(std::nothrow)AnalysisTableTool;
75
73
  context.add(analysis_table_tool);
76
74
 
77
 
  context.registerVariable(new sys_var_std_string("servers",
78
 
                                                  sysvar_memcached_servers));
79
 
                          
80
75
  return 0;
81
76
}
82
77
 
83
 
static void init_options(drizzled::module::option_context &context)
84
 
{
85
 
  context("servers",
86
 
          po::value<std::string>()->default_value(""),
87
 
          _("List of memcached servers."));
88
 
}
89
 
 
90
 
} /* namespace drizzle_plugin */
 
78
static int check_memc_servers(Session *,
 
79
                              drizzle_sys_var *,
 
80
                              void *save,
 
81
                              drizzle_value *value)
 
82
{
 
83
  char buff[STRING_BUFFER_USUAL_SIZE];
 
84
  int len= sizeof(buff);
 
85
  const char *input= value->val_str(value, buff, &len);
 
86
 
 
87
  if (input)
 
88
  {
 
89
    SysvarHolder &sysvar_holder= SysvarHolder::singleton();
 
90
    sysvar_holder.setServersStringVar(input);
 
91
    *(bool *) save= (bool) true;
 
92
    return 0;
 
93
  }
 
94
 
 
95
  *(bool *) save= (bool) false;
 
96
  return 1;
 
97
}
 
98
 
 
99
static void set_memc_servers(Session *,
 
100
                             drizzle_sys_var *,
 
101
                             void *var_ptr,
 
102
                             const void *save)
 
103
{
 
104
  if (*(bool *) save != false)
 
105
  {
 
106
    SysvarHolder &sysvar_holder= SysvarHolder::singleton();
 
107
    sysvar_holder.updateServersSysvar((const char **) var_ptr);
 
108
  }
 
109
}
 
110
 
 
111
static DRIZZLE_SYSVAR_STR(servers,
 
112
                          sysvar_memcached_servers,
 
113
                          PLUGIN_VAR_OPCMDARG,
 
114
                          N_("List of memcached servers."),
 
115
                          check_memc_servers, /* check func */
 
116
                          set_memc_servers, /* update func */
 
117
                          ""); /* default value */
 
118
 
 
119
static drizzle_sys_var *system_variables[]=
 
120
{
 
121
  DRIZZLE_SYSVAR(servers),
 
122
  NULL
 
123
};
91
124
 
92
125
DRIZZLE_DECLARE_PLUGIN
93
126
{
97
130
  "Padraig O'Sullivan",
98
131
  N_("Memcached Stats as I_S tables"),
99
132
  PLUGIN_LICENSE_BSD,
100
 
  drizzle_plugin::init,   /* Plugin Init      */
101
 
  NULL, /* depends */
102
 
  drizzle_plugin::init_options    /* config options   */
 
133
  init,   /* Plugin Init      */
 
134
  system_variables, /* system variables */
 
135
  NULL    /* config options   */
103
136
}
104
137
DRIZZLE_DECLARE_PLUGIN_END;