~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to plugin/info_schema/modules.cc

Remove PLUGIN and MODULES.

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
 
 *   Modules I_S table methods.
24
 
 */
25
 
 
26
 
#include "config.h"
27
 
 
28
 
#include <vector>
29
 
 
30
 
#include "drizzled/session.h"
31
 
#include "drizzled/show.h"
32
 
#include "drizzled/plugin/library.h"
33
 
#include "drizzled/global_charset_info.h"
34
 
 
35
 
 
36
 
#include "helper_methods.h"
37
 
#include "modules.h"
38
 
 
39
 
 
40
 
using namespace drizzled;
41
 
using namespace std;
42
 
 
43
 
/*
44
 
 * Vectors of columns for the modules I_S table.
45
 
 */
46
 
static vector<const plugin::ColumnInfo *> *columns= NULL;
47
 
 
48
 
/*
49
 
 * Methods for the modules I_S table.
50
 
 */
51
 
static plugin::InfoSchemaMethods *methods= NULL;
52
 
 
53
 
/*
54
 
 * modules I_S table.
55
 
 */
56
 
static plugin::InfoSchemaTable *mods_table= NULL;
57
 
 
58
 
/**
59
 
 * Populate the vectors of columns for the I_S table.
60
 
 *
61
 
 * @return a pointer to a std::vector of Columns.
62
 
 */
63
 
vector<const plugin::ColumnInfo *> *ModulesIS::createColumns()
64
 
{
65
 
  if (columns == NULL)
66
 
  {
67
 
    columns= new vector<const plugin::ColumnInfo *>;
68
 
  }
69
 
  else
70
 
  {
71
 
    clearColumns(*columns);
72
 
  }
73
 
 
74
 
  columns->push_back(new plugin::ColumnInfo("MODULE_NAME",
75
 
                                            NAME_CHAR_LEN,
76
 
                                            DRIZZLE_TYPE_VARCHAR,
77
 
                                            0,
78
 
                                            0,
79
 
                                            "Name"));
80
 
 
81
 
  columns->push_back(new plugin::ColumnInfo("MODULE_VERSION",
82
 
                                            20,
83
 
                                            DRIZZLE_TYPE_VARCHAR,
84
 
                                            0,
85
 
                                            0,
86
 
                                            ""));
87
 
 
88
 
  columns->push_back(new plugin::ColumnInfo("MODULE_AUTHOR",
89
 
                                            NAME_CHAR_LEN,
90
 
                                            DRIZZLE_TYPE_VARCHAR,
91
 
                                            0,
92
 
                                            1,
93
 
                                            ""));
94
 
 
95
 
  columns->push_back(new plugin::ColumnInfo("IS_BUILTIN",
96
 
                                            3,
97
 
                                            DRIZZLE_TYPE_VARCHAR,
98
 
                                            0,
99
 
                                            0,
100
 
                                            ""));
101
 
 
102
 
  columns->push_back(new plugin::ColumnInfo("MODULE_LIBRARY",
103
 
                                            65535,
104
 
                                            DRIZZLE_TYPE_VARCHAR,
105
 
                                            0,
106
 
                                            1,
107
 
                                            ""));
108
 
 
109
 
  columns->push_back(new plugin::ColumnInfo("MODULE_DESCRIPTION",
110
 
                                            65535,
111
 
                                            DRIZZLE_TYPE_VARCHAR,
112
 
                                            0,
113
 
                                            1,
114
 
                                            ""));
115
 
 
116
 
  columns->push_back(new plugin::ColumnInfo("MODULE_LICENSE",
117
 
                                            80,
118
 
                                            DRIZZLE_TYPE_VARCHAR,
119
 
                                            0,
120
 
                                            1,
121
 
                                            "License"));
122
 
  return columns;
123
 
}
124
 
 
125
 
/**
126
 
 * Initialize the I_S table.
127
 
 *
128
 
 * @return a pointer to an I_S table
129
 
 */
130
 
plugin::InfoSchemaTable *ModulesIS::getTable()
131
 
{
132
 
  columns= createColumns();
133
 
 
134
 
  if (methods == NULL)
135
 
  {
136
 
    methods= new ModulesISMethods();
137
 
  }
138
 
 
139
 
  if (mods_table == NULL)
140
 
  {
141
 
    mods_table= new plugin::InfoSchemaTable("OLD_MODULES",
142
 
                                            *columns,
143
 
                                            -1, -1, false, false, 0,
144
 
                                            methods);
145
 
  }
146
 
 
147
 
  return mods_table;
148
 
}
149
 
 
150
 
/**
151
 
 * Delete memory allocated for the table, columns and methods.
152
 
 */
153
 
void ModulesIS::cleanup()
154
 
{
155
 
  clearColumns(*columns);
156
 
  delete mods_table;
157
 
  delete methods;
158
 
  delete columns;
159
 
}
160
 
 
161
 
class ShowModules : public unary_function<drizzled::plugin::Module *, bool>
162
 
