OSDN Git Service

8883cb2a97ad1f50142291234acaf884dcef1eae
[ultramonkey-l7/sslproxy.git] / parameter / parameter.cpp
1 /*
2  * @file  parameter.cpp
3  * @brief parameter module creation class.
4  *
5  * L7VSD: Linux Virtual Server for Layer7 Load Balancing
6  * Copyright (C) 2008  NTT COMWARE Corporation.
7  *
8  * This program is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU Lesser General Public
10  * License as published by the Free Software Foundation; either
11  * version 2.1 of the License, or (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16  * Lesser General Public License for more details.
17  *
18  * You should have received a copy of the GNU Lesser General Public
19  * License along with this library; if not, write to the Free Software
20  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
21  * 02110-1301 USA
22  *
23  **********************************************************************/
24
25 #include "parameter_enum.h"
26 #include "parameter.h"
27 #include "parameter_impl.h"
28 #include "logger_wrapper.h"
29
30 LOG_CATEGORY_TAG param_cat = LOG_CAT_SSLPROXY_PARAMETER;
31
32 /*!
33  * Constructor of Parameter class
34  */
35 l7vs::Parameter::Parameter()
36 {
37         if( !ParameterImpl::getInstance().init() ){
38                 LOGGER_PUT_LOG_FATAL( param_cat, 1, "Parameter initialize failure" );
39                 /*-------- DEBUG LOG for sslproxy --------*/
40                 if (LOG_LV_DEBUG == logger_get_log_level(param_cat)) {
41                         LOGGER_PUT_LOG_DEBUG(param_cat, 1,
42                                 "function : Constructor l7vs::Parameter::Parameter() : "
43                                 "Initialize error.");
44                 }
45                 /*------ DEBUG LOG END for sslproxy ------*/
46                 exit(1);
47         }
48 }
49
50 /*!
51  * Destructor of Parameter class
52  */
53 l7vs::Parameter::~Parameter()
54 {
55 }
56
57 /*!
58  * reload config file
59  * @param[in]   comp    section TAG
60  * @param[in]   filename    config file name
61  * @return      true = success read file / false = failure read file
62  */
63 bool
64 l7vs::Parameter::rereadFile(PARAMETER_COMPONENT_TAG comp, const std::string& filename)
65 {
66         /*-------- DEBUG LOG for sslproxy --------*/
67         if (LOG_LV_DEBUG == logger_get_log_level(param_cat)) {
68                 LOGGER_PUT_LOG_DEBUG(param_cat, 2,
69                         "function : bool l7vs::Parameter::rereadFile("
70                         "PARAMETER_COMPONENT_TAG comp, "
71                         "const std::string& filename) : "
72                         "Call ParameterImpl.rereadFile("
73                         "comp = %d, "
74                         "filename = %s)",
75                         comp,
76                         filename.c_str());
77         }
78         /*------ DEBUG LOG END for sslproxy ------*/
79         return ParameterImpl::getInstance().rereadFile(comp, filename);
80 }
81
82 /*!
83  * check whether integer data exists.
84  * @param[in]   comp    section TAG
85  * @param[in]   key     key string
86  * @return      true = exist setting value / false = non exist setting value
87  */
88 bool
89 l7vs::Parameter::isIntExist(const PARAMETER_COMPONENT_TAG comp, const std::string& key)
90 {
91         return ParameterImpl::getInstance().isIntExist(comp, key);
92 }
93
94 /*!
95  * check whether character data exists.
96  * @param[in]   comp    section TAG
97  * @param[in]   key     key string
98  * @return      true = exist setting value / false = non exist setting value
99  */
100 bool
101 l7vs::Parameter::isStringExist(const PARAMETER_COMPONENT_TAG comp, const std::string& key)
102 {
103         return ParameterImpl::getInstance().isStringExist(comp, key);
104 }
105
106 /*!
107  * get integer data.
108  * @param[in]   comp    section TAG
109  * @param[in]   key     key string
110  * @return      value
111  */
112 int
113 l7vs::Parameter::getIntValue(const PARAMETER_COMPONENT_TAG comp, const std::string& key)
114 {
115         return ParameterImpl::getInstance().getIntValue(comp, key);
116 }
117
118 /*!
119  * get character data.
120  * @param[in]   comp    section TAG
121  * @param[in]   key     key string
122  * @return      value
123  */
124 std::string
125 l7vs::Parameter::getStringValue(const PARAMETER_COMPONENT_TAG comp, const std::string& key)
126 {
127         return ParameterImpl::getInstance().getStringValue(comp, key);
128 }
129
130 /*!
131  * get character map data.
132  * @param[in]   comp    section TAG
133  * @param[in]   key     key string
134  * @param[out]  retMap  map data
135  * @return      value
136  */
137 void
138 l7vs::Parameter::getStringMapValue(const PARAMETER_COMPONENT_TAG comp, const std::string& key, std::multimap<std::string, std::string>& retMap)
139 {
140         /*-------- DEBUG LOG for sslproxy --------*/
141         if (LOG_LV_DEBUG == logger_get_log_level(param_cat)) {
142                 LOGGER_PUT_LOG_DEBUG(param_cat, 3,
143                         "function : void l7vs::Parameter::getStringMapValue("
144                         "const PARAMETER_COMPONENT_TAG comp, "
145                         "const std::string& key, "
146                         "std::multimap<std::string, std::string>& retMap) : "
147                         "Call ParameterImpl.getStringMapValue("
148                         "comp = %d, "
149                         "key = %s)",
150                         comp,
151                         key.c_str());
152         }
153         /*------ DEBUG LOG END for sslproxy ------*/
154         return ParameterImpl::getInstance().getStringMapValue(comp, key, retMap);
155 }
156
157 /*!
158  * set-parameter function pointer relates component-tag
159  * @param[in]   comp    section TAG
160  * @param[in]   p_func  function pointer
161  */
162 void
163 l7vs::Parameter::registerFunctionPointer(const PARAMETER_COMPONENT_TAG comp, void(*p_func)())
164 {
165         ParameterImpl::getInstance().registerFunctionPointer(comp, p_func);
166 }
167