33 #include "../filesystem/FileSystem.h" 34 #include "../encoding/CharEncoding.h" 35 #include "../translator/Translator.h" 43 #include <boost/algorithm/string/join.hpp> 44 #include <boost/format.hpp> 45 #include <boost/graph/adjacency_list.hpp> 46 #include <boost/graph/topological_sort.hpp> 55 std::unique_ptr<te::core::AbstractPluginEngine> cppengine(
74 const std::vector<te::core::PluginInfo>& v_pInfo)
76 std::map<std::string, std::size_t> plugins_map;
78 const std::size_t nplugins = v_pInfo.size();
80 for(std::size_t i = 0; i != nplugins; ++i)
81 plugins_map.insert(std::make_pair(v_pInfo[i].name, i));
83 std::map<std::string, std::size_t>::const_iterator it_end = plugins_map.end();
85 typedef boost::adjacency_list<boost::vecS, boost::vecS, boost::directedS>
87 typedef boost::graph_traits<Graph>::vertex_descriptor Vertex;
91 for(std::size_t i = 0; i < nplugins; ++i)
92 boost::add_vertex(dgraph);
94 for(std::size_t i = 0; i != nplugins; ++i)
96 const std::vector<std::string>& required_plugins = v_pInfo[i].dependencies;
98 const std::size_t num_required_plugins = required_plugins.size();
100 for(std::size_t j = 0; j != num_required_plugins; ++j)
102 std::map<std::string, std::size_t>::const_iterator it =
103 plugins_map.find(required_plugins[j]);
109 boost::add_edge(it->second, i, dgraph);
114 std::vector<Vertex> toposortResult;
118 boost::topological_sort(dgraph, std::back_inserter(toposortResult));
120 catch(
const boost::not_a_dag& e)
122 boost::format err_msg(
123 TE_TR(
"The plugins cannot be sorted due to the following error: %1%"));
129 std::vector<te::core::PluginInfo> sortedPlugins;
131 for(
auto it = toposortResult.rbegin(); it != toposortResult.rend(); ++it)
132 sortedPlugins.push_back(v_pInfo[*it]);
134 assert(sortedPlugins.size() == v_pInfo.size());
136 return sortedPlugins;
147 std::vector<std::string> failToLoad;
158 failToLoad.push_back(pinfo.name);
161 if(failToLoad.size() > 0)
163 boost::format err_msg(
164 TE_TR(
"Could not load the following plugins:\n\n%1%"));
167 (err_msg % boost::algorithm::join(failToLoad,
"\n")).str());
173 std::vector<te::core::PluginInfo> pVec =
176 for(
auto plugin = pVec.rbegin(); plugin != pVec.rend(); ++plugin)
TECOREEXPORT void FinalizePluginSystem()
void insert(std::unique_ptr< AbstractPluginEngine > engine)
Register a new plugin engine.
TECOREEXPORT std::vector< PluginInfo > TopologicalSort(const std::vector< PluginInfo > &v_pinfo)
An exception indicating an error when loading a plugin.
void stop(const std::string &plugin_name)
Stop a loaded plugin.
A singleton that can be used to register plugin engines.
void insert(const PluginInfo &pinfo)
Adds plugin with its plugin information to the list of unloaded plugins.
Basic information about a plugin.
#define TE_TR(message)
It marks a string in order to get translated.
void load(const std::string &plugin_name, const bool start=true)
It tries to load the informed plugin.
void clear()
Unregister every plugin engine.
boost::error_info< struct tag_error_description, std::string > ErrorDescription
The base type for error report messages.
static PluginManager & instance()
Access the singleton.
General utilities for plugins.
TECOREEXPORT void UnloadPlugin(const std::string &plugin_name)
TECOREEXPORT void LoadAll(bool start=true)
std::vector< std::string > dependencies
The list of required plugins in order to launch the plugin.
const PluginInfo & getPluginInfo(const std::string &name) const
Return information about a plugin identified by the given name.
An exception indicating an error when two or more plugins have cyclic dependecy.
A plugin engine for plugins written in C++.
TECOREEXPORT std::vector< PluginInfo > DefaultPluginFinder()
static bool g_plugin_module_initialized(false)
TECOREEXPORT void InitializePluginSystem()
General utilities for searching for plugins.
void clear()
Stop and unload all plugins, then clear the internal list of plugins.
TECOREEXPORT void UnloadAll()
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.