iotivity 0.9.0
[platform/upstream/iotivity.git] / service / protocol-plugin / plugin-manager / src / Config.h
1 //******************************************************************
2 //
3 // Copyright 2014 Samsung Electronics All Rights Reserved.
4 //
5 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
6 //
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
10 //
11 //      http://www.apache.org/licenses/LICENSE-2.0
12 //
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.
18 //
19 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
20
21 /// @file Config.h
22
23 /// @brief
24
25 #ifndef __CONFIG_H
26 #define __CONFIG_H
27 #include <map>
28 #include <string>
29 #include <stdio.h>
30 #include <string.h>
31 #include <stdlib.h>
32 #include "rapidxml.hpp"
33 #include <fstream>
34 #include <vector>
35
36 using namespace rapidxml;
37
38 namespace OIC
39 {
40
41     enum PMRESULT
42     {
43         PM_S_OK
44         , PM_S_FALSE
45         , PM_E_POINTER
46         , PM_E_OUTOFMEMORY
47         , PM_E_FAIL
48         , PM_E_NOINTERFACE
49         , PM_E_NOTIMPL
50     };
51     /**
52     * @brief    Configuration class
53     *
54     *
55     */
56     class Config
57     {
58         public:
59             /**
60             * A function to register pluins in the path.
61             * This function will load plugins in plugin manager table.
62             *
63             * @param path plugin file path to be registered.
64             * @return int, 1 is success, 0 is fail.
65             *
66             * NOTE:
67             *
68             */
69             /**
70             *
71             * new Singleton pattern instance.
72             *
73             * @return config pointer Address.
74             */
75             static Config *Getinstance()
76             {
77                 if (NULL == s_configinstance)
78                 {
79                     s_configinstance = new Config();
80                 }
81
82                 return s_configinstance;
83             }
84             std::string  getPluginPath();
85             std::string  getVersion();
86             std::string  getValue(const std::string key);
87
88         private:
89             static Config *s_configinstance;
90             typedef std::map<std::string, std::string> configmap;
91             configmap m_configurationMap;
92             /**
93             * Constructor for Config.
94             * During construction time, configuration file  will be loaded.
95             *
96             */
97             Config();
98
99             /**
100             * Virtual destructor
101             */
102             virtual ~Config(void);
103
104             /**
105             * delete Singleton pattern instance.
106             */
107             static void deleteinstance()
108             {
109                 if (NULL != s_configinstance)
110                 {
111                     delete s_configinstance;
112                     s_configinstance = NULL;
113                 }
114             }
115             void setValue(const std::string key, const std::string value);
116             PMRESULT loadConfigFile(const std::string configfilepath);
117             PMRESULT parsing(std::vector<char> buffer, xml_document<> *doc);
118             PMRESULT getXmlData(  xml_node<> *pluginInfo, std::string key);
119     };
120 }
121
122 #endif