578c254b8574e363e4c404e2d71bbb06a787eac3
[profile/ivi/ico-uxf-homescreen.git] / src / syscond / CicoSysConLogConfig.cpp
1 /*
2  * Copyright (c) 2013, TOYOTA MOTOR CORPORATION.
3  *
4  * This program is licensed under the terms and conditions of the
5  * Apache License, version 2.0.  The full text of the Apache License is at
6  * http://www.apache.org/licenses/LICENSE-2.0
7  *
8  */
9
10 /*========================================================================*/    
11 /**
12  *  @file   CicoSysConLogConfig.cpp
13  *
14  *  @brief  This file implementation of CicoSysConLogConfig class
15  */
16 /*========================================================================*/    
17
18 #include <boost/property_tree/ptree.hpp>
19 #include <boost/property_tree/xml_parser.hpp>
20 #include <boost/foreach.hpp>
21 #include <boost/lexical_cast.hpp>
22
23 using namespace boost;
24 using namespace boost::property_tree;
25  
26 #include "CicoSysConLogConfig.h"
27
28 //==========================================================================    
29 //  private static variable
30 //==========================================================================    
31 CicoSysConLogConfig* CicoSysConLogConfig::ms_myInstance = NULL;
32
33 //--------------------------------------------------------------------------
34 /**
35  *  @brief  default constructor
36  */
37 //--------------------------------------------------------------------------
38 CicoSysConLogConfig::CicoSysConLogConfig()
39     : m_confFile(""), m_name("IcoSysConDaemon"),
40       m_levelPRF(false), m_levelTRA(false), m_levelDBG(false),
41       m_levelINF(false), m_levelWRN(false), m_levelCRI(false),
42       m_levelERR(false), m_flush(false), m_ecore(false)
43 {
44 }
45
46 //--------------------------------------------------------------------------
47 /**
48  *  @brief  destructor
49  */
50 //--------------------------------------------------------------------------
51 CicoSysConLogConfig::~CicoSysConLogConfig()
52 {
53 }
54
55 //--------------------------------------------------------------------------
56 /**
57  *  @brief  Get instance of CicoSysConLogConfig
58  *
59  *  @return  pointer of CicoSysConLogConfig object
60  */
61 //--------------------------------------------------------------------------
62 CicoSysConLogConfig*
63 CicoSysConLogConfig::getInstance(void)
64 {
65     if (NULL == ms_myInstance) {
66         ms_myInstance = new CicoSysConLogConfig();
67     }
68     return ms_myInstance;
69 }
70
71 //--------------------------------------------------------------------------
72 /**
73  *  @brief  Get instance of CicoSysConLogConfig
74  *
75  *  @param  [in]    confFile    config file name
76  *  @return 0 on success, other on error
77  */
78 //--------------------------------------------------------------------------
79 int
80 CicoSysConLogConfig::load(const std::string & confFile)
81 {
82     // load xml config file
83     ptree root;
84     read_xml(confFile, root);
85
86     //<log>
87     if (root.not_found() != root.find("system-controller.log")) {
88         printf("log element not found");
89         return -1;
90     }
91
92     ptree log = root.get_child("system-controller.log");
93
94     ptree child;
95     optional<std::string> sValue;
96     optional<bool> bValue;
97
98     // read <performance eneble="xxx"/>
99     sValue = log.get_optional<std::string>("name");
100     if (true == sValue.is_initialized()) {
101         m_name = sValue.get();
102     }
103
104     // read <performance eneble="xxx"/>
105     child  = log.get_child("level.performance");
106     bValue = child.get_optional<bool>("<xmlattr>.enable");
107     if (true == bValue.is_initialized()) {
108         m_levelPRF = bValue.get();
109     }
110
111     // read <trace eneble="xxx"/>
112     child  = log.get_child("level.trace");
113     bValue = child.get_optional<bool>("<xmlattr>.enable");
114     if (true == bValue.is_initialized()) {
115         m_levelTRA = bValue.get();
116     }
117
118     // read <debug eneble="xxx"/>
119     child  = log.get_child("level.debug");
120     bValue = child.get_optional<bool>("<xmlattr>.enable");
121     if (true == bValue.is_initialized()) {
122         m_levelDBG = bValue.get();
123     }
124
125     // read <info eneble="xxx"/>
126     child  = log.get_child("level.info");
127     bValue = child.get_optional<bool>("<xmlattr>.enable");
128     if (true == bValue.is_initialized()) {
129         m_levelINF = bValue.get();
130     }
131
132     // read <warning eneble="xxx"/>
133     child  = log.get_child("level.warning");
134     bValue = child.get_optional<bool>("<xmlattr>.enable");
135     if (true == bValue.is_initialized()) {
136         m_levelWRN = bValue.get();
137     }
138
139     // read <critical eneble="xxx"/>
140     child  = log.get_child("level.critical");
141     bValue = child.get_optional<bool>("<xmlattr>.enable");
142     if (true == bValue.is_initialized()) {
143         m_levelCRI = bValue.get();
144     }
145
146     // read <error eneble="xxx"/>
147     child  = log.get_child("level.error");
148     bValue = child.get_optional<bool>("<xmlattr>.enable");
149     if (true == bValue.is_initialized()) {
150         m_levelERR = bValue.get();
151     }
152
153     // read <flush eneble="xxx"/>
154     child  = log.get_child("flush");
155     bValue = child.get_optional<bool>("<xmlattr>.enable");
156     if (true == bValue.is_initialized()) {
157         m_flush = bValue.get();
158     }
159
160     // read <ecore eneble="xxx"/>
161     child  = log.get_child("ecore");
162     bValue = child.get_optional<bool>("<xmlattr>.enable");
163     if (true == bValue.is_initialized()) {
164         m_ecore = bValue.get();
165     }
166
167     return 0;
168 }
169
170
171 //--------------------------------------------------------------------------
172 /**
173  *  @brief  get log name
174  */
175 //--------------------------------------------------------------------------
176 std::string & 
177 CicoSysConLogConfig::getLogName(void)
178 {
179     return m_name;
180 }
181
182 //--------------------------------------------------------------------------
183 /**
184  *  @brief  get performance level enable state
185  */
186 //--------------------------------------------------------------------------
187 bool
188 CicoSysConLogConfig::isPRF(void)
189 {
190     return m_levelPRF;
191 }
192
193 //--------------------------------------------------------------------------
194 /**
195  *  @brief  get trace level enable state
196  */
197 //--------------------------------------------------------------------------
198 bool
199 CicoSysConLogConfig::isTRA(void)
200 {
201     return m_levelTRA;
202 }
203
204 //--------------------------------------------------------------------------
205 /**
206  *  @brief  get debug level enable state
207  */
208 //--------------------------------------------------------------------------
209 bool
210 CicoSysConLogConfig::isDBG(void)
211 {
212     return m_levelDBG;
213 }
214
215 //--------------------------------------------------------------------------
216 /**
217  *  @brief  get info level enable state
218  */
219 //--------------------------------------------------------------------------
220 bool
221 CicoSysConLogConfig::isINF(void)
222 {
223     return m_levelINF;
224 }
225
226 //--------------------------------------------------------------------------
227 /**
228  *  @brief  get warning level enable state
229  */
230 //--------------------------------------------------------------------------
231 bool
232 CicoSysConLogConfig::isWRN(void)
233 {
234     return m_levelWRN;
235 }
236
237 //--------------------------------------------------------------------------
238 /**
239  *  @brief  get critical level enable state
240  */
241 //--------------------------------------------------------------------------
242 bool
243 CicoSysConLogConfig::isCRI(void)
244 {
245     return m_levelCRI;
246 }
247
248 //--------------------------------------------------------------------------
249 /**
250  *  @brief  get error level enable state
251  */
252 //--------------------------------------------------------------------------
253 bool
254 CicoSysConLogConfig::isERR(void)
255 {
256     return m_levelERR;
257 }
258
259 //--------------------------------------------------------------------------
260 /**
261  *  @brief  get flush log enable state
262  */
263 //--------------------------------------------------------------------------
264 bool
265 CicoSysConLogConfig::isFlush(void)
266 {
267     return m_flush;
268 }
269
270 //--------------------------------------------------------------------------
271 /**
272  *  @brief  get ecore log print enalbe state
273  */
274 //--------------------------------------------------------------------------
275 bool
276 CicoSysConLogConfig::isEcore(void)
277 {
278     return m_ecore;
279 }
280 // vim:set expandtab ts=4 sw=4: