Salome HOME
Set plugin's library name as field of feature message.
[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_ModuleReader.h>
9 #include <Config_FeatureReader.h>
10
11 #include <libxml\parser.h>
12 #include <libxml\tree.h>
13
14 #ifdef _DEBUG
15 #include <iostream>
16 #endif
17
18 //Hardcoded xml entities
19 // * Nodes
20 const static char* NODE_PLUGIN = "plugin";
21 const static char* NODE_PLUGINS = "plugins";
22
23 // * Properties
24 const static char* PLUGINS_MODULE = "module";
25 const static char* PLUGIN_CONFIG = "configuration";
26 const static char* PLUGIN_LIBRARY = "library";
27
28 Config_ModuleReader::Config_ModuleReader()
29     : Config_XMLReader("plugins.xml"), myIsAutoImport(false)
30 {
31 }
32
33 Config_ModuleReader::~Config_ModuleReader()
34 {
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     if (myIsAutoImport)
56       importPlugin(aPluginConf, aPluginLibrary);
57     myPluginsMap[aPluginLibrary] = aPluginConf;
58   }
59 }
60
61 bool Config_ModuleReader::processChildren(xmlNodePtr theNode)
62 {
63   return isNode(theNode, NODE_PLUGINS, NULL);
64 }
65
66 void Config_ModuleReader::importPlugin(const std::string& thePluginName,
67                                        const std::string& thePluginLibrary)
68 {
69   Config_FeatureReader* aReader;
70   if(thePluginLibrary.empty()) {
71     aReader = new Config_FeatureReader(thePluginName);
72   } else {
73     aReader = new Config_FeatureReader(thePluginName, thePluginLibrary);
74   }
75   aReader->readAll();
76 }
77
78 void Config_ModuleReader::setAutoImport(bool theEnabled)
79 {
80   myIsAutoImport = theEnabled;
81 }
82
83 const std::map<std::string, std::string>& Config_ModuleReader::plugins() const
84 {
85   return myPluginsMap;
86 }