Add gitlab issue/merge request templates
[staging/basesystem.git] / service / native / framework_unified / client / NS_ConfigParser / src / ns_config_reader_writer.cpp
1 /*
2  * @copyright Copyright (c) 2016-2020 TOYOTA MOTOR CORPORATION.
3  *
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
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  */
16
17 ////////////////////////////////////////////////////////////////////////////////////////////////////
18 /// \ingroup  tag_NS_ConfigParser
19 /// \brief    This file contains implementation of CNSConfigParser class.
20 ///
21 ////////////////////////////////////////////////////////////////////////////////////////////////////
22
23 ////////////////////////////////////////////////////////////////////////////////////////////////////
24 // Include Files
25 ////////////////////////////////////////////////////////////////////////////////////////////////////
26 #include <native_service/ns_config_parser_if.h>
27 #include <string>
28 #include "ns_config_parser_frameworkunifiedlog.h"
29
30 CNSConfigParser::CNSConfigParser() : CNSConfigReader(), CNSConfigWriter() {  // LCOV_EXCL_BR_LINE 11:except branch
31 }
32
33 CNSConfigParser::CNSConfigParser(const std::string &f_c_filepath): CNSConfigReader(f_c_filepath),
34   CNSConfigWriter(f_c_filepath, TRUE) {  // LCOV_EXCL_BR_LINE 11:except branch
35   FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "File Path %s", f_c_filepath.c_str());
36
37   // get the data pointer from the config reader
38   PVOID l_pdata = GetDataPtr();  // LCOV_EXCL_BR_LINE 11:except branch
39
40   // set the same data pointer in config writer
41   SetDataPtr(l_pdata);  // LCOV_EXCL_BR_LINE 11:except branch
42 }
43
44 CNSConfigParser::~CNSConfigParser() {  // LCOV_EXCL_BR_LINE 11:except branch
45   FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "Destructor");
46
47   // set the data pointer to NULL in writer
48   SetDataPtr(NULL);  // LCOV_EXCL_BR_LINE 11:except branch
49 }
50
51 EFrameworkunifiedStatus CNSConfigParser::Parse(const std::string &f_c_filepath) {
52   EFrameworkunifiedStatus l_e_status = eFrameworkunifiedStatusOK;
53   FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+");
54
55   // FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__, "File Path %s", f_c_filepath.c_str());
56
57   // parse and create config document structure with reader
58   if (eFrameworkunifiedStatusOK == (l_e_status = CNSConfigReader::Parse(f_c_filepath))) {
59     // set the data pointer to NULL in writer
60     SetDataPtr(NULL);
61
62     // sets the same config document structure in writer
63     if (eFrameworkunifiedStatusOK == (l_e_status = CNSConfigWriter::Create(f_c_filepath))) {
64       // get the data pointer from the config reader
65       PVOID l_pdata = GetDataPtr();
66
67       // set the same data pointer in config writer
68       SetDataPtr(l_pdata);
69     }
70   }
71
72   FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-");
73   return l_e_status;
74 }