Salome HOME
Merge branch 'master' of newgeom:newgeom
[modules/shaper.git] / src / Config / Config_ModuleReader.cpp
1 /*
2  * Config_ModuleReader.cpp
3  *
4  *  Created on: Mar 20, 2014
5  *      Author: sbh
6  */
7
8 #include <Config_Keywords.h>
9 #include <Config_Common.h>
10 #include <Config_ModuleReader.h>
11 #include <Config_FeatureReader.h>
12
13 #include <libxml/parser.h>
14 #include <libxml/tree.h>
15
16 #ifdef _DEBUG
17 #include <iostream>
18 #endif
19
20
21
22 Config_ModuleReader::Config_ModuleReader(const char* theEventGenerated)
23     : Config_XMLReader("plugins.xml"),
24       myEventGenerated(theEventGenerated)
25 {
26 }
27
28 Config_ModuleReader::~Config_ModuleReader()
29 {
30 }
31
32 const std::map<std::string, std::string>& Config_ModuleReader::featuresInFiles() const
33 {
34   return myFeaturesInFiles;
35 }
36
37 /*
38  * Get module name from plugins.xml
39  * (property "module")
40  */
41 std::string Config_ModuleReader::getModuleName()
42 {
43   xmlNodePtr aRoot = findRoot();
44   return getProperty(aRoot, PLUGINS_MODULE);
45 }
46
47 /*
48  *
49  */
50 void Config_ModuleReader::processNode(xmlNodePtr theNode)
51 {
52   if (isNode(theNode, NODE_PLUGIN, NULL)) {
53     std::string aPluginConf = getProperty(theNode, PLUGIN_CONFIG);
54     std::string aPluginLibrary = getProperty(theNode, PLUGIN_LIBRARY);
55     std::list<std::string> aFeatures = importPlugin(aPluginConf, aPluginLibrary);
56     std::list<std::string>::iterator it = aFeatures.begin();
57     for( ; it != aFeatures.end(); it++ ) {
58       myFeaturesInFiles[*it] = aPluginConf;
59     }
60   }
61 }
62
63 bool Config_ModuleReader::processChildren(xmlNodePtr theNode)
64 {
65   return isNode(theNode, NODE_PLUGINS, NULL);
66 }
67
68 std::list<std::string>
69 Config_ModuleReader::importPlugin(const std::string& thePluginFile,
70                                   const std::string& thePluginLibrary)
71 {
72   Config_FeatureReader aReader = Config_FeatureReader(thePluginFile,
73                                                       thePluginLibrary,
74                                                       myEventGenerated);
75   aReader.readAll();
76   return aReader.features();
77 }
78