2 * Config_ModuleReader.cpp
4 * Created on: Mar 20, 2014
8 #include <Config_Keywords.h>
9 #include <Config_Common.h>
10 #include <Config_ModuleReader.h>
11 #include <Config_FeatureReader.h>
12 #include <Events_Error.h>
14 #include <libxml/parser.h>
15 #include <libxml/tree.h>
26 Config_ModuleReader::Config_ModuleReader(const char* theEventGenerated)
27 : Config_XMLReader("plugins.xml"),
28 myEventGenerated(theEventGenerated)
32 Config_ModuleReader::~Config_ModuleReader()
36 const std::map<std::string, std::string>& Config_ModuleReader::featuresInFiles() const
38 return myFeaturesInFiles;
42 * Get module name from plugins.xml
45 std::string Config_ModuleReader::getModuleName()
47 xmlNodePtr aRoot = findRoot();
48 return getProperty(aRoot, PLUGINS_MODULE);
54 void Config_ModuleReader::processNode(xmlNodePtr theNode)
56 if (isNode(theNode, NODE_PLUGIN, NULL)) {
57 std::string aPluginConf = getProperty(theNode, PLUGIN_CONFIG);
58 std::string aPluginLibrary = getProperty(theNode, PLUGIN_LIBRARY);
59 std::list<std::string> aFeatures = importPlugin(aPluginLibrary, aPluginConf);
60 std::list<std::string>::iterator it = aFeatures.begin();
61 for (; it != aFeatures.end(); it++) {
62 myFeaturesInFiles[*it] = aPluginConf;
67 bool Config_ModuleReader::processChildren(xmlNodePtr theNode)
69 return isNode(theNode, NODE_PLUGINS, NULL);
72 std::list<std::string> Config_ModuleReader::importPlugin(const std::string& thePluginLibrary,
73 const std::string& thePluginFile)
75 if (thePluginFile.empty()) { //probably a third party library
76 loadLibrary(thePluginLibrary);
77 return std::list<std::string>();
80 Config_FeatureReader aReader = Config_FeatureReader(thePluginFile, thePluginLibrary,
83 return aReader.features();
86 void Config_ModuleReader::loadLibrary(const std::string theLibName)
88 std::string aFileName = library(theLibName);
89 if (aFileName.empty())
93 HINSTANCE aModLib = ::LoadLibrary(aFileName.c_str());
94 if (!aModLib && theLibName != "DFBrowser") { // don't shor error for internal debugging tool
95 std::string errorMsg = "Failed to load " + aFileName;
96 std::cerr << errorMsg << std::endl;
97 Events_Error::send(errorMsg);
100 void* aModLib = dlopen( aFileName.c_str(), RTLD_LAZY | RTLD_GLOBAL );
101 if ( !aModLib && theLibName != "DFBrowser") { // don't shor error for internal debugging tool
102 std::cerr << "Failed to load " << aFileName.c_str() << std::endl;