Loading...
Searching...
No Matches
PluginManager.h
Go to the documentation of this file.
1/*
2 Copyright (C) 2008 National Institute For Space Research (INPE) - Brazil.
3
4 This file is part of the TerraLib - a Framework for building GIS enabled
5 applications.
6
7 TerraLib is free software: you can redistribute it and/or modify
8 it under the terms of the GNU Lesser General Public License as published by
9 the Free Software Foundation, either version 3 of the License,
10 or (at your option) any later version.
11
12 TerraLib is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU Lesser General Public License for more details.
16
17 You should have received a copy of the GNU Lesser General Public License
18 along with TerraLib. See COPYING. If not, write to
19 TerraLib Team at <terralib-team@terralib.org>.
20 */
21
22/*!
23 \file terralib/common/plugin/PluginManager.h
24
25 \brief A singleton for managing plugins.
26
27 \author Gilberto Ribeiro de Queiroz
28 \author Matheus Cavassan Zaglia
29 */
30
31#ifndef __TERRALIB_CORE_PLUGIN_PLUGINMANAGER_H__
32#define __TERRALIB_CORE_PLUGIN_PLUGINMANAGER_H__
33
34// TerraLib
35#include "../Config.h"
36#include "PluginInfo.h"
37
38namespace te
39{
40 namespace core
41 {
42 /*!
43 \class PluginManager
44 \brief A singleton for managing plugins.
45
46 \note Methods in this class are not thread-safe.
47 */
49 {
50 public:
51 /*!
52 \brief Return the list of plugins managed by PluginManager.
53
54 \param plugins A vector to output the name of plugins managed by this
55 singleton.
56
57 \note The list will contain: loaded, not-loaded and broken plugins.
58 */
59 std::vector<std::string> getPlugins() const;
60
61 /*!
62 \brief Return information about a plugin identified by the given name.
63
64 \param name The plugin name.
65
66 \return A plugin identified by the given name.
67
68 \exception te::OutOfRangeException It throws an exception if there isn't
69 a plugin with the given name in the manager.
70 */
71 const PluginInfo& getPluginInfo(const std::string& name) const;
72
73 /*! \brief Return the list of plugins that are loaded. */
74 std::vector<PluginInfo> getLoadedPlugins() const;
75
76 /*! \brief Return the list of plugins that were not loaded. */
77 std::vector<PluginInfo> getUnloadedPlugins() const;
78
79 /*! \brief Return the list of plugins that could not be loaded. */
80 std::vector<PluginInfo> getBrokenPlugins() const;
81
82
83 /*!
84 \brief Return the list of plugins that depends of a given plugin.
85
86 \param plugin_name Name of the plugin to be search.
87
88 \exception OutOfRangeException if the plugin is not found.
89 */
90 std::vector<std::string> getDependents(const std::string plugin_name);
91
92 /*! \brief Returns true if the plugin is in the broken list of plugins. */
93 bool isBroken(const std::string& plugin_name) const;
94
95 /*!
96 \brief Returns true if the plugin is in the not-loaded list of
97 plugins.
98 */
99 bool isUnloaded(const std::string& plugin_name) const;
100
101 /*!
102 \brief Returns true if the plugin is loaded otherwise returns false.
103 */
104 bool isLoaded(const std::string& plugin_name) const;
105
106 /*!
107 \brief Returns true if was found a plugin with the same shared library name loaded otherwise returns false.
108 */
109 bool validatySharedLibraryName(const std::string& shared_library_name) const;
110
111 /*!
112 \brief Returns true if the plugin has been fixed and moves it to the
113 unloaded list otherwise returns false.
114 */
115 bool isFixed(const std::string& plugin_name);
116
117 /*! \brief Tells if a given plugin is registered or not. */
118 bool exists(const std::string& plugin_name) const;
119
120 /*!
121 \brief Adds plugin with its plugin information to the list of unloaded
122 plugins.
123
124 \exception plugin_already_registered_error Throw an exception if a
125 plugin with the same
126 name already exists and it is registered in the manager.
127 */
128 void insert(const PluginInfo& pinfo);
129
130 /*!
131 \brief Remove plugin from the manager.
132
133 This method removes the plugin from the manager.
134 If the plugin was loaded, unload it and remove it from the manager.
135 If it was unloaded or broked, just removes it from the correct list.
136 Note that all its dependents will be moved to the broken list.
137
138 \param plugin_name Name of the plugin to be removed.
139
140 \exception te::InvalidArgumentException If the plugin can not be removed
141 an exception is raised.
142
143 \note Don't change the type of parameter to a const reference! (guess?)
144 */
145 void remove(const std::string& plugin_name);
146
147 /*!
148 \brief It tries to load the informed plugin.
149
150 The manager will check the plugin's dependencies before trying to load
151 it.
152
153 This method can be used to retry loading a broken plugin.
154
155 \pre plugins must be in the manager before calling this method.
156
157 \param plugin_name The plugin to be loaded
158 \param start If true it will try to startup the plugin if false
159 it doesn't automatically call plugin startup method.
160
161 \exception te::plugin::exception It throws an exception if any plugin
162 can not be loaded or started.
163
164 \note If the plugin in the list is already loaded this method will throw
165 an exception.
166
167 \note If the plugin load fails this method will add it to the list of
168 broken plugins and continues.
169 In this case at the end an exception is thrown.
170
171 \note If the plugin is in the broken list, on success load it will be
172 removed from the broken list.
173 */
174 void load(const std::string& plugin_name, const bool start = true);
175
176 /*!
177 \brief Start a loaded plugin.
178
179 \exception te::core::PluginStartupException It throws an exception if
180 any plugin can not be started.
181 */
182 void start(const std::string& plugin_name);
183
184 /*!
185 \brief Stop a loaded plugin.
186
187 \exception te::core::PluginShutdownException throws an exception if any
188 plugin can not be stoped.
189 */
190 void stop(const std::string& plugin_name);
191
192 /*!
193 \brief Try to unload a given plugin.
194
195 \param plugin_name The plugin to be unloaded.
196
197 \exception PluginUnloadException It will raise an exception if
198 plugin's code is not unloaded, if it is started or if the
199 plugin's is not managed by PluginManager.
200 */
201 void unload(const std::string& plugin_name);
202
203 /*!
204 \brief Try to unload a given plugin and its dependents recursively.
205
206 This method will call plugin's shutdown method if needed.
207
208 \param plugin_name The plugin to be unloaded.
209 */
210
211 void recursiveUnload(const std::string& plugin_name);
212
213 /*! \brief Stop and unload all plugins, then clear the internal list of
214 * plugins. */
215 void clear();
216
217 /*! \brief Access the singleton. */
219
220 private:
221 /*! \brief Constructor */
223
224 /*! \brief Destructor. */
226
227 // No copy allowed
230
231 private:
232 struct Impl;
233
234 Impl* m_pimpl;
235 };
236
237 } // end namespace core
238} // end namespace te
239
240#endif // __TERRALIB_CORE_PLUGIN_PLUGINMANAGER_H__
The basic information about a plugin.
A singleton for managing plugins.
Definition: PluginManager.h:49
std::vector< PluginInfo > getBrokenPlugins() const
Return the list of plugins that could not be loaded.
void clear()
Stop and unload all plugins, then clear the internal list of plugins.
PluginManager(const PluginManager &)
void recursiveUnload(const std::string &plugin_name)
Try to unload a given plugin and its dependents recursively.
const PluginInfo & getPluginInfo(const std::string &name) const
Return information about a plugin identified by the given name.
void remove(const std::string &plugin_name)
Remove plugin from the manager.
bool isBroken(const std::string &plugin_name) const
Returns true if the plugin is in the broken list of plugins.
void insert(const PluginInfo &pinfo)
Adds plugin with its plugin information to the list of unloaded plugins.
std::vector< std::string > getPlugins() const
Return the list of plugins managed by PluginManager.
~PluginManager()
Destructor.
std::vector< PluginInfo > getUnloadedPlugins() const
Return the list of plugins that were not loaded.
PluginManager()
Constructor.
PluginManager & operator=(const PluginManager &)
std::vector< PluginInfo > getLoadedPlugins() const
Return the list of plugins that are loaded.
void load(const std::string &plugin_name, const bool start=true)
It tries to load the informed plugin.
void unload(const std::string &plugin_name)
Try to unload a given plugin.
bool exists(const std::string &plugin_name) const
Tells if a given plugin is registered or not.
static PluginManager & instance()
Access the singleton.
bool isFixed(const std::string &plugin_name)
Returns true if the plugin has been fixed and moves it to the unloaded list otherwise returns false.
void start(const std::string &plugin_name)
Start a loaded plugin.
void stop(const std::string &plugin_name)
Stop a loaded plugin.
bool isLoaded(const std::string &plugin_name) const
Returns true if the plugin is loaded otherwise returns false.
std::vector< std::string > getDependents(const std::string plugin_name)
Return the list of plugins that depends of a given plugin.
bool isUnloaded(const std::string &plugin_name) const
Returns true if the plugin is in the not-loaded list of plugins.
bool validatySharedLibraryName(const std::string &shared_library_name) const
Returns true if was found a plugin with the same shared library name loaded otherwise returns false.
TerraLib.
Basic information about a plugin.
Definition: PluginInfo.h:64
#define TECOREEXPORT
Definition: Config.h:52