33 #include "../logger/Logger.h" 34 #include "../translator/Translator.h" 44 #include <boost/algorithm/string/join.hpp> 45 #include <boost/format.hpp> 51 std::vector<std::shared_ptr<AbstractPlugin> >
plugins;
65 std::vector<std::string>
plugins;
70 plugins.push_back(p->info().name);
76 plugins.push_back(p.
name);
82 plugins.push_back(p.
name);
89 const std::string& name)
const 94 if(p->info().name == name)
113 (boost::format(
"could not find plugin: '%1%'.") % name).str());
119 std::vector<te::core::PluginInfo>
plugins;
123 plugins.push_back(p->info());
140 const std::string plugin_name)
147 boost::format err_msg(
TE_TR(
"Could not find plugin: '%1%'."));
158 return p.name == plugin_name;
167 return p.name == plugin_name;
174 [&plugin_name](
const std::shared_ptr<AbstractPlugin>&
p) {
175 return p->info().name == plugin_name;
183 std::size_t plugin_pos;
216 boost::format err_msg(
217 TE_TR(
"There is already a plugin registered with name: '%1%', already " 226 boost::format err_msg(
TE_TR(
227 "There is already a plugin registered with name: '%1%', but not loaded " 236 boost::format err_msg(
237 TE_TR(
"There is already a plugin registered with the name: '%1%', but " 238 "presenting some problems to load or startup."));
261 for(std::vector<PluginInfo>::iterator it =
265 if(plugin_name == it->name)
278 if(plugin_name == it->name)
285 boost::format err_msg(
TE_TR(
"Could not find plugin: '%1%'."));
297 boost::format err_msg(
TE_TR(
"The plugin '%1%' is already loaded."));
307 boost::format err_msg(
308 TE_TR(
"The plugin '%1%' is not registered in the manager."));
315 bool found_in_unloaded_list =
false;
316 bool found_in_broken_list =
false;
318 std::size_t plugin_pos = 0;
324 found_in_unloaded_list =
true;
329 if(!found_in_unloaded_list)
336 found_in_broken_list =
true;
341 if(!found_in_broken_list)
343 boost::format err_msg(
TE_TR(
"Could not find plugin: '%1%'."));
356 std::vector<std::string> missing_deps;
357 for(
const std::string& plugin_dependency : pinfo.
dependencies)
360 missing_deps.push_back(plugin_dependency);
362 if(!missing_deps.empty())
364 if(found_in_unloaded_list)
367 boost::format err_msg(
368 TE_TR(
"Plugin '%1%' has the following dependency: '%2%'."));
371 (err_msg % plugin_name % boost::algorithm::join(missing_deps,
", "))
375 std::unique_ptr<AbstractPlugin> plugin(
nullptr);
384 plugin = engine.
load(pinfo);
386 if(plugin.get() ==
nullptr)
388 boost::format err_msg(
TE_TR(
"Could not load plugin: '%1%'."));
403 for(
const std::string& plugin_dependency : pinfo.
dependencies)
407 std::shared_ptr<AbstractPlugin>(plugin.release()));
409 if(found_in_unloaded_list)
414 else if(found_in_broken_list)
421 boost::format err_msg(
422 TE_TR(
"Unexpected error after loading plugin: '%1%'."));
427 catch(
const boost::exception& e)
431 if(found_in_unloaded_list)
434 if(
const std::string*
d = boost::get_error_info<ErrorDescription>(e))
440 boost::format err_msg(
TE_TR(
"Unknown error loading plugin: %1%."));
447 boost::format err_msg(
TE_TR(
"Unknown error loading plugin: %1%."));
457 if(p->info().name == plugin_name)
465 boost::format err_msg(
466 TE_TR(
"The plugin '%1%' is not loaded, load it before starting it."));
477 if(it->second.size() == 0)
481 if(p->info().name == plugin_name)
489 boost::format err_msg(
TE_TR(
490 "The plugin '%1%' is not loaded, load it before trying to stop it."));
496 boost::format err_msg(
497 TE_TR(
"The plugin '%1%' cannot be stopped, because is required by: %2%"));
499 std::string dependents = boost::algorithm::join(it->second,
", ");
501 TE_LOG_TRACE((err_msg % plugin_name % dependents).str());
509 for(std::size_t plugin_pos = 0; plugin_pos !=
m_pimpl->
plugins.size();
520 auto dependencies =
m_pimpl->
plugins[plugin_pos]->info().dependencies;
521 for(std::string dependency : dependencies)
528 "' dependency from: " + dependency));
537 boost::format err_msg(
TE_TR(
538 "The plugin '%1%' is initialized, stop it before trying to unload " 564 for(
auto it = v_pInfo.rbegin(); it != v_pInfo.rend(); ++it)
566 std::string plugin_name = it->name;
593 std::size_t plugin_pos)
595 assert(plugin_pos < unloaded_plugins.size());
597 PluginInfo pinfo = unloaded_plugins[plugin_pos];
599 unloaded_plugins.erase(unloaded_plugins.begin() + plugin_pos);
601 broken_plugins.push_back(pinfo);
605 std::size_t plugin_pos)
607 assert(plugin_pos < broken_plugins.size());
609 PluginInfo pinfo = broken_plugins[plugin_pos];
611 broken_plugins.erase(broken_plugins.begin() + plugin_pos);
613 unloaded_plugins.push_back(pinfo);
An exception indicating an error when shutting down a plugin.
An exception indicating an error when unloading a plugin.
void move_from_broken_to_unloaded_list(std::size_t plugin_pos)
void recursiveUnload(const std::string &plugin_name)
Try to unload a given plugin and its dependents recursively.
An exception indicating an error when loading a plugin.
void stop(const std::string &plugin_name)
Stop a loaded plugin.
std::string engine
The type of plugin execution engine: C++, JAVA, LUA or any other supported engine.
A singleton that can be used to register plugin engines.
An exception indicating an error when trying to shutdown a plugin with a dependent.
void insert(const PluginInfo &pinfo)
Adds plugin with its plugin information to the list of unloaded plugins.
std::vector< PluginInfo > getBrokenPlugins() const
Return the list of plugins that could not be loaded.
An exception indicating an error when trying to start a plugin.
std::vector< std::shared_ptr< AbstractPlugin > > plugins
The list of managed plugins: this will be needed to unload accordinly the plugins! ...
Basic information about a plugin.
#define TE_TR(message)
It marks a string in order to get translated.
bool isUnloaded(const std::string &plugin_name) const
Returns true if the plugin is in the not-loaded list of plugins.
void load(const std::string &plugin_name, const bool start=true)
It tries to load the informed plugin.
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...
boost::error_info< struct tag_error_description, std::string > ErrorDescription
The base type for error report messages.
virtual std::unique_ptr< AbstractPlugin > load(const PluginInfo &pinfo)=0
Load the informed plugin.
std::string name
The plugin name: an internal value used to identify the plugin in the system. Must be a unique value...
std::vector< PluginInfo > broken_plugins
The list of plugins that could not be loaded.
std::vector< std::string > getPlugins() const
Return the list of plugins managed by PluginManager.
static PluginManager & instance()
Access the singleton.
bool exists(const std::string &plugin_name) const
Tells if a given plugin is registered or not.
std::vector< PluginInfo > getUnloadedPlugins() const
Return the list of plugins that were not loaded.
The base class for plugin engines.
std::vector< std::string > getDependents(const std::string plugin_name)
Return the list of plugins that depends of a given plugin.
bool isBroken(const std::string &plugin_name) const
Returns true if the plugin is in the broken list of plugins.
static te::dt::DateTime d(2010, 8, 9, 15, 58, 39)
A singleton for managing plugins.
bool isLoaded(const std::string &plugin_name) const
Returns true if the plugin is loaded otherwise returns false.
AbstractPluginEngine & get(const std::string &engine_id) const
Find a plugin engine with the given id.
The base class for plugin engines.
std::vector< std::string > dependencies
The list of required plugins in order to launch the plugin.
~PluginManager()
Destructor.
const PluginInfo & getPluginInfo(const std::string &name) const
Return information about a plugin identified by the given name.
An exception indicating that a given item was not found in a collection (or range).
The base class for plugins in TerraLib.
std::vector< PluginInfo > unloaded_plugins
The list of plugins that are not loaded.
#define TE_LOG_TRACE(message)
Use this tag in order to log a message to the TerraLib default logger with the TRACE level...
void remove(const std::string &plugin_name)
Remove plugin from the manager.
void start(const std::string &plugin_name)
Start a loaded plugin.
An exception indicating that a given argument is not valid, for instance if a given item already exis...
void clear()
Stop and unload all plugins, then clear the internal list of plugins.
PluginManager()
Constructor.
std::vector< PluginInfo > getLoadedPlugins() const
Return the list of plugins that are loaded.
void unload(const std::string &plugin_name)
Try to unload a given plugin.
static PluginEngineManager & instance()
Access the singleton.
std::map< std::string, std::vector< std::string > > dependency_map
The list of plugins dependencies.
void move_from_unload_to_broken_list(std::size_t plugin_pos)