From eeacf9d5edd4ce70aeb9b6f38525926021386306 Mon Sep 17 00:00:00 2001 From: ToshikazuOhiwa Date: Mon, 30 Mar 2020 09:43:24 +0900 Subject: ss-versionlibrary branch --- system_service.mk | 44 +++ version_library/LICENSE | 177 +++++++++++ version_library/Makefile.client | 19 ++ version_library/library/Makefile | 37 +++ .../library/include/system_service/ss_ver.h | 338 +++++++++++++++++++++ .../include/system_service/version_library.h | 40 +++ version_library/library/src/ss_ver.cc | 309 +++++++++++++++++++ 7 files changed, 964 insertions(+) create mode 100644 system_service.mk create mode 100644 version_library/LICENSE create mode 100644 version_library/Makefile.client create mode 100644 version_library/library/Makefile create mode 100644 version_library/library/include/system_service/ss_ver.h create mode 100644 version_library/library/include/system_service/version_library.h create mode 100644 version_library/library/src/ss_ver.cc diff --git a/system_service.mk b/system_service.mk new file mode 100644 index 00000000..a8a06b06 --- /dev/null +++ b/system_service.mk @@ -0,0 +1,44 @@ +############################################################# +# +# Common Makefile for system_service +# Copyright (C) 2017-2019 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. +# +############################################################# + +CURRENT_DIR := $(dir $(lastword $(MAKEFILE_LIST))) + +############################################################# +# COMPONENT_NAME must not be blank and be named snake_case + +COMPONENT_NAME := system_service + +############################################################# + + + +############################################################# +# You can add several flags and libraries. +# When you add -I or -L path, DO NOT USE relative path. +# Instead, use $(CURRENT_DIR) variable +# that indicates the path this .mk file is stored. + +COMPONENT_CFLAGS := +COMPONENT_CXXFLAGS := +COMPONENT_LDLIBS := +COMPONENT_LDFLAGS := + +############################################################## + +include $(SDKTARGETSYSROOT)/usr/agl/share/agl.mk diff --git a/version_library/LICENSE b/version_library/LICENSE new file mode 100644 index 00000000..f433b1a5 --- /dev/null +++ b/version_library/LICENSE @@ -0,0 +1,177 @@ + + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS diff --git a/version_library/Makefile.client b/version_library/Makefile.client new file mode 100644 index 00000000..240fc489 --- /dev/null +++ b/version_library/Makefile.client @@ -0,0 +1,19 @@ +# +# @copyright Copyright (c) 2017-2019 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. +# + +SUBDIRS := library + +include ../system_service.mk diff --git a/version_library/library/Makefile b/version_library/library/Makefile new file mode 100644 index 00000000..65d2780e --- /dev/null +++ b/version_library/library/Makefile @@ -0,0 +1,37 @@ +# +# @copyright Copyright (c) 2016-2019 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. +# + +# installed shared library(.so) +INST_SHLIBS := libssver + +# compiled source +libssver_SRCS := ss_ver.cc + +# installed header +INST_HEADERS := version_library.h ss_ver.h + +# additional source path +VPATH += ./src \ + ./include/$(COMPONENT_NAME) + +# additional include path +CPPFLAGS += -I./include + +# linked library +LDFLAGS += -Wl,--no-as-needed +LDLIBS += -Wl,-Bdynamic,--no-as-needed -lNS_FrameworkUnified + +include ../../system_service.mk diff --git a/version_library/library/include/system_service/ss_ver.h b/version_library/library/include/system_service/ss_ver.h new file mode 100644 index 00000000..70d6b86a --- /dev/null +++ b/version_library/library/include/system_service/ss_ver.h @@ -0,0 +1,338 @@ +/* + * @copyright Copyright (c) 2016-2019 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. + */ + +#ifndef VERSION_LIBRARY_LIBRARY_INCLUDE_SYSTEM_SERVICE_SS_VER_H_ +#define VERSION_LIBRARY_LIBRARY_INCLUDE_SYSTEM_SERVICE_SS_VER_H_ + +#include +#include +#include +#include + +/** + * @file ss_ver.h + * @brief \~english This file supports CSSVer class, This class is a generic CSSVer abstraction + */ +/** @addtogroup BaseSystem + * @{ + */ +/** @addtogroup system_service + * @ingroup BaseSystem + * @{ + */ +/** @addtogroup version_library + * @ingroup system_service + * @{ + */ + +using namespace std; // NOLINT (readability/nolint) + +#define SSVER_VERCHAR_MAX (64) +#define SSVER_DATE_MAX (16) + +/** +* @struct SSVER_PkgInfo +* @brief \~english The structure of version package information +*/ +typedef struct { + char version[SSVER_VERCHAR_MAX]; /*!< \~english Version information (String):*/ + /*!< \~english The termination of string must be "\0"*/ + char date[SSVER_DATE_MAX]; /*!< \~english Date (String):The termination of string must be "\0" */ + /*!< \~english Date (String):Store "\0" when date information does not exist.*/ +} SSVER_PkgInfo; + +typedef std::map SSVerPkgList; +typedef SSVerPkgList::const_iterator SSVerPkgListIter; + +/////////////////////////////////////////////////////////////////////////////////////////////////// +// \ingroup SS_SystemManager +/////////////////////////////////////////////////////////////////////////////////////////////////// +// \brief This class is a generic CSSVer abstraction +/////////////////////////////////////////////////////////////////////////////////////////////////// +/** + * @class CSSVer + * \~english @brief Version information set-up/acquisition + * \~english @par Brief Introduction + * Class to provide the function of the version information set-up/acquisition + * + */ +class CSSVer { + private: + SSVerPkgList m_verList; + void dump(void) const; + + public: + ///////////////////////////////////////////////////////////////////////////////////// + /// \ingroup SS_SystemManager + /// \~english @par Summary + /// Constructor for CSSVer class + /// \~english @param None + /// \~english @retval None + /// \~english @par Preconditions + /// - None + /// \~english @par Changes of the internal state + /// - The internal state is not changed. + /// \~english @par Causes of failures + /// None + /// \~english @par Classification + /// Public + /// \~english @par Type + /// None + /// \~english @par Detail + /// Creates the instance of CSSVer class. \n + /// This API reads the version information registered in VersionDB and creates the package + /// lists inside a instance. \n + /// This can create some instances at the same time. \n + /// Meanwhile, this does not guarantee the action when some threads + /// inside same process access to same instances. \n + /// It is possible that version information is overwritten from other process but the information overwritten + /// at other process is not reflected into the version information held inside self-instance. + /// By this, it is necessary to recreate an instance to get the latest information. \n + /// \~english @see ~CSSVer + //////////////////////////////////////////////////////////////////////////////////// + CSSVer(); + + ///////////////////////////////////////////////////////////////////////////////////// + /// \ingroup SS_SystemManager + /// \~english @par Summary + /// Destructor for CSSVer class + /// \~english @param None + /// \~english @retval None + /// \~english @par Preconditions + /// - None + /// \~english @par Changes of the internal state + /// - The internal state is not changed. + /// \~english @par Causes of failures + /// None + /// \~english @par Classfication + /// Public + /// \~english @par Type + /// None + /// \~english @par Detail + /// Releases the instance of CSSVer class. + /// \~english @see CSSVer + //////////////////////////////////////////////////////////////////////////////////// + ~CSSVer(); + + // Wrapper + ///////////////////////////////////////////////////////////////////////////////////// + /// \ingroup SS_SystemManager + /// \~english @par Summary + /// Returns the first iterator of package list. + /// \~english @param None + /// \~english @retval SSVerPkgListIter The first iterator of package list + /// \~english @par + /// The structure of version package information + /// \~english @code + /// #define SSVER_VERCHAR_MAX (64) + /// #define SSVER_DATE_MAX (16) + /// typedef struct{ + /// char version[SSVER_VERCHAR_MAX]; /* Version information (String): The termination of + /// string must be "\0" */ + /// char date[SSVER_DATE_MAX]; /* Date (String): The termination of string must be "\0"*/ + /// /* Store "\0" when date information does not exist. */ + /// }SSVER_PkgInfo; + /// + /// typedef std::map SSVerPkgList; /* Package list definition */ + /// typedef SSVerPkgList::const_iterator SSVerPkgListIter; /* Iterator definition of package list */ + /// @endcode + /// \~english @par Preconditions + /// - None + /// \~english @par Changes of the internal state + /// - The internal state is not changed. + /// \~english @par Causes of failures + /// None + /// \~english @par Classification + /// Public + /// \~english @par Type + /// Sync only(None communication) + /// \~english @par Detail + /// Gets and returns the first iterator of package list from the package list inside an instance. + /// \~english @see end + //////////////////////////////////////////////////////////////////////////////////// + SSVerPkgListIter begin() { + return m_verList.begin(); + } + + ///////////////////////////////////////////////////////////////////////////////////// + /// \ingroup SS_SystemManager + /// \~english @par Summary + /// Returns the end iterator of package list. + /// \~english @param None + /// \~english @retval SSVerPkgListIter The end iterator of package list + /// \~english @par + /// The structure of version package information + /// \~english @code + /// #define SSVER_VERCHAR_MAX (64) + /// #define SSVER_DATE_MAX (16) + /// typedef struct{ + /// char version[SSVER_VERCHAR_MAX]; /* Version information (String): The termination of + /// string must be "\0" */ + /// char date[SSVER_DATE_MAX]; /* Date (String): The termination of string must be "\0" */ + /// /* Store "\0" when date information does not exist. */ + /// }SSVER_PkgInfo; + /// + /// typedef std::map SSVerPkgList; /* Package list definition */ + /// typedef SSVerPkgList::const_iterator SSVerPkgListIter; /* Iterator definition of package list */ + /// @endcode + /// \~english @par Preconditions + /// - None + /// \~english @par Changes of the internal state + /// - The internal state is not changed. + /// \~english @par Causes of failures + /// None + /// \~english @par Classification + /// Public + /// \~english @par Type + /// Sync only(None communication) + /// \~english @par Detail + /// Gets and returns the last iterator of package list from the package list inside a instance. + /// \~english @see begin + //////////////////////////////////////////////////////////////////////////////////// + SSVerPkgListIter end() { + return m_verList.end(); + } + + ///////////////////////////////////////////////////////////////////////////////////// + /// \ingroup SS_SystemManager + /// \~english @par Summary + /// Checks whether data exists in package list or not. + /// \~english @param None + /// \~english @retval bool The possibility of data existence of package list + /// \~english @par + /// - true : Data does not exist + /// - false : Data exists + /// \~english @par Preconditions + /// - None + /// \~english @par Changes of the internal state + /// - The internal state is not changed. + /// \~english @par Causes of failures + /// None + /// \~english @par Classification + /// Public + /// \~english @par Type + /// Sync only(None communication) + /// \~english @par Detail + /// Returns true when package list is null and return false when data exists. + /// \~english @see None + //////////////////////////////////////////////////////////////////////////////////// + bool empty() { + return m_verList.empty(); + } + + // Setter,getter + ///////////////////////////////////////////////////////////////////////////////////// + /// \ingroup SS_SystemManager + /// \~english @par Summary + /// Gets the package information of specified package. + /// \~english @param [in] name + /// std::string & - Package name + /// \~english @param [out] p_info + /// SSVER_PkgInfo* - Pointer to the storage area of package information + /// \~english @par + /// The structure of version package information + /// \~english @code + /// #define SSVER_VERCHAR_MAX (64) + /// #define SSVER_DATE_MAX (16) + /// typedef struct{ + /// char version[SSVER_VERCHAR_MAX]; /* Version information (String): The termination of + /// string must be "\0" */ + /// char date[SSVER_DATE_MAX]; /* Date (String): The termination of string must be "\0" */ + /// /* Store "\0" when date information does not exist. */ + /// }SSVER_PkgInfo; + /// + /// typedef std::map SSVerPkgList; /* Package list definition */ + /// typedef SSVerPkgList::const_iterator SSVerPkgListIter; /* Iterator definition of package list */ + /// @endcode + /// \~english @retval eFrameworkunifiedStatusOK Succeeded in getting package information + /// \~english @retval eFrameworkunifiedStatusFileLoadError Loading error for file + /// \~english @retval eFrameworkunifiedStatusFail Failed at some process + /// \~english @par Preconditions + /// - None + /// \~english @par Changes of the internal state + /// - The internal state is not changed. + /// \~english @par Causes of failures + /// - Pointer(p_info) to the storage area for package information specified + /// by parameters is NULL. [eFrameworkunifiedStatusFail] + /// - Package information does not exist. [eFrameworkunifiedStatusFileLoadError] + /// - Unexpected error occurs. [eFrameworkunifiedStatusFail] + /// \~english @par Classification + /// Public + /// \~english @par Type + /// Sync only(None communication) + /// \~english @par Detail + /// Returns this package information if the package name specified by parameters exists + /// in the package information list inside an instance. + /// This API reads and returns the package information from package + /// information storing files if it does not exist. \n + /// This adds the package information read from files to the package information list + /// inside an instance. \n + /// When other CSSVer instance (B) adds package from setPkgInfo during creating instance (A), + /// after that, this API can get the package information added by instance (A). + /// \~english @see setPkgInfo + //////////////////////////////////////////////////////////////////////////////////// + EFrameworkunifiedStatus getPkgInfo(const std::string &name, SSVER_PkgInfo* p_info); + + ///////////////////////////////////////////////////////////////////////////////////// + /// \ingroup SS_SystemManager + /// \~english @par Summary + /// Sets the package information of specified package. + /// \~english @param [in] name + /// std::string & - Package name + /// \~english @param [in] info + /// SSVER_PkgInfo* - Package information + /// \~english @par + /// The structure of version package information + /// \~english @code + /// #define SSVER_VERCHAR_MAX (64) + /// #define SSVER_DATE_MAX (16) + /// typedef struct{ + /// char version[SSVER_VERCHAR_MAX]; /* Version information (String): The termination of + /// string must be "\0" */ + /// char date[SSVER_DATE_MAX]; /* Date (String): The termination of string must be \ */ + /// /* Store "\0" when date information does not exist. */ + /// }SSVER_PkgInfo; + /// + /// typedef std::map SSVerPkgList; /* Package list definition */ + /// typedef SSVerPkgList::const_iterator SSVerPkgListIter; /* Iterator definition of package list */ + /// @endcode + /// \~english @retval eFrameworkunifiedStatusOK Succeeded in setting package information + /// \~english @retval eFrameworkunifiedStatusFail Faild at some process + /// \~english @par Preconditions + /// - None + /// \~english @par Changes of the internal state + /// - The internal state is not changed. + /// \~english @par Causes of failures + /// - Unexpected error occurs [eFrameworkunifiedStatusFail] + /// \~english @par Classification + /// Public + /// \~english @par Type + /// Sync only(None communication) + /// \~english @par Detail + /// Sets the package information specified by parameters and update VersionDB. \n + /// When some package information exists in the package information list inside an instance, + /// this API adds the package information specified by parameters to the package + /// information list inside an instance, + /// and writes the package information specified by parameters in package information storing files. \n + /// When package information does not exist in the package information list inside an instance, + /// this sets the package information specified by parameters to the package information list inside an instance + /// and writes the package information specified by parameters in package information storing files. + /// \~english @see getPkgInfo + //////////////////////////////////////////////////////////////////////////////////// + EFrameworkunifiedStatus setPkgInfo(const std::string &name, SSVER_PkgInfo &info); // NOLINT (readability/nolint) +}; + +#endif // VERSION_LIBRARY_LIBRARY_INCLUDE_SYSTEM_SERVICE_SS_VER_H_ diff --git a/version_library/library/include/system_service/version_library.h b/version_library/library/include/system_service/version_library.h new file mode 100644 index 00000000..b4a73048 --- /dev/null +++ b/version_library/library/include/system_service/version_library.h @@ -0,0 +1,40 @@ +// +// @copyright Copyright (c) 2017-2019 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. +// +/** + * @file version_library.h + * @brief \~english This file include ss_ver.h + */ +/** @addtogroup BaseSystem + * @{ + */ +/** @addtogroup system_service + * @ingroup BaseSystem + * @{ + */ +/** @addtogroup version_library + * @ingroup system_service + * @{ + */ +// Include guard +#ifndef SYSTEMSERVICE_VERSIONLIBRARY_H_ // NOLINT(build/header_guard) +#define SYSTEMSERVICE_VERSIONLIBRARY_H_ + +#include "system_service/ss_ver.h" + +#endif // SYSTEMSERVICE_VERSIONLIBRARY_H_ +/** @}*/ +/** @}*/ +/** @}*/ diff --git a/version_library/library/src/ss_ver.cc b/version_library/library/src/ss_ver.cc new file mode 100644 index 00000000..ab1900a4 --- /dev/null +++ b/version_library/library/src/ss_ver.cc @@ -0,0 +1,309 @@ +/* + * @copyright Copyright (c) 2016-2019 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. + */ + +#include +#include +#include +#include +#include +#include + +#include +#include + +#include + +// For DEBUG +#define ZONE_INIT ZONEMASK(10) +#define ZONE_FUNC ZONEMASK(11) +#define ZONE_MEM ZONEMASK(12) +#define ZONE_INFO ZONEMASK(29) +#define ZONE_WARN ZONEMASK(30) +#define ZONE_ERR ZONEMASK(31) + +#define ZONE_DEFAULT ZONE_FUNC + +#define SSVER_TMPDIR "/tmp/ssver" + +// FILE IO +class CPkgInfoIo { + private: + int m_fd; + std::string m_path; + static std::map m_dbgCnt; // Debug information for exclusive leakage check + + void openFD(const int32_t mode) { + m_fd = open(m_path.c_str(), mode, 0664); // LCOV_EXCL_BR_LINE 11:except,C++ STL + if (m_fd == -1) { + SS_ASERT_ERRNO(0); // LCOV_EXCL_BR_LINE 15: marco defined in ss_templates.h + throw eFrameworkunifiedStatusFail; + } + + // File lock to protect file accesses + SS_ASERT_ERRNO(0 == flock(m_fd, LOCK_EX)); // LCOV_EXCL_BR_LINE 15: marco defined in ss_templates.h + // LCOV_EXCL_BR_START 11:Unexpected branch + m_dbgCnt[m_path]++; + SS_ASERT_LOG(m_dbgCnt[m_path] == 1, "%s:%d", m_path.c_str(), // LCOV_EXCL_BR_LINE 15: marco define @ss_templates.h + m_dbgCnt[m_path]); + // LCOV_EXCL_BR_STOP + } + +public: + CPkgInfoIo(const std::string& pkgName) + : m_fd(-1), + m_path(SSVER_TMPDIR) { // LCOV_EXCL_BR_LINE 11:Unexpected branch + FRAMEWORKUNIFIEDLOG(ZONE_DEFAULT,__FUNCTION__,"+:%s",pkgName.c_str()); + m_path += "/"; + m_path += pkgName; + + FRAMEWORKUNIFIEDLOG(ZONE_DEFAULT,__FUNCTION__,"-"); + } + + ~CPkgInfoIo() { + FRAMEWORKUNIFIEDLOG(ZONE_DEFAULT, __FUNCTION__, "+"); + + // LCOV_EXCL_BR_START 11:Unexpected branch + m_dbgCnt[m_path]--; + SS_ASERT_LOG(m_dbgCnt[m_path] == 0, "%s:%d", m_path.c_str(), // LCOV_EXCL_BR_LINE 15: marco define @ss_templates.h + m_dbgCnt[m_path]); + SS_ASERT_ERRNO(0 == flock(m_fd, LOCK_UN)); // LCOV_EXCL_BR_LINE 15: marco defined in ss_templates.h + + if (m_fd != -1) { + SS_ASERT_ERRNO(0 == close(m_fd)); // LCOV_EXCL_BR_LINE 15: marco defined in ss_templates.h + } + // LCOV_EXCL_BR_STOP + FRAMEWORKUNIFIEDLOG(ZONE_DEFAULT, __FUNCTION__, "-"); + } + + void putData(SSVER_PkgInfo &info) { // NOLINT (readability/nolint) + FRAMEWORKUNIFIEDLOG(ZONE_DEFAULT, __FUNCTION__, "+"); + openFD(O_RDWR|O_CREAT|O_CLOEXEC); + ssize_t wsz; + wsz = write(m_fd, &info, sizeof(info)); + if (wsz != sizeof(info)) { // LCOV_EXCL_BR_LINE 5:std c lib error process + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + + FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "Failed write(). wsz=%d size=%d errno=%d", // LCOV_EXCL_LINE 5: glibc fail safe + wsz, sizeof(info), errno); // LCOV_EXCL_LINE 5:std c lib error process + throw eFrameworkunifiedStatusFail; // LCOV_EXCL_LINE 5:std c lib error process + } + FRAMEWORKUNIFIEDLOG(ZONE_DEFAULT, __FUNCTION__, "-"); + } + + void getData(SSVER_PkgInfo* p_info) { + FRAMEWORKUNIFIEDLOG(ZONE_DEFAULT, __FUNCTION__, "+"); + openFD(O_RDONLY|O_CLOEXEC); + + ssize_t rsz; + rsz = my_read(m_fd, p_info, sizeof(*p_info)); + if (rsz != sizeof(*p_info)) { // LCOV_EXCL_BR_LINE 5:std c lib error process + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + + FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "Failed read(). rsz=%d size=%d", rsz, // LCOV_EXCL_LINE 5:std c lib error process + sizeof(*p_info)); // LCOV_EXCL_LINE 5:std c lib error process + p_info->version[0] = '\0'; // LCOV_EXCL_LINE 5:std c lib error process + p_info->date[0] = '\0'; // LCOV_EXCL_LINE 5:std c lib error process + throw eFrameworkunifiedStatusFail; // LCOV_EXCL_LINE 5:std c lib error process + } + FRAMEWORKUNIFIEDLOG(ZONE_DEFAULT, __FUNCTION__, "-"); + } + + int my_read(int fd, void* buf, int size) { + int done = 0; + char *buffer = reinterpret_cast(buf); + int sz = done; + + while (size > 0) { + done = read(fd, buffer + done, size); + if (done < 0) { // LCOV_EXCL_BR_LINE 5:std c lib error process + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + + SS_ASERT_ERRNO(0); // LCOV_EXCL_LINE 5:std c lib error process + if (errno == EINTR) { // LCOV_EXCL_LINE 5:std c lib error process + continue; + } else { + return done; + } + } else if (done == 0) { // LCOV_EXCL_BR_LINE 5:std c lib error process + return sz; + } + size -= done; + sz += done; + } + return sz; + } +}; + +std::map CPkgInfoIo::m_dbgCnt; // Actual status + +//================================================================== +// private +//================================================================== +void CSSVer::dump(void) const { // LCOV_EXCL_START 7:debugging process + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + + std::string dumpStr; + dumpStr = "VERINFO DUMP\n"; + + for (SSVerPkgList::const_iterator ite = m_verList.begin(); + ite != m_verList.end(); ite++) { + dumpStr += ite->first; + dumpStr += "\n"; + dumpStr += ite->second.version; + dumpStr += "\n"; + dumpStr += ite->second.date; + dumpStr += "\n"; + } + + FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "%s", dumpStr.c_str()); +} +// LCOV_EXCL_STOP + +//================================================================== +// PUBLIC +//================================================================== +CSSVer::CSSVer() { + FRAMEWORKUNIFIEDLOG(ZONE_DEFAULT, __FUNCTION__, "+"); + DIR *dir = NULL; + struct dirent dent, *next; + struct stat statbuf; + + try { + if (stat(SSVER_TMPDIR, &statbuf) != 0) { + mkdir(SSVER_TMPDIR, 0775); + // Because this process is not locked, if multiple processes process at the same time, + // although it may have been created and fail, do not ASSERT it because it is harmless. + } + + // Linux dependency codes + if ((dir = opendir(SSVER_TMPDIR)) == NULL) { // LCOV_EXCL_BR_LINE 5:std c lib error process + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + + SS_ASERT_ERRNO(0); // LCOV_EXCL_LINE 5:std c lib error process + throw eFrameworkunifiedStatusFail; + } + + // LCOV_EXCL_BR_START 11:Unexpected branch + while (0 == readdir_r(dir, &dent, &next) && next) { + if (DT_REG == dent.d_type) { + SSVER_PkgInfo info; + std::string name(dent.d_name); + std::string verInfo; + + CPkgInfoIo pkgIo(name); + pkgIo.getData(&info); + + verInfo += "\nPACKAGE :"; + verInfo += name; + verInfo += "\n"; + verInfo += " VERSION:"; + verInfo += info.version; + verInfo += "\n"; + verInfo += " DATE :"; + verInfo += info.date; + verInfo += "\n"; + FRAMEWORKUNIFIEDLOG(ZONE_DEFAULT, __FUNCTION__, "%s", verInfo.c_str()); + + m_verList.insert(std::make_pair(name, info)); + } + } + SS_ASERT_ERRNO(0 == closedir(dir)); // LCOV_EXCL_BR_LINE 15: marco defined in ss_templates.h + // LCOV_EXCL_BR_STOP + } catch (...) { // LCOV_EXCL_START 6:unable to reach + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + + if (dir) { + SS_ASERT_ERRNO(0 == closedir(dir)); + } + } // LCOV_EXCL_STOP + FRAMEWORKUNIFIEDLOG(ZONE_DEFAULT, __FUNCTION__, "-"); +} + +CSSVer::~CSSVer() { + FRAMEWORKUNIFIEDLOG(ZONE_DEFAULT, __FUNCTION__, "+"); + FRAMEWORKUNIFIEDLOG(ZONE_DEFAULT, __FUNCTION__, "-"); +} + +EFrameworkunifiedStatus CSSVer::getPkgInfo(const std::string &name, SSVER_PkgInfo* p_info) { + FRAMEWORKUNIFIEDLOG(ZONE_DEFAULT, __FUNCTION__, "+"); + EFrameworkunifiedStatus versionlibraryRet = eFrameworkunifiedStatusOK; + try { + if (p_info == NULL) { + SS_ASERT(0); // LCOV_EXCL_BR_LINE 15: marco defined in ss_templates.h + throw eFrameworkunifiedStatusFail; + } + + SSVerPkgList::iterator ite = m_verList.find(name); + + if (ite != m_verList.end()) { + // cache hit + *p_info = ite->second; + } else { + // cache miss + std::string path(SSVER_TMPDIR); // LCOV_EXCL_BR_LINE 11:except,C++ STL + path += "/"; + path += name; + + if (access(path.c_str(), F_OK) == 0) { + // cache refresh + CPkgInfoIo pkgIo(name); // LCOV_EXCL_BR_LINE 11:Unexpected branch + pkgIo.getData(p_info); // LCOV_EXCL_BR_LINE 11:except,C++ STL + m_verList.insert(std::make_pair(name, *p_info)); // LCOV_EXCL_BR_LINE 11:except,C++ STL + } else { + throw eFrameworkunifiedStatusFileLoadError; + } + } + } catch (EFrameworkunifiedStatus ee) { + versionlibraryRet = ee; + } catch (...) { // LCOV_EXCL_START 6:unable to reach + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + + versionlibraryRet = eFrameworkunifiedStatusFail; + } // LCOV_EXCL_STOP + FRAMEWORKUNIFIEDLOG(ZONE_DEFAULT, __FUNCTION__, "-"); + return versionlibraryRet; +} + +EFrameworkunifiedStatus CSSVer::setPkgInfo(const std::string &name, SSVER_PkgInfo &info) { + FRAMEWORKUNIFIEDLOG(ZONE_DEFAULT, __FUNCTION__, "+"); + EFrameworkunifiedStatus versionlibraryRet = eFrameworkunifiedStatusOK; + try { + // LCOV_EXCL_BR_START 11:Unexpected branch + SSVerPkgList::iterator ite = m_verList.find(name); + + if (ite == m_verList.end()) { + m_verList.insert(std::make_pair(name, info)); + CPkgInfoIo pkgIo(name); + pkgIo.putData(info); + } else { + ite->second = info; + CPkgInfoIo pkgIo(name); + pkgIo.putData(info); + } + // LCOV_EXCL_BR_STOP + } catch (EFrameworkunifiedStatus ee) { + versionlibraryRet = ee; + } catch (...) { // LCOV_EXCL_START 6:unable to reach + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + + SS_ASERT(0); // LCOV_EXCL_BR_LINE 15: marco defined in ss_templates.h + versionlibraryRet = eFrameworkunifiedStatusFail; + } // LCOV_EXCL_STOP + + FRAMEWORKUNIFIEDLOG(ZONE_DEFAULT, __FUNCTION__, "-"); + return versionlibraryRet; +} // LCOV_EXCL_BR_LINE 10:for the last line + -- cgit 1.2.3-korg