Salome HOME
Changes in source code within porting on CentOS 6.3
[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_ModuleReader.h>
10 #include <Config_FeatureReader.h>
11
12 #include <libxml/parser.h>
13 #include <libxml/tree.h>
14
15 #ifdef _DEBUG
16 #include <iostream>
17 #endif
18
19
20
21 Config_ModuleReader::Config_ModuleReader()
22     : Config_XMLReader("plugins.xml"), myIsAutoImport(false)
23 {
24 }
25
26 Config_ModuleReader::~Config_ModuleReader()
27 {
28 }
29
30 /*
31  * Get module name from plugins.xml
32  * (property "module")
33  */
34 std::string Config_ModuleReader::getModuleName()
35 {
36   xmlNodePtr aRoot = findRoot();
37   return getProperty(aRoot, PLUGINS_MODULE);
38 }
39
40 /*
41  *
42  */
43 void Config_ModuleReader::processNode(xmlNodePtr theNode)
44 {
45   if (isNode(theNode, NODE_PLUGIN, NULL)) {
46     std::string aPluginConf = getProperty(theNode, PLUGIN_CONFIG);
47     std::string aPluginLibrary = getProperty(theNode, PLUGIN_LIBRARY);
48     if (myIsAutoImport)
49       importPlugin(aPluginConf, aPluginLibrary);
50     myPluginsMap[aPluginLibrary] = aPluginConf;
51   }
52 }
53
54 bool Config_ModuleReader::processChildren(xmlNodePtr theNode)
55 {
56   return isNode(theNode, NODE_PLUGINS, NULL);
57 }
58
59 void Config_ModuleReader::importPlugin(const std::string& thePluginName,
60                                        const std::string& thePluginLibrary)
61 {
62   Config_FeatureReader* aReader;
63   if(thePluginLibrary.empty()) {
64     aReader = new Config_FeatureReader(thePluginName);
65   } else {
66     aReader = new Config_FeatureReader(thePluginName, thePluginLibrary);
67   }
68   aReader->readAll();
69 }
70
71 void Config_ModuleReader::setAutoImport(bool theEnabled)
72 {
73   myIsAutoImport = theEnabled;
74 }
75
76 const std::map<std::string, std::string>& Config_ModuleReader::plugins() const
77 {
78   return myPluginsMap;
79 }