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 
38 namespace 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 the plugin has been fixed and moves it to the
108  unloaded list otherwise returns false.
109  */
110  bool isFixed(const std::string& plugin_name);
111 
112  /*! \brief Tells if a given plugin is registered or not. */
113  bool exists(const std::string& plugin_name) const;
114 
115  /*!
116  \brief Adds plugin with its plugin information to the list of unloaded
117  plugins.
118 
119  \exception plugin_already_registered_error Throw an exception if a
120  plugin with the same
121  name already exists and it is registered in the manager.
122  */
123  void insert(const PluginInfo& pinfo);
124 
125  /*!
126  \brief Remove plugin from the manager.
127 
128  This method removes the plugin from the manager.
129  If the plugin was loaded, unload it and remove it from the manager.
130  If it was unloaded or broked, just removes it from the correct list.
131  Note that all its dependents will be moved to the broken list.
132 
133  \param plugin_name Name of the plugin to be removed.
134 
135  \exception te::InvalidArgumentException If the plugin can not be removed
136  an exception is raised.
137 
138  \note Don't change the type of parameter to a const reference! (guess?)
139  */
140  void remove(const std::string& plugin_name);
141 
142  /*!
143  \brief It tries to load the informed plugin.
144 
145  The manager will check the plugin's dependencies before trying to load
146  it.
147 
148  This method can be used to retry loading a broken plugin.
149 
150  \pre plugins must be in the manager before calling this method.
151 
152  \param plugin_name The plugin to be loaded
153  \param start If true it will try to startup the plugin if false
154  it doesn't automatically call plugin startup method.
155 
156  \exception te::plugin::exception It throws an exception if any plugin
157  can not be loaded or started.
158 
159  \note If the plugin in the list is already loaded this method will throw
160  an exception.
161 
162  \note If the plugin load fails this method will add it to the list of
163  broken plugins and continues.
164  In this case at the end an exception is thrown.
165 
166  \note If the plugin is in the broken list, on success load it will be
167  removed from the broken list.
168  */
169  void load(const std::string& plugin_name, const bool start = true);
170 
171  /*!
172  \brief Start a loaded plugin.
173 
174  \exception te::core::PluginStartupException It throws an exception if
175  any plugin can not be started.
176  */
177  void start(const std::string& plugin_name);
178 
179  /*!
180  \brief Stop a loaded plugin.
181 
182  \exception te::core::PluginShutdownException throws an exception if any
183  plugin can not be stoped.
184  */
185  void stop(const std::string& plugin_name);
186 
187  /*!
188  \brief Try to unload a given plugin.
189 
190  \param plugin_name The plugin to be unloaded.
191 
192  \exception PluginUnloadException It will raise an exception if
193  plugin's code is not unloaded, if it is started or if the
194  plugin's is not managed by PluginManager.
195  */
196  void unload(const std::string& plugin_name);
197 
198  /*!
199  \brief Try to unload a given plugin and its dependents recursively.
200 
201  This method will call plugin's shutdown method if needed.
202 
203  \param plugin_name The plugin to be unloaded.
204  */
205 
206  void recursiveUnload(const std::string& plugin_name);
207 
208  /*! \brief Stop and unload all plugins, then clear the internal list of
209  * plugins. */
210  void clear();
211 
212  /*! \brief Access the singleton. */
213  static PluginManager& instance();
214 
215  private:
216  /*! \brief Constructor */
217  PluginManager();
218 
219  /*! \brief Destructor. */
220  ~PluginManager();
221 
222  // No copy allowed
224  PluginManager& operator=(const PluginManager&);
225 
226  private:
227  struct Impl;
228 
229  Impl* m_pimpl;
230  };
231 
232  } // end namespace core
233 } // end namespace te
234 
235 #endif // __TERRALIB_CORE_PLUGIN_PLUGINMANAGER_H__
Basic information about a plugin.
Definition: PluginInfo.h:63
#define TECOREEXPORT
Definition: Config.h:40
mydialect insert("+", new te::da::BinaryOpEncoder("+"))
URI C++ Library.
A singleton for managing plugins.
Definition: PluginManager.h:48
The basic information about a plugin.