diff options
author | Tadao Tanikawa <tanikawa.tadao@jp.panasonic.com> | 2020-11-20 23:36:23 +0900 |
---|---|---|
committer | Tadao Tanikawa <tanikawa.tadao@jp.panasonic.com> | 2020-11-22 09:02:55 +0900 |
commit | 17cf21bcf8a2e29d2cbcf0a313474d2a4ee44f5d (patch) | |
tree | 582a9768558d9eaf261ca5df6136e9de54c95816 /nsframework/framework_unified/client/NS_ConfigParser/src | |
parent | 9e86046cdb356913ae026f616e5bf17f6f238aa5 (diff) |
Re-organized sub-directory by category
Since all the sub-directories were placed in the
first level, created sub-directories, "hal", "module",
and "service" for classification and relocated each component.
Signed-off-by: Tadao Tanikawa <tanikawa.tadao@jp.panasonic.com>
Change-Id: Ifdf743ac0d1893bd8e445455cf0d2c199a011d5c
Diffstat (limited to 'nsframework/framework_unified/client/NS_ConfigParser/src')
9 files changed, 0 insertions, 1543 deletions
diff --git a/nsframework/framework_unified/client/NS_ConfigParser/src/makefile_PosixBasedOS001 b/nsframework/framework_unified/client/NS_ConfigParser/src/makefile_PosixBasedOS001 deleted file mode 100755 index 1e6e556..0000000 --- a/nsframework/framework_unified/client/NS_ConfigParser/src/makefile_PosixBasedOS001 +++ /dev/null @@ -1,207 +0,0 @@ -# -# @copyright Copyright (c) 2016-2020 TOYOTA MOTOR CORPORATION. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# - -# -# Standard Module Makefile version 2.0 -# - -# Name of the componet (team/domain prefix '_' component name) -COMPONENT_NAME = NS_ConfigParser - -ifndef PRJ_ROOT -export PRJ_ROOT = $(CURDIR)/../ -endif -include $(PRJ_ROOT)cfg/depends.mk - -# Name of the componet (team/domain prefix '_' component name) -# This must be the same as the RTC Component name and Eclipse Project Name -COMPONENT_NAME = NS_ConfigParser - - -# Additive Compile Flags (Flags from initiating make process will still apply) -DEFS += - -# Set local includes and then the reference includes (priority order determines search path) -# Default pattern are any configuration includes (which would be things like PosixBasedOS001), local (Team) component directories, -# dependencies includes (other teams) -# Local (current component references should be in the form of -# $(CC_IFLAG)$(TEAM_ROOT)$(COMPONENT_NAME)/directory -# Example your public include directory would be -# $(CC_IFLAG)$(TEAM_ROOT)$(COMPONENT_NAME)/inc -# Team references should only be to other's public includes such as -# $(CC_IFLAG)$(TEAM_ROOT)NS_MessageCenter/inc -# Global (non-team) references should be only to other's public includes such -# these are found in the depends include file and captured in the (DEPENDS_INCLUDES) variable -INCLUDES = \ - $(CFG_INCS) \ - $(CC_IFLAG)./ \ - $(DEPENDS_INCLUDES) \ - $(CC_IFLAG)$(TEAM_ROOT)$(COMPONENT_NAME)/inc \ - $(CC_IFLAG)$(TEAM_ROOT)NS_XMLConfigParser/inc - -# Do the same if you need to include library paths as well -# Do an incremental in case additional library paths are defined -# at the top-level make. Use similar guidelines as for includes -# for example to include a team component library it would be -# $(TEAM_ROOT)NS_MessageCenter/lib/NS_MessageCenter/ -LIB_PATHS += \ - $(DEPENDS_LIB_PATHS) \ - - - -# Define binary outputs. These can be libraries or executables. -# Name a variable for each deliverable. Suffixes should be -# EXEC - For Executables -> output to the bin directory -#TIME_EXEC = $(BIN_PATH)time -# LIB - For Static Libraries -> output to lib directory with specific naming -#MATH_LIB = $(LIB_PATH)$(LIB_PREFIX)math.$(LIB_EXT) -# SLIB - For Shared Objects -#FRMWRK_SLIB = $(SLIB_PATH)frmwrk.$(SO_EXT) -# LIB - Define the static library for Message Queue -# -# -ifdef DYNAMIC - COMPONENT_LIB = $(SLIB_PATH)$(LIB_PREFIX)$(COMPONENT_NAME)$(DEBUG_EXT).$(SO_EXT) -else - COMPONENT_LIB = $(LIB_PATH)$(LIB_PREFIX)$(COMPONENT_NAME)$(DEBUG_EXT).$(LIB_EXT) -endif - - -## Sources Section - -# Define Library & Executable Sources (on a per deliverable basis) -# This includes sources located in subdirectories. - -# Define generic line that pulls all c, cc, cpp files -# since your in the src folder is pull only files from there -COMPONENT_SRCS = \ - $(wildcard *.c) \ - $(wildcard *.cpp) - -# Define sources that my not be local to your component -# here, you can define indivial files or wildcard from -# a different folder. -NON_LOCAL_SRCS = \ - - -# List of all sources to be built. Can be assembled from the other defintitions. -# This only defines sources for the current directory, so if there are subdirectories -# those are not included. (Those are found in simple subdirectory makefiles that only -# direct the building of sources, but no linking into a binary) -SOURCES = \ - $(COMPONENT_SRCS) \ - $(NON_LOCAL_SRCS) \ - - - -# -# Convert the source files to object files with correct folder location. -# -# -C_LANG_OBJECTS = $(addprefix $(BLD_PATH),$(addsuffix .$(OBJ_EXT),$(basename $(filter %.c ,$(SOURCES) ) ) ) ) -CPP_LANG_OBJECTS = $(addprefix $(BLD_PATH),$(addsuffix .$(OBJ_EXT),$(basename $(filter %.cpp %.cc %.cxx,$(SOURCES) ) ) ) ) - - -# List of all sources to be generated. Can be assembled from the other defintitions. -OBJECTS = \ - $(C_LANG_OBJECTS) \ - $(CPP_LANG_OBJECTS) - - - -# All headers that are dependencies. Wildcard is easy to pickup local headers. -# This is only to automate the rebuilding, all builds on the servers are cleans -# So this is not a huge deal when building on a component level. -HEADERS = \ - $(wildcard *.h) \ - $(wildcard $(TEAM_ROOT)$(COMPONENT_NAME)/inc/*.h) \ - $(wildcard $(TEAM_ROOT)NativeServices/inc/*.h) \ - $(wildcard $(TEAM_ROOT)NativeServices/inc/native/*.h) \ - - -LIBRARIES = \ - $(COMPONENT_LIB) \ - -#DYNAMIC_LIBS += \ -# xml2 \ -# m - -# Make targets -# Standard -all: banner module_dirs subdirs local library binary - -debug: - $(MAKE) TARGET=arm DEBUG=TRUE all - -base: banner module_dirs subdirs local - -# Standard Building of Source Files (Default builds for all objects defined above) -$(C_LANG_OBJECTS): $(SOURCES) $(HEADERS) - $(CC_CMD) - -$(CPP_LANG_OBJECTS): $(SOURCES) $(HEADERS) - $(CPP_CMD) - -local: $(OBJECTS) - -# Defines specific for each deliverable - -# For a static library -$(COMPONENT_LIB): $(OBJECTS) -ifdef DYNAMIC -# For a dynamic library - $(SLIB_CMD) - $(HIDE_ECHO_FLAG)$(OBJCPY) --only-keep-debug $(@) $(@).debug - $(HIDE_ECHO_FLAG)$(OBJCPY) --strip-all $(@) - $(HIDE_ECHO_FLAG)$(OBJCPY) --add-gnu-debuglink=$(@).debug $(@) -else -# For a static library - $(AR_CMD) -endif - -# Standard set of derived targets -library: base \ - $(LIBRARIES) - @echo "***** `date` Done building library: $(COMPONENT_NAME) ******" - -binary: base \ - $(BINARIES) - -# Subdirs should be to jump to subdirectories -# standard form is of -# $(MAKE) -C subdirectory_name $(MAKECMDGOALS) -subdirs: - -clean: - -rm -f $(BINARIES) - -rm -f $(LIBRARIES) - -rm -f $(OBJECTS) - -rm -f $(COMPONENT_LIB).map - -rm -f $(COMPONENT_LIB).debug - --v: - @echo "objs: --> $(OBJECTS)" - @echo "sources: --> $(SOURCES)" - @echo "headers: --> $(HEADERS)" - @echo "includes: --> $(INCLUDES)" - @echo "lib paths: --> $(LIB_PATHS)" - @echo "static libs: --> $(LD_STATIC_LIBS)" - @echo "dynamic libs: --> $(LD_DYNAMIC_LIBS)" - @echo "lib: --> $(LIBRARIES)" - @echo "bin: --> $(BINARIES)" - -module_dirs: build_dirs - diff --git a/nsframework/framework_unified/client/NS_ConfigParser/src/ns_cfg_parser.cpp b/nsframework/framework_unified/client/NS_ConfigParser/src/ns_cfg_parser.cpp deleted file mode 100755 index a2abd78..0000000 --- a/nsframework/framework_unified/client/NS_ConfigParser/src/ns_cfg_parser.cpp +++ /dev/null @@ -1,365 +0,0 @@ -/* - * @copyright Copyright (c) 2016-2020 TOYOTA MOTOR CORPORATION. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -//////////////////////////////////////////////////////////////////////////////////////////////////// -/// \ingroup tag_NS_ConfigParser -/// \brief This file contains implementation of CCFGParser class. -/// -//////////////////////////////////////////////////////////////////////////////////////////////////// - -//////////////////////////////////////////////////////////////////////////////////////////////////// -// Include Files -//////////////////////////////////////////////////////////////////////////////////////////////////// - -#include <ns_cfg_internal.h> -#include <ns_cfg_parser.h> -#include <ns_config_parser_frameworkunifiedlog.h> - -#include <fstream> -#include <string> - -CCFGParser::CCFGParser() - : m_pmCFGData(NULL) { -} - -// LCOV_EXCL_START 200:CCFGParser is not external API class, this constructed function isn't used by other function -CCFGParser::CCFGParser(const std::string &f_cfilepath) - : m_pmCFGData(NULL) { - AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert - CFGParseFile(f_cfilepath); -} -// LCOV_EXCL_STOP - -CCFGParser::~CCFGParser() { - CFGData_Type::iterator l_itCfgStructure; - - if (NULL != m_pmCFGData) { // LCOV_EXCL_BR_LINE 5:m_pmCFGData cannot be NULL, because internal logic guarantee - // release the structure - for (l_itCfgStructure = m_pmCFGData->begin(); - l_itCfgStructure != m_pmCFGData->end(); - l_itCfgStructure++) { - CBlock *l_pBlock = (*l_itCfgStructure).second; - if (NULL != l_pBlock) { // LCOV_EXCL_BR_LINE 5:l_pBlock cannot be NULL, because map insert data success. - // clear the vector - l_pBlock->m_vElementPair.clear(); - - delete l_pBlock; // LCOV_EXCL_BR_LINE 11:except branch - l_pBlock = NULL; - } - } - - delete m_pmCFGData; // LCOV_EXCL_BR_LINE 11:except branch - m_pmCFGData = NULL; - } -} - -EFrameworkunifiedStatus CCFGParser::CFGParseFile(const std::string &f_cfilepath) { - EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK; - - size_t l_uiPos = 0; - std::string l_cLine(""); - std::string l_cTag(""); // LCOV_EXCL_BR_LINE 11:except branch - std::string l_cComment(""); // LCOV_EXCL_BR_LINE 11:except branch - - m_pmCFGData = new(std::nothrow) CFGData_Type(); // LCOV_EXCL_BR_LINE 11:except branch - - if (NULL != m_pmCFGData) { // LCOV_EXCL_BR_LINE 5:new's error case - // open the file - std::ifstream l_objFile(f_cfilepath.c_str()); // LCOV_EXCL_BR_LINE 11:except branch - - // check if file is opened - if (l_objFile.is_open()) { - CBlock *l_pBlock = NULL; - - // read until end of file is not reached or any other stream error occurred - while (!l_objFile.eof()) { - // read the line from the file - getline(l_objFile, l_cLine); // LCOV_EXCL_BR_LINE 11:except branch - - // if line is a comment - if ('#' == l_cLine[0] || ';' == l_cLine[0]) { - if (!l_cComment.empty()) { - l_cComment.append("\n"); // LCOV_EXCL_BR_LINE 11:except branch - } - l_cComment.append(l_cLine); - } else if ('[' == l_cLine[0]) { // if line is main tag - // creates new CBlock object, - // each block contains information of single like all its key-value pair and - // all the comments associated with it. - l_pBlock = new CBlock(); // LCOV_EXCL_BR_LINE 11:except branch - if (NULL != l_pBlock) { // LCOV_EXCL_BR_LINE 5:new's error case - // set the tag comment - l_pBlock->m_cComment = l_cComment; - l_cComment.clear(); - - if (std::string::npos != (l_uiPos = l_cLine.find(']'))) { - // set the tag - l_cTag = l_cLine.substr(1, l_uiPos - 1); // LCOV_EXCL_BR_LINE 11:except branch - - // insert the block with its tag name in structure(map) - m_pmCFGData->insert(make_pair(l_cTag, l_pBlock)); // NOLINT (readability/nolint) - } else { - delete l_pBlock; // LCOV_EXCL_BR_LINE 11:except branch - l_pBlock = NULL; - - // LCOV_EXCL_BR_START 15:marco defined in "native_service/ns_logger_if.h" - FRAMEWORKUNIFIEDLOG(ZONE_NS_ERR, __FUNCTION__, "End Tag missing"); - // LCOV_EXCL_BR_STOP - l_eStatus = eFrameworkunifiedStatusErrOther; - break; - } - } else { - // LCOV_EXCL_START 5:new's error case - AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert - FRAMEWORKUNIFIEDLOG(ZONE_NS_ERR, __FUNCTION__, "Error allocating memory for l_pBlock"); - l_eStatus = eFrameworkunifiedStatusNullPointer; - break; - // LCOV_EXCL_STOP - } - } else if (std::string::npos != (l_uiPos = l_cLine.find('='))) { // LCOV_EXCL_BR_LINE 11:except branch - if (NULL != l_pBlock) { // LCOV_EXCL_BR_LINE 5:new's error case - // create new node object, - // each node object contains the information of singlr key-value pair and - /// it's comment(if any) - // LCOV_EXCL_BR_START 11:except branch - CNode l_objNode; - l_objNode.m_cComment.append(l_cComment); - l_objNode.m_cTag = l_cLine.substr(0, l_uiPos); - l_objNode.m_cValue = l_cLine.substr(l_uiPos + 1); - - // insert the node object in block - l_pBlock->m_vElementPair.push_back(l_objNode); - // LCOV_EXCL_BR_STOP - - l_cComment.clear(); - } else { - // LCOV_EXCL_BR_START 15:marco defined in "native_service/ns_logger_if.h" - FRAMEWORKUNIFIEDLOG(ZONE_NS_ERR, __FUNCTION__, "l_pBlock is NULL"); - // LCOV_EXCL_BR_STOP - l_eStatus = eFrameworkunifiedStatusNullPointer; - break; - } - } - } - - // last comment - if (!l_cComment.empty()) { - m_cLastComment = l_cComment; - } else { - m_cLastComment.clear(); - } - - // close the file - l_objFile.close(); // LCOV_EXCL_BR_LINE 11:except branch - } else { - l_eStatus = eFrameworkunifiedStatusFail; - // LCOV_EXCL_BR_START 15:marco defined in "native_service/ns_logger_if.h" - FRAMEWORKUNIFIEDLOG(ZONE_NS_ERR, __FUNCTION__, "Error Opening File"); - // LCOV_EXCL_BR_STOP - } - } else { - // LCOV_EXCL_START 5:new's error case - AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert - FRAMEWORKUNIFIEDLOG(ZONE_NS_ERR, __FUNCTION__, "m_pmCFGData is NULL"); - l_eStatus = eFrameworkunifiedStatusNullPointer; - // LCOV_EXCL_STOP - } - - return l_eStatus; -} - -std::string CCFGParser::CFGGetData(const std::string &f_ckey) { - CFGData_Type::iterator l_itCfgStructure; - std::string l_cHeadTag = ""; - std::string l_cTag = ""; // LCOV_EXCL_BR_LINE 11:except branch - std::string l_cValue = ""; // LCOV_EXCL_BR_LINE 11:except branch - - size_t l_uiPos = 0; - - if (NULL != m_pmCFGData && !f_ckey.empty()) { // LCOV_EXCL_BR_LINE 5:new's error case(in function CFGParseFile) - if (std::string::npos != (l_uiPos = f_ckey.find('.'))) { // LCOV_EXCL_BR_LINE 11:except branch - l_cHeadTag = f_ckey.substr(0, l_uiPos); // LCOV_EXCL_BR_LINE 11:except branch - l_cTag = f_ckey.substr(l_uiPos + 1); // LCOV_EXCL_BR_LINE 11:except branch - } - - // search for the key and its associated value in internal structure - for (l_itCfgStructure = m_pmCFGData->begin(); - l_itCfgStructure != m_pmCFGData->end(); - l_itCfgStructure++) { - CBlock *l_pBlock = (*l_itCfgStructure).second; - - if (!l_cHeadTag.compare((*l_itCfgStructure).first) && NULL != l_pBlock) { - for (UI_32 l_uiCount = 0; l_uiCount < l_pBlock->m_vElementPair.size(); l_uiCount++) { - if (!l_cTag.compare(l_pBlock->m_vElementPair[l_uiCount].m_cTag)) { - // LCOV_EXCL_BR_START 200:After l_cValue assignment is empty,there is no other place to assignment the value - if (!l_cValue.empty()) { - // LCOV_EXCL_BR_STOP - // LCOV_EXCL_START 200:After l_cValue assignment is empty,there is no other place to assignment the value - AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert - l_cValue.append("\n"); - // LCOV_EXCL_STOP 200 - } - l_cValue.append(l_pBlock->m_vElementPair[l_uiCount].m_cValue); - } - } - } - } - } - - return l_cValue; -} - -EFrameworkunifiedStatus CCFGParser::CFGGetData(const std::string &f_ckey, std::string &f_cvalue) { - EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusFail; - - CFGData_Type::iterator l_itCfgStructure; - std::string l_cHeadTag = ""; - std::string l_cTag = ""; // LCOV_EXCL_BR_LINE 11:except branch - std::string l_cValue = ""; // LCOV_EXCL_BR_LINE 11:except branch - - size_t l_uiPos = 0; - - if (NULL != m_pmCFGData && !f_ckey.empty()) { // LCOV_EXCL_BR_LINE 5:new's error case(in function CFGParseFile) - if (std::string::npos != (l_uiPos = f_ckey.find('.'))) { // LCOV_EXCL_BR_LINE 11:except branch - l_cHeadTag = f_ckey.substr(0, l_uiPos); // LCOV_EXCL_BR_LINE 11:except branch - l_cTag = f_ckey.substr(l_uiPos + 1); // LCOV_EXCL_BR_LINE 11:except branch - } - - // search for the key and its associated value in internal structure - for (l_itCfgStructure = m_pmCFGData->begin(); - l_itCfgStructure != m_pmCFGData->end(); - l_itCfgStructure++) { - CBlock *l_pBlock = (*l_itCfgStructure).second; - - if (!l_cHeadTag.compare((*l_itCfgStructure).first) && NULL != l_pBlock) { - for (UI_32 l_uiCount = 0; l_uiCount < l_pBlock->m_vElementPair.size(); l_uiCount++) { - if (!l_cTag.compare(l_pBlock->m_vElementPair[l_uiCount].m_cTag)) { - if (!f_cvalue.empty()) { - f_cvalue.append("\n"); - } - f_cvalue.append(l_pBlock->m_vElementPair[l_uiCount].m_cValue); - - l_eStatus = eFrameworkunifiedStatusOK; - } - } - } - } - } - - return l_eStatus; -} - -EFrameworkunifiedStatus CCFGParser::CFGSetData(const std::string &f_cKey, std::string f_cvalue) { - EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusFail; - - CFGData_Type::iterator l_itCfgStructure; - std::string l_cHeadTag = ""; - std::string l_cTag = ""; // LCOV_EXCL_BR_LINE 11:except branch - std::string l_cValue = ""; // LCOV_EXCL_BR_LINE 11:except branch - size_t l_uiPos = 0; - - // LCOV_EXCL_BR_START 6:f_cKey is not NULL, because checked in CCFGWriter::SetValue - if (NULL != m_pmCFGData && !f_cKey.empty()) { - // LCOV_EXCL_BR_STOP - if (std::string::npos != (l_uiPos = f_cKey.find('.'))) { // LCOV_EXCL_BR_LINE 11:except branch - l_cHeadTag = f_cKey.substr(0, l_uiPos); // LCOV_EXCL_BR_LINE 11:except branch - l_cTag = f_cKey.substr(l_uiPos + 1); // LCOV_EXCL_BR_LINE 11:except branch - } - - // search for the key in internal structure and set the data for it - for (l_itCfgStructure = m_pmCFGData->begin(); - l_itCfgStructure != m_pmCFGData->end(); - l_itCfgStructure++) { - CBlock *l_pBlock = (*l_itCfgStructure).second; - - if (!l_cHeadTag.compare((*l_itCfgStructure).first) && NULL != l_pBlock) { - for (UI_32 l_uiCount = 0; l_uiCount < l_pBlock->m_vElementPair.size(); l_uiCount++) { - if (!l_cTag.compare(l_pBlock->m_vElementPair[l_uiCount].m_cTag)) { - l_pBlock->m_vElementPair[l_uiCount].m_cValue.assign(f_cvalue); - l_eStatus = eFrameworkunifiedStatusOK; - } - } - } - } - } else { - // LCOV_EXCL_START 6:f_cKey is not NULL, because checked in CCFGWriter::SetValue - AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert - l_eStatus = eFrameworkunifiedStatusNullPointer; - FRAMEWORKUNIFIEDLOG(ZONE_NS_ERR, __FUNCTION__, "m_pmCFGData is NULL"); - // LCOV_EXCL_STOP - } - - return l_eStatus; -} - -EFrameworkunifiedStatus CCFGParser::CFGSaveData(const std::string &f_cfilepath) { - EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK; - - CFGData_Type::iterator l_itCfgStructure; - - if (NULL != m_pmCFGData) { // LCOV_EXCL_BR_LINE 5:m_pmCFGData cannot be NULL, because internal logic guarantee - std::ofstream l_objFile(f_cfilepath.c_str()); - - // check if file is open - if (l_objFile.is_open()) { - // write the updated CFG structure back to the file - for (l_itCfgStructure = m_pmCFGData->begin(); - l_itCfgStructure != m_pmCFGData->end(); - l_itCfgStructure++) { - CBlock *l_pBlock = (*l_itCfgStructure).second; - if (NULL != l_pBlock) { // LCOV_EXCL_BR_LINE 11:except branch - // write the main tag comment in file - if (!l_pBlock->m_cComment.empty()) { - l_objFile << l_pBlock->m_cComment << std::endl; - } - - // write main tag to file - l_objFile << "[" << (*l_itCfgStructure).first << "]" << std::endl; - - for (UI_32 l_uiCount = 0; l_uiCount < l_pBlock->m_vElementPair.size(); l_uiCount++) { - // comment over the key-value pair - if (!l_pBlock->m_vElementPair[l_uiCount].m_cComment.empty()) { - l_objFile << l_pBlock->m_vElementPair[l_uiCount].m_cComment << std::endl;; - } - - // key-value - l_objFile << l_pBlock->m_vElementPair[l_uiCount].m_cTag << "=" - << l_pBlock->m_vElementPair[l_uiCount].m_cValue << std::endl; - } - } - } - - // last comment - if (!m_cLastComment.empty()) { - l_objFile << m_cLastComment << std::endl; - } - - // close the file - l_objFile.close(); // LCOV_EXCL_BR_LINE 11:except branch - } else { - l_eStatus = eFrameworkunifiedStatusFail; - FRAMEWORKUNIFIEDLOG(ZONE_NS_ERR, __FUNCTION__, "Cannot Open File"); - } - } else { - // LCOV_EXCL_START 5:m_pmCFGData cannot be NULL, because internal logic guarantee - AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert - l_eStatus = eFrameworkunifiedStatusNullPointer; - FRAMEWORKUNIFIEDLOG(ZONE_NS_ERR, __FUNCTION__, "m_pmCFGData is NULL"); - // LCOV_EXCL_STOP - } - - return l_eStatus; -} diff --git a/nsframework/framework_unified/client/NS_ConfigParser/src/ns_cfg_reader.cpp b/nsframework/framework_unified/client/NS_ConfigParser/src/ns_cfg_reader.cpp deleted file mode 100755 index 9eeb3c0..0000000 --- a/nsframework/framework_unified/client/NS_ConfigParser/src/ns_cfg_reader.cpp +++ /dev/null @@ -1,117 +0,0 @@ -/* - * @copyright Copyright (c) 2016-2020 TOYOTA MOTOR CORPORATION. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -//////////////////////////////////////////////////////////////////////////////////////////////////// -/// \ingroup tag_NS_ConfigParser -/// \brief This file contains implementation of CCFGReader class. -/// -//////////////////////////////////////////////////////////////////////////////////////////////////// - -//////////////////////////////////////////////////////////////////////////////////////////////////// -// Include Files -//////////////////////////////////////////////////////////////////////////////////////////////////// -#include <ns_cfg_reader.h> -#include <ns_cfg_parser.h> -#include <ns_config_parser_frameworkunifiedlog.h> -#include <string> - - - -CCFGReader::CCFGReader(): m_cFilePath(""), m_pCFGParser(NULL) { // LCOV_EXCL_BR_LINE 11:except branch -} - -// LCOV_EXCL_START 200:CCFGReader is not external API class, this constructed function isn't used by other function -CCFGReader::CCFGReader(const std::string &f_c_filepath): m_cFilePath(f_c_filepath), m_pCFGParser(NULL) { - AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert - FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "File Path %s", m_cFilePath.c_str()); - - m_pCFGParser = new CCFGParser(m_cFilePath); - - if (NULL == m_pCFGParser) { - FRAMEWORKUNIFIEDLOG(ZONE_NS_ERR, __FUNCTION__, "Memory allocation error for m_pCFGParser"); - } -} -// LCOV_EXCL_STOP - -EFrameworkunifiedStatus CCFGReader::ParseFile(const std::string &f_c_filepath) { - EFrameworkunifiedStatus l_e_status = eFrameworkunifiedStatusOK; - FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+"); - - // FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__, "File Path %s", f_c_filepath.c_str()); - - m_cFilePath.assign(f_c_filepath); - - m_pCFGParser = new(std::nothrow) CCFGParser(); // LCOV_EXCL_BR_LINE 11:except branch - - if (NULL == m_pCFGParser) { // LCOV_EXCL_BR_LINE 5:new's error case - // LCOV_EXCL_START 5:new's error case - AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert - FRAMEWORKUNIFIEDLOG(ZONE_NS_ERR, __FUNCTION__, "Memory allocation error for m_pCFGParser"); - l_e_status = eFrameworkunifiedStatusNullPointer; - // LCOV_EXCL_STOP - } else { - l_e_status = m_pCFGParser->CFGParseFile(f_c_filepath); - } - - FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-"); - return l_e_status; -} - -CCFGReader::~CCFGReader() { - if (NULL != m_pCFGParser) { - delete m_pCFGParser; - m_pCFGParser = NULL; - } -} - -PVOID CCFGReader::GetDataPtr() { - return m_pCFGParser; -} - -std::string CCFGReader::GetValue(const std::string &f_c_key) { - std::string l_cValue = ""; - - if (NULL != m_pCFGParser && !f_c_key.empty()) { // LCOV_EXCL_BR_LINE 11:except branch - // read the data from internal CFG structure - l_cValue = m_pCFGParser->CFGGetData(f_c_key); // LCOV_EXCL_BR_LINE 11:except branch - } - - return l_cValue; -} - -EFrameworkunifiedStatus CCFGReader::GetValue(const std::string &f_c_key, std::string &f_c_value) { - FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+"); - EFrameworkunifiedStatus l_e_status = eFrameworkunifiedStatusOK; - - if (NULL == m_pCFGParser) { // LCOV_EXCL_BR_LINE 5:m_pCFGParser cannot be NULL, because internal logic guarantee - // LCOV_EXCL_START 5:m_pCFGParser cannot be NULL, because internal logic guarantee - AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert - l_e_status = eFrameworkunifiedStatusNullPointer; - FRAMEWORKUNIFIEDLOG(ZONE_NS_ERR, __FUNCTION__, "Parser object(m_pCFGParser) is NULL"); - // LCOV_EXCL_STOP - } else if (f_c_key.empty()) { - l_e_status = eFrameworkunifiedStatusInvldParam; - // LCOV_EXCL_BR_START 15:marco defined in "native_service/ns_logger_if.h" - FRAMEWORKUNIFIEDLOG(ZONE_NS_ERR, __FUNCTION__, "Invalid Key"); - // LCOV_EXCL_BR_STOP - } else { - // read the data from internal CFG structure - l_e_status = m_pCFGParser->CFGGetData(f_c_key, f_c_value); - } - - FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-"); - return l_e_status; -} diff --git a/nsframework/framework_unified/client/NS_ConfigParser/src/ns_cfg_writer.cpp b/nsframework/framework_unified/client/NS_ConfigParser/src/ns_cfg_writer.cpp deleted file mode 100755 index 4bf16d5..0000000 --- a/nsframework/framework_unified/client/NS_ConfigParser/src/ns_cfg_writer.cpp +++ /dev/null @@ -1,135 +0,0 @@ -/* - * @copyright Copyright (c) 2016-2020 TOYOTA MOTOR CORPORATION. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -//////////////////////////////////////////////////////////////////////////////////////////////////// -/// \ingroup tag_NS_ConfigParser -/// \brief This file contains implementation of CCFGWriter class. -/// -//////////////////////////////////////////////////////////////////////////////////////////////////// - -//////////////////////////////////////////////////////////////////////////////////////////////////// -// Include Files -//////////////////////////////////////////////////////////////////////////////////////////////////// -#include <sys/types.h> -#include <sys/stat.h> -#include <stdio.h> -#include <unistd.h> - -#include <ns_cfg_parser.h> -#include <ns_cfg_writer.h> -#include <ns_config_parser_frameworkunifiedlog.h> - -#include <fstream> -#include <string> - - -CCFGWriter::CCFGWriter(): m_cFilePath(""), m_pCFGParser(NULL) { // LCOV_EXCL_BR_LINE 11:except branch - FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+"); -} - -CCFGWriter::CCFGWriter(const std::string &f_c_filepath): m_cFilePath(f_c_filepath), m_pCFGParser(NULL) { - FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "File Path %s", m_cFilePath.c_str()); - - m_pCFGParser = new CCFGParser(m_cFilePath); - - if (NULL == m_pCFGParser) { - FRAMEWORKUNIFIEDLOG(ZONE_NS_ERR, __FUNCTION__, "Memory allocation error for m_pCFGParser"); - } -} - -CCFGWriter::~CCFGWriter() { - if (NULL != m_pCFGParser) { - delete m_pCFGParser; // LCOV_EXCL_BR_LINE 11:except branch - m_pCFGParser = NULL; - } -} - -EFrameworkunifiedStatus CCFGWriter::ParseFile(const std::string &f_c_filepath) { - EFrameworkunifiedStatus l_e_status = eFrameworkunifiedStatusOK; - FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+"); - - // FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__, "File Path %s", f_c_filepath.c_str()); - - m_cFilePath.assign(f_c_filepath); - - m_pCFGParser = new(std::nothrow) CCFGParser(); // LCOV_EXCL_BR_LINE 11:except branch - - if (NULL == m_pCFGParser) { // LCOV_EXCL_BR_LINE 5:m_pCFGParser cannot be NULL, because internal logic guarantee - // LCOV_EXCL_START 5:m_pCFGParser cannot be NULL, because internal logic guarantee - AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert - FRAMEWORKUNIFIEDLOG(ZONE_NS_ERR, __FUNCTION__, "Memory allocation error for m_pCFGParser"); - l_e_status = eFrameworkunifiedStatusNullPointer; - // LCOV_EXCL_STOP - } else { - l_e_status = m_pCFGParser->CFGParseFile(f_c_filepath); - } - - FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-"); - return l_e_status; -} - -EFrameworkunifiedStatus CCFGWriter::SetPath(const std::string &f_c_path) { - EFrameworkunifiedStatus l_e_status = eFrameworkunifiedStatusOK; - - if (!f_c_path.empty()) { // LCOV_EXCL_BR_LINE 11:except branch - // set the file path - m_cFilePath.assign(f_c_path); - } else { - l_e_status = eFrameworkunifiedStatusInvldParam; - } - - return l_e_status; -} - -VOID CCFGWriter::SetDataPtr(PVOID f_p_data) { - if (NULL != f_p_data) { - // set the doc pointer - m_pCFGParser = static_cast<CCFGParser *>(f_p_data); - } else { - m_pCFGParser = NULL; - FRAMEWORKUNIFIEDLOG(ZONE_NS_ERR, __FUNCTION__, "Data Pointer not set in cfg writer"); // LCOV_EXCL_BR_LINE 15:marco defined in "native_service/ns_logger_if.h" - } -} - -EFrameworkunifiedStatus CCFGWriter::SetValue(const std::string &f_c_key, std::string f_c_value) { - EFrameworkunifiedStatus l_e_status = eFrameworkunifiedStatusOK; - - if (NULL != m_pCFGParser && !f_c_key.empty()) { - // set the data in internal CFG structure - l_e_status = m_pCFGParser->CFGSetData(f_c_key, f_c_value); // LCOV_EXCL_BR_LINE 11:except branch - } else { - l_e_status = eFrameworkunifiedStatusInvldParam; - } - - return l_e_status; -} - -EFrameworkunifiedStatus CCFGWriter::SaveData() { - EFrameworkunifiedStatus l_e_status = eFrameworkunifiedStatusOK; - - if (NULL != m_pCFGParser) { - if (0 == access(m_cFilePath.c_str(), W_OK)) { - // save the data permanently in config file - l_e_status = m_pCFGParser->CFGSaveData(m_cFilePath); - } else { - l_e_status = eFrameworkunifiedStatusFail; - } - } else { - l_e_status = eFrameworkunifiedStatusNullPointer; - } - - return l_e_status; -} diff --git a/nsframework/framework_unified/client/NS_ConfigParser/src/ns_config_reader.cpp b/nsframework/framework_unified/client/NS_ConfigParser/src/ns_config_reader.cpp deleted file mode 100755 index 839053a..0000000 --- a/nsframework/framework_unified/client/NS_ConfigParser/src/ns_config_reader.cpp +++ /dev/null @@ -1,346 +0,0 @@ -/* - * @copyright Copyright (c) 2016-2020 TOYOTA MOTOR CORPORATION. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -//////////////////////////////////////////////////////////////////////////////////////////////////// -/// \ingroup tag_NS_ConfigParser -/// \brief This file contains implementation of CNSConfigReader class. -/// -//////////////////////////////////////////////////////////////////////////////////////////////////// - -//////////////////////////////////////////////////////////////////////////////////////////////////// -// Include Files -//////////////////////////////////////////////////////////////////////////////////////////////////// -#include <stdlib.h> -#include <ctype.h> -#include <dlfcn.h> -#include <errno.h> - -#include <native_service/ns_config_parser_if.h> -#include <native_service/ns_reader.h> - -#include <cstring> -#include <string> - -#include "ns_config_parser_frameworkunifiedlog.h" -#include "ns_cfg_reader.h" -CNSConfigReader::CNSConfigReader() { - m_pReader = NULL; -} - -CNSConfigReader::CNSConfigReader(const std::string &f_c_filepath): m_pReader(NULL) { - FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "File Path %s", f_c_filepath.c_str()); - - if (eFrameworkunifiedStatusOK != Parse(f_c_filepath)) { - FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "Error Parsing file %s", f_c_filepath.c_str()); // LCOV_EXCL_BR_LINE 15:marco defined in "native_service/ns_logger_if.h" - } -} - -CNSConfigReader::~CNSConfigReader() { - FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "Destructor"); - - if (NULL != m_pReader) { - delete m_pReader; // LCOV_EXCL_BR_LINE 11:except branch - m_pReader = NULL; - } -} - -EFrameworkunifiedStatus CNSConfigReader::Parse(const std::string &f_c_filepath) { - EFrameworkunifiedStatus l_e_status = eFrameworkunifiedStatusOK; - FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+"); - - // FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__, "File Path %s", f_c_filepath.c_str()); - - if (NULL != m_pReader) { - delete m_pReader; // LCOV_EXCL_BR_LINE 11:except branch - m_pReader = NULL; - } - - // create parser object depending on file extension - if (NULL != std::strstr(f_c_filepath.c_str(), ".cfg")) { - m_pReader = new(std::nothrow) CCFGReader(); // LCOV_EXCL_BR_LINE 11:except branch - } else { - FRAMEWORKUNIFIEDLOG(ZONE_NS_ERR, __FUNCTION__, "Not CFG"); // LCOV_EXCL_BR_LINE 15:marco defined in "native_service/ns_logger_if.h" - l_e_status = eFrameworkunifiedStatusFail; - } - - if (NULL != m_pReader) { - l_e_status = m_pReader->ParseFile(f_c_filepath); - } else { - l_e_status = eFrameworkunifiedStatusNullPointer; - } - - FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-"); - return l_e_status; -} - -PVOID CNSConfigReader::GetDataPtr() { - if (NULL != m_pReader) { - // get the data pointer - return m_pReader->GetDataPtr(); - } else { - return NULL; - } -} - -BOOL CNSConfigReader::GetBool(const std::string &f_c_key) { - BOOL l_bResult = FALSE; - - if (NULL != m_pReader) { - std::string l_c_temp = m_pReader->GetValue(f_c_key); - - l_c_temp = FormatValue(l_c_temp); // LCOV_EXCL_BR_LINE 11:except branch - - if (!strcasecmp(l_c_temp.c_str(), "true")) { - l_bResult = TRUE; - } - } else { - FRAMEWORKUNIFIEDLOG(ZONE_NS_ERR, __FUNCTION__, "Config Reader (m_pReader) is NULL"); // LCOV_EXCL_BR_LINE 15:marco defined in "native_service/ns_logger_if.h" - } - - return l_bResult; -} - -F_64 CNSConfigReader::GetDouble(const std::string &f_c_key) { - F_64 l_fValue = 0; - - if (NULL != m_pReader) { - std::string l_c_temp = m_pReader->GetValue(f_c_key); - - errno = EOK; - - // convert string to double - l_fValue = strtod(l_c_temp.c_str(), NULL); - - if (EOK != errno) { - FRAMEWORKUNIFIEDLOG(ZONE_NS_ERR, __FUNCTION__, "Error converting string %s to double, errno=%d", l_c_temp.c_str(), errno); - } - } else { - FRAMEWORKUNIFIEDLOG(ZONE_NS_ERR, __FUNCTION__, "Config Reader (m_pReader) is NULL"); // LCOV_EXCL_BR_LINE 15:marco defined in "native_service/ns_logger_if.h" - } - - return l_fValue; -} - -F_32 CNSConfigReader::GetFloat(const std::string &f_c_key) { - F_32 l_fValue = 0; - - if (NULL != m_pReader) { - std::string l_c_temp = m_pReader->GetValue(f_c_key); - errno = EOK; - l_fValue = strtof(l_c_temp.c_str(), NULL); - - if (EOK != errno) { - l_fValue = 0; - FRAMEWORKUNIFIEDLOG(ZONE_NS_ERR, __FUNCTION__, "Error converting string %s to float, errno=%d", l_c_temp.c_str(), errno); - } - } else { - FRAMEWORKUNIFIEDLOG(ZONE_NS_ERR, __FUNCTION__, "Config Reader (m_pReader) is NULL"); // LCOV_EXCL_BR_LINE 15:marco defined in "native_service/ns_logger_if.h" - } - - return l_fValue; -} - -SI_32 CNSConfigReader::GetInt(const std::string &f_c_key) { - UI_64 l_ui_value = 0; - - if (NULL != m_pReader) { - std::string l_c_temp = m_pReader->GetValue(f_c_key); - - errno = EOK; - - if ((l_c_temp.size() >= 3) && ('0' == l_c_temp[0]) && ('X' == toupper(l_c_temp[1]))) { - l_ui_value = strtoul(l_c_temp.c_str(), NULL, 16); - } else { - l_ui_value = strtoul(l_c_temp.c_str(), NULL, 10); - } - - if (EOK != errno) { - l_ui_value = 0; - FRAMEWORKUNIFIEDLOG(ZONE_NS_ERR, __FUNCTION__, "Error converting string %s to int, errno=%d", l_c_temp.c_str(), errno); - } - } else { - FRAMEWORKUNIFIEDLOG(ZONE_NS_ERR, __FUNCTION__, "Config Reader (m_pReader) is NULL"); // LCOV_EXCL_BR_LINE 15:marco defined in "native_service/ns_logger_if.h" - } - - return static_cast<SI_32>(l_ui_value); -} - -std::string CNSConfigReader::GetString(const std::string &f_c_key) { - std::string l_c_temp = ""; - - if (NULL != m_pReader) { - l_c_temp = m_pReader->GetValue(f_c_key); // LCOV_EXCL_BR_LINE 11:except branch - - l_c_temp = FormatValue(l_c_temp); // LCOV_EXCL_BR_LINE 11:except branch - } else { - FRAMEWORKUNIFIEDLOG(ZONE_NS_ERR, __FUNCTION__, "Config Reader (m_pReader) is NULL"); - } - - return l_c_temp; -} - -EFrameworkunifiedStatus CNSConfigReader::GetBool(const std::string &f_c_key, BOOL &f_b_value) { - EFrameworkunifiedStatus l_e_status = eFrameworkunifiedStatusOK; - - std::string l_c_temp = ""; - - if (NULL != m_pReader) { - l_e_status = m_pReader->GetValue(f_c_key, l_c_temp); // LCOV_EXCL_BR_LINE 11:except branch - - if (eFrameworkunifiedStatusOK == l_e_status) { - l_c_temp = FormatValue(l_c_temp); // LCOV_EXCL_BR_LINE 11:except branch - - if (!strcasecmp(l_c_temp.c_str(), "true")) { - f_b_value = TRUE; - } else if (!strcasecmp(l_c_temp.c_str(), "false")) { - f_b_value = FALSE; - } else { - l_e_status = eFrameworkunifiedStatusErrOther; - } - } - } else { - FRAMEWORKUNIFIEDLOG(ZONE_NS_ERR, __FUNCTION__, "Config Reader (m_pReader) is NULL"); - l_e_status = eFrameworkunifiedStatusNullPointer; - } - - return l_e_status; -} - -EFrameworkunifiedStatus CNSConfigReader::GetDouble(const std::string &f_c_key, F_64 &f_d_value) { - EFrameworkunifiedStatus l_e_status = eFrameworkunifiedStatusOK; - - std::string l_c_temp = ""; - - if (NULL != m_pReader) { - l_e_status = m_pReader->GetValue(f_c_key, l_c_temp); // LCOV_EXCL_BR_LINE 11:except branch - - if (eFrameworkunifiedStatusOK == l_e_status) { - errno = EOK; - f_d_value = strtod(l_c_temp.c_str(), NULL); - - if (EOK != errno) { - FRAMEWORKUNIFIEDLOG(ZONE_NS_ERR, __FUNCTION__, "Error converting string %s to double, errno=%d", l_c_temp.c_str(), errno); - l_e_status = eFrameworkunifiedStatusInvldBuf; - } - } - } else { - FRAMEWORKUNIFIEDLOG(ZONE_NS_ERR, __FUNCTION__, "Config Reader (m_pReader) is NULL"); - l_e_status = eFrameworkunifiedStatusNullPointer; - } - - return l_e_status; -} - -EFrameworkunifiedStatus CNSConfigReader::GetFloat(const std::string &f_c_key, F_32 &f_f_value) { - EFrameworkunifiedStatus l_e_status = eFrameworkunifiedStatusOK; - - std::string l_c_temp = ""; - - if (NULL != m_pReader) { - l_e_status = m_pReader->GetValue(f_c_key, l_c_temp); // LCOV_EXCL_BR_LINE 11:except branch - - if (eFrameworkunifiedStatusOK == l_e_status) { - errno = EOK; - f_f_value = strtof(l_c_temp.c_str(), NULL); - - if (EOK != errno) { - f_f_value = 0; - FRAMEWORKUNIFIEDLOG(ZONE_NS_ERR, __FUNCTION__, "Error converting string %s to float, errno=%d", l_c_temp.c_str(), errno); - l_e_status = eFrameworkunifiedStatusInvldBuf; - } - } - } else { - FRAMEWORKUNIFIEDLOG(ZONE_NS_ERR, __FUNCTION__, "Config Reader (m_pReader) is NULL"); - l_e_status = eFrameworkunifiedStatusNullPointer; - } - - return l_e_status; -} - -EFrameworkunifiedStatus CNSConfigReader::GetInt(const std::string &f_c_key, SI_32 &f_i_value) { - EFrameworkunifiedStatus l_e_status = eFrameworkunifiedStatusOK; - - std::string l_c_temp = ""; - - UI_64 l_ui_value = 0; - - if (NULL != m_pReader) { - l_e_status = m_pReader->GetValue(f_c_key, l_c_temp); // LCOV_EXCL_BR_LINE 11:except branch - - if (eFrameworkunifiedStatusOK == l_e_status) { - errno = EOK; - - if ((l_c_temp.size() >= 3) && ('0' == l_c_temp[0]) && ('X' == toupper(l_c_temp[1]))) { - l_ui_value = strtoul(l_c_temp.c_str(), NULL, 16); - } else { - l_ui_value = strtoul(l_c_temp.c_str(), NULL, 10); - } - - f_i_value = static_cast<SI_32>(l_ui_value); - - if (EOK != errno) { - FRAMEWORKUNIFIEDLOG(ZONE_NS_ERR, __FUNCTION__, "Error converting string %s to int, errno=%d", l_c_temp.c_str(), errno); - l_e_status = eFrameworkunifiedStatusInvldBuf; - } - } - } else { - FRAMEWORKUNIFIEDLOG(ZONE_NS_ERR, __FUNCTION__, "Config Reader (m_pReader) is NULL"); - l_e_status = eFrameworkunifiedStatusNullPointer; - } - - return l_e_status; -} - -EFrameworkunifiedStatus CNSConfigReader::GetString(const std::string &f_c_key, std::string &f_c_value) { - EFrameworkunifiedStatus l_e_status = eFrameworkunifiedStatusOK; - - std::string l_c_temp = ""; - - if (NULL != m_pReader) { - l_e_status = m_pReader->GetValue(f_c_key, l_c_temp); // LCOV_EXCL_BR_LINE 11:except branch - - if (eFrameworkunifiedStatusOK == l_e_status) { - l_c_temp = FormatValue(l_c_temp); // LCOV_EXCL_BR_LINE 11:except branch - - f_c_value.assign(l_c_temp); - } - } else { - FRAMEWORKUNIFIEDLOG(ZONE_NS_ERR, __FUNCTION__, "Config Reader (m_pReader) is NULL"); - l_e_status = eFrameworkunifiedStatusNullPointer; - } - - return l_e_status; -} - -std::string CNSConfigReader::FormatValue(const std::string &f_c_value) { - std::string l_c_newvalue = f_c_value; - - if (0 < f_c_value.length()) { - UI_32 l_uiStrPos = static_cast<UI_32>(l_c_newvalue.length() - 1); - - while ('\n' == l_c_newvalue[l_uiStrPos] || '\r' == l_c_newvalue[l_uiStrPos]) { - l_c_newvalue = l_c_newvalue.substr(0, l_uiStrPos); - - if (0 == l_uiStrPos) { - break; - } - - l_uiStrPos--; - } - } - - return l_c_newvalue; -} diff --git a/nsframework/framework_unified/client/NS_ConfigParser/src/ns_config_reader_writer.cpp b/nsframework/framework_unified/client/NS_ConfigParser/src/ns_config_reader_writer.cpp deleted file mode 100755 index 6c2b2d6..0000000 --- a/nsframework/framework_unified/client/NS_ConfigParser/src/ns_config_reader_writer.cpp +++ /dev/null @@ -1,74 +0,0 @@ -/* - * @copyright Copyright (c) 2016-2020 TOYOTA MOTOR CORPORATION. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -//////////////////////////////////////////////////////////////////////////////////////////////////// -/// \ingroup tag_NS_ConfigParser -/// \brief This file contains implementation of CNSConfigParser class. -/// -//////////////////////////////////////////////////////////////////////////////////////////////////// - -//////////////////////////////////////////////////////////////////////////////////////////////////// -// Include Files -//////////////////////////////////////////////////////////////////////////////////////////////////// -#include <native_service/ns_config_parser_if.h> -#include <string> -#include "ns_config_parser_frameworkunifiedlog.h" - -CNSConfigParser::CNSConfigParser() : CNSConfigReader(), CNSConfigWriter() { // LCOV_EXCL_BR_LINE 11:except branch -} - -CNSConfigParser::CNSConfigParser(const std::string &f_c_filepath): CNSConfigReader(f_c_filepath), - CNSConfigWriter(f_c_filepath, TRUE) { // LCOV_EXCL_BR_LINE 11:except branch - FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "File Path %s", f_c_filepath.c_str()); - - // get the data pointer from the config reader - PVOID l_pdata = GetDataPtr(); // LCOV_EXCL_BR_LINE 11:except branch - - // set the same data pointer in config writer - SetDataPtr(l_pdata); // LCOV_EXCL_BR_LINE 11:except branch -} - -CNSConfigParser::~CNSConfigParser() { // LCOV_EXCL_BR_LINE 11:except branch - FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "Destructor"); - - // set the data pointer to NULL in writer - SetDataPtr(NULL); // LCOV_EXCL_BR_LINE 11:except branch -} - -EFrameworkunifiedStatus CNSConfigParser::Parse(const std::string &f_c_filepath) { - EFrameworkunifiedStatus l_e_status = eFrameworkunifiedStatusOK; - FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+"); - - // FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__, "File Path %s", f_c_filepath.c_str()); - - // parse and create config document structure with reader - if (eFrameworkunifiedStatusOK == (l_e_status = CNSConfigReader::Parse(f_c_filepath))) { - // set the data pointer to NULL in writer - SetDataPtr(NULL); - - // sets the same config document structure in writer - if (eFrameworkunifiedStatusOK == (l_e_status = CNSConfigWriter::Create(f_c_filepath))) { - // get the data pointer from the config reader - PVOID l_pdata = GetDataPtr(); - - // set the same data pointer in config writer - SetDataPtr(l_pdata); - } - } - - FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-"); - return l_e_status; -} diff --git a/nsframework/framework_unified/client/NS_ConfigParser/src/ns_config_writer.cpp b/nsframework/framework_unified/client/NS_ConfigParser/src/ns_config_writer.cpp deleted file mode 100755 index 601500d..0000000 --- a/nsframework/framework_unified/client/NS_ConfigParser/src/ns_config_writer.cpp +++ /dev/null @@ -1,227 +0,0 @@ -/* - * @copyright Copyright (c) 2016-2020 TOYOTA MOTOR CORPORATION. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -//////////////////////////////////////////////////////////////////////////////////////////////////// -/// \ingroup tag_NS_ConfigParser -/// \brief This file contains implementation of CNSConfigWriter class. -/// -//////////////////////////////////////////////////////////////////////////////////////////////////// - -//////////////////////////////////////////////////////////////////////////////////////////////////// -// Include Files -//////////////////////////////////////////////////////////////////////////////////////////////////// -#include <native_service/ns_config_parser_if.h> -#include <native_service/ns_writer.h> -#include <dlfcn.h> -#include <sstream> -#include <cstring> -#include <string> -#include "ns_cfg_writer.h" -#include "ns_config_parser_frameworkunifiedlog.h" - - -CNSConfigWriter::CNSConfigWriter(): m_pWriter(NULL) { -} - -CNSConfigWriter::CNSConfigWriter(const std::string &f_c_filepath): m_pWriter(NULL) { - FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "File Path %s", f_c_filepath.c_str()); - - Parse(f_c_filepath); -} - -CNSConfigWriter::CNSConfigWriter(const std::string &f_c_filepath, BOOL f_b_noload): m_pWriter(NULL) { - FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "File Path %s", f_c_filepath.c_str()); - - Create(f_c_filepath); -} - -CNSConfigWriter::~CNSConfigWriter() { - FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "Destructor"); - - if (NULL != m_pWriter) { - delete m_pWriter; // LCOV_EXCL_BR_LINE 11:except branch - m_pWriter = NULL; - } - // TODO(my_username): dlclose. -} - -EFrameworkunifiedStatus CNSConfigWriter::Parse(const std::string &f_c_filepath) { - EFrameworkunifiedStatus l_e_status = eFrameworkunifiedStatusOK; - - if (NULL != m_pWriter) { - delete m_pWriter; // LCOV_EXCL_BR_LINE 11:except branch - m_pWriter = NULL; - } - - // create parser object depending on file extension - if (std::strstr(f_c_filepath.c_str(), ".cfg") != NULL) { - m_pWriter = new(std::nothrow) CCFGWriter(); // LCOV_EXCL_BR_LINE 11:except branch - } else { - // LCOV_EXCL_BR_START 15:marco defined in "native_service/ns_logger_if.h" - FRAMEWORKUNIFIEDLOG(ZONE_NS_ERR, __FUNCTION__, "Not CFG"); - // LCOV_EXCL_BR_STOP - } - - if (NULL != m_pWriter) { - l_e_status = m_pWriter->ParseFile(f_c_filepath); - } else { - l_e_status = eFrameworkunifiedStatusNullPointer; - } - - return l_e_status; -} - -EFrameworkunifiedStatus CNSConfigWriter::Create(const std::string &f_c_filepath) { - EFrameworkunifiedStatus l_e_status = eFrameworkunifiedStatusOK; - - if (NULL != m_pWriter) { - delete m_pWriter; // LCOV_EXCL_BR_LINE 11:except branch - m_pWriter = NULL; - } - - // create parser object depending on file extension - if (std::strstr(f_c_filepath.c_str(), ".cfg") != NULL) { - m_pWriter = new(std::nothrow) CCFGWriter(); // LCOV_EXCL_BR_LINE 11:except branch - } else { - // LCOV_EXCL_BR_START 15:marco defined in "native_service/ns_logger_if.h" - FRAMEWORKUNIFIEDLOG(ZONE_NS_ERR, __FUNCTION__, "Not CFG"); - // LCOV_EXCL_BR_STOP - l_e_status = eFrameworkunifiedStatusFail; - } - - if (NULL != m_pWriter) { - l_e_status = m_pWriter->SetPath(f_c_filepath); - } else { - l_e_status = eFrameworkunifiedStatusNullPointer; - } - - return l_e_status; -} - -VOID CNSConfigWriter::SetDataPtr(PVOID f_p_data) { - if (NULL != m_pWriter) { - m_pWriter->SetDataPtr(f_p_data); - } else { - // LCOV_EXCL_BR_START 15:marco defined in "native_service/ns_logger_if.h" - FRAMEWORKUNIFIEDLOG(ZONE_NS_ERR, __FUNCTION__, "m_pWriter is NULL"); - // LCOV_EXCL_BR_STOP - } -} - -EFrameworkunifiedStatus CNSConfigWriter::Save() { - EFrameworkunifiedStatus l_e_status = eFrameworkunifiedStatusOK; - - if (NULL != m_pWriter) { - // save the updated config file - l_e_status = m_pWriter->SaveData(); - } else { - // LCOV_EXCL_BR_START 15:marco defined in "native_service/ns_logger_if.h" - FRAMEWORKUNIFIEDLOG(ZONE_NS_ERR, __FUNCTION__, "Config Writer (m_pWriter) is NULL"); - // LCOV_EXCL_BR_STOP - l_e_status = eFrameworkunifiedStatusNullPointer; - } - - return l_e_status; -} - -EFrameworkunifiedStatus CNSConfigWriter::SetBool(const std::string &f_c_key, BOOL f_b_value) { - EFrameworkunifiedStatus l_e_status = eFrameworkunifiedStatusOK; - - if (NULL != m_pWriter) { - std::string l_c_temp = ""; - - if (TRUE == f_b_value) { - l_c_temp = "TRUE"; - l_e_status = m_pWriter->SetValue(f_c_key, l_c_temp); // LCOV_EXCL_BR_LINE 11:except branch - } else if (FALSE == f_b_value) { // LCOV_EXCL_BR_LINE 11:except branch - l_c_temp = "FALSE"; - l_e_status = m_pWriter->SetValue(f_c_key, l_c_temp); // LCOV_EXCL_BR_LINE 11:except branch - } else { - FRAMEWORKUNIFIEDLOG(ZONE_NS_ERR, __FUNCTION__, "received bool value is not proper:: %d", f_b_value); - l_e_status = eFrameworkunifiedStatusInvldParam; - } - } else { - // LCOV_EXCL_BR_START 15:marco defined in "native_service/ns_logger_if.h" - FRAMEWORKUNIFIEDLOG(ZONE_NS_ERR, __FUNCTION__, "Config Writer (m_pWriter) is NULL"); - // LCOV_EXCL_BR_STOP - l_e_status = eFrameworkunifiedStatusNullPointer; - } - - return l_e_status; -} - -EFrameworkunifiedStatus CNSConfigWriter::Set(const std::string &f_cKey, F_64 f_f_value) { - EFrameworkunifiedStatus l_e_status = eFrameworkunifiedStatusOK; - - if (NULL != m_pWriter) { - std::stringstream l_cStream; - l_cStream << f_f_value; - - l_e_status = m_pWriter->SetValue(f_cKey, l_cStream.str()); // LCOV_EXCL_BR_LINE 11:except branch - } else { - // LCOV_EXCL_BR_START 15:marco defined in "native_service/ns_logger_if.h" - FRAMEWORKUNIFIEDLOG(ZONE_NS_ERR, __FUNCTION__, "Config Writer (m_pWriter) is NULL"); - // LCOV_EXCL_BR_STOP - l_e_status = eFrameworkunifiedStatusNullPointer; - } - - return l_e_status; -} - -EFrameworkunifiedStatus CNSConfigWriter::Set(const std::string &f_cKey, F_32 f_fValue) { - EFrameworkunifiedStatus l_e_status = eFrameworkunifiedStatusOK; - - if (NULL != m_pWriter) { // LCOV_EXCL_BR_LINE 11:except branch - std::stringstream l_cStream; - l_cStream << f_fValue; - - l_e_status = m_pWriter->SetValue(f_cKey, l_cStream.str()); // LCOV_EXCL_BR_LINE 11:except branch - } else { - FRAMEWORKUNIFIEDLOG(ZONE_NS_ERR, __FUNCTION__, "Config Writer (m_pWriter) is NULL"); - l_e_status = eFrameworkunifiedStatusNullPointer; - } - - return l_e_status; -} - -EFrameworkunifiedStatus CNSConfigWriter::Set(const std::string &f_cKey, SI_32 f_si_value) { - EFrameworkunifiedStatus l_e_status = eFrameworkunifiedStatusOK; - - if (NULL != m_pWriter) { - std::stringstream l_cStream; - l_cStream << f_si_value; // LCOV_EXCL_BR_LINE 11:except branch - - l_e_status = m_pWriter->SetValue(f_cKey, l_cStream.str()); // LCOV_EXCL_BR_LINE 11:except branch - } else { - FRAMEWORKUNIFIEDLOG(ZONE_NS_ERR, __FUNCTION__, "Config Writer (m_pWriter) is NULL"); // LCOV_EXCL_BR_LINE 11:except branch - l_e_status = eFrameworkunifiedStatusNullPointer; - } - - return l_e_status; -} - -EFrameworkunifiedStatus CNSConfigWriter::Set(const std::string &f_cKey, const std::string &f_s_value) { - EFrameworkunifiedStatus l_e_status = eFrameworkunifiedStatusOK; - - if (NULL != m_pWriter) { - l_e_status = m_pWriter->SetValue(f_cKey, f_s_value); // LCOV_EXCL_BR_LINE 11:except branch - } else { - FRAMEWORKUNIFIEDLOG(ZONE_NS_ERR, __FUNCTION__, "Config Writer (m_pWriter) is NULL"); // LCOV_EXCL_BR_LINE 11:except branch - l_e_status = eFrameworkunifiedStatusNullPointer; - } - - return l_e_status; -} diff --git a/nsframework/framework_unified/client/NS_ConfigParser/src/ns_reader.cpp b/nsframework/framework_unified/client/NS_ConfigParser/src/ns_reader.cpp deleted file mode 100755 index ff3cc7a..0000000 --- a/nsframework/framework_unified/client/NS_ConfigParser/src/ns_reader.cpp +++ /dev/null @@ -1,36 +0,0 @@ -/* - * @copyright Copyright (c) 2016-2020 TOYOTA MOTOR CORPORATION. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -//////////////////////////////////////////////////////////////////////////////////////////////////// -/// \ingroup tag_NS_ConfigParser -/// \brief This file contains implementation of IConfigReader class. -/// -//////////////////////////////////////////////////////////////////////////////////////////////////// - -//////////////////////////////////////////////////////////////////////////////////////////////////// -// Include Files -//////////////////////////////////////////////////////////////////////////////////////////////////// -#include <native_service/ns_reader.h> -#include <ns_config_parser_frameworkunifiedlog.h> - - -IConfigReader::IConfigReader() { - FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+"); -} - -IConfigReader::~IConfigReader() { - FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+"); -} diff --git a/nsframework/framework_unified/client/NS_ConfigParser/src/ns_writer.cpp b/nsframework/framework_unified/client/NS_ConfigParser/src/ns_writer.cpp deleted file mode 100755 index b2b52f0..0000000 --- a/nsframework/framework_unified/client/NS_ConfigParser/src/ns_writer.cpp +++ /dev/null @@ -1,36 +0,0 @@ -/* - * @copyright Copyright (c) 2016-2020 TOYOTA MOTOR CORPORATION. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -//////////////////////////////////////////////////////////////////////////////////////////////////// -/// \ingroup tag_NS_ConfigParser -/// \brief This file contains implementation of IConfigWriter class. -/// -//////////////////////////////////////////////////////////////////////////////////////////////////// - -//////////////////////////////////////////////////////////////////////////////////////////////////// -// Include Files -//////////////////////////////////////////////////////////////////////////////////////////////////// -#include <native_service/ns_writer.h> -#include <ns_config_parser_frameworkunifiedlog.h> - - -IConfigWriter::IConfigWriter() { - FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+"); -} - -IConfigWriter::~IConfigWriter() { - FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+"); -} |