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"), myEventGenerated(theEventGenerated)
31 Config_ModuleReader::~Config_ModuleReader()
35 const std::map<std::string, std::string>& Config_ModuleReader::featuresInFiles() const
37 return myFeaturesInFiles;
41 * Get module name from plugins.xml
44 std::string Config_ModuleReader::getModuleName()
46 xmlNodePtr aRoot = findRoot();
47 return getProperty(aRoot, PLUGINS_MODULE);
53 void Config_ModuleReader::processNode(xmlNodePtr theNode)
55 if (isNode(theNode, NODE_PLUGIN, NULL)) {
56 std::string aPluginConf = getProperty(theNode, PLUGIN_CONFIG);
57 std::string aPluginLibrary = getProperty(theNode, PLUGIN_LIBRARY);
58 std::list<std::string> aFeatures = importPlugin(aPluginLibrary, aPluginConf);
59 std::list<std::string>::iterator it = aFeatures.begin();
60 for(; it != aFeatures.end(); it++) {
61 myFeaturesInFiles[*it] = aPluginConf;
66 bool Config_ModuleReader::processChildren(xmlNodePtr theNode)
68 return isNode(theNode, NODE_PLUGINS, NULL);
71 std::list<std::string> Config_ModuleReader::importPlugin(const std::string& thePluginLibrary,
72 const std::string& thePluginFile)
74 if (thePluginFile.empty()) { //probably a third party library
75 loadLibrary(thePluginLibrary);
76 return std::list<std::string>();
79 Config_FeatureReader aReader = Config_FeatureReader(thePluginFile, thePluginLibrary,
82 return aReader.features();
85 void Config_ModuleReader::loadLibrary(const std::string theLibName)
87 std::string aFileName = library(theLibName);
88 if (aFileName.empty())
92 HINSTANCE aModLib = ::LoadLibrary(aFileName.c_str());
94 std::string errorMsg = "Failed to load " + aFileName;
95 std::cerr << errorMsg << std::endl;
96 Events_Error::send(errorMsg);
99 void* aModLib = dlopen( aFileName.c_str(), RTLD_LAZY );
101 std::cerr << "Failed to load " << aFileName.c_str() << std::endl;