summaryrefslogtreecommitdiffstats
path: root/version_library/library
diff options
context:
space:
mode:
authorToshikazuOhiwa <toshikazu_ohiwa@mail.toyota.co.jp>2020-03-30 09:43:24 +0900
committerToshikazuOhiwa <toshikazu_ohiwa@mail.toyota.co.jp>2020-03-30 09:43:24 +0900
commiteeacf9d5edd4ce70aeb9b6f38525926021386306 (patch)
treefc43e6e61fd546ed187ff0e03b9c469b7d0dde39 /version_library/library
parent706ad73eb02caf8532deaf5d38995bd258725cb8 (diff)
ss-versionlibrary branch
Diffstat (limited to 'version_library/library')
-rw-r--r--version_library/library/Makefile37
-rw-r--r--version_library/library/include/system_service/ss_ver.h338
-rw-r--r--version_library/library/include/system_service/version_library.h40
-rw-r--r--version_library/library/src/ss_ver.cc309
4 files changed, 724 insertions, 0 deletions
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 <native_service/frameworkunified_types.h>
+#include <string>
+#include <algorithm>
+#include <map>
+
+/**
+ * @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<std::string, SSVER_PkgInfo> 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<std::string, SSVER_PkgInfo> 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<std::string, SSVER_PkgInfo> 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<std::string, SSVER_PkgInfo> 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<std::string, SSVER_PkgInfo> 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 <sys/stat.h>
+#include <sys/types.h>
+#include <sys/file.h>
+#include <dirent.h>
+#include <unistd.h>
+#include <fcntl.h>
+
+#include <native_service/ns_logger_if.h>
+#include <system_service/ss_templates.h>
+
+#include <system_service/ss_ver.h>
+
+// 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<std::string, int> 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<char*>(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<std::string, int> 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
+