~jaypipes/drizzle/split-xa-resource-manager

« back to all changes in this revision

Viewing changes to plugin/info_schema/plugins.cc

  • Committer: Jay Pipes
  • Date: 2010-02-14 20:26:43 UTC
  • mfrom: (1273.1.27 staging)
  • Revision ID: jpipes@serialcoder-20100214202643-ahuqvc8rhn8u7y33
Merge trunk and resolve conflicts

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* - mode: c; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2
 
 *  vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
3
 
 *
4
 
 *  Copyright (C) 2009 Sun Microsystems
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
 
/**
22
 
 * @file 
23
 
 *   Plugins I_S table methods.
24
 
 */
25
 
 
26
 
#include "config.h"
27
 
#include "drizzled/session.h"
28
 
#include "drizzled/show.h"
29
 
 
30
 
#include "helper_methods.h"
31
 
#include "plugins.h"
32
 
 
33
 
#include <vector>
34
 
 
35
 
using namespace drizzled;
36
 
using namespace std;
37
 
 
38
 
/*
39
 
 * Vectors of columns for the plugins I_S table.
40
 
 */
41
 
static vector<const plugin::ColumnInfo *> *columns= NULL;
42
 
 
43
 
/*
44
 
 * Methods for the plugins I_S table.
45
 
 */
46
 
static plugin::InfoSchemaMethods *methods= NULL;
47
 
 
48
 
/*
49
 
 * plugins I_S table.
50
 
 */
51
 
static plugin::InfoSchemaTable *plugins_table= NULL;
52
 
 
53
 
/**
54
 
 * Populate the vectors of columns for the I_S table.
55
 
 *
56
 
 * @return a pointer to a std::vector of Columns.
57
 
 */
58
 
vector<const plugin::ColumnInfo *> *PluginsIS::createColumns()
59
 
{
60
 
  if (columns == NULL)
61
 
  {
62
 
    columns= new vector<const plugin::ColumnInfo *>;
63
 
  }
64
 
  else
65
 
  {
66
 
    clearColumns(*columns);
67
 
  }
68
 
 
69
 
  columns->push_back(new plugin::ColumnInfo("PLUGIN_NAME",
70
 
                                            NAME_CHAR_LEN,
71
 
                                            DRIZZLE_TYPE_VARCHAR,
72
 
                                            0,
73
 
                                            0,
74
 
                                            "Name"));
75
 
 
76
 
  columns->push_back(new plugin::ColumnInfo("PLUGIN_TYPE",
77
 
                                            NAME_CHAR_LEN,
78
 
                                            DRIZZLE_TYPE_VARCHAR,
79
 
                                            0,
80
 
                                            0,
81
 
                                            ""));
82
 
 
83
 
  columns->push_back(new plugin::ColumnInfo("IS_ACTIVE",
84
 
                                            3,
85
 
                                            DRIZZLE_TYPE_VARCHAR,
86
 
                                            0,
87
 
                                            0,
88
 
                                            ""));
89
 
 
90
 
  columns->push_back(new plugin::ColumnInfo("MODULE_NAME",
91
 
                                            NAME_CHAR_LEN,
92
 
                                            DRIZZLE_TYPE_VARCHAR,
93
 
                                            0,
94
 
                                            0,
95
 
                                            "Name"));
96
 
  return columns;
97
 
}
98
 
 
99
 
/**
100
 
 * Initialize the I_S table.
101
 
 *
102
 
 * @return a pointer to an I_S table
103
 
 */
104
 
plugin::InfoSchemaTable *PluginsIS::getTable()
105
 
{
106
 
  columns= createColumns();
107
 
 
108
 
  if (methods == NULL)
109
 
  {
110
 
    methods= new PluginsISMethods();
111
 
  }
112
 
 
113
 
  if (plugins_table == NULL)
114
 
  {
115
 
    plugins_table= new plugin::InfoSchemaTable("PLUGINS",
116
 
                                               *columns,
117
 
                                               -1, -1, false, false, 0,
118
 
                                               methods);
119
 
  }
120
 
 
121
 
  return plugins_table;
122
 
}
123
 
 
124
 
/**
125
 
 * Delete memory allocated for the table, columns and methods.
126
 
 */
127
 
void PluginsIS::cleanup()
128
 
{
129
 
  clearColumns(*columns);
130
 
  delete plugins_table;
131
 
  delete methods;
132
 
  delete columns;
133
 
}
134
 
 
135
 
class ShowPlugins
136
 
 : public unary_function<pair<const string, const drizzled::plugin::Plugin *>, bool>
137
 
{
138
 
  Session *session;
139
 
  Table *table;
140
 
  plugin::InfoSchemaTable *schema_table;
141
 
public:
142
 
  ShowPlugins(Session *session_arg, Table *table_arg, plugin::InfoSchemaTable *sch_tab_arg)
143
 
    : session(session_arg), table(table_arg), schema_table(sch_tab_arg) {}
144
 
 
145
 
  result_type operator() (argument_type plugin)
146
 
  {
147
 
    const CHARSET_INFO * const cs= system_charset_info;
148
 
 
149
 
    table->restoreRecordAsDefault();
150
 
 
151
 
    /* mark fields that will be written to in the write bitset */
152
 
    table->setWriteSet(0);
153
 
    table->setWriteSet(1);
154
 
    table->setWriteSet(2);
155
 
    table->setWriteSet(3);
156
 
    table->setWriteSet(4);
157
 
    table->setWriteSet(5);
158
 
 
159
 
    table->field[0]->store(plugin.first.c_str(),
160
 
                           plugin.first.size(), cs);
161
 
 
162
 
    table->field[1]->store(plugin.second->getTypeName().c_str(),
163
 
                           plugin.second->getTypeName().size(), cs);
164
 
 
165
 
    if (plugin.second->isActive())
166
 
    {
167
 
      table->field[2]->store(STRING_WITH_LEN("YES"),cs);
168
 
    }
169
 
    else
170
 
    {
171
 
      table->field[2]->store(STRING_WITH_LEN("NO"), cs);
172
 
    }
173
 
 
174
 
    table->field[3]->store(plugin.second->getModuleName().c_str(),
175
 
                           plugin.second->getModuleName().size(), cs);
176
 
 
177
 
    schema_table->addRow(table->record[0], table->s->reclength);
178
 
    return false;
179
 
  }
180
 
};
181
 
 
182
 
int PluginsISMethods::fillTable(Session *session, 
183
 
                                Table *table,
184
 
                                plugin::InfoSchemaTable *schema_table)
185
 
{
186
 
  drizzled::plugin::Registry &registry= drizzled::plugin::Registry::singleton();
187
 
  const map<string, const drizzled::plugin::Plugin *> &plugin_map=
188
 
    registry.getPluginsMap();
189
 
  map<string, const drizzled::plugin::Plugin *>::const_iterator iter=
190
 
    find_if(plugin_map.begin(), plugin_map.end(), ShowPlugins(session, table, schema_table));
191
 
  if (iter != plugin_map.end())
192
 
  {
193
 
    return 1;
194
 
  }
195
 
  return 0;
196
 
}