drizzle
C++ MySQL-protocol-compatible database server
Loading...
Searching...
No Matches
plugin/plugin.h
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, Inc.
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
21
22#pragma once
23
24#include <string>
25#include <vector>
26#include <map>
27#include <memory>
28
29#include <drizzled/visibility.h>
30#include <drizzled/common_fwd.h>
31
32#include <boost/noncopyable.hpp>
33
34namespace drizzled {
35namespace plugin {
36
37class Plugin;
38
39/*
40 * A uniform, runtime function-pointer deleter for owned plugins. The registry
41 * map holds a single concrete unique_ptr type for every entry regardless of
42 * which language/allocator produced the plugin. The C++ path installs a
43 * delete-based function pointer (default_cxx_plugin_deleter, defined below the
44 * class once Plugin is complete); a future Rust path installs a Box::from_raw
45 * drop extern "C" function pointer. Teardown calls the right destructor per
46 * entry with zero type discrimination, at the cost of one pointer per plugin.
47 */
48typedef void (*deleter_fn)(plugin::Plugin *);
49
50class DRIZZLED_API Plugin : boost::noncopyable
51{
52private:
53 const std::string _name;
54 bool _is_active;
55 module::Module *_module;
56 const std::string _type_name;
57
58public:
59 typedef std::pair<const std::string, const std::string> map_key;
60 typedef std::unique_ptr<plugin::Plugin, deleter_fn> owned_ptr;
61 typedef std::map<const map_key, owned_ptr> map;
62 typedef std::vector<Plugin *> vector;
63
64 explicit Plugin(const std::string &name, const std::string &type_name);
65 virtual ~Plugin() {}
66
67 /*
68 * This method is called for all plug-ins on shutdown,
69 * _before_ the plug-ins are deleted. It can be used
70 * when shutdown code references other plug-ins.
71 */
72 virtual void shutdownPlugin()
73 {
74 }
75
76 // This is run after all plugins have been initialized.
77 virtual void prime()
78 {
79 }
80
81 virtual void startup(drizzled::Session &)
82 {
83 }
84
85 void activate()
86 {
87 _is_active= true;
88 }
89
90 void deactivate()
91 {
92 _is_active= false;
93 }
94
95 bool isActive() const
96 {
97 return _is_active;
98 }
99
100 const std::string &getName() const
101 {
102 return _name;
103 }
104
105 void setModule(module::Module *module)
106 {
107 _module= module;
108 }
109
110 const std::string& getTypeName() const
111 {
112 return _type_name;
113 }
114
115 virtual bool removeLast() const
116 {
117 return false;
118 }
119
120 const std::string& getModuleName() const;
121};
122
123/*
124 * Default C++ deleter, defined here where Plugin is a complete type so the
125 * virtual destructor is in scope and `delete` is well-defined. This is the
126 * deleter forwarded by the one-arg Registry::add / context::add overloads.
127 */
128inline void default_cxx_plugin_deleter(plugin::Plugin *p) { delete p; }
129
130} /* end namespace plugin */
131} /* end namespace drizzled */
TODO: Rename this file - func.h is stupid.
Visibility Control Macros.
#define DRIZZLED_API
Definition visibility.h:38