summaryrefslogtreecommitdiffstats
path: root/nsframework/framework_unified/client/NS_UtilityCenter/src
diff options
context:
space:
mode:
authortakeshi_hoshina <takeshi_hoshina@mail.toyota.co.jp>2020-10-27 11:16:21 +0900
committertakeshi_hoshina <takeshi_hoshina@mail.toyota.co.jp>2020-10-27 11:16:21 +0900
commit947c78887e791596d4a5ec2d1079f8b1a049628b (patch)
tree3981e88eb8764d7180722f8466f36b756dc005af /nsframework/framework_unified/client/NS_UtilityCenter/src
parent706ad73eb02caf8532deaf5d38995bd258725cb8 (diff)
Diffstat (limited to 'nsframework/framework_unified/client/NS_UtilityCenter/src')
-rw-r--r--nsframework/framework_unified/client/NS_UtilityCenter/src/frameworkunified_version.cpp236
-rw-r--r--nsframework/framework_unified/client/NS_UtilityCenter/src/makefile_PosixBasedOS001194
-rw-r--r--nsframework/framework_unified/client/NS_UtilityCenter/src/ns_endianess.cpp52
-rw-r--r--nsframework/framework_unified/client/NS_UtilityCenter/src/ns_util_crc.cpp125
-rw-r--r--nsframework/framework_unified/client/NS_UtilityCenter/src/ns_util_directory.cpp145
-rw-r--r--nsframework/framework_unified/client/NS_UtilityCenter/src/ns_utility.cpp144
6 files changed, 896 insertions, 0 deletions
diff --git a/nsframework/framework_unified/client/NS_UtilityCenter/src/frameworkunified_version.cpp b/nsframework/framework_unified/client/NS_UtilityCenter/src/frameworkunified_version.cpp
new file mode 100644
index 00000000..3ee907f3
--- /dev/null
+++ b/nsframework/framework_unified/client/NS_UtilityCenter/src/frameworkunified_version.cpp
@@ -0,0 +1,236 @@
+/*
+ * @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_NativeServices
+/// \brief Implementation of CFrameworkunifiedVersion class
+///
+///
+//////////////////////////////////////////////////////////////////////////////////////////////////
+
+#include <native_service/ns_version_if.h>
+#include <stdio.h>
+#include <unistd.h>
+#include <time.h>
+#include <string>
+
+
+// defaults - top level makefile for entire system will provide an override
+#ifndef FRAMEWORKUNIFIED_SIGNATURE
+#define FRAMEWORKUNIFIED_SIGNATURE 0xE0344333
+#endif
+
+#ifndef FRAMEWORKUNIFIED_STRUC_VER
+#define FRAMEWORKUNIFIED_STRUC_VER 0x02
+#endif
+
+#ifndef FRAMEWORKUNIFIED_PRODUCT_VER
+#define FRAMEWORKUNIFIED_PRODUCT_VER 0x01
+#endif
+
+#ifndef PRODUCT_LABEL
+#define PRODUCT_LABEL "undefined"
+#endif
+
+#ifndef FRAMEWORKUNIFIED_BUILD_VER
+#define FRAMEWORKUNIFIED_BUILD_VER "undefined"
+#endif
+
+/* For future use */
+#define YEAR ((((__DATE__[7] - '0') * 10 + (__DATE__[8] - '0')) * 10 \
++ (__DATE__[9] - '0')) * 10 + (__DATE__[10] - '0'))
+
+#define MONTH (__DATE__[2] == 'n' ? 0 \
+: __DATE__[2] == 'b' ? 1 \
+: __DATE__[2] == 'r' ? (__DATE__[0] == 'M' ? 2 : 3) \
+: __DATE__[2] == 'y' ? 4 \
+: __DATE__[2] == 'n' ? 5 \
+: __DATE__[2] == 'l' ? 6 \
+: __DATE__[2] == 'g' ? 7 \
+: __DATE__[2] == 'p' ? 8 \
+: __DATE__[2] == 't' ? 9 \
+: __DATE__[2] == 'v' ? 10 : 11)
+
+#define DAY ((__DATE__[4] == ' ' ? 0 : __DATE__[4] - '0') * 10 \
++ (__DATE__[5] - '0'))
+
+#define DATE_AS_INT (((YEAR - 2000) * 12 + MONTH) * 31 + DAY)
+
+#define HOUR (((__TIME__[0] - '0') * 10 + (__TIME__[1] - '0')))
+
+#define MIN (((__TIME__[3] - '0') * 10 + (__TIME__[4] - '0')))
+
+
+////////////////////////////////////////////////////////////////////////////////////////////
+/// Function: Default Constructor
+////////////////////////////////////////////////////////////////////////////////////////////
+CFrameworkunifiedVersion::CFrameworkunifiedVersion():
+ m_tVersionInfo(const_cast<PSTR>(PRODUCT_LABEL),
+ FRAMEWORKUNIFIED_SIGNATURE,
+ FRAMEWORKUNIFIED_STRUC_VER,
+ FRAMEWORKUNIFIED_PRODUCT_VER,
+ DATE_AS_INT,
+ 0,
+ 0,
+ const_cast<PSTR>(FRAMEWORKUNIFIED_BUILD_VER),
+ 0),
+ m_u32Month(MONTH + 1),
+ m_u32Year(YEAR),
+ m_u32Day(DAY) {
+}
+
+////////////////////////////////////////////////////////////////////////////////////////////
+/// Function: Parametrized constructor
+////////////////////////////////////////////////////////////////////////////////////////////
+CFrameworkunifiedVersion::CFrameworkunifiedVersion(UI_16 major, UI_16 minor, UI_16 revision) :
+ m_tVersionInfo(const_cast<PSTR>(PRODUCT_LABEL),
+ FRAMEWORKUNIFIED_SIGNATURE,
+ FRAMEWORKUNIFIED_STRUC_VER,
+ FRAMEWORKUNIFIED_PRODUCT_VER,
+ DATE_AS_INT,
+ major,
+ minor,
+ const_cast<PSTR>(FRAMEWORKUNIFIED_BUILD_VER),
+ revision),
+ m_u32Month(MONTH + 1),
+ m_u32Year(YEAR),
+ m_u32Day(DAY) {
+}
+
+////////////////////////////////////////////////////////////////////////////////////////////
+/// Function: Destructor
+////////////////////////////////////////////////////////////////////////////////////////////
+CFrameworkunifiedVersion::~CFrameworkunifiedVersion() {
+}
+
+////////////////////////////////////////////////////////////////////////////////////////////
+/// Function: Compares two version instances
+////////////////////////////////////////////////////////////////////////////////////////////
+BOOL operator == (CFrameworkunifiedVersion &a, CFrameworkunifiedVersion &b) { // NOLINT (readability/nolint)
+ return a.operator == (b);
+}
+
+////////////////////////////////////////////////////////////////////////////////////////////
+/// Function: Compares two version instances
+////////////////////////////////////////////////////////////////////////////////////////////
+BOOL CFrameworkunifiedVersion::operator == (const CFrameworkunifiedVersion &f_test_i) {
+ if (!strcmp(m_tVersionInfo.p_str_product, f_test_i.m_tVersionInfo.p_str_product) &&
+ !strcmp(m_tVersionInfo.p_str_build, f_test_i.m_tVersionInfo.p_str_build) &&
+ (m_tVersionInfo.u16_major == f_test_i.m_tVersionInfo.u16_major) &&
+ (m_tVersionInfo.u16_minor == f_test_i.m_tVersionInfo.u16_minor) &&
+ (m_tVersionInfo.u16_revision == f_test_i.m_tVersionInfo.u16_revision) &&
+ (m_tVersionInfo.u32_date == f_test_i.m_tVersionInfo.u32_date) &&
+ (m_tVersionInfo.u32_product_version == f_test_i.m_tVersionInfo.u32_product_version) &&
+ (m_tVersionInfo.u32_signature == f_test_i.m_tVersionInfo.u32_signature) &&
+ (m_tVersionInfo.u32_struc_version == f_test_i.m_tVersionInfo.u32_struc_version)) {
+ return TRUE;
+ }
+
+ return FALSE;
+}
+
+////////////////////////////////////////////////////////////////////////////////////////////
+/// Function: Returns the version string
+////////////////////////////////////////////////////////////////////////////////////////////
+PCSTR CFrameworkunifiedVersion::VersionStr() {
+ static char version[30] = {};
+
+ snprintf(version, sizeof(version) - 1, "%s_%s_%02d.%02d.%02d",
+ m_tVersionInfo.p_str_product,
+ m_tVersionInfo.p_str_build,
+ m_tVersionInfo.u16_major,
+ m_tVersionInfo.u16_minor,
+ m_tVersionInfo.u16_revision);
+
+ return version;
+}
+
+////////////////////////////////////////////////////////////////////////////////////////////
+/// Function: Returns the date when the new version of the app was created
+////////////////////////////////////////////////////////////////////////////////////////////
+PCSTR CFrameworkunifiedVersion::DateStr() {
+ static char date[30] = {};
+
+ snprintf(date, sizeof(date) - 1, "%d-%02d-%02d",
+ m_u32Year,
+ m_u32Month,
+ m_u32Day);
+
+ return date;
+}
+
+////////////////////////////////////////////////////////////////////////////////////////////
+/// Function: Returns the Signature
+////////////////////////////////////////////////////////////////////////////////////////////
+UI_32 CFrameworkunifiedVersion::Signature() const {
+ return m_tVersionInfo.u32_signature;
+}
+
+////////////////////////////////////////////////////////////////////////////////////////////
+/// Function: Returns a new structure version
+////////////////////////////////////////////////////////////////////////////////////////////
+UI_32 CFrameworkunifiedVersion::StrucVersion() const {
+ return m_tVersionInfo.u32_struc_version;
+}
+
+////////////////////////////////////////////////////////////////////////////////////////////
+/// Function: Returns the product version
+////////////////////////////////////////////////////////////////////////////////////////////
+UI_32 CFrameworkunifiedVersion::ProductVersion() const {
+ return m_tVersionInfo.u32_product_version;
+}
+
+////////////////////////////////////////////////////////////////////////////////////////////
+/// Function: Returns the date
+////////////////////////////////////////////////////////////////////////////////////////////
+UI_32 CFrameworkunifiedVersion::Date() const {
+ return m_tVersionInfo.u32_date;
+}
+
+////////////////////////////////////////////////////////////////////////////////////////////
+/// Function: Returns the major number
+////////////////////////////////////////////////////////////////////////////////////////////
+UI_16 CFrameworkunifiedVersion::Major() const {
+ return m_tVersionInfo.u16_major;
+}
+
+////////////////////////////////////////////////////////////////////////////////////////////
+/// Function: Returns the minor number
+////////////////////////////////////////////////////////////////////////////////////////////
+UI_16 CFrameworkunifiedVersion::Minor() const {
+ return m_tVersionInfo.u16_minor;
+}
+
+////////////////////////////////////////////////////////////////////////////////////////////
+/// Function: Returns the unique product identifier
+////////////////////////////////////////////////////////////////////////////////////////////
+PCSTR CFrameworkunifiedVersion::Product() const {
+ return m_tVersionInfo.p_str_product;
+}
+
+////////////////////////////////////////////////////////////////////////////////////////////
+/// Function: Returns the unique build identifier number
+////////////////////////////////////////////////////////////////////////////////////////////
+PCSTR CFrameworkunifiedVersion::Build() const {
+ return m_tVersionInfo.p_str_build;
+}
+
+////////////////////////////////////////////////////////////////////////////////////////////
+/// Function: Returns the revision number
+////////////////////////////////////////////////////////////////////////////////////////////
+UI_16 CFrameworkunifiedVersion::Revision() const {
+ return m_tVersionInfo.u16_revision;
+}
diff --git a/nsframework/framework_unified/client/NS_UtilityCenter/src/makefile_PosixBasedOS001 b/nsframework/framework_unified/client/NS_UtilityCenter/src/makefile_PosixBasedOS001
new file mode 100644
index 00000000..14ad4d80
--- /dev/null
+++ b/nsframework/framework_unified/client/NS_UtilityCenter/src/makefile_PosixBasedOS001
@@ -0,0 +1,194 @@
+#
+# @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_UtilityCenter
+
+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_UtilityCenter
+
+# 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 \
+
+
+# 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 utility functions
+#
+#
+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 $(PRJ_ROOT)../$(COMPONENT_NAME)/inc/*.h) \
+
+
+LIBRARIES = \
+ $(COMPONENT_LIB) \
+
+
+# Make targets
+# Standard
+all: banner module_dirs subdirs local library binary
+
+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: --> $(LIBRARIES)"
+ @echo "bin: --> $(BINARIES)"
+
+
+module_dirs: build_dirs
diff --git a/nsframework/framework_unified/client/NS_UtilityCenter/src/ns_endianess.cpp b/nsframework/framework_unified/client/NS_UtilityCenter/src/ns_endianess.cpp
new file mode 100644
index 00000000..3dea53cb
--- /dev/null
+++ b/nsframework/framework_unified/client/NS_UtilityCenter/src/ns_endianess.cpp
@@ -0,0 +1,52 @@
+/*
+ * @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.
+ */
+
+
+#include <native_service/ns_endianess.h>
+
+UI_16 ConvertEndian_UI16(UI_16 f_value) { // NOLINT (readability/nolint)
+ UI_16 l_ret = static_cast<UI_16>((f_value << 8) | (f_value >> 8));
+ return l_ret;
+}
+
+
+SI_16 ConvertEndian_SI16(SI_16 f_value) { // NOLINT (readability/nolint)
+ SI_16 l_ret = static_cast<SI_16>((f_value << 8) | ((f_value >> 8) & 0xFF));
+ return l_ret;
+}
+
+
+UI_32 ConvertEndian_UI32(UI_32 f_value) { // NOLINT (readability/nolint)
+ UI_32 l_ret = ((f_value << 8) & 0xFF00FF00) | ((f_value >> 8) & 0xFF00FF);
+ return (l_ret << 16) | (l_ret >> 16);
+}
+
+SI_32 ConvertEndian_SI32(SI_32 f_value) { // NOLINT (readability/nolint)
+ SI_32 l_ret = ((f_value << 8) & 0xFF00FF00) | ((f_value >> 8) & 0xFF00FF);
+ return (l_ret << 16) | ((l_ret >> 16) & 0xFFFF);
+}
+
+UI_64 ConvertEndian_UI64(UI_64 f_value) { // // NOLINT (readability/nolint)
+ UI_64 l_ret = ((f_value << 8) & 0xFF00FF00FF00FF00ULL) | ((f_value >> 8) & 0x00FF00FF00FF00FFULL);
+ l_ret = ((l_ret << 16) & 0xFFFF0000FFFF0000ULL) | ((l_ret >> 16) & 0x0000FFFF0000FFFFULL);
+ return (l_ret << 32) | (l_ret >> 32);
+}
+
+SI_64 ConvertEndian_SI64(SI_64 f_value) { // NOLINT (readability/nolint)
+ SI_64 l_ret = ((f_value << 8) & 0xFF00FF00FF00FF00ULL) | ((f_value >> 8) & 0x00FF00FF00FF00FFULL);
+ l_ret = ((l_ret << 16) & 0xFFFF0000FFFF0000ULL) | ((l_ret >> 16) & 0x0000FFFF0000FFFFULL);
+ return (l_ret << 32) | ((l_ret >> 32) & 0xFFFFFFFFULL);
+}
diff --git a/nsframework/framework_unified/client/NS_UtilityCenter/src/ns_util_crc.cpp b/nsframework/framework_unified/client/NS_UtilityCenter/src/ns_util_crc.cpp
new file mode 100644
index 00000000..af823648
--- /dev/null
+++ b/nsframework/framework_unified/client/NS_UtilityCenter/src/ns_util_crc.cpp
@@ -0,0 +1,125 @@
+/*
+ * @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_UtilityCenter
+/// \brief This file contains implementation of APIs to calcuate 16-bit and 32-bit CRC checksum of file.
+///
+////////////////////////////////////////////////////////////////////////////////////////////////////
+
+////////////////////////////////////////////////////////////////////////////////////////////////////
+// Include Files
+////////////////////////////////////////////////////////////////////////////////////////////////////
+#include <native_service/ns_util_crc.h>
+#include <stdio.h>
+
+// buffer size for reading from file
+#define MAX_BUFFER_SIZE 4096
+
+// Static 32 bit CRC lookup table
+UI_16 g_arr_crc16_table[256] = {
+};
+
+// Static 32 bit CRC lookup table
+UI_32 g_arr_crc32_table[256] = {
+};
+
+
+////////////////////////////////////////////////////////////////////////////////////////////////
+/// CalculateCRC16
+/// This API calculates the 16 bit CRC checksum of a file
+////////////////////////////////////////////////////////////////////////////////////////////////
+EFrameworkunifiedStatus CalculateCRC16(PCSTR f_c_file_name, UI_16 &f_ui_check_sum) { // NOLINT (readability/nolint)
+ EFrameworkunifiedStatus l_e_status = eFrameworkunifiedStatusOK;
+
+ CHAR l_c_buffer[MAX_BUFFER_SIZE] = {0};
+ size_t l_ui_bytes_read = 0;
+ FILE *l_p_file = NULL;
+
+ if (NULL != f_c_file_name) {
+ f_ui_check_sum = 0xFFFF;
+
+ // Open the file
+ l_p_file = fopen(f_c_file_name, "rbe");
+
+ if (NULL == l_p_file) {
+ l_e_status = eFrameworkunifiedStatusFileLoadError;
+ } else {
+ l_ui_bytes_read = fread(l_c_buffer, 1, sizeof(l_c_buffer), l_p_file);
+
+ while (0 != l_ui_bytes_read) { // LCOV_EXCL_BR_LINE 11: not a branch
+ for (UI_32 l_ui_bytes_cnt = 0; l_ui_bytes_cnt < l_ui_bytes_read; l_ui_bytes_cnt++) { // LCOV_EXCL_BR_LINE 11: not a branch
+ f_ui_check_sum = static_cast<UI_16>(
+ g_arr_crc16_table[((f_ui_check_sum >> 8) ^ l_c_buffer[l_ui_bytes_cnt]) & 0xFF] ^ (f_ui_check_sum << 8));
+ }
+
+ l_ui_bytes_read = fread(l_c_buffer, 1, sizeof(l_c_buffer), l_p_file);
+ }
+
+ fclose(l_p_file);
+ l_p_file = NULL;
+ }
+
+ f_ui_check_sum = static_cast<UI_16>(~f_ui_check_sum);
+ } else {
+ l_e_status = eFrameworkunifiedStatusInvldParam;
+ }
+
+ return l_e_status;
+}
+
+////////////////////////////////////////////////////////////////////////////////////////////////
+/// CalculateCRC32
+/// This API calculates the 32 bit CRC checksum of a file
+////////////////////////////////////////////////////////////////////////////////////////////////
+EFrameworkunifiedStatus CalculateCRC32(PCSTR f_c_file_name, UI_32 &f_ui_check_sum) { // NOLINT (readability/nolint)
+ EFrameworkunifiedStatus l_e_status = eFrameworkunifiedStatusOK;
+
+ CHAR l_c_buffer[MAX_BUFFER_SIZE] = {0};
+ size_t l_ui_bytes_read = 0;
+ FILE *l_p_file = NULL;
+
+ if (NULL != f_c_file_name) {
+ f_ui_check_sum = 0xFFFFFFFF;
+
+ // Open the file
+ l_p_file = fopen(f_c_file_name, "rbe");
+
+ if (NULL == l_p_file) {
+ l_e_status = eFrameworkunifiedStatusFileLoadError;
+ } else {
+ l_ui_bytes_read = fread(l_c_buffer, 1, sizeof(l_c_buffer), l_p_file);
+
+ while (0 != l_ui_bytes_read) { // LCOV_EXCL_BR_LINE 11: not a branch
+ for (UI_32 l_ui_bytes_cnt = 0; l_ui_bytes_cnt < l_ui_bytes_read; l_ui_bytes_cnt++) { // LCOV_EXCL_BR_LINE 11: not a branch
+ f_ui_check_sum = (f_ui_check_sum >> 8)
+ ^ g_arr_crc32_table[(l_c_buffer[l_ui_bytes_cnt] ^ f_ui_check_sum) & 0xFF];
+ }
+
+ l_ui_bytes_read = fread(l_c_buffer, 1, sizeof(l_c_buffer), l_p_file);
+ }
+
+ fclose(l_p_file);
+ l_p_file = NULL;
+ }
+
+ f_ui_check_sum = ~f_ui_check_sum;
+ } else {
+ l_e_status = eFrameworkunifiedStatusInvldParam;
+ }
+
+ return l_e_status;
+}
diff --git a/nsframework/framework_unified/client/NS_UtilityCenter/src/ns_util_directory.cpp b/nsframework/framework_unified/client/NS_UtilityCenter/src/ns_util_directory.cpp
new file mode 100644
index 00000000..a8b4263d
--- /dev/null
+++ b/nsframework/framework_unified/client/NS_UtilityCenter/src/ns_util_directory.cpp
@@ -0,0 +1,145 @@
+/*
+ * @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_UtilityCenter
+/// \brief This file contains API implementation for handling file and folder functionalities.
+///
+///
+//////////////////////////////////////////////////////////////////////////////////////////////////
+
+#include <native_service/ns_util_directory.h>
+
+#include <dirent.h>
+#include <stdlib.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <errno.h>
+#include <cstring>
+#include <string>
+
+////////////////////////////////////////////////////////////////////////////////////////////////
+/// GetFileList
+/// Get list of files present in a specific directory
+////////////////////////////////////////////////////////////////////////////////////////////////
+EFrameworkunifiedStatus GetFileList(TFileList *f_pv_tfile_list, PCSTR f_pc_path) {
+ EFrameworkunifiedStatus l_e_status = eFrameworkunifiedStatusOK;
+
+ DIR *l_p_dir = NULL;
+ struct dirent *l_pt_dirent = NULL;
+
+ if (NULL != f_pc_path && NULL != f_pv_tfile_list) {
+ if (NULL != (l_p_dir = opendir(f_pc_path))) {
+ PCHAR l_c_file_name = NULL;
+ size_t l_ui_str_length = 0;
+ while (NULL != (l_pt_dirent = readdir(l_p_dir))) { // LCOV_EXCL_BR_LINE 11: not a branch
+ if (!((std::strcmp(l_pt_dirent->d_name, ".") == 0) || (std::strcmp(l_pt_dirent->d_name, "..") == 0))) {
+ l_ui_str_length = std::strlen(l_pt_dirent->d_name);
+
+ l_c_file_name = new(std::nothrow) CHAR[l_ui_str_length + 1];
+
+ if (NULL != l_c_file_name) { // LCOV_EXCL_BR_LINE 11: new's error case(c++)
+ std::memset(l_c_file_name, 0, (sizeof(CHAR) * (l_ui_str_length + 1)));
+
+ std::strncpy(l_c_file_name, l_pt_dirent->d_name, l_ui_str_length);
+
+ f_pv_tfile_list->push_back(l_c_file_name); // LCOV_EXCL_BR_LINE 11: not a branch
+
+ delete[] l_c_file_name; // LCOV_EXCL_BR_LINE 11: not a branch
+ l_c_file_name = NULL;
+ } else {
+ l_e_status = eFrameworkunifiedStatusNullPointer;
+ }
+ }
+ }
+ closedir(l_p_dir);
+ } else {
+ l_e_status = eFrameworkunifiedStatusFail;
+ }
+ } else {
+ l_e_status = eFrameworkunifiedStatusInvldParam;
+ }
+
+ return l_e_status;
+}
+
+
+////////////////////////////////////////////////////////////////////////////////////////////////
+/// CreateDirectory
+/// Method to create a directory.
+////////////////////////////////////////////////////////////////////////////////////////////////
+EFrameworkunifiedStatus CreateDirectory(std::string f_c_dir_path) {
+ EFrameworkunifiedStatus l_e_status = eFrameworkunifiedStatusOK;
+
+ if (!f_c_dir_path.empty()) {
+ PSTR l_c_temp_dir_path;
+ PSTR l_c_parsed_dir_path;
+ PCSTR l_c_copy_path = f_c_dir_path.c_str();
+
+ l_c_temp_dir_path = const_cast<PSTR >(f_c_dir_path.c_str());
+ // LCOV_EXCL_BR_START 11: not a branch
+ while (l_e_status == eFrameworkunifiedStatusOK && (l_c_parsed_dir_path = std::strchr(l_c_temp_dir_path, '/')) != 0) {
+ // LCOV_EXCL_BR_STOP
+ if (l_c_parsed_dir_path != l_c_temp_dir_path) {
+ /* Neither root nor double slash in path */
+ *l_c_parsed_dir_path = '\0';
+ if (0 != mkdir(l_c_copy_path, S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH)) {
+ if (EEXIST != errno) { // LCOV_EXCL_BR_LINE 11: not a branch
+ l_e_status = eFrameworkunifiedStatusFail;
+ } else {
+ // file already exist
+ if (TRUE != DoesDirecotryExist(f_c_dir_path)) { // LCOV_EXCL_BR_LINE 5: DoesDirecotryExist's error case
+ l_e_status = eFrameworkunifiedStatusFail;
+ }
+ }
+ }
+ *l_c_parsed_dir_path = '/';
+ }
+ l_c_temp_dir_path = l_c_parsed_dir_path + 1;
+ }
+ if (eFrameworkunifiedStatusOK == l_e_status) { // LCOV_EXCL_BR_LINE 11: not a branch
+ if (0 != mkdir(l_c_copy_path, S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH)) {
+ if (EEXIST != errno) { // LCOV_EXCL_BR_LINE 11: not a branch
+ l_e_status = eFrameworkunifiedStatusFail;
+ } else {
+ // file already exist
+ if (TRUE != DoesDirecotryExist(f_c_dir_path)) { // LCOV_EXCL_BR_LINE 5: DoesDirecotryExist's error case
+ l_e_status = eFrameworkunifiedStatusFail;
+ }
+ }
+ }
+ }
+ } else {
+ l_e_status = eFrameworkunifiedStatusFail;
+ }
+ return l_e_status;
+}
+
+////////////////////////////////////////////////////////////////////////////////////////////////////
+/// DoesDirecotryExist
+/// Method to check if a directory exists.
+////////////////////////////////////////////////////////////////////////////////////////////////////
+BOOL DoesDirecotryExist(std::string f_c_dir_path) {
+ BOOL l_b_directory_status = FALSE;
+
+ DIR *l_p_dir_descriptor = opendir(f_c_dir_path.c_str());
+ if (NULL != l_p_dir_descriptor) {
+ closedir(l_p_dir_descriptor);
+ l_b_directory_status = TRUE;
+ }
+ return l_b_directory_status;
+}
+
diff --git a/nsframework/framework_unified/client/NS_UtilityCenter/src/ns_utility.cpp b/nsframework/framework_unified/client/NS_UtilityCenter/src/ns_utility.cpp
new file mode 100644
index 00000000..d9e6776c
--- /dev/null
+++ b/nsframework/framework_unified/client/NS_UtilityCenter/src/ns_utility.cpp
@@ -0,0 +1,144 @@
+/*
+ * @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.
+ */
+
+#include <native_service/ns_utility_if.h>
+#include <native_service/ns_utility_sys.hpp>
+#include <stdlib.h>
+#include <ctime>
+#include <cstring>
+#include "ns_utility_sys_internal.hpp"
+#include "ns_utility_if_internal.h"
+// Random functions ////////////////////////////////////////////////////
+void utility_sys_seedrand() { // NOLINT (readability/nolint)
+ static bool s_seeded = false;
+ if (!s_seeded) {
+ s_seeded = true;
+ srand48(std::time(NULL));
+ }
+}
+
+UI_32 utility_sys_rand() { // NOLINT (readability/nolint)
+ utility_sys_seedrand();
+ return static_cast< UI_32 >(mrand48());
+}
+
+// Lock wrapper implementation /////////////////////////////////////
+
+///////////////////////////////////////////
+// Implements locking policy for mutexes //
+///////////////////////////////////////////
+
+// CMutex helper function
+template< class TErr >
+void MutexLock(pthread_mutex_t *mtx) {
+ if (EOK != pthread_mutex_lock(mtx)) {
+ throw TErr("");
+ }
+}
+
+CMutex::CMutex() {
+ pthread_mutex_t mtx_tmp = PTHREAD_MUTEX_INITIALIZER;
+ std::memcpy(&m_mtx, &mtx_tmp, sizeof(m_mtx));
+ if (EOK != pthread_mutex_init(&m_mtx, NULL)) {
+ throw lock_creation_error();
+ }
+}
+
+CMutex::~CMutex() {
+ pthread_mutex_destroy(&m_mtx);
+}
+
+void CMutex::ReadLock() {
+ MutexLock< lock_acquireread_error >(&m_mtx);
+}
+
+void CMutex::WriteLock() {
+ MutexLock< lock_acquirewrite_error >(&m_mtx);
+}
+
+void CMutex::Unlock() {
+ if (EOK != pthread_mutex_unlock(&m_mtx)) {
+ throw lock_release_error("");
+ }
+}
+
+
+/////////////////////////////////////////////////////////
+// implements locking policy for reader / writer locks //
+/////////////////////////////////////////////////////////
+CRWLock::CRWLock() {
+ pthread_rwlock_t rw_tmp = PTHREAD_RWLOCK_INITIALIZER;
+ std::memcpy(&m_rwl, &rw_tmp, sizeof(m_rwl));
+ if (EOK != pthread_rwlock_init(&m_rwl, NULL)) {
+ throw lock_creation_error();
+ }
+}
+
+CRWLock::~CRWLock() {
+ pthread_rwlock_destroy(&m_rwl);
+}
+
+void CRWLock::ReadLock() {
+ if (EOK != pthread_rwlock_rdlock(&m_rwl)) {
+ throw lock_acquireread_error();
+ }
+}
+
+void CRWLock::WriteLock() {
+ if (EOK != pthread_rwlock_wrlock(&m_rwl)) {
+ throw lock_acquirewrite_error();
+ }
+}
+
+void CRWLock::Unlock() {
+ if (EOK != pthread_rwlock_unlock(&m_rwl)) {
+ throw lock_release_error();
+ }
+}
+
+/////////////////////////////////////////////////////////
+// implements GNU Builtins for counting leading zeros //
+/////////////////////////////////////////////////////////
+
+// returns the number of leading zeros in a given 16bit value
+SI_16 NS_CountLeadingZeros_16Bit(UI_16 f_ui_val) { // NOLINT (readability/nolint)
+ return static_cast<SI_16>((f_ui_val == 0) ? NS_INVALID_RETURN : __builtin_clz(f_ui_val)); // NOLINT (readability/nolint)
+}
+
+// returns the number of leading zeros in a given 32bit value
+SI_16 NS_CountLeadingZeros_32Bit(UI_32 f_ui_val) { // NOLINT (readability/nolint)
+ return static_cast<SI_16>((f_ui_val == 0) ? NS_INVALID_RETURN : __builtin_clzl(f_ui_val)); // NOLINT (readability/nolint)
+}
+
+// returns the number of leading zeros in a given 64bit value
+SI_16 NS_CountLeadingZeros_64Bit(UI_64 f_ui_val) { // NOLINT (readability/nolint)
+ return static_cast<SI_16>((f_ui_val == 0) ? NS_INVALID_RETURN : __builtin_clzll(f_ui_val)); // NOLINT (readability/nolint)
+}
+
+// returns the number of trailing zeros in a given 16bit value
+SI_16 NS_CountTrailingZeros_16Bit(UI_16 f_ui_val) { // NOLINT (readability/nolint)
+ return static_cast<SI_16>((f_ui_val == 0) ? NS_INVALID_RETURN : __builtin_ctz(f_ui_val)); // NOLINT (readability/nolint)
+}
+
+// returns the number of trailing zeros in a given 32bit value
+SI_16 NS_CountTrailingZeros_32Bit(UI_32 f_ui_val) { // NOLINT (readability/nolint)
+ return static_cast<SI_16>((f_ui_val == 0) ? NS_INVALID_RETURN : __builtin_ctzl(f_ui_val)); // NOLINT (readability/nolint)
+}
+
+// returns the number of trailing zeros in a given 64bit value
+SI_16 NS_CountTrailingZeros_64Bit(UI_64 f_ui_val) { // NOLINT (readability/nolint)
+ return static_cast<SI_16>((f_ui_val == 0) ? NS_INVALID_RETURN : __builtin_ctzll(f_ui_val)); // NOLINT (readability/nolint)
+}