~drizzle-trunk/drizzle/development

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
/* - mode: c; c-basic-offset: 2; indent-tabs-mode: nil; -*-
 *  vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
 *
 *  Copyright (C) 2009 Sun Microsystems
 *
 *  This program is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation; either version 2 of the License, or
 *  (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program; if not, write to the Free Software
 *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 */

/**
 * @file 
 *   Plugins I_S table methods.
 */

#include "drizzled/server_includes.h"
#include "drizzled/session.h"
#include "drizzled/show.h"

#include "helper_methods.h"
#include "plugins.h"

#include <vector>

using namespace drizzled;
using namespace std;

/*
 * Vectors of columns for the plugins I_S table.
 */
static vector<const plugin::ColumnInfo *> *columns= NULL;

/*
 * Methods for the plugins I_S table.
 */
static plugin::InfoSchemaMethods *methods= NULL;

/*
 * plugins I_S table.
 */
static plugin::InfoSchemaTable *plugins_table= NULL;

/**
 * Populate the vectors of columns for the I_S table.
 *
 * @return a pointer to a std::vector of Columns.
 */
vector<const plugin::ColumnInfo *> *PluginsIS::createColumns()
{
  if (columns == NULL)
  {
    columns= new vector<const plugin::ColumnInfo *>;
  }
  else
  {
    clearColumns(*columns);
  }

  columns->push_back(new plugin::ColumnInfo("PLUGIN_NAME",
                                            NAME_CHAR_LEN,
                                            DRIZZLE_TYPE_VARCHAR,
                                            0,
                                            0,
                                            "Name"));

  columns->push_back(new plugin::ColumnInfo("PLUGIN_TYPE",
                                            NAME_CHAR_LEN,
                                            DRIZZLE_TYPE_VARCHAR,
                                            0,
                                            0,
                                            ""));

  columns->push_back(new plugin::ColumnInfo("IS_ACTIVE",
                                            3,
                                            DRIZZLE_TYPE_VARCHAR,
                                            0,
                                            0,
                                            ""));

  columns->push_back(new plugin::ColumnInfo("MODULE_NAME",
                                            NAME_CHAR_LEN,
                                            DRIZZLE_TYPE_VARCHAR,
                                            0,
                                            0,
                                            "Name"));
  return columns;
}

/**
 * Initialize the I_S table.
 *
 * @return a pointer to an I_S table
 */
plugin::InfoSchemaTable *PluginsIS::getTable()
{
  columns= createColumns();

  if (methods == NULL)
  {
    methods= new PluginsISMethods();
  }

  if (plugins_table == NULL)
  {
    plugins_table= new plugin::InfoSchemaTable("PLUGINS",
                                               *columns,
                                               -1, -1, false, false, 0,
                                               methods);
  }

  return plugins_table;
}

/**
 * Delete memory allocated for the table, columns and methods.
 */
void PluginsIS::cleanup()
{
  clearColumns(*columns);
  delete plugins_table;
  delete methods;
  delete columns;
}

class ShowPlugins
 : public unary_function<pair<const string, const drizzled::plugin::Plugin *>, bool>
{
  Session *session;
  Table *table;
  plugin::InfoSchemaTable *schema_table;
public:
  ShowPlugins(Session *session_arg, Table *table_arg, plugin::InfoSchemaTable *sch_tab_arg)
    : session(session_arg), table(table_arg), schema_table(sch_tab_arg) {}

  result_type operator() (argument_type plugin)
  {
    const CHARSET_INFO * const cs= system_charset_info;

    table->restoreRecordAsDefault();

    /* mark fields that will be written to in the write bitset */
    table->setWriteSet(0);
    table->setWriteSet(1);
    table->setWriteSet(2);
    table->setWriteSet(3);
    table->setWriteSet(4);
    table->setWriteSet(5);

    table->field[0]->store(plugin.first.c_str(),
                           plugin.first.size(), cs);

    table->field[1]->store(plugin.second->getTypeName().c_str(),
                           plugin.second->getTypeName().size(), cs);

    if (plugin.second->isActive())
    {
      table->field[2]->store(STRING_WITH_LEN("YES"),cs);
    }
    else
    {
      table->field[2]->store(STRING_WITH_LEN("NO"), cs);
    }

    table->field[3]->store(plugin.second->getModuleName().c_str(),
                           plugin.second->getModuleName().size(), cs);

    schema_table->addRow(table->record[0], table->s->reclength);
    return false;
  }
};

int PluginsISMethods::fillTable(Session *session, 
                                Table *table,
                                plugin::InfoSchemaTable *schema_table)
{
  drizzled::plugin::Registry &registry= drizzled::plugin::Registry::singleton();
  const map<string, const drizzled::plugin::Plugin *> &plugin_map=
    registry.getPluginsMap();
  map<string, const drizzled::plugin::Plugin *>::const_iterator iter=
    find_if(plugin_map.begin(), plugin_map.end(), ShowPlugins(session, table, schema_table));
  if (iter != plugin_map.end())
  {
    return 1;
  }
  return 0;
}