27 #include "../common/Exception.h"
28 #include "../common/Library.h"
29 #include "../common/LibraryManager.h"
30 #include "../common/Logger.h"
31 #include "../common/Translator.h"
32 #include "../common/PlatformUtils.h"
45 #include <boost/filesystem.hpp>
57 std::vector<PluginInfo::Resource>::const_iterator it = std::find_if(internalPluginInfo.
m_resources.begin(),
63 std::string m =
TR_PLUGIN(
"Shared library name not informed for plugin: ");
71 std::string libName = getPluginFileName(it->second);
80 boost::filesystem::path pluginFile( internalPluginInfo.
m_folder );
81 pluginFile /= libName;
84 if( boost::filesystem::exists(pluginFile) &&
85 boost::filesystem::is_regular_file(pluginFile) )
92 for( std::vector< std::string >::size_type dirIdx = 0 ; dirIdx <
93 m_defaultSearchDirs.size() ; ++dirIdx )
95 pluginFile = m_defaultSearchDirs[ dirIdx ];
96 pluginFile /= libName;
98 if(boost::filesystem::exists(pluginFile) &&
99 boost::filesystem::is_regular_file(pluginFile) )
101 internalPluginInfo.
m_folder = m_defaultSearchDirs[ dirIdx ];
111 std::string m =
TR_PLUGIN(
"Could not find load plugin: ");
112 m += internalPluginInfo.
m_name;
116 if(!slib->isLoaded())
122 if(getPluginFptr == NULL)
124 std::string m =
TR_PLUGIN(
"Could not find CppPluginGetInstance function into the plugin's code: ");
125 m += internalPluginInfo.
m_name;
131 std::auto_ptr<Plugin> cppPlugin(getPluginFptr(internalPluginInfo));
133 if(cppPlugin.get() == 0)
135 std::string m =
TR_PLUGIN(
"CppPluginGetInstance returned a null plugin instance: ");
136 m += internalPluginInfo.
m_name;
159 std::string nativeName = libName;
161 std::string nativeName = libName +
"_d";
172 dirs.push_back(
"." );
175 boost::filesystem::path p(
"lib");
177 if(boost::filesystem::is_directory(p))
178 dirs.push_back( boost::filesystem::system_complete( p ).
string() );
182 boost::filesystem::path p(
"win32");
184 if(boost::filesystem::is_directory(p))
185 dirs.push_back( boost::filesystem::system_complete( p ).
string() );
189 boost::filesystem::path p(
"win64");
191 if(boost::filesystem::is_directory(p))
192 dirs.push_back( boost::filesystem::system_complete( p ).
string() );
195 #ifdef TE_DEFAULT_PLUGINS_DIR
202 #ifdef TE_DIR_ENVIRONMENT_VARIABLE
204 char* e = getenv(TE_DIR_ENVIRONMENT_VARIABLE);
208 if(boost::filesystem::is_directory(e))
209 dirs.push_back( boost::filesystem::system_complete(e).
string() );
212 boost::filesystem::path p(e);
215 if(boost::filesystem::is_directory(p))
216 dirs.push_back( boost::filesystem::system_complete(p).
string() );
220 boost::filesystem::path p(e);
223 if(boost::filesystem::is_directory(p))
224 dirs.push_back( boost::filesystem::system_complete(p).
string() );
228 boost::filesystem::path p(e);
231 if(boost::filesystem::is_directory(p))
232 dirs.push_back( boost::filesystem::system_complete(p).
string() );
235 #ifdef TE_DEFAULT_PLUGINS_DIR
237 boost::filesystem::path p(e);
240 if(boost::filesystem::is_directory(p))
241 dirs.push_back( boost::filesystem::system_complete(p).
string() );
249 char* e = getenv(
"TERRALIB_DIR");
253 if(boost::filesystem::is_directory(e))
254 dirs.push_back( boost::filesystem::system_complete(e).
string() );
257 boost::filesystem::path p(e);
260 if(boost::filesystem::is_directory(p))
261 dirs.push_back( boost::filesystem::system_complete(p).
string() );
265 boost::filesystem::path p(e);
268 if(boost::filesystem::is_directory(p))
269 dirs.push_back( boost::filesystem::system_complete(p).
string() );
273 boost::filesystem::path p(e);
276 if(boost::filesystem::is_directory(p))
277 dirs.push_back( boost::filesystem::system_complete(p).
string() );
280 #ifdef TE_DEFAULT_PLUGINS_DIR
282 boost::filesystem::path p(e);
285 if(boost::filesystem::is_directory(p))
286 dirs.push_back( boost::filesystem::system_complete(p).
string() );
292 #ifdef TE_PLUGINS_PATH
294 if(boost::filesystem::is_directory(TE_PLUGINS_PATH))
295 dirs.push_back( boost::filesystem::system_complete(TE_PLUGINS_PATH).
string() );
298 boost::filesystem::path p(TE_PLUGINS_PATH);
301 if(boost::filesystem::is_directory(p))
302 dirs.push_back( boost::filesystem::system_complete(p).
string() );
306 boost::filesystem::path p(TE_PLUGINS_PATH);
309 if(boost::filesystem::is_directory(p))
310 dirs.push_back( boost::filesystem::system_complete(p).
string() );
314 boost::filesystem::path p(TE_PLUGINS_PATH);
317 if(boost::filesystem::is_directory(p))
318 dirs.push_back( boost::filesystem::system_complete(p).
string() );
321 #ifdef TE_DEFAULT_PLUGINS_DIR
323 boost::filesystem::path p(TE_PLUGINS_PATH);
326 if(boost::filesystem::is_directory(p))
327 dirs.push_back( boost::filesystem::system_complete(p).
string() );
333 std::vector< std::string > decPath;
335 for( std::vector< std::string >::size_type decPathIdx = 0 ; decPathIdx < decPath.size() ;
338 dirs.push_back( decPath[ decPathIdx ] );
341 std::vector< std::string > decLDPath;
343 for( std::vector< std::string >::size_type decLDPathIdx = 0 ; decLDPathIdx < decLDPath.size() ;
346 dirs.push_back( decLDPath[ decLDPathIdx ] );
void GetDecompostedPathEnvVar(std::vector< std::string > &paths)
Returns the system PATH enviroment variable, decomposed into directory names, or an empty vector if n...
The basic information about a plugin.
A proxy class for C++ plugins.
The basic information about a plugin.
std::vector< std::string > m_defaultSearchDirs
The default plugin libraries search directories.
void unload(AbstractPlugin *plugin)
It try to unload the informed plugin.
An abstract class for TerraLib Plugins.
static std::string getPluginFileName(const std::string &libName)
This method will help to form the library name wich contains the plugin.
This class is designed to declare objects to be thrown as exceptions by TerraLib. ...
std::vector< Resource > m_resources
The list of resources used by plugin.
#define TR_PLUGIN(message)
It marks a string in order to get translated. This is a special mark used in the Plugin module of Ter...
static std::string getNativeName(const std::string &name)
Given a library name without file extensions, prefixes and nor suffixes it will construct a library n...
Plugin *(* GetPluginFPtr)(const PluginInfo &info)
It exports Plugin's access function type.
void add(const std::string &id, const LibraryPtr &l)
It adds a new Library to be managed.
A plugin engine for plugins written in C++.
A class for handling shared libraries (DLLs, SO, DyLibs).
void GetDecompostedLDPathEnvVar(std::vector< std::string > &paths)
Returns the system LD_LIBRARY_PATH enviroment variable, decomposed into directory names...
#define TE_DEFAULT_PLUGINS_DIR
The default look up plugin dir.
A proxy class for C++ plugins.
AbstractPlugin * load(const PluginInfo &pInfo)
It try to create and load the informed plugin.
virtual const PluginInfo & getInfo() const =0
It return the information associated to the plugin.
boost::shared_ptr< Library > LibraryPtr
std::string m_engine
The type of plugin execution engine: C++, JAVA.
static LibraryManager & getInstance()
It returns a reference to the singleton instance.
std::string m_name
The plugin name: an internal value used to identify the plugin in the system. Must be a unique value...
static void getDefaultDirs(std::vector< std::string > &dirs)
It returns the default plugins libraries search directories.
A base class for plugin types.
std::string m_folder
The plugin folder (where the plugin is installed).