1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D
4 * Config_ModuleReader.cpp
6 * Created on: Mar 20, 2014
10 #include <Config_Keywords.h>
11 #include <Config_Common.h>
12 #include <Config_ModuleReader.h>
13 #include <Config_FeatureReader.h>
14 #include <Events_Error.h>
16 #include <libxml/parser.h>
17 #include <libxml/tree.h>
28 Config_ModuleReader::Config_ModuleReader(const char* theEventGenerated)
29 : Config_XMLReader("plugins.xml"),
30 myEventGenerated(theEventGenerated)
34 Config_ModuleReader::~Config_ModuleReader()
38 const std::map<std::string, std::string>& Config_ModuleReader::featuresInFiles() const
40 return myFeaturesInFiles;
44 * Get module name from plugins.xml
47 std::string Config_ModuleReader::getModuleName()
49 xmlNodePtr aRoot = findRoot();
50 return getProperty(aRoot, PLUGINS_MODULE);
56 void Config_ModuleReader::processNode(xmlNodePtr theNode)
58 if (isNode(theNode, NODE_PLUGIN, NULL)) {
59 std::string aPluginConf = getProperty(theNode, PLUGIN_CONFIG);
60 std::string aPluginLibrary = getProperty(theNode, PLUGIN_LIBRARY);
61 std::list<std::string> aFeatures = importPlugin(aPluginLibrary, aPluginConf);
62 std::list<std::string>::iterator it = aFeatures.begin();
63 for (; it != aFeatures.end(); it++) {
64 myFeaturesInFiles[*it] = aPluginConf;
69 bool Config_ModuleReader::processChildren(xmlNodePtr theNode)
71 return isNode(theNode, NODE_PLUGINS, NULL);
74 std::list<std::string> Config_ModuleReader::importPlugin(const std::string& thePluginLibrary,
75 const std::string& thePluginFile)
77 if (thePluginFile.empty()) { //probably a third party library
78 loadLibrary(thePluginLibrary);
79 return std::list<std::string>();
82 Config_FeatureReader aReader = Config_FeatureReader(thePluginFile, thePluginLibrary,
85 return aReader.features();
88 void Config_ModuleReader::loadLibrary(const std::string theLibName)
90 std::string aFileName = library(theLibName);
91 if (aFileName.empty())
95 HINSTANCE aModLib = ::LoadLibrary(aFileName.c_str());
96 if (!aModLib && theLibName != "DFBrowser") { // don't shor error for internal debugging tool
97 std::string errorMsg = "Failed to load " + aFileName;
98 std::cerr << errorMsg << std::endl;
99 Events_Error::send(errorMsg);
102 void* aModLib = dlopen( aFileName.c_str(), RTLD_LAZY | RTLD_GLOBAL );
103 if ( !aModLib && theLibName != "DFBrowser") { // don't shor error for internal debugging tool
104 std::cerr << "Failed to load " << aFileName.c_str() << std::endl;