#include <Config_Common.h>
#include <Config_ModuleReader.h>
#include <Config_FeatureReader.h>
+#include <Events_Error.h>
#include <libxml/parser.h>
#include <libxml/tree.h>
-#ifdef _DEBUG
+//Necessary for cerr
#include <iostream>
-#endif
-
+#ifdef WIN32
+#include <windows.h>
+#else
+#include <dlfcn.h>
+#endif
Config_ModuleReader::Config_ModuleReader(const char* theEventGenerated)
- : Config_XMLReader("plugins.xml"),
- myEventGenerated(theEventGenerated)
+ : Config_XMLReader("plugins.xml"), myEventGenerated(theEventGenerated)
{
}
if (isNode(theNode, NODE_PLUGIN, NULL)) {
std::string aPluginConf = getProperty(theNode, PLUGIN_CONFIG);
std::string aPluginLibrary = getProperty(theNode, PLUGIN_LIBRARY);
- std::list<std::string> aFeatures = importPlugin(aPluginConf, aPluginLibrary);
+ std::list<std::string> aFeatures = importPlugin(aPluginLibrary, aPluginConf);
std::list<std::string>::iterator it = aFeatures.begin();
- for( ; it != aFeatures.end(); it++ ) {
+ for(; it != aFeatures.end(); it++) {
myFeaturesInFiles[*it] = aPluginConf;
}
}
return isNode(theNode, NODE_PLUGINS, NULL);
}
-std::list<std::string>
-Config_ModuleReader::importPlugin(const std::string& thePluginFile,
- const std::string& thePluginLibrary)
+std::list<std::string> Config_ModuleReader::importPlugin(const std::string& thePluginLibrary,
+ const std::string& thePluginFile)
{
- Config_FeatureReader aReader = Config_FeatureReader(thePluginFile,
- thePluginLibrary,
+ if (thePluginFile.empty()) { //probably a third party library
+ loadLibrary(thePluginLibrary);
+ return std::list<std::string>();
+ }
+
+ Config_FeatureReader aReader = Config_FeatureReader(thePluginFile, thePluginLibrary,
myEventGenerated);
aReader.readAll();
return aReader.features();
}
+void Config_ModuleReader::loadLibrary(const std::string theLibName)
+{
+ std::string aFileName = library(theLibName);
+ if (aFileName.empty())
+ return;
+
+#ifdef WIN32
+ HINSTANCE aModLib = ::LoadLibrary(aFileName.c_str());
+ if (!aModLib) {
+ std::string errorMsg = "Failed to load " + aFileName;
+ std::cerr << errorMsg << std::endl;
+ Events_Error::send(errorMsg);
+ }
+#else
+ void* aModLib = dlopen( aFileName.c_str(), RTLD_LAZY | RTLD_GLOBAL );
+ if ( !aModLib ) {
+ std::cerr << "Failed to load " << aFileName.c_str() << std::endl;
+ }
+#endif
+}
+