32 #include "../filesystem/FileSystem.h" 33 #include "../lib/Library.h" 34 #include "../logger/Logger.h" 35 #include "../translator/Translator.h" 45 #include <boost/filesystem.hpp> 46 #include <boost/format.hpp> 79 std::unique_ptr<te::core::AbstractPlugin>
83 std::vector<Resource>::const_iterator it = std::find_if(pinfo.
resources.begin(),
88 return r.first ==
"shared_library_name";
93 boost::format err_msg(
TE_TR(
"Shared library name not informed for plugin: %1%."));
101 boost::filesystem::path plugin_file(slib_name);
103 std::shared_ptr<Library> slib(
new Library(plugin_file.string(),
true));
107 boost::format loading_log_msg(
TE_TR(
"Trying to load plugin '%1%' as: %2%"));
108 boost::format err_log_msg(
TE_TR(
"Plugin '%1%' could not loaded as: %2%"));
113 (loading_log_msg % pinfo.
name %
120 err_msg += plugin_file.string();
123 (path / plugin_file).string())).str());
125 #if(TE_PLATFORM == TE_PLATFORMCODE_APPLE) 126 if(!slib->isLoaded())
131 plugin_file /= slib_name;
134 (loading_log_msg % pinfo.
name %
143 err_msg += plugin_file.string();
145 (err_log_msg % pinfo.
name %
150 if(!slib->isLoaded())
155 plugin_file /=
"lib";
156 plugin_file /= slib_name;
159 (loading_log_msg % pinfo.
name %
168 err_msg += plugin_file.string();
170 (err_log_msg % pinfo.
name %
177 if(!slib->isLoaded())
179 boost::format err(
TE_TR(
"Could not find shared library as:\n%1%"));
186 void* fptr = slib->getAddress(
"te_cpp_plugin_get_instance");
190 if(plugin_entry ==
nullptr)
192 boost::format err_msg(
TE_TR(
"Could not find entry point '%1%' for plugin '%2%'."));
197 std::unique_ptr<CppPlugin> cpp_plugin(plugin_entry(pinfo));
199 if(cpp_plugin ==
nullptr)
201 boost::format err_msg(
TE_TR(
"Plugin '%1%' returned a null entry."));
206 std::unique_ptr<CppPluginProxy> proxy(
new CppPluginProxy(slib, std::move(cpp_plugin)));
208 return std::move(proxy);
214 if(plugin ==
nullptr)
217 if(plugin->info().engine !=
"C++")
219 boost::format err_msg(
TE_TR(
"Plugin '%1%' must be unloaded with plugin engine '%2%' not by C++ plugin engine."));
CppPlugin *(* te_get_plugin_fnct_t)(const PluginInfo &pinfo)
The type of function for plugin's entry point.
An exception indicating an error when loading a plugin.
An exception indicating an error when loading a plugin.
const std::string & id() const
It returns the id of the plugin engine.
CppPluginEngine()
Default construtor.
std::pair< std::string, std::string > Resource
const std::string & name() const
It returns the name of the plugin engine.
Basic information about a plugin.
std::vector< Resource > resources
The list of resources used by plugin.
#define TE_TR(message)
It marks a string in order to get translated.
A class for handling shared libraries (DLLs, SO, DyLibs).
boost::error_info< struct tag_error_description, std::string > ErrorDescription
The base type for error report messages.
std::string name
The plugin name: an internal value used to identify the plugin in the system. Must be a unique value...
static std::string absolutePath(const std::string &path)
Retrives the absolute path for the given path in UTF-8.
A proxy class for C++ plugins.
A base class for C++ plugins in TerraLib.
A plugin engine for plugins written in C++.
An exception indicating an error when releasing a given plugin.
~CppPluginEngine()
Destructor.
A proxy class for C++ plugins.
#define TE_LOG_TRACE(message)
Use this tag in order to log a message to the TerraLib default logger with the TRACE level...
static std::string currentPath()
Retrives the current working directory path in UTF-8.
static std::string getNativeName(const std::string &name)
Given a shared library name without file extensions, prefixes and nor suffixes it will construct a li...
Base exception class for TerraLib Core Runtime Library.
std::unique_ptr< AbstractPlugin > load(const PluginInfo &pinfo)
It loads a cpp plugin from a give PluginInfo.
void unload(std::unique_ptr< AbstractPlugin > plugin)
It unloads a cpp plugin from a give AbstractPlugin unique_ptr.