{
163
 
  Session *session;
164
 
  Table *table;
165
 
  plugin::InfoSchemaTable *schema_table;
166
 
 
167
 
  const string LICENSE_GPL_STRING;
168
 
  const string LICENSE_BSD_STRING;
169
 
  const string LICENSE_LGPL_STRING;
170
 
  const string LICENSE_PROPRIETARY_STRING;
171
 
 
172
 
public:
173
 
  ShowModules(Session *session_arg, Table *table_arg,
174
 
              plugin::InfoSchemaTable *sch_tab_arg)
175
 
    : session(session_arg), table(table_arg), schema_table(sch_tab_arg),
176
 
      LICENSE_GPL_STRING("GPL"),
177
 
      LICENSE_BSD_STRING("BSD"),
178
 
      LICENSE_LGPL_STRING("LGPL"),
179
 
      LICENSE_PROPRIETARY_STRING("PROPRIETARY")
180
 
  {}
181
 
 
182
 
  result_type operator() (argument_type module)
183
 
  {
184
 
    const drizzled::plugin::Manifest &manifest= module->getManifest();
185
 
    const CHARSET_INFO * const cs= system_charset_info;
186
 
 
187
 
    table->restoreRecordAsDefault();
188
 
    table->setWriteSet(0);
189
 
    table->setWriteSet(1);
190
 
    table->setWriteSet(2);
191
 
    table->setWriteSet(3);
192
 
    table->setWriteSet(4);
193
 
    table->setWriteSet(5);
194
 
    table->setWriteSet(6);
195
 
 
196
 
    table->field[0]->store(module->getName().c_str(),
197
 
                           module->getName().size(), cs);
198
 
 
199
 
    if (manifest.version)
200
 
    {
201
 
      table->field[1]->store(manifest.version, strlen(manifest.version), cs);
202
 
      table->field[1]->set_notnull();
203
 
    }
204
 
    else
205
 
      table->field[1]->set_null();
206
 
 
207
 
    if (manifest.author)
208
 
    {
209
 
      table->field[2]->store(manifest.author, strlen(manifest.author), cs);
210
 
      table->field[2]->set_notnull();
211
 
    }
212
 
    else
213
 
    {
214
 
      table->field[2]->set_null();
215
 
    }
216
 
 
217
 
    if (module->plugin_dl == NULL)
218
 
    {
219
 
      table->field[3]->store(STRING_WITH_LEN("YES"),cs);
220
 
      table->field[4]->set_null();
221
 
    }
222
 
    else
223
 
    {
224
 
      table->field[3]->store(STRING_WITH_LEN("NO"),cs);
225
 
      table->field[4]->store(module->plugin_dl->getName().c_str(),
226
 
                             module->plugin_dl->getName().size(), cs);
227
 
    }
228
 
 
229
 
    if (manifest.descr)
230
 
    {
231
 
      table->field[5]->store(manifest.descr, strlen(manifest.descr), cs);
232
 
      table->field[5]->set_notnull();
233
 
    }
234
 
    else
235
 
    {
236
 
      table->field[5]->set_null();
237
 
    }
238
 
 
239
 
    switch (manifest.license) {
240
 
    case PLUGIN_LICENSE_GPL:
241
 
      table->field[6]->store(LICENSE_GPL_STRING.c_str(),
242
 
                             LICENSE_GPL_STRING.size(), cs);
243
 
      break;
244
 
    case PLUGIN_LICENSE_BSD:
245
 
      table->field[6]->store(LICENSE_BSD_STRING.c_str(),
246
 
                             LICENSE_BSD_STRING.size(), cs);
247
 
      break;
248
 
    case PLUGIN_LICENSE_LGPL:
249
 
      table->field[6]->store(LICENSE_LGPL_STRING.c_str(),
250
 
                             LICENSE_LGPL_STRING.size(), cs);
251
 
      break;
252
 
    default:
253
 
      table->field[6]->store(LICENSE_PROPRIETARY_STRING.c_str(),
254
 
                             LICENSE_PROPRIETARY_STRING.size(),
255
 
                             cs);
256
 
      break;
257
 
    }
258
 
    table->field[6]->set_notnull();
259
 
 
260
 
    schema_table->addRow(table->record[0], table->s->reclength);
261
 
    return false;
262
 
  }
263
 
};
264
 
 
265
 
int ModulesISMethods::fillTable(Session *session, 
266
 
                                Table *table,
267
 
                                plugin::InfoSchemaTable *schema_table)
268
 
{
269
 
  drizzled::plugin::Registry &registry= drizzled::plugin::Registry::singleton();
270
 
  vector<drizzled::plugin::Module *> modules= registry.getList(true);
271
 
  vector<drizzled::plugin::Module *>::iterator iter=
272
 
    find_if(modules.begin(), modules.end(), ShowModules(session, table, schema_table));
273
 
  if (iter != modules.end())
274
 
  {
275
 
    return 1;
276
 
  }
277
 
  return 0;
278
 
}