2 * @file ns_xml_reader.h
3 * @brief \~english This file contains declaration of class CXMLReader.
6 /** @addtogroup BaseSystem
9 /** @addtogroup native_service
13 /** @addtogroup framework_unified
14 * @ingroup native_service
19 * @copyright Copyright (c) 2016-2020 TOYOTA MOTOR CORPORATION.
21 * Licensed under the Apache License, Version 2.0 (the "License");
22 * you may not use this file except in compliance with the License.
23 * You may obtain a copy of the License at
25 * http://www.apache.org/licenses/LICENSE-2.0
27 * Unless required by applicable law or agreed to in writing, software
28 * distributed under the License is distributed on an "AS IS" BASIS,
29 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
30 * See the License for the specific language governing permissions and
31 * limitations under the License.
34 ////////////////////////////////////////////////////////////////////////////////////////////////////
35 /// \ingroup tag_NS_ConfigParser
36 /// \brief This file contains declaration of class CXMLReader.
38 ////////////////////////////////////////////////////////////////////////////////////////////////////
40 #ifndef __FRAMEWORKUNIFIED_NATIVESERVICES_NSCONFIGPARSER_INC_NS_XML_READER_H__ // NOLINT (build/header_guard)
41 #define __FRAMEWORKUNIFIED_NATIVESERVICES_NSCONFIGPARSER_INC_NS_XML_READER_H__
43 ////////////////////////////////////////////////////////////////////////////////////////////////////
45 ////////////////////////////////////////////////////////////////////////////////////////////////////
46 #include <libxml/tree.h>
47 #include <native_service/frameworkunified_types.h>
48 #include <native_service/ns_reader.h>
54 * \~english @par Brief Introduction
55 * This class provides functionalities to read from XML config file.
58 class CXMLReader: public IConfigReader {
60 ////////////////////////////////////////////////////////////////////////////////
61 /// \ingroup CXMLReader
62 /// \~english @par Brief
63 /// This API constructor of CXMLReader class.
64 /// \~english @param None
65 /// \~english @retval None
66 /// \~english @par Prerequisite
67 /// - Load the shared library first
68 /// \~english @par Inside state change
69 /// - The API no inside state change
70 /// \~english @par None
71 /// \~english @par Classification
73 /// \~english @par Type
75 /// \~english @par Detail
76 /// This API should be called by ServiceA and create a new object of CXMLReader.
77 /// \~english @see None
78 ////////////////////////////////////////////////////////////////////////////////
80 ////////////////////////////////////////////////////////////////////////////////
81 /// \ingroup CXMLReader
82 /// \~english @par Brief
83 /// This API constructor of CXMLReader class.
84 /// \~english @param [IN] f_cFilePath
85 /// std::string - Full path of the configuration file
86 /// \~english @retval None
87 /// \~english @par Prerequisite
88 /// - Load the shared library first
89 /// \~english @par Inside state change
90 /// - The API no inside state change
91 /// \~english @par None
92 /// \~english @par Classification
94 /// \~english @par Type
96 /// \~english @par Detail
97 /// This API should be called by ServiceA and create a new object of CXMLReader with filepath.
98 /// \~english @see GetCXMLReaderObject
99 ////////////////////////////////////////////////////////////////////////////////
101 CXMLReader(const std::string &f_cFilePath); // NOLINT (readability/nolint)
103 ////////////////////////////////////////////////////////////////////////////////////////////////
104 /// \ingroup ~CXMLReader
105 /// \~english @par CXMLReader
106 /// Destructor of CXMLReader class.
107 /// \~english @param None
108 /// \~english @retval none
109 /// \~english @par Preconditons
111 /// \~english @par Change of internal status
112 /// - Close shared memory object.
113 /// \~english @par Conditions of processing failure
115 /// \~english @par Detail
116 /// Destruct the object of CXMLReader
117 /// \~english @par Classification
119 /// \~english @par Type
121 /// \~english @see CXMLReader
122 ////////////////////////////////////////////////////////////////////////////////////////////////
125 ////////////////////////////////////////////////////////////////////////////////
126 /// \ingroup ParseFile
127 /// \~english @par Brief
128 /// This API parser file
129 /// \~english @param [IN] f_cFilePath
130 /// std::string - path of file to parse
131 /// \~english @retval eFrameworkunifiedStatusOK Success
132 /// \~english @retval eFrameworkunifiedStatusNullPointer Null pointer
133 /// \~english @par Prerequisite
134 /// - Load the shared library first.
135 /// - Create XmlReader object.
136 /// \~english @par Inside state change
137 /// - The API no inside state change
138 /// \~english @par None
139 /// \~english @par Classification
141 /// \~english @par Type
143 /// \~english @par Detail
144 /// This API is used to parse the file from the path.
145 /// \~english @see CXMLReader or GetCXMLReaderObject
146 ////////////////////////////////////////////////////////////////////////////////
148 EFrameworkunifiedStatus ParseFile(const std::string &f_cFilePath);
150 ////////////////////////////////////////////////////////////////////////////////
151 /// \ingroup ParseFile
152 /// \~english @par Brief
153 /// Get Value with key
154 /// \~english @param [IN] f_cKey
155 /// std::string - key to search
156 /// \~english @retval std::string - value for key
157 /// \~english @par Prerequisite
158 /// - Load the shared library first.
159 /// - Create XmlReader object.
160 /// \~english @par Inside state change
161 /// - The API no inside state change
162 /// \~english @par None
163 /// \~english @par Classification
165 /// \~english @par Type
167 /// \~english @par Detail
168 /// This function is used to get the value associated with the key
169 /// \~english @see CXMLReader or GetCXMLReaderObject
170 ////////////////////////////////////////////////////////////////////////////////
171 std::string GetValue(const std::string &f_cKey);
172 ////////////////////////////////////////////////////////////////////////////////
173 /// \ingroup ParseFile
174 /// \~english @par Brief
175 /// Get Value with key
176 /// \~english @param [IN] f_cKey
177 /// std::string - key to search
178 /// \~english @param [REF] f_cValue
179 /// std::string - Value of key
180 /// \~english @retval eFrameworkunifiedStatusOK Success / Pass / OK
181 /// \~english @retval eFrameworkunifiedStatusFail Failed
182 /// \~english @retval eFrameworkunifiedStatusInvldParam Invalid parameter
183 /// \~english @retval eFrameworkunifiedStatusNullPointer Null pointer
184 /// \~english @par Prerequisite
185 /// - Load the shared library first.
186 /// - Create XmlReader object.
187 /// \~english @par Inside state change
188 /// - The API no inside state change
189 /// \~english @par None
190 /// \~english @par Classification
192 /// \~english @par Type
194 /// \~english @par Detail
195 /// This function is used to get the value associated with the key
196 /// \~english @see CXMLReader or GetCXMLReaderObject
197 ////////////////////////////////////////////////////////////////////////////////
200 EFrameworkunifiedStatus GetValue(const std::string &f_cKey, std::string &f_cValue); // NOLINT (readability/nolint)
201 ////////////////////////////////////////////////////////////////////////////////
202 /// \ingroup ParseFile
203 /// \~english @par Brief
204 /// Get Value with key
205 /// \~english @param None
206 /// \~english @retval PVOID - pointer of data structure
207 /// \~english @par Prerequisite
208 /// - Load the shared library first.
209 /// - Create XmlReader object.
210 /// \~english @par Inside state change
211 /// - The API no inside state change
212 /// \~english @par None
213 /// \~english @par Classification
215 /// \~english @par Type
217 /// \~english @par Detail
218 /// This function is used to get the data pointer. This pointer is then set in config writer.
219 /// \~english @see CXMLReader or GetCXMLReaderObject
220 ////////////////////////////////////////////////////////////////////////////////
224 ////////////////////////////////////////////////////////////////////////////////////////////////
226 /// This function is used to parse and get the value from xml file
228 /// \param [IN] f_pCurrNode
229 /// xmlNodePtr - pointer to current node in xml
230 /// \param [IN] f_cUserKey
231 /// std::string - Key to be searched for
233 /// \return std::string - content of key node
235 ////////////////////////////////////////////////////////////////////////////////////////////////
236 std::string XMLGetValue(xmlNodePtr f_pCurrNode, const std::string &f_cUserKey);
238 ////////////////////////////////////////////////////////////////////////////////////////////////
240 /// This function is used to parse and get the value from xml file
242 /// \param [IN] f_pCurrNode
243 /// xmlNodePtr - pointer to current node in xml
244 /// \param [IN] f_cUserKey
245 /// std::string - Key to be searched for
246 /// \param [IN] f_cValue
247 /// std::string - Value of Key
248 /// \param [IN] f_bKeyFound
249 /// BOOL - flag to check whether key exists in xml file or not
251 /// \return EFrameworkunifiedStatus - error if key not found or else eFrameworkunifiedStatusOK
253 ////////////////////////////////////////////////////////////////////////////////////////////////
254 EFrameworkunifiedStatus XMLGetValue(xmlNodePtr f_pCurrNode,
255 const std::string &f_cUserKey, std::string &f_cValue, BOOL &f_bKeyFound); // NOLINT (readability/nolint)
256 // pointer of xml document structure(DOM)
263 ////////////////////////////////////////////////////////////////////////////////
264 /// \ingroup GetCXMLReaderObject
265 /// \~english @par Brief
266 /// Get CXMLReader object.
267 /// \~english @param [IN] f_cFilePath
268 /// std::string - path of file to parse
269 /// \~english @retval CXMLReader *
270 /// \~english @par Prerequisite
271 /// - Load the shared library first.
272 /// \~english @par Inside state change
273 /// - The API no inside state change
274 /// \~english @par None
275 /// \~english @par Classification
277 /// \~english @par Type
279 /// \~english @par Detail
280 /// This API is used to create CXMLReader object with file path and return the CXMLReader pointer.
281 /// \~english @see None
282 ////////////////////////////////////////////////////////////////////////////////
283 CXMLReader *GetCXMLReaderObject(CHAR *f_cFilePath);
287 #endif /* __FRAMEWORKUNIFIED_NATIVESERVICES_NSCONFIGPARSER_INC_NS_XML_READER_H__ */ // NOLINT (build/header_guard)