diff options
Diffstat (limited to 'systemservice/logger_service/server/src')
30 files changed, 10787 insertions, 0 deletions
diff --git a/systemservice/logger_service/server/src/cached_file_writer.cpp b/systemservice/logger_service/server/src/cached_file_writer.cpp new file mode 100755 index 0000000..92c02f5 --- /dev/null +++ b/systemservice/logger_service/server/src/cached_file_writer.cpp @@ -0,0 +1,79 @@ +/* + * @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_SS_LoggerService +/// \brief TODO +/// +/////////////////////////////////////////////////////////////////////////////// +#include "readerWriter/writer/cached_file_writer.h" +#include <native_service/frameworkunified_types.h> + +namespace ReaderWriter { + +CCachedFileWriter::CCachedFileWriter() { + std::memset(this->m_buffer, 0, CACHED_BLOCK_SIZE); + m_index = 0u; +} + +CCachedFileWriter::~CCachedFileWriter() { +} + +EFrameworkunifiedStatus CCachedFileWriter::Write(UI_8* f_data, UI_32 f_length, + SI_32& f_bytesWritten) { + EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK; + // length check + if (f_data != NULL) { // LCOV_EXCL_BR_LINE 200: f_data can not be null + if ((this->m_index + f_length) > CACHED_BLOCK_SIZE) { // LCOV_EXCL_BR_LINE 200: data size can not over 4*1024 + l_eStatus = this->FlushCache(); + } + if (f_length > CACHED_BLOCK_SIZE) { // LCOV_EXCL_BR_LINE 200: data size can not over 4*1024 + // LCOV_EXCL_START 200: data size can not over 4*1024 + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, " Error. Possible memory corruption."); + FRAMEWORKUNIFIEDLOG( + ZONE_ERR, + __FUNCTION__, + " Error. Length(%d) bigger than cache. Will dump memory to core and ignore data. ", + f_length); + // LCOV_EXCL_STOP + } else { + (void) std::memcpy(&this->m_buffer[this->m_index], f_data, f_length); + this->m_index += f_length; + f_bytesWritten = f_length; + } + } else { + l_eStatus = eFrameworkunifiedStatusFail; + } + + return (l_eStatus); +} + +EFrameworkunifiedStatus CCachedFileWriter::FlushCache(void) { + EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK; + SI_32 l_written = 0; + SI_32 l_writtenTotal = 0; + while (((l_writtenTotal >= 0) && ((UI_32) l_writtenTotal < this->m_index)) + && (eFrameworkunifiedStatusOK == l_eStatus)) { + l_eStatus = this->WriteData(&this->m_buffer[l_writtenTotal], + this->m_index - l_writtenTotal, l_written); + l_writtenTotal += l_written; + l_written = 0; + } + this->m_index = 0; + return l_eStatus; +} +} // namespace ReaderWriter diff --git a/systemservice/logger_service/server/src/file_writer.cpp b/systemservice/logger_service/server/src/file_writer.cpp new file mode 100755 index 0000000..221a1d4 --- /dev/null +++ b/systemservice/logger_service/server/src/file_writer.cpp @@ -0,0 +1,122 @@ +/* + * @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_SS_LoggerService +/// \brief TODO +/// +/////////////////////////////////////////////////////////////////////////////// +#include "readerWriter/writer/file_writer.h" +#include <sys/types.h> +#include <sys/stat.h> +#include <fcntl.h> +#include <string> + +namespace ReaderWriter { +CFileWriter::CFileWriter() + : m_FileHandle(-1), + m_fileposn(-1), + m_maxFileSize(0) { +} + +CFileWriter::~CFileWriter() { + if (this->m_FileHandle != -1) { // LCOV_EXCL_BR_LINE 200: it aways open, so m_FileHandle can not be -1 + this->Close(); + this->m_FileHandle = -1; + } +} + +EFrameworkunifiedStatus CFileWriter::Initialize(CLoggerCfg* f_pLoggerCfg, + std::string f_Name1, UI_32 f_size1, + std::string f_Name2, UI_32 f_size2) { + EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusFail; + this->m_pLoggerCfg = f_pLoggerCfg; + this->m_maxFileSize = f_size1; + if ((f_Name1.length() != 0) && (this->m_FileHandle == -1)) { // LCOV_EXCL_BR_LINE 6:Due to the initial status + m_filename = f_Name1; + l_eStatus = this->Open(); + } + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-: %d", l_eStatus); + return (l_eStatus); +} + +EFrameworkunifiedStatus CFileWriter::Open(void) { + EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusFail; + if (this->m_FileHandle != -1) { // LCOV_EXCL_BR_LINE 6:Due to the initial status + // File already opened, no action required. + l_eStatus = eFrameworkunifiedStatusOK; + } else if (m_filename.length() != 0) { // LCOV_EXCL_BR_LINE 6:Because the applicable variable cannot be changed from the external API + this->m_FileHandle = open(m_filename.c_str(), + O_WRONLY | O_CREAT | O_TRUNC, + 0644); + if (-1 != this->m_FileHandle) { // LCOV_EXCL_BR_LINE 5:The open cannot pass because it cannot be mock + l_eStatus = eFrameworkunifiedStatusOK; + m_fileposn = lseek(m_FileHandle, 0L, SEEK_CUR); + } + } + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-: %d", l_eStatus); + return (l_eStatus); +} + +BOOL CFileWriter::IsOpen(void) { + return (-1 == m_FileHandle) ? FALSE : TRUE; +} + +EFrameworkunifiedStatus CFileWriter::Write(UI_8* f_data, UI_32 f_length, + SI_32& f_bytesWritten) { + return (this->WriteData(f_data, f_length, f_bytesWritten)); +} + +EFrameworkunifiedStatus CFileWriter::WriteData(UI_8* f_data, UI_32 f_length, + SI_32& f_bytesWritten) { + EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK; + f_bytesWritten = 0; + if (-1 == m_FileHandle) { // LCOV_EXCL_BR_LINE 200: m_FileHandle can not be null + l_eStatus = eFrameworkunifiedStatusFail; + } + + while ((eFrameworkunifiedStatusOK == l_eStatus) + && ((f_bytesWritten >= 0) && ((UI_32) f_bytesWritten < f_length))) { + SI_32 l_bytesWritten = -1; + m_fileposn = lseek(m_FileHandle, 0L, SEEK_CUR); + if ((m_fileposn + (UI_32) f_length) >= this->m_maxFileSize) { + SI_32 l_deltaLength = static_cast<SI_32>(this->m_maxFileSize - m_fileposn); + l_bytesWritten = static_cast<SI_32>(write(m_FileHandle, &f_data[f_bytesWritten], + l_deltaLength)); + f_bytesWritten += l_bytesWritten; + if ((l_bytesWritten >= 0) && (l_deltaLength == l_bytesWritten)) { + m_fileposn = lseek(m_FileHandle, 0L, SEEK_SET); + } + } else { + l_bytesWritten = static_cast<SI_32>(write(m_FileHandle, &f_data[f_bytesWritten], + f_length - f_bytesWritten)); + f_bytesWritten += l_bytesWritten; + } + l_eStatus = (l_bytesWritten > -1) ? eFrameworkunifiedStatusOK : eFrameworkunifiedStatusFail; + } + + return (l_eStatus); +} + +void CFileWriter::Close() { // LCOV_EXCL_START 6:Because the condition cannot be set + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + if (this->m_FileHandle != -1) { + (void) close(this->m_FileHandle); + this->m_FileHandle = -1; + } +} +// LCOV_EXCL_STOP +} // namespace ReaderWriter diff --git a/systemservice/logger_service/server/src/loggerservice_application.cpp b/systemservice/logger_service/server/src/loggerservice_application.cpp new file mode 100755 index 0000000..2d39fb2 --- /dev/null +++ b/systemservice/logger_service/server/src/loggerservice_application.cpp @@ -0,0 +1,952 @@ +/* + * @copyright Copyright (c) 2016-2020 TOYOTA MOTOR CORPORATION. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/////////////////////////////////////////////////////////////////////////////// +/// \ingroup tag_NS_InterfaceunifiedLogCapture +/// \brief This file contains the standard set functions called by the NS +// dispatcher on application initialization, cleanup and wakeup. +/// +/////////////////////////////////////////////////////////////////////////////// +// System Headers +#include <sys/types.h> +#include <sys/wait.h> +#include <sys/stat.h> +#include <unistd.h> +#include <fcntl.h> +#include <native_service/frameworkunified_application.h> +#include <native_service/frameworkunified_framework_if.h> +#include <native_service/frameworkunified_service_protocol.h> +#include <native_service/frameworkunified_types.h> +#include <native_service/cl_process.h> + +#include <native_service/nslogutil_cmd_if.h> +#include <native_service/ns_np_service.h> +#include <native_service/ns_np_service_protocol.h> + +#include <loggerservicedebug_loggerservicelog.h> +#include <loggerservicedebug_thread_if.h> +#include <loggerservicedebug_writer_Evntworker.h> + +#include <native_service/frameworkunified_timer.h> +#include <ss_logger_device_detection.h> + +#include <ss_logger_cfg.h> +#include <system_service/ss_logger_service_notifications.h> +#include <system_service/ss_logger_service.h> +#include <ss_logger_service_callbacks.h> + +#include <system_service/ss_sm_client_if.h> + +#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_devicedetection_service_notifications.h> +#include <system_service/ss_devicedetection_service_ifc.h> +#include <system_service/ss_services.h> +#include <ss_logger_error_event.h> +#include <ss_logger_reader_writer_control.h> +#include <ss_logger_common.h> +#include <stub/pfdrec_thread_ifc.h> +#include <system_service/ss_templates.h> +#include <system_service/ss_logger_store_logs.h> +#include <queue> +#include <string> + +// const definitions +#define TMPFS_PATH "/tmp" + +#define SYS_ILLEGAL_LOG_DELAY_TIME ( 20 * 1000 ) +const CHAR LOGGERSERVICELOGGER_SETPARAMS[] = TMPFS_PATH "/loggerservicelogger_setparams.log"; +const CHAR Counter_LOG_PATH_FN[] = TMPFS_PATH "/loggerservice_counter.log"; +const CHAR Mileage_LOG_PATH_FN[] = TMPFS_PATH "/loggerservice_mileage.log"; + +const CHAR g_strLogQueWriterWorkerName[] = "pdg.LogQueWriter"; +const CHAR g_strTransmitQueWriterWorkerName[] = "pdg.TransmitQueWriter"; +const CHAR g_strUdpQueWriterWorkerName[] = "pdg.UdpQueWriter"; +const CHAR g_strEvntLogQueWorkerName[] = "pdg.EvntLogQue"; + +// handles to writer threads +static HANDLE g_thrdLogWriter = NULL; // Var. that holds the child handle to the Log Writer thread +static HANDLE g_thrdTxWriter = NULL; // Var. that holds the child handle to the Tx Writer thread + +/// Event_logger +HANDLE g_thrdEvntLogWriter = NULL; // Var. that holds the child handle to the EVNTLOGGER Writer thread +static TEvntWriterInfo Evntlog_wi = { }; +TUploadEventLogResp g_stUploadEventLogResp; + +// global variable to store the service status +ELOGGERSERVICESTATUS g_eLoggerServiceStatus = eLSInit; + +// class to usb and reader threads +LoggerserviceDebugChildThread g_loggerservicedebug_threads; + +/// Device Detection Class Instance +DeviceDetectionServiceIf g_devDetect_t; + +CLoggerCfg g_loggerCfg; +CErrorEvent g_errorEventHandler; +CLoggerServiceCallbacks g_serviceCallbacks; +CLoggerDeviceDetection g_deviceDetection; +CReaderWriterControl g_ReaderWriterControl; +CPFDRECThread g_PFDRECThread; + +/// Decide the function NormalStartupProcess execution +static bool g_normal_startup_status = false; + +/// Callbacks for messages that will be received and processed by this module +static EFrameworkunifiedStatus OnUsbEject(HANDLE hApp); + +static EFrameworkunifiedStatus OnUsbStoreLogs(HANDLE hApp); + +static EFrameworkunifiedStatus SMSessionAckCb(HANDLE hApp); + +/// Positive Response Call backs from child thread for statistical counter read +static EFrameworkunifiedStatus cbStatisticalCounterSuccessResp(HANDLE hApp); + +/// Error Response Call backs from child thread for statistical counter read +static EFrameworkunifiedStatus cbStatisticalCounterErrorResp(HANDLE hApp); + +/// Response Call backs from child thread for clear event logs +static EFrameworkunifiedStatus cbClearEventLogsResponse(HANDLE hApp); + +/// Response Call backs from child thread for copying event logs to USB +static EFrameworkunifiedStatus cbCopyEventLogsUSBResponse(HANDLE hApp); + +/// Response Call backs from child thread for Reading number of events logged +static EFrameworkunifiedStatus cbReadNumbOfEventsResponse(HANDLE hApp); + +/// Response Call backs from child thread for Upload eventlog +static EFrameworkunifiedStatus cbUploadEventLogResponse(HANDLE hApp); + +/// Notificatin from SystemManager when All Services wakeup completed +static EFrameworkunifiedStatus cbServiceWakeupStatus(HANDLE hApp); + + +/// generate SYS_ILG_LOG +static EFrameworkunifiedStatus SysIllegalLogTimer_OnInterval(HANDLE hApp); + + +/// Call back tables for response from event logger child thread +FrameworkunifiedProtocolCallbackHandler evtLogChildThread_handler[] = { { // LCOV_EXCL_BR_LINE 11:Unexpected branch + eThrdCmdStatisticalCounterSuccessResp, cbStatisticalCounterSuccessResp }, { + eThrdCmdStatisticalCounterErrorResp, cbStatisticalCounterErrorResp }, { + eThrdCmdCopyEventLogUSBResponse, cbCopyEventLogsUSBResponse }, { + eThrdCmdClearEventLogResponse, cbClearEventLogsResponse }, { + eThrdCmdNumberOfEventsLoggedResponse, cbReadNumbOfEventsResponse }, { + eThrdCmdUploadEventLogResponse, cbUploadEventLogResponse } }; + +////////////////////////////////////////// +// Function : FrameworkunifiedOnInitialization +////////////////////////////////////////// +EFrameworkunifiedStatus FrameworkunifiedOnInitialization(HANDLE hApp) { + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+"); + EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK; + + // 1. Register Srv Availability Notification + if (eFrameworkunifiedStatusOK != (l_eStatus = FrameworkunifiedRegisterServiceAvailabilityNotification(hApp, NTFY_SS_LoggerService_Availability))) { // LCOV_EXCL_BR_LINE 4:NSFW // NOLINT[whitespace/line_length] + // LCOV_EXCL_START 4:NSFW + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, + "Failed to set service availability notification:0x%x ", l_eStatus); + // LCOV_EXCL_STOP + } + + // 2. Publish Service not available + if (eFrameworkunifiedStatusOK != (l_eStatus = FrameworkunifiedPublishServiceAvailability(hApp, FALSE))) { // LCOV_EXCL_BR_LINE 4:NSFW // NOLINT[whitespace/line_length] + // LCOV_EXCL_START 4:NSFW + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, + "Failed to set service availability notification:%d ", l_eStatus); + // LCOV_EXCL_STOP + } + + l_eStatus = g_loggerCfg.Initialize(hApp); + LOG_STATUS_IF_ERRORED(l_eStatus, "g_loggerCfg.Initialize()"); // LCOV_EXCL_BR_LINE 15: macro + + std::string l_cfgFilePathAndName = + "/usr/agl/conf/BS/ss/logger_service/rodata/ss_logger.cfg"; + if (eFrameworkunifiedStatusOK != (l_eStatus = g_loggerCfg.Load(l_cfgFilePathAndName))) { // LCOV_EXCL_BR_LINE 200:To ensure success + // LCOV_EXCL_START 200:To ensure success + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + FRAMEWORKUNIFIEDLOG( + ZONE_ERR, __FUNCTION__, + " Error. Failed to load SS_Logger configuration from %s with error: %d", + l_cfgFilePathAndName.c_str(), l_eStatus); + // LCOV_EXCL_STOP + } else if (eFrameworkunifiedStatusOK != (l_eStatus = g_loggerCfg.Validate())) { + FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, + " Error. Configuration validation failed with error: %d.", + l_eStatus); + } + + g_loggerCfg.Print(); // LCOV_EXCL_BR_LINE 11:Unexpected branch + + l_eStatus = g_deviceDetection.Initialize(hApp, &g_loggerCfg); // LCOV_EXCL_BR_LINE 11:Unexpected branch + LOG_STATUS_IF_ERRORED(l_eStatus, "g_deviceDetection.Initialize"); // LCOV_EXCL_BR_LINE 15: macro + + l_eStatus = g_ReaderWriterControl.Initialize(&g_loggerCfg); // LCOV_EXCL_BR_LINE 11:Unexpected branch + LOG_STATUS_IF_ERRORED(l_eStatus, "g_ReaderWriterControl.Initialize()"); // LCOV_EXCL_BR_LINE 15: macro + + if (NULL == (g_thrdEvntLogWriter = FrameworkunifiedCreateChildThreadWithPriority( hApp, g_strEvntLogQueWorkerName, EvntWriterWorkerOnStart, EvntWriterWorkerOnStop, frameworkunified::framework::CFrameworkunifiedThreadPriorities::GetPriority(std::string(g_strEvntLogQueWorkerName))))) { // LCOV_EXCL_BR_LINE 4:NSFW // NOLINT[whitespace/line_length] + // LCOV_EXCL_START 4:NSFW + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + FRAMEWORKUNIFIEDLOG( + ZONE_ERR, + __FUNCTION__, + "FrameworkunifiedCreateChildThreadWithPriority Failed Status:0x%x for thread create of %s", + l_eStatus, g_strEvntLogQueWorkerName); + return (l_eStatus); + // LCOV_EXCL_STOP + } else { + FRAMEWORKUNIFIEDLOG( // LCOV_EXCL_BR_LINE 15: macro + ZONE_INFO, + __FUNCTION__, + "FrameworkunifiedCreateChildThreadWithPriority Success Status: for thread create of %s", + g_strEvntLogQueWorkerName); // LCOV_EXCL_BR_LINE 15: macro + } + + l_eStatus = g_errorEventHandler.Initialize(hApp, &g_loggerCfg, // LCOV_EXCL_BR_LINE 11:Unexpected branch + &g_ReaderWriterControl, + g_thrdEvntLogWriter, + g_strEvntLogQueWorkerName); // LCOV_EXCL_BR_LINE 11:Unexpected branch + if (eFrameworkunifiedStatusOK != l_eStatus) { // LCOV_EXCL_BR_LINE 200:To ensure success + // LCOV_EXCL_START 200:To ensure success + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, + " Error. g_errorEventHandler.Initialize() returned: %d.", l_eStatus); + // LCOV_EXCL_STOP + } + l_eStatus = g_serviceCallbacks.Initialize(hApp, &g_loggerCfg, + &g_errorEventHandler); // LCOV_EXCL_BR_LINE 11:Unexpected branch + LOG_STATUS_IF_ERRORED(l_eStatus, "g_serviceCallbacks.Initialize()"); // LCOV_EXCL_BR_LINE 15: macro + + // Callback to Event log child Thread + l_eStatus = FrameworkunifiedAttachCallbacksToDispatcher( + hApp, g_strEvntLogQueWorkerName, evtLogChildThread_handler, + _countof(evtLogChildThread_handler)); // LCOV_EXCL_BR_LINE 11:Unexpected branch + FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__, // LCOV_EXCL_BR_LINE 15: macro + "Status of callback for child thread attach:%X", l_eStatus); // LCOV_EXCL_BR_LINE 15: macro + + // setup call backs for my children + FrameworkunifiedAttachCallbackToDispatcher(hApp, AppName, eThrdCmdUsbEject, OnUsbEject); // LCOV_EXCL_BR_LINE 11:Unexpected branch + FrameworkunifiedAttachCallbackToDispatcher(hApp, AppName, eThrdCmdUsbStoreLogs, + OnUsbStoreLogs); + + // Publications + FrameworkunifiedNotificationsList publish_notifs[] = { + // Notifications name,length, state + { NTFY_LOGGER_SETCONTROLMASK, sizeof(CHANGELOGPARAMS), eFrameworkunifiedStateVar } }; + + // Indicate to Notification Service what I will be Publishing! + if (eFrameworkunifiedStatusOK != (l_eStatus = FrameworkunifiedNPRegisterNotifications(hApp, publish_notifs, _countof(publish_notifs)))) { // LCOV_EXCL_BR_LINE 4:NSFW // NOLINT[whitespace/line_length] + // LCOV_EXCL_START 4:NSFW + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, + "FrameworkunifiedNPRegisterNotifications Failed Status:0x%x ", l_eStatus); + return (l_eStatus); + // LCOV_EXCL_STOP + } + + /// Start the Writer threads + strncpy(Evntlog_wi.mileage_filename, Mileage_LOG_PATH_FN, + Evntlog_wi.FN_LEN - 1); + Evntlog_wi.mileage_filename[Evntlog_wi.FN_LEN - 1] = '\0'; + strncpy(Evntlog_wi.base_cnt_filename, Counter_LOG_PATH_FN, + Evntlog_wi.FN_LEN - 1); + Evntlog_wi.base_cnt_filename[Evntlog_wi.FN_LEN - 1] = '\0'; + Evntlog_wi.max_filelen = g_loggerCfg.m_logMaxFileSize; + + if (eFrameworkunifiedStatusOK != (l_eStatus = FrameworkunifiedStartChildThread(hApp, g_thrdEvntLogWriter, sizeof(Evntlog_wi), &Evntlog_wi))) { // LCOV_EXCL_BR_LINE 4:NSFW // NOLINT[whitespace/line_length] + // LCOV_EXCL_START 4:NSFW + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + FRAMEWORKUNIFIEDLOG(ZONE_ERR, __PRETTY_FUNCTION__, + "Fail to Start Writer Worker thread. Status:0x%x", l_eStatus); + // LCOV_EXCL_STOP + } + + l_eStatus = RegisterSMSessionAckCallback(SMSessionAckCb); // LCOV_EXCL_BR_LINE 11:Unexpected branch + LOG_STATUS_IF_ERRORED(l_eStatus, "RegisterSMSessionAckCallback()"); // LCOV_EXCL_BR_LINE 15: macro + + l_eStatus = g_PFDRECThread.Initialize(hApp); // LCOV_EXCL_BR_LINE 11:Unexpected branch + LOG_STATUS_IF_ERRORED(l_eStatus, "g_PFDRECThread.Initialize()"); // LCOV_EXCL_BR_LINE 15: macro + + // Publish Service available this can also be published from FrameworkunifiedOnStart callback + if (eFrameworkunifiedStatusOK != (l_eStatus = FrameworkunifiedPublishServiceAvailability(hApp, TRUE))) { // LCOV_EXCL_BR_LINE 4:NSFW + // LCOV_EXCL_START 4:NSFW + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, + "Failed to set service availability notification:0x%x ", l_eStatus); + // LCOV_EXCL_STOP + } + +l_eStatus = FrameworkunifiedSubscribeNotificationWithCallback(hApp, NTFY_SSServiceWakeupStatus, cbServiceWakeupStatus); // LCOV_EXCL_BR_LINE 11:Unexpected branch + LOG_STATUS_IF_ERRORED(l_eStatus, "FrameworkunifiedSubscribeNotificationWithCallback()"); // LCOV_EXCL_BR_LINE 15: macro + + // Set Service status to init + g_eLoggerServiceStatus = eLSInit; + + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-"); + return (l_eStatus); +} + +static void *accOffOnCollect(void* param) { + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+"); + SS_LoggerStoreLogs(SS_STORELOGS_ACCOFFON_PRESS); + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-"); + return NULL; +} + +// Normal startup process +static EFrameworkunifiedStatus NormalStartupProcess(HANDLE hApp) { + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+"); + + EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK; + + if (false == g_normal_startup_status) { + T_SS_SM_START_DataStructType prm; + + l_eStatus = FrameworkunifiedGetMsgDataOfSize(hApp, &prm, sizeof(T_SS_SM_START_DataStructType), eSMRRetain); + if (eFrameworkunifiedStatusOK != l_eStatus) { + FRAMEWORKUNIFIEDLOG(ZONE_ERR, __PRETTY_FUNCTION__, "Failed PasGetMsgDataOfSize() [%d]", l_eStatus); + } + + if (prm.resetStatus == e_SS_SM_RESET_STATUS_NG) { + HANDLE timer = + FrameworkunifiedAttachTimerCallback(hApp, SYS_ILLEGAL_LOG_DELAY_TIME, 0, SysIllegalLogTimer_OnInterval); + if (timer == NULL) { + FRAMEWORKUNIFIEDLOG(ZONE_ERR, __PRETTY_FUNCTION__, " Failed to register timer."); + } + } + + if (0 == access("/tmp/accoffon", F_OK)) { + pthread_t threadAccOffOn; + pthread_create( &threadAccOffOn, NULL, accOffOnCollect, NULL); + } + + if (g_eLoggerServiceStatus == eLSStop) { + // Publish Service available this can also be published from FrameworkunifiedOnStart callback + if (eFrameworkunifiedStatusOK + != (l_eStatus = FrameworkunifiedPublishServiceAvailability(hApp, TRUE))) { + FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, + "Failed to set service availability notification:0x%x ", + l_eStatus); + } + + // Start the Writer threads + if (eFrameworkunifiedStatusOK + != (l_eStatus = FrameworkunifiedStartChildThread(hApp, g_thrdEvntLogWriter, + sizeof(Evntlog_wi), &Evntlog_wi))) { + FRAMEWORKUNIFIEDLOG(ZONE_ERR, __PRETTY_FUNCTION__, + "Fail to Start Writer Worker thread. Status:0x%x", l_eStatus); + } + } + // Set Service status to init + g_eLoggerServiceStatus = eLSStart; + + // Set normal_startup_status flag (true) + g_normal_startup_status = true; + } + + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-"); + return l_eStatus; +} + +/** + * EFrameworkunifiedStatus FrameworkunifiedOnPreStart(HANDLE hApp) + * @brief Used to . + * + * @param hApp Handle to the SS_Power Framework Obj. + * + * @return method status of completion or failure. + */ +EFrameworkunifiedStatus FrameworkunifiedOnPreStart(HANDLE hApp) { + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+"); + + EFrameworkunifiedStatus l_eStatus = NormalStartupProcess(hApp); + + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-"); + return l_eStatus; +} + +/** + * EFrameworkunifiedStatus FrameworkunifiedOnBackgroundStart(HANDLE hApp) + * @brief Used to . + * + * @param hApp Handle to the SS_Power Framework Obj. + * + * @return method status of completion or failure. + */ +EFrameworkunifiedStatus FrameworkunifiedOnBackgroundStart(HANDLE hApp) { + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+"); + + EFrameworkunifiedStatus l_eStatus = NormalStartupProcess(hApp); + + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-"); + return l_eStatus; +} + +/** + * EFrameworkunifiedStatus FrameworkunifiedOnStart(HANDLE hApp) + * @brief Used to . + * + * @param hApp Handle to the SS_Power Framework Obj. + * + * @return method status of completion or failure. + */ +EFrameworkunifiedStatus FrameworkunifiedOnStart(HANDLE hApp) { + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+"); + + EFrameworkunifiedStatus l_eStatus = NormalStartupProcess(hApp); + + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-"); + return l_eStatus; +} + +static EFrameworkunifiedStatus SysIllegalLogTimer_OnInterval(HANDLE hApp) { // LCOV_EXCL_START 200: There is no SUBCP_STS_COMNG case + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+"); + EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK; + l_eStatus = SS_LoggerStoreLogs(SS_STORELOGS_SYS_ILLEGAL); + if (l_eStatus != eFrameworkunifiedStatusOK) { + FRAMEWORKUNIFIEDLOG(ZONE_ERR, __PRETTY_FUNCTION__, " Failed SS_LoggerStoreLogs()"); + } + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-"); + return l_eStatus; +} +// LCOV_EXCL_STOP + +/** + * EFrameworkunifiedStatus FrameworkunifiedOnPreStop(HANDLE hApp) + * @brief Used to . + * + * @param hApp Handle to the SS_Power Framework Obj. + * + * @return method status of completion. + */ +EFrameworkunifiedStatus FrameworkunifiedOnPreStop(HANDLE hApp) { + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+"); + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-"); + return eFrameworkunifiedStatusOK; +} + +/** + * EFrameworkunifiedStatus FrameworkunifiedOnBackgroundStop(HANDLE hApp) + * @brief Used to . + * + * @param hApp Handle to the SS_Power Framework Obj. + * + * @return method status of completion. + */ +EFrameworkunifiedStatus FrameworkunifiedOnBackgroundStop(HANDLE hApp) { + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+"); + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-"); + return eFrameworkunifiedStatusOK; +} + +/** + * EFrameworkunifiedStatus FrameworkunifiedOnStop(HANDLE hApp) + * @brief Used to . + * + * @param hApp Handle to the SS_Power Framework Obj. + * + * @return method status of completion or failure. + */ +EFrameworkunifiedStatus FrameworkunifiedOnStop(HANDLE hApp) { + EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK; + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+"); + + /*Get stop factor form hApp*/ + T_SS_SM_STOP_DataStructType errorType; + + // LCOV_EXCL_BR_START 4: NSFW error + if (eFrameworkunifiedStatusOK + != FrameworkunifiedGetMsgDataOfSize(hApp, (PVOID) &errorType, sizeof(errorType), + eSMRRelease)) { + // LCOV_EXCL_BR_STOP + // LCOV_EXCL_START 4: NSFW error + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + FRAMEWORKUNIFIEDLOG(ZONE_ERR, __PRETTY_FUNCTION__, + " FrameworkunifiedGetMsgDataOfSize failed with error"); + // LCOV_EXCL_STOP + } else { + EFrameworkunifiedStatus loggerserviceRet = SS_LoggerStoreLogs(SS_STORELOGS_INTERFACEUNIFIEDLOG); + LOG_STATUS_IF_ERRORED(loggerserviceRet, "Fail to save Loggerservice Log"); + EFrameworkunifiedStatus naviLog_status = g_errorEventHandler.SaveNaviLog( + errorType.shutdownTrigger); + LOG_STATUS_IF_ERRORED(naviLog_status, "Fail to save Navi Log"); + } + StopLoggingFunction(hApp); + + if (g_eLoggerServiceStatus == eLSStart) { // LCOV_EXCL_BR_LINE 200: g_eLoggerServiceStatus must be eLSStart on ACC-OFF + LoggerService_OnStop(hApp); + } + + // Set normal_startup_status flag (false) + g_normal_startup_status = false; + + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-"); + return (l_eStatus); +} + +/** + * EFrameworkunifiedStatus FrameworkunifiedCreateStateMachine(HANDLE hApp) + * @brief Used to . + * + * @param hApp Handle to the SS_Power Framework Obj. + * + * @return method status of completion or failure. + */ +EFrameworkunifiedStatus FrameworkunifiedCreateStateMachine(HANDLE hApp) { // LCOV_EXCL_START 8:dead code + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+"); + + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-"); + return eFrameworkunifiedStatusOK; +} +// LCOV_EXCL_STOP + +/** + * EFrameworkunifiedStatus LoggerService_OnStop(HANDLE hApp) + * @brief Logger Stop is called on Shutdown complete cmd + * + * @param hApp Handle to the SS_Power Framework Obj. + * + * @return method status of completion or failure. + */ +EFrameworkunifiedStatus LoggerService_OnStop(HANDLE hApp) { + EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK; + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+"); + + // Set Service status to init + g_eLoggerServiceStatus = eLSStop; + + /// Start the Writer threads + if (eFrameworkunifiedStatusOK != (l_eStatus = FrameworkunifiedStopChildThread(hApp, g_thrdEvntLogWriter, sizeof(Evntlog_wi), &Evntlog_wi))) { // LCOV_EXCL_BR_LINE 4:NSFW // NOLINT[whitespace/line_length] + // LCOV_EXCL_START 4:NSFW + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + FRAMEWORKUNIFIEDLOG(ZONE_ERR, __PRETTY_FUNCTION__, + "Fail to Start Writer Worker thread. Status:0x%x", l_eStatus); + // LCOV_EXCL_STOP + } else { + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __PRETTY_FUNCTION__, + "Successful in Sending Stop to ChildThread"); + } + + // Publish Service available this can also be published from FrameworkunifiedOnStart callback + if (eFrameworkunifiedStatusOK != (l_eStatus = FrameworkunifiedPublishServiceAvailability(hApp, FALSE))) { // LCOV_EXCL_BR_LINE 4:NSFW // NOLINT[whitespace/line_length] + // LCOV_EXCL_START 4:NSFW + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, + "Failed to set service availability notification:0x%x ", l_eStatus); + // LCOV_EXCL_STOP + } + + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-"); + return (l_eStatus); +} + +EFrameworkunifiedStatus SMSessionAckCb(HANDLE hApp) { + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+"); + EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK; + HANDLE l_hSession; + + INTERFACEUNIFIEDLOG_RECEIVED_FROM(hApp); // LCOV_EXCL_BR_LINE 15: macro + + l_hSession = FrameworkunifiedGetOpenSessionHandle(hApp); + + if (NULL == l_hSession) { // LCOV_EXCL_BR_LINE 4:NSFW + // LCOV_EXCL_START 4:NSFW + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + FRAMEWORKUNIFIEDLOG( + ZONE_ERR, __FUNCTION__, + " Error. FrameworkunifiedGetSessionHandle() returned a NULL session handle. " + "Error events originating from System Manager will not be detected."); + // LCOV_EXCL_STOP + } else { + l_eStatus = FrameworkunifiedSetSessionHandle(hApp, FrameworkunifiedGetMsgSrc(hApp), l_hSession); + LOG_STATUS_IF_ERRORED(l_eStatus, "FrameworkunifiedSetSessionHandle()"); // LCOV_EXCL_BR_LINE 15: macro + + l_eStatus = g_errorEventHandler.RegisterSessionErrorEvent(l_hSession); + LOG_STATUS_IF_ERRORED(l_eStatus, // LCOV_EXCL_BR_LINE 15: macro + "g_errorEventHandler.RegisterSessionErrorEvent()"); + } + + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-"); + return (l_eStatus); +} + +EFrameworkunifiedStatus FrameworkunifiedOnWakeup(HANDLE hApp) { // LCOV_EXCL_START 8:dead code + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK; + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+"); + + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-"); + return (l_eStatus); +} +// LCOV_EXCL_STOP + +////////////////////////////////////////// +// Function : FrameworkunifiedOnShutdown +////////////////////////////////////////// +EFrameworkunifiedStatus FrameworkunifiedOnShutdown(HANDLE hApp) { // LCOV_EXCL_START 8:dead code + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK; + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+"); + + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-"); + return (l_eStatus); +} +// LCOV_EXCL_STOP + +////////////////////////////////////////// +// Function : FrameworkunifiedOnEShutdown +////////////////////////////////////////// +EFrameworkunifiedStatus FrameworkunifiedOnEShutdown(HANDLE hApp) { // LCOV_EXCL_START 8:dead code + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK; + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+"); + + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-"); + return (l_eStatus); +} +// LCOV_EXCL_STOP + +////////////////////////////////////////// +// Function : FrameworkunifiedOnDebugDump +////////////////////////////////////////// +EFrameworkunifiedStatus FrameworkunifiedOnDebugDump(HANDLE hApp) { + EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK; + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+"); + + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-"); + return (l_eStatus); +} + +//////////////////////////////////////////////////////////////////////////////////////////// +/// HACK! mb20100701 +/// \todo Add behavior to this function +//////////////////////////////////////////////////////////////////////////////////////////// +EFrameworkunifiedStatus FrameworkunifiedOnDestroy(HANDLE hApp) { // LCOV_EXCL_START 14:For process termination processing + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+"); + + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-"); + return eFrameworkunifiedStatusNotImplemented; +} +// LCOV_EXCL_STOP + +EFrameworkunifiedStatus OnUsbEject(HANDLE hApp) { // LCOV_EXCL_START 7:debug code + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK; + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __PRETTY_FUNCTION__, "+"); + + if (g_loggerservicedebug_threads.Running( + LoggerserviceDebugChildThread::kLoggerserviceDebugCaptureLogScript)) { + g_loggerservicedebug_threads.Stop(LoggerserviceDebugChildThread::kLoggerserviceDebugCaptureLogScript); + FRAMEWORKUNIFIEDLOG( + ZONE_INFO, + __FUNCTION__, + "Stopped Thread: %s", + g_loggerservicedebug_threads.Name( + LoggerserviceDebugChildThread::kLoggerserviceDebugCaptureLogScript)); + } + + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __PRETTY_FUNCTION__, "-"); + return (l_eStatus); +} +// LCOV_EXCL_STOP + +EFrameworkunifiedStatus OnUsbStoreLogs(HANDLE hApp) { // LCOV_EXCL_START 7:debug code + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK; + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __PRETTY_FUNCTION__, "+"); + TThrdCaptureLogsEvt evt = { }; + if (eFrameworkunifiedStatusOK + != (l_eStatus = FrameworkunifiedGetMsgDataOfSize(hApp, &evt, sizeof(evt)))) { + FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "FrameworkunifiedGetMsgDataOfSize Failed Status:0x%x ", + l_eStatus); + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __PRETTY_FUNCTION__, "-"); + return l_eStatus; + } + + l_eStatus = FrameworkunifiedSendChild(hApp, g_thrdLogWriter, eThrdCmdWriterStop, 0, NULL); + l_eStatus = FrameworkunifiedSendChild(hApp, g_thrdTxWriter, eThrdCmdWriterStop, 0, NULL); + + l_eStatus = FrameworkunifiedSendChild(hApp, g_thrdLogWriter, eThrdCmdWriteFilesToUsb, + sizeof(evt), &evt); + l_eStatus = FrameworkunifiedSendChild(hApp, g_thrdTxWriter, eThrdCmdWriteFilesToUsb, + sizeof(evt), &evt); + + l_eStatus = FrameworkunifiedSendChild(hApp, g_thrdLogWriter, eThrdCmdWriterResume, 0, + NULL); + l_eStatus = FrameworkunifiedSendChild(hApp, g_thrdTxWriter, eThrdCmdWriterResume, 0, NULL); + + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __PRETTY_FUNCTION__, "-"); + return (l_eStatus); +} +// LCOV_EXCL_STOP + +/////////////////////////////////////////////////////////////////////// +/// Function :cbStatisticalCounterPosResponse +/////////////////////////////////////////////////////////////////////// +// LCOV_EXCL_START 8:dead code +EFrameworkunifiedStatus cbStatisticalCounterSuccessResp(HANDLE hApp) { + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+"); + EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK; + + TStatisticalCntCmdSuccessResp l_stCmdSuccessResp; + SS_loggerserviceprotocol l_eResponseCmd; + HANDLE l_hSession = NULL; + if (eFrameworkunifiedStatusOK + != (l_eStatus = ReadMsg<TStatisticalCntCmdSuccessResp>(hApp, + l_stCmdSuccessResp))) { + LOG_ERROR("ReadMsg()"); + } else { + if (NULL + != (l_hSession = FrameworkunifiedGetSessionHandle( + hApp, l_stCmdSuccessResp.stSessiondata.strSrcName.c_str(), + l_stCmdSuccessResp.stSessiondata.session_id))) { + l_eResponseCmd = SS_LOGGER_READ_STATL_COUNTER_SUCCESS_RESP; + if (eFrameworkunifiedStatusOK + != (l_eStatus = FrameworkunifiedSendMsg(l_hSession, l_eResponseCmd, + sizeof(SStatisticalCounter), + &l_stCmdSuccessResp.stBuffer))) { + LOG_ERROR("FrameworkunifiedSendMsg()"); + } + } else { + l_eStatus = eFrameworkunifiedStatusInvldHandle; + LOG_ERROR("FrameworkunifiedGetSessionHandle()"); + } + } + + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-"); + return (l_eStatus); +} +// LCOV_EXCL_STOP + +/////////////////////////////////////////////////////////////////////// +/// Function :cbStatisticalCounterErrResponse +/////////////////////////////////////////////////////////////////////// +// LCOV_EXCL_START 8:dead code +EFrameworkunifiedStatus cbStatisticalCounterErrorResp(HANDLE hApp) { + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+"); + EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK; + + TSessionData l_stSessiondata; + SS_loggerserviceprotocol l_eResponseCmd; + HANDLE l_hSession = NULL; + if (eFrameworkunifiedStatusOK + != (l_eStatus = ReadMsg<TSessionData>(hApp, l_stSessiondata))) { + LOG_ERROR("ReadMsg()"); + } else { + if (NULL + != (l_hSession = FrameworkunifiedGetSessionHandle(hApp, + l_stSessiondata.strSrcName.c_str(), + l_stSessiondata.session_id))) { + l_eResponseCmd = SS_LOGGER_READ_STATL_COUNTER_ERROR_RESP; + if (eFrameworkunifiedStatusOK + != (l_eStatus = FrameworkunifiedSendMsg(l_hSession, l_eResponseCmd, 0x00, NULL))) { + LOG_ERROR("FrameworkunifiedSendMsg()"); + } + } else { + l_eStatus = eFrameworkunifiedStatusInvldHandle; + LOG_ERROR("FrameworkunifiedGetSessionHandle()"); + } + } + + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-"); + return (l_eStatus); +} +// LCOV_EXCL_STOP + +/////////////////////////////////////////////////////////////////////// +/// Function :cbClearEventLogsResponse +/////////////////////////////////////////////////////////////////////// +// LCOV_EXCL_START 8:dead code +EFrameworkunifiedStatus cbClearEventLogsResponse(HANDLE hApp) { + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+"); + EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK; + TClearEvntLogCmdResponse l_stCmdResponse; + HANDLE l_hSession = NULL; + SS_loggerserviceprotocol l_eResponseCmd; + + if (eFrameworkunifiedStatusOK + != (l_eStatus = ReadMsg<TClearEvntLogCmdResponse>(hApp, l_stCmdResponse))) { + LOG_ERROR("ReadMsg()"); + } else { + if (NULL + != (l_hSession = FrameworkunifiedGetSessionHandle( + hApp, l_stCmdResponse.stSessiondata.strSrcName.c_str(), + l_stCmdResponse.stSessiondata.session_id))) { + if (l_stCmdResponse.u8Response == (UI_8) CLEAR_EVENT_LOG_SUCCESS) { + l_eResponseCmd = SS_LOGGERCLEAREVENT_SUCCESS_RESP; + } else { + l_eResponseCmd = SS_LOGGERCLEAREVENT_ERROR_RESP; + } + + if (eFrameworkunifiedStatusOK + != (l_eStatus = FrameworkunifiedSendMsg(l_hSession, l_eResponseCmd, 0x00, NULL))) { + LOG_ERROR("FrameworkunifiedSendMsg()"); + } + } else { + l_eStatus = eFrameworkunifiedStatusInvldHandle; + LOG_ERROR("FrameworkunifiedGetSessionHandle()"); + } + } + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-"); + return (l_eStatus); +} +// LCOV_EXCL_STOP + +/////////////////////////////////////////////////////////////////////// +/// Function :cbCopyEventLogsUSBResponse +/////////////////////////////////////////////////////////////////////// +// LCOV_EXCL_START 8:dead code +EFrameworkunifiedStatus cbCopyEventLogsUSBResponse(HANDLE hApp) { + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+"); + EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK; + TWriteFilesToUsbCmdResponse l_stCmdResponse; + HANDLE l_hSession = NULL; + SS_loggerserviceprotocol l_eResponseCmd; + EEvtLoggerErrorCode l_eResponseCode; + + if (eFrameworkunifiedStatusOK + != (l_eStatus = ReadMsg<TWriteFilesToUsbCmdResponse>(hApp, + l_stCmdResponse))) { + LOG_ERROR("ReadMsg()"); + } else { + if (NULL + != (l_hSession = FrameworkunifiedGetSessionHandle( + hApp, l_stCmdResponse.stSessiondata.strSrcName.c_str(), + l_stCmdResponse.stSessiondata.session_id))) { + if (l_stCmdResponse.u8Response == (UI_8) COPY_EVT_USB_SUCCESS) { + l_eResponseCmd = SS_LOGGERCOPYEVENTUSB_SUCCESS_RESP; + l_eResponseCode = NO_ERROR_INFO; + } else { + l_eResponseCmd = SS_LOGGERCOPYEVENTUSB_ERROR_RESP; + l_eResponseCode = (EEvtLoggerErrorCode) l_stCmdResponse.u8Response; + } + + if (eFrameworkunifiedStatusOK + != (l_eStatus = FrameworkunifiedSendMsg(l_hSession, l_eResponseCmd, + sizeof(EEvtLoggerErrorCode), + &l_eResponseCode))) { + LOG_ERROR("FrameworkunifiedSendMsg()"); + } + } else { + l_eStatus = eFrameworkunifiedStatusInvldHandle; + LOG_ERROR("FrameworkunifiedGetSessionHandle()"); + } + } + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-"); + return (l_eStatus); +} +// LCOV_EXCL_STOP + +// LCOV_EXCL_START 8:dead code +EFrameworkunifiedStatus cbReadNumbOfEventsResponse(HANDLE hApp) { + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+"); + EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK; + UI_16 l_NumOfEvents = 0; + TEvntsLogged l_stNumberOfEvtsLogged; + HANDLE l_hsession = NULL; + + if (eFrameworkunifiedStatusOK + != (l_eStatus = ReadMsg<TEvntsLogged>(hApp, l_stNumberOfEvtsLogged))) { + LOG_ERROR("ReadMsg()"); + } else { + l_NumOfEvents = l_stNumberOfEvtsLogged.u16numberofeventslogged; + if (NULL + != (l_hsession = FrameworkunifiedGetSessionHandle( + hApp, l_stNumberOfEvtsLogged.stSessiondata.strSrcName.c_str(), + l_stNumberOfEvtsLogged.stSessiondata.session_id))) { + if (eFrameworkunifiedStatusOK + != (l_eStatus = FrameworkunifiedSendMsg(l_hsession, + SS_LOGGER_ENG_READ_NUMOFEVENTS_RESP, + sizeof(UI_16), &l_NumOfEvents))) { + LOG_ERROR("FrameworkunifiedSendMsg()"); + } + } else { + l_eStatus = eFrameworkunifiedStatusNullPointer; + LOG_ERROR("FrameworkunifiedGetSessionHandle()"); + } + } + + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-"); + return (l_eStatus); +} +// LCOV_EXCL_STOP + +// LCOV_EXCL_START 8:dead code +EFrameworkunifiedStatus cbUploadEventLogResponse(HANDLE hApp) { + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+"); + EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK; + HANDLE l_hsession = NULL; + + FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__, "UploadEventLog Response Msg Len = %d", + FrameworkunifiedGetMsgLength(hApp)); + if (eFrameworkunifiedStatusOK + != (l_eStatus = ReadMsg<TUploadEventLogResp>(hApp, g_stUploadEventLogResp))) { + LOG_ERROR("ReadMsg()"); + } else { + if (NULL + != (l_hsession = FrameworkunifiedGetSessionHandle( + hApp, g_stUploadEventLogResp.stSessiondata.strSrcName.c_str(), + g_stUploadEventLogResp.stSessiondata.session_id))) { + if (eFrameworkunifiedStatusOK + != (l_eStatus = FrameworkunifiedSendMsg(l_hsession, SS_LOGGER_UPLOAD_EVENTLOG_RESP, + sizeof(STEventLogPersistBuffer), + &g_stUploadEventLogResp.stEventLogBuffer))) { + LOG_ERROR("FrameworkunifiedSendMsg()"); + } + } else { + l_eStatus = eFrameworkunifiedStatusNullPointer; + LOG_ERROR("FrameworkunifiedGetSessionHandle()"); + } + } + + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-"); + return (l_eStatus); +} +// LCOV_EXCL_STOP + +EFrameworkunifiedStatus cbServiceWakeupStatus(HANDLE hApp) { + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+"); + EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK; + + l_eStatus = g_errorEventHandler.CreateKernelLog(hApp, + SS_LOGGER_KBOOTLOG_CREATE); + LOG_STATUS_IF_ERRORED(l_eStatus, "CreateKernelLog(SS_LOGGER_KBOOTLOG_CREATE)"); + + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-"); + return (l_eStatus); +} + +void StopLoggingFunction(HANDLE hApp) { + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+"); + // PFDRECThread Stop + EFrameworkunifiedStatus l_eStatus = g_PFDRECThread.Finalize(hApp); + LOG_STATUS_IF_ERRORED(l_eStatus, "g_PFDRECThread.Finalize()"); + + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-"); +} diff --git a/systemservice/logger_service/server/src/loggerservice_main.cpp b/systemservice/logger_service/server/src/loggerservice_main.cpp new file mode 100755 index 0000000..a7ee212 --- /dev/null +++ b/systemservice/logger_service/server/src/loggerservice_main.cpp @@ -0,0 +1,59 @@ +/* + * @copyright Copyright (c) 2016-2020 TOYOTA MOTOR CORPORATION. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/////////////////////////////////////////////////////////////////////////////// +/// \ingroup tag_NS_InterfaceunifiedLogCapture +/// \brief Application entry point. +/// +/////////////////////////////////////////////////////////////////////////////// +// System Headers +#include <pthread.h> +#include <native_service/frameworkunified_dispatcher.h> +#include <native_service/frameworkunified_application.h> +#include <system_service/ss_system_if.h> +#include <loggerservicedebug_loggerservicelog.h> +#include <system_service/ss_version.h> +#include <native_service/ns_version_if.h> +#include <system_service/ss_services.h> +#include <cstdlib> +#include <iostream> + +CFrameworkunifiedVersion g_FrameworkunifiedVersion(MAJORNO, MINORNO, REVISION); + +FRAMEWORKUNIFIEDLOGPARAM g_FrameworkunifiedLogParams = { FRAMEWORKUNIFIEDLOGOPTIONS, { +ZONE_TEXT_10, ZONE_TEXT_11, ZONE_TEXT_12, +ZONE_TEXT_13, ZONE_TEXT_14, ZONE_TEXT_15, +ZONE_TEXT_16, ZONE_TEXT_17, ZONE_TEXT_18, +ZONE_TEXT_19, ZONE_TEXT_20, ZONE_TEXT_21, +ZONE_TEXT_22, ZONE_TEXT_23, ZONE_TEXT_24, +ZONE_TEXT_25, ZONE_TEXT_26, ZONE_TEXT_27, +ZONE_TEXT_28, ZONE_TEXT_29, ZONE_TEXT_30, +ZONE_TEXT_31 }, FRAMEWORKUNIFIEDLOGZONES }; + +const CHAR AppName[] = SERVICE_LOGGER; + +////////////////////////////////////////// +// Function : main +////////////////////////////////////////// +int main(int argc, char *argv[]) { + EFrameworkunifiedStatus eStatus = eFrameworkunifiedStatusOK; + FrameworkunifiedDefaultCallbackHandler cbFuncs; // LCOV_EXCL_BR_LINE 11:Unexpected branch + FRAMEWORKUNIFIED_MAKE_DEFAULT_CALLBACK(cbFuncs); // LCOV_EXCL_BR_LINE 15: macro + FRAMEWORKUNIFIED_SET_ZONES(); // LCOV_EXCL_BR_LINE 15: macro + + eStatus = FrameworkunifiedDispatcherWithArguments(AppName, argc, argv, &cbFuncs); // LCOV_EXCL_BR_LINE 11:Unexpected branch + return eStatus; +} // LCOV_EXCL_BR_LINE 10:the last line diff --git a/systemservice/logger_service/server/src/loggerservicedebug_child_thread.cpp b/systemservice/logger_service/server/src/loggerservicedebug_child_thread.cpp new file mode 100755 index 0000000..4a8668f --- /dev/null +++ b/systemservice/logger_service/server/src/loggerservicedebug_child_thread.cpp @@ -0,0 +1,134 @@ +/* + * @copyright Copyright (c) 2016-2020 TOYOTA MOTOR CORPORATION. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/////////////////////////////////////////////////////////////////////////////// +/// \ingroup tag_NS_InterfaceunifiedLogCapture +/// \brief Class that threads for usb, and readers use to AGL and get +/// information from the parent. +/// +/////////////////////////////////////////////////////////////////////////////// +// System Headers +#include <loggerservicedebug_thread_if.h> +#include <new> + +const CHAR g_strLogQueReaderWorkerName[] = "pdg.LogQueR"; +const CHAR g_strTransmitQueReaderWorkerName[] = "pdg.TransQueR"; +const CHAR g_strPerformanceQueReaderWorkerName[] = "pdg.PerformQueR"; +const CHAR g_strUsbEjectWorkerName[] = "pdg.UsbEject"; +const CHAR g_strUsbLogCaptureWorkerName[] = "pdg.UsbLogCapt"; +const CHAR g_strCaptureLogScriptExeName[] = "pdg.CaptLogScri"; + +LoggerserviceDebugChildThread::LoggerserviceDebugChildThread() { + names[LoggerserviceDebugChildThread::kLoggerserviceDebugLogQueReader] = + g_strLogQueReaderWorkerName; + names[LoggerserviceDebugChildThread::kLoggerserviceDebugTransmitQueReader] = + g_strTransmitQueReaderWorkerName; + names[LoggerserviceDebugChildThread::kLoggerserviceDebugCaptureLogScript] = + g_strCaptureLogScriptExeName; + names[LoggerserviceDebugChildThread::kLoggerservicePerformanceLogQueReader] = + g_strPerformanceQueReaderWorkerName; + + threads[LoggerserviceDebugChildThread::kLoggerserviceDebugLogQueReader] = NULL; + threads[LoggerserviceDebugChildThread::kLoggerserviceDebugTransmitQueReader] = NULL; + threads[LoggerserviceDebugChildThread::kLoggerserviceDebugCaptureLogScript] = NULL; + threads[LoggerserviceDebugChildThread::kLoggerservicePerformanceLogQueReader] = NULL; +} // LCOV_EXCL_BR_LINE 10:the last line + +LoggerserviceDebugChildThread::~LoggerserviceDebugChildThread() { // LCOV_EXCL_START 14:global instance + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert +} +// LCOV_EXCL_STOP + +BOOL LoggerserviceDebugChildThread::Start(ELoggerserviceDebugThreads id, const char* parentsName, + const char * sendDataToQue, + void* (*routine)(void*), + const char * sendToUdpQue) { // LCOV_EXCL_START 7:debug code + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + BOOL rtn = FALSE; + if (id < LoggerserviceDebugChildThread::kLoggerserviceDebugMax && id > -1) { + if (threads[id] == NULL) { + if ( NULL + != (threads[id] = new (std::nothrow) CChild(parentsName, + sendDataToQue, + names[id].c_str(), + routine, sendToUdpQue))) { + rtn = TRUE; + } + } else { + rtn = TRUE; + } + } + + return rtn; +} +// LCOV_EXCL_STOP + +void LoggerserviceDebugChildThread::Stop(ELoggerserviceDebugThreads id) { // LCOV_EXCL_START 7:debug code + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + if (id < LoggerserviceDebugChildThread::kLoggerserviceDebugMax && id > -1) { + if (threads[id] != NULL) { + delete threads[id]; + threads[id] = NULL; + } + } +} +// LCOV_EXCL_STOP + +BOOL LoggerserviceDebugChildThread::Running(ELoggerserviceDebugThreads id) const { // LCOV_EXCL_START 7:debug code + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + BOOL rtn = FALSE; + if (id < LoggerserviceDebugChildThread::kLoggerserviceDebugMax && id > -1) { + if (threads[id] != NULL) { + rtn = TRUE; + } + } + + return rtn; +} +// LCOV_EXCL_STOP + +void LoggerserviceDebugChildThread::StopAll() { // LCOV_EXCL_START 7:debug code + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + for (int id = kLoggerserviceDebugLogQueReader; id < kLoggerserviceDebugMax; id++) { + if (threads[id] != NULL) { + threads[id]->Join(); + delete threads[id]; + threads[id] = NULL; + } + } +} +// LCOV_EXCL_STOP + +const char * LoggerserviceDebugChildThread::Name(ELoggerserviceDebugThreads id) { // LCOV_EXCL_START 7:debug code + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + if (id < LoggerserviceDebugChildThread::kLoggerserviceDebugMax && id > -1) { + return names[id].c_str(); + } + + return NULL; +} +// LCOV_EXCL_STOP + +void LoggerserviceDebugChildThread::LiftWaitBarrier(ELoggerserviceDebugThreads id) { // LCOV_EXCL_START 7:debug code + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + if (id < LoggerserviceDebugChildThread::kLoggerserviceDebugMax && id > -1) { + if (threads[id] != NULL) { + threads[id]->IsValidWaitBarrier(); + } + } +} +// LCOV_EXCL_STOP + diff --git a/systemservice/logger_service/server/src/loggerservicedebug_writer_Evntworker.cpp b/systemservice/logger_service/server/src/loggerservicedebug_writer_Evntworker.cpp new file mode 100755 index 0000000..5d29a58 --- /dev/null +++ b/systemservice/logger_service/server/src/loggerservicedebug_writer_Evntworker.cpp @@ -0,0 +1,1362 @@ +/* + * @copyright Copyright (c) 2016-2020 TOYOTA MOTOR CORPORATION. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/////////////////////////////////////////////////////////////////////////////// +/// \ingroup tag_NS_LogTraceSender +/// \brief frameworkunifieddebug writer thread class, handles writing a log file +/// all really done by my_writer class. +/// +/////////////////////////////////////////////////////////////////////////////// +// System Headers +#include "loggerservicedebug_writer_Evntworker.h" +#include <string.h> +#include <unistd.h> +#include <fcntl.h> +#include <time.h> +#include <sys/timeb.h> +#include <boost/bind.hpp> +#include <errno.h> +#include <native_service/ns_np_service_protocol.h> +#include <native_service/frameworkunified_application.h> +#include <native_service/frameworkunified_framework_types.h> +#include <native_service/frameworkunified_timer.h> +#include <loggerservicedebug_thread_if.h> +#include <loggerservicedebug_loggerservicelog.h> +#include <system_service/ss_logger_service_notifications.h> +#include <system_service/ss_devicedetection_service_ifc.h> +#include <system_service/ss_logger_service_protocol.h> +#include <system_service/ss_logger_service.h> +#include <system_service/ss_templates.h> +#include <stub/Clock_API.h> +#include <new> +#include <utility> +#include <string> + +/// Macros definition for the constants +#define SIZE_0 (size_t)0 +#define SIZE_1 (size_t)1 +#define COUNTER_SIZE 6 ///< Counter ID 2 bytes and Counter Value is 4 bytes +#define SINGLE_EVENT_INFO_SIZE 10 ///< Event log size +#define INITIAL_CNT_VALUE 0x00000001 ///< Init count value for counter logging +#define MAX_CNT_VALUE 0xFFFFFFFF ///< Max count calue for counter logging +#define MAX_USB_DEVICE 2 ///< Max USB devices + +// Temp path for event logs that used for copying to USB +const CHAR TMP_DEBUG_EVNTLOG_PATH_FN[] = "/tmp/loggerservice_Evntdebug.dat"; + +// Structure to hold the USB device information +TThrdEvtLogStore gSUSBDevInfo[MAX_USB_DEVICE] = { }; + +// Structure to hold the SD card device information +TThrdEvtLogStore gSSDCardevInfo = { }; + +// Object for device detection class +DeviceDetectionServiceIf m_device_detector_obj; + +// Map container for startup phase counter +CounterInformation CEvntWriterWorker::counter; + +// Deque container for event logging +DEQUE_Event_Type CEvntWriterWorker::deque_event_info; + +static CEvntWriterWorker * pObj = new (std::nothrow) CEvntWriterWorker(); // LCOV_EXCL_BR_LINE 11:Unexpected branch +static TEvntWriterInfo wi = { }; + +// Event Common Info global structure +extern UEvtLoggerCommonInfo g_uEvtLoggerCommonInfo; +extern UI_16 g_u16DiagId; +static EFrameworkunifiedStatus ReadEventLogQueue(HANDLE hThread); +// created global variables as they are used in non member function +HANDLE g_hReceive = NULL; +HANDLE g_hEvtLogTimer = NULL; + +CEvntWriterWorker::CEvntWriterWorker() + : m_u32MileageData(0), + m_u32NumberEventsLogged(0) { + memset(m_stVINnumber.VINstr, 0, m_stVINnumber.VIN_LEN); +} + +CEvntWriterWorker::~CEvntWriterWorker() { // LCOV_EXCL_START 14:global instance + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert +} +// LCOV_EXCL_STOP + +EFrameworkunifiedStatus CEvntWriterWorker::Initialize(HANDLE hThread) { + return eFrameworkunifiedStatusOK; +} + +/////////////////////////////////////////////////////////////////////// +/// Function :EventLogRegisterCbHandlers +/////////////////////////////////////////////////////////////////////// +EFrameworkunifiedStatus CEvntWriterWorker::EventLogRegisterCbHandlers(HANDLE hThread) { // LCOV_EXCL_START 8: dead code + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+"); + EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK; + + FrameworkunifiedProtocolCallbackHandler aParentHandlers[] = { { + eThrdCmdWriteEvntFilesToUsb, boost::bind( + &CEvntWriterWorker::OnCmdWriteEventFilesToUsb, this, _1) }, { + eThrdCmdClearEvntLogs, boost::bind( + &CEvntWriterWorker::OnCmdClearEventLogs, this, _1) }, { + eThrdCmdStatisticalCounter, boost::bind( + &CEvntWriterWorker::OnCmdReadStatisticalCounter, this, _1) }, { + eThrdCmdResetStatisticalCntrs, boost::bind( + &CEvntWriterWorker::OnCmdResetStatisticalCounter, this, _1) }, { + eThrdCmdSetVINnumber, boost::bind(&CEvntWriterWorker::OnCmdSetVIN, this, + _1) }, { eThrdCmdImmPersistEvtLog, + boost::bind(&CEvntWriterWorker::immediate_persist_event_log, this, _1) }, + { eThrdCmdMileageData, boost::bind(&CEvntWriterWorker::EvtThd_SetMileage, + this, _1) }, { + eThrdCmdGetNumberOfEventsLogged, boost::bind( + &CEvntWriterWorker::OnCmdReadNumberOfEventsLogged, this, _1) }, { + eThrdCmdUploadEventLog, boost::bind( + &CEvntWriterWorker::OnCmdUploadEventLog, this, _1) } }; + + if (eFrameworkunifiedStatusOK + != (l_eStatus = FrameworkunifiedAttachParentCallbacksToDispatcher( + hThread, aParentHandlers, _countof(aParentHandlers)))) { + FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, + "Error: parent call backs attach failed , err code: %d", l_eStatus); + } + + // TO DO replace the queue name with macro EVENTLOG_MSGQ_NAME, after NS delivers it. + if (NULL != (g_hReceive = McOpenReceiverNotBlocked("/EvntLogQue"))) { + if (NULL + == (g_hEvtLogTimer = FrameworkunifiedAttachTimerCallback(hThread, 100, 1000, + ReadEventLogQueue))) { + LOG_ERROR("FrameworkunifiedAttachTimerCallback()"); + } + } else { + LOG_ERROR("McOpenReceiverNotBlocked"); + } + + return l_eStatus; +} +// LCOV_EXCL_STOP + +EFrameworkunifiedStatus ReadEventLogQueue(HANDLE hThread) { + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+"); + EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK; + CHAR source[MAX_QUEUE_NAME_SIZE]; + UI_32 l_cmd = 0; + UI_8 pbuf[MAX_QUEUE_MSG_SIZE]; + + if (NULL != g_hReceive) { // LCOV_EXCL_BR_LINE 6: g_hReceive is always null + // LCOV_EXCL_START 8: dead code + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + while (1) { + if (eFrameworkunifiedStatusOK != (l_eStatus = McReceive(g_hReceive, source, &l_cmd, + MAX_QUEUE_MSG_SIZE, + pbuf))) { + break; + } else { + switch (l_cmd) { + case SS_MSG_EVTLOG: + if (pObj) { + if (eFrameworkunifiedStatusOK != (l_eStatus = pObj->OnCmdEventLog(pbuf))) { + LOG_ERROR("OnCmdEventLog()"); + } + } else { + LOG_ERROR("pObj NULL"); + } + break; + + case SS_MSG_LOGGERCNT: + if (pObj) { + if (eFrameworkunifiedStatusOK != (l_eStatus = pObj->OnCmdIncrcount(pbuf))) { + LOG_ERROR("OnCmdIncrcount()"); + } + } else { + LOG_ERROR("pObj NULL"); + } + break; + + case SS_MSG_LOGGER_CNT_EVTLOG: + if (pObj) { + if (eFrameworkunifiedStatusOK + != (l_eStatus = pObj->OnCmdIncrwriteevent(pbuf))) { + LOG_ERROR("OnCmdIncrwriteevent()"); + } + } else { + LOG_ERROR("pObj NULL"); + } + break; + + default: + break; + } + } + } + // LCOV_EXCL_STOP + } else { + LOG_ERROR("Receive Handle NULL"); // LCOV_EXCL_BR_LINE 15:macro + } + + if (eFrameworkunifiedStatusErrNoEAGAIN == l_eStatus) { // LCOV_EXCL_BR_LINE 6: l_eStatus is always eFrameworkunifiedStatusOK + l_eStatus = eFrameworkunifiedStatusOK; // LCOV_EXCL_LINE 6: l_eStatus is always eFrameworkunifiedStatusOK + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + } + + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-"); + return l_eStatus; +} +/////////////////////////////////////////////////////////////////////// +/// Function :EvntWriterWorkerOnStart +/////////////////////////////////////////////////////////////////////// +EFrameworkunifiedStatus EvntWriterWorkerOnStart(HANDLE hThread) { + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __PRETTY_FUNCTION__, "+"); + EFrameworkunifiedStatus eStatus = eFrameworkunifiedStatusFail; + + if (eFrameworkunifiedStatusOK != (eStatus = FrameworkunifiedGetMsgDataOfSize(hThread, (PVOID) &wi, sizeof(wi), eSMRRelease))) { // LCOV_EXCL_BR_LINE 4:NSFW // NOLINT[whitespace/line_length] + // LCOV_EXCL_START 4:NSFW + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, + "Error: Unable to read handle from FrameWork Thread.%d", eStatus); + // LCOV_EXCL_STOP + } else { + FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__, + "Successfully read handle from FrameWork Thread.\n"); // LCOV_EXCL_BR_LINE 15:macro + } + + // Device Detection Obj initialization + if (m_device_detector_obj.Initialize(hThread)) { // LCOV_EXCL_BR_LINE 200:To ensure success + memset(&gSUSBDevInfo, 0, sizeof(gSUSBDevInfo)); + memset(&gSSDCardevInfo, 0, sizeof(gSSDCardevInfo)); + + if (eFrameworkunifiedStatusOK != (eStatus = m_device_detector_obj.NotifyOnDeviceDetectionAvailability( DD_USBServiceAvailabilityCallBack))) { + FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, + "Error: ServiceAvailabilityCallback registration failed"); + } + + if (eFrameworkunifiedStatusOK != (eStatus = m_device_detector_obj.NotifyOnOpenSessionAck( DD_USBOpenSessionAckCallBack))) { + FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, + "Error: OpenSessionAckCallback registration failed"); + } + + if (eFrameworkunifiedStatusOK != (eStatus = m_device_detector_obj.NotifyOnCloseSessionAck( DD_USBCloseSessionAckCallBack))) { + FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, + "Error: CloseSessionCallback registration failed"); + } + } else { + // LCOV_EXCL_START 200:To ensure success + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, + "Error: Device Detection Object Initialization failed!"); + // LCOV_EXCL_STOP + } + + if (pObj) { // LCOV_EXCL_BR_LINE 200:As it is always TRUE + FrameworkunifiedSetThreadSpecificData(hThread, pObj); + if (eFrameworkunifiedStatusOK != (eStatus = pObj->Initialize(hThread))) { + FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, + "Error: CEvntWriterWorker Initialize Failed"); + } + } else { + // LCOV_EXCL_START 200:As it is always TRUE + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + eStatus = eFrameworkunifiedStatusNullPointer; + FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "pObj is NULL"); + // LCOV_EXCL_STOP + } + + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __PRETTY_FUNCTION__, "-"); + return eStatus; +} + +/////////////////////////////////////////////////////////////////////// +/// Function :EvntWriterWorkerOnStop +/////////////////////////////////////////////////////////////////////// +EFrameworkunifiedStatus EvntWriterWorkerOnStop(HANDLE hThread) { + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __PRETTY_FUNCTION__, "+"); + EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusFail; + + if (pObj) { // LCOV_EXCL_BR_LINE 200:As it is always TRUE + if (NULL != g_hEvtLogTimer) { // LCOV_EXCL_BR_LINE 200:As it is always NULL + // LCOV_EXCL_START 200:As it is always NULL + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + CALL_AND_LOG_STATUS(FrameworkunifiedDetachTimerCallback(hThread, g_hEvtLogTimer)); + g_hEvtLogTimer = NULL; + // LCOV_EXCL_STOP + } + + /// To Read all msgs of EventLog queue on shutdown + CALL_AND_LOG_STATUS(ReadEventLogQueue(hThread)); // LCOV_EXCL_BR_LINE 11:Unexpected branch + /// Close ReadEventLog Queue receive handle + if (NULL != g_hReceive) { // LCOV_EXCL_BR_LINE 200:As it is always NULL + // LCOV_EXCL_START 200:As it is always NULL + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + CALL_AND_LOG_STATUS(McClose(g_hReceive)); + g_hReceive = NULL; + // LCOV_EXCL_STOP + } + } + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __PRETTY_FUNCTION__, "-"); + return l_eStatus; +} + +/////////////////////////////////////////////////////////////////////// +/// Function :OnCmdIncrcount_phase +/////////////////////////////////////////////////////////////////////// +VOID CEvntWriterWorker::OnCmdIncrcount_phase(st_LogCount *cnt) { // LCOV_EXCL_START 8: dead code + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __PRETTY_FUNCTION__, "+"); + + if (NULL != cnt) { + EStatCounterGroupID group; + UI_16 counterID = ((*cnt).cnt_id); + group = static_cast<EStatCounterGroupID>((counterID >> 8) & 0x00FF); + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __PRETTY_FUNCTION__, + "Increment counter(%04X) for group(%02X) by one", counterID, group); + counterIncrementByValue(group, counterID, 0x01u); + } else { + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __PRETTY_FUNCTION__, "Function call without parameter"); + } + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __PRETTY_FUNCTION__, "-"); +} +// LCOV_EXCL_STOP + +/////////////////////////////////////////////////////////////////////// +/// Function :OnCmdIncrcount +/////////////////////////////////////////////////////////////////////// +EFrameworkunifiedStatus CEvntWriterWorker::OnCmdIncrcount(UI_8 *pbuf) { // LCOV_EXCL_START 8: dead code + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __PRETTY_FUNCTION__, "+"); + EFrameworkunifiedStatus eStatus = eFrameworkunifiedStatusOK; + st_LogCount cnt; + + if (eFrameworkunifiedStatusOK + == (eStatus = McGetDataOfSize(pbuf, (PVOID) &cnt, sizeof(cnt)))) { + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, + "call increment function cnt.phase=%x,cnt.ID=%x", cnt.phase, + cnt.cnt_id); + OnCmdIncrcount_phase(&cnt); + } else { + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __PRETTY_FUNCTION__, "Not recieved data from q"); + } + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __PRETTY_FUNCTION__, "-"); + return eStatus; +} +// LCOV_EXCL_STOP + +/////////////////////////////////////////////////////////////////////// +/// Function :OnCmdIncrwriteevent +/////////////////////////////////////////////////////////////////////// +EFrameworkunifiedStatus CEvntWriterWorker::OnCmdIncrwriteevent(UI_8* pbuf) { // LCOV_EXCL_START 8: dead code + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + EFrameworkunifiedStatus eStatus = eFrameworkunifiedStatusOK; + st_LogEvent EC; + st_LogEvent_ss ev = { }; + st_LogCount C; + + if (eFrameworkunifiedStatusOK + == (eStatus = McGetDataOfSize(pbuf, (PVOID) &EC, sizeof(EC)))) { + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __PRETTY_FUNCTION__, "Successful increment"); + ev.event_id = EC.event_id; + ev.data[0] = EC.data[0]; + ev.data[1] = EC.data[1]; + ev.data[2] = EC.data[2]; + ev.data[3] = EC.data[3]; + OnCmdWriteEventLogs(&ev); + C.phase = (SystemPhase) (EC.phase); + C.cnt_id = EC.cnt_ID; + OnCmdIncrcount_phase(&C); + } else { + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __PRETTY_FUNCTION__, "Not recieved data from q"); + } + return eStatus; +} +// LCOV_EXCL_STOP + +/////////////////////////////////////////////////////////////////////// +/// Function :OnCmdWriteEventLogs +/////////////////////////////////////////////////////////////////////// +VOID CEvntWriterWorker::OnCmdWriteEventLogs(st_LogEvent_ss *ev) { // LCOV_EXCL_START 8: dead code + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert +// FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __PRETTY_FUNCTION__, "+"); + UI_32 u32deque_size = 0; + u32deque_size = static_cast<UI_32>(deque_event_info.size()); + u32deque_size = u32deque_size * SINGLE_EVENT_INFO_SIZE; // Existing Event Info size + u32deque_size += SINGLE_EVENT_INFO_SIZE; + // FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __PRETTY_FUNCTION__,"Deque size before write:%X ",u32deque_size); + + if (u32deque_size > MAX_EVENTLOG_SIZE) { +// FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __PRETTY_FUNCTION__,"Deque size will be exceeded after new event:%X ",u32deque_size); +// FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __PRETTY_FUNCTION__,"Removed the oldest event and add latest event in the the end"); + deque_event_info.pop_front(); + u32deque_size = static_cast<UI_32>(deque_event_info.size()); +// FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __PRETTY_FUNCTION__,"Deque size after pop:%X ",(u32deque_size*SINGLE_EVENT_INFO_SIZE)); + } + deque_event_info.push_back(*ev); +// FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __PRETTY_FUNCTION__,"Deque size after write:%X ", +// (deque_event_info.size()*SINGLE_EVENT_INFO_SIZE)); +// FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __PRETTY_FUNCTION__, "-"); +} +// LCOV_EXCL_STOP + +UI_32 LS_ConvertEndian(UI_32 * pvar) { // LCOV_EXCL_START 8: dead code + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + UI_32 retVal = (UI_32) 0; + UI_32 var = *pvar; + retVal = (((var & 0xFF000000) >> 24) | ((var & 0x00FF0000) >> 8) + | ((var & 0x0000FF00) << 8) | ((var & 0x000000FF) << 24)); + return (retVal); +} +// LCOV_EXCL_STOP + +/////////////////////////////////////////////////////////////////////// +/// Function :OnCmdEventLog +/////////////////////////////////////////////////////////////////////// +EFrameworkunifiedStatus CEvntWriterWorker::OnCmdEventLog(UI_8* pbuf) { // LCOV_EXCL_START 8: dead code + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + EFrameworkunifiedStatus eStatus = eFrameworkunifiedStatusOK; +// FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __PRETTY_FUNCTION__, "+"); + st_LogEvent_ss ev = { }; + st_LogEvent_full ev_full = { }; + UI_32 l_mileage; + if (eFrameworkunifiedStatusOK + == (eStatus = McGetDataOfSize(pbuf, &ev_full, sizeof(ev_full)))) { + if (0 != ev_full.grp_ID) { + if (0x01 == ev_full.grp_ID) { + // copied to local var as m_u32MileageData value is persisted + l_mileage = m_u32MileageData; + ev.ts = LS_ConvertEndian(&l_mileage); + } else { + ev.ts = ev_full.ts; + } + ev.grp_ID = ev_full.grp_ID; + ev.event_id = ev_full.event_id; + FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__, "TS %u, GRPID %d, EVTID %d", ev.ts, + ev.grp_ID, ev.event_id); + // FRAMEWORKUNIFIEDLOG_EVT(Zone,EventId,4,data0,data1,data2,data3) + // Data in tool should be represented in Little Endian format means data3(MSB)..data0(LSB) + // In the COMMON_DATA, 1st element of structure u_stEvtLoggerCommonInfo is stored in the CommonData[0], + // ie BodayCAN_Stat, + // in the data array, byte0=>MSB, byte3=>LSB in the tool + if (ev_full.typeofdata == COMMON_DATA) { + for (UI_8 j = 0; j < 3; j++) { + ev.data[j] = g_uEvtLoggerCommonInfo.CommonData[j]; + } + // byte0 param + ev.data[3] = ev_full.data[0]; + } else { + // in array data[0] => MSB in tool, data[3] => LSB in the tool + for (UI_8 i = 4, j = 0; i > 0 && j < 4; i--, j++) { + ev.data[i - 1] = ev_full.data[j]; + } + } + OnCmdWriteEventLogs(&ev); + } else { + FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "Error: Invalid event"); + } + } +// FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __PRETTY_FUNCTION__, "-"); + return eStatus; +} +// LCOV_EXCL_STOP + +/////////////////////////////////////////////////////////////////////// +/// Function :OnCmdStop +/////////////////////////////////////////////////////////////////////// +EFrameworkunifiedStatus CEvntWriterWorker::OnCmdStop(HANDLE hThread) { // LCOV_EXCL_START 8: dead code + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + return eFrameworkunifiedStatusOK; +} +// LCOV_EXCL_STOP + +EFrameworkunifiedStatus CEvntWriterWorker::OnCmdStart(HANDLE hThread) { // LCOV_EXCL_START 8: dead code + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + return eFrameworkunifiedStatusOK; +} +// LCOV_EXCL_STOP + +/////////////////////////////////////////////////////////////////////// +/// Function :read_count_from_file +/////////////////////////////////////////////////////////////////////// +EFrameworkunifiedStatus CEvntWriterWorker::readCountFromFile(PCSTR filename) { // LCOV_EXCL_START 8: dead code + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+"); + EFrameworkunifiedStatus eStatus = eFrameworkunifiedStatusOK; + UI_32 counter_ID = 0; + UI_32 counter_val = 0; + FILE* fp; + if (filename != NULL) { + FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__, "Open counter file:%s", filename); + if (NULL != (fp = ::fopen(filename, "r"))) { + while (!feof(fp)) { + EStatCounterGroupID group; + UI_8 groupID; + UI_8 count = static_cast<UI_8>(::fscanf(fp, "%04X%08X", &counter_ID, &counter_val)); + groupID = (counter_ID >> 8) & 0xFF; + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "Read: 0x%04X 0x%08X", counter_ID, + counter_val); + if ((count == 2u) + && (groupID >= static_cast<UI_8>(STARTUP_SHUTDOWN_COUNTER_GROUP)) + && (groupID <= static_cast<UI_8>(APP_USAGE_COUNTER_GROUP))) { + // Check if group is valid before casting it o EStatCounterGroup + group = static_cast<EStatCounterGroupID>(groupID); + counterIncrementByValue(group, static_cast<UI_16>(counter_ID), counter_val); + } + } + ::fclose(fp); + } else { + FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "Normal File failed to open"); + eStatus = eFrameworkunifiedStatusFileLoadError; + } + } else { + FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "Filename is NULL-pointer"); + eStatus = eFrameworkunifiedStatusAccessError; + } + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-"); + return eStatus; +} +// LCOV_EXCL_STOP + +// LCOV_EXCL_START 8: dead code +EFrameworkunifiedStatus CEvntWriterWorker::writeGroupToFile(FILE *fp, + EStatCounterGroupID group) { + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+"); + EFrameworkunifiedStatus eStatus = eFrameworkunifiedStatusOK; + if (fp != NULL) { + CounterInformation::iterator countInfIt = counter.find(group); + if (countInfIt != counter.end()) { + Counter count = countInfIt->second; + if (!count.empty()) { + Counter::iterator countIt; + for (countIt = count.begin(); countIt != count.end(); ++countIt) { + ::fprintf(fp, "%04X%08X\n", countIt->first, countIt->second); + } + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "Written %d entries for Group 0x%02X", + (UI_8)count.size(), (UI_8)group); + } else { + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "Group 0x%02X is empty", (UI_8)group); + } + } else { + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "Group not found in map"); + } + } else { + FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "Parameter fp is NULL-pointer"); + eStatus = eFrameworkunifiedStatusAccessError; + } + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-"); + return eStatus; +} +// LCOV_EXCL_STOP + +/////////////////////////////////////////////////////////////////////// +/// Function :writeCountToFile +/////////////////////////////////////////////////////////////////////// +EFrameworkunifiedStatus CEvntWriterWorker::writeCountToFile(PCSTR filename) { // LCOV_EXCL_START 8: dead code + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+"); + FILE *fp; + EFrameworkunifiedStatus eStatus = eFrameworkunifiedStatusOK; + CounterInformation::iterator countInfIt; + if (0 == strcmp(filename, Counter_LOG_PATH_FN)) { + if (NULL != (fp = ::fopen(filename, "w"))) { + for (countInfIt = counter.begin(); countInfIt != counter.end(); + ++countInfIt) { + (void) writeGroupToFile(fp, countInfIt->first); + } + ::fclose(fp); + } + } else { + FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "Error: Not valid file"); + eStatus = eFrameworkunifiedStatusErrNoEBADF; + } + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-"); + return eStatus; +} +// LCOV_EXCL_STOP + +/////////////////////////////////////////////////////////////////////// +/// Function :read_events_from_buffer +/////////////////////////////////////////////////////////////////////// +// LCOV_EXCL_START 8: dead code +VOID CEvntWriterWorker::read_events_from_buffer( + STEventLogPersistBuffer* f_pstEvtLogBuf) { + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+"); + deque_event_info.clear(); + for (int i = 0; i < (f_pstEvtLogBuf->Current_Log_Size); i++) { + if (i < f_pstEvtLogBuf->EVT_BUFMAXSIZE) { + deque_event_info.push_back(f_pstEvtLogBuf->EvtLog_Buffer[i]); + } else { + FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, + "Error: EventLog buffer size greater than EVT_BUFMAXSIZE"); + } + } + FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__, "Size of DEQUE event is :%d", + static_cast<int>(deque_event_info.size())); + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-"); +} +// LCOV_EXCL_STOP + +/////////////////////////////////////////////////////////////////////// +/// Function :write_events_to_buffer +/////////////////////////////////////////////////////////////////////// +// LCOV_EXCL_START 8: dead code +VOID CEvntWriterWorker::write_events_to_buffer( + STEventLogPersistBuffer* f_pstEvtLogBuf) { + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert +// FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+"); + st_LogEvent_ss l_event_info; + DEQUE_Event_Type::iterator deque_it; + deque_it = deque_event_info.begin(); + int i = 0; + + memset(f_pstEvtLogBuf, 0x00, sizeof(STEventLogPersistBuffer)); + while (deque_it != deque_event_info.end()) { + if (0x00 != deque_it->grp_ID) { + l_event_info.ts = deque_it->ts; + l_event_info.grp_ID = deque_it->grp_ID; + l_event_info.event_id = deque_it->event_id; + memcpy(l_event_info.data, deque_it->data, sizeof(l_event_info.data)); +// FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __PRETTY_FUNCTION__,"Event record is:%X ",++EventRecordCnt); + if (i < f_pstEvtLogBuf->EVT_BUFMAXSIZE) { + memcpy(&f_pstEvtLogBuf->EvtLog_Buffer[i], &l_event_info, + sizeof(l_event_info)); + } + } + deque_it++; + i++; + } + f_pstEvtLogBuf->Current_Log_Size = static_cast<UI_16>(deque_event_info.size()); + FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__, "Size of DEQUE event is :%d", + static_cast<int>(deque_event_info.size())); +// FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-"); +} +// LCOV_EXCL_STOP + +/////////////////////////////////////////////////////////////////////// +/// Function :write_event_to_file +/////////////////////////////////////////////////////////////////////// +EFrameworkunifiedStatus CEvntWriterWorker::write_event_to_file(const CHAR* filename) { // LCOV_EXCL_START 8: dead code + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+"); + EFrameworkunifiedStatus eStatus = eFrameworkunifiedStatusOK; + UI_32 u32File_Size; + st_LogEvent_ss Sevent_Info; + DEQUE_Event_Type::iterator deque_it; + FILE *fp; + + if (NULL != (fp = ::fopen(filename, "wb"))) { + deque_it = deque_event_info.begin(); + while (deque_it != deque_event_info.end()) { + Sevent_Info.ts = deque_it->ts; + Sevent_Info.grp_ID = deque_it->grp_ID; + Sevent_Info.event_id = deque_it->event_id; + memcpy(Sevent_Info.data, deque_it->data, sizeof(Sevent_Info.data)); + + if (0x00 != deque_it->grp_ID) { + if (SIZE_1 + != (u32File_Size = static_cast<UI_32>(::fwrite(&Sevent_Info, sizeof(Sevent_Info), 1, + fp)))) { + FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "Error: Writing in to file is failed"); + eStatus = eFrameworkunifiedStatusFail; + break; + } + } + deque_it++; + } + ::fclose(fp); + } else { + FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "Error: File failed to open"); + eStatus = eFrameworkunifiedStatusFileLoadError; + } + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-"); + return eStatus; +} +// LCOV_EXCL_STOP + +/////////////////////////////////////////////////////////////////////// +/// Function :OnCmdClearEventLogs +/////////////////////////////////////////////////////////////////////// +EFrameworkunifiedStatus CEvntWriterWorker::OnCmdClearEventLogs(HANDLE hThread) { // LCOV_EXCL_START 8: dead code + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+"); + + EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK; + TSessionData l_stSessionData; + TClearEvntLogCmdResponse l_stCmdResponse; + + if (eFrameworkunifiedStatusOK + != (l_eStatus = ReadMsg<TSessionData>(hThread, + l_stCmdResponse.stSessiondata))) { + LOG_ERROR("ReadMsg()"); + } else { + deque_event_info.clear(); + if (eFrameworkunifiedStatusOK != (l_eStatus = immediate_persist_event_log(hThread))) { + l_stCmdResponse.u8Response = (UI_8) CLEAR_EVENT_LOG_FAILED; + } else { + l_stCmdResponse.u8Response = (UI_8) CLEAR_EVENT_LOG_SUCCESS; + } + if (eFrameworkunifiedStatusOK + != (l_eStatus = FrameworkunifiedSendParent(hThread, eThrdCmdClearEventLogResponse, + sizeof(TClearEvntLogCmdResponse), + &l_stCmdResponse))) { + LOG_ERROR("FrameworkunifiedSendParent()"); + } + } + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-"); + return l_eStatus; +} +// LCOV_EXCL_STOP 8 + +/////////////////////////////////////////////////////////////////////// +/// Function :OnCmdSetVIN +/////////////////////////////////////////////////////////////////////// +EFrameworkunifiedStatus CEvntWriterWorker::OnCmdSetVIN(HANDLE hThread) { // LCOV_EXCL_START 8: dead code + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK; + STVIN_NUMBER l_stVIN_Number; + + if (eFrameworkunifiedStatusOK + == (l_eStatus = FrameworkunifiedGetMsgDataOfSize(hThread, &l_stVIN_Number, + sizeof(l_stVIN_Number), eSMRRelease))) { + memcpy(&m_stVINnumber, &l_stVIN_Number, sizeof(STVIN_NUMBER)); + } + + return l_eStatus; +} +// LCOV_EXCL_STOP + +/////////////////////////////////////////////////////////////////////// +/// Function :OnCmdGetVIN +/////////////////////////////////////////////////////////////////////// +VOID CEvntWriterWorker::OnCmdGetVIN(STVIN_NUMBER& f_stVIN_Number) { // LCOV_EXCL_START 8: dead code + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + memcpy(&f_stVIN_Number, &m_stVINnumber, sizeof(STVIN_NUMBER)); +} +// LCOV_EXCL_STOP + +/////////////////////////////////////////////////////////////////////// +/// Function :OnCmdWriteEventFilesToUsb +/////////////////////////////////////////////////////////////////////// +EFrameworkunifiedStatus CEvntWriterWorker::OnCmdWriteEventFilesToUsb(HANDLE hThread) { // LCOV_EXCL_START 8: dead code + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+"); + EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK; + TWriteFilesToUsbCmdData l_stCmdData; + TWriteFilesToUsbCmdResponse l_stCmdResponse; + + TThrdEvtLogStore evt = { }; + if (eFrameworkunifiedStatusOK + != (l_eStatus = ReadMsg<TWriteFilesToUsbCmdData>(hThread, l_stCmdData))) { + LOG_ERROR("ReadMsg()"); + } else { + if ((USB0 == l_stCmdData.eDevId) || (USB1 == l_stCmdData.eDevId)) { + memcpy(&evt, &gSUSBDevInfo[l_stCmdData.eDevId], sizeof(TThrdEvtLogStore)); + } else if (SD == l_stCmdData.eDevId) { + memcpy(&evt, &gSSDCardevInfo, sizeof(TThrdEvtLogStore)); + } else { + l_eStatus = eFrameworkunifiedStatusInvldID; + LOG_ERROR("Invalid DeviceId()"); + } + FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__, + "USB dev info:Available %d, Location %s, Parse %s ", + evt.IsDeviceAvailable, evt.parse_fn, evt.location); + l_stCmdResponse.u8Response = copy_event_files_to_usb(&evt); + l_stCmdResponse.stSessiondata.strSrcName = l_stCmdData.stSessiondata.strSrcName; + l_stCmdResponse.stSessiondata.session_id = l_stCmdData.stSessiondata.session_id; + if (eFrameworkunifiedStatusOK + != (l_eStatus = FrameworkunifiedSendParent(hThread, eThrdCmdCopyEventLogUSBResponse, + sizeof(TWriteFilesToUsbCmdResponse), + &l_stCmdResponse))) { + LOG_ERROR("FrameworkunifiedSendParent()"); + } + } + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-"); + return l_eStatus; +} +// LCOV_EXCL_STOP + +/////////////////////////////////////////////////////////////////////// +/// Function :OnCmdReadStatisticalCounter +/////////////////////////////////////////////////////////////////////// +EFrameworkunifiedStatus CEvntWriterWorker::OnCmdReadStatisticalCounter(HANDLE hThread) { // LCOV_EXCL_START 8: dead code + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+"); + EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK; + SStatisticalCounter buffer = { 0 }; + TStatisticalCntCmdSuccessResp l_stCmdSuccessResp; + + if (hThread != NULL) { + TStatisticalCountersCmd l_stCmdData; + if (eFrameworkunifiedStatusOK + != (l_eStatus = ReadMsg<TStatisticalCountersCmd>(hThread, l_stCmdData))) { + LOG_ERROR("ReadMsg()"); + } else { + if (eFrameworkunifiedStatusOK + != (l_eStatus = ReadStatisticalCounter(l_stCmdData.eGroupId, buffer))) { + LOG_ERROR("ReadStatisticalCounter()"); + if (eFrameworkunifiedStatusOK + != (l_eStatus = FrameworkunifiedSendParent(hThread, + eThrdCmdStatisticalCounterErrorResp, + sizeof(TSessionData), + &l_stCmdData.stSessiondata))) { + LOG_ERROR("FrameworkunifiedSendParent()"); + } + } else { + (VOID) memcpy(&l_stCmdSuccessResp.stBuffer, &buffer, + sizeof(SStatisticalCounter)); + (VOID) memcpy(&l_stCmdSuccessResp.stSessiondata, + &l_stCmdData.stSessiondata, sizeof(TSessionData)); + if (eFrameworkunifiedStatusOK + != (l_eStatus = FrameworkunifiedSendParent(hThread, + eThrdCmdStatisticalCounterSuccessResp, + sizeof(TStatisticalCntCmdSuccessResp), + &l_stCmdSuccessResp))) { + LOG_ERROR("FrameworkunifiedSendParent()"); + } + } + } + } + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-"); + return l_eStatus; +} +// LCOV_EXCL_STOP + +/////////////////////////////////////////////////////////////////////// +/// Function :ReadStatisticalCounter +/////////////////////////////////////////////////////////////////////// +// LCOV_EXCL_START 8: dead code +EFrameworkunifiedStatus CEvntWriterWorker::ReadStatisticalCounter( + EStatCounterGroupID eCounterGroup, SStatisticalCounter& buffer) { + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+"); + EFrameworkunifiedStatus eStatus = eFrameworkunifiedStatusOK; + UI_32 size = 0u; + + CounterInformation::iterator countInfIt = counter.find(eCounterGroup); + if (counter.end() != countInfIt) { + Counter count = countInfIt->second; + Counter::iterator countIt; + if (((UI_16) count.size()) <= 40) { + for (countIt = count.begin(); countIt != count.end(); ++countIt) { + UI_16 counterID = countIt->first; + UI_32 counterVal = countIt->second; + u16copy(&buffer.StatisticalCountBuffer[size], counterID); + size += static_cast<UI_16>( sizeof(counterID)); + + counterVal = countIt->second; + u32copy(&buffer.StatisticalCountBuffer[size], counterVal); + size += static_cast<UI_16>( sizeof(counterVal)); + } + } else { + eStatus = eFrameworkunifiedStatusInvldBuf; + FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, + "Error: Too many counter elements %02d > 42 ", static_cast<int>(count.size())); + } + } else { + /*OK, here: empty buffer will be returned*/ + } + + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-"); + return eStatus; +} +// LCOV_EXCL_STOP + +/////////////////////////////////////////////////////////////////////// +/// Function :OnCmdResetStatisticalCounter +/////////////////////////////////////////////////////////////////////// +EFrameworkunifiedStatus CEvntWriterWorker::OnCmdResetStatisticalCounter(HANDLE hThread) { // LCOV_EXCL_START 8: dead code + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+"); + EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK; + TStatisticalCountersCmd l_stCmdData; + + if (hThread != NULL) { + if (eFrameworkunifiedStatusOK + != (l_eStatus = ReadMsg<TStatisticalCountersCmd>(hThread, l_stCmdData))) { + LOG_ERROR("ReadMsg()"); + } else { + if (eFrameworkunifiedStatusOK + != (l_eStatus = ResetStatisticalCounter(l_stCmdData.eGroupId))) { + LOG_ERROR("ResetStatisticalCounter()"); + } + } + } + + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-"); + return l_eStatus; +} +// LCOV_EXCL_STOP +/////////////////////////////////////////////////////////////////////// +/// Function :ResetStatisticalCounter +/////////////////////////////////////////////////////////////////////// +// LCOV_EXCL_START 8: dead code +EFrameworkunifiedStatus CEvntWriterWorker::ResetStatisticalCounter( + EStatCounterGroupID eCounterGroup) { + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+"); + EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK; + CounterInformation::iterator countInfIt; + countInfIt = counter.find(eCounterGroup); + if (counter.end() != countInfIt) { + countInfIt->second.clear(); + counter.erase(countInfIt->first); + FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__, "Erased group: 0x%02X from map", + (UI_8)eCounterGroup); + } else { + l_eStatus = eFrameworkunifiedStatusInvldID; + } + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-"); + return l_eStatus; +} +// LCOV_EXCL_STOP + +/////////////////////////////////////////////////////////////////////// +/// Function :_GetCurrentTimeString +/////////////////////////////////////////////////////////////////////// +PSTR _GetCurrentTimeString(PCHAR TempFileName, PSTR f_pstrVIN) { // LCOV_EXCL_START 8: dead code + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+"); + + uint32_t rawtime; + uint8_t status; + struct tm local_time; + CHAR tbuf[30]; + UI_8 l_len = 0; + std::string l_strVIN = f_pstrVIN; + + // Time string is based on current date and time. Time string format is <year-mon-dayThhmm>. + Clock_getSystemTimeY2K38(&rawtime, &status); + Clock_getLocalTimeY2K38(&rawtime, &local_time); + if (0 + != (l_len = static_cast<UI_8>(strftime(tbuf, sizeof(tbuf), "%Y-%m-%dT%H%M", + &local_time)))) { + sprintf(TempFileName, "%s_%s_%04X.dat", l_strVIN.c_str(), tbuf, // NOLINT (runtime/printf) + g_u16DiagId); + } + FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__, "EventLog File Name :%s, tbuf_len = %d", + TempFileName, l_len); + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-"); + return TempFileName; +} +// LCOV_EXCL_STOP + +/////////////////////////////////////////////////////////////////////// +/// Function :copy_event_files_to_usb +/////////////////////////////////////////////////////////////////////// +UI_8 CEvntWriterWorker::copy_event_files_to_usb(TThrdEvtLogStore *pStUSBIndo) { // LCOV_EXCL_START 8: dead code + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+"); + EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK; + CHAR buffer[10]; + CHAR TempFileName[MAX_SYS_INFO_SIZE]; + STVIN_NUMBER l_stVIN_Number; + std::string _filename(""); + UI_8 u8Result = COPY_EVT_USB_SUCCESS; + + // Initializing all Char arrays. + memset(buffer, 0, 10); + memset(TempFileName, 0, MAX_SYS_INFO_SIZE); + + if (pStUSBIndo->IsDeviceAvailable == TRUE) { + _filename = pStUSBIndo->location; + OnCmdGetVIN(l_stVIN_Number); + _filename += _GetCurrentTimeString(TempFileName, l_stVIN_Number.VINstr); + + if (eFrameworkunifiedStatusOK != (l_eStatus = write_event_to_file(_filename.c_str()))) { + FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "Error: Write to file failed:%d", + l_eStatus); + u8Result = (UI_8) USB_DEVICE_WRITE_ERROR; + } + + } else { + FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, + "Error: Device not available, so event logs can not be copied"); + u8Result = (UI_8) USB_DEVICE_NOT_AVAILABLE; + } + + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __PRETTY_FUNCTION__, "-"); + return u8Result; +} +// LCOV_EXCL_STOP + +/////////////////////////////////////////////////////////////////////// +/// Function :DD_USBSrvDetectionCallBack +/////////////////////////////////////////////////////////////////////// +EFrameworkunifiedStatus DD_USBSrvDetectionCallBack(HANDLE hApp) { // LCOV_EXCL_START 8: dead code + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __PRETTY_FUNCTION__, "+"); + + EFrameworkunifiedStatus eStatus = eFrameworkunifiedStatusOK; + SS_MediaDetectInfo tMediaDetectInfo = { }; + std::string FilePathStr; + UI_8 u8Pos = 0; + + if (eFrameworkunifiedStatusOK + != (eStatus = FrameworkunifiedGetMsgDataOfSize(hApp, &tMediaDetectInfo, + sizeof(tMediaDetectInfo)))) { + FRAMEWORKUNIFIEDLOG(ZONE_ERR, __PRETTY_FUNCTION__, + "MediaDetectCallBack FrameworkunifiedGetMsgDataOfSize Failed Status:0x%x ", + eStatus); + } + FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__, " Device = %d", tMediaDetectInfo.dev_type); + FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__, " Availability = %d", + tMediaDetectInfo.bIsDeviceAvailable); + FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__, " device path = %s", + tMediaDetectInfo.deviceMountpath); + FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__, " File path = %s", + tMediaDetectInfo.filepathName); + + FilePathStr.append(tMediaDetectInfo.deviceMountpath); + + if (tMediaDetectInfo.dev_type == eUSB) { + if (tMediaDetectInfo.bIsDeviceAvailable == TRUE) { + u8Pos = static_cast<UI_8>(FilePathStr.find_last_of("/\\")); + + if (FilePathStr.compare(u8Pos + 1, 12, "usb-00-d0-p0") == 0) { + FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__, "USB1 Detected "); + gSUSBDevInfo[0].IsDeviceAvailable = TRUE; + snprintf(gSUSBDevInfo[0].parse_fn, gSUSBDevInfo[0].FN_LEN, "%s/", + FilePathStr.c_str()); + snprintf(gSUSBDevInfo[0].location, gSUSBDevInfo[0].FN_LEN, "%s/", + FilePathStr.c_str()); + } else if (FilePathStr.compare(u8Pos + 1, 12, "usb-01-d0-p0") == 0) { + FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__, "USB2 Detected "); + gSUSBDevInfo[1].IsDeviceAvailable = TRUE; + snprintf(gSUSBDevInfo[1].parse_fn, gSUSBDevInfo[1].FN_LEN, "%s/", + FilePathStr.c_str()); + snprintf(gSUSBDevInfo[1].location, gSUSBDevInfo[1].FN_LEN, "%s/", + FilePathStr.c_str()); + } else { + FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__, "USB Detected :%s", FilePathStr.c_str()); + } + } else { + u8Pos = static_cast<UI_8>(FilePathStr.find_last_of("/\\")); + + if (FilePathStr.compare(u8Pos + 1, 12, "usb-00-d0-p0") == 0) { + FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__, "USB1 Ejected "); + gSUSBDevInfo[0].IsDeviceAvailable = FALSE; + } else if (FilePathStr.compare(u8Pos + 1, 12, "usb-01-d0-p0") == 0) { + FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__, "USB2 Ejected "); + gSUSBDevInfo[1].IsDeviceAvailable = FALSE; + } else { + FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__, "USB Ejected :%s", FilePathStr.c_str()); + } + } + + } else if (tMediaDetectInfo.dev_type == eSD) { + if (tMediaDetectInfo.bIsDeviceAvailable == TRUE) { + FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__, "SD card Detected "); + gSSDCardevInfo.IsDeviceAvailable = TRUE; + snprintf(gSSDCardevInfo.parse_fn, gSSDCardevInfo.FN_LEN, "%s/", + FilePathStr.c_str()); + snprintf(gSSDCardevInfo.location, gSSDCardevInfo.FN_LEN, "%s/", + FilePathStr.c_str()); + } else { + FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__, "SD card Ejected "); + gSSDCardevInfo.IsDeviceAvailable = FALSE; + } + } + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __PRETTY_FUNCTION__, "-"); + + return eStatus; +} +// LCOV_EXCL_STOP + +////////////////////////////////////////// +// Function : DD_USBServiceAvailabilityCallBack +////////////////////////////////////////// +EFrameworkunifiedStatus DD_USBServiceAvailabilityCallBack(HANDLE hThread) { + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+"); + EFrameworkunifiedStatus eStatus = eFrameworkunifiedStatusOK; + + if (FrameworkunifiedIsServiceAvailable(hThread)) { + if (eFrameworkunifiedStatusOK // LCOV_EXCL_BR_LINE:200 Because the IF of DetectionService is guaranteed to be successful + != (eStatus = m_device_detector_obj.OpenSessionRequest())) { + FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "Open session request failed"); + } + } else { + if (eFrameworkunifiedStatusOK // LCOV_EXCL_BR_LINE:200 Because the IF of DetectionService is guaranteed to be successful + != (eStatus = m_device_detector_obj.CloseSessionRequest())) { + FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "Close session request failed"); + } + } + + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-"); + return eStatus; +} + +////////////////////////////////////////// +// Function : DD_USBOpenSessionAckCallBack +////////////////////////////////////////// +EFrameworkunifiedStatus DD_USBOpenSessionAckCallBack(HANDLE hThread) { + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+"); + EFrameworkunifiedStatus eStatus = eFrameworkunifiedStatusOK; + + if (eFrameworkunifiedStatusOK == (eStatus = // LCOV_EXCL_BR_LINE:200 Because the IF of DetectionService is guaranteed to be successful + m_device_detector_obj.DecodeOpenSessionResponse())) { + if (eFrameworkunifiedStatusOK + != (eStatus = m_device_detector_obj.RegisterForDeviceDetectionEvent( // LCOV_EXCL_BR_LINE:200 Because the IF of DetectionService is guaranteed to be successful // NOLINT[whitespace/line_length] + SS_DEV_DETECT_ANY_USB_EV, DD_USBSrvDetectionCallBack))) { + FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, + "Registration for SS_DEV_DETECT_ANY_USB_EV failed"); + } + + if (eFrameworkunifiedStatusOK + != (eStatus = m_device_detector_obj.RegisterForDeviceDetectionEvent( // LCOV_EXCL_BR_LINE:200 Because the IF of DetectionService is guaranteed to be successful // NOLINT[whitespace/line_length] + SS_DEV_DETECT_ANY_SD_EV, DD_USBSrvDetectionCallBack))) { + FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, + "Registration for SS_DEV_DETECT_ANY_SD_EV failed"); + } + } else { + FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "Decode open session response failed"); + } + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-"); + return eStatus; +} +////////////////////////////////////////// +// Function : DD_USBCloseSessionAckCallBack +////////////////////////////////////////// +EFrameworkunifiedStatus DD_USBCloseSessionAckCallBack(HANDLE hApp) { // LCOV_EXCL_START 200: CloseSessionRequest can not be called // NOLINT[whitespace/line_length] + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+"); + EFrameworkunifiedStatus eStatus = eFrameworkunifiedStatusOK; + CloseSessionAck tCloseSessionAck = { }; + + if (hApp) { + if (eFrameworkunifiedStatusOK + == (eStatus = FrameworkunifiedGetMsgDataOfSize(hApp, &tCloseSessionAck, + sizeof(tCloseSessionAck)))) { + if (eFrameworkunifiedStatusOK == tCloseSessionAck.eStatus) { + UI_32 l_uiSessionId = tCloseSessionAck.sessionId; + FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__, "session %d closed successfully", + l_uiSessionId); + } + } + } + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-"); + return eStatus; +} +// LCOV_EXCL_STOP + +// LCOV_EXCL_START 8: dead code +EFrameworkunifiedStatus CEvntWriterWorker::counterIncrementByValue(EStatCounterGroupID group, + UI_16 id, UI_32 value) { + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+"); + EFrameworkunifiedStatus result = eFrameworkunifiedStatusFail; + CounterInformation::iterator count_inf_it; + count_inf_it = counter.find(group); + if (counter.end() == count_inf_it) { + Counter newCounter; + newCounter.insert(std::pair<UI_16, UI_32>(id, value)); + counter.insert(std::pair<EStatCounterGroupID, Counter>(group, newCounter)); + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, + "Added new Counter for group %d, id: 0x%04X, value: 0x%08X", + (UI_8)group, id, value); + } else { + Counter::iterator count_it; + count_it = count_inf_it->second.find(id); + if (count_inf_it->second.end() == count_it) { + count_inf_it->second.insert(std::pair<UI_16, UI_32>(id, value)); + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, + "Added new Entry for group %d, id: 0x%04X, value: 0x%08X", + (UI_8)group, id, value); + } else { + if (count_it->second != MAX_CNT_VALUE) { + count_it->second += value; + } + FRAMEWORKUNIFIEDLOG( + ZONE_FUNC, + __FUNCTION__, + "Modified Entry for group %d, id: 0x%04X, by value: 0x%08X, new value: 0x%08X", + (UI_8)group, id, value, count_it->second); + } + } + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-"); + return result; +} +// LCOV_EXCL_STOP + +EFrameworkunifiedStatus CEvntWriterWorker::immediate_persist_event_log(HANDLE hThread) { // LCOV_EXCL_START 8: dead code + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+"); + STEventLogPersistBuffer* l_evtlogbuf; + l_evtlogbuf = new (std::nothrow) STEventLogPersistBuffer; + + if (NULL != l_evtlogbuf) { + if (pObj) { + pObj->write_events_to_buffer(l_evtlogbuf); + } else { + FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, + "Error: CEvntWriterWorker Object handle is NULL"); + } + delete l_evtlogbuf; + } else { + FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, + "Error: New failed to allocate memory, err: %s", strerror(errno)); + } + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-"); + return eFrameworkunifiedStatusOK; +} +// LCOV_EXCL_STOP + +EFrameworkunifiedStatus CEvntWriterWorker::EvtThd_SetMileage(HANDLE hThread) { // LCOV_EXCL_START 8: dead code + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+"); + EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK; + UI_32 l_u32mileage; + if (eFrameworkunifiedStatusOK + != (l_eStatus = FrameworkunifiedGetMsgDataOfSize(hThread, &l_u32mileage, + sizeof(l_u32mileage)))) { + FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "FrameworkunifiedGetMsgDataOfSize Failed Status:%d ", + l_eStatus); + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-"); + return l_eStatus; + } + m_u32MileageData = l_u32mileage; + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-"); + return l_eStatus; +} +// LCOV_EXCL_STOP + +/////////////////////////////////////////////////////////////////////// +/// Function :write_mileage_to_file +/////////////////////////////////////////////////////////////////////// +EFrameworkunifiedStatus CEvntWriterWorker::write_mileage_to_file(const CHAR* filename) { // LCOV_EXCL_START 8: dead code + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+"); + EFrameworkunifiedStatus eStatus = eFrameworkunifiedStatusOK; + UI_32 u32File_Size; + SI_32 fd = -1; + + if (-1 != (fd = ::open(filename, O_WRONLY | O_CREAT | O_TRUNC, + S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP))) { + if (SIZE_0 + >= (u32File_Size = static_cast<UI_32>(::write(fd, &m_u32MileageData, sizeof(UI_32))))) { + FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "Error: Writing in to file is failed"); + eStatus = eFrameworkunifiedStatusFail; + } + ::close(fd); + } else { + FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "Error: File failed to open"); + eStatus = eFrameworkunifiedStatusFileLoadError; + } + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-"); + return eStatus; +} +// LCOV_EXCL_STOP + +/////////////////////////////////////////////////////////////////////// +/// Function :read_mileage_from_file +/////////////////////////////////////////////////////////////////////// +EFrameworkunifiedStatus CEvntWriterWorker::read_mileage_from_file(const CHAR* filename) { // LCOV_EXCL_START 8: dead code + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+"); + EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK; +// UI_32 u32File_Size; + SI_32 fd = -1; + + if (NULL != filename) { + if (-1 != (fd = ::open(filename, O_RDONLY, S_IRUSR))) { + if (-1 == ::read(fd, &m_u32MileageData, sizeof(UI_32))) { + FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "Error: Reading file failed, %s", + strerror(errno)); + l_eStatus = eFrameworkunifiedStatusFail; + } else { + FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__, "m_u32MileageData = %d", + m_u32MileageData); + } + ::close(fd); + } else { + FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "Error: File failed to open"); + l_eStatus = eFrameworkunifiedStatusFileLoadError; + } + } else { + FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "Error: Filename is NULL"); + l_eStatus = eFrameworkunifiedStatusNullPointer; + } + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-"); + return l_eStatus; +} +// LCOV_EXCL_STOP + +/////////////////////////////////////////////////////////////////////// +/// Function :OnCmdReadNumberOfEventsLogged +/////////////////////////////////////////////////////////////////////// +EFrameworkunifiedStatus CEvntWriterWorker::OnCmdReadNumberOfEventsLogged(HANDLE hThread) { // LCOV_EXCL_START 8: dead code + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+"); + EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK; + TEvntsLogged l_stEventsLogged; + + if (eFrameworkunifiedStatusOK + != (l_eStatus = ReadMsg<TSessionData>(hThread, + l_stEventsLogged.stSessiondata))) { + LOG_ERROR("ReadMsg()"); + } else { + l_stEventsLogged.u16numberofeventslogged = (UI_16) deque_event_info.size(); + FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__, "Number of Events Read: %d", + l_stEventsLogged.u16numberofeventslogged); + + if (eFrameworkunifiedStatusOK + != (l_eStatus = FrameworkunifiedSendParent(hThread, + eThrdCmdNumberOfEventsLoggedResponse, + sizeof(TEvntsLogged), &l_stEventsLogged))) { + FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__, "Error: FrameworkunifiedSendMsg failed %d", l_eStatus); + } + } + + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-"); + return l_eStatus; +} +// LCOV_EXCL_STOP + +/////////////////////////////////////////////////////////////////////// +/// Function :OnCmdUploadEventLog +/////////////////////////////////////////////////////////////////////// +EFrameworkunifiedStatus CEvntWriterWorker::OnCmdUploadEventLog(HANDLE hThread) { // LCOV_EXCL_START 8: dead code + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+"); + EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK; + + if (eFrameworkunifiedStatusOK + != (l_eStatus = ReadMsg<TSessionData>( + hThread, m_stUploadEventLogResp.stSessiondata))) { + LOG_ERROR("ReadMsg()"); + } else { + if (pObj) { + pObj->write_events_to_buffer(&m_stUploadEventLogResp.stEventLogBuffer); + if (eFrameworkunifiedStatusOK + != (l_eStatus = FrameworkunifiedSendParent(hThread, eThrdCmdUploadEventLogResponse, + sizeof(TUploadEventLogResp), + &m_stUploadEventLogResp))) { + LOG_ERROR("FrameworkunifiedSendParent()"); + } + } else { + FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, + "Error: CEvntWriterWorker Object handle is NULL"); + } + } + + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-"); + return l_eStatus; +} +// LCOV_EXCL_STOP + +/////////////////////////////////////////////////////////////////////// +/// Function :OnCmdCopyEvntLogToTmp +/////////////////////////////////////////////////////////////////////// +EFrameworkunifiedStatus CEvntWriterWorker::OnCmdCopyEvntLogToTmp(HANDLE hThread) { // LCOV_EXCL_START 8: dead code + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + return eFrameworkunifiedStatusOK; +} +// LCOV_EXCL_STOP diff --git a/systemservice/logger_service/server/src/mem_reader.cpp b/systemservice/logger_service/server/src/mem_reader.cpp new file mode 100755 index 0000000..5ad6a6c --- /dev/null +++ b/systemservice/logger_service/server/src/mem_reader.cpp @@ -0,0 +1,125 @@ +/* + * @copyright Copyright (c) 2016-2020 TOYOTA MOTOR CORPORATION. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/////////////////////////////////////////////////////////////////////////////// +/// \ingroup tag_SS_LoggerService +/// \brief This file supports reading from a shared mem area. +/// +/////////////////////////////////////////////////////////////////////////////// +#include "readerWriter/reader/mem_reader.h" +#include <string> + +namespace ReaderWriter { + +CMemReader::CMemReader() + : m_pSharedBuf(NULL), + m_sharedBufSize(0) { +} + +CMemReader::~CMemReader() { + this->Close(); +} + +EFrameworkunifiedStatus CMemReader::Initialize(CLoggerCfg* f_pLoggerCfg, std::string f_name, + UI_32 f_maxSize) { + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+"); + EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusInvldParam; + m_sharedBufSize = f_maxSize; + m_pSharedBuf = new (std::nothrow) CNSSharedMemReader(f_name, TRUE); // LCOV_EXCL_BR_LINE 5:Cannot pass because it cannot be new + if (NULL != m_pSharedBuf) { // LCOV_EXCL_BR_LINE 5:Cannot pass because it cannot be new + l_eStatus = this->Open(); + } else { + l_eStatus = eFrameworkunifiedStatusNullPointer; + } + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-: %d", l_eStatus); + return (l_eStatus); +} + +EFrameworkunifiedStatus CMemReader::Open(void) { + EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusInvldParam; + if (NULL != m_pSharedBuf) { // LCOV_EXCL_BR_LINE 5: new will aways sucess, so m_pSharedBuf will noe be null + if (!m_pSharedBuf->IsOpen()) { + // maps the shared memory buffer + l_eStatus = m_pSharedBuf->Open(); + } else { + // Already opened no action required + l_eStatus = eFrameworkunifiedStatusOK; + } + } else { + l_eStatus = eFrameworkunifiedStatusNullPointer; + } + return l_eStatus; +} + +BOOL CMemReader::IsOpen(void) { + return this->m_pSharedBuf->IsOpen(); +} + +EFrameworkunifiedStatus CMemReader::Read(UI_8* f_data, UI_32 f_length, SI_32& f_bytesRead) { + EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK; + + if (this->m_pSharedBuf != NULL) { + if (TRUE != this->m_pSharedBuf->IsOpen()) { + l_eStatus = m_pSharedBuf->Open(); + } + if (l_eStatus == eFrameworkunifiedStatusOK) { + f_bytesRead = m_pSharedBuf->Read(reinterpret_cast<char *>(f_data), f_length); + if (NS_SHM_ERROR != f_bytesRead) { + l_eStatus = eFrameworkunifiedStatusOK; + } else { + l_eStatus = eFrameworkunifiedStatusFail; + } + } + + } else { + l_eStatus = eFrameworkunifiedStatusNullPointer; + } + return (l_eStatus); +} + +EFrameworkunifiedStatus CMemReader::ReadToFile(std::string f_fileName, UI_32& f_Written) { + EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusFail; + + if ((NULL != m_pSharedBuf) && // LCOV_EXCL_BR_LINE 5: new will aways sucess, so m_pSharedBuf will noe be null + (f_fileName.length() != 0)) { + l_eStatus = m_pSharedBuf->DumpToFile(f_fileName.c_str(), &f_Written); + } + + return l_eStatus; +} + +void CMemReader::Close(void) { + if (NULL != m_pSharedBuf) { // LCOV_EXCL_BR_LINE 6: m_pSharedBuf can not be null + // un-map the shared memory object + (void) m_pSharedBuf->Close(); + + delete m_pSharedBuf; + m_pSharedBuf = NULL; + } +} + +EFrameworkunifiedStatus CMemReader::ResetPosition(void) { + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+"); + EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusNullPointer; + if (NULL != m_pSharedBuf) { // LCOV_EXCL_BR_LINE 6:Because m_pSharedBuf is always NULL + // un-map the shared memory object + l_eStatus = m_pSharedBuf->SetReadPtrToWritePtr(); + LOG_STATUS_IF_ERRORED(l_eStatus, "m_pSharedBuf->SetReadPtrToWritePtr();"); // LCOV_EXCL_BR_LINE 15:Macro + } + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-: %d", l_eStatus); + return (l_eStatus); +} +} // namespace ReaderWriter diff --git a/systemservice/logger_service/server/src/mod_version.c b/systemservice/logger_service/server/src/mod_version.c new file mode 100755 index 0000000..0594b74 --- /dev/null +++ b/systemservice/logger_service/server/src/mod_version.c @@ -0,0 +1,49 @@ +/* + * @copyright Copyright (c) 2016-2020 TOYOTA MOTOR CORPORATION. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/////////////////////////////////////////////////////////////////////////////// +/// \ingroup tag_NS_LogTraceSender +/// \brief This file supports logging module version identification. +/// +/////////////////////////////////////////////////////////////////////////////// + +#include <stdlib.h> +#include <stdio.h> +#include <string.h> + +#include <native_service/frameworkunified_types.h> + +#define MOD_VERSION_LENGTH 12 + +static CHAR s_ModVersion[MOD_VERSION_LENGTH + 1] = "0.0.0"; + +SI_8 GetModuleVersion (CHAR* pRetBuf, UI_8 nBufLen) +{ // LCOV_EXCL_START 8: dead code + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + UI_8 CopyLen = 0; + SI_8 RetVal = -1; + + if (NULL != pRetBuf) + { + CopyLen = MIN_VAL(nBufLen, MOD_VERSION_LENGTH); + strncpy(pRetBuf, s_ModVersion, CopyLen); + pRetBuf[CopyLen] = '\0'; + RetVal = 0; + } + return RetVal; +} +// LCOV_EXCL_STOP 8: dead code + diff --git a/systemservice/logger_service/server/src/queue_reader.cpp b/systemservice/logger_service/server/src/queue_reader.cpp new file mode 100755 index 0000000..6c056c3 --- /dev/null +++ b/systemservice/logger_service/server/src/queue_reader.cpp @@ -0,0 +1,101 @@ +/* + * @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_SS_LoggerService +/// \brief TODO +/// +/////////////////////////////////////////////////////////////////////////////// +#include "readerWriter/reader/queue_reader.h" +#include <string> + +namespace ReaderWriter { +CQueueReader::CQueueReader() + : m_handle(-1), + m_queName("") { // LCOV_EXCL_BR_LINE 11:except,C++ STL +} + +CQueueReader::~CQueueReader() { + if (this->IsOpen()) { + this->Close(); + } +} + +EFrameworkunifiedStatus CQueueReader::Initialize(CLoggerCfg* f_pLoggerCfg, + std::string f_name, UI_32 f_maxSize) { + EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusInvldParam; + if (f_pLoggerCfg != NULL) { // LCOV_EXCL_BR_LINE 6:Because the applicable variable cannot be changed from the external API + this->m_pLoggerCfg = f_pLoggerCfg; + // Check for invalid name + if (f_name.length() != 0) { // LCOV_EXCL_BR_LINE 6:it can not be 0 + m_queName = f_name; + l_eStatus = this->Open(); + } + } + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-: %d", l_eStatus); + return (l_eStatus); +} + +EFrameworkunifiedStatus CQueueReader::Open(void) { + EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusInvldParam; + + if (-1 != m_handle) { // LCOV_EXCL_BR_LINE 6:Because m_handle is always -1 + // Queue already opened, no action required. + l_eStatus = eFrameworkunifiedStatusOK; + } else if (m_queName.length() != 0) { // LCOV_EXCL_BR_LINE 6:Because m_queName is not always an empty string + const UI_32 MAX_MESSAGES_STORED_IN_QUEUE = 512; + struct mq_attr mqattr; + mqattr.mq_flags = 0; + mqattr.mq_maxmsg = MAX_MESSAGES_STORED_IN_QUEUE; + mqattr.mq_msgsize = MAX_QUEUE_MSG_SIZE; + + this->m_handle = mq_open(m_queName.c_str(), O_RDONLY | O_CREAT, 0666, + &mqattr); + if (-1 != m_handle) { // LCOV_EXCL_BR_LINE 5:mq_open cannot be passed because it cannot be turned mock + l_eStatus = eFrameworkunifiedStatusOK; + } + } + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-: %d", l_eStatus); + return (l_eStatus); +} + +BOOL CQueueReader::IsOpen(void) { + return (-1 != m_handle) ? TRUE : FALSE; // LCOV_EXCL_BR_LINE 6:Because the condition cannot be set +} + +EFrameworkunifiedStatus CQueueReader::Read(UI_8* f_data, UI_32 f_length, + SI_32& f_bytesRead) { + EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusFail; + + if (this->m_handle != -1) { // LCOV_EXCL_BR_LINE 6:Because the condition cannot be set + if (f_length <= MAX_QUEUE_MSG_SIZE) { // LCOV_EXCL_BR_LINE 6:Because the applicable variable cannot be changed from the external API + f_bytesRead = static_cast<SI_32>(mq_receive(this->m_handle, reinterpret_cast<char *>(f_data), + (size_t) MAX_QUEUE_MSG_SIZE, NULL)); + + if ((0 <= f_bytesRead) && ((UI_32) f_bytesRead <= f_length)) { // LCOV_EXCL_BR_LINE 6:Because the condition cannot be set + l_eStatus = eFrameworkunifiedStatusOK; + } + } + } + return (l_eStatus); +} + +void CQueueReader::Close(void) { + if (this->m_handle != -1) { // LCOV_EXCL_BR_LINE 200: m_handle is aways not -1 + (void) mq_close(this->m_handle); + } +} +} // namespace ReaderWriter diff --git a/systemservice/logger_service/server/src/reader.cpp b/systemservice/logger_service/server/src/reader.cpp new file mode 100755 index 0000000..04880f0 --- /dev/null +++ b/systemservice/logger_service/server/src/reader.cpp @@ -0,0 +1,86 @@ +/* + * @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_SS_LoggerService +/// \brief TODO +/// +/////////////////////////////////////////////////////////////////////////////// +#include "readerWriter/reader/reader.h" +#include <string> +#include <new> +#include <iostream> +#include "readerWriter/reader/queue_reader.h" +#include "readerWriter/reader/mem_reader.h" +#include "ss_logger_cfg.h" +namespace ReaderWriter { +CReader::CReader() + : m_pLoggerCfg(NULL) { +} + +CReader::~CReader() { +} + +CReader* CReader::OpenReader(CLoggerCfg* f_pLoggerCfg, EReaderType f_type, + std::string f_name, UI_32 f_maxSize) { + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+"); + CReader* l_ret = NULL; + if (f_pLoggerCfg != NULL) { // LCOV_EXCL_BR_LINE 200:As it is not always NULL + if (f_name.length() != 0) { // LCOV_EXCL_BR_LINE 200:Because it is not always an empty string + switch (f_type) { // LCOV_EXCL_BR_LINE 200:As it must be eReaderWriterTypeQueue or eReaderWriterTypeMem + case eReaderWriterTypeFile: + break; + + case eReaderWriterTypeQueue: + l_ret = new (std::nothrow) CQueueReader(); // LCOV_EXCL_BR_LINE 5:Cannot pass because it cannot be new + break; + + case eReaderWriterTypeMem: + l_ret = new (std::nothrow) CMemReader(); // LCOV_EXCL_BR_LINE 5:Cannot pass because it cannot be new + break; + + default: + break; + } + } + if (NULL != l_ret) { // LCOV_EXCL_BR_LINE 200:As it is not always NULL + if (eFrameworkunifiedStatusOK != l_ret->Initialize(f_pLoggerCfg, f_name, f_maxSize)) { + delete (l_ret); + l_ret = NULL; + } + } + } + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-"); + return l_ret; +} + + +EFrameworkunifiedStatus CReader::ReadToFile(std::string f_fileName, UI_32& f_Written) { + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+"); + EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusNotImplemented; + + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-"); + return l_eStatus; +} + +EFrameworkunifiedStatus CReader::ResetPosition(void) { + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+"); + EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusNotImplemented; + + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-"); + return l_eStatus; +} +} // namespace ReaderWriter diff --git a/systemservice/logger_service/server/src/reader_writer.cpp b/systemservice/logger_service/server/src/reader_writer.cpp new file mode 100755 index 0000000..ef32384 --- /dev/null +++ b/systemservice/logger_service/server/src/reader_writer.cpp @@ -0,0 +1,282 @@ +/* + * @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_SS_LoggerService +/// \brief TODO +/// +/////////////////////////////////////////////////////////////////////////////// +#include "readerWriter/reader_writer.h" +#include <errno.h> +#include <loggerservicedebug_loggerservicelog.h> +#include <system_service/ss_templates.h> +#include <native_service/frameworkunified_thread_priority.h> +#include <string> + +namespace ReaderWriter { + +CReaderWriter::CReaderWriter() + : m_pLoggerCfg(NULL), + m_reader(NULL), + m_writer(NULL), + m_running(FALSE), + m_thread(-1), + m_readerName(""), + m_paused(FALSE) { + + pthread_cond_init(&m_condVariable, NULL); +} + +CReaderWriter::~CReaderWriter() { // LCOV_EXCL_START 14:global instance + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + if (NULL != this->m_reader) { + delete (this->m_reader); + this->m_reader = NULL; + } + + if (NULL != this->m_writer) { + delete (this->m_writer); + this->m_writer = NULL; + } +} +// LCOV_EXCL_STOP + +EFrameworkunifiedStatus CReaderWriter::Initialize(CLoggerCfg* f_pLoggerCfg, + EReaderType f_readerType, + std::string f_readerName, + UI_32 f_readerMaxSize, + EWriterType f_writerType, + std::string f_writer1Name, + UI_32 f_writer1MaxSize, + std::string f_writer2Name, + UI_32 f_writer2MaxSize) { + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+"); + EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK; + if (NULL == (this->m_pLoggerCfg = f_pLoggerCfg)) { // LCOV_EXCL_BR_LINE 6:Because the applicable variable cannot be changed from the external API + // FRAMEWORKUNIFIEDLOG not needed... If this starts we won't be able to print loggerservicelogs anyways. + l_eStatus = eFrameworkunifiedStatusNullPointer; + } else { + this->m_reader = CReader::OpenReader(f_pLoggerCfg, f_readerType, // LCOV_EXCL_BR_LINE 11:except,C++ STL + f_readerName, f_readerMaxSize); + this->m_writer = CWriter::OpenWriter(f_pLoggerCfg, f_writerType, // LCOV_EXCL_BR_LINE 11:except,C++ STL + f_writer1Name, f_writer1MaxSize, + f_writer2Name, f_writer2MaxSize); + + if ((NULL == this->m_reader) || (NULL == this->m_writer)) { + l_eStatus = eFrameworkunifiedStatusFail; + + this->Cleanup(this); + } + } + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-: %d", l_eStatus); + return (l_eStatus); +} + +EFrameworkunifiedStatus CReaderWriter::Start(std::string f_readerName) { + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+"); + EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusNullPointer; + if (this->m_running == FALSE) { // LCOV_EXCL_BR_LINE 6:Because m_running is always FALSE + this->m_readerName = f_readerName; + BOOL l_barInit = + // LCOV_EXCL_BR_START 5:pthread cannot be passed because it cannot be turned mock + (EOK == pthread_barrier_init(&m_barrier, NULL, 2)) ? TRUE : FALSE; + if (l_barInit) { + // LCOV_EXCL_BR_STOP + pthread_attr_t attr; + struct sched_param params; + pthread_attr_init(&attr); + pthread_attr_getschedparam(&attr, ¶ms); + SI_32 prio = frameworkunified::framework::CFrameworkunifiedThreadPriorities::GetPriority( + f_readerName); + if (-1 != prio) { // LCOV_EXCL_BR_LINE 6:Because prio is always -1 + // LCOV_EXCL_START 6:Because the prio is not always -1 + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + params.sched_priority = prio; + pthread_attr_setinheritsched(&attr, PTHREAD_EXPLICIT_SCHED); + pthread_attr_setschedparam(&attr, ¶ms); + // LCOV_EXCL_STOP + } + + if (EOK == pthread_create(&m_thread, &attr, &CReaderWriter::ThreadFunctionWrapper, this)) { // LCOV_EXCL_BR_LINE 5:pthread cannot be passed because it cannot be turned mock // NOLINT[whitespace/line_length] + this->m_running = TRUE; + l_eStatus = eFrameworkunifiedStatusOK; + pthread_barrier_wait(&this->m_barrier); /* Wait for thread to take off*/ + } + } + } else { + l_eStatus = eFrameworkunifiedStatusOK; + } + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-: %d", l_eStatus); + return (l_eStatus); +} + +void* CReaderWriter::ThreadFunctionWrapper(void* param) { + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+"); + CReaderWriter* l_pObj = reinterpret_cast<CReaderWriter *>(param); + + l_pObj->ThreadFunction(l_pObj); + FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, " Error. ThreadFunction has exited"); + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-"); + return NULL; +} + +void CReaderWriter::ThreadFunction(CReaderWriter* l_pObj) { + EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK; + int l_oldState; + + pthread_setname_np(pthread_self(), this->m_readerName.c_str()); + pthread_cleanup_push(&CReaderWriter::CleanupWrapper, this); + pthread_mutex_init(&m_writeMutex, NULL); + pthread_mutex_init(&m_pauseMutex, NULL); + int l_wait = pthread_barrier_wait(&m_barrier); + + if ((eFrameworkunifiedStatusOK == l_eStatus) + // LCOV_EXCL_BR_START 5:pthread cannot be passed because it cannot be turned mock + && (((PTHREAD_BARRIER_SERIAL_THREAD == l_wait) || (0 == l_wait)))) { + // LCOV_EXCL_BR_STOP + UI_8 data[MAX_QUEUE_MSG_SIZE + 1]; + while (TRUE) { + if (TRUE == this->m_paused) { + if (EOK == pthread_mutex_lock(&this->m_pauseMutex)) { // LCOV_EXCL_BR_LINE 5:pthread cannot be passed because it cannot be turned mock + (void)pthread_cond_wait(&m_condVariable, &m_pauseMutex); // LCOV_EXCL_BR_LINE 5:pthread cannot be passed because it cannot be turned mock + (void) pthread_mutex_unlock(&this->m_pauseMutex); // LCOV_EXCL_BR_LINE 5:pthread cannot be passed because it cannot be turned mock + } + } + if (!this->m_reader->IsOpen() || !this->m_writer->IsOpen()) { // LCOV_EXCL_BR_LINE 6:As it is not always open + (void)this->m_reader->Open(); // LCOV_EXCL_BR_LINE 11:Unexpected branch + (void)this->m_writer->Open(); // LCOV_EXCL_BR_LINE 11:Unexpected branch + } + + if (!this->m_reader->IsOpen() || !this->m_writer->IsOpen()) { + +// ->Reduced frequency of accesses to IsOpen() + usleep(1000*1000); // LCOV_EXCL_BR_LINE 5:C function + } else { + while ((eFrameworkunifiedStatusOK == l_eStatus) && (FALSE == this->m_paused)) { + SI_32 l_bytesRead = -1; + SI_32 l_bytesWritten = -1; + l_eStatus = this->m_reader->Read(data, + MAX_QUEUE_MSG_SIZE, + l_bytesRead); // LCOV_EXCL_BR_LINE 11:except,C++ STL + if (eFrameworkunifiedStatusOK == l_eStatus) { + pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, + &l_oldState); + if (EOK == pthread_mutex_lock(&this->m_writeMutex)) { // LCOV_EXCL_BR_LINE 5: c code error case + l_eStatus = this->m_writer->Write(data, + (UI_32) l_bytesRead, + l_bytesWritten); + (void) pthread_mutex_unlock(&this->m_writeMutex); + } + pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, + &l_oldState); + } + } + l_eStatus = eFrameworkunifiedStatusOK; // Reset l_eStatus + } + } + } + + pthread_cleanup_pop(1); +} + + +void CReaderWriter::CleanupWrapper(void* param) { + CReaderWriter* l_pObj = reinterpret_cast<CReaderWriter *>(param); + + l_pObj->Cleanup(l_pObj); +} + +void CReaderWriter::Cleanup(CReaderWriter* l_pObj) { + +// (void) pthread_mutex_unlock(&this->m_pauseMutex); +// (void) pthread_mutex_unlock(&this->m_writeMutex); + + + if (this->m_reader != NULL) { // LCOV_EXCL_BR_LINE 5: new will aways sucess, so m_reader can not be null + delete (this->m_reader); + this->m_reader = NULL; + } + if (this->m_writer != NULL) { // LCOV_EXCL_BR_LINE 5: new will aways sucess, so m_writer can not be null + delete (this->m_writer); + this->m_writer = NULL; + } + this->m_running = FALSE; +} + +EFrameworkunifiedStatus CReaderWriter::FlushCache(std::string f_filename) { + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+"); + EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK; + if (TRUE == this->m_pLoggerCfg->IsLoggingEnabled()) { // LCOV_EXCL_BR_LINE 6: it can not be false + if (EOK == pthread_mutex_lock(&this->m_writeMutex)) { // LCOV_EXCL_BR_LINE 5:pthread cannot be passed because it cannot be turned mock + if (this->m_writer != NULL) { // LCOV_EXCL_BR_LINE 5: new will aways sucess, so m_writer can not be null + l_eStatus = this->m_writer->FlushCache(); + LOG_STATUS_IF_ERRORED(l_eStatus, "this->m_writer->FlushCache()") + } + (void) pthread_mutex_unlock(&this->m_writeMutex); + } + + UI_32 l_written; + if (NULL != this->m_reader) { // LCOV_EXCL_BR_LINE 6:Because it depends on the startup process + l_eStatus = this->m_reader->ReadToFile(f_filename, l_written); + /*Don't output error, if function not implemented*/ + l_eStatus = + (l_eStatus == eFrameworkunifiedStatusNotImplemented) ? eFrameworkunifiedStatusOK : l_eStatus; + LOG_STATUS_IF_ERRORED(l_eStatus, + "this->m_reader->ReadToFile(f_filename, l_written)"); + } else { + l_eStatus = eFrameworkunifiedStatusNullPointer; + } + } + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-"); + return (l_eStatus); +} + +EFrameworkunifiedStatus CReaderWriter::UpdateLoggingParameters(void) { + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+"); + EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK; + if (EOK == pthread_mutex_lock(&this->m_writeMutex)) { // LCOV_EXCL_BR_LINE 5:pthread cannot be passed because it cannot be turned mock + if (this->m_writer != NULL) { + l_eStatus = this->m_writer->UpdateLoggingParameters(); + } + (void) pthread_mutex_unlock(&this->m_writeMutex); + } + BOOL l_enabled = this->m_pLoggerCfg->IsLoggingEnabled(); + if ((this->m_paused == FALSE) && (FALSE == l_enabled)) { + this->Pause(); + } else if ((this->m_paused == TRUE) && (TRUE == l_enabled)) { + this->Resume(); + } + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "- : %d", l_eStatus); + return (l_eStatus); +} + +void CReaderWriter::Pause(void) { + (void) pthread_mutex_lock(&this->m_pauseMutex); + this->m_paused = TRUE; + + (void) pthread_mutex_unlock(&this->m_pauseMutex); +} + +void CReaderWriter::Resume(void) { + (void) pthread_mutex_lock(&this->m_pauseMutex); + if (this->m_reader != NULL) { // LCOV_EXCL_BR_LINE 5: new will aways sucess, so m_reader can not be null + (void) this->m_reader->ResetPosition(); + } + pthread_cond_signal(&m_condVariable); + this->m_paused = FALSE; + (void) pthread_mutex_unlock(&this->m_pauseMutex); +} +} // namespace ReaderWriter diff --git a/systemservice/logger_service/server/src/ss_logger_cfg.cpp b/systemservice/logger_service/server/src/ss_logger_cfg.cpp new file mode 100755 index 0000000..b353bbe --- /dev/null +++ b/systemservice/logger_service/server/src/ss_logger_cfg.cpp @@ -0,0 +1,754 @@ +/* + * @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_SS_LoggerService +/// \brief Provide support for CPU high load monitor configuration. +/// +/////////////////////////////////////////////////////////////////////////////// +/////////////////////////////////////////////////////////////////////////////// +// INCLUDES +/////////////////////////////////////////////////////////////////////////////// +#include "ss_logger_cfg.h" +#include <stdio.h> +#include <string.h> +#include <stdlib.h> +#include <dirent.h> +#include <boost/bind.hpp> +#include <native_service/nslogutil_cmd_if.h> +#include <native_service/ns_np_service_protocol.h> +#include <system_service/ss_logger_service_notifications.h> +#include <iostream> +#include <iomanip> +#include <sstream> +#include <string> +#include <algorithm> +#include <vector> + +const static UI_32 cMAX_EMMC_COUNTER_VALUE = 100000u; // NOLINT (build/storage_class) +/////////////////////////////////////////////////////////////////////////////// +// CLASS METHODS +/////////////////////////////////////////////////////////////////////////////// + +CLoggerCfg::CLoggerCfg() + : m_logMaxFileSize(0), + m_performanceLogMaxFileSize(0), + m_emmcOutputMax(0), + m_emmcOutputErrMax(0), + m_emmcOutputGrpRelaunchMax(0), + m_emmcOutputNaviLogMax(0), + m_emmcOutputNaviLogNmlMax(0), + m_emmcOutputNaviLogErrMax(0), + m_emmcOutputPath(""), + m_emmcOutputNaviLogPath(""), + m_usb0MountPath(""), + m_usb1MountPath(""), + m_sdMountPath(""), + m_eDevType(eDevUSB1), + m_UserInvokedLoggingNumber(1u), + m_EmmcCounter(0u), + m_eLoggerUDPLoggingStatus(eDeactivate), + m_eLoggerStatus(SS_LOGGER_DEFAULT_VALUE) { + m_udpEnvFlag = FALSE; + std::memset(m_logMask, 0, sizeof(m_logMask)); + std::memset(&m_ExternalLogList, 0, sizeof(&m_ExternalLogList)); + } + +CLoggerCfg::~CLoggerCfg(void) { // LCOV_EXCL_START 14:global instance + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + + if (m_ExternalLogList.p_info != NULL) { + delete[] m_ExternalLogList.p_info; + m_ExternalLogList.p_info = NULL; + } +} +// LCOV_EXCL_STOP + +EFrameworkunifiedStatus CLoggerCfg::Initialize(HANDLE f_hApp) { + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+"); + + char* l_udp_env = getenv("UDPLOGS_ON"); + m_udpEnvFlag = ( + l_udp_env == NULL ? + FALSE : (strcmp("TRUE", l_udp_env) == 0 ? TRUE : FALSE)); + + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-"); + return eFrameworkunifiedStatusOK; +} +EFrameworkunifiedStatus CLoggerCfg::SetandPersistLoggingParams(HANDLE f_hApp, + STLoggerSetAllParams f_Params, + BOOL f_InitCall) { + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+"); + EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK; + BOOL l_paramChanged = f_InitCall; + BOOL l_updateLoggerState = f_InitCall; + + if ((TRUE == l_paramChanged) // LCOV_EXCL_BR_LINE 200:l_paramChanged is never TRUE + || + (m_eLoggerStatus != f_Params.Logger_State) + || // LCOV_EXCL_BR_LINE 200:Because m_UserInvokedLoggingNumber != f_Params.Log_FolderCnt is never false + (m_UserInvokedLoggingNumber != f_Params.Log_FolderCnt) + || (m_eLoggerUDPLoggingStatus != f_Params.Logger_UDPState) + || (m_eDevType != f_Params.Device_Type)) { + l_paramChanged = TRUE; + } else { + l_paramChanged = FALSE; + } + + l_updateLoggerState = + ((l_updateLoggerState == TRUE) + || (m_eLoggerStatus != f_Params.Logger_State)) ? TRUE : FALSE; + + // After startup Logging will be set to default value + if (TRUE == f_InitCall) { // LCOV_EXCL_BR_LINE 200:f_InitCall is never TRUE + // LCOV_EXCL_START 200:f_InitCall is never TRUE + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + m_eLoggerStatus = SS_LOGGER_DEFAULT_VALUE; + // LCOV_EXCL_STOP + } else { + m_eLoggerStatus = f_Params.Logger_State; + } + m_eLoggerUDPLoggingStatus = f_Params.Logger_UDPState; + m_UserInvokedLoggingNumber = f_Params.Log_FolderCnt; + m_eDevType = f_Params.Device_Type; + + if (TRUE == l_paramChanged) { + l_eStatus = PersistLoggingParam(f_hApp); + LOG_STATUS_IF_ERRORED(l_eStatus, // LCOV_EXCL_BR_LINE 15: macro + "PersistLoggingParam()"); + } + + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-"); + return (l_eStatus); +} + +EFrameworkunifiedStatus CLoggerCfg::SetLoggingParams(HANDLE f_hApp, + const STLoggerSetParams f_stLoggerSetParams) { + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+"); + EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK; + STLoggerSetAllParams l_Params; + + l_Params.Logger_UDPState = m_eLoggerUDPLoggingStatus; + l_Params.Log_FolderCnt = m_UserInvokedLoggingNumber; + l_Params.Logger_State = f_stLoggerSetParams.Logger_State; + l_Params.Device_Type = f_stLoggerSetParams.Device_Type; + + l_eStatus = SetandPersistLoggingParams(f_hApp, l_Params, FALSE); + LOG_STATUS_IF_ERRORED(l_eStatus, "SetandPersistLoggingParams()"); // LCOV_EXCL_BR_LINE 15: macro + + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-"); + return (l_eStatus); +} + +EFrameworkunifiedStatus CLoggerCfg::SetUDPLogging(HANDLE f_hApp, + const ELOGGER_STAT f_eUDPLoggingStatus) { + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+"); + EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK; + STLoggerSetAllParams l_Params; + + l_Params.Logger_UDPState = f_eUDPLoggingStatus; + l_Params.Log_FolderCnt = m_UserInvokedLoggingNumber; + l_Params.Logger_State = m_eLoggerStatus; + l_Params.Device_Type = m_eDevType; + + l_eStatus = SetandPersistLoggingParams(f_hApp, l_Params, FALSE); + LOG_STATUS_IF_ERRORED(l_eStatus, "SetandPersistLoggingParams()"); // LCOV_EXCL_BR_LINE 15: macro + + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-"); + return (l_eStatus); +} + +EFrameworkunifiedStatus CLoggerCfg::PersistLoggingParam(HANDLE f_hApp) { + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+"); + FRAMEWORKUNIFIEDLOG( + ZONE_INFO, __FUNCTION__, + "LoggerState = %d, Device_Type = %d,UDPLogging = %d, TriggerNumber = %d", + m_eLoggerStatus, m_eDevType, m_eLoggerUDPLoggingStatus, + m_UserInvokedLoggingNumber); // LCOV_EXCL_BR_LINE 11:Unexpected branch + + this->UpdateLoggingStatus(); + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-"); + return eFrameworkunifiedStatusOK; +} + +void CLoggerCfg::RemoveCarriageReturn(std::string &f_str) { + if (f_str.empty()) { // LCOV_EXCL_BR_LINE 8: Because there is no empty string case + return; + } + + if ('\r' == f_str.at(f_str.size() - 1)) { + f_str.erase(f_str.size() - 1, 1); + } +} +EFrameworkunifiedStatus CLoggerCfg::Load(const std::string &f_filePathAndName) { + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+"); + EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusDbRecNotFound; + + if ("" == f_filePathAndName) { // LCOV_EXCL_BR_LINE 200: Because there is no empty string case + // LCOV_EXCL_START 200: Because there is no empty string case + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, " Invalid configuration file name detected."); + l_eStatus = eFrameworkunifiedStatusInvldParam; + // LCOV_EXCL_STOP + } else { + // FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__, "Reading Configuration Data from %s", f_filePathAndName.c_str()); + + CNSConfigReader *l_pReaderCfg = new CNSConfigReader(); // LCOV_EXCL_BR_LINE 11:except,C++ STL + if (NULL == l_pReaderCfg) { // LCOV_EXCL_BR_LINE 5:new error + // LCOV_EXCL_START 5:new error + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, + " Error. Unable to allocate CNSConfigReader object."); + l_eStatus = eFrameworkunifiedStatusFileLoadError; + // LCOV_EXCL_STOP + } else { + if (eFrameworkunifiedStatusOK != (l_eStatus = l_pReaderCfg->Parse(f_filePathAndName))) { // LCOV_EXCL_BR_LINE 200:To ensure success // NOLINT[whitespace/line_length] + // LCOV_EXCL_START 200:To ensure success + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, + " Error. l_pReaderCfg->Parse(%s) returned: 0x%X", + f_filePathAndName.c_str(), l_eStatus); + // LCOV_EXCL_STOP + } else if (eFrameworkunifiedStatusOK != (l_eStatus = l_pReaderCfg->GetInt("LOGGING.LogMaxFileSize", m_logMaxFileSize))) { // LCOV_EXCL_BR_LINE 200:To ensure success // NOLINT[whitespace/line_length] + // LCOV_EXCL_START 200:To ensure success + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + LOG_STATUS(l_eStatus, "l_pReaderCfg->GetInt(LOGGING.LogMaxFileSize)"); + // LCOV_EXCL_STOP + } else if (eFrameworkunifiedStatusOK != (l_eStatus = l_pReaderCfg->GetInt("LOGGING.PerformanceLogSize", m_performanceLogMaxFileSize))) { // LCOV_EXCL_BR_LINE 200:To ensure success // NOLINT[whitespace/line_length] + // LCOV_EXCL_START 200:To ensure success + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + LOG_STATUS(l_eStatus, "l_pReaderCfg->GetInt(LOGGING.LogMaxFileSize)"); + // LCOV_EXCL_STOP + } else if (eFrameworkunifiedStatusOK != (l_eStatus = l_pReaderCfg->GetString("LOGGING.EmmcOutputPath", m_emmcOutputPath))) { // LCOV_EXCL_BR_LINE 200:To ensure success // NOLINT[whitespace/line_length] + // LCOV_EXCL_START 200:To ensure success + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + LOG_STATUS(l_eStatus, "l_pReaderCfg->GetString(LOGGING.EmmcOutputPath)"); + // LCOV_EXCL_STOP + } else if (eFrameworkunifiedStatusOK != (l_eStatus = l_pReaderCfg->GetString("LOGGING.EmmcOutputNaviLogPath", m_emmcOutputNaviLogPath))) { // LCOV_EXCL_BR_LINE 200:To ensure success // NOLINT[whitespace/line_length] + // LCOV_EXCL_START 200:To ensure success + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + LOG_STATUS(l_eStatus, + "l_pReaderCfg->GetString(LOGGING.EmmcOutputNaviLogPath)"); + // LCOV_EXCL_STOP + } else if (eFrameworkunifiedStatusOK != (l_eStatus = l_pReaderCfg->GetString("LOGGING.Usb0MountPath", m_usb0MountPath))) { // LCOV_EXCL_BR_LINE 200:To ensure success // NOLINT[whitespace/line_length] + // LCOV_EXCL_START 200:To ensure success + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + LOG_STATUS(l_eStatus, "l_pReaderCfg->GetString(LOGGING.Usb0MountPath)"); + // LCOV_EXCL_STOP + } else if (eFrameworkunifiedStatusOK != (l_eStatus = l_pReaderCfg->GetString("LOGGING.Usb1MountPath", m_usb1MountPath))) { // LCOV_EXCL_BR_LINE 200:To ensure success // NOLINT[whitespace/line_length] + // LCOV_EXCL_START 200:To ensure success + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + LOG_STATUS(l_eStatus, "l_pReaderCfg->GetString(LOGGING.Usb1MountPath)"); + // LCOV_EXCL_STOP + } else if (eFrameworkunifiedStatusOK != (l_eStatus = l_pReaderCfg->GetString("LOGGING.SdMountPath", m_sdMountPath))) { // LCOV_EXCL_BR_LINE 200:To ensure success // NOLINT[whitespace/line_length] + // LCOV_EXCL_START 200:To ensure success + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + LOG_STATUS(l_eStatus, "l_pReaderCfg->GetString(LOGGING.SdMountPath)"); + // LCOV_EXCL_STOP + } else if (eFrameworkunifiedStatusOK != (l_eStatus = l_pReaderCfg->GetInt("LOGGING.EmmcOutputMax", m_emmcOutputMax))) { // LCOV_EXCL_BR_LINE 200:To ensure success // NOLINT[whitespace/line_length] + // LCOV_EXCL_START 200:To ensure success + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + LOG_STATUS(l_eStatus, "l_pReaderCfg->GetString(LOGGING.EmmcOutputMax)"); + // LCOV_EXCL_STOP + } else if (eFrameworkunifiedStatusOK != (l_eStatus = l_pReaderCfg->GetInt("LOGGING.EmmcOutputErrMax", m_emmcOutputErrMax))) { // LCOV_EXCL_BR_LINE 200:To ensure success // NOLINT[whitespace/line_length] + // LCOV_EXCL_START 200:To ensure success + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + LOG_STATUS(l_eStatus, + "l_pReaderCfg->GetString(LOGGING.EmmcOutputErrMax)"); + // LCOV_EXCL_STOP + } else if (eFrameworkunifiedStatusOK != (l_eStatus = l_pReaderCfg->GetInt("LOGGING.EmmcOutputGrpRelaunchMax", m_emmcOutputGrpRelaunchMax))) { // LCOV_EXCL_BR_LINE 200:To ensure success // NOLINT[whitespace/line_length] + // LCOV_EXCL_START 200:To ensure success + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + LOG_STATUS(l_eStatus, + "l_pReaderCfg->GetString(LOGGING.EmmcOutputGrpRelaunchMax)"); + // LCOV_EXCL_STOP + } else if (eFrameworkunifiedStatusOK != (l_eStatus = l_pReaderCfg->GetInt("LOGGING.EmmcOutputNaviLogMax", m_emmcOutputNaviLogMax))) { // LCOV_EXCL_BR_LINE 200:To ensure success // NOLINT[whitespace/line_length] + // LCOV_EXCL_START 200:To ensure success + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + LOG_STATUS(l_eStatus, + "l_pReaderCfg->GetString(LOGGING.EmmcOutputNaviLogMax)"); + // LCOV_EXCL_STOP + } else if (eFrameworkunifiedStatusOK != (l_eStatus = l_pReaderCfg->GetInt("LOGGING.EmmcOutputNaviLogNmlMax", m_emmcOutputNaviLogNmlMax))) { // LCOV_EXCL_BR_LINE 200:To ensure success // NOLINT[whitespace/line_length] + // LCOV_EXCL_START 200:To ensure success + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + LOG_STATUS(l_eStatus, + "l_pReaderCfg->GetString(LOGGING.EmmcOutputNaviLogNmlMax)"); + // LCOV_EXCL_STOP + } else if (eFrameworkunifiedStatusOK != (l_eStatus = l_pReaderCfg->GetInt("LOGGING.EmmcOutputNaviLogErrMax", m_emmcOutputNaviLogErrMax))) { // LCOV_EXCL_BR_LINE 200:To ensure success // NOLINT[whitespace/line_length] + // LCOV_EXCL_START 200:To ensure success + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + LOG_STATUS(l_eStatus, + "l_pReaderCfg->GetString(LOGGING.EmmcOutputNaviLogErrMax)"); + // LCOV_EXCL_STOP + } else if (eFrameworkunifiedStatusOK != (l_eStatus = l_pReaderCfg->GetString("STORAGE.ThreadName", m_loggerStorageInfo.Name))) { // LCOV_EXCL_BR_LINE 200:To ensure success // NOLINT[whitespace/line_length] + // LCOV_EXCL_START 200:To ensure success + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + LOG_STATUS(l_eStatus, "l_pReaderCfg->GetString(STORAGE.ThreadName)"); + // LCOV_EXCL_STOP + } else if (eFrameworkunifiedStatusOK != (l_eStatus = l_pReaderCfg->GetInt("STORAGE.Priority", m_loggerStorageInfo.Priority))) { // LCOV_EXCL_BR_LINE 200:To ensure success // NOLINT[whitespace/line_length] + // LCOV_EXCL_START 200:To ensure success + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + LOG_STATUS(l_eStatus, "l_pReaderCfg->GetInt(STORAGE.Priority)"); + // LCOV_EXCL_STOP + } else if (eFrameworkunifiedStatusOK != (l_eStatus = l_pReaderCfg->GetInt("STORAGE.Timeout", m_loggerStorageInfo.Timeout))) { // LCOV_EXCL_BR_LINE 200:To ensure success // NOLINT[whitespace/line_length] + // LCOV_EXCL_START 200:To ensure success + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + LOG_STATUS(l_eStatus, "l_pReaderCfg->GetInt(STORAGE.Timeout)"); + // LCOV_EXCL_STOP + } else if (eFrameworkunifiedStatusOK != (l_eStatus = l_pReaderCfg->GetInt("STORAGE.TimeoutAfter", m_loggerStorageInfo.TimeoutAfter))) { // LCOV_EXCL_BR_LINE 200:To ensure success // NOLINT[whitespace/line_length] + // LCOV_EXCL_START 200:To ensure success + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + LOG_STATUS(l_eStatus, "l_pReaderCfg->GetInt(STORAGE.TimeoutAfter)"); + // LCOV_EXCL_STOP + } else if (eFrameworkunifiedStatusOK != (l_eStatus = l_pReaderCfg->GetInt("LOGGING.ExternalLogNum", m_ExternalLogList.num))) { // LCOV_EXCL_BR_LINE 200:To ensure success // NOLINT[whitespace/line_length] + LOG_STATUS(l_eStatus, "l_pReaderCfg->GetString(LOGGING.ExternalLogNum)"); // LCOV_EXCL_LINE 200:To ensure success // NOLINT[whitespace/line_length] + } else if (eFrameworkunifiedStatusOK != (l_eStatus = l_pReaderCfg->GetInt("LOGGING.ExternalLogMax", m_ExternalLogList.max))) { // LCOV_EXCL_BR_LINE 200:To ensure success // NOLINT[whitespace/line_length] + LOG_STATUS(l_eStatus, "l_pReaderCfg->GetString(LOGGING.ExternalLogMax)"); // LCOV_EXCL_LINE 200:To ensure success // NOLINT[whitespace/line_length] + } else { + RemoveCarriageReturn(m_emmcOutputPath); + RemoveCarriageReturn(m_emmcOutputNaviLogPath); + RemoveCarriageReturn(m_usb0MountPath); + RemoveCarriageReturn(m_usb1MountPath); + RemoveCarriageReturn(m_sdMountPath); + RemoveCarriageReturn(m_loggerStorageInfo.Name); + + for (UI_32 i = 0; i < ZONE_MASK_ARRAY_ELTS; i++) { + SI_32 l_logMaskTemp; + std::stringstream l_cfgParamName; + + l_cfgParamName << "SETLOGMASK.MASK" << i; + if (eFrameworkunifiedStatusOK != (l_eStatus = l_pReaderCfg->GetInt(l_cfgParamName.str(), l_logMaskTemp))) { // LCOV_EXCL_BR_LINE 200:To ensure success // NOLINT[whitespace/line_length] + // LCOV_EXCL_START 200:To ensure success + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, + " Error. l_pReaderCfg->GetInt(%s) failed with error: %d.", + l_cfgParamName.str().c_str(), l_eStatus); + + break; + // LCOV_EXCL_STOP + } else { + m_logMask[i] = (UI_32) l_logMaskTemp; + } + } + + m_EELStorageRelPath = "/EEL_export"; + m_EELActivateRelPath = "/EEL_activate"; + m_LoggerserviceEmmcLogsRelPath = "/LOGGERSERVICE_EMMC_LOGS"; + + if (m_ExternalLogList.num > 0) { + std::string str = "EXTERNAL_"; // LCOV_EXCL_BR_LINE 11:Excluded due to gcov constraints (others) + UI_32 num = 0; + + if (m_ExternalLogList.num <= m_ExternalLogList.max) { + num = m_ExternalLogList.num; + } else { + num = m_ExternalLogList.max; + } + + // LCOV_EXCL_BR_START 11:Excluded due to gcov constraints (others) + m_ExternalLogList.p_info = new ExternalLogInfo[num]; + + // Load external log info + for (UI_32 i = 0; i < num; i++) { + std::string query = str + std::to_string(i+1); + if (eFrameworkunifiedStatusOK != + (l_eStatus = l_pReaderCfg->GetString((query+".OutputPath"), m_ExternalLogList.p_info[i].dirname))) { + LOG_STATUS(l_eStatus, "l_pReaderCfg->GetString(EXTERNAL.OutputPath)"); // LCOV_EXCL_LINE 200:To ensure success // NOLINT[whitespace/line_length] + } else if (eFrameworkunifiedStatusOK != + (l_eStatus = l_pReaderCfg->GetString((query+".ExtLogPath"), m_ExternalLogList.p_info[i].path))) { + LOG_STATUS(l_eStatus, "l_pReaderCfg->GetString(EXTERNAL.ExtLogPath)"); // LCOV_EXCL_LINE 200:To ensure success // NOLINT[whitespace/line_length] + } else if (eFrameworkunifiedStatusOK != + (l_eStatus = l_pReaderCfg->GetBool((query+".Remove"), m_ExternalLogList.p_info[i].remove))) { + LOG_STATUS(l_eStatus, "l_pReaderCfg->GetBool(EXTERNAL.Remove)"); // LCOV_EXCL_LINE 200:To ensure success // NOLINT[whitespace/line_length] + } else { + RemoveCarriageReturn(m_ExternalLogList.p_info[i].dirname); + RemoveCarriageReturn(m_ExternalLogList.p_info[i].path); + } + } + // LCOV_EXCL_BR_STOP 11:Excluded due to gcov constraints (others) + } else { + // None external log + } + + if (eFrameworkunifiedStatusOK == l_eStatus) { // LCOV_EXCL_BR_LINE 200:To ensure success + FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__, + " Info. Configuration successfully loaded."); // LCOV_EXCL_BR_LINE 15: macro + } + } + + delete l_pReaderCfg; // LCOV_EXCL_BR_LINE 11:Unexpected branch + } + } + + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-"); + return (l_eStatus); +} + +EFrameworkunifiedStatus CLoggerCfg::Validate(void) { + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+"); + EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusInvldParam; + + if (m_logMaxFileSize == 0) { // LCOV_EXCL_BR_LINE 200:Because the size is never 0 + // LCOV_EXCL_START 200:Because the size is never 0 + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + FRAMEWORKUNIFIEDLOG( + ZONE_ERR, + __FUNCTION__, + " Error. Invalid configuration detected. LogMaxFileSize: %d Must be > 0.", + m_logMaxFileSize); + // LCOV_EXCL_STOP + } else if (m_emmcOutputPath == "") { + FRAMEWORKUNIFIEDLOG( + ZONE_ERR, + __FUNCTION__, + " Error. Invalid configuration detected." + " EmmcOutputPath: %s Must be a valid path containing a trailing backslash.", + m_emmcOutputPath.c_str()); + } else if (m_emmcOutputNaviLogPath == "") { // LCOV_EXCL_BR_LINE 200:Because it is not always an empty string + // LCOV_EXCL_START 200:Because it is not always an empty string + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + FRAMEWORKUNIFIEDLOG( + ZONE_ERR, + __FUNCTION__, + " Error. Invalid configuration detected." + " EmmcOutputNaviLogPath: %s Must be a valid path containing a trailing backslash.", + m_emmcOutputNaviLogPath.c_str()); + // LCOV_EXCL_STOP + } else if (m_usb0MountPath == "") { // LCOV_EXCL_BR_LINE 200:Because it is not always an empty string + // LCOV_EXCL_START 200:Because it is not always an empty string + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + FRAMEWORKUNIFIEDLOG( + ZONE_ERR, + __FUNCTION__, + " Error. Invalid configuration detected." + " Usb0MountPath: %s Must be a valid path containing a trailing backslash.", + m_usb0MountPath.c_str()); + // LCOV_EXCL_STOP + } else if (m_usb1MountPath == "") { // LCOV_EXCL_BR_LINE 200:Because it is not always an empty string + // LCOV_EXCL_START 200:Because it is not always an empty string + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + FRAMEWORKUNIFIEDLOG( + ZONE_ERR, + __FUNCTION__, + " Error. Invalid configuration detected." + " Usb1MountPath: %s Must be a valid path containing a trailing backslash.", + m_usb1MountPath.c_str()); + // LCOV_EXCL_STOP + } else if (m_sdMountPath == "") { // LCOV_EXCL_BR_LINE 200:Because it is not always an empty string + // LCOV_EXCL_START 200:Because it is not always an empty string + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + FRAMEWORKUNIFIEDLOG( + ZONE_ERR, + __FUNCTION__, + " Error. Invalid configuration detected. SdMountPath: %s Must be a valid path containing a trailing backslash.", + m_sdMountPath.c_str()); + // LCOV_EXCL_STOP + } else { + l_eStatus = eFrameworkunifiedStatusOK; + } + + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-"); + return (l_eStatus); +} + +void CLoggerCfg::Print(void) { + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+"); + + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-"); +} + +std::string CLoggerCfg::getEmmcOutputPath(void) { + return (m_emmcOutputPath); +} + +std::string CLoggerCfg::getEmmcOutputNaviLogPath(void) { + return (m_emmcOutputNaviLogPath); +} + +std::string CLoggerCfg::getUsb0MountPath(void) { + return (m_usb0MountPath); +} +void CLoggerCfg::setUsb0MountPath(std::string& f_deviceMountpath) { + m_usb0MountPath = f_deviceMountpath; +} + +EFrameworkunifiedStatus CLoggerCfg::GetUserInvokedDestination(std::string& f_dest) { + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+"); + EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK; + + f_dest = ""; + switch (m_eDevType) { + case eDevUSB1: + f_dest = m_usb0MountPath; + break; + + case eDevUSB2: + f_dest = m_usb1MountPath; + break; + + case eDevSD: + f_dest = m_sdMountPath; + break; + + case eTotalDevicesTypes: + case eInvalid_DevType: + default: + FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, " Error. Unknown device type: %d", + m_eDevType); + l_eStatus = eFrameworkunifiedStatusFail; + break; + } + + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-"); + return (l_eStatus); +} + +EFrameworkunifiedStatus CLoggerCfg::GetEmmcDestination(std::string& f_dest) { + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+"); + EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK; + + f_dest = m_emmcOutputPath; + + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-"); + return (l_eStatus); +} + +EFrameworkunifiedStatus CLoggerCfg::GetEmmcNaviLogDestination(std::string& f_dest) { + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+"); + EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK; + + f_dest = m_emmcOutputNaviLogPath; + + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-"); + return (l_eStatus); +} + +UI_32 CLoggerCfg::GetUserInvokedCounter(void) { + return m_UserInvokedLoggingNumber; +} + +EFrameworkunifiedStatus CLoggerCfg::GetIncrementAndPersistUserInvokedCounter( + HANDLE f_hApp, UI_32 &f_counter) { + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+"); + EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK; + + f_counter = m_UserInvokedLoggingNumber; + m_UserInvokedLoggingNumber++; + l_eStatus = PersistLoggingParam(f_hApp); + + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-"); + return (l_eStatus); +} + +EFrameworkunifiedStatus CLoggerCfg::GetAndIncrementEmmcCounter(UI_32 &f_counter) { + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+"); + EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK; + std::string l_checkFileName; + std::vector<UI_32> l_vector; + DIR *l_dirp; + struct dirent l_dirent; + struct dirent* next = NULL; + size_t l_pos; + UI_32 l_count; + UI_32 l_maxCount; + + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+"); + + if (m_EmmcCounter == 0u) { + l_maxCount = 0; + l_dirp = opendir(m_emmcOutputPath.c_str()); + if (l_dirp != NULL) { // LCOV_EXCL_BR_LINE 5: m_emmcOutputPath is not null, opendir is C code, always ok + for (;;) { + int l_ret = readdir_r(l_dirp, &l_dirent, &next); + if (((l_ret == 0) && (next == NULL)) + || (l_ret > 0)) { + break; + } + l_checkFileName = l_dirent.d_name; + l_pos = l_checkFileName.find(".tar.gz"); + if (std::string::npos != l_pos) { + l_pos = l_checkFileName.find("_"); + if (std::string::npos != l_pos) { // LCOV_EXCL_BR_LINE 200: tar.gz file is aways has "_" + std::string l_numberString = l_checkFileName.substr(0, l_pos); + l_count = static_cast<UI_32>(strtoul(l_numberString.c_str(), NULL, 10)); + l_vector.push_back(l_count); + l_maxCount = std::max(l_count, l_maxCount); + } + } + } + closedir(l_dirp); + } else { + // LCOV_EXCL_START 5: m_emmcOutputPath is not null, opendir is C code, always ok + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + f_counter = 1; + return eFrameworkunifiedStatusOK; + // LCOV_EXCL_STOP + } + + // reach at max number + if (l_maxCount >= LOGGERSERVICELOG_EMMC_COUNTER_MAX) { + RefreshEmmcCounter(m_EmmcCounter); + } else { + m_EmmcCounter = l_maxCount + 1; + } + } else if (m_EmmcCounter >= LOGGERSERVICELOG_EMMC_COUNTER_MAX) { + // reach at max number + RefreshEmmcCounter(m_EmmcCounter); + } else { + m_EmmcCounter++; + } + + f_counter = m_EmmcCounter; + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-"); + return (l_eStatus); +} + +EFrameworkunifiedStatus CLoggerCfg::RefreshEmmcCounter(UI_32& f_counter) const { + EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK; + std::string l_checkFileName; + std::vector<std::string> l_vector; + DIR *l_dirp; + struct dirent l_dirent; + struct dirent* next = NULL; + size_t l_pos; + + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+"); + + // get filename saved frameworkunifiedlog on eMMC Device + l_dirp = opendir(m_emmcOutputPath.c_str()); + if (l_dirp != NULL) { // LCOV_EXCL_BR_LINE 5: m_emmcOutputPath is not null, opendir is C code, always ok + for (;;) { + int l_ret = readdir_r(l_dirp, &l_dirent, &next); + if (((l_ret == 0) && (next == NULL)) || (l_ret > 0)) { + break; + } + l_checkFileName = l_dirent.d_name; + l_pos = l_checkFileName.find(".tar.gz"); + if (std::string::npos != l_pos) { + l_pos = l_checkFileName.find("_"); + if (std::string::npos != l_pos) { + l_vector.push_back(l_checkFileName); + } + } + } + closedir(l_dirp); + } else { + // LCOV_EXCL_START 5: m_emmcOutputPath is not null, opendir is C code, always ok + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + // ignore opendir failure. this means saved frameworkunifiedlog is nothing on eMMC Device + FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "open dir error path=%s errno=%s.", + m_emmcOutputPath.c_str(), strerror(errno)); + f_counter = 1; + return eFrameworkunifiedStatusOK; + // LCOV_EXCL_STOP + } + + // sort at log count + std::sort(l_vector.begin(), l_vector.end()); + + std::vector<std::string>::iterator it; + std::string l_orgFilePath; + std::string l_renameFilePath; + UI_32 l_wpt = 0; + UI_32 l_count; + + it = l_vector.begin(); + while (it != l_vector.end()) { + std::stringstream l_nameStream; + // get log counter parts + l_wpt++; + l_checkFileName = *it; + l_pos = l_checkFileName.find("_"); + std::string l_numberString = l_checkFileName.substr(0, l_pos); + l_count = static_cast<UI_32>(strtoul(l_numberString.c_str(), NULL, 10)); + + // rename file if necessary + if (l_count != l_wpt) { + l_renameFilePath = l_orgFilePath = m_emmcOutputPath.c_str(); + l_renameFilePath.append("/"); + l_orgFilePath.append("/"); + l_orgFilePath.append(l_checkFileName); + + l_nameStream << std::setw(5) << std::setfill('0') << std::right + << std::dec << l_wpt; + l_checkFileName.replace(0, l_pos, l_nameStream.str()); + + l_renameFilePath.append(l_checkFileName); + + if (rename(l_orgFilePath.c_str(), l_renameFilePath.c_str()) != 0) { // LCOV_EXCL_BR_LINE 5: rename is C code + // LCOV_EXCL_START 5: rename is C code + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + // rename failed but continue reamin log rename because new log need to be saved. + FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, + "log file[%s]->[%s] rename failed: err=%s.", + l_orgFilePath.c_str(), l_renameFilePath.c_str(), strerror(errno)); + // LCOV_EXCL_STOP + } + } + it++; + } + + f_counter = l_wpt + 1; + + // set return value as next log counter + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-"); + return l_eStatus; +} + +BOOL CLoggerCfg::IsUDPLoggingEnabled(void) { + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+"); + BOOL l_ret = + ((this->m_eLoggerUDPLoggingStatus == eActivate) + || (this->m_udpEnvFlag == TRUE)) ? TRUE : FALSE; + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "- : %s", (TRUE == l_ret)?"TRUE":"FALSE"); + return (l_ret); +} + +void CLoggerCfg::AddLoggingParamCB(CbFuncPtr f_fp) { + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+"); + if (f_fp != NULL) { // LCOV_EXCL_BR_LINE 6: it aways not be null + this->m_LoggingCallBack.push_back(f_fp); + (void) f_fp(NULL); + } + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-"); +} + +void CLoggerCfg::UpdateLoggingStatus(void) { + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+"); + std::vector<CbFuncPtr>::iterator l_iter; + for (l_iter = m_LoggingCallBack.begin(); l_iter != m_LoggingCallBack.end(); l_iter++) { // LCOV_EXCL_BR_LINE 11:Unexpected branch // NOLINT[whitespace/line_length] + (void) (*l_iter)(NULL); + } + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-"); +} + +EFrameworkunifiedStatus CLoggerCfg::GetLoggerStorageInfo(SLoggerStorageInfo &f_info) { + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+"); + EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK; + f_info = m_loggerStorageInfo; + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-"); + return (l_eStatus); +} + +BOOL CLoggerCfg::IsLoggingEnabled(void) { + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+"); + return (this->m_eLoggerStatus == eActivate) ? TRUE : FALSE; + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-"); +} + +ExternalLogList CLoggerCfg::GetExternalLogList(void) { + return (m_ExternalLogList); +} // LCOV_EXCL_BR_LINE 10:the last line diff --git a/systemservice/logger_service/server/src/ss_logger_device_detection.cpp b/systemservice/logger_service/server/src/ss_logger_device_detection.cpp new file mode 100755 index 0000000..04bc4b5 --- /dev/null +++ b/systemservice/logger_service/server/src/ss_logger_device_detection.cpp @@ -0,0 +1,209 @@ +/* + * @copyright Copyright (c) 2016-2020 TOYOTA MOTOR CORPORATION. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/////////////////////////////////////////////////////////////////////////////// +/// \ingroup tag_NS_InterfaceunifiedLogCapture +/// \brief This file supports USB logging threads. +/// +/////////////////////////////////////////////////////////////////////////////// + +// System Headers +#include <errno.h> +#include <stdio.h> +#include <stddef.h> +#include <stdlib.h> +#include <unistd.h> +#include <fcntl.h> +#ifdef AGL_STUB +#else +#include <sys/usbdi.h> +#endif +#include <limits.h> +#include <string.h> +#include <native_service/ns_message_center_if.h> +#include <ss_logger_fs_directory.h> +#include <boost/bind.hpp> + +// Pasa Logs +#include <loggerservicedebug_loggerservicelog.h> +#include <ss_logger_device_detection.h> +#include <loggerservicedebug_thread_if.h> +#include <native_service/frameworkunified_framework_if.h> +#include <system_service/ss_logger_service.h> +#include <system_service/ss_devicedetection_service_notifications.h> +#include <system_service/ss_devicedetection_service_ifc.h> +#include <system_service/ss_sm_client_if.h> +#include <string> +#include "ss_logger_common.h" + +// +const SI_32 INVALID_FD = -1; + +// Max command line length +const UI_32 MAX_SYS_CMD_LN_LENGTH = 120; + +CLoggerDeviceDetection::CLoggerDeviceDetection() : + m_pLoggerCfg(NULL), + m_loggerUtil(NULL) { +} + +CLoggerDeviceDetection::~CLoggerDeviceDetection() { // LCOV_EXCL_START 14:global instance + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert +} +// LCOV_EXCL_STOP + +EFrameworkunifiedStatus CLoggerDeviceDetection::Initialize(HANDLE f_hApp, CLoggerCfg * f_pLoggerCfg) { + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+"); + EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK; + m_pLoggerCfg = f_pLoggerCfg; + // Device Detection Obj initialization + if (m_devDetect.Initialize(f_hApp)) { // LCOV_EXCL_BR_LINE 200:To ensure success + if (eFrameworkunifiedStatusOK != (l_eStatus = m_devDetect.NotifyOnDeviceDetectionAvailability( + boost::bind(&CLoggerDeviceDetection::DD_ServiceAvailabilityCallBack, this, _1) ))) { + FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "ServiceAvailabilityCallback registration failed"); + } + + if (eFrameworkunifiedStatusOK != (l_eStatus = m_devDetect.NotifyOnOpenSessionAck( + boost::bind(&CLoggerDeviceDetection::DD_OpenSessionAckCallBack, this, _1) ))) { + FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "OpenSessionAckCallback registration failed"); + } + + if (eFrameworkunifiedStatusOK != (l_eStatus = m_devDetect.NotifyOnCloseSessionAck( + boost::bind(&CLoggerDeviceDetection::DD_CloseSessionAckCallBack, this, _1) ))) { + FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "CloseSessionCallback registration failed"); + } + } else { + // LCOV_EXCL_START 200:To ensure success + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "Device Detection Object Initialization failed!"); + // LCOV_EXCL_STOP + } + + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-"); + return l_eStatus; +} + +////////////////////////////////////////// +// Function : ServiceAvailabilityCallBack +////////////////////////////////////////// +EFrameworkunifiedStatus CLoggerDeviceDetection::DD_ServiceAvailabilityCallBack(HANDLE hApp) { + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+"); + EFrameworkunifiedStatus eStatus = eFrameworkunifiedStatusOK; + + if (FrameworkunifiedIsServiceAvailable(hApp)) { + if (eFrameworkunifiedStatusOK != (eStatus = m_devDetect.OpenSessionRequest())) { + FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "Open session request failed"); + } + } else { + if (eFrameworkunifiedStatusOK != (eStatus = m_devDetect.CloseSessionRequest())) { + FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "Close session request failed"); + } + } + + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-"); + return eStatus; +} + +////////////////////////////////////////// +// Function : OpenSessionAckCallBack +////////////////////////////////////////// +EFrameworkunifiedStatus CLoggerDeviceDetection::DD_OpenSessionAckCallBack(HANDLE hApp) { + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+"); + EFrameworkunifiedStatus eStatus = eFrameworkunifiedStatusOK; + + if (eFrameworkunifiedStatusOK == (eStatus = m_devDetect.DecodeOpenSessionResponse())) { + if (eFrameworkunifiedStatusOK != (eStatus = m_devDetect.RegisterForDeviceDetectionEvent(SS_DEV_DETECT_ANY_USB_EV, + boost::bind(&CLoggerDeviceDetection::DD_MediaDetectCallBack, this, _1)))) { + FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "Registration for SS_DEV_DETECT_ANY_USB_EV failed"); + } + } else { + FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "Decode open session response failed"); + } + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-"); + return eStatus; +} +////////////////////////////////////////// +// Function : OpenSessionAckCallBack +////////////////////////////////////////// +EFrameworkunifiedStatus CLoggerDeviceDetection::DD_CloseSessionAckCallBack(HANDLE hApp) { // LCOV_EXCL_START 200: can not called from devicedetection_service // NOLINT[whitespace/line_length] + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+"); + EFrameworkunifiedStatus eStatus = eFrameworkunifiedStatusOK; + CloseSessionAck tCloseSessionAck; + + if (hApp) { + if (eFrameworkunifiedStatusOK == (eStatus = FrameworkunifiedGetMsgDataOfSize(hApp, &tCloseSessionAck, sizeof (tCloseSessionAck)))) { + if (eFrameworkunifiedStatusOK == tCloseSessionAck.eStatus) { + UI_32 l_uiSessionId = tCloseSessionAck.sessionId; + FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__, "session %d closed successfully", l_uiSessionId); + } + } + } + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-"); + return eStatus; +} +// LCOV_EXCL_STOP + +EFrameworkunifiedStatus CLoggerDeviceDetection::DD_CloseSessionWithDevDetectionSrv(HANDLE hApp) { // LCOV_EXCL_START 200: can not called from devicedetection_service // NOLINT[whitespace/line_length] + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+"); + EFrameworkunifiedStatus eStatus = eFrameworkunifiedStatusOK; + + if (eFrameworkunifiedStatusOK == (eStatus = m_devDetect. + NotifyOnCloseSessionAck(boost::bind(&CLoggerDeviceDetection::DD_CloseSessionAckCallBack, this, _1)))) { + if (eFrameworkunifiedStatusOK != (eStatus = m_devDetect.CloseSessionRequest())) { + FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "Failed to send CloseSessionRequest"); + } + } else { + FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "Failed to register closeSessionAckCallback"); + } + + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-"); + return eStatus; +} +// LCOV_EXCL_STOP + +EFrameworkunifiedStatus CLoggerDeviceDetection::DD_MediaDetectCallBack(HANDLE hApp) { // LCOV_EXCL_START 200: can not called from devicedetection_service // NOLINT[whitespace/line_length] + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+"); + EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK; + std::string l_devstr; + std::string l_filePathStr; + SS_MediaDetectInfo l_tMediaDetectInfo; + + + if (eFrameworkunifiedStatusOK != (l_eStatus = FrameworkunifiedGetMsgDataOfSize(hApp, &l_tMediaDetectInfo, sizeof (l_tMediaDetectInfo)))) { + FRAMEWORKUNIFIEDLOG(ZONE_ERR, __PRETTY_FUNCTION__, "FrameworkunifiedGetMsgDataOfSize Failed Status:0x%x ", l_eStatus); + } else { + FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__, " Device = %d", l_tMediaDetectInfo.dev_type); + FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__, " Availability = %d", l_tMediaDetectInfo.bIsDeviceAvailable); + FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__, " device path = %s", l_tMediaDetectInfo.deviceMountpath); + FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__, " File path = %s", l_tMediaDetectInfo.filepathName); + + if (l_tMediaDetectInfo.dev_type == eUSB) { + if (l_tMediaDetectInfo.bIsDeviceAvailable == TRUE && m_pLoggerCfg != NULL) { + std::string l_usbMountPath; + l_usbMountPath = l_tMediaDetectInfo.deviceMountpath; + m_pLoggerCfg->setUsb0MountPath(l_usbMountPath); + m_loggerUtil->SetUsbMountPath(l_usbMountPath); + } + } + } + + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-"); + return (l_eStatus); +} +// LCOV_EXCL_STOP diff --git a/systemservice/logger_service/server/src/ss_logger_error_event.cpp b/systemservice/logger_service/server/src/ss_logger_error_event.cpp new file mode 100755 index 0000000..6e82da7 --- /dev/null +++ b/systemservice/logger_service/server/src/ss_logger_error_event.cpp @@ -0,0 +1,1047 @@ +/* + * @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_SS_LoggerService +/// \brief This file supports error event logging. +/// +/////////////////////////////////////////////////////////////////////////////// +#include "ss_logger_error_event.h" +#include <string.h> +#include <sys/types.h> +#include <sys/stat.h> +#include <boost/bind.hpp> +#include <unistd.h> +#include <sys/wait.h> +#include <native_service/frameworkunified_framework_if.h> +#include <system_service/ss_sm_client_if.h> +#include <system_service/ss_client_names.h> +#include <system_service/ss_logger_service_protocol.h> +#include <system_service/ss_logger_service.h> +#include <system_service/ss_services.h> +#include <system_service/ss_templates.h> +#include <stub/el_mem.h> +#include <native_service/cl_process.h> +#include <stub/Clock_API.h> +#include <string> +#include "loggerservicedebug_loggerservicelog.h" +#include "loggerservicedebug_thread_if.h" +#include "ss_logger_service_callbacks.h" +#include "ss_logger_error_event_archive.h" +#include "ss_logger_common.h" +#include "ss_logger_types.h" +#include "ss_logger_fs_directory.h" + +CErrorEvent::CErrorEvent() + : m_hApp(NULL), + m_bIsPrevEventCompleted(true), + m_errorEventNtfData(), + m_pLoggerCfg(NULL), + m_pReaderWriterControl(NULL), + m_ServiceName(""), + m_time(0), + m_currentEventTriggerNumber(0), + m_diagsessionhandle(NULL), + m_thrdEvntLogWriter(NULL), + m_sfd(-1) { // LCOV_EXCL_BR_LINE 11:Unexpected branch + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+"); + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-"); +} // LCOV_EXCL_BR_LINE 11:Unexpected branch + +CErrorEvent::~CErrorEvent() { // LCOV_EXCL_START 14:globle instance + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+"); + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-"); +} +// LCOV_EXCL_STOP + +EFrameworkunifiedStatus CErrorEvent::Initialize(HANDLE f_hApp, CLoggerCfg *f_pLoggerCfg, + CReaderWriterControl *f_pReaderWriterControl, + HANDLE f_thrdEvntLogWriter, + std::string f_strEvntLogQueWorkerName) { + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+"); + EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK; + Timer *l_pTimer; + + m_sfd = CL_ProcessInit(); + if (m_sfd == -1) { // LCOV_EXCL_BR_LINE 8:Because the process initialization is guaranteed to be successful + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, " Error. m_sfd CL_ProcessInit() failed \n."); // LCOV_EXCL_LINE 8:Because the process initialization is guaranteed to be successful + } + + SS_LoggerServerEvents l_errorEventStateEvents[] = { + SS_LOGGER_SCREENCAPTURE_EVT }; + + FrameworkunifiedProtocolCallbackHandler l_smCallbacks[] = { + // Logging Protocol Callbacks + { SS_SM_EVENT_ERROR_TO_SSL, boost::bind(&CErrorEvent::OnStartLogging, + this, _1) }, { + SS_SM_ERROR_EVENT_LOGGING_START_RSPN, boost::bind( + &CErrorEvent::OnLogStartResponse, this, _1) }, { + SS_SM_ERROR_EVENT_ARTIFACT_RSPN, boost::bind( + &CErrorEvent::OnArtifactResponse, this, _1) } }; // LCOV_EXCL_BR_LINE 11:Unexpected branch + + FrameworkunifiedProtocolCallbackHandler l_selfCallbacks[] = { + // Logging Protocol Callbacks + { SS_LOGGER_ERROR_EVENT_ARTIFACT_REQ, boost::bind( + &CErrorEvent::OnArtifactRequest, this, _1) }, { + SS_SM_ERROR_EVENT_ARTIFACT_RSPN, boost::bind( + &CErrorEvent::OnArtifactResponse, this, _1) } }; // LCOV_EXCL_BR_LINE 11:Unexpected branch + + FrameworkunifiedProtocolCallbackHandler l_requesterCallbacks[] = { { + SS_LOGGER_SCREENCAPTURE_EVT_ACK, boost::bind( + &CErrorEvent::OnObtainScreenShotResponse, this, _1) } }; // LCOV_EXCL_BR_LINE 11:Unexpected branch + + FrameworkunifiedProtocolCallbackHandler l_storageThreadCallbacks[] = { { + eLoggerStorageThreadCmdOK, boost::bind(&CErrorEvent::OnStorageResponseOk, + this, _1) }, { + eLoggerStorageThreadCmdWriteFailed, boost::bind( + &CErrorEvent::OnStorageResponseWriteFailed, this, _1) }, { + eLoggerStorageThreadCmdNotFound, boost::bind( + &CErrorEvent::OnStorageResponseNotFound, this, _1) }, { + eLoggerStorageThreadCmdNoWritten, boost::bind( + &CErrorEvent::OnStorageResponseNoWritten, this, _1) } }; // LCOV_EXCL_BR_LINE 11:Unexpected branch + for (UI_32 i = 0; i < _countof(l_requesterCallbacks); i++) { + m_requesterCallbacksVec.push_back(l_requesterCallbacks[i]); // LCOV_EXCL_BR_LINE 11:Unexpected branch + } + + if (NULL == f_hApp) { // LCOV_EXCL_BR_LINE 6:As it is not always NULL + // LCOV_EXCL_START 6:As it is not always NULL + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + l_eStatus = eFrameworkunifiedStatusInvldHandle; + FRAMEWORKUNIFIEDLOG( + ZONE_ERR, __FUNCTION__, + " Error. Argument f_hApp passed NULL pointer. Initialization failed."); + // LCOV_EXCL_STOP + } else if (NULL == (m_thrdEvntLogWriter = f_thrdEvntLogWriter)) { // LCOV_EXCL_BR_LINE 6:As it is not always NULL + // LCOV_EXCL_START 6:As it is not always NULL + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + l_eStatus = eFrameworkunifiedStatusInvldHandle; + FRAMEWORKUNIFIEDLOG( + ZONE_ERR, __FUNCTION__, + " Error. Argument f_hApp passed NULL pointer. Initialization failed."); + // LCOV_EXCL_STOP + } else if (eFrameworkunifiedStatusOK != (l_eStatus = m_errorEventCfg.Initialize(f_pLoggerCfg))) { // LCOV_EXCL_BR_LINE 200:To ensure success + // LCOV_EXCL_START 200:To ensure success + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, + " Error. m_errorEventCfg.Initialize() returned: %d.", l_eStatus); + // LCOV_EXCL_STOP + } else if (eFrameworkunifiedStatusOK != (l_eStatus = FrameworkunifiedAttachCallbacksToDispatcher(f_hApp, SERVICE_LOGGER, l_selfCallbacks, _countof(l_selfCallbacks)))) { // LCOV_EXCL_BR_LINE 4:NSFW // NOLINT[whitespace/line_length] + // LCOV_EXCL_START 4:NSFW + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + FRAMEWORKUNIFIEDLOG( + ZONE_ERR, + __FUNCTION__, + " Error. FrameworkunifiedAttachCallbacksToDispatcher(SERVICE_SYSMANAGER) returned: %d.", + l_eStatus); + // LCOV_EXCL_STOP + } else if (eFrameworkunifiedStatusOK != (l_eStatus = FrameworkunifiedAttachCallbacksToDispatcher(f_hApp, SERVICE_SYSMANAGER, l_smCallbacks, _countof(l_smCallbacks)))) { // LCOV_EXCL_BR_LINE 4:NSFW // NOLINT[whitespace/line_length] + // LCOV_EXCL_START 4:NSFW + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + FRAMEWORKUNIFIEDLOG( + ZONE_ERR, + __FUNCTION__, + " Error. FrameworkunifiedAttachCallbacksToDispatcher(SERVICE_SYSMANAGER) returned: %d.", + l_eStatus); + // LCOV_EXCL_STOP + } else if (eFrameworkunifiedStatusOK != (l_eStatus = FrameworkunifiedDefineStateEvents(f_hApp, &l_errorEventStateEvents, static_cast<UI_32>(_countof(l_errorEventStateEvents))))) { // LCOV_EXCL_BR_LINE 4:NSFW // NOLINT[whitespace/line_length] + // LCOV_EXCL_START 4:NSFW + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + FRAMEWORKUNIFIEDLOG( + ZONE_ERR, + __FUNCTION__, + " Error. FrameworkunifiedDefineStateEvents(SS_LOGGER_SCREENCAPTURE_EVT) returned: %d", + l_eStatus); + // LCOV_EXCL_STOP + } else if (NULL == f_pLoggerCfg) { // LCOV_EXCL_BR_LINE 200:As it is not always NULL + // LCOV_EXCL_START 200:As it is not always NULL + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + l_eStatus = eFrameworkunifiedStatusNullPointer; + FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, " Error. f_pLoggerCfg passed NULL pointer."); + // LCOV_EXCL_STOP + } else if (eFrameworkunifiedStatusOK != (l_eStatus = m_loggerPopups.Initialize(f_pLoggerCfg))) { // LCOV_EXCL_BR_LINE 200:To ensure success // NOLINT[whitespace/line_length] + // LCOV_EXCL_START 200:To ensure success + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, + " Error. m_loggerPopups.Initialize(f_pLoggerCfg) returned: %d.", + l_eStatus); + // LCOV_EXCL_STOP + } else if (NULL == f_pReaderWriterControl) { // LCOV_EXCL_BR_LINE 200:As it is not always NULL + // LCOV_EXCL_START 200:As it is not always NULL + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + l_eStatus = eFrameworkunifiedStatusNullPointer; + FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, + " Error. Argument f_pReaderWriterControl passed NULL pointer."); + // LCOV_EXCL_STOP + } else if (eFrameworkunifiedStatusOK != (l_eStatus = m_loggerStorage.Initialize(f_hApp, AppName, f_pLoggerCfg))) { // LCOV_EXCL_BR_LINE 200:To ensure success // NOLINT[whitespace/line_length] + // LCOV_EXCL_START 200:To ensure success + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, + " Error. m_loggerPopups.Initialize(f_pLoggerCfg) returned: %d.", + l_eStatus); + // LCOV_EXCL_STOP + } else if (eFrameworkunifiedStatusOK != (l_eStatus = FrameworkunifiedAttachCallbacksToDispatcher( f_hApp, ERROR_EVENT_STORAGE_QUEUE_NAME, l_storageThreadCallbacks, _countof(l_storageThreadCallbacks)))) { // LCOV_EXCL_BR_LINE 4:NSFW // NOLINT[whitespace/line_length] + // LCOV_EXCL_START 4:NSFW + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + FRAMEWORKUNIFIEDLOG( + ZONE_ERR, + __FUNCTION__, + " Error. FrameworkunifiedAttachCallbacksToDispatcher(ERROR_EVENT_STORAGE_QUEUE_NAME) returned: %d.", + l_eStatus); + // LCOV_EXCL_STOP + } else if (eFrameworkunifiedStatusOK != (l_eStatus = m_loggerCanEvent.Initialize(f_pLoggerCfg))) { // LCOV_EXCL_BR_LINE 200:To ensure success // NOLINT[whitespace/line_length] + // LCOV_EXCL_START 200:To ensure success + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, + " Error. m_loggerCanEvent.Initialize() returned: %d.", l_eStatus); + // LCOV_EXCL_STOP + } else { + m_hApp = f_hApp; + m_pLoggerCfg = f_pLoggerCfg; + m_pReaderWriterControl = f_pReaderWriterControl; + l_eStatus = m_loggerUtil.Initialize(m_pLoggerCfg); // LCOV_EXCL_BR_LINE 11:Unexpected branch + LOG_STATUS_IF_ERRORED(l_eStatus, // LCOV_EXCL_BR_LINE 5:macro + "CLoggerUtil::m_loggerUtil.Initialize(m_pLoggerCfg)"); + + l_pTimer = &m_errorEventTimers[kSSL_ERROR_EVENT_TIMER_LOGGING_START_RSPN]; + l_pTimer->Initialize( + f_hApp, SS_LOGGER_ERROR_EVENT_TIMER_ID_LOGGING_START_RSPN, + boost::bind(&CErrorEvent::OnLogStartResponseTimeout, this, _1)); // LCOV_EXCL_BR_LINE 11:Unexpected branch + + l_pTimer = &m_errorEventTimers[kSSL_ERROR_EVENT_TIMER_ARTIFACT_RSPN]; + l_pTimer->Initialize( + f_hApp, SS_LOGGER_ERROR_EVENT_TIMER_ID_ARTIFACT_RESPONSE, + boost::bind(&CErrorEvent::OnArtifactResponseTimeout, this, _1)); // LCOV_EXCL_BR_LINE 11:Unexpected branch + m_ServiceName = ""; + } + + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-"); + return (l_eStatus); +} + +/////////////////////////////////////////////////////////////////////////// +// Function : RegisterSessionErrorEvent +// brief : Register session event. This function is called within the +// context of the System Manager session acknowledgment handler. +/////////////////////////////////////////////////////////////////////////// +EFrameworkunifiedStatus CErrorEvent::RegisterSessionErrorEvent(HANDLE f_hSession) { + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+"); + EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK; + + l_eStatus = FrameworkunifiedRegisterEvent(f_hSession, SS_SM_EVENT_ERROR_TO_SSL); + LOG_STATUS_IF_ERRORED(l_eStatus, "FrameworkunifiedRegisterEvent(SS_SM_EVENT_ERROR_TO_SSL)"); // LCOV_EXCL_BR_LINE 5:macro + + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-"); + return (l_eStatus); +} + +/////////////////////////////////////////////////////////////////////////// +// Function : OnOpenSession +// brief : Called when a requester opens a session with SS_Logger +// service. This function attaches error event callbacks +// to the dispatcher with the source set to the requester. +/////////////////////////////////////////////////////////////////////////// +EFrameworkunifiedStatus CErrorEvent::OnOpenSession(HANDLE f_hApp, PCSTR f_pRequesterName, + HANDLE f_hSession) { + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+"); + EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK; + + l_eStatus = FrameworkunifiedAttachCallbacksToDispatcher(f_hApp, f_pRequesterName, + &m_requesterCallbacksVec[0], + static_cast<UI_32>(m_requesterCallbacksVec.size()), + f_hSession); + + LOG_STATUS_IF_ERRORED(l_eStatus, "FrameworkunifiedAttachCallbacksToDispatcher(f_hSession)"); // LCOV_EXCL_BR_LINE 5:macro + + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-"); + return (l_eStatus); +} + +/////////////////////////////////////////////////////////////////////////// +// Function : OnOpenSession +// brief : Called when a requester opens a session with SS_Logger +// service. This function attaches error event callbacks +// to the dispatcher with the source set to the requester. +/////////////////////////////////////////////////////////////////////////// +EFrameworkunifiedStatus CErrorEvent::OnCloseSession(HANDLE f_hApp, PCSTR f_pRequesterName, + HANDLE f_hSession) { + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+"); + EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK; + UI_32 l_cmdIdArr[m_requesterCallbacksVec.size()]; // NOLINT (runtime/arrays) + + for (UI_32 i = 0; i < m_requesterCallbacksVec.size(); i++) { + l_cmdIdArr[i] = m_requesterCallbacksVec[i].iCmd; + } + + l_eStatus = FrameworkunifiedDetachCallbacksFromDispatcher(f_hApp, f_pRequesterName, + l_cmdIdArr, + static_cast<UI_32>(m_requesterCallbacksVec.size()), + f_hSession); + + LOG_STATUS_IF_ERRORED(l_eStatus, "FrameworkunifiedAttachCallbacksToDispatcher()"); // LCOV_EXCL_BR_LINE 5:macro + + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-"); + return (l_eStatus); +} + +/////////////////////////////////////////////////////////////////////////// +// Function : OnStartLogging +// brief : Called by SS_Logger and external services to begin logging +// artifact collection. This function sends a logging request +// to System Manager. See SS_SM_EVENT_ERROR_TO_SSL. +/////////////////////////////////////////////////////////////////////////// +EFrameworkunifiedStatus CErrorEvent::OnStartLogging(HANDLE f_hApp) { + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+"); + EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK; + SMErrorEventNtfData l_eventErrorNtfData; + + INTERFACEUNIFIEDLOG_RECEIVED_FROM(f_hApp); // LCOV_EXCL_BR_LINE 5:macro + + if (eFrameworkunifiedStatusOK != (l_eStatus = ReadMsg<SMErrorEventNtfData>(f_hApp, l_eventErrorNtfData))) { // LCOV_EXCL_BR_LINE 200:To ensure success // NOLINT[whitespace/line_length] + // when failed to ReadMsg, we can't know event-type for action, so nothing is able to do. + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + LOG_ERROR("ReadMsg()"); // LCOV_EXCL_LINE 200:To ensure success + } else { + if (TRUE == this->m_pLoggerCfg->IsLoggingEnabled()) { // LCOV_EXCL_BR_LINE 200:As it is always TRUE + if (TRUE == m_bIsPrevEventCompleted) { + TLoggerErrorEvent l_eventData = l_eventErrorNtfData; + + if (IsNeedVerify(l_eventData.EventType)) { + // if need output log to external storage, check whether device is authenticated or not. + VerifyExtStorage(l_eventData); + } + + uint8_t status; + Clock_getSystemTimeY2K38(&m_time, &status); + m_currentEventTriggerNumber = m_pLoggerCfg->GetUserInvokedCounter(); + l_eStatus = m_loggerUtil.checkDestinationAvailable(l_eventData); + if (eFrameworkunifiedStatusOK == l_eStatus) { + m_bIsPrevEventCompleted = false; /* See timer start / timeout handler below. */ + + m_artifactResponseVec.clear(); + + m_errorEventNtfData = l_eventErrorNtfData; /* Overwrite m_eventErrorNtfData when logging complete. */ + m_errorEventNtfData.EventBitMask = m_errorEventCfg + .GetEventsForErrorEvent(l_eventErrorNtfData.EventType); + l_eStatus = SendLogStartRequestToSystemManager( + m_errorEventNtfData.EventType); + LOG_STATUS_IF_ERRORED(l_eStatus, + "SendLogStartRequestToSystemManager()"); + l_eStatus = m_loggerCanEvent.PublishStartEvent(f_hApp, + m_errorEventNtfData); + LOG_STATUS_IF_ERRORED( + l_eStatus, + "m_loggerCanEvent.PublishStartEvent(f_hApp,m_errorEventNtfData);"); + + bool result = + m_errorEventTimers[kSSL_ERROR_EVENT_TIMER_LOGGING_START_RSPN] + .Start(m_loggingStartRspnToSec, 0, 0, 0); + if (FALSE == result) { // LCOV_EXCL_BR_LINE 200:As it is always TRUE + // LCOV_EXCL_START 200:As it is always TRUE + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + FRAMEWORKUNIFIEDLOG( + ZONE_ERR, + __FUNCTION__, + " Error. Failed to start timer kSSL_ERROR_EVENT_TIMER_LOGGING_START_RSPN."); + // LCOV_EXCL_STOP + } + } else { + FRAMEWORKUNIFIEDLOG(ZONE_WARN, __FUNCTION__, + " Warning. Destination not available. "); + m_errorEventNtfData = l_eventErrorNtfData; /* Overwrite m_eventErrorNtfData when logging complete. */ + m_errorEventNtfData.EventBitMask = m_errorEventCfg + .GetEventsForErrorEvent(l_eventErrorNtfData.EventType); + l_eStatus = OnStorageResponseNotFound(f_hApp); + LOG_STATUS_IF_ERRORED(l_eStatus, "OnStorageResponseNotFound(f_hApp)"); + } + } else { + // Not-Need Resp to SM, because of keep logging sequance. + FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, + " Error. Logging already in progress. Event dropped."); + } + } else { + // LCOV_EXCL_START 200:As it is always TRUE + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + if (l_eventErrorNtfData.isNeedReboot == TRUE) { + FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, + "System will reboot soon, so stop logging function."); + StopLoggingFunction(f_hApp); + } + FRAMEWORKUNIFIEDLOG( + ZONE_INFO, + __FUNCTION__, + "Logging is disabled! Dropping Event. Sending Complete to SS_SystemManager"); + l_eStatus = SendLogCompleteRequestToSystemManager(eFrameworkunifiedStatusFail); + LOG_STATUS_IF_ERRORED(l_eStatus, + "SendLogCompleteRequestToSystemManager()"); + // LCOV_EXCL_STOP + } + } + + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-"); + return (l_eStatus); +} + +/////////////////////////////////////////////////////////////////////////// +// Function : OnLogStartResponse +// brief : Called by System Manager after the acknowledgment of the +// logging session start request. This function starts the +// artifact collection process. See +// SS_SM_ERROR_EVENT_LOGGING_START_RSPN. +/////////////////////////////////////////////////////////////////////////// +EFrameworkunifiedStatus CErrorEvent::OnLogStartResponse(HANDLE f_hApp) { + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+"); + EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK; + m_errorEventTimers[kSSL_ERROR_EVENT_TIMER_LOGGING_START_RSPN].Stop(); + m_errorEventCfg.GetArtifactRequestVec(m_errorEventNtfData.EventType, + m_artifactRequestVec); + + l_eStatus = RequestNextArtifact(f_hApp); + LOG_STATUS_IF_ERRORED(l_eStatus, "RequestNextArtifact()"); + + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-"); + return (l_eStatus); +} + +/////////////////////////////////////////////////////////////////////////// +// Function : OnLogStartResponseTimeout +// brief : Called when / if SM fails to respond to a logging start +// request and the logging star response timer expires. +/////////////////////////////////////////////////////////////////////////// +EFrameworkunifiedStatus CErrorEvent::OnLogStartResponseTimeout(HANDLE f_hApp) { + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+"); + EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK; + + FRAMEWORKUNIFIEDLOG( + ZONE_ERR, + __FUNCTION__, + " Error. SM failed to respond to a logging start request in the required amount of time."); + + m_bIsPrevEventCompleted = TRUE; + + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-"); + return (l_eStatus); +} + +/////////////////////////////////////////////////////////////////////////// +// Function : RequestNextArtifact +// brief : This function requests the next artifact from the service +// that owns the artifact. If no artifacts remain, this +// function performs initiates artifact post processing. +/////////////////////////////////////////////////////////////////////////// +EFrameworkunifiedStatus CErrorEvent::RequestNextArtifact(HANDLE f_hApp) { + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+"); + EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK; + UI_32 l_timeoutSec; + UI_32 l_timeoutMs; + + if (0 != m_artifactRequestVec.size()) { + TLoggingArtifact &l_nextArtifact = m_artifactRequestVec.back(); + l_eStatus = m_loggerPopups.ShowStartPopup( + f_hApp, m_errorEventNtfData, &m_artifactRequestVec, + m_loggerUtil.getDestination(m_errorEventNtfData)); + + LOG_STATUS_IF_ERRORED( + l_eStatus, + "m_loggerPopups.ShowStartPopup(f_hApp,m_errorEventNtfData,&m_artifactRequestVec )"); + + TEXT(__FUNCTION__, + "Requesting next artifact ID:%d from:%s, with timeout:%d ms.", + l_nextArtifact.ArtifactId, + l_nextArtifact.Information.OwnerServiceName.c_str(), + l_nextArtifact.Information.RequestTimeoutMs); + + l_timeoutSec = l_nextArtifact.Information.RequestTimeoutMs / 1000; + l_timeoutMs = l_nextArtifact.Information.RequestTimeoutMs % 1000; + bool result = + m_errorEventTimers[kSSL_ERROR_EVENT_TIMER_ARTIFACT_RSPN].Start( + l_timeoutSec, l_timeoutMs, 0, 0); + if (FALSE == result) { // LCOV_EXCL_BR_LINE 200:As it is always TRUE + // LCOV_EXCL_START 200:As it is always TRUE + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, + "Failed to start timer kSSL_ERROR_EVENT_TIMER_ARTIFACT_RSPN."); + // LCOV_EXCL_STOP + } + switch (l_nextArtifact.Information.Cb.Type) { + case eCbTypePath: { + l_eStatus = CheckPathForArtifact(f_hApp, l_nextArtifact); + } + break; + + case eCbTypeFunction: { + if (l_nextArtifact.Information.Cb.Function == NULL) { // LCOV_EXCL_BR_LINE 200:As it is not always NULL + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + l_eStatus = eFrameworkunifiedStatusNullPointer; // LCOV_EXCL_LINE 200:As it is not always NULL + } else { + l_eStatus = l_nextArtifact.Information.Cb.Function(f_hApp, + l_nextArtifact); + LOG_STATUS_IF_ERRORED( + l_eStatus, + "l_nextArtifact.Information.Cb.Function(f_hApp, l_nextArtifact)"); + } + } + break; + + case eCbTypeInvalid: + default: + { + FRAMEWORKUNIFIEDLOG( + ZONE_ERR, + __FUNCTION__, + " Error. Unknown artifact or artifact owner for artifact ID:" + " %d. Invalid logging artifact configuration likely.", + l_nextArtifact.ArtifactId); + } + break; + } + } else { + if ((m_errorEventNtfData.EventType == eErrorEventTypeUserInvokedClearLogs) + || (m_errorEventNtfData.EventType + == eErrorEventTypeUserInvokedCollectNaviLog)) { + l_eStatus = this->OnStorageResponseOk(f_hApp); + return (l_eStatus); + } + uint8_t status; + Clock_getSystemTimeY2K38(&m_time, &status); + FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__, + " Info. All logging error event artifacts have been collected."); + l_eStatus = m_loggerUtil.checkDestinationAvailable(m_errorEventNtfData); + LOG_STATUS_IF_ERRORED( + l_eStatus, + "m_loggerUtil.checkDestinationAvailable(m_errorEventNtfData)"); + if (eFrameworkunifiedStatusOK == l_eStatus) { + /* Check one last time after all logs have been collected */ + /* if we should show popup for archiving and writing to USB */ + l_eStatus = m_loggerPopups.ShowStartPopup( + f_hApp, m_errorEventNtfData, &m_artifactRequestVec, + m_loggerUtil.getDestination(m_errorEventNtfData)); + LOG_STATUS_IF_ERRORED( + l_eStatus, + "m_loggerPopups.ShowStartPopup(f_hApp,m_errorEventNtfData,&m_artifactRequestVec )"); + + l_eStatus = m_loggerUtil.getFilePathAndName(f_hApp, m_errorEventNtfData, + m_time, m_archiveDestination); + LOG_STATUS_IF_ERRORED( + l_eStatus, + "m_loggerUtil.getFilePathAndName()"); + + std::string destination_path = m_loggerUtil.getDestination( + m_errorEventNtfData); + if (destination_path.compare(m_pLoggerCfg->m_emmcOutputPath) == 0) { + if (eFrameworkunifiedStatusOK + != m_loggerUtil.deleteOldEmmcLog(m_archiveDestination, + m_errorEventNtfData.EventType)) { + FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, + " Error. m_loggerUtil.deleteOldEmmcLog()"); + } + } + + l_eStatus = this->m_loggerStorage.Start(m_archiveDestination, + this->m_artifactResponseVec, + m_time); + LOG_STATUS_IF_ERRORED( + l_eStatus, + "m_loggerStorage.Start()"); + if (l_eStatus != eFrameworkunifiedStatusOK) { + l_eStatus = this->OnStorageResponseWriteFailed(f_hApp); + LOG_STATUS_IF_ERRORED(l_eStatus, + "this->OnStorageResponseWriteFailed(f_hApp)"); + } + } else { + l_eStatus = this->OnStorageResponseNotFound(f_hApp); + LOG_STATUS_IF_ERRORED( + l_eStatus, + "this->OnStorageResponseNotFound(f_hApp)"); + } + } + + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-"); + return (l_eStatus); +} + +/////////////////////////////////////////////////////////////////////////// +// Function : OnArtifactResponse +// brief : This function is called when an artifact has been made ready +// by the owning service. +/////////////////////////////////////////////////////////////////////////// +EFrameworkunifiedStatus CErrorEvent::OnArtifactResponse(HANDLE f_hApp) { + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+"); + EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK; + ARTIFACT_RESPONSE l_artifactResponse; + + if (eFrameworkunifiedStatusOK != (l_eStatus = ReadMsg<ARTIFACT_RESPONSE>(f_hApp, l_artifactResponse))) { // LCOV_EXCL_BR_LINE 200:To ensure success // NOLINT[whitespace/line_length] + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + LOG_ERROR("ReadMsg()"); // LCOV_EXCL_LINE 200:To ensure success + } else { + m_errorEventTimers[kSSL_ERROR_EVENT_TIMER_ARTIFACT_RSPN].Stop(); + + // Prevent processing of artifacts that arrive after the error event logging session has completed. + if (m_artifactRequestVec.size() > 0) { + TEXT(__FUNCTION__, "Artifact ID:%d received.", + l_artifactResponse.ArtifactId); + + TLoggingArtifact &l_artifactCurr = m_artifactRequestVec.back(); + if (l_artifactCurr.ArtifactId != l_artifactResponse.ArtifactId) { + TEXT( + __FUNCTION__, + "Failure collecting current artifact. Expected artifact ID:%d, received artifact ID:%d." + " Ignoring received artifact.", + l_artifactCurr.ArtifactId, l_artifactResponse.ArtifactId); + } else { + TLoggingArtifactResponse l_response; + l_response.ArtifactId = l_artifactResponse.ArtifactId; + l_response.Filepath = l_artifactResponse.FilePathAndName; + l_response.Remove = l_artifactCurr.Information.Remove; + m_artifactResponseVec.push_back(l_response); + m_artifactRequestVec.pop_back(); // Remove received artifact from request vector. + l_eStatus = RequestNextArtifact(f_hApp); + LOG_STATUS_IF_ERRORED(l_eStatus, "RequestNextArtifact()"); + } + } else { + FRAMEWORKUNIFIEDLOG( + ZONE_ERR, + __FUNCTION__, + " Error. Received spurious artifact ID: %d. No error event logging session active.", + l_artifactResponse.ArtifactId); // LCOV_EXCL_BR_LINE 5:macro + } + } + + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-"); + return (l_eStatus); +} + +/////////////////////////////////////////////////////////////////////////// +// Function : OnArtifactResponseTimeout +// brief : This function is called when a requested artifact response +// fails to arrive in the required amount of time. +/////////////////////////////////////////////////////////////////////////// +EFrameworkunifiedStatus CErrorEvent::OnArtifactResponseTimeout(HANDLE f_hApp) { + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+"); + EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK; + + if (m_artifactRequestVec.size() > 0) { // LCOV_EXCL_BR_LINE 200:As it cannot always be 0 + TLoggingArtifact &l_artifactCurr = m_artifactRequestVec.back(); + + FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, + " Error. Artifact response timer expired for artifact ID: %d.", + l_artifactCurr.ArtifactId); + + // Remove artifact from request vector. + m_artifactRequestVec.pop_back(); + + RequestNextArtifact(f_hApp); + } + + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-"); + return (l_eStatus); +} + +/////////////////////////////////////////////////////////////////////////// +// Function : OnArtifactRequest +// brief : This function services an artifact request generated by +// the error event sub system. The requested artifact will +// be one of the artifacts owned by SSL. +/////////////////////////////////////////////////////////////////////////// +EFrameworkunifiedStatus CErrorEvent::OnArtifactRequest(HANDLE f_hApp) { + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+"); + EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK; + EArtifactId l_requestedArtifactId; + + if (eFrameworkunifiedStatusOK + != (l_eStatus = ReadMsg<EArtifactId>(f_hApp, l_requestedArtifactId))) { + LOG_ERROR("ReadMsg()"); + } else { + switch (l_requestedArtifactId) { + case eArtifactIdInterfaceunifiedDebugLog: + l_eStatus = OnObtainLoggerserviceLogRequest(f_hApp); + LOG_STATUS_IF_ERRORED(l_eStatus, "OnObtainLoggerserviceLogRequest()"); + break; + + case eArtifactIdTransmitLog: + l_eStatus = OnObtainTransmitLogRequest(f_hApp); + LOG_STATUS_IF_ERRORED(l_eStatus, "OnObtainTransmitLogRequest()"); + break; + + case eArtifactIdPerformanceLog: + l_eStatus = OnObtainPerformanceLogRequest(f_hApp); + LOG_STATUS_IF_ERRORED(l_eStatus, "OnObtainPerformanceLogRequest()"); + break; + + case eArtifactIdScreenShot: + l_eStatus = OnObtainScreenShotRequest(f_hApp); + LOG_STATUS_IF_ERRORED(l_eStatus, "OnObtainScreenShotRequest()"); + break; + + case eArtifactIdKernelLog: + l_eStatus = OnObtainKernelLogInfoRequest(f_hApp); + LOG_STATUS_IF_ERRORED(l_eStatus, "OnObtainKernelLogInfoRequest()"); + break; + + case eArtifactIdDRInitialLog: + l_eStatus = OnObtainDRInitialLogRequest(f_hApp); + LOG_STATUS_IF_ERRORED(l_eStatus, "OnObtainDRInitialLogRequest()"); + break; + + case eArtifactIdDRLocationLog: + l_eStatus = OnObtainDRLocationLogRequest(f_hApp); + LOG_STATUS_IF_ERRORED(l_eStatus, "OnObtainDRLocationLogRequest()"); + break; + + case eArtifactIdClearAllLog: + l_eStatus = OnClearAllLogRequest(f_hApp); + LOG_STATUS_IF_ERRORED(l_eStatus, "OnClearAllLogRequest()"); + break; + + case eArtifactIdNaviLog: + l_eStatus = OnNaviLogRequest(f_hApp); + LOG_STATUS_IF_ERRORED(l_eStatus, "OnNaviLogRequest()"); + break; + + default: + FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, + " Error. Unsupported logging artifact requested: %d.", + l_requestedArtifactId); + break; + } + } + + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-"); + return (l_eStatus); +} + +/////////////////////////////////////////////////////////////////////////// +// Function : OnStorageResponseOk +// brief : This function services response from the storage thread. It +// is called when the logs have been stored successfully. +/////////////////////////////////////////////////////////////////////////// +EFrameworkunifiedStatus CErrorEvent::OnStorageResponseOk(HANDLE f_hApp) { + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+"); + EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK; + + l_eStatus = this->m_loggerPopups.ShowEndPopup(f_hApp, m_errorEventNtfData, + m_archiveDestination); + LOG_STATUS_IF_ERRORED( + l_eStatus, + "this->m_loggerPopups.ShowEndPopup(f_hApp,m_errorEventNtfData,m_archiveDestination)"); + + if (m_errorEventNtfData.EventType == eErrorEventTypeDiagEvent) { + l_eStatus = sendDiagEventResponse(); + LOG_STATUS_IF_ERRORED(l_eStatus, "sendDiagEventResponse()"); + } + if (m_errorEventNtfData.isNeedReboot == TRUE) { + FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, + "System will reboot soon, so stop logging function."); + StopLoggingFunction(f_hApp); + } + m_bIsPrevEventCompleted = true; + l_eStatus = SendLogCompleteRequestToSystemManager(eFrameworkunifiedStatusOK); + + l_eStatus = m_loggerCanEvent.PublishEndEvent(f_hApp, m_errorEventNtfData, + m_currentEventTriggerNumber, + m_time); + LOG_STATUS_IF_ERRORED(l_eStatus, "m_loggerCanEvent.PublishEndEvent();"); + LOG_STATUS_IF_ERRORED(l_eStatus, "SendLogCompleteRequestToSystemManager()"); + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-"); + return (l_eStatus); +} + +/////////////////////////////////////////////////////////////////////////// +// Function : OnStorageResponseWriteFailed +// brief : This function services response from the storage thread. It +// is called when the logs failed to be written to the target +// destination. +/////////////////////////////////////////////////////////////////////////// +EFrameworkunifiedStatus CErrorEvent::OnStorageResponseWriteFailed(HANDLE f_hApp) { + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+"); + EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK; + l_eStatus = m_loggerPopups.ShowErrorPopup(f_hApp, m_errorEventNtfData, + (UI_16) eWriteToDeviceFailed); + LOG_STATUS_IF_ERRORED( + l_eStatus, "m_loggerPopups.ShowErrorPopup(f_hApp, eWriteToDeviceFailed)"); + + if (m_errorEventNtfData.EventType == eErrorEventTypeDiagEvent) { + sendDiagEventErrorResponse(eDEVICE_WRITE_ERROR); + } + if (m_errorEventNtfData.isNeedReboot == TRUE) { + FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, + "System will reboot soon, so stop logging function."); + StopLoggingFunction(f_hApp); + } + m_bIsPrevEventCompleted = true; + l_eStatus = SendLogCompleteRequestToSystemManager(eFrameworkunifiedStatusFail); + + l_eStatus = m_loggerCanEvent.PublishErrorEvent(f_hApp, m_errorEventNtfData, + TRUE, + m_currentEventTriggerNumber, + m_time); + LOG_STATUS_IF_ERRORED(l_eStatus, "m_loggerCanEvent.PublishErrorEvent();"); + + LOG_STATUS_IF_ERRORED(l_eStatus, "SendLogCompleteRequestToSystemManager()"); + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-"); + return (l_eStatus); +} + +/////////////////////////////////////////////////////////////////////////// +// Function : OnStorageResponseNotFound +// brief : This function services response from the storage thread. It +// is called when the logs failed to be written to the target +// destination because the target was not found +/////////////////////////////////////////////////////////////////////////// +EFrameworkunifiedStatus CErrorEvent::OnStorageResponseNotFound(HANDLE f_hApp) { + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+"); + EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK; + l_eStatus = m_loggerPopups.ShowErrorPopup(f_hApp, m_errorEventNtfData, + (UI_16) eSelectedDeviceNotFound); + LOG_STATUS_IF_ERRORED( + l_eStatus, + "m_loggerPopups.ShowErrorPopup(f_hApp, eSelectedDeviceNotFound)"); + + if (m_errorEventNtfData.EventType == eErrorEventTypeDiagEvent) { + l_eStatus = sendDiagEventErrorResponse(eDEVICE_NOT_AVAILABLE); + LOG_STATUS_IF_ERRORED(l_eStatus, "sendDiagEventErrorResponse(eDEVICE_NOT_AVAILABLE)"); + } + if (m_errorEventNtfData.isNeedReboot == TRUE) { + FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, + "System will reboot soon, so stop logging function."); + StopLoggingFunction(f_hApp); + } + m_bIsPrevEventCompleted = true; + l_eStatus = SendLogCompleteRequestToSystemManager(eFrameworkunifiedStatusFail); + + l_eStatus = m_loggerCanEvent.PublishErrorEvent(f_hApp, m_errorEventNtfData, + TRUE, + m_currentEventTriggerNumber, + m_time); + LOG_STATUS_IF_ERRORED(l_eStatus, "m_loggerCanEvent.PublishErrorEvent();"); + + LOG_STATUS_IF_ERRORED(l_eStatus, "SendLogCompleteRequestToSystemManager()"); + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-"); + return (l_eStatus); +} + +/////////////////////////////////////////////////////////////////////////// +// Function : OnStorageResponseNoWritten +// brief : This function services response from the storage thread. It +// is called when no logs where found. +/////////////////////////////////////////////////////////////////////////// +EFrameworkunifiedStatus CErrorEvent::OnStorageResponseNoWritten(HANDLE f_hApp) { + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+"); + EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK; + + l_eStatus = m_loggerPopups.ShowErrorPopup(f_hApp, m_errorEventNtfData, + (UI_16) eNoLogToStore); + LOG_STATUS_IF_ERRORED(l_eStatus, + "m_loggerPopups.ShowErrorPopup(f_hApp, eNoLogToStore)"); + + if (m_errorEventNtfData.EventType == eErrorEventTypeDiagEvent) { + l_eStatus = sendDiagEventErrorResponse(eNO_ERROR_INFO); + LOG_STATUS_IF_ERRORED(l_eStatus, "sendDiagEventErrorResponse(eNO_ERROR_INFO)"); + } + if (m_errorEventNtfData.isNeedReboot == TRUE) { + FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, + "System will reboot soon, so stop logging function."); + StopLoggingFunction(f_hApp); + } + m_bIsPrevEventCompleted = true; + l_eStatus = SendLogCompleteRequestToSystemManager(eFrameworkunifiedStatusOK); + + l_eStatus = m_loggerCanEvent.PublishErrorEvent(f_hApp, m_errorEventNtfData, + TRUE, + m_currentEventTriggerNumber, + m_time); + LOG_STATUS_IF_ERRORED(l_eStatus, "m_loggerCanEvent.PublishErrorEvent();"); + + LOG_STATUS_IF_ERRORED(l_eStatus, "SendLogCompleteRequestToSystemManager()"); + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-"); + return (l_eStatus); +} + +EFrameworkunifiedStatus CErrorEvent::sendDiagEventErrorResponse(EELL_ErrorCode f_errCode) { + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+"); + EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK; + if (this->m_ServiceName.length() > 0) { + l_eStatus = sendDiagEventErrorResponse(f_errCode, this->m_ServiceName); + this->m_ServiceName = ""; + } + + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-"); + return (l_eStatus); +} + +EFrameworkunifiedStatus CErrorEvent::sendDiagEventErrorResponse(EELL_ErrorCode f_errCode, + std::string f_destName) { + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+"); + EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK; + + if (eFrameworkunifiedStatusOK != (l_eStatus = FrameworkunifiedSendMsg(m_diagsessionhandle, SS_LOGGERCOPYEMERGENCYLOGS_ERROR_RESP, sizeof(EELL_ErrorCode), &f_errCode))) { // LCOV_EXCL_BR_LINE 4: NSFW error case. // NOLINT[whitespace/line_length] + // LCOV_EXCL_START 4: NSFW error case. + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, + "SS_LOGGERCOPYEMERGENCYLOGS_ERROR_RESP Msg send failed = %x", + l_eStatus); + // LCOV_EXCL_STOP + } + + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-"); + return (l_eStatus); +} + +EFrameworkunifiedStatus CErrorEvent::sendDiagEventResponse(void) { + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+"); + EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK; + + if (eFrameworkunifiedStatusOK != (l_eStatus = FrameworkunifiedSendMsg(m_diagsessionhandle, SS_LOGGERCOPYEMERGENCYLOGS_SUCCESS_RESP, 0, NULL))) { + FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, + "SS_LOGGERCOPYEMERGENCYLOGS_SUCCESS_RESP Msg send failed = %x", + l_eStatus); + } + + m_ServiceName = ""; + + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-"); + return (l_eStatus); +} + +EFrameworkunifiedStatus CErrorEvent::SetDiagEventSourceName(std::string f_serviceName) { + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+"); + EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusFail; + if ((f_serviceName.length() > 0) + && (this->m_ServiceName.length() == 0)) { + this->m_ServiceName = f_serviceName; + l_eStatus = eFrameworkunifiedStatusOK; + } else { + FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, + " Error. f_serviceName(%s), m_serviceName(%s)", + f_serviceName.c_str(), m_ServiceName.c_str()); + } + + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-"); + return (l_eStatus); +} + +void CErrorEvent::SetDiagSessionHandle(HANDLE f_sessionhandle) { + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+"); + + m_diagsessionhandle = f_sessionhandle; + + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-"); +} + +void CErrorEvent::SetMileage(UI_32 f_mileage) { + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+"); + this->m_loggerUtil.SetMilage(f_mileage); + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-"); +} + +// LCOV_EXCL_START 200: +EFrameworkunifiedStatus CErrorEvent::SaveNaviLog(EPWR_SHUTDOWN_TRIGGER_TYPE errType) { + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+"); + EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK; + UI_32 l_logMaxNum = 0; + std::string l_Filename = ""; + + uint32_t l_time; + uint8_t status; + Clock_getSystemTimeY2K38(&l_time, &status); + l_eStatus = m_loggerUtil.getEmmcNaviLogParams(l_time, errType, l_Filename, + l_logMaxNum); + + if (eFrameworkunifiedStatusOK != l_eStatus) { + FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, + " Error: getEmmcNaviLogParams NaviLog update failed %d", l_eStatus); + } else { + if (l_logMaxNum == 0) { + /*OutputNaviLogNmlMax or OutputNaviLogErrMax = 0. */ + FRAMEWORKUNIFIEDLOG( + ZONE_WARN, + __FUNCTION__, + " Warning: Not update NaviLog. OutputNaviLogNmlMax or OutputNaviLogErrMax = 0"); + } else { + FILE *fp; + void *p; + p = EL_mem_exram_mmap_simple(EL_MEM_ID_NAVI_LOG, PROT_READ | PROT_WRITE, + MAP_SHARED, + EL_MEM_CACHE_INVALID); + if (p == MAP_FAILED) { + FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, + "Error : EL_mem_exram_mmap_simple MAP_FAILD"); + l_eStatus = eFrameworkunifiedStatusFail; + } else { + fp = fopen(l_Filename.c_str(), "wb"); + if (fp == NULL) { + FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "Could not open file %s", + l_Filename.c_str()); + l_eStatus = eFrameworkunifiedStatusAccessError; + } else { + fwrite(p, sizeof(unsigned char), EL_mem_getLength(EL_MEM_ID_NAVI_LOG), + fp); + fclose(fp); + } + if (0 != EL_mem_exram_munmap(p, EL_mem_getLength(EL_MEM_ID_NAVI_LOG))) { + FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "Error : EL_mem_exram_munmap"); + } + } + } + } + + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-"); + return (l_eStatus); +} +// LCOV_EXCL_STOP + +EFrameworkunifiedStatus CErrorEvent::VerifyExtStorage(TLoggerErrorEvent event) { + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+"); + EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusFail; + std::string f_path; + + f_path = m_pLoggerCfg->getUsb0MountPath(); + + if (eFrameworkunifiedStatusOK == l_eStatus) { + l_eStatus = eFrameworkunifiedStatusFail; + + if (eFrameworkunifiedStatusFail == l_eStatus) { + // timeout or error + FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "Error : get secure log failed or timeout"); + } + } else { + // timeout + FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "Error : ticket verify timeout."); + } + + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-"); + return (l_eStatus); +} + +bool CErrorEvent::IsNeedVerify(EErrorEventType type) { + bool ret = false; + switch (type) { + case eErrorEventTypeUserInvokedCollectScreenShot: + case eErrorEventTypeUserInvokedCollectAllLogs: + case eErrorEventTypeUserInvokedCollectInterfaceunifiedLogs: + case eErrorEventTypeInterfaceunifiedEmmcLogs: + case eErrorEventTypeEelExport: + case eErrorEventTypeDiagEvent: + case eErrorEventTypeCanEvent: + ret = true; + break; + default: + break; + } + return ret; +} diff --git a/systemservice/logger_service/server/src/ss_logger_error_event_archive.cpp b/systemservice/logger_service/server/src/ss_logger_error_event_archive.cpp new file mode 100755 index 0000000..b718705 --- /dev/null +++ b/systemservice/logger_service/server/src/ss_logger_error_event_archive.cpp @@ -0,0 +1,413 @@ +/* + * @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_SS_LoggerService +/// \brief This file supports error event logging. +/// +/////////////////////////////////////////////////////////////////////////////// +#include "ss_logger_error_event_archive.h" +#include <string.h> +#include <errno.h> +#include <unistd.h> +#include <dirent.h> +#include <sys/types.h> +#include <sys/stat.h> +#include <fcntl.h> +#include <libtar_listhash.h> +#include <libtar.h> +#include <zlib.h> +#include <stdio.h> +#include <boost/bind.hpp> +#include <native_service/frameworkunified_framework_if.h> +#include <system_service/ss_services.h> +#include <system_service/ss_templates.h> +#include <iostream> +#include <fstream> +#include <string> +#include <vector> +#include "ss_logger_util.h" +#include "loggerservicedebug_loggerservicelog.h" +#include "ss_logger_fs_directory.h" + +// GZF save variables +static gzFile g_gzFile; + +CErrorEventArchive::CErrorEventArchive(void) { + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+"); + m_pTarInfo = NULL; + g_gzFile = NULL; + m_gztype.openfunc = (openfunc_t) &CErrorEventArchive::gzOpenArchive; + m_gztype.closefunc = (closefunc_t) &CErrorEventArchive::gzCloseArchive; + m_gztype.readfunc = (readfunc_t) &CErrorEventArchive::gzReadArchive; + m_gztype.writefunc = (writefunc_t) &CErrorEventArchive::gzWriteArchive; + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-"); +} + +CErrorEventArchive::~CErrorEventArchive(void) { + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+"); + if (NULL != m_pTarInfo) { // LCOV_EXCL_BR_LINE 6: it will close after close + // LCOV_EXCL_START 6: it will close after close + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + (void) closeArchive(); + m_pTarInfo = NULL; + // LCOV_EXCL_STOP + } + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-"); +} + +EFrameworkunifiedStatus CErrorEventArchive::openArchive(std::string f_pathAndName) { + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+"); + EFrameworkunifiedStatus l_eFrameworkunifiedStatus = eFrameworkunifiedStatusOK; + + if (NULL == m_pTarInfo) { // LCOV_EXCL_BR_LINE 6: closeArchive will be set to null + m_pathAndName = f_pathAndName; + + /* check if directory exists */ + size_t l_found = f_pathAndName.find_last_of('/'); + std::string l_path = f_pathAndName.substr(0, l_found); + + if (0 != access(l_path.c_str(), F_OK)) { + FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__, "Directory does not exist. Creating..."); + l_eFrameworkunifiedStatus = CFSDirectory::CreateDirectory(l_path); + } + + /* create archive in tmp */ + m_tmpName = "/tmp/log.tar.gz"; + + int l_tarRetVal = tar_open(&m_pTarInfo, const_cast<char*>(m_tmpName.c_str()), + &m_gztype, + O_WRONLY | O_CREAT, + TARMODE, + TAR_GNU); + + if ((l_tarRetVal != 0) || (m_pTarInfo == NULL) || (g_gzFile == NULL)) { // LCOV_EXCL_BR_LINE 5: tar_open's error case. // NOLINT[whitespace/line_length] + // LCOV_EXCL_START 5: tar_open's error case. + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "Could not open TAR-Archive!"); + l_eFrameworkunifiedStatus = eFrameworkunifiedStatusAccessError; + // LCOV_EXCL_STOP + } + } else { + // LCOV_EXCL_START 6: closeArchive will be set to null + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + FRAMEWORKUNIFIEDLOG(ZONE_WARN, __FUNCTION__, "Tar is still open"); + l_eFrameworkunifiedStatus = eFrameworkunifiedStatusFail; + // LCOV_EXCL_STOP + } + + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-"); + return (l_eFrameworkunifiedStatus); +} + +EFrameworkunifiedStatus CErrorEventArchive::addToArchive(std::string f_filePathAndName, + std::string f_destinationName, + UI_8 f_depth) { + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+"); + EFrameworkunifiedStatus l_eFrameworkunifiedStatus = eFrameworkunifiedStatusFileLoadError; + struct stat l_stat; + int l_statRetVal; + + if (0 != access(f_filePathAndName.c_str(), F_OK)) { // LCOV_EXCL_BR_LINE 200: file is aways exist + // LCOV_EXCL_START 200: file is aways exist + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, + " Error. The specified file path and name does not exist: %s", + f_filePathAndName.c_str()); + // LCOV_EXCL_STOP + } else if (0 != (l_statRetVal = stat(f_filePathAndName.c_str(), &l_stat))) { // LCOV_EXCL_BR_LINE 5: stat's error case. // NOLINT[whitespace/line_length] + // LCOV_EXCL_START 5: stat's error case. + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, + " Error. stat() for file or directory returned error: %s -> %d", + f_filePathAndName.c_str(), l_statRetVal); + // LCOV_EXCL_STOP + } else if (0 != S_ISDIR(l_stat.st_mode)) { + if (0 < f_depth) { // LCOV_EXCL_BR_LINE 6: it aways 4 + l_eFrameworkunifiedStatus = addDirectoryToArchive(f_filePathAndName, f_destinationName, + f_depth); + } else { + // LCOV_EXCL_START 6: it aways 4 + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + FRAMEWORKUNIFIEDLOG(ZONE_WARN, __FUNCTION__, + "Maximum recursive depth reached! File %s not added to archive.", + f_filePathAndName.c_str()); + // LCOV_EXCL_STOP + } + } else if (0 != S_ISREG(l_stat.st_mode)) { // LCOV_EXCL_BR_LINE 200: it can not be a symbolic link + l_eFrameworkunifiedStatus = addFileToArchive(f_filePathAndName, f_destinationName); + } else { + // LCOV_EXCL_START 200: it can not be a symbolic link + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + FRAMEWORKUNIFIEDLOG( + ZONE_ERR, + __FUNCTION__, + " Error. specified file may be a symbolic link or other non 'regular' type. File: %s, mode: 0x%04X.", + f_filePathAndName.c_str(), l_stat.st_mode); + // LCOV_EXCL_STOP + } + + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-"); + return (l_eFrameworkunifiedStatus); +} + +// LCOV_EXCL_START 8: can not be called +EFrameworkunifiedStatus CErrorEventArchive::addToArchive( + std::vector<std::string> f_filePathAndNameList) { + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+"); + EFrameworkunifiedStatus l_eFrameworkunifiedStatus = eFrameworkunifiedStatusOK; + + std::vector<std::string>::iterator l_vIter = f_filePathAndNameList.begin(); + while ((eFrameworkunifiedStatusOK == l_eFrameworkunifiedStatus) + && (l_vIter != f_filePathAndNameList.end())) { + l_eFrameworkunifiedStatus = addToArchive(*l_vIter, *l_vIter); + l_vIter++; + } + + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-"); + return (l_eFrameworkunifiedStatus); +} +// LCOV_EXCL_STOP + +EFrameworkunifiedStatus CErrorEventArchive::closeArchive(void) { + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+"); + EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK; + + if (0 != tar_append_eof(m_pTarInfo)) { // LCOV_EXCL_BR_LINE 5: tar_append_eof's error case. + // LCOV_EXCL_START 5: tar_append_eof's error case. + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + FRAMEWORKUNIFIEDLOG(ZONE_INFO, __PRETTY_FUNCTION__, "tar_append_eof()"); + l_eStatus = eFrameworkunifiedStatusFail; + // LCOV_EXCL_STOP + } + if (0 != tar_close(m_pTarInfo)) { // LCOV_EXCL_BR_LINE 5: tar_close's error case. + // LCOV_EXCL_START 5: tar_close's error case. + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "Could not close archive"); + l_eStatus = eFrameworkunifiedStatusFail; + // LCOV_EXCL_STOP + } else { + m_pTarInfo = NULL; + g_gzFile = NULL; + } + + if (eFrameworkunifiedStatusOK == l_eStatus) { // LCOV_EXCL_BR_LINE 6: it aways be ok +#ifdef RELEASE_BUILD + l_eStatus = CLoggerUtil::PathCheckAndCopyFile(m_tmpName, m_pathAndName); +#else + l_eStatus = CLoggerUtil::CopyFile(m_tmpName, m_pathAndName); +#endif // RELEASE_BUILD + if (eFrameworkunifiedStatusOK == l_eStatus) { + l_eStatus = + (0 == remove(m_tmpName.c_str())) ? eFrameworkunifiedStatusOK : eFrameworkunifiedStatusFault; + if (eFrameworkunifiedStatusOK != l_eStatus) { // LCOV_EXCL_BR_LINE 5: remove's error case. + // LCOV_EXCL_START 5: remove's error case. + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + FRAMEWORKUNIFIEDLOG( + ZONE_WARN, + __FUNCTION__, + " Warning. Failed to remove temporary archive. Will overwrite on next event"); + // LCOV_EXCL_STOP + } + } else if (eFrameworkunifiedStatusErrNoEAGAIN == l_eStatus) { // LCOV_EXCL_BR_LINE 200: write can not be ErrNoEAGAIN + // LCOV_EXCL_START 200: write can not be ErrNoEAGAIN + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + // disk space full + struct stat st_buf; + size_t req_size; + if (stat(m_tmpName.c_str(), &st_buf) != -1) { // LCOV_EXCL_BR_LINE 5: stat's error case. + req_size = st_buf.st_size; + if (eFrameworkunifiedStatusOK + == CLoggerUtil::forceDeleteOldLog(m_pathAndName, req_size)) { +#ifdef RELEASE_BUILD + l_eStatus = CLoggerUtil::PathCheckAndCopyFile(m_tmpName, m_pathAndName); +#else + l_eStatus = CLoggerUtil::CopyFile(m_tmpName, m_pathAndName); +#endif // RELEASE_BUILD + if (eFrameworkunifiedStatusOK != l_eStatus) { // LCOV_EXCL_BR_LINE 200: PathCheckAndCopyFile can not be fail + FRAMEWORKUNIFIEDLOG( + ZONE_ERR, + __FUNCTION__, + "Try Again but Error. Failed to copy to destination.%s, size=%d", + m_pathAndName.c_str(), req_size); + } + } else { + FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, + "Error. force delete failed.%s, size=%d", + m_pathAndName.c_str(), req_size); + } + FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__, " emmc full: dest=%s, size=%d", + m_pathAndName.c_str(), req_size); + } else { + // LCOV_EXCL_START 5: stat's error case. + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, + "Warning. Failed to get tmp log file stat. dest=%s", + m_pathAndName.c_str()); + // LCOV_EXCL_STOP + } + // LCOV_EXCL_STOP + } else { + /*should we copy lost archive to emmc??*/ + FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, + " Error. Failed to copy to destination. %s", m_pathAndName.c_str()); + } + remove(m_tmpName.c_str()); + m_tmpName = ""; + } + + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-"); + return (l_eStatus); +} + +EFrameworkunifiedStatus CErrorEventArchive::addFileToArchive(std::string f_filename, + std::string f_destinationName) { + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+"); + EFrameworkunifiedStatus l_eFrameworkunifiedStatus = eFrameworkunifiedStatusOK; /*check if Tar is open and if file can be read */ + + char path[PATH_MAX]; + + if ((NULL != m_pTarInfo) && (0 != f_destinationName.length()) // LCOV_EXCL_BR_LINE 200: it will awalys be true + && (realpath(f_filename.c_str(), path) != NULL)) { + int l_tarRetVal = tar_append_file(m_pTarInfo, path, + const_cast<char*>(f_destinationName. c_str())); + if (0 != l_tarRetVal) { // LCOV_EXCL_BR_LINE 5: tar_append_file's error case. + // LCOV_EXCL_START 5: tar_append_file's error case. + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, + "Could not add file \'%s\' to tar archive.", f_filename.c_str()); + l_eFrameworkunifiedStatus = eFrameworkunifiedStatusAccessError; + // LCOV_EXCL_STOP + } + } else { + // LCOV_EXCL_START 200: it will awalys be true + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, + "Archive not opened or could not access file: \"%s\"", + f_filename.c_str()); + l_eFrameworkunifiedStatus = eFrameworkunifiedStatusInvldParam; + // LCOV_EXCL_STOP + } + + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-"); + return (l_eFrameworkunifiedStatus); +} + +EFrameworkunifiedStatus CErrorEventArchive::addDirectoryToArchive( + std::string f_path, std::string f_destinationName, UI_8 f_depth) { + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+"); + EFrameworkunifiedStatus l_eFrameworkunifiedStatus = eFrameworkunifiedStatusOK; + struct dirent l_pDirent; + struct dirent* next; + + DIR *l_pDir = opendir(f_path.c_str()); + if (l_pDir != NULL) { // LCOV_EXCL_BR_LINE 5: opendir's error case. + while (0 == readdir_r(l_pDir, &l_pDirent, &next) && next != NULL) { + if ((0 != strcmp(l_pDirent.d_name, ".")) && /* Ignore special . directory. */ + (0 != strcmp(l_pDirent.d_name, "..")) && /* Ignore special .. directory. */ + (0 != strcmp(l_pDirent.d_name, "lost+found")) && /* Ignore lost+found. */ + ('.' != l_pDirent.d_name[0])) { /* Ignore hidden files */ + std::string l_extension = "/"; + std::string l_fileName = f_path; + std::string l_destName = f_destinationName; + l_extension.append(l_pDirent.d_name); + l_fileName.append(l_extension); + l_destName.append(l_extension); + l_eFrameworkunifiedStatus = addToArchive(l_fileName, l_destName, static_cast<UI_8>(f_depth - 1)); + } + } + + closedir(l_pDir); + } + + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-"); + return (l_eFrameworkunifiedStatus); +} + +SI_32 CErrorEventArchive::gzOpenArchive(PCHAR f_pcPathname, SI_32 f_siOflags, + SI_32 f_siMode) { + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+"); + SI_32 l_siFileDescriptor = -1; + + if (f_pcPathname) { // LCOV_EXCL_BR_LINE 6: Pathname is awalys be set + PCHAR l_pcGzoflags; + + switch (f_siOflags & O_ACCMODE) { // LCOV_EXCL_BR_LINE 6: only O_WRONLY be set + case O_WRONLY: { + l_pcGzoflags = (PCHAR) "wb"; + break; + } + // LCOV_EXCL_START 6: only O_WRONLY be set + case O_RDONLY: { + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + l_pcGzoflags = (PCHAR) "rb"; + break; + } + // LCOV_EXCL_STOP + case O_RDWR: + default: { + return -1; + } + } + + if (-1 == (l_siFileDescriptor = // LCOV_EXCL_BR_LINE 5: open's error case. + open(f_pcPathname, f_siOflags, f_siMode))) { + // LCOV_EXCL_START 5: open's error case. + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-"); + return -1; + // LCOV_EXCL_STOP + } + + if ((f_siOflags & O_CREAT) // LCOV_EXCL_BR_LINE 5: fchmod's error case. + && fchmod(l_siFileDescriptor, f_siMode)) { + // LCOV_EXCL_START 5: fchmod's error case. + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + close(l_siFileDescriptor); + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-"); + return -1; + // LCOV_EXCL_STOP + } + + g_gzFile = gzdopen(l_siFileDescriptor, l_pcGzoflags); + if (!g_gzFile) { // LCOV_EXCL_BR_LINE 5: gzdopen's error case. + // LCOV_EXCL_START 5: gzdopen's error case. + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + close(l_siFileDescriptor); + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-"); + return -1; + // LCOV_EXCL_STOP + } + } else { + FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "Source Path empty."); + } + + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-"); + return (SI_32) l_siFileDescriptor; +} +SI_32 CErrorEventArchive::gzCloseArchive() { + return gzclose(g_gzFile); +} + +ssize_t CErrorEventArchive::gzWriteArchive(int fd, const void* buf, + size_t count) { + return gzwrite(g_gzFile, const_cast<void*>(buf), (unsigned int) count); +} + +ssize_t CErrorEventArchive::gzReadArchive(int fd, void* buf, size_t count) { + return gzread(g_gzFile, buf, (unsigned int) count); +} diff --git a/systemservice/logger_service/server/src/ss_logger_error_event_can_evt_reply.cpp b/systemservice/logger_service/server/src/ss_logger_error_event_can_evt_reply.cpp new file mode 100755 index 0000000..f400e83 --- /dev/null +++ b/systemservice/logger_service/server/src/ss_logger_error_event_can_evt_reply.cpp @@ -0,0 +1,147 @@ +/* + * @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_SS_LoggerService +/// \brief This file supports notifying CAN abou HK and CAN error events +/// +/////////////////////////////////////////////////////////////////////////////// +#include <stdio.h> +#include <time.h> +#include <stub/Clock_API.h> +#include "ss_logger_error_event_can_evt_reply.h" +CLoggerErrorEventCANEvtReply::CLoggerErrorEventCANEvtReply() { +} + +CLoggerErrorEventCANEvtReply::~CLoggerErrorEventCANEvtReply() { // LCOV_EXCL_START 14:globle instance + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert +} +// LCOV_EXCL_STOP + +EFrameworkunifiedStatus CLoggerErrorEventCANEvtReply::Initialize(CLoggerCfg* f_pLoggerCfg) { + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+"); + EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK; + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-"); + return (l_eStatus); +} + +BOOL CLoggerErrorEventCANEvtReply::IsEventNeeded(TLoggerErrorEvent f_event) { + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+"); + BOOL l_ret = + ((f_event.EventBitMask & EVENT_BIT_CAN_NOTIFICATION) != 0) ? TRUE : FALSE; + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-"); + return (l_ret); +} + +EFrameworkunifiedStatus CLoggerErrorEventCANEvtReply::PublishStartEvent( + HANDLE f_hApp, TLoggerErrorEvent f_event) { + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+"); + EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK; + if (TRUE == IsEventNeeded(f_event)) { + l_eStatus = FrameworkunifiedPublishPublicEvent(f_hApp, eSSLoggerCANEventStart, NULL, 0); + LOG_STATUS_IF_ERRORED( + l_eStatus, + "FrameworkunifiedPublishPublicEvent(f_hApp,eSSLoggerCANEventStart,NULL,0)"); + } + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-"); + return (l_eStatus); +} + +EFrameworkunifiedStatus CLoggerErrorEventCANEvtReply::PublishEndEvent( + HANDLE f_hApp, TLoggerErrorEvent f_event, UI_32 f_triggerNumber, + uint32_t f_time) { + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+"); + EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK; + if (TRUE == IsEventNeeded(f_event)) { + STEventCANLoggerEventInfo l_info; + struct tm l_tm; + CLOCK_RETURN clock_ret = Clock_getLocalTimeY2K38(&f_time, &l_tm); + if (CLOCK_OK == clock_ret) { + l_info.valid = TRUE; + l_info.success = TRUE; + l_info.triggerNumber = f_triggerNumber; + l_info.dateAndTime.DateTime_Stat = 0; + l_info.dateAndTime.DateTimeDay = static_cast<UI_8>(l_tm.tm_mday); + l_info.dateAndTime.DateTimeHour = static_cast<UI_8>(l_tm.tm_hour); + l_info.dateAndTime.DateTimeMinute = static_cast<UI_8>(l_tm.tm_min); + l_info.dateAndTime.DateTimeMonth = static_cast<UI_8>(l_tm.tm_mon + 1); + l_info.dateAndTime.DateTimeSecond = static_cast<UI_8>(l_tm.tm_sec); + l_info.dateAndTime.DateTimeYear = static_cast<UI_8>(l_tm.tm_year % 100); + l_info.dateAndTime.TimeFormat = 0; + FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__, + " Info. Time sent to CAN is: 20%2d/%2d/%2d %2d:%2d:%2d", + l_info.dateAndTime.DateTimeYear, l_info.dateAndTime.DateTimeMonth, + l_info.dateAndTime.DateTimeDay, l_info.dateAndTime.DateTimeHour, + l_info.dateAndTime.DateTimeMinute, + l_info.dateAndTime.DateTimeSecond); + + } else { + l_info.success = TRUE; + l_info.valid = FALSE; + FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, " Error. Passed time is invalid."); + } + l_eStatus = FrameworkunifiedPublishPublicEvent(f_hApp, eSSLoggerCANEventFinished, + &l_info, sizeof(l_info)); + + LOG_STATUS_IF_ERRORED( + l_eStatus, + "FrameworkunifiedPublishPublicEvent(f_hApp,eSSLoggerCANEventFinished,NULL,0)"); + } + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-"); + return (l_eStatus); +} + +EFrameworkunifiedStatus CLoggerErrorEventCANEvtReply::PublishErrorEvent( + HANDLE f_hApp, TLoggerErrorEvent f_event, BOOL f_isValid, + UI_32 f_triggerNumber, uint32_t f_time) { + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+"); + EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK; + if (TRUE == IsEventNeeded(f_event)) { + STEventCANLoggerEventInfo l_info; + struct tm l_tm; + CLOCK_RETURN clock_ret = Clock_getLocalTimeY2K38(&f_time, &l_tm); + l_info.valid = f_isValid; + l_info.success = FALSE; + if (CLOCK_OK == clock_ret) { + l_info.triggerNumber = f_triggerNumber; + l_info.dateAndTime.DateTime_Stat = 0; + l_info.dateAndTime.DateTimeDay = static_cast<UI_8>(l_tm.tm_mday); + l_info.dateAndTime.DateTimeHour = static_cast<UI_8>(l_tm.tm_hour); + l_info.dateAndTime.DateTimeMinute = static_cast<UI_8>(l_tm.tm_min); + l_info.dateAndTime.DateTimeMonth = static_cast<UI_8>(l_tm.tm_mon + 1); + l_info.dateAndTime.DateTimeSecond = static_cast<UI_8>(l_tm.tm_sec); + l_info.dateAndTime.DateTimeYear = static_cast<UI_8>(l_tm.tm_year % 100); + l_info.dateAndTime.TimeFormat = 0; + FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__, + " Info. Time sent to CAN is: 20%2d/%2d/%2d %2d:%2d:%2d", + l_info.dateAndTime.DateTimeYear, l_info.dateAndTime.DateTimeMonth, + l_info.dateAndTime.DateTimeDay, l_info.dateAndTime.DateTimeHour, + l_info.dateAndTime.DateTimeMinute, + l_info.dateAndTime.DateTimeSecond); + + } else { + l_info.valid = FALSE; + FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, " Error. Passed time is invalid."); + } + l_eStatus = FrameworkunifiedPublishPublicEvent(f_hApp, eSSLoggerCANEventFinished, + &l_info, sizeof(l_info)); + LOG_STATUS_IF_ERRORED( // LCOV_EXCL_BR_LINE 15: macro + l_eStatus, + "FrameworkunifiedPublishPublicEvent(f_hApp,eSSLoggerCANEventFinished,NULL,0)"); + } + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-"); + return (l_eStatus); +} diff --git a/systemservice/logger_service/server/src/ss_logger_error_event_cfg.cpp b/systemservice/logger_service/server/src/ss_logger_error_event_cfg.cpp new file mode 100755 index 0000000..fcd733e --- /dev/null +++ b/systemservice/logger_service/server/src/ss_logger_error_event_cfg.cpp @@ -0,0 +1,335 @@ +/* + * @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_SS_LoggerService +/// \brief This file supports error event logging configuration. +/// +/////////////////////////////////////////////////////////////////////////////// +#include <string.h> +#include <native_service/frameworkunified_framework_if.h> +#include <system_service/ss_logger_service.h> +#include <system_service/ss_services.h> +#include <system_service/ss_templates.h> +#include <vector> +#include "loggerservicedebug_loggerservicelog.h" +#include "ss_logger_error_event_cfg.h" + +enum ARTIFACT_BIT { + ARTIFACT_BIT_NONE = 0x00000000, + ARTIFACT_BIT_LOGGERSERVICE_DEBUG_LOG = 1 << (UI_32) eArtifactIdInterfaceunifiedDebugLog, + ARTIFACT_BIT_TRANSMIT_LOG = 1 << (UI_32) eArtifactIdTransmitLog, + ARTIFACT_BIT_PERFORMANCE_LOG = 1 << (UI_32) eArtifactIdPerformanceLog, + ARTIFACT_BIT_BOOT_MICRO_LOG = 1 << (UI_32) eArtifactIdBootMicroLog, + ARTIFACT_BIT_SYSTEM_DATA_LOG = 1 << (UI_32) eArtifactIdSystemDataCsv, + ARTIFACT_BIT_SHOW_MEM_TXT = 1 << (UI_32) eArtifactIdShowMemTxt, + ARTIFACT_BIT_PROCESS_CORE = 1 << (UI_32) eArtifactIdProcessCore, + ARTIFACT_BIT_DEBUG_DUMP_LOG = 1 << (UI_32) eArtifactIdDebugDumpLog, + ARTIFACT_BIT_KERNEL_LOG = 1 << (UI_32) eArtifactIdKernelLog, + ARTIFACT_BIT_KERNEL_BOOT_LOG = 1 << (UI_32) eArtifactIdKernelBootLog, + ARTIFACT_BIT_DRINITIAL_LOG = 1 << (UI_32) eArtifactIdDRInitialLog, + ARTIFACT_BIT_DRLOCATION_LOG = 1 << (UI_32) eArtifactIdDRLocationLog, + ARTIFACT_BIT_CHLM_MC_LOGS = 1 << (UI_32) eArtifactIdCpuHighLoadMonteCarloLogs, + ARTIFACT_BIT_METACORE_LOGS = 1 << (UI_32) eArtifactIdMetaCoreLogs, + ARTIFACT_BIT_SCREEN_SHOT = 1 << (UI_32) eArtifactIdScreenShot, + ARTIFACT_BIT_CMS_LOGS = 1 << (UI_32) eArtifactIdCmsLogs, + ARTIFACT_BIT_INTERNAL_DTC_LOG = 1 << (UI_32) eArtifactIDInternalDTC, + ARTIFACT_BIT_CLEAR_ALL_LOG = 1 << (UI_32) eArtifactIdClearAllLog, + ARTIFACT_BIT_NAVI_LOG = 1 << (UI_32) eArtifactIdNaviLog, + ARTIFACT_BIT_DEBUG_FOLDER_CONTENT = 1 + << (UI_32) eArtifactIdDebugFolderContent, + ARTIFACT_BIT_DEBUG_FOLDER2_CONTENT = 1 + << (UI_32) eArtifactIdDebugFolder2Content, + ARTIFACT_BIT_COM_LOG = 1 << (UI_32) eArtifactIdComDebugLog, + ARTIFACT_BIT_PSTORE_LOG = 1 << (UI_32) eArtifactIdPstoreLog +}; + +////////////////////////////////////////////////////////////////////////////////////////// +///// Definition for Logging Artifact Filepaths +////////////////////////////////////////////////////////////////////////////////////////// +const char LAF_DEBUG_FOLDER[] = "/nv/BS/ss/logger_service/rwdata"; +const char LAF_DEBUG_FOLDER2[] = "/nv/BS/ss/logger_service/rwdata/log2"; +const char LAF_MONTECARLO_FN[] = "/tmp/MonteCarlo"; +const char LAF_METACORE_FN[] = "/tmp/MetaCore"; +const char LAF_CMS_FN[] = "/tmp/cms"; +const char LAF_INT_DTC_FN[] = "/tmp/dtc_error.log"; +const char LAF_LOGGERSERVICELOG_COM[] = "/ramd/BS/ss/logger_service/rwdata/frameworkunifiedlog/communication"; +const char LAF_KERNEL_BOOT_FN[] = "/ramd/BS/ss/logger_service/rwdata/frameworkunifiedlog/kernelboot.log"; +const char LAF_PSTORELOG[] = "/dev/pstore"; + +#define ARTIFACT_BIT_ALL_OUTPUT_LOG (ARTIFACT_BIT_LOGGERSERVICE_DEBUG_LOG | \ + ARTIFACT_BIT_DEBUG_DUMP_LOG | \ + ARTIFACT_BIT_SYSTEM_DATA_LOG | \ + ARTIFACT_BIT_SHOW_MEM_TXT | \ + ARTIFACT_BIT_COM_LOG | \ + ARTIFACT_BIT_KERNEL_LOG | \ + ARTIFACT_BIT_KERNEL_BOOT_LOG | \ + ARTIFACT_BIT_SCREEN_SHOT | \ + ARTIFACT_BIT_TRANSMIT_LOG | \ + ARTIFACT_BIT_PERFORMANCE_LOG | \ + ARTIFACT_BIT_DRINITIAL_LOG | \ + ARTIFACT_BIT_DRLOCATION_LOG | \ + ARTIFACT_BIT_CHLM_MC_LOGS | \ + ARTIFACT_BIT_INTERNAL_DTC_LOG | \ + ARTIFACT_BIT_METACORE_LOGS | \ + ARTIFACT_BIT_PSTORE_LOG) + +TLoggingArtifactCfg CErrorEventCfg::m_loggerErrorEventCfgTbl[eErrorEventTypeMaxValue] = { + { eErrorEventTypeProcessCrash, { (ARTIFACT_BIT_ALL_OUTPUT_LOG + | ARTIFACT_BIT_NAVI_LOG), (EVENT_BIT_NONE) } }, + + { eErrorEventTypeProcessExit, { (ARTIFACT_BIT_ALL_OUTPUT_LOG + | ARTIFACT_BIT_NAVI_LOG), (EVENT_BIT_NONE) } }, + + { eErrorEventTypeHeartBeatFailure, { (ARTIFACT_BIT_ALL_OUTPUT_LOG + | ARTIFACT_BIT_NAVI_LOG), (EVENT_BIT_NONE) } }, + + { eErrorEventTypeSystemLowMemory, { (ARTIFACT_BIT_ALL_OUTPUT_LOG + | ARTIFACT_BIT_NAVI_LOG), (EVENT_BIT_NONE) } }, + + { eErrorEventTypeUserInvokedUserForceReset, { ARTIFACT_BIT_ALL_OUTPUT_LOG, + (EVENT_BIT_NONE) } }, + + { eErrorEventTypeUserInvokedCollectAllLogs, { ARTIFACT_BIT_ALL_OUTPUT_LOG, + (EVENT_BIT_POPUP | EVENT_BIT_CAN_NOTIFICATION) } }, + + { eErrorEventTypeUserInvokedCollectScreenShot, { (ARTIFACT_BIT_NONE + | ARTIFACT_BIT_SCREEN_SHOT), + + (EVENT_BIT_POPUP | EVENT_BIT_CAN_NOTIFICATION) } }, + + { eErrorEventTypeUserInvokedCollectInterfaceunifiedLogs, { ARTIFACT_BIT_ALL_OUTPUT_LOG, + (EVENT_BIT_POPUP | EVENT_BIT_CAN_NOTIFICATION) } }, + + { eErrorEventTypeUserInvokedCollectDevLogs, { ARTIFACT_BIT_ALL_OUTPUT_LOG, + (EVENT_BIT_NONE) } + }, + + { eErrorEventTypeBootMicroReset, { (ARTIFACT_BIT_ALL_OUTPUT_LOG + | ARTIFACT_BIT_NAVI_LOG), (EVENT_BIT_NONE) } }, + + { eErrorEventTypeEelExport, { ARTIFACT_BIT_ALL_OUTPUT_LOG, + (EVENT_BIT_POPUP | EVENT_BIT_CAN_NOTIFICATION) } }, + + { eErrorEventTypeInterfaceunifiedEmmcLogs, { (ARTIFACT_BIT_DEBUG_FOLDER_CONTENT + | ARTIFACT_BIT_DEBUG_FOLDER2_CONTENT), + + (EVENT_BIT_POPUP | EVENT_BIT_CAN_NOTIFICATION) } }, + + { eErrorEventTypeDiagEvent, { ARTIFACT_BIT_ALL_OUTPUT_LOG, + (EVENT_BIT_DIAG) } }, + + { eErrorEventTypeCanEvent, { ARTIFACT_BIT_ALL_OUTPUT_LOG, + (EVENT_BIT_CAN_NOTIFICATION) } }, + + { eErrorEventTypeDtcEvent, { (ARTIFACT_BIT_ALL_OUTPUT_LOG + | ARTIFACT_BIT_NAVI_LOG), + + (EVENT_BIT_CAN_NOTIFICATION) } }, + + { eErrorEventTypeModConnFailed, { (ARTIFACT_BIT_ALL_OUTPUT_LOG + | ARTIFACT_BIT_NAVI_LOG), (EVENT_BIT_NONE) } }, + + { eErrorEventTypeStartRespFailed, { (ARTIFACT_BIT_ALL_OUTPUT_LOG + | ARTIFACT_BIT_NAVI_LOG), (EVENT_BIT_NONE) } }, + + { eErrorEventTypeModuleInvokedResetRequest, { (ARTIFACT_BIT_ALL_OUTPUT_LOG + | ARTIFACT_BIT_NAVI_LOG), (EVENT_BIT_NONE) } }, + + { eErrorEventTypeModuleInvokedCollectDebugLogs, + { (ARTIFACT_BIT_ALL_OUTPUT_LOG | ARTIFACT_BIT_NAVI_LOG), + (EVENT_BIT_NONE) } }, + + { eErrorEventTypeUserInvokedClearLogs, { (ARTIFACT_BIT_NONE + | ARTIFACT_BIT_CLEAR_ALL_LOG), (EVENT_BIT_NONE) } }, + + { eErrorEventTypeUserInvokedCollectNaviLog, { (ARTIFACT_BIT_NONE + | ARTIFACT_BIT_NAVI_LOG), (EVENT_BIT_NONE) } }, + + { eErrorEventTypeGroupRelaunch, { (ARTIFACT_BIT_ALL_OUTPUT_LOG + | ARTIFACT_BIT_NAVI_LOG), (EVENT_BIT_NONE) } }, + + { eErrorEventTypeReserved1, { (ARTIFACT_BIT_NONE), (EVENT_BIT_NONE) } }, + + { eErrorEventTypeReserved2, { (ARTIFACT_BIT_NONE), (EVENT_BIT_NONE) } }, + + { eErrorEventTypeReserved3, { (ARTIFACT_BIT_NONE), (EVENT_BIT_NONE) } } }; + +TLoggingArtifact CErrorEventCfg::m_loggerErrorArtifactCfgTbl[eArtifactIdMaxValue] = { // LCOV_EXCL_BR_LINE 11:Unexpected branch + /*Artifact ID Owner Timeout Callback Type Path CallBack Function Delete tmp artifact*/ + { eArtifactIdInterfaceunifiedDebugLog, { SERVICE_LOGGER, 5000, { eCbTypeFunction, "", SSLogger_SendtoSelf }, TRUE } }, + { eArtifactIdTransmitLog, { SERVICE_LOGGER, 5000, { eCbTypeFunction, "", SSLogger_SendtoSelf }, TRUE } }, + { eArtifactIdPerformanceLog, { SERVICE_LOGGER, 5, { eCbTypeFunction, "", SSLogger_SendtoSelf }, FALSE } }, + { eArtifactIdBootMicroLog, { SERVICE_SYSMANAGER, 1000, { eCbTypeFunction, "", SSLogger_SendtoSM }, TRUE } }, + { eArtifactIdSystemDataCsv, { SERVICE_SYSMANAGER, 5000, { eCbTypeFunction, "", SSLogger_SendtoSM }, TRUE } }, + { eArtifactIdShowMemTxt, { SERVICE_SYSMANAGER, 8000, { eCbTypeFunction, "", SSLogger_SendtoSM }, TRUE } }, + { eArtifactIdProcessCore, { SERVICE_SYSMANAGER, 5000, { eCbTypeFunction, "", SSLogger_SendtoSM }, TRUE } }, + { eArtifactIdDebugDumpLog, { SERVICE_SYSMANAGER, 4000, { eCbTypeFunction, "", SSLogger_SendtoSM }, TRUE } }, + { eArtifactIdScreenShot, { SERVICE_LOGGER, 1100, { eCbTypeFunction, "", SSLogger_SendtoSelf }, TRUE } }, + { eArtifactIdDebugFolderContent, { SERVICE_LOGGER, 50000, { eCbTypePath, LAF_DEBUG_FOLDER, NULL }, FALSE } }, + { eArtifactIdDebugFolder2Content, { SERVICE_LOGGER, 50000, { eCbTypePath, LAF_DEBUG_FOLDER2, NULL }, FALSE } }, + { eArtifactIdKernelLog, { SERVICE_LOGGER, 5000, { eCbTypeFunction, "", SSLogger_SendtoSelf }, TRUE } }, + { eArtifactIdKernelBootLog, { SERVICE_LOGGER, 5000, { eCbTypePath, LAF_KERNEL_BOOT_FN, NULL }, FALSE } }, + { eArtifactIdDRInitialLog, { SERVICE_LOGGER, 500, { eCbTypeFunction, "", SSLogger_SendtoSelf }, TRUE } }, + { eArtifactIdDRLocationLog, { SERVICE_LOGGER, 500, { eCbTypeFunction, "", SSLogger_SendtoSelf }, TRUE } }, + { eArtifactIdCpuHighLoadMonteCarloLogs, { SERVICE_LOGGER, 50, { eCbTypePath, LAF_MONTECARLO_FN, NULL }, TRUE } }, + { eArtifactIdMetaCoreLogs, { SERVICE_LOGGER, 50, { eCbTypePath, LAF_METACORE_FN, NULL }, TRUE } }, + { eArtifactIdCmsLogs, { SERVICE_LOGGER, 500, { eCbTypePath, LAF_CMS_FN, NULL }, TRUE } }, + { eArtifactIDInternalDTC, { SERVICE_LOGGER, 500, { eCbTypePath, LAF_INT_DTC_FN, NULL }, TRUE } }, + { eArtifactIdComDebugLog, { SERVICE_LOGGER, 500, { eCbTypePath, LAF_LOGGERSERVICELOG_COM, NULL }, FALSE } }, + { eArtifactIdPstoreLog, { SERVICE_LOGGER, 50, { eCbTypePath, LAF_PSTORELOG, NULL }, FALSE } }, + { eArtifactIdClearAllLog, { SERVICE_LOGGER, 500, { eCbTypeFunction, "", SSLogger_SendtoSelf }, FALSE } }, + { eArtifactIdNaviLog, { SERVICE_LOGGER, 5000, { eCbTypeFunction, "", SSLogger_SendtoSelf }, FALSE } }, +}; // LCOV_EXCL_BR_LINE 11:Unexpected branch + +CErrorEventCfg::CErrorEventCfg() { + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+"); + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-"); +} + +CErrorEventCfg::~CErrorEventCfg() { // LCOV_EXCL_START 14:globle instance + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+"); + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-"); +} +// LCOV_EXCL_STOP + +EFrameworkunifiedStatus CErrorEventCfg::Initialize(CLoggerCfg* p_logger_cfg) { + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+"); + EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK; + UI_32 l_cnt; + + m_ext_log_num = 0; + ExternalLogList ext_log = p_logger_cfg->GetExternalLogList(); + + for (l_cnt = 0; l_cnt < eArtifactIdMaxValue; l_cnt++) { + EArtifactId l_artifactId = m_loggerErrorArtifactCfgTbl[l_cnt].ArtifactId; + TLoggingArtifactInformation l_artifactInformation = + m_loggerErrorArtifactCfgTbl[l_cnt].Information; + m_errorArtifactMap[l_artifactId] = l_artifactInformation; // LCOV_EXCL_BR_LINE 11:Unexpected branch + } + for (l_cnt = 0; l_cnt < eErrorEventTypeMaxValue; l_cnt++) { + EErrorEventType l_eventType = m_loggerErrorEventCfgTbl[l_cnt].ErrorType; + TLoggingErrorEventInformation l_errorEvtInformation = + m_loggerErrorEventCfgTbl[l_cnt].Information; + m_errorEventTypeToArtifactBitMaskMap[l_eventType] = l_errorEvtInformation; + } + + // Set external log info + if (ext_log.num > 0) { + if (ext_log.num <= ext_log.max) { + m_ext_log_num = ext_log.num; + } else { + m_ext_log_num = ext_log.max; + } + + for (UI_32 i = 0; i < m_ext_log_num; i++) { + EArtifactId l_artifactId = (EArtifactId) (eArtifactIdMaxValue + i); + TLoggingArtifactInformation artifact_info; + artifact_info.Cb.Function = NULL; + artifact_info.Cb.Path = ext_log.p_info[i].path; + artifact_info.Cb.Type = eCbTypePath; + artifact_info.OwnerServiceName = SERVICE_LOGGER; + artifact_info.Remove = ext_log.p_info[i].remove; + artifact_info.RequestTimeoutMs = 5000; + m_errorArtifactMap[l_artifactId] = artifact_info; + } + } + + l_eStatus = (EFrameworkunifiedStatus) ValidateConfiguration(); + LOG_STATUS_IF_ERRORED(l_eStatus, "ValidateConfiguration()"); // LCOV_EXCL_BR_LINE 5:macro + + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-"); + return (l_eStatus); +} + +UI_32 CErrorEventCfg::ValidateConfiguration(void) { + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+"); + + UI_32 l_return = 0; + + if ((eArtifactIdMaxValue + m_ext_log_num) != m_errorArtifactMap.size()) { // LCOV_EXCL_BR_LINE 6:Be sure not to exceed the eArtifactIdMaxValue + // LCOV_EXCL_START 6:Be sure not to exceed the eArtifactIdMaxValue + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, + "Artifact map size mismatch: Expected: %d, Found: %d", + (eArtifactIdMaxValue + m_ext_log_num), m_errorArtifactMap.size()); + l_return |= 1; + // LCOV_EXCL_STOP + } + if (eErrorEventTypeMaxValue != m_errorEventTypeToArtifactBitMaskMap.size()) { // LCOV_EXCL_BR_LINE 6:Be sure not to exceed the eErrorEventTypeMaxValue + // LCOV_EXCL_START 6:Be sure not to exceed the eErrorEventTypeMaxValue + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, + "Error event map size mismatch: Expected: %d, Found: %d", + eErrorEventTypeMaxValue, m_errorEventTypeToArtifactBitMaskMap.size()); + l_return |= 4; + // LCOV_EXCL_STOP + } + + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-"); + return (l_return); +} + +void CErrorEventCfg::GetArtifactRequestVec( + EErrorEventType f_eventType, + std::vector<TLoggingArtifact> &f_refArtifactRequestVec) { + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+"); + ARTIFACT_BIT_MASK l_artifactRequestBits = 0; + ARTIFACT_BIT l_artifactBit; + TLoggingArtifact l_artifact; + UI_32 l_artifactId; + + f_refArtifactRequestVec.clear(); + + if (f_eventType < eErrorEventTypeMaxValue) { + l_artifactRequestBits = m_errorEventTypeToArtifactBitMaskMap[f_eventType] + .ArtifactBitMask; + } + + if (l_artifactRequestBits > 0) { + for (l_artifactId = 0; l_artifactId < eArtifactIdMaxValue; l_artifactId++) { + l_artifactBit = (ARTIFACT_BIT) (1 << l_artifactId); + if ((l_artifactRequestBits & l_artifactBit) > 0) { + l_artifact.ArtifactId = (EArtifactId) l_artifactId; + l_artifact.Information = m_errorArtifactMap[l_artifact.ArtifactId]; + f_refArtifactRequestVec.push_back(l_artifact); + } + } + + // Set external log info + if (m_ext_log_num > 0) { + for (l_artifactId = 0; l_artifactId < m_ext_log_num; l_artifactId++) { + l_artifact.ArtifactId = (EArtifactId) (eArtifactIdMaxValue + l_artifactId); + l_artifact.Information = m_errorArtifactMap[l_artifact.ArtifactId]; + f_refArtifactRequestVec.push_back(l_artifact); + } + } + } + + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-"); +} + +EVENT_BIT_MASK CErrorEventCfg::GetEventsForErrorEvent( + EErrorEventType f_eventType) { + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+"); + EVENT_BIT_MASK l_events = EVENT_BIT_NONE; + if (f_eventType < eErrorEventTypeMaxValue) { // LCOV_EXCL_BR_LINE 6:Be sure not to exceed the eErrorEventTypeMaxValue + l_events = m_errorEventTypeToArtifactBitMaskMap[f_eventType].EventBitMask; + } + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-"); + return (l_events); +} // LCOV_EXCL_BR_LINE 10:the last line diff --git a/systemservice/logger_service/server/src/ss_logger_error_event_responses.cpp b/systemservice/logger_service/server/src/ss_logger_error_event_responses.cpp new file mode 100755 index 0000000..dc23d8b --- /dev/null +++ b/systemservice/logger_service/server/src/ss_logger_error_event_responses.cpp @@ -0,0 +1,625 @@ +/* + * @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_SS_LoggerService +/// \brief This file supports error event logging. +/// +/////////////////////////////////////////////////////////////////////////////// +#include <string.h> +#include <unistd.h> +#include <sys/wait.h> +#include <boost/bind.hpp> +#include <errno.h> +#include <sys/types.h> +#include <sys/stat.h> +#include <sys/klog.h> +#include <native_service/frameworkunified_framework_if.h> +#include <native_service/frameworkunified_multithreading.h> +#include <native_service/ns_sharedmem.h> +#include <native_service/ns_sharedmem_reader.h> +#include <native_service/ns_ringbuffer.h> +#include <native_service/ns_logger_if.h> +#include <system_service/ss_sm_client_if.h> +#include <system_service/ss_logger_service_protocol.h> +#include <system_service/ss_services.h> +#include <system_service/ss_templates.h> +#include <native_service/cl_process.h> +#include <native_service/cl_lockid.h> +#include <sstream> +#include <string> +#include "loggerservicedebug_loggerservicelog.h" +#include "loggerservicedebug_thread_if.h" +#include "ss_logger_error_event.h" +#include "ss_logger_service_callbacks.h" +#include "ss_logger_scrshot.h" +#include "ss_logger_fs_directory.h" +#include "ss_logger_common.h" +#include "ss_logger_types.h" + +EFrameworkunifiedStatus SSLogger_SendtoSM(HANDLE f_hApp, TLoggingArtifact f_artifact) { + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+"); + EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK; + l_eStatus = SendLogArtifactRequestToSystemManager(f_artifact.ArtifactId); + if (eFrameworkunifiedStatusOK != l_eStatus) { + FRAMEWORKUNIFIEDLOG( + ZONE_ERR, + __FUNCTION__, + " Error. SendLogArtifactRequestToSystemManager returned: %d for artifact ID: %d", + l_eStatus, f_artifact.ArtifactId); + } + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-"); + return (l_eStatus); +} + +EFrameworkunifiedStatus SSLogger_SendtoSelf(HANDLE f_hApp, TLoggingArtifact f_artifact) { + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+"); + EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusNullPointer; + if (NULL != f_hApp) { // LCOV_EXCL_BR_LINE 6: double check + l_eStatus = FrameworkunifiedSendSelf(f_hApp, SS_LOGGER_ERROR_EVENT_ARTIFACT_REQ, + sizeof(f_artifact.ArtifactId), + &f_artifact.ArtifactId); + + if (eFrameworkunifiedStatusOK != l_eStatus) { // LCOV_EXCL_BR_LINE 4: NSFW error case. + // LCOV_EXCL_START 4: NSFW error case. + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + FRAMEWORKUNIFIEDLOG( + ZONE_ERR, + __FUNCTION__, + " Error. FrameworkunifiedSendSelf(SS_LOGGER_ERROR_EVENT_ARTIFACT_REQ) returned error: %d for artifact ID: %d.", + l_eStatus, f_artifact.ArtifactId); + // LCOV_EXCL_STOP + } + } + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-"); + return (l_eStatus); +} +/////////////////////////////////////////////////////////////////////////// +// Function : SendLogArtifactResponseToSelf +// brief : Collect frameworkunifiedlog artifact and return a response to +// SS_Logger. +/////////////////////////////////////////////////////////////////////////// +EFrameworkunifiedStatus CErrorEvent::SendLogArtifactResponseToSelf( + HANDLE f_hApp, EArtifactId f_artifactId, + std::string f_artifactFilePathAndName) { + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+"); + EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK; + ARTIFACT_RESPONSE l_artifactResponse; + + l_artifactResponse.ArtifactId = f_artifactId; + + strncpy(l_artifactResponse.FilePathAndName, f_artifactFilePathAndName.c_str(), + sizeof(l_artifactResponse.FilePathAndName) - 1); + + l_eStatus = FrameworkunifiedSendSelf(f_hApp, SS_SM_ERROR_EVENT_ARTIFACT_RSPN, + sizeof(l_artifactResponse), &l_artifactResponse); + + LOG_STATUS_IF_ERRORED(l_eStatus, + "FrameworkunifiedSendSelf(SS_SM_ERROR_EVENT_ARTIFACT_RSPN)"); + + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-"); + return (l_eStatus); +} + +/////////////////////////////////////////////////////////////////////////// +// Function : OnObtainLoggerserviceLogRequest +// brief : Collect frameworkunifiedlog artifact and return a response to +// SS_Logger. +/////////////////////////////////////////////////////////////////////////// +EFrameworkunifiedStatus CErrorEvent::OnObtainLoggerserviceLogRequest(HANDLE f_hApp) { + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+"); + EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK; + std::string dir_path = DEBUG_LOG_PATH_DIR; + + l_eStatus = CFSDirectory::CreateDirectory(dir_path); + if (l_eStatus != eFrameworkunifiedStatusOK) { + FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "Error: Create FRAMEWORKUNIFIEDLOG tmp directory %d", + l_eStatus); + } else { + UI_32 l_DumpSize = 0; + std::string src_file_path; + std::string dst_file_path; + PCSTR file_name; + UI_32 num; + bool log_clear = true; + + switch (m_errorEventNtfData.EventType) { + // _DIAG + case eErrorEventTypeUserInvokedUserForceReset: + case eErrorEventTypeUserInvokedCollectAllLogs: + case eErrorEventTypeUserInvokedCollectScreenShot: + case eErrorEventTypeUserInvokedCollectInterfaceunifiedLogs: + case eErrorEventTypeDiagEvent: + case eErrorEventTypeCanEvent: + case eErrorEventTypeDtcEvent: + case eErrorEventTypeModuleInvokedCollectDebugLogs: + // _DEBUG + case eErrorEventTypeUserInvokedCollectDevLogs: + log_clear = false; + break; + default: + break; + } + + num = NSLogGetFrameworkunifiedlogFileTotalNum(); + for (UI_32 cont = 0; cont < num; cont++) { + file_name = NSLogGetFrameworkunifiedlogFileName(cont); + if (file_name == NULL) { + break; + } + src_file_path = FRAMEWORKUNIFIEDLOG_RAMDISC_PATH; + src_file_path.append("/"); + src_file_path.append(file_name); + dst_file_path = DEBUG_LOG_PATH_DIR; + dst_file_path.append("/"); + dst_file_path.append(file_name); + CNSRingBuffer* l_pLoggerservicelog; + int index; + index = NSLogGetFrameworkunifiedlogIndex(src_file_path.c_str()); + l_pLoggerservicelog = new (std::nothrow) CNSRingBuffer( + src_file_path, 0, index + LOCK_NSLOG_ACCES_IF_1); + if (l_pLoggerservicelog == NULL) { // LCOV_EXCL_BR_LINE 5: new's error case + // LCOV_EXCL_START 5: new's error case + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + l_eStatus = eFrameworkunifiedStatusInvldHandle; + FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, + "Error: FRAMEWORKUNIFIEDLOG RingBuffer handle is NULL %s", + src_file_path.c_str()); + // LCOV_EXCL_STOP + } else if (eFrameworkunifiedStatusOK != (l_eStatus = l_pLoggerservicelog->Open())) { + FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, + "Error: FRAMEWORKUNIFIEDLOG RingBuffer Open failed %s %d", + src_file_path.c_str(), l_eStatus); + } else if (eFrameworkunifiedStatusOK + != (l_eStatus = l_pLoggerservicelog->DumpToFile(dst_file_path.c_str(), + &l_DumpSize))) { + FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, + "Error: FRAMEWORKUNIFIEDLOG RingBuffer DumpToFile failed %s %d", + src_file_path.c_str(), l_eStatus); + } + if (NULL != l_pLoggerservicelog) { // LCOV_EXCL_BR_LINE 5: new's error case + if (log_clear) { + if (eFrameworkunifiedStatusOK != (l_eStatus = l_pLoggerservicelog->ClearBuf())) { + FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, + "Error: FRAMEWORKUNIFIEDLOG RingBuffer ClearBuf failed %s %d", + src_file_path.c_str(), l_eStatus); + } + } + (void) l_pLoggerservicelog->Close(); + delete l_pLoggerservicelog; + } + } + l_eStatus = SendLogArtifactResponseToSelf(f_hApp, eArtifactIdInterfaceunifiedDebugLog, + DEBUG_LOG_PATH_DIR); + LOG_STATUS_IF_ERRORED( + l_eStatus, "SendLogArtifactResponseToSelf(eArtifactIdInterfaceunifiedDebugLog)"); + } + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-"); + return (l_eStatus); +} + +/////////////////////////////////////////////////////////////////////////// +// Function : OnObtainLoggerserviceLogRequest +// brief : Collect frameworkunifiedlog artifact and return a response to +// SS_Logger. +/////////////////////////////////////////////////////////////////////////// +EFrameworkunifiedStatus CErrorEvent::OnObtainTransmitLogRequest(HANDLE f_hApp) { + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+"); + EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK; + std::string l_RootPath; + + l_eStatus = m_pReaderWriterControl->FlushCache(eReaderWriterLogTransmit); + LOG_STATUS_IF_ERRORED(l_eStatus, "m_pReaderWriterControl->FlushCache(eReaderWriterLogTransmit)"); + l_RootPath = TRANSMIT_LOG_PATH_FN; + if (access(l_RootPath.c_str(), R_OK) != 0) { + l_RootPath = ""; + } + l_eStatus = SendLogArtifactResponseToSelf(f_hApp, eArtifactIdTransmitLog, + l_RootPath.c_str()); + + LOG_STATUS_IF_ERRORED(l_eStatus, + "SendLogArtifactResponseToSelf(eArtifactIdTransmitLog)"); + + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-"); + return (l_eStatus); +} + +/////////////////////////////////////////////////////////////////////////// +// Function : OnObtainLoggerserviceLogRequest +// brief : Collect frameworkunifiedlog artifact and return a response to +// SS_Logger. +/////////////////////////////////////////////////////////////////////////// +EFrameworkunifiedStatus CErrorEvent::OnObtainPerformanceLogRequest(HANDLE f_hApp) { + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+"); + EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK; + + l_eStatus = m_pReaderWriterControl->FlushCache(eReaderWriterLogPerformance); + LOG_STATUS_IF_ERRORED( + l_eStatus, + "m_pReaderWriterControl->FlushCache(eReaderWriterLogPerformance)"); + l_eStatus = SendLogArtifactResponseToSelf(f_hApp, eArtifactIdPerformanceLog, + PERFORMANCE_LOG_PATH_FN); + + LOG_STATUS_IF_ERRORED( + l_eStatus, "SendLogArtifactResponseToSelf(eArtifactIdPerformanceLog)"); + + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-"); + return (l_eStatus); +} + +/////////////////////////////////////////////////////////////////////////// +// Function : OnObtainScreenShotRequest +// brief : Collect screen shot artifact from PLM and return a response +// to SS_Logger. +/////////////////////////////////////////////////////////////////////////// +EFrameworkunifiedStatus CErrorEvent::OnObtainScreenShotRequest(HANDLE f_hApp) { + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+"); + + EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusFail; + + l_eStatus = SendLogArtifactResponseToSelf(f_hApp, eArtifactIdScreenShot, + SCREEN_SHOT_PATH); + LOG_STATUS_IF_ERRORED( + l_eStatus, "SendLogArtifactResponseToSelf(eArtifactIdScreenShot)"); + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-"); + return l_eStatus; +} + +/////////////////////////////////////////////////////////////////////////// +// Function : OnObtainScreenShotResponse +// brief : Callback from PLM when the screen shot file has been written +// to storage. The data received contains the file path and +// name to the written screen shot file. See +// SS_LOGGER_SCREENCAPTURE_EVT_ACK. +/////////////////////////////////////////////////////////////////////////// +EFrameworkunifiedStatus CErrorEvent::OnObtainScreenShotResponse(HANDLE f_hApp) { + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+"); + EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK; + STScreenCaptureEvt l_ScreenCaptureEvtAck; + + if (eFrameworkunifiedStatusOK != (l_eStatus = ReadMsg<STScreenCaptureEvt>(f_hApp, l_ScreenCaptureEvtAck))) { // LCOV_EXCL_BR_LINE 200:To ensure success // NOLINT[whitespace/line_length] + // LCOV_EXCL_START 200:To ensure success + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + LOG_ERROR("ReadMsg()"); + // LCOV_EXCL_STOP + } else { + if (FALSE == l_ScreenCaptureEvtAck.fSucessful) { + FRAMEWORKUNIFIEDLOG( + ZONE_ERR, + __FUNCTION__, + " Error. Screen shot acquisition failed. l_ScreenCaptureEvtAck.fSucessful == FALSE."); + l_ScreenCaptureEvtAck.strNameAndLocation[0] = '\0'; + } + + l_eStatus = SendLogArtifactResponseToSelf( + f_hApp, eArtifactIdScreenShot, + l_ScreenCaptureEvtAck.strNameAndLocation); // LCOV_EXCL_BR_LINE 11:Unexpected branch + + LOG_STATUS_IF_ERRORED( // LCOV_EXCL_BR_LINE 5:macro + l_eStatus, "SendLogArtifactResponseToSelf(eArtifactIdScreenShot)"); + } + + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-"); + return (l_eStatus); +} + +/////////////////////////////////////////////////////////////////////////// +// Function : OnObtainKernelLogInfoRequest +// brief : Collect kernel log artifact and return a response to +// SS_Logger. +/////////////////////////////////////////////////////////////////////////// +EFrameworkunifiedStatus CErrorEvent::OnObtainKernelLogInfoRequest(HANDLE f_hApp) { + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+"); + + EFrameworkunifiedStatus l_eStatus = CreateKernelLog(f_hApp, SS_LOGGER_KLOG_GET); + + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-"); + return (l_eStatus); +} + +/////////////////////////////////////////////////////////////////////////// +// Function : OnObtainDRInitialLogRequest +// brief : Collect DRInitialLog artifact and return a response to +// SS_Logger. +/////////////////////////////////////////////////////////////////////////// +EFrameworkunifiedStatus CErrorEvent::OnObtainDRInitialLogRequest(HANDLE f_hApp) { + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+"); + EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK; + UI_32 l_DumpSize = 0; + + CNSSharedMemReader* l_pDRInitial = new (std::nothrow) CNSSharedMemReader( + SHMEM_DRINITIALLOG, FALSE); + + if (NULL == l_pDRInitial) { // LCOV_EXCL_BR_LINE 5: new's error case + l_eStatus = eFrameworkunifiedStatusInvldHandle; + FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "Error: DRInitial SharedMem handle is NULL"); + } else if (eFrameworkunifiedStatusOK != (l_eStatus = l_pDRInitial->Open())) { + FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "Error: DRInitial Open failed %d", l_eStatus); + } else if (eFrameworkunifiedStatusOK + != (l_eStatus = l_pDRInitial->DumpToFile(DRINITIAL_LOG_PATH_FN, + &l_DumpSize))) { + FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "Error: DRInitial DumpToFile failed %d", + l_eStatus); + } else { + l_eStatus = SendLogArtifactResponseToSelf(f_hApp, eArtifactIdDRInitialLog, + DRINITIAL_LOG_PATH_FN); + LOG_STATUS_IF_ERRORED( + l_eStatus, "SendLogArtifactResponseToSelf(eArtifactIdDRInitialLog)"); + } + + if (NULL != l_pDRInitial) { // LCOV_EXCL_BR_LINE 5: new's error case + (void) l_pDRInitial->Close(); + } + + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-"); + return (l_eStatus); +} + +/////////////////////////////////////////////////////////////////////////// +// Function : OnObtainDRLocationLogRequest +// brief : Collect DRLocationLog artifact and return a response to +// SS_Logger. +/////////////////////////////////////////////////////////////////////////// +EFrameworkunifiedStatus CErrorEvent::OnObtainDRLocationLogRequest(HANDLE f_hApp) { + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+"); + EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK; + UI_32 l_DumpSize = 0; + + CNSSharedMemReader* l_pDRLocation = new (std::nothrow) CNSSharedMemReader( + SHMEM_DRLOCATIONLOG, FALSE); + + if (NULL == l_pDRLocation) { // LCOV_EXCL_BR_LINE 5: new's error case + l_eStatus = eFrameworkunifiedStatusInvldHandle; + FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "Error: DRInitial SharedMem handle is NULL"); + } else if (eFrameworkunifiedStatusOK != (l_eStatus = l_pDRLocation->Open())) { + FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "Error: DRLocation Open failed %d", + l_eStatus); + } else if (eFrameworkunifiedStatusOK + != (l_eStatus = l_pDRLocation->DumpToFile(DRLOCATION_LOG_PATH_FN, + &l_DumpSize))) { + FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "Error: DRLocation DumpToFile failed %d", + l_eStatus); + } else { + l_eStatus = SendLogArtifactResponseToSelf(f_hApp, eArtifactIdDRLocationLog, + DRLOCATION_LOG_PATH_FN); + + LOG_STATUS_IF_ERRORED( + l_eStatus, "SendLogArtifactResponseToSelf(eArtifactIdDRLocationLog)"); + } + + if (NULL != l_pDRLocation) { // LCOV_EXCL_BR_LINE 5: new's error case + (void) l_pDRLocation->Close(); + delete l_pDRLocation; + } + + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-"); + return (l_eStatus); +} + +/////////////////////////////////////////////////////////////////////////// +// Function : OnClearAllLogRequest +// brief : Callback from LoggerService when the event log file has been delete +// from storage. The data received contains the file path. +/////////////////////////////////////////////////////////////////////////// +EFrameworkunifiedStatus CErrorEvent::OnClearAllLogRequest(HANDLE f_hApp) { + std::string clear_file_path = CLEAR_LOG_PATH_FN; + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+"); + EFrameworkunifiedStatus l_eStatus; + + if (CFSDirectory::RemoveSubDirectory(clear_file_path)) { + FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__, + "SS_Logger Clear %s directory delete successful.", + clear_file_path.c_str()); + } else { + FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, + "SS_Logger Clear %s directory delete failed.", + clear_file_path.c_str()); + } + + clear_file_path = "/nv/BS/ss/logger_service/rwdata/log2/awlog/"; + if (CFSDirectory::RemoveSubDirectory(clear_file_path)) { + FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__, + "SS_Logger Clear %s directory delete successful.", + clear_file_path.c_str()); + } else { + FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, + "SS_Logger Clear %s directory delete failed.", + clear_file_path.c_str()); + } + + clear_file_path = "/nv/BS/ss/logger_service/rwdata/log2/core/"; + if (CFSDirectory::RemoveSubDirectory(clear_file_path)) { + FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__, + "SS_Logger Clear %s directory delete successful.", + clear_file_path.c_str()); + } else { + FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, + "SS_Logger Clear %s directory delete failed.", + clear_file_path.c_str()); + } + + l_eStatus = SendLogArtifactResponseToSelf(f_hApp, eArtifactIdClearAllLog, + clear_file_path.c_str()); + LOG_STATUS_IF_ERRORED(l_eStatus, + "SendLogArtifactResponseToSelf(eArtifactIdClearAllLog)"); + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-"); + return (l_eStatus); +} + +/////////////////////////////////////////////////////////////////////////// +// Function : OnNaviLogRequest +// brief : Callback from LoggerService when the event log file has been xxxxxx BUGBUG +// from storage. The data received contains the file path. +/////////////////////////////////////////////////////////////////////////// +EFrameworkunifiedStatus CErrorEvent::OnNaviLogRequest(HANDLE f_hApp) { + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+"); + EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK; + + EFrameworkunifiedStatus naviLog_status; + switch (m_errorEventNtfData.EventType) { + case eErrorEventTypeProcessCrash: + case eErrorEventTypeProcessExit: + case eErrorEventTypeHeartBeatFailure: + case eErrorEventTypeSystemLowMemory: + case eErrorEventTypeBootMicroReset: + case eErrorEventTypeModConnFailed: + case eErrorEventTypeStartRespFailed: + case eErrorEventTypeModuleInvokedResetRequest: + case eErrorEventTypeGroupRelaunch: + naviLog_status = SaveNaviLog(epssdmsdtGENERIC_ERROR_RESET); + break; + default: + naviLog_status = SaveNaviLog(epssdmsdtNORMAL_RESET); + break; + } + FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "Error: Fail to save Navi Log %d", + naviLog_status); + + l_eStatus = SendLogArtifactResponseToSelf(f_hApp, eArtifactIdNaviLog, ""); + LOG_STATUS_IF_ERRORED(l_eStatus, + "SendLogArtifactResponseToSelf(eArtifactIdNaviLog)"); + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-"); + return (l_eStatus); +} + +EFrameworkunifiedStatus CErrorEvent::CheckPathForArtifact(HANDLE f_hApp, + TLoggingArtifact f_artifact) { + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+"); + EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusInvldParam; + std::string l_Path; + + if (f_artifact.Information.Cb.Type == eCbTypePath) { + l_Path = f_artifact.Information.Cb.Path; + if (access(l_Path.c_str(), R_OK) != 0) { + FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__, + "File/Directory %s not found. Returning empty string.", + l_Path.c_str()); + l_Path = ""; + } + l_eStatus = SendLogArtifactResponseToSelf(f_hApp, f_artifact.ArtifactId, + l_Path.c_str()); + + LOG_STATUS_IF_ERRORED(l_eStatus, "SendLogArtifactResponseToSelf()"); + } + + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-"); + return (l_eStatus); +} + +/* Read all messages remaining in the ring buffer. (allowed for non-root) */ +#define SYSLOG_ACTION_READ_ALL 3 +/* Return size of the log buffer */ +#define SYSLOG_ACTION_SIZE_BUFFER 10 + +EFrameworkunifiedStatus CErrorEvent::CreateKernelLog(HANDLE f_hApp, + SS_LOGGER_KLOG_OPE_TYPE type) { + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+"); + EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK; + int len; + int fd; + char* buf; + ssize_t wr_len; + + len = klogctl(SYSLOG_ACTION_SIZE_BUFFER, NULL, 0); + if (len < 0) { // LCOV_EXCL_BR_LINE 5: klogctl's error case + // LCOV_EXCL_START 5: klogctl's error case + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + l_eStatus = eFrameworkunifiedStatusFail; + FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, + "Error. Failed to get syslog buffer size: %d, %s", errno, + strerror(errno)); + // LCOV_EXCL_STOP + } else { + buf = reinterpret_cast<char*>(malloc(len)); + if (buf != NULL) { // LCOV_EXCL_BR_LINE 5: new's error case + len = klogctl(SYSLOG_ACTION_READ_ALL, buf, len); + if ((len < 0) || (len == 0)) { // LCOV_EXCL_BR_LINE 5: klogctl's error case + // LCOV_EXCL_START 5: klogctl's error case + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + l_eStatus = eFrameworkunifiedStatusFail; + FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, + "Error. Failed to read syslog buffer: %d, %s", errno, + strerror(errno)); + // LCOV_EXCL_STOP + } else { + std::string file_put_path = ""; + EArtifactId artifact_id = eArtifactIdMaxValue; + switch (type) { + case SS_LOGGER_KLOG_GET: + file_put_path = KERNEL_LOG_PATH_FN; + artifact_id = eArtifactIdKernelLog; + fd = open(file_put_path.c_str(), + O_WRONLY | O_CREAT | O_TRUNC | O_CLOEXEC, 0644); + break; + case SS_LOGGER_KBOOTLOG_CREATE: + file_put_path = KERNEL_BOOT_LOG_PATH_FN; + artifact_id = eArtifactIdKernelBootLog; + fd = open(file_put_path.c_str(), + O_WRONLY | O_CREAT | O_TRUNC | O_CLOEXEC, 0644); + break; + default: + fd = -1; + break; + } + + if (fd == -1) { + l_eStatus = eFrameworkunifiedStatusFail; + FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, + "Error. Failed to open file: %s: %d, %s", + file_put_path.c_str(), errno, strerror(errno)); + } else { + wr_len = write(fd, buf, len); + if (wr_len == -1) { // LCOV_EXCL_BR_LINE 5: write's error case + // LCOV_EXCL_START 5: write's error case + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, + " Error. File write failed. errno: %d, %s", errno, + strerror(errno)); + // LCOV_EXCL_STOP + } + fsync(fd); + close(fd); + + if (SS_LOGGER_KLOG_GET == type) { + l_eStatus = SendLogArtifactResponseToSelf(f_hApp, artifact_id, + file_put_path.c_str()); + if (eFrameworkunifiedStatusOK != l_eStatus) { // LCOV_EXCL_BR_LINE 4: NSFW error case. + // LCOV_EXCL_START 4: NSFW error case. + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + FRAMEWORKUNIFIEDLOG( + ZONE_ERR, + __FUNCTION__, + "SendLogArtifactResponseToSelf failed. EFrameworkunifiedStatus:%d, ArtifactID:%d, Path:%s", + l_eStatus, artifact_id, file_put_path.c_str()); + // LCOV_EXCL_STOP + } + } + } + } + free(buf); + } else { + // LCOV_EXCL_START 5: new's error case + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + l_eStatus = eFrameworkunifiedStatusFail; + FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "Memory allocation Failed %s", + strerror(errno)); + // LCOV_EXCL_STOP + } + } + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-"); + return (l_eStatus); +} + diff --git a/systemservice/logger_service/server/src/ss_logger_error_event_storage.cpp b/systemservice/logger_service/server/src/ss_logger_error_event_storage.cpp new file mode 100755 index 0000000..ffdebe7 --- /dev/null +++ b/systemservice/logger_service/server/src/ss_logger_error_event_storage.cpp @@ -0,0 +1,628 @@ +/* + * @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_SS_LoggerService +/// \brief TODO +/// +/////////////////////////////////////////////////////////////////////////////// +/////////////////////////////////////////////////////////////////////////////// +// INCLUDES +/////////////////////////////////////////////////////////////////////////////// +#include "ss_logger_error_event_storage.h" +#include <stdlib.h> +#include <sched.h> +#include <string.h> +#include <errno.h> +#include <dirent.h> +#include <unistd.h> +#include <string> +#include "ss_logger_util.h" +#include "ss_logger_error_event_archive.h" +#include "ss_logger_fs_directory.h" +#include "ss_logger_common.h" + +CLoggerErrorEventStorage::CLoggerErrorEventStorage() + : m_parentMcQueue(NULL), + m_thread(-1), + m_sendQueue(-1), + m_receiveQueue(-1), + m_destination(""), + m_mutexInit(-1), + m_pLoggerCfg(NULL), + m_logTime(0) { + m_responseVec.clear(); + m_mqattr.mq_flags = 0; + m_mqattr.mq_maxmsg = 1; + m_mqattr.mq_msgsize = 32; + m_mqattr.mq_curmsgs = 0; +} + +CLoggerErrorEventStorage::~CLoggerErrorEventStorage() { // LCOV_EXCL_START 14:globle instance + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + this->Cleanup(); +} +// LCOV_EXCL_STOP + +EFrameworkunifiedStatus CLoggerErrorEventStorage::Initialize(HANDLE f_hApp, + std::string f_ParentName, + CLoggerCfg *f_pLoggerCfg) { + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+"); + EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK; + pthread_attr_t l_attr; + struct sched_param l_params; + + /* Open the queue */ + if (NULL == (m_pLoggerCfg = f_pLoggerCfg)) { // LCOV_EXCL_BR_LINE 200:As it is not always NULL + // LCOV_EXCL_START 200:As it is not always NULL + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + l_eStatus = eFrameworkunifiedStatusNullPointer; + FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, " Error. Parameter f_pLoggerCfg is NULL."); + // LCOV_EXCL_STOP + } else if (eFrameworkunifiedStatusOK != (l_eStatus = m_pLoggerCfg->GetLoggerStorageInfo(m_loggerStorageInfo))) { // LCOV_EXCL_BR_LINE 200:To ensure success // NOLINT[whitespace/line_length] + // LCOV_EXCL_START 200:To ensure success + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, + " Error. GetLoggerStorageInfo(m_loggerStorageInfo)"); + // LCOV_EXCL_STOP + } else if (NULL == (m_parentMcQueue = McOpenSender(f_ParentName.c_str()))) { // LCOV_EXCL_BR_LINE 4:NSFW + // LCOV_EXCL_START 4:NSFW + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + l_eStatus = eFrameworkunifiedStatusErrOther; + FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, " Error. McOpenSender(f_ParentName)"); + // LCOV_EXCL_STOP + } else if (-1 == (this->m_sendQueue = mq_open(m_loggerStorageInfo.Name.c_str(), O_CREAT | O_WRONLY, 0666, &m_mqattr))) { // LCOV_EXCL_BR_LINE 5:C code eror // NOLINT[whitespace/line_length] + // LCOV_EXCL_START 5:C code eror + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + l_eStatus = eFrameworkunifiedStatusErrOther; + FRAMEWORKUNIFIEDLOG( + ZONE_ERR, + __FUNCTION__, + " Error. mq_open(ERROR_EVENT_STORAGE_QUEUE_NAME,O_CREAT | O_WRONLY, 0666, NULL)"); + // LCOV_EXCL_STOP + } else if (-1 == (this->m_receiveQueue = mq_open(m_loggerStorageInfo.Name.c_str(), O_RDONLY))) { // LCOV_EXCL_BR_LINE 5:C code eror // NOLINT[whitespace/line_length] + // LCOV_EXCL_START 5:C code eror + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + l_eStatus = eFrameworkunifiedStatusSessionLimitMaxedOut; + FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, + " Error. mq_open(ERROR_EVENT_STORAGE_QUEUE_NAME,O_RDONLY)"); + // LCOV_EXCL_STOP + } else if (EOK != (m_mutexInit = pthread_mutex_init(&this->m_mutex, NULL))) { // LCOV_EXCL_BR_LINE 5:C code eror + // LCOV_EXCL_START 5:C code eror + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + l_eStatus = eFrameworkunifiedStatusFail; + FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, + " Error. pthread_mutex_init(&this->m_mutex, NULL)"); + // LCOV_EXCL_STOP + } else if (EOK != pthread_attr_init(&l_attr)) { // LCOV_EXCL_BR_LINE 5:C code eror + // LCOV_EXCL_START 5:C code eror + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + l_eStatus = eFrameworkunifiedStatusSemUnlockFail; + FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, " Error. pthread_attr_init()"); + // LCOV_EXCL_STOP + } else if (EOK != pthread_attr_getschedparam(&l_attr, &l_params)) { // LCOV_EXCL_BR_LINE 5:C code eror + // LCOV_EXCL_START 5:C code eror + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + l_eStatus = eFrameworkunifiedStatusSemCloseFail; + FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, " Error. pthread_attr_getschedparam()"); + // LCOV_EXCL_STOP + } else { + l_params.sched_priority = m_loggerStorageInfo.Priority; + if (EOK != pthread_attr_setinheritsched(&l_attr, PTHREAD_EXPLICIT_SCHED)) { // LCOV_EXCL_BR_LINE 5:C code eror + // LCOV_EXCL_START 5:C code eror + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, " Error. pthread_attr_setinheritsched()"); + // LCOV_EXCL_STOP + } else if (EOK != pthread_attr_setschedparam(&l_attr, &l_params)) { // LCOV_EXCL_BR_LINE 5:C code eror + l_eStatus = eFrameworkunifiedStatusDbResultError; + FRAMEWORKUNIFIEDLOG( + ZONE_ERR, + __FUNCTION__, + " Error but continue. pthread_attr_setschedparam(), priority = %d: %s", + m_loggerStorageInfo.Priority, strerror(errno)); // LCOV_EXCL_BR_LINE 11:Unexpected branch + l_eStatus = eFrameworkunifiedStatusOK; + } + if (EOK != pthread_create(&this->m_thread, &l_attr, &CLoggerErrorEventStorage::ThreadFunctionWrapper, this)) { // LCOV_EXCL_BR_LINE 5:C code eror // NOLINT[whitespace/line_length] + // LCOV_EXCL_START 5:C code eror + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + l_eStatus = eFrameworkunifiedStatusDbRecNotFound; + FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, " Error. pthread_create()"); + // LCOV_EXCL_STOP + } else { + l_eStatus = eFrameworkunifiedStatusOK; + } + } + if (eFrameworkunifiedStatusOK != l_eStatus) { // LCOV_EXCL_BR_LINE 200:To ensure success + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + this->Cleanup(); // LCOV_EXCL_LINE 200:To ensure success + } + + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-: %d", l_eStatus); + return (l_eStatus); +} + +EFrameworkunifiedStatus CLoggerErrorEventStorage::Start( + std::string f_target, TArtifactResponseVec f_responseVector, + uint32_t f_time) { + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+"); + EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK; + /* Start the thread*/ + if (EOK == pthread_mutex_lock(&this->m_mutex)) { // LCOV_EXCL_BR_LINE 200:To ensure success + this->m_destination = f_target; + this->m_responseVec = f_responseVector; + this->m_logTime = f_time; + (void) pthread_mutex_unlock(&this->m_mutex); + } + UI_8 l_cmd[MAX_QUEUE_MSG_SIZE]; + l_cmd[0] = 1; + if (-1 == mq_send(this->m_sendQueue, reinterpret_cast<CHAR*>(l_cmd), m_mqattr.mq_msgsize, 0)) { + FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, + " Error. mq_send(this->m_sendQueue %d) return %s", m_sendQueue, + strerror(errno)); + l_eStatus = eFrameworkunifiedStatusFail; + } + + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-: %d", l_eStatus); + return (l_eStatus); +} + +void CLoggerErrorEventStorage::ThreadFunction(void) { + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+"); + char l_data[MAX_QUEUE_MSG_SIZE] = { }; + SI_32 l_bytesRead = -1; + SI_32 l_oldState; + ELoggerStorageThreadCommands l_cmdId = eLoggerStorageThreadCmdWriteFailed; + EFrameworkunifiedStatus l_eStatus; + + (void) pthread_setname_np(pthread_self(), ERROR_EVENT_STORAGE_QUEUE_NAME); + + pthread_cleanup_push(&CLoggerErrorEventStorage::CleanupWrapper, this); + while (-1 // LCOV_EXCL_BR_LINE 200: mq_send can not send size of -1 + != (l_bytesRead = + static_cast<SI_32>(mq_receive(this->m_receiveQueue, reinterpret_cast<char *>(l_data), + (size_t) m_mqattr.mq_msgsize, NULL)))) { + std::string l_target; + TArtifactResponseVec l_responseVec; + uint32_t l_logTime; + uint8_t status; + Clock_getSystemTimeY2K38(&l_logTime, &status); + (void) pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, &l_oldState); + if (EOK == pthread_mutex_lock(&this->m_mutex)) { // LCOV_EXCL_BR_LINE 5: pthread_mutex_lock's error case. + l_target = this->m_destination; + l_responseVec = this->m_responseVec; + l_logTime = this->m_logTime; + this->m_responseVec.clear(); + this->m_destination = ""; + + (void) pthread_mutex_unlock(&this->m_mutex); + } + (void) pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, &l_oldState); + if (access(l_target.c_str(), F_OK) == 0) { + if (CFSDirectory::IsDirectory(l_target)) { // LCOV_EXCL_BR_LINE 6: can not be a dir + // LCOV_EXCL_START 6: new file create, it can not be find + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + BOOL isDeleteFiles = FALSE; + SI_32 l_filesCopied = this->CopyFiles(l_target, l_responseVec, + isDeleteFiles); + + switch (l_filesCopied) { + case -1: + /*Error while moving files*/ + l_cmdId = eLoggerStorageThreadCmdWriteFailed; + break; + case 0: + /*No files where moved*/ + l_cmdId = eLoggerStorageThreadCmdNoWritten; + break; + default: + if (l_filesCopied > 0) { + l_cmdId = eLoggerStorageThreadCmdOK; + FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__, + " Info. %d files successfully copied.", l_filesCopied); + } + break; + } + // LCOV_EXCL_STOP + } + } else { + if (eFrameworkunifiedStatusOK + != (l_eStatus = this->PackageAndPlaceArtifacts(l_target, + l_responseVec, + l_logTime))) { + /*Write Error.*/ + l_cmdId = eLoggerStorageThreadCmdWriteFailed; + } else { + l_cmdId = eLoggerStorageThreadCmdOK; + FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__, + " Info. Archive successfully written."); + } + if (eFrameworkunifiedStatusOK != RemoveDeprecatedArtifacts(l_responseVec)) { + FRAMEWORKUNIFIEDLOG( + ZONE_WARN, __FUNCTION__, + " Warning. Wasn't able to delete all deprecated log artifacts."); + } + } + + std::string l_usb_path; + size_t l_usb_path_length = 0; + if (m_pLoggerCfg != NULL) { // LCOV_EXCL_BR_LINE 6: m_pLoggerCfg can not be null + l_usb_path = m_pLoggerCfg->getUsb0MountPath(); + l_usb_path_length = l_usb_path.length(); + if ((l_usb_path_length > 1) + && (l_usb_path[l_usb_path.length() - 1] == '/')) { + l_usb_path_length--; + } + } + if ((l_usb_path_length > 0) + && (l_target.compare(0, l_usb_path_length, l_usb_path, 0, + l_usb_path_length) != 0)) { + l_usb_path_length = 0; + } + if ((l_usb_path_length == 0) + && (l_target.compare(0, sizeof(DEBUG_USB_PATH) - 1, DEBUG_USB_PATH, 0, + sizeof(DEBUG_USB_PATH) - 1) == 0)) { + l_usb_path = DEBUG_USB_PATH; + l_usb_path_length = sizeof(DEBUG_USB_PATH) - 1; + } + if (l_usb_path_length > 1) { // if USB path is '/' only, length is 1. + // So conditions to be syncfs is greater than 1 + // sync usb device + DIR* l_dirp = opendir(l_usb_path.c_str()); + if (l_dirp != NULL) { // LCOV_EXCL_BR_LINE 5: c code error case + int fd = dirfd(l_dirp); + if (fd != -1) { // LCOV_EXCL_BR_LINE 5: c code error case + if (syncfs(fd) == -1) { + FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, + " Error. syncfs failed path=%s [%s]", l_usb_path.c_str(), + strerror(errno)); + } + } else { + FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, + " Error. syncfs get fd failed path=%s, [%s]", + l_usb_path.c_str(), strerror(errno)); + } + closedir(l_dirp); + } else { + FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, + " Error. syncfs opendir failed path=%s, [%s]", + l_usb_path.c_str(), strerror(errno)); + } + { +#define USB_MEMORY_SYNC_WAITTIME 8 // 8 sec + const struct timespec intval = { USB_MEMORY_SYNC_WAITTIME, 0 }; + FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__, + "%d sec:Waiting for USB Memory Synchronization.(%s)", + USB_MEMORY_SYNC_WAITTIME, l_usb_path.c_str()); + nanosleep(&intval, NULL); + } + } + if (eFrameworkunifiedStatusOK + != McSend(this->m_parentMcQueue, m_loggerStorageInfo.Name.c_str(), + l_cmdId, 0, NULL)) { + FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, " Error. McSend(this->m_parentMcQueue)"); + } + } + pthread_cleanup_pop(1); + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-"); +} + +void CLoggerErrorEventStorage::Cleanup(void) { + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+"); + if (-1 != this->m_receiveQueue) { // LCOV_EXCL_BR_LINE 200: m_receiveQueue cam not be -1 + if (-1 == mq_close(this->m_receiveQueue)) { + FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, " Error. mq_close()"); + } + this->m_receiveQueue = -1; + } + if (-1 != this->m_sendQueue) { // LCOV_EXCL_BR_LINE 200: m_sendQueue cam not be -1 + if (-1 == mq_close(this->m_sendQueue)) { + FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, " Error. mq_close()"); + } + this->m_sendQueue = -1; + if (-1 == mq_unlink(m_loggerStorageInfo.Name.c_str())) { + FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, " Error. mq_unlink()"); + } + } + + if (-1 != m_mutexInit) { // LCOV_EXCL_BR_LINE 200: m_mutexInit cam not be -1 + if (EOK != pthread_mutex_destroy(&this->m_mutex)) { // LCOV_EXCL_BR_LINE 5: c code error case + // LCOV_EXCL_START 5: c code error case + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, " Error. mq_unlink()"); + // LCOV_EXCL_STOP + } + m_mutexInit = -1; + } + + if (NULL != m_parentMcQueue) { // LCOV_EXCL_BR_LINE 200: m_parentMcQueue cam not be null + if (eFrameworkunifiedStatusOK != McClose(m_parentMcQueue)) { + FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, " Error. McClose()"); + } + this->m_parentMcQueue = NULL; + } + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-"); +} + +void* CLoggerErrorEventStorage::ThreadFunctionWrapper(void* param) { + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+"); + CLoggerErrorEventStorage* l_pObj = + reinterpret_cast<CLoggerErrorEventStorage *>(param); + + l_pObj->ThreadFunction(); + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-"); + return NULL; +} + +void CLoggerErrorEventStorage::CleanupWrapper(void* param) { + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+"); + CLoggerErrorEventStorage* l_pObj = + reinterpret_cast<CLoggerErrorEventStorage *>(param); + + l_pObj->Cleanup(); + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-"); +} + +/////////////////////////////////////////////////////////////////////////// +// Function : PackageAndPlaceArtifacts +// brief : This function creates an archive for all collected artifacts +// and places the archive in the required location depending +// on the event type and required naming criteria. +/////////////////////////////////////////////////////////////////////////// +EFrameworkunifiedStatus CLoggerErrorEventStorage::PackageAndPlaceArtifacts( + std::string f_archiveDestination, TArtifactResponseVec &f_responseVector, + uint32_t f_logTime) { + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+"); + EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK; + std::string l_coreFileName = ""; + SI_32 l_ret = 0; + + if (f_archiveDestination.size() == 0) { + FRAMEWORKUNIFIEDLOG( + ZONE_ERR, + __FUNCTION__, + " Error. Unknown package file path and name. Logging artifacts not stored!"); + l_eStatus = eFrameworkunifiedStatusFail; + } else { + CErrorEventArchive l_archiver; + l_eStatus = l_archiver.openArchive(f_archiveDestination); + if (eFrameworkunifiedStatusOK != l_eStatus) { // LCOV_EXCL_BR_LINE 6: it can not be fail + // LCOV_EXCL_START 6: it can not be fail + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + FRAMEWORKUNIFIEDLOG( + ZONE_ERR, + __FUNCTION__, + " Error. Failed to create logging archive: %s. Log archive will not be stored!", + f_archiveDestination.c_str()); + // LCOV_EXCL_STOP + } else { + for (UI_32 i = 0; (i < f_responseVector.size()); i++) { + if (f_responseVector[i].Filepath != std::string("")) { + std::string l_destName = f_responseVector[i].Filepath; + + if ((f_responseVector[i].Filepath.find(".bmp") // LCOV_EXCL_BR_LINE 200: no bmp file be set + == f_responseVector[i].Filepath.find_last_of('.')) + && (f_responseVector[i].Filepath.find(".bmp") + != std::string::npos)) { + // LCOV_EXCL_START 200: no bmp file be set + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + char buffer[20]; + struct tm local_time; + Clock_getLocalTimeY2K38(&f_logTime, &local_time); + if (0 + != strftime(buffer, sizeof(buffer), "%Y%m%d%H%M%S.bmp", + &local_time)) { + l_destName = buffer; + } + // LCOV_EXCL_STOP + } else { + l_destName = f_responseVector[i].Filepath.substr( + f_responseVector[i].Filepath.find_last_of('/') + 1); + } + if (f_responseVector[i].ArtifactId == eArtifactIdPstoreLog) { // LCOV_EXCL_BR_LINE 200: can not be eArtifactIdPstoreLog // NOLINT[whitespace/line_length] + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + l_destName = KERNEL_LOG_PATH_DIR; // LCOV_EXCL_LINE 200: can not be eArtifactIdPstoreLog + } + l_eStatus = l_archiver.addToArchive(f_responseVector[i].Filepath, + l_destName); + if (eFrameworkunifiedStatusOK != l_eStatus) { // LCOV_EXCL_BR_LINE 200: can not be fail + // LCOV_EXCL_START 200: can not be fail + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + FRAMEWORKUNIFIEDLOG( + ZONE_ERR, + __FUNCTION__, + " Error. Failed to add artifact: %s to archive %s. Continuing with next artifact.", + f_responseVector[i].Filepath.c_str(), + f_archiveDestination.c_str()); + // LCOV_EXCL_STOP + } + l_ret++; + if ((l_ret % m_loggerStorageInfo.TimeoutAfter) == 0) { + usleep(m_loggerStorageInfo.Timeout); + } + } + } + + if (eFrameworkunifiedStatusOK != l_archiver.closeArchive()) { // LCOV_EXCL_BR_LINE 200: closeArchive can not be fail + // LCOV_EXCL_START 200: closeArchive can not be fail + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + l_eStatus = eFrameworkunifiedStatusFail; + FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, " Error. l_archiver.closeArchive()"); + // LCOV_EXCL_STOP + } else { + // Cleanup artifacts that are no longer required. + int rc = access(f_archiveDestination.c_str(), F_OK); + if (0 != rc) { // LCOV_EXCL_BR_LINE 5: f_archiveDestination is aways exist + // LCOV_EXCL_START 5: f_archiveDestination is aways exist + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, + " Error. Archive verification failed. Errno: %d, %s.", errno, + strerror(errno)); + l_eStatus = eFrameworkunifiedStatusFail; + // LCOV_EXCL_STOP + } else { + TEXT(__FUNCTION__, + " Error Event: A archive successfully written to: %s.", + f_archiveDestination.c_str()); + l_eStatus = eFrameworkunifiedStatusOK; + } + } + } + } + + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-"); + return (l_eStatus); +} + +/////////////////////////////////////////////////////////////////////////////////////////// +/////////////////////////////////////////////////////////////////////////////////////////// +/// File Copy +/// arg: +/// isDeleteFiles : TRUE - delete original files after copy. +/// FALSE - not delete after copy. +/// returns: +/// -1: error while writing +/// else, number of files written +/////////////////////////////////////////////////////////////////////////////////////////// +/////////////////////////////////////////////////////////////////////////////////////////// +// LCOV_EXCL_START 8: can not be called +SI_32 CLoggerErrorEventStorage::CopyFiles( + std::string f_destination, TArtifactResponseVec &f_responseVector, + BOOL isDeleteFiles) { + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+"); + SI_32 l_ret = 0; + BOOL l_isFaile = FALSE; + for (UI_32 i = 0; i < f_responseVector.size(); i++) { + if (f_responseVector[i].Filepath != "") { + if (CFSDirectory::IsDirectory(f_responseVector[i].Filepath)) { + DIR * l_pDir = opendir(f_responseVector[i].Filepath.c_str()); + if (l_pDir == NULL) { + FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "Could not open directory: %s", + f_responseVector[i].Filepath.c_str()); + } else { + struct dirent l_pDirent; + struct dirent* next; + while (0 == readdir_r(l_pDir, &l_pDirent, &next) && next != NULL) { + if ((0 != strcmp(l_pDirent.d_name, ".")) && /* Ignore special . directory. */ + (0 != strcmp(l_pDirent.d_name, "..")) && /* Ignore special .. directory. */ + (0 != strcmp(l_pDirent.d_name, "lost+found")) && /* Ignore lost+found. */ + ('.' != l_pDirent.d_name[0])) { /* Ignore hidden files */ + std::string l_fileSource = f_responseVector[i].Filepath; + std::string l_fileDestination = f_destination; + l_fileSource.append("/"); + l_fileSource.append(l_pDirent.d_name); + l_fileDestination.append("/"); + l_fileDestination.append(l_pDirent.d_name); + EFrameworkunifiedStatus loggerserviceRet = eFrameworkunifiedStatusOK; + if (isDeleteFiles == TRUE) { + loggerserviceRet = CLoggerUtil::MoveUntyped(l_fileSource, + l_fileDestination); + } else { + loggerserviceRet = CLoggerUtil::CopyUntyped(l_fileSource, + l_fileDestination); + } + + if (eFrameworkunifiedStatusOK == loggerserviceRet) { + l_ret++; + if ((l_ret % m_loggerStorageInfo.TimeoutAfter) == 0) { + usleep(m_loggerStorageInfo.Timeout); + } + } else { + l_isFaile = TRUE; + FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "Could not move: %s", + l_fileSource.c_str()); + } + } + } + (void) closedir(l_pDir); + } + } else { + std::string l_filename = f_responseVector[i].Filepath.substr( + f_responseVector[i].Filepath.find_last_of('/')); + std::string l_destination = std::string(f_destination).append( + l_filename); + if (eFrameworkunifiedStatusOK + == CLoggerUtil::MoveUntyped(f_responseVector[i].Filepath, + l_destination)) { + l_ret++; + if ((l_ret % m_loggerStorageInfo.TimeoutAfter) == 0) { + usleep(m_loggerStorageInfo.Timeout); + } + } else { + FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "Could not move: %s", + f_responseVector[i].Filepath.c_str()); + l_isFaile = TRUE; + } + } + } + } + if (l_isFaile) + l_ret = -1; + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-"); + return (l_ret); +} +// LCOV_EXCL_STOP + +EFrameworkunifiedStatus CLoggerErrorEventStorage::RemoveDeprecatedArtifacts( + TArtifactResponseVec &f_responseVector) { + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+"); + EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK; + BOOL l_success = TRUE; + for (UI_32 i = 0; i < f_responseVector.size(); i++) { + if ((f_responseVector[i].Filepath != "") + && (TRUE == f_responseVector[i].Remove)) { + if (CFSDirectory::IsDirectory(f_responseVector[i].Filepath)) { + if (TRUE + != CFSDirectory::RemoveDirectory(f_responseVector[i].Filepath)) { + FRAMEWORKUNIFIEDLOG(ZONE_WARN, __FUNCTION__, + " Warning. Directory %s failed to be deleted.", + f_responseVector[i].Filepath.c_str()); + l_success &= FALSE; + } else { + FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__, + " Info. Directory %s has been successfully deleted.", + f_responseVector[i].Filepath.c_str()); + } + + } else { + errno = 0; + if (0 != remove(f_responseVector[i].Filepath.c_str())) { // LCOV_EXCL_BR_LINE 5: c code error case + // LCOV_EXCL_START 5: c code error case + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + if (errno == ENOENT) { + FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__, + " Info. %s not available. Skipping file deletion.", + f_responseVector[i].Filepath.c_str()); + } else { + FRAMEWORKUNIFIEDLOG(ZONE_WARN, __FUNCTION__, + " Warning. File %s failed to be deleted.", + f_responseVector[i].Filepath.c_str()); + l_success &= FALSE; + } + errno = 0; + // LCOV_EXCL_STOP + } else { + FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__, + " Info. File %s has been successfully deleted.", + f_responseVector[i].Filepath.c_str()); + } + } + } + } + l_eStatus = (l_success == TRUE) ? eFrameworkunifiedStatusOK : eFrameworkunifiedStatusFail; + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-"); + return l_eStatus; +} diff --git a/systemservice/logger_service/server/src/ss_logger_fs_directory.cpp b/systemservice/logger_service/server/src/ss_logger_fs_directory.cpp new file mode 100755 index 0000000..4cb3996 --- /dev/null +++ b/systemservice/logger_service/server/src/ss_logger_fs_directory.cpp @@ -0,0 +1,236 @@ +/* + * @copyright Copyright (c) 2016-2020 TOYOTA MOTOR CORPORATION. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/////////////////////////////////////////////////////////////////////////////// +/// \ingroup tag_SS_LoggerService +/// \brief This file contains declaration of class CFSDirectory. +/// +/////////////////////////////////////////////////////////////////////////////// +#include "ss_logger_fs_directory.h" +#include <stdio.h> +#include <sys/types.h> +#include <sys/stat.h> +#include <dirent.h> +#include <errno.h> +#include <fcntl.h> +#include <string> +#include "loggerservicedebug_loggerservicelog.h" +#include "ss_logger_types.h" +#include "ss_logger_util.h" + +//////////////////////////////////////////////////////////////////////////////////////////////////// +/// CFSDirectory +/// Constructor of CFSDirectory class +//////////////////////////////////////////////////////////////////////////////////////////////////// +CFSDirectory::CFSDirectory() { // LCOV_EXCL_START 14:static instance + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert +} +// LCOV_EXCL_STOP + +//////////////////////////////////////////////////////////////////////////////////////////////////// +/// CFSDirectory +/// Destructor of CFSDirectory class +//////////////////////////////////////////////////////////////////////////////////////////////////// +CFSDirectory::~CFSDirectory() { // LCOV_EXCL_START 14:static instance + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert +} +// LCOV_EXCL_STOP + +//////////////////////////////////////////////////////////////////////////////////////////////////// +/// CreateDirectory +/// Method to create a directory. +//////////////////////////////////////////////////////////////////////////////////////////////////// +EFrameworkunifiedStatus CFSDirectory::CreateDirectory(std::string &f_cDirPath) { + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+"); + EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK; + + if (!f_cDirPath.empty()) { // LCOV_EXCL_BR_LINE 6: f_cDirPath is aways not empty + PSTR l_cTempDirPath; + PSTR l_cParsedDirPath; + PCSTR l_cCopypath = f_cDirPath.c_str(); + + l_cTempDirPath = const_cast<PSTR>(f_cDirPath.c_str()); + while (l_eStatus == eFrameworkunifiedStatusOK + && (l_cParsedDirPath = std::strchr(l_cTempDirPath, '/')) != 0) { + if (l_cParsedDirPath != l_cTempDirPath) { + /* Neither root nor double slash in path */ + *l_cParsedDirPath = '\0'; + if (0 + != mkdir(l_cCopypath, + S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH)) { + if (EEXIST != errno) { + FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "Error Cannot Create directory %s", + l_cCopypath); + l_eStatus = eFrameworkunifiedStatusFail; + } else { + // file already exist + } + } + *l_cParsedDirPath = '/'; + } + l_cTempDirPath = l_cParsedDirPath + 1; + } + if (eFrameworkunifiedStatusOK == l_eStatus) { + if (0 + != mkdir(l_cCopypath, + S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH)) { + if (EEXIST != errno) { + FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "Error Cannot Create directory %s", + l_cCopypath); + l_eStatus = eFrameworkunifiedStatusFail; + } else { + // file already exist + } + } + } + } else { + // LCOV_EXCL_START 6: f_cDirPath is aways not empty + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "String Empty."); + l_eStatus = eFrameworkunifiedStatusFail; + // LCOV_EXCL_STOP + } + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-"); + return l_eStatus; +} + +//////////////////////////////////////////////////////////////////////////////////////////////////// +/// DoesDirectoryExist +/// Method to check if a directory exists. +//////////////////////////////////////////////////////////////////////////////////////////////////// +BOOL CFSDirectory::DoesDirectoryExist(std::string &f_cDirPath) { + DIR* l_pDirDescriptor = opendir(f_cDirPath.c_str()); + if (NULL != l_pDirDescriptor) { + closedir(l_pDirDescriptor); + return TRUE; + } + return FALSE; +} + +//////////////////////////////////////////////////////////////////////////////////////////////////// +/// IsDirectory +/// Method to check if the entity is a directory. +//////////////////////////////////////////////////////////////////////////////////////////////////// +BOOL CFSDirectory::IsDirectory(std::string &f_cPath) { + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+"); + BOOL l_bReturn = FALSE; + + if (!f_cPath.empty()) { // LCOV_EXCL_BR_LINE 6: f_cPath can not be empty + struct stat st_buf; + if (-1 == stat(f_cPath.c_str(), &st_buf)) { // LCOV_EXCL_BR_LINE 5: c code. + // LCOV_EXCL_START 5: c code. + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, + "Error: stat failed for path/file %s, errno %d", f_cPath.c_str(), + errno); + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-"); + l_bReturn = FALSE; + return l_bReturn; + // LCOV_EXCL_STOP + } + + // Get the status of the file + if (S_ISREG(st_buf.st_mode)) { + l_bReturn = FALSE; // return false if f_cPath is a regular file + } + if (S_ISDIR(st_buf.st_mode)) { + l_bReturn = TRUE; // return true if f_cPath is a directory + } + } else { + // LCOV_EXCL_START 6: f_cPath can not be empty + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "Pathname empty."); + l_bReturn = FALSE; + // LCOV_EXCL_STOP + } + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-"); + return l_bReturn; +} + +//////////////////////////////////////////////////////////////////////////////////////////////////// +/// RemoveDirectory +/// Method to remove a directory. +//////////////////////////////////////////////////////////////////////////////////////////////////// +BOOL CFSDirectory::RemoveDirectory(std::string &f_cPath) { + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+"); + BOOL l_bReturn = FALSE; + + if (RemoveSubDirectory(f_cPath)) { + // delete the parent directory + if (0 == rmdir(f_cPath.c_str())) { // LCOV_EXCL_BR_LINE 5: c code error case + l_bReturn = TRUE; + } + } + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-"); + return l_bReturn; +} + +//////////////////////////////////////////////////////////////////////////////////////////////////// +/// RemoveSubDirectory +/// Method to remove a sub directory. +//////////////////////////////////////////////////////////////////////////////////////////////////// +BOOL CFSDirectory::RemoveSubDirectory(std::string &f_cPath) { + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+"); + BOOL l_bReturn = TRUE; + + if (!f_cPath.empty()) { // LCOV_EXCL_BR_LINE 6: f_cPath can not be empty + std::string l_cFilePath = ""; + + struct dirent l_Dirent; + struct dirent* next; + DIR *l_pDir = NULL; + + l_pDir = opendir(f_cPath.c_str()); + if (NULL != l_pDir) { // LCOV_EXCL_BR_LINE 5: c code. + if ('/' != f_cPath[f_cPath.length() - 1]) { + f_cPath.append("/"); + } + + while (0 == readdir_r(l_pDir, &l_Dirent, &next) && next != NULL) { + if (0 != std::strcmp(l_Dirent.d_name, ".") + && 0 != std::strcmp(l_Dirent.d_name, "..") + && 0 != std::strcmp(l_Dirent.d_name, "lost+found")) { + l_cFilePath.assign(f_cPath); + l_cFilePath.append(l_Dirent.d_name); // concatenate the strings to get the complete f_cPath + + if (TRUE == IsDirectory(l_cFilePath)) { + l_bReturn = RemoveDirectory(l_cFilePath); + } else { + // it's a file, we can use unlink + if (unlink(l_cFilePath.c_str()) == -1) { + l_bReturn = FALSE; + } + } + } + } + closedir(l_pDir); // close the directory + CLoggerUtil::SyncDir(f_cPath); + } else { + // LCOV_EXCL_START 5: c code. + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "l_pDir is NULL"); + // LCOV_EXCL_STOP + } + } else { + // LCOV_EXCL_START 6: f_cPath can not be empty + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "Pathname empty."); + l_bReturn = FALSE; + // LCOV_EXCL_STOP + } + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-"); + return l_bReturn; +} diff --git a/systemservice/logger_service/server/src/ss_logger_popups.cpp b/systemservice/logger_service/server/src/ss_logger_popups.cpp new file mode 100755 index 0000000..92a5737 --- /dev/null +++ b/systemservice/logger_service/server/src/ss_logger_popups.cpp @@ -0,0 +1,176 @@ +/* + * @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_SS_LoggerService +/// \brief TODO +/// +/////////////////////////////////////////////////////////////////////////////// +/////////////////////////////////////////////////////////////////////////////// +// INCLUDES +/////////////////////////////////////////////////////////////////////////////// +#include "ss_logger_popups.h" +#include <string> +#include <vector> +CLoggerPopups::CLoggerPopups() + : m_pLoggerCfg(NULL), + m_startShown(FALSE) { +} + +CLoggerPopups::~CLoggerPopups() { // LCOV_EXCL_START 14:globle instance + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert +} +// LCOV_EXCL_STOP + +EFrameworkunifiedStatus CLoggerPopups::Initialize(CLoggerCfg* f_pLoggerCfg) { + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+"); + EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK; + this->m_pLoggerCfg = f_pLoggerCfg; + l_eStatus = (m_pLoggerCfg == NULL) ? eFrameworkunifiedStatusNullPointer : eFrameworkunifiedStatusOK; + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-"); + return (l_eStatus); +} + +BOOL CLoggerPopups::IsPopupNeeded(TLoggerErrorEvent f_event) { + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+"); + BOOL l_ret = ((f_event.EventBitMask & EVENT_BIT_POPUP) != 0) ? TRUE : FALSE; + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-"); + return (l_ret); +} + +BOOL CLoggerPopups::CanShowStartPopup( + std::vector<TLoggingArtifact>* f_remainingArtifact) { + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+"); + BOOL l_ret = FALSE; + if (f_remainingArtifact != NULL) { + l_ret = TRUE; + std::vector<TLoggingArtifact>::iterator l_iter; + for (l_iter = f_remainingArtifact->begin(); + f_remainingArtifact->end() != l_iter; l_iter++) { + if (l_iter->ArtifactId == eArtifactIdScreenShot) { + l_ret = FALSE; + break; + } + } + } + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-"); + return (l_ret); +} + +std::string CLoggerPopups::getDeviceName(std::string f_dest) { + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+"); + std::string l_ret = ""; + if (f_dest.length() == 0) { + } else if (f_dest.find(this->m_pLoggerCfg->m_usb0MountPath) != std::string::npos) { + l_ret = "USB 1"; + } else if (f_dest.find(this->m_pLoggerCfg->m_usb1MountPath) != std::string::npos) { + l_ret = "USB 2"; + } else if (f_dest.find(this->m_pLoggerCfg->m_sdMountPath) != std::string::npos) { + l_ret = "SD card"; + } else if (f_dest.find(this->m_pLoggerCfg->m_emmcOutputPath) + != std::string::npos) { + l_ret = "Emmc"; + } else { + FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, " Error. No matching Path found for %s", + f_dest.c_str()); + } + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-: %s", l_ret.c_str()); + return (l_ret); +} + +EFrameworkunifiedStatus CLoggerPopups::ShowStartPopup( + HANDLE f_hApp, TLoggerErrorEvent f_event, + std::vector<TLoggingArtifact>* f_remainingArtifact, std::string f_dest) { + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+"); + EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK; + if (this->m_startShown != FALSE) { + FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__, "Pop up already shown"); + } else if (TRUE != IsPopupNeeded(f_event)) { + this->m_startShown = TRUE; + FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__, "Start pop up not needed for event %d.", + f_event.EventType); + } else if (TRUE != CanShowStartPopup(f_remainingArtifact)) { + FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__, "Screenshot still in artifact vector."); + } else { + this->m_startShown = TRUE; + STLoggerFolderInfo l_folderInfo; + l_folderInfo.FoldernameAndLogname[0] = '\0'; + std::string l_dest = this->getDeviceName(f_dest); + std::size_t l_len = l_dest.copy(l_folderInfo.StorageTarget, + sizeof(l_folderInfo.StorageTarget) - 1u, 0); + l_folderInfo.StorageTarget[l_len] = '\0'; + FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__, " Info. Show start pop up. Destination: %s", + l_folderInfo.StorageTarget); + l_eStatus = FrameworkunifiedPublishEvent(f_hApp, SS_LOGGER_LOGSTARTED_EVT, + NULL, + &l_folderInfo, sizeof(l_folderInfo)); + + LOG_STATUS_IF_ERRORED(l_eStatus, + "FrameworkunifiedPublishEvent(SS_LOGGER_LOGSTARTED_EVT)"); + } + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-"); + return (l_eStatus); +} + +EFrameworkunifiedStatus CLoggerPopups::ShowEndPopup(HANDLE f_hApp, TLoggerErrorEvent f_event, + std::string f_dest) { + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+"); + EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK; + this->m_startShown = FALSE; + if (TRUE != IsPopupNeeded(f_event)) { + FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__, + " Info. No pop up needed at end of Logging."); + } else { + STLoggerFolderInfo l_folderInfo; + std::size_t l_len = f_dest.copy( + l_folderInfo.FoldernameAndLogname, + sizeof(l_folderInfo.FoldernameAndLogname) - 1u, + f_dest.find_last_of('/') + 1); + l_folderInfo.FoldernameAndLogname[l_len] = '\0'; + + std::string l_dest = this->getDeviceName(f_dest); + l_len = l_dest.copy(l_folderInfo.StorageTarget, + sizeof(l_folderInfo.StorageTarget) - 1, 0); + l_folderInfo.StorageTarget[l_len] = '\0'; + FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__, + " Info. Show end pop up. Filepath: %s, Device: %s", + l_folderInfo.FoldernameAndLogname, l_folderInfo.StorageTarget); + l_eStatus = FrameworkunifiedPublishEvent(f_hApp, SS_LOGGER_LOGINFO_EVT, + NULL, + &l_folderInfo, sizeof(l_folderInfo)); + + LOG_STATUS_IF_ERRORED(l_eStatus, "FrameworkunifiedPublishEvent(SS_LOGGER_LOGINFO_EVT)"); + } + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-"); + return (l_eStatus); +} + +EFrameworkunifiedStatus CLoggerPopups::ShowErrorPopup(HANDLE f_hApp, + TLoggerErrorEvent f_event, + UI_16 f_errCode) { + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+"); + EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK; + UI_16 l_errorcode = (UI_16) f_errCode; + this->m_startShown = FALSE; + if (IsPopupNeeded(f_event) == TRUE) { + l_eStatus = FrameworkunifiedPublishEvent(f_hApp, SS_LOGGER_ERRORINFO_EVT, + NULL, + &l_errorcode, sizeof(l_errorcode)); + LOG_STATUS_IF_ERRORED(l_eStatus, "FrameworkunifiedPublishEvent(SS_LOGGER_ERRORINFO_EVT)"); + } + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-"); + return (l_eStatus); +} diff --git a/systemservice/logger_service/server/src/ss_logger_reader_writer_control.cpp b/systemservice/logger_service/server/src/ss_logger_reader_writer_control.cpp new file mode 100755 index 0000000..692cab8 --- /dev/null +++ b/systemservice/logger_service/server/src/ss_logger_reader_writer_control.cpp @@ -0,0 +1,151 @@ +/* + * @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. + */ + +/* + * ss_logger_reader_writer_control.cpp + */ +#include "ss_logger_reader_writer_control.h" +#include <boost/bind.hpp> +#include <native_service/ns_sharedmem.h> +#include <native_service/ns_transmit_log.h> +#include <native_service/ns_logger_if.h> +#include <string> +#include "ss_logger_common.h" + +#define LOGGERSERVICELOG_REMOTE_IP_PORT 3500 +#define TRANSMIT_REMOTE_IP_PORT 3500 + +CReaderWriterControl::CReaderWriterControl() + : m_pLoggerCfg(NULL) { // LCOV_EXCL_BR_LINE 11:Unexpected branch +} + +CReaderWriterControl::~CReaderWriterControl() { // LCOV_EXCL_START 14:globle instance + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert +} +// LCOV_EXCL_STOP + +EFrameworkunifiedStatus CReaderWriterControl::Initialize(CLoggerCfg * f_pLoggerCfg) { + EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK; + if (NULL != f_pLoggerCfg) { // LCOV_EXCL_BR_LINE 200:As it is not always NULL + this->m_pLoggerCfg = f_pLoggerCfg; + + l_eStatus = m_debugReaderWriter.Initialize( // LCOV_EXCL_BR_LINE 11:Unexpected branch + f_pLoggerCfg, ReaderWriter::eReaderWriterTypeMem, std::string(FRAMEWORKUNIFIEDLOG_SHAREDMEM_NAME), + FRAMEWORKUNIFIEDLOG_SHAREDMEM_SIZE, ReaderWriter::eReaderWriterTypeUdp, + std::string("169.254.80.9"), LOGGERSERVICELOG_REMOTE_IP_PORT, "", 0); // LCOV_EXCL_BR_LINE 11:except,C++ STL + if (eFrameworkunifiedStatusOK == l_eStatus) { // LCOV_EXCL_BR_LINE 200:To ensure success + l_eStatus = m_debugReaderWriter.Start(std::string("pdg.LogQueR")); + } + + LOG_STATUS_IF_ERRORED( // LCOV_EXCL_BR_LINE 15:macro + l_eStatus, "m_debugReaderWriter.Start(std::string(pdg.TransQueR)"); + + + l_eStatus = m_transmitReaderWriter.Initialize( // LCOV_EXCL_BR_LINE 11:Unexpected branch + f_pLoggerCfg, ReaderWriter::eReaderWriterTypeMem, + std::string(TRANSMIT_LOG_SHAREDMEM_NAME), TRANSMIT_LOG_SHAREDMEM_SIZE, + ReaderWriter::eReaderWriterTypeUdp, std::string("169.254.80.9"), + TRANSMIT_REMOTE_IP_PORT, "", 0); // LCOV_EXCL_BR_LINE 11:except,C++ STL + if (eFrameworkunifiedStatusOK == l_eStatus) { // LCOV_EXCL_BR_LINE 6:it can not be fail + l_eStatus = m_transmitReaderWriter.Start(std::string("pdg.TransQueR")); // LCOV_EXCL_BR_LINE 11:except,C++ STL + } + + LOG_STATUS_IF_ERRORED( // LCOV_EXCL_BR_LINE 15:macro + l_eStatus, "m_transmitReaderWriter.Start(std::string(pdg.TransQueR)"); + + + l_eStatus = m_performanceReaderWriter.Initialize( // LCOV_EXCL_BR_LINE 11:Unexpected branch + f_pLoggerCfg, ReaderWriter::eReaderWriterTypeQueue, std::string("/NSplog"), 0, + ReaderWriter::eReaderWriterTypeFile, std::string(PERFORMANCE_LOG_PATH_FN), + f_pLoggerCfg->m_performanceLogMaxFileSize, std::string("169.254.80.9"), + 0); // LCOV_EXCL_BR_LINE 11:except,C++ STL + + if (eFrameworkunifiedStatusOK == l_eStatus) { // LCOV_EXCL_BR_LINE 6:it can not be fail + l_eStatus = m_performanceReaderWriter.Start( + std::string("pdg.PerformQueR")); // LCOV_EXCL_BR_LINE 11:except,C++ STL + } + + LOG_STATUS_IF_ERRORED( // LCOV_EXCL_BR_LINE 15:macro + l_eStatus, + "m_performanceReaderWriter.Start(std::string(pdg.PerformQueR)"); + + + this->m_pLoggerCfg->AddLoggingParamCB( + boost::bind(&CReaderWriterControl::UpdateLoggingParams, this, _1)); + } + return (l_eStatus); +} + +EFrameworkunifiedStatus CReaderWriterControl::UpdateLoggingParams(void* param) { + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+"); + EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK; + l_eStatus = this->m_debugReaderWriter.UpdateLoggingParameters(); + LOG_STATUS_IF_ERRORED(l_eStatus, // LCOV_EXCL_BR_LINE 15:macro + "this->m_debugReaderWriter.UpdateLoggingParameters()"); + + l_eStatus = this->m_transmitReaderWriter.UpdateLoggingParameters(); + LOG_STATUS_IF_ERRORED( // LCOV_EXCL_BR_LINE 15:macro + l_eStatus, "this->m_transmitReaderWriter.UpdateLoggingParameters()"); + + l_eStatus = this->m_performanceReaderWriter.UpdateLoggingParameters(); + LOG_STATUS_IF_ERRORED( // LCOV_EXCL_BR_LINE 15:macro + l_eStatus, + "this->m_performanceReaderWriter." + "UpdateLoggingParameters()"); + + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "- : %d", l_eStatus); + return (l_eStatus); +} + +EFrameworkunifiedStatus CReaderWriterControl::FlushCache(EReaderWriterType f_type) { + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+"); + EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusInvldParam; + switch (f_type) { // LCOV_EXCL_BR_LINE 8: eReaderWriterLogDebug and eReaderWriterLogInvalid can not be called + // LCOV_EXCL_START 8: dead code + case eReaderWriterLogDebug: + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + l_eStatus = this->m_debugReaderWriter.FlushCache( + std::string(DEBUG_LOG_PATH_FN)); + LOG_STATUS_IF_ERRORED( + l_eStatus, "this->m_debugReaderWriter.FlushCache(DEBUG_LOG_PATH_FN)"); + break; + // LCOV_EXCL_STOP + case eReaderWriterLogTransmit: + l_eStatus = this->m_transmitReaderWriter.FlushCache( + std::string(TRANSMIT_LOG_PATH_FN)); + LOG_STATUS_IF_ERRORED( + l_eStatus, + "this->m_debugReaderWriter.FlushCache(TRANSMIT_LOG_PATH_FN)"); + break; + + case eReaderWriterLogPerformance: + l_eStatus = this->m_performanceReaderWriter.FlushCache( + std::string(PERFORMANCE_LOG_PATH_FN)); + LOG_STATUS_IF_ERRORED( + l_eStatus, + "this->m_debugReaderWriter.FlushCache(PERFORMANCE_LOG_PATH_FN)"); + break; + // LCOV_EXCL_START 8: dead code + case eReaderWriterLogInvalid: + default: + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + break; + // LCOV_EXCL_STOP + } + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "- : %d", l_eStatus); + return (l_eStatus); +} + diff --git a/systemservice/logger_service/server/src/ss_logger_server_callbacks.cpp b/systemservice/logger_service/server/src/ss_logger_server_callbacks.cpp new file mode 100755 index 0000000..82a677b --- /dev/null +++ b/systemservice/logger_service/server/src/ss_logger_server_callbacks.cpp @@ -0,0 +1,900 @@ +/* + * @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_SS_LoggerService +/// \brief This file contains the callback for Notifications and Protocol +/// commands. +/// +/////////////////////////////////////////////////////////////////////////////// +#include "ss_logger_service_callbacks.h" +#include <string.h> +#include <boost/bind.hpp> +#include <errno.h> +#include <native_service/frameworkunified_framework_if.h> +#include <native_service/frameworkunified_multithreading.h> +#include <system_service/ss_logger_service.h> +#include <ss_logger_common.h> +#include <system_service/ss_logger_service_notifications.h> +#include <system_service/ss_logger_service_protocol.h> +#include <native_service/ns_config_parser_if.h> +#include <native_service/nslogutil_cmd_if.h> +#include <system_service/ss_sm_client_if.h> +#include <queue> +#include <new> +#include <string> +#include "ss_logger_error_event.h" +#include "loggerservicedebug_loggerservicelog.h" +#include "loggerservicedebug_thread_if.h" +extern CErrorEvent g_errorEventHandler; +extern HANDLE g_thrdEvntLogWriter; + +// Global variables +STCanCurrentDateTime g_stDateAndTime = { 0 }; +UEvtLoggerCommonInfo g_uEvtLoggerCommonInfo; +UI_16 g_u16DiagId = 0; + +CLoggerServiceCallbacks::CLoggerServiceCallbacks() + : m_pLoggerCfg(NULL), + m_pErrorEvent(NULL) { + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+"); + FrameworkunifiedProtocolCallbackHandler l_protocolHandlers[kNUMBER_PROTOCOL_HANDLERS] = + { { SS_LOGGER_MILEAGE_DATA, boost::bind( + &CLoggerServiceCallbacks::LoggerServer_SetMileageData, this, _1) }, + { SS_LOGGER_SET_PARAMS, boost::bind( + &CLoggerServiceCallbacks::LoggerServer_SetLoggerParams, this, _1) }, + { SS_LOGGER_UDP_LOGGING, boost::bind( + &CLoggerServiceCallbacks::LoggerServer_UDPLogging, this, _1) }, + { SS_LOGGERCOPYEVENTUSB, boost::bind( + &CLoggerServiceCallbacks::LoggerServer_OnCopyEvntLog, this,_1) }, + { SS_LOGGERCLEAREVENT, boost::bind( + &CLoggerServiceCallbacks::LoggerServer_OnClearEvntLog, this, _1) }, + { SS_LOGGER_READ_STATL_COUNTER, boost::bind( + &CLoggerServiceCallbacks::LoggerServer_OnReadStatCounter, this, _1) }, + { SS_LOGGER_EVENT_COMMONINFO, boost::bind( + &CLoggerServiceCallbacks::LoggerServer_UpdateCommonInfo, this, _1) }, + { SS_LOGGER__CWORD56__EVENT_INFO, boost::bind( + &CLoggerServiceCallbacks::LoggerServer_Handle_CWORD56_Events, this, _1) }, + { SS_LOGGER_RESET_STATL_COUNTER, boost::bind( + &CLoggerServiceCallbacks::LoggerServer_OnResetStatCounter, this, _1) }, + { SS_LOGGER_SET_VIN, boost::bind( + &CLoggerServiceCallbacks::LoggerServer_OnSetVIN, this, _1) }, + { SS_LOGGERCOPYEMERGENCYLOGS, boost::bind( + &CLoggerServiceCallbacks::LoggerServer_OnCopyEmergencyLog, this, _1) }, + { eSSLoggerCANProtocolIDCANTrigger, boost::bind( + &CLoggerServiceCallbacks::LoggerServer_OnCANTrigger, this, _1) }, + { eSSLoggerCANProtocolIDDTCTrigger, boost::bind( + &CLoggerServiceCallbacks::LoggerServer_OnDTCTrigger, this, _1) }, + { SS_LOGGER_SHUTDOWN_COMPLETE, boost::bind( + &CLoggerServiceCallbacks::LoggerServer_On_SHTDWN_Complete, this, _1) }, + { SS_LOGGER_ENG_READ_NUMOFEVENTS, boost::bind( + &CLoggerServiceCallbacks::LoggerServer_OnReadNumberOfEvents, this, _1) }, + { SS_LOGGER_SET_DIAGID, boost::bind( + &CLoggerServiceCallbacks::LoggerServer_OnSetDiagID, this, _1) }, + { SS_LOGGER_UPLOAD_EVENTLOG, boost::bind( + &CLoggerServiceCallbacks::LoggerServer_UploadEventLog, this, _1) } }; // LCOV_EXCL_BR_LINE 11:Unexpected branch + + for (UI_8 i = 0u; i < kNUMBER_PROTOCOL_HANDLERS; i++) { + m_protocolHandlers[i].iCmd = l_protocolHandlers[i].iCmd; + m_protocolHandlers[i].callBack = l_protocolHandlers[i].callBack; // LCOV_EXCL_BR_LINE 11:Unexpected branch + } + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-"); +} + +CLoggerServiceCallbacks::~CLoggerServiceCallbacks() { // LCOV_EXCL_START 14:globle instance + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+"); + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-"); +} +// LCOV_EXCL_STOP + +EFrameworkunifiedStatus CLoggerServiceCallbacks::Initialize(HANDLE f_hApp, + CLoggerCfg *f_pLoggerCfg, + CErrorEvent* f_pErrorEvent) { + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+"); + EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK; + m_pLoggerCfg = f_pLoggerCfg; + m_pErrorEvent = f_pErrorEvent; + + if ((NULL == m_pLoggerCfg) || (NULL == m_pErrorEvent)) { // LCOV_EXCL_BR_LINE 200:As it is always TRUE + // LCOV_EXCL_START 200:As it is always TRUE + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, + "NULL pointer passed to Initialize function!!!!!"); + l_eStatus = eFrameworkunifiedStatusNullPointer; + // LCOV_EXCL_STOP + } else { + // Attach callback : Open Session Request + if (eFrameworkunifiedStatusOK != (l_eStatus = FrameworkunifiedAttachCallbackToDispatcher(f_hApp, FRAMEWORKUNIFIED_ANY_SOURCE, PROTOCOL_OPEN_SESSION_REQ, boost::bind(&CLoggerServiceCallbacks::LoggerServerOnOpenSession, this, _1)))) { // LCOV_EXCL_BR_LINE 4:NSFW // NOLINT[whitespace/line_length] + // LCOV_EXCL_START 4:NSFW + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + FRAMEWORKUNIFIEDLOG( + ZONE_ERR, + __FUNCTION__, + "FrameworkunifiedAttachCallbackToDispatcher PROTOCOL_OPEN_SESSION_REQ (FRAMEWORKUNIFIED_ANY_SOURCE) Failed Status:0x%x ", + l_eStatus); + // LCOV_EXCL_STOP + } else if ( eFrameworkunifiedStatusOK != (l_eStatus = FrameworkunifiedRegisterServiceAvailabilityNotification(f_hApp, NTFY_SS_LoggerService_Availability))) { // LCOV_EXCL_BR_LINE 4:NSFW // NOLINT[whitespace/line_length] + // LCOV_EXCL_START 4:NSFW + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, + "Failed to set service availability notification:0x%x ", l_eStatus); + // LCOV_EXCL_STOP + } else { + } + } + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-"); + return (l_eStatus); +} + +////////////////////////////////////////// +// Function : DevDetectionServerOnOpenSession +// Callback for PROTOCOL_OPEN_SESSION_REQ +////////////////////////////////////////// +EFrameworkunifiedStatus CLoggerServiceCallbacks::LoggerServerOnOpenSession(HANDLE hApp) { + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+"); + EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK; + HANDLE l_hClientService = NULL; + HANDLE l_hSession = NULL; + + // Get the requester name + PCSTR pRequester = FrameworkunifiedGetMsgSrc(hApp); + OpenSessionAck tOpenAck; + + if (pRequester) { // LCOV_EXCL_BR_LINE 4:NSFW + l_hClientService = FrameworkunifiedMcOpenSender(hApp, pRequester); + + if (l_hClientService) { // LCOV_EXCL_BR_LINE 4:NSFW + // Create a session + l_hSession = FrameworkunifiedCreateSession(hApp, pRequester); + UI_32 l_nSessionId = 0; + if (eFrameworkunifiedStatusOK != (l_eStatus = FrameworkunifiedAttachCallbacksToDispatcher( hApp, pRequester, m_protocolHandlers, kNUMBER_PROTOCOL_HANDLERS, l_hSession))) { // LCOV_EXCL_BR_LINE 4:NSFW // NOLINT[whitespace/line_length] + // LCOV_EXCL_START 4:NSFW + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + FRAMEWORKUNIFIEDLOG( + ZONE_ERR, + __PRETTY_FUNCTION__, + "FrameworkunifiedAttachCallbacksToDispatcher ss_logger_server_protocol_handlers Failed Status:0x%x ", + l_eStatus); + // LCOV_EXCL_STOP + } + + l_eStatus = this->m_pErrorEvent->OnOpenSession(hApp, pRequester, + l_hSession); + if (eFrameworkunifiedStatusOK != l_eStatus) { // LCOV_EXCL_BR_LINE 200:To ensure success + // LCOV_EXCL_START 200:To ensure success + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, + " Error. m_pErrorEvent->OnOpenSession(%s, %p) returned: %d.", + pRequester, l_hSession, l_eStatus); + // LCOV_EXCL_STOP + } + + // Attach callback : close Session Request + if (eFrameworkunifiedStatusOK != (l_eStatus = FrameworkunifiedAttachCallbackToDispatcher(hApp, pRequester, PROTOCOL_CLOSE_SESSION_REQ, boost::bind(&CLoggerServiceCallbacks::LoggerServerOnCloseSession, this, _1)))) { // LCOV_EXCL_BR_LINE 4:NSFW // NOLINT[whitespace/line_length] + // LCOV_EXCL_START 4:NSFW + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + FRAMEWORKUNIFIEDLOG( + ZONE_ERR, + __FUNCTION__, + "FrameworkunifiedAttachCallbackToDispatcher " "PROTOCOL_CLOSE_SESSION_REQ (FRAMEWORKUNIFIED_ANY_SOURCE) Failed Status:0x%x ", + l_eStatus); + // LCOV_EXCL_STOP + } + + l_nSessionId = FrameworkunifiedGetSessionId(l_hSession); + + FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__, "Session id is %d", l_nSessionId); // LCOV_EXCL_BR_LINE 15:macro + // sending the session open + tOpenAck.eStatus = eFrameworkunifiedStatusOK; + tOpenAck.sessionId = l_nSessionId; + tOpenAck.sessionType = 1; + + // Copy session name to data structure + strncpy(tOpenAck.cSessionName, FrameworkunifiedGetAppName(hApp), + MAX_QUEUE_NAME_SIZE - 1); + tOpenAck.cSessionName[MAX_QUEUE_NAME_SIZE - 1] = '\0'; + + // send OpenSession ACK + if (eFrameworkunifiedStatusOK != (l_eStatus = FrameworkunifiedSendMsg(l_hClientService, PROTOCOL_OPEN_SESSION_ACK, sizeof(OpenSessionAck), (PVOID) &tOpenAck))) { // LCOV_EXCL_BR_LINE 4:NSFW // NOLINT[whitespace/line_length] + // LCOV_EXCL_START 4:NSFW + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + FRAMEWORKUNIFIEDLOG(ZONE_ERR, __PRETTY_FUNCTION__, + "FrameworkunifiedSendMsg PROTOCOL_OPEN_SESSION_ACK Failed Status:0x%x ", + l_eStatus); + // LCOV_EXCL_STOP + } else { + l_eStatus = FrameworkunifiedSetSessionHandle(hApp, FrameworkunifiedGetMsgSrc(hApp), l_hSession); + LOG_STATUS_IF_ERRORED(l_eStatus, "FrameworkunifiedSetSessionHandle()"); // LCOV_EXCL_BR_LINE 15:macro + } + } + l_eStatus = FrameworkunifiedMcClose(l_hClientService); + LOG_STATUS_IF_ERRORED(l_eStatus, "FrameworkunifiedMcClose()"); // LCOV_EXCL_BR_LINE 15:macro + } + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-"); + + return l_eStatus; +} + +////////////////////////////////////////// +// Function : DevDetectionServerOnCloseSession +// Callback for PROTOCOL_CLOSE_SESSION_REQ +////////////////////////////////////////// +EFrameworkunifiedStatus CLoggerServiceCallbacks::LoggerServerOnCloseSession(HANDLE hApp) { + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+"); + EFrameworkunifiedStatus eStatus = eFrameworkunifiedStatusOK; + HANDLE hSession = NULL; + HANDLE l_hClientService = NULL; + // Get the requester name + PCSTR pRequester = FrameworkunifiedGetMsgSrc(hApp); + CloseSessionAck tCloseAck; + CloseSessionReq tClose; + + if (pRequester) { // LCOV_EXCL_BR_LINE 4:NSFW + l_hClientService = FrameworkunifiedMcOpenSender(hApp, pRequester); + if (l_hClientService) { // LCOV_EXCL_BR_LINE 4:NSFW + // Read the data from the message + if (eFrameworkunifiedStatusOK != (eStatus = FrameworkunifiedGetMsgDataOfSize(hApp, &tClose, sizeof(tClose), eSMRRelease))) { // LCOV_EXCL_BR_LINE 4:NSFW // NOLINT[whitespace/line_length] + // LCOV_EXCL_START 4:NSFW + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "Error: FrameworkunifiedGetMsgDataOfSize Failed"); + + if (eFrameworkunifiedStatusOK != (eStatus = FrameworkunifiedMcClose(l_hClientService))) { + FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "Error: FrameworkunifiedMcClose failed"); + } + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-"); + return eStatus; + // LCOV_EXCL_STOP + } + + hSession = FrameworkunifiedGetSessionHandle(hApp, pRequester, tClose.sessionId); + + // Create a list of commands to be detached from the dispatcher + UI_32 cmd_array[kNUMBER_PROTOCOL_HANDLERS] = { 0 }; + for (UI_32 i = 0; i < kNUMBER_PROTOCOL_HANDLERS; i++) { + cmd_array[i] = m_protocolHandlers[i].iCmd; + } + + if (NULL != hSession) { // LCOV_EXCL_BR_LINE 4:NSFW + // Detach callbacks associated with client + if (eFrameworkunifiedStatusOK != (eStatus = FrameworkunifiedDetachCallbacksFromDispatcher(hApp, pRequester, cmd_array, kNUMBER_PROTOCOL_HANDLERS, hSession))) { // LCOV_EXCL_BR_LINE 4:NSFW // NOLINT[whitespace/line_length] + // LCOV_EXCL_START 4:NSFW + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + FRAMEWORKUNIFIEDLOG( + ZONE_ERR, + __PRETTY_FUNCTION__, + "FrameworkunifiedAttachCallbacksToDispatcher ss_logger_server_protocol_handlers Failed Status:0x%x ", + eStatus); + // LCOV_EXCL_STOP + } + + eStatus = m_pErrorEvent->OnCloseSession(hApp, pRequester, hSession); + if (eFrameworkunifiedStatusOK != eStatus) { // LCOV_EXCL_BR_LINE 200:To ensure success + // LCOV_EXCL_START 200:To ensure success + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, + " Error. m_pErrorEvent->OnCloseSession(%s, %p) returned: %d.", + pRequester, hSession, eStatus); + // LCOV_EXCL_STOP + } + + // API to destroy the session handle and remove it from the Application Framework. + // LCOV_EXCL_BR_START 4:NSFW + if (eFrameworkunifiedStatusOK != (eStatus = FrameworkunifiedDestroySession(hApp, // Application Handle + hSession))) { // Session Handle + // LCOV_EXCL_BR_STOP + // LCOV_EXCL_START 4:NSFW + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "Session destroy failed"); + // LCOV_EXCL_STOP + } + } + // sending the session close ack + tCloseAck.eStatus = eFrameworkunifiedStatusOK; + tCloseAck.sessionId = tClose.sessionId; + + // send CloseSession ACK + if (eFrameworkunifiedStatusOK != (eStatus = FrameworkunifiedSendMsg(l_hClientService, PROTOCOL_CLOSE_SESSION_ACK, sizeof(CloseSessionAck), (PVOID) &tCloseAck))) { // LCOV_EXCL_BR_LINE 4:NSFW // NOLINT[whitespace/line_length] + // LCOV_EXCL_START 4:NSFW + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + FRAMEWORKUNIFIEDLOG(ZONE_ERR, __PRETTY_FUNCTION__, + "FrameworkunifiedSendMsg PROTOCOL_CLOSE_SESSION_ACK Failed Status:0x%x ", + eStatus); + // LCOV_EXCL_STOP + } + if (eFrameworkunifiedStatusOK != (eStatus = FrameworkunifiedMcClose(l_hClientService))) { // LCOV_EXCL_BR_LINE 4:NSFW + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "Error: FrameworkunifiedMcClose failed"); // LCOV_EXCL_LINE 15:macro + } + } + } + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-"); + return eStatus; +} + +////////////////////////////////////////// +// Function : LoggerServer_SetMileageData +// Callback for SS_LOGGER_MILEAGE_DATA +////////////////////////////////////////// +EFrameworkunifiedStatus CLoggerServiceCallbacks::LoggerServer_SetMileageData(HANDLE hApp) { + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+"); + STLOGGER_CANDIAGSTAT MileageInfo_t; + EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK; + memset(&MileageInfo_t, 0x00, sizeof(STLOGGER_CANDIAGSTAT)); + if (eFrameworkunifiedStatusOK != (l_eStatus = FrameworkunifiedGetMsgDataOfSize(hApp, &MileageInfo_t, sizeof(MileageInfo_t), eSMRRelease))) { // LCOV_EXCL_BR_LINE 4:NSFW // NOLINT[whitespace/line_length] + // LCOV_EXCL_START 4:NSFW + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, " FrameworkunifiedGetMsgDataOfSize Failed"); + l_eStatus = eFrameworkunifiedStatusFail; + // LCOV_EXCL_STOP + } else { + UI_32 l_mileage = (MileageInfo_t.Odo_MSB_H << 24 + | MileageInfo_t.Odo_MSB_L << 16 | MileageInfo_t.Odo_LSB_H << 8 + | MileageInfo_t.Odo_LSB_L); + // if value set to SNA + if (0xFFFFFFFF != l_mileage) { + this->m_pErrorEvent->SetMileage(l_mileage); + // Immediate Persist Event Log + if (eFrameworkunifiedStatusOK != (l_eStatus = FrameworkunifiedSendChild(hApp, g_thrdEvntLogWriter, eThrdCmdMileageData, sizeof(UI_32), &l_mileage))) { // LCOV_EXCL_BR_LINE 4:NSFW // NOLINT[whitespace/line_length] + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "FrameworkunifiedSendChild msg failed:%d", l_eStatus); // LCOV_EXCL_LINE 15:macro + } + } + } + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-"); + return l_eStatus; +} + +////////////////////////////////////////// +// Function : LoggerServer_SetLoggerParams +// Callback for SS_LOGGER_SET_PARAMS +////////////////////////////////////////// +EFrameworkunifiedStatus CLoggerServiceCallbacks::LoggerServer_SetLoggerParams(HANDLE hApp) { + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+"); + EFrameworkunifiedStatus eStatus = eFrameworkunifiedStatusOK; + STLoggerSetParams l_stLoggerSetParams = { eInvalid_LoggerState, eDevUSB1 }; + + if (eFrameworkunifiedStatusOK != (eStatus = FrameworkunifiedGetMsgDataOfSize(hApp, &l_stLoggerSetParams, sizeof(l_stLoggerSetParams), eSMRRelease))) { // LCOV_EXCL_BR_LINE 4:NSFW // NOLINT[whitespace/line_length] + // LCOV_EXCL_START 4:NSFW + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "Error: FrameworkunifiedGetMsgDataOfSize Failed"); + eStatus = eFrameworkunifiedStatusFail; + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-"); + return eStatus; + // LCOV_EXCL_STOP + } else { + eStatus = m_pLoggerCfg->SetLoggingParams(hApp, l_stLoggerSetParams); + } + + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-"); + return eStatus; +} + +////////////////////////////////////////// +// Function : LoggerServer_SetLoggerParams +// Callback for SS_LOGGER_SET_PARAMS +////////////////////////////////////////// +EFrameworkunifiedStatus CLoggerServiceCallbacks::LoggerServer_UDPLogging(HANDLE hApp) { + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+"); + EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK; + ELOGGER_STAT l_eUDPLoggingStatus = eInvalid_LoggerState; + + if (eFrameworkunifiedStatusOK != (l_eStatus = FrameworkunifiedGetMsgDataOfSize(hApp, &l_eUDPLoggingStatus, sizeof(l_eUDPLoggingStatus), eSMRRelease))) { // LCOV_EXCL_BR_LINE 4:NSFW // NOLINT[whitespace/line_length] + // LCOV_EXCL_START 4:NSFW + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "Error: FrameworkunifiedGetMsgDataOfSize Failed"); + l_eStatus = eFrameworkunifiedStatusFail; + // LCOV_EXCL_STOP + } else { + l_eStatus = m_pLoggerCfg->SetUDPLogging(hApp, l_eUDPLoggingStatus); + LOG_STATUS_IF_ERRORED( // LCOV_EXCL_BR_LINE 15:macro + l_eStatus, + "m_pLoggerCfg->SetUDPLogging()"); + } + + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-"); + return (l_eStatus); +} + +EFrameworkunifiedStatus CLoggerServiceCallbacks::LoggerServer_UpdateCommonInfo(HANDLE hApp) { + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+"); + EFrameworkunifiedStatus eStatus = eFrameworkunifiedStatusOK; + + if (eFrameworkunifiedStatusOK != (eStatus = FrameworkunifiedGetMsgDataOfSize(hApp, &g_uEvtLoggerCommonInfo.u_stEvtLoggerCommonInfo, sizeof(g_uEvtLoggerCommonInfo.u_stEvtLoggerCommonInfo), eSMRRelease))) { // LCOV_EXCL_BR_LINE 4:NSFW // NOLINT[whitespace/line_length] + // LCOV_EXCL_START 4:NSFW + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, " FrameworkunifiedGetMsgDataOfSize Failed"); + eStatus = eFrameworkunifiedStatusFail; + // LCOV_EXCL_STOP + } + + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-"); + return eStatus; +} + +EFrameworkunifiedStatus CLoggerServiceCallbacks::LoggerServer_Handle_CWORD56_Events(HANDLE hApp) { + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+"); + EFrameworkunifiedStatus eStatus = eFrameworkunifiedStatusOK; + STEventLoggerEventInfo l_stEventLoggingEventInfo; + UI_16 l_evtid = 0; + + if (eFrameworkunifiedStatusOK != (eStatus = FrameworkunifiedGetMsgDataOfSize(hApp, &l_stEventLoggingEventInfo, sizeof(l_stEventLoggingEventInfo), eSMRRelease))) { // LCOV_EXCL_BR_LINE 4:NSFW // NOLINT[whitespace/line_length] + // LCOV_EXCL_START 4:NSFW + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, " FrameworkunifiedGetMsgDataOfSize Failed"); + eStatus = eFrameworkunifiedStatusFail; + // LCOV_EXCL_STOP + } + l_evtid = static_cast<UI_16>(((l_stEventLoggingEventInfo.EventGroup & 0x00FF) << 8) + | (l_stEventLoggingEventInfo.EventIdentifier & 0x00FF)); + FRAMEWORKUNIFIEDLOG_EVT(ZONE_INFO, l_evtid, 4, l_stEventLoggingEventInfo.EventData[3], + l_stEventLoggingEventInfo.EventData[2], + l_stEventLoggingEventInfo.EventData[1], + l_stEventLoggingEventInfo.EventData[0]); + + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-"); + return eStatus; +} + +EFrameworkunifiedStatus CLoggerServiceCallbacks::LoggerServer_OnCopyEmergencyLog( + HANDLE f_hApp) { + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+"); + EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK; + EDevNumber l_eDevNumber; + std::string l_path = ""; + std::string l_srcName = ""; + + if (NULL != f_hApp) { // LCOV_EXCL_BR_LINE 6: it can't be null. + PCSTR l_tmp_srcname = FrameworkunifiedGetMsgSrc(f_hApp); + if (NULL != l_tmp_srcname) { // LCOV_EXCL_BR_LINE 6: it can't be null. + l_srcName = l_tmp_srcname; + } + + if (eFrameworkunifiedStatusOK + == (l_eStatus = FrameworkunifiedGetMsgDataOfSize(f_hApp, &l_eDevNumber, + sizeof(l_eDevNumber), eSMRRelease))) { + switch (l_eDevNumber) { + case eEEL_USB1: + l_path = m_pLoggerCfg->m_usb0MountPath; + break; + + case eEEL_USB2: + l_path = m_pLoggerCfg->m_usb1MountPath; + break; + + case eEEL_SD: + l_path = m_pLoggerCfg->m_sdMountPath; + break; + + default: + /*send back error response wrong param*/ + l_eStatus = eFrameworkunifiedStatusInvldParam; + break; + } + } else { + FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, " Error. Could not get msg Data."); + } + + HANDLE l_hSession = NULL; + if (NULL == (l_hSession = FrameworkunifiedGetCurrentSessionHandle(f_hApp))) { // LCOV_EXCL_BR_LINE 4: NSFW error case. + // LCOV_EXCL_START 4: NSFW error case. + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + l_eStatus = eFrameworkunifiedStatusNullPointer; + LOG_ERROR("FrameworkunifiedGetCurrentSessionHandle()"); + // LCOV_EXCL_STOP + } else { + m_pErrorEvent->SetDiagSessionHandle(l_hSession); + } + if (0 == l_srcName.length()) { // LCOV_EXCL_BR_LINE 6: it can't be 0. + // LCOV_EXCL_START 6: it can't be 0. + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, + " Error. Could not get name of source service."); + // LCOV_EXCL_STOP + l_eStatus = eFrameworkunifiedStatusInvldHandle; + } else if (eFrameworkunifiedStatusOK != l_eStatus) { + FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, + " Error. Invalid parameter l_eDevNumber(%d).", l_eDevNumber); + l_eStatus = m_pErrorEvent->sendDiagEventErrorResponse(eNO_ERROR_INFO, + l_srcName); + LOG_STATUS_IF_ERRORED(l_eStatus, "m_pErrorEvent->sendDiagEventErrorResponse(l_srcName)"); + l_eStatus = eFrameworkunifiedStatusInvldParam; + } else if (eFrameworkunifiedStatusOK + != (l_eStatus = m_pErrorEvent->SetDiagEventSourceName(l_srcName))) { + FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, + " Error. m_pErrorEvent->SetDiagEventSourceName() returned %d.", l_eStatus); + l_eStatus = m_pErrorEvent->sendDiagEventErrorResponse(eNO_ERROR_INFO, + l_srcName); + LOG_STATUS_IF_ERRORED(l_eStatus, "m_pErrorEvent->sendDiagEventErrorResponse(l_srcName)"); + l_eStatus = eFrameworkunifiedStatusFail; + } else if (eFrameworkunifiedStatusOK != (l_eStatus = + SendDiagLoggingRequestToSystemManager(l_path))) { // LCOV_EXCL_BR_LINE 4: NSFW error case. + // LCOV_EXCL_START 4: NSFW error case. + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + /* call System Manager interface*/ + FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, + " Error. SendDiagLoggingRequestToSystemManager() returned %d.", l_eStatus); + l_eStatus = m_pErrorEvent->sendDiagEventErrorResponse(eNO_ERROR_INFO); + LOG_STATUS_IF_ERRORED(l_eStatus, "m_pErrorEvent->sendDiagEventErrorResponse()"); + l_eStatus = eFrameworkunifiedStatusFail; + // LCOV_EXCL_STOP + } else { + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "Log Request passed to SystemManager."); + } + } + + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-"); + return (l_eStatus); +} + +EFrameworkunifiedStatus CLoggerServiceCallbacks::LoggerServer_OnCANTrigger(HANDLE f_hApp) { + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+"); + EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK; + l_eStatus = SendCANLoggingRequestToSystemManager(); + LOG_STATUS_IF_ERRORED(l_eStatus, "SendCANLoggingRequestToSystemManager()"); // LCOV_EXCL_BR_LINE 15:macro + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-"); + return (l_eStatus); +} + +EFrameworkunifiedStatus CLoggerServiceCallbacks::LoggerServer_OnDTCTrigger(HANDLE f_hApp) { + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+"); + EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK; + UI_32 l_dtc; + if (eFrameworkunifiedStatusOK != (l_eStatus = FrameworkunifiedGetMsgDataOfSize(f_hApp, &l_dtc, sizeof(l_dtc), eSMRRelease))) { // LCOV_EXCL_BR_LINE 4:NSFW // NOLINT[whitespace/line_length] + // LCOV_EXCL_START 4:NSFW + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, " Error. Could not get msg Data."); + // LCOV_EXCL_STOP + } else { + l_eStatus = SendDTCLoggingRequestToSystemManager(l_dtc); + LOG_STATUS_IF_ERRORED(l_eStatus, "SendDTCLoggingRequestToSystemManager(dtc)"); // LCOV_EXCL_BR_LINE 15:macro + // Immediate Persist Event Log + if (eFrameworkunifiedStatusOK != (l_eStatus = FrameworkunifiedSendChild(f_hApp, g_thrdEvntLogWriter, eThrdCmdImmPersistEvtLog, 0x00, NULL))) { // LCOV_EXCL_BR_LINE 4:NSFW // NOLINT[whitespace/line_length] + // LCOV_EXCL_START 4:NSFW + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__, "FrameworkunifiedSendChild msg failed:%X", l_eStatus); + // LCOV_EXCL_STOP + } + } + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-"); + return (l_eStatus); +} + +EFrameworkunifiedStatus CLoggerServiceCallbacks::LoggerServer_On_SHTDWN_Complete( + HANDLE f_hApp) { + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+"); + EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK; + l_eStatus = LoggerService_OnStop(f_hApp); + LOG_STATUS_IF_ERRORED(l_eStatus, "LoggerService_OnStop()"); // LCOV_EXCL_BR_LINE 15:macro + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-"); + return (l_eStatus); +} + +/////////////////////////////////////////////////////////////////////// +/// Function :LoggerServer_OnSetVIN +/////////////////////////////////////////////////////////////////////// +EFrameworkunifiedStatus CLoggerServiceCallbacks::LoggerServer_OnSetVIN(HANDLE hApp) { + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+"); + EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK; + STVIN_NUMBER l_stVIN_Number; + + if (eFrameworkunifiedStatusOK == (l_eStatus = FrameworkunifiedGetMsgDataOfSize(hApp, &l_stVIN_Number, sizeof(l_stVIN_Number), eSMRRelease))) { // LCOV_EXCL_BR_LINE 4:NSFW // NOLINT[whitespace/line_length] + if (eFrameworkunifiedStatusOK != (l_eStatus = FrameworkunifiedSendChild(hApp, g_thrdEvntLogWriter, eThrdCmdSetVINnumber, sizeof(STVIN_NUMBER), &l_stVIN_Number))) { // LCOV_EXCL_BR_LINE 4:NSFW // NOLINT[whitespace/line_length] + // LCOV_EXCL_START 4:NSFW + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__, "FrameworkunifiedSendChild msg failed:%X", l_eStatus); + // LCOV_EXCL_STOP + } + } else { + // LCOV_EXCL_START 4:NSFW + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__, "FrameworkunifiedGetMsgDataOfSize failed errval: %X", + l_eStatus); + // LCOV_EXCL_STOP + } + + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-"); + return (l_eStatus); +} + +/////////////////////////////////////////////////////////////////////// +/// Function :LoggerServer_OnCopyEvntLog +/////////////////////////////////////////////////////////////////////// +EFrameworkunifiedStatus CLoggerServiceCallbacks::LoggerServer_OnCopyEvntLog(HANDLE hApp) { + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+"); + EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK; + + TWriteFilesToUsbCmdData l_stCmdData; + HANDLE l_hSession = NULL; + + if (hApp != NULL) { // LCOV_EXCL_BR_LINE 6: it can not be null + PCSTR l_tmp_srcname = FrameworkunifiedGetMsgSrc(hApp); + if (NULL != l_tmp_srcname) { // LCOV_EXCL_BR_LINE 6: it can not be null + l_stCmdData.stSessiondata.strSrcName = l_tmp_srcname; + } + if (l_stCmdData.stSessiondata.strSrcName.empty()) { // LCOV_EXCL_BR_LINE 6: it can not be empty + // LCOV_EXCL_START 6: it can not be empty + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + l_eStatus = eFrameworkunifiedStatusNullPointer; + LOG_ERROR("FrameworkunifiedGetMsgSrc()"); + // LCOV_EXCL_STOP + } else if (NULL == (l_hSession = FrameworkunifiedGetCurrentSessionHandle(hApp))) { // LCOV_EXCL_BR_LINE 6: it can not be null + // LCOV_EXCL_START 6: it can not be null + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + l_eStatus = eFrameworkunifiedStatusNullPointer; + LOG_ERROR("FrameworkunifiedGetCurrentSessionHandle()"); + // LCOV_EXCL_STOP + } else { + l_stCmdData.stSessiondata.session_id = FrameworkunifiedGetSessionId(l_hSession); + if (eFrameworkunifiedStatusOK + != (l_eStatus = ReadMsg<EEvtLogUSBDevNumber>(hApp, l_stCmdData.eDevId))) { + LOG_ERROR("ReadMsg()"); + } else { + if (eFrameworkunifiedStatusOK + != (l_eStatus = FrameworkunifiedSendChild(hApp, g_thrdEvntLogWriter, // LCOV_EXCL_BR_LINE 4:NSFW + eThrdCmdWriteEvntFilesToUsb, + sizeof(TWriteFilesToUsbCmdData), + &l_stCmdData))) { + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + LOG_ERROR("FrameworkunifiedSendChild()"); // LCOV_EXCL_LINE 4:NSFW + } + } + } + } else { + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "Invalid App handler"); // LCOV_EXCL_LINE 6: it can not be null + } + + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-"); + return (l_eStatus); +} + +/////////////////////////////////////////////////////////////////////// +/// Function :LoggerServer_OnClearEvntLog +/////////////////////////////////////////////////////////////////////// +EFrameworkunifiedStatus CLoggerServiceCallbacks::LoggerServer_OnClearEvntLog(HANDLE hApp) { + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+"); + EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK; + + if (hApp != NULL) { // LCOV_EXCL_BR_LINE 200:As it is not always NULL + TSessionData l_sessiondata; + HANDLE l_hSession = NULL; + PCSTR l_tmp_srcname = FrameworkunifiedGetMsgSrc(hApp); // LCOV_EXCL_BR_LINE 11:Unexpected branch + if (NULL != l_tmp_srcname) { // LCOV_EXCL_BR_LINE 4:NSFW + l_sessiondata.strSrcName = l_tmp_srcname; + } + if (l_sessiondata.strSrcName.empty()) { // LCOV_EXCL_BR_LINE 4:As it is guaranteed by NSFW and is not always an empty string + // LCOV_EXCL_START 4:As it is guaranteed by NSFW and is not always an empty string + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + l_eStatus = eFrameworkunifiedStatusNullPointer; + LOG_ERROR("FrameworkunifiedGetMsgSrc()"); + // LCOV_EXCL_STOP + } else if (NULL == (l_hSession = FrameworkunifiedGetCurrentSessionHandle(hApp))) { // LCOV_EXCL_BR_LINE 4:NSFW + // LCOV_EXCL_START 4:NSFW + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + l_eStatus = eFrameworkunifiedStatusNullPointer; + LOG_ERROR("FrameworkunifiedGetCurrentSessionHandle()"); + // LCOV_EXCL_STOP + } else { + l_sessiondata.session_id = FrameworkunifiedGetSessionId(l_hSession); // LCOV_EXCL_BR_LINE 11:Unexpected branch + if (eFrameworkunifiedStatusOK != (l_eStatus = FrameworkunifiedSendChild(hApp, g_thrdEvntLogWriter, eThrdCmdClearEvntLogs, sizeof(TSessionData), &l_sessiondata))) { // LCOV_EXCL_BR_LINE 4:NSFW // NOLINT[whitespace/line_length] + // LCOV_EXCL_START 4:NSFW + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + LOG_ERROR("FrameworkunifiedSendChild()"); + // LCOV_EXCL_STOP + } + } + } + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-"); + return (l_eStatus); +} + +/////////////////////////////////////////////////////////////////////// +/// Function :LoggerServer_OnReadStatCounter +/////////////////////////////////////////////////////////////////////// +EFrameworkunifiedStatus CLoggerServiceCallbacks::LoggerServer_OnReadStatCounter( + HANDLE hApp) { + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+"); + EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK; + + if (hApp != NULL) { // LCOV_EXCL_BR_LINE 6: it can not be null + TStatisticalCountersCmd l_stCmdData; + HANDLE l_hSession = NULL; + + PCSTR l_tmp_srcname = FrameworkunifiedGetMsgSrc(hApp); + if (NULL != l_tmp_srcname) { // LCOV_EXCL_BR_LINE 6: it can not be null + l_stCmdData.stSessiondata.strSrcName = l_tmp_srcname; + } + if (l_stCmdData.stSessiondata.strSrcName.empty()) { // LCOV_EXCL_BR_LINE 6: it can not be empty + // LCOV_EXCL_START 6: it can not be empty + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + l_eStatus = eFrameworkunifiedStatusNullPointer; + LOG_ERROR("FrameworkunifiedGetMsgSrc()"); + // LCOV_EXCL_STOP + } else if (NULL == (l_hSession = FrameworkunifiedGetCurrentSessionHandle(hApp))) { // LCOV_EXCL_BR_LINE 6: it can not be null + // LCOV_EXCL_START 6: it can not be empty + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + l_eStatus = eFrameworkunifiedStatusNullPointer; + LOG_ERROR("FrameworkunifiedGetCurrentSessionHandle()"); + // LCOV_EXCL_STOP + } else { + l_stCmdData.stSessiondata.session_id = FrameworkunifiedGetSessionId(l_hSession); + if (eFrameworkunifiedStatusOK + != (l_eStatus = ReadMsg<EStatCounterGroupID>(hApp, + l_stCmdData.eGroupId))) { + LOG_ERROR("ReadMsg()"); + } else { + if (eFrameworkunifiedStatusOK + != (l_eStatus = FrameworkunifiedSendChild(hApp, g_thrdEvntLogWriter, // LCOV_EXCL_BR_LINE 4:NSFW + eThrdCmdStatisticalCounter, + sizeof(TStatisticalCountersCmd), + &l_stCmdData))) { + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + LOG_ERROR("FrameworkunifiedSendChild()");// LCOV_EXCL_LINE 4:NSFW + } + } + } + } + + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-"); + return (l_eStatus); +} + +/////////////////////////////////////////////////////////////////////// +/// Function :LoggerServer_OnResetStatCounter +/////////////////////////////////////////////////////////////////////// +EFrameworkunifiedStatus CLoggerServiceCallbacks::LoggerServer_OnResetStatCounter( + HANDLE hApp) { + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+"); + EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK; + + if (hApp != NULL) { // LCOV_EXCL_BR_LINE 6: it can not be null + TStatisticalCountersCmd l_stCmdData; + HANDLE l_hSession = NULL; + PCSTR l_tmp_srcname = FrameworkunifiedGetMsgSrc(hApp); + if (NULL != l_tmp_srcname) { // LCOV_EXCL_BR_LINE 6: it can not be null + l_stCmdData.stSessiondata.strSrcName = l_tmp_srcname; + } + if (l_stCmdData.stSessiondata.strSrcName.empty()) { // LCOV_EXCL_BR_LINE 6: it can not be empty + // LCOV_EXCL_START 6: it can not be empty + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + l_eStatus = eFrameworkunifiedStatusNullPointer; + LOG_ERROR("FrameworkunifiedGetMsgSrc()"); + // LCOV_EXCL_STOP + } else if (NULL == (l_hSession = FrameworkunifiedGetCurrentSessionHandle(hApp))) { // LCOV_EXCL_BR_LINE 6: it can not be null + // LCOV_EXCL_START 6: it can not be empty + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + l_eStatus = eFrameworkunifiedStatusNullPointer; + LOG_ERROR("FrameworkunifiedGetCurrentSessionHandle()"); + // LCOV_EXCL_STOP + } else { + l_stCmdData.stSessiondata.session_id = FrameworkunifiedGetSessionId(l_hSession); + if (eFrameworkunifiedStatusOK + != (l_eStatus = ReadMsg<EStatCounterGroupID>(hApp, + l_stCmdData.eGroupId))) { + LOG_ERROR("ReadMsg()"); + } else { + if (eFrameworkunifiedStatusOK + != (l_eStatus = FrameworkunifiedSendChild(hApp, g_thrdEvntLogWriter, // LCOV_EXCL_BR_LINE 4:NSFW + eThrdCmdResetStatisticalCntrs, + sizeof(TStatisticalCountersCmd), + &l_stCmdData))) { + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + LOG_ERROR("FrameworkunifiedSendChild()"); // LCOV_EXCL_LINE 4:NSFW + } + } + } + } + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-"); + return (l_eStatus); +} + +/////////////////////////////////////////////////////////////////////// +/// Function :LoggerServer_OnReadNumberOfEvents +/////////////////////////////////////////////////////////////////////// +EFrameworkunifiedStatus CLoggerServiceCallbacks::LoggerServer_OnReadNumberOfEvents( + HANDLE hApp) { + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+"); + EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK; + TSessionData l_sessiondata; + HANDLE l_hSession = NULL; + + l_sessiondata.strSrcName = FrameworkunifiedGetMsgSrc(hApp); + if (l_sessiondata.strSrcName.empty()) { // LCOV_EXCL_BR_LINE 6: it can not be empty + // LCOV_EXCL_START 6: it can not be empty + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + l_eStatus = eFrameworkunifiedStatusNullPointer; + LOG_ERROR("FrameworkunifiedGetMsgSrc()"); + // LCOV_EXCL_STOP + } else if (NULL == (l_hSession = FrameworkunifiedGetCurrentSessionHandle(hApp))) { // LCOV_EXCL_BR_LINE 6: it can not be null + // LCOV_EXCL_START 6: it can not be empty + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + l_eStatus = eFrameworkunifiedStatusNullPointer; + LOG_ERROR("FrameworkunifiedGetCurrentSessionHandle()"); + // LCOV_EXCL_STOP + } else { + l_sessiondata.session_id = FrameworkunifiedGetSessionId(l_hSession); + if (eFrameworkunifiedStatusOK + != (l_eStatus = FrameworkunifiedSendChild(hApp, g_thrdEvntLogWriter, // LCOV_EXCL_BR_LINE 4:NSFW + eThrdCmdGetNumberOfEventsLogged, + sizeof(TSessionData), &l_sessiondata))) { + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + LOG_ERROR("FrameworkunifiedSendChild()"); // LCOV_EXCL_LINE 4:NSFW + } + } + + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-"); + return (l_eStatus); +} + +/////////////////////////////////////////////////////////////////////// +/// Function :LoggerServer_OnSetDiagID +/////////////////////////////////////////////////////////////////////// +EFrameworkunifiedStatus CLoggerServiceCallbacks::LoggerServer_OnSetDiagID(HANDLE hApp) { + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+"); + EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK; + UI_16 l_DiagId = 0; + + if (eFrameworkunifiedStatusOK != (l_eStatus = ReadMsg<UI_16>(hApp, l_DiagId))) { // LCOV_EXCL_BR_LINE 200:To ensure success + // LCOV_EXCL_START 200:To ensure success + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + LOG_ERROR("ReadMsg()"); + // LCOV_EXCL_STOP + } else { + g_u16DiagId = l_DiagId; + } + return l_eStatus; +} + +/////////////////////////////////////////////////////////////////////// +/// Function :LoggerServer_UploadEventLog +/////////////////////////////////////////////////////////////////////// +EFrameworkunifiedStatus CLoggerServiceCallbacks::LoggerServer_UploadEventLog(HANDLE hApp) { + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+"); + EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK; + TSessionData l_sessiondata; + HANDLE l_hSession = NULL; + + PCSTR l_tmp_srcname = FrameworkunifiedGetMsgSrc(hApp); + if (NULL != l_tmp_srcname) { // LCOV_EXCL_BR_LINE 6: it can not be null + l_sessiondata.strSrcName = l_tmp_srcname; + } + if (l_sessiondata.strSrcName.empty()) { // LCOV_EXCL_BR_LINE 6: it can not be empty + // LCOV_EXCL_START 6: it can not be empty + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + l_eStatus = eFrameworkunifiedStatusNullPointer; + LOG_ERROR("FrameworkunifiedGetMsgSrc()"); + // LCOV_EXCL_STOP + } else if (NULL == (l_hSession = FrameworkunifiedGetCurrentSessionHandle(hApp))) { // LCOV_EXCL_BR_LINE 6: it can not be null + // LCOV_EXCL_START 6: it can not be null + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + l_eStatus = eFrameworkunifiedStatusNullPointer; + LOG_ERROR("FrameworkunifiedGetCurrentSessionHandle()"); + // LCOV_EXCL_STOP + } else { + l_sessiondata.session_id = FrameworkunifiedGetSessionId(l_hSession); + if (eFrameworkunifiedStatusOK + != (l_eStatus = FrameworkunifiedSendChild(hApp, g_thrdEvntLogWriter, // LCOV_EXCL_BR_LINE 4:NSFW + eThrdCmdUploadEventLog, + sizeof(TSessionData), &l_sessiondata))) { + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + LOG_ERROR("FrameworkunifiedSendChild()"); // LCOV_EXCL_LINE 4:NSFW + } + } + + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-"); + return (l_eStatus); +} diff --git a/systemservice/logger_service/server/src/ss_logger_util.cpp b/systemservice/logger_service/server/src/ss_logger_util.cpp new file mode 100755 index 0000000..6ac7225 --- /dev/null +++ b/systemservice/logger_service/server/src/ss_logger_util.cpp @@ -0,0 +1,1273 @@ +/* + * @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_SS_LoggerService +/// \brief Provide support for SS Logger module utility functions. +/// +/////////////////////////////////////////////////////////////////////////////// +/////////////////////////////////////////////////////////////////////////////// +// INCLUDES +/////////////////////////////////////////////////////////////////////////////// +#include "ss_logger_util.h" +#include <sys/types.h> +#include <sys/stat.h> +#include <fcntl.h> +#include <stdio.h> +#include <dirent.h> +#include <stdlib.h> +#include <unistd.h> +#include <errno.h> +#include <stub/Clock_API.h> +#include <iomanip> +#include <sstream> +#include <string> +#include <algorithm> +#include <vector> +#include "ss_logger_common.h" + +#include <system_service/ss_logger_store_logs.h> + +#define SS_STORE_FILENAME_SYSILG_TERM "_SYS_ILG_RESET.tar.gz" +#define SS_STORE_FILENAME__CWORD52__TERM "__CWORD52_.log" + + +char CLoggerUtil::m_usbpath[USB_PATH_SIZE]; + +/////////////////////////////////////////////////////////////////////////////// +// CLASS METHODS +/////////////////////////////////////////////////////////////////////////////// +CLoggerUtil::CLoggerUtil(void) + : m_pCfg(NULL), + m_Milage(0), + m_bootCount(0) { + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+"); + m_usbpath[0] = '\0'; + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-"); +} + +CLoggerUtil::~CLoggerUtil(void) { // LCOV_EXCL_START 14:globle instance + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+"); + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-"); +} +// LCOV_EXCL_STOP + +EFrameworkunifiedStatus CLoggerUtil::Initialize(CLoggerCfg *f_pLoggerCfg) { + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+"); + EFrameworkunifiedStatus l_eStatus; + + m_pCfg = f_pLoggerCfg; + l_eStatus = (NULL != f_pLoggerCfg) ? eFrameworkunifiedStatusOK : eFrameworkunifiedStatusInvldParam; + + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-"); + return (l_eStatus); +} + +std::string CLoggerUtil::getDestination(TLoggerErrorEvent &f_eventNtfData) { + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+: %d ", f_eventNtfData.EventType); + std::string l_path = ""; + EFrameworkunifiedStatus l_eStatus; + + switch (f_eventNtfData.EventType) { + case eErrorEventTypeProcessCrash: + case eErrorEventTypeHeartBeatFailure: + case eErrorEventTypeSystemLowMemory: + case eErrorEventTypeBootMicroReset: + case eErrorEventTypeProcessExit: + case eErrorEventTypeUserInvokedUserForceReset: + case eErrorEventTypeModConnFailed: + case eErrorEventTypeStartRespFailed: + case eErrorEventTypeUserInvokedCollectDevLogs: + case eErrorEventTypeModuleInvokedResetRequest: + case eErrorEventTypeModuleInvokedCollectDebugLogs: + case eErrorEventTypeDtcEvent: + case eErrorEventTypeUserInvokedClearLogs: + case eErrorEventTypeGroupRelaunch: + l_eStatus = m_pCfg->GetEmmcDestination(l_path); + break; + + case eErrorEventTypeUserInvokedCollectNaviLog: + l_eStatus = m_pCfg->GetEmmcNaviLogDestination(l_path); + break; + + case eErrorEventTypeEelExport: + l_path = f_eventNtfData.ModuleName; + l_eStatus = eFrameworkunifiedStatusOK; + break; + + case eErrorEventTypeInterfaceunifiedEmmcLogs: + l_path = f_eventNtfData.ModuleName; + l_eStatus = eFrameworkunifiedStatusOK; + break; + + case eErrorEventTypeUserInvokedCollectAllLogs: + case eErrorEventTypeUserInvokedCollectScreenShot: + case eErrorEventTypeUserInvokedCollectInterfaceunifiedLogs: + case eErrorEventTypeCanEvent: + l_eStatus = m_pCfg->GetUserInvokedDestination(l_path); + break; + + case eErrorEventTypeDiagEvent: + l_path = f_eventNtfData.ModuleName; + l_eStatus = eFrameworkunifiedStatusOK; + break; + + default: + l_eStatus = eFrameworkunifiedStatusFail; + break; + } + if (eFrameworkunifiedStatusOK != l_eStatus) { + FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, " Error. Could not get filepath "); + } + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-: %s", l_path.c_str()); + return (l_path); +} +EFrameworkunifiedStatus CLoggerUtil::checkDestinationAvailable( + TLoggerErrorEvent &f_eventNtfData) { + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+"); + EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusFail; + std::string l_path = CLoggerUtil::getDestination(f_eventNtfData); + std::string::size_type ret; + + if (l_path.length() > 0) { + ret = l_path.find(DEBUG_USB_PATH); + if (ret != std::string::npos && ret == 0) { + if (0 == access(m_usbpath, W_OK)) { // LCOV_EXCL_BR_LINE 5:C code + // LCOV_EXCL_START 5:C code + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + std::string path = l_path.substr(sizeof(DEBUG_USB_PATH) - 1); + f_eventNtfData.ModuleName = m_usbpath; + f_eventNtfData.ModuleName.append(path); + l_eStatus = eFrameworkunifiedStatusOK; + // LCOV_EXCL_STOP + } + } else { + if (0 == access(l_path.c_str(), W_OK)) { // LCOV_EXCL_BR_LINE 5:C code + l_eStatus = eFrameworkunifiedStatusOK; + } + } + } + + if (eFrameworkunifiedStatusOK != l_eStatus) { + FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, + " Error. Failed the check path: l_eStatus(%d), l_path(%s)", + l_eStatus, l_path.c_str()); // LCOV_EXCL_BR_LINE 11:except,C++ STL + } + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-"); + return (l_eStatus); +} + +static void SetSuffixFromType(std::string &pathAndName, EErrorEventType type) { // NOLINT (runtime/references) + switch (type) { + case eErrorEventTypeProcessCrash: + case eErrorEventTypeHeartBeatFailure: + case eErrorEventTypeSystemLowMemory: + case eErrorEventTypeBootMicroReset: + case eErrorEventTypeProcessExit: + case eErrorEventTypeModConnFailed: + case eErrorEventTypeStartRespFailed: + case eErrorEventTypeModuleInvokedResetRequest: + pathAndName.insert(pathAndName.find(".tar.gz"), "_ERR"); + break; + case eErrorEventTypeUserInvokedUserForceReset: + case eErrorEventTypeUserInvokedCollectAllLogs: + case eErrorEventTypeUserInvokedCollectScreenShot: + case eErrorEventTypeUserInvokedCollectInterfaceunifiedLogs: + case eErrorEventTypeDiagEvent: + case eErrorEventTypeCanEvent: + case eErrorEventTypeDtcEvent: + case eErrorEventTypeModuleInvokedCollectDebugLogs: + pathAndName.insert(pathAndName.find(".tar.gz"), "_DIAG"); + break; + case eErrorEventTypeUserInvokedCollectDevLogs: + pathAndName.insert(pathAndName.find(".tar.gz"), "_DEBUG"); + break; + case eErrorEventTypeGroupRelaunch: + pathAndName.insert(pathAndName.find(".tar.gz"), "_GRP_RELAUNCH"); + break; + default: + break; + } +} + +EFrameworkunifiedStatus CLoggerUtil::getFilePathAndName(HANDLE f_hApp, + TLoggerErrorEvent &f_eventNtfData, + uint32_t f_time, + std::string &f_pathAndName) { + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+"); + EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK; + f_pathAndName = ""; + + switch (f_eventNtfData.EventType) { // LCOV_EXCL_BR_LINE 200: eErrorEventTypeEelExport ex. can not be run + case eErrorEventTypeProcessCrash: + case eErrorEventTypeProcessExit: + case eErrorEventTypeHeartBeatFailure: + case eErrorEventTypeSystemLowMemory: + case eErrorEventTypeBootMicroReset: + case eErrorEventTypeModConnFailed: + case eErrorEventTypeStartRespFailed: + case eErrorEventTypeGroupRelaunch: + l_eStatus = m_pCfg->GetEmmcDestination(f_pathAndName); + if (eFrameworkunifiedStatusOK != l_eStatus) { // LCOV_EXCL_BR_LINE 6:it will aways return ok + // LCOV_EXCL_START 6:it will aways return ok + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, + " Error. GetEmmcDestination() returned %d.", + l_eStatus); + // LCOV_EXCL_STOP + } else { + f_pathAndName.append("/"); + f_pathAndName.append(GetEmmcFilename(f_time)); + } + break; + + case eErrorEventTypeUserInvokedUserForceReset: + case eErrorEventTypeUserInvokedCollectDevLogs: + l_eStatus = m_pCfg->GetEmmcDestination(f_pathAndName); + if (eFrameworkunifiedStatusOK != l_eStatus) { // LCOV_EXCL_BR_LINE 6:it will aways return ok + // LCOV_EXCL_START 6:it will aways return ok + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, + " Error. GetEmmcDestination() returned %d.", + l_eStatus); + // LCOV_EXCL_STOP + } else { + f_pathAndName.append("/"); + f_pathAndName.append(GetEmmcFilename(f_time)); + } + break; + case eErrorEventTypeModuleInvokedResetRequest: + case eErrorEventTypeModuleInvokedCollectDebugLogs: + case eErrorEventTypeDtcEvent: + l_eStatus = m_pCfg->GetEmmcDestination(f_pathAndName); + if (eFrameworkunifiedStatusOK != l_eStatus) { // LCOV_EXCL_BR_LINE 6:it will aways return ok + // LCOV_EXCL_START 6:it will aways return ok + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, + " Error. GetEmmcDestination() returned %d.", + l_eStatus); + // LCOV_EXCL_STOP + } else { + f_pathAndName.append("/"); + f_pathAndName.append(GetEmmcFilename(f_time)); + if (!f_eventNtfData.ModuleName.empty()) { // LCOV_EXCL_BR_LINE 6: ModuleName can not be empty + size_t l_pos = f_pathAndName.find(".tar.gz"); + if (l_pos != std::string::npos) { // LCOV_EXCL_BR_LINE 6: ".tar.gz" is aways exist + f_pathAndName.insert(l_pos, f_eventNtfData.ModuleName); + } + } + } + break; + case eErrorEventTypeEelExport: // LCOV_EXCL_START 6: impossible to confirm because it can not get in + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + f_pathAndName = f_eventNtfData.ModuleName; + f_pathAndName.append("/"); + f_pathAndName.append("loggerservicelogs_export_"); + f_pathAndName.append(GetTimeString(f_time)); + f_pathAndName.append(".tar.gz"); + break; + // LCOV_EXCL_STOP + case eErrorEventTypeInterfaceunifiedEmmcLogs: // LCOV_EXCL_START 6: impossible to confirm because it can not get in + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + // store the target location on event trigger + f_pathAndName = f_eventNtfData.ModuleName; + break; + // LCOV_EXCL_STOP + case eErrorEventTypeUserInvokedCollectAllLogs: + l_eStatus = m_pCfg->GetUserInvokedDestination(f_pathAndName); + if (eFrameworkunifiedStatusOK != l_eStatus) { // LCOV_EXCL_BR_LINE 6: impossible to confirm because it can not be fail + // LCOV_EXCL_START 6: impossible to confirm because it can not be fail + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, + " Error. GetUserInvokedDestination() returned %d.", + l_eStatus); + // LCOV_EXCL_STOP + } else { + std::string l_emmc_path = m_pCfg->getEmmcOutputPath(); + f_pathAndName.append(l_emmc_path); + f_pathAndName.append("/"); + f_pathAndName.append(GetUserInvokedFilename(f_hApp, f_time)); + if (!f_eventNtfData.ModuleName.empty()) { // LCOV_EXCL_BR_LINE 6: it can not be empty + size_t l_pos = f_pathAndName.find(".tar.gz"); + if (l_pos != std::string::npos) { // LCOV_EXCL_BR_LINE 6: ".tar.gz" is aways exist + f_pathAndName.insert(l_pos, f_eventNtfData.ModuleName); + } + } + } + break; + + case eErrorEventTypeUserInvokedCollectScreenShot: + case eErrorEventTypeUserInvokedCollectInterfaceunifiedLogs: + case eErrorEventTypeCanEvent: + l_eStatus = m_pCfg->GetUserInvokedDestination(f_pathAndName); + if (eFrameworkunifiedStatusOK != l_eStatus) { // LCOV_EXCL_BR_LINE 6: impossible to confirm because it can not be fail + // LCOV_EXCL_START 6: impossible to confirm because it can not be fail + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, + " Error. GetUserInvokedDestination() returned %d.", + l_eStatus); + // LCOV_EXCL_STOP + } else { + f_pathAndName.append("/"); + f_pathAndName.append(GetUserInvokedFilename(f_hApp, f_time)); + } + break; + + case eErrorEventTypeDiagEvent: // LCOV_EXCL_START 6: impossible to confirm because it can not get in + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + f_pathAndName = f_eventNtfData.ModuleName; + f_pathAndName.append("/"); + f_pathAndName.append(GetUserInvokedFilename(f_hApp, f_time)); + l_eStatus = eFrameworkunifiedStatusOK; + break; + // LCOV_EXCL_STOP + case eErrorEventTypeUserInvokedClearLogs: + case eErrorEventTypeUserInvokedCollectNaviLog: + l_eStatus = eFrameworkunifiedStatusOK; + break; + + default: + FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, " Error. Unknown event type: %d.", + f_eventNtfData.EventType); + l_eStatus = eFrameworkunifiedStatusFail; + break; + } + + SetSuffixFromType(f_pathAndName, f_eventNtfData.EventType); + + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-"); + return (l_eStatus); +} + +// LCOV_EXCL_START 13: +EFrameworkunifiedStatus CLoggerUtil::getNaviLogFilePathAndName(std::string &f_prefix, + uint32_t f_time, + std::string &f_pathAndName) { // LCOV_EXCL_BR_LINE 13: + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+"); + EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK; + + l_eStatus = m_pCfg->GetEmmcNaviLogDestination(f_pathAndName); + if (eFrameworkunifiedStatusOK != l_eStatus) { + FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, + " Error. GetEmmNaviLogDestination() returned %d.", + l_eStatus); + } else { + f_pathAndName.append("/"); + f_pathAndName.append(f_prefix); + f_pathAndName.append(GetEmmcNaviLogFilename(f_time)); + } + + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-"); + return (l_eStatus); +} +// LCOV_EXCL_STOP + +// LCOV_EXCL_START 200: +EFrameworkunifiedStatus CLoggerUtil::getEmmcNaviLogParams( + uint32_t f_time, EPWR_SHUTDOWN_TRIGGER_TYPE errorType, + std::string &f_pathName, UI_32 &f_logMax) { + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+"); + DIR *l_dirp = NULL; + EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK; + std::string l_prefix = ""; + + std::vector<std::string> l_vector; + std::string l_path = m_pCfg->getEmmcOutputNaviLogPath(); + + if ((errorType == epssdmsdtGENERIC_ERROR_RESET) + || (errorType == epssdmsdtFATAL_ERROR_RESET)) { + /*When reset occured !!*/ + f_logMax = m_pCfg->m_emmcOutputNaviLogErrMax; + l_prefix = "ERR_"; + } else { + /* ACC OFF occured*/ + f_logMax = m_pCfg->m_emmcOutputNaviLogNmlMax; + l_prefix = "NML_"; + } + + if (f_logMax == 0) { + l_eStatus = eFrameworkunifiedStatusOK; + return l_eStatus; + } + + l_dirp = opendir(l_path.c_str()); + if (l_dirp != NULL) { + struct dirent l_dirent; + struct dirent* next; + + while (0 == readdir_r(l_dirp, &l_dirent, &next) && next != NULL) { + std::string l_findFileName = l_dirent.d_name; + size_t l_find_pos_top = l_findFileName.find(l_prefix.c_str()); + size_t l_find_pos = l_findFileName.find(".log"); + if (std::string::npos != l_find_pos + && std::string::npos != l_find_pos_top) { + l_vector.push_back(l_findFileName); + } + } + closedir(l_dirp); + } + std::sort(l_vector.begin(), l_vector.end()); + + for (UI_32 i = static_cast<UI_32>(l_vector.size()); i != 0; i--) { + std::string l_FilePath = l_path; + std::string l_FileName = l_vector.at(i - 1); + l_FilePath.append("/"); + l_FilePath.append(l_FileName.c_str()); + + if (i < f_logMax) { + size_t l_pos = l_FileName.find("_", l_prefix.size()); + if (std::string::npos != l_pos) { + std::string l_renameFilePath = l_path; + std::stringstream l_numStream; + l_numStream << std::setw(5) << std::setfill('0') << std::right << std::dec << (i + 1); + l_renameFilePath.append("/"); + l_renameFilePath.append(l_prefix); + l_renameFilePath.append(l_numStream.str()); + l_renameFilePath.append(l_FileName, l_pos, (l_FileName.size() - l_pos)); + if (0 != rename(l_FilePath.c_str(), l_renameFilePath.c_str())) { + FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, " Error. rename navilog file %s:%d.", + l_FilePath.c_str(), errno); + } + } + } else { + if (0 != unlink(l_FilePath.c_str())) { + FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, " Error. delete navilog file %s:%d.", + l_FilePath.c_str(), errno); + } + } + } + // sync parent directory + SyncDir(l_path); + + l_eStatus = getNaviLogFilePathAndName(l_prefix, f_time, f_pathName); + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-"); + return l_eStatus; +} +// LCOV_EXCL_STOP + +// LCOV_EXCL_START 200: can not be called +size_t CLoggerUtil::deleteRequestLogs(std::string f_emmcpath, + ELOGGERSERVICELOGTYPE f_reqtype, size_t f_reqsize, + ELOGGERSERVICELOGTYPE f_deltype) { + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+"); + DIR* l_dirp = NULL; + std::vector<std::string> vect; + std::vector<std::string>::iterator it; + UI_32 l_count = 0; + size_t l_totalsize = 0; + + // create saved file list on eMMC + l_dirp = opendir(f_emmcpath.c_str()); + if (l_dirp != NULL) { + struct dirent l_dirent; + struct dirent* next; + while (0 == readdir_r(l_dirp, &l_dirent, &next) && next != NULL) { + std::string l_filename = l_dirent.d_name; + if (CLoggerUtil::QueryLoggerservicelogType(l_filename) == f_deltype) { + vect.push_back(l_filename); + } + } + closedir(l_dirp); + } else { + FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, " open failed eMMC path: %s", + f_emmcpath.c_str()); + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-"); + return 0; + } + + // get num of delete logs + std::sort(vect.begin(), vect.end()); + for (it = vect.begin(); it != vect.end(); it++) { + l_count++; + + std::string l_filename = *it; + struct stat st_buf; + std::string l_tmpstr = f_emmcpath; + l_tmpstr.append(l_filename.c_str()); + if (stat(l_tmpstr.c_str(), &st_buf) != -1) { + l_totalsize += st_buf.st_size; + } + + if (l_totalsize > f_reqsize) { + break; + } + } + + // start delete logs + if ((l_totalsize > f_reqsize) || (f_reqtype == eLoggerservicelogTypeAbnormal) + || (f_reqtype == eLoggerservicelogTypeGrpRelaunch)) { + for (it = vect.begin(); it != vect.end() && l_count > 0; it++) { + l_count--; + + std::string l_filename = *it; + std::string l_tmpstr = f_emmcpath; + l_tmpstr.append(l_filename.c_str()); + if (unlink(l_tmpstr.c_str()) != 0) { + FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, " unlink failed %s:%d.", + l_tmpstr.c_str(), errno); + } + FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__, " del-file=%s total=%d", l_tmpstr.c_str(), + l_totalsize); + } + SyncDir(f_emmcpath); + } else { + l_totalsize = 0; + FRAMEWORKUNIFIEDLOG( + ZONE_INFO, + __FUNCTION__, + " nothing to delete logs req-type=%d del-logtype=%d total=%d, log_count=%d", + f_reqtype, f_deltype, l_totalsize, l_count); + } + + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-"); + return l_totalsize; +} +// LCOV_EXCL_STOP + +// LCOV_EXCL_START 200: can not be called +EFrameworkunifiedStatus CLoggerUtil::forceDeleteOldLog(std::string f_archive_destination, + size_t f_req_size) { + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+"); + EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusFail; + std::string l_emmc_path; + size_t l_delsize = 0; + ELOGGERSERVICELOGTYPE l_logtype = eLoggerservicelogTypeOther; + + size_t l_pos = f_archive_destination.find_last_of('/'); + if (std::string::npos != l_pos) { + l_emmc_path = f_archive_destination.substr(0, l_pos); + l_emmc_path.append("/"); + l_logtype = CLoggerUtil::QueryLoggerservicelogType( + f_archive_destination.substr(l_pos + 1, + f_archive_destination.size() - l_pos + 1)); + } + + if (l_logtype == eLoggerservicelogTypeOther) { + // not found + FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, " Invalid Parameter. dest=%s", + f_archive_destination.c_str()); + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-"); + return eFrameworkunifiedStatusFail; + } + + // remove dirty-file if exist + if (unlink(f_archive_destination.c_str()) != 0) { + FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, " unlink failed %s:%d.", + f_archive_destination.c_str(), errno); + } + + // delete normal log + l_delsize = deleteRequestLogs(l_emmc_path, l_logtype, f_req_size, + eLoggerservicelogTypeNormal); + if (l_delsize >= f_req_size) { + FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__, + " delete normal logs success: req-size=%d, del-size=%d", f_req_size, + l_delsize); + l_eStatus = eFrameworkunifiedStatusOK; + } else if (l_logtype == eLoggerservicelogTypeAbnormal) { + // delete abnormal log if request type is abnormal + FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__, + " continue delete abnormal logs: req-size=%d, del-size=%d", + f_req_size, l_delsize); + size_t l_tmpsize = f_req_size; + l_tmpsize -= l_delsize; + l_delsize = deleteRequestLogs(l_emmc_path, l_logtype, l_tmpsize, + eLoggerservicelogTypeAbnormal); + if (l_delsize >= l_tmpsize) { + FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__, + " delete abnormal logs success: req-size=%d, del-size=%d", + f_req_size, l_delsize); + l_eStatus = eFrameworkunifiedStatusOK; + } else { + FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, + " abnormal log delete not complete. req-size=%d, del-size=%d", + f_req_size, l_delsize); + } + } else if (l_logtype == eLoggerservicelogTypeGrpRelaunch) { + FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__, + " continue delete group relaunch logs: req-size=%d, del-size=%d", + f_req_size, l_delsize); + size_t l_tmpsize = f_req_size; + l_tmpsize -= l_delsize; + l_delsize = deleteRequestLogs(l_emmc_path, l_logtype, l_tmpsize, + eLoggerservicelogTypeGrpRelaunch); + if (l_delsize >= l_tmpsize) { + FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__, + " delete group relaunch logs success: req-size=%d, del-size=%d", + f_req_size, l_delsize); + l_eStatus = eFrameworkunifiedStatusOK; + } else { + FRAMEWORKUNIFIEDLOG( + ZONE_ERR, __FUNCTION__, + " group relaunch log delete not complete. req-size=%d, del-size=%d", + f_req_size, l_delsize); + } + } else { + FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, + " normal log del not complete. req-size=%d, del-size=%d", f_req_size, + l_delsize); + } + + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-"); + return l_eStatus; +} +// LCOV_EXCL_STOP + +EFrameworkunifiedStatus CLoggerUtil::deleteOldLog(std::string log_path, + std::vector<std::string>& l_vector, + std::string& f_archive_destination, + UI_32 max_num) { + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+"); + EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK; + size_t l_pos = f_archive_destination.find_last_of('/'); + if (std::string::npos != l_pos) { // LCOV_EXCL_BR_LINE 200: there is always '/' in f_destination + std::sort(l_vector.begin(), l_vector.end()); + std::vector<std::string>::iterator itr = l_vector.begin(); + for (UI_32 i = static_cast<UI_32>(l_vector.size()); (max_num - 1) < i; i--, itr++) { + if (itr == l_vector.end()) { // LCOV_EXCL_BR_LINE 200: (max_num - 1) can not be -1. + break; + } + std::string l_FilePath = log_path; + std::string l_FileName = *itr; + l_FilePath.append("/"); + l_FilePath.append(l_FileName.c_str()); + if (0 != unlink(l_FilePath.c_str())) { + l_eStatus = eFrameworkunifiedStatusAccessError; + FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, " Error. delete old log file %s:%d.", + l_FilePath.c_str(), errno); + } + } + SyncDir(log_path); + } else { + // LCOV_EXCL_START 200: there is always '/' in f_destination + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + l_eStatus = eFrameworkunifiedStatusFail; + FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, " Error. delete target not found. %s", + f_archive_destination.c_str()); + // LCOV_EXCL_STOP + } + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-"); + return l_eStatus; +} + +EFrameworkunifiedStatus CLoggerUtil::deleteOldEmmcLog(std::string& f_archive_destination, + EErrorEventType type) { + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+"); + DIR *l_dirp = NULL; + std::vector<std::string> vect_abnrm; /* ILLEGAL RESET LOG INFO or ERROR EXIT LOG INFO */ + std::vector<std::string> vect_nrm; /* NORMAL LOG INFO */ + std::vector<std::string> vect_rlnc; /* RELAUNCH LOG INFO */ + std::string l_emmc_path = m_pCfg->getEmmcOutputPath(); + EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK; + + UI_32 abnrm_count = 0; + + l_dirp = opendir(l_emmc_path.c_str()); + if (l_dirp != NULL) { // LCOV_EXCL_BR_LINE 5: opendir's error case. + struct dirent l_dirent; + struct dirent* next; + while (0 == readdir_r(l_dirp, &l_dirent, &next) && next != NULL) { + std::string l_findFileName = l_dirent.d_name; + +// if ((std::string::npos != l_findFileName.find("_ILG_RESET.tar.gz")) +// || (std::string::npos != l_findFileName.find("_ERR.tar.gz"))) { +// vect_abnrm.push_back(l_findFileName); + if ((l_findFileName == ".") || (l_findFileName == "..")) { + continue; + } else if (std::string::npos != l_findFileName.find(SS_STORE_FILENAME_SYSILG_TERM)) { + vect_abnrm.push_back(l_findFileName); + } else if(std::string::npos != l_findFileName.find(SS_STORE_FILENAME__CWORD52__TERM)) { // LCOV_EXCL_BR_LINE 8: SS_STORE_FILENAME__CWORD52__TERM can not be set // NOLINT[whitespace/line_length] + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + vect_abnrm.push_back(l_findFileName); // LCOV_EXCL_LINE 8: SS_STORE_FILENAME_SYSILG_TERM can not be set // NOLINT[whitespace/line_length] + } else if((std::string::npos != l_findFileName.find("_ILG_RESET.tar.gz")) || + (std::string::npos != l_findFileName.find("_ERR.tar.gz"))) { + vect_abnrm.push_back(l_findFileName); + abnrm_count++; + + } else if (std::string::npos + != l_findFileName.find("_GRP_RELAUNCH.tar.gz")) { + vect_rlnc.push_back(l_findFileName); + } else if (std::string::npos != l_findFileName.find(".tar.gz")) { + vect_nrm.push_back(l_findFileName); + } + } + closedir(l_dirp); + } + + switch (type) { + case eErrorEventTypeProcessCrash: + case eErrorEventTypeProcessExit: + case eErrorEventTypeHeartBeatFailure: + case eErrorEventTypeSystemLowMemory: + case eErrorEventTypeBootMicroReset: + case eErrorEventTypeModConnFailed: + case eErrorEventTypeStartRespFailed: + case eErrorEventTypeModuleInvokedResetRequest: + +// if ((UI_32) m_pCfg->m_emmcOutputErrMax <= vect_abnrm.size()) { +// l_eStatus = deleteOldLog(l_emmc_path, vect_abnrm, f_archive_destination, +// (UI_32) m_pCfg->m_emmcOutputErrMax); + if ((UI_32)m_pCfg->m_emmcOutputErrMax <= abnrm_count) { + l_eStatus = SS_LoggerStoreLogs_deleteOldLogAbnrm(l_emmc_path, vect_abnrm, f_archive_destination, + (UI_32)m_pCfg->m_emmcOutputErrMax, abnrm_count); + + } + break; + case eErrorEventTypeGroupRelaunch: + if ((UI_32) m_pCfg->m_emmcOutputGrpRelaunchMax <= vect_rlnc.size()) { + l_eStatus = deleteOldLog(l_emmc_path, vect_rlnc, f_archive_destination, + (UI_32) m_pCfg->m_emmcOutputGrpRelaunchMax); + } + break; + default: + if ((UI_32) m_pCfg->m_emmcOutputMax <= vect_nrm.size()) { + l_eStatus = deleteOldLog(l_emmc_path, vect_nrm, f_archive_destination, + (UI_32) m_pCfg->m_emmcOutputMax); + } + break; + } + + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-"); + return l_eStatus; +} + +void CLoggerUtil::SetMilage(UI_32 f_Milage) { + m_Milage = f_Milage; +} + +std::string CLoggerUtil::GetUserInvokedFilename(HANDLE f_hApp, uint32_t f_time) { + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+"); + std::string l_ret = ""; + std::stringstream l_nameStream; + UI_32 l_seqNumber = 0; + + EFrameworkunifiedStatus l_eStatus = m_pCfg->GetIncrementAndPersistUserInvokedCounter( + f_hApp, l_seqNumber); + LOG_STATUS_IF_ERRORED( + l_eStatus, + "GetIncrementAndPersistUserInvokedCounter()"); + + /* new counter value was not persisted if l_eStatus != eFrameworkunifiedStatusOK */ + + l_nameStream << std::setw(5) << std::setfill('0') << std::right << std::dec << l_seqNumber << '_'; + l_nameStream << std::setw(8) << std::setfill('0') << std::right << std::dec << m_Milage << '_'; + l_nameStream << std::setw(5) << std::setfill('0') << std::right << std::dec << m_bootCount << '_'; + l_nameStream << std::setw(15) << GetTimeString(f_time) << ".tar.gz"; + + l_ret = l_nameStream.str(); + + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-"); + return (l_ret); +} + +std::string CLoggerUtil::GetEmmcFilename(uint32_t f_time) { + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+"); + std::string l_ret = ""; + std::stringstream l_nameStream; + UI_32 l_counter = 0; + + m_pCfg->GetAndIncrementEmmcCounter(l_counter); + l_nameStream << std::setw(5) << std::setfill('0') << std::right << std::dec << l_counter << '_'; + l_nameStream << std::setw(15) << this->GetTimeString(f_time) << ".tar.gz"; + + l_ret = l_nameStream.str(); + + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-"); + return (l_ret); +} + +// LCOV_EXCL_START 8: dead code +std::string CLoggerUtil::GetEmmcErrorFilename(uint32_t f_time) { + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+"); + std::string l_ret = ""; + std::stringstream l_nameStream; + UI_32 l_counter = 0; + + m_pCfg->GetAndIncrementEmmcCounter(l_counter); + l_nameStream << std::setw(5) << std::setfill('0') << std::right << std::dec << l_counter << '_'; + l_nameStream << std::setw(15) << this->GetTimeString(f_time) << "_ERR.tar.gz"; + + l_ret = l_nameStream.str(); + + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-"); + return (l_ret); +} +// LCOV_EXCL_STOP + +// LCOV_EXCL_START 13: +std::string CLoggerUtil::GetEmmcNaviLogFilename(uint32_t f_time) { + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+"); + std::string l_ret = ""; + std::stringstream l_nameStream; + UI_32 l_counter = 1; + + l_nameStream << std::setw(5) << std::setfill('0') << std::right << std::dec << l_counter << '_'; + l_nameStream << std::setw(15) << this->GetTimeString(f_time) << ".log"; + + l_ret = l_nameStream.str(); + + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-"); + return (l_ret); +} +// LCOV_EXCL_STOP + +std::string CLoggerUtil::GetTimeString(uint32_t f_time) { + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+"); + std::string l_ret = "00000000_000000"; + struct tm local_time; + Clock_getLocalTimeY2K38(&f_time, &local_time); + char buffer[20]; + if (0 + != strftime(buffer, sizeof(buffer), "%Y%m%d_%H%M%S", // LCOV_EXCL_BR_LINE 5: c code + &local_time)) { + l_ret = buffer; + } + + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-"); + return (l_ret); +} + +void CLoggerUtil::SetUsbMountPath(std::string usbpath) { + strncpy(m_usbpath, usbpath.c_str(), USB_PATH_SIZE - 1); + m_usbpath[USB_PATH_SIZE - 1] = '\0'; +} +#ifdef RELEASE_BUILD +EFrameworkunifiedStatus CLoggerUtil::PathCheckAndCopyFile(std::string f_source, + std::string f_destination) { + EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusFail; + std::string::size_type ret; + + ret = f_destination.find(m_usbpath); + l_eStatus = CopyFile(f_source, f_destination); + + return l_eStatus; +} +#endif // RELEASE_BUILD +///////////////////////////////////////////////////////////////////////// +///// Static Functions +///////////////////////////////////////////////////////////////////////// + +EFrameworkunifiedStatus CLoggerUtil::CopyFile(std::string f_source, + std::string f_destination) { + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+"); + EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK; + ssize_t l_nrd; + ssize_t l_nwr; + char l_buf[BUF_MAX_SIZE]; + + int l_if = open(f_source.c_str(), O_RDONLY | O_CLOEXEC, 0); + if (-1 == l_if) { // LCOV_EXCL_BR_LINE 5: open's error case. + // LCOV_EXCL_START 5: open's error case. + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "src open fail:%s,errno:%d,msg:%s", + f_source.c_str(), errno, strerror(errno)); + l_eStatus = eFrameworkunifiedStatusFail; + // LCOV_EXCL_STOP + } else { + bool isWebdav = false; + std::string l_tmpDest; + size_t l_pos = f_destination.find_last_of('/'); + + l_tmpDest = f_destination; + if (f_destination.find("/mnt/import") != std::string::npos) { // LCOV_EXCL_BR_LINE 13: + // if output to webdav's directory, don't create temporary file. + // because of being unable to rename the file on it. + isWebdav = true; + } + + int l_of = open(l_tmpDest.c_str(), O_WRONLY | O_CREAT | O_CLOEXEC, 0640); + if (-1 == l_of) { // LCOV_EXCL_BR_LINE 5: open's error case. + // LCOV_EXCL_START 5: open's error case. + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "dest open fail:%s,errno:%d,msg:%s", + l_tmpDest.c_str(), errno, strerror(errno)); + l_eStatus = eFrameworkunifiedStatusFail; + // LCOV_EXCL_STOP + } else { + do { + l_nrd = read(l_if, l_buf, sizeof(l_buf)); + if (l_nrd == -1) { // LCOV_EXCL_BR_LINE 5: read's error case. + // LCOV_EXCL_START 5: read's error case. + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "read fail:%s,errno:%d,msg:%s", + f_source.c_str(), errno, strerror(errno)); + l_eStatus = eFrameworkunifiedStatusAccessError; + break; + // LCOV_EXCL_STOP + } + + l_nwr = write(l_of, l_buf, l_nrd); + if (l_nwr == -1) { // LCOV_EXCL_BR_LINE 5: write's error case. + // LCOV_EXCL_START 5: write's error case. + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + if (ENOSPC == errno) { + FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, + "write fail(ENOSPC):%s,errno:%d,msg:%s", l_tmpDest.c_str(), + errno, strerror(errno)); + l_eStatus = eFrameworkunifiedStatusErrNoEAGAIN; + } else { + FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "write fail:%s,errno:%d,msg%s", + l_tmpDest.c_str(), errno, strerror(errno)); + l_eStatus = eFrameworkunifiedStatusAccessError; + } + break; + // LCOV_EXCL_STOP + } + } while (l_nrd > 0); + + fsync(l_of); + close(l_of); + + if (l_eStatus != eFrameworkunifiedStatusOK) { // LCOV_EXCL_BR_LINE 6: can not be fail + // LCOV_EXCL_START 6: can not be fail + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + close(l_if); + return l_eStatus; + // LCOV_EXCL_STOP + } + + { + struct stat istat_buf, ostat_buf; + int ret; + ret = fstat(l_if, &istat_buf); + if (ret < 0) { // LCOV_EXCL_BR_LINE 5: fstat's error case. + // LCOV_EXCL_START 5: fstat's error case. + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, " Error. stat(%s). errno: %d, %s", + f_source.c_str(), errno, strerror(errno)); + // LCOV_EXCL_STOP + } else { + while (1) { + ret = stat(l_tmpDest.c_str(), &ostat_buf); + if (ret < 0) { // LCOV_EXCL_BR_LINE 5: stat's error case. + // LCOV_EXCL_START 5: stat's error case. + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, " Error. stat(%s). errno: %d, %s", + l_tmpDest.c_str(), errno, strerror(errno)); + break; + // LCOV_EXCL_STOP + } + if (ostat_buf.st_size >= istat_buf.st_size) { // LCOV_EXCL_BR_LINE 5: read and write can not fail, so the size is same // NOLINT[whitespace/line_length] + break; + } + usleep(10000); // interval + } + } + } + } + close(l_if); + + if (!isWebdav) { // LCOV_EXCL_BR_LINE 6: isWebdav is aways false + if (rename(l_tmpDest.c_str(), f_destination.c_str()) != 0) { // LCOV_EXCL_BR_LINE 5: rename's error case. + // LCOV_EXCL_START 5: rename's error case. + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "rename %s to %s fail,errno:%d,msg:%s", + l_tmpDest.c_str(), f_destination.c_str(), errno, strerror(errno)); + // LCOV_EXCL_STOP + } + } + + if (std::string::npos != l_pos) { // LCOV_EXCL_BR_LINE 200: there is always '/' in f_destination + std::string l_destPath = f_destination.substr(0, l_pos); + SyncDir(l_destPath); + } else { + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "dest invalid:%s", f_destination.c_str()); // LCOV_EXCL_LINE 200: there is always '/' in f_destination // NOLINT[whitespace/line_length] + } + } + + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-"); + return (l_eStatus); +} + +// LCOV_EXCL_START 8: can not be called +EFrameworkunifiedStatus CLoggerUtil::CopyUntyped(std::string f_source, + std::string f_destination) { + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+"); + EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK; + struct stat l_stat; + int l_statRetVal; + if (0 != access(f_source.c_str(), F_OK)) { + FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, + " Error. The specified file path and name does not exist: %s", + f_source.c_str()); + } else if (0 != (l_statRetVal = lstat(f_source.c_str(), &l_stat))) { + FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, + " Error. stat() for file or directory returned error: %s -> %d", + f_source.c_str(), l_statRetVal); + } else if (0 != S_ISDIR(l_stat.st_mode)) { + l_eStatus = CopyDirectory(f_source, f_destination); + } else if (0 != S_ISLNK(l_stat.st_mode)) { + // avoid duplicate copy for eErrorEventTypeInterfaceunifiedEmmcLogs: /nv/log/awlog -> /nv/BS/ss/logger_service/rwdata/log2/awlog + if (f_source.find("/nv/BS/ss/logger_service/rwdata/awlog") == std::string::npos) { + l_eStatus = CopyDirectory(f_source, f_destination); + } + } else if (0 != S_ISREG(l_stat.st_mode)) { +#ifdef RELEASE_BUILD + l_eStatus = PathCheckAndCopyFile(f_source, f_destination); +#else + l_eStatus = CopyFile(f_source, f_destination); +#endif // RELEASE_BUILD + } else { + FRAMEWORKUNIFIEDLOG( + ZONE_ERR, + __FUNCTION__, + " Error. specified file may be a symbolic link or other non 'regular' type. File: %s, mode: 0x%04X.", + f_source.c_str(), l_stat.st_mode); + } + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-"); + return (l_eStatus); +} +// LCOV_EXCL_STOP + +// LCOV_EXCL_START 8: can not be called +EFrameworkunifiedStatus CLoggerUtil::CopyDirectory(std::string f_source, + std::string f_destination) { + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+"); + EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK; + DIR * l_pDir = opendir(f_source.c_str()); + + if (l_pDir == NULL) { + FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "Could not open directory: %s", + f_source.c_str()); + } else { + if (mkdir(f_destination.c_str(), 0775) == -1) { + if (errno == EEXIST) { + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "Directory: %s already exists.", + f_destination.c_str()); + } else { + FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, + "Could not create directory: %s. Errno: %s", + f_destination.c_str(), strerror(errno)); + l_eStatus = eFrameworkunifiedStatusFail; + } + } else { + SyncDir(f_destination); + size_t l_pos = f_destination.find_last_of('/'); + if (l_pos != std::string::npos) { + std::string l_destPath = f_destination.substr(0, l_pos); + SyncDir(l_destPath); + } + } + + struct dirent l_pDirent; + struct dirent* next; + while (0 == readdir_r(l_pDir, &l_pDirent, &next) && next != NULL) { + if ((0 != strcmp(l_pDirent.d_name, ".")) && /* Ignore special . directory. */ + (0 != strcmp(l_pDirent.d_name, "..")) && /* Ignore special .. directory. */ + (0 != strcmp(l_pDirent.d_name, "lost+found")) && /* Ignore lost+found. */ + ('.' != l_pDirent.d_name[0])) { /* Ignore hidden files */ + std::string l_fileSource = f_source; + std::string l_fileDestination = f_destination; + l_fileSource.append("/"); + l_fileSource.append(l_pDirent.d_name); + l_fileDestination.append("/"); + l_fileDestination.append(l_pDirent.d_name); + l_eStatus = CopyUntyped(l_fileSource, l_fileDestination); + } + } + + closedir(l_pDir); + } + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-"); + return (l_eStatus); +} +// LCOV_EXCL_STOP + +// LCOV_EXCL_START 8: can not be called +EFrameworkunifiedStatus CLoggerUtil::MoveFile(std::string f_source, + std::string f_destination) { + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+"); + EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK; +#ifdef RELEASE_BUILD + l_eStatus = CLoggerUtil::PathCheckAndCopyFile(f_source, f_destination); + LOG_STATUS_IF_ERRORED(l_eStatus, "CLoggerUtil::PathCheckAndCopyFile()"); +#else + l_eStatus = CLoggerUtil::CopyFile(f_source, f_destination); + LOG_STATUS_IF_ERRORED(l_eStatus, "CLoggerUtil::CopyFile()"); +#endif // RELEASE_BUILD + if (eFrameworkunifiedStatusOK == l_eStatus) { + l_eStatus = (0 == remove(f_source.c_str())) ? eFrameworkunifiedStatusOK : eFrameworkunifiedStatusFail; + if (l_eStatus == eFrameworkunifiedStatusOK) { + size_t l_pos = f_source.find_last_of('/'); + if (std::string::npos != l_pos) { + std::string l_emmc_path = f_source.substr(0, l_pos); + SyncDir(l_emmc_path); + } + } + } + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-"); + return (l_eStatus); +} +// LCOV_EXCL_STOP + +// LCOV_EXCL_START 8: can not be called +EFrameworkunifiedStatus CLoggerUtil::MoveUntyped(std::string f_source, + std::string f_destination) { + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+"); + EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusFail; + struct stat l_stat; + int l_statRetVal; + if (0 != access(f_source.c_str(), F_OK)) { + FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, + " Error. The specified file path and name does not exist: %s", + f_source.c_str()); + } else if (0 != (l_statRetVal = stat(f_source.c_str(), &l_stat))) { + FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, + " Error. stat() for file or directory returned error: %s -> %d", + f_source.c_str(), l_statRetVal); + } else if (0 != S_ISDIR(l_stat.st_mode)) { + l_eStatus = CLoggerUtil::MoveDirectory(f_source, f_destination); + LOG_STATUS_IF_ERRORED( + l_eStatus, "CLoggerUtil::MoveDirectory(f_source, f_destination);"); + } else if (0 != S_ISREG(l_stat.st_mode)) { + l_eStatus = CLoggerUtil::MoveFile(f_source, f_destination); + LOG_STATUS_IF_ERRORED(l_eStatus, + "CLoggerUtil::MoveFile(f_source, f_destination)"); + } else { + FRAMEWORKUNIFIEDLOG( + ZONE_ERR, + __FUNCTION__, + " Error. specified file may be a symbolic link or other non 'regular' type. File: %s, mode: 0x%04X.", + f_source.c_str(), l_stat.st_mode); + } + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-"); + return (l_eStatus); +} +// LCOV_EXCL_STOP + +// LCOV_EXCL_START 8: can not be called +EFrameworkunifiedStatus CLoggerUtil::MoveDirectory(std::string f_source, + std::string f_destination) { + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+"); + EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK; + DIR * l_pDir = opendir(f_source.c_str()); + + if (l_pDir == NULL) { + FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "Could not open directory: %s", + f_source.c_str()); + l_eStatus = eFrameworkunifiedStatusFail; + } else { + errno = 0; + if (mkdir(f_destination.c_str(), 0666) == -1) { + if (errno == EEXIST) { + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "Directory: %s already exists.", + f_destination.c_str()); + } else { + FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, + "Could not create directory: %s. Errno: %s", + f_destination.c_str(), strerror(errno)); + l_eStatus = eFrameworkunifiedStatusFail; + } + errno = 0; + } else { + SyncDir(f_destination); + size_t l_pos = f_destination.find_last_of('/'); + if (l_pos != std::string::npos) { + std::string l_destPath = f_destination.substr(0, l_pos); + SyncDir(l_destPath); + } + } + + if (eFrameworkunifiedStatusOK == l_eStatus) { /* if directory already exists or has been newly created */ + struct dirent l_pDirent; + struct dirent* next; + + while (0 == readdir_r(l_pDir, &l_pDirent, &next) && next != NULL) { + if ((0 != strcmp(l_pDirent.d_name, ".")) && /* Ignore special . directory. */ + (0 != strcmp(l_pDirent.d_name, "..")) && /* Ignore special .. directory. */ + (0 != strcmp(l_pDirent.d_name, "lost+found")) && /* Ignore lost+found. */ + ('.' != l_pDirent.d_name[0])) { /* Ignore hidden files */ + std::string l_fileSource = f_source; + std::string l_fileDestination = f_destination; + l_fileSource.append("/"); + l_fileSource.append(l_pDirent.d_name); + l_fileDestination.append("/"); + l_fileDestination.append(l_pDirent.d_name); + l_eStatus = MoveUntyped(l_fileSource, l_fileDestination); + } + } + } else { + } + closedir(l_pDir); + } + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-"); + return (l_eStatus); +} +// LCOV_EXCL_STOP + +// LCOV_EXCL_START 200: can not be called +ELOGGERSERVICELOGTYPE CLoggerUtil::QueryLoggerservicelogType(std::string f_logname) { + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert +// if (f_logname.find("_ILG_RESET.tar.gz") != std::string::npos + if (f_logname.find(SS_STORE_FILENAME_SYSILG_TERM) != std::string::npos) { + return eLoggerservicelogTypeAbnormal; + } else if (f_logname.find(SS_STORE_FILENAME__CWORD52__TERM) != std::string::npos) { + return eLoggerservicelogTypeAbnormal; + } else if (f_logname.find("_ILG_RESET.tar.gz") != std::string::npos + + || f_logname.find("_ERR.tar.gz") != std::string::npos) { + return eLoggerservicelogTypeAbnormal; + } else if (f_logname.find("_GRP_RELAUNCH.tar.gz") != std::string::npos) { + return eLoggerservicelogTypeGrpRelaunch; + } else if (f_logname.find(".tar.gz") != std::string::npos) { + return eLoggerservicelogTypeNormal; + } else { + return eLoggerservicelogTypeOther; + } +} +// LCOV_EXCL_STOP + +void CLoggerUtil::SyncDir(std::string f_dir_path) { + int fd = open(f_dir_path.c_str(), O_RDONLY | O_DIRECTORY | O_CLOEXEC); +#define OPE_ERR_MSG "%s %s failed. errno:%d,msg:%s" + if (fd == -1) { // LCOV_EXCL_BR_LINE 5: open's error case. + // LCOV_EXCL_START 5: open's error case. + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, OPE_ERR_MSG, f_dir_path.c_str(), "open", + errno, strerror(errno)); + // LCOV_EXCL_STOP + } else { + if (fsync(fd) == -1) { // LCOV_EXCL_BR_LINE 5: open's error case. + // LCOV_EXCL_START 5: open's error case. + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, OPE_ERR_MSG, f_dir_path.c_str(), "fsync", + errno, strerror(errno)); + // LCOV_EXCL_STOP + } + if (close(fd) == -1) { // LCOV_EXCL_BR_LINE 5: open's error case. + // LCOV_EXCL_START 5: open's error case. + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, OPE_ERR_MSG, f_dir_path.c_str(), "close", + errno, strerror(errno)); + // LCOV_EXCL_STOP + } + } +#undef OPE_ERR_MSG +} + diff --git a/systemservice/logger_service/server/src/testapps/fopen b/systemservice/logger_service/server/src/testapps/fopen new file mode 100755 index 0000000..e69de29 --- /dev/null +++ b/systemservice/logger_service/server/src/testapps/fopen diff --git a/systemservice/logger_service/server/src/testapps/testapps.log b/systemservice/logger_service/server/src/testapps/testapps.log new file mode 100755 index 0000000..e69de29 --- /dev/null +++ b/systemservice/logger_service/server/src/testapps/testapps.log diff --git a/systemservice/logger_service/server/src/testapps/testapps.tar.gz b/systemservice/logger_service/server/src/testapps/testapps.tar.gz new file mode 100755 index 0000000..e69de29 --- /dev/null +++ b/systemservice/logger_service/server/src/testapps/testapps.tar.gz diff --git a/systemservice/logger_service/server/src/udp_file_writer.cpp b/systemservice/logger_service/server/src/udp_file_writer.cpp new file mode 100755 index 0000000..c07db07 --- /dev/null +++ b/systemservice/logger_service/server/src/udp_file_writer.cpp @@ -0,0 +1,161 @@ +/* + * @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_SS_LoggerService +/// \brief TODO +/// +/////////////////////////////////////////////////////////////////////////////// +#include "readerWriter/writer/udp_file_writer.h" +#include "readerWriter/writer/file_writer.h" +#include "readerWriter/writer/cached_file_writer.h" + +namespace ReaderWriter { + +// LCOV_EXCL_START 8:dead code +CUdpFileWriter::CUdpFileWriter() + : m_pUdpWriter(NULL), + m_pFileWriter(NULL), + m_pLoggerCfg(NULL), + m_ipAddress(""), + m_port(0), + m_FileName(""), + m_FileSize(0) { + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert +} +// LCOV_EXCL_STOP + +CUdpFileWriter::~CUdpFileWriter() { // LCOV_EXCL_START 8:dead code + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + if (this->m_pFileWriter != NULL) { + delete (this->m_pFileWriter); + this->m_pFileWriter = NULL; + } + if (this->m_pUdpWriter != NULL) { + delete (this->m_pUdpWriter); + this->m_pUdpWriter = NULL; + } +} +// LCOV_EXCL_STOP + +// LCOV_EXCL_START 8:dead code +EFrameworkunifiedStatus CUdpFileWriter::Initialize(CLoggerCfg* f_pLoggerCfg, + std::string f_Name1, UI_32 f_size1, + std::string f_Name2, UI_32 f_size2) { + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusFail; + if ((NULL == this->m_pFileWriter) && (NULL == this->m_pUdpWriter) + && (NULL != f_pLoggerCfg)) { + this->m_pFileWriter = new (std::nothrow) CCachedFileWriter(); + this->m_pUdpWriter = new (std::nothrow) CUdpWriter(); + m_pLoggerCfg = f_pLoggerCfg; + m_ipAddress = f_Name2; + m_port = f_size2; + m_FileName = f_Name1; + m_FileSize = f_size1; + EFrameworkunifiedStatus l_eStatus1 = this->m_pUdpWriter->Initialize(m_pLoggerCfg, + m_ipAddress, m_port, + "", 0); + EFrameworkunifiedStatus l_eStatus2 = this->m_pFileWriter->Initialize(m_pLoggerCfg, + m_FileName, + m_FileSize, "", 0); + l_eStatus = + ((l_eStatus1 != eFrameworkunifiedStatusOK) || (eFrameworkunifiedStatusOK != l_eStatus2)) ? + eFrameworkunifiedStatusFail : eFrameworkunifiedStatusOK; + if (l_eStatus == eFrameworkunifiedStatusOK) { + l_eStatus = this->Open(); + } + } else { + l_eStatus = eFrameworkunifiedStatusNullPointer; + } + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-: %d", l_eStatus); + return (l_eStatus); +} +// LCOV_EXCL_STOP + +EFrameworkunifiedStatus CUdpFileWriter::Open(void) { // LCOV_EXCL_START 8:dead code + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusFail; + if ((NULL != this->m_pFileWriter) && (NULL != this->m_pUdpWriter)) { + EFrameworkunifiedStatus l_eStatus1 = this->m_pUdpWriter->Open(); + EFrameworkunifiedStatus l_eStatus2 = this->m_pFileWriter->Open(); + l_eStatus = + ((l_eStatus1 != eFrameworkunifiedStatusOK) || (eFrameworkunifiedStatusOK != l_eStatus2)) ? + eFrameworkunifiedStatusFail : eFrameworkunifiedStatusOK; + } + + return (l_eStatus); +} +// LCOV_EXCL_STOP + +BOOL CUdpFileWriter::IsOpen(void) { // LCOV_EXCL_START 8:dead code + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + BOOL l_ret = FALSE; + if ((this->m_pUdpWriter != NULL) && (this->m_pFileWriter != NULL)) { + l_ret = (m_pUdpWriter->IsOpen() && m_pFileWriter->IsOpen()); + } + return l_ret; +} +// LCOV_EXCL_STOP + +// LCOV_EXCL_START 8:dead code +EFrameworkunifiedStatus CUdpFileWriter::Write(UI_8* f_data, UI_32 f_length, + SI_32& f_bytesWritten) { + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK; + if ((NULL != this->m_pUdpWriter)) { + l_eStatus = this->m_pUdpWriter->Write(f_data, f_length, f_bytesWritten); + LOG_STATUS_IF_ERRORED(l_eStatus, "this->m_pUdpWriter->Write() failed."); + } + + if ((NULL != this->m_pFileWriter)) { + l_eStatus = this->m_pFileWriter->Write(f_data, f_length, f_bytesWritten); + LOG_STATUS_IF_ERRORED(l_eStatus, "this->m_pFileWriter->Write() failed."); + } else { + l_eStatus = eFrameworkunifiedStatusFail; + } + return (l_eStatus); +} +// LCOV_EXCL_STOP + +void CUdpFileWriter::Close() { // LCOV_EXCL_START 8:dead code + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + if (this->m_pFileWriter != NULL) { + this->m_pFileWriter->Close(); + delete (this->m_pFileWriter); + this->m_pFileWriter = NULL; + } + if (this->m_pUdpWriter != NULL) { + this->m_pUdpWriter->Close(); + delete (this->m_pUdpWriter); + this->m_pUdpWriter = NULL; + } +} +// LCOV_EXCL_STOP + +EFrameworkunifiedStatus CUdpFileWriter::FlushCache(void) { // LCOV_EXCL_START 8:dead code + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + return (this->m_pFileWriter->FlushCache()); +} +// LCOV_EXCL_STOP + +EFrameworkunifiedStatus CUdpFileWriter::UpdateLoggingParameters(void) { // LCOV_EXCL_START 8:dead code + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + return (this->m_pUdpWriter->UpdateLoggingParameters()); +} +} // namespace ReaderWriter + +// LCOV_EXCL_STOP diff --git a/systemservice/logger_service/server/src/udp_writer.cpp b/systemservice/logger_service/server/src/udp_writer.cpp new file mode 100755 index 0000000..8fc4d84 --- /dev/null +++ b/systemservice/logger_service/server/src/udp_writer.cpp @@ -0,0 +1,295 @@ +/* + * @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_SS_LoggerService +/// \brief TODO +/// +/////////////////////////////////////////////////////////////////////////////// +#include "readerWriter/writer/udp_writer.h" +#include <sys/socket.h> +#include <arpa/inet.h> +#include <errno.h> +#include <string.h> +#include <inttypes.h> +#ifdef AGL_STUB +#include <other_service/PosixBasedOS001ClockCycleApi.h> +#else +#include <sys/syspage.h> +#include <sys/neutrino.h> +#endif +#include <native_service/ns_logger_if.h> +#include <string> +#include <algorithm> + +#define TIME_UNTIL_UDP_START (UI_32)25 + +namespace ReaderWriter { + +CUdpWriter::CUdpWriter() + : m_SocketHandle(-1), + m_IPAddress(""), + m_index(0), + m_port(REMOTE_IP_PORT), + m_InitialTimeElapsed(FALSE) { + std::memset(&m_oSAInfo, 0, sizeof(sockaddr_in)); + std::memset(&m_buffer[0], 0, UDP_CACHED_BLOCK_SIZE); +} + +CUdpWriter::~CUdpWriter() { + if (m_SocketHandle != -1) { + this->Close(); + } +} + +EFrameworkunifiedStatus CUdpWriter::Initialize(CLoggerCfg* f_pLoggerCfg, std::string f_Name1, + UI_32 f_size1, std::string f_Name2, + UI_32 f_size2) { + EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK; + this->m_pLoggerCfg = f_pLoggerCfg; + this->m_IPAddress = f_Name1; + if (NULL == f_pLoggerCfg) { // LCOV_EXCL_BR_LINE 200: f_pLoggerCfg can not be null + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + l_eStatus = eFrameworkunifiedStatusNullPointer; // LCOV_EXCL_LINE 200: f_pLoggerCfg can not be null + } else if ((f_pLoggerCfg->IsUDPLoggingEnabled())) { + if (m_IPAddress.length() > 0) { + this->m_port = f_size1; + l_eStatus = this->Open(); + LOG_STATUS_IF_ERRORED( + l_eStatus, + "this->Open() failed. UDP logging disabled. Enable via Engineering Menu."); + // Continue without UDP Logging; + l_eStatus = eFrameworkunifiedStatusOK; + } else { + l_eStatus = eFrameworkunifiedStatusInvldParam; + } + } else { + this->m_SocketHandle = -1; + } + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-: %d", l_eStatus); + return (l_eStatus); +} + +BOOL CUdpWriter::IsOpen(void) { + BOOL l_ret = (-1 != m_SocketHandle) ? TRUE : FALSE; + if (TRUE == l_ret) { +#ifdef AGL_STUB + UI_32 l_elapsed = ((UI_32)((F_64)ClockCycle()/1000000)); +#else + UI_32 l_elapsed = ((UI_32) ((F_64) ClockCycle() + / (F_64) (SYSPAGE_ENTRY(qtime)->cycles_per_sec))); +#endif + // check if 20 Seconds have elapsed since startup + if (TIME_UNTIL_UDP_START <= l_elapsed) { + FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__, + "%d seconds elapsed. Starting UDP logging", l_elapsed); + m_InitialTimeElapsed = TRUE; + l_ret = TRUE; + + } else { + FRAMEWORKUNIFIEDLOG( + ZONE_INFO, + __FUNCTION__, + "Time before starting UDP not yet elapsed. Waiting for %d more seconds", + (TIME_UNTIL_UDP_START - l_elapsed)); + usleep((TIME_UNTIL_UDP_START - l_elapsed)*1000); + FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__, "Starting UDP now!"); + } + } + return l_ret; +} + +EFrameworkunifiedStatus CUdpWriter::Open() { + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+"); + EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusFail; + if ((m_IPAddress.length() > 0)) { + int l_SocketOption = 1; + // Set the domain using the classes domain value. + m_oSAInfo.sin_family = AF_INET; + m_oSAInfo.sin_addr.s_addr = inet_addr(OWN_ADDRESS); // m_IPAddress.c_str()); // "192.168.1.2");//htonl(INADDR_ANY); + m_oSAInfo.sin_port = htons(this->m_port); + if (FALSE == this->m_pLoggerCfg->IsUDPLoggingEnabled()) { + this->Close(); + l_eStatus = eFrameworkunifiedStatusFail; + } else if (this->m_SocketHandle != -1) { + FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__, + " Info. socket already opened. No action required"); + l_eStatus = eFrameworkunifiedStatusOK; + } else if (-1 == (this->m_SocketHandle = socket(AF_INET, SOCK_DGRAM, 0))) { + FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, + " Error. socket(AF_INET, SOCK_DGRAM, 0) returned -1. errno: %s", + strerror(errno)); + errno = 0; + l_eStatus = eFrameworkunifiedStatusDbExecuteFail; + } else if (setsockopt(m_SocketHandle, SOL_SOCKET, SO_REUSEADDR, + &l_SocketOption, sizeof(l_SocketOption)) == -1) { + FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, + "setsockopt(SO_REUSEADDR) failed.errno: %s", strerror(errno)); + errno = 0; + l_eStatus = eFrameworkunifiedStatusDbResultError; + } +#ifdef AGL_STUB + else if (setsockopt(m_SocketHandle, SOL_SOCKET, SO_REUSEADDR , // LCOV_EXCL_BR_LINE 6: the same calls will get the same return // NOLINT (readability/braces) + &l_SocketOption, sizeof(l_SocketOption)) == -1) +#else + else if (setsockopt(m_SocketHandle, SOL_SOCKET, SO_REUSEPORT, // NOLINT (readability/braces) + &l_SocketOption, sizeof(l_SocketOption)) == -1) +#endif + { + FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, + "setsockopt(SO_REUSEPORT) failed. errno: %s", strerror(errno)); + errno = 0; + l_eStatus = eFrameworkunifiedStatusDbResultError; + } else if (setsockopt(m_SocketHandle, SOL_SOCKET, SO_DONTROUTE, + &l_SocketOption, sizeof(l_SocketOption)) == -1) { + FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, + "setsockopt(SO_DONTROUTE) failed. errno: %s", strerror(errno)); + errno = 0; + l_eStatus = eFrameworkunifiedStatusDbResultError; + } else if (INADDR_NONE == m_oSAInfo.sin_addr.s_addr) { + FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, " Error. Invalid local address."); + l_eStatus = eFrameworkunifiedStatusDbRecNotFound; + } else if (0 + != bind(this->m_SocketHandle, (const struct sockaddr *) &m_oSAInfo, + sizeof(m_oSAInfo))) { + FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, + " Error. bind() returned not zero. errno: %s", strerror(errno)); + errno = 0; + l_eStatus = eFrameworkunifiedStatusSemUnlockFail; + } else { + m_oSAInfo.sin_addr.s_addr = inet_addr(m_IPAddress.c_str()); + if (INADDR_NONE == m_oSAInfo.sin_addr.s_addr) { + FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, " Error. Invalid target address."); + l_eStatus = eFrameworkunifiedStatusFault; + } else { + l_eStatus = eFrameworkunifiedStatusOK; + } + } + + if (eFrameworkunifiedStatusOK != l_eStatus) { + this->Close(); + m_SocketHandle = -1; + } + } + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "- : %d", l_eStatus); + return (l_eStatus); +} + +EFrameworkunifiedStatus CUdpWriter::WriteData(UI_8 *f_data, UI_32 f_length, + SI_32 &f_bytesWritten) { + EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK; + UI_8 l_retry = SEND_RETRY_VALUE; + if (this->m_SocketHandle == -1) { + l_eStatus = eFrameworkunifiedStatusInvldParam; + } else { + while ((0 != l_retry) + && ((f_bytesWritten >= 0) && ((UI_32) f_bytesWritten != f_length))) { + SI_32 l_bytesWritten = (SI_32)(sendto(m_SocketHandle, &f_data[f_bytesWritten], + f_length - f_bytesWritten, 0, + (const struct sockaddr *) &m_oSAInfo, + sizeof(m_oSAInfo))); + f_bytesWritten += l_bytesWritten; + l_eStatus = (l_bytesWritten >= 0) ? eFrameworkunifiedStatusOK : eFrameworkunifiedStatusFail; + if (eFrameworkunifiedStatusOK != l_eStatus) { + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "l_retry: %d, errno: %s", l_retry, + strerror(errno)); + errno = 0; + l_retry--; + usleep(100); + } else { + l_retry = SEND_RETRY_VALUE; + } + } + } + return (l_eStatus); +} + +EFrameworkunifiedStatus CUdpWriter::Write(UI_8* f_data, UI_32 f_length, + SI_32& f_bytesWritten) { + EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK; + f_bytesWritten = 0; + if ((f_data == NULL)) { + l_eStatus = eFrameworkunifiedStatusNullPointer; + } else if ((-1 == m_SocketHandle)) { + l_eStatus = eFrameworkunifiedStatusFail; + } + + if (eFrameworkunifiedStatusOK == l_eStatus) { + if (f_length > UDP_MAX_LENGTH) { + FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, " Error. Possible memory corruption."); + FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, " Error. Length(%d) bigger than cache. ", + f_length); + } else { + UI_32 l_remainingIndex = 0; + + while (l_remainingIndex != f_length) { + UI_32 l_offset = (UDP_CACHED_BLOCK_SIZE - this->m_index); + l_offset = std::min(l_offset, (f_length - l_remainingIndex)); + (void) std::memcpy(&this->m_buffer[this->m_index], + &f_data[l_remainingIndex], l_offset); + l_remainingIndex += l_offset; + this->m_index += l_offset; + if (this->m_index == UDP_CACHED_BLOCK_SIZE) { + (void) this->FlushCache(); + this->m_index = 0; + } + } + f_bytesWritten = f_length; + } + } + return (l_eStatus); +} +void CUdpWriter::Close() { + if (m_SocketHandle != -1) { + (void) close(m_SocketHandle); + m_SocketHandle = -1; + } +} + +EFrameworkunifiedStatus CUdpWriter::UpdateLoggingParameters(void) { + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+"); + EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK; + if (this->m_pLoggerCfg != NULL) { + BOOL l_enabled = this->m_pLoggerCfg->IsUDPLoggingEnabled(); + if ((TRUE == l_enabled) && (m_SocketHandle == -1)) { + FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__, " Info. Opening UDP."); + l_eStatus = this->Open(); + } else if (((FALSE == l_enabled) && (m_SocketHandle != -1))) { + FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__, " Info. Closing UDP."); + l_eStatus = eFrameworkunifiedStatusOK; + this->Close(); + } else { + } + } + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "- :%d", l_eStatus); + return (l_eStatus); +} + +EFrameworkunifiedStatus CUdpWriter::FlushCache(void) { + EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK; + SI_32 l_written = 0; + SI_32 l_writtenTotal = 0; + while (((l_writtenTotal >= 0) && ((UI_32) l_writtenTotal < this->m_index)) + && (eFrameworkunifiedStatusOK == l_eStatus)) { + l_eStatus = this->WriteData(&this->m_buffer[l_writtenTotal], + this->m_index - l_writtenTotal, l_written); + l_writtenTotal += l_written; + l_written = 0; + } + this->m_index = 0; + return l_eStatus; +} +} // namespace ReaderWriter diff --git a/systemservice/logger_service/server/src/writer.cpp b/systemservice/logger_service/server/src/writer.cpp new file mode 100755 index 0000000..907b202 --- /dev/null +++ b/systemservice/logger_service/server/src/writer.cpp @@ -0,0 +1,86 @@ +/* + * @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_SS_LoggerService +/// \brief TODO +/// +/////////////////////////////////////////////////////////////////////////////// +#include <string> +#include <new> +#include <iostream> +#include "readerWriter/writer/writer.h" +#include "readerWriter/writer/file_writer.h" +#include "readerWriter/writer/udp_writer.h" +#include "readerWriter/writer/udp_file_writer.h" +#include "readerWriter/writer/cached_file_writer.h" + +namespace ReaderWriter { + +CWriter::CWriter() + : m_pLoggerCfg(NULL) { +} + +CWriter::~CWriter() { +} + +CWriter* CWriter::OpenWriter(CLoggerCfg* f_pLoggerCfg, EReaderType f_type, + std::string f_Name1, UI_32 f_size1, + std::string f_Name2, UI_32 f_size2) { + CWriter* l_ret = NULL; + if ((f_Name1.length() != 0) && (f_pLoggerCfg != NULL)) { // LCOV_EXCL_BR_LINE 200:As it is always TRUE + switch (f_type) {// LCOV_EXCL_BR_LINE 200:As it must be eReaderWriterTypeQueue or eReaderWriterTypeMem + case eReaderWriterTypeFile: + l_ret = new (std::nothrow) CCachedFileWriter(); // LCOV_EXCL_BR_LINE 5:Cannot pass because it cannot be new + break; + + case eReaderWriterTypeUdp: + l_ret = new (std::nothrow) CUdpWriter(); // LCOV_EXCL_BR_LINE 5:Cannot pass because it cannot be new + break; + case eReaderWriterTypeUdpAndFile: // LCOV_EXCL_START 8:dead code + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + if (f_Name2.length() != 0) { + l_ret = new (std::nothrow) CUdpFileWriter(); + } + // LCOV_EXCL_STOP + default: + break; + } + } + if (NULL != l_ret) { // LCOV_EXCL_BR_LINE 200:As it is not always NULL + if (eFrameworkunifiedStatusOK != l_ret->Initialize(f_pLoggerCfg, f_Name1, f_size1, f_Name2, f_size2)) { + FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "Open Writer Failed"); + delete (l_ret); + l_ret = NULL; + } + } + + return l_ret; +} + +EFrameworkunifiedStatus CWriter::FlushCache(void) { // LCOV_EXCL_START 8:Base class virtual functions + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "Default function called!"); + return (eFrameworkunifiedStatusOK); +} +// LCOV_EXCL_STOP + +EFrameworkunifiedStatus CWriter::UpdateLoggingParameters(void) { + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "Default function called!"); + return (eFrameworkunifiedStatusOK); +} +} // namespace ReaderWriter + |