2 * @copyright Copyright (c) 2016-2020 TOYOTA MOTOR CORPORATION.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
18 * @file ns_xml_writer.h
19 * @brief \~english This file contains declaration of class CXMLWriter.
21 /** @addtogroup BaseSystem
24 /** @addtogroup native_service
28 /** @addtogroup framework_unified
29 * @ingroup native_service
33 ////////////////////////////////////////////////////////////////////////////////////////////////////
34 /// \ingroup tag_NS_ConfigParser
35 /// \brief This file contains declaration of class CXMLWriter.
37 ////////////////////////////////////////////////////////////////////////////////////////////////////
39 #ifndef __FRAMEWORKUNIFIED_NATIVESERVICES_NSCONFIGPARSER_INC_NS_XML_WRITER_H__ // NOLINT (build/header_guard)
40 #define __FRAMEWORKUNIFIED_NATIVESERVICES_NSCONFIGPARSER_INC_NS_XML_WRITER_H__
42 ////////////////////////////////////////////////////////////////////////////////////////////////////
44 ////////////////////////////////////////////////////////////////////////////////////////////////////
45 #include <libxml/tree.h>
47 #include <native_service/frameworkunified_types.h>
48 #include <native_service/ns_writer.h>
54 * \~english @brief this file has the CXMLWriter class definitions
55 * \~english @par Brief Introduction
56 * This class provides functionalities to write to XML config file
59 class CXMLWriter: public IConfigWriter {
61 ////////////////////////////////////////////////////////////////////////////////
62 /// \ingroup CXMLWriter
63 /// \~english @par Brief
64 /// Parameterless Constructor of CXMLWriter class
65 /// \~english @param None
66 /// \~english @retval None
67 /// \~english @par Prerequisite
68 /// - Load the shared library first
69 /// \~english @par Inside state change
70 /// - The API no inside state change
71 /// \~english @par None
72 /// \~english @par Classification
74 /// \~english @par Type
76 /// \~english @par Detail
77 /// This API should be called by ServiceA and create a new object without file path of CXMLWriter
78 /// \~english @see GetCXMLWriterObjectNoParam
79 ////////////////////////////////////////////////////////////////////////////////
82 ////////////////////////////////////////////////////////////////////////////////
83 /// \ingroup CXMLWriter
84 /// \~english @par Brief
85 /// Constructor of CXMLWriter class
86 /// \~english @param [IN] f_cFilePath
87 /// std::string - Full path of the configuration file
88 /// \~english @retval None
89 /// \~english @par Prerequisite
90 /// - Load the shared library first
91 /// \~english @par Inside state change
92 /// - The API no inside state change
93 /// \~english @par None
94 /// \~english @par Classification
96 /// \~english @par Type
98 /// \~english @par Detail
99 /// This API should be called by ServiceA and create a new object with file path of CXMLWriter
100 /// \~english @see GetCXMLWriterObject
101 ////////////////////////////////////////////////////////////////////////////////
102 CXMLWriter(const std::string &f_cFilePath); // NOLINT (readability/nolint)
104 ////////////////////////////////////////////////////////////////////////////////////////////////
105 /// \ingroup ~CXMLWriter
106 /// \~english @par CXMLWriter
107 /// Destructor of CXMLWriter class.
108 /// \~english @param None
109 /// \~english @retval none
110 /// \~english @par Preconditons
112 /// \~english @par Change of internal status
114 /// \~english @par Conditions of processing failure
116 /// \~english @par Detail
117 /// Destruct the object of CXMLWriter
118 /// \~english @par Classification
120 /// \~english @par Type
122 /// \~english @see CXMLWriter
123 ////////////////////////////////////////////////////////////////////////////////////////////////
126 ////////////////////////////////////////////////////////////////////////////////
127 /// \ingroup ParseFile
128 /// \~english @par Brief
130 /// \~english @param [IN] f_cFilePath
131 /// std::string - path of file to parse
132 /// \~english @retval eFrameworkunifiedStatusOK Success
133 /// \~english @retval eFrameworkunifiedStatusNullPointer Null pointer
134 /// \~english @par Prerequisite
135 /// - Load the shared library first
136 /// - Create CXMLWriter object
137 /// \~english @par Inside state change
138 /// - The API no inside state change
139 /// \~english @par None
140 /// \~english @par Classification
142 /// \~english @par Type
144 /// \~english @par Detail
145 /// This function is used to parse the file
146 /// \~english @see CXMLWriter
147 ////////////////////////////////////////////////////////////////////////////////
149 EFrameworkunifiedStatus ParseFile(const std::string &f_cFilePath);
151 ////////////////////////////////////////////////////////////////////////////////
152 /// \ingroup SetValue
153 /// \~english @par Brief
154 /// Set vaule for key
155 /// \~english @param [IN] f_cKey
156 /// std::string - key to search
157 /// \~english @param [IN] f_cValue
158 /// std::string - value to set
159 /// \~english @retval eFrameworkunifiedStatusOK Success / Pass / OK
160 /// \~english @retval eFrameworkunifiedStatusFail Failed
161 /// \~english @retval eFrameworkunifiedStatusInvldParam Invalid parameter
162 /// \~english @retval eFrameworkunifiedStatusNullPointer Null pointer
163 /// \~english @par Prerequisite
164 /// - Load the shared library first
165 /// - Create CXMLWriter object
166 /// - ParseFile set the path
167 /// \~english @par Inside state change
168 /// - The API no inside state change
169 /// \~english @par None
170 /// \~english @par Classification
172 /// \~english @par Type
174 /// \~english @par Detail
175 /// This function is used to set the value for the key
176 /// \~english @see CXMLWriter,ParseFile
177 ////////////////////////////////////////////////////////////////////////////////
179 EFrameworkunifiedStatus SetValue(const std::string &f_cKey, std::string f_cValue);
180 ////////////////////////////////////////////////////////////////////////////////
181 /// \ingroup SaveData
182 /// \~english @par Brief
183 /// Save changed data
184 /// \~english @param None
185 /// \~english @retval eFrameworkunifiedStatusOK Success / Pass / OK
186 /// \~english @retval eFrameworkunifiedStatusFail Failed
187 /// \~english @par Prerequisite
188 /// - Load the shared library first
189 /// - Create CXMLWriter object
190 /// - ParseFile set the path
191 /// - Change the data
192 /// \~english @par Inside state change
193 /// - The API no inside state change
194 /// \~english @par None
195 /// \~english @par Classification
197 /// \~english @par Type
199 /// \~english @par Detail
200 /// This function is used to save the changed value to the xml config file
201 /// \~english @see GetCXMLWriterObjectNoParam
202 ////////////////////////////////////////////////////////////////////////////////
204 EFrameworkunifiedStatus SaveData();
205 ////////////////////////////////////////////////////////////////////////////////
207 /// \~english @par Brief
209 /// \~english @param [IN] f_cPath
210 /// std::string - Path of file
211 /// \~english @retval eFrameworkunifiedStatusOK Success / Pass / OK
212 /// \~english @retval eFrameworkunifiedStatusInvldParam Invalid parameter
213 /// \~english @par Prerequisite
214 /// - Load the shared library first
215 /// - Create CXMLWriter object
216 /// \~english @par Inside state change
217 /// - The API no inside state change
218 /// \~english @par None
219 /// \~english @par Classification
221 /// \~english @par Type
223 /// \~english @par Detail
224 /// This function is used to set the config file path
225 /// \~english @see GetCXMLWriterObjectNoParam
226 ////////////////////////////////////////////////////////////////////////////////
228 EFrameworkunifiedStatus SetPath(const std::string &f_cPath);
229 ////////////////////////////////////////////////////////////////////////////////
230 /// \ingroup SetDataPtr
231 /// \~english @par Brief
233 /// \~english @param [IN] f_pData
234 /// PVOID - Pointer to data structure
235 /// \~english @retval VOID
236 /// \~english @par Prerequisite
237 /// - Load the shared library first
238 /// - Create CXMLWriter object
239 /// \~english @par Inside state change
240 /// - The API no inside state change
241 /// \~english @par None
242 /// \~english @par Classification
244 /// \~english @par Type
246 /// \~english @par Detail
247 /// This function is used to set the data pointer in config writer class
248 /// \~english @see CXMLWriter
249 ////////////////////////////////////////////////////////////////////////////////
251 VOID SetDataPtr(PVOID f_pData);
254 ////////////////////////////////////////////////////////////////////////////////////////////////
256 /// This function is used to parse the value from xml file
258 /// \param [IN] f_pCurrNode
259 /// xmlNodePtr - pointer to current node in xml
260 /// \param [IN] f_cUserKey
261 /// std::string - Key to be searched for
262 /// \param [IN] f_cValue
263 /// std::string - Required Value for key
264 /// \param [IN] f_bKeyFound
265 /// std::string - Flag to check whether key is present in xml file
267 /// \return EFrameworkunifiedStatus- success or failure
269 ////////////////////////////////////////////////////////////////////////////////////////////////
270 EFrameworkunifiedStatus XMLSetValue(xmlNodePtr f_pCurrNode,
271 const std::string &f_cUserKey, // NOLINT (readability/nolint)
272 std::string &f_cValue, // NOLINT (readability/nolint)
273 BOOL &f_bKeyFound); // NOLINT (readability/nolint)
275 // pointer of xml document structure(DOM)
278 // path of config file
279 std::string m_cFilePath;
285 ////////////////////////////////////////////////////////////////////////////////
286 /// \ingroup GetCXMLWriterObject
287 /// \~english @par Brief
288 /// Get CXMLWriter object.
289 /// \~english @param [IN] f_cFilePath
290 /// std::string - path of file to parse
291 /// \~english @retval CXMLWriter *
292 /// \~english @par Prerequisite
293 /// - Load the shared library first.
294 /// \~english @par Inside state change
295 /// - The API no inside state change
296 /// \~english @par None
297 /// \~english @par Classification
299 /// \~english @par Type
301 /// \~english @par Detail
302 /// This API is used to create CXMLWriter object with file path and return the CXMLWriter pointer.
303 /// \~english @see None
304 ////////////////////////////////////////////////////////////////////////////////
305 CXMLWriter *GetCXMLWriterObject(CHAR *f_cFilePath);
307 ////////////////////////////////////////////////////////////////////////////////
308 /// \ingroup GetCXMLWriterObjectNoParam
309 /// \~english @par Brief
310 /// Get CXMLWriter object.
311 /// \~english @param None
312 /// \~english @retval CXMLWriter *
313 /// \~english @par Prerequisite
314 /// - Load the shared library first.
315 /// \~english @par Inside state change
316 /// - The API no inside state change
317 /// \~english @par None
318 /// \~english @par Classification
320 /// \~english @par Type
322 /// \~english @par Detail
323 /// This API is used to create CXMLWriter object without file path and return the CXMLWriter pointer.
324 /// \~english @see None
325 ////////////////////////////////////////////////////////////////////////////////
327 CXMLWriter *GetCXMLWriterObjectNoParam();
332 #endif /* __FRAMEWORKUNIFIED_NATIVESERVICES_NSCONFIGPARSER_INC_NS_XML_WRITER_H__ */ // NOLINT (build/header_guard)