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.
17 ////////////////////////////////////////////////////////////////////////////////////////////////////
18 /// \ingroup tag_NS_ConfigParser
19 /// \brief This file contains implementation of CCFGReader class.
21 ////////////////////////////////////////////////////////////////////////////////////////////////////
23 ////////////////////////////////////////////////////////////////////////////////////////////////////
25 ////////////////////////////////////////////////////////////////////////////////////////////////////
26 #include <ns_cfg_reader.h>
27 #include <ns_cfg_parser.h>
28 #include <ns_config_parser_frameworkunifiedlog.h>
33 CCFGReader::CCFGReader(): m_cFilePath(""), m_pCFGParser(NULL) { // LCOV_EXCL_BR_LINE 11:except branch
36 // LCOV_EXCL_START 200:CCFGReader is not external API class, this constructed function isn't used by other function
37 CCFGReader::CCFGReader(const std::string &f_c_filepath): m_cFilePath(f_c_filepath), m_pCFGParser(NULL) {
38 AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert
39 FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "File Path %s", m_cFilePath.c_str());
41 m_pCFGParser = new CCFGParser(m_cFilePath);
43 if (NULL == m_pCFGParser) {
44 FRAMEWORKUNIFIEDLOG(ZONE_NS_ERR, __FUNCTION__, "Memory allocation error for m_pCFGParser");
49 EFrameworkunifiedStatus CCFGReader::ParseFile(const std::string &f_c_filepath) {
50 EFrameworkunifiedStatus l_e_status = eFrameworkunifiedStatusOK;
51 FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+");
53 // FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__, "File Path %s", f_c_filepath.c_str());
55 m_cFilePath.assign(f_c_filepath);
57 m_pCFGParser = new(std::nothrow) CCFGParser(); // LCOV_EXCL_BR_LINE 11:except branch
59 if (NULL == m_pCFGParser) { // LCOV_EXCL_BR_LINE 5:new's error case
60 // LCOV_EXCL_START 5:new's error case
61 AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert
62 FRAMEWORKUNIFIEDLOG(ZONE_NS_ERR, __FUNCTION__, "Memory allocation error for m_pCFGParser");
63 l_e_status = eFrameworkunifiedStatusNullPointer;
66 l_e_status = m_pCFGParser->CFGParseFile(f_c_filepath);
69 FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-");
73 CCFGReader::~CCFGReader() {
74 if (NULL != m_pCFGParser) {
80 PVOID CCFGReader::GetDataPtr() {
84 std::string CCFGReader::GetValue(const std::string &f_c_key) {
85 std::string l_cValue = "";
87 if (NULL != m_pCFGParser && !f_c_key.empty()) { // LCOV_EXCL_BR_LINE 11:except branch
88 // read the data from internal CFG structure
89 l_cValue = m_pCFGParser->CFGGetData(f_c_key); // LCOV_EXCL_BR_LINE 11:except branch
95 EFrameworkunifiedStatus CCFGReader::GetValue(const std::string &f_c_key, std::string &f_c_value) {
96 FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+");
97 EFrameworkunifiedStatus l_e_status = eFrameworkunifiedStatusOK;
99 if (NULL == m_pCFGParser) { // LCOV_EXCL_BR_LINE 5:m_pCFGParser cannot be NULL, because internal logic guarantee
100 // LCOV_EXCL_START 5:m_pCFGParser cannot be NULL, because internal logic guarantee
101 AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert
102 l_e_status = eFrameworkunifiedStatusNullPointer;
103 FRAMEWORKUNIFIEDLOG(ZONE_NS_ERR, __FUNCTION__, "Parser object(m_pCFGParser) is NULL");
105 } else if (f_c_key.empty()) {
106 l_e_status = eFrameworkunifiedStatusInvldParam;
107 // LCOV_EXCL_BR_START 15:marco defined in "native_service/ns_logger_if.h"
108 FRAMEWORKUNIFIEDLOG(ZONE_NS_ERR, __FUNCTION__, "Invalid Key");
111 // read the data from internal CFG structure
112 l_e_status = m_pCFGParser->CFGGetData(f_c_key, f_c_value);
115 FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-");