diff options
author | takeshi_hoshina <takeshi_hoshina@mail.toyota.co.jp> | 2020-10-27 11:16:21 +0900 |
---|---|---|
committer | takeshi_hoshina <takeshi_hoshina@mail.toyota.co.jp> | 2020-10-27 11:16:21 +0900 |
commit | 947c78887e791596d4a5ec2d1079f8b1a049628b (patch) | |
tree | 3981e88eb8764d7180722f8466f36b756dc005af /nsframework/framework_unified/client/NS_ConfigParser/include | |
parent | 706ad73eb02caf8532deaf5d38995bd258725cb8 (diff) |
basesystem 0.1sandbox/ToshikazuOhiwa/basesystem
Diffstat (limited to 'nsframework/framework_unified/client/NS_ConfigParser/include')
5 files changed, 569 insertions, 0 deletions
diff --git a/nsframework/framework_unified/client/NS_ConfigParser/include/ns_cfg_internal.h b/nsframework/framework_unified/client/NS_ConfigParser/include/ns_cfg_internal.h new file mode 100644 index 00000000..64aad8b0 --- /dev/null +++ b/nsframework/framework_unified/client/NS_ConfigParser/include/ns_cfg_internal.h @@ -0,0 +1,54 @@ +/* + * @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 the declaration of internal structure for parsing cfg configuration +/// file. +/// +//////////////////////////////////////////////////////////////////////////////////////////////////// + +#ifndef FRAMEWORK_UNIFIED_CLIENT_NS_CONFIGPARSER_INCLUDE_NS_CFG_INTERNAL_H_ +#define FRAMEWORK_UNIFIED_CLIENT_NS_CONFIGPARSER_INCLUDE_NS_CFG_INTERNAL_H_ + +//////////////////////////////////////////////////////////////////////////////////////////////////// +// Include Files +//////////////////////////////////////////////////////////////////////////////////////////////////// +#include <string> +#include <vector> + +class CNode { + public: + CNode(): m_cComment(""), m_cTag(""), m_cValue("") {} // LCOV_EXCL_BR_LINE 11:except branch + + ~CNode() {} + + std::string m_cComment; + std::string m_cTag; + std::string m_cValue; +}; + +class CBlock { + public: + CBlock(): m_cComment("") {} // LCOV_EXCL_BR_LINE 11:except branch + + ~CBlock() {} + + std::string m_cComment; + std::vector<CNode> m_vElementPair; +}; + +#endif // FRAMEWORK_UNIFIED_CLIENT_NS_CONFIGPARSER_INCLUDE_NS_CFG_INTERNAL_H_ diff --git a/nsframework/framework_unified/client/NS_ConfigParser/include/ns_cfg_parser.h b/nsframework/framework_unified/client/NS_ConfigParser/include/ns_cfg_parser.h new file mode 100644 index 00000000..8d7a47fd --- /dev/null +++ b/nsframework/framework_unified/client/NS_ConfigParser/include/ns_cfg_parser.h @@ -0,0 +1,148 @@ +/* + * @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 the declaration of class CCFGParser. +/// This class contains the parsing logic for reading and writing from and to cfg files +/// respectively. +/// +//////////////////////////////////////////////////////////////////////////////////////////////////// + +#ifndef FRAMEWORK_UNIFIED_CLIENT_NS_CONFIGPARSER_INCLUDE_NS_CFG_PARSER_H_ +#define FRAMEWORK_UNIFIED_CLIENT_NS_CONFIGPARSER_INCLUDE_NS_CFG_PARSER_H_ + +//////////////////////////////////////////////////////////////////////////////////////////////////// +// Include Files +//////////////////////////////////////////////////////////////////////////////////////////////////// +#include <native_service/frameworkunified_types.h> +#include <string> +#include <map> + +// forward declaration of classes +class CNode; +class CBlock; + +typedef std::map<std::string, CBlock *> CFGData_Type; + +class CCFGParser { + public: + //////////////////////////////////////////////////////////////////////////////////////////////// + /// CCFGParser + /// Constructor of CCFGReader class + /// + /// \param + /// + /// \return + /// + //////////////////////////////////////////////////////////////////////////////////////////////// + CCFGParser(); + + //////////////////////////////////////////////////////////////////////////////////////////////// + /// CCFGParser + /// Constructor of CCFGReader class + /// + /// \param [IN] f_c_filepath + /// std::string - Full path of the configuration file + /// + /// \return + /// + //////////////////////////////////////////////////////////////////////////////////////////////// + explicit CCFGParser(const std::string &f_c_filepath); + + //////////////////////////////////////////////////////////////////////////////////////////////// + /// ~CCFGParser + /// Destructor of CCFGReader class + /// + /// \param + /// + /// \return + /// + //////////////////////////////////////////////////////////////////////////////////////////////// + ~CCFGParser(); + + //////////////////////////////////////////////////////////////////////////////////////////////// + /// CFGParseFile + /// This function is used to parse the configuration file and store data in internal structure + /// + /// \param [IN] f_c_filepath + /// std::string - full path of the configuration file + /// + /// \return EFrameworkunifiedStatus - success or failure + /// + //////////////////////////////////////////////////////////////////////////////////////////////// + EFrameworkunifiedStatus CFGParseFile(const std::string &f_c_filepath); + + //////////////////////////////////////////////////////////////////////////////////////////////// + /// CFGGetData + /// This function is used to get the value associated with the key from internal CFG structure + /// + /// \param [IN] f_c_key + /// std::string - key to search + /// + /// \return std::string - value for key + /// + //////////////////////////////////////////////////////////////////////////////////////////////// + std::string CFGGetData(const std::string &f_c_key); + + //////////////////////////////////////////////////////////////////////////////////////////////// + /// CFGGetData + /// This function is used to get the value associated with the key from internal CFG structure + /// + /// \param [IN] f_c_key + /// std::string - key to search + /// \param [IN] f_c_value + /// std::string - Value of key + /// + /// \return EFrameworkunifiedStatus + /// EFrameworkunifiedStatus - error if key not founf or else eFrameworkunifiedStatusOK + /// + //////////////////////////////////////////////////////////////////////////////////////////////// + EFrameworkunifiedStatus CFGGetData(const std::string &f_c_key, std::string &f_c_value); // NOLINT (readability/nolint) + + //////////////////////////////////////////////////////////////////////////////////////////////// + /// CFGSetData + /// This function is used to set the value for the key in internal CFG structure + /// + /// \param [IN] f_c_key + /// std::string - key to search + /// \param [IN] f_c_value + /// std::string - value to set + /// + /// \return EFrameworkunifiedStatus - success or failure + /// + //////////////////////////////////////////////////////////////////////////////////////////////// + EFrameworkunifiedStatus CFGSetData(const std::string &f_c_key, std::string f_c_value); + + //////////////////////////////////////////////////////////////////////////////////////////////// + /// CFGSaveData + /// This function is used to save the changed value to the cfg config file + /// + /// \param [IN] f_c_filepath + /// std::string - full path of the configuration file + /// + /// \return EFrameworkunifiedStatus - success or failure + /// + //////////////////////////////////////////////////////////////////////////////////////////////// + EFrameworkunifiedStatus CFGSaveData(const std::string &f_c_filepath); + + private: + // internal data structure created by parsing the cfg file + CFGData_Type *m_pmCFGData; + std::string m_cLastComment; +}; + +#endif // FRAMEWORK_UNIFIED_CLIENT_NS_CONFIGPARSER_INCLUDE_NS_CFG_PARSER_H_ diff --git a/nsframework/framework_unified/client/NS_ConfigParser/include/ns_cfg_reader.h b/nsframework/framework_unified/client/NS_ConfigParser/include/ns_cfg_reader.h new file mode 100644 index 00000000..d47c04b1 --- /dev/null +++ b/nsframework/framework_unified/client/NS_ConfigParser/include/ns_cfg_reader.h @@ -0,0 +1,133 @@ +/* + * @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 declaration of class CCFGReader. +/// +//////////////////////////////////////////////////////////////////////////////////////////////////// + +#ifndef FRAMEWORK_UNIFIED_CLIENT_NS_CONFIGPARSER_INCLUDE_NS_CFG_READER_H_ +#define FRAMEWORK_UNIFIED_CLIENT_NS_CONFIGPARSER_INCLUDE_NS_CFG_READER_H_ + +//////////////////////////////////////////////////////////////////////////////////////////////////// +// Include Files +//////////////////////////////////////////////////////////////////////////////////////////////////// +#include <native_service/ns_reader.h> +#include <string> + +class CCFGParser; + +/* + * This class provides functionalities to read from CFG config file + */ +class CCFGReader: public IConfigReader { + public: + //////////////////////////////////////////////////////////////////////////////////////////////// + /// CCFGReader + /// Constructor of CCFGReader class + /// + /// \param + /// + /// \return + /// + //////////////////////////////////////////////////////////////////////////////////////////////// + CCFGReader(); + + //////////////////////////////////////////////////////////////////////////////////////////////// + /// CCFGReader + /// Constructor of CCFGReader class + /// + /// \param [IN] f_c_filepath + /// std::string - Full path of the configuration file + /// + /// \return + /// + //////////////////////////////////////////////////////////////////////////////////////////////// + explicit CCFGReader(const std::string &f_c_filepath); + + //////////////////////////////////////////////////////////////////////////////////////////////// + /// ~CCFGReader + /// Destructor of CCFGReader class + /// + /// \param + /// + /// \return + /// + //////////////////////////////////////////////////////////////////////////////////////////////// + ~CCFGReader(); + + //////////////////////////////////////////////////////////////////////////////////////////////// + /// ParseFile + /// This function is used to parse the file + /// + /// \param [IN] f_c_filepath + /// std::string - path of file to parse + /// + /// \return EFrameworkunifiedStatus - success or failure + /// + //////////////////////////////////////////////////////////////////////////////////////////////// + EFrameworkunifiedStatus ParseFile(const std::string &f_c_filepath); + + //////////////////////////////////////////////////////////////////////////////////////////////// + /// GetString + /// This function is used to get the value associated with the key + /// + /// \param [IN] f_c_key + /// std::string - key to search + /// + /// \return std::string - value for key + /// + //////////////////////////////////////////////////////////////////////////////////////////////// + std::string GetValue(const std::string &f_c_key); + + //////////////////////////////////////////////////////////////////////////////////////////////// + /// GetString + /// This function is used to get the value associated with the key + /// + /// \param [IN] f_c_key + /// std::string - key to search + /// \param [REF] f_c_value + /// std::string - Value of key + /// + /// \return EFrameworkunifiedStatus + /// EFrameworkunifiedStatus - error if key not found else eFrameworkunifiedStatusOK + /// + //////////////////////////////////////////////////////////////////////////////////////////////// + EFrameworkunifiedStatus GetValue(const std::string &f_c_key, std::string &f_c_value); // NOLINT (readability/nolint) + + //////////////////////////////////////////////////////////////////////////////////////////////// + /// GetDataPtr + /// This function is used to get the data pointer. This pointer is then set in config writer. + /// This is needed to avoid recreation of same data structure object in both reader and writer + /// when we create object of NSConfigParser. + /// + /// \param + /// + /// \return PVOID - pointer of data structure + /// + //////////////////////////////////////////////////////////////////////////////////////////////// + PVOID GetDataPtr(); + + private: + // path of config file + std::string m_cFilePath; + + // CFG file parser object + CCFGParser *m_pCFGParser; +}; + +#endif // FRAMEWORK_UNIFIED_CLIENT_NS_CONFIGPARSER_INCLUDE_NS_CFG_READER_H_ diff --git a/nsframework/framework_unified/client/NS_ConfigParser/include/ns_cfg_writer.h b/nsframework/framework_unified/client/NS_ConfigParser/include/ns_cfg_writer.h new file mode 100644 index 00000000..58d16399 --- /dev/null +++ b/nsframework/framework_unified/client/NS_ConfigParser/include/ns_cfg_writer.h @@ -0,0 +1,146 @@ +/* + * @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 declaration of class CCFGWriter. +/// +//////////////////////////////////////////////////////////////////////////////////////////////////// + +#ifndef FRAMEWORK_UNIFIED_CLIENT_NS_CONFIGPARSER_INCLUDE_NS_CFG_WRITER_H_ +#define FRAMEWORK_UNIFIED_CLIENT_NS_CONFIGPARSER_INCLUDE_NS_CFG_WRITER_H_ + +//////////////////////////////////////////////////////////////////////////////////////////////////// +// Include Files +//////////////////////////////////////////////////////////////////////////////////////////////////// +#include <native_service/ns_writer.h> +#include <string> + +class CCFGParser; + +/* + * This class provides functionalities to write to CFG config file + */ +class CCFGWriter: public IConfigWriter { + public: + //////////////////////////////////////////////////////////////////////////////////////////////// + /// CCFGWriter + /// Constructor of CCFGWriter class + /// + /// \param + /// + /// \return + /// + //////////////////////////////////////////////////////////////////////////////////////////////// + CCFGWriter(); + + //////////////////////////////////////////////////////////////////////////////////////////////// + /// CCFGWriter + /// Constructor of CCFGWriter class + /// + /// \param [IN] f_c_filepath + /// std::string - Full path of the configuration file + /// + /// \return + /// + //////////////////////////////////////////////////////////////////////////////////////////////// + explicit CCFGWriter(const std::string &f_c_filepath); + + //////////////////////////////////////////////////////////////////////////////////////////////// + /// ~CCFGWriter + /// Destructor of CCFGWriter class + /// + /// \param + /// + /// \return + /// + //////////////////////////////////////////////////////////////////////////////////////////////// + ~CCFGWriter(); + + //////////////////////////////////////////////////////////////////////////////////////////////// + /// ParseFile + /// This function is used to parse the file + /// + /// \param [IN] f_c_filepath + /// std::string - path of file to parse + /// + /// \return EFrameworkunifiedStatus - success or failure + /// + //////////////////////////////////////////////////////////////////////////////////////////////// + EFrameworkunifiedStatus ParseFile(const std::string &f_c_filepath); + + //////////////////////////////////////////////////////////////////////////////////////////////// + /// SetValue + /// This function is used to set the value for the key + /// + /// \param [IN] f_c_key + /// std::string - key to search + /// \param [IN] f_c_value + /// std::string - value to set + /// + /// \return EFrameworkunifiedStatus + /// EFrameworkunifiedStatus - error if key not found else eFrameworkunifiedStatusOK + /// + //////////////////////////////////////////////////////////////////////////////////////////////// + EFrameworkunifiedStatus SetValue(const std::string &f_c_key, std::string f_c_value); + + //////////////////////////////////////////////////////////////////////////////////////////////// + /// SaveData + /// This function is used to save the changed value to the cfg config file + /// + /// \param + /// + /// \return EFrameworkunifiedStatus - success or failure + /// + //////////////////////////////////////////////////////////////////////////////////////////////// + EFrameworkunifiedStatus SaveData(); + + //////////////////////////////////////////////////////////////////////////////////////////////// + /// SetDataPtr + /// This function is used to set the config file path + /// + /// \param [IN] f_c_path + /// std::string - Path of file + /// + /// \return EFrameworkunifiedStatus - success or failure + /// + //////////////////////////////////////////////////////////////////////////////////////////////// + EFrameworkunifiedStatus SetPath(const std::string &f_c_path); + + //////////////////////////////////////////////////////////////////////////////////////////////// + /// SetDataPtr + /// This function is used to set the data pointer in writer class with data pointer + /// created in config reader class. + /// This is needed to avoid recreation of same data structure object in both reader and writer + /// when we create object of NSConfigParser + /// + /// \param [IN] f_p_data + /// PVOID - Pointer to data structure + /// + /// \return VOID + /// + //////////////////////////////////////////////////////////////////////////////////////////////// + VOID SetDataPtr(PVOID f_p_data); + + private: + // path of config file + std::string m_cFilePath; + + // CFG file parser object + CCFGParser *m_pCFGParser; +}; + +#endif // FRAMEWORK_UNIFIED_CLIENT_NS_CONFIGPARSER_INCLUDE_NS_CFG_WRITER_H_ diff --git a/nsframework/framework_unified/client/NS_ConfigParser/include/ns_config_parser_frameworkunifiedlog.h b/nsframework/framework_unified/client/NS_ConfigParser/include/ns_config_parser_frameworkunifiedlog.h new file mode 100644 index 00000000..c48f09d7 --- /dev/null +++ b/nsframework/framework_unified/client/NS_ConfigParser/include/ns_config_parser_frameworkunifiedlog.h @@ -0,0 +1,88 @@ +/* + * @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 +/// +/// +//////////////////////////////////////////////////////////////////////////////////////////////////// + +#ifndef FRAMEWORK_UNIFIED_CLIENT_NS_CONFIGPARSER_INCLUDE_NS_CONFIG_PARSER_FRAMEWORKUNIFIEDLOG_H_ +#define FRAMEWORK_UNIFIED_CLIENT_NS_CONFIGPARSER_INCLUDE_NS_CONFIG_PARSER_FRAMEWORKUNIFIEDLOG_H_ + +//////////////////////////////////////////////////////////////////////////////////////////////////// +// Include Files +//////////////////////////////////////////////////////////////////////////////////////////////////// +#include <native_service/ns_logger_if.h> + +#define ZONE_INIT ZONEMASK(10) +#define ZONE_FUNC ZONEMASK(11) +#define ZONE_MEM ZONEMASK(12) +#define ZONE_13 ZONEMASK(13) +#define ZONE_14 ZONEMASK(14) +#define ZONE_15 ZONEMASK(15) +#define ZONE_16 ZONEMASK(16) +#define ZONE_17 ZONEMASK(17) +#define ZONE_18 ZONEMASK(18) +#define ZONE_19 ZONEMASK(19) +#define ZONE_20 ZONEMASK(20) +#define ZONE_21 ZONEMASK(21) +#define ZONE_22 ZONEMASK(22) +#define ZONE_23 ZONEMASK(23) +#define ZONE_24 ZONEMASK(24) +#define ZONE_25 ZONEMASK(25) +#define ZONE_26 ZONEMASK(26) +#define ZONE_27 ZONEMASK(27) +#define ZONE_28 ZONEMASK(28) +#define ZONE_INFO ZONEMASK(29) +#define ZONE_WARN ZONEMASK(30) +#define ZONE_ERR ZONEMASK(31) + +#define ZONE_TEXT_10 "Init" +#define ZONE_TEXT_11 "Function" +#define ZONE_TEXT_12 "Memory" +#define ZONE_TEXT_13 "" +#define ZONE_TEXT_14 "" +#define ZONE_TEXT_15 "" +#define ZONE_TEXT_16 "" +#define ZONE_TEXT_17 "" +#define ZONE_TEXT_18 "" +#define ZONE_TEXT_19 "" +#define ZONE_TEXT_20 "" +#define ZONE_TEXT_21 "" +#define ZONE_TEXT_22 "" +#define ZONE_TEXT_23 "" +#define ZONE_TEXT_24 "" +#define ZONE_TEXT_25 "" +#define ZONE_TEXT_26 "" +#define ZONE_TEXT_27 "" +#define ZONE_TEXT_28 "" +#define ZONE_TEXT_29 "Info" +#define ZONE_TEXT_30 "Warning" +#define ZONE_TEXT_31 "Error" + +#ifndef FRAMEWORKUNIFIEDLOGOPTIONS +#define FRAMEWORKUNIFIEDLOGOPTIONS (LPRINT) // LPRINT , LMSGQ, LSLOGGER +#endif + +#ifndef FRAMEWORKUNIFIEDLOGZONES +// #define FRAMEWORKUNIFIEDLOGZONES (ZONE_WARN|ZONE_ERR) +#define FRAMEWORKUNIFIEDLOGZONES (ZONE_INIT|ZONE_FUNC|ZONE_INFO|ZONE_WARN|ZONE_ERR|ZONE_NS_WAR|ZONE_NS_ERR) +#endif + +extern const CHAR kAppName[]; +#endif // FRAMEWORK_UNIFIED_CLIENT_NS_CONFIGPARSER_INCLUDE_NS_CONFIG_PARSER_FRAMEWORKUNIFIEDLOG_H_ |