~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/plugin/registry.cc

  • Committer: Brian Aker
  • Date: 2008-07-28 18:01:38 UTC
  • Revision ID: brian@tangent.org-20080728180138-q2pxlq0qiapvqsdn
Remove YEAR field type

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) 2008 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; version 2 of the License.
9
 
 *
10
 
 *  This program is distributed in the hope that it will be useful,
11
 
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
 
 *  GNU General Public License for more details.
14
 
 *
15
 
 *  You should have received a copy of the GNU General Public License
16
 
 *  along with this program; if not, write to the Free Software
17
 
 *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
18
 
 */
19
 
 
20
 
#include "config.h"
21
 
 
22
 
#include <string>
23
 
#include <vector>
24
 
#include <map>
25
 
 
26
 
#include "drizzled/plugin/registry.h"
27
 
 
28
 
#include "drizzled/plugin.h"
29
 
#include "drizzled/plugin/library.h"
30
 
#include "drizzled/show.h"
31
 
#include "drizzled/cursor.h"
32
 
 
33
 
using namespace std;
34
 
 
35
 
namespace drizzled
36
 
{
37
 
 
38
 
plugin::Registry::~Registry()
39
 
{
40
 
  map<string, plugin::Library *>::iterator iter= library_map.begin();
41
 
  while (iter != library_map.end())
42
 
  {
43
 
    delete (*iter).second;
44
 
    ++iter;
45
 
  }
46
 
  library_map.clear();
47
 
}
48
 
 
49
 
void plugin::Registry::shutdown()
50
 
{
51
 
  plugin::Registry& registry= singleton();
52
 
  delete &registry;
53
 
}
54
 
 
55
 
plugin::Module *plugin::Registry::find(string name)
56
 
{
57
 
  transform(name.begin(), name.end(), name.begin(), ::tolower);
58
 
 
59
 
  map<string, plugin::Module *>::iterator map_iter;
60
 
  map_iter= module_map.find(name);
61
 
  if (map_iter != module_map.end())
62
 
    return (*map_iter).second;
63
 
  return(0);
64
 
}
65
 
 
66
 
void plugin::Registry::add(plugin::Module *handle)
67
 
{
68
 
  string add_str(handle->getName());
69
 
  transform(add_str.begin(), add_str.end(),
70
 
            add_str.begin(), ::tolower);
71
 
 
72
 
  module_map[add_str]= handle;
73
 
}
74
 
 
75
 
 
76
 
vector<plugin::Module *> plugin::Registry::getList(bool active)
77
 
{
78
 
  plugin::Module *plugin= NULL;
79
 
 
80
 
  vector<plugin::Module *> plugins;
81
 
  plugins.reserve(module_map.size());
82
 
 
83
 
  map<string, plugin::Module *>::iterator map_iter;
84
 
  for (map_iter= module_map.begin();
85
 
       map_iter != module_map.end();
86
 
       map_iter++)
87
 
  {
88
 
    plugin= (*map_iter).second;
89
 
    if (active)
90
 
      plugins.push_back(plugin);
91
 
    else if (plugin->isInited)
92
 
      plugins.push_back(plugin);
93
 
  }
94
 
 
95
 
  return plugins;
96
 
}
97
 
 
98
 
plugin::Library *plugin::Registry::addLibrary(const string &plugin_name)
99
 
{
100
 
 
101
 
  /* If this dll is already loaded just return it */
102
 
  plugin::Library *library= findLibrary(plugin_name);
103
 
  if (library != NULL)
104
 
  {
105
 
    return library;
106
 
  }
107
 
 
108
 
  library= plugin::Library::loadLibrary(plugin_name);
109
 
  if (library != NULL)
110
 
  {
111
 
    /* Add this dll to the map */
112
 
    library_map.insert(make_pair(plugin_name, library));
113
 
  }
114
 
 
115
 
  return library;
116
 
}
117
 
 
118
 
void plugin::Registry::removeLibrary(const string &plugin_name)
119
 
{
120
 
  map<string, plugin::Library *>::iterator iter=
121
 
    library_map.find(plugin_name);
122
 
  if (iter != library_map.end())
123
 
  {
124
 
    library_map.erase(iter);
125
 
    delete (*iter).second;
126
 
  }
127
 
}
128
 
 
129
 
plugin::Library *plugin::Registry::findLibrary(const string &plugin_name) const
130
 
{
131
 
  map<string, plugin::Library *>::const_iterator iter=
132
 
    library_map.find(plugin_name);
133
 
  if (iter != library_map.end())
134
 
    return (*iter).second;
135
 
  return NULL;
136
 
}
137
 
 
138
 
} /* namespace drizzled */