diff options
Diffstat (limited to 'systemservice/interface_unified/library/src')
13 files changed, 6052 insertions, 0 deletions
diff --git a/systemservice/interface_unified/library/src/libSS_SystemIfUnified.ver b/systemservice/interface_unified/library/src/libSS_SystemIfUnified.ver new file mode 100755 index 0000000..7a646f2 --- /dev/null +++ b/systemservice/interface_unified/library/src/libSS_SystemIfUnified.ver @@ -0,0 +1,78 @@ +/* + * @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. + */ + +# +# libNS_FrameworkUnified version script +# +{ + global: + ### .text section ### + extern "C++" { + AttachCallbackToSystemManager*; + DetachCallbacksFromInterfaceunifiedDispatcher*; + DetachParentCallbacksFromInterfaceunifiedDispatcher*; + GetStr*; + GetSystemManagerSessionHandle*; + SendInterfaceunifiedOnStopResponseToSystemManager*; + GetInterfaceunifiedOnStartExtInfo*; + GetInterfaceunifiedOnStopExtInfo*; + OnSystemManagerDebugDump*; + FrameworkunifiedSSFrameworkInterface*; + RegisterSMSessionAckCallback*; + RemountPartition*; + SendBootModeSetRequestToSystemManager*; + SetDataResetModeToSystemManager*; + SetProgUpdateStateToSystemManager*; + SendCANLoggingRequestToSystemManager*; + SendCpuResetRequestToSystemManager*; + SendDTCLoggingRequestToSystemManager*; + SendDebugDumpResponseToSystemManager*; + SendDiagLoggingRequestToSystemManager*; + SendEelExportRequestToSystemManager*; + SendLogArtifactRequestToSystemManager*; + SendLogCompleteRequestToSystemManager*; + SendLogStartRequestToSystemManager*; + SendInterfaceunifiedEmmcLogsRequestToSystemManager*; + SendClearLogsRequestToSystemManager*; + SendShutdownToSystemManager*; + SendStartupConfirmationToSystemManager*; + SendSystemModeRequestToSystemManager*; + SendInitCompReportToSystemManager*; + Send_CWORD56_HeartBeatRequestToSystemManager*; + SendVarCodeDataToSystemManager*; + SendWakeUpToSystemManager*; + SetBootLoaderInfoRequestToSystemManager*; + + GetBootLoaderInfoRequestToSystemManager*; + + SetWakeupOrderToSystemManager*; + SetNextWakeupTypeToSystemManager*; + Set_UseStopCompleteNotificationVsInterfaceunifiedOnStopFnc_StateVar*; + SendUserInvokedLoggingRequestToSystemManager*; + RegisterBootMicroLogRequestCb*; + SendBootMicroResetNotificationToSystemManager*; + SendBootMicroLogResponseToSystemManager*; + SS_ConvLastInfoToOrder*; + DeviceDetectionServiceIf::*; + LoggerServiceIf::*; + Process::*; + Timer::*; + TimerCtrl::*; + }; + local: + *; +}; + diff --git a/systemservice/interface_unified/library/src/makefile_PosixBasedOS001 b/systemservice/interface_unified/library/src/makefile_PosixBasedOS001 new file mode 100755 index 0000000..68fa52e --- /dev/null +++ b/systemservice/interface_unified/library/src/makefile_PosixBasedOS001 @@ -0,0 +1,180 @@ +# +# @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 = SS_PowerServiceIf + +ifndef PRJ_ROOT +export PRJ_ROOT = $(CURDIR)/../ +endif +include $(PRJ_ROOT)cfg/depends.mk + +# 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 + + +# Define binary outputs. These can be libraries or executables. +# Name a variable for each deliverable. Suffixes should be +# EXEC - For Executables -> output to the bin directory +#TIME_EXEC = $(BIN_PATH)time +# LIB - For Static Libraries -> output to lib directory with specific naming +#MATH_LIB = $(LIB_PATH)$(LIB_PREFIX)math.$(LIB_EXT) +# SLIB - For Shared Objects +#FRMWRK_SLIB = $(SLIB_PATH)frmwrk.$(SO_EXT) +# LIB - Define the static library for Message Queue +# +# +##COMPONENT_LIB = $(LIB_PATH)$(LIB_PREFIX)$(COMPONENT_NAME)$(DEBUG_EXT).$(LIB_EXT) +ifdef DYNAMIC_OFF + 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 + +debug: + $(MAKE) TARGET=arm DEBUG=TRUE all + +base: banner module_dirs subdirs local + +# Standard Building of Source Files (Default builds for all objects defined above) +$(C_LANG_OBJECTS): $(SOURCES) $(HEADERS) + $(CC_CMD) + +$(CPP_LANG_OBJECTS): $(SOURCES) $(HEADERS) + $(CPP_CMD) + +local: $(OBJECTS) + +# Defines specific for each deliverable + +# For a static library +$(COMPONENT_LIB): $(OBJECTS) +ifdef DYNAMIC_OFF +# For a dynamic library + $(SLIB_CMD) +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/systemservice/interface_unified/library/src/ss_devicedetection_service_ifc.cpp b/systemservice/interface_unified/library/src/ss_devicedetection_service_ifc.cpp new file mode 100755 index 0000000..1f68df6 --- /dev/null +++ b/systemservice/interface_unified/library/src/ss_devicedetection_service_ifc.cpp @@ -0,0 +1,673 @@ +/* + * @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_SystemServices_DeviceDetection +/// \brief This file contains service interface functions. +/// +/////////////////////////////////////////////////////////////////////////////// +#include "system_service/ss_devicedetection_service_ifc.h" +#include <native_service/frameworkunified_application.h> +#include <native_service/frameworkunified_framework_if.h> +#include <native_service/frameworkunified_types.h> +#include <native_service/frameworkunified_framework_types.h> +#include <string.h> + +#ifdef AGL_STUB +#else +#include "dcmd_sim_mmcsd.h" +#endif +#include <sys/types.h> +#include <sys/stat.h> +#include <fcntl.h> +#include <unistd.h> +#include <stdio.h> +#ifdef AGL_STUB +#else +#include <sys/dcmd_cam.h> +#endif +#include <errno.h> +#include <sys/ioctl.h> +#include <linux/cdrom.h> +#include <asm-generic/param.h> + +#include "system_service/ss_services.h" +#include "system_service/ss_devicedetection_service_protocol.h" +#include "system_service/ss_devicedetection_service_protocol_local.h" +#include "system_service/ss_devicedetection_service_notifications.h" +#include "system_service/ss_devicedetection_service_local.h" +#include "system_service/ss_devicedetection_service_types_local.h" +#include "ss_devicedetection_service_if_interfaceunifiedlog.h" + +DeviceDetectionServiceIf::DeviceDetectionServiceIf() + : m_hApp(NULL), + m_hService(NULL), + m_hSession(NULL) { +} + +DeviceDetectionServiceIf::~DeviceDetectionServiceIf() { + CloseSessionRequest(); // if the session is still connected + if ((NULL != m_hApp) && (NULL != m_hService)) { + FrameworkunifiedCloseService(m_hApp, m_hService); + } + m_hService = NULL; + m_hSession = NULL; + m_hApp = NULL; +} // LCOV_EXCL_BR_LINE 10:Because destructor + +EFrameworkunifiedStatus DeviceDetectionServiceIf::NotifyOnDeviceDetectionAvailability( + CbFuncPtr f_pCallBackFn) { + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+"); + EFrameworkunifiedStatus eStatus = eFrameworkunifiedStatusInvldHandle; + if (NULL != m_hApp && NULL != f_pCallBackFn) { + // Subscriptions + FrameworkunifiedNotificationCallbackHandler + g_aryDeviceDetect_Notif_Cbs[] = { + // Notifications name, Call back function + { NTFY_SS_Device_Detection_Service_Availability, f_pCallBackFn}, + }; + + if (0 != strcmp(SS_DEV_DETECT_SRV, FrameworkunifiedGetAppName(m_hApp))) { + // Subscribe and attach call backs to notifications + if (eFrameworkunifiedStatusOK + != (eStatus = FrameworkunifiedSubscribeNotificationsWithCallback( + m_hApp, g_aryDeviceDetect_Notif_Cbs, + _countof(g_aryDeviceDetect_Notif_Cbs)))) { + FRAMEWORKUNIFIEDLOG( + ZONE_ERR, + __FUNCTION__, + "Error: FrameworkunifiedAttachNotificationCallbacksToDispatcher Failed Status:0x%x ", + eStatus); + } + } + } + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-"); + return eStatus; +} + +EFrameworkunifiedStatus DeviceDetectionServiceIf::DetachDeviceDetectionAvailabilityCb() { + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+"); + EFrameworkunifiedStatus eStatus = eFrameworkunifiedStatusInvldHandle; + if (NULL != m_hApp) { + if (0 != strcmp(SS_DEV_DETECT_SRV, FrameworkunifiedGetAppName(m_hApp))) { + // Unsubscribe and detach call backs to notifications + if (eFrameworkunifiedStatusOK != (eStatus = + FrameworkunifiedUnsubscribeNotificationWithCallback(m_hApp, NTFY_SS_Device_Detection_Service_Availability))) { + FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, + "Error: InterfaceunifiedDetachNotificationCallback Failed Status:0x%x ", + eStatus); + } + } + } + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-"); + return eStatus; +} + +EFrameworkunifiedStatus DeviceDetectionServiceIf::NotifyOnOpenSessionAck( + CbFuncPtr f_pCallBackFn) { + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+"); + EFrameworkunifiedStatus eStatus = eFrameworkunifiedStatusInvldHandle; + if (NULL != m_hApp && NULL != f_pCallBackFn) { + if (eFrameworkunifiedStatusOK + != (eStatus = FrameworkunifiedAttachCallbackToDispatcher(m_hApp, + SS_DEV_DETECT_SRV, + PROTOCOL_OPEN_SESSION_ACK, + f_pCallBackFn))) { + FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, + "Error: FrameworkunifiedAttachCallbackToDispatcher Failed Status:0x%x ", + eStatus); + } + } + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-"); + return eStatus; +} + +EFrameworkunifiedStatus DeviceDetectionServiceIf::DetachOpenSessionAckCb() { + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+"); + EFrameworkunifiedStatus eStatus = eFrameworkunifiedStatusInvldHandle; + if (NULL != m_hApp) { + if (eFrameworkunifiedStatusOK + != (eStatus = FrameworkunifiedDetachCallbackFromDispatcher(m_hApp, + SS_DEV_DETECT_SRV, + PROTOCOL_OPEN_SESSION_ACK))) { + FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, + "Error: FrameworkunifiedDetachCallbackFromDispatcher Failed Status:0x%x ", + eStatus); + } + } + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-"); + return eStatus; +} + +EFrameworkunifiedStatus DeviceDetectionServiceIf::NotifyOnCloseSessionAck( + CbFuncPtr f_pCallBackFn) { + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+"); + EFrameworkunifiedStatus eStatus = eFrameworkunifiedStatusInvldHandle; + + if (NULL != m_hApp && NULL != f_pCallBackFn) { + if (eFrameworkunifiedStatusOK + != (eStatus = FrameworkunifiedAttachCallbackToDispatcher(m_hApp, + SS_DEV_DETECT_SRV, + PROTOCOL_CLOSE_SESSION_ACK, + f_pCallBackFn))) { + FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, + "Error: FrameworkunifiedAttachCallbackToDispatcher Failed Status:0x%x ", + eStatus); + } + } + + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-"); + return eStatus; +} + +EFrameworkunifiedStatus DeviceDetectionServiceIf::DetachCloseSessionAckCb() { + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+"); + EFrameworkunifiedStatus eStatus = eFrameworkunifiedStatusInvldHandle; + + if (NULL != m_hApp) { + if (eFrameworkunifiedStatusOK + != (eStatus = FrameworkunifiedDetachCallbackFromDispatcher( + m_hApp, + SS_DEV_DETECT_SRV, + PROTOCOL_CLOSE_SESSION_ACK))) { + FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, + "Error: FrameworkunifiedDetachCallbackFromDispatcher Failed Status:0x%x ", + eStatus); + } + } + + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-"); + return eStatus; +} + +EFrameworkunifiedStatus DeviceDetectionServiceIf::RegisterForDeviceDetectionEvent( + SS_DeviceDetectionServerEvents f_eDevDetectEvent, CbFuncPtr f_pCallBackFn, + PCSTR pFilepath) { + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+"); + EFrameworkunifiedStatus eStatus = eFrameworkunifiedStatusInvldHandle; + char l_filepathname[FILEPATH_SIZE] = { '\0' }; + int len = 0; + + if (NULL != pFilepath) { + len = strlen(pFilepath); + strcpy(l_filepathname, pFilepath); // NOLINT (runtime/printf) + } + + if (NULL != m_hSession && NULL != f_pCallBackFn) { + if (CheckDetectEvent(f_eDevDetectEvent)) { + if (eFrameworkunifiedStatusOK + != (eStatus = FrameworkunifiedAttachCallbackToDispatcher(m_hApp, + SS_DEV_DETECT_SRV, + f_eDevDetectEvent, + f_pCallBackFn, m_hSession))) { + FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, + "Error: FrameworkunifiedAttachCallbackToDispatcher Failed Status:0x%x ", + eStatus); + } + + eStatus = FrameworkunifiedSendMsg(m_hSession, SS_REGISTER_DETECT_EVENT, + sizeof(SS_DeviceDetectionServerEvents), + &f_eDevDetectEvent); + } else { + if (eFrameworkunifiedStatusOK + != (eStatus = FrameworkunifiedAttachCallbackToDispatcher(m_hApp, + SS_DEV_DETECT_SRV, + f_eDevDetectEvent, + f_pCallBackFn, m_hSession))) { + FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, + "Error: FrameworkunifiedAttachCallbackToDispatcher Failed Status:0x%x ", + eStatus); + } + + // client registers for the event + if (eFrameworkunifiedStatusOK + != (eStatus = FrameworkunifiedRegisterEvent(m_hSession, f_eDevDetectEvent))) { + FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, + "Error: FrameworkunifiedRegisterEvents Failed Status:0x%x", eStatus); + } + + if (NULL != pFilepath) { + eStatus = FrameworkunifiedSendMsg(m_hSession, SS_REGISTER_FILEPATHNAME, len, + l_filepathname); + } + } + } + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-"); + return eStatus; +} + +EFrameworkunifiedStatus DeviceDetectionServiceIf::UnRegisterForDeviceDetectionEvent( + SS_DeviceDetectionServerEvents f_eDevDetectEvent) { + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+"); + EFrameworkunifiedStatus eStatus = eFrameworkunifiedStatusInvldHandle; + + if (NULL != m_hSession) { + if (eFrameworkunifiedStatusOK + != (eStatus = FrameworkunifiedDetachCallbackFromDispatcher(m_hApp, + SS_DEV_DETECT_SRV, + f_eDevDetectEvent, + m_hSession))) { + FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, + "Error: InterfaceunifiedDetachCallbackToDispatcher Failed Status:0x%x ", eStatus); + } + + // client registers for the event + if (eFrameworkunifiedStatusOK != (eStatus = FrameworkunifiedUnRegisterEvent(m_hSession, f_eDevDetectEvent))) { + FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, + "Error: FrameworkunifiedUnRegisterEvents Failed Status:0x%x", eStatus); + } + + if (eFrameworkunifiedStatusOK != (eStatus = FrameworkunifiedSendMsg(m_hSession, SS_UNREGISTER_DETECT_EVENT, + sizeof(SS_DeviceDetectionServerEvents), + &f_eDevDetectEvent))) { + FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, + "UnRegister Detect Event[0x%x] Send Error[0x%x]", f_eDevDetectEvent, eStatus); + } + } + + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-"); + return eStatus; +} + +BOOL DeviceDetectionServiceIf::Initialize(HANDLE hApp) { + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+"); + BOOL l_eStatus = TRUE; + + if (NULL != hApp) { + m_hApp = hApp; + } else { + l_eStatus = FALSE; // eFrameworkunifiedStatusInvldHandle; + } + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-"); + return l_eStatus; +} + +EFrameworkunifiedStatus DeviceDetectionServiceIf::OpenSessionRequest() { + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+"); + EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusInvldHandle; + if (NULL != m_hApp) { + // if the session is there then we need to close it first! + if (NULL != m_hService) { + CloseSessionRequest(); + FrameworkunifiedCloseService(m_hApp, m_hService); + m_hService = NULL; + } + BOOL l_bServiceAvailable = FrameworkunifiedIsServiceAvailable(m_hApp); + if (FALSE == l_bServiceAvailable) { + FRAMEWORKUNIFIEDLOG(ZONE_ERR, __PRETTY_FUNCTION__, + "DeviceError: Service is unavailable"); + l_eStatus = eFrameworkunifiedStatusFail; + } else { + // Now open the service. + if (l_bServiceAvailable + && (NULL != (m_hService = OpenService()))) { // LCOV_EXCL_BR_LINE 8:Because l_bServiceAvailable is always TRUE + // [DM: TODO] Check if we need to open a session with some data sent to Server. + UI_32 l_pTestData = 1; + if (eFrameworkunifiedStatusOK != (l_eStatus = FrameworkunifiedOpenSessionWithData(m_hService, + (PVOID) &l_pTestData, + sizeof(UI_32)))) { + FRAMEWORKUNIFIEDLOG(ZONE_ERR, __PRETTY_FUNCTION__, "Error: FrameworkunifiedOpenSessionWithData Failed"); + } + } else { + l_eStatus = eFrameworkunifiedStatusFail; + FRAMEWORKUNIFIEDLOG(ZONE_ERR, __PRETTY_FUNCTION__, "Error: FrameworkunifiedOpenService Failed"); + } + } + } else { + FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "Error: OpenSessionRequest Failed %X", + l_eStatus); + } + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-"); + return l_eStatus; +} + +HANDLE DeviceDetectionServiceIf::OpenService() { + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+"); + HANDLE l_hService = NULL; + + if (NULL == (l_hService = FrameworkunifiedOpenService(m_hApp, SS_DEV_DETECT_SRV))) { + FRAMEWORKUNIFIEDLOG(ZONE_ERR, __PRETTY_FUNCTION__, "Error: FrameworkunifiedOpenService : Failed to open Device Detection Service"); + } + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-"); + return l_hService; +} + +EFrameworkunifiedStatus DeviceDetectionServiceIf::DecodeOpenSessionResponse() { + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+"); + EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusInvldHandle; + + if (NULL != m_hService && NULL != m_hApp) { // LCOV_EXCL_BR_LINE 8:Because when m_hApp is NULL, m_hService is NULL + if (NULL == (m_hSession = FrameworkunifiedGetOpenSessionHandle(m_hApp))) { + FRAMEWORKUNIFIEDLOG(ZONE_ERR, __PRETTY_FUNCTION__, "Error: Error in extracting OpenSessionAck response."); + l_eStatus = eFrameworkunifiedStatusFail; + } else { + l_eStatus = eFrameworkunifiedStatusOK; + FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__, "Logger Session Name: %s, Session Id: %d", + FrameworkunifiedGetSessionName(m_hSession), FrameworkunifiedGetSessionId(m_hSession)); + } + } else { + FRAMEWORKUNIFIEDLOG( + ZONE_ERR, + __FUNCTION__, + "Error. m_hService: %p, m_hApp: %p is NULL. Open session handle not acquired," + " l_eStatus: eFrameworkunifiedStatusInvldHandle.", m_hService, m_hApp); + } + + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-"); + return l_eStatus; +} + +EFrameworkunifiedStatus DeviceDetectionServiceIf::CloseSessionRequest() { + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+"); + EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusInvldHandle; + + if (NULL != m_hService && NULL != m_hSession) { + if (eFrameworkunifiedStatusOK != (l_eStatus = FrameworkunifiedCloseSession(m_hService, m_hSession))) { + FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "Error: FrameworkunifiedCloseSession Failed"); + } + m_hSession = NULL; // clear our session handle + } + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-"); + return l_eStatus; +} + +BOOL DeviceDetectionServiceIf::CheckDetectEvent( + SS_DeviceDetectionServerEvents f_eDevDetectEvent) { + BOOL chkevt = FALSE; + + switch (f_eDevDetectEvent) { + case SS_DEV_INFO_ANY_USB_EV: + case SS_DEV_DETECT_ANY_USB_EV: + case SS_DEV_DETECT_ANY_SD_EV: + case SS_DEV_DETECT_ANY_DISC_EV: + case SS_DEV_DETECT_ANY_USB_NCM_EV: + + case SS_DEV_DETECT_ANY_USB_DCM_NCM_EV: + case SS_DEV_DETECT_ANY_USB__CWORD57__EV: + case SS_DEV_DETECT_ANY_USB_ACM_EV: + case SS_DEV_DETECT_ANY_USB_DEV_MNG_EV: + case SS_DEV_DETECT_ANY_USB_VEHICLE_CTRL_EV: + case SS_DEV_DETECT_ANY_USB_DSRC_APP_EV: + case SS_DEV_DETECT_ANY_USB_DSRC_CTRL_EV: + case SS_DEV_DETECT_ANY_USB_IR_VICS_DATA_EV: + case SS_DEV_ERR_USB_OVER_CURRENT_EV: + case SS_DEV_DETECT_ANY_USB_MTP_EV: + case SS_DEV_INFO_ANY_USB_NOTIFY_EV: + case SS_DEV_DETECT_ANY_USB__CWORD57__ROLE_EV: + case SS_DEV_INFO_SD_FORMAT_COMP_EV: + case SS_DEV_INFO_ANY_USB_DVDP_EV: + chkevt = TRUE; + break; + default: + break; + } + return chkevt; +} + +static void ReadString(const char *file, char *buf, int len) { + int fd; + ssize_t r; + char *tmp; + + if (file == NULL) { // LCOV_EXCL_BR_LINE 8:Because file is not NULL + // LCOV_EXCL_START 8:Because file is not NULL + buf[0] = '\0'; + return; + // LCOV_EXCL_STOP + } + + fd = open(file, O_RDONLY); + if (fd < 0) { // LCOV_EXCL_BR_LINE 6:Because the sequence at the time of open failure cannot be passed + // LCOV_EXCL_START 6:Because the sequence at the time of open failure cannot be passed + buf[0] = '\0'; + return; + // LCOV_EXCL_STOP + } + + r = read(fd, buf, len); + close(fd); + if (r > 0 && r < len) { + buf[r] = '\0'; + r--; + /* If there is a line feed code'\n' at the end of the acquired data, replace it with '\0' */ + while (buf[r] == '\n') { + buf[r] = '\0'; + if (r == 0) + break; + r--; + } + /* If there is a line feed code'\n' in the middle of the acquired data, replace with '\0' */ + tmp = buf; + while ((tmp = strchr(tmp, '\n')) != NULL) { + *tmp = ' '; + tmp++; + } + return; + } else { + buf[0] = '\0'; + } +} + +static bool isMounttedDir(char* pMountDir) { + char buf[4096]; + + if (!pMountDir) { // LCOV_EXCL_BR_LINE 8:Because pMountDir is not NULL + // LCOV_EXCL_START 8:Because pMountDir is not NULL + return false; + // LCOV_EXCL_STOP + } + + ReadString("/proc/mounts", buf, sizeof(buf)); + if (strstr(buf, pMountDir)) { // The mount folder is already in use as a mount point + return true; + } + + return false; +} + +EFrameworkunifiedStatus DeviceDetectionServiceIf::MountSD(uint8_t part_num, + BOOL *already_mounted) { + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+"); + EFrameworkunifiedStatus eStatus = eFrameworkunifiedStatusInvldHandle; + + FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__, "part_num %d", part_num); + + if (NULL == m_hSession) { + FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "m_hSession is NULL"); + return eFrameworkunifiedStatusInvldHandle; + } + + if (part_num > 3) { + return eFrameworkunifiedStatusInvldParam; + } + + char mount_dir[256]; + if (part_num != 0) { + sprintf(mount_dir, "/mnt/mmcblk1p%d", part_num); // NOLINT (runtime/printf) + } else { + sprintf(mount_dir, "/mnt/mmcblk1"); // NOLINT (runtime/printf) + } + if (isMounttedDir(mount_dir)) { + *already_mounted = TRUE; + return eFrameworkunifiedStatusOK; + } else { + *already_mounted = FALSE; + } + + char filename[256]; + struct stat st; + if (part_num != 0) { + sprintf(filename, "/dev/mmcblk1p%d", part_num); // NOLINT (runtime/printf) + } else { + sprintf(filename, "/dev/mmcblk1"); // NOLINT (runtime/printf) + } + if (stat(filename, &st) != 0) { + return eFrameworkunifiedStatusAccessError; + } + + if (eFrameworkunifiedStatusOK + == (eStatus = FrameworkunifiedSendMsg(m_hSession, SS_DEV_MOUNT_SD, sizeof(uint8_t), + &part_num))) { + FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__, "Send MountSD msg Sucessfully"); + } + + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-"); + + return eStatus; +} + +EFrameworkunifiedStatus DeviceDetectionServiceIf::UmountSD(uint8_t part_num, + BOOL *already_umounted) { + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+"); + EFrameworkunifiedStatus eStatus = eFrameworkunifiedStatusInvldHandle; + + FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__, "part_num %d", part_num); + + if (NULL == m_hSession) { + FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "m_hSession is NULL"); + return eFrameworkunifiedStatusInvldHandle; + } + + if (part_num > 3) { + return eFrameworkunifiedStatusInvldParam; + } + + char mount_dir[256]; + if (part_num != 0) { + sprintf(mount_dir, "/mnt/mmcblk1p%d", part_num); // NOLINT (runtime/printf) + } else { + sprintf(mount_dir, "/mnt/mmcblk1"); // NOLINT (runtime/printf) + } + + if (isMounttedDir(mount_dir)) { + *already_umounted = FALSE; + } else { + *already_umounted = TRUE; + return eFrameworkunifiedStatusOK; + } + + char filename[256]; + struct stat st; + + if (part_num != 0) { + sprintf(filename, "/dev/mmcblk1p%d", part_num); // NOLINT (runtime/printf) + } else { + sprintf(filename, "/dev/mmcblk1"); // NOLINT (runtime/printf) + } + if (stat(filename, &st) != 0) { + return eFrameworkunifiedStatusAccessError; + } + + if (eFrameworkunifiedStatusOK + == (eStatus = FrameworkunifiedSendMsg(m_hSession, SS_DEV_UMOUNT_SD, sizeof(uint8_t), + &part_num))) { + FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__, "Send UmountSD msg Sucessfully"); + } + + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-"); + + return eStatus; +} + +static const uint8_t VBUS_RESET_INTERVAL_MIN = 11; + +static EFrameworkunifiedStatus SendUsbVBusResetMsg(HANDLE handle, int8_t port, uint8_t interval) { + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __func__, "+"); + EFrameworkunifiedStatus eStatus = eFrameworkunifiedStatusOK; + + if (NULL == handle) { + FRAMEWORKUNIFIEDLOG(ZONE_WARN, __func__, "Invalid Handle."); + return eFrameworkunifiedStatusInvldHandle; + } + + int16_t data[] = {port, interval}; + eStatus = FrameworkunifiedSendMsg(handle, SS_USB_VBUS_RESET, sizeof(data), data); + + if (eFrameworkunifiedStatusOK != eStatus) { + FRAMEWORKUNIFIEDLOG(ZONE_ERR, __func__, "FrameworkunifiedSendMsg Send Error[0x%x]", eStatus); + return eStatus; + } + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __func__, "-"); + return eStatus; +} + +EFrameworkunifiedStatus DeviceDetectionServiceIf::UsbVBusReset(int8_t port, uint8_t interval) { + return SendUsbVBusResetMsg(m_hSession, port, interval); +} + +EFrameworkunifiedStatus DeviceDetectionServiceIf::UsbVBusReset(int8_t port) { + return SendUsbVBusResetMsg(m_hSession, port, VBUS_RESET_INTERVAL_MIN); +} + +EFrameworkunifiedStatus DeviceDetectionServiceIf::RoleSwStateNotify( + SS_DEV_ROLE_SW_STATE state) { + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+"); + EFrameworkunifiedStatus eStatus = eFrameworkunifiedStatusFail; + EFrameworkunifiedStatus result = eFrameworkunifiedStatusFail; + UI_32 rcvlength = 0; + UI_32 bufflength; + + if (NULL == m_hSession) { + FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "No Session"); + return eFrameworkunifiedStatusInvldHandle; + } + + bufflength = sizeof(EFrameworkunifiedStatus); + eStatus = FrameworkunifiedInvokeSync(m_hSession, SS_DEV_ROLE_SW_STATE_NOTIFY, + sizeof(SS_DEV_ROLE_SW_STATE), &state, bufflength, + &result, &rcvlength); + + if (eFrameworkunifiedStatusOK != eStatus) { + FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "FrameworkunifiedSendMsg Send Error[0x%x]", eStatus); + return eStatus; + } + + if (bufflength != rcvlength) { + FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, + "FrameworkunifiedInvokeSync Response Error. bufflen[%d], rcvlen[%d]", bufflength, + rcvlength); + return eStatus; + } + + eStatus = result; + + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-"); + return eStatus; +} + +EFrameworkunifiedStatus DeviceDetectionServiceIf::FormatSD(void) { + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+"); + EFrameworkunifiedStatus eStatus = eFrameworkunifiedStatusOK; + + if (NULL == m_hSession) { + FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "Invalid Handle."); + return eFrameworkunifiedStatusInvldHandle; + } + + if (access("/dev/mmcblk1", F_OK) != 0) { + return eFrameworkunifiedStatusAccessError; + } + + eStatus = FrameworkunifiedSendMsg(m_hSession, SS_DEV_FORMAT_SD, 0, NULL); + + if (eFrameworkunifiedStatusOK != eStatus) { + FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "FrameworkunifiedSendMsg Send Error[0x%x]", eStatus); + return eStatus; + } + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-"); + return eStatus; +} // LCOV_EXCL_BR_LINE 10:Because the last line + diff --git a/systemservice/interface_unified/library/src/ss_framework_if.cpp b/systemservice/interface_unified/library/src/ss_framework_if.cpp new file mode 100755 index 0000000..91d323a --- /dev/null +++ b/systemservice/interface_unified/library/src/ss_framework_if.cpp @@ -0,0 +1,55 @@ +/* + * @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_SystemManagerIf +/// \brief This file provides support for the System Manager AGL framework +/// interface. +/// +/////////////////////////////////////////////////////////////////////////////// + +#include <native_service/frameworkunified_types.h> +#include <native_service/frameworkunified_framework_if.h> +#include <string.h> +#include "system_service/ss_system_if.h" +#include "system_service/interfaceunified_system_application.h" +#include "system_service/ss_services.h" +#include "system_service/ss_test_clients.h" +#include "system_service/ss_templates.h" +#include "ss_system_if_interfaceunifiedlog.h" + +HANDLE g_SystemIf_hApp = NULL; + +EFrameworkunifiedStatus FrameworkunifiedSSFrameworkInterface(HANDLE hApp) { + EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK; + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+"); + + g_SystemIf_hApp = hApp; + PCSTR pAppNameStr = FrameworkunifiedGetAppName(hApp); + + if (0 != strcmp(SERVICE_SYSMANAGER, pAppNameStr) && + 0 != strcmp(TC_Power, pAppNameStr)) { + l_eStatus = InterfaceunifiedSystemConnectToSystemManagerService(hApp); + LOG_STATUS(l_eStatus, "InterfaceunifiedSystemConnectToSystemManagerService()"); + + if (0 != strcmp(TC_SysManager, pAppNameStr)) { + l_eStatus = InterfaceunifiedSystemConnectToHeartBeatService(hApp); + LOG_STATUS(l_eStatus, "InterfaceunifiedSystemConnectToHeartBeatService()"); + } + } + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-"); + return l_eStatus; +} // LCOV_EXCL_BR_LINE 10:Because the last line diff --git a/systemservice/interface_unified/library/src/ss_heartbeat_client.cpp b/systemservice/interface_unified/library/src/ss_heartbeat_client.cpp new file mode 100755 index 0000000..a080e9a --- /dev/null +++ b/systemservice/interface_unified/library/src/ss_heartbeat_client.cpp @@ -0,0 +1,156 @@ +/* + * @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_SystemManagerIf +/// \brief This file provides support for the System Manager client +/// heartbeat service interface. +/// +/////////////////////////////////////////////////////////////////////////////// +#include <string.h> +#include <native_service/frameworkunified_application.h> +#include <native_service/frameworkunified_framework_if.h> +#include <native_service/frameworkunified_types.h> +#include <native_service/frameworkunified_framework_types.h> +#include <new> +#include "system_service/ss_heartbeat_service_protocol.h" +#include "system_service/ss_heartbeat_notifications.h" +#include "system_service/ss_heartbeat_if.h" +#include "system_service/ss_services.h" +#include "system_service/ss_sm_thread_names.h" +#include "system_service/ss_templates.h" +#include "ss_system_if_interfaceunifiedlog.h" + +CHeartBeatServiceIf * pHeartBeatServiceIf = NULL; + +template <typename C, eFrameworkunifiedStatus(C::*M)(HANDLE)> + +// LCOV_EXCL_START 6:Because process initialization +EFrameworkunifiedStatus HeartBeatIfCallback(HANDLE hApp) { + EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusNullPointer; + C * pObj = static_cast<C *>(pHeartBeatServiceIf); + if (pObj) { + l_eStatus = (pObj->*M)(hApp); + } + return l_eStatus; +} +// LCOV_EXCL_STOP + +/***************************************************************************** + @ingroup: SS_SystemManager + @brief: InterfaceunifiedSystemConnectToHeartBeatService + @note: . Called from framework for every app to start connection to HeartBeat + @param HANDLE - Handle to message queue of HeartBeat Service. + @return EFrameworkunifiedStatus OK or Fail +*****************************************************************************/ +EFrameworkunifiedStatus InterfaceunifiedSystemConnectToHeartBeatService(HANDLE hApp) { + EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK; + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+"); + /// Avoid opening a session to the HeartBeat + /// service Since it uses the framework as well + /// Avoid opening a session to System Manager For testing + // TODO(my_username): Remove system manager check + if ((0 != strcmp(SERVICE_SYSMANAGER, FrameworkunifiedGetAppName(hApp)))) { + FrameworkunifiedProtocolCallbackHandler g_aryHeartBeat_Protocol_Cbs[] = { + // Command ID, Call back functions + { SS_HEARTBEAT_REQUEST, HeartBeatIfCallback<CHeartBeatServiceIf, &CHeartBeatServiceIf::OnHeartBeatRequest>} + }; // LCOV_EXCL_BR_LINE 11:Unexpected branch + + /// Attach the valid callback for this service + if ( eFrameworkunifiedStatusOK != // LCOV_EXCL_BR_LINE 6:Because process initialization + (l_eStatus = FrameworkunifiedAttachCallbacksToDispatcher( + hApp, + SS_SMHeartbeat, + g_aryHeartBeat_Protocol_Cbs, + _countof(g_aryHeartBeat_Protocol_Cbs)))) { + LOG_ERROR("FrameworkunifiedAttachCallbacksToDispatcher()"); + } else { + // LCOV_EXCL_BR_LINE 5:Because constructor + pHeartBeatServiceIf = + new(std::nothrow) CHeartBeatServiceIf(FALSE, NULL, FrameworkunifiedGetAppName(hApp)); + } // LCOV_EXCL_BR_LINE 11:Unexpected branch + + } else { + FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__, "Heartbeat service name duplicated."); + } + + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-"); + + return l_eStatus; // LCOV_EXCL_BR_LINE 11:Unexpected branch +} + +/***************************************************************************** + @ingroup: SS_SystemManager + @brief: CHeartBeatServiceIf constructor + @param - +*****************************************************************************/ +CHeartBeatServiceIf::CHeartBeatServiceIf(BOOL avail, HANDLE service, PCSTR name) { + g_tHeartBeatSession.szServiceName = name; // LCOV_EXCL_BR_LINE 11:Unexpected branch + g_tHeartBeatSession.fAvailable = avail; + g_tHeartBeatSession.hService = service; +} + +// LCOV_EXCL_START 10:Because destructor +/***************************************************************************** + @ingroup: SS_SystemManager + @brief: CHeartBeatServiceIf destructor +*****************************************************************************/ +CHeartBeatServiceIf::~CHeartBeatServiceIf() { + if (pHeartBeatServiceIf != NULL) { + delete pHeartBeatServiceIf; + pHeartBeatServiceIf = NULL; + } +} +// LCOV_EXCL_STOP + +// LCOV_EXCL_START 6:Because process initialization +/***************************************************************************** + @ingroup: SS_SystemManager + @brief: OnHeartBeatRequest + @note: . + @param HANDLE - Handle to message queue of HeartBeat Service. + @return EFrameworkunifiedStatus OK or Fail +*****************************************************************************/ +EFrameworkunifiedStatus CHeartBeatServiceIf::OnHeartBeatRequest(HANDLE hApp) { + EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK; + BOOL l_availability; + + if (g_tHeartBeatSession.hService == NULL) { + if ( NULL == (g_tHeartBeatSession.hService = FrameworkunifiedMcOpenSender(hApp, SS_SMHeartbeat)) ) { + l_eStatus = eFrameworkunifiedStatusNullPointer; + FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, + " Error: FrameworkunifiedMcOpenSender(%s) returned NULL", + SS_SMHeartbeat); + return l_eStatus; + } + } + + if ( (0 == strcmp(SS_SMHeartbeat, FrameworkunifiedGetMsgSrc(hApp))) ) { + if (NULL != g_tHeartBeatSession.hService) { + l_availability = FrameworkunifiedGetSelfAvailability(hApp); + + if (eFrameworkunifiedStatusOK != (l_eStatus = FrameworkunifiedSendMsg(g_tHeartBeatSession.hService, SS_HEARTBEAT_RESPONSE, + sizeof(l_availability), &l_availability))) { + LOG_ERROR("FrameworkunifiedSendMsg"); + } + } else { + l_eStatus = eFrameworkunifiedStatusInvldHandle; + FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "Invalid handle[_g_hHeartBeatSessionHandle = :NULL]"); + } + } + return l_eStatus; +} +// LCOV_EXCL_STOP diff --git a/systemservice/interface_unified/library/src/ss_last_to_order.cpp b/systemservice/interface_unified/library/src/ss_last_to_order.cpp new file mode 100755 index 0000000..140101f --- /dev/null +++ b/systemservice/interface_unified/library/src/ss_last_to_order.cpp @@ -0,0 +1,186 @@ +/* + * @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 <stdint.h> +#include <stdio.h> +#include <string.h> +#include <agl_wakeup_order.h> +#include <list> +#include <fstream> +#include <iostream> +#include <stdexcept> +#include <string> +#include "system_service/ss_last_to_order.h" +#include "ss_last_to_order_local.h" + +#include "system_service/ss_templates.h" +#include "ss_system_if_interfaceunifiedlog.h" +#define SCO_STATE_LOG(...) FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__, __VA_ARGS__); +#define SCO_ERROR_LOG(...) FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, __VA_ARGS__); +#define SCO_ASSERT(x) SS_ASERT(x); + +//************* CONFIG FILE Format **************** +#define ORDERNAME_MAX 64 +#define CONTENT_NAME_MAX 128 +#pragma pack(push, 1) +typedef struct { + char lastinfo[SS_CCAT_MAX][CONTENT_NAME_MAX]; + char orderName[ORDERNAME_MAX]; +}SS_LASTINFO_TO_OEDER_PACKED_t; +#pragma pack(pop) +//************************************************* + + +typedef struct { + SS_LAST_INFO_t lastinfo; + std::string orderName; +}SS_LASTINFO_TO_OEDER_t; + + + +//**************************** +// load configuration file +//**************************** +static int +loadConfig(std::string &cfgPath, std::list<SS_LASTINFO_TO_OEDER_t> *p_cfgList) throw() { // NOLINT (runtime/references) + int ret = 0; + + try { + std::ifstream fin(cfgPath.c_str(), std::ios::in | std::ios::binary); + if (!fin) { + SCO_ERROR_LOG("cfg file error %s", cfgPath.c_str()); + throw std::domain_error("open error"); + } + char magic[4]; + + fin.read(reinterpret_cast<char*>(&magic), sizeof(magic)); + if (fin.fail()) { + throw std::domain_error("read magic"); + } + + if (memcmp(magic, "CTOO", sizeof(magic)) != 0) { + throw std::domain_error("magic error"); + } + + uint32_t numOfElement = 0; + fin.read(reinterpret_cast<char*>(&numOfElement), sizeof(numOfElement)); + if ( fin.fail() ) { + throw std::domain_error("read numOfElement"); + } + + for (uint32_t ii = 0; ii < numOfElement; ii++) { + SS_LASTINFO_TO_OEDER_PACKED_t element; + fin.read(reinterpret_cast<char*>(&element), sizeof(element)); + if ( fin.fail() ) { + throw std::domain_error("read element"); + } + SS_LASTINFO_TO_OEDER_t tmp; + tmp.lastinfo[SS_CCAT_F_VIDEO] = element.lastinfo[SS_CCAT_F_VIDEO]; + tmp.lastinfo[SS_CCAT_F_SUB_VIDEO] = element.lastinfo[SS_CCAT_F_SUB_VIDEO]; + tmp.lastinfo[SS_CCAT_F_AUDIO] = element.lastinfo[SS_CCAT_F_AUDIO]; + tmp.lastinfo[SS_CCAT_R_VIDEO] = element.lastinfo[SS_CCAT_R_VIDEO]; + tmp.lastinfo[SS_CCAT_R_AUDIO] = element.lastinfo[SS_CCAT_R_AUDIO]; + tmp.orderName = element.orderName; + p_cfgList->push_back(tmp); + } + SCO_STATE_LOG("%s is loaded", cfgPath.c_str()); + } catch (std::exception &e) { + if (ret == 0) ret = -1; + SCO_ERROR_LOG("%s", e.what()); + SCO_ASSERT(0); + } catch (...) { + SCO_ASSERT(0); + ret = -1; + } + return ret; +} + + + +static +bool +isPassCondition(SS_CONT_CATEGORY_t cat, SS_LAST_INFO_t &lastInfo, SS_LASTINFO_TO_OEDER_t &tblElement) { // NOLINT (runtime/references) + std::string &tblStr = tblElement.lastinfo[cat]; + + if (tblStr != "EMPTY") { + //Category with content specification + SS_LAST_INFO_t::iterator iteCont = lastInfo.find(cat); + if (iteCont == lastInfo.end() || iteCont->second != tblStr) { + return false; + } + } + return true; +} + + + +//**************************** +// SS_ConvLastInfoToOrder +//**************************** +EFrameworkunifiedStatus +SS_ConvLastInfoToOrder(SS_LAST_INFO_t &curInfo, std::string &order, const char* p_cfgPath/* = NULL*/) { // NOLINT (runtime/references) + std::string cfgPath = (p_cfgPath) ? p_cfgPath : SS_LAST_TO_ORDER_CONF_PATH; + + static std::list<SS_LASTINFO_TO_OEDER_t> s_convList; + static std::string s_readCfgPath = "__default__"; + bool isHit = false; + + // If the same CONFIG, do not READ after the second. + if (s_readCfgPath != cfgPath) { + int ret; + s_convList.clear(); + + ret = loadConfig(cfgPath, &s_convList); + if (ret != 0) { goto ERROR; } + s_readCfgPath = cfgPath; + +#if 0 // DEBUG + for (std::list<SS_LASTINFO_TO_OEDER_PACKED_t>::iterator tblElt = s_convList.begin(); + tblElt != s_convList.end(); + tblElt++) { + SCO_STATE_LOG("FV:%s FSV:%s FA:%s RV:%s RA:%s O:%s", + tblElt->lastinfo[SS_CCAT_F_VIDEO], tblElt->lastinfo[SS_CCAT_F_SUB_VIDEO], tblElt->lastinfo[SS_CCAT_F_AUDIO], + tblElt->lastinfo[SS_CCAT_R_VIDEO], tblElt->lastinfo[SS_CCAT_R_AUDIO], tblElt->orderName); + } +#endif + } + + for (std::list<SS_LASTINFO_TO_OEDER_t>::iterator tblElt = s_convList.begin(); + tblElt != s_convList.end(); + tblElt++) { + if (isPassCondition(SS_CCAT_F_VIDEO , curInfo, *tblElt) == false) { + continue; + } else if (isPassCondition(SS_CCAT_F_SUB_VIDEO, curInfo, *tblElt) == false) { + continue; + } else if (isPassCondition(SS_CCAT_F_AUDIO , curInfo, *tblElt) == false) { + continue; + } else if (isPassCondition(SS_CCAT_R_VIDEO , curInfo, *tblElt) == false) { + continue; + } else if (isPassCondition(SS_CCAT_R_AUDIO , curInfo, *tblElt) == false) { + continue; + } + + isHit = true; + order = tblElt->orderName; + break; + } + if (!isHit) { + order = WON_DEFAULT; + } + return eFrameworkunifiedStatusOK; +ERROR: + return eFrameworkunifiedStatusFail; +} diff --git a/systemservice/interface_unified/library/src/ss_logger_service_ifc.cpp b/systemservice/interface_unified/library/src/ss_logger_service_ifc.cpp new file mode 100755 index 0000000..1766bfa --- /dev/null +++ b/systemservice/interface_unified/library/src/ss_logger_service_ifc.cpp @@ -0,0 +1,781 @@ +/* + * @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_SystemServices_Logger +/// \brief This file supports the _CWORD77_ logger service. +/// +/////////////////////////////////////////////////////////////////////////////// +#include "system_service/ss_logger_service_ifc.h" +#include <string.h> +#include <native_service/frameworkunified_application.h> +#include <native_service/frameworkunified_framework_if.h> +#include <native_service/frameworkunified_types.h> +#include <native_service/frameworkunified_framework_types.h> +#include <string> +#include "system_service/ss_logger_service_protocol.h" +#include "system_service/ss_logger_service_notifications.h" +#include "system_service/ss_logger_service.h" +#include "system_service/ss_logger_service_local.h" +#include "system_service/ss_services.h" +#include "ss_logger_service_if_interfaceunifiedlog.h" + +LoggerServiceIf::LoggerServiceIf() + : m_hApp(NULL), + m_hService(NULL), + m_hSession(NULL) { +} + +LoggerServiceIf::~LoggerServiceIf() { + CloseSessionRequest(); // if the session is still connected + + m_hService = NULL; + m_hSession = NULL; + m_hApp = NULL; +} // LCOV_EXCL_BR_LINE 10:Because destructor + +EFrameworkunifiedStatus LoggerServiceIf::NotifyOnLoggerServiceAvailability( + CbFuncPtr f_pCallBackFn) { + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+"); + EFrameworkunifiedStatus eStatus = eFrameworkunifiedStatusInvldHandle; + if (NULL != m_hApp && NULL != f_pCallBackFn) { + // Subscriptions + FrameworkunifiedNotificationCallbackHandler g_aryLogger_Notif_Cbs[] = { + // Notifications name, Call back function + { NTFY_SS_LoggerService_Availability, f_pCallBackFn }, }; + + if (0 != strcmp(SERVICE_LOGGER, FrameworkunifiedGetAppName(m_hApp))) { + // Subscribe and attach call backs to notifications + if (eFrameworkunifiedStatusOK + != (eStatus = FrameworkunifiedSubscribeNotificationsWithCallback( + m_hApp, g_aryLogger_Notif_Cbs, _countof(g_aryLogger_Notif_Cbs)))) { + FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, + "FrameworkunifiedAttachNotificationCallbacksToDispatcher Failed Status:0x%x ", + eStatus); + } + } + } + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-"); + return eStatus; +} + +EFrameworkunifiedStatus LoggerServiceIf::NotifyOnOpenSessionAck(CbFuncPtr f_pCallBackFn) { + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+"); + EFrameworkunifiedStatus eStatus = eFrameworkunifiedStatusInvldHandle; + if (NULL != m_hApp && NULL != f_pCallBackFn) { + if (eFrameworkunifiedStatusOK + != (eStatus = FrameworkunifiedAttachCallbackToDispatcher(m_hApp, + SERVICE_LOGGER, + PROTOCOL_OPEN_SESSION_ACK, + f_pCallBackFn))) { + FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, + "FrameworkunifiedAttachCallbackToDispatcher Failed Status:0x%x ", eStatus); + } + } + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-"); + return eStatus; +} + +EFrameworkunifiedStatus LoggerServiceIf::NotifyOnCloseSessionAck(CbFuncPtr f_pCallBackFn) { + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+"); + EFrameworkunifiedStatus eStatus = eFrameworkunifiedStatusInvldHandle; + + if (NULL != m_hApp && NULL != f_pCallBackFn) { + if (eFrameworkunifiedStatusOK + != (eStatus = FrameworkunifiedAttachCallbackToDispatcher(m_hApp, + SERVICE_LOGGER, + PROTOCOL_CLOSE_SESSION_ACK, + f_pCallBackFn))) { + FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, + "FrameworkunifiedAttachCallbackToDispatcher Failed Status:0x%x ", eStatus); + } + } + + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-"); + return eStatus; +} + +BOOL LoggerServiceIf::Initialize(HANDLE hApp) { + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+"); + BOOL l_eStatus = TRUE; + + if (NULL != hApp) { + m_hApp = hApp; + } else { + l_eStatus = FALSE; // eFrameworkunifiedStatusInvldHandle; + } + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-"); + return l_eStatus; +} + +EFrameworkunifiedStatus LoggerServiceIf::OpenSessionRequest() { + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+"); + EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusInvldHandle; + if (NULL != m_hApp) { + // if the session is there then we need to close it first! + if (NULL != m_hService) { + CloseSessionRequest(); + m_hService = NULL; + } + BOOL l_bServiceAvailable = FrameworkunifiedIsServiceAvailable(m_hApp); + if (FALSE == l_bServiceAvailable) { + FRAMEWORKUNIFIEDLOG(ZONE_ERR, __PRETTY_FUNCTION__, "Service is unavailable"); + l_eStatus = eFrameworkunifiedStatusFail; + } else { + // Now open the service. + if (l_bServiceAvailable + && (NULL != (m_hService = OpenService()))) { // LCOV_EXCL_BR_LINE 8:Because bServiceAvailable is always TRUE + // [DM: TODO] Check if we need to open a session with some data sent to Server. + UI_32 l_pTestData = 1; + if (eFrameworkunifiedStatusOK + != (l_eStatus = FrameworkunifiedOpenSessionWithData(m_hService, + (PVOID) &l_pTestData, + sizeof(UI_32)))) { + FRAMEWORKUNIFIEDLOG(ZONE_ERR, __PRETTY_FUNCTION__, + "FrameworkunifiedOpenSessionWithData Failed, errval :%d", l_eStatus); + } + } else { + l_eStatus = eFrameworkunifiedStatusFail; + FRAMEWORKUNIFIEDLOG(ZONE_ERR, __PRETTY_FUNCTION__, + "FrameworkunifiedOpenService Failed, errval :%d", l_eStatus); + } + } + } + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-"); + return l_eStatus; +} + +HANDLE LoggerServiceIf::OpenService() { + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+"); + HANDLE l_hService = NULL; + + if (NULL == (l_hService = FrameworkunifiedOpenService(m_hApp, SERVICE_LOGGER))) { + FRAMEWORKUNIFIEDLOG(ZONE_ERR, __PRETTY_FUNCTION__, + "FrameworkunifiedOpenService : Failed to open Logger Service"); + } + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-"); + return l_hService; +} + +EFrameworkunifiedStatus LoggerServiceIf::DecodeOpenSessionResponse() { + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+"); + EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusInvldHandle; + std::string l_strSessionName; + if (NULL != m_hService + && NULL != m_hApp) { // LCOV_EXCL_BR_LINE 8:Because there is no case where m_hApp is NULL and m_hService is not NULL + if (NULL == (m_hSession = FrameworkunifiedGetOpenSessionHandle(m_hApp))) { + FRAMEWORKUNIFIEDLOG(ZONE_ERR, __PRETTY_FUNCTION__, + "Error in extracting OpenSessionAck response."); + l_eStatus = eFrameworkunifiedStatusFail; + } else { + l_eStatus = eFrameworkunifiedStatusOK; + l_strSessionName = FrameworkunifiedGetSessionName(m_hSession); + if (l_strSessionName.empty()) { + l_eStatus = eFrameworkunifiedStatusFail; + FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "SessionName is empty"); + } else { + if (eFrameworkunifiedStatusOK + != (FrameworkunifiedSetSessionHandle(m_hApp, l_strSessionName.c_str(), m_hSession))) { + l_eStatus = eFrameworkunifiedStatusFail; + FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "Error: FrameworkunifiedSetSessionHandle() failed"); + } + } + } + } + + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-"); + return l_eStatus; +} + +EFrameworkunifiedStatus LoggerServiceIf::CloseSessionRequest() { + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+"); + EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusInvldHandle; + + if (NULL != m_hService && NULL != m_hSession) { + if (eFrameworkunifiedStatusOK != (l_eStatus = FrameworkunifiedCloseSession(m_hService, m_hSession))) { + FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "FrameworkunifiedCloseSession Failed"); + } + m_hSession = NULL; // clear our session handle + } + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-"); + return l_eStatus; +} + +EFrameworkunifiedStatus LoggerServiceIf::RegisterForLoggerEvent( + SS_LoggerServerEvents f_eLoggerEvent, CbFuncPtr f_pCallBackFn) { + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+"); + EFrameworkunifiedStatus eStatus = eFrameworkunifiedStatusInvldHandle; + + if (NULL != m_hSession && NULL != f_pCallBackFn) { + if (eFrameworkunifiedStatusOK + != (eStatus = FrameworkunifiedAttachCallbackToDispatcher(m_hApp, + SERVICE_LOGGER, + f_eLoggerEvent, + f_pCallBackFn, m_hSession))) { + FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, + "FrameworkunifiedAttachCallbackToDispatcher Failed Status:0x%x ", eStatus); + } + + // client registers for the event + if (eFrameworkunifiedStatusOK + != (eStatus = FrameworkunifiedRegisterEvent(m_hSession, f_eLoggerEvent))) { + FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "FrameworkunifiedRegisterEvents Failed Status:0x%x", + eStatus); + } + FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__, "FrameworkunifiedRegisterEvents Status:0x%x", eStatus); + } + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-"); + return eStatus; +} + +EFrameworkunifiedStatus LoggerServiceIf::UnRegisterForLoggerEvent( + SS_LoggerServerEvents f_eLoggerEvent) { + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+"); + EFrameworkunifiedStatus eStatus = eFrameworkunifiedStatusInvldHandle; + + if (NULL != m_hSession) { + eStatus = eFrameworkunifiedStatusOK; + } + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-"); + return eStatus; +} + +//////////////////////////////////////////////////////////////////////////////////////////// +/// SendDiagStat +/// API to send CAN Diagnostic status data(it has mileage info) to Logger Service +/// (Command: SS_LOGGER_MILEAGE_DATA) +/// +/// \return status +/// EFrameworkunifiedStatus - success or error +//////////////////////////////////////////////////////////////////////////////////////////// + +EFrameworkunifiedStatus LoggerServiceIf::SendDiagStat(STLOGGER_CANDIAGSTAT *pCanDiagStat_t) { + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+"); + EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusInvldHandle; + STLOGGER_CANDIAGSTAT l_candiagstat; + + memcpy(&l_candiagstat, pCanDiagStat_t, sizeof(STLOGGER_CANDIAGSTAT)); + + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "Before Valid Session"); + if (NULL != m_hService && NULL != m_hSession) { + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "Entered Valid Session"); + if (eFrameworkunifiedStatusOK + != (l_eStatus = FrameworkunifiedSendMsg(m_hSession, SS_LOGGER_MILEAGE_DATA, + sizeof(STLOGGER_CANDIAGSTAT), &l_candiagstat))) { + FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "FrameworkunifiedSendMsg Failed"); + } + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "Msg Send Successfully"); + } + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-"); + return l_eStatus; +} + +/////////////////////////////////////////////////////////////////////// +/// Function :LoggerIf_CANGetCurrentDateAndTime +/////////////////////////////////////////////////////////////////////// +EFrameworkunifiedStatus LoggerServiceIf::LoggerIf_CANGetCurrentDateAndTime( + STCanCurrentDateTime stDateAndTime) { + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+"); + EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusInvldHandle; + + if (NULL != m_hService && NULL != m_hSession) { + if (eFrameworkunifiedStatusOK + != (l_eStatus = FrameworkunifiedSendMsg(m_hSession, SS_LOGGER_SET_DATETIME, + sizeof(stDateAndTime), &stDateAndTime))) { + FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "FrameworkunifiedSendMsg Failed"); + } + } + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-"); + return l_eStatus; +} + +/////////////////////////////////////////////////////////////////////// +/// Function :LoggerIf_CANSetVIN +/////////////////////////////////////////////////////////////////////// +EFrameworkunifiedStatus LoggerServiceIf::LoggerIf_CANSetVIN(STVIN_NUMBER& stVinNumber) { + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+"); + EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusInvldHandle; + + stVinNumber.VINstr[stVinNumber.VIN_LEN - 1] = '\0'; + + if (NULL != m_hService && NULL != m_hSession) { + if (eFrameworkunifiedStatusOK + != (l_eStatus = FrameworkunifiedSendMsg(m_hSession, SS_LOGGER_SET_VIN, + sizeof(STVIN_NUMBER), &stVinNumber))) { + FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "FrameworkunifiedSendMsg() Failed with error: %X", + l_eStatus); + } + } else { + FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "Service or Session Handle NULL"); + } + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-"); + return l_eStatus; +} + +//////////////////////////////////////////////////////////////////////////////////////////// +/// LoggerIf_SetLoggerParams +/// API is to inform Logger Service about the device selected to store the logs +/// and about Enable/Disable Logging. +/// (Command: SS_LOGGER_SET_PARAMS) +/// +/// \return status +/// EFrameworkunifiedStatus - success or error +//////////////////////////////////////////////////////////////////////////////////////////// +EFrameworkunifiedStatus LoggerServiceIf::LoggerIf_SetLoggerParams(ELOGGER_STAT eLoggerStatus, + EDEV_TYPE eDevType) { + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+"); + EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusInvldHandle; + STLoggerSetParams l_stLoggerParams; + + l_stLoggerParams.Logger_State = eLoggerStatus; + l_stLoggerParams.Device_Type = eDevType; + + if (NULL != m_hService && NULL != m_hSession) { + if (eFrameworkunifiedStatusOK + != (l_eStatus = FrameworkunifiedSendMsg(m_hSession, SS_LOGGER_SET_PARAMS, + sizeof(STLoggerSetParams), &l_stLoggerParams))) { + FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "FrameworkunifiedSendMsg Failed"); + } + } + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-"); + return l_eStatus; +} + +//////////////////////////////////////////////////////////////////////////////////////////// +/// LoggerIf_UDPLogging +/// API is to inform Logger Service about UDP logging +/// and about Enable/Disable Logging. +/// (Command: SS_LOGGER_UDP_LOGGING) +/// +/// \return status +/// EFrameworkunifiedStatus - success or error +//////////////////////////////////////////////////////////////////////////////////////////// +EFrameworkunifiedStatus LoggerServiceIf::LoggerIf_UDPLogging(ELOGGER_STAT eLoggerStatus) { + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+"); + EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusInvldHandle; + + if (NULL != m_hService && NULL != m_hSession) { + if (eFrameworkunifiedStatusOK + != (l_eStatus = FrameworkunifiedSendMsg(m_hSession, SS_LOGGER_UDP_LOGGING, + sizeof(ELOGGER_STAT), &eLoggerStatus))) { + FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "FrameworkunifiedSendMsg Failed"); + } + } + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-"); + return l_eStatus; +} + +EFrameworkunifiedStatus LoggerServiceIf::LoggerIf_ScreenCaptureEventACK( + STScreenCaptureEvt stScreenCaptureInfo) { + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+"); + EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusInvldHandle; + + if (NULL != m_hSession) { + if (eFrameworkunifiedStatusOK + != (l_eStatus = FrameworkunifiedSendMsg(m_hSession, SS_LOGGER_SCREENCAPTURE_EVT_ACK, + sizeof(stScreenCaptureInfo), + &stScreenCaptureInfo))) { + FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "FrameworkunifiedSendMsg Failed"); + } else { + FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__, " Screen shot ACK sent successfully."); + } + } else { + FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, + "Error. m_hSession is NULL. Screen shot capture ACK not sent."); + } + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-"); + return l_eStatus; +} + +/////////////////////////////////////////////////////////////////////// +/// Function :LoggerIf_EventLoggingCommonInfo +/////////////////////////////////////////////////////////////////////// +EFrameworkunifiedStatus LoggerServiceIf::LoggerIf_EventLoggingCommonInfo( + STEventLoggerCommonInfo stEventCommonInfo) { + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+"); + EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusInvldHandle; + + if (NULL != m_hService && NULL != m_hSession) { + if (eFrameworkunifiedStatusOK + != (l_eStatus = FrameworkunifiedSendMsg(m_hSession, SS_LOGGER_EVENT_COMMONINFO, + sizeof(stEventCommonInfo), + &stEventCommonInfo))) { + FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "FrameworkunifiedSendMsg Failed"); + } + } + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-"); + return l_eStatus; +} + +/////////////////////////////////////////////////////////////////////// +/// Function :LoggerIf_EventLoggingEventInfo +/////////////////////////////////////////////////////////////////////// +EFrameworkunifiedStatus LoggerServiceIf::LoggerIf_EventLoggingEventInfo( + STEventLoggerEventInfo stEventInfo) { + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+"); + EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusInvldHandle; + + if (NULL != m_hService && NULL != m_hSession) { + if (eFrameworkunifiedStatusOK + != (l_eStatus = FrameworkunifiedSendMsg(m_hSession, SS_LOGGER__CWORD56__EVENT_INFO, + sizeof(stEventInfo), &stEventInfo))) { + FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "FrameworkunifiedSendMsg Failed"); + } + } + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-"); + return l_eStatus; +} + +/////////////////////////////////////////////////////////////////////// +/// Function :LoggerIf_EventLoggingResetInfo +/// (Command: SS_LOGGER__CWORD56__RESET_INFO) +/////////////////////////////////////////////////////////////////////// +EFrameworkunifiedStatus LoggerServiceIf::LoggerIf_EventLoggingResetInfo( + STEventLoggerResetInfo stResetInfo) { + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+"); + EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusInvldHandle; + + if (NULL != m_hService && NULL != m_hSession) { + if (eFrameworkunifiedStatusOK + != (l_eStatus = FrameworkunifiedSendMsg(m_hSession, SS_LOGGER__CWORD56__RESET_INFO, + sizeof(stResetInfo), &stResetInfo))) { + FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "FrameworkunifiedSendMsg Failed"); + } + } + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-"); + return l_eStatus; +} + +/////////////////////////////////////////////////////////////////////// +/// Function :LoggerIf_EventLoggingResetInfo +/// (Command: SS_LOGGER_DIAGDTC_ACTIVE) +/////////////////////////////////////////////////////////////////////// +EFrameworkunifiedStatus LoggerServiceIf::LoggerIf_PersistEventLogOnActiveDTC(void) { + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+"); + EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusInvldHandle; + + if (NULL != m_hService && NULL != m_hSession) { + if (eFrameworkunifiedStatusOK + != (l_eStatus = FrameworkunifiedSendMsg(m_hSession, SS_LOGGER_DIAGDTC_ACTIVE, 0x00, + NULL))) { + FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "FrameworkunifiedSendMsg Failed"); + } + } + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-"); + return l_eStatus; +} + +/////////////////////////////////////////////////////////////////////// +/// Function :LoggerIf_EventLoggingResetInfo +/// (Command: SS_LOGGER_SHUTDOWN_COMPLETE) +/////////////////////////////////////////////////////////////////////// +EFrameworkunifiedStatus LoggerServiceIf::LoggerIf_Shutdown_Complete(void) { + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+"); + EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusInvldHandle; + + if (NULL != m_hService && NULL != m_hSession) { + if (eFrameworkunifiedStatusOK + != (l_eStatus = FrameworkunifiedSendMsg(m_hSession, SS_LOGGER_SHUTDOWN_COMPLETE, + 0x00, NULL))) { + FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "FrameworkunifiedSendMsg Failed"); + } + } + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-"); + return l_eStatus; +} + +/////////////////////////////////////////////////////////////////////// +/// Function :StoreEventLogsToUSB +/////////////////////////////////////////////////////////////////////// +EFrameworkunifiedStatus LoggerServiceIf::StoreEventLogsToUSB( + EEvtLogUSBDevNumber eUSBDevNumber) { + + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+"); + + EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusInvldHandle; + + FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__, + "Copy the Event logs in to USB command received:%X", eUSBDevNumber); + + if (NULL != m_hSession) { + if (eFrameworkunifiedStatusOK + != (l_eStatus = FrameworkunifiedSendMsg(m_hSession, SS_LOGGERCOPYEVENTUSB, + sizeof(EEvtLogUSBDevNumber), &eUSBDevNumber))) { + FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "FrameworkunifiedSendMsg Failed"); + } + } else { + FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "Session failed"); + } + + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-"); + return l_eStatus; +} + +/////////////////////////////////////////////////////////////////////// +/// Function :StoreEmergencyErrorLogsToUSB +/////////////////////////////////////////////////////////////////////// +EFrameworkunifiedStatus LoggerServiceIf::StoreEmergencyErrorLogsToUSB( + EDevNumber eDevNumber) { + + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+"); + + EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusInvldHandle; + + FRAMEWORKUNIFIEDLOG( + ZONE_INFO, __FUNCTION__, + "Copy the Emergency Error logs in to External Device command received:%X", + eDevNumber); + + if (NULL != m_hSession) { + if (eFrameworkunifiedStatusOK + != (l_eStatus = FrameworkunifiedSendMsg(m_hSession, SS_LOGGERCOPYEMERGENCYLOGS, + sizeof(EDevNumber), &eDevNumber))) { + FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "FrameworkunifiedSendMsg Failed"); + } + } else { + FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "Session failed"); + } + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-"); + return l_eStatus; +} + +/////////////////////////////////////////////////////////////////////// +/// Function :ClearEventLogs +/////////////////////////////////////////////////////////////////////// +EFrameworkunifiedStatus LoggerServiceIf::ClearEventLogs(void) { + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+"); + + EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusInvldHandle; + + FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__, "Request for clearing the event logs"); + + if (NULL != m_hSession) { + if (eFrameworkunifiedStatusOK + != (l_eStatus = FrameworkunifiedSendMsg(m_hSession, SS_LOGGERCLEAREVENT, 0, NULL))) { + FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "FrameworkunifiedSendMsg Failed"); + } + } else { + FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "Session failed"); + } + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-"); + return l_eStatus; +} + +/////////////////////////////////////////////////////////////////////// +/// Function :ReadStatisticalCounter +/////////////////////////////////////////////////////////////////////// +EFrameworkunifiedStatus LoggerServiceIf::ReadStatisticalCounter( + EStatCounterGroupID eCounterGroup) { + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+"); + + EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusInvldHandle; + + FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__, + "Request to read the statistical counter for group ID:%X", + eCounterGroup); + + if (NULL != m_hSession) { + if (eFrameworkunifiedStatusOK + != (l_eStatus = FrameworkunifiedSendMsg(m_hSession, SS_LOGGER_READ_STATL_COUNTER, + sizeof(EStatCounterGroupID), &eCounterGroup))) { + FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "FrameworkunifiedSendMsg Failed"); + } + } else { + FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "Session failed"); + } + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-"); + return l_eStatus; +} + +/////////////////////////////////////////////////////////////////////// +/// Function :ReadStatisticalCounter +/////////////////////////////////////////////////////////////////////// +EFrameworkunifiedStatus LoggerServiceIf::ResetStatisticalCounter( + EStatCounterGroupID eCounterGroup) { + + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+"); + + EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusInvldHandle; + + FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__, + "Request to reset the statistical counter for group ID:%X", + eCounterGroup); + + if (NULL != m_hSession) { + if (eFrameworkunifiedStatusOK + != (l_eStatus = FrameworkunifiedSendMsg(m_hSession, SS_LOGGER_RESET_STATL_COUNTER, + sizeof(EStatCounterGroupID), &eCounterGroup))) { + FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "FrameworkunifiedSendMsg Failed"); + } + } else { + FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "Session failed"); + } + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-"); + return l_eStatus; +} + +/////////////////////////////////////////////////////////////////////// +/// Function LoggerServiceIf::StartDTCLoggingToEmmc +/////////////////////////////////////////////////////////////////////// +EFrameworkunifiedStatus LoggerServiceIf::StartDTCLoggingToEmmc(UI_32 f_dtc) { + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+"); + EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusInvldHandle; + FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__, "Request to start logging for DTC:0x%4X", + f_dtc); + l_eStatus = this->SendMessage(eSSLoggerCANProtocolIDDTCTrigger, + (UI_32) sizeof(f_dtc), &f_dtc); + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-"); + return l_eStatus; +} + +/////////////////////////////////////////////////////////////////////// +/// Function LoggerServiceIf::StartCANLogging +/////////////////////////////////////////////////////////////////////// +EFrameworkunifiedStatus LoggerServiceIf::StartCANLogging(void) { + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+"); + EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusInvldHandle; + FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__, "Request to start CAN logging."); + l_eStatus = this->SendMessage(eSSLoggerCANProtocolIDCANTrigger, 0, NULL); + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-"); + return l_eStatus; +} + +/////////////////////////////////////////////////////////////////////// +/// Function LoggerServiceIf::RegisterLoggingStartNotification +/////////////////////////////////////////////////////////////////////// +EFrameworkunifiedStatus LoggerServiceIf::RegisterLoggingStartNotification( + CbFuncPtr f_pCallBackFn) { + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+"); + EFrameworkunifiedStatus l_eStatus; + + if (NULL == this->m_hApp) { + l_eStatus = eFrameworkunifiedStatusNullPointer; + FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "(NULL == this->m_hApp)"); + } else if (NULL == f_pCallBackFn) { + l_eStatus = eFrameworkunifiedStatusNullPointer; + FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "(NULL == f_pCallBackFn)"); + } else { + l_eStatus = FrameworkunifiedSubscribeToSessionEventWithCallback(this->m_hApp, + eSSLoggerCANEventStart, + f_pCallBackFn, + this->m_hSession); + if (eFrameworkunifiedStatusOK != l_eStatus) { + FRAMEWORKUNIFIEDLOG( + ZONE_ERR, + __FUNCTION__, + "FrameworkunifiedSubscribeToSessionEventWithCallback(eSSLoggerCANEventStart) returned %X", + l_eStatus); + } + } + + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-"); + return (l_eStatus); +} + +/////////////////////////////////////////////////////////////////////// +/// Function LoggerServiceIf::RegisterLoggingStartNotification +/////////////////////////////////////////////////////////////////////// +EFrameworkunifiedStatus LoggerServiceIf::RegisterLoggingFinishNotification( + CbFuncPtr f_pCallBackFn) { + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+"); + EFrameworkunifiedStatus l_eStatus; + + if (NULL == this->m_hApp) { + l_eStatus = eFrameworkunifiedStatusNullPointer; + FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "(NULL == this->m_hApp)"); + } else if (NULL == f_pCallBackFn) { + l_eStatus = eFrameworkunifiedStatusNullPointer; + FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "(NULL == f_pCallBackFn)"); + } else { + l_eStatus = FrameworkunifiedSubscribeToSessionEventWithCallback( + this->m_hApp, eSSLoggerCANEventFinished, f_pCallBackFn, + this->m_hSession); + + if (eFrameworkunifiedStatusOK != l_eStatus) { + FRAMEWORKUNIFIEDLOG( + ZONE_ERR, + __FUNCTION__, + "FrameworkunifiedSubscribeToSessionEventWithCallback(eSSLoggerCANEventFinished) returned %X", + l_eStatus); + } + } + + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-"); + return (l_eStatus); +} + +/////////////////////////////////////////////////////////////////////// +/// Function :SendMessage +/////////////////////////////////////////////////////////////////////// +EFrameworkunifiedStatus LoggerServiceIf::SendMessage(UI_32 f_cmdID, UI_32 f_size, + void* f_pData) { + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+"); + EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusInvldHandle; + + if ((NULL != m_hSession) + && ((f_pData != NULL) || (f_size == 0))) { // LCOV_EXCL_BR_LINE 8:Because there is no case where f_pData is NULL and f_size is not 0 + if (eFrameworkunifiedStatusOK + != (l_eStatus = FrameworkunifiedSendMsg(m_hSession, f_cmdID, f_size, f_pData))) { + FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "FrameworkunifiedSendMsg Failed"); + } + } else { + FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "Session failed"); + } + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-"); + return l_eStatus; +} + +/////////////////////////////////////////////////////////////////////// +/// Function :LoggerIf_SetDiagID +/////////////////////////////////////////////////////////////////////// +EFrameworkunifiedStatus LoggerServiceIf::LoggerIf_SetDiagID(UI_16 f_u16DiagID) { + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+"); + EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK; + + if (NULL != m_hSession) { + if (eFrameworkunifiedStatusOK + != (l_eStatus = FrameworkunifiedSendMsg(m_hSession, SS_LOGGER_SET_DIAGID, + sizeof(UI_16), &f_u16DiagID))) { + FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "FrameworkunifiedSendMsg Failed %d", l_eStatus); + } + } else { + l_eStatus = eFrameworkunifiedStatusNullPointer; + FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "Session failed"); + } + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-"); + return l_eStatus; +} + +/////////////////////////////////////////////////////////////////////// +/// Function :LoggerIf_UploadEventLog +/////////////////////////////////////////////////////////////////////// +EFrameworkunifiedStatus LoggerServiceIf::LoggerIf_UploadEventLog() { + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+"); + EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK; + + if (NULL != m_hSession) { + if (eFrameworkunifiedStatusOK + != (l_eStatus = FrameworkunifiedSendMsg(m_hSession, SS_LOGGER_UPLOAD_EVENTLOG, 0x00, + NULL))) { + FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "FrameworkunifiedSendMsg Failed %d", l_eStatus); + } + } else { + l_eStatus = eFrameworkunifiedStatusNullPointer; + FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "Session failed"); + } + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-"); + return l_eStatus; +} // LCOV_EXCL_BR_LINE 10:Because the last line diff --git a/systemservice/interface_unified/library/src/ss_power_client.cpp b/systemservice/interface_unified/library/src/ss_power_client.cpp new file mode 100755 index 0000000..30bdbaa --- /dev/null +++ b/systemservice/interface_unified/library/src/ss_power_client.cpp @@ -0,0 +1,254 @@ +/* + * @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_PowerServiceIf +/// \brief This file supports Power Service client management. +/// +/////////////////////////////////////////////////////////////////////////////// + +#include <inttypes.h> +#include <string.h> +#include <native_service/frameworkunified_application.h> +#include <native_service/frameworkunified_framework_if.h> +#include <native_service/frameworkunified_types.h> +#include <native_service/frameworkunified_framework_types.h> +#include <string> +#include "system_service/ss_power_service.h" +#include "system_service/ss_power_service_protocol.h" +#include "system_service/ss_power_service_notifications.h" +#include "system_service/ss_services.h" +#include "system_service/ss_system_if.h" +#include "system_service/ss_templates.h" +#include "ss_power_if_interfaceunifiedlog.h" + +typedef struct { + BOOL fAvailable; + HANDLE hSession; + HANDLE hService; + std::string szServiceName; +} TPowerSession; + +static EFrameworkunifiedStatus OnPowerCloseSesionAck(HANDLE hApp); +static EFrameworkunifiedStatus OnPowerOpenSessionAck(HANDLE hApp); +static EFrameworkunifiedStatus OnPowerAvailability(HANDLE hApp); +static EFrameworkunifiedStatus OnPowerAvailable(HANDLE hApp); +static EFrameworkunifiedStatus OnPowerUnavailable(HANDLE hApp); +static TPowerSession g_tPowerSession = { }; + +/// Base on the a user group affiliation we will call there start and stop methods +/// Note: there group and subgroup strings are empty we will call start on the every +/// first case of +EFrameworkunifiedStatus InterfaceunifiedSystemConnectToPowerSerivce(HANDLE hApp) { + EFrameworkunifiedStatus eStatus = eFrameworkunifiedStatusOK; + FRAMEWORKUNIFIEDLOG0(ZONE_FUNC, __FUNCTION__, "+"); + + // Subscriptions + FrameworkunifiedNotificationCallbackHandler g_aryPower_Notif_Cbs[] = { + // Notifications name, Call back function + { szNTFY_PowerAvailability, OnPowerAvailability }, }; + + /// Avoid opening a session to the Power + /// service Since it uses the framework as well + if (0 != strcmp(SERVICE_POWER, FrameworkunifiedGetAppName(hApp))) { + // Subscribe and attach call backs to notifications, to Notification Service! + if (eFrameworkunifiedStatusOK + != (eStatus = FrameworkunifiedSubscribeNotificationsWithCallback( + hApp, g_aryPower_Notif_Cbs, _countof(g_aryPower_Notif_Cbs)))) { + FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, + "FrameworkunifiedAttachNotificationCallbacksToDispatcher Failed Status:0x%x ", + eStatus); + } else { + /// Need to save the Group and Subgroup values + g_tPowerSession.szServiceName = FrameworkunifiedGetAppName(hApp); + + /// Cleanup any other data members + g_tPowerSession.fAvailable = FALSE; + g_tPowerSession.hService = NULL; + g_tPowerSession.hSession = NULL; + } + } + + FRAMEWORKUNIFIEDLOG0(ZONE_FUNC, __FUNCTION__, "-"); + + return eStatus; +} + +EFrameworkunifiedStatus OnPowerAvailability(HANDLE hApp) { + EFrameworkunifiedStatus eStatus = eFrameworkunifiedStatusFail; + FRAMEWORKUNIFIEDLOG0(ZONE_FUNC, __FUNCTION__, "+"); + + FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__, + "Power Service Availability notification received ****"); + + if (sizeof(BOOL) == FrameworkunifiedGetMsgLength(hApp)) { + BOOL avalibility = FALSE; + if (eFrameworkunifiedStatusOK + == (eStatus = FrameworkunifiedGetMsgDataOfSize(hApp, &avalibility, sizeof(BOOL)))) { + if (TRUE == avalibility) { + eStatus = OnPowerAvailable(hApp); + } else { + eStatus = OnPowerUnavailable(hApp); + } + } else { + FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, + "FrameworkunifiedAttachNotificationCallbacksToDispatcher Failed Status:0x%x ", + eStatus); + } + } + + FRAMEWORKUNIFIEDLOG0(ZONE_FUNC, __FUNCTION__, "-"); + return eStatus; +} + +EFrameworkunifiedStatus OnPowerAvailable(HANDLE hApp) { + EFrameworkunifiedStatus eStatus = eFrameworkunifiedStatusFail; + + FRAMEWORKUNIFIEDLOG0(ZONE_FUNC, __FUNCTION__, "+"); + + // if the service is available before the close happens then close the session and service first. + if (NULL != g_tPowerSession.hService && NULL != g_tPowerSession.hSession) { + EFrameworkunifiedStatus interfaceunifiedRet = FrameworkunifiedCloseSession(g_tPowerSession.hService, + g_tPowerSession.hSession); + SS_ASERT(interfaceunifiedRet == eFrameworkunifiedStatusOK); + g_tPowerSession.hSession = NULL; + g_tPowerSession.hService = NULL; + } + + PCSTR power_name = FrameworkunifiedGetMsgSrc(hApp); + + // opening the service + if (NULL == (g_tPowerSession.hService = FrameworkunifiedOpenService(hApp, power_name))) { + FRAMEWORKUNIFIEDLOG0(ZONE_ERR, __FUNCTION__, "Power: Failed to open service"); + } else { + FrameworkunifiedProtocolCallbackHandler g_aryPower_Protocol_Cbs[] = { + // Command ID, Call back functions + { PROTOCOL_OPEN_SESSION_ACK, OnPowerOpenSessionAck }, + { PROTOCOL_CLOSE_SESSION_ACK, OnPowerCloseSesionAck }, }; + + /// Attach the valid callback for this service + if (eFrameworkunifiedStatusOK + == (eStatus = FrameworkunifiedAttachCallbacksToDispatcher( + hApp, power_name, g_aryPower_Protocol_Cbs, + _countof(g_aryPower_Protocol_Cbs)))) { + EPWR_SESSION_TYPE tOpenSessionReq = epsstBASIC; + /// opening the session with service + if (eFrameworkunifiedStatusOK + != (eStatus = FrameworkunifiedOpenSessionWithData(g_tPowerSession.hService, + &tOpenSessionReq, + sizeof(tOpenSessionReq)))) { + FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "FrameworkunifiedOpenSession Failed Status:0x%x ", + eStatus); + } + + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "%s has received PowerService Available.", + FrameworkunifiedGetAppName(hApp)); + } else { + FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, + "FrameworkunifiedAttachCallbacksToDispatcher Failed Status:0x%x ", eStatus); + } + } + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-"); + return eStatus; +} + +EFrameworkunifiedStatus OnPowerUnavailable(HANDLE hApp) { + EFrameworkunifiedStatus eStatus = eFrameworkunifiedStatusOK; + + FRAMEWORKUNIFIEDLOG0(ZONE_FUNC, __FUNCTION__, "+"); + if (0 == strcmp(SERVICE_POWER, FrameworkunifiedGetAppName(hApp))) { + if ((g_tPowerSession.hSession != NULL) + && (g_tPowerSession.hService != NULL)) { + if (eFrameworkunifiedStatusOK + != (eStatus = FrameworkunifiedCloseSession(g_tPowerSession.hService, + g_tPowerSession.hSession))) { + FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "FrameworkunifiedCloseSession Failed Status:0x%x", + eStatus); + } + g_tPowerSession.hSession = NULL; + g_tPowerSession.hService = NULL; + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, + "%s has received PowerService Unavailable.", FrameworkunifiedGetAppName(hApp)); + } else { + FRAMEWORKUNIFIEDLOG( + ZONE_ERR, + __FUNCTION__, + "Error INVALID HANDLE [g_tPowerSession.hSession :0x%" PRIxPTR "]; [g_tPowerSession.hService :0x%" PRIxPTR "] ", // NOLINT (whitespace/line_length) + (uintptr_t) g_tPowerSession.hSession, (uintptr_t) g_tPowerSession.hService); + } + } else { + eStatus = eFrameworkunifiedStatusOK; + } + FRAMEWORKUNIFIEDLOG0(ZONE_FUNC, __FUNCTION__, "-"); + + return eStatus; +} + +/////////////////////////////////////////////////////////// +/// Function: OnHeartBeatClientOpenSessionAck +/// HeartBeat Service OpenSession callback +/////////////////////////////////////////////////////////// +EFrameworkunifiedStatus OnPowerOpenSessionAck(HANDLE hApp) { + EFrameworkunifiedStatus eStatus = eFrameworkunifiedStatusFail; + FRAMEWORKUNIFIEDLOG0(ZONE_FUNC, __FUNCTION__, "+"); + + g_tPowerSession.hSession = FrameworkunifiedGetOpenSessionHandle(hApp); + if (NULL != g_tPowerSession.hSession) { + g_tPowerSession.fAvailable = TRUE; + eStatus = eFrameworkunifiedStatusOK; + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, + "%s Session to PowerService has been successfully opened.", + FrameworkunifiedGetAppName(hApp)); + } else { + FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "FrameworkunifiedGetOpenSessionHandle returned : %" PRIxPTR "", + (uintptr_t) g_tPowerSession.hSession); + g_tPowerSession.hSession = NULL; + } + + FRAMEWORKUNIFIEDLOG0(ZONE_FUNC, __FUNCTION__, "-"); + + return eStatus; +} + +/////////////////////////////////////////////////////////// +/// Function: OnHeartBeatClientCloseSessionAck +/// HeartBeat Service CloseSession callback +/////////////////////////////////////////////////////////// +EFrameworkunifiedStatus OnPowerCloseSesionAck(HANDLE hApp) { + EFrameworkunifiedStatus eStatus = eFrameworkunifiedStatusOK; + + FRAMEWORKUNIFIEDLOG0(ZONE_FUNC, __FUNCTION__, "+"); + + // Close Service + if (NULL != g_tPowerSession.hService) { + eStatus = FrameworkunifiedCloseService(hApp, g_tPowerSession.hService); + if (eFrameworkunifiedStatusOK != eStatus) { + FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, " Error: FrameworkunifiedCloseService() errored %d/'%s", + eStatus, GetStr(eStatus).c_str()); + } + g_tPowerSession.hService = NULL; + g_tPowerSession.hSession = NULL; + } + g_tPowerSession.fAvailable = FALSE; + eStatus = eFrameworkunifiedStatusOK; + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, + "%s Session to PowerService has been successfully closed.", + FrameworkunifiedGetAppName(hApp)); + + FRAMEWORKUNIFIEDLOG0(ZONE_FUNC, __FUNCTION__, "-"); + + return eStatus; +} diff --git a/systemservice/interface_unified/library/src/ss_pwrsvc_if.cpp b/systemservice/interface_unified/library/src/ss_pwrsvc_if.cpp new file mode 100755 index 0000000..86d8ebb --- /dev/null +++ b/systemservice/interface_unified/library/src/ss_pwrsvc_if.cpp @@ -0,0 +1,343 @@ +/* + * @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_PowerServiceIf +/// \brief This file supports the Power Service module interface. +/// +/////////////////////////////////////////////////////////////////////////////// +#include "system_service/ss_power_service_if.h" +#include <string.h> +#include <native_service/frameworkunified_application.h> +#include <native_service/frameworkunified_framework_if.h> +#include <native_service/frameworkunified_types.h> +#include <native_service/frameworkunified_framework_types.h> +#include "system_service/ss_power_service.h" +#include "system_service/ss_power_service_protocol.h" +#include "system_service/ss_power_service_notifications.h" +#include "system_service/ss_system_if.h" +#include "system_service/ss_services.h" +#include "system_service/ss_string_maps.h" +#include "system_service/ss_templates.h" +#include "ss_power_if_interfaceunifiedlog.h" + +HANDLE OpenPowerService(HANDLE f_hApp) { + EFrameworkunifiedStatus l_eStatus; + HANDLE l_hService = NULL; + if (NULL == f_hApp) { + l_eStatus = eFrameworkunifiedStatusInvldHandle; + LOG_ERROR("NULL == f_App"); + } else if (NULL == (l_hService = FrameworkunifiedOpenService(f_hApp, SERVICE_POWER))) { + l_eStatus = eFrameworkunifiedStatusNullPointer; + LOG_ERROR("FrameworkunifiedOpenService(f_hApp, SERVICE_POWER)"); + } + return l_hService; +} + +EFrameworkunifiedStatus ClosePowerService(HANDLE f_hApp, HANDLE f_hService) { + EFrameworkunifiedStatus l_eStatus; + if (NULL == f_hApp) { + l_eStatus = eFrameworkunifiedStatusInvldHandle; + LOG_ERROR("NULL == f_App"); + } else if (NULL == f_hService) { + l_eStatus = eFrameworkunifiedStatusInvldHandle; + LOG_ERROR("NULL == f_hService"); + } else { + l_eStatus = FrameworkunifiedCloseService(f_hApp, f_hService); + LOG_STATUS(l_eStatus, "FrameworkunifiedCloseService(f_hApp, f_hService)"); + f_hService = NULL; + } + return l_eStatus; +} + +/////////////////////////////////////////////////////////////////////////////////////////////////// +/// Session Related Requests +/// Any client can also use FrameworkunifiedOpenSession and FrameworkunifiedOpenSessionWithData. +/// In that case, the PVOID data passed as a parameter should be MM_OpenSessionRequestIf +/// to open a session with the Power Service. +/// The client can also use the below API for Opening a session with Power Service. +/////////////////////////////////////////////////////////////////////////////////////////////////// + +EFrameworkunifiedStatus PwrServiceOpenSessionRequest(HANDLE f_hService, + EPWR_SESSION_TYPE f_eSessionType) { + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+"); + EFrameworkunifiedStatus l_eStatus; + + if (NULL == f_hService) { + l_eStatus = eFrameworkunifiedStatusInvldHandle; + LOG_ERROR("NULL == f_hService"); + } else if (epsstUNKNOWN == f_eSessionType) { + l_eStatus = eFrameworkunifiedStatusInvldParam; + LOG_ERROR("epsstUNKNOWN == f_eSessionType"); + } else { + l_eStatus = FrameworkunifiedOpenSessionWithData(f_hService, &f_eSessionType, + sizeof(f_eSessionType)); + LOG_STATUS(l_eStatus, "FrameworkunifiedOpenSessionWithData()"); + } + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-"); + return l_eStatus; +} + +EFrameworkunifiedStatus PwrServiceCloseSessionRequest(HANDLE f_hService, HANDLE f_hSession) { + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+"); + EFrameworkunifiedStatus l_eStatus; + + if (NULL == f_hService) { + l_eStatus = eFrameworkunifiedStatusInvldHandle; + LOG_ERROR("NULL == f_hService"); + } else if (NULL == f_hSession) { + l_eStatus = eFrameworkunifiedStatusInvldHandle; + LOG_ERROR("NULL == f_hSession"); + } else { + CALL_AND_LOG_STATUS(FrameworkunifiedCloseSession(f_hService, f_hSession)); + } + + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-"); + return l_eStatus; +} + +EFrameworkunifiedStatus PwrServiceDecodeOpenSessionResponse(HANDLE f_hApp, + HANDLE& f_hSession) { // NOLINT (runtime/references) + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+"); + EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK; + + if (NULL == f_hApp) { + l_eStatus = eFrameworkunifiedStatusInvldHandle; + LOG_ERROR("NULL == f_App"); + } else { + if (NULL == (f_hSession = FrameworkunifiedGetOpenSessionHandle(f_hApp))) { + FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, + " Error: FrameworkunifiedGetOpenSessionHandle('%s') returned NULL", + FrameworkunifiedGetAppName(f_hApp)); + l_eStatus = eFrameworkunifiedStatusNullPointer; + } + } + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-"); + return l_eStatus; +} + +EFrameworkunifiedStatus PwrServiceSetVoltageState(HANDLE f_hSession, + EPWR_VOLTAGE_STATE_TYPE f_eVoltage_state) { + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+"); + EFrameworkunifiedStatus l_eStatus; + if (NULL == f_hSession) { + l_eStatus = eFrameworkunifiedStatusInvldHandle; + LOG_ERROR("NULL == f_hSession"); + } else if (epsvsINVALID == f_eVoltage_state) { + l_eStatus = eFrameworkunifiedStatusInvldParam; + LOG_ERROR("epsvsINVALID == f_eVoltage_state"); + } else { + Pwr_ServiceSetInterface l_tServiceSetIf; + std::memset(&l_tServiceSetIf, 0, sizeof(l_tServiceSetIf)); + l_tServiceSetIf.data.voltage.state = f_eVoltage_state; + l_eStatus = FrameworkunifiedSendMsg(f_hSession, SS_POWER_VOLTAGE_STATE, + sizeof(l_tServiceSetIf), (PVOID) &l_tServiceSetIf); + LOG_STATUS(l_eStatus, "FrameworkunifiedSendMsg(SS_POWER_VOLTAGE_STATE)"); + } + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-"); + return l_eStatus; +} + +EFrameworkunifiedStatus PwrServiceSetCrankState(HANDLE f_hSession, + EPWR_CRANK_STATE_TYPE f_eCrank_state) { + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+"); + EFrameworkunifiedStatus l_eStatus; + + if (NULL == f_hSession) { + l_eStatus = eFrameworkunifiedStatusInvldHandle; + LOG_ERROR("NULL == f_hSession"); + } else if (epscsINVALID == f_eCrank_state) { + l_eStatus = eFrameworkunifiedStatusInvldParam; + LOG_ERROR("epsvsINVALID == f_eCrank_state"); + } else { + Pwr_ServiceSetInterface l_tServiceSetIf; + std::memset(&l_tServiceSetIf, 0, sizeof(l_tServiceSetIf)); + l_tServiceSetIf.data.crank.state = f_eCrank_state; + l_eStatus = FrameworkunifiedSendMsg(f_hSession, SS_POWER_CRANK_STATE, + sizeof(l_tServiceSetIf), (PVOID) &l_tServiceSetIf); + LOG_STATUS(l_eStatus, "FrameworkunifiedSendMsg(SS_POWER_CRANK_STATE)"); + } + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-"); + return l_eStatus; +} + +EFrameworkunifiedStatus PwrServiceSendShutdownRequest( + HANDLE f_hSession, EPWR_SHUTDOWN_REQUEST_MSG_STRUCT &f_eState) { // NOLINT (runtime/references) + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+"); + EFrameworkunifiedStatus l_eStatus; + if (NULL == f_hSession) { + l_eStatus = eFrameworkunifiedStatusInvldHandle; + LOG_ERROR("NULL == f_hSession"); + } else { + Pwr_ServiceSetInterface l_tServiceSetIf; + std::memset(&l_tServiceSetIf, 0, sizeof(l_tServiceSetIf)); + l_tServiceSetIf.data.shutdownRequestMsg = f_eState; + l_eStatus = FrameworkunifiedSendMsg(f_hSession, SS_POWER_SHUTDOWN_REQUEST_MSG, + sizeof(l_tServiceSetIf), &l_tServiceSetIf); + + LOG_STATUS(l_eStatus, "FrameworkunifiedSendMsg(SS_POWER_SHUTDOWN_REQUEST_MSG)"); + } + + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-"); + return l_eStatus; +} // End of EFrameworkunifiedStatus PwrServiceSendShutdownRequest( + +EFrameworkunifiedStatus PwrServiceSendSetShutdownPopupRequest( + HANDLE f_hSession, EPWR_SHUTDOWN_POPUP_TYPE f_eShutdownPopup) { + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+"); + EFrameworkunifiedStatus l_eStatus; + if (NULL == f_hSession) { + l_eStatus = eFrameworkunifiedStatusInvldHandle; + LOG_ERROR("NULL == f_hSession"); + } else { + Pwr_ServiceSetInterface l_tServiceSetIf; + std::memset(&l_tServiceSetIf, 0, sizeof(l_tServiceSetIf)); + switch (f_eShutdownPopup) { + case epsspPowerSave1: + case epsspPowerSave2: + case epsspPowerSave3: + case epsspPowerSaveClr: + case epsspLowVoltage1: + case epsspLowVoltage2: + case epsspLowVoltage3: + case epsspLowVoltageClr: + case epsspBattCouplingSW1: + case epsspBattCouplingSW2: + case epsspBattCouplingSW3: + case epsspBattCouplingSWClr: + case epsspAbnormalTemp_1st: + case epsspAbnormalTemp_Clr: + case epsspLimpHome_1st: + case epsspLimpHome_2nd: + case epsspLimpHome_3rd: + case epsspLimpHome_Clr: + case epsspProdMd_1st: + case epsspProdMd_Clr: + case epsspTransMd_1st: + case epsspTransMd_Clr: + case epsspAllClr: + l_tServiceSetIf.data.shutdownPopup.shutdownPopupEvent = + f_eShutdownPopup; + l_eStatus = FrameworkunifiedSendMsg(f_hSession, + SS_POWER_PUBLISH_SHUTDOWN_CONDITION_REQ, + sizeof(l_tServiceSetIf), &l_tServiceSetIf); + LOG_STATUS(l_eStatus, + "FrameworkunifiedSendMsg(SS_POWER_PUBLISH_SHUTDOWN_CONDITION_REQ)"); + break; + + default: + FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, + " Error: Unknown 'ShutdownPopup' value: 0x%X/%d", + f_eShutdownPopup, f_eShutdownPopup); + l_eStatus = eFrameworkunifiedStatusInvldParam; + break; + } + } + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-"); + return l_eStatus; +} // End of EFrameworkunifiedStatus PwrServiceSendSetShutdownPopupRequest( HANDLE f_hSession, + +EFrameworkunifiedStatus PwrServiceSendStartupConfirmationMsgRequest( + HANDLE f_hSession, EPWR_SC_MSG_STRUCT f_eState) { + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+"); + EFrameworkunifiedStatus l_eStatus; + if (NULL == f_hSession) { + l_eStatus = eFrameworkunifiedStatusInvldHandle; + LOG_ERROR("NULL == f_hSession"); + } else { + Pwr_ServiceSetInterface l_tServiceSetIf; + std::memset(&l_tServiceSetIf, 0, sizeof(l_tServiceSetIf)); + l_tServiceSetIf.data.startupConfirmationMsg = f_eState; + l_eStatus = FrameworkunifiedSendMsg(f_hSession, SS_POWER_FWD_START_CONFIRMATION_MSG_REQ, + sizeof(l_tServiceSetIf), &l_tServiceSetIf); + + LOG_STATUS(l_eStatus, "FrameworkunifiedSendMsg(SS_POWER_FWD_START_CONFIRMATION_MSG_REQ)"); + } + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-"); + return l_eStatus; +} // End of EFrameworkunifiedStatus PwrServiceSendStartupConfirmationMsgRequest ( HANDLE f_hSession, + +EFrameworkunifiedStatus PwrServiceSystemModeInfoRequest(HANDLE f_hSession) { + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+"); + EFrameworkunifiedStatus l_eStatus; + if (NULL == f_hSession) { + l_eStatus = eFrameworkunifiedStatusInvldHandle; + LOG_ERROR("NULL == f_hSession"); + } else { + l_eStatus = FrameworkunifiedSendMsg(f_hSession, SS_POWER_SYSTEM_MODE_INFO_REQ, 0, NULL); + LOG_STATUS(l_eStatus, "FrameworkunifiedSendMsg(SS_POWER_SYSTEM_MODE_INFO_REQ)"); + } + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-"); + return l_eStatus; +} + +EFrameworkunifiedStatus PwrServiceSendInitCompReport(HANDLE f_hSession) { + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+"); + EFrameworkunifiedStatus l_eStatus; + if (NULL == f_hSession) { + l_eStatus = eFrameworkunifiedStatusInvldHandle; + LOG_ERROR("NULL == f_hSession"); + } else { + l_eStatus = FrameworkunifiedSendMsg(f_hSession, SS_POWER_INITCOMP_REP, 0, NULL); + LOG_STATUS(l_eStatus, "FrameworkunifiedSendMsg(SS_POWER_INITCOMP_REP)"); + } + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-"); + return l_eStatus; +} + +EFrameworkunifiedStatus PwrServiceSendPowerRequest( + HANDLE f_hSession, EPWR_POWER_REQUEST_MSG_STRUCT_WITH_UMCR &f_eState) { // NOLINT (runtime/references) + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+"); + EFrameworkunifiedStatus l_eStatus; + if (NULL == f_hSession) { + l_eStatus = eFrameworkunifiedStatusInvldHandle; + LOG_ERROR("NULL == f_hSession"); + } else { + Pwr_ServiceSetInterface l_tServiceSetIf; + std::memset(&l_tServiceSetIf, 0, sizeof(l_tServiceSetIf)); + l_tServiceSetIf.data.powerRequestMsg = f_eState; + l_eStatus = FrameworkunifiedSendMsg(f_hSession, SS_POWER_POWER_REQUEST_MSG, + sizeof(l_tServiceSetIf), (PVOID) &l_tServiceSetIf); + + char l_cBuf[200] = { 0 }; + snprintf( + l_cBuf, + sizeof(l_cBuf), + "FrameworkunifiedSendMsg(SS_POWER_POWER_REQUEST_MSG(%s, %s))", + GetStr(l_tServiceSetIf.data.powerRequestMsg.userMode).c_str(), + GetStr(l_tServiceSetIf.data.powerRequestMsg.userModeChangeReason).c_str()); + LOG_STATUS(l_eStatus, l_cBuf); + } + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-"); + return l_eStatus; +} // End of EFrameworkunifiedStatus PwrServiceSendPowerRequest( HANDLE f_hSession + +EFrameworkunifiedStatus PwrServiceSendHeartBeatRequest(HANDLE f_hSession, + EPWR_HB_REQ_MSG_STRUCT *f_eHbReqMsg) { + FRAMEWORKUNIFIEDLOG0(ZONE_FUNC, __FUNCTION__, "+"); + EFrameworkunifiedStatus l_eStatus; + if (NULL == f_hSession) { + l_eStatus = eFrameworkunifiedStatusInvldHandle; + LOG_ERROR("NULL == f_hSession"); + } else { + l_eStatus = FrameworkunifiedSendMsg(f_hSession, SS_POWER_HEARTBEAT_REQ, + sizeof(EPWR_HB_REQ_MSG_STRUCT), + reinterpret_cast<void *>(f_eHbReqMsg)); + LOG_STATUS(l_eStatus, "FrameworkunifiedSendMsg(SS_POWER_HEARTBEAT_REQ)"); + } + FRAMEWORKUNIFIEDLOG0(ZONE_FUNC, __FUNCTION__, "-"); + return l_eStatus; +} // LCOV_EXCL_BR_LINE 10:Because the last line diff --git a/systemservice/interface_unified/library/src/ss_sm_client.cpp b/systemservice/interface_unified/library/src/ss_sm_client.cpp new file mode 100755 index 0000000..664a98d --- /dev/null +++ b/systemservice/interface_unified/library/src/ss_sm_client.cpp @@ -0,0 +1,1509 @@ +/* + * @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_SystemManagerIf +/// \brief This file provides support for the System Manager client interface. +/// +/////////////////////////////////////////////////////////////////////////////// +#include "system_service/ss_sm_client_if.h" +#include <sys/mount.h> +#include <errno.h> +#include <string.h> +#include <fcntl.h> + +#include <native_service/frameworkunified_application.h> +#include <native_service/frameworkunified_framework_if.h> +#include <native_service/frameworkunified_types.h> +#include <native_service/frameworkunified_framework_types.h> +#include <native_service/frameworkunified_dispatcher.h> +#include <native_service/frameworkunified_sm_framework_dispatch.h> +#include <native_service/frameworkunified_sm_hsmframework.h> + +#include <string> + +#include "system_service/ss_system_manager_if.h" +#include "system_service/ss_system_manager_protocol.h" +#include "system_service/ss_system_manager_notifications.h" +#include "system_service/ss_system_if.h" +#include "system_service/ss_services.h" +#include "system_service/ss_power_service_protocol.h" +#include "system_service/ss_templates.h" +#include "system_service/ss_string_maps.h" +#include "system_service/ss_error_message.h" +#include "system_service/ss_sm_client_if_local.h" + +#include "system_service/ss_boot_map.h" +#include "ss_system_if_interfaceunifiedlog.h" + +typedef struct { + BOOL fAvailable; + HANDLE hService; + std::string szServiceName; + std::string strIAm; +} TSystemManagerSession; // LCOV_EXCL_BR_LINE 11:Unexpected branch + +typedef enum { + MODULE_STATE_INVALID = 0, /// Initial state of all modules + MODULE_STATE_CONNECTING, /// Attempting to established a session connection + MODULE_STATE_CONNECTED, /// A session connection has been established + MODULE_STATE_STARTING, /// Received a START from System Manager, + /// called FrameworkunifiedOnStart or enqueued evStart + MODULE_STATE_START_FAILED, /// Application returned error from FrameworkunifiedOnStart + MODULE_STATE_STARTED, /// Sent Start Response to System Manager + MODULE_STATE_STOPPING, /// Received a Stop Request from System Manager, + /// called FrameworkunifiedOnStop or enqueued evStop + MODULE_STATE_STOP_FAILED, /// Application returned error from FrameworkunifiedOnStop + MODULE_STATE_STOPPED, /// Sent Start Response to System Manager + MODULE_STATE_DEBUG_DUMPING, + MODULE_STATE_STARTED_PRE, //!< Sent Pre-Start Response to System Manager + MODULE_STATE_START_PRE_FAILED, //!< Application returned error from FrameworkunifiedOnPreStart + MODULE_STATE_STOPPED_PRE, //!< Sent Pre-Stop Response to System Manager + MODULE_STATE_STOP_PRE_FAILED, //!< Application returned error from FrameworkunifiedOnPreStop + MODULE_STATE_STARTED_BACKGROUND, //!< Sent Background-Start Response to System Manager + MODULE_STATE_START_BACKGROUND_FAILED, //!< Application returned error from FrameworkunifiedOnBackgroundStart + MODULE_STATE_STOPPED_BACKGROUND, //!< Sent Background-Stop Response to System Manager + MODULE_STATE_STOP_BACKGROUND_FAILED //!< Application returned error from FrameworkunifiedOnBackgroundStop +} ModuleStateType; + +static SMStopCompleteAck g_responseCompleteAck; + +static EFrameworkunifiedStatus OnSystemManagerStart(HANDLE hApp); +static EFrameworkunifiedStatus OnSystemManagerStop(HANDLE hApp); +static EFrameworkunifiedStatus OnSystemManagerPreStart(HANDLE hApp); +static EFrameworkunifiedStatus OnSystemManagerPreStop(HANDLE hApp); +static EFrameworkunifiedStatus OnSystemManagerBackgroundStart(HANDLE hApp); +static EFrameworkunifiedStatus OnSystemManagerBackgroundStop(HANDLE hApp); +static EFrameworkunifiedStatus OnSystemManagerOpenSessionAck(HANDLE hApp); +static EFrameworkunifiedStatus DebugDumpAppCbStatistics(HANDLE hApp); +static EFrameworkunifiedStatus DebugDumpMemoryMap(HANDLE hApp); +static EFrameworkunifiedStatus SystemManagerOpenSender(HANDLE hApp); + +static TSystemManagerSession g_tSystemManagerSession = { }; // LCOV_EXCL_BR_LINE 11:Unexpected branch +static pthread_mutex_t gMutexObj = PTHREAD_MUTEX_INITIALIZER; + +static EFrameworkunifiedStatus SendMsgToSystemManager(UI_32 uiCmd, UI_32 uiLength, + PCVOID pData); +static EFrameworkunifiedStatus SendMsgToSystemManager(UI_32 uiCmd, PCSTR f_pCmdName, + UI_32 uiLength, PCVOID pData); + +static EFrameworkunifiedStatus InvokeSyncRequestToSystemManager(UI_32 uiCmd, + PCSTR f_pCmdName, + UI_32 uiLength, PCVOID pData, + UI_32 uiResLength, + PVOID pResData); + +static EFrameworkunifiedStatus CommonSystemManagerStartStopCallbackProcessing( + HANDLE hApp, UI_32 f_InterfaceunifiedEvID, SS_String f_pInterfaceunifiedEvName, CbFuncPtr f_InterfaceunifiedFncCb, + PCSTR f_pInterfaceunifiedFncName, ModuleStateType f_moduleSuccessState, + ModuleStateType f_moduleFailureState, BOOL f_bUseNotificationVsFncFlag, + PCSTR f_pUseNotificationText, SS_SystemManagerProtocol f_ProtocolId, + PCSTR f_pProtocolName); + +static EFrameworkunifiedStatus SendInterfaceunifiedOnResponseToSystemManager( + SS_SystemManagerProtocol f_ProtocolID, PCSTR f_pProtocolName, + PCSTR f_InterfaceunifiedOnFncName, ModuleStateType f_moduleSuccessState, + ModuleStateType f_moduleFailureState, EFrameworkunifiedStatus f_eStatus); + +// Pointer of function which is called when SM OpenSession Ack is received. +// client can register this function pointer using RegisterSMSessionAckCallback() API +static CbFuncPtr CallbackFnPtr = NULL; + +static BOOL UseStopCompleteNotificationVsInterfaceunifiedOnStopFnc = FALSE; + +static VOID LoadCbHandlerCmdIDsIntoDetachCbIDsArray( + const FrameworkunifiedProtocolCallbackHandler* pMsgHandler, UI_32 * puiCmdIdArray, + UI_32 uiHandlerCount); + +static VOID SetModuleState(ModuleStateType f_moduleState, BOOL f_bLog = TRUE); + +static ModuleStateType g_moduleState = MODULE_STATE_INVALID; +extern HANDLE g_SystemIf_hApp; + +//****************************************************************************** +void Init_SS_IF_ModuleState_StrMap( + std::map<ModuleStateType, SS_String> & m_strMap) { // NOLINT (runtime/references) +// LCOV_EXCL_BR_START 11:Unexpected branch + MAP_ENTRY(m_strMap, MODULE_STATE_INVALID); + MAP_ENTRY(m_strMap, MODULE_STATE_CONNECTING); + MAP_ENTRY(m_strMap, MODULE_STATE_CONNECTED); + MAP_ENTRY(m_strMap, MODULE_STATE_STARTING); + MAP_ENTRY(m_strMap, MODULE_STATE_START_FAILED); + MAP_ENTRY(m_strMap, MODULE_STATE_STARTED); + MAP_ENTRY(m_strMap, MODULE_STATE_STOPPING); + MAP_ENTRY(m_strMap, MODULE_STATE_STOP_FAILED); + MAP_ENTRY(m_strMap, MODULE_STATE_STOPPED); + MAP_ENTRY(m_strMap, MODULE_STATE_STARTED_PRE); + MAP_ENTRY(m_strMap, MODULE_STATE_START_PRE_FAILED); + MAP_ENTRY(m_strMap, MODULE_STATE_STOPPED_PRE); + MAP_ENTRY(m_strMap, MODULE_STATE_STOP_PRE_FAILED); + MAP_ENTRY(m_strMap, MODULE_STATE_STARTED_BACKGROUND); + MAP_ENTRY(m_strMap, MODULE_STATE_START_BACKGROUND_FAILED); + MAP_ENTRY(m_strMap, MODULE_STATE_STOPPED_BACKGROUND); + MAP_ENTRY(m_strMap, MODULE_STATE_STOP_BACKGROUND_FAILED); + MAP_ENTRY(m_strMap, MODULE_STATE_DEBUG_DUMPING); +// LCOV_EXCL_BR_STOP +} // End of void Init_SS_IF_ModuleState_StrMap(std::map<ModuleStateType, SS_String> & m_strMap) + +class EnumStringMap<ModuleStateType, Init_SS_IF_ModuleState_StrMap> g_oSS_IF_ModuleStateStrMap; + +// LCOV_EXCL_START 6:Because the condition cannot be set +SS_String GetStr(ModuleStateType f_enum) { + return g_oSS_IF_ModuleStateStrMap.GetStr(f_enum); +} + +HANDLE GetSystemManagerSessionHandle(void) { + return g_tSystemManagerSession.hService; +} // End of HANDLE GetSystemManagerSessionHandle(void) +// LCOV_EXCL_STOP + +EFrameworkunifiedStatus InterfaceunifiedSystemConnectToSystemManagerService(HANDLE hApp) { + EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK; + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+"); + + CallbackFnPtr = NULL; + + /// Avoid opening a session to the SystemManager + /// service Since it uses the framework as well + if (0 != strcmp(SERVICE_SYSMANAGER, FrameworkunifiedGetAppName(hApp))) { + // LCOV_EXCL_BR_LINE 6:Duplicate check(AppName has been checked by the caller) + memset(&g_responseCompleteAck, 0, sizeof(g_responseCompleteAck)); + g_responseCompleteAck.unSessionId = 0; + strcpy(g_responseCompleteAck.szServiceName, SERVICE_SYSMANAGER); // NOLINT (runtime/printf) + + pthread_mutex_lock(&gMutexObj); + + /// Need to save the Group and Subgroup values + g_tSystemManagerSession.szServiceName = SERVICE_SYSMANAGER; + g_tSystemManagerSession.strIAm = FrameworkunifiedGetAppName(hApp); + + /// Cleanup any other data members + g_tSystemManagerSession.fAvailable = FALSE; + g_tSystemManagerSession.hService = NULL; + + pthread_mutex_unlock(&gMutexObj); + + l_eStatus = SystemManagerOpenSender(hApp); + + LOG_STATUS_IF_ERRORED(l_eStatus, "SystemManagerOpenSender()"); + } else { + // LCOV_EXCL_START 6:Duplicate check(AppName has been checked by the caller) + FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__, + " I am SystemManager ! Not registering for '%s' notification", + NTFY_SSSystemMgrAvailability); + // LCOV_EXCL_STOP + } + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-"); + return l_eStatus; +} + +/////////////////////////////////////////////////////////// +/// Function: SystemManagerOpenSender +/// +/////////////////////////////////////////////////////////// + +EFrameworkunifiedStatus SystemManagerOpenSender(HANDLE hApp) { + EFrameworkunifiedStatus l_eStatus; + + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+"); + + pthread_mutex_lock(&gMutexObj); + + // LCOV_EXCL_START 6:Duplicate check(hService is NULL only) + if (g_tSystemManagerSession.hService != NULL) { + FRAMEWORKUNIFIEDLOG(ZONE_WARN, __FUNCTION__, " Warn: hService != NULL"); + pthread_mutex_unlock(&gMutexObj); + return eFrameworkunifiedStatusFail; + } + // LCOV_EXCL_STOP + + // opening the service + if (NULL + == (g_tSystemManagerSession.hService = FrameworkunifiedMcOpenSender(hApp, + SERVICE_SYSMANAGER))) { + l_eStatus = eFrameworkunifiedStatusNullPointer; + LOG_ERROR("FrameworkunifiedMcOpenSender(SERVICE_SYSMANAGER)"); + } else { + FrameworkunifiedProtocolCallbackHandler l_SystemManager_Protocol_Cbs[] = { + // Command ID, Call back functions + { SS_SM_PROTOCOL_OPEN_SESSION_ACK, OnSystemManagerOpenSessionAck }, + { SS_SM_START, OnSystemManagerStart }, + { SS_SM_STOP, OnSystemManagerStop }, + { SS_SM_PRE_START, OnSystemManagerPreStart }, + { SS_SM_PRE_STOP, OnSystemManagerPreStop }, + { SS_SM_BACKGROUND_START, OnSystemManagerBackgroundStart }, + { SS_SM_BACKGROUND_STOP, OnSystemManagerBackgroundStop }, + { SS_SM_DEBUG_DUMP, OnSystemManagerDebugDump }, + }; // LCOV_EXCL_BR_LINE 11:Unexpected branch + + /// Attach the valid callback for this service + if (eFrameworkunifiedStatusOK != // LCOV_EXCL_BR_LINE 11:Unexpected branch + (l_eStatus = FrameworkunifiedAttachCallbacksToDispatcher( + hApp, SERVICE_SYSMANAGER, l_SystemManager_Protocol_Cbs, + _countof(l_SystemManager_Protocol_Cbs)))) { + LOG_ERROR("FrameworkunifiedAttachCallbacksToDispatcher()"); + } else if (eFrameworkunifiedStatusOK != // LCOV_EXCL_BR_LINE 11:Unexpected branch + (l_eStatus = FrameworkunifiedSendMsg(g_tSystemManagerSession.hService, + SS_SM_PROTOCOL_OPEN_SESSION_REQ, 0, NULL))) { + FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, " Error: FrameworkunifiedSendMsg(%s) errored: 0x%X/%s", + g_tSystemManagerSession.szServiceName.c_str(), l_eStatus, + GetStr(l_eStatus).c_str()); + } // LCOV_EXCL_BR_LINE 11:Unexpected branch + } + pthread_mutex_unlock(&gMutexObj); + + if (eFrameworkunifiedStatusOK == l_eStatus) { + g_moduleState = MODULE_STATE_CONNECTING; + } + + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-"); + return l_eStatus; // LCOV_EXCL_BR_LINE 11:Unexpected branch +} + +// LCOV_EXCL_START 6:Because the condition cannot be set +/////////////////////////////////////////////////////////// +/// Function: OnSystemManagerOpenSessionAck +/// Service Manager OpenSession callback +/////////////////////////////////////////////////////////// +EFrameworkunifiedStatus OnSystemManagerOpenSessionAck(HANDLE hApp) { + EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK; + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+"); + + if (NULL == hApp) { + l_eStatus = eFrameworkunifiedStatusNullPointer; + LOG_ERROR("NULL == hApp"); + } else { + pthread_mutex_lock(&gMutexObj); + if (NULL == g_tSystemManagerSession.hService) { + l_eStatus = eFrameworkunifiedStatusNullPointer; + LOG_ERROR("FrameworkunifiedGetOpenSessionHandle()"); + g_tSystemManagerSession.fAvailable = FALSE; + } else { + LOG_SUCCESS("FrameworkunifiedGetOpenSessionHandle(hApp)"); + g_tSystemManagerSession.fAvailable = TRUE; + g_moduleState = MODULE_STATE_CONNECTED; + } + pthread_mutex_unlock(&gMutexObj); + + if ((eFrameworkunifiedStatusOK == l_eStatus) && (CallbackFnPtr != NULL)) { + // Call the RegisterSMSessionAckCallback()-registered function + if (eFrameworkunifiedStatusOK != (l_eStatus = (CallbackFnPtr)(hApp))) { + FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, + " Error: The 'CallbackFnPtr' function as set by " + "the RegisterSMSessionAckCallback() function " + "errored: 0x%x/%s", + l_eStatus, GetStr(l_eStatus).c_str()); + } + } + } + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-"); + return l_eStatus; +} // EFrameworkunifiedStatus OnSystemManagerOpenSessionAck( HANDLE hApp ) +// LCOV_EXCL_STOP + +/////////////////////////////////////////////////////////// +/// Macro: +/// +/////////////////////////////////////////////////////////// +#define SETUP_AND_CALL_COMMON_SYSTEM_MANAGER_START_STOP_PROCESSING( \ + hApp, evInterfaceunifiedId, InterfaceunifiedFnc, ModStateSuccess, ModStateFailure, \ + NotifFlag, NotifText, ProtocolId) \ + l_eStatus = CommonSystemManagerStartStopCallbackProcessing( \ + hApp, \ + evInterfaceunifiedId, \ + #evInterfaceunifiedId, \ + InterfaceunifiedFnc, \ + #InterfaceunifiedFnc "()", \ + ModStateSuccess, \ + ModStateFailure, \ + NotifFlag, \ + NotifText, \ + ProtocolId, \ + #ProtocolId); \ + LOG_STATUS(l_eStatus, \ + "CommonSystemManagerStartStopCallbackProcessing(" #InterfaceunifiedFnc "())"); + +// LCOV_EXCL_START 6:Because the condition cannot be set +/////////////////////////////////////////////////////////// +/// Function: OnSystemManagerStart +/// +/////////////////////////////////////////////////////////// +EFrameworkunifiedStatus OnSystemManagerStart(HANDLE hApp) { + EFrameworkunifiedStatus l_eStatus; + FrameworkunifiedDefaultCallbackHandler cbFuncs; + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+"); + + l_eStatus = FrameworkunifiedGetDefaultCbHandler(&cbFuncs); + LOG_STATUS_IF_ERRORED(l_eStatus, "FrameworkunifiedGetDefaultCbHandler()"); + + // Call CommonSystemManagerStartStopCallbackProcessing(), & log status + SETUP_AND_CALL_COMMON_SYSTEM_MANAGER_START_STOP_PROCESSING( + hApp, FRAMEWORKUNIFIED_EVENT(evFrameworkunifiedStart), cbFuncs.onStart, MODULE_STATE_STARTED, + MODULE_STATE_START_FAILED, FALSE, "", SS_SM_START_COMPL_RSPN); + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-"); + return l_eStatus; +} // End of EFrameworkunifiedStatus OnSystemManagerStart( HANDLE hApp ) + +/////////////////////////////////////////////////////////// +/// Function: OnSystemManagerStop +/// +/////////////////////////////////////////////////////////// +EFrameworkunifiedStatus OnSystemManagerStop(HANDLE hApp) { + EFrameworkunifiedStatus l_eStatus; + FrameworkunifiedDefaultCallbackHandler cbFuncs; + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+"); + + l_eStatus = FrameworkunifiedGetDefaultCbHandler(&cbFuncs); + LOG_STATUS_IF_ERRORED(l_eStatus, "FrameworkunifiedGetDefaultCbHandler()"); + + // Call CommonSystemManagerStartStopCallbackProcessing(), & log status + SETUP_AND_CALL_COMMON_SYSTEM_MANAGER_START_STOP_PROCESSING( + hApp, FRAMEWORKUNIFIED_EVENT(evFrameworkunifiedStop), cbFuncs.onStop, MODULE_STATE_STOPPED, + MODULE_STATE_STOP_FAILED, UseStopCompleteNotificationVsInterfaceunifiedOnStopFnc, + " 'UseStopCompleteNotificationVsInterfaceunifiedOnStopFnc' is 'True': " + "setting 'l_eStatus' to 'eFrameworkunifiedStatusFail'", + SS_SM_STOP_COMPL_RSPN); + + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-"); + return l_eStatus; +} // End of EFrameworkunifiedStatus OnSystemManagerStop( HANDLE hApp ) + +/////////////////////////////////////////////////////////// +/// Function: OnSystemManagerPreStart +/// +/////////////////////////////////////////////////////////// +static EFrameworkunifiedStatus OnSystemManagerPreStart(HANDLE hApp) { + EFrameworkunifiedStatus l_eStatus; + FrameworkunifiedDefaultCallbackHandler cbFuncs; // LCOV_EXCL_BR_LINE 11:Excluded due to gcov restrictions(others) + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+"); + + l_eStatus = FrameworkunifiedGetDefaultCbHandler(&cbFuncs); // LCOV_EXCL_BR_LINE 11:Excluded due to gcov restrictions(others) + LOG_STATUS_IF_ERRORED(l_eStatus, "FrameworkunifiedGetDefaultCbHandler()"); + + // Call CommonSystemManagerStartStopCallbackProcessing(), & log status + SETUP_AND_CALL_COMMON_SYSTEM_MANAGER_START_STOP_PROCESSING( + hApp, + FRAMEWORKUNIFIED_EVENT(evFrameworkunifiedPreStart), + cbFuncs.onPreStart, + MODULE_STATE_STARTED_PRE, + MODULE_STATE_START_PRE_FAILED, + FALSE, + "", + SS_SM_PRE_START_COMPL_RSPN); + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-"); // LCOV_EXCL_BR_LINE 15:Excluded for function that are expanded inline + return l_eStatus; +} // End of EFrameworkunifiedStatus OnSystemManagerPreStart( HANDLE hApp ) + +/////////////////////////////////////////////////////////// +/// Function: OnSystemManagerPreStop +/// +/////////////////////////////////////////////////////////// +static EFrameworkunifiedStatus OnSystemManagerPreStop(HANDLE hApp) { + EFrameworkunifiedStatus l_eStatus; + FrameworkunifiedDefaultCallbackHandler cbFuncs; // LCOV_EXCL_BR_LINE 11:Excluded due to gcov restrictions(others) + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+"); + + l_eStatus = FrameworkunifiedGetDefaultCbHandler(&cbFuncs); // LCOV_EXCL_BR_LINE 11:Excluded due to gcov restrictions(others) + LOG_STATUS_IF_ERRORED(l_eStatus, "FrameworkunifiedGetDefaultCbHandler()"); + + // Call CommonSystemManagerStartStopCallbackProcessing(), & log status + SETUP_AND_CALL_COMMON_SYSTEM_MANAGER_START_STOP_PROCESSING( + hApp, + FRAMEWORKUNIFIED_EVENT(evFrameworkunifiedPreStop), + cbFuncs.onPreStop, + MODULE_STATE_STOPPED_PRE, + MODULE_STATE_STOP_PRE_FAILED, + FALSE, + "", + SS_SM_PRE_STOP_COMPL_RSPN); + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-"); // LCOV_EXCL_BR_LINE 15:Excluded for function that are expanded inline + return l_eStatus; +} // End of EFrameworkunifiedStatus OnSystemManagerPreStop( HANDLE hApp ) + +/////////////////////////////////////////////////////////// +/// Function: OnSystemManagerBackgroundStart +/// +/////////////////////////////////////////////////////////// +static EFrameworkunifiedStatus OnSystemManagerBackgroundStart(HANDLE hApp) { + EFrameworkunifiedStatus l_eStatus; + FrameworkunifiedDefaultCallbackHandler cbFuncs; // LCOV_EXCL_BR_LINE 11:Excluded due to gcov restrictions(others) + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+"); + + l_eStatus = FrameworkunifiedGetDefaultCbHandler(&cbFuncs); // LCOV_EXCL_BR_LINE 11:Excluded due to gcov restrictions(others) + LOG_STATUS_IF_ERRORED(l_eStatus, "FrameworkunifiedGetDefaultCbHandler()"); + + // Call CommonSystemManagerStartStopCallbackProcessing(), & log status + SETUP_AND_CALL_COMMON_SYSTEM_MANAGER_START_STOP_PROCESSING( + hApp, + FRAMEWORKUNIFIED_EVENT(evFrameworkunifiedBackgroundStart), + cbFuncs.onBackgroundStart, + MODULE_STATE_STARTED_BACKGROUND, + MODULE_STATE_START_BACKGROUND_FAILED, + FALSE, + "", + SS_SM_BACKGROUND_START_COMPL_RSPN); + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-"); // LCOV_EXCL_BR_LINE 15:Excluded for function that are expanded inline + return l_eStatus; +} // End of EFrameworkunifiedStatus OnSystemManagerBackgroundStart( HANDLE hApp ) + +/////////////////////////////////////////////////////////// +/// Function: OnSystemManagerBackgroundStop +/// +/////////////////////////////////////////////////////////// +static EFrameworkunifiedStatus OnSystemManagerBackgroundStop(HANDLE hApp) { + EFrameworkunifiedStatus l_eStatus; + FrameworkunifiedDefaultCallbackHandler cbFuncs; // LCOV_EXCL_BR_LINE 11:Excluded due to gcov restrictions(others) + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+"); + + l_eStatus = FrameworkunifiedGetDefaultCbHandler(&cbFuncs); // LCOV_EXCL_BR_LINE 11:Excluded due to gcov restrictions(others) + LOG_STATUS_IF_ERRORED(l_eStatus, "FrameworkunifiedGetDefaultCbHandler()"); + + // Call CommonSystemManagerStartStopCallbackProcessing(), & log status + SETUP_AND_CALL_COMMON_SYSTEM_MANAGER_START_STOP_PROCESSING( + hApp, + FRAMEWORKUNIFIED_EVENT(evFrameworkunifiedBackgroundStop), + cbFuncs.onBackgroundStop, + MODULE_STATE_STOPPED_BACKGROUND, + MODULE_STATE_STOP_BACKGROUND_FAILED, + FALSE, + "", + SS_SM_BACKGROUND_STOP_COMPL_RSPN); + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-"); // LCOV_EXCL_BR_LINE 15:Excluded for function that are expanded inline + return l_eStatus; +} // End of EFrameworkunifiedStatus OnSystemManagerBackgroundStop( HANDLE hApp ) + +/////////////////////////////////////////////////////////// +/// Function: CommonSystemManagerStartStopCallbackProcessing +/// +/////////////////////////////////////////////////////////// +EFrameworkunifiedStatus CommonSystemManagerStartStopCallbackProcessing( + HANDLE hApp, UI_32 f_InterfaceunifiedEvID, SS_String f_pInterfaceunifiedEvName, CbFuncPtr f_InterfaceunifiedFncCb, + PCSTR f_pInterfaceunifiedFncName, ModuleStateType f_moduleSuccessState, + ModuleStateType f_moduleFailureState, BOOL f_bUseNotificationVsFncFlag, + PCSTR f_pUseNotificationText, SS_SystemManagerProtocol f_ProtocolId, + PCSTR f_pProtocolName) { + EFrameworkunifiedStatus l_eStatus; + EFrameworkunifiedStatus l_StatusFncReturned; + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+"); + SS_String l_pInterfaceunifiedFncName; + + if (f_moduleSuccessState == g_moduleState) { + FRAMEWORKUNIFIEDLOG(ZONE_WARN, __FUNCTION__, + " Warning: Module state already is '%s', just " + "returning '%s' to System Manager", + GetStr(g_moduleState).c_str(), f_pProtocolName); + l_eStatus = eFrameworkunifiedStatusOK; + l_StatusFncReturned = l_eStatus; + } else { + // If client application is a state machine, post an Event instead of calling + // InterfaceunifiedOnXYZ() + if (FrameworkunifiedIsStateMachineApp(hApp)) { + l_pInterfaceunifiedFncName = "FrameworkunifiedPostEvent(FRAMEWORKUNIFIED_EVENT(" + f_pInterfaceunifiedEvName + " ))"; + CFrameworkunifiedHSMFramework* l_pStateMachine = FrameworkunifiedGetStateMachine(hApp); + if (NULL == l_pStateMachine) { + l_eStatus = eFrameworkunifiedStatusNullPointer; + LOG_ERROR("FrameworkunifiedGetStateMachine()"); + l_StatusFncReturned = l_eStatus; + } else { + l_eStatus = l_pStateMachine->FrameworkunifiedPostEvent(f_InterfaceunifiedEvID); + if (eFrameworkunifiedStatusOK != l_eStatus) { + FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, + " Error: l_pStateMachine->FrameworkunifiedPostEvent(%s) " + "errored: %d/'%s'", + f_pInterfaceunifiedEvName.c_str(), l_eStatus, GetStr(l_eStatus).c_str()); + l_StatusFncReturned = l_eStatus; + } else { + FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__, + " f_bUseNotificationVsFncFlag is '%s'", + GetStr(f_bUseNotificationVsFncFlag).c_str()); + if (f_bUseNotificationVsFncFlag) { + // + // DON'T send an 'Ok' back to the SendInterfaceunifiedOnResponse function: if + // it detects a 'Ok' it will send a SS_SM_<protocol>_RSPN back + // to System Manager, telling System Manager that the request + // has been completely serviced. + l_StatusFncReturned = eFrameworkunifiedStatusFail; + FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__, "%s", f_pUseNotificationText); + } else { + // + // Always send an 'Ok' back for the evInterfaceunified<protocol> version + // of InterfaceunifiedOn<protocol>; the l_eStatus applies to the + // FrameworkunifiedPostEvent() function, not the actual <protocol> event + // handler. + l_StatusFncReturned = eFrameworkunifiedStatusOK; + } + } // End else successful FrameworkunifiedPostEvent() + } // End else valid FrameworkunifiedGetStateMachine() + } else { // End if FrameworkunifiedIsStateMachineApp() is TRUE + l_pInterfaceunifiedFncName = f_pInterfaceunifiedFncName; + if (f_InterfaceunifiedFncCb) { + l_eStatus = (f_InterfaceunifiedFncCb)(hApp); + LOG_STATUS(l_eStatus, f_pInterfaceunifiedFncName); + l_StatusFncReturned = l_eStatus; + } else { + SS_ASERT(0); + l_StatusFncReturned = eFrameworkunifiedStatusOK; + } + } + } + + l_eStatus = SendInterfaceunifiedOnResponseToSystemManager(f_ProtocolId, f_pProtocolName, + l_pInterfaceunifiedFncName.c_str(), + f_moduleSuccessState, + f_moduleFailureState, + l_StatusFncReturned); + const char l_cFormat[] = "SendInterfaceunifiedOnResponseToSystemManager(%s)"; + char l_cBuf[sizeof(l_cFormat) + strlen(f_pProtocolName) + 1]; // NOLINT (runtime/arrays) + snprintf(l_cBuf, sizeof(l_cBuf), l_cFormat, f_pProtocolName); + LOG_STATUS_IF_ERRORED(l_eStatus, l_cBuf); + + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-"); + return l_eStatus; +} // End of CommonSystemManagerStartStopCallbackProcessing( + + +/////////////////////////////////////////////////////////// +/// Function: SendInterfaceunifiedOnStopResponseToSystemManager() +/// +/////////////////////////////////////////////////////////// +EFrameworkunifiedStatus SendInterfaceunifiedOnStopResponseToSystemManager(EFrameworkunifiedStatus f_eStatus) { + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+"); + EFrameworkunifiedStatus l_eStatus = SendInterfaceunifiedOnResponseToSystemManager( + SS_SM_STOP_COMPL_RSPN, "SS_SM_STOP_COMPL_RSPN", "FrameworkunifiedOnStop()", + MODULE_STATE_STOPPED, MODULE_STATE_STOP_FAILED, f_eStatus); + LOG_STATUS_IF_ERRORED(l_eStatus, "SendInterfaceunifiedOnResponseToSystemManager(" + "SS_SM_STOP_COMPL_RSPN"); + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-"); + return l_eStatus; +} // End of EFrameworkunifiedStatus SendInterfaceunifiedOnStopResponseToSystemManager(EFrameworkunifiedStatus f_eStatus) + +/////////////////////////////////////////////////////////// +/// Function: GetInterfaceunifiedOnStartExtInfo() +/// +/////////////////////////////////////////////////////////// +EFrameworkunifiedStatus GetInterfaceunifiedOnStartExtInfo(T_SS_SM_START_ExtDataStructType &f_info) { // NOLINT (runtime/references) + EFrameworkunifiedStatus l_eStatus; + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+"); + + l_eStatus = InvokeSyncRequestToSystemManager( + SS_SM_GET_START_EXT_INFO, "SS_SM_GET_START_EXT_INFO", 0, NULL, + sizeof(T_SS_SM_START_ExtDataStructType), (PVOID) & f_info); + LOG_STATUS_IF_ERRORED(l_eStatus, "InvokeSyncRequestToSystemManager()"); + + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-"); + return l_eStatus; +} + +/////////////////////////////////////////////////////////// +/// Function: GetInterfaceunifiedOnStopExtInfo() +/// +/////////////////////////////////////////////////////////// +EFrameworkunifiedStatus GetInterfaceunifiedOnStopExtInfo(T_SS_SM_STOP_ExtDataStructType &f_info) { // NOLINT (runtime/references) + EFrameworkunifiedStatus l_eStatus; + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+"); + + l_eStatus = InvokeSyncRequestToSystemManager( + SS_SM_GET_STOP_EXT_INFO, "SS_SM_GET_STOP_EXT_INFO", 0, NULL, + sizeof(T_SS_SM_STOP_ExtDataStructType), (PVOID) & f_info); + LOG_STATUS_IF_ERRORED(l_eStatus, "InvokeSyncRequestToSystemManager()"); + + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-"); + return l_eStatus; +} + +// LCOV_EXCL_START 6:Because the condition cannot be set +/////////////////////////////////////////////////////////// +/// Function: OnSystemManagerDebugDump +/// +/////////////////////////////////////////////////////////// +EFrameworkunifiedStatus OnSystemManagerDebugDump(HANDLE hApp) { + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+"); + EFrameworkunifiedStatus l_eStatus; + FrameworkunifiedDefaultCallbackHandler cbFuncs; + + g_moduleState = MODULE_STATE_DEBUG_DUMPING; + l_eStatus = FrameworkunifiedGetDefaultCbHandler(&cbFuncs); + LOG_STATUS_IF_ERRORED(l_eStatus, "FrameworkunifiedGetDefaultCbHandler()"); + + if (cbFuncs.onDebugDump) { + l_eStatus = cbFuncs.onDebugDump(hApp); + LOG_STATUS_IF_ERRORED(l_eStatus, "FrameworkunifiedOnDebugDump()"); + } else { + SS_ASERT(0); + } + + l_eStatus = DebugDumpAppCbStatistics(hApp); + LOG_STATUS_IF_ERRORED(l_eStatus, "DebugDumpAppCbStatistics()"); + + l_eStatus = DebugDumpMemoryMap(hApp); + LOG_STATUS_IF_ERRORED(l_eStatus, "DebugDumpMemoryMap()"); + + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-"); + return l_eStatus; +} // End of EFrameworkunifiedStatus OnSystemManagerDebugDump( HANDLE hApp ) + +/////////////////////////////////////////////////////////// +/// Function: DebugDumpAppCbStatistics +/// +/////////////////////////////////////////////////////////// +EFrameworkunifiedStatus DebugDumpAppCbStatistics(HANDLE hApp) { + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+"); + EFrameworkunifiedStatus l_eStatus; +l_eStatus = eFrameworkunifiedStatusOK; + +FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-"); +return l_eStatus; +} + +/////////////////////////////////////////////////////////// +/// Function: DebugDumpMemoryMap +/// +/////////////////////////////////////////////////////////// +EFrameworkunifiedStatus DebugDumpMemoryMap(HANDLE hApp) { +#define MEM_MAP_READ_SIZE 4096 +#define DUMP_MAX_SIZE 131072 // 128KB + + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+"); + EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusFail; + char buf[MEM_MAP_READ_SIZE]; + std::string bufString; + int fd, ret; + + fd = open("/proc/self/maps", O_RDONLY); + if (fd != -1) { + while ((ret = read(fd, buf, MEM_MAP_READ_SIZE)) > 0) { + if ((bufString.size() + ret) > DUMP_MAX_SIZE) { + // If read it again, it will break because it overflows + break; + } + bufString.append(buf, ret); + } + close(fd); + if (ret >= 0) { + l_eStatus = eFrameworkunifiedStatusOK; + SendDebugDumpResponseToSystemManager(bufString); + } + } + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-"); + return l_eStatus; +} +// LCOV_EXCL_STOP + +////////////////////////////////////////// +// SendDebugDumpResponseToSystemManager +////////////////////////////////////////// +VOID SendDebugDumpResponseToSystemManager(BOOL f_bFormatStrRequired, + PCSTR f_cFormat, ...) { + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+"); + EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK; + va_list l_argList; + const UI_32 l_maxDebugDumpMsgSize = (1024 * 4); + CHAR l_cMsg[l_maxDebugDumpMsgSize] = { 0 }; + PCSTR l_pAppName; + + pthread_mutex_lock(&gMutexObj); + + l_pAppName = FrameworkunifiedGetAppName(g_SystemIf_hApp); // LCOV_EXCL_BR_LINE 11:Unexpected branch + if (f_bFormatStrRequired) { + // build a format string + // Format: AppName/debugdump_data + snprintf(l_cMsg, l_maxDebugDumpMsgSize, "%s/", l_pAppName); + } + + va_start(l_argList, f_cFormat); + vsnprintf(&l_cMsg[strlen(l_cMsg)], l_maxDebugDumpMsgSize - strlen(l_cMsg), + f_cFormat, l_argList); + va_end(l_argList); + + if (0 == strcmp(SERVICE_SYSMANAGER, l_pAppName)) { + l_eStatus = FrameworkunifiedSendSelf(g_SystemIf_hApp, SS_SM_DEBUG_DUMP_RSPN, + strlen(l_cMsg) + 1, l_cMsg); // LCOV_EXCL_BR_LINE 11:Unexpected branch + LOG_STATUS_IF_ERRORED(l_eStatus, "FrameworkunifiedSendSelf(SS_SM_DEBUG_DUMP_RSPN)"); + } else if (NULL != g_tSystemManagerSession.hService) { + l_eStatus = FrameworkunifiedSendMsg(g_tSystemManagerSession.hService, + SS_SM_DEBUG_DUMP_RSPN, strlen(l_cMsg) + 1, l_cMsg); // LCOV_EXCL_BR_LINE 11:Unexpected branch + LOG_STATUS_IF_ERRORED(l_eStatus, "FrameworkunifiedSendMsg(SS_SM_DEBUG_DUMP_RSPN)"); + } else { + l_eStatus = eFrameworkunifiedStatusNullPointer; + FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, + " Error: Invalid handle[g_tSystemManagerSession.hService == NULL]"); + } + + pthread_mutex_unlock(&gMutexObj); + + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-"); +} // End of EFrameworkunifiedStatus SendDebugDumpResponseToSystemManager( HANDLE hApp ) + +// LCOV_EXCL_START 6:Because the condition cannot be set +////////////////////////////////////////// +// SendDebugDumpResponseToSystemManager +////////////////////////////////////////// +VOID SendDebugDumpResponseToSystemManager(std::string & f_messageStr) { // NOLINT (runtime/references) + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+"); + EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK; + + pthread_mutex_lock(&gMutexObj); + + if (0 == strcmp(SERVICE_SYSMANAGER, FrameworkunifiedGetAppName(g_SystemIf_hApp))) { + l_eStatus = FrameworkunifiedSendSelf(g_SystemIf_hApp, SS_SM_DEBUG_DUMP_RSPN, + f_messageStr.size() + 1, f_messageStr.c_str()); + LOG_STATUS_IF_ERRORED(l_eStatus, "FrameworkunifiedSendSelf(SS_SM_DEBUG_DUMP_RSPN)"); + } else if (NULL != g_tSystemManagerSession.hService) { + l_eStatus = FrameworkunifiedSendMsg(g_tSystemManagerSession.hService, + SS_SM_DEBUG_DUMP_RSPN, f_messageStr.size() + 1, + f_messageStr.c_str()); + LOG_STATUS_IF_ERRORED(l_eStatus, "FrameworkunifiedSendMsg(SS_SM_DEBUG_DUMP_RSPN)"); + } else { + l_eStatus = eFrameworkunifiedStatusNullPointer; + FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, " Error: hService = NULL"); + } + + pthread_mutex_unlock(&gMutexObj); + + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-"); +} // End of EFrameworkunifiedStatus SendDebugDumpResponseToSystemManager(std::string & f_messageStr) +// LCOV_EXCL_STOP + +/////////////////////////////////////////////////////////// +/// Function: SendInterfaceunifiedOnResponseToSystemManager() +/// +/////////////////////////////////////////////////////////// +EFrameworkunifiedStatus SendInterfaceunifiedOnResponseToSystemManager( + SS_SystemManagerProtocol f_ProtocolID, PCSTR f_pProtocolName, + PCSTR f_InterfaceunifiedOnFncName, ModuleStateType f_moduleSuccessState, + ModuleStateType f_moduleFailureState, EFrameworkunifiedStatus f_eStatus) { + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+"); + EFrameworkunifiedStatus l_eStatus; + + if (eFrameworkunifiedStatusOK != f_eStatus) { + FRAMEWORKUNIFIEDLOG(ZONE_WARN, __FUNCTION__, + " Warning: '%s' returned %d/%s, NOT sending '%s' to System Manager", + f_InterfaceunifiedOnFncName, f_eStatus, GetStr(f_eStatus).c_str(), + f_pProtocolName); + l_eStatus = f_eStatus; + SetModuleState(f_moduleFailureState); + } else { + if (f_moduleSuccessState == g_moduleState) { + FRAMEWORKUNIFIEDLOG(ZONE_WARN, __FUNCTION__, + " Warning: Module state already is '%s', just " + "returning '%s' to System Manager", + GetStr(g_moduleState).c_str(), f_pProtocolName); + } + + l_eStatus = SendMsgToSystemManager(static_cast<UI_32>(f_ProtocolID), + f_pProtocolName, + sizeof(g_responseCompleteAck), + &g_responseCompleteAck); // LCOV_EXCL_BR_LINE 11:Unexpected branch + const char l_cFormat[] = "SendMsgToSystemManager(%s)"; + char l_cBuf[sizeof(l_cFormat) + strlen(f_pProtocolName) + 1]; // NOLINT (runtime/arrays) + snprintf(l_cBuf, sizeof(l_cBuf), l_cFormat, f_pProtocolName); + LOG_STATUS(l_eStatus, l_cBuf); + SetModuleState(f_moduleSuccessState); + } + + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-"); + return l_eStatus; +} // End of SendInterfaceunifiedOnResponseToSystemManager( + +/////////////////////////////////////////////////////////// +/// Function: SendMsgToSystemManager +/// +/////////////////////////////////////////////////////////// +EFrameworkunifiedStatus SendMsgToSystemManager(UI_32 uiCmd, PCSTR f_pCmdName, UI_32 uiLength, + PCVOID pData) { + FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__, " Sending %s", f_pCmdName); + + return SendMsgToSystemManager(uiCmd, uiLength, pData); +} // End of EFrameworkunifiedStatus SendMsgToSystemManager(UI_32 uiCmd, PCSTR f_pCmdName, UI_32 uiLength, PCVOID pData) + +/////////////////////////////////////////////////////////// +/// Function: SendMsgToSystemManager +/// +/////////////////////////////////////////////////////////// +EFrameworkunifiedStatus SendMsgToSystemManager(UI_32 uiCmd, UI_32 uiLength, PCVOID pData) { + EFrameworkunifiedStatus l_eStatus; + if (NULL == g_tSystemManagerSession.hService) { + l_eStatus = eFrameworkunifiedStatusNullPointer; + LOG_ERROR("NULL == g_tSystemManagerSession.hService"); + } else { + pthread_mutex_lock(&gMutexObj); + l_eStatus = FrameworkunifiedSendMsg(g_tSystemManagerSession.hService, uiCmd, uiLength, + pData); + pthread_mutex_unlock(&gMutexObj); + LOG_STATUS_IF_ERRORED(l_eStatus, "FrameworkunifiedSendMsg()"); + } + return l_eStatus; +} // End of EFrameworkunifiedStatus SendMsgToSystemManager(UI_32 uiCmd, UI_32 uiLength, PCVOID pData) + +/////////////////////////////////////////////////////////// +/// Function: InvokeSyncRequestToSystemManager +/// +/////////////////////////////////////////////////////////// +EFrameworkunifiedStatus InvokeSyncRequestToSystemManager(UI_32 uiCmd, PCSTR f_pCmdName, + UI_32 uiLength, PCVOID pData, + UI_32 uiResLength, PVOID pResData) { + EFrameworkunifiedStatus l_eStatus; + UI_32 uiRcvLength = 0; + FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__, " Sending %s", f_pCmdName); + + if (NULL == g_tSystemManagerSession.hService) { + l_eStatus = eFrameworkunifiedStatusNullPointer; + LOG_ERROR("NULL == g_tSystemManagerSession.hService"); + } else { + pthread_mutex_lock(&gMutexObj); + l_eStatus = FrameworkunifiedInvokeSync(g_tSystemManagerSession.hService, uiCmd, uiLength, + pData, uiResLength, pResData, &uiRcvLength); // LCOV_EXCL_BR_LINE 11:Unexpected branch + if (eFrameworkunifiedStatusOK == l_eStatus) { + if (uiResLength != uiRcvLength) { + LOG_ERROR("uiResLength != uiRcvLength"); + l_eStatus = eFrameworkunifiedStatusFail; + } + } + pthread_mutex_unlock(&gMutexObj); + LOG_STATUS_IF_ERRORED(l_eStatus, "FrameworkunifiedInvokeSync()"); + } + return l_eStatus; +} // End of Function + +// LCOV_EXCL_START 6:Because the condition cannot be set +/////////////////////////////////////////////////////////// +/// Function: SendWakeUpToSystemManager +/// +/////////////////////////////////////////////////////////// +EFrameworkunifiedStatus SendWakeUpToSystemManager(wakeInfo *pData) { + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+"); + EFrameworkunifiedStatus l_eStatus = SendMsgToSystemManager(SS_SM_WAKEUP_MODULES, + "SS_SM_WAKEUP_MODULES", + sizeof(wakeInfo), + (PCVOID) pData); + LOG_STATUS_IF_ERRORED(l_eStatus, "SendMsgToSystemManager()"); + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-"); + return l_eStatus; +} // End of EFrameworkunifiedStatus SendWakeUpToSystemManager(wakeInfo *pData) +// LCOV_EXCL_STOP + +// LCOV_EXCL_START 6:Because the condition cannot be set +/////////////////////////////////////////////////////////// +/// Function: SendShutdownToSystemManager +/// +/////////////////////////////////////////////////////////// +EFrameworkunifiedStatus SendShutdownToSystemManager(Pwr_ServiceSetInterface *pData) { + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+"); + EFrameworkunifiedStatus l_eStatus = SendMsgToSystemManager(SS_SM_SHUTDOWN_MODULES, + "SS_SM_SHUTDOWN_MODULES", + sizeof(Pwr_ServiceSetInterface), + (PCVOID) pData); + LOG_STATUS_IF_ERRORED(l_eStatus, "SendMsgToSystemManager()"); + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-"); + return l_eStatus; +} // End of EFrameworkunifiedStatus SendShutdownToSystemManager(Pwr_ServiceSetInterface *pData) +// LCOV_EXCL_STOP + +/////////////////////////////////////////////////////////// +/// Function: RegisterSMSessionAckCallback +/// +/////////////////////////////////////////////////////////// +EFrameworkunifiedStatus RegisterSMSessionAckCallback(EFrameworkunifiedStatus (*CallbackPtr)(HANDLE)) { + CallbackFnPtr = CallbackPtr; + return eFrameworkunifiedStatusOK; +} // End of EFrameworkunifiedStatus RegisterSMSessionAckCallback(EFrameworkunifiedStatus (*CallbackPtr)(HANDLE)) + +// LCOV_EXCL_START 6:Because the condition cannot be set +/////////////////////////////////////////////////////////// +/// Function: SendSystemModeRequestToSystemManager +/// +/////////////////////////////////////////////////////////// +EFrameworkunifiedStatus SendSystemModeRequestToSystemManager(void) { + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+"); + EFrameworkunifiedStatus l_eStatus = SendMsgToSystemManager(SS_SM_SYSTEM_MODE_INFO_REQ, + "SS_SM_SYSTEM_MODE_INFO_REQ", 0, + NULL); + LOG_STATUS_IF_ERRORED(l_eStatus, "SendMsgToSystemManager()"); + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-"); + return l_eStatus; +} // End of EFrameworkunifiedStatus SendSystemModeRequestToSystemManager(void) + +/////////////////////////////////////////////////////////// +/// Function: SendInitCompReportToSystemManager +/// +/////////////////////////////////////////////////////////// +EFrameworkunifiedStatus SendInitCompReportToSystemManager(void) { + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+"); + EFrameworkunifiedStatus l_eStatus = SendMsgToSystemManager(SS_SM_INITCOMP_REP, + "SS_SM_INITCOMP_REP", 0, NULL); + LOG_STATUS_IF_ERRORED(l_eStatus, "SendMsgToSystemManager()"); + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-"); + return l_eStatus; +} // End of EFrameworkunifiedStatus SendInitCompReportToSystemManager(void) + + +/////////////////////////////////////////////////////////// +/// Function: AttachCallbackToSystemManager +/// +/////////////////////////////////////////////////////////// +EFrameworkunifiedStatus AttachCallbackToSystemManager(HANDLE hApp, UI_32 iCmd, + CbFuncPtr fpOnCmd) { + return FrameworkunifiedAttachCallbackToDispatcher( + hApp, g_tSystemManagerSession.szServiceName.c_str(), iCmd, fpOnCmd); +} // End of EFrameworkunifiedStatus AttachCallbackToSystemManager( HANDLE hApp, UI_32 iCmd, CbFuncPtr fpOnCmd ) +// LCOV_EXCL_STOP + +/////////////////////////////////////////////////////////// +/// Function: SetDataResetModeToSystemManager +/// +/////////////////////////////////////////////////////////// +EFrameworkunifiedStatus SetDataResetModeToSystemManager(ESMDataResetModeInfo dataResetMode) { + EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK; + EFrameworkunifiedStatus l_resData; + + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+"); + + switch (dataResetMode) { + case e_SS_SM_DATA_RESET_MODE_NONE: + case e_SS_SM_DATA_RESET_MODE_USER: + case e_SS_SM_DATA_RESET_MODE_FACTORY: + break; + default: + FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__, "dataResetMode %d", dataResetMode); + return eFrameworkunifiedStatusInvldParam; + } + + l_eStatus = InvokeSyncRequestToSystemManager(SS_SM_DATA_RESET_MODE_SET_REQ, + "SS_SM_DATA_RESET_MODE_SET_REQ", + sizeof(dataResetMode), + (PVOID) & dataResetMode, + sizeof(l_resData), + (PVOID) & l_resData); // LCOV_EXCL_BR_LINE 11:Unexpected branch + LOG_STATUS_IF_ERRORED(l_eStatus, "InvokeSyncRequestToSystemManager()"); + + if (eFrameworkunifiedStatusOK == l_eStatus) { + if (eFrameworkunifiedStatusOK != l_resData) { + l_eStatus = l_resData; + FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__, " l_eStatus %d", l_eStatus); + } + } + + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-"); + return l_eStatus; +} // End of EFrameworkunifiedStatus SetDataResetModeToSystemManager(ESMDataResetModeInfo dataResetMode) + +/////////////////////////////////////////////////////////// +/// Function: SetProgUpdateStateToSystemManager +/// +/////////////////////////////////////////////////////////// +EFrameworkunifiedStatus SetProgUpdateStateToSystemManager( + SMProgUpdateState progUpdateState) { + EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK; + EFrameworkunifiedStatus l_resData; + + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+"); + + if (progUpdateState & SS_SM_PROG_UPDATE_STATE_UPDATED) { + } else if (progUpdateState & SS_SM_PROG_UPDATE_STATE_MAP_UPDATED) { + } else if (progUpdateState & SS_SM_PROG_UPDATE_STATE_MAPDIFF_UPDATED) { + } else { + FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__, "unknown %#x", progUpdateState); + return eFrameworkunifiedStatusInvldParam; + } + + l_eStatus = InvokeSyncRequestToSystemManager( + SS_SM_PROG_UPDATE_STATE_SET_REQ, "SS_SM_PROG_UPDATE_STATE_SET_REQ", + sizeof(progUpdateState), (PVOID) & progUpdateState, sizeof(l_resData), + (PVOID) & l_resData); // LCOV_EXCL_BR_LINE 11:Unexpected branch + LOG_STATUS_IF_ERRORED(l_eStatus, "InvokeSyncRequestToSystemManager()"); + + if ((eFrameworkunifiedStatusOK == l_eStatus) && (eFrameworkunifiedStatusOK != l_resData)) { + l_eStatus = l_resData; + LOG_ERROR("SM RESP"); + } + + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-"); + return l_eStatus; +} // End of EFrameworkunifiedStatus SetProgUpdateStateToSystemManager(SMProgUpdateState progUpdateState) + +/////////////////////////////////////////////////////////// +/// Function: SetNextWakeupTypeToSystemManager +/// +/////////////////////////////////////////////////////////// +EFrameworkunifiedStatus SetNextWakeupTypeToSystemManager(ESMNextWakeupType f_wakeupType) { + EFrameworkunifiedStatus l_eStatus; + EFrameworkunifiedStatus l_resData; + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+"); + + switch (f_wakeupType) { + case e_SS_SM_NEXT_WAKEUP_TYPE_NONE: + case e_SS_SM_NEXT_WAKEUP_TYPE_COLD: + case e_SS_SM_NEXT_WAKEUP_TYPE_HOT: + break; + default: + FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "unknown type(%d)", f_wakeupType); + return eFrameworkunifiedStatusInvldParam; + } + + l_eStatus = InvokeSyncRequestToSystemManager(SS_SM_NEXT_WAKEUP_TYPE_SET_REQ, + "SS_SM_NEXT_WAKEUP_TYPE_SET_REQ", + sizeof(f_wakeupType), + (PVOID) & f_wakeupType, + sizeof(l_resData), + (PVOID) & l_resData); // LCOV_EXCL_BR_LINE 11:Unexpected branch + LOG_STATUS_IF_ERRORED(l_eStatus, "InvokeSyncRequestToSystemManager()"); + + if (eFrameworkunifiedStatusOK == l_eStatus) { + if (eFrameworkunifiedStatusOK != l_resData) { + l_eStatus = l_resData; + FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, " l_eStatus %d", l_eStatus); + } + } + + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-"); + return l_eStatus; +} + +/////////////////////////////////////////////////////////// +/// Function: SendCpuResetRequestToSystemManager +/// +/////////////////////////////////////////////////////////// +EFrameworkunifiedStatus SendCpuResetRequestToSystemManager( + ESMCpuResetReason l_eCpuResetReason, std::string f_messageStr/* = "" */, + std::string f_suffixStr/* = "" */) { + TSystemManagerCpuResetInfo l_resetInfo; // LCOV_EXCL_BR_LINE 11:Unexpected branch + EFrameworkunifiedStatus l_eStatus; + + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+"); + + l_resetInfo.resetReason = l_eCpuResetReason; + snprintf(l_resetInfo.messageStr, SS_SM_RESET_MSG_STR_SIZE, "%s", + f_messageStr.c_str()); // LCOV_EXCL_BR_LINE 11:Unexpected branch + snprintf(l_resetInfo.suffixStr, SS_SM_SUFFIX_STR_SIZE, "%s", + f_suffixStr.c_str()); // LCOV_EXCL_BR_LINE 11:Unexpected branch + + l_eStatus = SendMsgToSystemManager(SS_SM_CPU_RESET_REQ, "SS_SM_CPU_RESET_REQ", + sizeof(l_resetInfo), + (PVOID) & l_resetInfo); // LCOV_EXCL_BR_LINE 11:Unexpected branch + + LOG_STATUS_IF_ERRORED(l_eStatus, "SendMsgToSystemManager()"); + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-"); + return l_eStatus; +} // End of SendCpuResetRequestToSystemManager + +/////////////////////////////////////////////////////////// +/// Function: SendStartupConfirmationToSystemManager +/// +/////////////////////////////////////////////////////////// +// LCOV_EXCL_START 6:Because the condition cannot be set +EFrameworkunifiedStatus SendStartupConfirmationToSystemManager( + StartupConfirmationMsgStrut &f_startupConfirmationMsg) { //NOLINT (runtime/references) + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+"); + EFrameworkunifiedStatus l_eStatus; + + Pwr_ServiceSetInterface tServiceSetIf; + tServiceSetIf.data.startupConfirmationMsg = f_startupConfirmationMsg; + + l_eStatus = SendMsgToSystemManager(SS_SM_FWD_STARTUP_CONFIRMATION_MSG_REQ, + "SS_SM_FWD_STARTUP_CONFIRMATION_MSG_REQ", + sizeof(Pwr_ServiceSetInterface), + (PCVOID) & tServiceSetIf); + LOG_STATUS_IF_ERRORED(l_eStatus, "SendMsgToSystemManager()"); + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-"); + return l_eStatus; +} // End of EFrameworkunifiedStatus SendStartupConfirmationToSystemManager( +// LCOV_EXCL_STOP + +// LCOV_EXCL_START 6:Because the condition cannot be set +EFrameworkunifiedStatus SendSystemErrorToSystemManager(EFrameworkunifiedSystemError f_systemError) { + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+"); + EFrameworkunifiedStatus l_eStatus = SendMsgToSystemManager(SS_SM_PROPAGATE_SYSTEM_ERROR, + sizeof(f_systemError), + reinterpret_cast<void*>(&f_systemError)); + LOG_STATUS_IF_ERRORED(l_eStatus, "SendMsgToSystemManager()"); + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-"); + return l_eStatus; +} + +EFrameworkunifiedStatus Send_CWORD56_HeartBeatRequestToSystemManager( + EPWR_HB_REQ_MSG_STRUCT f_HbReq) { + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+"); + EFrameworkunifiedStatus l_eStatus = SendMsgToSystemManager(SS_SM__CWORD56__HEARTBEAT_REQ, + sizeof(f_HbReq), + reinterpret_cast<void*>(&f_HbReq)); + LOG_STATUS_IF_ERRORED(l_eStatus, "SendMsgToSystemManager()"); + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-"); + return l_eStatus; +} +// LCOV_EXCL_STOP + +VOID Set_UseStopCompleteNotificationVsInterfaceunifiedOnStopFnc_StateVar(BOOL f_SetTrue) { + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+"); + UseStopCompleteNotificationVsInterfaceunifiedOnStopFnc = f_SetTrue; + FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__, + " UseStopCompleteNotificationVsInterfaceunifiedOnStopFnc set '%s'", + UseStopCompleteNotificationVsInterfaceunifiedOnStopFnc ? "True" : "False"); + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-"); +} + +EFrameworkunifiedStatus SendBootMicroResetNotificationToSystemManager( + eSMBootMicroResetReason f_ResetReason) { + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+"); + EFrameworkunifiedStatus l_eStatus; + + l_eStatus = SendMsgToSystemManager(SS_SM_BOOT_MICRO_RESET_NTF, + "SS_SM_BOOT_MICRO_RESET_NTF", + sizeof(f_ResetReason), &f_ResetReason); + + LOG_STATUS_IF_ERRORED(l_eStatus, + "SendMsgToSystemManager(SS_SM_BOOT_MICRO_RESET_NTF)"); + + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-"); + return l_eStatus; +} + +EFrameworkunifiedStatus SendUserInvokedLoggingRequestToSystemManager( + eSMUserLogType f_userInvokedLogType, std::string f_messageStr/* = "" */, + std::string f_suffixStr/* = "" */) { + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+"); + EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK; + + try { + switch (f_userInvokedLogType) { + case e_SS_SM_CAPTURE_ALL_LOGS: + case e_SS_SM_SCREEN_CAPTURE: + case e_SS_SM_CAPTURE_INTERFACEUNIFIED_LOGS: + case e_SS_SM_CAPTURE_DEV_LOGS: + case e_SS_SM_CAPTURE_MODULE_LOGS: + case e_SS_SM_CAPTURE_DTC_LOGS: + case e_SS_SM_CAPTURE_NAVI_LOGS: + case e_SS_SM_CAPTURE_GROUP_RELAUNCH: + break; + default: + FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, " Error: Unknown key ID '%d'", + f_userInvokedLogType); + throw eFrameworkunifiedStatusInvldParam; + break; + } + + TSystemManagerLoggingRequestInfo l_logInfo = { }; + + snprintf(l_logInfo.messageStr, SS_SM_LOG_MSG_STR_SIZE, "%s", + f_messageStr.c_str()); // LCOV_EXCL_BR_LINE 11:Unexpected branch + snprintf(l_logInfo.suffixStr, SS_SM_SUFFIX_STR_SIZE, "%s", + f_suffixStr.c_str()); // LCOV_EXCL_BR_LINE 11:Unexpected branch + + l_logInfo.logType = f_userInvokedLogType; + l_eStatus = SendMsgToSystemManager(SS_SM_USER_INVOKED_LOG_REQ, + "SS_SM_USER_INVOKED_LOG_REQ", + sizeof(l_logInfo), &l_logInfo); // LCOV_EXCL_BR_LINE 11:Unexpected branch + LOG_STATUS_IF_ERRORED(l_eStatus, + "SendMsgToSystemManager(SS_SM_USER_INVOKED_LOG_REQ)"); + } catch (EFrameworkunifiedStatus e) { + l_eStatus = e; + } + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-"); + return (l_eStatus); // LCOV_EXCL_BR_LINE 11:Unexpected branch +} + +// LCOV_EXCL_START 6:Because the condition cannot be set +EFrameworkunifiedStatus SendDiagLoggingRequestToSystemManager( + std::string f_copyDestPathStr) { + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+"); + EFrameworkunifiedStatus l_eStatus; + + l_eStatus = SendMsgToSystemManager(SS_SM_ERROR_EVENT_DIAG_LOG_REQ, + "SS_SM_ERROR_EVENT_DIAG_LOG_REQ", + f_copyDestPathStr.length() + 1, + f_copyDestPathStr.c_str()); + LOG_STATUS_IF_ERRORED( + l_eStatus, "SendMsgToSystemManager(SS_SM_ERROR_EVENT_DIAG_LOG_REQ)"); + + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-"); + return (l_eStatus); +} + +EFrameworkunifiedStatus SendCANLoggingRequestToSystemManager(void) { + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+"); + EFrameworkunifiedStatus l_eStatus; + + l_eStatus = SendMsgToSystemManager(SS_SM_ERROR_EVENT_CAN_LOG_REQ, + "SS_SM_ERROR_EVENT_CAN_LOG_REQ", 0, NULL); + + LOG_STATUS_IF_ERRORED( + l_eStatus, "SendMsgToSystemManager(SS_SM_ERROR_EVENT_CAN_LOG_REQ)"); + + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-"); + return (l_eStatus); +} + +EFrameworkunifiedStatus SendDTCLoggingRequestToSystemManager(UI_32 f_dtc) { + SS_ASERT(0); + return eFrameworkunifiedStatusOK; +} +// LCOV_EXCL_STOP + +EFrameworkunifiedStatus RegisterBootMicroLogRequestCb(HANDLE hApp, CbFuncPtr fpOnCmd) { + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+"); + EFrameworkunifiedStatus l_eStatus; + + if (NULL == hApp) { + l_eStatus = eFrameworkunifiedStatusNullPointer; + LOG_ERROR("(NULL == hApp)"); + } else if (NULL == fpOnCmd) { + l_eStatus = eFrameworkunifiedStatusNullPointer; + LOG_ERROR("(NULL == fpOnCmd)"); + } else { + l_eStatus = FrameworkunifiedSubscribeToSessionEventWithCallback( + hApp, SS_SM_BOOT_MICRO_LOG_REQ, fpOnCmd, + g_tSystemManagerSession.hService); // LCOV_EXCL_BR_LINE 11:Unexpected branch + + LOG_STATUS_IF_ERRORED( + l_eStatus, + "FrameworkunifiedSubscribeToSessionEventWithCallback(SS_SM_BOOT_MICRO_LOG_REQ)"); + } + + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-"); + return (l_eStatus); +} + +EFrameworkunifiedStatus SendBootMicroLogResponseToSystemManager(std::string f_logString) { + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+"); + EFrameworkunifiedStatus l_eStatus; + + l_eStatus = SendMsgToSystemManager(SS_SM_BOOT_MICRO_LOG_RSP, + "SS_SM_BOOT_MICRO_LOG_RSP", + f_logString.size() + 1, + f_logString.c_str()); + + LOG_STATUS_IF_ERRORED(l_eStatus, + "SendMsgToSystemManager(SS_SM_BOOT_MICRO_LOG_RSP)"); + + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-"); + return l_eStatus; +} + +// LCOV_EXCL_START 6:Because the condition cannot be set +EFrameworkunifiedStatus DetachCallbacksFromInterfaceunifiedDispatcher( + HANDLE hApp, PCSTR pServiceName, + const FrameworkunifiedProtocolCallbackHandler* pMsgHandler, UI_32 uiHandlerCount, + HANDLE hSession) { + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+"); + EFrameworkunifiedStatus l_eStatus; + PUI_32 l_puiCmdIdArray; + + if (NULL == pServiceName) { + l_eStatus = eFrameworkunifiedStatusInvldParam; + LOG_ERROR("NULL == pServiceName"); + } else if (NULL == pMsgHandler) { + l_eStatus = eFrameworkunifiedStatusInvldParam; + LOG_ERROR("NULL == pMsgHandler"); + } else if (0 == uiHandlerCount) { + l_eStatus = eFrameworkunifiedStatusInvldParam; + LOG_ERROR("0 == uiHandlerCount"); + } else if (NULL == hSession) { + l_eStatus = eFrameworkunifiedStatusInvldParam; + LOG_ERROR("NULL == hSession"); + } else if (NULL + == (l_puiCmdIdArray = new (std::nothrow) UI_32[uiHandlerCount])) { + l_eStatus = eFrameworkunifiedStatusNullPointer; + LOG_ERROR("new (std::nothrow)UI_32[ uiHandlerCount ]"); + } else { + LoadCbHandlerCmdIDsIntoDetachCbIDsArray(pMsgHandler, l_puiCmdIdArray, + uiHandlerCount); + + l_eStatus = FrameworkunifiedDetachCallbacksFromDispatcher(hApp, pServiceName, + l_puiCmdIdArray, + uiHandlerCount, hSession); + LOG_STATUS(l_eStatus, "FrameworkunifiedDetachCallbacksFromDispatcher()"); + delete[] l_puiCmdIdArray; + } + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-"); + return l_eStatus; +} // End of EFrameworkunifiedStatus DetachCallbacksFromInterfaceunifiedDispatcher(HANDLE hApp, + +EFrameworkunifiedStatus DetachParentCallbacksFromInterfaceunifiedDispatcher( + HANDLE hApp, const FrameworkunifiedProtocolCallbackHandler* pMsgHandler, + UI_32 uiHandlerCount) { + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+"); + EFrameworkunifiedStatus l_eStatus; + PUI_32 l_puiCmdIdArray; + + if (NULL == pMsgHandler) { + l_eStatus = eFrameworkunifiedStatusInvldParam; + LOG_ERROR("NULL == pMsgHandler"); + } else if (0 == uiHandlerCount) { + l_eStatus = eFrameworkunifiedStatusInvldParam; + LOG_ERROR("0 == uiHandlerCount"); + } else if (NULL + == (l_puiCmdIdArray = new (std::nothrow) UI_32[uiHandlerCount])) { + l_eStatus = eFrameworkunifiedStatusNullPointer; + LOG_ERROR("new (std::nothrow)UI_32[ uiHandlerCount ]"); + } else { + LoadCbHandlerCmdIDsIntoDetachCbIDsArray(pMsgHandler, l_puiCmdIdArray, + uiHandlerCount); + + l_eStatus = FrameworkunifiedDetachParentCallbacksFromDispatcher(hApp, l_puiCmdIdArray, + uiHandlerCount); + LOG_STATUS(l_eStatus, "FrameworkunifiedDetachParentCallbacksFromDispatcher()"); + delete[] l_puiCmdIdArray; + } + + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-"); + return l_eStatus; +} // End of EFrameworkunifiedStatus DetachParentCallbacksFromInterfaceunifiedDispatcher(HANDLE hApp, + +VOID LoadCbHandlerCmdIDsIntoDetachCbIDsArray( + const FrameworkunifiedProtocolCallbackHandler* pMsgHandler, UI_32 * puiCmdIdArray, + UI_32 uiHandlerCount) { + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+"); + for (UI_32 i = 0; i < uiHandlerCount; i++) { + puiCmdIdArray[i] = pMsgHandler[i].iCmd; + } + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-"); +} // End of VOID LoadCbHandlerCmdIDsIntoDetachCbIDsArray(const FrameworkunifiedProtocolCallbackHandler* pMsgHandler, + +/////////////////////////////////////////////////////////// +/// Function: SendLogStartRequestToSystemManager +/// +/////////////////////////////////////////////////////////// +EFrameworkunifiedStatus SendLogStartRequestToSystemManager(EErrorEventType f_errorEvent) { + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+"); + EFrameworkunifiedStatus l_eStatus; + + l_eStatus = SendMsgToSystemManager(SS_SM_ERROR_EVENT_LOGGING_START_REQ, + "SS_SM_ERROR_EVENT_LOGGING_START_REQ", + sizeof(f_errorEvent), &f_errorEvent); + + LOG_STATUS_IF_ERRORED( + l_eStatus, "SendMsgToSystemManager(SS_SM_ERROR_EVENT_LOGGING_START_REQ)"); + + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-"); + return (l_eStatus); +} + +/////////////////////////////////////////////////////////// +/// Function: SendLogArtifactRequestToSystemManager +/// +/////////////////////////////////////////////////////////// +EFrameworkunifiedStatus SendLogArtifactRequestToSystemManager(EArtifactId f_artifactId) { + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+"); + EFrameworkunifiedStatus l_eStatus; + + l_eStatus = SendMsgToSystemManager(SS_SM_ERROR_EVENT_ARTIFACT_REQ, + "SS_SM_ERROR_EVENT_ARTIFACT_REQ", + sizeof(f_artifactId), &f_artifactId); + + LOG_STATUS_IF_ERRORED( + l_eStatus, "SendMsgToSystemManager(SS_SM_ERROR_EVENT_ARTIFACT_REQ)"); + + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-"); + return (l_eStatus); +} + +/////////////////////////////////////////////////////////// +/// Function: SendLogCompleteRequestToSystemManager +/// +/////////////////////////////////////////////////////////// +EFrameworkunifiedStatus SendLogCompleteRequestToSystemManager(EFrameworkunifiedStatus f_eStatus) { + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+"); + EFrameworkunifiedStatus l_eStatus; + + if (eFrameworkunifiedStatusOK != f_eStatus) { + l_eStatus = eFrameworkunifiedStatusFail; + } else { + l_eStatus = f_eStatus; + } + + l_eStatus = SendMsgToSystemManager(SS_SM_ERROR_EVENT_LOGGING_COMPLETE, + "SS_SM_ERROR_EVENT_LOGGING_COMPLETE", + sizeof(l_eStatus), &l_eStatus); + + LOG_STATUS_IF_ERRORED( + l_eStatus, "SendMsgToSystemManager(SS_SM_ERROR_EVENT_LOGGING_COMPLETE)"); + + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-"); + return (l_eStatus); +} + +/////////////////////////////////////////////////////////// +/// Function: SendEelExportRequestToSystemManager +/// +/////////////////////////////////////////////////////////// +EFrameworkunifiedStatus SendEelExportRequestToSystemManager(std::string f_path) { + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+"); + EFrameworkunifiedStatus l_eStatus; + + l_eStatus = SendMsgToSystemManager(SS_SM_ERROR_EVENT_EEL_EXPORT_REQ, + "SS_SM_ERROR_EVENT_EEL_EXPORT_REQ", + f_path.length() + 1, f_path.c_str()); + + LOG_STATUS_IF_ERRORED( + l_eStatus, "SendMsgToSystemManager(SS_SM_ERROR_EVENT_EEL_EXPORT_REQ)"); + + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-"); + return (l_eStatus); +} +// LCOV_EXCL_STOP + +/////////////////////////////////////////////////////////// +/// Function: SendInterfaceunifiedEmmcLogsRequestToSystemManager +/// +/////////////////////////////////////////////////////////// +EFrameworkunifiedStatus SendInterfaceunifiedEmmcLogsRequestToSystemManager(std::string f_path) { + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+"); + EFrameworkunifiedStatus l_eStatus; + + l_eStatus = SendMsgToSystemManager(SS_SM_ERROR_EVENT_INTERFACEUNIFIED_EMMC_LOGS_REQ, + "SS_SM_ERROR_EVENT_INTERFACEUNIFIED_EMMC_LOGS_REQ", + f_path.length() + 1, f_path.c_str()); + + LOG_STATUS_IF_ERRORED( + l_eStatus, "SendMsgToSystemManager(SS_SM_ERROR_EVENT_INTERFACEUNIFIED_EMMC_LOGS_REQ)"); + + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-"); + return (l_eStatus); +} + +/////////////////////////////////////////////////////////// +/// Function: SendClearLogsRequestToSystemManager +/// +/////////////////////////////////////////////////////////// +EFrameworkunifiedStatus SendClearLogsRequestToSystemManager( + TSystemManagerClearLogsInfo *f_info) { + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+"); + EFrameworkunifiedStatus l_eStatus; + + if (!f_info) { + l_eStatus = eFrameworkunifiedStatusInvldParam; + } else { + l_eStatus = SendMsgToSystemManager(SS_SM_ERROR_EVENT_CLR_LOGS_REQ, + "SS_SM_ERROR_EVENT_CLR_LOGS_REQ", 0, + NULL); + + LOG_STATUS_IF_ERRORED( + l_eStatus, "SendMsgToSystemManager(SS_SM_ERROR_EVENT_CLR_LOGS_REQ)"); + } + + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-"); + return (l_eStatus); +} + +VOID SetModuleState(ModuleStateType f_moduleState, BOOL f_bLog) { + if (f_bLog) { // LCOV_EXCL_BR_LINE 8:f_bLog is true only + FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__, " Changing SM_IF state from '%s' to '%s'", + GetStr(g_moduleState).c_str(), GetStr(f_moduleState).c_str()); + } + g_moduleState = f_moduleState; +} // LCOV_EXCL_BR_LINE 10:Because the last line +// End of VOID ModuleLaunchParams::SetModuleState(SMModuleState f_moduleState ) + +// EOF /SS_SystemIf/src/ss_sm_client.cpp diff --git a/systemservice/interface_unified/library/src/ss_string_maps.cpp b/systemservice/interface_unified/library/src/ss_string_maps.cpp new file mode 100755 index 0000000..629043a --- /dev/null +++ b/systemservice/interface_unified/library/src/ss_string_maps.cpp @@ -0,0 +1,462 @@ +/* + * @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_SystemManagerIf +/// \brief This file provides support for the System Manager client interface. +/// +/////////////////////////////////////////////////////////////////////////////// + +#include "system_service/ss_string_maps.h" +#include <native_service/frameworkunified_types.h> +#include <native_service/ns_logger_if.h> +#include <map> +#include "system_service/ss_power_service.h" +#include "system_service/ss_templates.h" +#include "system_service/ss_system_manager_if.h" +#include "system_service/ss_system_manager_protocol.h" +#include "ss_system_if_interfaceunifiedlog.h" + +/* + * 't'emplate for string-map initialization functions +void Init_SS_xyz_StrMap(std::map<SS_xyz, SS_String> &m_strMap) +{ + MAP_ENTRY( m_strMap, ); + MAP_ENTRY( m_strMap, ); +} // End of void Init_SS_xyz_StrMap(std::map<SS_xyz, SS_String> &m_strMap) +*/ + + +//****************************************************************************** +void Init_eSMBootMicroResetReason_StrMap(std::map<eSMBootMicroResetReason, + SS_String> & m_strMap) { // NOLINT (runtime/references) + MAP_ENTRY(m_strMap, SS_SM_BOOT_MICRO_RESET_REASON_SELF_RESET); + MAP_ENTRY(m_strMap, SS_SM_BOOT_MICRO_RESET_REASON_USER_FORCE_RESET); + MAP_ENTRY(m_strMap, SS_SM_BOOT_MICRO_RESET_REASON_DSP_RESET); + MAP_ENTRY(m_strMap, SS_SM_BOOT_MICRO_RESET_REASON_HB_TIMEOUT); +} +class EnumStringMap< eSMBootMicroResetReason, + Init_eSMBootMicroResetReason_StrMap> + m_oeSMBootMicroResetReasonMap; +// LCOV_EXCL_START 6:Because the condition cannot be set +SS_String GetStr(eSMBootMicroResetReason f_enum) { + return m_oeSMBootMicroResetReasonMap.GetStr(f_enum); +} +// LCOV_EXCL_STOP + +//****************************************************************************** +void Init_EInterfaceunifiedSystemError_StrMap(std::map<EFrameworkunifiedSystemError, SS_String> & m_strMap) { // NOLINT (runtime/references) + MAP_ENTRY(m_strMap, eFrameworkunifiedSystemErrorNone); + MAP_ENTRY(m_strMap, eFrameworkunifiedDSPHardwareReset); +} +class EnumStringMap< EFrameworkunifiedSystemError, Init_EInterfaceunifiedSystemError_StrMap> m_oEInterfaceunifiedSystemErrorMap; +// LCOV_EXCL_START 6:Because the condition cannot be set +SS_String GetStr(EFrameworkunifiedSystemError f_enum) { + return m_oEInterfaceunifiedSystemErrorMap.GetStr(f_enum); +} +// LCOV_EXCL_STOP + +//****************************************************************************** +void Init_EErrorEventType_StrMap(std::map<EErrorEventType, SS_String> & m_strMap); // NOLINT (runtime/references) +class EnumStringMap< EErrorEventType, Init_EErrorEventType_StrMap> m_oEErrorEventTypeMap; +SS_String GetStr(EErrorEventType f_enum) { + return m_oEErrorEventTypeMap.GetStr(f_enum); +} + +//****************************************************************************** +void Init_BOOL_StrMap(std::map<BOOL, SS_String> & m_strMap) { // NOLINT (runtime/references) + MAP_ENTRY(m_strMap, TRUE); + MAP_ENTRY(m_strMap, FALSE); +} // End of void Init_BOOL_StrMap(std::map<BOOL, SS_String> & m_strMap) +class EnumStringMap< BOOL, Init_BOOL_StrMap> m_oBOOLMap; +SS_String GetStr(BOOL f_enum) { + return m_oBOOLMap.GetStr(f_enum); +} + +//****************************************************************************** +void Init_SS_LimpHomeCutoff_StrMap(std::map<EPWR_LHC_TYPE, SS_String> & m_strMap) { // NOLINT (runtime/references) + MAP_ENTRY(m_strMap, epslhcINVALID); + MAP_ENTRY(m_strMap, epslhcDISABLED); + MAP_ENTRY(m_strMap, epslhcENABLED); +} // End of void Init_SS_LimpHomeCutoff_StrMap(std::map<EPWR_LHC_TYPE, SS_String> & m_strMap) +class EnumStringMap< EPWR_LHC_TYPE, Init_SS_LimpHomeCutoff_StrMap> m_oSS_LimpHomeCutoffMap; +SS_String GetStr(EPWR_LHC_TYPE f_enum) { + return m_oSS_LimpHomeCutoffMap.GetStr(f_enum); +} + +//****************************************************************************** +void Init_SS_ProductionMode_StrMap(std::map<EPWR_PROD_MODE_TYPE, SS_String> & m_strMap) { // NOLINT (runtime/references) + MAP_ENTRY(m_strMap, epspmINVALID); + MAP_ENTRY(m_strMap, epspmDISABLED); + MAP_ENTRY(m_strMap, epspmENABLED); +} // End of void Init_SS_ProductionMode_StrMap(std::map<EPWR_PROD_MODE_TYPE, SS_String> & m_strMap) +class EnumStringMap< EPWR_PROD_MODE_TYPE, Init_SS_ProductionMode_StrMap> + m_oSS_ProductionModeMap; +SS_String GetStr(EPWR_PROD_MODE_TYPE f_enum) { + return m_oSS_ProductionModeMap.GetStr(f_enum); +} + +//****************************************************************************** +void Init_SS_StartupStage_StrMap(std::map<EPWR_STARTUP_STAGE_TYPE, SS_String> & m_strMap) { // NOLINT (runtime/references) + MAP_ENTRY(m_strMap, epssusfINVALID); + MAP_ENTRY(m_strMap, epssusSYSTEM_SERVICES_STARTED); + MAP_ENTRY(m_strMap, epssusALL_SERVICES_LAUNCHED); +} // End of void Init_SS_StartupStage_StrMap(std::map<EPWR_STARTUP_STAGE_TYPE, SS_String> & m_strMap) +class EnumStringMap< EPWR_STARTUP_STAGE_TYPE, Init_SS_StartupStage_StrMap> + m_oSS_StartupStageMap; +// LCOV_EXCL_START 6:Because the condition cannot be set +SS_String GetStr(EPWR_STARTUP_STAGE_TYPE f_enum) { + return m_oSS_StartupStageMap.GetStr(f_enum); +} +// LCOV_EXCL_STOP + +//****************************************************************************** +void Init_SS_SystemMode_StrMap(std::map<EPWR_SYSTEM_MODE_INFO, SS_String> & m_strMap) { // NOLINT (runtime/references) + MAP_ENTRY(m_strMap, epssinfINVALID); + MAP_ENTRY(m_strMap, epssinfNORMAL); + MAP_ENTRY(m_strMap, epssinfPROGRAMMING); +} // End of void Init_SS_SystemMode_StrMap(std::map<EPWR_SYSTEM_MODE_INFO, SS_String> & m_strMap) +class EnumStringMap< EPWR_SYSTEM_MODE_INFO, Init_SS_SystemMode_StrMap> + m_oSS_SystemModeMap; +// LCOV_EXCL_START 6:Because the condition cannot be set +SS_String GetStr(EPWR_SYSTEM_MODE_INFO f_enum) { + return m_oSS_SystemModeMap.GetStr(f_enum); +} +// LCOV_EXCL_STOP + +//****************************************************************************** +void Init_SS_TransportMode_StrMap(std::map<EPWR_TRANSPORT_MODE_TYPE, SS_String> & m_strMap) { // NOLINT (runtime/references) + MAP_ENTRY(m_strMap, epstmINVALID); + MAP_ENTRY(m_strMap, epstmDISABLED); + MAP_ENTRY(m_strMap, epstmENABLED); +} // End of void Init_SS_TransportMode_StrMap(std::map<EPWR_TRANSPORT_MODE_TYPE, SS_String> & m_strMap) +class EnumStringMap< EPWR_TRANSPORT_MODE_TYPE, Init_SS_TransportMode_StrMap> + m_oSS_TransportModeMap; +SS_String GetStr(EPWR_TRANSPORT_MODE_TYPE f_enum) { + return m_oSS_TransportModeMap.GetStr(f_enum); +} + +//****************************************************************************** +void Init_EInterfaceunifiedStatus_StrMap(std::map<EFrameworkunifiedStatus, SS_String> & m_strMap); // NOLINT (runtime/references) +class EnumStringMap< EFrameworkunifiedStatus, Init_EInterfaceunifiedStatus_StrMap> m_oEInterfaceunifiedStatusMap; +SS_String GetStr(EFrameworkunifiedStatus f_enum) { + return m_oEInterfaceunifiedStatusMap.GetStr(f_enum); +} + +//****************************************************************************** +void Init_SS_SystemManagerProtocol_StrMap(std::map<SS_SystemManagerProtocol, + SS_String> & m_strMap); // NOLINT (runtime/references) +class EnumStringMap< SS_SystemManagerProtocol, + Init_SS_SystemManagerProtocol_StrMap> m_oSSSMProtocolMap; +SS_String GetStr(SS_SystemManagerProtocol f_enum) { + return m_oSSSMProtocolMap.GetStr(f_enum); +} + +//****************************************************************************** +void Init_SS_ColdStart_StrMap(std::map<EPWR_SC_COLD_START_REQ_TYPE, + SS_String> &m_strMap) { // NOLINT (runtime/references) + MAP_ENTRY(m_strMap, epsscrtINVALID); + MAP_ENTRY(m_strMap, epsscrtNOT_REQUIRED); + MAP_ENTRY(m_strMap, epsscrtREQUIRED); +} +class EnumStringMap< EPWR_SC_COLD_START_REQ_TYPE, + Init_SS_ColdStart_StrMap> m_oSSColdStart_Map; +// LCOV_EXCL_START 6:Because the condition cannot be set +SS_String GetStr(EPWR_SC_COLD_START_REQ_TYPE f_enum) { + return m_oSSColdStart_Map.GetStr(f_enum); +} +// LCOV_EXCL_STOP + +//****************************************************************************** +void Init_SS__CWORD56__BootMode_StrMap(std::map<EPWR_SC__CWORD56__BOOT_MODE_TYPE, SS_String> &m_strMap) { // NOLINT (runtime/references) + MAP_ENTRY(m_strMap, eps_CWORD56_bmINVALID); + MAP_ENTRY(m_strMap, eps_CWORD56_bmAPPLICATION_MODE); + MAP_ENTRY(m_strMap, eps_CWORD56_bmPROGRAMMING_MODE); +} // End of void Init_SS__CWORD56__BootMode_StrMap(std::map<EPWR_SC__CWORD56__BOOT_MODE_TYPE, SS_String> &m_strMap) +class EnumStringMap< EPWR_SC__CWORD56__BOOT_MODE_TYPE, + Init_SS__CWORD56__BootMode_StrMap> m_oSS_CWORD56_BootMode_Map; +SS_String GetStr(EPWR_SC__CWORD56__BOOT_MODE_TYPE f_enum) { + return m_oSS_CWORD56_BootMode_Map.GetStr(f_enum); +} + +//****************************************************************************** +void Init_SS__CWORD102__BootMode_StrMap(std::map<ESMBootModeInfo, SS_String> &m_strMap) { // NOLINT (runtime/references) + MAP_ENTRY(m_strMap, e_SS_SM_BOOT_MODE_INVALID); + MAP_ENTRY(m_strMap, e_SS_SM_BOOT_MODE_APPLICATION); + MAP_ENTRY(m_strMap, e_SS_SM_BOOT_MODE_PROGRAMMING); +} // End of void Init_SS__CWORD102__BootMode_StrMap(std::map<ESMBootModeInfo, SS_String> &m_strMap) + +class EnumStringMap< ESMBootModeInfo, + Init_SS__CWORD102__BootMode_StrMap> m_oSS_CWORD102_BootMode_Map; +SS_String GetStr(ESMBootModeInfo f_enum) { + return m_oSS_CWORD102_BootMode_Map.GetStr(f_enum); +} + +//****************************************************************************** +void Init_SS_ShutdownTrigger_StrMap(std::map<EPWR_SHUTDOWN_TRIGGER_TYPE, + SS_String> & m_strMap); // NOLINT (runtime/references) +class EnumStringMap< EPWR_SHUTDOWN_TRIGGER_TYPE, + Init_SS_ShutdownTrigger_StrMap> m_oSSShutdownTrigger_Map; +SS_String GetStr(EPWR_SHUTDOWN_TRIGGER_TYPE f_enum) { + return m_oSSShutdownTrigger_Map.GetStr(f_enum); +} + +//****************************************************************************** +void Init_SS_UserMode_StrMap(std::map<EPWR_USER_MODE_TYPE, SS_String> & m_strMap) { // NOLINT (runtime/references) + // Map of System Services User Mode enum values to string description + MAP_ENTRY(m_strMap, epsumINVALID); + MAP_ENTRY(m_strMap, epsumOFF); + MAP_ENTRY(m_strMap, epsumON); +} // End of void Init_SS_UserMode_StrMap(std::map<EPWR_USER_MODE_TYPE, SS_String> & m_strMap) + +class EnumStringMap< EPWR_USER_MODE_TYPE, + Init_SS_UserMode_StrMap> m_oSSUserMode_Map; +SS_String GetStr(EPWR_USER_MODE_TYPE f_enum) { + return m_oSSUserMode_Map.GetStr(f_enum); +} + +//****************************************************************************** +void Init_SS_CpuResetReason_StrMap(std::map<ESMCpuResetReason, SS_String> &m_strMap) { // NOLINT (runtime/references) + MAP_ENTRY(m_strMap, e_SS_SM_CPU_RESET_REASON_NORMAL); + MAP_ENTRY(m_strMap, e_SS_SM_CPU_RESET_REASON_DATA_RESET); + MAP_ENTRY(m_strMap, e_SS_SM_CPU_RESET_REASON_USER_FORCE_RESET); + MAP_ENTRY(m_strMap, e_SS_SM_CPU_RESET_REASON_GENERIC_ERR); + MAP_ENTRY(m_strMap, e_SS_SM_CPU_RESET_REASON_DSP_ERR); + MAP_ENTRY(m_strMap, e_SS_SM_CPU_RESET_REASON_CRITICAL_ERR); +} // End of void Init_SS_CpuResetReason_StrMap(std::map<ESMCpuResetReason, SS_String> &m_strMap) +class EnumStringMap< ESMCpuResetReason, + Init_SS_CpuResetReason_StrMap> m_oSS_CpuResetReason_Map; +// LCOV_EXCL_START 6:Because the condition cannot be set +SS_String GetStr(ESMCpuResetReason f_enum) { + return m_oSS_CpuResetReason_Map.GetStr(f_enum); +} +// LCOV_EXCL_STOP + +//****************************************************************************** +void Init_SS_UserModeChangeReason_StrMap(std::map<ePwrServiceUserModeChangeReasonType, SS_String> &m_strMap) { // NOLINT (runtime/references) + // LCOV_EXCL_BR_START 11:Excluded due to gcov restrictions(other) + MAP_ENTRY(m_strMap, epsumcrNOT_AVAILABLE); + MAP_ENTRY(m_strMap, epsumcrON_KEY); + MAP_ENTRY(m_strMap, epsumcrPARKING_B); + MAP_ENTRY(m_strMap, epsumcrPRE_BA); + MAP_ENTRY(m_strMap, epsumcrNORMAL); + MAP_ENTRY(m_strMap, epsumcrBACKGROUND_BA); + // LCOV_EXCL_BR_STOP 11:Excluded due to gcov restrictions(other) +} +class EnumStringMap< EPWR_USER_MODE_CHANGE_REASON_TYPE, + Init_SS_UserModeChangeReason_StrMap> m_oSS_UMCR_Map; +SS_String GetStr(EPWR_USER_MODE_CHANGE_REASON_TYPE f_enum) { + return m_oSS_UMCR_Map.GetStr(f_enum); +} + +//****************************************************************************** +void Init_SS_StartupReason_StrMap(std::map<EPWR_WAKEUP_FACTOR_TYPE, + SS_String> & m_strMap); // NOLINT (runtime/references) +class EnumStringMap< EPWR_WAKEUP_FACTOR_TYPE , + Init_SS_StartupReason_StrMap> m_oSSStartupReason_Map; +SS_String GetStr(EPWR_WAKEUP_FACTOR_TYPE f_enum) { + return m_oSSStartupReason_Map.GetStr(f_enum); +} + +//****************************************************************************** +void Init_EErrorEventType_StrMap(std::map<EErrorEventType, SS_String> & m_strMap) { // NOLINT (runtime/references) + MAP_ENTRY(m_strMap, eErrorEventTypeProcessCrash); + MAP_ENTRY(m_strMap, eErrorEventTypeHeartBeatFailure); + MAP_ENTRY(m_strMap, eErrorEventTypeSystemLowMemory); + MAP_ENTRY(m_strMap, eErrorEventTypeReserved1); + MAP_ENTRY(m_strMap, eErrorEventTypeUserInvokedUserForceReset); + MAP_ENTRY(m_strMap, eErrorEventTypeReserved2); + MAP_ENTRY(m_strMap, eErrorEventTypeReserved3); + MAP_ENTRY(m_strMap, eErrorEventTypeUserInvokedCollectAllLogs); + MAP_ENTRY(m_strMap, eErrorEventTypeBootMicroReset); + MAP_ENTRY(m_strMap, eErrorEventTypeProcessExit); + MAP_ENTRY(m_strMap, eErrorEventTypeUserInvokedCollectScreenShot); + MAP_ENTRY(m_strMap, eErrorEventTypeUserInvokedCollectInterfaceunifiedLogs); + MAP_ENTRY(m_strMap, eErrorEventTypeEelExport); + MAP_ENTRY(m_strMap, eErrorEventTypeInterfaceunifiedEmmcLogs); + MAP_ENTRY(m_strMap, eErrorEventTypeDiagEvent); + MAP_ENTRY(m_strMap, eErrorEventTypeCanEvent); + MAP_ENTRY(m_strMap, eErrorEventTypeDtcEvent); + MAP_ENTRY(m_strMap, eErrorEventTypeModConnFailed); + MAP_ENTRY(m_strMap, eErrorEventTypeStartRespFailed); + MAP_ENTRY(m_strMap, eErrorEventTypeUserInvokedCollectDevLogs); + MAP_ENTRY(m_strMap, eErrorEventTypeModuleInvokedResetRequest); + MAP_ENTRY(m_strMap, eErrorEventTypeModuleInvokedCollectDebugLogs); + MAP_ENTRY(m_strMap, eErrorEventTypeUserInvokedClearLogs); + MAP_ENTRY(m_strMap, eErrorEventTypeGroupRelaunch); + MAP_ENTRY(m_strMap, eErrorEventTypeMaxValue); +} // End of void Init_EErrorEventType_StrMap(std::map<EErrorEventType, SS_String> & m_strMap) + +void Init_SS_SystemManagerProtocol_StrMap(std::map<SS_SystemManagerProtocol, SS_String> &m_strMap) { // NOLINT (runtime/references) + // LCOV_EXCL_BR_START 11:Excluded due to gcov restrictions(other) + MAP_ENTRY(m_strMap, SS_SM_NOTIFY_SYSTEM_LAUNCH_COMPLETE); + MAP_ENTRY(m_strMap, SS_SM_PROTOCOL_INTERFACE_END); + MAP_ENTRY(m_strMap, SS_SM_START); + MAP_ENTRY(m_strMap, SS_SM_START_COMPL_RSPN); + MAP_ENTRY(m_strMap, SS_SM_STOP); + MAP_ENTRY(m_strMap, SS_SM_STOP_COMPL_RSPN); + MAP_ENTRY(m_strMap, SS_SM_PRE_START); + MAP_ENTRY(m_strMap, SS_SM_PRE_START_COMPL_RSPN); + MAP_ENTRY(m_strMap, SS_SM_PRE_STOP); + MAP_ENTRY(m_strMap, SS_SM_PRE_STOP_COMPL_RSPN); + MAP_ENTRY(m_strMap, SS_SM_BACKGROUND_START); + MAP_ENTRY(m_strMap, SS_SM_BACKGROUND_START_COMPL_RSPN); + MAP_ENTRY(m_strMap, SS_SM_BACKGROUND_STOP); + MAP_ENTRY(m_strMap, SS_SM_BACKGROUND_STOP_COMPL_RSPN); + MAP_ENTRY(m_strMap, SS_SM_GET_START_EXT_INFO); + MAP_ENTRY(m_strMap, SS_SM_GET_STOP_EXT_INFO); + MAP_ENTRY(m_strMap, SS_SM_WAKEUP_MODULES_CMPL_RSPN); + MAP_ENTRY(m_strMap, SS_SM_SHUTDOWN_MODULES_CMPL_RSPN); + MAP_ENTRY(m_strMap, SS_SM_WAKEUP_MODULES); + MAP_ENTRY(m_strMap, SS_SM_SHUTDOWN_MODULES); + MAP_ENTRY(m_strMap, SS_SM_CRNT_STATE_QUERY); + MAP_ENTRY(m_strMap, SS_SM_CRNT_STATE_QUERY_RSPN); + MAP_ENTRY(m_strMap, SS_SM_SYSTEM_MODE_INFO_REQ); + MAP_ENTRY(m_strMap, SS_SM_SYSTEM_MODE_INFO_RSPN); + MAP_ENTRY(m_strMap, SS_SM_INITCOMP_REP); + MAP_ENTRY(m_strMap, SS_SM_DATA_RESET_MODE_SET_REQ); + MAP_ENTRY(m_strMap, SS_SM_PROG_UPDATE_STATE_SET_REQ); + MAP_ENTRY(m_strMap, SS_SM_CPU_RESET_REQ); + MAP_ENTRY(m_strMap, SS_SM_REMOTE_DATA_RESET_REQ); + MAP_ENTRY(m_strMap, SS_SM_FWD_STARTUP_CONFIRMATION_MSG_REQ); + MAP_ENTRY(m_strMap, SS_SM_FWD_START_CONFIRMATION_MSG_RESP); + MAP_ENTRY(m_strMap, SS_SM_POWER_REQUEST_MSG); + MAP_ENTRY(m_strMap, SS_SM_POWER_REQUEST_MSG_RESP); + MAP_ENTRY(m_strMap, SS_SM_USER_MODE_SET_RESP); + + MAP_ENTRY(m_strMap, SS_SM_EVENT_ERROR); + MAP_ENTRY(m_strMap, SS_SM_EVENT_ERROR_TO_SSL); + MAP_ENTRY(m_strMap, SS_SM_ERROR_EVENT_LOGGING_START_REQ); + MAP_ENTRY(m_strMap, SS_SM_ERROR_EVENT_LOGGING_START_RSPN); + MAP_ENTRY(m_strMap, SS_SM_ERROR_EVENT_ARTIFACT_REQ); + MAP_ENTRY(m_strMap, SS_SM_ERROR_EVENT_ARTIFACT_RSPN); + MAP_ENTRY(m_strMap, SS_SM_ERROR_EVENT_LOGGING_COMPLETE); + MAP_ENTRY(m_strMap, SS_SM_ERROR_EVENT_LOGGING_COMPLETE_RSPN); + MAP_ENTRY(m_strMap, SS_SM_ERROR_EVENT_TIMER_ID_LOGGER_START_REQ); + MAP_ENTRY(m_strMap, SS_SM_ERROR_EVENT_TIMER_ID_DEBUG_DUMP_RSPN); + MAP_ENTRY(m_strMap, SS_SM_ERROR_EVENT_TIMER_ID_BOOT_MICRO_LOG_RSPN); + MAP_ENTRY(m_strMap, SS_SM_ERROR_EVENT_TIMER_ID_CORE_FILE_POLL); + MAP_ENTRY(m_strMap, SS_SM_USER_INVOKED_LOG_REQ); + MAP_ENTRY(m_strMap, SS_SM_ERROR_EVENT_EEL_EXPORT_REQ); + MAP_ENTRY(m_strMap, SS_SM_ERROR_EVENT_INTERFACEUNIFIED_EMMC_LOGS_REQ); + MAP_ENTRY(m_strMap, SS_SM_ERROR_EVENT_INTERFACEUNIFIED_EMMC_LOGS_RSPN); + MAP_ENTRY(m_strMap, SS_SM_ERROR_EVENT_CLR_LOGS_REQ); + MAP_ENTRY(m_strMap, SS_SM_ERROR_EVENT_PROCESS_EXIT); + MAP_ENTRY(m_strMap, SS_SM_ERROR_EVENT_DIAG_LOG_REQ); + MAP_ENTRY(m_strMap, SS_SM_ERROR_EVENT_CAN_LOG_REQ); + MAP_ENTRY(m_strMap, SS_SM_GROUP_LAUNCH_TRIGGER); + MAP_ENTRY(m_strMap, SS_SM_DEBUG_DUMP); + MAP_ENTRY(m_strMap, SS_SM_DEBUG_DUMP_RSPN); + MAP_ENTRY(m_strMap, SS_SM_CPU_HIGH_LOAD_DETECTED); + MAP_ENTRY(m_strMap, SS_SM_PROPAGATE_SYSTEM_ERROR); + MAP_ENTRY(m_strMap, SS_SM__CWORD56__HEARTBEAT_REQ); + MAP_ENTRY(m_strMap, SS_SM__CWORD56__HEARTBEAT_RSPN); + MAP_ENTRY(m_strMap, SS_SM_BOOT_MICRO_RESET_NTF); + MAP_ENTRY(m_strMap, SS_SM_BOOT_MICRO_LOG_REQ); + MAP_ENTRY(m_strMap, SS_SM_BOOT_MICRO_LOG_RSP); + MAP_ENTRY(m_strMap, SS_SM_NEXT_WAKEUP_TYPE_SET_REQ); + // LCOV_EXCL_BR_STOP 11:Excluded due to gcov restrictions(other) +} // End of void Init_SS_SystemManagerProtocol_StrMap(std::map<SS_SystemManagerProtocol, SS_String> &m_strMap) + + + +void Init_EInterfaceunifiedStatus_StrMap(std::map<EFrameworkunifiedStatus, SS_String> & m_strMap) { // NOLINT (runtime/references) + MAP_ENTRY(m_strMap, eFrameworkunifiedStatusEmptyMediaList); + MAP_ENTRY(m_strMap, eFrameworkunifiedStatusSessionLimitMaxedOut); + MAP_ENTRY(m_strMap, eFrameworkunifiedStatusDbRecNotFound); + MAP_ENTRY(m_strMap, eFrameworkunifiedStatusDbResultError); + MAP_ENTRY(m_strMap, eFrameworkunifiedStatusDbExecuteFail); + MAP_ENTRY(m_strMap, eFrameworkunifiedStatusSemCloseFail); + MAP_ENTRY(m_strMap, eFrameworkunifiedStatusSemUnlockFail); + MAP_ENTRY(m_strMap, eFrameworkunifiedStatusSemLockFail); + MAP_ENTRY(m_strMap, eFrameworkunifiedStatusFail); + MAP_ENTRY(m_strMap, eFrameworkunifiedStatusErrOther); + MAP_ENTRY(m_strMap, eFrameworkunifiedStatusOK); + MAP_ENTRY(m_strMap, eFrameworkunifiedStatusInvldBuf); + MAP_ENTRY(m_strMap, eFrameworkunifiedStatusInvldHandle); + MAP_ENTRY(m_strMap, eFrameworkunifiedStatusInvldHndlType); + MAP_ENTRY(m_strMap, eFrameworkunifiedStatusInvldQName); + MAP_ENTRY(m_strMap, eFrameworkunifiedStatusMsgQFull); + MAP_ENTRY(m_strMap, eFrameworkunifiedStatusInvldNotification); + MAP_ENTRY(m_strMap, eFrameworkunifiedStatusInvldParam); + MAP_ENTRY(m_strMap, eFrameworkunifiedStatusInvldBufSize); + MAP_ENTRY(m_strMap, eFrameworkunifiedStatusInvldID); + MAP_ENTRY(m_strMap, eFrameworkunifiedStatusCannotRelease); + MAP_ENTRY(m_strMap, eFrameworkunifiedStatusBadConnection); + MAP_ENTRY(m_strMap, eFrameworkunifiedStatusExit); + MAP_ENTRY(m_strMap, eFrameworkunifiedStatusNotImplemented); + MAP_ENTRY(m_strMap, eFrameworkunifiedStatusThreadBusy); + MAP_ENTRY(m_strMap, eFrameworkunifiedStatusThreadSelfJoin); + MAP_ENTRY(m_strMap, eFrameworkunifiedStatusThreadInvalidVal); + MAP_ENTRY(m_strMap, eFrameworkunifiedStatusThreadNotExist); + MAP_ENTRY(m_strMap, eFrameworkunifiedStatusFault); + MAP_ENTRY(m_strMap, eFrameworkunifiedStatusServNotFound); + MAP_ENTRY(m_strMap, eFrameworkunifiedStatusServerInUse); + MAP_ENTRY(m_strMap, eFrameworkunifiedStatusDbIndexing); + MAP_ENTRY(m_strMap, eFrameworkunifiedStatusNullPointer); + MAP_ENTRY(m_strMap, eFrameworkunifiedStatusMsgNotProcessed); + MAP_ENTRY(m_strMap, eFrameworkunifiedStatusFileLoadSuccess); + MAP_ENTRY(m_strMap, eFrameworkunifiedStatusFileLoadError); + MAP_ENTRY(m_strMap, eFrameworkunifiedStatusAccessError); + MAP_ENTRY(m_strMap, eFrameworkunifiedStatusDuplicate); + MAP_ENTRY(m_strMap, eFrameworkunifiedStatusMsgQEmpty); + MAP_ENTRY(m_strMap, eFrameworkunifiedStatusThreadAlreadyRunning); + MAP_ENTRY(m_strMap, eFrameworkunifiedStatusErrNoEBADF); + MAP_ENTRY(m_strMap, eFrameworkunifiedStatusErrNoEAGAIN); + MAP_ENTRY(m_strMap, eFrameworkunifiedStatusErrNoEINTR); +} // End of void Init_EInterfaceunifiedStatus_StrMap(std::map<EFrameworkunifiedStatus, SS_String> & m_strMap){ + +void Init_SS_ShutdownTrigger_StrMap(std::map<EPWR_SHUTDOWN_TRIGGER_TYPE, SS_String> & m_strMap) { // NOLINT (runtime/references) + MAP_ENTRY(m_strMap, epssdmsdtINVALID); + MAP_ENTRY(m_strMap, epssdmsdtTESTACC_OFF); + MAP_ENTRY(m_strMap, epssdmsdtON_KEY); + MAP_ENTRY(m_strMap, epssdmsdtIGN_LOCK); + MAP_ENTRY(m_strMap, epssdmsdtPWR_SAVE); + MAP_ENTRY(m_strMap, epssdmsdtTMP_STARTUP); + MAP_ENTRY(m_strMap, epssdmsdtDIAG_DEACTIVATION); + MAP_ENTRY(m_strMap, epssdmsdtABNORMAL_VOLTAGE); + MAP_ENTRY(m_strMap, epssdmsdtABNORMAL_TEMP); + MAP_ENTRY(m_strMap, epssdmsdtBATTERYCUTOFF); + MAP_ENTRY(m_strMap, epssdmsdtLIMPHOME); + MAP_ENTRY(m_strMap, epssdmsdtHU_CAN_ERROR); + MAP_ENTRY(m_strMap, epssdmsdtBODY_CAN_ERROR); + MAP_ENTRY(m_strMap, epssdmsdtTRANSPORT_MODE); + MAP_ENTRY(m_strMap, epssdmsdtPRODUCTION_MODE); + MAP_ENTRY(m_strMap, epssdmsdtIGN_OFF); + MAP_ENTRY(m_strMap, epssdmsdtGENERIC_ERROR_RESET); + MAP_ENTRY(m_strMap, epssdmsdtFATAL_ERROR_RESET); + MAP_ENTRY(m_strMap, epssdmsdtUSER_DATA_RESET); + MAP_ENTRY(m_strMap, epssdmsdtFACTORY_DATA_RESET); + MAP_ENTRY(m_strMap, epssdmsdtFAST_SLEEP_MODE); + MAP_ENTRY(m_strMap, epssdmsdtNORMAL_RESET); +} // End of void Init_SS_ShutdownTrigger_StrMap(std::map<EPWR_SHUTDOWN_TRIGGER_TYPE, SS_String> & m_strMap) + +void Init_SS_StartupReason_StrMap(std::map<EPWR_WAKEUP_FACTOR_TYPE, SS_String> & m_strMap) { // NOLINT (runtime/references) + MAP_ENTRY(m_strMap, epswfINVALID); + MAP_ENTRY(m_strMap, epswfTESTACC); + MAP_ENTRY(m_strMap, epswfON_KEY); + MAP_ENTRY(m_strMap, epswfIGN_ACC); + MAP_ENTRY(m_strMap, epswfDR_OPEN_CLOSE); + MAP_ENTRY(m_strMap, epswfDX_ACTIVATION); + MAP_ENTRY(m_strMap, epswfPASS_ACTIVATION); + MAP_ENTRY(m_strMap, epswfSPVACTIVATION); + MAP_ENTRY(m_strMap, epswfUSER_DATA_RESET); +} // LCOV_EXCL_BR_LINE 10:Because the last line +// End of void Init_SS_WakeupFactor_StrMap(std::map<EPWR_WAKEUP_FACTOR_TYPE, SS_String> & m_strMap) + +// EOF ss_string_maps.cpp + + diff --git a/systemservice/interface_unified/library/src/ss_system_process.cpp b/systemservice/interface_unified/library/src/ss_system_process.cpp new file mode 100755 index 0000000..71a969a --- /dev/null +++ b/systemservice/interface_unified/library/src/ss_system_process.cpp @@ -0,0 +1,1147 @@ +/* + * @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_SystemManagerIf +/// \brief This file provides support for the System Manager client interface. +/// +/////////////////////////////////////////////////////////////////////////////// + +#include "system_service/ss_system_process.h" +#include <errno.h> +#include <sys/types.h> +#include <unistd.h> +#include <limits.h> +#include <pwd.h> +#include <grp.h> +#include <elfio/elfio_dump.hpp> + +#include <string.h> +#include <signal.h> +#include <sys/wait.h> +#include <assert.h> +#include <sys/stat.h> +#include <fcntl.h> +#include <libgen.h> +#include <stdio.h> +#include <stdlib.h> +#include <vector> +#include "ss_system_if_interfaceunifiedlog.h" + +const char* iProcess_DEFAULT_PROCESS_USER_NAME = "default_user"; +uid_t iProcess_DEFAULT_PROCESS_USER = 4999; +gid_t iPrpocess_DEFAULT_PROCESS_GROUP = 4999; + +/** + * Process: Called when the class is instantiated. + * + * @return + */ +Process::Process(int cpu_assign) : + m_lValidationTag(lProcess_VALIDATION_VALUE), + m_cpu_assign(cpu_assign), + m_tProcessId(-1), + m_eProcessLoadMode(NOWAIT), + m_strFile(""), + m_strProcessName(""), + m_iErrorCode(0), + m_fAutoKill(TRUE), + m_iReturnCode(0) { +} + + +/** + * ~Process: Called when the object is destroyed. + * + * @return + */ +Process::~Process() { + // ASSERT_VALID (this); + + // + // Set the validation tag to NOT valid + m_lValidationTag = 0; + + // + // Cleanup after ourselves... + // + if ((m_fAutoKill) && (m_tProcessId != -1) && (m_tProcessId != getpid())) { + KillProcess(); // Then remove the process from PosixBasedOS001 + } +} + +/** + * Process: Used to create an object and copy another + * object to the new object. + * + * @param p_rhs_i Reference to the class being copied from. + * @return Process( const + */ +Process::Process(const Process& p_rhs_i) { + // Copy data from the specified object to this object. + Copy(p_rhs_i); +} + + +/** + * operator=: Called when one object is assigned + * to another object. + * + * @param p_rhs_i Reference to the class being copied from. + * @return Process& + */ +Process& Process::operator= (const Process& p_rhs_i) { + // Don't do anything if we're being copied on to ourselves. + if (this == &p_rhs_i) return (*this); + + // Copy data from the specified object to this object. + Copy(p_rhs_i); + + return (*this); +} + + +/** + * Copy: Copies data members from the specified object to this object. + * No attempt is made to free dynamically allocated objects within + * this object (you must do that before calling this function). + * + * @param p_rhs_i + * @return void + */ +void Process::Copy(const Process& p_rhs_i) { + // Copy data from the specified object to this object. + m_lValidationTag = p_rhs_i.m_lValidationTag; + + m_tProcessId = p_rhs_i.m_tProcessId; + m_eProcessLoadMode = p_rhs_i.m_eProcessLoadMode; + m_strFile = p_rhs_i.m_strFile; + m_strlstArgv = p_rhs_i.m_strlstArgv; + m_strProcessName = p_rhs_i.m_strProcessName; + m_iErrorCode = p_rhs_i.m_iErrorCode; + m_fAutoKill = p_rhs_i.m_fAutoKill; + m_iReturnCode = p_rhs_i.m_iReturnCode; +} + +/** + * GetProcessReturnCode: This function will return the processes + * exit/return code. This is not the value of ERRNO as returned by + * GetLastPosixBasedOS001ErrorCode(). + * + * @return code from the process + */ +int Process::GetProcessReturnCode() { + int iProcessReturn = 0; + if (waitpid(m_tProcessId, &iProcessReturn, WNOHANG) > 0) { + m_iReturnCode = WEXITSTATUS(iProcessReturn); + } + + return m_iReturnCode; +} + +static int getIdsFromUserName(const char* user_name, uid_t *uid, gid_t *gid) { + int ret = -1; + + try { + if (NULL == user_name) { + *uid = geteuid(); + *gid = getegid(); + } else { + static __thread size_t bufSize = 0; + static __thread char *buf = NULL; + struct passwd pwd; + struct passwd *result; + + if (0 == bufSize) { + struct stat statInfo; + + bufSize = -1; + + if (0 != stat("/etc/passwd", &statInfo) || 0 >= statInfo.st_size) { + throw "/etc/passwd is not exist"; + } + + bufSize = statInfo.st_size * 2; + + // Since SystemManager is a resident service, + // the area secured here is not explicity released by free() + // in anticipation of release at the end of the process + buf = reinterpret_cast<char *>(malloc(sizeof(char) * bufSize)); + if (NULL == buf) { + throw "malloc()"; + } + } + + if (NULL == buf) { + throw "buf = NULL"; + } + + ret = getpwnam_r(user_name, &pwd, buf, bufSize, &result); + if (ret == 0 && result != NULL) { + *uid = pwd.pw_uid; + *gid = pwd.pw_gid; + } else { + throw "getpwnam_r()"; + } + } + + ret = 0; + } + + catch (const char *e) { + FRAMEWORKUNIFIEDLOG(ZONE_ERR, __PRETTY_FUNCTION__, "ERROR:%s", e); + } + + return ret; +} + +/** + * CreateProcess: This method will create a PosixBasedOS001 process with the executable provided and mode as a calling parameter. + * The caller can also provide a list of arguments that will be provided to the executable at startup. + * The calling p_strProcessName parameter is a textual name that will be + * associated with the newly created process by the OS. The process state information + * will be maintained by this object. + * + * Upon successful creation of the process, the scheduling policy and priority + * of the process will be set to the provided values. The user can change these + * values through the SetSchedulingPolicy() and SetPriority() method calls. + * + * @param p_strFile_i Path and Filename of executable to create process for + * @param p_strlstArgv_i List of ARGV values for new process + * @param p_eMode_i Mode to create and load new process + * WAIT - The invoked program is loaded into available memory, is executed, + * and then the original program resumes execution. + * NOWAIT - Causes the current program to execute concurrently with the new child process. + * @param p_strProcessName_i This is the name that will be registered to the OS for this process + * @param p_eSchedulingPolicy_i Scheduling Policy for this process + * FIFO - A fixed priority scheduler in which the highest ready process runs until it + * blocks or is preempted by a higher priority process. + * ROUND_ROBIN - The same as FIFO, except processes at the same priority level time-slice. + * OTHER - A general time sharing scheduler in which a process decays in priority if it + * consumes too much processor before blocking. It reverts to its default priority + * when it blocks. Should it fail to run over a 2 second period and it has decayed + * then it's boosted one priority level up to a maximum of its default priority. + * @param p_iPriority_i Priority for this process + * @param p_lSpawnFlags_i Spawning flags. These are PosixBasedOS001 specific.... + * @return void + */ +void Process::CreateProcess( + const SS_String& p_strFile_i, // Path and Filename of executable to create process for + const StringList& p_strlstArgv_i, // List of ARGV values for new process + const eProcessLoadMode p_eMode_i, // Mode to create and load new process + const SS_String& p_strProcessName_i, // This is the name that will be registered to the OS for this process + const eProcessSchedulingPolicy p_eSchedulingPolicy_i, // Scheduling Policy for this process + const int p_iPriority_i, // Priority for this process + const char* unix_user_name, + const long p_lSpawnFlags_i // Posix Spawning flags. These are PosixBasedOS001 specific.... // NOLINT (runtime/int) +) { + //======================================================================================== + // Perform some idiot checking of the parameters that are passed in. + // Check the priority level that is being set to make sure it is in bounds. + // Then save off the calling parameters into the objects member variables. + // Also check the number of valid calling (argv[]) parameters passed in + //======================================================================================== + m_iErrorCode = 0; // Initialize to NO ERROR + m_iReturnCode = 0; // Initialize value (0 usually means good in unix/PosixBasedOS001) + + // + // Process filename os provided + // + if (p_strFile_i.empty()) { + return; // PAD THIS IS BAD!!! TODO: Change this to something meaningful + } + + // + // Save off process calling arguments + // + m_eProcessLoadMode = p_eMode_i; + + m_strFile = p_strFile_i; + + if (!p_strProcessName_i.empty()) + m_strProcessName = p_strProcessName_i; + + // + // Copy Argument List... + // + SetCallingArgumentList(p_strlstArgv_i); + + // + // Valid number of calling arguments + // + int iNumberElements = m_strlstArgv.size(); + if (iNumberElements > (iProcess_MAXIMUM_NUMBER_OF_PROCESS_ARGUMENTS - 3)) { + return; // PAD THIS IS BAD!!! TODO: Change this to something meaningful + } + + + //======================================================================================== + // Initialize to the beginning of the provided argument list. + // Allocate an array of buffer pointers that will be used for the ARGV calling parameters + // for the specified process. + // Set the ARGV[0] equal to the process name being created + // Set the ARGV[1] equal to the process name to be registered with the OS. + // If p_strProcessName_is NULL, do not set the cArgv[1] parameter + // Populate the array that will hold the argument list for the new process we are creating. + //======================================================================================== + // + + int iLoop = 1; + char * cArgv[iProcess_MAXIMUM_NUMBER_OF_PROCESS_ARGUMENTS]; + + cArgv[0] = basename(const_cast<char *>(p_strFile_i.c_str())); // Set the executable filename + + // Go through the list of provided argv calling parameters to the CreateProcess + // function, and copy the arguments to the ARGV[] calling argument which will be passed + // into the process being created. + StringListIter at = m_strlstArgv.begin(); + for (; at != m_strlstArgv.end(); at++, iLoop++) { + cArgv[iLoop] = const_cast<char *>(at->c_str()); + } + + cArgv[iLoop] = NULL; + + try { + CL_ProcessAttr_t clAttr; + CL_ProcessSchedPolicy_t clPolicy = CL_PROCESS_SCHED_POLICY_OTHER; + int clPriority = 0; + + if (0 != CL_ProcessCreateAttrInit(&clAttr)) { + throw "CL_ProcessCreateAttrInit()"; + } + + + // In order to collect even the child processes of the service, all are group leaders. + if (0 != CL_ProcessCreateAttrSetGroup(&clAttr, 1)) { + throw "CL_ProcessCreateAttrInit()"; + } + + if (0 != CL_ProcessCreateAttrSetCpuAssign(&clAttr, m_cpu_assign)) { + throw "CL_ProcessCreateAttrSetCpuAssign()"; + } + + switch (p_eSchedulingPolicy_i) { + case FIFO: + clPolicy = CL_PROCESS_SCHED_POLICY_FIFO; + break; + case ROUND_ROBIN: + clPolicy = CL_PROCESS_SCHED_POLICY_RR; + break; + case OTHER: + clPolicy = CL_PROCESS_SCHED_POLICY_OTHER; + break; + default: + FRAMEWORKUNIFIEDLOG(ZONE_ERR, __PRETTY_FUNCTION__, "p_eSchedulingPolicy_i = %d", p_eSchedulingPolicy_i); + break; + } + + switch (p_eSchedulingPolicy_i) { + case FIFO: + case ROUND_ROBIN: + if ((1 > p_iPriority_i) || (p_iPriority_i > 99)) { + FRAMEWORKUNIFIEDLOG(ZONE_ERR, __PRETTY_FUNCTION__, "p_eSchedulingPolicy_i = %d", p_eSchedulingPolicy_i); + } else { + clPriority = p_iPriority_i; + } + break; + case OTHER: + default: + if ((-20 > p_iPriority_i) || (p_iPriority_i > 19)) { + FRAMEWORKUNIFIEDLOG(ZONE_ERR, __PRETTY_FUNCTION__, "p_eSchedulingPolicy_i = %d", p_eSchedulingPolicy_i); + } else { + clPriority = p_iPriority_i; + } + break; + } + + if (0 != CL_ProcessCreateAttrSetSchedule(&clAttr, clPolicy, clPriority)) { + throw "CL_ProcessCreateAttrSetSchedule()"; + } + + uid_t uid = 0; + gid_t gid = 0; + + if (0 != getIdsFromUserName(unix_user_name, &uid, &gid)) { + FRAMEWORKUNIFIEDLOG(ZONE_ERR, __PRETTY_FUNCTION__, "unexpected unix_user_name [%s]", unix_user_name); + uid = geteuid(); + gid = getegid(); + } + if (uid == 0) { + FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "!! uid=root %s", m_strFile.c_str()); + uid = UINT_MAX; + } + if (0 != CL_ProcessCreateAttrSetUid(&clAttr, uid)) { + throw "CL_ProcessCreateAttrSetUid()"; + } + + if (0 != CL_ProcessCreateAttrSetGid(&clAttr, gid)) { + throw "CL_ProcessCreateAttrSetGid()"; + } + + if (0 != CL_ProcessCreateAttrSetDisableCloseFds(&clAttr)) { + throw "CL_ProcessCreateAttrSetDisableCloseFds()"; + } + char environment_string[2048] = {0}; // Size is provisional + fprintf(stderr, "[%s](%d)Process Create Target : %s \n", __func__, __LINE__, m_strFile.c_str()); + + CheckLdPreLoad(&m_strFile, environment_string); + + CreateProcess(&m_strFile, const_cast<char* const*>(cArgv), environment_string, &clAttr); + } + + catch(const char *e) { + FRAMEWORKUNIFIEDLOG(ZONE_ERR, __PRETTY_FUNCTION__, "%s", e); + } +} + +/** + * CreateProcess: This method will create a process with the executable provided and mode as a calling parameter. + * The caller can also provide a list of arguments that will be provided to the executable at startup. + * The calling p_strProcessName parameter is a textual name that will be + * associated with the newly created process by the OS. The process state information + * will be maintained by this object. + * + * @param p_str_file Path and Filename of executable to create process for + * @param c_argv use process arguments + * @param environment_string Set LD_PRELOAD string + * @param cl_attr CL_ProcessAttr_t + * @return void + */ +void Process::CreateProcess(const SS_String *p_str_file, char* const*c_argv, char* environment_string, + const CL_ProcessAttr_t *cl_attr) { + try { + if ((p_str_file == NULL) || (c_argv == NULL) || (cl_attr == NULL)) { + throw "CreateProcess() Invaild Param"; + } + + int process_id = -1; + if (environment_string[0] == '\0') { + // If there is no LD_PRELOAD setting, set envp to NULL + process_id = CL_ProcessCreate(p_str_file->c_str(), c_argv, NULL, cl_attr); + } else { + // vector holding preferences + std::vector<SS_String> *vec_environ = GetEnvironVector(); + + // Set LD_PRELOAD string as the last element + SS_String ld_preload_string = SS_String(environment_string); + vec_environ->push_back(environment_string); + + // Number of acquired environment variables + 1(For terminal) memory allocation + size_t env_num = sizeof(char*) * (vec_environ->size() + 1); + char **p_environment = static_cast<char **>(malloc(env_num)); + memset(p_environment, 0x00, env_num); + + // Create environment variable list + int i = 0; + char **p_environment_tmp = p_environment; + for (std::vector<SS_String>::iterator itr = vec_environ->begin(); itr != vec_environ->end(); itr++, i++) { + p_environment_tmp[i] = static_cast<char *>(malloc(sizeof(char) * (itr->length() + 1))); + + snprintf(p_environment_tmp[i], itr->length() + 1, "%s", itr->c_str()); + } + + // Set envp for environment variable + process_id = CL_ProcessCreate(p_str_file->c_str(), c_argv, p_environment, cl_attr); + + // Free memory + i = 0; + p_environment_tmp = p_environment; + for (std::vector<SS_String>::iterator itr = vec_environ->begin(); itr != vec_environ->end(); itr++, i++) { + free(p_environment_tmp[i]); + } + + free(p_environment); + delete(vec_environ); + } + + if (process_id == -1) { + throw "CL_ProcessCreate()"; + } + + m_tProcessId = process_id; + } + catch (const char *e) { + FRAMEWORKUNIFIEDLOG(ZONE_ERR, __PRETTY_FUNCTION__, "%s", e); + } +} +/** + * CreateProcess: This method will create a PosixBasedOS001 process with the executable provided and mode as a calling parameter. + * The caller can also provide a list of arguments that will be provided to the executable at startup. + * The calling p_strProcessName parameter is a textual name that will be + * associated with the newly created process by the OS. The process state information + * will be maintained by this object. + * + * @param p_strFile_i Path and Filename of executable to create process for + * @param p_strProcessName This is the name that will be registered to the OS for this process + * @return void + */ +void Process::CreateProcess(const SS_String& p_strFile_i, const SS_String& p_strProcessName, + const char* unix_user_name, const long p_lSpawnFlags_i) { // NOLINT (runtime/int) + StringList strlstArgv; + + try { + CreateProcess(p_strFile_i, + strlstArgv, + NOWAIT, + p_strProcessName, + FIFO, + iProcess_DEFAULT_PROCESS_PRIORITY, + unix_user_name, + p_lSpawnFlags_i); + } + catch (...) { + return; // PAD THIS IS BAD!!! TODO: Change this to something meaningful + } +} + + +/** + * CreateProcess: This method will create a process with the executable provided and mode as a calling parameter. + * The caller can also provide a list of arguments that will be provided to the executable at startup. + * The calling p_strProcessName parameter is a textual name that will be + * associated with the newly created process by the OS. The process state information + * will be maintained by this object. + * + * + * @param p_strFile_i Path and Filename of executable to create process for + * @param p_strProcessName This is the name that will be registered to the OS for this process + * @param p_iPriority_i Priority of process + * @return void + */ +void Process::CreateProcess(const SS_String& p_strFile_i, const SS_String& p_strProcessName, const int p_iPriority_i, + const char* unix_user_name, const long p_lSpawnFlags_i) { // NOLINT (runtime/int) + StringList strlstArgv; + + try { + eProcessSchedulingPolicy policy; + + if (0 < p_iPriority_i) { + policy = FIFO; + } else { + policy = OTHER; + } + + CreateProcess(p_strFile_i, + strlstArgv, + NOWAIT, + p_strProcessName, + policy, + p_iPriority_i, + unix_user_name, + p_lSpawnFlags_i); + } + catch (...) { + return; // PAD THIS IS BAD!!! TODO: Change this to something meaningful + } +} + +/** + * CreateProcess: This method will create a process with the executable provided and mode as a calling parameter. + * The caller can also provide a list of arguments that will be provided to the executable at startup. + * The calling p_strProcessName parameter is a textual name that will be + * associated with the newly created process by the OS. The process state information + * will be maintained by this object. + * + * @param p_strFile_i Path and Filename of executable to create process for + * @param p_lSpawnFlags_i Spawning flags. These are PosixBasedOS001 specific. + * @return void + */ +void Process::CreateProcess(const SS_String& p_strFile_i, const char* unix_user_name, const long p_lSpawnFlags_i) { // NOLINT (runtime/int) + StringList strlstArgv; + + try { + CreateProcess(p_strFile_i, + strlstArgv, + NOWAIT, + basename(const_cast<char *>(p_strFile_i.c_str())), + FIFO, + iProcess_DEFAULT_PROCESS_PRIORITY, + unix_user_name, + p_lSpawnFlags_i); + } + catch (...) { + return; // PAD THIS IS BAD!!! TODO: Change this to something meaningful + } +} + + + +/** + * CreateProcess: This method will create a process with the executable provided and mode as a calling parameter. + * The caller can also provide a list of arguments that will be provided to the executable at startup. + * The calling p_strProcessName parameter is a textual name that will be + * associated with the newly created process by the OS. The process state information + * will be maintained by this object. + * + * @param p_strFile_i Path and Filename of executable to create process for + * @param p_strProcessName This is the name that will be registered to the OS for this process + * @param p_strlstArgv_i List of ARGV values for new process + * @param p_lSpawnFlags_i Spawning flags. These are PosixBasedOS001 specific. + * @return void + */ +void Process::CreateProcess(const SS_String& p_strFile_i, const SS_String& p_strProcessName_i, + const StringList& p_strlstArgv_i, const char* unix_user_name, const long p_lSpawnFlags_i) { // NOLINT (runtime/int) + try { + CreateProcess(p_strFile_i, + p_strlstArgv_i, + NOWAIT, + p_strProcessName_i, + FIFO, + iProcess_DEFAULT_PROCESS_PRIORITY, + unix_user_name, + p_lSpawnFlags_i); + } + catch (...) { + return; // PAD THIS IS BAD!!! TODO: Change this to something meaningful + } +} + + +void Process::CreateProcess(const SS_String& p_strFile_i, const SS_String& p_strProcessName_i, const int p_iPriority_i, + const StringList& p_strlstArgv_i, const char* unix_user_name, const long p_lSpawnFlags_i) { // NOLINT (runtime/int) + try { + eProcessSchedulingPolicy policy; + + if (0 < p_iPriority_i) { + policy = FIFO; + } else { + policy = OTHER; + } + + CreateProcess(p_strFile_i, + p_strlstArgv_i, + NOWAIT, + p_strProcessName_i, + policy, + p_iPriority_i, + unix_user_name, + p_lSpawnFlags_i); + } + catch (...) { + return; // PAD THIS IS BAD!!! TODO: Change this to something meaningful + } +} + + +/** + * CreateProcessWait: This method will create a process with the executable provided. + * The process state information will be maintained by this object. + * + * @param p_strFile_i Path and Filename of executable to create process for + * @return void + */ +void Process::CreateProcessWait(const SS_String& p_strFile_i) { + StringList strlstArgv; + + try { + CreateProcess(p_strFile_i, + strlstArgv, + WAIT, + basename(const_cast<char *>(p_strFile_i.c_str())), + FIFO, + iProcess_DEFAULT_PROCESS_PRIORITY, + iProcess_DEFAULT_PROCESS_USER_NAME, + iProcess_DEFAULT_PROCESS_FLAGS); + } + catch (...) { + return; // PAD THIS IS BAD!!! TODO: Change this to something meaningful + } +} + +/** + * CreateProcessWait: This method will create a PosixBasedOS001 process with the executable provided. + * The process state information will be maintained by this object. + * + * + * @param p_strFile_i Path and Filename of executable to create process for + * @param p_strlstArguments_i List of process calling arguments + * @return void + */ +void Process::CreateProcessWait(const SS_String& p_strFile_i, const StringList& p_strlstArguments_i) { + try { + CreateProcess(p_strFile_i, + p_strlstArguments_i, + WAIT, + basename(const_cast<char *>(p_strFile_i.c_str())), + FIFO, + iProcess_DEFAULT_PROCESS_PRIORITY, + iProcess_DEFAULT_PROCESS_USER_NAME, + iProcess_DEFAULT_PROCESS_FLAGS); + } + catch (...) { + return; // PAD THIS IS BAD!!! TODO: Change this to something meaningful + } +} + + + +/** + * KillProcess: This method will delete the process represented by this object. All variables associated + * with this object will be initialized to a know value. + * + * @param + * @return void + */ +void Process::KillProcess(int signal) { + //===================================================================================== + // Intialize the objects m_iErrorCode member variable to 0 (no error). + // Then try to delete the process that this object represents. + m_iErrorCode = 0; + + if (DoesProcessExist()) { + if (-1 == killpg(m_tProcessId, signal)) { + return; // PAD THIS IS BAD!!! TODO: Change this to something meaningful + } + } + + // + // If no errors, clear out any process specific member variables for this object + // + m_tProcessId = -1; + m_strProcessName = ""; +} + +/** + * SetSchedulingPolicy: This method will change the scheduling policy for the process this + * object represents. + * + * @param p_eSchedulingPolicy_i Scheduling policy + * @return void + */ +void Process::SetSchedulingPolicy( + const eProcessSchedulingPolicy p_eSchedulingPolicy_i // Scheduling policy +) { + //======================================================================================= + // Attempt to change the scheduling policy for the process that this object + // represents. If the change fails, restore the previous settings. + // + m_iErrorCode = 0; + struct sched_param cur_sch_params; + sched_getparam(m_tProcessId, &cur_sch_params); + if (0 != sched_setscheduler(m_tProcessId, ConvertToPosixBasedOS001SchedularPolicy(p_eSchedulingPolicy_i), + &cur_sch_params)) { + m_iErrorCode = errno; + return; // PAD THIS IS BAD!!! TODO: Change this to something meaningful + } +} + +/** + * SetPriority: This method will change the priority for the process this + * object represents. + * + * @param p_iPriority_i Scheduling Policy for this process + * @return void + */ +void Process::SetPriority(const int p_iPriority_i) { + //======================================================================================= + // Attempt to change the priority for the process that this object + // represents. If the change fails, restore the previous settings. + // + m_iErrorCode = 0; + struct sched_param cur_sch_params; + sched_getparam(m_tProcessId, &cur_sch_params); + cur_sch_params.sched_priority = p_iPriority_i; + + if (-1 == sched_setparam(m_tProcessId, &cur_sch_params)) { + m_iErrorCode = errno; + return; // PAD THIS IS BAD!!! TODO: Change this to something meaningful + } +} + + +/** + * IncreasePriorityByOne: This method will increase the priority for the process this + * object represents by one. + * + * @param + * @return void + */ +void Process::IncreasePriorityByOne(void) { + //================================================================================ + // Retrieve the current priority of the process. Check to see if already at max. + // If so just return. Otherwise increase by one and set the priority... + // + try { + int iCurrentPriority = GetPriority(); + if (iCurrentPriority < iProcess_MAXIMUM_PROCESS_PRIORITY) { + SetPriority(iCurrentPriority + 1); + } + } + catch (...) { + return; // PAD THIS IS BAD!!! TODO: Change this to something meaningful + } +} + + +/** + * DecreasePriorityByOne: This method will decrease the priority for the process this + * object represents by one. + * + * + * @return void + */ +void Process::DecreasePriorityByOne(void) { + //================================================================================ + // Retrieve the current priority of the process. Check to see if already at minimum. + // If so just return. Otherwise decrease by one and set the priority... + // + try { + int iCurrentPriority = GetPriority(); + if (iCurrentPriority > 1) { + SetPriority(iCurrentPriority - 1); + } + } + catch (...) { + return; // PAD THIS IS BAD!!! TODO: Change this to something meaningful + } +} + + + + + +//////////////////////////////////////////////////////////////////////////////////////////////////// +// ConvertToPosixBasedOS001SchedularPolicy +// +// This method will return to the caller the equivalent PosixBasedOS001 schedular policy for the process +// that this object represents +// +// +// Calling Arguments: +// NONE +// +// Return Argument: +// FIFO, // A fixed priority scheduler in which the highest ready process runs until it +// // blocks or is preempted by a higher priority process. +// ROUND_ROBIN, // The same as FIFO, except processes at the same priority level time-slice. +// OTHER // A general time sharing scheduler in which a process decays in priority if it +// // consumes too much processor before blocking. It reverts to its default priority +// // when it blocks. Should it fail to run over a 2 second period and it has decayed +// // then it's boosted one priority level up to a maximum of its default priority. +// +int const Process::ConvertToPosixBasedOS001SchedularPolicy(const eProcessSchedulingPolicy p_eSchedulingPolicy_i) { + int iReturnValue = SCHED_RR; // Default is RR + switch (p_eSchedulingPolicy_i) { + case FIFO: + { + iReturnValue = SCHED_FIFO; + break; + } + + case ROUND_ROBIN: + { + iReturnValue = SCHED_RR; + break; + } + + case OTHER: + { + iReturnValue = SCHED_OTHER; + break; + } + } + + return iReturnValue; +} + +//////////////////////////////////////////////////////////////////////////////////////////////////// +// ConvertFromPosixBasedOS001SchedularPolicy +// +// This method will return to the caller the eProcessSchedulingPolicy based on the PosixBasedOS001 schedular +// policy for the process that this object represents +// +// +// Calling Arguments: +// PosixBasedOS001 Scheduling Policy +// +// Return Argument: +// FIFO, // A fixed priority scheduler in which the highest ready process runs until it +// // blocks or is preempted by a higher priority process. +// ROUND_ROBIN, // The same as FIFO, except processes at the same priority level time-slice. +// OTHER // A general time sharing scheduler in which a process decays in priority if it +// // consumes too much processor before blocking. It reverts to its default priority +// // when it blocks. Should it fail to run over a 2 second period and it has decayed +// // then it's boosted one priority level up to a maximum of its default priority. +// +Process::eProcessSchedulingPolicy const Process::ConvertFromPosixBasedOS001SchedularPolicy + (const int p_iPosixBasedOS001chedulingPolicy_i) { + eProcessSchedulingPolicy ePolicy = ROUND_ROBIN; // Default is RR + switch (p_iPosixBasedOS001chedulingPolicy_i) { + case SCHED_FIFO: + { + ePolicy = FIFO; + break; + } + + case SCHED_RR: + { + ePolicy = ROUND_ROBIN; + break; + } + case SCHED_OTHER: + { + ePolicy = OTHER; + break; + } + } // Switch + + return ePolicy; +} + + +/** + * DoesProcessExist: This method will return a BOOLean indicating whether this + * process exists. + * + * @return BOOL TRUE - Process Exists, FALSE - Process does not exist + */ +BOOL Process::DoesProcessExist(void) { + struct sched_param cur_sch_params; + if (-1 >= sched_getparam(m_tProcessId, &cur_sch_params)) { // or the segment data + return FALSE; + } + + return TRUE; +} + + + +/** + * SetProcessName: This method will set this objects process name member variable to the + * provided string value. + * + * @param p_strProcessName_i Process Name to set the m_strProcessName member variable to + * @return void + */ +void Process::SetProcessName(const SS_String& p_strProcessName_i) { + // + // Idiot checking + // + assert(!p_strProcessName_i.empty()); + + m_strProcessName = p_strProcessName_i; +} + +/** + * GetSchedulingPolicy: This method will return to the caller the + * currently configured process scheduling policy. + * + * @return Process::eProcessSchedulingPolicy const + */ +Process::eProcessSchedulingPolicy const Process::GetSchedulingPolicy(void) { + int policy = 0; + if (-1 == (policy = sched_getscheduler(m_tProcessId))) { + m_iErrorCode = errno; + return ROUND_ROBIN; // PAD THIS IS BAD!!! TODO: Change this to something meaningful + } + + return (ConvertFromPosixBasedOS001SchedularPolicy (policy)); +} + + + +/** + * GetPriority: This method will return to the caller the currently configured + * process priority. + * + * @return int const + */ +int const Process::GetPriority(void) { + struct sched_param cur_sch_params; + if (-1 >= sched_getparam(m_tProcessId, &cur_sch_params)) { + m_iErrorCode = errno; + return -1; // PAD THIS IS BAD!!! TODO: Change this to something meaningful + } + + return (cur_sch_params.sched_priority); +} + + + +/** + * SetCallingArgumentList: This method will set the calling argument list + * that this object represents. + * + * @param p_pcArgv_i Pointer to NULL terminated argument list. + * @param p_iArgc_i Number of parameters + * @return void + */ +void Process::SetCallingArgumentList(const char *p_pcArgv_i[], const int p_iArgc_i) { + //////////////////////////////////////////////////////////////////////// + // Set the executable filename first. This is always the 1st argument + // in the argument list. Then set the argument list for the process + // which is held in m_strlstArgv. + // + if (p_iArgc_i > (iProcess_MAXIMUM_NUMBER_OF_PROCESS_ARGUMENTS - 3)) { + return; // PAD THIS IS BAD!!! TODO: Change this to something meaningful + } + + // + // First make sure that the argument list is empty. + // + if (!m_strlstArgv.empty()) { + m_strlstArgv.clear(); // Remove all elements from the current list + } // Process Argument list is NOT empty + + // + // Once empty, put the new arguments into the list + // + StringListIter at = m_strlstArgv.begin(); + int iLoop; + for (iLoop = 0; iLoop < p_iArgc_i; iLoop ++) { + at = m_strlstArgv.insert(at, p_pcArgv_i[iLoop]); + } +} + + +/** + * SetCallingArgumentList: This method will set the calling argument + * list that this object represents. + * + * @param p_strlstParameters_i List of parameters + * @return void + */ +void Process::SetCallingArgumentList(const StringList& p_strlstParameters_i) { + if (p_strlstParameters_i.size()) { + m_strlstArgv.clear(); // Empty the current list. + m_strlstArgv = p_strlstParameters_i; + } +} + +/** + * Search if libTestFwCommon.so is dynamically linked. + * + * @param process_path Search target binary path + * @return bool + */ +static bool CheckLinkedTestfwLibrary(SS_String *process_path) { + if (NULL == process_path) { + fprintf(stderr, "[%s](%d)Invaild Param.\n", __func__, __LINE__); + return false; + } + + ELFIO::elfio reader; + if (!reader.load(process_path->c_str())) { + fprintf(stderr, "[%s](%d)%s is not ELF!\n", __func__, __LINE__, process_path->c_str()); + return false; + } + + ELFIO::Elf_Half n = reader.sections.size(); + for ( ELFIO::Elf_Half i = 0; i < n; ++i ) { + ELFIO::section* sec = reader.sections[i]; + if ( SHT_DYNAMIC == sec->get_type() ) { + ELFIO::dynamic_section_accessor dynamic(reader, sec); + + ELFIO::Elf_Xword dynamic_num = dynamic.get_entries_num(); + if ( dynamic_num > 0 ) { + for ( ELFIO::Elf_Xword i = 0; i < dynamic_num; ++i ) { + ELFIO::Elf_Xword dynamic_tag = 0; + ELFIO::Elf_Xword dynamic_value = 0; + SS_String dynamic_str; + dynamic.get_entry(i, dynamic_tag, dynamic_value, dynamic_str); + + // Search if the acquired dynamic section string contains libTestFwCommon.so + if (SS_String::npos != dynamic_str.find("libTestFwCommon.so")) { + fprintf(stderr, "[%s](%d)libTestFwCommon is linked.\n", __func__, __LINE__); + return true; + } + + // Check for continuation of dynamic section element + if ( DT_NULL == dynamic_tag ) { + break; + } + } + } else { + // If dynamic section is not found + fprintf(stderr, "[%s](%d)dynamic symbol is not find.\n", __func__, __LINE__); + } + } + } + + fprintf(stderr, "[%s](%d)libTestFwCommon is not find. \n", __func__, __LINE__); + return false; +} + +/** + * This method is a private method to be called from CreateProcess func. + * Check environment variable MOCK_LIBRARY where Mock Library Name to set in LD_PRELOAD is set + * and output character string to set in LD_PRELOAD if there is setting. + * + * @param process_path,environment_string + * @return void + */ +void Process::CheckLdPreLoad(SS_String *process_path, char *environment_string) { + if ((process_path == NULL || environment_string == NULL)) { + fprintf(stderr, "[%s](%d)Invaild Param.\n", __func__, __LINE__); + return; + } + + // Check if environment variable MOCK_LIBRARY for LD_PRELOAD setting is set + char *value_mock_library = getenv("MOCK_LIBRARY"); + + if (value_mock_library != NULL) { + // When MOCK_LIBRARY is set + fprintf(stderr, "[%s](%d)MOCK_LIBRARY = %s \n", __func__, __LINE__, value_mock_library); + + // Check whether the process to be started is a core unit or TestFW, and execute LD_PRELOAD if libTestFwCommon.so is linked + if (CheckLinkedTestfwLibrary(process_path)) { + SS_String key_value; + SS_String key_ld_preload = "LD_PRELOAD="; + + // Create LD_PRELOAD setting string + // LD_PRELOAD is enabled when the string is an envp argument in the form "LD_PRELOAD=hoge_mock.so hoge_mock.so ..." + key_value = key_ld_preload + value_mock_library; + strncpy(environment_string, key_value.c_str(), key_value.length()); + fprintf(stderr, "[%s](%d)Set envp: %s \n", __func__, __LINE__, environment_string); + return; + } else { + // If the unit does not require LD_PRELOAD setting, set envairoment_string to NULL. + fprintf(stderr, "[%s](%d)Core Unit is not setting LD_PRELOAD\n", __func__, __LINE__); + return; + } + } else { + // If it is not set to MOCK_LIBRARY, it is not necessary to set LD_PRELOAD, so set envairoment_string to NULL. + fprintf(stderr, "[%s](%d)The MOCK_LIBRARY variable was unestablished.\n", __func__, __LINE__); + return; + } +} + +/** + * Acquire the character string of the environment variable and set it in String Vector + * and return in a pointer of Vector. + * + * @param process_path,environment_string + * @return vector<SS_String> pointer + */ +extern char ** environ; +std::vector<SS_String> *Process::GetEnvironVector(void) { + // If LD_PRELOAD is set, copy existing environment settings and set to environment_pointer + + std::vector<SS_String>* vector_environ = new std::vector<SS_String>; + + char **environ_tmp = environ; + + // Insert environ_string into the vector table + int i = 0; + while (environ_tmp[i] != NULL) { + SS_String str_env(environ_tmp[i]); + vector_environ->push_back(str_env); + i++; + } + + return vector_environ; +} +// ---------------------------------------- diff --git a/systemservice/interface_unified/library/src/ss_system_timer.cpp b/systemservice/interface_unified/library/src/ss_system_timer.cpp new file mode 100755 index 0000000..24209fb --- /dev/null +++ b/systemservice/interface_unified/library/src/ss_system_timer.cpp @@ -0,0 +1,228 @@ +/* + * @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_SystemManagerIf +/// \brief This file provides support for the System Manager client interface. +/// +/////////////////////////////////////////////////////////////////////////////// + +#include "system_service/ss_system_timer.h" +#include <native_service/ns_timer_if.h> +#include <native_service/ns_message_center_if.h> +#include <utility> +#include "ss_system_timer_local.h" + +Timer::Timer() : + m_bInit(FALSE), m_hApp(NULL), m_hSnd(NULL), m_hTmr(NULL) { + bzero(&m_tTi, sizeof(m_tTi)); +} + +Timer::Timer(HANDLE hdl, UI_32 id, CbFuncPtr CbFn): + m_bInit(FALSE), m_hApp(NULL), m_hSnd(NULL), m_hTmr(NULL) { + bzero(&m_tTi, sizeof(m_tTi)); + Initialize(hdl, id, CbFn); +} + +Timer::~Timer() { + if (m_bInit) { + Shutdown(); + } +} // LCOV_EXCL_BR_LINE 10:Because destructor + +BOOL Timer::Initialize(HANDLE hApp, UI_32 id, CbFuncPtr CbFn) { + if (!m_bInit && hApp && id && CbFn) { + m_hApp = hApp; + m_tTi.iCmd = id; + m_tTi.t_sec = 0; + m_tTi.t_nsec = 0; + m_tTi.rpt_sec = 0; + m_tTi.rpt_nsec = 0; + m_CbFn = CbFn; + m_hSnd = McOpenSender(FrameworkunifiedGetAppName(m_hApp)); + m_hTmr = NS_TimerCreate(m_tTi, CALLBACK_MESSAGE, m_hSnd); + m_bInit = TRUE; + } + return m_bInit; +} + +void Timer::Reinitialize(UI_32 id) { + if (!m_bInit && id) { + m_tTi.iCmd = id; + + m_tTi.t_sec = 0; + m_tTi.t_nsec = 0; + m_tTi.rpt_sec = 0; + m_tTi.rpt_nsec = 0; + + m_hSnd = McOpenSender(FrameworkunifiedGetAppName(m_hApp)); + m_hTmr = NS_TimerCreate(m_tTi, CALLBACK_MESSAGE, m_hSnd); + m_bInit = TRUE; + } + return; +} + +void Timer::Shutdown() { + if (m_bInit) { + Stop(); + NS_TimerDelete(m_hTmr); + m_hTmr = NULL; + McClose(m_hSnd); + m_hSnd = NULL; + m_bInit = FALSE; + } +} + +BOOL Timer::SetTime(UI_32 ss, UI_32 sms, UI_32 rs, UI_32 rms) { + if (m_bInit) { + m_tTi.t_sec = ss; + m_tTi.t_nsec = (ss || sms) ? sms*NS_PER_MS : 1; // LCOV_EXCL_BR_LINE 11:Unexpected branch + m_tTi.rpt_sec = rs; + m_tTi.rpt_nsec = rms*NS_PER_MS; + } + return m_bInit; +} + +BOOL Timer::Start(UI_32 ss, UI_32 sms, UI_32 rs, UI_32 rms) { + if (m_bInit) { + SetTime(ss, sms, rs, rms); + FrameworkunifiedAttachCallbackToDispatcher(m_hApp, TIMER_SERVICE_NAME, m_tTi.iCmd, m_CbFn); + NS_TimerSetTime(m_hTmr, m_tTi); + } + return m_bInit; +} + +BOOL Timer::Start() { + if (m_bInit) { + FrameworkunifiedAttachCallbackToDispatcher(m_hApp, TIMER_SERVICE_NAME, m_tTi.iCmd, m_CbFn); + m_tTi.t_nsec = (m_tTi.t_sec || m_tTi.t_nsec) ? m_tTi.t_nsec : 1; // LCOV_EXCL_BR_LINE 11:Unexpected branch + NS_TimerSetTime(m_hTmr, m_tTi); + } + return m_bInit; +} + +BOOL Timer::Stop() { + if (m_bInit) { + NSTimerInfo ti = m_tTi; + ti.t_sec = 0; + ti.t_nsec = 0; + ti.rpt_sec = 0; + ti.rpt_nsec = 0; + NS_TimerSetTime(m_hTmr, ti); + FrameworkunifiedDetachCallbackFromDispatcher(m_hApp, TIMER_SERVICE_NAME, ti.iCmd); + } + return m_bInit; +} + +// LCOV_EXCL_START 6:Because the condition cannot be set +TimerCtrl::TimerCtrl() + : m_hApp(NULL), m_nTimersMax(DEFAULT_NTIMERS) { +} + +TimerCtrl::TimerCtrl(UI_32 ntimers) + : m_hApp(NULL), m_nTimersMax(ntimers) { +} + +void TimerCtrl::Initialize(HANDLE hApp) { + if ( NULL != hApp ) { + m_hApp = hApp; + if (m_aTimers.empty() && m_rTimers.empty()) { + for (UI_32 i = DEFAULT_TIMERID; i < DEFAULT_TIMERID+m_nTimersMax; ++i) { + m_aTimers.push_back(i); + } + } + } +} + +void TimerCtrl::Shutdown() { + m_aTimers.clear(); + while (m_rTimers.begin() != m_rTimers.end()) { + Timer* p_timer = m_rTimers.begin()->second; + p_timer->Shutdown(); + delete p_timer; + m_rTimers.erase(m_rTimers.begin()); + } +} + +UI_32 TimerCtrl::CreateTimer(CbFuncPtr CbFn) { + if (!m_aTimers.empty()) { + UI_32 id = m_aTimers.front(); + m_aTimers.pop_front(); + Timer* p_timer = new Timer(m_hApp, id, CbFn); + m_rTimers.insert(std::pair<UI_32, Timer*>(id, p_timer)); + return id; + } + return 0; +} + +UI_32 TimerCtrl::DeleteTimer(UI_32 id) { + if (m_rTimers.find(id) != m_rTimers.end()) { + Timer* p_timer = m_rTimers.find(id)->second; + p_timer->Shutdown(); + delete p_timer; + m_rTimers.erase(m_rTimers.find(id)); + m_aTimers.push_back(id); + return id; + } + return 0; +} + +UI_32 TimerCtrl::SetTimer(UI_32 id, UI_32 ss, UI_32 sms, UI_32 rs, UI_32 rms) { + if (m_rTimers.find(id) != m_rTimers.end()) { + Timer* p_timer = m_rTimers.find(id)->second; + p_timer->SetTime(ss, sms, rs, rms); + return id; + } + return 0; +} +UI_32 TimerCtrl::StartTimer(UI_32 id, UI_32 ss, UI_32 sms, UI_32 rs, UI_32 rms) { + if (m_rTimers.find(id) != m_rTimers.end()) { + Timer* p_timer = m_rTimers.find(id)->second; + p_timer->Start(ss, sms, rs, rms); + return id; + } + return 0; +} + +UI_32 TimerCtrl::StartTimerMulti(UI_32 id, UI_32 ss, UI_32 sms, UI_32 rs, UI_32 rms, UI_32 subId) { + if (m_rTimers.find(id) != m_rTimers.end()) { + Timer* p_timer = m_rTimers.find(id)->second; + p_timer->Shutdown(); + p_timer->Reinitialize(id + subId); + p_timer->Start(ss, sms, rs, rms); + return id; + } + return 0; +} + +UI_32 TimerCtrl::StartTimer(UI_32 id) { + if (m_rTimers.find(id) != m_rTimers.end()) { + Timer* p_timer = m_rTimers.find(id)->second; + p_timer->Start(); + return id; + } + return 0; +} + +UI_32 TimerCtrl::StopTimer(UI_32 id) { + if (m_rTimers.find(id) != m_rTimers.end()) { + Timer* p_timer = m_rTimers.find(id)->second; + p_timer->Stop(); + return id; + } + return 0; +} +// LCOV_EXCL_STOP |