attic/src/plugin/PluginManager.cpp
Go to the documentation of this file.
1 /* Copyright (C) 2008 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 "../core/translator/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 void te::plugin::PluginManager::setUnloadedPlugins(const boost::ptr_vector<te::plugin::PluginInfo> unloadedPlugins)
100 {
101  m_unloadedPlugins = unloadedPlugins;
102 }
103 
104 const boost::ptr_vector<te::plugin::PluginInfo>& te::plugin::PluginManager::getBrokenPlugins() const
105 {
106  return m_brokenPlugins;
107 }
108 
109 void te::plugin::PluginManager::setBrokenPlugins(const boost::ptr_vector<te::plugin::PluginInfo> brokenPlugins)
110 {
111  m_brokenPlugins = brokenPlugins;
112 }
113 
114 bool te::plugin::PluginManager::isBrokenPlugin(const std::string& pluginName) const
115 {
116  for(boost::ptr_vector<PluginInfo>::const_iterator it = m_brokenPlugins.begin(); it != m_brokenPlugins.end(); ++it)
117  if(it->m_name == pluginName)
118  return true;
119 
120  return false;
121 }
122 
123 bool te::plugin::PluginManager::isUnloadedPlugin(const std::string& pluginName) const
124 {
125  for(boost::ptr_vector<PluginInfo>::const_iterator it = m_unloadedPlugins.begin(); it != m_unloadedPlugins.end(); ++it)
126  if(it->m_name == pluginName)
127  return true;
128 
129  return false;
130 }
131 
132 bool te::plugin::PluginManager::isLoaded(const std::string& pname) const
133 {
134  return m_pluginsMap.find(pname) != m_pluginsMap.end();
135 }
136 
138 {
139 // unload all plugins before loading all again!
140  unloadAll();
141 
142  boost::ptr_vector<PluginInfo> plugins;
143 
144 // have we already load plugins?
145  if(m_unloadedPlugins.empty())
146  {
147 // if yes, then we can find and load new plugins
148  if(m_finders.empty())
149  {
150  DefaultFinder f;
151  f.getPlugins(plugins);
152  }
153  else
154  {
155  const std::size_t nfinders = m_finders.size();
156 
157  for(std::size_t i = 0; i < nfinders; ++i)
158  m_finders[i]->getPlugins(plugins);
159  }
160  }
161  else
162  {
163 // use last unloaded list
164  plugins = m_unloadedPlugins;
165  }
166 
167  load(plugins, start);
168 }
169 
171 {
172 // start by the last loaded plugin
173  std::vector<AbstractPlugin*>::reverse_iterator it = m_plugins.rbegin();
174 
175  while(it != m_plugins.rend())
176  {
177  std::auto_ptr<PluginInfo> pinfo(new PluginInfo((*it)->getInfo()));
178  unload(*it);
179  m_unloadedPlugins.push_back(pinfo.release());
180  it = m_plugins.rbegin(); // always get last loaded plugin
181  }
182 
183 // some assertions
184  assert(m_pluginCategoryMap.empty());
185  assert(m_plugins.empty());
186  assert(m_pluginsMap.empty());
187 }
188 
190 {
191  unloadAll();
192  m_unloadedPlugins.clear();
193  m_brokenPlugins.clear();
194 }
195 
196 void te::plugin::PluginManager::load(boost::ptr_vector<PluginInfo>& plugins, const bool start)
197 {
198  sort(plugins);
199 
200  bool hasException = false;
201 
202  const std::size_t nplugins = plugins.size();
203 
204  std::string exceptionPlugins;
205 
206  for(std::size_t i = 0; i < nplugins; ++i)
207  {
208  const PluginInfo& pInfo = plugins[i];
209 
210  try
211  {
212  load(pInfo, start);
213  }
214  catch(...)
215  {
216  hasException = true;
217  exceptionPlugins += "\n" + pInfo.m_name;
218  }
219  }
220 
221  if(hasException || !m_brokenPlugins.empty())
222  throw Exception(TE_TR("\n\nPlugins not loaded:" ) + exceptionPlugins);
223 }
224 
225 void te::plugin::PluginManager::load(const PluginInfo& pInfo, const bool start)
226 {
227  if(isLoaded(pInfo.m_name))
228  throw Exception((boost::format("Plugin %1% is already loaded") % pInfo.m_name).str());
229 
230 // check if required plugins is already loaded
231  if(!isLoaded(pInfo.m_requiredPlugins))
232  {
233  moveToBrokenList(pInfo);
234  throw Exception(TE_TR("A required plugin is not loaded!"));
235  }
236 
237  std::auto_ptr<AbstractPlugin> plugin;
238 
239 /////////////////////////////
240 // how many modules were loaded before the plugin?
241  std::size_t nmodules = TerraLib::getInstance().getNumRegModules();
242 /////////////////////////////
243 
244  try
245  {
246 // if everything is ready for loading the plugin let's call its engine
247  std::auto_ptr<AbstractPluginEngine> engine(PluginEngineFactory::make(pInfo.m_engine));
248 
249  if(engine.get() == 0)
250  throw Exception((boost::format("Could not determine plugin's language type for %1%!") % pInfo.m_name).str());
251 
252  plugin.reset(engine->load(pInfo));
253 
254  if(plugin.get() == 0)
255  throw Exception((boost::format("Could not load plugin %1%!") % pInfo.m_name).str());
256  }
257  catch(const std::exception& e)
258  {
259  moveToBrokenList(pInfo);
260  Exception ee(e.what());
261  throw ee;
262  }
263  catch(...)
264  {
265  moveToBrokenList(pInfo);
266  throw;
267  }
268 
269  try
270  {
271 /////////////////////////////
272 // if after loading the plugin there are more modules than before we need to initilize the new loaded modules
273  if(TerraLib::getInstance().getNumRegModules() > nmodules)
274  {
275  std::size_t nnmodules = TerraLib::getInstance().getNumRegModules();
276 
277  for(std::size_t i = nmodules; i < nnmodules; ++i)
279  }
280 /////////////////////////////
281 
282  if(start)
283  plugin->startup();
284 
285  std::string plg_name = plugin->getInfo().m_name;
286 // register plugin in the map and add it to its category
287  m_pluginCategoryMap[pInfo.m_category].push_back(plugin.get());
288  m_plugins.push_back(plugin.get());
289  m_pluginsMap[plg_name] = plugin.release();
290 
291 // remove plugin from broken or unloaded list
292  removeFromBrokenList(pInfo);
293  removeFromUnloadedList(pInfo);
294 
295  updateDependents(plg_name);
296  }
297  catch(const std::exception& e)
298  {
299  moveToBrokenList(pInfo);
300  Exception ee(e.what());
301  throw ee;
302  }
303  catch(...)
304  {
305  moveToBrokenList(pInfo);
306  throw; // sorry, but maybe this will cause the code to crash due to the unload of plugin module!
307  }
308 }
309 
310 void te::plugin::PluginManager::load(const std::string& pluginName)
311 {
312  PluginInfo pInfo = getPlugin(pluginName);
313  load(pInfo);
314 }
315 
316 void te::plugin::PluginManager::unload(const std::string& name)
317 {
318  std::map<std::string, AbstractPlugin*>::iterator it = m_pluginsMap.find(name);
319 
320  if(it == m_pluginsMap.end())
321  throw Exception((boost::format("Plugin %1% is not loaded!") % name).str());
322 
323  AbstractPlugin* plugin = it->second;
324 
325  if(plugin == 0)
326  throw Exception((boost::format("Plugin %1% is NULL!") % name).str());
327 
328  unload(plugin);
329 }
330 
332 {
333  const std::string pluginName = plugin->getInfo().m_name;
334  const std::string pluginCategory = plugin->getInfo().m_category;
335 
336 // check dependency
337  if(hasDependents(pluginName))
338  moveDependentsToBrokenList(pluginName);
339 // throw Exception((boost::format("Could not unload plugin %1% because other plugins depends on it!") % pluginName).str());
340 
341 // shutdown plugin!
342  if(plugin->isStarted())
343  plugin->shutdown();
344 
345 // locate plugin engine and unload it!
346  std::auto_ptr<AbstractPluginEngine> engine(PluginEngineFactory::make(plugin->getInfo().m_engine));
347 
348  if(engine.get() == 0)
349  throw Exception((boost::format("Could not determine plugin %1% language type!") % pluginName).str());
350 
351  std::auto_ptr<PluginInfo> pInfo(new PluginInfo(plugin->getInfo()));
352 
353  engine->unload(plugin); // the plugin pointer is already invalidated!
354 
355  m_unloadedPlugins.push_back(pInfo);
356 
357 // remove plugin from manager if it is managed by it
358  removeFromCategory(plugin, pluginCategory);
359 
360  {
361  std::vector<AbstractPlugin*>::iterator it = std::find(m_plugins.begin(), m_plugins.end(), plugin);
362 
363  if(it != m_plugins.end())
364  m_plugins.erase(it);
365  }
366 
367  {
368  std::map<std::string, AbstractPlugin*>::iterator it = m_pluginsMap.find(pluginName);
369 
370  if(it != m_pluginsMap.end())
371  m_pluginsMap.erase(it);
372  }
373 }
374 
376 {
377 // start by the last loaded plugin
378  std::vector<AbstractPlugin*>::reverse_iterator it = m_plugins.rbegin();
379 
380  while(it != m_plugins.rend())
381  {
382  if((*it)->isStarted())
383  (*it)->shutdown();
384 
385  ++it;
386  }
387 }
388 
390 {
391  return m_pluginsMap.size() + m_unloadedPlugins.size() + m_brokenPlugins.size();
392 }
393 
394 bool te::plugin::PluginManager::isLoaded(const std::vector<std::string>& plugins) const
395 {
396  const std::size_t size = plugins.size();
397 
398  for(std::size_t i = 0; i < size; ++i)
399  if(!isLoaded(plugins[i]))
400  return false; // there is a missing plugin!
401 
402  return true;
403 }
404 
406 {
407  add(new PluginInfo(plugin));
408 }
409 
411 {
412  //try
413  //{
414  // if(!isLoaded(plugin->m_requiredPlugins))
415  // throw Exception("Missing requirement");
416 
417  m_unloadedPlugins.push_back(plugin);
418  //}
419  //catch(Exception&)
420  //{
421  // m_brokenPlugins.push_back(plugin);
422  //}
423 }
424 
425 void te::plugin::PluginManager::remove(const std::string& plugin)
426 {
427  PluginInfo info = getPlugin(plugin);
428 
429  if(isLoaded(plugin))
430  {
431  AbstractPlugin* plg = detach(plugin);
432  plg->shutdown();
433  delete plg;
434 
435  return;
436  }
437 
438  if(isUnloadedPlugin(plugin))
439  {
441  return;
442  }
443 
444  removeFromBrokenList(info);
445 }
446 
447 std::vector<std::string> te::plugin::PluginManager::getDependents(const std::string& pluginName) const
448 {
449  std::vector<std::string> dependents;
450 
451  const std::size_t nplugins = m_plugins.size();
452 
453  for(std::size_t i = 0; i < nplugins; ++i)
454  {
455  if(pluginName == m_plugins[i]->getInfo().m_name)
456  continue;
457 
458  const std::vector<std::string>& requiredPlugins = m_plugins[i]->getInfo().m_requiredPlugins;
459 
460  const std::size_t size = requiredPlugins.size();
461 
462  for(std::size_t j = 0; j < size; ++j)
463  {
464 // is the checked plugin a required plugin?
465  if(pluginName == requiredPlugins[j])
466  {
467  dependents.push_back(m_plugins[i]->getInfo().m_name); // it->first contains the name of the plugin that requires pluginName!
468  break;
469  }
470  }
471  }
472 
473  return dependents;
474 }
475 
476 bool te::plugin::PluginManager::hasDependents(const std::string& pluginName) const
477 {
478  return getDependents(pluginName).empty() ? false : true;
479 }
480 
482 {
483 // find plugin
484  std::map<std::string, AbstractPlugin*>::iterator it = m_pluginsMap.find(name);
485 
486  if(it == m_pluginsMap.end())
487  throw Exception((boost::format(TE_TR("Could not find the given plugin (%1%) in order to detach it from PluginManager!")) % name).str());
488 
489  AbstractPlugin* p = it->second;
490 
491  if(p == 0)
492  throw Exception((boost::format(TE_TR("Could not detach a NULL plugin (%1%) from PluginManager!")) % name).str());
493 
494 // check if it doesn't have dependents plugins
495  if(hasDependents(name))
497 // throw Exception((boost::format(TE_TR("There are some plugins that depends on %1%!")) % name).str());
498 
499 // see if we must destroy the plugin category index: in the case the detached plugin being the only plugin in its category
501 
502 // remove plugin from manager
503  std::vector<AbstractPlugin*>::iterator itv = std::find(m_plugins.begin(), m_plugins.end(), p);
504 
505  if(itv == m_plugins.end())
506  throw Exception(TE_TR("PluginManager has lost the synchronization between its internal indexes!"));
507 
508  m_plugins.erase(itv);
509 
510  m_pluginsMap.erase(name);
511 
512 // finally... just return the plugin pointer and loose its ownership
513  return p;
514 }
515 
516 void te::plugin::PluginManager::getCategories(std::vector<std::string>& categories) const
517 {
518  std::map<std::string, std::vector<AbstractPlugin*> >::const_iterator it = m_pluginCategoryMap.begin();
519 
520  while(it != m_pluginCategoryMap.end())
521  {
522  categories.push_back(it->first);
523 
524  ++it;
525  }
526 }
527 
528 void te::plugin::PluginManager::addCategory(const std::string& name)
529 {
530  std::map<std::string, std::vector<AbstractPlugin*> >::iterator it = m_pluginCategoryMap.find(name);
531 
532  if(it == m_pluginCategoryMap.end())
533  {
534  std::vector<AbstractPlugin*> vec;
535  m_pluginCategoryMap.insert(std::map<std::string, std::vector<AbstractPlugin*> >::value_type(name, vec));
536  }
537 }
538 
539 void te::plugin::PluginManager::sort(boost::ptr_vector<PluginInfo>& plugins) const
540 {
541 // let's create an auxiliary index to make a topological sort on the plugin list
542  std::map<std::string, std::size_t> newPluginsMap;
543 
544  const std::size_t nplugins = plugins.size();
545 
546  for(std::size_t i = 0; i < nplugins; ++i)
547  newPluginsMap.insert(std::make_pair(plugins[i].m_name, i));
548 
549 // let's cache the iterator to the end of the map
550  std::map<std::string, std::size_t>::const_iterator itend = newPluginsMap.end();
551 
552 // let's make a graph with the plugins dependency
553  typedef boost::adjacency_list<boost::vecS, boost::vecS, boost::directedS> Graph;
554  typedef boost::graph_traits<Graph>::vertex_descriptor Vertex;
555 
556  Graph dgraph; // The dependency graph must be a DAG - when we make a topological sort this will be assured.
557 
558  for(std::size_t i = 0; i < nplugins; ++i) // add all vertex, maybe there aren't dependencies!
559  boost::add_vertex(dgraph);
560 
561  for(std::size_t i = 0; i < nplugins; ++i)
562  {
563  const std::vector<std::string>& requiredPlugins = plugins[i].m_requiredPlugins;
564 
565  const std::size_t nrequiredplugins = requiredPlugins.size();
566 
567  for(std::size_t j = 0; j < nrequiredplugins; ++j)
568  {
569  std::map<std::string, std::size_t>::const_iterator it = newPluginsMap.find(requiredPlugins[j]);
570 
571  if(it != itend)
572  {
573 // 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!)
574  boost::add_edge(it->second, i, dgraph);
575  }
576  }
577  }
578 
579 // now let's make a topological sort in order to be possible to traverse an load the plugins in the right order
580  std::vector<Vertex> toposortResult;
581 
582  boost::topological_sort(dgraph, std::back_inserter(toposortResult));
583 
584 // now let's load the plugins traversing the output result from topological sort in reverse-order (!!!topo sort output is not cool!!!)
585  boost::ptr_vector<PluginInfo> pluginsTemp;
586 
587  for(std::vector<Vertex>::reverse_iterator it = toposortResult.rbegin(); it != toposortResult.rend(); ++it)
588  pluginsTemp.push_back(new PluginInfo(plugins[*it]));
589 
590  plugins = pluginsTemp;
591 }
592 
593 void te::plugin::PluginManager::removeFromCategory(AbstractPlugin* plugin, const std::string& category)
594 {
595  std::map<std::string, std::vector<AbstractPlugin*> >::iterator it = m_pluginCategoryMap.find(category);
596 
597  if(it == m_pluginCategoryMap.end())
598  return;
599 
600  std::vector<AbstractPlugin*>& plugins = it->second;
601 
602  const std::size_t size = plugins.size();
603 
604  for(std::size_t i = 0; i < size; ++i)
605  {
606  if(plugin == plugins[i])
607  {
608  plugins.erase(plugins.begin() + i);
609 
610  if(plugins.empty())
611  m_pluginCategoryMap.erase(it);
612 
613  return;
614  }
615  }
616 }
617 
619 {
620  removeFromUnloadedList(pInfo);
621  removeFromBrokenList(pInfo);
622 
623 // add it to the end of the broken list
624  m_brokenPlugins.push_back(new PluginInfo(pInfo));
625 }
626 
628 {
629  for(boost::ptr_vector<PluginInfo>::iterator it = m_brokenPlugins.begin(); it != m_brokenPlugins.end(); ++it)
630  {
631  if(pInfo.m_name == it->m_name)
632  {
633  m_brokenPlugins.erase(it);
634  break;
635  }
636  }
637 }
638 
640 {
641  for(boost::ptr_vector<PluginInfo>::iterator it = m_unloadedPlugins.begin(); it != m_unloadedPlugins.end(); ++it)
642  {
643  if(pInfo.m_name == it->m_name)
644  {
645  m_unloadedPlugins.erase(it);
646  break;
647  }
648  }
649 }
650 
651 void te::plugin::PluginManager::moveDependentsToBrokenList(const std::string& plugin, const bool& unloadPlugin)
652 {
653  if(isBrokenPlugin(plugin))
654  return;
655 
656  std::vector<std::string> deps = getDependents(plugin);
657 
658  if(!deps.empty())
659  {
660  std::vector<std::string>::iterator it;
661 
662  for(it=deps.begin(); it!=deps.end(); ++it)
663  moveDependentsToBrokenList(*it, true);
664  }
665 
666  te::plugin::PluginInfo info(getPlugin(plugin));
667 
668  if(unloadPlugin)
669  {
670  if(isLoaded(info.m_name))
671  unload(info.m_name);
672 
673  moveToBrokenList(info);
674  }
675 }
676 
677 void te::plugin::PluginManager::updateDependents(const std::string& plugin)
678 {
679  boost::ptr_vector<PluginInfo> deps = getBrokenPlugins();
680 
681  if(!deps.empty())
682  {
683  boost::ptr_vector<PluginInfo>::iterator it;
684  std::vector<PluginInfo*> toUpdate;
685 
686  for(it=deps.begin(); it!=deps.end(); ++it)
687  if(isLoaded((*it).m_requiredPlugins))
688  toUpdate.push_back(new PluginInfo(*it));
689 
690  std::vector<PluginInfo*>::iterator it2;
691  for(it2=toUpdate.begin(); it2 != toUpdate.end(); ++it2)
692  {
693  removeFromBrokenList(*(*it2));
694  m_unloadedPlugins.push_back(*it2);
695  }
696  }
697 }
698 
700 {
701 }
702 
704 {
707 }
708 
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...
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.
void remove(const std::string &plugin)
PluginManager()
It creates a new plugin.
void setUnloadedPlugins(boost::ptr_vector< te::plugin::PluginInfo > unloadedPlugins)
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.
Base exception class for plugin module.
virtual const PluginInfo & getInfo() const =0
It return the information associated to the plugin.
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!
void updateDependents(const std::string &plugin)
#define TE_TR(message)
It marks a string in order to get translated.
Definition: Translator.h:242
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.
std::string m_engine
The type of plugin execution engine: C++, JAVA.
std::size_t getNumRegModules() const
It returns the number of registered modules.
static TerraLib & getInstance()
It returns a reference to the singleton instance.
void removeFromBrokenList(const PluginInfo &pInfo)
std::map< std::string, AbstractPlugin * > m_pluginsMap
A map from (plugin&#39;s name) to (plugin instance).
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&#39;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.
virtual bool isStarted() const =0
It tells if the plugin was started or not.
AbstractPlugin * detach(const std::string &pluginName)
It detaches the given plugin from the list of loaded plugins.
std::vector< AbstractFinder * > m_finders
The list of plugin finders.
te::gm::Polygon * p
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.
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...
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.
void setBrokenPlugins(boost::ptr_vector< te::plugin::PluginInfo > brokenPlugins)
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.
std::map< std::string, std::vector< AbstractPlugin * > > m_pluginCategoryMap
A map from (plugin category) to (plugins in category)
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.
void unload(const std::string &name)
It tries to unload a given plugin.