1 //******************************************************************
3 // Copyright 2014 Samsung Electronics All Rights Reserved.
5 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
7 // Licensed under the Apache License, Version 2.0 (the "License");
8 // you may not use this file except in compliance with the License.
9 // You may obtain a copy of the License at
11 // http://www.apache.org/licenses/LICENSE-2.0
13 // Unless required by applicable law or agreed to in writing, software
14 // distributed under the License is distributed on an "AS IS" BASIS,
15 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 // See the License for the specific language governing permissions and
17 // limitations under the License.
19 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
30 using namespace rapidxml;
33 Config *Config::s_configinstance = NULL;
37 if (loadConfigFile("./pluginmanager.xml") != PM_S_OK)
39 fprintf(stderr, "PM Configuration file is not exist current Folder.\n" );
46 s_configinstance->deleteinstance();
47 s_configinstance = NULL;
50 PMRESULT Config::loadConfigFile(const std::string configfilepath)
53 std::ifstream xmlFile(configfilepath.c_str());
56 std::vector<char> buffer((istreambuf_iterator<char>(xmlFile)), istreambuf_iterator<char>());
57 buffer.push_back('\0');
59 // Parse the buffer using the xml file parsing library into doc
60 parsing(buffer, &doc);
63 xml_node<> *root_node = doc.first_node("pluginManager");
64 xml_node<> *pluginInfo = root_node->first_node("pluginInfo");
66 getXmlData(pluginInfo, "pluginPath");
67 getXmlData(pluginInfo, "maxMEM");
68 getXmlData(pluginInfo, "version");
69 getXmlData(pluginInfo, "name");
74 PMRESULT Config::parsing(std::vector<char> buffer, xml_document<> *doc)
76 // Parse the buffer using the xml file parsing library into doc
79 doc->parse<0>(&buffer[0]);
81 catch (rapidxml::parse_error err)
83 //print errors to screen
84 fprintf(stderr, "PM Configuration file parsing error \n");
85 exit(EXIT_FAILURE); //then exit
90 PMRESULT Config::getXmlData(xml_node<> *pluginInfo, std::string key)
92 xml_attribute<> *iAttr = NULL;
93 std::string value = "";
94 if (iAttr = pluginInfo->first_attribute(key.c_str()))
96 value = iAttr->value();
106 void Config::setValue(const std::string key, const std::string value)
108 m_configurationMap.insert( std::pair<std::string, std::string>(key, value));
111 std::string Config::getValue(const std::string key)
113 std::map<std::string, std::string>::iterator m_iterator;
115 m_iterator = m_configurationMap.find(key.c_str());
117 if (m_iterator != m_configurationMap.end())
119 return m_iterator->second;
127 std::string Config::getVersion()
129 std::map<std::string, std::string>::iterator m_iterator;
131 m_iterator = m_configurationMap.find("version");
133 if (m_iterator != m_configurationMap.end())
135 return m_iterator->second;
143 std::string Config::getPluginPath()
145 std::map<std::string, std::string>::iterator m_iterator;
147 m_iterator = m_configurationMap.find("pluginPath");
149 if (m_iterator != m_configurationMap.end())
151 return m_iterator->second;