9db7827816b51d4b4f5fcb771d8a9f578d3b05fb
[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 #ifdef ANDROID
36 #include <jni.h>
37 #endif
38
39 #define PATH_MAX_SIZE 100
40
41 using namespace rapidxml;
42
43 namespace OIC
44 {
45
46     enum PMRESULT
47     {
48         PM_S_OK
49         , PM_S_FALSE
50         , PM_E_POINTER
51         , PM_E_OUTOFMEMORY
52         , PM_E_FAIL
53         , PM_E_NOINTERFACE
54         , PM_E_NOTIMPL
55     };
56     /**
57     * @brief    Configuration class
58     *
59     *
60     */
61     class Config
62     {
63         public:
64             /**
65             * A function to register pluins in the path.
66             * This function will load plugins in plugin manager table.
67             *
68             * @param path plugin file path to be registered.
69             * @return int, 1 is success, 0 is fail.
70             *
71             * NOTE:
72             *
73             */
74             /**
75             *
76             * new Singleton pattern instance.
77             *
78             * @return config pointer Address.
79             */
80             static Config *Getinstance(void *args = NULL)
81             {
82                 if (NULL == s_configinstance)
83                 {
84                     s_configinstance = new Config(args);
85                 }
86
87                 return s_configinstance;
88             }
89             std::string  getPluginPath();
90             std::string  getVersion();
91             std::string  getValue(const std::string key);
92
93         private:
94             static Config *s_configinstance;
95             typedef std::map<std::string, std::string> configmap;
96             configmap m_configurationMap;
97
98             /**
99             * Constructor for Config.
100             * During construction time, configuration file  will be loaded.
101             *
102             */
103             Config(void *args = NULL);
104
105             /**
106             * Virtual destructor
107             */
108             virtual ~Config(void);
109
110             /**
111             * delete Singleton pattern instance.
112             */
113             static void deleteinstance()
114             {
115                 if (NULL != s_configinstance)
116                 {
117                     delete s_configinstance;
118                     s_configinstance = NULL;
119                 }
120             }
121             void setValue(const std::string key, const std::string value);
122             PMRESULT loadConfigFile(const std::string configfilepath);
123             PMRESULT parsing(char *xmlData, xml_document<> *doc);
124             PMRESULT getXmlData(  xml_node<> *pluginInfo, std::string key);
125     };
126 }
127
128 #endif