Init basesystem source codes.
[staging/basesystem.git] / video_in_hal / nsframework / framework_unified / client / include / native_service / ns_xml_reader.h
1 /**
2  * @file ns_xml_reader.h
3  * @brief \~english This file contains declaration of class CXMLReader.
4  *
5  */
6 /** @addtogroup BaseSystem
7  *  @{
8  */
9 /** @addtogroup native_service
10  *  @ingroup BaseSystem
11  *  @{
12  */
13 /** @addtogroup framework_unified
14  *  @ingroup native_service
15  *  @{
16  */
17
18 /*
19  * @copyright Copyright (c) 2016-2020 TOYOTA MOTOR CORPORATION.
20  *
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
24  *
25  *      http://www.apache.org/licenses/LICENSE-2.0
26  *
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.
32  */
33
34 ////////////////////////////////////////////////////////////////////////////////////////////////////
35 /// \ingroup  tag_NS_ConfigParser
36 /// \brief    This file contains declaration of class CXMLReader.
37 ///
38 ////////////////////////////////////////////////////////////////////////////////////////////////////
39
40 #ifndef __FRAMEWORKUNIFIED_NATIVESERVICES_NSCONFIGPARSER_INC_NS_XML_READER_H__  // NOLINT  (build/header_guard)
41 #define __FRAMEWORKUNIFIED_NATIVESERVICES_NSCONFIGPARSER_INC_NS_XML_READER_H__
42
43 ////////////////////////////////////////////////////////////////////////////////////////////////////
44 // Include Files
45 ////////////////////////////////////////////////////////////////////////////////////////////////////
46 #include <libxml/tree.h>
47 #include <native_service/frameworkunified_types.h>
48 #include <native_service/ns_reader.h>
49 #include <string>
50
51
52 /**
53  * @class CXMLReader
54  * \~english @par   Brief Introduction
55  *        This class provides functionalities to read from XML config file.
56  *
57  */
58 class CXMLReader: public IConfigReader {
59  public:
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
72   ///       Public
73   /// \~english @par Type
74   ///       Sync
75   /// \~english @par Detail
76   ///       This API should be called by ServiceA and create a new object of CXMLReader.
77   /// \~english @see None
78   ////////////////////////////////////////////////////////////////////////////////
79   CXMLReader();
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
93   ///       Public
94   /// \~english @par Type
95   ///       Sync
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   ////////////////////////////////////////////////////////////////////////////////
100
101   CXMLReader(const std::string &f_cFilePath);  // NOLINT  (readability/nolint)
102
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
110   ///           - None
111   /// \~english @par Change of internal status
112   ///           - Close shared memory object.
113   /// \~english @par Conditions of processing failure
114   ///           -None
115   /// \~english @par Detail
116   ///           Destruct the object of CXMLReader
117   /// \~english @par Classification
118   ///           - Public
119   /// \~english @par Type
120   ///           - sync only
121   /// \~english @see CXMLReader
122   ////////////////////////////////////////////////////////////////////////////////////////////////
123   ~CXMLReader();
124
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
140   ///       Public
141   /// \~english @par Type
142   ///       Sync
143   /// \~english @par Detail
144   ///       This API is used to parse the file from the path.
145   /// \~english @see CXMLReader or GetCXMLReaderObject
146   ////////////////////////////////////////////////////////////////////////////////
147
148   EFrameworkunifiedStatus ParseFile(const std::string &f_cFilePath);
149
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
164   ///       Public
165   /// \~english @par Type
166   ///       Sync
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
191   ///       Public
192   /// \~english @par Type
193   ///       Sync
194   /// \~english @par Detail
195   ///       This function is used to get the value associated with the key
196   /// \~english @see CXMLReader or GetCXMLReaderObject
197   ////////////////////////////////////////////////////////////////////////////////
198
199
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
214   ///       Public
215   /// \~english @par Type
216   ///       Sync
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   ////////////////////////////////////////////////////////////////////////////////
221   PVOID GetDataPtr();
222
223  private:
224   ////////////////////////////////////////////////////////////////////////////////////////////////
225   /// XMLGetValue
226   /// This function is used to parse and get the value from xml file
227   ///
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
232   ///
233   /// \return std::string - content of key node
234   ///
235   ////////////////////////////////////////////////////////////////////////////////////////////////
236   std::string XMLGetValue(xmlNodePtr f_pCurrNode, const std::string &f_cUserKey);
237
238   ////////////////////////////////////////////////////////////////////////////////////////////////
239   /// XMLGetValue
240   /// This function is used to parse and get the value from xml file
241   ///
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
250   ///
251   /// \return EFrameworkunifiedStatus - error if key not found or else eFrameworkunifiedStatusOK
252   ///
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)
257   xmlDocPtr m_pXmlDoc;
258 };
259
260 #ifdef __cplusplus
261 extern "C" {
262 #endif
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
276   ///       Public
277   /// \~english @par Type
278   ///       Sync
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);
284 #ifdef __cplusplus
285 }
286 #endif
287 #endif /* __FRAMEWORKUNIFIED_NATIVESERVICES_NSCONFIGPARSER_INC_NS_XML_READER_H__ */  // NOLINT  (build/header_guard)
288 /** @}*/
289 /** @}*/
290 /** @}*/
291 /** @}*/