All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
PluginManager.cpp
Go to the documentation of this file.
1 /* Copyright (C) 2001-2009 National Institute For Space Research (INPE) - Brazil.
2 
3  This file is part of the TerraLib - a Framework for building GIS enabled applications.
4 
5  TerraLib is free software: you can redistribute it and/or modify
6  it under the terms of the GNU Lesser General Public License as published by
7  the Free Software Foundation, either version 3 of the License,
8  or (at your option) any later version.
9 
10  TerraLib 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 Lesser General Public License for more details.
14 
15  You should have received a copy of the GNU Lesser General Public License
16  along with TerraLib. See COPYING. If not, write to
17  TerraLib Team at <terralib-team@terralib.org>.
18  */
19 
20 /*!
21  \file terralib/plugin/PluginManager.cpp
22 
23  \brief A singleton for managing plugins.
24 */
25 
26 // TerraLib
27 #include "../common/STLUtils.h"
28 #include "../common/TerraLib.h"
29 #include "../common/Translator.h"
30 #include "AbstractFinder.h"
31 #include "AbstractPlugin.h"
32 #include "AbstractPluginEngine.h"
33 #include "DefaultFinder.h"
34 #include "PluginEngineFactory.h"
35 #include "PluginInfo.h"
36 #include "PluginManager.h"
37 
38 // STL
39 #include <algorithm>
40 #include <cassert>
41 #include <memory>
42 
43 // Boost
44 #include <boost/graph/adjacency_list.hpp>
45 #include <boost/graph/properties.hpp>
46 #include <boost/graph/exception.hpp>
47 #include <boost/graph/topological_sort.hpp>
48 #include <boost/format.hpp>
49 #include <boost/filesystem.hpp>
50 
51 std::vector<std::string>
53 {
54  std::vector<std::string> plugins;
55 
56 // retrieve the list of loaded plugins
57  for(std::vector<AbstractPlugin*>::const_iterator it = m_plugins.begin(); it != m_plugins.end(); ++it)
58  plugins.push_back((*it)->getInfo().m_name);
59 
60 // retrieve the list of unloaded plugins
61  for(boost::ptr_vector<PluginInfo>::const_iterator it = m_unloadedPlugins.begin(); it != m_unloadedPlugins.end(); ++it)
62  plugins.push_back(it->m_name);
63 
64 // retrieve the list of broken plugins
65  for(boost::ptr_vector<PluginInfo>::const_iterator it = m_brokenPlugins.begin(); it != m_brokenPlugins.end(); ++it)
66  plugins.push_back(it->m_name);
67 
68  return plugins;
69 }
70 
71 const te::plugin::PluginInfo& te::plugin::PluginManager::getPlugin(const std::string& name) const
72 {
73 // check in the loaded list first
74  {
75  std::map<std::string, AbstractPlugin*>::const_iterator it = m_pluginsMap.find(name);
76 
77  if(it != m_pluginsMap.end())
78  return it->second->getInfo();
79  }
80 
81 // check in not-loaded list
82  for(boost::ptr_vector<PluginInfo>::const_iterator it = m_unloadedPlugins.begin(); it != m_unloadedPlugins.end(); ++it)
83  if(it->m_name == name)
84  return *it;
85 
86 // check in the broken list
87  for(boost::ptr_vector<PluginInfo>::const_iterator it = m_brokenPlugins.begin(); it != m_brokenPlugins.end(); ++it)
88  if(it->m_name == name)
89  return *it;
90 
91  throw Exception((boost::format("Could not find plugin %1%") % name).str());
92 }
93 
94 const boost::ptr_vector<te::plugin::PluginInfo>& te::plugin::PluginManager::getUnloadedPlugins() const
95 {
96  return m_unloadedPlugins;
97 }
98 
99 const boost::ptr_vector<te::plugin::PluginInfo>& te::plugin::PluginManager::getBrokenPlugins() const
100 {
101  return m_brokenPlugins;
102 }
103 
104 bool te::plugin::PluginManager::isBrokenPlugin(const std::string& pluginName) const
105 {
106  for(boost::ptr_vector<PluginInfo>::const_iterator it = m_brokenPlugins.begin(); it != m_brokenPlugins.end(); ++it)
107  if(it->m_name == pluginName)
108  return true;
109 
110  return false;
111 }
112 
113 bool te::plugin::PluginManager::isUnloadedPlugin(const std::string& pluginName) const
114 {
115  for(boost::ptr_vector<PluginInfo>::const_iterator it = m_unloadedPlugins.begin(); it != m_unloadedPlugins.end(); ++it)
116  if(it->m_name == pluginName)
117  return true;
118 
119  return false;
120 }
121 
122 bool te::plugin::PluginManager::isLoaded(const std::string& pname) const
123 {
124  return m_pluginsMap.find(pname) != m_pluginsMap.end();
125 }
126 
128 {
129 // unload all plugins before loading all again!
130  unloadAll();
131 
132  boost::ptr_vector<PluginInfo> plugins;
133 
134 // have we already load plugins?
135  if(m_unloadedPlugins.empty())
136  {
137 // if yes, then we can find and load new plugins
138  if(m_finders.empty())
139  {
140  DefaultFinder f;
141  f.getPlugins(plugins);
142  }
143  else
144  {
145  const std::size_t nfinders = m_finders.size();
146 
147  for(std::size_t i = 0; i < nfinders; ++i)
148  m_finders[i]->getPlugins(plugins);
149  }
150  }
151  else
152  {
153 // use last unloaded list
154  plugins = m_unloadedPlugins;
155  }
156 
157  load(plugins, start);
158 }
159 
161 {
162 // start by the last loaded plugin
163  std::vector<AbstractPlugin*>::reverse_iterator it = m_plugins.rbegin();
164 
165  while(it != m_plugins.rend())
166  {
167  std::auto_ptr<PluginInfo> pinfo(new PluginInfo((*it)->getInfo()));
168  unload(*it);
169  m_unloadedPlugins.push_back(pinfo.release());
170  it = m_plugins.rbegin(); // always get last loaded plugin
171  }
172 
173 // some assertions
174  assert(m_pluginCategoryMap.empty());
175  assert(m_plugins.empty());
176  assert(m_pluginsMap.empty());
177 }
178 
180 {
181  unloadAll();
182  m_unloadedPlugins.clear();
183  m_brokenPlugins.clear();
184 }
185 
186 void te::plugin::PluginManager::load(boost::ptr_vector<PluginInfo>& plugins, const bool start)
187 {
188  sort(plugins);
189 
190  bool hasException = false;
191 
192  const std::size_t nplugins = plugins.size();
193 
194  std::string exceptionPlugins;
195 
196  for(std::size_t i = 0; i < nplugins; ++i)
197  {
198  const PluginInfo& pInfo = plugins[i];
199 
200  try
201  {
202  load(pInfo, start);
203  }
204  catch(...)
205  {
206  hasException = true;
207  exceptionPlugins += "\n" + pInfo.m_name;
208  }
209  }
210 
211  if(hasException || !m_brokenPlugins.empty())
212  throw Exception(TE_TR("\n\nPlugins not loaded:" ) + exceptionPlugins);
213 }
214 
215 void te::plugin::PluginManager::load(const PluginInfo& pInfo, const bool start)
216 {
217  if(isLoaded(pInfo.m_name))
218  throw Exception((boost::format("Plugin %1% is already loaded") % pInfo.m_name).str());
219 
220 // check if required plugins is already loaded
221  if(!isLoaded(pInfo.m_requiredPlugins))
222  {
223  moveToBrokenList(pInfo);
224  throw Exception(TE_TR("A required plugin is not loaded!"));
225  }
226 
227  std::auto_ptr<AbstractPlugin> plugin;
228 
229 /////////////////////////////
230 // how many modules were loaded before the plugin?
231  std::size_t nmodules = TerraLib::getInstance().getNumRegModules();
232 /////////////////////////////
233 
234  try
235  {
236 // if everything is ready for loading the plugin let's call its engine
237  std::auto_ptr<AbstractPluginEngine> engine(PluginEngineFactory::make(pInfo.m_engine));
238 
239  if(engine.get() == 0)
240  throw Exception((boost::format("Could not determine plugin's language type for %1%!") % pInfo.m_name).str());
241 
242  plugin.reset(engine->load(pInfo));
243 
244  if(plugin.get() == 0)
245  throw Exception((boost::format("Could not load plugin %1%!") % pInfo.m_name).str());
246  }
247  catch(const std::exception& e)
248  {
249  moveToBrokenList(pInfo);
250  Exception ee(e.what());
251  throw ee;
252  }
253  catch(...)
254  {
255  moveToBrokenList(pInfo);
256  throw;
257  }
258 
259  try
260  {
261 /////////////////////////////
262 // if after loading the plugin there are more modules than before we need to initilize the new loaded modules
263  if(TerraLib::getInstance().getNumRegModules() > nmodules)
264  {
265  std::size_t nnmodules = TerraLib::getInstance().getNumRegModules();
266 
267  for(std::size_t i = nmodules; i < nnmodules; ++i)
269  }
270 /////////////////////////////
271 
272  if(start)
273  plugin->startup();
274 
275  std::string plg_name = plugin->getInfo().m_name;
276 // register plugin in the map and add it to its category
277  m_pluginCategoryMap[pInfo.m_category].push_back(plugin.get());
278  m_plugins.push_back(plugin.get());
279  m_pluginsMap[plg_name] = plugin.release();
280 
281 // remove plugin from broken or unloaded list
282  removeFromBrokenList(pInfo);
283  removeFromUnloadedList(pInfo);
284 
285  updateDependents(plg_name);
286  }
287  catch(const std::exception& e)
288  {
289  moveToBrokenList(pInfo);
290  Exception ee(e.what());
291  throw ee;
292  }
293  catch(...)
294  {
295  moveToBrokenList(pInfo);
296  throw; // sorry, but maybe this will cause the code to crash due to the unload of plugin module!
297  }
298 }
299 
300 void te::plugin::PluginManager::load(const std::string& pluginName)
301 {
302  load(getPlugin(pluginName));
303 }
304 
305 void te::plugin::PluginManager::unload(const std::string& name)
306 {
307  std::map<std::string, AbstractPlugin*>::iterator it = m_pluginsMap.find(name);
308 
309  if(it == m_pluginsMap.end())
310  throw Exception((boost::format("Plugin %1% is not loaded!") % name).str());
311 
312  AbstractPlugin* plugin = it->second;
313 
314  if(plugin == 0)
315  throw Exception((boost::format("Plugin %1% is NULL!") % name).str());
316 
317  unload(plugin);
318 }
319 
321 {
322  const std::string pluginName = plugin->getInfo().m_name;
323  const std::string pluginCategory = plugin->getInfo().m_category;
324 
325 // check dependency
326  if(hasDependents(pluginName))
327  moveDependentsToBrokenList(pluginName);
328 // throw Exception((boost::format("Could not unload plugin %1% because other plugins depends on it!") % pluginName).str());
329 
330 // shutdown plugin!
331  if(plugin->isStarted())
332  plugin->shutdown();
333 
334 // locate plugin engine and unload it!
335  std::auto_ptr<AbstractPluginEngine> engine(PluginEngineFactory::make(plugin->getInfo().m_engine));
336 
337  if(engine.get() == 0)
338  throw Exception((boost::format("Could not determine plugin %1% language type!") % pluginName).str());
339 
340  std::auto_ptr<PluginInfo> pInfo(new PluginInfo(plugin->getInfo()));
341 
342  engine->unload(plugin); // the plugin pointer is already invalidated!
343 
344  m_unloadedPlugins.push_back(pInfo);
345 
346 // remove plugin from manager if it is managed by it
347  removeFromCategory(plugin, pluginCategory);
348 
349  {
350  std::vector<AbstractPlugin*>::iterator it = std::find(m_plugins.begin(), m_plugins.end(), plugin);
351 
352  if(it != m_plugins.end())
353  m_plugins.erase(it);
354  }
355 
356  {
357  std::map<std::string, AbstractPlugin*>::iterator it = m_pluginsMap.find(pluginName);
358 
359  if(it != m_pluginsMap.end())
360  m_pluginsMap.erase(it);
361  }
362 }
363 
365 {
366 // start by the last loaded plugin
367  std::vector<AbstractPlugin*>::reverse_iterator it = m_plugins.rbegin();
368 
369  while(it != m_plugins.rend())
370  {
371  if((*it)->isStarted())
372  (*it)->shutdown();
373 
374  ++it;
375  }
376 }
377 
379 {
380  return m_pluginsMap.size() + m_unloadedPlugins.size() + m_brokenPlugins.size();
381 }
382 
383 bool te::plugin::PluginManager::isLoaded(const std::vector<std::string>& plugins) const
384 {
385  const std::size_t size = plugins.size();
386 
387  for(std::size_t i = 0; i < size; ++i)
388  if(!isLoaded(plugins[i]))
389  return false; // there is a missing plugin!
390 
391  return true;
392 }
393 
395 {
396  add(new PluginInfo(plugin));
397 }
398 
400 {
401  //try
402  //{
403  // if(!isLoaded(plugin->m_requiredPlugins))
404  // throw Exception("Missing requirement");
405 
406  m_unloadedPlugins.push_back(plugin);
407  //}
408  //catch(Exception&)
409  //{
410  // m_brokenPlugins.push_back(plugin);
411  //}
412 }
413 
414 void te::plugin::PluginManager::remove(const std::string& plugin)
415 {
416  PluginInfo info = getPlugin(plugin);
417 
418  if(isLoaded(plugin))
419  {
420  AbstractPlugin* plg = detach(plugin);
421  plg->shutdown();
422  delete plg;
423 
424  return;
425  }
426 
427  if(isUnloadedPlugin(plugin))
428  {
429  removeFromUnloadedList(info);
430  return;
431  }
432 
433  removeFromBrokenList(info);
434 }
435 
436 std::vector<std::string> te::plugin::PluginManager::getDependents(const std::string& pluginName) const
437 {
438  std::vector<std::string> dependents;
439 
440  const std::size_t nplugins = m_plugins.size();
441 
442  for(std::size_t i = 0; i < nplugins; ++i)
443  {
444  if(pluginName == m_plugins[i]->getInfo().m_name)
445  continue;
446 
447  const std::vector<std::string>& requiredPlugins = m_plugins[i]->getInfo().m_requiredPlugins;
448 
449  const std::size_t size = requiredPlugins.size();
450 
451  for(std::size_t j = 0; j < size; ++j)
452  {
453 // is the checked plugin a required plugin?
454  if(pluginName == requiredPlugins[j])
455  {
456  dependents.push_back(m_plugins[i]->getInfo().m_name); // it->first contains the name of the plugin that requires pluginName!
457  break;
458  }
459  }
460  }
461 
462  return dependents;
463 }
464 
465 bool te::plugin::PluginManager::hasDependents(const std::string& pluginName) const
466 {
467  return getDependents(pluginName).empty() ? false : true;
468 }
469 
471 {
472 // find plugin
473  std::map<std::string, AbstractPlugin*>::iterator it = m_pluginsMap.find(name);
474 
475  if(it == m_pluginsMap.end())
476  throw Exception((boost::format(TE_TR("Could not find the given plugin (%1%) in order to detach it from PluginManager!")) % name).str());
477 
478  AbstractPlugin* p = it->second;
479 
480  if(p == 0)
481  throw Exception((boost::format(TE_TR("Could not detach a NULL plugin (%1%) from PluginManager!")) % name).str());
482 
483 // check if it doesn't have dependents plugins
484  if(hasDependents(name))
485  moveDependentsToBrokenList(name);
486 // throw Exception((boost::format(TE_TR("There are some plugins that depends on %1%!")) % name).str());
487 
488 // see if we must destroy the plugin category index: in the case the detached plugin being the only plugin in its category
489  removeFromCategory(p, p->getInfo().m_category);
490 
491 // remove plugin from manager
492  std::vector<AbstractPlugin*>::iterator itv = std::find(m_plugins.begin(), m_plugins.end(), p);
493 
494  if(itv == m_plugins.end())
495  throw Exception(TE_TR("PluginManager has lost the synchronization between its internal indexes!"));
496 
497  m_plugins.erase(itv);
498 
499  m_pluginsMap.erase(name);
500 
501 // finally... just return the plugin pointer and loose its ownership
502  return p;
503 }
504 
505 void te::plugin::PluginManager::getCategories(std::vector<std::string>& categories) const
506 {
507  std::map<std::string, std::vector<AbstractPlugin*> >::const_iterator it = m_pluginCategoryMap.begin();
508 
509  while(it != m_pluginCategoryMap.end())
510  {
511  categories.push_back(it->first);
512 
513  ++it;
514  }
515 }
516 
517 void te::plugin::PluginManager::addCategory(const std::string& name)
518 {
519  std::map<std::string, std::vector<AbstractPlugin*> >::iterator it = m_pluginCategoryMap.find(name);
520 
521  if(it == m_pluginCategoryMap.end())
522  {
523  std::vector<AbstractPlugin*> vec;
524  m_pluginCategoryMap.insert(std::map<std::string, std::vector<AbstractPlugin*> >::value_type(name, vec));
525  }
526 }
527 
528 void te::plugin::PluginManager::sort(boost::ptr_vector<PluginInfo>& plugins) const
529 {
530 // let's create an auxiliary index to make a topological sort on the plugin list
531  std::map<std::string, std::size_t> newPluginsMap;
532 
533  const std::size_t nplugins = plugins.size();
534 
535  for(std::size_t i = 0; i < nplugins; ++i)
536  newPluginsMap.insert(std::make_pair(plugins[i].m_name, i));
537 
538 // let's cache the iterator to the end of the map
539  std::map<std::string, std::size_t>::const_iterator itend = newPluginsMap.end();
540 
541 // let's make a graph with the plugins dependency
542  typedef boost::adjacency_list<boost::vecS, boost::vecS, boost::directedS> Graph;
543  typedef boost::graph_traits<Graph>::vertex_descriptor Vertex;
544 
545  Graph dgraph; // The dependency graph must be a DAG - when we make a topological sort this will be assured.
546 
547  for(std::size_t i = 0; i < nplugins; ++i) // add all vertex, maybe there aren't dependencies!
548  boost::add_vertex(dgraph);
549 
550  for(std::size_t i = 0; i < nplugins; ++i)
551  {
552  const std::vector<std::string>& requiredPlugins = plugins[i].m_requiredPlugins;
553 
554  const std::size_t nrequiredplugins = requiredPlugins.size();
555 
556  for(std::size_t j = 0; j < nrequiredplugins; ++j)
557  {
558  std::map<std::string, std::size_t>::const_iterator it = newPluginsMap.find(requiredPlugins[j]);
559 
560  if(it != itend)
561  {
562 // if plugin A (it->second) is required for plugin B (i) then there must be a directed edge from A to B (A must come first then B!)
563  boost::add_edge(it->second, i, dgraph);
564  }
565  }
566  }
567 
568 // now let's make a topological sort in order to be possible to traverse an load the plugins in the right order
569  std::vector<Vertex> toposortResult;
570 
571  boost::topological_sort(dgraph, std::back_inserter(toposortResult));
572 
573 // now let's load the plugins traversing the output result from topological sort in reverse-order (!!!topo sort output is not cool!!!)
574  boost::ptr_vector<PluginInfo> pluginsTemp;
575 
576  for(std::vector<Vertex>::reverse_iterator it = toposortResult.rbegin(); it != toposortResult.rend(); ++it)
577  pluginsTemp.push_back(new PluginInfo(plugins[*it]));
578 
579  plugins = pluginsTemp;
580 }
581 
582 void te::plugin::PluginManager::removeFromCategory(AbstractPlugin* plugin, const std::string& category)
583 {
584  std::map<std::string, std::vector<AbstractPlugin*> >::iterator it = m_pluginCategoryMap.find(category);
585 
586  if(it == m_pluginCategoryMap.end())
587  return;
588 
589  std::vector<AbstractPlugin*>& plugins = it->second;
590 
591  const std::size_t size = plugins.size();
592 
593  for(std::size_t i = 0; i < size; ++i)
594  {
595  if(plugin == plugins[i])
596  {
597  plugins.erase(plugins.begin() + i);
598 
599  if(plugins.empty())
600  m_pluginCategoryMap.erase(it);
601 
602  return;
603  }
604  }
605 }
606 
608 {
609  removeFromUnloadedList(pInfo);
610  removeFromBrokenList(pInfo);
611 
612 // add it to the end of the broken list
613  m_brokenPlugins.push_back(new PluginInfo(pInfo));
614 }
615 
617 {
618  for(boost::ptr_vector<PluginInfo>::iterator it = m_brokenPlugins.begin(); it != m_brokenPlugins.end(); ++it)
619  {
620  if(pInfo.m_name == it->m_name)
621  {
622  m_brokenPlugins.erase(it);
623  break;
624  }
625  }
626 }
627 
629 {
630  for(boost::ptr_vector<PluginInfo>::iterator it = m_unloadedPlugins.begin(); it != m_unloadedPlugins.end(); ++it)
631  {
632  if(pInfo.m_name == it->m_name)
633  {
634  m_unloadedPlugins.erase(it);
635  break;
636  }
637  }
638 }
639 
640 void te::plugin::PluginManager::moveDependentsToBrokenList(const std::string& plugin, const bool& unloadPlugin)
641 {
642  if(isBrokenPlugin(plugin))
643  return;
644 
645  std::vector<std::string> deps = getDependents(plugin);
646 
647  if(!deps.empty())
648  {
649  std::vector<std::string>::iterator it;
650 
651  for(it=deps.begin(); it!=deps.end(); ++it)
652  moveDependentsToBrokenList(*it, true);
653  }
654 
655  te::plugin::PluginInfo info(getPlugin(plugin));
656 
657  if(unloadPlugin)
658  {
659  if(isLoaded(info.m_name))
660  unload(info.m_name);
661 
662  moveToBrokenList(info);
663  }
664 }
665 
666 void te::plugin::PluginManager::updateDependents(const std::string& plugin)
667 {
668  boost::ptr_vector<PluginInfo> deps = getBrokenPlugins();
669 
670  if(!deps.empty())
671  {
672  boost::ptr_vector<PluginInfo>::iterator it;
673  std::vector<PluginInfo*> toUpdate;
674 
675  for(it=deps.begin(); it!=deps.end(); ++it)
676  if(isLoaded((*it).m_requiredPlugins))
677  toUpdate.push_back(new PluginInfo(*it));
678 
679  std::vector<PluginInfo*>::iterator it2;
680  for(it2=toUpdate.begin(); it2 != toUpdate.end(); ++it2)
681  {
682  removeFromBrokenList(*(*it2));
683  m_unloadedPlugins.push_back(*it2);
684  }
685  }
686 }
687 
689 {
690 }
691 
693 {
694  te::common::FreeContents(m_finders);
695  te::common::FreeContents(m_plugins);
696 }
697 
This is the abstract factory for plugin engines.
void moveDependentsToBrokenList(const std::string &plugin, const bool &unloadPlugin=false)
void moveToBrokenList(const PluginInfo &pInfo)
std::string m_name
The plugin name: an internal value used to identify the plugin in the system. Must be a unique value...
Definition: PluginInfo.h:66
virtual const PluginInfo & getInfo() const =0
It return the information associated to the plugin.
void shutdownAll()
It try to shutdown all plugins.
std::vector< std::string > m_requiredPlugins
The list of required plugins in order to lunch the plugin.
Definition: PluginInfo.h:78
void remove(const std::string &plugin)
PluginManager()
It creates a new plugin.
An abstract class for TerraLib Plugins.
A plugin finder that search for plugins in some special directories defined by compile time macros...
Definition: DefaultFinder.h:48
void addCategory(const std::string &name)
Add a new category type.
virtual bool isStarted() const =0
It tells if the plugin was started or not.
void removeFromCategory(AbstractPlugin *plugin, const std::string &category)
It removes the given plugin from the category and then updates the internal category index...
void unloadAll()
It try to unload all plugins.
bool hasDependents(const std::string &pluginName) const
If there is a plugin that depends on the informed plugin it returns true, otherwise, if no plugin depends on it, return false.
void add(const PluginInfo &plugin)
Adds plug-in to unload list.
boost::ptr_vector< PluginInfo > m_brokenPlugins
The list of plugins that could not be loaded.
std::vector< AbstractPlugin * > m_plugins
The list of managed plugins: this will be need to unload accordinly the plugins!
~PluginManager()
Singleton destructor.
void updateDependents(const std::string &plugin)
The AbstractFinder class allows applications to extend how PluginManager can search for plugins...
#define TE_TR(message)
It marks a string in order to get translated.
Definition: Translator.h:345
void load(boost::ptr_vector< PluginInfo > &plugins, const bool start=true)
It tries to load all informed plugins.
void removeFromUnloadedList(const PluginInfo &pInfo)
boost::ptr_vector< PluginInfo > m_unloadedPlugins
The list of plugins that are not loaded.
An abstract class for TerraLib Plugins.
std::string m_engine
The type of plugin execution engine: C++, JAVA.
Definition: PluginInfo.h:71
std::size_t getNumRegModules() const
It returns the number of registered modules.
Definition: TerraLib.cpp:128
static TerraLib & getInstance()
It returns a reference to the singleton instance.
void removeFromBrokenList(const PluginInfo &pInfo)
An abstract class for plugin engines.
const boost::ptr_vector< PluginInfo > & getUnloadedPlugins() const
It returns the list of plugins that are not loaded.
virtual void shutdown()=0
This method will be called by TerraLib to shutdown plugin's functionality.
void clear()
Unload all plugins and them clear the internal list.
void sort(boost::ptr_vector< PluginInfo > &plugins) const
It sorts the plugins according to their dependency.
void getCategories(std::vector< std::string > &categories) const
Get plugins category types.
std::vector< std::string > getPlugins() const
It returns the list of plugins managed by PluginManager.
AbstractPlugin * detach(const std::string &pluginName)
It detaches the given plugin from the list of loaded plugins.
bool isUnloadedPlugin(const std::string &pluginName) const
It returns true if the plugin is in the not-loaded list of plugins.
static AbstractPluginEngine * make(const std::string &factoryKey)
It creates an object with the appropriated factory.
void initialize()
It initializes the TerraLib Platform.
Definition: TerraLib.cpp:33
A plugin finder that search for plugins in some special directories defined by compile time macros...
const boost::ptr_vector< PluginInfo > & getBrokenPlugins() const
It returns the list of plugins that could not be loaded.
std::size_t getNumPlugins() const
It returns the number of plugins kept in the manager.
const PluginInfo & getPlugin(const std::string &name) const
It returns the plugin identified by the given name.
void loadAll(const bool start=true)
It loads all the plugins in the not-loaded list or searchs for installed plugin with installed finder...
A singleton for managing plugins.
bool isBrokenPlugin(const std::string &pluginName) const
It returns true if the plugin is in the broken list of plugins.
bool isLoaded(const std::string &pname) const
It returns true if the plugin is loaded otherwise returns false.
std::vector< std::string > getDependents(const std::string &pluginName) const
It searches for all plugins that depends on the given plugin.
The basic information about a plugin.
Definition: PluginInfo.h:61
The basic information about a plugin.
void getPlugins(boost::ptr_vector< PluginInfo > &plugins)
This method searches for installed plugins and output the plugins information in the PluginInfo vecto...
void FreeContents(boost::unordered_map< K, V * > &m)
This function can be applied to a map of pointers. It will delete each pointer in the map...
Definition: BoostUtils.h:55
std::string m_category
The plugin category.
Definition: PluginInfo.h:75
void unload(const std::string &name)
It tries to unload a given plugin.