diff options
author | 2020-11-19 12:45:32 +0900 | |
---|---|---|
committer | 2020-11-19 12:45:32 +0900 | |
commit | 8e0e00d21146a84c18f9cf9409e187b4fb0248aa (patch) | |
tree | ef791689dad216ac61091a1d1bd3b928d563aba6 /video_in_hal/systemservice/system_manager/server/src | |
parent | 18df6e21c6743a137e2760c52ca89d0789e90417 (diff) |
Init basesystem source codes.
Signed-off-by: Riku Nomoto <riku_nomoto@mail.toyota.co.jp>
Change-Id: I55aa2f1406ce7f751ae14140b613b53b68995528
Diffstat (limited to 'video_in_hal/systemservice/system_manager/server/src')
17 files changed, 14256 insertions, 0 deletions
diff --git a/video_in_hal/systemservice/system_manager/server/src/heartbeat/ss_hb_if.cpp b/video_in_hal/systemservice/system_manager/server/src/heartbeat/ss_hb_if.cpp new file mode 100755 index 0000000..a3c2777 --- /dev/null +++ b/video_in_hal/systemservice/system_manager/server/src/heartbeat/ss_hb_if.cpp @@ -0,0 +1,201 @@ +/* + * @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_SystemManager +/// \brief This file provides support for the application heartbeat system. +/// +/////////////////////////////////////////////////////////////////////////////// +#include <native_service/frameworkunified_application.h> +#include <native_service/frameworkunified_framework_if.h> +#include <native_service/frameworkunified_service_protocol.h> +#include <ss_hb_thread.h> +#include <system_service/ss_sm_client_if.h> +#include <system_service/ss_heartbeat_notifications.h> +#include <system_service/ss_heartbeat_service_protocol.h> +#include <system_service/ss_templates.h> +#include <new> +#include "ss_sm_systemmanagerlog.h" + +template<typename C, eFrameworkunifiedStatus (C::*M)(HANDLE)> EFrameworkunifiedStatus HBThreadCallback(HANDLE hThread) { + EFrameworkunifiedStatus eStatus = eFrameworkunifiedStatusNullPointer; + C * pObj = static_cast<C *>(FrameworkunifiedGetThreadSpecificData(hThread)); + if (pObj) { // LCOV_EXCL_BR_LINE 4:pObj must not be NULL + eStatus = (pObj->*M)(hThread); + } + return eStatus; +} + +static VOID DeletePObj(CHeartBeatThread * pObj) { // LCOV_EXCL_START 8: dead code + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + delete pObj; +} +// LCOV_EXCL_STOP + +static VOID DeleteHBTimer(CHeartBeatThread * pObj) { // LCOV_EXCL_START 8: dead code + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + EFrameworkunifiedStatus l_eStatus = pObj->HeartBeatTimersDelete(); + LOG_STATUS_IF_ERRORED(l_eStatus, "pObj->HeartBeatTimersDelete()"); +} +// LCOV_EXCL_STOP + +#define DetachParentCbThreadProtocols(hThread, handler) \ +{ \ + EFrameworkunifiedStatus l_eStatus = DetachParentCallbacksFromInterfaceunifiedDispatcher( \ + hThread, \ + handler, \ + static_cast<UI_32>(_countof(handler))); \ + LOG_STATUS_IF_ERRORED(l_eStatus, "DetachParentCallbacksFromInterfaceunifiedDispatcher()") \ +} + +#define DetachCbProtocols(hThread, f_pStr, f_protocolHandlers, hSession) \ +{ \ + EFrameworkunifiedStatus l_eStatus = \ + DetachCallbacksFromInterfaceunifiedDispatcher( \ + hThread, \ + f_pStr, \ + f_protocolHandlers, \ + static_cast<UI_32>(_countof(f_protocolHandlers)), \ + hSession); \ + LOG_STATUS_IF_ERRORED(l_eStatus, "DetachCallbacksFromInterfaceunifiedDispatcher()") \ +} + +/*****************************************************************************/ +/** + @ingroup: SS_SystemManager + @brief: HBThreadStart: function would be called at the time of starting of the thread + @note: . + @param HANDLE - Handle to message queue of HeartBeat Service. + @return EFrameworkunifiedStatus + */ +/*****************************************************************************/ +EFrameworkunifiedStatus HBThreadStart(HANDLE hThread) { + EFrameworkunifiedStatus l_eStatus; + FRAMEWORKUNIFIEDLOG0(ZONE_FUNC, __FUNCTION__, "+"); + + FrameworkunifiedProtocolCallbackHandler HBThreadCommonHandlers[] = { + // Command ID, Call back functions + { SS_HEARTBEAT_RESPONSE, HBThreadCallback<CHeartBeatThread, &CHeartBeatThread::HBOnClientResponse> }, + { SS_HEARTBEAT_PRINT_CONNECTIONS, HBThreadCallback<CHeartBeatThread, &CHeartBeatThread::HBOnPrintConnections> }, + { SS_HEARTBEAT_PRINT_STACK, HBThreadCallback<CHeartBeatThread, &CHeartBeatThread::HBOnPrintStack> } }; // LCOV_EXCL_BR_LINE 11:unexpected branch // NOLINT(whitespace/line_length) + + FrameworkunifiedProtocolCallbackHandler HBThreadProtocolHandlers[] = { + // Command ID, Call back functions + { SS_HEARTBEAT_START, HBThreadCallback<CHeartBeatThread, &CHeartBeatThread::HBOnStartThread> }, + { SS_HEARTBEAT_STOP, HBThreadCallback<CHeartBeatThread, &CHeartBeatThread::HBOnStopThread> }, + { SS_HEARTBEAT_DELETE_MODULE_ENTRY, HBThreadCallback<CHeartBeatThread, &CHeartBeatThread::HBOnRemoveModule> }, + { SS_HEARTBEAT_APPEND_MODULE_ENTRY, HBThreadCallback<CHeartBeatThread, &CHeartBeatThread::HBOnAppendModule> }, + { SS_HEARTBEAT_PERIODIC_STATUS_REQ, HBThreadCallback<CHeartBeatThread, + &CHeartBeatThread::HBOnPeriodicStatusRequest> }, + { SS_HEARTBEAT_AVAIL_CHECK_REQ, HBThreadCallback<CHeartBeatThread, &CHeartBeatThread::HBOnAvailCheckRequest> } + }; // LCOV_EXCL_BR_LINE 11:unexpected branch // NOLINT(whitespace/line_length) + + CHeartBeatThread * pObj = new (std::nothrow) CHeartBeatThread(hThread); // LCOV_EXCL_BR_LINE 11:unexpected branch // NOLINT(whitespace/line_length) + if (NULL == pObj) { // LCOV_EXCL_BR_LINE 5: Standard lib + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + l_eStatus = eFrameworkunifiedStatusNullPointer; // LCOV_EXCL_LINE 5: Standard lib + LOG_ERROR("new(std::nothrow) CHeartBeatThread(hThread)"); // LCOV_EXCL_LINE 5: Standard lib + // LCOV_EXCL_BR_START 6:always return eFrameworkunifiedStatusOK + } else if (eFrameworkunifiedStatusOK != (l_eStatus = pObj->HeartBeatTimerInit(hThread))) { + // LCOV_EXCL_BR_STOP + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + LOG_ERROR("pObj->HeartBeatTimerInit(hThread)"); // LCOV_EXCL_LINE 6:always return eFrameworkunifiedStatusOK + DeletePObj(pObj); // LCOV_EXCL_LINE 6:always return eFrameworkunifiedStatusOK + // LCOV_EXCL_BR_START 4: NSFW error case. + } else if (eFrameworkunifiedStatusOK != (l_eStatus = FrameworkunifiedAttachParentCallbacksToDispatcher(hThread, + HBThreadProtocolHandlers, static_cast<UI_32>(_countof(HBThreadProtocolHandlers))))) { + // LCOV_EXCL_BR_STOP + // LCOV_EXCL_START 4: NSFW error case. + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + LOG_ERROR("FrameworkunifiedAttachParentCallbacksToDispatcher(HBThreadProtocolHandlers)"); + DeleteHBTimer(pObj); + DeletePObj(pObj); + // LCOV_EXCL_STOP + // LCOV_EXCL_BR_START 4: NSFW error case. + } else if (eFrameworkunifiedStatusOK != (l_eStatus = FrameworkunifiedAttachParentCallbacksToDispatcher(hThread, + HBThreadCommonHandlers, static_cast<UI_32>(_countof(HBThreadCommonHandlers))))) { + // LCOV_EXCL_BR_STOP + // LCOV_EXCL_START 4: NSFW error case. + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + LOG_ERROR("FrameworkunifiedAttachParentCallbacksToDispatcher(HBThreadCommonHandlers)"); + DetachParentCbThreadProtocols(hThread, HBThreadProtocolHandlers); + DeleteHBTimer(pObj); + DeletePObj(pObj); + // LCOV_EXCL_STOP + } else if (eFrameworkunifiedStatusOK != (l_eStatus = FrameworkunifiedAttachCallbacksToDispatcher(hThread, FRAMEWORKUNIFIED_ANY_SOURCE, HBThreadCommonHandlers, static_cast<UI_32>(_countof(HBThreadCommonHandlers)), NULL))) { // 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 + LOG_ERROR("FrameworkunifiedAttachCallbacksToDispatcher(" + "FRAMEWORKUNIFIED_ANY_SOURCE, HBThreadCommonHandlers)"); + DetachParentCbThreadProtocols(hThread, HBThreadCommonHandlers); + DetachParentCbThreadProtocols(hThread, HBThreadProtocolHandlers); + DeleteHBTimer(pObj); + DeletePObj(pObj); + // LCOV_EXCL_STOP + } else { + l_eStatus = FrameworkunifiedSetThreadSpecificData(hThread, pObj); // LCOV_EXCL_BR_LINE 11:unexpected branch // NOLINT(whitespace/line_length) + 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 + LOG_ERROR("FrameworkunifiedSetThreadSpecificData(hThread, pObj)"); + DetachCbProtocols(hThread, FRAMEWORKUNIFIED_ANY_SOURCE, HBThreadCommonHandlers, + NULL); + DetachParentCbThreadProtocols(hThread, HBThreadCommonHandlers); + DetachParentCbThreadProtocols(hThread, HBThreadProtocolHandlers); + DeleteHBTimer(pObj); + DeletePObj(pObj); + // LCOV_EXCL_STOP + } else { + FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__, " Successful"); + } + } + FRAMEWORKUNIFIEDLOG0(ZONE_FUNC, __FUNCTION__, "-"); + return l_eStatus; +} + +/*****************************************************************************/ +/** + @ingroup: SS_SystemManager + @brief: HBThreadStop: function would be called at the time of stopping of the thread + @note: . + @param HANDLE - Handle to message queue of HeartBeat Service. + @return EFrameworkunifiedStatus + */ +/*****************************************************************************/ +EFrameworkunifiedStatus HBThreadStop(HANDLE hThread) { // LCOV_EXCL_START 14: Resident process, not called by NSFW + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + EFrameworkunifiedStatus l_eStatus; + + FRAMEWORKUNIFIEDLOG0(ZONE_FUNC, __FUNCTION__, "+"); + + CHeartBeatThread * pObj = static_cast<CHeartBeatThread *>(FrameworkunifiedGetThreadSpecificData(hThread)); + if (NULL == pObj) { + l_eStatus = eFrameworkunifiedStatusNullPointer; + LOG_ERROR("FrameworkunifiedGetThreadSpecificData(hThread)"); + } else { + // delete timers + CALL_AND_LOG_STATUS_IF_ERRORED(pObj->HeartBeatTimersDelete()); + CALL_AND_LOG_STATUS_IF_ERRORED(pObj->HBPublishAvailabilityStatus(hThread, FALSE)); + DeletePObj(pObj); + } + + FrameworkunifiedSetThreadSpecificData(hThread, NULL); + CALL_AND_LOG_STATUS_IF_ERRORED(FrameworkunifiedDetachServiceFromDispatcher(hThread, FrameworkunifiedGetAppName(hThread))); + + FRAMEWORKUNIFIEDLOG0(ZONE_FUNC, __FUNCTION__, "-"); + + return l_eStatus; +}// LCOV_EXCL_STOP diff --git a/video_in_hal/systemservice/system_manager/server/src/heartbeat/ss_hb_service_protocol.cpp b/video_in_hal/systemservice/system_manager/server/src/heartbeat/ss_hb_service_protocol.cpp new file mode 100755 index 0000000..5fb4e00 --- /dev/null +++ b/video_in_hal/systemservice/system_manager/server/src/heartbeat/ss_hb_service_protocol.cpp @@ -0,0 +1,184 @@ +/* + * @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_SystemManager +/// \brief This file provides support for the application heartbeat system. +/// +/////////////////////////////////////////////////////////////////////////////// +#include <system_service/ss_heartbeat_service_protocol.h> +#include <system_service/ss_system_manager_if.h> +#include <system_service/ss_system_manager_if_local.h> +#include <stdlib.h> +#include <string.h> +#include <native_service/frameworkunified_framework_if.h> +#include <system_service/ss_services.h> +#include <system_service/ss_templates.h> + +#include "ss_hb_thread.h" +#include "ss_sm_systemmanagerlog.h" + +/***************************************************************************** + @ingroup: SS_SystemManager + @brief: HBOnTimerExpiry + @note: . + @param HANDLE - Handle to message queue of HeartBeat Service. + @return EFrameworkunifiedStatus + *****************************************************************************/ +EFrameworkunifiedStatus CHeartBeatThread::HBOnTimerExpiry(HANDLE f_hThread) { + FRAMEWORKUNIFIEDLOG(ZONE_PERIODIC_FUNC, __FUNCTION__, "+"); + EFrameworkunifiedStatus l_eStatus; + + // check heart beat replies received from clients. + l_eStatus = HBCheckHeartBeatResponses(f_hThread); + LOG_STATUS_IF_ERRORED(l_eStatus, "HBCheckHeartBeatResponses()"); // LCOV_EXCL_BR_LINE 15: marco defined in ss_templates.h // NOLINT(whitespace/line_length) + + // send heart beat requests to clients + l_eStatus = HBSendRequest(f_hThread); + LOG_STATUS_IF_ERRORED(l_eStatus, "HBSendRequest()"); // LCOV_EXCL_BR_LINE 15: marco defined in ss_templates.h // NOLINT(whitespace/line_length) + + FRAMEWORKUNIFIEDLOG(ZONE_PERIODIC_FUNC, __FUNCTION__, "-"); + return (l_eStatus); +} + +/***************************************************************************** + @ingroup: SS_SystemManager + @brief: HBOnClientResponse + @note: . + @param HANDLE - Handle to message queue of HeartBeat Service. + @return EFrameworkunifiedStatus OK or Fail + *****************************************************************************/ +EFrameworkunifiedStatus CHeartBeatThread::HBOnClientResponse(HANDLE f_hThread) { + EFrameworkunifiedStatus l_eStatus; + FRAMEWORKUNIFIEDLOG(ZONE_PERIODIC_FUNC, __FUNCTION__, "+"); + l_eStatus = m_oSessionHandler.HBProcessClientResponse(f_hThread); + LOG_STATUS_IF_ERRORED(l_eStatus, "m_oSessionHandler.HBProcessClientResponse(f_hThread)"); // LCOV_EXCL_BR_LINE 15: marco defined in ss_templates.h // NOLINT(whitespace/line_length) + FRAMEWORKUNIFIEDLOG(ZONE_PERIODIC_FUNC, __FUNCTION__, "-"); + return l_eStatus; +} + +/***************************************************************************** + @ingroup: SS_SystemManager + @brief: HBOnPeriodicStatusRequest + @note: . + @param HANDLE - Handle to message queue of HeartBeat Service. + @return EFrameworkunifiedStatus OK or Fail + *****************************************************************************/ +EFrameworkunifiedStatus CHeartBeatThread::HBOnPeriodicStatusRequest(HANDLE f_hThread) { + EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK; + FRAMEWORKUNIFIEDLOG(ZONE_PERIODIC_FUNC, __FUNCTION__, "+"); + // LCOV_EXCL_BR_START 4: NSFW error case. + if (eFrameworkunifiedStatusOK != (l_eStatus = FrameworkunifiedSendParent(f_hThread, SS_HEARTBEAT_PERIODIC_RESP, 0, NULL))) { + // LCOV_EXCL_BR_STOP + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + LOG_ERROR("FrameworkunifiedSendParent(SS_HEARTBEAT_PERIODIC_RESP)"); // LCOV_EXCL_LINE 4: NSFW error case. + } else { + FRAMEWORKUNIFIEDLOG(ZONE_PERIODIC_INFO, __FUNCTION__, "Successful"); + } + + FRAMEWORKUNIFIEDLOG(ZONE_PERIODIC_FUNC, __FUNCTION__, "-"); + return l_eStatus; +} + +/***************************************************************************** + @ingroup: SS_SystemManager + @brief: HBOnPeriodicStatusRequest + @note: . + @param HANDLE - Handle to message queue of HeartBeat Service. + @return EFrameworkunifiedStatus OK or Fail + *****************************************************************************/ +EFrameworkunifiedStatus CHeartBeatThread::HBOnAvailCheckRequest(HANDLE f_hThread) { + FRAMEWORKUNIFIEDLOG(ZONE_STATE, __FUNCTION__, "+"); + + EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK; + THbAvailCheck check; + l_eStatus = m_oSessionHandler.HBAvailableCheck(check); + SS_ASERT(l_eStatus == eFrameworkunifiedStatusOK); // LCOV_EXCL_BR_LINE 15: marco defined in ss_templates.h // NOLINT(whitespace/line_length) + + // LCOV_EXCL_BR_START 4: NSFW error case. + if (eFrameworkunifiedStatusOK != (l_eStatus = FrameworkunifiedSendParent(f_hThread, SS_HEARTBEAT_AVAIL_CHECK_RESP, sizeof(check), &check))) { + // LCOV_EXCL_BR_STOP + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + LOG_ERROR("FrameworkunifiedSendParent(SS_HEARTBEAT_AVAIL_CHECK_RESP)"); // LCOV_EXCL_LINE 4: NSFW error case. + } + + return l_eStatus; +} + +/***************************************************************************** + @ingroup: SS_SystemManager + @brief: HBOnRemoveModule + @note: . + @param HANDLE - Handle to message queue of HeartBeat Service. + @return EFrameworkunifiedStatus OK or Fail + *****************************************************************************/ +EFrameworkunifiedStatus CHeartBeatThread::HBOnRemoveModule(HANDLE f_hThread) { + EFrameworkunifiedStatus l_eStatus; + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+"); + + TSMRequestMessage tReqMsgData; + // ReadMsg(): * + // Check hApp ptr, msg size, msg reception, read msg if all ok. * + // Report any errors found. * + // * + // LCOV_EXCL_BR_START 4: NSFW error case. + if (eFrameworkunifiedStatusOK != (l_eStatus = ReadMsg <TSMRequestMessage> (f_hThread, tReqMsgData))) { + // LCOV_EXCL_BR_STOP + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + LOG_ERROR("ReadMsg()"); // LCOV_EXCL_LINE 4: NSFW error case. + } else { + FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__, + " %s is required to be Deleted from HeartBeat Monitor List", tReqMsgData.pstModuleName); + + // delete module entry from map + l_eStatus = m_oSessionHandler.HBDeleteRegisteredClientEntry(f_hThread, tReqMsgData.pstModuleName); + LOG_STATUS_IF_ERRORED(l_eStatus, "m_oSessionHandler.HBDeleteRegisteredProcessEntry()"); // LCOV_EXCL_BR_LINE 15: marco defined in ss_templates.h // NOLINT(whitespace/line_length) + } + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-"); + return l_eStatus; +} + +/***************************************************************************** + @ingroup: SS_SystemManager + @brief: HBOnAppendModule + @note: . + @param HANDLE - Handle to message queue of HeartBeat Service. + @return EFrameworkunifiedStatus OK or Fail + *****************************************************************************/ +EFrameworkunifiedStatus CHeartBeatThread::HBOnAppendModule(HANDLE f_hThread) { + EFrameworkunifiedStatus l_eStatus; + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+"); + + TSMRequestMessage tReqMsgData; + // ReadMsg(): * + // Check hApp ptr, msg size, msg reception, read msg if all ok. * + // Report any errors found. * + // * + if (eFrameworkunifiedStatusOK != (l_eStatus = ReadMsg < TSMRequestMessage > (f_hThread, tReqMsgData))) { + LOG_ERROR("ReadMsg()"); + } else { + FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__, + " %s is required to be Appended from HeartBeat Monitor List", tReqMsgData.pstModuleName); + + // append module entry from map + SubscriberName l_Subscriber = tReqMsgData.pstModuleName; + l_eStatus = m_oSessionHandler.HBEntrySubscriber(l_Subscriber); // LCOV_EXCL_BR_LINE 11:unexpected branch // NOLINT(whitespace/line_length) + LOG_STATUS_IF_ERRORED(l_eStatus, "m_oSessionHandler.HBEntrySubscriber()"); // LCOV_EXCL_BR_LINE 15: marco defined in ss_templates.h // NOLINT(whitespace/line_length) + } + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-"); + return l_eStatus; +} +// EOF diff --git a/video_in_hal/systemservice/system_manager/server/src/heartbeat/ss_hb_session.cpp b/video_in_hal/systemservice/system_manager/server/src/heartbeat/ss_hb_session.cpp new file mode 100755 index 0000000..8178e46 --- /dev/null +++ b/video_in_hal/systemservice/system_manager/server/src/heartbeat/ss_hb_session.cpp @@ -0,0 +1,415 @@ +/* + * @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_SystemManager +/// \brief This file provides support for the application heartbeat system. +/// +/////////////////////////////////////////////////////////////////////////////// + +#include <native_service/frameworkunified_framework_if.h> +#include <native_service/frameworkunified_service_protocol.h> +#include <system_service/ss_heartbeat_service_protocol.h> +#include <system_service/ss_services.h> +#include <system_service/ss_sm_thread_names.h> +#include <system_service/ss_templates.h> +#include <iostream> +#include <iomanip> +#include <utility> +#include <list> +#include <string> + +#include "ss_sm_systemmanagerlog.h" +#include "ss_hb_thread.h" +#include "ss_hb_session.h" +#include "ss_system_manager.h" + +using namespace std; // NOLINT + +CHeartBeatSessionHandler::CHeartBeatSessionHandler() { +} + +CHeartBeatSessionHandler::~CHeartBeatSessionHandler() { // LCOV_EXCL_START 14: Resident process, not called by NSFW + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert +} +// LCOV_EXCL_STOP + +/***************************************************************************** + @ingroup: SS_SystemManager + @brief: HbSessionInfo + @note: HbSessionInfo constructor + @param + @return + *****************************************************************************/ +CHeartBeatSessionHandler::HbSessionInfo::HbSessionInfo(SubscriberName f_Subscriber) { + fRunning = FALSE; + fHeartBeatRequestSent = FALSE; + fHeartBeatResponseReceived = FALSE; + HeartBeatRetryCount = 0; + fHeartBeatTimedOut = FALSE; + hSession = NULL; + szName = f_Subscriber; + fisAvailability = FALSE; +} + +/***************************************************************************** + @ingroup: SS_SystemManager + @brief: HBEntrySubscriber + @note: + @param + @return + *****************************************************************************/ +EFrameworkunifiedStatus CHeartBeatSessionHandler::HBEntrySubscriber(SubscriberName &f_Subscriber) { + EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK; + // check if the subscriber is already in map + HbSessionIter l_SessionInfoIterator = m_mapHbSessions.find(f_Subscriber); + + // the l_SessionInfoIterator is set to the end then the subscriber is not in the map + if (m_mapHbSessions.end() == l_SessionInfoIterator) { + FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__, "Entry Subscriber : %s", f_Subscriber.c_str()); + HbSessionInfo l_NewHBClientSessionInfo(f_Subscriber.c_str()); // LCOV_EXCL_BR_LINE 11:unexpected branch // NOLINT(whitespace/line_length) + + pair<HbSessionIter, bool> ret; + // insert new subscriber entry into the session map + ret = m_mapHbSessions.insert(std::make_pair(f_Subscriber, l_NewHBClientSessionInfo)); + if (!ret.second) { // LCOV_EXCL_BR_LINE 6:l_NewHBClientSessionInfo must not be NULL. + // LCOV_EXCL_START 6:l_NewHBClientSessionInfo must not be NULL. + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + l_eStatus = eFrameworkunifiedStatusFail; + SS_ASERT(0); // LCOV_EXCL_BR_LINE 15: marco defined in ss_templates.h // NOLINT(whitespace/line_length) + // LCOV_EXCL_STOP + } + } else { + FRAMEWORKUNIFIEDLOG(ZONE_WARN, __FUNCTION__, "Subscriber '%s' is already in the map", f_Subscriber.c_str()); + } + return l_eStatus; +} + +/***************************************************************************** + @ingroup: SS_SystemManager + @brief: ProcessHBClientResponse + @note: Process the response received from client, update relevant structure data + @param HANDLE + @return EFrameworkunifiedStatus + *****************************************************************************/ +EFrameworkunifiedStatus CHeartBeatSessionHandler::HBProcessClientResponse(HANDLE f_hThread) { + EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK; + FRAMEWORKUNIFIEDLOG(ZONE_PERIODIC_INFO, __FUNCTION__, "+"); + BOOL l_availability = FALSE; + + if (eFrameworkunifiedStatusOK != (l_eStatus = ReadMsg<BOOL>(f_hThread, l_availability))) { + LOG_ERROR("ReadMsg()"); // LCOV_EXCL_BR_LINE 15: marco defined in ss_templates.h // NOLINT(whitespace/line_length) + } + + // find the subscriber... + HbSessionIter l_SessionInfoIterator = m_mapHbSessions.find(FrameworkunifiedGetMsgSrc(f_hThread)); + + // the l_SessionInfoIterator is set to the end then the subscriber is not in the map + if (m_mapHbSessions.end() != l_SessionInfoIterator) { + l_SessionInfoIterator->second.HeartBeatRetryCount = 0; + l_SessionInfoIterator->second.fHeartBeatResponseReceived = TRUE; + l_SessionInfoIterator->second.fHeartBeatRequestSent = FALSE; + l_SessionInfoIterator->second.fisAvailability = l_availability; + FRAMEWORKUNIFIEDLOG(ZONE_PERIODIC_INFO, __FUNCTION__, + "HeartBeat received from module: %s ", l_SessionInfoIterator->first.c_str()); + } else { + FRAMEWORKUNIFIEDLOG(ZONE_PERIODIC_INFO, __FUNCTION__, + "Ignoring Heart Beat Response, Client: %s not found in the map!", FrameworkunifiedGetMsgSrc(f_hThread)); + } + FRAMEWORKUNIFIEDLOG(ZONE_PERIODIC_INFO, __FUNCTION__, "-"); + return l_eStatus; +} + +/***************************************************************************** + @ingroup: SS_SystemManager + @brief: HBPrintConnection + @note: .Print registered client information + @param VOID + @return VOID + *****************************************************************************/ +VOID CHeartBeatSessionHandler::HBPrintConnection() { + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+"); + + // find the subscriber... + HbSessionIter l_SessionInfoIterator = m_mapHbSessions.begin(); + for (; l_SessionInfoIterator != m_mapHbSessions.end(); l_SessionInfoIterator++) { + FRAMEWORKUNIFIEDLOG(ZONE_DEBUG_DUMP, __FUNCTION__, + "HeartBeat Service is Connected to: %s via a Session: Running: %s ", + l_SessionInfoIterator->second.szName.data(), + (l_SessionInfoIterator->second.fRunning ? "YES" : "NO")); + } + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-"); +} + +/***************************************************************************** + @ingroup: SS_SystemManager + @brief: HBPrintStack + @note: .Print registered client information + @param VOID + @return VOID + *****************************************************************************/ +VOID CHeartBeatSessionHandler::HBPrintStack(UI_32 f_MaxHeartBeatRetryCount) { + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+"); + + // find the subscriber... + HbSessionIter l_SessionInfoIterator = m_mapHbSessions.begin(); + for (; l_SessionInfoIterator != m_mapHbSessions.end(); l_SessionInfoIterator++) { + if (FALSE == l_SessionInfoIterator->second.fHeartBeatResponseReceived) { + FRAMEWORKUNIFIEDLOG(ZONE_DEBUG_DUMP, __FUNCTION__, + "HeartBeat Service is Connected to: %s via a Session: Running: %s ", + l_SessionInfoIterator->second.szName.data(), + (l_SessionInfoIterator->second.fRunning ? "YES" : "NO")); + FRAMEWORKUNIFIEDLOG(ZONE_DEBUG_DUMP, __FUNCTION__, + "Retry count (%d) within limit (%d), HeartBeatTimedout = %s", + l_SessionInfoIterator->second.HeartBeatRetryCount, + f_MaxHeartBeatRetryCount, + (l_SessionInfoIterator->second.fHeartBeatTimedOut == TRUE ? + "TRUE" : "FALSE")); + } + } + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-"); +} + +/***************************************************************************** + @ingroup: SS_SystemManager + @brief: HBCheckResponses + @note: Check if all clients have replied to heartbeat query and generate report + @param THbReportData Report structure to be filled + @param UI_32 Heartbeat max retry count + @return eFrameworkunifiedStatusFail if one or more modules have timed out, eFrameworkunifiedStatusOK otherwise. + *****************************************************************************/ +EFrameworkunifiedStatus CHeartBeatSessionHandler::HBCheckResponses( + THbReportData &f_tReportData, UI_32 f_MaxHeartBeatRetryCount, + SI_32 f_HeartBeatIntervalRepeat, SI_32 f_ChkIndex) { + EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK; + FRAMEWORKUNIFIEDLOG(ZONE_PERIODIC_FUNC, __FUNCTION__, "+"); + + HbSessionIter l_SessionInfoIterator = m_mapHbSessions.begin(); + memset(&f_tReportData, 0, sizeof(THbReportData)); + + int index = 0; + + while (l_SessionInfoIterator != m_mapHbSessions.end()) { + if (f_ChkIndex == (index % f_HeartBeatIntervalRepeat)) { + // check if report queue is full + // LCOV_EXCL_BR_START 6: f_tReportData.nNumOfModules can't more than SS_MAX_NUM_MODULES + if (SS_MAX_NUM_MODULES <= f_tReportData.nNumOfModules) { + // LCOV_EXCL_BR_STOP + FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, + " Error: SS_MAX_NUM_MODULES '%d' <= f_tReportData.nNumOfModules '%d'. See ss_system_manager_if.h.", + SS_MAX_NUM_MODULES, f_tReportData.nNumOfModules); + + FRAMEWORKUNIFIEDLOG(ZONE_PERIODIC_FUNC, __FUNCTION__, "-"); + return eFrameworkunifiedStatusInvldBuf; + } + + + strncpy(f_tReportData.tModuleList[f_tReportData.nNumOfModules].ProcQueueName, + l_SessionInfoIterator->first.c_str(), + sizeof(f_tReportData.tModuleList[f_tReportData.nNumOfModules].ProcQueueName) - 1); + f_tReportData.tModuleList[f_tReportData.nNumOfModules].HeartBeatRetryCount = + l_SessionInfoIterator->second.HeartBeatRetryCount; + f_tReportData.tModuleList[f_tReportData.nNumOfModules].ProcHBState = HB_STATUS_GOOD; + + if (TRUE == l_SessionInfoIterator->second.fHeartBeatResponseReceived) { + l_SessionInfoIterator->second.fHeartBeatResponseReceived = FALSE; + FRAMEWORKUNIFIEDLOG(ZONE_PERIODIC_INFO, __FUNCTION__, + "[%s] Heart Beat Response Received !", + l_SessionInfoIterator->second.szName.c_str()); + } else if (TRUE == l_SessionInfoIterator->second.fHeartBeatTimedOut) { + f_tReportData.tModuleList[f_tReportData.nNumOfModules].ProcHBState = HB_STATUS_TIMEOUT; + } else if ((TRUE == l_SessionInfoIterator->second.fHeartBeatRequestSent) + && (FALSE == l_SessionInfoIterator->second.fHeartBeatTimedOut)) { + l_SessionInfoIterator->second.HeartBeatRetryCount++; + + if (l_SessionInfoIterator->second.HeartBeatRetryCount > f_MaxHeartBeatRetryCount) { + l_eStatus = eFrameworkunifiedStatusFail; + l_SessionInfoIterator->second.fHeartBeatTimedOut = TRUE; + l_SessionInfoIterator->second.HeartBeatRetryCount = 0; + + f_tReportData.tModuleList[f_tReportData.nNumOfModules].ProcHBState = HB_STATUS_TIMEOUT; + + FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, + " Error: Heart Beat Retry count of [%s] has crossed max limit (%d)." + "Disabling sending HeartBeat query to it", + l_SessionInfoIterator->second.szName.c_str(), + f_MaxHeartBeatRetryCount); + } else { + FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, + " Error: [%s] has missed a Heart Beat. Retry count (%d) is within max retry limit (%d)", + l_SessionInfoIterator->second.szName.c_str(), + l_SessionInfoIterator->second.HeartBeatRetryCount, + f_MaxHeartBeatRetryCount); + } + } + } + + f_tReportData.nNumOfModules++; + ++l_SessionInfoIterator; + index++; + } + + FRAMEWORKUNIFIEDLOG(ZONE_PERIODIC_FUNC, __FUNCTION__, "-"); + return l_eStatus; +} + +/***************************************************************************** + @ingroup: SS_SystemManager + @brief: HBSendRequest + @note: .Sent heart beat query to the registered clients + @param void + @return EFrameworkunifiedStatus +******************************************************************************/ +EFrameworkunifiedStatus CHeartBeatSessionHandler::HBSendRequest(HANDLE f_hThread, + SI_32 f_HeartBeatIntervalRepeat, SI_32 f_ChkIndex) { + EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK; + FRAMEWORKUNIFIEDLOG(ZONE_PERIODIC_FUNC, __FUNCTION__, "+"); + + // Get session iterator + HbSessionIter l_SessionInfoIterator = m_mapHbSessions.begin(); + + if (l_SessionInfoIterator == m_mapHbSessions.end()) { + FRAMEWORKUNIFIEDLOG(ZONE_PERIODIC_INFO, __FUNCTION__, "No Client has opened session with HeartBeat"); + FRAMEWORKUNIFIEDLOG(ZONE_PERIODIC_FUNC, __FUNCTION__, "-"); + return l_eStatus; + } + + int index = 0; + + while (l_SessionInfoIterator != m_mapHbSessions.end()) { + if (f_ChkIndex == (index % f_HeartBeatIntervalRepeat)) { + if (l_SessionInfoIterator->second.hSession == NULL) { // LCOV_EXCL_BR_LINE 200:hSession must not be NULL + l_SessionInfoIterator->second.hSession = FrameworkunifiedMcOpenSender(f_hThread, l_SessionInfoIterator->first.c_str()); + if (NULL == l_SessionInfoIterator->second.hSession) { // LCOV_EXCL_BR_LINE 200:hSession must not be NULL + // LCOV_EXCL_START 200: hSession must not be NULL + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, + " Error: FrameworkunifiedMcOpenSender(%s) returned NULL", + l_SessionInfoIterator->first.c_str()); + // LCOV_EXCL_STOP + } else { + l_SessionInfoIterator->second.fRunning = TRUE; + } + } + + if ((NULL != l_SessionInfoIterator->second.hSession) + && (FALSE == l_SessionInfoIterator->second.fHeartBeatTimedOut)) { + if (eFrameworkunifiedStatusOK == (l_eStatus = FrameworkunifiedSendMsg(l_SessionInfoIterator->second.hSession, SS_HEARTBEAT_REQUEST, 0, NULL))) { // LCOV_EXCL_BR_LINE 5:NSFW's error // NOLINT(whitespace/line_length) + /// TODO review if we are required to return failure if sending message to one process failed. + l_SessionInfoIterator->second.fHeartBeatResponseReceived = FALSE; + l_SessionInfoIterator->second.fHeartBeatRequestSent = TRUE; + FRAMEWORKUNIFIEDLOG(ZONE_PERIODIC_INFO, __FUNCTION__, + "HeartBeat Request sent to : %s", l_SessionInfoIterator->first.c_str()); + } else { + // LCOV_EXCL_START 5:NSFW's error + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, + " Error: FrameworkunifiedSendMsg(%s, SS_HEARTBEAT_REQUEST) errored: %d/'%s'", + l_SessionInfoIterator->first.c_str(), l_eStatus, + GetStr(l_eStatus).c_str()); + // LCOV_EXCL_STOP + } + } else { + FRAMEWORKUNIFIEDLOG(ZONE_PERIODIC_INFO, __FUNCTION__, + " HeartBeat Request was not sent to '%s', timeout is '%s'", + l_SessionInfoIterator->first.c_str(), + (l_SessionInfoIterator->second.fHeartBeatTimedOut == TRUE ? "TRUE" : "FALSE")); + } + } + ++l_SessionInfoIterator; + index++; + } + + FRAMEWORKUNIFIEDLOG(ZONE_PERIODIC_FUNC, __FUNCTION__, "-"); + return l_eStatus; +} + +/***************************************************************************** + @ingroup: SS_SystemManager + @brief: HBDeleteRegisteredClientEntry + @note: . + @param + @return EFrameworkunifiedStatus +******************************************************************************/ +EFrameworkunifiedStatus CHeartBeatSessionHandler::HBDeleteRegisteredClientEntry(HANDLE f_hThread, PSTR pQueueName) { + EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK; + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+"); + + SubscriberName tQueuename(pQueueName); + + FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__, "Looking for %s.", tQueuename.c_str()); + + HbSessionIter l_SessionInfoIterator = m_mapHbSessions.find(tQueuename); + + if (m_mapHbSessions.end() != l_SessionInfoIterator) { + // Close the session handle + if (NULL != l_SessionInfoIterator->second.hSession) { // LCOV_EXCL_BR_LINE 200:hSession must not be NULL when tQueuename exists. // NOLINT(whitespace/line_length) + // LCOV_EXCL_BR_START 4: NSFW error case. + if (eFrameworkunifiedStatusOK != (l_eStatus = FrameworkunifiedMcClose(l_SessionInfoIterator->second.hSession))) { + // LCOV_EXCL_BR_STOP + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + LOG_ERROR("FrameworkunifiedMcClose()"); // LCOV_EXCL_LINE 4: NSFW error case. + } + l_SessionInfoIterator->second.hSession = NULL; + } + m_mapHbSessions.erase(tQueuename); + FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__, "Deleting '%s' Successful ", tQueuename.c_str()); + } else { + FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__, + "%s not found in Heart beat client list", tQueuename.c_str()); + } + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-"); + return l_eStatus; +} + +/***************************************************************************** + @ingroup: SS_SystemManager + @brief: HBAvailableCheck + @note: . + @param + @return EFrameworkunifiedStatus +******************************************************************************/ +EFrameworkunifiedStatus CHeartBeatSessionHandler::HBAvailableCheck(THbAvailCheck &check) { + EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK; + BOOL isOk = TRUE; + + std::list<std::string> ngList; + for (HbSessionIter ite = m_mapHbSessions.begin(); ite != m_mapHbSessions.end(); ite++) { + if (ite->second.fisAvailability == FALSE) { + ngList.push_back(ite->first); + // Notify Last Service as Representative + snprintf(check.serviceName, SS_SM_HB_MAX_PROC_NAME_SIZE, "%s", ite->first.c_str()); + isOk = FALSE; + } + } + + if (isOk == FALSE) { + FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "********* AVAILABILITY CHECK ERROR **********"); + fprintf(stderr, "HBOnAvailCheckRequest/********* AVAILABILITY CHECK ERROR **********\n"); // LCOV_EXCL_BR_LINE 11:unexpected branch // NOLINT(whitespace/line_length) + } else { + FRAMEWORKUNIFIEDLOG(ZONE_STATE, __FUNCTION__, "********* AVAILABILITY CHECK OK **********"); + fprintf(stderr, "HBOnAvailCheckRequest/********* AVAILABILITY CHECK OK **********\n"); // LCOV_EXCL_BR_LINE 11:unexpected branch // NOLINT(whitespace/line_length) + } + + for (std::list<std::string>::iterator ite = ngList.begin(); ite != ngList.end(); ite++) { + FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, " %s", ite->c_str()); + fprintf(stderr, " %s\n", ite->c_str()); // LCOV_EXCL_BR_LINE 11:unexpected branch // NOLINT(whitespace/line_length) + } + + check.isOk = isOk; + + return l_eStatus; +} diff --git a/video_in_hal/systemservice/system_manager/server/src/heartbeat/ss_hb_thread.cpp b/video_in_hal/systemservice/system_manager/server/src/heartbeat/ss_hb_thread.cpp new file mode 100755 index 0000000..19d124a --- /dev/null +++ b/video_in_hal/systemservice/system_manager/server/src/heartbeat/ss_hb_thread.cpp @@ -0,0 +1,355 @@ +/* + * @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_SystemManager +/// \brief This file provides support for the application heartbeat system. +/// +/////////////////////////////////////////////////////////////////////////////// +#include <native_service/frameworkunified_application.h> +#include <native_service/frameworkunified_framework_if.h> +#include <native_service/frameworkunified_service_protocol.h> +#include <system_service/ss_heartbeat_notifications.h> +#include <system_service/ss_heartbeat_service_protocol.h> +#include <system_service/ss_power_service_notifications.h> +#include <system_service/ss_services.h> +#include <system_service/ss_templates.h> + +#include "ss_hb_thread.h" +#include "ss_sm_systemmanagerlog.h" +#include "ss_system_manager.h" + +/// Total Timers used by Heart Beat Thread +/// This value is used for creating timers +#define HBMaxTimers 1 +#define HBTimerInterval 1 + +template<typename C, eFrameworkunifiedStatus (C::*M)(HANDLE)> EFrameworkunifiedStatus HBThreadCallback(HANDLE hThread) { + EFrameworkunifiedStatus eStatus = eFrameworkunifiedStatusOK; + C * pObj = static_cast<C *>(FrameworkunifiedGetThreadSpecificData(hThread)); + if (pObj) { // LCOV_EXCL_BR_LINE 4:pObj must not be NULL + eStatus = (pObj->*M)(hThread); + } + return eStatus; +} + +/***************************************************************************** + @ingroup: SS_SystemManager + @brief: CHeartBeatThread + @note: Constructor +*****************************************************************************/ +CHeartBeatThread::CHeartBeatThread(HANDLE f_hThread) : + m_oTimerCtrl(HBMaxTimers) + , m_HBTimerID(0) + , m_NextChkIndex(0) + , m_hThread(f_hThread) { // LCOV_EXCL_BR_LINE 11:unexpected branch // NOLINT(whitespace/line_length) + std::memset(&m_HBConfigParams, 0, sizeof(m_HBConfigParams)); +} + +/***************************************************************************** + @ingroup: SS_SystemManager + @brief: ~CHeartBeatThread + @note: Destructor +*****************************************************************************/ +CHeartBeatThread::~CHeartBeatThread() { // LCOV_EXCL_START 14: Resident process, not called by NSFW + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert +} +// LCOV_EXCL_STOP + +/***************************************************************************** + @ingroup: SS_SystemManager + @brief: HBPublishAvailabilityStatus + @note: . + @param HANDLE - Handle to message queue of HeartBeat Service. + @param BOOL - The Availability Status to be published + @return EFrameworkunifiedStatus +*****************************************************************************/ +EFrameworkunifiedStatus CHeartBeatThread::HBPublishAvailabilityStatus(HANDLE hThread, BOOL f_bAvailabiltyStatus) {// LCOV_EXCL_START 14: Resident process, not called by NSFW + EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK; + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+"); + + // Send availability notification to users + l_eStatus = FrameworkunifiedPublishServiceAvailability(hThread, f_bAvailabiltyStatus); + char l_cBuf[100] = { 0 }; + snprintf(l_cBuf, + sizeof(l_cBuf), + "FrameworkunifiedPublishServiceAvailability(%s)", + GetStr(f_bAvailabiltyStatus).c_str()); + LOG_STATUS(l_eStatus, l_cBuf); // LCOV_EXCL_BR_LINE 15: marco defined in ss_templates.h // NOLINT(whitespace/line_length) + + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-"); + return l_eStatus; +}// LCOV_EXCL_STOP + +/***************************************************************************** + @ingroup: SS_SystemManager + @brief: HBOnStartThread + @note: . + @param HANDLE - Handle to message queue of HeartBeat Service. + @return EFrameworkunifiedStatus +*****************************************************************************/ +EFrameworkunifiedStatus CHeartBeatThread::HBOnStartThread(HANDLE hThread) { + EFrameworkunifiedStatus l_eStatus; + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+"); + + UI_32 l_DataLen = FrameworkunifiedGetMsgLength(hThread); // LCOV_EXCL_BR_LINE 11:unexpected branch // NOLINT(whitespace/line_length) + + if ((sizeof(UI_32) + (SS_MAX_NUM_MODULES * SS_SM_HB_MAX_PROC_NAME_SIZE) + sizeof(m_HBConfigParams)) < l_DataLen) { + FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, + " Error: message buffer sizes invalid:received %d", l_DataLen); + return eFrameworkunifiedStatusInvldParam; + } + + CHAR l_Data[l_DataLen]; // NOLINT + // LCOV_EXCL_BR_START 4: NSFW error case. + if (eFrameworkunifiedStatusOK != + (l_eStatus = FrameworkunifiedGetMsgDataOfSize(hThread, (PVOID) & l_Data, static_cast<UI_32>(sizeof(l_Data)), eSMRRelease))) { + // LCOV_EXCL_BR_STOP + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, + " Error: FrameworkunifiedGetMsgDataOfSize() errored: 0x%x", l_eStatus); + return l_eStatus; + } + + CHAR* p_Data = &l_Data[0]; + UI_32 list_num; + memcpy(&m_HBConfigParams, p_Data, sizeof(m_HBConfigParams)); + p_Data = p_Data + sizeof(m_HBConfigParams); + memcpy(&list_num, p_Data, sizeof(list_num)); + p_Data = p_Data + sizeof((list_num)); + + for (UI_32 i = 0; i < list_num; i++) { + SubscriberName l_Subscriber = p_Data; // LCOV_EXCL_BR_LINE 11:unexpected branch // NOLINT(whitespace/line_length) + // LCOV_EXCL_BR_START 4: NSFW error case. + if (eFrameworkunifiedStatusOK != m_oSessionHandler.HBEntrySubscriber(l_Subscriber)) { + // LCOV_EXCL_BR_STOP + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, " Error: HBEntrySubscriber"); + } + p_Data = p_Data + SS_SM_HB_MAX_PROC_NAME_SIZE; + } + + if (0 == m_HBConfigParams.ApplicationHeartBeatIntervalInitial) { + FRAMEWORKUNIFIEDLOG(ZONE_WARN, __FUNCTION__, + " Warning: Heart beat disabled via configuration file interval " + "parameter set to 0."); + } else if (0 != m_HBTimerID) { + FRAMEWORKUNIFIEDLOG(ZONE_WARN, __FUNCTION__, + " Warning: Heart Beat Timer ID '%d' already created, ignoring " + "repeated Heart Beat Start command.", m_HBTimerID); + } else { + // LCOV_EXCL_BR_START 4: NSFW error case. + if (eFrameworkunifiedStatusOK != + (l_eStatus = FrameworkunifiedRegisterServiceAvailabilityNotification(hThread, NTFY_HeartBeatAvailability))) { + // LCOV_EXCL_BR_STOP + // LCOV_EXCL_START 4: NSFW error case. + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + LOG_ERROR("FrameworkunifiedRegisterServiceAvailabilityNotification(" NTFY_HeartBeatAvailability ")"); + // LCOV_EXCL_STOP + } + else { + FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__, + "Service availability %s Registered SOURCE : %s", + NTFY_HeartBeatAvailability, + FrameworkunifiedGetAppName(hThread)); + + // Publish Heart Beat Availability + // LCOV_EXCL_BR_START 4: NSFW error case. + if (eFrameworkunifiedStatusOK != (l_eStatus = HBPublishAvailabilityStatus(hThread, TRUE))) { + // LCOV_EXCL_BR_STOP + // LCOV_EXCL_START 4: NSFW error case. + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + LOG_ERROR("HBPublishAvailabilityStatus(TRUE)"); + // LCOV_EXCL_STOP + } + } + // Create Heart Beat app monitor + m_HBTimerID = m_oTimerCtrl.CreateTimer(HBThreadCallback<CHeartBeatThread, &CHeartBeatThread::HBOnTimerExpiry>); // LCOV_EXCL_BR_LINE 11:unexpected branch // NOLINT(whitespace/line_length) + if (0 == m_HBTimerID) { // LCOV_EXCL_BR_LINE 8: m_HBTimerID can't be 0 + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, " Error: Heart Beat Timer ID creation failed."); + // return eFrameworkunifiedStatusFail; + } else { + // Start Heart Beat app monitor + m_oTimerCtrl.StartTimer(m_HBTimerID, + m_HBConfigParams.ApplicationHeartBeatIntervalInitial, + 0, + HBTimerInterval, + 0); // LCOV_EXCL_BR_LINE 11:unexpected branch // NOLINT(whitespace/line_length) + FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__, "Initial Heart Beat Timer created for %d seconds interval", + m_HBConfigParams.ApplicationHeartBeatIntervalInitial); + FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__, "Repetitive Heart Beat Timer created for %d seconds interval", + m_HBConfigParams.ApplicationHeartBeatIntervalRepeat); + } + } + + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-"); + return l_eStatus; +} + +/***************************************************************************** + @ingroup: SS_SystemManager + @brief: HBOnStopThread + @note: . + @param HANDLE - Handle to message queue of HeartBeat Service. + @return EFrameworkunifiedStatus +*****************************************************************************/ +EFrameworkunifiedStatus CHeartBeatThread::HBOnStopThread(HANDLE hThread) { + EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK; + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+"); + if (0 != m_HBTimerID) { + // Stop HeartBeat timer + m_oTimerCtrl.StopTimer(m_HBTimerID); + FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__, " Timer '%d' stopped", m_HBTimerID); + } + else { + FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, " Error: 'm_HBTimerID' is '0'; unable to stop timer"); + } + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-"); + return l_eStatus; +} + +/***************************************************************************** + @ingroup: SS_SystemManager + @brief: HeartBeatTimerInit + @note: + @param HANDLE - Handle to message queue of HeartBeat Service. + @return EFrameworkunifiedStatus +*****************************************************************************/ +EFrameworkunifiedStatus CHeartBeatThread::HeartBeatTimerInit(HANDLE hThread) { + EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK; + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+"); + + m_oTimerCtrl.Initialize(hThread); + + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-"); + return l_eStatus; +} + +/***************************************************************************** + @ingroup: SS_SystemManager + @brief: HeartBeatTimersDelete + @note: + @param void + @return EFrameworkunifiedStatus +*****************************************************************************/ +EFrameworkunifiedStatus CHeartBeatThread::HeartBeatTimersDelete() {// LCOV_EXCL_START 14: Resident process, not called by NSFW + EFrameworkunifiedStatus l_eStatus; + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+"); + + if (0 == m_HBTimerID) { + FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, " Error: 'm_HBTimerID' is '0'; unable to delete timer"); + l_eStatus = eFrameworkunifiedStatusInvldParam; + } else { + // Delete Heart Beat timer + UI_32 l_TimerID = m_oTimerCtrl.DeleteTimer(m_HBTimerID); + if (0 == l_TimerID) { + l_eStatus = eFrameworkunifiedStatusDbRecNotFound; + LOG_ERROR("m_oTimerCtrl.DeleteTimer(m_HBTimerID)"); // LCOV_EXCL_BR_LINE 15: marco defined in ss_templates.h // NOLINT(whitespace/line_length) + } else { + l_eStatus = eFrameworkunifiedStatusOK; + FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__, " Successful"); + } + m_HBTimerID = 0; + } + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-"); + return l_eStatus; +}// LCOV_EXCL_STOP + +/***************************************************************************** + @ingroup: SS_SystemManager + @brief: HBCheckHeartBeatResponses + @note: This function checks heartbeat responses and generates a summary + report for System Manager if one or more modules have failed to + reply within the configured maximum number of heartbeat retries. + @param HANDLE - Handle to message queue of HeartBeat Service. + @return EFrameworkunifiedStatus +*****************************************************************************/ +EFrameworkunifiedStatus CHeartBeatThread::HBCheckHeartBeatResponses(HANDLE hThread) { + EFrameworkunifiedStatus l_eStatus; + THbReportData f_tReportData; + FRAMEWORKUNIFIEDLOG(ZONE_PERIODIC_FUNC, __FUNCTION__, "+"); + + l_eStatus = m_oSessionHandler.HBCheckResponses(f_tReportData, + m_HBConfigParams.MaxHeartBeatRetryCount, + m_HBConfigParams.ApplicationHeartBeatIntervalRepeat, + m_NextChkIndex); + if (l_eStatus == eFrameworkunifiedStatusFail) { // Send a heartbeat report ONLY if a heartbeat failure is detected. + // send report to system manager + l_eStatus = FrameworkunifiedSendParent(hThread, + SS_HEARTBEAT_ERROR_DETECTED, + sizeof(f_tReportData), + &f_tReportData); + LOG_STATUS_IF_ERRORED(l_eStatus, "FrameworkunifiedSendParent(SS_HEARTBEAT_ERROR_DETECTED)"); // LCOV_EXCL_BR_LINE 15: marco defined in ss_templates.h // NOLINT(whitespace/line_length) + } + FRAMEWORKUNIFIEDLOG0(ZONE_PERIODIC_FUNC, __FUNCTION__, "-"); + return l_eStatus; +} + +/***************************************************************************** + @ingroup: SS_SystemManager + @brief: HBSendRequest + @note: . + @param HANDLE - Handle to message queue of HeartBeat Service. + @return EFrameworkunifiedStatus +*****************************************************************************/ +EFrameworkunifiedStatus CHeartBeatThread::HBSendRequest(HANDLE hThread) { + EFrameworkunifiedStatus l_eStatus; + + CALL_AND_LOG_STATUS_IF_ERRORED( // LCOV_EXCL_BR_LINE 15: marco defined in ss_templates.h // NOLINT(whitespace/line_length) + m_oSessionHandler.HBSendRequest(hThread, m_HBConfigParams.ApplicationHeartBeatIntervalRepeat, m_NextChkIndex)); // LCOV_EXCL_BR_LINE 15: marco defined in ss_templates.h // NOLINT(whitespace/line_length) + + m_NextChkIndex++; + if (m_HBConfigParams.ApplicationHeartBeatIntervalRepeat <= m_NextChkIndex) { + m_NextChkIndex = 0; + } + + return l_eStatus; +} + +/***************************************************************************** + @ingroup: SS_SystemManager + @brief: HBOnPrintConnections + @note: .Prints all active sessions connected to HeartBeat + @param HANDLE hThread + @return EFrameworkunifiedStatus +*****************************************************************************/ +EFrameworkunifiedStatus CHeartBeatThread::HBOnPrintConnections(HANDLE hThread) { + EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK; + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+"); + + m_oSessionHandler.HBPrintConnection(); + + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-"); + return l_eStatus; +} + +/***************************************************************************** + @ingroup: SS_SystemManager + @brief: HBOnPrintStack + @note: . Prints all sessions connected to HeartBeat + @param HANDLE - Handle to message queue of HeartBeat Service. + @return EFrameworkunifiedStatus +*****************************************************************************/ +EFrameworkunifiedStatus CHeartBeatThread::HBOnPrintStack(HANDLE hThread) { + EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK; + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+"); + + m_oSessionHandler.HBPrintStack(m_HBConfigParams.MaxHeartBeatRetryCount); + + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-"); + return l_eStatus; +} diff --git a/video_in_hal/systemservice/system_manager/server/src/processlauncher/ProcessLauncher.cpp b/video_in_hal/systemservice/system_manager/server/src/processlauncher/ProcessLauncher.cpp new file mode 100755 index 0000000..6b709fe --- /dev/null +++ b/video_in_hal/systemservice/system_manager/server/src/processlauncher/ProcessLauncher.cpp @@ -0,0 +1,317 @@ +/* + * @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_SystemManager +/// \brief This file provides support for process launching and termination. +/// +/////////////////////////////////////////////////////////////////////////////// +#include <native_service/frameworkunified_framework_if.h> +#include <native_service/frameworkunified_multithreading.h> +#include <system_service/ss_templates.h> +#include <system_service/ss_string_maps.h> +#include <native_service/ns_plogger_if.h> +#include <string> + +#include "ProcessLauncher.h" +#include "ss_sm_process_launcher_protocol.h" +#include "ss_sm_process_launcher.h" +#include "ss_sm_systemmanagerlog.h" +#include "ss_sm_signals.h" + +CProcessLauncher::CProcessLauncher() { // LCOV_EXCL_START 8: dead code + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert +} +// LCOV_EXCL_STOP + +CProcessLauncher::CProcessLauncher(void *) { +} + +CProcessLauncher::~CProcessLauncher() { // LCOV_EXCL_START 14: resident process end + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + m_mapOfProcesses.clear(); +} +// LCOV_EXCL_STOP + +EFrameworkunifiedStatus CProcessLauncher::PLTerminateModule( + HANDLE hThread, + T_ProcessLauncherTerminationResp *f_pTerminateRespData) { + EFrameworkunifiedStatus l_eStatus; + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+"); + + T_ProcessLauncherTerminationReq l_ModuleTerminateReq; + + // LCOV_EXCL_BR_START 4:NSFW error case + if (eFrameworkunifiedStatusOK + != (l_eStatus = ReadMsg < T_ProcessLauncherTerminationReq > (hThread, l_ModuleTerminateReq, eSMRRetain))) { + // LCOV_EXCL_BR_STOP + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + LOG_ERROR("ReadMsg()"); // LCOV_EXCL_LINE 4:NSFW error case + } else { + // get pointer to the process object launched earlier + Process * l_pProcessPtr = m_mapOfProcesses[l_ModuleTerminateReq.path]; // LCOV_EXCL_BR_LINE 11:unexpected branch // NOLINT(whitespace/line_length) + + // Confirm that the process pointer for the module exists in the map + if (NULL != l_pProcessPtr) { // LCOV_EXCL_BR_LINE 200: l_pProcessPtr must not be null + // check if process still exists + if (l_pProcessPtr->DoesProcessExist()) { + FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__, + " Terminating %s, PID: %d.", l_ModuleTerminateReq.path, l_pProcessPtr->GetProcessId()); + // kill unresponsive process + l_pProcessPtr->KillProcess(SS_SM_ABORT_SIGNAL); + + if (NULL != f_pTerminateRespData) { // LCOV_EXCL_BR_LINE 200: f_pTerminateRespData must not be null + std::strcpy(f_pTerminateRespData->name, // NOLINT + l_ModuleTerminateReq.name); + std::strcpy(f_pTerminateRespData->path, // NOLINT + l_ModuleTerminateReq.path); + std::strcpy(f_pTerminateRespData->args, // NOLINT + l_ModuleTerminateReq.args); + f_pTerminateRespData->moduleIterator = + l_ModuleTerminateReq.moduleIterator; + f_pTerminateRespData->groupIterator = + l_ModuleTerminateReq.groupIterator; + } + } else { + FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__, " Info: %s has already terminated.", l_ModuleTerminateReq.path); + + l_eStatus = eFrameworkunifiedStatusServNotFound; + } + // remove process entry + m_mapOfProcesses.erase(l_ModuleTerminateReq.path); + // delete process object + delete l_pProcessPtr; // LCOV_EXCL_BR_LINE 11:unexpected branch // NOLINT(whitespace/line_length) + } else { // LCOV_EXCL_BR_LINE 200: l_pProcessPtr will not be null + // LCOV_EXCL_START 200: l_pProcessPtr will not be null + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + l_eStatus = eFrameworkunifiedStatusDbRecNotFound; + FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, " Error: %s not in m_mapOfProcesses", l_ModuleTerminateReq.path); + // LCOV_EXCL_STOP + } + } + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-"); + return l_eStatus; +} + +EFrameworkunifiedStatus CProcessLauncher::PLOnCmdTerminateModule(HANDLE hThread) { + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+"); + EFrameworkunifiedStatus l_eStatus; + + T_ProcessLauncherTerminationResp l_TerminateRespData; + if (eFrameworkunifiedStatusOK == (l_eStatus = PLTerminateModule(hThread, &l_TerminateRespData))) { + // reply to System Manager about successful module termination + l_eStatus = FrameworkunifiedSendParent(hThread, + ePLThrdCmd_TERMINATE_MODULE_RESP, + sizeof(l_TerminateRespData), + &l_TerminateRespData); + LOG_STATUS(l_eStatus, "FrameworkunifiedSendParent(ePLThrdCmd_TERMINATE_MODULE_RESP"); // LCOV_EXCL_BR_LINE 15: marco defined in ss_templates.h // NOLINT(whitespace/line_length) + } else if (eFrameworkunifiedStatusServNotFound == l_eStatus) { // Already terminated + FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__, " Info. Module already terminated."); + } else { + FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, + " Error: PLTerminateModule(%s) errored: %d/'%s'", + l_TerminateRespData.name, l_eStatus, GetStr(l_eStatus).c_str()); + } + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-"); + return l_eStatus; +} + +EFrameworkunifiedStatus CProcessLauncher::PLOnCmdModuleStatus(HANDLE hThread) { + return eFrameworkunifiedStatusOK; +} + +VOID buildArgList(StringList& arg_list, PSTR args) { // NOLINT + arg_list.clear(); + char * pch = NULL; + pch = std::strtok(args, " "); + while (pch != NULL) { + arg_list.push_back(pch); + pch = std::strtok(NULL, " "); + } +} + +EFrameworkunifiedStatus CProcessLauncher::PLLaunchModule(HANDLE hThread, T_ProcessLaunchResp &f_LaunchRespData) { + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+"); + EFrameworkunifiedStatus l_eStatus; + Process *l_pProcessPtr = NULL; + T_ProcessLauncherLaunchReq l_ModuleLaunchReq; + + // LCOV_EXCL_BR_START 4:NSFW error case + if (eFrameworkunifiedStatusOK + != (l_eStatus = ReadMsg < T_ProcessLauncherLaunchReq > (hThread, l_ModuleLaunchReq))) { + // LCOV_EXCL_BR_STOP + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + LOG_ERROR("ReadMsg()"); // LCOV_EXCL_LINE 4:NSFW error case + } else { + FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__, + "Sending to Launcher name: %s, path: %s, args: %s, lmsk: %s, " + "prio: %d ", l_ModuleLaunchReq.name, + l_ModuleLaunchReq.path, l_ModuleLaunchReq.args, + l_ModuleLaunchReq.logging_mask, l_ModuleLaunchReq.priority); + + StringList args; + buildArgList(args, l_ModuleLaunchReq.args); // LCOV_EXCL_BR_LINE 15: marco defined in ns_logger_if.h // NOLINT(whitespace/line_length) + + int log_mask_str_len = static_cast<int>(std::strlen(l_ModuleLaunchReq.logging_mask)); + if (log_mask_str_len > 0) { + // Create mask argument to be passed to application. + // The argument must be of the form "-m 0x00000000,0x00000000,...", assuming n 32-bit mask values. + // The storage size of the argument must include one byte for the NULL termination character. + args.push_back("-m"); + args.push_back(l_ModuleLaunchReq.logging_mask); + FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__, " %s args: logging_mask: %s", + l_ModuleLaunchReq.path, l_ModuleLaunchReq.logging_mask); + } else { + FRAMEWORKUNIFIEDLOG(ZONE_PROC_LAUNCH_INFO, __FUNCTION__, + " '%s' has no logging_mask specified. Using compile time defaults.", + l_ModuleLaunchReq.path); + } + + std::strcpy(f_LaunchRespData.name, l_ModuleLaunchReq.name); // NOLINT Module queue name + std::strcpy(f_LaunchRespData.path, l_ModuleLaunchReq.path); // NOLINT Module path and file name + std::strcpy(f_LaunchRespData.args, l_ModuleLaunchReq.args); // NOLINT + f_LaunchRespData.moduleIterator = l_ModuleLaunchReq.moduleIterator; + f_LaunchRespData.groupIterator = l_ModuleLaunchReq.groupIterator; + + // Process exists? If not, re-launch the process and create a new map entry. + l_pProcessPtr = m_mapOfProcesses[l_ModuleLaunchReq.path]; // LCOV_EXCL_BR_LINE 11:unexpected branch // NOLINT(whitespace/line_length) + if (NULL == l_pProcessPtr) { // LCOV_EXCL_BR_LINE 200: l_pProcessPtr must not be null + FRAMEWORKUNIFIEDLOG(ZONE_PROC_LAUNCH_INFO, __FUNCTION__, + " '%s' is not in the module map. Creating new process.", + l_ModuleLaunchReq.name); + + SS_String sPathAndFileName = l_ModuleLaunchReq.path; // LCOV_EXCL_BR_LINE 11:unexpected branch // NOLINT(whitespace/line_length) + l_pProcessPtr = new (std::nothrow) Process(l_ModuleLaunchReq.cpu_assign); // LCOV_EXCL_BR_LINE 11:unexpected branch // NOLINT(whitespace/line_length) + + if (NULL == l_pProcessPtr) { // LCOV_EXCL_BR_LINE 11::new operation failed + // LCOV_EXCL_START 11::new operation failed + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, " Error: Process() returned NULL"); + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-"); + return eFrameworkunifiedStatusThreadNotExist; + // LCOV_EXCL_STOP 11::new operation failed + } + + const char* uname = + ('\0' == f_LaunchRespData.moduleIterator->unix_user_name[0]) ? + NULL : &f_LaunchRespData.moduleIterator->unix_user_name[0]; // LCOV_EXCL_BR_LINE 11:unexpected branch // NOLINT(whitespace/line_length) + + l_pProcessPtr->CreateProcess(sPathAndFileName, "", l_ModuleLaunchReq.priority, args, uname); // LCOV_EXCL_BR_LINE 11:unexpected branch // NOLINT(whitespace/line_length) + + FRAMEWORKUNIFIEDLOG(ZONE_PROC_LAUNCH_INFO, __FUNCTION__, + " Process Name: %s Process File: %s Pid: %d Is Alive: %s\n", + l_pProcessPtr->GetProcessName().data(), + l_pProcessPtr->GetExecutableFileName(), + l_pProcessPtr->GetProcessId(), + (l_pProcessPtr->DoesProcessExist() == FALSE) ? "No" : "Yes"); + + // Add the process in the map + m_mapOfProcesses[l_ModuleLaunchReq.path] = l_pProcessPtr; // LCOV_EXCL_BR_LINE 11:unexpected branch // NOLINT(whitespace/line_length) + + // launch response + f_LaunchRespData.pid = l_pProcessPtr->GetProcessId(); + f_LaunchRespData.priority = l_pProcessPtr->GetPriority(); // LCOV_EXCL_BR_LINE 11:unexpected branch // NOLINT(whitespace/line_length) + l_eStatus = eFrameworkunifiedStatusOK; + } else { + // LCOV_EXCL_START 200: l_pProcessPtr must not be null + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + FRAMEWORKUNIFIEDLOG(ZONE_PROC_LAUNCH_INFO, __FUNCTION__, + " %s already in Process Map", l_ModuleLaunchReq.name); + // the module is already in the list. Send the response to system manager with PID 0x7FFFFFFF + f_LaunchRespData.pid = 0x7FFFFFFF; + f_LaunchRespData.priority = l_ModuleLaunchReq.priority; + l_eStatus = eFrameworkunifiedStatusOK; + // LCOV_EXCL_STOP + } + } + + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-"); + return l_eStatus; +} + +EFrameworkunifiedStatus CProcessLauncher::PLOnCmdLaunchModule(HANDLE hThread) { + EFrameworkunifiedStatus l_eStatus; + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+"); + + l_eStatus = PLCmdLaunchModule(hThread, ePLThrdCmd_LAUNCH_MODULE_RESP, "ePLThrdCmd_LAUNCH_MODULE_RESP"); // LCOV_EXCL_BR_LINE 11:unexpected branch // NOLINT(whitespace/line_length) + LOG_STATUS_IF_ERRORED(l_eStatus, " PLCmdLaunchModule(ePLThrdCmd_LAUNCH_MODULE_RESP)"); // LCOV_EXCL_BR_LINE 11:unexpected branch // NOLINT(whitespace/line_length) + + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-"); + return l_eStatus; +} + +EFrameworkunifiedStatus CProcessLauncher::PLOnCmdRelaunchModule(HANDLE hThread) { + EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK; + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+"); + + // Terminate unresponsive module + CALL_AND_LOG_STATUS(PLTerminateModule(hThread)); // LCOV_EXCL_BR_LINE 15: marco defined in ss_templates.h // NOLINT(whitespace/line_length) + + l_eStatus = PLCmdLaunchModule(hThread, ePLThrdCmd_RELAUNCH_MODULE_RESP, "ePLThrdCmd_RELAUNCH_MODULE_RESP"); // LCOV_EXCL_BR_LINE 11:unexpected branch // NOLINT(whitespace/line_length) + LOG_STATUS_IF_ERRORED(l_eStatus, "PLCmdLaunchModule(ePLThrdCmd_RELAUNCH_MODULE_RESP)"); // LCOV_EXCL_BR_LINE 15: marco defined in ss_templates.h // NOLINT(whitespace/line_length) + + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-"); + return l_eStatus; +} + +EFrameworkunifiedStatus CProcessLauncher::PLCmdLaunchModule(HANDLE hThread, UI_32 f_protocol_ID, std::string f_protocol_str) { + EFrameworkunifiedStatus l_eStatus; + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+"); + + T_ProcessLaunchResp l_LaunchRespData; + l_LaunchRespData.pid = 0; + if (eFrameworkunifiedStatusOK != (l_eStatus = PLLaunchModule(hThread, l_LaunchRespData))) { // 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: PLLaunchModule(%s, %s) errored: %d/'%s'", + l_LaunchRespData.name, f_protocol_str.c_str(), l_eStatus, + GetStr(l_eStatus).c_str()); + // LCOV_EXCL_STOP 4:NSFW error case + } else { + l_eStatus = FrameworkunifiedSendParent(hThread, f_protocol_ID, + sizeof(T_ProcessLaunchResp), &l_LaunchRespData); + + 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: FrameworkunifiedSendParent( %s, %s ) errored: %d/'%s'", + l_LaunchRespData.name, f_protocol_str.c_str(), l_eStatus, + GetStr(l_eStatus).c_str()); + // LCOV_EXCL_STOP 4:NSFW + } + } + + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-"); + return l_eStatus; +} + +EFrameworkunifiedStatus CProcessLauncher::PLOnCmdStop(HANDLE hThread) { // LCOV_EXCL_START 14: resident process end + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + return eFrameworkunifiedStatusOK; +} +// LCOV_EXCL_STOP + +EFrameworkunifiedStatus CProcessLauncher::PLOnCmdStart(HANDLE hThread) { + return eFrameworkunifiedStatusOK; +} + +EFrameworkunifiedStatus CProcessLauncher::PLOnCmdHeartbeatStatusReq(HANDLE hThread) { + FrameworkunifiedSendParent(hThread, ePLThrdCmd_THREAD_STATUS_RESP, 0, NULL); + return eFrameworkunifiedStatusOK; +} + diff --git a/video_in_hal/systemservice/system_manager/server/src/processlauncher/ProcessLauncher_if.cpp b/video_in_hal/systemservice/system_manager/server/src/processlauncher/ProcessLauncher_if.cpp new file mode 100755 index 0000000..3d9b2e9 --- /dev/null +++ b/video_in_hal/systemservice/system_manager/server/src/processlauncher/ProcessLauncher_if.cpp @@ -0,0 +1,126 @@ +/* + * @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_SystemManager +/// \brief This file provides support for process launching and termination. +/// +/////////////////////////////////////////////////////////////////////////////// +#include <native_service/frameworkunified_framework_if.h> + +#include "ProcessLauncher.h" +#include "ss_sm_process_launcher_protocol.h" +#include "ss_sm_systemmanagerlog.h" + +template<typename C, eFrameworkunifiedStatus (C::*M)(HANDLE)> EFrameworkunifiedStatus ProcessLauncherCallback(HANDLE hThread) { + EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK; + + C * pObj = static_cast<C *>(FrameworkunifiedGetThreadSpecificData(hThread)); + + if (pObj) { // LCOV_EXCL_BR_LINE 5:pObj must not be NULL + l_eStatus = (pObj->*M)(hThread); + } + + return l_eStatus; +} + +EFrameworkunifiedStatus ProcessLauncherOnStart(HANDLE hThread) { + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+"); + EFrameworkunifiedStatus l_eStatus; + CProcessLauncher * pObj = new (std::nothrow) CProcessLauncher(NULL); // LCOV_EXCL_BR_LINE 11:unexpected branch // NOLINT(whitespace/line_length) + + if (pObj) { // LCOV_EXCL_BR_LINE 5:new error + // LCOV_EXCL_BR_START 200:l_eStatus always return eFrameworkunifiedStatusOK + if (eFrameworkunifiedStatusOK != (l_eStatus = pObj->PLOnCmdStart(hThread))) { + // LCOV_EXCL_BR_STOP + // LCOV_EXCL_START 200:l_eStatus always return eFrameworkunifiedStatusOK + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, + " Error: pObj->PLOnCmdStart(hThread) errored: %d/'%s'", + l_eStatus, GetStr(l_eStatus).c_str()); + // LCOV_EXCL_STOP + } else { + FrameworkunifiedSetThreadSpecificData(hThread, pObj); + + FrameworkunifiedProtocolCallbackHandler aParentHandlers[] = { { + ePLThrdCmd_LAUNCH_MODULE_REQST, ProcessLauncherCallback< + CProcessLauncher, + &CProcessLauncher::PLOnCmdLaunchModule> }, { + ePLThrdCmd_TERMINATE_MODULE_REQST, ProcessLauncherCallback< + CProcessLauncher, + &CProcessLauncher::PLOnCmdTerminateModule> }, { + ePLThrdCmd_RELAUNCH_MODULE_REQST, ProcessLauncherCallback< + CProcessLauncher, + &CProcessLauncher::PLOnCmdRelaunchModule> }, { + ePLThrdCmd_MODULE_STATUS_REQST, ProcessLauncherCallback< + CProcessLauncher, + &CProcessLauncher::PLOnCmdModuleStatus> }, { + ePLThrdCmd_THREAD_STATUS_REQST, ProcessLauncherCallback< + CProcessLauncher, + &CProcessLauncher::PLOnCmdHeartbeatStatusReq> } }; // LCOV_EXCL_BR_LINE 11:unexpected branch // NOLINT(whitespace/line_length) + + // LCOV_EXCL_BR_START 4:NSFW error case + if (eFrameworkunifiedStatusOK + != (l_eStatus = FrameworkunifiedAttachParentCallbacksToDispatcher(hThread, aParentHandlers, + static_cast<UI_32>(_countof(aParentHandlers))))) { + // LCOV_EXCL_BR_STOP + // LCOV_EXCL_START 4:NSFW error case + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, + " Error: FrameworkunifiedAttachParentCallbacksToDispatcher() errored: %d/'%s'", + l_eStatus, GetStr(l_eStatus).c_str()); + // LCOV_EXCL_STOP + } else { + // Add other Attaches here!!! + } + } + } else { // LCOV_EXCL_BR_LINE 5::new operation failed + // LCOV_EXCL_START 5:new error + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, " Error: new CProcessLauncher( NULL ) returned NULL"); + l_eStatus = eFrameworkunifiedStatusNullPointer; + // LCOV_EXCL_STOP + } + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-"); + return l_eStatus; +} + +// LCOV_EXCL_START 200:Thread which registered in init_process_launcher() is never stoppped. +EFrameworkunifiedStatus ProcessLauncherOnStop(HANDLE hThread) { + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+"); + EFrameworkunifiedStatus l_eStatus; + CProcessLauncher * pObj = static_cast<CProcessLauncher *>(FrameworkunifiedGetThreadSpecificData(hThread)); + + if (pObj) { + if (eFrameworkunifiedStatusOK != (l_eStatus = pObj->PLOnCmdStop(hThread))) { + LOG_ERROR("PLOnCmdStop()"); // LCOV_EXCL_BR_LINE 15: marco defined in ss_templates.h // NOLINT(whitespace/line_length) + } + delete pObj; + pObj = NULL; + } + + FrameworkunifiedSetThreadSpecificData(hThread, NULL); + + if (eFrameworkunifiedStatusOK != (l_eStatus = FrameworkunifiedDetachServiceFromDispatcher(hThread, FrameworkunifiedGetAppName(hThread)))) { + LOG_ERROR("FrameworkunifiedDetachServiceFromDispatcher()"); // LCOV_EXCL_BR_LINE 15: marco defined in ss_templates.h // NOLINT(whitespace/line_length) + } + + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-"); + return l_eStatus; +} +// LCOV_EXCL_STOP + diff --git a/video_in_hal/systemservice/system_manager/server/src/ss_sm_config.cpp b/video_in_hal/systemservice/system_manager/server/src/ss_sm_config.cpp new file mode 100755 index 0000000..2a8d11e --- /dev/null +++ b/video_in_hal/systemservice/system_manager/server/src/ss_sm_config.cpp @@ -0,0 +1,1528 @@ +/* + * @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_SystemManager +/// \brief This file provides support for System Manager configuration. +/// +/////////////////////////////////////////////////////////////////////////////// + +#include <boost/algorithm/string.hpp> + + +#include <other_service/PosixBasedOS001ClockCycleApi.h> +#include <other_service/ultoa.h> +#include <native_service/frameworkunified_framework_if.h> +#include <system_service/ss_string_maps.h> +#include <system_service/ss_templates.h> +#include <native_service/ns_config_parser_if.h> +#include <errno.h> +#include <sys/time.h> +#include <sys/resource.h> +#include <cctype> +#include <string> +#include <iomanip> +#include <fstream> +#include <iostream> +#include <sstream> +#include <algorithm> +#include <functional> +#include <list> +#include <vector> +#include <utility> + +#include "ss_sm_config.h" +#include "ss_sm_systemmanagerlog.h" +#include "ss_sm_launch_configuration.h" +#include "system_launcher_cfg_format.h" +#include "ss_sm_default_paths.h" + +using namespace std; // NOLINT + +// Constants for Heart Beat configuration data +const UI_32 HBApplicationHeartBeatIntervalInitial = 40u; // Units of seconds. 0 = HB Disabled. +const UI_32 HBApplicationHeartBeatIntervalRepeat = 5u; // Units of seconds. 0 = HB Disabled. +const UI_32 HBMaxHeartBeatRetryCount = 3u; + +// Constants for Crash Detector configuration data +const BOOL CDEnabled = TRUE; + +// Constants for system low memory configuration data + +const UI_32 SLMTimerValue = 5000; // msec +const UI_32 SLMThresholdValue = (1024 * 512); // bytes +const UI_32 SLMRetryCount = 6; +const UI_32 SLMSystemmanagerLogIntervalMs = 30000; + +// Constants for Module connect time and Stat Resp Time + +const UI_32 ModuleConnectionNumTimesToCheck = 5; +const UI_32 ModuleConnectionTimeOutSec = 5; // sec +const UI_32 ModuleStartRespTimeOutSec = 120; // sec + +// Constants for Critical Apps Max wait timeout + +const UI_32 CriticalAppsMaxShutdownTimeFastSleepSec = 2; // sec +const UI_32 CriticalAppsMaxShutdownTimeNormalResetSec = 15; // sec + +// Constants for User Mode data structure type +const BOOL isBoolean = TRUE; + +const CHAR SMConfigDataHeader[] = "SystemManager"; +const CHAR HBConfigDataHeader[] = "HeartBeat"; +const CHAR CDConfigDataHeader[] = "CrashDetector"; +const CHAR SLMConfigDataHeader[] = "SysLowMemory"; +const CHAR UserModeConfigDataHeader[] = "UserMode"; + +struct CfgLaunchParams { + CfgLaunchParams() : + group_id(0), + group_launch_wait(0), + group_wait_for_trigger(0), + priority(0), + critical(0), + retry_cnt(0), + is_start_required(0), + shutdown_critical(0), + shutdown_wait_time(0), + fast_shutdown_wait_time(0), + cpu_assign(0x0), + is_agl_unit(TRUE), + disable_agl_resethistory(FALSE), + disable_nonagl_resethistory(FALSE) { + std::memset(&group_name[0], 0, sizeof(group_name)); + std::memset(&name[0], 0, sizeof(name)); + std::memset(&binary_name[0], 0, sizeof(binary_name)); + std::memset(&arguments[0], 0, sizeof(arguments)); + std::memset(&logging_msk_str[0], 0, sizeof(logging_msk_str)); + std::memset(&restart[0], 0, sizeof(restart)); + std::memset(&unix_user_name[0], 0, sizeof(unix_user_name)); + std::memset(&env_value_condition[0], 0, sizeof(env_value_condition)); + } + + CHAR group_name[100]; + UI_32 group_id; + UI_32 group_launch_wait; + BOOL group_wait_for_trigger; + CHAR name[100]; + CHAR binary_name[MAX_PATH_LENGTH]; + UI_32 priority; + BOOL critical; + UI_32 retry_cnt; + CHAR arguments[512]; + CHAR logging_msk_str[50]; + CHAR restart[32]; + BOOL is_start_required; + BOOL shutdown_critical; + UI_32 shutdown_wait_time; + UI_32 fast_shutdown_wait_time; + TUserNameBuffer unix_user_name; // TODO(username): Stuff.: Does Posix define a useful + // constant representing max length of user id? + CHAR env_value_condition[256]; + int cpu_assign; + + public: + BOOL IsAGLUnit(void) const { return is_agl_unit; } + BOOL IsAGLResetHistoryDisable(void) const { return disable_agl_resethistory; } + BOOL IsNonAGLResetHistoryDisable(void) const { return disable_nonagl_resethistory; } + void SetAGLUnit(BOOL f_is_agl_unit) { is_agl_unit = f_is_agl_unit; } + void SetAGLResetHistoryDisable(BOOL f_disable_agl_resethistory) { + disable_agl_resethistory = f_disable_agl_resethistory; + } + void SetNonAGLResetHisoryDisable(BOOL f_disable_nonagl_resethistory) { + disable_nonagl_resethistory = f_disable_nonagl_resethistory; + } + + private: + BOOL is_agl_unit; + BOOL disable_agl_resethistory; + BOOL disable_nonagl_resethistory; +}; + +namespace ss_sm_cfg { +class cfg_args { + public: + enum { // typedef enum _tokens + group_name, + group_id, + group_launch_wait, + group_wait_for_trigger, + name, + binary_name, + priority, + critical, + retry_cnt, + arguments, + logging_msk, + restart, + is_start_required, + shutdown_critical, + shutdown_wait_time, + fast_shutdown_wait_time, + unix_user_name, + is_agl_unit, + disable_agl_resethistory, + disable_nonagl_resethistory, + env_value_condition, + cpu_assign, + END + }; +}; +}; // namespace ss_sm_cfg + +static void set_grp_member_info(const LaunchInfo& launch_info, ModuleLaunchList& module_lst); // NOLINT +static void load_parameters_order_cfg( + GroupLaunchMap& groups_map, LaunchOrderedVector& f_OrderList, SS_String& f_launchOrderName, SS_String& f_launchCfgFn); // NOLINT + +/******************************************************************************* + * CTimeSpan class * + * * + * Set Initial time, reset Final and Delta to zero, return time * + * */ +UI_64 CTimeSpan::Begin() { + initial = GetTimeMilliseconds(); + final = 0; + delta = 0; + return initial; +} // End of UI_64 CTimeSpan::Begin() + +/* + * Set Final time, calculate Delta time, return time + */ +UI_64 CTimeSpan::End() { + final = GetTimeMilliseconds(); + delta = (final > initial) ? (final - initial) : 0; // LCOV_EXCL_BR_LINE 11:unexpected branch // NOLINT(whitespace/line_length) + return final; +} // End of UI_64 CTimeSpan::End() + +UI_64 CTimeSpan::GetInitial(void) { + return initial; +} + +UI_64 CTimeSpan::GetFinal() { + return final; +} + +UI_64 CTimeSpan::GetDelta() { + return delta; +} + +UI_64 CTimeSpan::GetTimeMilliseconds() { + UI_64 l_totalmsec = 0; + struct timespec timeSpec; + + if (0 != clock_gettime(CLOCK_MONOTONIC, &timeSpec)) { + SS_ASERT_ERRNO(0); // LCOV_EXCL_BR_LINE 15: marco defined in ss_templates.h // NOLINT(whitespace/line_length) + } else { + l_totalmsec = (timeSpec.tv_sec * 1000ULL) + + (timeSpec.tv_nsec / 1000000); + } + + return l_totalmsec; +} + +/* * + * End of CTimeSpan class * + ******************************************************************************/ + +ModuleLaunchParams::ModuleLaunchParams(): + name("") + , path("") + , arguments("") + , restart("") + , configuration_priority(0) + , cpu_assign(0x0) + , previous_priority(0) + , current_priority(0) + , critical(FALSE) + , retry_cnt(0) + , logging_msk_str("") + , is_start_required(FALSE) + , shutdown_critical(FALSE) + , shutdown_wait_time(0) + , fast_shutdown_wait_time(0) + , pid(0) + , hsession(NULL) + , relaunch_count(0) + , relaunch_status(NotRelaunched) + , group_id(0xFFFF) + , m_serviceAvailability(FALSE) + , m_startReason() + , m_stopReason() + , m_ModuleDebugDumpState(MODULE_DEBUG_DUMP_STATE_NOT_REQUESTED) + , is_agl_unit(TRUE) + , disable_agl_resethistory(FALSE) + , disable_nonagl_resethistory(FALSE) { // LCOV_EXCL_BR_START 11:Gcov constraints (because exception-handling routes are automatically generated) + SetModuleState(MODULE_STATE_INVALID, FALSE); + // + // Module State strings + m_ModuleStateStrMap[MODULE_STATE_INVALID] = "INVALID"; + m_ModuleStateStrMap[MODULE_STATE_SKIPPED] = "SKIPPED"; + m_ModuleStateStrMap[MODULE_STATE_LAUNCHING] = "LAUNCHING"; + m_ModuleStateStrMap[MODULE_STATE_LAUNCHED] = "LAUNCHED"; + m_ModuleStateStrMap[MODULE_STATE_LAUNCH_FAILED] = "LAUNCH_FAIL"; + m_ModuleStateStrMap[MODULE_STATE_CONNECTED] = "CONNECTED"; + m_ModuleStateStrMap[MODULE_STATE_START_SENT] = "START_SENT"; + m_ModuleStateStrMap[MODULE_STATE_START_FAILED] = "START_FAIL"; + m_ModuleStateStrMap[MODULE_STATE_STARTED] = "STARTED"; + m_ModuleStateStrMap[MODULE_STATE_STOP_FAILED] = "STOP_FAIL"; + m_ModuleStateStrMap[MODULE_STATE_STOP_SENT] = "STOP_SENT"; + m_ModuleStateStrMap[MODULE_STATE_STOPPED] = "STOPPED"; + m_ModuleStateStrMap[MODULE_STATE_START_PRE_SENT] = "PRE_START_SENT"; + m_ModuleStateStrMap[MODULE_STATE_START_PRE_FAILED] = "PRE_START_FAIL"; + m_ModuleStateStrMap[MODULE_STATE_STARTED_PRE] = "PRE_STARTED"; + m_ModuleStateStrMap[MODULE_STATE_STOP_PRE_SENT] = "PRE_STOP_SENT"; + m_ModuleStateStrMap[MODULE_STATE_STOP_PRE_FAILED] = "PRE_STOP_FAIL"; + m_ModuleStateStrMap[MODULE_STATE_STOPPED_PRE] = "PRE_STOPPED"; + m_ModuleStateStrMap[MODULE_STATE_START_BACKGROUND_SENT] = "BACKGROUND_START_SENT"; + m_ModuleStateStrMap[MODULE_STATE_START_BACKGROUND_FAILED] = "BACKGROUND_START_FAIL"; + m_ModuleStateStrMap[MODULE_STATE_STARTED_BACKGROUND] = "BACKGROUND_STARTED"; + m_ModuleStateStrMap[MODULE_STATE_STOP_BACKGROUND_SENT] = "BACKGROUND_STOP_SENT"; + m_ModuleStateStrMap[MODULE_STATE_STOP_BACKGROUND_FAILED] = "BACKGROUND_STOP_FAIL"; + m_ModuleStateStrMap[MODULE_STATE_STOPPED_BACKGROUND] = "BACKGROUND_STOPPED"; + // LCOV_EXCL_BR_STOP + + m_startReason.SetReason(NotStarted); + m_stopReason.SetReason(NotStopped); + + MAP_ENTRY(m_ModuleDebugDumpStateStrMap, MODULE_DEBUG_DUMP_STATE_NOT_REQUESTED); // LCOV_EXCL_BR_LINE 15: marco defined in ss_templates.h // NOLINT(whitespace/line_length) + MAP_ENTRY(m_ModuleDebugDumpStateStrMap, MODULE_DEBUG_DUMP_STATE_REQUEST_SENT); // LCOV_EXCL_BR_LINE 15: marco defined in ss_templates.h // NOLINT(whitespace/line_length) + MAP_ENTRY(m_ModuleDebugDumpStateStrMap, MODULE_DEBUG_DUMP_STATE_RESPONSE_RECEIVED); // LCOV_EXCL_BR_LINE 15: marco defined in ss_templates.h // NOLINT(whitespace/line_length) + + std::memset(&unix_user_name[0], 0, sizeof(unix_user_name)); +} // End of ModuleLaunchParams::ModuleLaunchParams() : + +ModuleLaunchParams::~ModuleLaunchParams() { +} // End of ModuleLaunchParams::~ModuleLaunchParams() : + +SMModuleState ModuleLaunchParams::GetModuleState(void) { + return m_moduleState; +} // End of SMModuleState ModuleLaunchParams::GetModuleState(void) + +BOOL ModuleLaunchParams::IsModuleState(SMModuleState f_moduleState) { + return m_moduleState == f_moduleState; +} // End of BOOL ModuleLaunchParams::IsModuleState(SMModuleState f_moduleState ) + +// IsModuleConnected +// Determine if a module is in a state capable of receiving messages from System Manager. +BOOL ModuleLaunchParams::IsModuleConnected() const { + BOOL l_isModuleConnected = FALSE; + + switch (m_moduleState) { + case MODULE_STATE_CONNECTED: + case MODULE_STATE_START_SENT: + case MODULE_STATE_START_FAILED: + case MODULE_STATE_STARTED: + case MODULE_STATE_STOP_SENT: + case MODULE_STATE_STOP_FAILED: + case MODULE_STATE_STOPPED: + case MODULE_STATE_START_PRE_SENT: + case MODULE_STATE_START_PRE_FAILED: + case MODULE_STATE_STARTED_PRE: + case MODULE_STATE_STOP_PRE_SENT: + case MODULE_STATE_STOP_PRE_FAILED: + case MODULE_STATE_STOPPED_PRE: + case MODULE_STATE_START_BACKGROUND_SENT: + case MODULE_STATE_START_BACKGROUND_FAILED: + case MODULE_STATE_STARTED_BACKGROUND: + case MODULE_STATE_STOP_BACKGROUND_SENT: + case MODULE_STATE_STOP_BACKGROUND_FAILED: + case MODULE_STATE_STOPPED_BACKGROUND: + l_isModuleConnected = TRUE; + break; + + default: + l_isModuleConnected = FALSE; + break; + } + + return (l_isModuleConnected); +} // End of BOOL ModuleLaunchParams::IsModuleConnected(void) + +VOID ModuleLaunchParams::SetModuleState(SMModuleState f_moduleState, BOOL f_bLog) { + m_moduleState = f_moduleState; + + switch (m_moduleState) { // Because the module status cannot be changed from the external API + case MODULE_STATE_INVALID: + case MODULE_STATE_SKIPPED: + case MODULE_STATE_LAUNCH_FAILED: + case MODULE_STATE_LAUNCHING: + case MODULE_STATE_LAUNCHED: + case MODULE_STATE_CONNECTED: + break; + case MODULE_STATE_START_SENT: + m_startReason.Begin(); + break; + case MODULE_STATE_START_FAILED: + m_startReason.End(); + m_startReason.SetReason(StartedByModuleStartFail); + break; + case MODULE_STATE_STARTED: + m_startReason.End(); + m_startReason.SetReason(StartedByModuleStartComplete); + break; + + case MODULE_STATE_STOP_SENT: + m_stopReason.Begin(); + break; + + case MODULE_STATE_STOP_FAILED: + m_stopReason.End(); + m_stopReason.SetReason(StoppedByModuleStopFail); + break; + case MODULE_STATE_STOPPED: + m_stopReason.End(); + m_stopReason.SetReason(StoppedByModuleStopComplete); + break; + + case MODULE_STATE_START_PRE_SENT: + m_startReason.Begin(); + break; + case MODULE_STATE_START_PRE_FAILED: + m_startReason.End(); + m_startReason.SetReason(StartedByModulePreStartFail); + break; + case MODULE_STATE_STARTED_PRE: + m_startReason.End(); + m_startReason.SetReason(StartedByModulePreStartComplete); + break; + case MODULE_STATE_STOP_PRE_SENT: + m_stopReason.Begin(); + break; + case MODULE_STATE_STOP_PRE_FAILED: + m_stopReason.End(); + m_stopReason.SetReason(StoppedByModulePreStopFail); + break; + case MODULE_STATE_STOPPED_PRE: + m_stopReason.End(); + m_stopReason.SetReason(StoppedByModulePreStopComplete); + break; + + case MODULE_STATE_START_BACKGROUND_SENT: + m_startReason.Begin(); + break; + case MODULE_STATE_START_BACKGROUND_FAILED: + m_startReason.End(); + m_startReason.SetReason(StartedByModuleBackgroundStartFail); + break; + case MODULE_STATE_STARTED_BACKGROUND: + m_startReason.End(); + m_startReason.SetReason(StartedByModuleBackgroundStartComplete); + break; + case MODULE_STATE_STOP_BACKGROUND_SENT: + m_stopReason.Begin(); + break; + case MODULE_STATE_STOP_BACKGROUND_FAILED: + m_stopReason.End(); + m_stopReason.SetReason(StoppedByModuleBackgroundStopFail); + break; + case MODULE_STATE_STOPPED_BACKGROUND: + m_stopReason.End(); + m_stopReason.SetReason(StoppedByModuleBackgroundStopComplete); + break; + + // default: Don't code a 'default' here - let the compiler + // issue a warning ( set via -Wall or -Wswitch ) when the set of + // enumerations changes - then the maintainer will + // automagically know to update this switch statement. + } + + if (f_bLog) { + char buf[255]; + char *p = buf; + strcpy(p, m_ModuleStateStrMap[m_moduleState].c_str()); // NOLINT + p += m_ModuleStateStrMap[m_moduleState].size(); + strcpy(p, ":"); // NOLINT + p += sizeof(":") - 1; + strcpy(p, name.c_str()); // NOLINT + FRAMEWORKUNIFIEDLOG(ZONE_STATE, __FUNCTION__, buf); + } +} // End of VOID ModuleLaunchParams::SetModuleState(SMModuleState f_moduleState ) + +std::string ModuleLaunchParams::ModuleStateStr(void) { + return m_ModuleStateStrMap[m_moduleState]; +} // End of std::string ModuleLaunchParams::ModuleStateStr(SMModuleState f_moduleState ) + +SMModuleDebugDumpState ModuleLaunchParams::GetModuleDebugDumpState(void) { // LCOV_EXCL_START 6: Because the condition cannot be set // NOLINT(whitespace/line_length) + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + return m_ModuleDebugDumpState; +} // End of SMModuleDebugDumpState ModuleLaunchParams::GetModuleDebugDumpState(void) +// LCOV_EXCL_STOP + +std::string ModuleLaunchParams::GetModuleDebugDumpStateStr(void) { + return m_ModuleDebugDumpStateStrMap[m_ModuleDebugDumpState]; +} // End of std::string ModuleLaunchParams::GetModuleDebugDumpStateStr() + +VOID ModuleLaunchParams::SetModuleDebugDumpState( + SMModuleDebugDumpState f_moduleDebugDumpState, BOOL f_bLog) { + m_ModuleDebugDumpState = f_moduleDebugDumpState; + + if (f_bLog) { // LCOV_EXCL_BR_LINE 200:f_bLog must be TRUE + FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__, " %s set for %s", + GetModuleDebugDumpStateStr().c_str(), name.c_str()); + } +} // End of VOID ModuleLaunchParams::SetModuleDebugDumpState(SMModuleDebugDumpState f_moduleDebugDumpState ) + +EFrameworkunifiedStatus ModuleLaunchParams::SendMsgAndUpdateState( + const UI_32 f_iCmd, const T_SS_SM_START_DataStructType* const f_startData) { + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+"); + char l_cBuf[500] = " Error: char l_cBuf[] not built"; + T_SS_SM_START_DataStructType l_startData; + SMModuleState l_SendSuccess = MODULE_STATE_START_SENT; + SMModuleState l_SendFailed = MODULE_STATE_START_FAILED; + + memcpy(&l_startData, f_startData, sizeof(T_SS_SM_START_DataStructType)); + + switch (relaunch_status) { // LCOV_EXCL_BR_LINE 6: Because all conditions cannot be satisfied from the external API + case NotRelaunched: + // Setting startup information at the first startup + break; + case RelaunchSafe: // LCOV_EXCL_START 6: Because all conditions cannot be satisfied from the external API + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + l_startData.resetStatus = e_SS_SM_RESET_STATUS_NONE; + break; + case RelaunchErr: + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + l_startData.resetStatus = e_SS_SM_RESET_STATUS_NG; + break; + default: + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + SS_ASERT(0); + break; + // LCOV_EXCL_STOP + } + + switch (f_iCmd) { + case SS_SM_PRE_START: + l_SendSuccess = MODULE_STATE_START_PRE_SENT; + l_SendFailed = MODULE_STATE_START_PRE_FAILED; + break; + case SS_SM_PRE_STOP: + l_SendSuccess = MODULE_STATE_STOP_PRE_SENT; + l_SendFailed = MODULE_STATE_STOP_PRE_FAILED; + break; + case SS_SM_BACKGROUND_START: + l_SendSuccess = MODULE_STATE_START_BACKGROUND_SENT; + l_SendFailed = MODULE_STATE_START_BACKGROUND_FAILED; + break; + case SS_SM_BACKGROUND_STOP: + l_SendSuccess = MODULE_STATE_STOP_BACKGROUND_SENT; + l_SendFailed = MODULE_STATE_STOP_BACKGROUND_FAILED; + break; + case SS_SM_START: + default: + l_SendSuccess = MODULE_STATE_START_SENT; + l_SendFailed = MODULE_STATE_START_FAILED; + break; + } + + const EFrameworkunifiedStatus l_eStatus = FrameworkunifiedSendMsg(hsession, f_iCmd, + sizeof(T_SS_SM_START_DataStructType), + static_cast<PCVOID>(&l_startData)); + + // LCOV_EXCL_START 6: As no TRUE is returned + if (IS_ZONE_SET(ZONE_ERR) || IS_ZONE_SET(ZONE_INFO)) { + + snprintf(l_cBuf, sizeof(l_cBuf), "FrameworkunifiedSendMsg(%s, system_manager protocol message, %d/%s)", + name.c_str(), l_startData.startupReason, + GetStr(l_startData.startupReason).c_str()); + } + // LCOV_EXCL_STOP 6:As no TRUE is returned + if (eFrameworkunifiedStatusOK != l_eStatus) { // LCOV_EXCL_BR_LINE 4:NSFW's error + // LCOV_EXCL_START 4:NSFW's error + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + LOG_ERROR(l_cBuf); // LCOV_EXCL_BR_LINE 15: marco defined in ss_templates.h // NOLINT(whitespace/line_length) + SetModuleState(l_SendFailed); + // LCOV_EXCL_STOP + } else { + LOG_SUCCESS(l_cBuf); // LCOV_EXCL_BR_LINE 15: marco defined in ss_templates.h // NOLINT(whitespace/line_length) + SetModuleState(l_SendSuccess); + } + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-"); + return l_eStatus; +} +// End of EFrameworkunifiedStatus ModuleLaunchParams::SendMsgAndUpdateState(T_SS_SM_START_DataStructType const * f_startData) + +EFrameworkunifiedStatus ModuleLaunchParams::SendMsgAndUpdateState( + T_SS_SM_STOP_DataStructType const* f_stopData) { + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+"); + char l_cBuf[500] = " Error: char l_cBuf[] not built"; + EFrameworkunifiedStatus l_eStatus = FrameworkunifiedSendMsg(hsession, SS_SM_STOP, + sizeof(T_SS_SM_STOP_DataStructType), + static_cast<PCVOID>(f_stopData)); + + if (IS_ZONE_SET(ZONE_ERR) || IS_ZONE_SET(ZONE_INFO)) { // LCOV_EXCL_BR_LINE 200:alwasy true + snprintf(l_cBuf, sizeof(l_cBuf), "FrameworkunifiedSendMsg(%s, SS_SM_STOP, %d/%s, " + "Last User Mode: %s)", name.c_str(), + f_stopData->shutdownTrigger, + GetStr(f_stopData->shutdownTrigger).c_str(), + GetStr(f_stopData->lastUserMode).c_str()); + } + if (eFrameworkunifiedStatusOK != l_eStatus) { // LCOV_EXCL_BR_LINE 4:NSFW's error + // LCOV_EXCL_START 4:NSFW's error + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + LOG_ERROR(l_cBuf); // LCOV_EXCL_BR_LINE 15: marco defined in ss_templates.h // NOLINT(whitespace/line_length) + SetModuleState(MODULE_STATE_STOP_FAILED); + // LCOV_EXCL_STOP + } else { + FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__, " %s successful", l_cBuf); + SetModuleState(MODULE_STATE_STOP_SENT); + } + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-"); + return l_eStatus; +} +// End of EFrameworkunifiedStatus ModuleLaunchParams::SendMsgAndUpdateState(T_SS_SM_STOP_DataStructType const * f_stopData) + +EFrameworkunifiedStatus ModuleLaunchParams::GetPriority(UI_32& f_Priority) { + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+"); + EFrameworkunifiedStatus l_eStatus; + + struct sched_param cur_sch_params; + errno = 0; + f_Priority = 0xDEAD; + + if (0 == pid) { // LCOV_EXCL_BR_LINE 200: pid can not be 0 + // LCOV_EXCL_START 200: pid can not be 0 + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + l_eStatus = eFrameworkunifiedStatusInvldParam; + LOG_ERROR("0 == pid"); // LCOV_EXCL_BR_LINE 15: marco defined in ss_templates.h // NOLINT(whitespace/line_length) + // LCOV_EXCL_STOP + } else if (-1 >= sched_getparam(pid, &cur_sch_params)) { // LCOV_EXCL_BR_LINE 5: system function failed + // LCOV_EXCL_START 5: system function failed + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + l_eStatus = eFrameworkunifiedStatusFault; + FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, + " Error: 'sched_getparam( pid %d, &cur_sch_params )' returned -1, " + "strerr() is '%s'", pid, strerror(errno)); + // LCOV_EXCL_STOP + } else { + l_eStatus = eFrameworkunifiedStatusOK; + f_Priority = cur_sch_params.sched_priority; + } + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-"); + return l_eStatus; +} // End of EFrameworkunifiedStatus ModuleLaunchParams::GetPriority (UI_32 & f_Priority ) + +EFrameworkunifiedStatus ModuleLaunchParams::SetPriority(UI_32 f_Priority) { + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+"); + EFrameworkunifiedStatus l_eStatus; + + errno = 0; + + if (99 < f_Priority) { // LCOV_EXCL_BR_LINE 200: priority can not greater than 99 + // LCOV_EXCL_START 200: priority can not greater than 99 + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + l_eStatus = eFrameworkunifiedStatusInvldParam; + FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, " Error: Invalid 'f_Priority' %d/0x%X", + f_Priority, f_Priority); + // LCOV_EXCL_STOP + } else if (0 == pid) { // LCOV_EXCL_BR_LINE 200: pid can not be 0 + // LCOV_EXCL_START 200: pid can not be 0 + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + l_eStatus = eFrameworkunifiedStatusInvldParam; + LOG_ERROR("0 == pid"); // LCOV_EXCL_BR_LINE 15: marco defined in ss_templates.h // NOLINT(whitespace/line_length) + // LCOV_EXCL_STOP + } else { + int rc; + struct sched_param l_schedParam = { }; + l_schedParam.sched_priority = f_Priority; + + if (f_Priority == 0) { // LCOV_EXCL_BR_LINE 200: f_Priority can not be 0 + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + rc = sched_setscheduler(pid, SCHED_OTHER, &l_schedParam); // LCOV_EXCL_LINE 200: f_Priority can not be 0 + } else { + rc = sched_setscheduler(pid, SCHED_FIFO, &l_schedParam); + } + SS_ASERT_ERRNO(0 == rc); // LCOV_EXCL_BR_LINE 15: marco defined in ss_templates.h // NOLINT(whitespace/line_length) + if (rc == 0) { + previous_priority = current_priority; + current_priority = f_Priority; + l_eStatus = eFrameworkunifiedStatusOK; + FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__, + " setprio( %s, pid %d, 'previous_priority' %d -> %d ) successful", + name.c_str(), pid, previous_priority, f_Priority); + } else if (rc == -1) { // LCOV_EXCL_BR_LINE 5: system function failed + // LCOV_EXCL_START 5: system function failed + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + l_eStatus = eFrameworkunifiedStatusFault; + FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, + " setprio( %s, pid %d, 'current_priority' %d -> %d ) returned '-1', strerr() is '%s'", + name.c_str(), pid, current_priority, f_Priority, + strerror(errno)); + // LCOV_EXCL_STOP + } else { // LCOV_EXCL_BR_LINE 5: can not be other value + // LCOV_EXCL_START 5: can not be other value + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + l_eStatus = eFrameworkunifiedStatusFault; + FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, + " setprio( %s, pid %d, 'current_priority' %d -> %d ) returned '%d'; " + "'rc' is neither original priority nor '-1': 'errno' is '%d', strerr() is '%s'", + name.c_str(), pid, current_priority, f_Priority, rc, + errno, strerror(errno)); + // LCOV_EXCL_STOP + } + } + + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-"); + return l_eStatus; +} // End of EFrameworkunifiedStatus ModuleLaunchParams::SetPriority( UI_32 f_Priority ) + +SysMgrConfiguration::SysMgrConfiguration(): +l_pReaderCfg(NULL) { +} + +SysMgrConfiguration::~SysMgrConfiguration() { +} + +static BOOL is_satisfy_env_launch_cond(CHAR *env_cond) { // LCOV_EXCL_START 6: Because the condition cannot be set + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + BOOL l_isSatisfy = FALSE; + BOOL l_isReverse = FALSE; + CHAR *l_pString = NULL; + + FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__, "env_cond [%s]", env_cond); + + if (NULL != (l_pString = strstr(env_cond, "!="))) { + l_isReverse = TRUE; + } else if (NULL == (l_pString = strstr(env_cond, "=="))) { + SS_ASERT(0); + } + + if (NULL != l_pString) { + CHAR *l_pEnv = env_cond; + CHAR *l_pValue = l_pString + 2; + *l_pString = '\0'; + + CHAR *l_pEnvVariable = NULL; + + if (NULL != (l_pEnvVariable = std::getenv(l_pEnv))) { + l_isSatisfy = (0 == strcmp(l_pValue, l_pEnvVariable)) ? TRUE : FALSE; + if (l_isReverse) { + l_isSatisfy = !l_isSatisfy; + } + } + } + + return l_isSatisfy; +} + +static void set_grp_member_info(const LaunchInfo& launch_info, ModuleLaunchList& module_lst) { // NOLINT + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + // Note: the + ModuleLaunchParams grp_member_info; + grp_member_info.name = launch_info.name; + grp_member_info.path = launch_info.binary_name; + grp_member_info.arguments = launch_info.arguments; + grp_member_info.restart = launch_info.restart; + grp_member_info.configuration_priority = launch_info.priority; + grp_member_info.retry_cnt = launch_info.retry_cnt; + grp_member_info.logging_msk_str = launch_info.logging_msk_str; + grp_member_info.critical = launch_info.critical; + grp_member_info.shutdown_critical = launch_info.shutdown_critical; + grp_member_info.shutdown_wait_time = launch_info.shutdown_wait_time; + grp_member_info.group_id = launch_info.group_id; + grp_member_info.is_start_required = launch_info.is_start_required; + grp_member_info.fast_shutdown_wait_time = launch_info.fast_shutdown_wait_time; + grp_member_info.SetAGLUnit(launch_info.IsAGLUnit()); + grp_member_info.SetAGLResetHistoryDisable(launch_info.IsAGLResetHistoryDisable()); + grp_member_info.SetNonAGLResetHisoryDisable(launch_info.IsNonAGLResetHistoryDisable()); + + module_lst.push_back(grp_member_info); +} +// LCOV_EXCL_STOP + +static ModuleLaunchListIter set_cfg_grp_member_info( + const CfgLaunchParams& launch_info, ModuleLaunchList& module_lst) { // NOLINT + ModuleLaunchParams grp_member_info; + ModuleLaunchListIter moduleLaunchListIter; + + grp_member_info.name = launch_info.name; + grp_member_info.path = launch_info.binary_name; + grp_member_info.arguments = ( // LCOV_EXCL_BR_LINE 11:unexpected branch // NOLINT(whitespace/line_length) + std::strcmp(launch_info.arguments, "NULL") == 0 ? "" : launch_info.arguments); + grp_member_info.restart = ( // LCOV_EXCL_BR_LINE 11:unexpected branch // NOLINT(whitespace/line_length) + std::strcmp(launch_info.restart, "NULL") == 0 ? "" : launch_info.restart); + grp_member_info.configuration_priority = launch_info.priority; + grp_member_info.cpu_assign = launch_info.cpu_assign; + grp_member_info.retry_cnt = launch_info.retry_cnt; + grp_member_info.logging_msk_str = ( // LCOV_EXCL_BR_LINE 11:unexpected branch // NOLINT(whitespace/line_length) + std::strcmp(launch_info.logging_msk_str, "NULL") == 0 ? "" : launch_info.logging_msk_str); + + grp_member_info.critical = launch_info.critical; + grp_member_info.shutdown_critical = launch_info.shutdown_critical; + grp_member_info.shutdown_wait_time = launch_info.shutdown_wait_time; + grp_member_info.group_id = launch_info.group_id; + grp_member_info.is_start_required = launch_info.is_start_required; + grp_member_info.fast_shutdown_wait_time = launch_info.fast_shutdown_wait_time; + grp_member_info.SetAGLUnit(launch_info.IsAGLUnit()); + grp_member_info.SetAGLResetHistoryDisable(launch_info.IsAGLResetHistoryDisable()); + grp_member_info.SetNonAGLResetHisoryDisable(launch_info.IsNonAGLResetHistoryDisable()); + + strncpy(&grp_member_info.unix_user_name[0], &launch_info.unix_user_name[0], + sizeof(TUserNameBuffer)); + + moduleLaunchListIter = module_lst.insert(module_lst.end(), grp_member_info); + return (moduleLaunchListIter); +} + +static void load_parameters_order_cfg(GroupLaunchMap& groups_map, // NOLINT + LaunchOrderedVector& f_OrderList, SS_String& f_launchOrderName, // NOLINT + SS_String& f_launchCfgFn) { // NOLINT + SS_String l_OrderCfgFn = f_launchCfgFn; + string::size_type pos = l_OrderCfgFn.find(".cfg"); + + if (pos == string::npos) { // LCOV_EXCL_BR_LINE 5:C error + // LCOV_EXCL_START 5:C error + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + FRAMEWORKUNIFIEDLOG(ZONE_WARN, __FUNCTION__, "invalid file name:%s", + f_launchCfgFn.c_str()); + return; + // LCOV_EXCL_STOP + } + + l_OrderCfgFn.replace(pos, strlen(".order.cfg"), ".order.cfg"); + CNSConfigReader *l_pReaderOrderCfg = new CNSConfigReader(l_OrderCfgFn); + + if (l_pReaderOrderCfg != NULL) { // LCOV_EXCL_BR_LINE 5:new error + CHAR key[128]; + std::sprintf(key, "%s.order", f_launchOrderName.c_str()); // NOLINT + SS_String value = l_pReaderOrderCfg->GetString(key); + std::vector<std::string> strList; + if (value.empty()) { // LCOV_EXCL_BR_LINE 200:cannot be empty + goto ERROR; + } +// LCOV_EXCL_START 6: Because an initialization condition is set at SystemManager startup and the branching condition cannot be satisfied + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + boost::split(strList, value, boost::is_any_of("|")); + for (UI_32 i = 0; i < strList.size(); i++) { + char* endptr = NULL; + f_OrderList.push_back( + static_cast<UI_32>(strtoul(strList[i].c_str(), &endptr, 10))); + if (*endptr != '\0') { + // Discard boot order if invalid string is detected + f_OrderList.clear(); + goto ERROR; + } + } + std::sprintf(key, "%s.owlist", f_launchOrderName.c_str()); // NOLINT + SS_String ow_list_value = l_pReaderOrderCfg->GetString(key); + std::vector<std::string> owList; + + if (!ow_list_value.empty()) { + boost::split(owList, ow_list_value, boost::is_any_of("|")); + for (UI_32 i = 0; i < owList.size(); i++) { + std::sprintf(key, "%s.%s", f_launchOrderName.c_str(), // NOLINT + owList[i].c_str()); + SS_String grop_ow_time = l_pReaderOrderCfg->GetString(key); + if (owList[i].compare(0, 4, "oww_") == 0) { + char* endptr = NULL; + SS_String group_name = owList[i].substr(strlen("oww_")); + UI_32 group_launch_wait = static_cast<UI_32>(strtoul( + grop_ow_time.c_str(), &endptr, 10)); + if (*endptr != '\0') { + continue; + } + GroupLaunchMapIter grp_iter = groups_map.begin(); + while (grp_iter != groups_map.end()) { + if (group_name == grp_iter->second.name) { + grp_iter->second.grp_launch_wait = group_launch_wait; + FRAMEWORKUNIFIEDLOG(ZONE_STATE, __FUNCTION__, + "grp_launch_wait %s=%d", group_name.c_str(), + group_launch_wait); + break; + } + grp_iter++; + } + } + } + } + } else { + FRAMEWORKUNIFIEDLOG(ZONE_WARN, __FUNCTION__, "ConfigReader(%s) is NULL", + l_OrderCfgFn.c_str()); + } +// LCOV_EXCL_STOP + ERROR: if (l_pReaderOrderCfg != NULL) { // LCOV_EXCL_BR_LINE 200:cannot be null + delete l_pReaderOrderCfg; // LCOV_EXCL_BR_LINE 11:unexpected branch // NOLINT(whitespace/line_length) + } + return; +} + +// Given a string, splits it up on the seperator character +// SubStringIterator( "a|b|| c |", '|' ) +// -> On each subsequent invocation of next() would return "a", "b", "", " c ", "" +class SubStringIterator { + typedef std::string::const_iterator SCIter; + + public: + SubStringIterator(const std::string& s, char c) : + m_position(s.begin()), m_end(s.end()), m_seperator(c), m_done(false) { + } + + std::string next() { + SCIter begin = m_position; + while (m_position != m_end && + *m_position != m_seperator) { + ++m_position; + } + + const std::string ret(begin, m_position); + if (m_position == m_end) { + m_done = true; + } else { + ++m_position; + } + + return ret; + } + bool done() const { + return m_done; + } + + private: + SCIter m_position; + const SCIter m_end; + const char m_seperator; + bool m_done; +}; + +template<class Iter> +static +Iter skipPrecedingWS(Iter begin, Iter end) { // LCOV_EXCL_START 6: Because the condition cannot be set + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + return std::find_if(begin, end, + std::not1(std::ptr_fun((int (*)(int))std::isspace))); +} + +// remove only preceding and trailing whitespace, but leave intermediate whitespace characters alone +std::string strip(const std::string& str) { + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + std::string::const_iterator skipTo = skipPrecedingWS(str.begin(), str.end()); + if (skipTo == str.end()) { // if string consists of ONLY whitespace + return std::string(""); + } else { + return std::string(skipTo, skipPrecedingWS(str.rbegin(), str.rend()).base()); + } +} +// LCOV_EXCL_STOP + +BOOL SysMgrConfiguration::LoadParametersCfg(GroupLaunchMap& groups_map, + ProcessNameMap& f_processNameMap, LaunchOrderedVector& f_OrderList, + SS_String& f_launchOrderName, SS_String& f_launchCfgFn) { + BOOL rtn_code = TRUE; + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+"); + + l_pReaderCfg = new (std::nothrow) CNSConfigReader(f_launchCfgFn); // LCOV_EXCL_BR_LINE 11:unexpected branch // NOLINT(whitespace/line_length) + + if (NULL != l_pReaderCfg) { // LCOV_EXCL_BR_LINE 5:new error + UI_32 launch_idx = 1; + CHAR key[128]; + std::sprintf(key, "ModulesLaunchConfig.Launch%d", launch_idx); // NOLINT + SS_String value = l_pReaderCfg->GetString(key); + + if (value.empty()) { // LCOV_EXCL_BR_LINE 200:cannot be empty +// LCOV_EXCL_START 6: For setting the initialization conditions at SystemManager startup + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, + " Error: l_pReaderCfg->GetString(%s) returned empty-string; " + "is launch configuration file mis-configured ?", + key); + rtn_code = FALSE; +// LCOV_EXCL_STOP + } else { + const char* nfsenv = getenv("AGL_NFS"); + bool isNfs = (nfsenv && strcmp(nfsenv, "y") == 0) ? true : false; // LCOV_EXCL_BR_LINE 11:unexpected branch // NOLINT(whitespace/line_length) + + std::list<std::string> capFiles; + if (isNfs) { +// LCOV_EXCL_START 6: Because an initialization condition is set at SystemManager startup and the branching condition cannot be satisfied + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + const std::string capPath("/usr/debug/share/target/cap.lst"); + std::ifstream fin(capPath.c_str()); + std::string line; + while (fin && std::getline(fin, line)) { + std::list<std::string> strList; + boost::split(strList, line, boost::is_any_of("|")); + if (!strList.empty()) { + if (strList.front()[0] == '/') { // Only character strings beginning with '/' are considered PATH + capFiles.push_back(strList.front().c_str()); + } + } + } + } +// LCOV_EXCL_STOP + while (!value.empty()) { + CHAR critical[10] = { }; + CHAR is_start_required[10] = { }; + CHAR shutdown_critical[10] = { }; + CHAR group_wait_for_trigger[10] = { }; + CHAR is_agl_unit[10] = { }; + CHAR disable_agl_resethistory[10] = { }; + CHAR disable_nonagl_resethistory[10] = { }; + CfgLaunchParams cfg_data; + + int at = static_cast<int>(ss_sm_cfg::cfg_args::group_name); + + SubStringIterator iter(value, '|'); + while (!iter.done() && ss_sm_cfg::cfg_args::END != at) { + const std::string data_ = iter.next(); + if (!data_.empty()) { + const char* data = data_.c_str(); + switch (at) { + case ss_sm_cfg::cfg_args::group_name: + snprintf(cfg_data.group_name, + sizeof(cfg_data.group_name), "%s", data); + break; + case ss_sm_cfg::cfg_args::group_id: + cfg_data.group_id = static_cast<UI_32>(strtoul(data, NULL, 10)); + break; + case ss_sm_cfg::cfg_args::group_launch_wait: + cfg_data.group_launch_wait = + static_cast<UI_32>(strtoul(data, NULL, 10)); + break; + case ss_sm_cfg::cfg_args::group_wait_for_trigger: + snprintf(group_wait_for_trigger, + sizeof(group_wait_for_trigger), "%s", data); + break; + case ss_sm_cfg::cfg_args::name: + snprintf(cfg_data.name, sizeof(cfg_data.name), "%s", data); + break; + case ss_sm_cfg::cfg_args::binary_name: + snprintf(cfg_data.binary_name, + sizeof(cfg_data.binary_name), "%s", data); + break; + case ss_sm_cfg::cfg_args::priority: + cfg_data.priority = static_cast<UI_32>(strtoul(data, NULL, 10)); + break; + case ss_sm_cfg::cfg_args::critical: + snprintf(critical, sizeof(critical), "%s", data); + break; + case ss_sm_cfg::cfg_args::retry_cnt: + cfg_data.retry_cnt = static_cast<UI_32>(strtoul(data, NULL, 10)); + break; + case ss_sm_cfg::cfg_args::arguments: + strncpy(cfg_data.arguments, data, + sizeof(cfg_data.arguments) - 1); + break; + case ss_sm_cfg::cfg_args::logging_msk: + snprintf(cfg_data.logging_msk_str, + sizeof(cfg_data.logging_msk_str), "%s", data); + break; + case ss_sm_cfg::cfg_args::restart: + snprintf(cfg_data.restart, sizeof(cfg_data.restart), "%s", data); + break; + case ss_sm_cfg::cfg_args::is_start_required: + snprintf(is_start_required, + sizeof(is_start_required), "%s", data); + break; + case ss_sm_cfg::cfg_args::shutdown_critical: + snprintf(shutdown_critical, + sizeof(shutdown_critical), "%s", data); + break; + case ss_sm_cfg::cfg_args::shutdown_wait_time: + cfg_data.shutdown_wait_time = + static_cast<UI_32>(strtoul(data, NULL, 10)); + break; + case ss_sm_cfg::cfg_args::fast_shutdown_wait_time: + cfg_data.fast_shutdown_wait_time = + static_cast<UI_32>(strtoul(data, NULL, 10)); + break; + case ss_sm_cfg::cfg_args::unix_user_name: + strncpy(&cfg_data.unix_user_name[0], + strip(data_).c_str(), + sizeof(cfg_data.unix_user_name) - 1); + break; + case ss_sm_cfg::cfg_args::is_agl_unit: + strncpy(is_agl_unit, data, sizeof(is_agl_unit)); + break; + case ss_sm_cfg::cfg_args::disable_agl_resethistory: + strncpy(disable_agl_resethistory, data, sizeof(disable_agl_resethistory)); + break; + case ss_sm_cfg::cfg_args::disable_nonagl_resethistory: + strncpy(disable_nonagl_resethistory, data, sizeof(disable_nonagl_resethistory)); + break; + case ss_sm_cfg::cfg_args::env_value_condition: // LCOV_EXCL_START 6: Because an initialization condition is set at SystemManager startup and the branching condition cannot be satisfied // NOLINT(whitespace/line_length) + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + snprintf(cfg_data.env_value_condition, + sizeof(cfg_data.env_value_condition), "%s", data); + break; + case ss_sm_cfg::cfg_args::cpu_assign: + cfg_data.cpu_assign = + static_cast<int>(strtoul(data, NULL, 16)); + break; + default: + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, + " Error: unknown ss_sm_cfg::cfg_args::xxx/'at' " + "enum value '%d'", at); + break; + // LCOV_EXCL_STOP + } + } + ++at; + } + //////////////////////////////////////////////////////////////////////////////// +// LCOV_EXCL_BR_START 6: Because an initialization condition is set at SystemManager startup and the branching condition cannot be satisfied + if (0 != std::strlen(cfg_data.env_value_condition) + && FALSE + == is_satisfy_env_launch_cond( +// LCOV_EXCL_BR_STOP + cfg_data.env_value_condition)) { // LCOV_EXCL_LINE 6: For setting the initialization conditions at SystemManager startup + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__, + "exclude %s from wakeup service", cfg_data.name); + } else { + if (isNfs) { // LCOV_EXCL_BR_LINE 6: Because an initialization condition is set at SystemManager startup and the branching condition cannot be satisfied + // Since the NFS environment is used by copying the executable file containing the CAP to /tmp, it is read out. +// LCOV_EXCL_START 6: Because an initialization condition is set at SystemManager startup and the branching condition cannot be satisfied + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + std::string binPath(cfg_data.binary_name); + for (std::list<std::string>::iterator ite = + capFiles.begin(); ite != capFiles.end(); ite++) { + if (binPath == *ite) { + std::list<std::string> nodes; + boost::split(nodes, binPath, boost::is_any_of("/")); + std::string newPath("/tmp/"); + newPath += nodes.back(); + FRAMEWORKUNIFIEDLOG(ZONE_STATE, __FUNCTION__, "EXCHG %s", newPath.c_str()); + snprintf(cfg_data.binary_name, + sizeof(cfg_data.binary_name), "%s", newPath.c_str()); + break; + } + } + } +// LCOV_EXCL_STOP + // FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__, "is_start_required: %s", is_start_required); + cfg_data.is_start_required = (std::strcmp("True", + is_start_required) == 0); + + if (std::strcmp("True", group_wait_for_trigger) == 0) { + cfg_data.group_wait_for_trigger = TRUE; + } else { + cfg_data.group_wait_for_trigger = FALSE; + } + + // FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__, "critical: %s", critical); + cfg_data.critical = (std::strcmp("True", critical) == 0); + + // FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__, "shutdown_critical: %s", shutdown_critical); + cfg_data.shutdown_critical = (std::strcmp("True", + shutdown_critical) == 0); + + cfg_data.SetAGLUnit(ParseBoolParameter(is_agl_unit, TRUE)); + cfg_data.SetAGLResetHistoryDisable(ParseBoolParameter(disable_agl_resethistory)); + cfg_data.SetNonAGLResetHisoryDisable(ParseBoolParameter(disable_nonagl_resethistory)); + + GroupLaunchInfo grp_info; + grp_info.start_complete = FALSE; + grp_info.stop_complete = FALSE; + grp_info.launch_complete = FALSE; + grp_info.name = cfg_data.group_name; + grp_info.id = cfg_data.group_id; + grp_info.grp_launch_wait = cfg_data.group_launch_wait; + grp_info.grp_wait_for_trigger = + cfg_data.group_wait_for_trigger; + ModuleLaunchListIter l_moduleLaunchListIter; + + GroupLaunchMapIter grp_iter = groups_map.find(grp_info.id); + if (grp_iter != groups_map.end()) { + l_moduleLaunchListIter = set_cfg_grp_member_info( + cfg_data, grp_iter->second.modules); + } else { + l_moduleLaunchListIter = set_cfg_grp_member_info( + cfg_data, grp_info.modules); + + // add this grp info object to the list of grps + groups_map.insert(make_pair(grp_info.id, grp_info)); + } + + std::string l_binaryNameStr = cfg_data.binary_name; + size_t l_binaryNamePos = l_binaryNameStr.find_last_of("/"); + if (std::string::npos != l_binaryNamePos) { + l_binaryNameStr = l_binaryNameStr.substr(l_binaryNamePos + 1); + f_processNameMap.insert( + make_pair(l_binaryNameStr, l_moduleLaunchListIter)); + } + } + + std::sprintf(key, "ModulesLaunchConfig.Launch%d", ++launch_idx); // NOLINT + value = l_pReaderCfg->GetString(key); + } // end while + } + } else { // LCOV_EXCL_START 6: Because new doesn't pass the failure case + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + // defaults use from the header file ... this is much faster then reading from an xml file. + FRAMEWORKUNIFIEDLOG(ZONE_WARN, __FUNCTION__, + " Warning: \"new CNSConfigReader(%s)\" returned NULL; using " + "constants.", f_launchCfgFn.c_str()); + UI_32 num_of_items = static_cast<UI_32>(_countof(g_arrLaunchTableCfg)); + for (UI_32 arr_idx = 0; arr_idx < num_of_items; arr_idx++) { + GroupLaunchInfo grp_info; + grp_info.launch_complete = FALSE; + grp_info.name = g_arrLaunchTableCfg[arr_idx].group_name; + grp_info.id = g_arrLaunchTableCfg[arr_idx].group_id; + grp_info.grp_launch_wait = + g_arrLaunchTableCfg[arr_idx].group_launch_wait; + + GroupLaunchMapIter grp_iter = groups_map.find(grp_info.id); + + if (grp_iter != groups_map.end()) { + set_grp_member_info(g_arrLaunchTableCfg[arr_idx], + grp_iter->second.modules); + } else { + set_grp_member_info(g_arrLaunchTableCfg[arr_idx], + grp_info.modules); + // add this grp info object to the list of grps + groups_map.insert(make_pair(grp_info.id, grp_info)); + } + } + } + // LCOV_EXCL_STOP + if (rtn_code == TRUE) { + load_parameters_order_cfg(groups_map, f_OrderList, f_launchOrderName, f_launchCfgFn); + } + + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-"); + return rtn_code; +} + +VOID SysMgrConfiguration::PrintGroupInfo(GroupLaunchInfo& refGrpInfo) { + std::stringstream l_logMsg; + + l_logMsg << endl << "Group: " << refGrpInfo.name.data() << endl + << " id: " << refGrpInfo.id << endl << " wait-time: " + << refGrpInfo.grp_launch_wait << endl << " launch complete: " + << (refGrpInfo.launch_complete == TRUE ? "YES" : "NO"); // LCOV_EXCL_BR_LINE 11:unexpected branch // NOLINT(whitespace/line_length) + + std::string l_logStr = l_logMsg.str(); + FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__, "%s", l_logStr.c_str()); +} + +VOID SysMgrConfiguration::PrintModuleInfo(ModuleLaunchParams& refMbrInfo) { + std::stringstream l_logMsg; + + // LCOV_EXCL_BR_START 11:unexpected branch // NOLINT(whitespace/line_length) + l_logMsg << endl << "Module: " << refMbrInfo.name.data() << endl + << " path: " << refMbrInfo.path.data() << endl << " args: " + << refMbrInfo.arguments.data() << endl << " restart: " + << refMbrInfo.restart.data() << endl + << " configuration_priority: " + << refMbrInfo.configuration_priority << endl + << " cpu_assign: " + << refMbrInfo.cpu_assign << endl + << " current_priority: " << refMbrInfo.current_priority << endl + << " previous_priority: " << refMbrInfo.previous_priority << endl + << " critical: " << (refMbrInfo.critical == TRUE ? "YES" : "NO") + << endl + << " retry count: " << refMbrInfo.retry_cnt << endl + << " logging mask: " << refMbrInfo.logging_msk_str << endl + << " is_start_required: " + << (refMbrInfo.is_start_required == TRUE ? "YES" : "NO") + << endl + << " shutdown_critical: " + << (refMbrInfo.shutdown_critical == TRUE ? "YES" : "NO") << endl + << " shutdown_wait_time: " << refMbrInfo.shutdown_wait_time + << endl << " fast_shutdown_wait_time: " + << refMbrInfo.fast_shutdown_wait_time << endl << " is_agl_unit: " + << refMbrInfo.IsAGLUnit() << endl << " disable_agl_resethistory: " + << refMbrInfo.IsAGLResetHistoryDisable() << endl << " disable_nonagl_resethistory: " + << refMbrInfo.IsNonAGLResetHistoryDisable() << endl << " state: " + << refMbrInfo.ModuleStateStr() << endl << " group ID: " + << refMbrInfo.group_id << endl << " debug dump state: " + << refMbrInfo.GetModuleDebugDumpStateStr(); + // LCOV_EXCL_BR_STOP + std::string l_logStr = l_logMsg.str(); + FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__, "%s", l_logStr.c_str()); +} + +VOID SysMgrConfiguration::PrintAllInfo(GroupLaunchMap& refGrpMap) { + // get first client from the map... + GroupLaunchMapIter grp_iter = refGrpMap.begin(); + + for (; grp_iter != refGrpMap.end(); grp_iter++) { + PrintGroupInfo(grp_iter->second); + ModuleLaunchListIter mbr_iter = grp_iter->second.modules.begin(); + for (; mbr_iter != grp_iter->second.modules.end(); mbr_iter++) { + PrintModuleInfo(*mbr_iter); + } + } +} + +BOOL SysMgrConfiguration::ParseBoolParameter(PCSTR f_value, BOOL f_default) const { + if (FALSE == f_default) { + const char TRUE_VALUE[] = "True"; + if (0 == strcmp(TRUE_VALUE, f_value)) { + return TRUE; + } + } else { + const char FALSE_VALUE[] = "False"; + if (0 == strcmp(FALSE_VALUE, f_value)) { + return FALSE; + } + } + return f_default; +} + +/* + * SM Configuration data constructor + */ +SMConfigParams::SMConfigParams() { +} + +/* + * SM Configuration data destructor + */ +SMConfigParams::~SMConfigParams() { +} + +//////////////////////////////////////////////////////////////////////////////////////////// +/// PrintConfigInfo +/// \brief Print the configuration data stored in config structure +/// +/// \param [in] configata +/// ConfigurationData & - Ref to structure that get populated. +/// +/// \return VOID +//////////////////////////////////////////////////////////////////////////////////////////// +VOID SMConfigParams::PrintConfigInfo(ConfigurationData const & f_ConfigParams) { + FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__, "AppHeartBeatInterval_Initial Info: %d", + f_ConfigParams.HBConfig.ApplicationHeartBeatIntervalInitial); + FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__, "AppHeartBeatInterval_Repeat Info: %d", + f_ConfigParams.HBConfig.ApplicationHeartBeatIntervalRepeat); + FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__, "HBMaxHeartBeatRetryCount Info: %d", + f_ConfigParams.HBConfig.MaxHeartBeatRetryCount); + FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__, "CDEnabled: %d", + f_ConfigParams.CDConfig.CrashDetectorEnabled); + FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__, "SLMTimerValue: %d", + f_ConfigParams.SLMConfig.SLMTimerValue); + FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__, "SLMMaxRetryCount: %d", + f_ConfigParams.SLMConfig.SLMMaxRetryCount); + FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__, "SLMThresholdValue: %d", + f_ConfigParams.SLMConfig.SLMThresholdValue); + FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__, "SLMSystemmanagerLogIntervalMs: %d", + f_ConfigParams.SLMConfig.SLMSystemmanagerLogIntervalMs); + FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__, "UserModeStructIsBoolean: %s", + GetStr(f_ConfigParams.UMConfig.IsUserModeNotificationABOOL).c_str()); + FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__, "ModuleConnectionNumTimesToCheck: %d", + f_ConfigParams.MCConfig.ModuleConnectionNumTimesToCheck); + FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__, "ModuleConnectionTimeOutSec: %d", + f_ConfigParams.MCConfig.ModuleConnectionTimeOutSec); + FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__, "ModuleStartRespTimeOutSec: %d", + f_ConfigParams.MCConfig.ModuleStartRespTimeOutSec); + FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__, "CriticalAppsMaxShutdownTimeFastSleep: %d", + f_ConfigParams.CAMSTConfig.CriticalAppsMaxShutdownTimeFastSleep); + FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__, + "CriticalAppsMaxShutdownTimeNormalReset: %d", + f_ConfigParams.CAMSTConfig.CriticalAppsMaxShutdownTimeNormalReset); + return; +} + +//////////////////////////////////////////////////////////////////////////////////////////// +/// GetSMConfigInformation +/// \brief Read config data from cfg file and populate the configuration data structure +/// +/// \param [in] f_ConfigParams & - Ref to ConfigurationData that get populated. +/// \param [in] f_FileName - Configuration file name. +/// +/// \return BOOL +/// BOOL - TRUE or FALSE +//////////////////////////////////////////////////////////////////////////////////////////// +BOOL SMConfigParams::GetSMConfigInformation(ConfigurationData& f_ConfigParams, SS_String f_FileName) { + EFrameworkunifiedStatus l_eStatus; + BOOL l_rtnCode = FALSE; // LCOV_EXCL_BR_LINE 15: marco defined in ns_logger_if.h // NOLINT(whitespace/line_length) + + CNSConfigReader *l_pReaderCfg = new (std::nothrow) CNSConfigReader(); // LCOV_EXCL_BR_LINE 10: As new does not fail +// LCOV_EXCL_BR_START 6: Because the applicable variable cannot be changed from the external API (only evaluated by the initial value) + if (NULL == l_pReaderCfg) { + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, + " Error. new CNSConfigReader() returned NULL pointer."); + } else { + if (eFrameworkunifiedStatusOK != (l_eStatus = l_pReaderCfg->Parse(f_FileName))) { + // LCOV_EXCL_START 6: Because the applicable variable cannot be changed from the external API (only evaluated by the initial value) + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, + " Error. l_pReaderCfg->Open(%s) returned NULL pointer.", + f_FileName.c_str()); + // LCOV_EXCL_STOP + } else if (eFrameworkunifiedStatusOK + != (l_eStatus = l_pReaderCfg->GetInt( + "Heartbeat.MaxHeartBeatRetryCount", + f_ConfigParams.HBConfig.MaxHeartBeatRetryCount))) { + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + LOG_STATUS_IF_ERRORED(l_eStatus, // LCOV_EXCL_START 6: Because the applicable variable cannot be changed from the external API (only evaluated by the initial value) + "l_pReaderCfg->GetInt('Heartbeat.MaxHeartBeatRetryCount')"); + } else if (eFrameworkunifiedStatusOK + != (l_eStatus = l_pReaderCfg->GetInt( + "Heartbeat.AppHeartBeatIntervalInitial", + f_ConfigParams.HBConfig.ApplicationHeartBeatIntervalInitial))) { + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + LOG_STATUS_IF_ERRORED(l_eStatus, // LCOV_EXCL_LINE 6: Because the applicable variable cannot be changed from the external API (only evaluated by the initial value) + "l_pReaderCfg->GetInt('Heartbeat.AppHeartBeatIntervalInitial')"); + } else if (eFrameworkunifiedStatusOK + != (l_eStatus = l_pReaderCfg->GetInt( + "Heartbeat.AppHeartBeatIntervalRepeat", + f_ConfigParams.HBConfig.ApplicationHeartBeatIntervalRepeat))) { + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + LOG_STATUS_IF_ERRORED(l_eStatus, // LCOV_EXCL_LINE 6: Because the applicable variable cannot be changed from the external API (only evaluated by the initial value) + "l_pReaderCfg->GetInt('Heartbeat.AppHeartBeatIntervalRepeat')"); + } else if (eFrameworkunifiedStatusOK + != (l_eStatus = l_pReaderCfg->GetBool("CrashDetector.Enabled", + f_ConfigParams.CDConfig.CrashDetectorEnabled))) { + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + LOG_STATUS_IF_ERRORED(l_eStatus, // LCOV_EXCL_LINE 6: Because the applicable variable cannot be changed from the external API (only evaluated by the initial value) + "l_pReaderCfg->GetBool('CrashDetector.Enabled')"); + } else if (eFrameworkunifiedStatusOK + != (l_eStatus = l_pReaderCfg->GetInt("SysLowMemory.TimerValue", + f_ConfigParams.SLMConfig.SLMTimerValue))) { + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + LOG_STATUS_IF_ERRORED(l_eStatus, // LCOV_EXCL_LINE 6: Because the applicable variable cannot be changed from the external API (only evaluated by the initial value) + "l_pReaderCfg->GetInt('SysLowMemory.TimerValue')"); + } else if (eFrameworkunifiedStatusOK + != (l_eStatus = l_pReaderCfg->GetInt( + "SysLowMemory.MaxRetryCount", + f_ConfigParams.SLMConfig.SLMMaxRetryCount))) { + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + LOG_STATUS_IF_ERRORED(l_eStatus, // LCOV_EXCL_LINE 6: Because the applicable variable cannot be changed from the external API (only evaluated by the initial value) + "l_pReaderCfg->GetInt('SysLowMemory.MaxRetryCount')"); + } else if (eFrameworkunifiedStatusOK + != (l_eStatus = l_pReaderCfg->GetInt( + "SysLowMemory.ThresholdValue", + f_ConfigParams.SLMConfig.SLMThresholdValue))) { + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + LOG_STATUS_IF_ERRORED(l_eStatus, // LCOV_EXCL_LINE 6: Because the applicable variable cannot be changed from the external API (only evaluated by the initial value) + "l_pReaderCfg->GetInt('SysLowMemory.ThresholdValue')"); + } else if (eFrameworkunifiedStatusOK + != (l_eStatus = l_pReaderCfg->GetInt( + "SysLowMemory.InterfaceunifiedLogIntervalMs", + f_ConfigParams.SLMConfig.SLMSystemmanagerLogIntervalMs))) { + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + LOG_STATUS_IF_ERRORED(l_eStatus, // LCOV_EXCL_LINE 6: Because the applicable variable cannot be changed from the external API (only evaluated by the initial value) + "l_pReaderCfg->GetInt('SysLowMemory.InterfaceunifiedLogIntervalMs')"); + } else if (eFrameworkunifiedStatusOK + != (l_eStatus = l_pReaderCfg->GetBool( + "UserModeNotification.IsBoolean", + f_ConfigParams.UMConfig.IsUserModeNotificationABOOL))) { + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + LOG_STATUS_IF_ERRORED(l_eStatus, // LCOV_EXCL_LINE 6: Because the applicable variable cannot be changed from the external API (only evaluated by the initial value) + "l_pReaderCfg->GetBool('UserModeNotification.IsBoolean')"); + f_ConfigParams.UMConfig.IsUserModeNotificationABOOL = TRUE; + } else if (eFrameworkunifiedStatusOK + != (l_eStatus = l_pReaderCfg->GetInt( + "Module.ModuleConnectionNumTimesToCheck", + f_ConfigParams.MCConfig.ModuleConnectionNumTimesToCheck))) { + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + LOG_STATUS_IF_ERRORED(l_eStatus, // LCOV_EXCL_LINE 6: Because the applicable variable cannot be changed from the external API (only evaluated by the initial value) + "l_pReaderCfg->GetInt('Module.ModuleConnectionNumTimesToCheck')"); + } else if (eFrameworkunifiedStatusOK + != (l_eStatus = l_pReaderCfg->GetInt( + "Module.ModuleConnectionTimeOutSec", + f_ConfigParams.MCConfig.ModuleConnectionTimeOutSec))) { + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + LOG_STATUS_IF_ERRORED(l_eStatus, // LCOV_EXCL_LINE 6: Because the applicable variable cannot be changed from the external API (only evaluated by the initial value) + "l_pReaderCfg->GetInt('Module.ModuleConnectionTimeOutSec')"); + } else if (eFrameworkunifiedStatusOK + != (l_eStatus = l_pReaderCfg->GetInt( + "Module.ModuleStartRespTimeOutSec", + f_ConfigParams.MCConfig.ModuleStartRespTimeOutSec))) { + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + LOG_STATUS_IF_ERRORED(l_eStatus, // LCOV_EXCL_LINE 6: Because the applicable variable cannot be changed from the external API (only evaluated by the initial value) + "l_pReaderCfg->GetInt('Module.ModuleStartRespTimeOutSec')"); + } else if (eFrameworkunifiedStatusOK + != (l_eStatus = l_pReaderCfg->GetInt( + "CriticalApps.CriticalAppsMaxShutdownTimeFastSleep", + f_ConfigParams.CAMSTConfig.CriticalAppsMaxShutdownTimeFastSleep))) { + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + LOG_STATUS_IF_ERRORED(l_eStatus, // LCOV_EXCL_LINE 6: Because the applicable variable cannot be changed from the external API (only evaluated by the initial value) + "l_pReaderCfg->GetInt('CriticalApps.CriticalAppsMaxShutdownTimeFastSleep')"); + } else if (eFrameworkunifiedStatusOK + != (l_eStatus = l_pReaderCfg->GetInt( + "CriticalApps.CriticalAppsMaxShutdownTimeNormalReset", + f_ConfigParams.CAMSTConfig.CriticalAppsMaxShutdownTimeNormalReset))) { + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + LOG_STATUS_IF_ERRORED(l_eStatus, // LCOV_EXCL_LINE 6: Because the applicable variable cannot be changed from the external API (only evaluated by the initial value) + "l_pReaderCfg->GetInt('CriticalApps.CriticalAppsMaxShutdownTimeNormalReset')"); + } else { + l_rtnCode = TRUE; + } + + delete l_pReaderCfg; // LCOV_EXCL_BR_LINE 10: As the delete does not fail + } +// LCOV_EXCL_BR_STOP + + return (l_rtnCode); +} + +//////////////////////////////////////////////////////////////////////////////////////////// +/// LoadSMConfigParameters +/// \brief Read System Manager configuration parameters from cfg file or +/// use defaults values in case cfg file is not available +/// +/// \param [in] f_ConfigParams & - Ref to ConfigurationData that get populated. +/// \param [in] f_FileName - Configuration file name. +/// +/// \return BOOL +/// BOOL - TRUE or FALSE +//////////////////////////////////////////////////////////////////////////////////////////// +BOOL SMConfigParams::LoadSMConfigParameters(ConfigurationData& f_ConfigParams, SS_String f_FileName) { + BOOL rtn_code = TRUE; + + rtn_code = GetSMConfigInformation(f_ConfigParams, f_FileName); + + // cfg config file not found, use constants + if (FALSE == rtn_code) { + // LCOV_EXCL_START 6: Because the applicable variable cannot be changed from the external API (only evaluated by the initial value) + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + FRAMEWORKUNIFIEDLOG(ZONE_WARN, __FUNCTION__, + " Warning: cfg config file not open, using constants"); + + // Heart Beat constants + f_ConfigParams.HBConfig.ApplicationHeartBeatIntervalInitial = + HBApplicationHeartBeatIntervalInitial; + f_ConfigParams.HBConfig.ApplicationHeartBeatIntervalRepeat = + HBApplicationHeartBeatIntervalRepeat; + f_ConfigParams.HBConfig.MaxHeartBeatRetryCount = HBMaxHeartBeatRetryCount; + + // Crash Detector constants + f_ConfigParams.CDConfig.CrashDetectorEnabled = CDEnabled; + + // System Low Memory + f_ConfigParams.SLMConfig.SLMTimerValue = SLMTimerValue; + f_ConfigParams.SLMConfig.SLMMaxRetryCount = SLMRetryCount; + f_ConfigParams.SLMConfig.SLMThresholdValue = SLMThresholdValue; + f_ConfigParams.SLMConfig.SLMSystemmanagerLogIntervalMs = SLMSystemmanagerLogIntervalMs; + + // Module connect and start resp + f_ConfigParams.MCConfig.ModuleConnectionNumTimesToCheck = + ModuleConnectionNumTimesToCheck; + f_ConfigParams.MCConfig.ModuleConnectionTimeOutSec = + ModuleConnectionTimeOutSec; + f_ConfigParams.MCConfig.ModuleStartRespTimeOutSec = ModuleStartRespTimeOutSec; + + // Critical Apps shutdown time + f_ConfigParams.CAMSTConfig.CriticalAppsMaxShutdownTimeFastSleep = + CriticalAppsMaxShutdownTimeFastSleepSec; + f_ConfigParams.CAMSTConfig.CriticalAppsMaxShutdownTimeNormalReset = + CriticalAppsMaxShutdownTimeNormalResetSec; + + // USer Mode Data Structure Type + f_ConfigParams.UMConfig.IsUserModeNotificationABOOL = TRUE; + // LCOV_EXCL_STOP + } + PrintConfigInfo(f_ConfigParams); + + return rtn_code; +} // LCOV_EXCL_BR_LINE 10: Final line + diff --git a/video_in_hal/systemservice/system_manager/server/src/ss_sm_dynamic_launcher.cpp b/video_in_hal/systemservice/system_manager/server/src/ss_sm_dynamic_launcher.cpp new file mode 100755 index 0000000..6144fa4 --- /dev/null +++ b/video_in_hal/systemservice/system_manager/server/src/ss_sm_dynamic_launcher.cpp @@ -0,0 +1,221 @@ +/* + * @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_SystemManager +/// \brief This file provides support for System Manager process launching. +/// +/////////////////////////////////////////////////////////////////////////////// + +#include <string> +#include <sstream> +#include <iomanip> + +#include "ss_sm_dynamic_launch_table.h" +#include "ss_sm_systemmanagerlog.h" + +DynamicLaunchBase::DynamicLaunchBase(): +m_vOrderedGroup(), +m_iterOrderedGroup() { +} + + +DynamicLaunchBase::~DynamicLaunchBase() { +} + +UI_32 DynamicLaunchBase::get_id() const { + // FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__, " DLB: Active Group ID is %d", *m_iterOrderedGroup); + return *m_iterOrderedGroup; +} + +UI_32 DynamicLaunchBase::advance_id() { + if (!is_end()) { + m_iterOrderedGroup++; + } + // FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__, " DLB: Active Group ID is %d", *m_iterOrderedGroup); + return *m_iterOrderedGroup; +} + +UI_32 DynamicLaunchBase::decrement_id() { + if (!is_begin()) { // LCOV_EXCL_BR_LINE 5: stdlib error case. + m_iterOrderedGroup--; + } + // FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__, " DLB: Active Group ID is %d", *m_iterOrderedGroup); + return *m_iterOrderedGroup; +} + +BOOL DynamicLaunchBase::is_begin() { + // FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__, " DLB: Active Group ID is %d", *m_iterOrderedGroup); + return (m_iterOrderedGroup == m_vOrderedGroup.begin()); +} + +BOOL DynamicLaunchBase::is_end() { + // FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__, " DLB: Active Group ID is %d", *m_iterOrderedGroup); + DynamicOrderedIter l_it = m_iterOrderedGroup; + l_it++; + return (l_it == m_vOrderedGroup.end()); +} + +VOID DynamicLaunchBase::to_begin() { + m_iterOrderedGroup = m_vOrderedGroup.begin(); + return; +} + +VOID DynamicLaunchBase::to_end() { + m_iterOrderedGroup = m_vOrderedGroup.end(); + m_iterOrderedGroup--; + return; +} + +VOID DynamicLaunchBase::print_info() { + UI_32 idx = 1; + std::stringstream l_logMsg; + DynamicOrderedIter l_dyn_iter = m_vOrderedGroup.begin(); + for (; l_dyn_iter != m_vOrderedGroup.end(); l_dyn_iter++) { + l_logMsg << std::endl << "Index: " << std::setw(2) << idx + << " Group Id: " << std::setw(2) << *l_dyn_iter; + + idx++; + } + + std::string l_logStr = l_logMsg.str(); + FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__, "%s", l_logStr.c_str()); +} + +DynamicLauncher::DynamicLauncher() :DynamicLaunchBase(), +m_nLaunchGroupId(0), +m_nLaunchBeforeGroupId(0), +m_nLaunchAfterGroupId(0), +m_nAviageTriggerId(0), +m_bDynamicLaunchEnabled(FALSE), // by default until set by some one will this be disabled. +m_eSourceType(SS_SOURCE_NA) { // invalid +} + +DynamicLauncher::~DynamicLauncher() { +} + +BOOL DynamicLauncher::dynamic_launch_enabled() const { // LCOV_EXCL_START 8: Dead code + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + return m_bDynamicLaunchEnabled; +} +// LCOV_EXCL_STOP + +VOID DynamicLauncher::configure_dynamic_launch(const SS_SOURCE& source_type, + GroupLaunchMap& group_info, LaunchOrderedVector& order_info) { + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+"); + m_eSourceType = source_type; + // "Dynamic Launch" is not used due to high dependency on a service table + create_normal_launch_vector(group_info, order_info); + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-"); +} + +BOOL DynamicLauncher::is_inGroupLaunchMap(UI_32& id, + GroupLaunchMap& group_info) { // LCOV_EXCL_START 8: Dead code + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+"); + BOOL Ret = FALSE; + GroupLaunchMapIter l_grp_iter = group_info.find(id); + if (l_grp_iter != group_info.end()) { + Ret = TRUE; + } + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-"); + return Ret; +} +// LCOV_EXCL_STOP + +// LCOV_EXCL_START 8: Dead code +DynamicLaunchInfo* DynamicLauncher::get_dynamic_source_info( + const SS_SOURCE& source_type, BOOL& source_trigger, + BOOL& is_aviage_required) { + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + UI_32 num_of_items = static_cast<UI_32>(_countof(g_arrDynamicLaunchTableCfg)); + DynamicLaunchInfo * point_to_this = NULL; + for (UI_32 arr_idx = 0; arr_idx < num_of_items; arr_idx++) { + if (g_arrDynamicLaunchTableCfg[arr_idx].source == source_type) { + source_trigger = g_arrDynamicLaunchTableCfg[arr_idx].group_trigger; + point_to_this = &g_arrDynamicLaunchTableCfg[arr_idx]; + if ((SS_SOURCE_FM == source_type) || (SS_SOURCE_AM == source_type) + || (SS_SOURCE_FM_DAB == source_type) + || (SS_SOURCE_SDARS == source_type)) { + is_aviage_required = FALSE; + } + break; + } + } + + return point_to_this; +} +// LCOV_EXCL_STOP + +UI_32 DynamicLauncher::get_id_using_group_name(PCSTR group_name, + GroupLaunchMap& group_info) { // LCOV_EXCL_START 8: Dead code + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + GroupLaunchMapIter l_grp_iter = group_info.begin(); + UI_32 rtn_grp_id = 0; + for (; l_grp_iter != group_info.end(); l_grp_iter++) { + if (0 == strcmp(group_name, l_grp_iter->second.name.c_str())) { + rtn_grp_id = l_grp_iter->second.id; + break; + } + } + + return rtn_grp_id; +} +// LCOV_EXCL_STOP + +VOID DynamicLauncher::create_normal_launch_vector(GroupLaunchMap& group_info, + LaunchOrderedVector& order_info) { + m_vOrderedGroup.clear(); + + if (order_info.size() != 0) { // LCOV_EXCL_BR_LINE 6: To initialize conditions for launching SystemManager + // LCOV_EXCL_START 6: To initialize conditions for launching SystemManager + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + LaunchOrderedIter l_ord_iter = order_info.begin(); + while (l_ord_iter != order_info.end()) { + if (is_inGroupLaunchMap(*l_ord_iter, group_info) == TRUE) { + m_vOrderedGroup.push_back(*l_ord_iter); + } + l_ord_iter++; + } + // LCOV_EXCL_STOP + } else { + GroupLaunchMapIter l_grp_iter = group_info.begin(); + while (l_grp_iter != group_info.end()) { + m_vOrderedGroup.push_back(l_grp_iter->second.id); + l_grp_iter++; + } + } + m_iterOrderedGroup = m_vOrderedGroup.begin(); + m_bDynamicLaunchEnabled = TRUE; + print_info(); +} + +VOID DynamicLauncher::copyDynOrderedVector(DynamicModuleStart& Start) { + Start.setGroupVector(this->m_vOrderedGroup); +} + +// DynamicModuleStart + +DynamicModuleStart::DynamicModuleStart() :DynamicLaunchBase() { +} + +DynamicModuleStart::~DynamicModuleStart() { +} + +VOID DynamicModuleStart::setGroupVector(DynamicOrderedVector& Vector) { + m_vOrderedGroup.assign(Vector.begin(), Vector.end()); + m_iterOrderedGroup = m_vOrderedGroup.begin(); +} // LCOV_EXCL_BR_LINE 10: Final line diff --git a/video_in_hal/systemservice/system_manager/server/src/ss_sm_version.cpp b/video_in_hal/systemservice/system_manager/server/src/ss_sm_version.cpp new file mode 100755 index 0000000..9df970f --- /dev/null +++ b/video_in_hal/systemservice/system_manager/server/src/ss_sm_version.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_SystemManager +/// \brief This file provides support for module version management. +/// +/////////////////////////////////////////////////////////////////////////////// +#include <system_service/ss_package.h> +#include <system_service/ss_ver.h> +#include <system_service/ss_templates.h> +#include <system_service/ss_string_maps.h> +#include <system_service/ss_system_manager_protocol.h> +#include <system_service/ss_system_manager_protocol_local.h> +#include <iostream> +#include <string> +#include <sstream> +#include <fstream> +#include "ss_sm_systemmanagerlog.h" +#include "ss_sm_version.h" + +using namespace std; // NOLINT + +CSMVersion::CSMVersion() { +} + +CSMVersion::~CSMVersion() { +} + +EFrameworkunifiedStatus CSMVersion::get_version(SS_VersionNumberType& f_VersionNumber) { + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+"); + CSSVer ver; + + EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK; + f_VersionNumber = 0; + + SSVER_PkgInfo info; + l_eStatus = ver.getPkgInfo(SS_PKG_MAIN_EMMC, &info); + if (l_eStatus == eFrameworkunifiedStatusOK) { // LCOV_EXCL_BR_LINE 6: To initialize conditions for launching SystemManager + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + f_VersionNumber = strtoull(info.version, NULL, 10); // LCOV_EXCL_LINE 6: To initialize conditions for launching SystemManager + } else { + SS_ASERT(0); // LCOV_EXCL_BR_LINE 15: marco defined in ss_templates.h // NOLINT(whitespace/line_length) + } + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-"); + return l_eStatus; +} // End of EFrameworkunifiedStatus CSMVersion::get_version(SS_VersionNumberType &f_VersionNumber) + +EFrameworkunifiedStatus CSMVersion::get_build_info(std::string& f_buildInfoStr) { + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+"); + EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK; + std::string build_info_str; + CSSVer ver; + SSVER_PkgInfo info; + l_eStatus = ver.getPkgInfo(SS_PKG_MAIN_PRODUCT_SI, &info); + if (l_eStatus == eFrameworkunifiedStatusOK) { // LCOV_EXCL_BR_LINE 6: To initialize conditions for launching SystemManager + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + build_info_str += info.version; // LCOV_EXCL_LINE 6: To initialize conditions for launching SystemManager + } else { + SS_ASERT(0); // LCOV_EXCL_BR_LINE 15: marco defined in ss_templates.h // NOLINT(whitespace/line_length) + } + f_buildInfoStr = build_info_str; + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-"); + return l_eStatus; +} // LCOV_EXCL_BR_LINE 10: Final line End of EFrameworkunifiedStatus CSMVersion::get_build_info(SS_String &f_buildInfoStr) +// EOF /SS_SystemManager/src/ss_sm_version.cpp diff --git a/video_in_hal/systemservice/system_manager/server/src/ss_system_manager.cpp b/video_in_hal/systemservice/system_manager/server/src/ss_system_manager.cpp new file mode 100755 index 0000000..8e26f23 --- /dev/null +++ b/video_in_hal/systemservice/system_manager/server/src/ss_system_manager.cpp @@ -0,0 +1,3655 @@ +/* + * @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_SystemManager +/// \brief This file provides support for System Manager business logic. +/// +/////////////////////////////////////////////////////////////////////////////// + +#include <native_service/cl_lock.h> +#include <native_service/cl_process.h> +#include <native_service/cl_monitor.h> + +#include <native_service/frameworkunified_application.h> +#include <native_service/frameworkunified_framework_if.h> +#include <native_service/frameworkunified_multithreading.h> +#include <native_service/frameworkunified_thread_priority.h> + +#include <native_service/ns_np_service_nor_persistence.h> +#include <native_service/ns_np_service_protocol.h> +#include <native_service/ns_plogger_if.h> +#include <native_service/ns_np_service_if.h> +#include <native_service/ns_backup.h> + +#include <heartbeat/ss_hb_if.h> + +#include <processlauncher/ProcessLauncher_if.h> +#include <processlauncher/ss_sm_process_launcher.h> +#include <processlauncher/ss_sm_process_launcher_protocol.h> + +#include <system_service/ss_system_manager_conf.h> +#include <stub/ss_diag.h> + +#include <system_service/ss_client_names.h> +#include <system_service/ss_heartbeat_service_protocol.h> +#include <system_service/ss_power_service_if.h> +#include <system_service/ss_power_service_notifications.h> +#include <system_service/ss_power_service_protocol.h> +#include <system_service/ss_services.h> +#include <system_service/ss_sm_thread_names.h> +#include <system_service/ss_sm_thread_names_local.h> +#include <system_service/ss_sm_client_if.h> +#include <system_service/ss_string_maps.h> +#include <system_service/ss_system_manager_notifications.h> +#include <system_service/ss_system_manager_notifications_local.h> +#include <system_service/ss_templates.h> +#include <system_service/ss_sm_client_if_local.h> +#include <system_service/ss_test_clients.h> +#include <stub/Clock_API.h> +#include <power_hal.h> +#include <dirent.h> +#include <errno.h> +#include <fcntl.h> +#include <stdio.h> +#include <stdlib.h> +#include <sys/mman.h> +#include <sys/resource.h> +#include <sys/procfs.h> +#include <sys/timeb.h> +#include <sys/wait.h> +#include <inttypes.h> +#include <libgen.h> +#include <spawn.h> +#include <pthread.h> +#include <linux/oom.h> +#include <sys/stat.h> +#include <sys/types.h> +#include <sys/ioctl.h> +#include <sched.h> +#include <other_service/itoa.h> +#include <iomanip> +#include <fstream> +#include <string> +#include <map> +#include <vector> +#include "ss_sm_signals.h" +#include "ss_sm_default_paths.h" +#include "ss_sm_systemmanagerlog.h" +#include "ss_sm_version.h" +#include "ss_system_manager.h" +using namespace std; // NOLINT + +static CSystemManager g_oSystemManger; + +#define SS_SM_TEMP_FILE_FOR_STORE_LOGS "/nv/BS/ss/system_manager/rwdata/sm_tempStoreLogs" +#define TR_USB_PATH "/usr/agl/bin/realtimeUsbLog" + +// \brief: public structure that is used for logging by NSLogger. +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 +}; + +std::string NumberToString(int Number) { // LCOV_EXCL_START 8: dead code + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + std::ostringstream ss; + ss << Number; + return ss.str(); +} +// LCOV_EXCL_STOP + +/* Check if "Mount Point" exsists as Directory */ +/*****************************************************************************/ +/** + @ingroup: CSystemManager + @brief: No Argument Constructor. + @note: . + @param void + @return void + */ +/*****************************************************************************/ +template<typename C, eFrameworkunifiedStatus (C::*M)(HANDLE)> EFrameworkunifiedStatus SysMgrCallback(HANDLE hApp) { + EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusFail; + C * pObj = static_cast<C *>(&g_oSystemManger); + if (pObj) { + l_eStatus = (pObj->*M)(hApp); + } + return l_eStatus; +} + +//************************************************************************** +// System Manager State String Map * +// * +void Init_SS_SMModuleState_StrMap(std::map<SS_SMModuleState, SS_String> & m_strMap) { // NOLINT + MAP_ENTRY(m_strMap, SS_SM_READY_TO_LAUNCH_APP); + MAP_ENTRY(m_strMap, SS_SM_APPS_LAUNCH_IN_PROGRESS); + MAP_ENTRY(m_strMap, SS_SM_APPS_LAUNCHED_READY_TO_START); + MAP_ENTRY(m_strMap, SS_SM_APPS_START_IN_PROGRESS); + MAP_ENTRY(m_strMap, SS_SM_APPS_START_COMPLETE); + MAP_ENTRY(m_strMap, SS_SM_APPS_STOPPING_AT__CWORD56__REQ); + MAP_ENTRY(m_strMap, SS_SM_APPS_STOPPING_AT_INTERNAL_REQ); + MAP_ENTRY(m_strMap, SS_SM_WAITING_FOR_CRITICAL_APPS_AT__CWORD56__REQ); + MAP_ENTRY(m_strMap, SS_SM_WAITING_FOR_CRITICAL_APPS_AT_INTERNAL_REQ); + MAP_ENTRY(m_strMap, SS_SM_APPS_PRE_START_IN_PROGRESS); + MAP_ENTRY(m_strMap, SS_SM_APPS_PRE_STOP_IN_PROGRESS); + MAP_ENTRY(m_strMap, SS_SM_APPS_PRE_RUN_COMPLETE); + MAP_ENTRY(m_strMap, SS_SM_APPS_BACKGROUND_START_IN_PROGRESS); + MAP_ENTRY(m_strMap, SS_SM_APPS_BACKGROUND_STOP_IN_PROGRESS); + MAP_ENTRY(m_strMap, SS_SM_APPS_BACKGROUND_RUN_COMPLETE); +} // End of void Init_SS_SMModuleState_StrMap(std::map<SS_SMModuleState, + +class EnumStringMap<SS_SMModuleState, Init_SS_SMModuleState_StrMap> + m_oSS_SMModuleStateStrMap; +SS_String GetStr(SS_SMModuleState f_enum) { + return m_oSS_SMModuleStateStrMap.GetStr(f_enum); // LCOV_EXCL_BR_LINE 11:unexpected branch // NOLINT(whitespace/line_length) +} // End of SS_String :GetStr(SS_SMModuleState f_enum) +// * +// End of System Manager State String Map * +//************************************************************************** + +std::string CSystemManager::m_bootOpt; // NOLINT + +/*****************************************************************************/ +/** + @ingroup: CSystemManager + @brief: No Argument Constructor. + @note: . + @param void + @return void + */ +/*****************************************************************************/ +CSystemManager & CSystemManager::GetInstance() { + return g_oSystemManger; +} + +/*****************************************************************************/ +/** + @ingroup: CSystemManager + @brief: No Argument Constructor. + @note: . + @param void + @return void + */ +/*****************************************************************************/ +CSystemManager::CSystemManager() : + m_hHeartbeatThread(INVALID_HANDLE, eSM_ThreadNotExist), + m_hProcLauncherThread(INVALID_HANDLE, eSM_ThreadNotExist), + m_SystemLaunchProgress(SS_SM_INITIAL_GROUP), + m_GroupLaunchTimer(NULL), + m_GroupRelaunchCount(0), + m_GroupRelaunchLimit(0), + m_hPowerServiceSession(NULL), + m_ActiveGroupId(SS_SM_INITIAL_GROUP), + m_StartUpReason(epswfINVALID), + m_DataResetMode(e_SS_SM_DATA_RESET_MODE_NONE), + m_ProgUpdateState(SS_SM_PROG_UPDATE_STATE_NONE), + m_NextWakeupType(e_SS_SM_NEXT_WAKEUP_TYPE_NONE), + m_DramBackupStatus(e_SS_SM_DRAM_BACKUP_NG), + m_isIlgReset(FALSE), + m_ResetStatus(e_SS_SM_RESET_STATUS_NONE), + m_ResetCount(0), + m_SMCurrentState(SS_SM_READY_TO_LAUNCH_APP), + + m_MaxShutdownTime(0), + m_NbrDebugDumpRspnRecv(0), + m_isRcvModeInfo(FALSE), + m_BinaryFilesPath(""), + m_ConfigFilesPath(""), + m_pfStopCompleteHandler( + SysMgrCallback<CSystemManager, &CSystemManager::send_shutdown_complete_response>), + m_VersionNumberStruct(0, eFrameworkunifiedStatusErrOther), + m_BuildInfoStr(""), + m_isRstPending(FALSE), + m_rstPendingInfo(), + m_UsingVMPlayer(FALSE), + NVM_VALID_SIGNATURE(0xBA5EBA11), + m_lastUserMode(epsumON), + m_shutdownTrigger(epssdmsdtINVALID), + m_isImmediateReset(FALSE), + m_isImmResetReq(FALSE), + m_needReNotifyStartPrm(FALSE), + m_pVarCodeStr(NULL), + m_SSLGroupLaunchMapIterator(NULL), + m_ModuleLaunchListIter(NULL), + m_bIsNPP_ServicesStarted(FALSE), + m_bIsBackupAvail(FALSE), + m_oSystemLauncher(), + m_SystemStarter(), + m_NPPStopSent(FALSE), + m_userModeChangeReason(epsumcrNOT_AVAILABLE), + m__CWORD56_CmdHist(SS_SM__CWORD56__CMD_HIST_SIZE), + m_SMCmdHist(SS_SM_CMD_HIST_SIZE), + m_TimerCmdHist(SS_SM_TIMER_CMD_HIST_SIZE), + m_PubCmdHist(SS_SM_PUB_CMD_HIST_SIZE), + m_ErrHist(SS_SM_ERR_HIST_SIZE), + m_ClProcessSigFd(-1), + m_SysMemMonitor(), + m_FreeMemAvailable(0), + m_coreFileSizeBytes(0), + m_BootMicroResetReason(SS_SM_BOOT_MICRO_RESET_REASON_SELF_RESET), + m_errorEventQueueLocked(FALSE), + m_isPrevErrEventCompleted(TRUE), + m_errorEventResult(eFrameworkunifiedStatusOK), + m_requestedArtifactId(eArtifactIdInterfaceunifiedDebugLog) { // LCOV_EXCL_BR_LINE 11:unexpected branch // NOLINT(whitespace/line_length) + m_InitialBoot = true; + + m_ResetFactor = PSM_FACTOR_NONE; + + m_Wake.powerupType = epswsPWRON; + m_Wake.up.level = epswlFULLRUN; + + m_SystemModeInfo.lastUserMode = m_lastUserMode; + m_SystemModeInfo.limpHomeCutoff = epslhcINVALID; + m_SystemModeInfo.productionMode = epspmINVALID; + m_SystemModeInfo.transportMode = epstmINVALID; + m_SystemModeInfo.systemMode = epssinfINVALID; + m_SystemModeInfo.startupStage = epssusfINVALID; + + bzero(&m_SMConfig, sizeof(m_SMConfig)); + bzero(&m_startUpConfirmationMsg, sizeof(m_startUpConfirmationMsg)); + bzero(&m_HBReport, sizeof(m_HBReport)); + + m__CWORD56_HistIter = m__CWORD56_CmdHist.begin(); + m_TimerHistIter = m_TimerCmdHist.begin(); + m_SMHistIter = m_SMCmdHist.begin(); + m_PubHistIter = m_PubCmdHist.begin(); + m_ErrHistIter = m_ErrHist.begin(); + + ////******************************************************************//// + //// Initialization of enum<=>enum and enum=>string maps //// + //// //// + + // + // **** Initialization of powerupType enum maps **** + // Map of System Services powerupType to BOOL enum values + m_PowerType_to_SSBoolEnumMap[epswsPWRON] = TRUE; + m_PowerType_to_SSBoolEnumMap[epswsPWROFF] = FALSE; + // + // Map of System Services powerupType to System Services User Mode enum values + m_PowerType_to_SSUserModeEnumMap[epswsPWRON] = epsumON; + m_PowerType_to_SSUserModeEnumMap[epswsPWROFF] = epsumOFF; + // + // Map of BOOL to System Services powerupType enum values + m_SSBool_to_PowerTypeEnumMap[TRUE] = epswsPWRON; + m_SSBool_to_PowerTypeEnumMap[FALSE] = epswsPWROFF; + // + // **** Initialization of User Mode ( aka Last User Mode ) maps **** + // Map of BOOL to System Services User Mode enum values + m_SSBool_to_SSUserModeEnumMap[FALSE] = epsumOFF; + m_SSBool_to_SSUserModeEnumMap[TRUE] = epsumON; + // + // Map of BOOL to System Services User Mode enum values + m_SSUserMode_to_SSBoolEnumMap[epsumOFF] = FALSE; + m_SSUserMode_to_SSBoolEnumMap[epsumON] = TRUE; + + // LCOV_EXCL_BR_STOP + //// //// + //// End of Initialization of enum<=>enum and enum=>string maps //// + ////******************************************************************//// + + m_startUpConfirmationMsg.wakeupType = epsstINVALID; + m_startUpConfirmationMsg.coldStartRequest = epsscrtINVALID; + m_startUpConfirmationMsg.HWVersion = UINT32_MAX; + m_startUpConfirmationMsg.matchedHardwareType = UINT32_MAX; + m_startUpConfirmationMsg.softwareType = UINT32_MAX; + m_startUpConfirmationMsg.imageType = UINT32_MAX; + m_startUpConfirmationMsg.majorVersion = UINT32_MAX; + m_startUpConfirmationMsg.minorVersion = UINT32_MAX; + + m_SystemManagerPriority = PR_SS_SYSMANAGER; +} + +/*****************************************************************************/ +/** + @ingroup: CSystemManager + @brief: Destructor + @note: . + @param void + @return void + */ +/*****************************************************************************/ +CSystemManager::~CSystemManager() { // LCOV_EXCL_BR_LINE 11:unexpected branch // NOLINT(whitespace/line_length) + if (NULL != m_pVarCodeStr) { + delete[] m_pVarCodeStr; // LCOV_EXCL_BR_LINE 11:unexpected branch // NOLINT(whitespace/line_length) + } +} + +/*****************************************************************************/ +/** + @ingroup: CSystemManager + @brief: Initialize_memory Memory initialization processing + @note: . + @param + @return void + */ +/*****************************************************************************/ +void CSystemManager::Initialize_memory(HANDLE hApp, bool* l_isInitFail, EFrameworkunifiedStatus* l_eStatus_work, BOOL isIllReset) { + int ret; + EFrameworkunifiedStatus l_eStatus; + + /// Start Process for Realtime USB Logging + { + PreLaunchModuleParams l_rtuparam; + l_rtuparam.LaunchFunc = CreateRtUsb; + l_rtuparam.relaunchLimit = 1; + l_rtuparam.name = "realtimeUsbLog"; + l_rtuparam.binaryFileName = TR_USB_PATH; +/* l_rtuparam.pid = CreateRtUsb(); + if (l_rtuparam.pid == 1) { + FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, " Error: CreateRtUsb()"); + } */ + m_PreLaunchModuleList.push_back(l_rtuparam); + } + + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+"); + + int fd = open("/dev/urandom", O_RDONLY); // LCOV_EXCL_BR_LINE 5: standard lib error + if (fd == -1) { // LCOV_EXCL_BR_LINE 5: standard lib error + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + SS_ASERT_ERRNO(0); // LCOV_EXCL_LINE 5: standard lib error + } else { + char buf[4]; + ret = static_cast<int>(read(fd, buf, 4)); // LCOV_EXCL_BR_LINE 5: standard lib error + if (-1 == ret) { // LCOV_EXCL_BR_LINE 5: standard lib error + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + SS_ASERT_ERRNO(0); // LCOV_EXCL_LINE 5: standard lib error + } else if (4 != ret) { // LCOV_EXCL_BR_LINE 5: standard lib error + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + SS_ASERT(0); // LCOV_EXCL_LINE 5: standard lib error + } else { + fprintf(stderr, "WakeupID:%X%X%X%X\n", buf[0], buf[1], buf[2], buf[3]); + FRAMEWORKUNIFIEDLOG(ZONE_STATE, __FUNCTION__, "WakeupID:%X%X%X%X", buf[0], buf[1], buf[2], buf[3]); + } + close(fd); + } + + FRAMEWORKUNIFIEDLOG(ZONE_STATE, __FUNCTION__, "bootOpt:%s", m_bootOpt.c_str()); + + *l_eStatus_work = FrameworkunifiedAttachCallbackToDispatcherWithFd(hApp, m_ClProcessSigFd, // LCOV_EXCL_BR_LINE 4: nsfw error + SysMgrCallback<CSystemManager, &CSystemManager::OnProcessTermDetected>); + + if (eFrameworkunifiedStatusOK != *l_eStatus_work) { // LCOV_EXCL_BR_LINE 4: nsfw error + // LCOV_EXCL_START 4: nsfw error + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + LOG_ERROR("FrameworkunifiedAttachCallbackToDispatcherWithFd()"); + *l_isInitFail = true; + // LCOV_EXCL_STOP + } + + pthread_mutex_init(&sm_hist_mutex, NULL); + + ReadPathFromEnvironmentVariables(); + ReadUsingVMPlayerEnvironmentVariable(); + + // FIXME : Dump information from power_hal by using + + if (eFrameworkunifiedStatusOK != (*l_eStatus_work = SetSystemModeInfoStruct())) { + LOG_ERROR("SetSystemModeInfoStruct()"); // LCOV_EXCL_BR_LINE 15: marco defined in ss_templates.h // NOLINT(whitespace/line_length) + *l_isInitFail = true; + } + + // Select configuration file for wakeup services + BOOL bIsVupMode = (m_SystemModeInfo.systemMode == epssinfPROGRAMMING) ? TRUE : FALSE; // LCOV_EXCL_BR_LINE 11:unexpected branch // NOLINT(whitespace/line_length) + + T_SS_SM_INIT_HOOK_IN_PARAM inPrm; + + std::memset(&inPrm, 0, sizeof(inPrm)); + inPrm.bIsVupMode = bIsVupMode; + + if (eFrameworkunifiedStatusOK != (*l_eStatus_work = ss_sm_initHook(hApp, &inPrm, &m_productCustomPrm))) { + SS_ASERT_LOG(0, "ERROR: ss_sm_initHook()"); // LCOV_EXCL_BR_LINE 15: marco defined in ss_templates.h // NOLINT(whitespace/line_length) + *l_isInitFail = true; + } + + SetEnvVariableForVupMode(bIsVupMode); + + // Get the Version Number + // GetVersionNumber() will report any errors + m_VersionNumberStruct.m_eSystemmanagerStatus = GetVersionNumber(m_VersionNumberStruct.m_VersionNumber); + + *l_eStatus_work = GetBuildInfo(m_BuildInfoStr); + l_eStatus = *l_eStatus_work; + + LOG_ERROR_REC_HIST_IF_ERRORED(l_eStatus, "GetBuildInfo()"); // LCOV_EXCL_BR_LINE 15: marco defined in ss_system_manager.h // NOLINT(whitespace/line_length) + + INTERFACEUNIFIEDLOG_WHEN_COMPILED; // LCOV_EXCL_BR_LINE 15: marco defined in ss_system_manager.h // NOLINT(whitespace/line_length) + + FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__, " %s priority is %d", SERVICE_SYSMANAGER, m_SystemManagerPriority); + FRAMEWORKUNIFIEDLOG(ZONE_PERFORMANCE, __FUNCTION__, " %s was compiled at %s @ %s", __FILE__, __DATE__, __TIME__); + + FRAMEWORKUNIFIEDLOG(ZONE_PERFORMANCE, __FUNCTION__, " Host Processor Software Version is '0x%016llX'", + m_VersionNumberStruct.m_VersionNumber); + + FRAMEWORKUNIFIEDLOG(ZONE_PERFORMANCE, __FUNCTION__, " Host Processor Build Version is '%s'", m_BuildInfoStr.c_str()); + + LogESystemmanagerStatusEnums(); + LogProtocolIDs(); +} + +/*****************************************************************************/ +/** + @ingroup: CSystemManager + @brief: Initialize_callbacks Callback enrollment process + @note: . + @param + @return void + */ +/*****************************************************************************/ +void CSystemManager::Initialize_callbacks(HANDLE hApp, bool *l_isInitFail, EFrameworkunifiedStatus *l_eStatus_work) { + EFrameworkunifiedStatus l_eStatus; + + m_GroupLaunchTimer = new (std::nothrow) TimerCtrl(eSM_TIMERS_END); // LCOV_EXCL_BR_LINE 11:unexpected branch // NOLINT(whitespace/line_length) + if (NULL == m_GroupLaunchTimer) { // LCOV_EXCL_BR_LINE 5: Because new doesn't pass the failure case + // LCOV_EXCL_START 5: Because new doesn't pass the failure case + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + *l_eStatus_work = eFrameworkunifiedStatusNullPointer; + LOG_ERROR("new(std::nothrow)TimerCtrl(eSM_TIMERS_END)"); + *l_isInitFail = true; + // LCOV_EXCL_STOP + } + + // LCOV_EXCL_BR_START 11:unexpected branch // NOLINT(whitespace/line_length) + m_GroupLaunchTimer->Initialize(hApp); + m_aTimerIDs[eSM_TIMER_GROUP_MONITOR] = + m_GroupLaunchTimer->CreateTimer(SysMgrCallback<CSystemManager, &CSystemManager::OnGroupLaunchTimerExpiry>); + m_aTimerIDs[eSM_TIMER_PROCESS_LAUNCH_MONITOR] = + m_GroupLaunchTimer->CreateTimer(SysMgrCallback<CSystemManager, &CSystemManager::OnProcessLaunchTimerExpiry>); + m_aTimerIDs[eSM_TIMER_HEARTBEAT_MONITOR] = + m_GroupLaunchTimer->CreateTimer(SysMgrCallback<CSystemManager, &CSystemManager::OnHeartBeatMonitorTimerExpiry>); + m_aTimerIDs[eSM_TIMER_PROCESSLAUNCHER_MONITOR] = + m_GroupLaunchTimer->CreateTimer(SysMgrCallback<CSystemManager, + &CSystemManager::OnProcessLaunchMonitorTimerExpiry>); + m_aTimerIDs[eSM_TIMER_CLIENT_START_MONITOR] = + m_GroupLaunchTimer->CreateTimer(SysMgrCallback<CSystemManager, + &CSystemManager::OnClientStartMonitorTimerExpiry>); + m_aTimerIDs[eSM_TIMER_NPP_STATUS_CHECK_MONITOR] = + m_GroupLaunchTimer->CreateTimer(SysMgrCallback<CSystemManager, + &CSystemManager::OnNPPStatusCheckMonitorTimerExpiry>); + m_aTimerIDs[eSM_TIMER__CWORD56__HEARTBEAT_RESPONSE] = + m_GroupLaunchTimer->CreateTimer(SysMgrCallback<CSystemManager, + &CSystemManager::On_CWORD56_HeartBeatResponseIntervalTimerExpiry>); + m_aTimerIDs[eSM_TIMER_LAUNCH_GROUP_TRIGGER_PROC_RESP_TIMER] = + m_GroupLaunchTimer->CreateTimer(SysMgrCallback<CSystemManager, + &CSystemManager::OnLaunchGroupTriggerProcessResponseTimerExpiry>); + m_aTimerIDs[eSM_TIMER_GROUP_LAUNCH_WAIT_TIMER] = + m_GroupLaunchTimer->CreateTimer(SysMgrCallback<CSystemManager, &CSystemManager::OnGroupLaunchWaitTimeout>); + m_aTimerIDs[eSM_TIMER_MODULE_CONNECT_WAIT_TIMER] = + m_GroupLaunchTimer->CreateTimer(SysMgrCallback<CSystemManager, &CSystemManager::OnModuleConnectWaitTimeout>); + m_aTimerIDs[eSM_TIMER_START_RESP_MONITOR_WAIT_TIMER] = + m_GroupLaunchTimer->CreateTimer(SysMgrCallback<CSystemManager, &CSystemManager::OnStartRespMonitorTimeout>); + m_aTimerIDs[eSM_TIMER_SHUTDOWN_COMPLETE_MONITOR] = + m_GroupLaunchTimer->CreateTimer(SysMgrCallback<CSystemManager, + &CSystemManager::OnShutdownCompleteMonitorTimeout>); + m_aTimerIDs[eSM_TIMER_CLIENT_STOP_MONITOR] = + m_GroupLaunchTimer->CreateTimer(SysMgrCallback<CSystemManager, &CSystemManager::OnClientStopMonitorTimerExpiry>); + + FrameworkunifiedProtocolCallbackHandler l_cbArrayAnySource[] = { + // Command ID, Call back functions + { SS_SM_PROTOCOL_OPEN_SESSION_REQ, SysMgrCallback<CSystemManager, &CSystemManager::OnOpenSession> }, + { SS_SM_CPU_RESET_REQ, SysMgrCallback<CSystemManager, &CSystemManager::OnCpuResetRequest> } + }; + + FrameworkunifiedProtocolCallbackHandler l_cbArrayGroupLaunchService[] = { + // Command ID, Call back functions + { SS_SM_GROUP_LAUNCH_TRIGGER, SysMgrCallback<CSystemManager, &CSystemManager::OnLaunchGroupTriggerProcessResponse> } + }; + + FrameworkunifiedProtocolCallbackHandler l_cbArrayNPPService[] = { + // Command ID, Call back functions + { NPS_NPP_READY_EVENT, SysMgrCallback<CSystemManager, &CSystemManager::OnNPPReadyEventCallback> }, + { NPS_GET_READYSTATUS_ACK, SysMgrCallback<CSystemManager, &CSystemManager::OnNPPReadyStatusCallback> }, + { NPS_NPP_STOP_ACK, SysMgrCallback<CSystemManager, &CSystemManager::OnNppStopComplete> } + }; + + FrameworkunifiedProtocolCallbackHandler l_cbArrayPowerService[] = { + // Command ID, Call back functions + { SS_SM_POWER_REQUEST_MSG, SysMgrCallback<CSystemManager, &CSystemManager::OnPowerRequestCallback> }, + { SS_SM_WAKEUP_MODULES, SysMgrCallback<CSystemManager, &CSystemManager::OnWakeupCallback> }, + { SS_SM_SYSTEM_MODE_INFO_REQ, SysMgrCallback<CSystemManager, &CSystemManager::OnSystemModeInfoRequest> }, + { SS_SM_INITCOMP_REP, SysMgrCallback<CSystemManager, &CSystemManager::OnInitCompReportCallback> }, + { SS_SM_SHUTDOWN_MODULES, SysMgrCallback<CSystemManager, &CSystemManager::OnShutdownModulesRequest> }, + { SS_SM_FWD_STARTUP_CONFIRMATION_MSG_REQ, + SysMgrCallback<CSystemManager, &CSystemManager::OnSetStartupConfirmationDataRequest> } + }; + + FrameworkunifiedProtocolCallbackHandler l_cbArraySystemManager[] = { + // Command ID, Call back functions + { SS_SM_SendTriggerToSelf, SysMgrCallback<CSystemManager, &CSystemManager::OnLaunchGroupSelfTrigger> }, + { SS_SM_DEBUG_DUMP_RSPN, SysMgrCallback<CSystemManager, &CSystemManager::OnDebugDumpResponseReceived> } + }; + // LCOV_EXCL_BR_STOP + +#define ATTACH_CBS_TO_DISPATCHER(L_ARRAY, CALLING_SERVICE_NAME) \ + *l_eStatus_work = l_eStatus = FrameworkunifiedAttachCallbacksToDispatcher(hApp, \ + CALLING_SERVICE_NAME, \ + L_ARRAY, \ + static_cast<UI_32>_countof(L_ARRAY)); \ + if (eFrameworkunifiedStatusOK != l_eStatus) { \ + FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, \ + " Error: FrameworkunifiedAttachCallbacksToDispatcher(%s) errored: %d/'%s'", \ + #L_ARRAY, \ + l_eStatus, \ + GetStr(l_eStatus).c_str()); \ + *l_isInitFail = true; \ + } +// End of #define ATTACH_CBS_TO_DISPATCHER( CALLING_SERVICE_NAME, L_ARRAY ) + + // LCOV_EXCL_BR_START 15: marco defined above + // Note: This macro will exit this function if the embedded fnc errors. + ATTACH_CBS_TO_DISPATCHER(l_cbArrayAnySource, FRAMEWORKUNIFIED_ANY_SOURCE); + + // Note: This macro will exit this function if the embedded fnc errors. + ATTACH_CBS_TO_DISPATCHER(l_cbArrayGroupLaunchService, SS_GROUP_LAUNCH_TRIGGER); + + // Note: This macro will exit this function if the embedded fnc errors. + ATTACH_CBS_TO_DISPATCHER(l_cbArrayNPPService, FRAMEWORKUNIFIED_NS_NPSERVICE); + + // Note: This macro will exit this function if the embedded fnc errors. + ATTACH_CBS_TO_DISPATCHER(l_cbArrayPowerService, SERVICE_POWER); + + // Note: This macro will exit this function if the embedded fnc errors. + ATTACH_CBS_TO_DISPATCHER(l_cbArraySystemManager, SERVICE_SYSMANAGER); + // LCOV_EXCL_BR_STOP + + { + char pathBuf[128]; + // LCOV_EXCL_BR_START 11:unexpected branch // NOLINT(whitespace/line_length) + snprintf(pathBuf, sizeof(pathBuf), "/proc/%d/oom_score_adj", getpid()); + std::ofstream fo(pathBuf); + fo << OOM_SCORE_ADJ_MIN << endl; + fo.close(); + // LCOV_EXCL_BR_STOP + FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__, "set OOM_SCORE_ADJ_MIN(SS_SysManager/%d)", getpid()); + } + +#undef ATTACH_CBS_TO_DISPATCHER + + // LCOV_EXCL_BR_START 4: nsfw error + *l_eStatus_work = FrameworkunifiedSubscribeNotificationWithCallback(hApp, NTFY_BackupMgr_Availability, + SysMgrCallback<CSystemManager, &CSystemManager::OnBackupMgrAvailCallback>); + // LCOV_EXCL_BR_STOP + if (eFrameworkunifiedStatusOK != *l_eStatus_work) { // LCOV_EXCL_BR_LINE 4: nsfw error + // LCOV_EXCL_START 4: nsfw error + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + LOG_ERROR("FrameworkunifiedSubscribeNotificationWithCallback()"); + *l_isInitFail = true; + // LCOV_EXCL_STOP + } + + if (eFrameworkunifiedStatusOK != (*l_eStatus_work = ErrorEventInit(hApp))) { // LCOV_EXCL_BR_LINE 6: function do not return error + // LCOV_EXCL_START 6: function do not return error + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + LOG_ERROR("ErrorEventInit()"); + *l_isInitFail = true; + // LCOV_EXCL_STOP + } + +#ifndef SS_SM_SKIP_HEARTBEAT_INIT + // LCOV_EXCL_BR_START 6: function do not return error, expect nsfw error + if (eFrameworkunifiedStatusOK != (*l_eStatus_work = init_Heartbeat(hApp))) { + // LCOV_EXCL_BR_STOP + // LCOV_EXCL_START 6: function do not return error, expect nsfw error + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + LOG_ERROR("init_HeartBeat()"); + *l_isInitFail = true; + // LCOV_EXCL_STOP + } +#else +#warning Test code - NOT calling init_Heartbeat(hApp) + FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, " Error: NOT calling init_Heartbeat(hApp)"); +#endif +#undef SS_SM_SKIP_HEARTBEAT_INIT + + // LCOV_EXCL_BR_START 6: function do not return error, expect nsfw error + if (eFrameworkunifiedStatusOK != (*l_eStatus_work = init_process_launcher(hApp))) { + // LCOV_EXCL_BR_STOP + // LCOV_EXCL_START 6: function do not return error, expect nsfw error + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + LOG_ERROR("init_process_launcher()"); + *l_isInitFail = true; + // LCOV_EXCL_STOP + } + + // LCOV_EXCL_BR_START 6: function do not return error, expect init error + if (eFrameworkunifiedStatusOK != (*l_eStatus_work = start_process_launching(hApp))) { + // LCOV_EXCL_BR_STOP + // LCOV_EXCL_START 6: function do not return error, expect init error + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + LOG_ERROR("start_process_launching()"); + *l_isInitFail = true; + // LCOV_EXCL_STOP + } + + // LCOV_EXCL_BR_START 6: function do not return error, expect nsfw error + if (eFrameworkunifiedStatusOK != (*l_eStatus_work = init_sysmem_monitor(hApp))) { + // LCOV_EXCL_BR_STOP + // LCOV_EXCL_START 6: function do not return error, expect nsfw error + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + LOG_ERROR("init_sysmem_monitor()"); + *l_isInitFail = true; + // LCOV_EXCL_STOP + } + + /// Internal thread monitoring start + // LCOV_EXCL_BR_START 11:unexpected branch // NOLINT(whitespace/line_length) + m_GroupLaunchTimer->StartTimer(m_aTimerIDs[eSM_TIMER_HEARTBEAT_MONITOR], + SS_HEARTBEAT_MONITOR_TIMER_CONFIG, 0, + SS_HEARTBEAT_MONITOR_TIMER_CONFIG, 0); + + m_GroupLaunchTimer->StartTimer( + m_aTimerIDs[eSM_TIMER_PROCESSLAUNCHER_MONITOR], + SS_PROCESSLAUNCHER_MONITOR_TIMER_CONFIG, 0, + SS_PROCESSLAUNCHER_MONITOR_TIMER_CONFIG, 0); + + m_GroupLaunchTimer->StartTimer( + m_aTimerIDs[eSM_TIMER_NPP_STATUS_CHECK_MONITOR], + SS_NPP_STATUS_CHECK_MONITOR_TIME_SEC, 0, + SS_NPP_STATUS_CHECK_MONITOR_TIME_SEC, 0); + // LCOV_EXCL_BR_STOP +} + + +/*****************************************************************************/ +/** + @ingroup: CSystemManager + @brief: Initialization + @note: . + @param HANDLE hApp + @return void + */ +/*****************************************************************************/ +EFrameworkunifiedStatus CSystemManager::Initialize(HANDLE hApp) { + bool l_isInitFail = false; + EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK; + int ret; + PsmFactorT l_startup_factor; + + // Need to call Lock System Initialize API once in the system + ret = CL_LockSystemInit(); + if (ret != 0) { + fprintf(stderr, "SS_SysManager/%s/Error: CL_LockSystemInit() errored: %d\n", __FUNCTION__, ret); + } + + ret = CL_LockProcessInit(); + if (ret != 0) { + fprintf(stderr, "SS_SysManager/%s/Error: CL_LockProcessInit() errored: %d\n", __FUNCTION__, ret); + l_isInitFail = true; + } + + ret = PsmGetStartupFactor(hApp, &l_startup_factor); + if (ret == 0) { + if ((static_cast<UI_32>(l_startup_factor) & PSM_RESET_HISTORY) == PSM_RESET_HISTORY) { + DGCODE_RET_API l_ret = DGCODE_RET_ERROR; + uint64_t l_SystemResetRobCode = 0; + DGCODE_ROB_SSR_INFO l_info; + if (l_startup_factor == PSM_FACTOR_AGL_WITH_HISTORY) { + l_SystemResetRobCode = 0x2219; // AGL cause + } else if (l_startup_factor == PSM_FACTOR_TIER1_WITH_HISTORY) { + l_SystemResetRobCode = 0x221A; // Tier1 cause + } else if (l_startup_factor == PSM_FACTOR_USER_WITH_HISTORY) { + l_SystemResetRobCode = 0x8027; // USER cause + } else { + // No processing + } + + if (l_SystemResetRobCode != 0) { + memset(&l_info, 0x00, sizeof(DGCODE_ROB_SSR_INFO)); + + l_ret = Diag_PutRoBInfo(hApp, l_SystemResetRobCode, &l_info); + if (l_ret == DGCODE_RET_ERROR) { + LOG_ERROR("Diag_PutRoBInfo()"); + } + } + } + } else { + (void)fprintf(stderr, "SS_SysManager/%s/ERROR:start-up factor not get\n", __FUNCTION__); + } + + m_isIlgReset = (false == GetSyscomPowerStatusInfo(hApp)) ? TRUE : FALSE; + if (m_isIlgReset || ("elog" == m_bootOpt)) { + fprintf(stderr, "SS_SysManager/%s/Error: ILGRST LOG SAVE\n", __func__); + StoreDebugLogs(hApp, SS_STORELOGS_ILLEGAL); + } else { + StoreDebugLogs(hApp, SS_STORELOGS_ACCOFFON); + } + + if (m_isIlgReset == TRUE) { + // overwrite AGL_ILLRESET_FLAG. + uint32_t tmp = static_cast<uint32_t>(m_isIlgReset); + if (PowerHalSetResetInfo(AGL_ILLRESET_FLAG, tmp)) { + FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, + "Could not set AGL_ILLRESET_FLAG to power_hal"); + } + } else { + // keep last value of AGL_ILLRESET_FLAG. + } + + FRAMEWORKUNIFIED_SET_ZONES(); + NsLogSetLogMethod(LPRINT | LMSGQ); + // FRAMEWORKUNIFIEDLOG can not be used until this line + + m_ClProcessSigFd = CL_ProcessInit(); // LCOV_EXCL_BR_LINE 4: nsfw error + if (m_ClProcessSigFd == -1) { // LCOV_EXCL_BR_LINE 4: nsfw error + // LCOV_EXCL_START 4: nsfw error + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, " Error: CL_ProcessInit()"); + l_isInitFail = true; + // LCOV_EXCL_STOP + } + + ret = CL_MonitorInit(CL_MONITOR_INIT_SYSTEM); + if(ret != 0) { + fprintf(stderr, "SS_SysManager/%s/Error: CL_MonitorInit() errored: %d\n", __FUNCTION__, ret); + l_isInitFail = true; + } + + // Threads MUST NOT be started until this line +// ===== Initialization No.1 + Initialize_memory(hApp, &l_isInitFail, &l_eStatus, m_isIlgReset); + +// ===== Initialization No.2 + Initialize_callbacks(hApp, &l_isInitFail, &l_eStatus); + + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-"); + + return l_eStatus; +} + +EFrameworkunifiedStatus CSystemManager::SetEnvVariableForVupMode(BOOL bIsVupMode) { + EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK; + const CHAR SmVupModeEnvVariable[] = "SM_VUP_MODE"; + const CHAR *l_pValue = bIsVupMode ? "y" : "n"; // LCOV_EXCL_BR_LINE 11:unexpected branch // NOLINT(whitespace/line_length) + + if (0 != setenv(SmVupModeEnvVariable, l_pValue, 1)) { // LCOV_EXCL_BR_LINE 5: standard lib error + // LCOV_EXCL_START 5: standard lib error + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + SS_ASERT_ERRNO(0); + l_eStatus = eFrameworkunifiedStatusFail; + // LCOV_EXCL_STOP + } + + return l_eStatus; +} + +int CSystemManager::CreateRtUsb(void) {// LCOV_EXCL_START 8: dead code + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + int pid = -1; + int ret; + + ret = mkdir("/var/run", 0775); + if ((ret < 0) && (errno != EEXIST)) { + return -1; + } + pid = fork(); + switch (pid) { + case 0: /* child process */ + { + struct sched_param param; + int policy; + const char *exec; + exec = const_cast<char *>(TR_USB_PATH); + param.sched_priority = 0; + policy = SCHED_OTHER; + if (sched_setscheduler(getpid(), policy, ¶m) < 0) { + SS_ASERT(0); + _exit(-1); + } + if (setpriority(PRIO_PROCESS, getpid(), 0) < 0) { + SS_ASERT(0); + _exit(-1); + } + // exec + if (execlp(exec, exec, NULL) < 0) { + SS_ASERT(0); + _exit(-1); + } + _exit(0); + } + break; + + case -1: /* error */ + SS_ASERT(0); + goto ERROR; + + default: /* parent process */ + break; + } + +ERROR: + return pid; +}// LCOV_EXCL_STOP + +bool CSystemManager::StoreDebugLogs(const HANDLE h_app, + SS_STORELOGS_OPE_TYPE type) { + bool isMountRamd = false; + EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK; + int pid; + + if (!GetDramPowerStatusInfo(h_app)) { + goto ERROR; + } else if (access(SS_SM_TEMP_FILE_FOR_STORE_LOGS, F_OK) == 0) { + fprintf(stderr, "SS_SysManager/%s/Error: Skip StoreDebugLogs\n", __FUNCTION__); + goto ERROR; + } + + isMountRamd = true; + + if (type == SS_STORELOGS_ILLEGAL) { + UI_32 l_ErrLogCount = 0; + if (PowerHalGetResetInfo(AGL_ERRLOG_COUNTER, &l_ErrLogCount)) { + fprintf(stderr, "SS_SysManager/%s/Error: " + "Could not read AGL_ERRLOG_COUNTER from power_hal\n", __FUNCTION__); + goto ERROR; + } + + if (l_ErrLogCount >= SS_SM_ERR_LOGGING_LIMIT) { + fprintf(stderr, "SS_SysManager/%s/Error: " + "Skip StoreDebugLogs by continuous error l_ErrLogCount=%lu\n", + __FUNCTION__, l_ErrLogCount); + goto ERROR; + } + + l_ErrLogCount++; + if (PowerHalSetResetInfo(AGL_ERRLOG_COUNTER, l_ErrLogCount)) { + // Just logging, don't go to ERROR. + fprintf(stderr, "SS_SysManager/%s/Error: " + "Could not write AGL_ERRLOG_COUNTER to power_hal\n", __FUNCTION__); + } + } else if (type == SS_STORELOGS_ACCOFFON) { + if (0 != unlink(SS_LOGGER_SAVE_INTERFACEUNIFIEDLOG_FLAG)) { + fprintf(stderr, "SS_SysManager/%s/Error: ACCOFFON LOG SAVE\n", __FUNCTION__); + } else { + goto ERROR; + } + } + + pid = fork(); + if (pid == 0) { + int fd = open(SS_SM_TEMP_FILE_FOR_STORE_LOGS, + O_CREAT | O_TRUNC | O_RDWR, 00664); + if (-1 == fd) { // LCOV_EXCL_BR_LINE 5:fd must not be -1 + fprintf(stderr, "SS_SysManager/%s/Error: Failed open %s errno: %d\n", + __FUNCTION__, SS_SM_TEMP_FILE_FOR_STORE_LOGS, errno); + } else { + fsync(fd); + close(fd); + } + FRAMEWORKUNIFIED_SET_ZONES(); // LCOV_EXCL_BR_LINE 15: marco defined in ns_logger_if.h // NOLINT(whitespace/line_length) + NsLogSetLogMethod(LPRINT | LMSGQ); + + if (eFrameworkunifiedStatusOK != (l_eStatus = SS_LoggerStoreLogs(type))) { // LCOV_EXCL_BR_LINE 200: always return OK + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + fprintf(stderr, "SS_SysManager/%s/Error: SS_LoggerStoreDebugLogs() errored: %d\n", __FUNCTION__, l_eStatus); // LCOV_EXCL_LINE 200: always return OK // NOLINT(whitespace/line_length) + } + // Close accessing the RAMD by FRAMEWORKUNIFIEDLOG for RAMD initialization + NsForceClose(); + + if (0 != unlink(SS_SM_TEMP_FILE_FOR_STORE_LOGS)) { + SS_ASERT_ERRNO(0); // LCOV_EXCL_BR_LINE 15: marco defined in ss_templates.h // NOLINT(whitespace/line_length) + } + + exit(0); + } else if (pid == -1) { // LCOV_EXCL_BR_LINE 5:fork error case + // LCOV_EXCL_START 5:fork error case + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + fprintf(stderr, "SS_SysManager/%s/Error: ASSERT %d\n", __FUNCTION__, __LINE__); + // LCOV_EXCL_STOP + } else { + if (-1 == waitpid(pid, NULL, 0)) { // LCOV_EXCL_BR_LINE 5:waitpid error case + // LCOV_EXCL_START 5:waitpid error case + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + fprintf(stderr, "SS_SysManager/%s/Error: ASSERT %d\n", __FUNCTION__, __LINE__); + // LCOV_EXCL_STOP + } + } + ERROR: + return isMountRamd; +} + +#define SS_SM_SCAC_DEVICE_NODE "/dev/scac_driver" +#define SS_SM_SCAC_CMD_SHUTDOWN 0x3000 + +EFrameworkunifiedStatus CSystemManager::SecureChipOff() { + static bool isOffDone = false; + EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK; + int32_t fd; + int32_t res; + + if (!isOffDone) { + fd = open(SS_SM_SCAC_DEVICE_NODE, O_RDWR); + if (fd < 0) { + FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "open(%s) ERR", SS_SM_SCAC_DEVICE_NODE); + l_eStatus = eFrameworkunifiedStatusFail; + } else { + res = ioctl(fd, SS_SM_SCAC_CMD_SHUTDOWN); + if (res < 0) { // LCOV_EXCL_BR_LINE 5: standard lib error + // LCOV_EXCL_START 5: standard lib error + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "ioctl(SS_SM_SCAC_CMD_SHUTDOWN) ERR"); + l_eStatus = eFrameworkunifiedStatusFail; + // LCOV_EXCL_STOP + } + + close(fd); + } + + isOffDone = true; + } else { + FRAMEWORKUNIFIEDLOG(ZONE_STATE, __FUNCTION__, "Skip Chip Off"); + } + + return l_eStatus; +} + +UI_32 CSystemManager::InProgressStateToSendMsg() const { + UI_32 l_iCmd = SS_SYSTEM_MANAGER_PROTOCOL_ENDING_INDEX; + switch (m_SMCurrentState) { + case SS_SM_APPS_PRE_START_IN_PROGRESS: + l_iCmd = SS_SM_PRE_START; + break; + case SS_SM_APPS_PRE_STOP_IN_PROGRESS: + l_iCmd = SS_SM_PRE_STOP; + break; + case SS_SM_APPS_BACKGROUND_START_IN_PROGRESS: + l_iCmd = SS_SM_BACKGROUND_START; + break; + case SS_SM_APPS_BACKGROUND_STOP_IN_PROGRESS: + l_iCmd = SS_SM_BACKGROUND_STOP; + break; + case SS_SM_APPS_START_IN_PROGRESS: + l_iCmd = SS_SM_START; + break; + default: + break; + } + return l_iCmd; +} + +SMModuleState CSystemManager::InProgressStateToState() const { + SMModuleState l_state = MODULE_STATE_INVALID; + switch (m_SMCurrentState) { + case SS_SM_APPS_PRE_START_IN_PROGRESS: + l_state = MODULE_STATE_STARTED_PRE; + break; + case SS_SM_APPS_PRE_STOP_IN_PROGRESS: + l_state = MODULE_STATE_STOPPED_PRE; + break; + case SS_SM_APPS_BACKGROUND_START_IN_PROGRESS: + l_state = MODULE_STATE_STARTED_BACKGROUND; + break; + case SS_SM_APPS_BACKGROUND_STOP_IN_PROGRESS: + l_state = MODULE_STATE_STOPPED_BACKGROUND; + break; + case SS_SM_APPS_START_IN_PROGRESS: + l_state = MODULE_STATE_STARTED; + break; + default: + break; + } + return l_state; +} + +/////////////////////////////////////////////////////////////////////////////// +/// \ingroup SetSystemModeInfoStruct +/// Read ( or initialize ) NVM and set the SystemModeInfo structure +/// +/// \return EFrameworkunifiedStatus +/// Success ==> eFrameworkunifiedStatusOK +/// Failure ==> Other values +/////////////////////////////////////////////////////////////////////////////// +EFrameworkunifiedStatus CSystemManager::SetSystemModeInfoStruct() { + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+"); + EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK; + + if (m_UsingVMPlayer) { + FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__, " 'm_UsingVMPlayer' is True," + " using default SystemModeInfo values"); + m_SystemModeInfo.limpHomeCutoff = epslhcDISABLED; + m_SystemModeInfo.productionMode = epspmDISABLED; + m_SystemModeInfo.transportMode = epstmDISABLED; + m_SystemModeInfo.systemMode = epssinfNORMAL; + m_DataResetMode = e_SS_SM_DATA_RESET_MODE_NONE; + m_ResetCount = 0; + m_ProgUpdateState = SS_SM_PROG_UPDATE_STATE_NONE; + // Don't change the m_SystemModeInfo.startupStage. + // It is set dynamically as System Manager initializes the _CWORD102_. + } else { + uint32_t tmp = 0; + if (PowerHalGetResetInfo(AGL_RESET_COUNTER, &m_ResetCount)) { + FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, + "Could not read AGLRESET_COUNTER from power_hal, assume to 0"); + m_ResetCount = 0; + } + + if (PowerHalGetResetInfo(AGL_PROGUPDATE_STATE, &m_ProgUpdateState)) { + FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, + "Could not read AGL_PROGUPDATE_STATE from power_hal, " + "assume to SS_SM_PROG_UPDATE_STATE_NONE"); + m_ProgUpdateState = SS_SM_PROG_UPDATE_STATE_NONE; + } + + if (PowerHalGetResetInfo(AGL_DATARESET_STATE, &tmp)) { + FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, + "Could not read AGL_DATARESET_STATE from power_hal, " + "assume to e_SS_SM_DATA_REESET_MODE_NONE"); + m_DataResetMode = e_SS_SM_DATA_RESET_MODE_NONE; + } else { + m_DataResetMode = static_cast<ESMDataResetModeInfo>(tmp); + } + m_SystemModeInfo.systemMode = epssinfNORMAL; + } // End else ! m_UsingVMPlayer + + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-"); + return l_eStatus; +} // End of EFrameworkunifiedStatus CSystemManager::SetSystemModeInfoStruct() + +/////////////////////////////////////////////////////////////////////////////// +/// \ingroup ClearDramBackupInfo +/// +/// \param [in] +/// +/// +/// \return EFrameworkunifiedStatus +/// Success ==> eFrameworkunifiedStatusOK +/// Failure ==> Other values +/////////////////////////////////////////////////////////////////////////////// +EFrameworkunifiedStatus CSystemManager::ClearDramBackupInfo(HANDLE hApp) { + EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK; + int ret; + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+"); + + FRAMEWORKUNIFIEDLOG(ZONE_STATE, __FUNCTION__, "PsmClrRamJudgeFlgPower()"); + ret = PsmClrRamJudgeFlgPower(hApp); + if (ret != 0) { // LCOV_EXCL_BR_LINE 11: Excluded due to gcov constraints (others) + SS_ASERT_ERRNO(0); // LCOV_EXCL_BR_LINE 15: marco defined in ss_templates.h // NOLINT(whitespace/line_length) + l_eStatus = eFrameworkunifiedStatusFail; + } + + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-"); + return l_eStatus; +} + +/////////////////////////////////////////////////////////////////////////////// +/// \ingroup CloseApplication +/// Process request to close Application +/// +/// \param [in] +/// +/// +/// \return EFrameworkunifiedStatus +/// Success ==> eFrameworkunifiedStatusOK +/// Failure ==> Other values +/////////////////////////////////////////////////////////////////////////////// +EFrameworkunifiedStatus CSystemManager::CloseApplication(HANDLE hApp) { // LCOV_EXCL_START 6: Because the condition cannot be set + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + EFrameworkunifiedStatus l_eStatus; + + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+"); + + if (eFrameworkunifiedStatusOK + != (l_eStatus = FrameworkunifiedPublishServiceAvailability(hApp, FALSE))) { + LOG_ERROR("FrameworkunifiedPublishServiceAvailability(hApp,FALSE)"); + } else if (eFrameworkunifiedStatusOK != (l_eStatus = + FrameworkunifiedUnRegisterServiceAvailabilityNotification(hApp))) { + LOG_ERROR("FrameworkunifiedUnRegisterServiceAvailabilityNotification(hApp)"); + } else { + FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__, " Successful"); + } + + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-"); + return l_eStatus; +} // End of EFrameworkunifiedStatus CSystemManager::CloseApplication(HANDLE hApp) +// LCOV_EXCL_STOP + +/////////////////////////////////////////////////////////////////////////////// +/// \ingroup SMStateStartCompleteEntry +/// entry for SM module state(SS_SM_APPS_START_COMPLETE) +/// +/// \param +/// +/// \return EFrameworkunifiedStatus +/////////////////////////////////////////////////////////////////////////////// +VOID CSystemManager::SMStateStartCompleteEntry(HANDLE hApp) { + EFrameworkunifiedStatus l_eStatus; + + FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__, + "All %d groups have been sent system_manager protocol message, sending Start Complete to _CWORD56_", + m_SystemStarter.get_id()); + CALL_AND_LOG_STATUS_IF_ERRORED( // LCOV_EXCL_BR_LINE 15: marco defined in ss_templates.h // NOLINT(whitespace/line_length) + send_power_request_complete_response(hApp, "Startup")); // LCOV_EXCL_BR_LINE 15: marco defined in ss_templates.h // NOLINT(whitespace/line_length) + + CALL_AND_LOG_STATUS(PublishPowerOnOffNotification(hApp)); // LCOV_EXCL_BR_LINE 15: marco defined in ss_templates.h // NOLINT(whitespace/line_length) + + if (m_InitialBoot == true) { + m_InitialBoot = false; + + const ESMServiceWakeupStatus l_svcWupStatus = e_SS_SM_SVC_WAKEUP_STATUS_COMPLETE; + + CALL_AND_LOG_STATUS( // LCOV_EXCL_BR_LINE 15: marco defined in ss_templates.h // NOLINT(whitespace/line_length) + FrameworkunifiedNPPublishNotification(hApp, NTFY_SSServiceWakeupStatus, // LCOV_EXCL_BR_LINE 15: marco defined in ss_templates.h // NOLINT(whitespace/line_length) + &l_svcWupStatus, sizeof(ESMServiceWakeupStatus))); // LCOV_EXCL_BR_LINE 15: marco defined in ss_templates.h // NOLINT(whitespace/line_length) + + // If all modules are restarted, a passive warning will be issued + // indicating that Heartbeat is already running. + + UI_32 l_list_num = static_cast<UI_32>(m_HBList.size()); + if (SS_MAX_NUM_MODULES < l_list_num) { + l_list_num = SS_MAX_NUM_MODULES; + FRAMEWORKUNIFIEDLOG(ZONE_WARN, __FUNCTION__, + " Warn: SS_MAX_NUM_MODULES '%d' < m_HBList.size '%d'", + SS_MAX_NUM_MODULES, l_list_num); + } + + CHAR send_data[sizeof(l_list_num) + + (l_list_num * SS_SM_HB_MAX_PROC_NAME_SIZE) + + sizeof(m_SMConfig.HBConfig)]; + CHAR* p_prm = &send_data[0]; + + memcpy(p_prm, reinterpret_cast<char *>(&m_SMConfig.HBConfig), sizeof(m_SMConfig.HBConfig)); + p_prm = p_prm + sizeof(m_SMConfig.HBConfig); + memcpy(p_prm, reinterpret_cast<char *>(&l_list_num), sizeof(l_list_num)); + p_prm = p_prm + sizeof(l_list_num); + + for (UI_32 i = 0; i < l_list_num; i++) { + snprintf(p_prm, SS_SM_HB_MAX_PROC_NAME_SIZE, "%s", m_HBList[i].c_str()); + p_prm = p_prm + SS_SM_HB_MAX_PROC_NAME_SIZE; + } + l_eStatus = SendRequestToHeartBeat(hApp, SS_HEARTBEAT_START, &send_data, static_cast<UI_32>(sizeof(send_data))); // LCOV_EXCL_BR_LINE 11:unexpected branch // NOLINT(whitespace/line_length) + LOG_ERROR_REC_HIST_IF_ERRORED(l_eStatus, "SendRequestToHeartBeat()"); // LCOV_EXCL_BR_LINE 15: marco defined in ss_templates.h // NOLINT(whitespace/line_length) + + m_DataResetMode = e_SS_SM_DATA_RESET_MODE_NONE; + { + uint32_t tmp = static_cast<uint32_t>(m_DataResetMode); + if (PowerHalSetResetInfo(AGL_DATARESET_STATE, tmp)) { + FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, + "Could not set AGL_DATARESET_STATE to power_hal"); + } + } + + m_ProgUpdateState = SS_SM_PROG_UPDATE_STATE_NONE; + if (PowerHalSetResetInfo(AGL_PROGUPDATE_STATE, m_ProgUpdateState)) { + FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, + "Could not set AGL_PROGUPDATE_STATE to power_hal"); + } + + m_isIlgReset = FALSE; + { + uint32_t tmp = static_cast<uint32_t>(m_isIlgReset); + if (PowerHalSetResetInfo(AGL_ILLRESET_FLAG, tmp)) { + FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, + "Could not set AGL_ILLRESET_FLAG to power_hal"); + } + } + + if (access(SS_SM_TEMP_FILE_FOR_STORE_LOGS, F_OK) == 0) { + SS_ASERT_ERRNO(0 == unlink(SS_SM_TEMP_FILE_FOR_STORE_LOGS)); // LCOV_EXCL_BR_LINE 15: marco defined in ss_templates.h // NOLINT(whitespace/line_length) + } + } + + for (vector<std::string>::iterator protectedSvc = + m_productCustomPrm.protectedSvcs.begin(); + protectedSvc != m_productCustomPrm.protectedSvcs.end(); + protectedSvc++) { + ModuleLaunchListIter l_ModuleListIter; + l_eStatus = GetModuleIterator(protectedSvc->c_str(), l_ModuleListIter); + if (eFrameworkunifiedStatusOK == l_eStatus) { + if ((l_ModuleListIter->IsModuleState(MODULE_STATE_STARTED)) + || (l_ModuleListIter->IsModuleState(MODULE_STATE_LAUNCHED) + && !l_ModuleListIter->is_start_required)) { + char pathBuf[128]; + + snprintf(pathBuf, 128, "/proc/%d/oom_score_adj", l_ModuleListIter->pid); // NOLINT + std::ofstream fo(pathBuf); // LCOV_EXCL_BR_LINE 11:unexpected branch // NOLINT(whitespace/line_length) + fo << OOM_SCORE_ADJ_MIN << endl; // LCOV_EXCL_BR_LINE 11:unexpected branch // NOLINT(whitespace/line_length) + fo.close(); // LCOV_EXCL_BR_LINE 11:unexpected branch // NOLINT(whitespace/line_length) + FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__, "set OOM_SCORE_ADJ_MIN(%s/%d)", + l_ModuleListIter->name.c_str(), l_ModuleListIter->pid); + } else { + SS_ASERT(0); // LCOV_EXCL_BR_LINE 15: marco defined in ss_templates.h // NOLINT(whitespace/line_length) + } + } + } + + for (vector<std::string>::iterator groupRelaunchSvc = + m_productCustomPrm.groupRelaunchSvcs.begin(); + groupRelaunchSvc != m_productCustomPrm.groupRelaunchSvcs.end(); + groupRelaunchSvc++) { + ModuleLaunchListIter l_ModuleListIter; + l_eStatus = GetModuleIterator(groupRelaunchSvc->c_str(), l_ModuleListIter); + if (eFrameworkunifiedStatusOK == l_eStatus) { + if ((l_ModuleListIter->IsModuleState(MODULE_STATE_STARTED)) + || (l_ModuleListIter->IsModuleState(MODULE_STATE_LAUNCHED) + && !l_ModuleListIter->is_start_required)) { + GroupRelaunchModuleParams l_param; // LCOV_EXCL_BR_LINE 11:unexpected branch // NOLINT(whitespace/line_length) + l_param.name = l_ModuleListIter->name.c_str(); + m_GroupRelaunchModuleList.push_back(l_param); + + if (l_ModuleListIter->retry_cnt > m_GroupRelaunchLimit) { + m_GroupRelaunchLimit = l_ModuleListIter->retry_cnt; + } + + FRAMEWORKUNIFIEDLOG(ZONE_STATE, __FUNCTION__, "GroupRelaunchSvcs:%s(%d)", + l_ModuleListIter->name.c_str(), l_ModuleListIter->pid); + } else { + FRAMEWORKUNIFIEDLOG(ZONE_STATE, __FUNCTION__, "%s is not Launched", groupRelaunchSvc->c_str()); + } + } else { + FRAMEWORKUNIFIEDLOG(ZONE_STATE, __FUNCTION__, "%s is not exist", groupRelaunchSvc->c_str()); + } + } + FRAMEWORKUNIFIEDLOG(ZONE_STATE, __FUNCTION__, "GroupRelaunchLimit:%d", m_GroupRelaunchLimit); + + SendDeferMsg(hApp); // LCOV_EXCL_BR_LINE 11:unexpected branch // NOLINT(whitespace/line_length) +} // End of VOID CSystemManager::SMStateStartCompleteEntry() + +/////////////////////////////////////////////////////////////////////////////// +/// \ingroup SMStateEntry +/// entry for SM module state +/// +/// \param +/// +/// \return EFrameworkunifiedStatus +/////////////////////////////////////////////////////////////////////////////// +VOID CSystemManager::SMStateEntry(HANDLE hApp, SS_SMModuleState l_SMState) { + switch (l_SMState) { + case SS_SM_APPS_START_COMPLETE: + case SS_SM_APPS_PRE_RUN_COMPLETE: + case SS_SM_APPS_BACKGROUND_RUN_COMPLETE: + SMStateStartCompleteEntry(hApp); + break; + default: + break; + } +} // End of VOID CSystemManager::SMStateEntry(SS_SMModuleState l_SMState) + +/////////////////////////////////////////////////////////////////////////////// +/// \ingroup SMStateExit +/// exit for SM module state +/// +/// \param +/// +/// \return EFrameworkunifiedStatus +/////////////////////////////////////////////////////////////////////////////// +VOID CSystemManager::SMStateExit(HANDLE hApp, SS_SMModuleState l_SMState) { + switch (l_SMState) { + case SS_SM_APPS_START_COMPLETE: + break; + default: + break; + } +} // End of VOID CSystemManager::SMStateExit(SS_SMModuleState l_SMState) + +/////////////////////////////////////////////////////////////////////////////// +/// \ingroup SMSetState +/// set module state +/// +/// \param +/// +/// \return EFrameworkunifiedStatus +/////////////////////////////////////////////////////////////////////////////// +VOID CSystemManager::SMSetState(HANDLE hApp, SS_SMModuleState l_SMNewState) { + // FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+"); + FRAMEWORKUNIFIEDLOG(ZONE_STATE, __FUNCTION__, "%s -> %s", + GetStr(m_SMCurrentState).c_str(), GetStr(l_SMNewState).c_str()); + + if (l_SMNewState != m_SMCurrentState) { + SMStateExit(hApp, m_SMCurrentState); + + m_SMCurrentState = l_SMNewState; + + SMStateEntry(hApp, m_SMCurrentState); + } + // FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-"); +} + +/////////////////////////////////////////////////////////////////////////////// +/// \ingroup register_all_notification_callbacks +/// register all notifications and callbacks with NP_NPS +/// this function gets called when NP_NPS reply launch complete +/// +/// \param +/// +/// \return EFrameworkunifiedStatus +/////////////////////////////////////////////////////////////////////////////// +EFrameworkunifiedStatus CSystemManager::register_all_notification_callbacks(HANDLE hApp) { + EFrameworkunifiedStatus l_eStatus; + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+"); + + FrameworkunifiedNotificationsList userModeNotificationsBOOL[] = { { + NTFY_SSSystemMgrPowerOnOff, sizeof(BOOL), eFrameworkunifiedStateVar }, { + NTFY_SSSystemMgrUserMode, sizeof(BOOL), eFrameworkunifiedStateVar } }; + + FrameworkunifiedNotificationsList userModeNotificationsStruct[] = { { + NTFY_SSSystemMgrPowerOnOff, + sizeof(T_SS_SM_UserModeOnOffNotification_Struct), eFrameworkunifiedStateVar }, { + NTFY_SSSystemMgrUserMode, + sizeof(T_SS_SM_UserModeOnOffNotification_Struct), eFrameworkunifiedStateVar } }; + + FrameworkunifiedNotificationsList sm_notifications[] = { + { NTFY_SSSystemMgrStartUpType, sizeof(EPWR_SC_WAKEUP_TYPE), eFrameworkunifiedStateVar }, + { NTFY_SSSystemMgrDataReset, sizeof(ESMDataResetType), eFrameworkunifiedStateVar }, + { NTFY_SSSystemMgrShutdownStarted, 0, eFrameworkunifiedStateVar }, + { NTFY_SSServiceWakeupStatus, sizeof(ESMServiceWakeupStatus), eFrameworkunifiedStateVar }, + { NTFY_SSNeedAplRestart, 0, eFrameworkunifiedStateVar } }; + + if (m_SMConfig.UMConfig.IsUserModeNotificationABOOL) { + l_eStatus = FrameworkunifiedNPRegisterNotifications(hApp, userModeNotificationsBOOL, + static_cast<UI_32>(_countof(userModeNotificationsBOOL))); + } else { + l_eStatus = FrameworkunifiedNPRegisterNotifications(hApp, + userModeNotificationsStruct, + static_cast<UI_32>(_countof(userModeNotificationsStruct))); + } + + if (eFrameworkunifiedStatusOK != l_eStatus) { + LOG_ERROR("FrameworkunifiedNPRegisterNotifications(userModeNotifications)"); // LCOV_EXCL_BR_LINE 15: marco defined in ss_templates.h // NOLINT(whitespace/line_length) + } else if (eFrameworkunifiedStatusOK != (l_eStatus = FrameworkunifiedNPRegisterNotifications(hApp, sm_notifications, static_cast<UI_32>(_countof(sm_notifications))))) { // LCOV_EXCL_BR_LINE 4:NSFW error case //NOLINT (whitespace/line_length) + // LCOV_EXCL_START 4: nsfw error code + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + LOG_ERROR("FrameworkunifiedNPRegisterNotifications(sm_notifications)"); // LCOV_EXCL_BR_LINE 15: marco defined in ss_templates.h // NOLINT(whitespace/line_length) + // LCOV_EXCL_STOP + } else if (eFrameworkunifiedStatusOK != (l_eStatus = FrameworkunifiedRegisterServiceAvailabilityNotification(hApp, NTFY_SSSystemMgrAvailability))) { // LCOV_EXCL_BR_LINE 4:NSFW error case //NOLINT (whitespace/line_length) + // LCOV_EXCL_START 4: nsfw error code + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + LOG_ERROR("FrameworkunifiedRegisterServiceAvailabilityNotification(" // LCOV_EXCL_BR_LINE 15: marco defined in ss_templates.h // NOLINT(whitespace/line_length) + NTFY_SSSystemMgrAvailability ")"); // LCOV_EXCL_BR_LINE 15: marco defined in ss_templates.h // NOLINT(whitespace/line_length) + // LCOV_EXCL_STOP + } else if (eFrameworkunifiedStatusOK != (l_eStatus = FrameworkunifiedPublishServiceAvailability(hApp, TRUE))) { // LCOV_EXCL_BR_LINE 4:NSFW error case //NOLINT (whitespace/line_length) + // LCOV_EXCL_START 4: nsfw error code + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + LOG_ERROR("FrameworkunifiedPublishServiceAvailability('NTFY_SSSystemMgrAvailability ', TRUE)"); // LCOV_EXCL_BR_LINE 15: marco defined in ss_templates.h // NOLINT(whitespace/line_length) + // LCOV_EXCL_STOP + } else { + LOG_SUCCESS("FrameworkunifiedPublishServiceAvailability('NTFY_SSSystemMgrAvailability ', TRUE)"); // LCOV_EXCL_BR_LINE 15: marco defined in ss_templates.h // NOLINT(whitespace/line_length) + + REC_HIST_IF_SUCCESSFUL(NTFY_SSSystemMgrAvailability, m_PubCmdHist, // LCOV_EXCL_BR_LINE 15: marco defined in ss_templates.h // NOLINT(whitespace/line_length) + m_PubHistIter, "", l_eStatus); // LCOV_EXCL_BR_LINE 15: marco defined in ss_templates.h // NOLINT(whitespace/line_length) + } + + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-"); + return l_eStatus; +} + +/////////////////////////////////////////////////////////////////////////////// +/// \ingroup +/// +/// \param +/// +/// \return +/////////////////////////////////////////////////////////////////////////////// +EFrameworkunifiedStatus CSystemManager::init_Heartbeat(HANDLE hApp) { + EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK; + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+"); + + FrameworkunifiedProtocolCallbackHandler hb_protocol_callbacks[] = { { + SS_HEARTBEAT_PERIODIC_RESP, SysMgrCallback<CSystemManager, + &CSystemManager::OnHeartBeatThreadHeartbeatResponse> }, { + SS_HEARTBEAT_ERROR_DETECTED, SysMgrCallback<CSystemManager, + &CSystemManager::OnHeartBeatErrorDetected> }, { + SS_HEARTBEAT_AVAIL_CHECK_RESP, SysMgrCallback<CSystemManager, + &CSystemManager::OnCheckAvailResponse> } }; // LCOV_EXCL_BR_LINE 11:unexpected branch + + // Subscribe to Notifications (All required notifications) + if (eFrameworkunifiedStatusOK != (l_eStatus = FrameworkunifiedAttachCallbacksToDispatcher(hApp, SS_SMHeartbeat, hb_protocol_callbacks, static_cast<UI_32>(_countof(hb_protocol_callbacks))))) { // LCOV_EXCL_BR_LINE 4:NSFW error case //NOLINT (whitespace/line_length) + // LCOV_EXCL_START 4: nsfw error + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + LOG_ERROR("FrameworkunifiedAttachCallbacksToDispatcher(hb_notification_handlers)"); + // LCOV_EXCL_STOP + } else if (NULL == (m_hHeartbeatThread.m_ThreadHdl = FrameworkunifiedCreateChildThreadWithPriority(hApp, SS_SMHeartbeat, HBThreadStart, HBThreadStop, PR_SMHEARTBEAT))) { // LCOV_EXCL_BR_LINE 4:NSFW error case //NOLINT (whitespace/line_length) + // LCOV_EXCL_START 4: nsfw error + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + l_eStatus = eFrameworkunifiedStatusThreadNotExist; + m_hHeartbeatThread.m_ThreadState = eSM_ThreadNotExist; + LOG_ERROR("FrameworkunifiedCreateChildThreadWithPriority(hApp, SS_SMHeartbeat)"); + // LCOV_EXCL_STOP + } else if (eFrameworkunifiedStatusOK != (l_eStatus = FrameworkunifiedStartChildThread(hApp, m_hHeartbeatThread.m_ThreadHdl, 0, NULL))) { // LCOV_EXCL_BR_LINE 4:NSFW error case //NOLINT (whitespace/line_length) + // LCOV_EXCL_START 4: nsfw error + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + m_hHeartbeatThread.m_ThreadState = eSM_ThreadNotExist; + LOG_ERROR("FrameworkunifiedStartChildThread(SS_SMHeartbeat)"); + // LCOV_EXCL_STOP + } else { + m_hHeartbeatThread.m_ThreadState = eSMThreadIsFine; + } + + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-"); + return l_eStatus; +} + +EFrameworkunifiedStatus CSystemManager::init_sysmem_monitor(HANDLE hApp) { + EFrameworkunifiedStatus l_eStatus; + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+"); + + FrameworkunifiedProtocolCallbackHandler sysmem_protocol_callbacks[] = { { + eSysMemThrdCmd_SYS_LOW_MEMORY, SysMgrCallback<CSystemManager, + &CSystemManager::OnLowSystemMemory> } }; // LCOV_EXCL_BR_LINE 11:unexpected branch // NOLINT(whitespace/line_length) + // LCOV_EXCL_BR_START 4: For setting the initialization conditions at SystemManager startup + if (eFrameworkunifiedStatusOK + != (l_eStatus = FrameworkunifiedAttachCallbacksToDispatcher( + hApp, + m_SysMemMonitor.GetThreadName().c_str(), sysmem_protocol_callbacks, + static_cast<UI_32>(_countof(sysmem_protocol_callbacks))))) { + // LCOV_EXCL_BR_STOP + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + LOG_ERROR("FrameworkunifiedAttachCallbacksToDispatcher()"); // LCOV_EXCL_LINE 4: For setting the initialization conditions at SystemManager startup + } else { + m_SysMemMonitor.SetSLMConfigData(m_SMConfig.SLMConfig); // LCOV_EXCL_BR_LINE 11:unexpected branch // NOLINT(whitespace/line_length) + l_eStatus = m_SysMemMonitor.Initialize(hApp); // LCOV_EXCL_BR_LINE 11:unexpected branch // NOLINT(whitespace/line_length) + LOG_ERROR_REC_HIST_IF_ERRORED // LCOV_EXCL_BR_LINE 6: For setting the initialization conditions at SystemManager startup + (l_eStatus, "m_SysMemMonitor.Initialize(hApp);"); // LCOV_EXCL_BR_LINE 6: For setting the initialization conditions at SystemManager startup + } + + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-"); + return l_eStatus; +} + +/////////////////////////////////////////////////////////////////////////////// +/// \ingroup +/// +/// \param +/// +/// \return +/////////////////////////////////////////////////////////////////////////////// +EFrameworkunifiedStatus CSystemManager::OnGroupLaunchTimerExpiry(HANDLE hThread) { // LCOV_EXCL_START 6: Because the condition cannot be set + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK; + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+"); + UI_32 l_launchID = m_oSystemLauncher.get_id(); + + FRAMEWORKUNIFIEDLOG(ZONE_PERFORMANCE, __FUNCTION__, " Received from group %d", l_launchID); + REC_HIST_IF_SUCCESSFUL("SM_TIMER_GROUP_MONITOR", m_TimerCmdHist, + m_TimerHistIter, "TIMER", l_eStatus); + + LogGroupModulesState(l_launchID, + " Group launch timer expired, processing next group."); + + if (NULL == hThread) { + l_eStatus = eFrameworkunifiedStatusInvldParam; + LOG_ERROR("NULL == hThread"); + } else { + // FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "Timer expired for group id,%d",m_oSystemLauncher.get_id()); + if (!m_oSystemLauncher.is_end()) { + l_launchID = m_oSystemLauncher.advance_id(); + if (eFrameworkunifiedStatusOK != (l_eStatus = OnLaunchGroup(hThread))) { + FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, + " Error: OnLaunchGroup(%d) errored: %d/'%s'", l_launchID, + l_eStatus, GetStr(l_eStatus).c_str()); + } + } + } + + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-"); + return l_eStatus; +} // End of EFrameworkunifiedStatus CSystemManager::OnGroupLaunchTimerExpiry( HANDLE hThread ) +// LCOV_EXCL_STOP + +/////////////////////////////////////////////////////////////////////////////// +/// \ingroup +/// +/// \param +/// +/// \return +/////////////////////////////////////////////////////////////////////////////// +EFrameworkunifiedStatus CSystemManager::FindNameOfTerminatedProcess(SI_32 f_pid, SS_String &f_ModuleName) { + EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusDbRecNotFound; + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+"); + + GroupLaunchMapIter l_GroupIterator = m_MapProclaunchGrps.begin(); + if (l_GroupIterator == m_MapProclaunchGrps.end()) { // LCOV_EXCL_BR_LINE 200: Group Map cannot be empty + // LCOV_EXCL_START 200: Group Map cannot be empty + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "Error : Group Map empty"); // LCOV_EXCL_BR_LINE 15: marco defined in ns_logger_if.h // NOLINT(whitespace/line_length) + l_eStatus = eFrameworkunifiedStatusInvldParam; + // LCOV_EXCL_STOP + } else { + BOOL l_bModuleFound = FALSE; + for (; (FALSE == l_bModuleFound) + && (l_GroupIterator != m_MapProclaunchGrps.end()); + l_GroupIterator++) { + ModuleLaunchListIter l_ModuleListIterator = + l_GroupIterator->second.modules.begin(); + for (; (FALSE == l_bModuleFound) + && (l_ModuleListIterator + != l_GroupIterator->second.modules.end()); + l_ModuleListIterator++) { + if (l_ModuleListIterator->pid == f_pid) { + l_bModuleFound = TRUE; + f_ModuleName = l_ModuleListIterator->name; + l_eStatus = eFrameworkunifiedStatusOK; + } + } + } + } + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-"); + return l_eStatus; +} +/////////////////////////////////////////////////////////////////////////////// +/// \ingroup +/// +/// \param +/// +/// \return +/////////////////////////////////////////////////////////////////////////////// +EFrameworkunifiedStatus CSystemManager::GetBinaryNameOfProcess(SS_String f_ModuleQueueName, + SS_String &f_ModuleBinaryName) { + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+"); + EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusFail; + ModuleLaunchListIter l_moduleIter; + + f_ModuleBinaryName = ""; + l_eStatus = GetModuleIterator(f_ModuleQueueName.c_str(), l_moduleIter); + if (eFrameworkunifiedStatusOK != l_eStatus) { + LOG_ERROR("GetModuleIterator()"); // LCOV_EXCL_BR_LINE 15: marco defined in ss_templates.h // NOLINT(whitespace/line_length) + } else { + size_t l_pos = l_moduleIter->path.find_last_of("\\/"); + if (std::string::npos == l_pos) { // LCOV_EXCL_BR_LINE 5: stdlib error case. + // LCOV_EXCL_START 5: stdlib error case. + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, + " Error. Unable to parse binary name from path %s.", + l_moduleIter->path.c_str()); + // LCOV_EXCL_STOP + } else { + f_ModuleBinaryName = l_moduleIter->path.substr(l_pos + 1); + l_eStatus = eFrameworkunifiedStatusOK; + } + } + + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-"); + return l_eStatus; +} + +/////////////////////////////////////////////////////////////////////////////// +/// \ingroup +/// +/// \param +/// +/// \return +/////////////////////////////////////////////////////////////////////////////// +EFrameworkunifiedStatus CSystemManager::init_process_launcher(HANDLE hApp) { + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+"); + EFrameworkunifiedStatus l_eStatus; + UI_32 TODO = 0; + + FrameworkunifiedProtocolCallbackHandler process_launcher_protocol_callbacks[] = { + // Command ID, Call back functions + { ePLThrdCmd_LAUNCH_MODULE_RESP, SysMgrCallback<CSystemManager, + &CSystemManager::OnModuleLaunchResponse> }, + { ePLThrdCmd_TERMINATE_MODULE_RESP, SysMgrCallback<CSystemManager, + &CSystemManager::OnTerminateModuleResponse> }, + { ePLThrdCmd_RELAUNCH_MODULE_RESP, SysMgrCallback<CSystemManager, + &CSystemManager::OnReLaunchModuleResponse> }, + { ePLThrdCmd_THREAD_STATUS_RESP, SysMgrCallback<CSystemManager, + &CSystemManager::OnProcessLauncherThreadHeartbeatResponse> } }; // LCOV_EXCL_BR_LINE 11:unexpected branch // NOLINT(whitespace/line_length) + + // setup call backs for my children + if (eFrameworkunifiedStatusOK != (l_eStatus = FrameworkunifiedAttachCallbacksToDispatcher(hApp, SS_SMLauncher, process_launcher_protocol_callbacks, static_cast<UI_32>(_countof(process_launcher_protocol_callbacks))))) { // LCOV_EXCL_BR_LINE 4:NSFW error case //NOLINT (whitespace/line_length) + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + LOG_ERROR("FrameworkunifiedAttachCallbacksToDispatcher()"); // LCOV_EXCL_LINE 4: For setting the initialization conditions at SystemManager startup + //////// Create Writer Child Threads handles the writing of data + } else if (NULL == (m_hProcLauncherThread.m_ThreadHdl = FrameworkunifiedCreateChildThreadWithPriority(hApp, SS_SMLauncher, ProcessLauncherOnStart, ProcessLauncherOnStop, PR_SMPROCLAUNCH))) { // LCOV_EXCL_BR_LINE 4:NSFW error case //NOLINT (whitespace/line_length) + // LCOV_EXCL_START 4: For setting the initialization conditions at SystemManager startup + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + l_eStatus = eFrameworkunifiedStatusNullPointer; + m_hProcLauncherThread.m_ThreadState = eSM_ThreadNotExist; + FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, + " Error: FrameworkunifiedCreateChildThreadWithPriority(%s) errored: %d/'%s'", + SS_SMLauncher, l_eStatus, GetStr(l_eStatus).c_str()); + // LCOV_EXCL_STOP + } else if (eFrameworkunifiedStatusOK != (l_eStatus = FrameworkunifiedStartChildThread(hApp, m_hProcLauncherThread.m_ThreadHdl, sizeof(UI_32), &TODO))) { // LCOV_EXCL_BR_LINE 4:NSFW error case //NOLINT (whitespace/line_length) + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + m_hProcLauncherThread.m_ThreadState = // LCOV_EXCL_LINE 4: For setting the initialization conditions at SystemManager startup + eSM_ThreadNotExist; // LCOV_EXCL_LINE 4: For setting the initialization conditions at SystemManager startup + LOG_ERROR("FrameworkunifiedStartChildThread()"); // LCOV_EXCL_LINE 4: For setting the initialization conditions at SystemManager startup + } else { + m_hProcLauncherThread.m_ThreadState = eSMThreadIsFine; + } + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-"); + return l_eStatus; +} + +EFrameworkunifiedStatus CSystemManager::OnGroupLaunchWaitTimeout(HANDLE hApp) { + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+"); + EFrameworkunifiedStatus l_eStatus; + SetCmdHist("SM_TIMER_GROUP_LAUNCH_WAIT_TIMER", m_TimerCmdHist, m_TimerHistIter, FrameworkunifiedGetMsgSrc(hApp)); // LCOV_EXCL_BR_LINE 11:unexpected branch // NOLINT(whitespace/line_length) + CALL_AND_LOG_STATUS(OnLaunchGroup(hApp)); // LCOV_EXCL_BR_LINE 15: marco defined in ss_templates.h // NOLINT(whitespace/line_length) + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-"); + return l_eStatus; +} + +/////////////////////////////////////////////////////////////////////////////// +/// \ingroup +/// +/// \param +/// +/// \return +/////////////////////////////////////////////////////////////////////////////// +EFrameworkunifiedStatus CSystemManager::OnModuleLaunchResponse(HANDLE hApp) { + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+"); + EFrameworkunifiedStatus l_eStatus; + INTERFACEUNIFIEDLOG_RECEIVED_FROM(hApp); // LCOV_EXCL_BR_LINE 15: marco defined in ns_logger_if.h // NOLINT(whitespace/line_length) + FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__, "from %s", FrameworkunifiedGetMsgSrc(hApp)); + + GroupLaunchMapIter l_GroupIter; + ModuleLaunchListIter l_ModuleIter; + UI_32 l_launchID = m_oSystemLauncher.get_id(); + + l_eStatus = PerformModuleLaunchRespProcessing(hApp, l_GroupIter, l_ModuleIter, "ML"); + if (eFrameworkunifiedStatusOK != l_eStatus) { + LOG_ERROR("PerformModuleLaunchRespProcessing()"); // LCOV_EXCL_BR_LINE 15: marco defined in ss_templates.h // NOLINT(whitespace/line_length) + } else if (l_GroupIter->second.id == l_launchID) { + BOOL IsGroupLaunchComplete = TRUE; + // Search the group for any module that has not completed launching. + for (l_ModuleIter = l_GroupIter->second.modules.begin(); + IsGroupLaunchComplete && (l_ModuleIter != l_GroupIter->second.modules.end()); + l_ModuleIter++) { + IsGroupLaunchComplete = !l_ModuleIter->IsModuleState(MODULE_STATE_LAUNCHING); + } + + if (IsGroupLaunchComplete) { + m_GroupLaunchTimer->StopTimer(m_aTimerIDs[eSM_TIMER_GROUP_MONITOR]); + l_GroupIter->second.launch_complete = TRUE; + FRAMEWORKUNIFIEDLOG(ZONE_STATE, __FUNCTION__, "Group%d LaunchComp", l_GroupIter->second.id); + + if (!m_oSystemLauncher.is_end()) { + l_launchID = m_oSystemLauncher.advance_id(); + FRAMEWORKUNIFIEDLOG(ZONE_STATE, __FUNCTION__, "Next group:%d", l_launchID); + if (FALSE == l_GroupIter->second.grp_wait_for_trigger) { + UI_32 l_Sec = (l_GroupIter->second.grp_launch_wait) / (1000 * 1000); + UI_32 l_mSec = 0; + if (l_Sec > 0) { + l_mSec = ((l_GroupIter->second.grp_launch_wait) % (1000 * 1000)) / 1000; + } else { + l_mSec = (l_GroupIter->second.grp_launch_wait) / 1000; + } + m_GroupLaunchTimer->StartTimer( + m_aTimerIDs[eSM_TIMER_GROUP_LAUNCH_WAIT_TIMER], l_Sec, l_mSec, 0, 0); + } else { + // Start the timer for group trigger... added for optimization + m_GroupLaunchTimer->StartTimer( + m_aTimerIDs[eSM_TIMER_LAUNCH_GROUP_TRIGGER_PROC_RESP_TIMER], + SS_LAUNCH_GROUP_TRIGGER_TIMER_CONFIG, 0, 0, 0); + } + } + } else { + FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__, " Group %d/%s LaunchIncomp", l_launchID, + l_GroupIter->second.name.c_str()); + } + } else { + FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__, + " '%s' ( Group %d/%s ) Launch Response received late - " + "group id is now %d", l_ModuleIter->name.c_str(), + l_GroupIter->second.id, l_GroupIter->second.name.c_str() + , l_launchID); + } + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-"); + return l_eStatus; +} + +EFrameworkunifiedStatus CSystemManager::OnReLaunchModuleResponse(HANDLE hApp) { + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+"); + EFrameworkunifiedStatus l_eStatus; + INTERFACEUNIFIEDLOG_RECEIVED_FROM(hApp); // LCOV_EXCL_BR_LINE 15: marco defined in ss_templates.h // NOLINT(whitespace/line_length) + FRAMEWORKUNIFIEDLOG(ZONE_PERFORMANCE, __FUNCTION__, "from %s", FrameworkunifiedGetMsgSrc(hApp)); + + GroupLaunchMapIter l_GroupIter; + ModuleLaunchListIter l_ModuleIter; + + l_eStatus = PerformModuleLaunchRespProcessing(hApp, l_GroupIter, l_ModuleIter, "RL"); + LOG_ERROR_REC_HIST_IF_ERRORED(l_eStatus, "PerformModuleLaunchRespProcessing()"); // LCOV_EXCL_BR_LINE 15: marco defined in ss_system_manager.h // NOLINT(whitespace/line_length) + + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-"); + return l_eStatus; +} // End of EFrameworkunifiedStatus CSystemManager::OnReLaunchModuleResponse( HANDLE hApp ) + + +EFrameworkunifiedStatus CSystemManager::PerformModuleLaunchRespProcessing(HANDLE hApp, + GroupLaunchMapIter & f_GroupIter, ModuleLaunchListIter & f_ModuleIter, + PCSTR p_sPPD_tag) { + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+"); + EFrameworkunifiedStatus l_eStatus; + T_ProcessLaunchResp l_LaunchRespData; + + // ReadMsg(): * + // Check hApp ptr, msg size, msg reception, read msg if all ok. * + // Report any errors found. * + // * + if (eFrameworkunifiedStatusOK != (l_eStatus = ReadMsg < T_ProcessLaunchResp > (hApp, l_LaunchRespData))) { // LCOV_EXCL_BR_LINE 4: nsfw error // NOLINT(whitespace/line_length) + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + LOG_ERROR("ReadMsg()"); // LCOV_EXCL_LINE 4: nsfw error + } else { + BOOL b_DidModuleLaunch = FALSE; + f_GroupIter = l_LaunchRespData.groupIterator; + f_ModuleIter = l_LaunchRespData.moduleIterator; + SS_String l_ModulePath = l_LaunchRespData.path; + + FRAMEWORKUNIFIEDLOG(ZONE_PERFORMANCE, __FUNCTION__, "%s(%d)", l_LaunchRespData.name, l_LaunchRespData.pid); + + if (l_LaunchRespData.pid == -1) { + f_ModuleIter->pid = -1; + + FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, " Error: Process launch failed: %s, %s", + f_ModuleIter->name.c_str(), l_ModulePath.c_str()); + + /// TODO + /// If PID is -1, launch had failed. Add logic to do necessary action. + + f_ModuleIter->SetModuleState(MODULE_STATE_LAUNCH_FAILED); + } else if (l_LaunchRespData.pid == 0x7FFFFFFF) { + FRAMEWORKUNIFIEDLOG(ZONE_WARN, __FUNCTION__, " Warning: '%s', '%s' already launched", + f_ModuleIter->name.c_str(), l_ModulePath.c_str()); + + b_DidModuleLaunch = TRUE; + } else { + f_ModuleIter->pid = l_LaunchRespData.pid; + b_DidModuleLaunch = TRUE; + } + + if (b_DidModuleLaunch) { + // + // Module state could already be MODULE_STATE_CONNECTED if + // module process ran before process launcher thread completed; + // don't overwrite/reset the MODULE_STATE_CONNECTED state. + if (f_ModuleIter->IsModuleState(MODULE_STATE_LAUNCHING)) { + f_ModuleIter->SetModuleState(MODULE_STATE_LAUNCHED); + } + + l_eStatus = f_ModuleIter->GetPriority(f_ModuleIter->current_priority); + if (eFrameworkunifiedStatusOK != l_eStatus) { + FRAMEWORKUNIFIEDLOG(ZONE_WARN, __FUNCTION__, " Warning: f_ModuleIter->GetPriority( " + "f_ModuleIter->current_priority ) returned %d/'%s'. " + "Setting 'current_priority' = 'configuration_priority' %d.", + l_eStatus, GetStr(l_eStatus).c_str(), + f_ModuleIter->configuration_priority); + f_ModuleIter->current_priority = f_ModuleIter->configuration_priority; + l_eStatus = eFrameworkunifiedStatusOK; + } + } + } + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-"); + return l_eStatus; +} // End of EFrameworkunifiedStatus CSystemManager::PerformModuleLaunchRespProcessing( + +/////////////////////////////////////////////////////////////////////////////// +/// \ingroup OnTerminateModuleResponse +/// +/// \param HANDLE hApp +/// +/// \return EFrameworkunifiedStatus +/////////////////////////////////////////////////////////////////////////////// +EFrameworkunifiedStatus CSystemManager::OnTerminateModuleResponse(HANDLE hApp) { + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+"); + EFrameworkunifiedStatus l_eStatus; + T_ProcessLauncherTerminationResp l_TerminateRespData; + INTERFACEUNIFIEDLOG_RECEIVED_FROM(hApp); // LCOV_EXCL_BR_LINE 15: marco defined in ss_templates.h // NOLINT(whitespace/line_length) + FRAMEWORKUNIFIEDLOG(ZONE_STATE, __FUNCTION__, " from %s", FrameworkunifiedGetMsgSrc(hApp)); + + // ReadMsg(): * + // Check hApp ptr, msg size, msg reception, read msg if all ok. * + // Report any errors found. * + // * + if (eFrameworkunifiedStatusOK != (l_eStatus = ReadMsg < T_ProcessLauncherTerminationResp + > (hApp, l_TerminateRespData))) { + LOG_ERROR("ReadMsg()"); // LCOV_EXCL_BR_LINE 15: marco defined in ss_templates.h // NOLINT(whitespace/line_length) + } else { + ModuleLaunchListIter l_ModuleIter = l_TerminateRespData.moduleIterator; + + SS_String l_ModulePath = m_BinaryFilesPath + l_ModuleIter->path; + + if ((0 == strcmp(l_ModulePath.c_str(), l_TerminateRespData.path)) + && (0 == strcmp(l_ModuleIter->arguments.c_str(), + l_TerminateRespData.args))) { + l_ModuleIter->pid = 0; + FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__, " %s Termination successful", + l_ModuleIter->name.c_str()); + } else { + if (0 != strcmp(l_ModulePath.c_str(), l_TerminateRespData.path)) { + FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, + " Error: ModuleIter->path != l_TerminateRespData.path" + " \" '%s' != '%s' \"", l_ModuleIter->path.c_str(), + l_TerminateRespData.path); + } + if (0 != strcmp(l_ModuleIter->arguments.c_str(), + l_TerminateRespData.args)) { + FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, " Error: ModuleIter->arguments != " + "l_TerminateRespData.args, \" '%s' != '%s' \"", + l_ModuleIter->arguments.c_str(), l_TerminateRespData.args); + } + } + } + + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-"); + return l_eStatus; +} // End of EFrameworkunifiedStatus CSystemManager::OnTerminateModuleResponse( HANDLE hApp ) + +/////////////////////////////////////////////////////////////////////// +/// \ingroup ReadPathAndFileNameEnvironmentVariables +/// +/// \param +/// +/// \return VOID +/////////////////////////////////////////////////////////////////////////////// +VOID CSystemManager::ReadPathFromEnvironmentVariables() { + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+"); // LCOV_EXCL_BR_LINE 15: marco defined in ns_logger_if.h // NOLINT(whitespace/line_length) + CHAR *l_pEnvVariable = NULL; + + // read Path from environment variable + if (NULL == (l_pEnvVariable = std::getenv(BaseDirPathEnvVariable))) { + // Environment variable not set, set it to default path + FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__, "Using Default path for Binary Files : %s", DefaultBasePath); + m_BinaryFilesPath = DefaultBasePath; + + FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__, "Using Default path for Config Files : %s%s", + DefaultBasePath, DefaultConfigFilesPath); + m_ConfigFilesPath = DefaultBasePath; + } else { + // set path of binary files + m_BinaryFilesPath = l_pEnvVariable; + + // set path of configuration files + m_ConfigFilesPath = l_pEnvVariable; + } + // set path of configuration files + m_ConfigFilesPath += DefaultConfigFilesPath; + + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-"); + return; +} + +/////////////////////////////////////////////////////////////////////// +/// \ingroup GetConfigDataFileNameFromEnvironmentVariable +/// +/// \param +/// +/// \return SS_String +/////////////////////////////////////////////////////////////////////////////// +SS_String CSystemManager::ReadLaunchConfigFileNameFromEnvironmentVariable() { + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+"); + CHAR *l_pEnvVariable = NULL; + SS_String l_FileName; + + // read Launch Config File Name from environment variable + // LCOV_EXCL_BR_START 5: standard lib error + if (NULL == (l_pEnvVariable = std::getenv(LaunchConfigFileNameEnvVariable))) { + // LCOV_EXCL_BR_STOP + // Environment variable not set, set it to default file name + // LCOV_EXCL_START 5: standard lib error + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__, " Using Default Launch Configuration file : %s", + DefaultLaunchConfigFileName); + l_FileName = DefaultLaunchConfigFileName; + // LCOV_EXCL_STOP + } else { + l_FileName = l_pEnvVariable; + } + + FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__, " Using Launch Configuration file: %s", l_FileName.c_str()); + + SS_String retStr = m_ConfigFilesPath + l_FileName; // LCOV_EXCL_BR_LINE 11:unexpected branch // NOLINT(whitespace/line_length) + if (access(retStr.c_str(), F_OK) != 0) { // LCOV_EXCL_BR_LINE 5: standard lib error + // LCOV_EXCL_START 5: standard lib error + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + FRAMEWORKUNIFIEDLOG(ZONE_WARN, __FUNCTION__, "no found %s", retStr.c_str()); + SS_ASERT(0); + // LCOV_EXCL_STOP + } + return retStr; +} + +/////////////////////////////////////////////////////////////////////// +/// \ingroup GetConfigDataFileNameFromEnvironmentVariable +/// +/// \param +/// +/// \return SS_String +/////////////////////////////////////////////////////////////////////////////// +SS_String CSystemManager::ReadConfigDataFileNameFromEnvironmentVariable() { + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+"); + CHAR *l_pEnvVariable = NULL; + SS_String l_FileName = ""; + + // read SM Config Data File Name from environment variable + // LCOV_EXCL_BR_START 5: standard lib error + if (NULL == (l_pEnvVariable = std::getenv(SMConfigDataFileNameEnvVariable))) { + // LCOV_EXCL_BR_STOP 5: standard lib error + // LCOV_EXCL_START 5: standard lib error + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + // Environment variable not set, set it to default file name + FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__, "Using Default Configuration Data file : %s", DefaultSMConfigFileName); + l_FileName = DefaultSMConfigFileName; + // LCOV_EXCL_STOP + } else { + l_FileName = l_pEnvVariable; + } + + SS_String retStr = m_ConfigFilesPath + l_FileName; // LCOV_EXCL_BR_LINE 11:unexpected branch // NOLINT(whitespace/line_length) + if (access(retStr.c_str(), F_OK) != 0) { // LCOV_EXCL_BR_LINE 5: standard lib error + // LCOV_EXCL_START 5: standard lib error + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + FRAMEWORKUNIFIEDLOG(ZONE_WARN, __FUNCTION__, "no found %s", retStr.c_str()); + SS_ASERT(0); + // LCOV_EXCL_STOP + } + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-"); + return retStr; +} + +/////////////////////////////////////////////////////////////////////// +/// \ingroup ReadUsingVMPlayerEnvironmentVariable +/// +/// \param +/// +/// \return VOID +/////////////////////////////////////////////////////////////////////////////// +VOID CSystemManager::ReadUsingVMPlayerEnvironmentVariable() { + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+"); + CHAR *l_pEnvVariable = std::getenv(UsingVMPlayerVariable); + m_UsingVMPlayer = (NULL != l_pEnvVariable); + FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__, " %sunning on a VMPlayer", + m_UsingVMPlayer ? "R" : "Not r"); + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-"); + return; +} // End of VOID CSystemManager::ReadUsingVMPlayerEnvironmentVariable() + +/////////////////////////////////////////////////////////////////////////////// +/// \ingroup +/// +/// \param +/// +/// \return +/////////////////////////////////////////////////////////////////////////////// +EFrameworkunifiedStatus CSystemManager::start_process_launching(HANDLE hApp) { + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+"); + EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK; + BOOL l_bIsGoodRc; + SS_String l_SMConfigFile(ReadConfigDataFileNameFromEnvironmentVariable()); + SMConfigParams SMConfigData; + SS_String l_LaunchConfigFile(ReadLaunchConfigFileNameFromEnvironmentVariable()); // LCOV_EXCL_BR_LINE 11:unexpected branch // NOLINT(whitespace/line_length) + SysMgrConfiguration l_launchConfig; + + FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__, " Reading %s Configuration Data from %s", + SERVICE_SYSMANAGER, l_SMConfigFile.c_str()); + + l_bIsGoodRc = SMConfigData.LoadSMConfigParameters(m_SMConfig, l_SMConfigFile); + + if (!l_bIsGoodRc) { // LCOV_EXCL_BR_LINE 6: For setting the initialization conditions at SystemManager startup + // LCOV_EXCL_START 6: For setting the initialization conditions at SystemManager startup + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, + " Error: SMConfigData.LoadSMConfigParameters(m_SMConfig, " + " %s) returned FALSE", l_SMConfigFile.c_str()); + l_eStatus = eFrameworkunifiedStatusFileLoadError; + // LCOV_EXCL_STOP + } else { + SMSetState(hApp, SS_SM_APPS_LAUNCH_IN_PROGRESS); // LCOV_EXCL_BR_LINE 11:unexpected branch // NOLINT(whitespace/line_length) + FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__, " Reading Launch Configuration Data from %s", + l_LaunchConfigFile.c_str()); + + SS_String l_launchOrderName = "DEFAULT"; // LCOV_EXCL_BR_LINE 11:unexpected branch // NOLINT(whitespace/line_length) + LaunchOrderedVector l_OrderList; + + l_bIsGoodRc = l_launchConfig.LoadParametersCfg(m_MapProclaunchGrps, + m_MapProcNames, l_OrderList, l_launchOrderName, l_LaunchConfigFile); + + if (l_OrderList.size() != 0) { // LCOV_EXCL_BR_LINE 6: For setting the initialization conditions at SystemManager startup + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + FRAMEWORKUNIFIEDLOG(ZONE_STATE, __FUNCTION__, "wakeup order:%s", + l_launchOrderName.c_str()); + } else { + FRAMEWORKUNIFIEDLOG(ZONE_STATE, __FUNCTION__, "wakeup order:DEFAULT"); + } + + if (!l_bIsGoodRc) { // LCOV_EXCL_BR_LINE 6: For setting the initialization conditions at SystemManager startup + // LCOV_EXCL_START 6: For setting the initialization conditions at SystemManager startup + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, " Error: l_launchConfig.LoadParametersCfg( " + "m_MapProclaunchGrps, m_MapProcNames, %s ) returned FALSE", + l_LaunchConfigFile.c_str()); + l_eStatus = eFrameworkunifiedStatusFileLoadError; + // LCOV_EXCL_STOP + } else { + m_SystemLaunchProgress = SS_SM_INITIAL_GROUP; + // l_launchConfig.PrintAllInfo( m_MapProclaunchGrps ); + + FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__, " System Launch Started"); + // Don't use DynamicLaunch because its dependency on the services table is complex + SS_SOURCE source_type = SS_SOURCE_FM; + + m_oSystemLauncher.configure_dynamic_launch(source_type, m_MapProclaunchGrps, l_OrderList); + m_oSystemLauncher.copyDynOrderedVector(m_SystemStarter); + // m_SystemStarter.print_info(); + + // start the timer upon successful launching of first process + FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__, + "Starting Module Connection Timeout timer with %d sec period", + m_SMConfig.MCConfig.ModuleConnectionTimeOutSec); + m_GroupLaunchTimer->StartTimer( + m_aTimerIDs[eSM_TIMER_MODULE_CONNECT_WAIT_TIMER], + m_SMConfig.MCConfig.ModuleConnectionTimeOutSec, 0, + m_SMConfig.MCConfig.ModuleConnectionTimeOutSec, 0); // LCOV_EXCL_BR_LINE 11:unexpected branch // NOLINT(whitespace/line_length) + CALL_AND_LOG_STATUS(OnLaunchGroup(hApp)); // LCOV_EXCL_BR_LINE 6: For setting the initialization conditions at SystemManager startup + } + } + + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-"); + return l_eStatus; +} + + +EFrameworkunifiedStatus CSystemManager::GetLastSourceInfo(SS_SOURCE &source_type) { // LCOV_EXCL_START 8: Because the condition cannot be set + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+"); + EFrameworkunifiedStatus l_eStatus; + + CHAR LastSource[64 + 1] = { '\0' }; + l_eStatus = NPSynchronousReadPersistentData(SERVICE_AS_MODE, + NTFY_SSLastSourceType, LastSource, static_cast<UI_32>(sizeof(LastSource) - 1)); + if (eFrameworkunifiedStatusOK != l_eStatus) { + LOG_ERROR("NPSynchronousReadPersistentData(" + SERVICE_AS_MODE "," NTFY_SSLastSourceType); + } else { + std::string tempstr(LastSource); + FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__, " String got from persistence %s", LastSource); + UI_32 pos = static_cast<UI_32>(tempstr.find("_")); + std::string tempstr2 = tempstr.substr(0, pos); + UI_64 value = strtoull(tempstr2.c_str(), 0, 10); + source_type = static_cast<SS_SOURCE>((UI_32)(value >> 32) & 0x0000FFFF); + } + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-"); + return l_eStatus; +} + +EFrameworkunifiedStatus CSystemManager::OnLaunchGroupTriggerProcessResponse(HANDLE hApp) { + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+"); + EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK; + INTERFACEUNIFIEDLOG_RECEIVED_FROM(hApp); + UI_32 l_groupID; + + FRAMEWORKUNIFIEDLOG(ZONE_STATE, __FUNCTION__, "from %s", FrameworkunifiedGetMsgSrc(hApp)); + SetCmdHist("SS_SM_GROUP_LAUNCH_TRIGGER", m_SMCmdHist, m_SMHistIter, FrameworkunifiedGetMsgSrc(hApp)); + // stop group launch trigger process response timer + m_GroupLaunchTimer->StopTimer(m_aTimerIDs[eSM_TIMER_LAUNCH_GROUP_TRIGGER_PROC_RESP_TIMER]); + + if (eFrameworkunifiedStatusOK != (l_eStatus = ReadMsg < UI_32 > (hApp, l_groupID))) { + LOG_ERROR("ReadMsg()"); + } else { + SS_SOURCE source_type = SS_SOURCE_NA; + l_eStatus = GetLastSourceInfo(source_type); + + if ((SS_SOURCE_AM == source_type) || (SS_SOURCE_FM == source_type) + || (SS_SOURCE_FM_DAB == source_type) || (SS_SOURCE_SDARS == source_type)) { + if (l_groupID == m_oSystemLauncher.get_id()) { + CALL_AND_LOG_STATUS(OnLaunchGroup(hApp)); + } else { + FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, + " Error: Received Group ID %d != Sys Mgr Group ID %d", l_groupID, + m_oSystemLauncher.get_id()); + l_eStatus = eFrameworkunifiedStatusInvldParam; + } + } else { // media is last source + CALL_AND_LOG_STATUS(OnLaunchGroup(hApp)); + } + } + + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-"); + return l_eStatus; +} + +EFrameworkunifiedStatus CSystemManager::OnLaunchGroupTriggerProcessResponseTimerExpiry(HANDLE hApp) { + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+"); + EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK; + INTERFACEUNIFIEDLOG_RECEIVED_FROM(hApp); + REC_HIST_IF_SUCCESSFUL("SM_TIMER_LAUNCH_GROUP_TRIGGER", m_TimerCmdHist, + m_TimerHistIter, FrameworkunifiedGetMsgSrc(hApp), l_eStatus); + CALL_AND_LOG_STATUS(OnLaunchGroup(hApp)); + + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-"); + return l_eStatus; +} + +/////////////////////////////////////////////////////////////////////////////// +/// \ingroup +/// +/// \param +/// +/// \return +/////////////////////////////////////////////////////////////////////////////// +EFrameworkunifiedStatus CSystemManager::OnLaunchGroupSelfTrigger(HANDLE hApp) { + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+"); + EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK; + + FRAMEWORKUNIFIEDLOG(ZONE_STATE, __FUNCTION__, "from %s", FrameworkunifiedGetMsgSrc(hApp)); + + REC_HIST_IF_SUCCESSFUL("SS_SM_SendTriggerToSelf", m_SMCmdHist, m_SMHistIter, + FrameworkunifiedGetMsgSrc(hApp), l_eStatus); + + CALL_AND_LOG_STATUS(OnLaunchGroup(hApp)); + + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-"); + return l_eStatus; +} +// LCOV_EXCL_STOP + +/////////////////////////////////////////////////////////////////////////////// +/// \ingroup +/// +/// \param +/// +/// \return +/////////////////////////////////////////////////////////////////////////////// +EFrameworkunifiedStatus CSystemManager::OnLaunchGroup(HANDLE hApp) { + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+"); + EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK; + GroupLaunchMapIter l_GroupIter; + UI_32 l_launch_ID = m_oSystemLauncher.get_id(); + + // FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__, " Launching group %d", l_launch_ID ); + + l_GroupIter = m_MapProclaunchGrps.find(l_launch_ID); + + if (l_GroupIter->second.launch_complete == FALSE) { // LCOV_EXCL_BR_LINE 6: Because it is not called for a condition that results in "TRUE" + // FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__ + // , " m_bIsNPP_ServicesStarted ? %s, group.id: %d, Launch_Group: %d" + // , m_bIsNPP_ServicesStarted ? "Yes" : "No" + // , l_GroupIter->second.id + // , m_SystemLaunchProgress ); + + if ((m_bIsNPP_ServicesStarted && m_bIsBackupAvail) || (l_GroupIter->second.id <= 2)) { // LCOV_EXCL_BR_LINE 6: Because it is not called for the condition that results in "FALSE" // NOLINT(whitespace/line_length) + ModuleLaunchListIter l_ModuleListIterator = l_GroupIter->second.modules.begin(); + if (l_ModuleListIterator != l_GroupIter->second.modules.end()) { // LCOV_EXCL_BR_LINE 6: For setting the initialization conditions at SystemManager startup // NOLINT(whitespace/line_length) + // FRAMEWORKUNIFIEDLOG(ZONE_PERFORMANCE, __FUNCTION__, "GRPLCH,(start),%d,%s", + // l_GroupIter->second.id,l_GroupIter->second.name.c_str()); + + FRAMEWORKUNIFIEDLOG(ZONE_STATE, __FUNCTION__, "Launching Group%d/%s", + l_GroupIter->second.id, l_GroupIter->second.name.c_str()); + SS_String l_ModulePath; + for (; l_ModuleListIterator != l_GroupIter->second.modules.end(); l_ModuleListIterator++) { + if (l_ModuleListIterator->IsModuleState(MODULE_STATE_INVALID)) { + char l_cFormat[] = "SendRequestToLauncher(%s, " + "ePLThrdCmd_LAUNCH_MODULE_REQST)"; + char l_cBuf[sizeof(l_cFormat) + MAX_NAME_SIZE_APP]; + snprintf(l_cBuf, sizeof(l_cBuf), l_cFormat, + l_ModuleListIterator->name.c_str()); + + l_eStatus = SendRequestToLauncher(hApp, l_ModuleListIterator, // LCOV_EXCL_BR_LINE 11:unexpected branch // NOLINT(whitespace/line_length) + ePLThrdCmd_LAUNCH_MODULE_REQST, // LCOV_EXCL_BR_LINE 11:unexpected branch // NOLINT(whitespace/line_length) + "ePLThrdCmd_LAUNCH_MODULE_REQST"); // LCOV_EXCL_BR_LINE 11:unexpected branch // NOLINT(whitespace/line_length) + + if (eFrameworkunifiedStatusOK != l_eStatus) { // LCOV_EXCL_BR_LINE 6: For setting the initialization conditions at SystemManager startup // NOLINT(whitespace/line_length) + // LCOV_EXCL_START 6: For setting the initialization conditions at SystemManager startup // NOLINT(whitespace/line_length) + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + l_ModuleListIterator->SetModuleState( + MODULE_STATE_LAUNCH_FAILED); + SetCmdHist(l_cBuf, m_ErrHist, m_ErrHistIter, + GetStr(l_eStatus).c_str()); + // LCOV_EXCL_STOP + } else { + l_ModuleListIterator->SetModuleState(MODULE_STATE_LAUNCHING); + } + } else { + l_ModulePath = (m_BinaryFilesPath + l_ModuleListIterator->path); // LCOV_EXCL_BR_LINE 11:unexpected branch // NOLINT(whitespace/line_length) + FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__, + " Not launching %s: module state is %s", + l_ModulePath.c_str(), + l_ModuleListIterator->ModuleStateStr().c_str()); + } + } + + // LCOV_EXCL_BR_START 6: For setting the initialization conditions at SystemManager startup // NOLINT(whitespace/line_length) + if (FALSE == + l_GroupIter->second.grp_wait_for_trigger) { + // LCOV_EXCL_BR_STOP + m_GroupLaunchTimer->StartTimer(m_aTimerIDs[eSM_TIMER_GROUP_MONITOR], + SS_GROUP_LAUNCH_TIMER_CONFIG, 0, 0, 0); // LCOV_EXCL_BR_LINE 11:unexpected branch // NOLINT(whitespace/line_length) + } + } + } + + if (m_oSystemLauncher.is_end()) { // LCOV_EXCL_BR_LINE 6: For setting the initialization conditions at SystemManager startup // NOLINT(whitespace/line_length) + FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__, "System Launch Completed"); + + if (epssusSYSTEM_SERVICES_STARTED == m_SystemModeInfo.startupStage) { + // If startupStage == SYSTEM_SERVICES_STARTED, a notification is requested because there are SVCs required for notification to the _CWORD56_. + l_eStatus = SendSystemModeInfoResponse(hApp, epssusALL_SERVICES_LAUNCHED); + LOG_ERROR_REC_HIST_IF_ERRORED(l_eStatus, // LCOV_EXCL_BR_LINE 15: marco defined in ss_system_manager.h // NOLINT(whitespace/line_length) + "UpdateStartupStageState_SendSystemModeInfoResponse" // LCOV_EXCL_BR_LINE 15: marco defined in ss_system_manager.h // NOLINT(whitespace/line_length) + "( epssusALL_SERVICES_LAUNCHED )"); // LCOV_EXCL_BR_LINE 15: marco defined in ss_system_manager.h // NOLINT(whitespace/line_length) + } + + m_SystemModeInfo.startupStage = epssusALL_SERVICES_LAUNCHED; + + if (is_current_state(SS_SM_APPS_LAUNCH_IN_PROGRESS)) { + SMSetState(hApp, SS_SM_APPS_LAUNCHED_READY_TO_START); + } + // SysMgrConfiguration config; + // config.PrintAllInfo( m_MapProclaunchGrps ); + } + } + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-"); + return l_eStatus; +} // End of EFrameworkunifiedStatus CSystemManager::OnLaunchGroup(HANDLE hApp) + +/////////////////////////////////////////////////////////////////////////////// +/// \ingroup OnProcessLaunchTimerExpiry +/// +/// \param HANDLE hApp +/// +/// \return EFrameworkunifiedStatus +/////////////////////////////////////////////////////////////////////////////// +EFrameworkunifiedStatus CSystemManager::OnProcessLaunchTimerExpiry(HANDLE hApp) { // LCOV_EXCL_START 8: Because the condition cannot be set + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK; + // ToDo 2013_05_17 Jay When used ? Dead code ? Don't see a StartTimer call. + REC_HIST_IF_SUCCESSFUL("SM_TIMER_PROCESS_LAUNCH_MONITOR", m_TimerCmdHist, + m_TimerHistIter, FrameworkunifiedGetMsgSrc(hApp), l_eStatus); + m_GroupLaunchTimer->StopTimer(m_aTimerIDs[eSM_TIMER_PROCESS_LAUNCH_MONITOR]); + return eFrameworkunifiedStatusOK; +} +// LCOV_EXCL_STOP + +/////////////////////////////////////////////////////////////////////////////// +/// \ingroup OnHeartBeatMonitorTimerExpiry +/// +/// \param HANDLE hApp +/// +/// \return EFrameworkunifiedStatus +/////////////////////////////////////////////////////////////////////////////// +EFrameworkunifiedStatus CSystemManager::OnHeartBeatMonitorTimerExpiry(HANDLE hApp) { + FRAMEWORKUNIFIEDLOG(ZONE_PERIODIC_FUNC, __FUNCTION__, "+"); + FRAMEWORKUNIFIEDLOG(ZONE_PERIODIC_INFO, __FUNCTION__, " Received from %s", FrameworkunifiedGetMsgSrc(hApp)); + EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK; // LCOV_EXCL_BR_LINE 15: marco defined in ns_logger_if.h // NOLINT(whitespace/line_length) + REC_HIST_IF_SUCCESSFUL("SM_TIMER_HEARTBEAT_MONITOR", m_TimerCmdHist, // LCOV_EXCL_BR_LINE 15: marco defined in ss_system_manager.h // NOLINT(whitespace/line_length) + m_TimerHistIter, FrameworkunifiedGetMsgSrc(hApp), l_eStatus); // LCOV_EXCL_BR_LINE 15: marco defined in ss_system_manager.h // NOLINT(whitespace/line_length) + + // LCOV_EXCL_BR_START 4: nsfw error + if (eFrameworkunifiedStatusOK != (l_eStatus = FrameworkunifiedSendChild(hApp, m_hHeartbeatThread.m_ThreadHdl, + SS_HEARTBEAT_PERIODIC_STATUS_REQ, 0, NULL))) { + // LCOV_EXCL_BR_STOP 4: nsfw error + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + LOG_ERROR("FrameworkunifiedSendChild(m_hHeartbeatThread.m_ThreadHdl, " // LCOV_EXCL_LINE 4: nsfw error + "SS_HEARTBEAT_PERIODIC_STATUS_REQ)"); // LCOV_EXCL_BR_LINE 15: marco defined in ss_templates.h // NOLINT(whitespace/line_length) + } else { + m_hHeartbeatThread.m_ThreadState = eSMWaitForHeartbeat; + } + + FRAMEWORKUNIFIEDLOG(ZONE_PERIODIC_FUNC, __FUNCTION__, "-"); + return l_eStatus; +} + +/////////////////////////////////////////////////////////////////////////////// +/// \ingroup SystemManagerDebugDump +/// implement post mortem function +/// +/// \param +/// +/// \return void +/////////////////////////////////////////////////////////////////////////////// + +VOID CSystemManager::SystemManagerDebugDump(HANDLE hApp) { + std::stringstream l_debugDumpBuf; + cmdHistIter i; + + // LCOV_EXCL_BR_START 11:unexpected branch // NOLINT(whitespace/line_length) + l_debugDumpBuf << FrameworkunifiedGetAppName(hApp) << "/" << endl + << " <SYSTEM MANAGER DUMP DATA> " << endl << endl << " ***internals*** " << endl + << endl << " SM state: " + << GetStr(m_SMCurrentState).c_str() << endl << " SM startup reason: " + << GetStr(m_StartUpReason).c_str() << endl << " SM shutdown reason: " + << GetStr(m_shutdownTrigger).c_str() << endl << " LUM: " + << GetStr(m_lastUserMode).c_str() << endl << " TPM: " + << GetStr(m_SystemModeInfo.transportMode).c_str() << endl << " LPH: " + << GetStr(m_SystemModeInfo.limpHomeCutoff).c_str() << endl << " PMode: " + << GetStr(m_SystemModeInfo.productionMode).c_str() << endl << " ActiveGroup: " + << m_ActiveGroupId << endl << " m_MaxShutdownTime: " << m_MaxShutdownTime + << endl << " NPP: " << (m_bIsNPP_ServicesStarted ? "Started" : "notStarted") + << endl + << endl << " ***Error history***" << endl; + // LCOV_EXCL_BR_STOP + + for (i = m_ErrHist.begin(); i != m_ErrHist.end(); ++i) { + l_debugDumpBuf << endl << " " << i->m_cmd.c_str() << " @ " << i->m_time // LCOV_EXCL_BR_LINE 11:unexpected branch // NOLINT(whitespace/line_length) + << "ms EC:" << i->m_sender.c_str() << endl; // LCOV_EXCL_BR_LINE 11:unexpected branch // NOLINT(whitespace/line_length) + } + + l_debugDumpBuf << endl << " ***_CWORD56_ command history***" << endl; + + for (i = m__CWORD56_CmdHist.begin(); i != m__CWORD56_CmdHist.end(); ++i) { + l_debugDumpBuf << endl << " " << i->m_cmd.c_str() << " @ " << i->m_time << "ms" << endl; // LCOV_EXCL_BR_LINE 11:unexpected branch // NOLINT(whitespace/line_length) + } + + l_debugDumpBuf << endl << " ***Timer history***" << endl; + + for (i = m_TimerCmdHist.begin(); i != m_TimerCmdHist.end(); ++i) { + l_debugDumpBuf << endl << " " << i->m_cmd.c_str() << " @ " << i->m_time << "ms" << endl; // LCOV_EXCL_BR_LINE 11:unexpected branch // NOLINT(whitespace/line_length) + } + + l_debugDumpBuf << endl << " ***SM message history***" << endl; + + for (i = m_SMCmdHist.begin(); i != m_SMCmdHist.end(); ++i) { + l_debugDumpBuf << endl << " " << i->m_cmd.c_str() << " @ " << i->m_time << "ms " // LCOV_EXCL_BR_LINE 11:unexpected branch // NOLINT(whitespace/line_length) + << i->m_sender.c_str() << endl; // LCOV_EXCL_BR_LINE 11:unexpected branch // NOLINT(whitespace/line_length) + } + + l_debugDumpBuf << endl << " ***Publishshing history***" << endl; + + for (i = m_PubCmdHist.begin(); i != m_PubCmdHist.end(); ++i) { + l_debugDumpBuf << endl << " " << i->m_cmd.c_str() << " @ " << i->m_time << "ms " // LCOV_EXCL_BR_LINE 11:unexpected branch // NOLINT(whitespace/line_length) + << i->m_sender.c_str() << endl; // LCOV_EXCL_BR_LINE 11:unexpected branch // NOLINT(whitespace/line_length) + } + + l_debugDumpBuf << endl << " ***SM start table***" << endl; // LCOV_EXCL_BR_LINE 11:unexpected branch // NOLINT(whitespace/line_length) + + // LCOV_EXCL_BR_START 11:unexpected branch // NOLINT(whitespace/line_length) + l_debugDumpBuf << endl + << " index | name | start required? | isOKFlag | Module state | start sent " + "| start resposne received |start delta | stop sent | reply received | stop delta | PID" + << endl; + // LCOV_EXCL_BR_STOP + + for (UI_32 k = 1u; (k <= m_MapProclaunchGrps.size()); k++) { + GroupLaunchMapIter l_GroupIterator = m_MapProclaunchGrps.find(k); + + if (l_GroupIterator != m_MapProclaunchGrps.end()) { + ModuleLaunchListIter l_ModuleListIterator = l_GroupIterator->second.modules.begin(); + + for (int i = 1u; l_ModuleListIterator != l_GroupIterator->second.modules.end(); + l_ModuleListIterator++, i++) { + // LCOV_EXCL_BR_START 11:unexpected branch // NOLINT(whitespace/line_length) + std::string sIsOKFlag = GetModuleCondition(l_ModuleListIterator) ? " " : // 'blank' means OK + "X"; // 'X' means state mismatch + + l_debugDumpBuf << " " << std::setw(2) << std::right << i << " | " + << std::setw(24) << std::left << l_ModuleListIterator->name.c_str() + << " | " << std::setw(5) << std::left + << (l_ModuleListIterator->is_start_required ? "TRUE" : "FALSE") + + << " | " << sIsOKFlag.c_str() << " | " << std::setw(24) << std::left + << l_ModuleListIterator->ModuleStateStr().c_str() << " | " + << l_ModuleListIterator->m_startReason.GetInitial() << " | " + << l_ModuleListIterator->m_startReason.GetFinal() << " | " + << std::setw(3) << std::right + << static_cast<SI_16>(l_ModuleListIterator->m_startReason.GetDelta()) + << "ms" << " | " << l_ModuleListIterator->m_stopReason.GetInitial() + << " | " << l_ModuleListIterator->m_stopReason.GetFinal() << " | " + << std::setw(3) + << static_cast<SI_16>(l_ModuleListIterator->m_stopReason.GetDelta()) + << "ms" << " | " << l_ModuleListIterator->pid << endl; + // LCOV_EXCL_BR_STOP + } + } + } + + l_debugDumpBuf << endl << " ***Heartbeat information***" << endl; + + l_debugDumpBuf << endl << " Entire State:" << m_HBReport.eEntireState << endl; // LCOV_EXCL_BR_LINE 11:unexpected branch // NOLINT(whitespace/line_length) + + l_debugDumpBuf << endl << " Number of Modules:" << m_HBReport.nNumOfModules << endl; + + for (UI_32 j = 0; j < m_HBReport.nNumOfModules; j++) { // LCOV_EXCL_BR_LINE 11:unexpected branch // NOLINT(whitespace/line_length) + // LCOV_EXCL_START 6: Because the applicable variable cannot be changed from the external API (only evaluated by the initial value) + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + if (0 != m_HBReport.tModuleList[j].HeartBeatRetryCount) { + l_debugDumpBuf << endl << " " << m_HBReport.tModuleList[j].ProcQueueName << "," + << m_HBReport.tModuleList[j].ProcHBState << ", " + << m_HBReport.tModuleList[j].HeartBeatRetryCount << endl; + } + // LCOV_EXCL_STOP + } + + std::string l_debugDumpStr = l_debugDumpBuf.str(); + + SendDebugDumpResponseToSystemManager(l_debugDumpStr); // LCOV_EXCL_BR_LINE 11:unexpected branch // NOLINT(whitespace/line_length) +} + +/////////////////////////////////////////////////////////////////////////////// +/// \ingroup OnProcessLaunchMonitorTimerExpiry +/// This sends request to launcher thread to confirm that it +/// is still responsive. +/// +/// \param [in] hApp +/// HANDLE - Handle of the Client Application +/// +/// \return Status +/// EFrameworkunifiedStatus - success or error +/////////////////////////////////////////////////////////////////////////////// +EFrameworkunifiedStatus CSystemManager::OnProcessLaunchMonitorTimerExpiry(HANDLE hApp) { + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+"); + FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__, " Received from %s", FrameworkunifiedGetMsgSrc(hApp)); + EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK; + + REC_HIST_IF_SUCCESSFUL("TIMER_PROCESSLAUNCHER_MONITOR", m_TimerCmdHist, // LCOV_EXCL_BR_LINE 15: marco defined in ss_system_manager.h // NOLINT(whitespace/line_length) + m_TimerHistIter, FrameworkunifiedGetMsgSrc(hApp), l_eStatus); // LCOV_EXCL_BR_LINE 15: marco defined in ss_system_manager.h // NOLINT(whitespace/line_length) + + // LCOV_EXCL_BR_START 4: nsfw error + if (eFrameworkunifiedStatusOK != (l_eStatus = FrameworkunifiedSendChild(hApp, m_hProcLauncherThread.m_ThreadHdl, + ePLThrdCmd_THREAD_STATUS_REQST, 0, NULL))) { + // LCOV_EXCL_BR_STOP 4: nsfw error + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + LOG_ERROR("FrameworkunifiedSendChild(m_hProcLauncherThread.m_ThreadHdl," // LCOV_EXCL_LINE 4: nsfw error + "ePLThrdCmd_THREAD_STATUS_REQST)"); // LCOV_EXCL_BR_LINE 15: marco defined in ss_templates.h // NOLINT(whitespace/line_length) + } else { + m_hProcLauncherThread.m_ThreadState = eSMWaitForHeartbeat; + } + + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-"); + return l_eStatus; +} + +/////////////////////////////////////////////////////////////////////////////// +/// \ingroup SendRequestToLauncher +/// This function is used for sending request to launcher thread from +/// System Manager. +/// +/// \param HANDLE hApp +/// ModuleLaunchListIter f_ModuleListIterator => iterator node from map for the module +/// ESMPLThreadCommandIds f_CommandId => command id to send +/// SS_String f_ModulePath => Path of the Module +/// +/// \return Status +/// EFrameworkunifiedStatus - success or error +/////////////////////////////////////////////////////////////////////////////// +EFrameworkunifiedStatus CSystemManager::PerformLaunchProcedure(HANDLE hApp, + ModuleLaunchListIter f_ModuleIterator, SS_String & f_stopCompName) { + EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK; + + SS_String s_ModuleStatus2; + + // Register for Stop Complete notification + if (!f_ModuleIterator->shutdown_critical) { + s_ModuleStatus2 = "is not shutdown_critical"; + // LCOV_EXCL_BR_START 6: For setting the initialization conditions at SystemManager startup + + } else if (eFrameworkunifiedStatusOK != (l_eStatus = + FrameworkunifiedSubscribeNotificationWithCallback( + hApp, + f_stopCompName.c_str(), + SysMgrCallback<CSystemManager, &CSystemManager::OnModuleStopCompleteNotification>))) { + // LCOV_EXCL_BR_STOP + // LCOV_EXCL_START 6: For setting the initialization conditions at SystemManager startup + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, + " Error: FrameworkunifiedSubscribeNotificationWithCallback(hApp, %s) errored: %d/'%s'", + f_stopCompName.c_str(), l_eStatus, GetStr(l_eStatus).c_str()); + + s_ModuleStatus2 = "is shutdown_critical but errored"; + // LCOV_EXCL_STOP + } else { + s_ModuleStatus2 = f_stopCompName + " is now registered"; // LCOV_EXCL_BR_LINE 11:unexpected branch // NOLINT(whitespace/line_length) + } + + FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__, "%s", s_ModuleStatus2.c_str()); + + return l_eStatus; +} + +/////////////////////////////////////////////////////////////////////////////// +/// \ingroup PerformTerminateProcedure +/// Perform Procedure for Service Terminate. +/// +/// \param HANDLE hApp +/// ModuleLaunchListIter f_ModuleListIterator => iterator node from map for the module +/// SS_String & f_availabilityName => Availability Name +/// SS_String & f_stopCompName => Stop Complete Notification Name +/// +/// \return Status +/// EFrameworkunifiedStatus - success or error +/////////////////////////////////////////////////////////////////////////////// +EFrameworkunifiedStatus CSystemManager::PerformTerminateProcedure(HANDLE hApp, + ModuleLaunchListIter f_ModuleIterator, SS_String & f_availabilityName, + SS_String & f_stopCompName) { + EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK; + + // close session + f_ModuleIterator->SetModuleState(MODULE_STATE_INVALID); + f_ModuleIterator->pid = 0; + if (NULL != f_ModuleIterator->hsession) { // LCOV_EXCL_BR_LINE 200:hsession must not be NULL. + l_eStatus = FrameworkunifiedMcClose(f_ModuleIterator->hsession); // LCOV_EXCL_BR_LINE 4: nsfw error + if (eFrameworkunifiedStatusOK != l_eStatus) { // LCOV_EXCL_BR_LINE 4: nsfw error + // LCOV_EXCL_START 4: nsfw error + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, " Error: FrameworkunifiedMcClose(%s) errored: %d/'%s'", + f_ModuleIterator->name.c_str(), l_eStatus, GetStr(l_eStatus).c_str()); + // LCOV_EXCL_STOP + } + f_ModuleIterator->hsession = NULL; + } + + // Availability + if (f_ModuleIterator->is_start_required) { + // Initialize Availability + HANDLE pPublishMq = McOpenSender(FRAMEWORKUNIFIED_NS_NPSERVICE); // LCOV_EXCL_BR_LINE 4: nsfw error + if (NULL == pPublishMq) { // LCOV_EXCL_BR_LINE 4: nsfw error + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + SS_ASERT(0); // LCOV_EXCL_LINE 4: nsfw error + } else { + ServiceAvailability tServiceAvailability; + + snprintf(tServiceAvailability.cServiceName, MAX_NAME_SIZE_APP, "%s", + f_ModuleIterator->name.c_str()); + tServiceAvailability.eServiceAvailability = eFrameworkunifiedServiceNotAvailable; + + l_eStatus = NPPublishNotification(pPublishMq, f_ModuleIterator->name.c_str(), // LCOV_EXCL_BR_LINE 4: nsfw error + f_availabilityName.c_str(), &tServiceAvailability, // LCOV_EXCL_BR_LINE 4: nsfw error + sizeof(tServiceAvailability)); // LCOV_EXCL_BR_LINE 4: nsfw error + if (eFrameworkunifiedStatusOK != l_eStatus) { // LCOV_EXCL_BR_LINE 4: nsfw error + // LCOV_EXCL_START 4: nsfw error + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, " Error: NPPublishNotification(%s)", + f_availabilityName.c_str()); + // LCOV_EXCL_STOP + } + + l_eStatus = McClose(pPublishMq); // LCOV_EXCL_BR_LINE 4: nsfw error + if (eFrameworkunifiedStatusOK != l_eStatus) { + // LCOV_EXCL_START 4: nsfw error + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + SS_ASERT(0); // LCOV_EXCL_BR_LINE 15: marco defined in ss_templates.h // NOLINT(whitespace/line_length) + // LCOV_EXCL_STOP + } + } + } + + if (f_ModuleIterator->shutdown_critical) { + // Unregister Stop Complete notification + if (eFrameworkunifiedStatusOK != (l_eStatus = FrameworkunifiedUnsubscribeNotificationWithCallback(hApp, f_stopCompName.c_str()))) { // LCOV_EXCL_BR_LINE 4: nsfw error // NOLINT(whitespace/line_length) + // LCOV_EXCL_START 4: nsfw error + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, + " Error: FrameworkunifiedUnsubscribeNotificationWithCallback(hApp, %s) errored: %d/'%s'", + f_stopCompName.c_str(), l_eStatus, GetStr(l_eStatus).c_str()); + // LCOV_EXCL_STOP + } else { + SS_String s_ModuleStatus2 = f_stopCompName + " is now unregistered "; + FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__, "%s", s_ModuleStatus2.c_str()); + } + } + + return l_eStatus; +} + +/////////////////////////////////////////////////////////////////////////////// +/// \ingroup SendRequestToLauncher +/// This function is used for sending request to launcher thread from +/// System Manager. +/// +/// \param HANDLE hApp +/// ModuleLaunchListIter f_ModuleListIterator => iterator node from map for the module +/// ESMPLThreadCommandIds f_CommandId => command id to send +/// SS_String f_ModulePath => Path of the Module +/// +/// \return Status +/// EFrameworkunifiedStatus - success or error +/////////////////////////////////////////////////////////////////////////////// +EFrameworkunifiedStatus CSystemManager::SendRequestToLauncher(HANDLE hApp, + ModuleLaunchListIter f_ModuleIterator, ESMPLThreadCommandIds f_CommandId, + SS_String f_CommandIdStr) { + EFrameworkunifiedStatus l_eStatus; + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+"); + SS_String l_ModulePath = m_BinaryFilesPath + f_ModuleIterator->path; + + T_ProcessLauncherLaunchReq l_ModuleLaunchReq = { }; + strcpy(l_ModuleLaunchReq.name, f_ModuleIterator->name.c_str()); // NOLINT + strcpy(l_ModuleLaunchReq.path, l_ModulePath.c_str()); // NOLINT + strncpy(l_ModuleLaunchReq.args, f_ModuleIterator->arguments.c_str(), // NOLINT + sizeof(l_ModuleLaunchReq.args) - 1); + strcpy(l_ModuleLaunchReq.logging_mask, // NOLINT + f_ModuleIterator->logging_msk_str.c_str()); + l_ModuleLaunchReq.priority = f_ModuleIterator->configuration_priority; + l_ModuleLaunchReq.cpu_assign = f_ModuleIterator->cpu_assign; + l_ModuleLaunchReq.groupIterator = m_MapProclaunchGrps.find( + f_ModuleIterator->group_id); + l_ModuleLaunchReq.moduleIterator = f_ModuleIterator; + + FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__, + "Queue:%s, path:%s, args:%s, lmsk:%s, prio:%d, cmd:%s", l_ModuleLaunchReq.name, + l_ModuleLaunchReq.path, l_ModuleLaunchReq.args, l_ModuleLaunchReq.logging_mask, + l_ModuleLaunchReq.priority, f_CommandIdStr.c_str()); + + if (eFrameworkunifiedStatusOK != (l_eStatus = FrameworkunifiedSendChild(hApp, m_hProcLauncherThread.m_ThreadHdl, f_CommandId, sizeof(l_ModuleLaunchReq), reinterpret_cast<void *>(&l_ModuleLaunchReq)))) { // LCOV_EXCL_BR_LINE 4: Because an initialization condition is set at SystemManager startup and the branching condition cannot be satisfied // NOLINT(whitespace/line_length) + // LCOV_EXCL_START 4: Because an initialization condition is set at SystemManager startup and the branching condition cannot be satisfied + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, + " Error: FrameworkunifiedSendChild( %s, %s ) errored: %d/'%s'", l_ModulePath.c_str(), + f_CommandIdStr.c_str(), l_eStatus, GetStr(l_eStatus).c_str()); + // LCOV_EXCL_STOP + } else { + SS_String l_availabilityName = f_ModuleIterator->name + "/Availability"; // LCOV_EXCL_BR_LINE 11:unexpected branch // NOLINT(whitespace/line_length) + SS_String l_stopCompName = f_ModuleIterator->name + "/StopComp"; // LCOV_EXCL_BR_LINE 11:unexpected branch // NOLINT(whitespace/line_length) + // Perform command-specific processing + switch (f_CommandId) { // LCOV_EXCL_BR_LINE 6: Because the case is fixed on the call from the SystemManager::Initialize + // LCOV_EXCL_START 6: Because the case is fixed on the call from the SystemManager::Initialize + case ePLThrdCmd_RELAUNCH_MODULE_REQST: + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + l_eStatus = PerformTerminateProcedure(hApp, f_ModuleIterator, + l_availabilityName, l_stopCompName); + if (eFrameworkunifiedStatusOK != l_eStatus) { + SS_ASERT(0); + } + + l_eStatus = PerformLaunchProcedure(hApp, f_ModuleIterator, l_stopCompName); + if (eFrameworkunifiedStatusOK != l_eStatus) { + SS_ASERT(0); + } + break; + // LCOV_EXCL_STOP + + case ePLThrdCmd_LAUNCH_MODULE_REQST: + l_eStatus = PerformLaunchProcedure(hApp, f_ModuleIterator, l_stopCompName); + if (eFrameworkunifiedStatusOK != l_eStatus) { // LCOV_EXCL_BR_LINE 6: For setting the initialization conditions at SystemManager startup + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + SS_ASERT(0); // LCOV_EXCL_LINE 6: For setting the initialization conditions at SystemManager startup + } + break; + + case ePLThrdCmd_TERMINATE_MODULE_REQST: + l_eStatus = PerformTerminateProcedure(hApp, f_ModuleIterator, + l_availabilityName, l_stopCompName); // LCOV_EXCL_BR_LINE 11:unexpected branch // NOLINT(whitespace/line_length) + if (eFrameworkunifiedStatusOK != l_eStatus) { + SS_ASERT(0); // LCOV_EXCL_BR_LINE 15: marco defined in ss_templates.h // NOLINT(whitespace/line_length) + } + break; + + // LCOV_EXCL_START 6: Because the case is fixed on the call from the SystemManager::Initialize + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + case ePLThrdCmd_LAUNCH_MODULE_RESP: + case ePLThrdCmd_MODULE_STATUS_REQST: + case ePLThrdCmd_RELAUNCH_MODULE_RESP: + case ePLThrdCmd_TERMINATE_MODULE_RESP: + case ePLThrdCmd_THREAD_STATUS_REQST: + case ePLThrdCmd_THREAD_STATUS_RESP: + case ePLThrdCmd_NONE: + break; + // default: Don't code a 'default' here - let the compiler + // issue a warning ( set via -Wall or -Wswitch ) when the set of + // enumerations changes - then the maintainer will + // automagically know to update this switch statement. + // LCOV_EXCL_STOP + } + } + + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-"); + return l_eStatus; +} // End of EFrameworkunifiedStatus CSystemManager::SendRequestToLauncher( + +/////////////////////////////////////////////////////////////////////////////// +/// \ingroup RemoveModuleEntryFromHB +/// This function is called to send module information to heart beat thread +/// which is to be removed from its list of services to be monitored. +/// +/// \param HANDLE hApp, +/// const CHAR *f_ModuleName => Module Name +/// +/// \return Status +/// EFrameworkunifiedStatus - success or error +/////////////////////////////////////////////////////////////////////////////// +EFrameworkunifiedStatus CSystemManager::RemoveModuleEntryFromHB(HANDLE hApp, const CHAR *f_ModuleName) { + EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK; + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+"); + + HBListIter l_HBIter = std::find(m_HBList.begin(), m_HBList.end(), f_ModuleName); + if (l_HBIter != m_HBList.end()) { + m_HBList.erase(l_HBIter); + } + + TSMRequestMessage l_ModuleDetails; + strncpy(l_ModuleDetails.pstModuleName, f_ModuleName, + sizeof(l_ModuleDetails.pstModuleName) - 1); + l_ModuleDetails.pstModuleName[sizeof(l_ModuleDetails.pstModuleName) - 1] = '\0'; + l_eStatus = SendRequestToHeartBeat(hApp, SS_HEARTBEAT_DELETE_MODULE_ENTRY, + &l_ModuleDetails, sizeof(TSMRequestMessage)); + + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-"); + return l_eStatus; +} +/////////////////////////////////////////////////////////////////////////////// +/// \ingroup OnHeartBeatThreadHeartbeatResponse +/// This function gets called when heart beat thread replies the +/// heart beat query sent by the System Manager. +/// \param [in] hApp +/// HANDLE - Handle of the Client Application +/// +/// \return Status +/// EFrameworkunifiedStatus - success or error +/////////////////////////////////////////////////////////////////////////////// +EFrameworkunifiedStatus CSystemManager::OnHeartBeatThreadHeartbeatResponse(HANDLE hApp) { + FRAMEWORKUNIFIEDLOG(ZONE_PERIODIC_INFO, __FUNCTION__, "HeartBeat HeartBeat Received"); + m_hHeartbeatThread.m_ThreadState = eSMThreadIsFine; + return eFrameworkunifiedStatusOK; +} + +/////////////////////////////////////////////////////////////////////////////// +/// \ingroup OnCheckAvailResponse +/// This function gets service's availability status from HBThread +/// \param [in] hApp +/// HANDLE - Handle of the Client Application +/// +/// \return Status +/// EFrameworkunifiedStatus - success or error +/////////////////////////////////////////////////////////////////////////////// +EFrameworkunifiedStatus CSystemManager::OnCheckAvailResponse(HANDLE hApp) { + EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK; + THbAvailCheck result; + + if (eFrameworkunifiedStatusOK != (l_eStatus = ReadMsg < THbAvailCheck > (hApp, result))) { + LOG_ERROR("ReadMsg()"); // LCOV_EXCL_BR_LINE 15: marco defined in ss_tempaltes.h // NOLINT(whitespace/line_length) + } else if (result.isOk == FALSE) { + } + return eFrameworkunifiedStatusOK; +} + +/////////////////////////////////////////////////////////////////////////////// +/// \ingroup OnProcessLauncherThreadHeartbeatResponse +/// This function gets called when launcher thread replies the +/// heart beat query sent by the System Manager. +/// \param [in] hApp +/// HANDLE - Handle of the Client Application +/// +/// \return Status +/// EFrameworkunifiedStatus - success or error +/////////////////////////////////////////////////////////////////////////////// +EFrameworkunifiedStatus CSystemManager::OnProcessLauncherThreadHeartbeatResponse(HANDLE hApp) { + FRAMEWORKUNIFIEDLOG(ZONE_PERIODIC_INFO, __FUNCTION__, "ProcessLaunch HeartBeat Received"); + m_hProcLauncherThread.m_ThreadState = eSMThreadIsFine; + return eFrameworkunifiedStatusOK; +} + +/////////////////////////////////////////////////////////////////////////////// +/// \ingroup RegisterCallbacksForRequester +/// Register callbacks for External Protocol commands +/// +/// \param [in] +/// +/// +/// \return EFrameworkunifiedStatus +/// Success ==> eFrameworkunifiedStatusOK +/// Failure ==> Other values +/////////////////////////////////////////////////////////////////////////////// +EFrameworkunifiedStatus CSystemManager::RegisterCallbacksForRequester(HANDLE hApp, PCSTR f_pRequester) { + EFrameworkunifiedStatus l_eStatus; + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+"); + + // Attach Session Protocol messages. + FrameworkunifiedProtocolCallbackHandler l_sm_protocol_handlers[] = { + // Command ID, Call back functions + { SS_SM_START_COMPL_RSPN, + SysMgrCallback<CSystemManager, &CSystemManager::OnModuleStartCompleteResponse> }, + { SS_SM_STOP_COMPL_RSPN, + SysMgrCallback<CSystemManager, &CSystemManager::OnModuleStopCompleteResponse> }, + { SS_SM_PRE_START_COMPL_RSPN, + SysMgrCallback<CSystemManager, &CSystemManager::OnModuleStartCompleteResponse> }, + { SS_SM_PRE_STOP_COMPL_RSPN, + SysMgrCallback<CSystemManager, &CSystemManager::OnModuleStartCompleteResponse> }, + { SS_SM_BACKGROUND_START_COMPL_RSPN, + SysMgrCallback<CSystemManager, &CSystemManager::OnModuleStartCompleteResponse> }, + { SS_SM_BACKGROUND_STOP_COMPL_RSPN, + SysMgrCallback<CSystemManager, &CSystemManager::OnModuleStartCompleteResponse> }, + { SS_SM_GET_START_EXT_INFO, SysMgrCallback<CSystemManager, + &CSystemManager::OnGetStartExtInfo> }, + { SS_SM_GET_STOP_EXT_INFO, SysMgrCallback<CSystemManager, + &CSystemManager::OnGetStopExtInfo> }, + { SS_SM_CRNT_STATE_QUERY, SysMgrCallback<CSystemManager, + &CSystemManager::OnCurrentSMStateQuery> }, + { SS_SM_DATA_RESET_MODE_SET_REQ, SysMgrCallback<CSystemManager, + &CSystemManager::OnSetDataResetModeRequest> }, + { SS_SM_PROG_UPDATE_STATE_SET_REQ, SysMgrCallback<CSystemManager, + &CSystemManager::OnSetProgUpdateStateRequest> }, + + { SS_SM__CWORD56__HEARTBEAT_REQ, SysMgrCallback<CSystemManager, + &CSystemManager::On_CWORD56_HeartBeatRequest> }, + { SS_SM_NEXT_WAKEUP_TYPE_SET_REQ, SysMgrCallback<CSystemManager, + &CSystemManager::OnSetNextWakeupTypeRequest> }, + // Error Event Logging + { SS_SM_ERROR_EVENT_LOGGING_START_REQ, SysMgrCallback<CSystemManager, + &CSystemManager::OnLoggingStartRequest> }, + { SS_SM_ERROR_EVENT_ARTIFACT_REQ, SysMgrCallback<CSystemManager, + &CSystemManager::OnErrorEventArtifactRequest> }, + { SS_SM_ERROR_EVENT_LOGGING_COMPLETE, SysMgrCallback<CSystemManager, + &CSystemManager::OnErrorEventLoggingComplete> }, + { SS_SM_DEBUG_DUMP_RSPN, SysMgrCallback<CSystemManager, + &CSystemManager::OnDebugDumpResponseReceived> }, + { SS_SM_PROPAGATE_SYSTEM_ERROR, SysMgrCallback<CSystemManager, + &CSystemManager::OnPropagateSystemError> }, + { SS_SM_BOOT_MICRO_RESET_NTF, SysMgrCallback<CSystemManager, + &CSystemManager::OnBootMicroResetNotification> }, + { SS_SM_BOOT_MICRO_LOG_RSP, SysMgrCallback<CSystemManager, + &CSystemManager::OnBootMicroLogResponse> }, + { SS_SM_USER_INVOKED_LOG_REQ, SysMgrCallback<CSystemManager, + &CSystemManager::OnUserInvokedLoggingRequest> }, + { SS_SM_ERROR_EVENT_EEL_EXPORT_REQ, SysMgrCallback<CSystemManager, + &CSystemManager::OnEelExportRequest> }, + { SS_SM_ERROR_EVENT_INTERFACEUNIFIED_EMMC_LOGS_REQ, SysMgrCallback<CSystemManager, + &CSystemManager::OnSystemmanagerEmmcLogsRequest> }, + { SS_SM_ERROR_EVENT_CLR_LOGS_REQ, SysMgrCallback<CSystemManager, + &CSystemManager::OnSystemmanagerClearLogsRequest> }, + { SS_SM_ERROR_EVENT_DIAG_LOG_REQ, SysMgrCallback<CSystemManager, + &CSystemManager::OnDiagLoggingRequest> }, + { SS_SM_ERROR_EVENT_CAN_LOG_REQ, SysMgrCallback<CSystemManager, + &CSystemManager::OnCANLoggingRequest> } }; // LCOV_EXCL_BR_LINE 11:unexpected branch // NOLINT(whitespace/line_length) + + l_eStatus = FrameworkunifiedAttachCallbacksToDispatcher(hApp, f_pRequester, + l_sm_protocol_handlers, static_cast<UI_32>(_countof(l_sm_protocol_handlers))); // LCOV_EXCL_BR_LINE 11:unexpected branch // NOLINT(whitespace/line_length) + + if (eFrameworkunifiedStatusOK != l_eStatus) { + FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, + " Error: FrameworkunifiedAttachCallbacksToDispatcher(%s) errored: %d/'%s'", f_pRequester, + l_eStatus, GetStr(l_eStatus).c_str()); + } + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-"); + return l_eStatus; +} // End of EFrameworkunifiedStatus CSystemManager::RegisterCallbacksForRequester( HANDLE hApp, PCSTR f_pRequester) + +/////////////////////////////////////////////////////////////////////////////// +/// \ingroup open_session_with_sm_test_client +/// Process request to open session with sm test client +/// +/// \param [in] +/// +/// +/// \return EFrameworkunifiedStatus +/// Success ==> eFrameworkunifiedStatusOK +/// Failure ==> Other values +/////////////////////////////////////////////////////////////////////////////// +EFrameworkunifiedStatus CSystemManager::open_session_with_sm_test_client(HANDLE hApp, PCSTR pRequester) { + EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusFail; + UI_32 const l_ui32DefaultSessionID = 0; + OpenSessionAck tOpenAck = { }; + +/* + * Here pRequester is SMTesteClient with whom session is opened and its handle is stored in m_hPowerServiceSession handle. + * This case comes only while testing SystemManager through SMTestClient (PowerService should not be running). + */ + // Validate session handle + if (NULL == m_hPowerServiceSession) { + FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, + " Error: Session Handle NULL, calling FrameworkunifiedMcOpenSender for %s", pRequester); + + m_hPowerServiceSession = FrameworkunifiedMcOpenSender(hApp, pRequester); + // + // Set the Session Handle for Framework so FrameworkunifiedSendResponse won't error due to a null + // session handle. + // + // LCOV_EXCL_BR_START 4:NSFW's error + if (eFrameworkunifiedStatusOK != (l_eStatus = FrameworkunifiedSetSessionHandle(hApp, + pRequester, // [in] PCSTR - Name of the associated service name + m_hPowerServiceSession))) { // [in] HANDLE - Session handle + // LCOV_EXCL_BR_STOP + // LCOV_EXCL_START 4:NSFW's error + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, + " Error: FrameworkunifiedSetSessionHandle(%s) errored: %d/'%s'", pRequester, + l_eStatus, GetStr(l_eStatus).c_str()); + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-"); + return l_eStatus; + // LCOV_EXCL_STOP + } + } + + if (m_hPowerServiceSession == NULL) { // LCOV_EXCL_BR_LINE 200:m_hPowerServiceSession must not be NULL + // LCOV_EXCL_START 200:m_hPowerServiceSession must not be NULL + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, + " Error: Invalid Session Handle to service (%s) ", pRequester); + // LCOV_EXCL_STOP + } else { + FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__, "Session opened with %s", pRequester); + + // Copy session name to data structure + strncpy(tOpenAck.cSessionName, FrameworkunifiedGetAppName(hApp), + sizeof(tOpenAck.cSessionName) - 1); + tOpenAck.eStatus = eFrameworkunifiedStatusOK; + tOpenAck.sessionId = l_ui32DefaultSessionID; + + FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__, "About to send Open Session ACK"); + // send OpenSession ACK + // LCOV_EXCL_BR_START 4:NSFW's error + if (eFrameworkunifiedStatusOK != (l_eStatus = FrameworkunifiedSendMsg(m_hPowerServiceSession, + PROTOCOL_OPEN_SESSION_ACK, sizeof(OpenSessionAck), + (PVOID) & tOpenAck))) { + // LCOV_EXCL_BR_STOP + // LCOV_EXCL_START 4:NSFW's error + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + LOG_ERROR("FrameworkunifiedSendMsg(PROTOCOL_OPEN_SESSION_ACK)"); + + // Close the message queue handle + if (NULL != m_hPowerServiceSession) { + CALL_AND_LOG_STATUS_IF_ERRORED(FrameworkunifiedMcClose(m_hPowerServiceSession)); + m_hPowerServiceSession = NULL; + } + // LCOV_EXCL_STOP + } else { + CALL_AND_LOG_STATUS_IF_ERRORED(RegisterCallbacksForRequester(hApp, pRequester)); + } + } // end of else block of if(l_ModuleListIterator->hsession == NULL) + + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-"); + return l_eStatus; +} + +/////////////////////////////////////////////////////////////////////////////// +/// \ingroup OnOpenSession +/// Process request to open session +/// +/// \param [in] +/// +/// +/// \return EFrameworkunifiedStatus +/// Success ==> eFrameworkunifiedStatusOK +/// Failure ==> Other values +/////////////////////////////////////////////////////////////////////////////// +EFrameworkunifiedStatus CSystemManager::OnOpenSession(HANDLE hApp) { + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+"); + INTERFACEUNIFIEDLOG_RECEIVED_FROM(hApp); // LCOV_EXCL_BR_LINE 15: marco defined in ss_templates.h // NOLINT(whitespace/line_length) + EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK; + UI_32 const l_ui32DefaultSessionID = 0; + UI_32 const l_ui32DefaultSessionType = 0; + OpenSessionAck tOpenAck = { }; + PCSTR pRequester = FrameworkunifiedGetMsgSrc(hApp); + FRAMEWORKUNIFIEDLOG(ZONE_PERFORMANCE, __FUNCTION__, "%s", pRequester); + + ModuleLaunchListIter l_ModuleListIter; + + REC_HIST_IF_SUCCESSFUL("PROTOCOL_OPEN_SESSION_REQ", m_SMCmdHist, m_SMHistIter, // LCOV_EXCL_BR_LINE 15: marco defined in ss_system_manager.h // NOLINT(whitespace/line_length) + FrameworkunifiedGetMsgSrc(hApp), l_eStatus); // LCOV_EXCL_BR_LINE 15: marco defined in ss_system_manager.h // NOLINT(whitespace/line_length) + + l_eStatus = GetModuleIterator(pRequester, l_ModuleListIter); + + if (eFrameworkunifiedStatusOK != l_eStatus) { + // Special handling for open session request from SMTestClient. + if ((0 == strcmp(TC_SysManager, pRequester))) { + open_session_with_sm_test_client(hApp, pRequester); + } else { + FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, " Error: %s not found in Group Launch Map", + pRequester); + } + } else { + /**********************************************************************/ + if (0 != l_ModuleListIter->pid) { + UI_32 l_ClientPriority; + l_eStatus = l_ModuleListIter->GetPriority(l_ClientPriority); + + if (eFrameworkunifiedStatusOK != l_eStatus) { + LOG_ERROR("l_ModuleListIter->GetPriority( l_ClientPriority )"); // LCOV_EXCL_BR_LINE 15: marco defined in ss_templates.h // NOLINT(whitespace/line_length) + } else if (l_ClientPriority != l_ModuleListIter->configuration_priority) { + FRAMEWORKUNIFIEDLOG(ZONE_WARN, __FUNCTION__, " Changing %s's priority from %d to %d", + pRequester, l_ClientPriority, + l_ModuleListIter->configuration_priority); + CALL_AND_LOG_STATUS_IF_ERRORED( // LCOV_EXCL_BR_LINE 15: marco defined in ss_templates.h // NOLINT(whitespace/line_length) + l_ModuleListIter->SetPriority( // LCOV_EXCL_BR_LINE 15: marco defined in ss_templates.h // NOLINT(whitespace/line_length) + l_ModuleListIter->configuration_priority)); // LCOV_EXCL_BR_LINE 15: marco defined in ss_templates.h // NOLINT(whitespace/line_length) + } + } + /**********************************************************************/ + + // ToDo Jay 2013 Jan 09 REPLACE WITH CORRECT SERVICE / SESSION HANDLE + // LOGIC + // validate session handle + if (NULL == l_ModuleListIter->hsession) { + // LCOV_EXCL_BR_START 4: nsfw error + if (NULL == (l_ModuleListIter->hsession = FrameworkunifiedMcOpenSender(hApp, pRequester))) { + // LCOV_EXCL_BR_STOP 4: nsfw error + // LCOV_EXCL_START 4: nsfw error + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, + " Error: FrameworkunifiedMcOpenSender(App %s, %s) returned NULL", + FrameworkunifiedGetAppName(hApp), pRequester); + return eFrameworkunifiedStatusInvldHandle; + // LCOV_EXCL_STOP + } + } else { + /* + * Currently System Manager does not support multiple sessions from same client. + * When a client gets restarted after Crash or after missing HeartBeat, System Manager + * would receive OpenSession request from that client even when System Manager already + * has a open session with that client. + */ + FRAMEWORKUNIFIEDLOG(ZONE_WARN, __FUNCTION__, + " Warning: Repeated Session Opening Request from %s", pRequester); + } + if (eFrameworkunifiedStatusOK != (l_eStatus = RegisterCallbacksForRequester(hApp, pRequester))) { + // Close the message queue handle + if (NULL != l_ModuleListIter->hsession) { // LCOV_EXCL_BR_LINE 6: Due to NULL checking + if (eFrameworkunifiedStatusOK != (l_eStatus = FrameworkunifiedMcClose(l_ModuleListIter->hsession))) { + LOG_ERROR("FrameworkunifiedMcClose()"); // LCOV_EXCL_BR_LINE 11:unexpected branch // NOLINT(whitespace/line_length) + } + l_ModuleListIter->hsession = NULL; + } + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-"); + return l_eStatus; + } + + // Copy session name to data structure + strncpy(tOpenAck.cSessionName, FrameworkunifiedGetAppName(hApp), sizeof(tOpenAck.cSessionName) - 1); + tOpenAck.eStatus = eFrameworkunifiedStatusOK; + tOpenAck.sessionId = l_ui32DefaultSessionID; + tOpenAck.sessionType = l_ui32DefaultSessionType; + + // send OpenSession ACK + // LCOV_EXCL_BR_START 4: nsfw error + if (eFrameworkunifiedStatusOK + != (l_eStatus = FrameworkunifiedSendMsg(l_ModuleListIter->hsession, + SS_SM_PROTOCOL_OPEN_SESSION_ACK, sizeof(OpenSessionAck), + (PVOID) & tOpenAck))) { // LCOV_EXCL_BR_STOP + // LCOV_EXCL_START 4: nsfw error + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, + " Error: FrameworkunifiedSendMsg( %s, SS_SM_PROTOCOL_OPEN_SESSION_ACK)" + " errored: %d/'%s'", l_ModuleListIter->name.c_str(), l_eStatus, + GetStr(l_eStatus).c_str()); + + if (NULL != l_ModuleListIter->hsession) { + // Close the message queue handle + if (eFrameworkunifiedStatusOK != (l_eStatus = FrameworkunifiedMcClose(l_ModuleListIter->hsession))) { + FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, + " Error: FrameworkunifiedMcClose(%s) errored: %d/'%s'", + l_ModuleListIter->name.c_str(), l_eStatus, + GetStr(l_eStatus).c_str()); + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-"); + } + l_ModuleListIter->hsession = NULL; + } + // LCOV_EXCL_STOP + } else { + // Store PowerService session handle in class so it can be accessed faster + // to use opened session while replying to PowerService. + if ((0 == strcmp(SERVICE_POWER, pRequester))) { + m_hPowerServiceSession = l_ModuleListIter->hsession; + } + + l_ModuleListIter->SetModuleState(MODULE_STATE_CONNECTED); + + FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__, " SM State: %s, %s.is_start_required: %s", + GetStr(m_SMCurrentState).c_str(), l_ModuleListIter->name.c_str(), + GetStr(l_ModuleListIter->is_start_required).c_str()); + + if (l_ModuleListIter->is_start_required + && ((SS_SM_APPS_START_IN_PROGRESS == m_SMCurrentState) + || (SS_SM_APPS_START_COMPLETE == m_SMCurrentState))) { + T_SS_SM_START_DataStructType f_startupData(m_StartUpReason, + m_PowerType_to_SSBoolEnumMap[m_Wake.powerupType], m_DataResetMode, + m_startUpConfirmationMsg.securityStatus, + m_startUpConfirmationMsg.wakeupType, m_DramBackupStatus, + m_ResetStatus, m_ResetCount); + const UI_32 l_iCmd = InProgressStateToSendMsg(); + if (l_iCmd != SS_SYSTEM_MANAGER_PROTOCOL_ENDING_INDEX) { + CALL_AND_LOG_STATUS_IF_ERRORED(l_ModuleListIter->SendMsgAndUpdateState(l_iCmd, &f_startupData)); // LCOV_EXCL_BR_LINE 11: Gcov constraints (because exception-handling routes are automatically generated) // NOLINT(whitespace/line_length) + } + } + } + } + + if (eFrameworkunifiedStatusOK == l_eStatus) { + std::string l_Subscriber; + l_Subscriber = FrameworkunifiedGetMsgSrc(hApp); + + // check if the heart beat subscriber is already in list + HBListIter l_HBIter = std::find(m_HBList.begin(), m_HBList.end(), l_Subscriber); + if (l_HBIter == m_HBList.end()) { + m_HBList.push_back(l_Subscriber); + } + if (m_SMCurrentState == SS_SM_APPS_START_COMPLETE) { + TSMRequestMessage l_ModuleDetails; + snprintf(l_ModuleDetails.pstModuleName, sizeof(l_ModuleDetails.pstModuleName), + "%s", l_Subscriber.c_str()); + l_eStatus = SendRequestToHeartBeat(hApp, SS_HEARTBEAT_APPEND_MODULE_ENTRY, + &l_ModuleDetails, sizeof(TSMRequestMessage)); + LOG_ERROR_REC_HIST_IF_ERRORED(l_eStatus, "SendRequestToHeartBeat()"); // LCOV_EXCL_BR_LINE 15: marco defined in ss_templates.h // NOLINT(whitespace/line_length) + } + } + + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-"); + return l_eStatus; +} + +/////////////////////////////////////////////////////////////////////// +/// ConstructGetResultResponse +/// +/// +////////////////////////////////////////////////////////////////////// +EFrameworkunifiedStatus CSystemManager::add_state_information_to_response(CHAR *f_MessageResponse) const { + const CHAR ReadyToLaunchAppDescription[] = "_READY_TO_LAUNCH:"; + const CHAR StartInProgressDescription[] = "_START_IN_PROGRESS:"; + const CHAR LaunchInProgressDescription[] = "_LAUNCH_IN_PROGRESS:"; + const CHAR LaunchedReadyToStartDescription[] = "_READY_TO_START:"; + const CHAR StopInProgressDescription[] = "_STOP_IN_PROGRESS:"; + const CHAR StartCompleteDescription[] = "_START_COMPLETED:"; + const CHAR WaitingForCriticalAppsToStopDescription[] = "_WAITING_FOR_CRITICAL_APPS_TO_STOP:"; + const CHAR PreStartInProgressDescription[] = "_PRE_START_IN_PROGRESS:"; + const CHAR PreStopInProgressDescription[] = "_PRE_STOP_IN_PROGRESS:"; + const CHAR PreRunCompleteDescription[] = "_PRE_RUN_COMPLETE:"; + const CHAR BackgroundStartInProgressDescription[] = "_BACKGROUND_START_IN_PROGRESS:"; + const CHAR BackgroundStopInProgressDescription[] = "_BACKGROUND_STOP_IN_PROGRESS:"; + const CHAR BackgroundRunCompleteDescription[] = "_BACKGROUND_RUN_COMPLETE:"; + EFrameworkunifiedStatus eStatus = eFrameworkunifiedStatusOK; + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+"); + CHAR l_Buffer[5]; + UI_32 l_Index = 0; + + std::map<SS_SMModuleState, std::string> StateMap; // State Map + StateMap[SS_SM_READY_TO_LAUNCH_APP] = ReadyToLaunchAppDescription; + StateMap[SS_SM_APPS_LAUNCH_IN_PROGRESS] = LaunchInProgressDescription; + StateMap[SS_SM_APPS_LAUNCHED_READY_TO_START] = LaunchedReadyToStartDescription; + StateMap[SS_SM_APPS_START_IN_PROGRESS] = StartInProgressDescription; + StateMap[SS_SM_APPS_START_COMPLETE] = StartCompleteDescription; + StateMap[SS_SM_APPS_STOPPING_AT__CWORD56__REQ] = StopInProgressDescription; + StateMap[SS_SM_APPS_STOPPING_AT_INTERNAL_REQ] = StopInProgressDescription; + StateMap[SS_SM_WAITING_FOR_CRITICAL_APPS_AT_INTERNAL_REQ] = + WaitingForCriticalAppsToStopDescription; + StateMap[SS_SM_WAITING_FOR_CRITICAL_APPS_AT__CWORD56__REQ] = + WaitingForCriticalAppsToStopDescription; + StateMap[SS_SM_APPS_PRE_START_IN_PROGRESS] = PreStartInProgressDescription; + StateMap[SS_SM_APPS_PRE_STOP_IN_PROGRESS] = PreStopInProgressDescription; + StateMap[SS_SM_APPS_PRE_RUN_COMPLETE] = PreRunCompleteDescription; + StateMap[SS_SM_APPS_BACKGROUND_START_IN_PROGRESS] = BackgroundStartInProgressDescription; + StateMap[SS_SM_APPS_BACKGROUND_STOP_IN_PROGRESS] = BackgroundStopInProgressDescription; + StateMap[SS_SM_APPS_BACKGROUND_RUN_COMPLETE] = BackgroundRunCompleteDescription; + + itoa(m_SMCurrentState, l_Buffer, 16); + while (l_Buffer[l_Index]) { + l_Buffer[l_Index] = toupper(l_Buffer[l_Index]); + l_Index++; + } + + if (SS_SM_MAX_RESP_MSG_SIZE > (strlen(f_MessageResponse) + sizeof(l_Buffer) + + StateMap[m_SMCurrentState].length() + 1)) { + strncat(f_MessageResponse, l_Buffer, sizeof(l_Buffer)); + strncat(f_MessageResponse, StateMap[m_SMCurrentState].c_str(), + StateMap[m_SMCurrentState].length()); + } else { + eStatus = eFrameworkunifiedStatusFail; + } + + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-"); + return eStatus; +} + +/////////////////////////////////////////////////////////////////////// +/// ConstructGetResultResponse +/// +/// +////////////////////////////////////////////////////////////////////// +EFrameworkunifiedStatus CSystemManager::construct_get_result_response(CHAR *f_MessageResponse) { + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+"); + const EFrameworkunifiedStatus eStatus = add_state_information_to_response(f_MessageResponse); + if (eFrameworkunifiedStatusOK == eStatus) { + FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__, "Response Constructed"); + } + + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-"); + return eStatus; +} + +/////////////////////////////////////////////////////////////////////// +/// REC_HIST_IF_SUCCESSFUL / SetCmdHist +/// +/// +////////////////////////////////////////////////////////////////////// +void CSystemManager::SetCmdHist(std::string cmd, cmdHist &hist, cmdHistIter &it, std::string sender) { + UI_64 l_time = 0XDEAD; + CTimeSpan* timerClass = new (std::nothrow) CTimeSpan(); // LCOV_EXCL_BR_LINE 5: Because new cannot fail + if (NULL == timerClass) { // LCOV_EXCL_BR_LINE 5: Because new cannot fail + // LCOV_EXCL_START 5: Because new cannot fail + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, + " 'new (std::nothrow) CTimeSpan()' returned NULL, " + "'it->m_time' being set to 0xDEAD"); + // LCOV_EXCL_STOP + } else { + l_time = timerClass->GetTimeMilliseconds(); + } + + pthread_mutex_lock(&sm_hist_mutex); + + it->m_time = l_time; + it->m_cmd = cmd; + it->m_sender = sender; + it++; + + if (it != hist.end()) { // LCOV_EXCL_BR_LINE 5: std: because it is a member of a vector and it is difficult to create a failing condition + it = hist.begin(); + } + + pthread_mutex_unlock(&sm_hist_mutex); + + delete timerClass; // LCOV_EXCL_BR_LINE 5: Because the delete cannot fail +} + +/////////////////////////////////////////////////////////////////////// +/// OnCurrentPowerStateQuery +/// +/// +////////////////////////////////////////////////////////////////////// +EFrameworkunifiedStatus CSystemManager::OnCurrentSMStateQuery(HANDLE hApp) { + EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK; + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+"); + INTERFACEUNIFIEDLOG_RECEIVED_FROM(hApp); + FRAMEWORKUNIFIEDLOG(ZONE_STATE, __FUNCTION__, "Received from %s", FrameworkunifiedGetMsgSrc(hApp)); + + SS_SMCurrentState l_CurrentState; + + REC_HIST_IF_SUCCESSFUL("SS_SM_CRNT_STATE_QUERY", m_SMCmdHist, m_SMHistIter, + FrameworkunifiedGetMsgSrc(hApp), l_eStatus); + if (eFrameworkunifiedStatusOK != (l_eStatus = ReadMsg < SS_SMCurrentState > (hApp, l_CurrentState))) { + LOG_ERROR("ReadMsg()"); // LCOV_EXCL_BR_LINE 11:unexpected branch // NOLINT(whitespace/line_length) + } else { + construct_get_result_response(l_CurrentState.respMsgString); + + ModuleLaunchListIter l_ModuleListIter; + PCSTR l_moduleName = FrameworkunifiedGetMsgSrc(hApp); + if (eFrameworkunifiedStatusOK != (l_eStatus = GetModuleIterator(l_moduleName, l_ModuleListIter))) { // LCOV_EXCL_BR_LINE 200: can not be other value // NOLINT (whitespace/line_length) + // LCOV_EXCL_START 200: can not be other value + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, + " Error: Module %s not found in Group Launch Map", l_moduleName); + // LCOV_EXCL_STOP + } else if (l_ModuleListIter->hsession != NULL) { // LCOV_EXCL_BR_LINE 200: can not be NULL // NOLINT (whitespace/line_length) + if (eFrameworkunifiedStatusOK != (l_eStatus = FrameworkunifiedSendMsg(l_ModuleListIter->hsession, // LCOV_EXCL_BR_LINE 4: nsfw error + SS_SM_CRNT_STATE_QUERY_RSPN, sizeof(SS_SMCurrentState), + (PVOID) & l_CurrentState))) { + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + LOG_ERROR("FrameworkunifiedSendMsg(SS_SM_CRNT_STATE_QUERY_RSPN)"); // LCOV_EXCL_LINE 4: nsfw error + } + } else { + // LCOV_EXCL_START 200: can not be NUL + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, " NULL == hsession; %s not connected yet", + l_ModuleListIter->name.c_str()); + // LCOV_EXCL_STOP + } + } + + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-"); + return l_eStatus; +} + +EFrameworkunifiedStatus CSystemManager::GetVersionNumber(SS_VersionNumberType & f_VersionNumber) { + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+"); + EFrameworkunifiedStatus l_eStatus; + + CSMVersion cVersion; + if (eFrameworkunifiedStatusOK != (l_eStatus = cVersion.get_version(f_VersionNumber))) { // LCOV_EXCL_BR_LINE 6: For setting the initialization conditions at SystemManager startup // NOLINT(whitespace/line_length) + LOG_ERROR("cVersion.get_version()"); // LCOV_EXCL_BR_LINE 6: For setting the initialization conditions at SystemManager startup // NOLINT(whitespace/line_length) + } + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-"); + return l_eStatus; +} // End of EFrameworkunifiedStatus CSystemManager::GetVersionNumber( SS_VersionNumberType + +EFrameworkunifiedStatus CSystemManager::GetBuildInfo(std::string &f_BuildInfoStr) { + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+"); + EFrameworkunifiedStatus l_eStatus; + + CSMVersion cVersion; + if (eFrameworkunifiedStatusOK != (l_eStatus = cVersion.get_build_info(f_BuildInfoStr))) { // LCOV_EXCL_BR_LINE 6: For setting the initialization conditions at SystemManager startup // NOLINT(whitespace/line_length) + LOG_ERROR("cVersion.get_build_info()"); // LCOV_EXCL_BR_LINE 6:For setting the initialization conditions at SystemManager startup // NOLINT(whitespace/line_length) + } + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-"); + return l_eStatus; +} // End of EFrameworkunifiedStatus CSystemManager::GetBuildInfo(std::string) + +bool CSystemManager::GetDramPowerStatusInfo(const HANDLE h_app) { + PsmDramStsT l_dram_sts = PSM_DRAM_STS_NORMAL; + bool ret = false; + + // Checking dram power status. + if (PsmGetDramPowerSupplyAbnormalityCheckResultPower(h_app, &l_dram_sts)) + return ret; + + if (l_dram_sts == PSM_DRAM_STS_NORMAL) + ret = true; + + return ret; +} + +bool CSystemManager::GetDramStoreStatusInfo(const HANDLE h_app) { + PsmSysupDramT l_dram1 = PSM_SYSUP_DRAM_NORMAL; + PsmSysupDramT l_dram2 = PSM_SYSUP_DRAM_NORMAL; + PsmSysupDramT l_dram3 = PSM_SYSUP_DRAM_NORMAL; + PsmStartStatusT l_sts = PSM_START_STATUS_FACTRESET; + + bool ret = false; + + // Checking factory shipment status + if (PsmGetStartStatusPower(h_app, &l_sts)) + return ret; + + if (l_sts == PSM_START_STATUS_FACTRESET) { + ret = true; + goto finish; + } + + // Checking dram power + if (!GetDramPowerStatusInfo(h_app)) + goto finish; + + // Checking dram status. + if (PsmGetDramBackupStatusPower(h_app, &l_dram1, &l_dram2, &l_dram3)) + goto finish; + + // l_dram2 and l_dram3 would be ignored. + if (l_dram1 == PSM_SYSUP_DRAM_NORMAL) + ret = true; + + if (l_dram2 == PSM_SYSUP_DRAM_SFTERRSR) + ret = true; + +finish: + return ret; +} + +bool CSystemManager::GetSyscomPowerStatusInfo(const HANDLE h_app) { + PsmComStsT l_syscom_sts = PSM_COM_STS_NORMAL; + bool ret = false; + + if (PsmGetSyscomStatusPower(h_app, &l_syscom_sts)) + return ret; + + if (l_syscom_sts == PSM_COM_STS_NORMAL) + ret = true; + + return ret; +} + +EFrameworkunifiedStatus CSystemManager::OnSetStartupConfirmationDataRequest(HANDLE hApp) { + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+"); + INTERFACEUNIFIEDLOG_RECEIVED_FROM(hApp); // LCOV_EXCL_BR_LINE 15: marco defined in ss_templates.h // NOLINT(whitespace/line_length) + FRAMEWORKUNIFIEDLOG(ZONE_PERFORMANCE, __FUNCTION__, "from %s", FrameworkunifiedGetMsgSrc(hApp)); + EFrameworkunifiedStatus l_eStatus; + Pwr_ServiceSetInterface tServiceSetIf; + // ReadMsg(): * + // Check hApp ptr, msg size, msg reception, read msg if all ok. * + // Report any errors found. * + // * + if (eFrameworkunifiedStatusOK + != (l_eStatus = ReadMsg < Pwr_ServiceSetInterface > (hApp, tServiceSetIf))) { // LCOV_EXCL_BR_LINE 4:NSFW's error + // LCOV_EXCL_START 4:NSFW's error + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + LOG_ERROR("ReadMsg()"); // LCOV_EXCL_BR_LINE 15: marco defined in ss_templates.h // NOLINT(whitespace/line_length) + // LCOV_EXCL_STOP + } else { + m_startUpConfirmationMsg = tServiceSetIf.data.startupConfirmationMsg; + FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__, " %s Startup Confirmation data:", FrameworkunifiedGetMsgSrc(hApp)); + SYSTEMMANAGERLOG_StartupConfirmationMsg(m_startUpConfirmationMsg); // LCOV_EXCL_BR_LINE 15: marco defined in ns_logger_if.h // NOLINT(whitespace/line_length) + DGCODE_RET_API l_ret = DGCODE_RET_ERROR; + + l_ret = Diag_StartupAllStatusOfDTC(); + if (l_ret == DGCODE_RET_ERROR) { + LOG_ERROR("Diag_StartupAllStatusOfDTC()"); // LCOV_EXCL_BR_LINE 15: marco defined in ss_templates.h // NOLINT(whitespace/line_length) + } + + if ((e_SS_SM_NEXT_WAKEUP_TYPE_COLD == m_NextWakeupType) && (epsstCOLDSTART != m_startUpConfirmationMsg.wakeupType)) { // LCOV_EXCL_BR_LINE 6: Because the above formula cannot be set to true // NOLINT(whitespace/line_length) + // LCOV_EXCL_START 6: Because the condition cannot be set + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + FRAMEWORKUNIFIEDLOG(ZONE_STATE, __FUNCTION__, "WakeupType Change to Cold by Svc Request"); + m_startUpConfirmationMsg.wakeupType = epsstCOLDSTART; + // LCOV_EXCL_STOP + } + + m_ResetStatus = ((m_isIlgReset == TRUE) ? + e_SS_SM_RESET_STATUS_NG : + ((m_isImmediateReset == TRUE) ? + e_SS_SM_RESET_STATUS_IMMEDIATE : e_SS_SM_RESET_STATUS_NONE)); + if (e_SS_SM_RESET_STATUS_NG == m_ResetStatus) { + FRAMEWORKUNIFIEDLOG(ZONE_ERR, __PRETTY_FUNCTION__, + "ResetStatus NG illRst:%s lastErr:Not Support", + m_isIlgReset ? "TRUE" : "FALSE"); + m_ResetCount++; + if (PowerHalSetResetInfo(AGL_RESET_COUNTER, m_ResetCount)) { + FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, + "Could not back up m_ResetCount(%lu) to power_hal", m_ResetCount); + } + } + + m_DramBackupStatus = + ((epsstWARMSTART != m_startUpConfirmationMsg.wakeupType) + || (e_SS_SM_DATA_RESET_MODE_FACTORY == m_DataResetMode) + || (GetDramStoreStatusInfo(hApp) == false)) ? + e_SS_SM_DRAM_BACKUP_NG : e_SS_SM_DRAM_BACKUP_OK; + + if (e_SS_SM_DRAM_BACKUP_NG == m_DramBackupStatus) { + FRAMEWORKUNIFIEDLOG(ZONE_ERR, __PRETTY_FUNCTION__, + "DramBackup NG wakeupType:%s dataResetMode:%s", + (epsstWARMSTART == m_startUpConfirmationMsg.wakeupType) ? + "WARM" : "COLD", + (e_SS_SM_DATA_RESET_MODE_FACTORY == m_DataResetMode) ? + "FACTORY" : "NotFactory"); + } + + if (m_needReNotifyStartPrm) { // LCOV_EXCL_BR_LINE 6: Because the condition cannot be satisfied from the external API + // LCOV_EXCL_BR_START 6: Because both sides are not FALSE + if (e_SS_SM_DRAM_BACKUP_NG == m_DramBackupStatus) { + // LCOV_EXCL_BR_STOP + m_DramBackupStatus = e_SS_SM_DRAM_BACKUP_NG; + } + } + + if (m_needReNotifyStartPrm) { // LCOV_EXCL_BR_LINE 6: Because the condition cannot be satisfied from the external API + if (e_SS_SM_RESET_STATUS_NG == m_ResetStatus) { + // do nothing, keep m_ResetStatus. + } else if (e_SS_SM_RESET_STATUS_IMMEDIATE == m_ResetStatus) { + // do nothing, keep m_ResetStatus. + } else { + m_ResetStatus = e_SS_SM_RESET_STATUS_NONE; + } + + if (epsstWARMSTART != m_startUpConfirmationMsg.wakeupType) { // LCOV_EXCL_BR_LINE 6: Because the above condition cannot be satisfied // NOLINT(whitespace/line_length) + m_startUpConfirmationMsg.wakeupType = epsstCOLDSTART; + } + } + + CALL_AND_LOG_STATUS(ClearDramBackupInfo(hApp)); // LCOV_EXCL_BR_LINE 15: marco defined in ss_templates.h // NOLINT(whitespace/line_length) + + FRAMEWORKUNIFIEDLOG(ZONE_STATE, __FUNCTION__, "\n" + "start prm\n" + "dramBackupStatus = %s\n" + "wakeupType = %s\n" + "dataResetMode = %s\n" + "resetStatus = %s\n" + "resetCount = %d\n" + "progUpdateState = %d", + (m_DramBackupStatus == e_SS_SM_DRAM_BACKUP_OK) ? "OK" : "NG", + (m_startUpConfirmationMsg.wakeupType == epsstWARMSTART) ? "WARM" : "COLD", + (m_DataResetMode == e_SS_SM_DATA_RESET_MODE_FACTORY) ? "FACT" : + (m_DataResetMode == e_SS_SM_DATA_RESET_MODE_USER) ? "USER" : + (m_DataResetMode == e_SS_SM_DATA_RESET_MODE_PROGUPDATE) ? "PROG" : "NONE", + (m_ResetStatus == e_SS_SM_RESET_STATUS_IMMEDIATE) ? "IMM" : + (m_ResetStatus == e_SS_SM_RESET_STATUS_NONE) ? "NONE" : "NG", m_ResetCount, + m_ProgUpdateState); + + if (eFrameworkunifiedStatusOK != (l_eStatus = FrameworkunifiedNPPublishNotification(hApp, NTFY_SSSystemMgrStartUpType, &m_startUpConfirmationMsg.wakeupType, sizeof(EPWR_SC_WAKEUP_TYPE)))) { // LCOV_EXCL_BR_LINE 4:NSFW error case //NOLINT (whitespace/line_length) + // LCOV_EXCL_START 4: nsfw error + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, + " Error: FrameworkunifiedNPPublishNotification(%s, %s) errored: %d/'%s'", + NTFY_SSSystemMgrStartUpType, + GetStr(m_startUpConfirmationMsg.wakeupType).c_str(), l_eStatus, + GetStr(l_eStatus).c_str()); + // LCOV_EXCL_STOP + } else { + FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__, " FrameworkunifiedNPPublishNotification(%s, %s) successful", + NTFY_SSSystemMgrStartUpType, + GetStr(m_startUpConfirmationMsg.wakeupType).c_str()); + + // LCOV_EXCL_BR_START 200: As there are no cases other than eFrameworkunifiedStatusOK + REC_HIST_IF_SUCCESSFUL("SM/StartUpType", + m_PubCmdHist, m_PubHistIter, "", l_eStatus); + // LCOV_EXCL_BR_STOP + } + } + + EFrameworkunifiedStatus l_responseStatus = l_eStatus; + + ModuleLaunchListIter l_ModuleListIter; + PCSTR l_moduleName = FrameworkunifiedGetMsgSrc(hApp); + if (eFrameworkunifiedStatusOK != (l_eStatus = GetModuleIterator(l_moduleName, l_ModuleListIter))) { + FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, + " Error: Module %s not found in Group Launch Map", l_moduleName); + } else if (l_ModuleListIter->hsession != NULL) { + if (eFrameworkunifiedStatusOK != (l_eStatus = FrameworkunifiedSendMsg(l_ModuleListIter->hsession, // LCOV_EXCL_BR_LINE 4:NSFW's error + SS_SM_FWD_START_CONFIRMATION_MSG_RESP, sizeof(EFrameworkunifiedStatus), + (PVOID) & l_responseStatus))) { + // LCOV_EXCL_START 4:NSFW's error + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + LOG_ERROR("FrameworkunifiedSendMsg(SS_SM_FWD_START_CONFIRMATION_MSG_RESP)"); // LCOV_EXCL_BR_LINE 15: marco defined in ss_templates.h // NOLINT(whitespace/line_length) + // LCOV_EXCL_STOP + } + } else { + FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, " NULL == hsession; %s not connected yet", l_ModuleListIter->name.c_str()); + } + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-"); + return l_eStatus; +} // End of EFrameworkunifiedStatus CSystemManager::OnSetStartupConfirmationDataRequest( HANDLE hApp ) + +EFrameworkunifiedStatus CSystemManager::GetTimeStamp(std::string& TimeStamp) { + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+"); + EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK; + + CHAR format[256] = { '\0' }; + CHAR l_format[256] = { '\0' }; + struct timeb timebuf; + uint32_t time; + uint8_t status; + struct tm theTime; + ftime(&timebuf); + Clock_getSystemTimeY2K38(&time, &status); + CLOCK_RETURN clock_ret = Clock_CnvSecToDateY2K38(&time, &theTime); + + if (CLOCK_OK != clock_ret) { + return eFrameworkunifiedStatusNullPointer; + } + + sprintf(l_format, "GMT Time,%04d-%02d-%02d %02d:%02d:%02d.%hu\n", // NOLINT + theTime.tm_year + 1900, theTime.tm_mon + 1, theTime.tm_mday, + theTime.tm_hour, theTime.tm_min, theTime.tm_sec, timebuf.millitm); + + struct timespec timeSpec; + + if (0 != clock_gettime(CLOCK_MONOTONIC, &timeSpec)) { + SS_ASERT_ERRNO(0); // LCOV_EXCL_BR_LINE 15: marco defined in ss_templates.h // NOLINT(whitespace/line_length) + } else { + time_t timeInSecs = timeSpec.tv_sec; + sprintf(format, "Elaps Time,%ld:%02ld:%02ld\n", (timeInSecs / 3600), // NOLINT + ((timeInSecs % 3600) / 60), (timeInSecs % 60)); + } + + TimeStamp.clear(); + TimeStamp.assign(format); + TimeStamp.append(l_format); + + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-"); + return l_eStatus; +} + +VOID CSystemManager::SYSTEMMANAGERLOG_StartupConfirmationMsg(EPWR_SC_MSG_STRUCT & f_scMsg) { + std::stringstream l_enumStr; + l_enumStr << endl; + l_enumStr << " HostProcSoftVer:" << hex << std::setw(16) << std::setfill('0') + << m_VersionNumberStruct.m_VersionNumber << endl; + l_enumStr << " _CWORD56_ Boot Mode:" << GetStr(f_scMsg._CWORD56_BootMode) << endl; // LCOV_EXCL_BR_LINE 11:unexpected branch // NOLINT(whitespace/line_length) + l_enumStr << " wakeupType :" << GetStr(f_scMsg.wakeupType); // LCOV_EXCL_BR_LINE 11:unexpected branch // NOLINT(whitespace/line_length) + + FRAMEWORKUNIFIEDLOG(ZONE_STATE, __FUNCTION__, "%s", l_enumStr.str().c_str()); +} // End of VOID CSystemManager::SYSTEMMANAGERLOG_StartupConfirmationMsg( EPWR_SC_MSG_STRUCT & f_scMsg ) + +VOID CSystemManager::LogESystemmanagerStatusEnums() { + #define INITIAL_INDEX eFrameworkunifiedStatusEmptyMediaList + #define FINAL_INDEX eFrameworkunifiedStatusErrNoEINTR + + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+"); + std::stringstream l_enumStr; + for (int i = INITIAL_INDEX; i <= FINAL_INDEX; i++) { + // LCOV_EXCL_BR_START 11:unexpected branch // NOLINT(whitespace/line_length) + l_enumStr << "\n" << "0x" << std::setfill('0') << std::setw(8) << hex << i + << "/" << std::setfill(' ') << std::setw(2) << dec << i << ": " + << GetStr(static_cast<EFrameworkunifiedStatus>(i)); + // LCOV_EXCL_BR_STOP + } + + std::string l_logMsg = l_enumStr.str(); + SystemmanagerLogString(ZONE_INFO, __FUNCTION__, l_logMsg); // LCOV_EXCL_BR_LINE 11:unexpected branch // NOLINT(whitespace/line_length) + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-"); + +#undef INITIAL_INDEX +#undef FINAL_INDEX +} // End of VOID CSystemManager::LogESystemmanagerStatusEnums() + +VOID CSystemManager::LogProtocolIDs() { +#define INITIAL_INDEX SS_SYSTEM_MANAGER_PROTOCOL_BEGINNING_INDEX +#define FINAL_INDEX SS_SYSTEM_MANAGER_PROTOCOL_ENDING_INDEX + + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+"); + std::stringstream l_enumStr; + for (int i = INITIAL_INDEX; i <= FINAL_INDEX; i++) { + // LCOV_EXCL_BR_START 11:unexpected branch // NOLINT(whitespace/line_length) + l_enumStr << "\n" << "0x" << std::setfill('0') << std::setw(8) << hex << i + << "/" << std::setfill(' ') << std::setw(2) << dec << i << ": " + << GetStr(static_cast<SS_SystemManagerProtocol>(i)); + // LCOV_EXCL_BR_STOP + } + + std::string l_logMsg = l_enumStr.str(); + SystemmanagerLogString(ZONE_INFO, __FUNCTION__, l_logMsg); // LCOV_EXCL_BR_LINE 11:unexpected branch // NOLINT(whitespace/line_length) + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-"); + +#undef INITIAL_INDEX +#undef FINAL_INDEX +} // End of VOID CSystemManager::LogProtocolIDs() + +VOID CSystemManager::SystemmanagerLogString(TFrameworkunifiedZone f_zone, PCSTR f_func, std::string &f_text) { + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+"); + UI_32 l_offset = 0; + UI_32 l_msgLenMax = MAX_QUEUE_MSG_SIZE - 512; // Leave space for the appending of + // the NSLog date/time/service/line string. + + if (f_text.at(f_text.length() - 1) == '\n') { // LCOV_EXCL_BR_LINE 6: For setting the initialization conditions at SystemManager startup + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + f_text.erase(f_text.length() - 1); // LCOV_EXCL_LINE 6: For setting the initialization conditions at SystemManager startup + } + + while (l_offset < f_text.size()) { + UI_32 l_charsRem = static_cast<UI_32>(f_text.size() - l_offset); + UI_32 l_msgLen = (l_charsRem > l_msgLenMax) ? // LCOV_EXCL_BR_LINE 6: For setting the initialization conditions at SystemManager startup + l_msgLenMax : l_charsRem; // LCOV_EXCL_BR_LINE 6: For setting the initialization conditions at SystemManager startup + std::string l_msgStr = f_text.substr(l_offset, l_msgLen); + size_t l_newLinePos = l_msgStr.find_last_of("\n", l_msgLen); + if ((l_newLinePos != std::string::npos) && (l_charsRem > l_msgLenMax)) { // LCOV_EXCL_BR_LINE 6: For setting the initialization conditions at SystemManager startup // NOLINT(whitespace/line_length) + // LCOV_EXCL_START 6: For setting the initialization conditions at SystemManager startup + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + l_msgStr = f_text.substr(l_offset, l_newLinePos); + l_offset += static_cast<UI_32>(l_newLinePos); + // LCOV_EXCL_STOP + } else { + l_offset += l_msgLen; + } + + FRAMEWORKUNIFIEDLOG(f_zone, f_func, l_msgStr.c_str()); + } + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-"); +} // LCOV_EXCL_BR_LINE 10: Final line + +// End of /SS_SystemManager/src/ss_system_manager.cpp diff --git a/video_in_hal/systemservice/system_manager/server/src/ss_system_manager_callbacks.cpp b/video_in_hal/systemservice/system_manager/server/src/ss_system_manager_callbacks.cpp new file mode 100755 index 0000000..2e597ce --- /dev/null +++ b/video_in_hal/systemservice/system_manager/server/src/ss_system_manager_callbacks.cpp @@ -0,0 +1,3411 @@ +/* + * @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_SystemManager +/// \brief This file provides support for System Manager business logic. +/// +/////////////////////////////////////////////////////////////////////////////// +#include <system_service/ss_heartbeat_service_protocol.h> +#include <system_service/ss_system_manager_if.h> +#include <system_service/ss_system_manager_if_local.h> +#include <native_service/frameworkunified_multithreading.h> +#include <sys/wait.h> +#include <system_service/ss_system_manager_notifications.h> +#include <system_service/ss_system_manager_notifications_local.h> +#include <native_service/frameworkunified_framework_if.h> +#include <system_service/ss_services.h> +#include <system_service/ss_power_service_if.h> +#include <processlauncher/ProcessLauncher.h> +#include <processlauncher/ss_sm_process_launcher_protocol.h> +#include <processlauncher/ss_sm_process_launcher.h> +#include <heartbeat/ss_hb_thread.h> + +#include <system_service/ss_power_service_notifications.h> +#include <system_service/ss_power_service_protocol.h> + +#include <native_service/ns_np_service.h> +#include <native_service/ns_np_service_protocol.h> +#include <native_service/ns_backup.h> + +#include <stub/ss_diag.h> + +#include <system_service/ss_error_message.h> +#include <system_service/ss_test_clients.h> +#include <system_service/ss_templates.h> +#include <native_service/ns_plogger_if.h> + +#include <stdlib.h> +#include <stdio.h> +#include <sys/types.h> +#include <sys/stat.h> +#include <fcntl.h> +#include <iomanip> +#include <vector> +#include <algorithm> +#include <string> + +#include "ss_system_manager_callbacks.h" +#include "ss_system_manager.h" +#include "ss_sm_systemmanagerlog.h" +#include "ss_sm_config.h" + +using namespace std; // NOLINT + +extern SS_String GetStr(SS_SMModuleState f_enum); + +template<typename C, eFrameworkunifiedStatus (C::*M)(HANDLE)> EFrameworkunifiedStatus SysMgrCallback(HANDLE hApp) { + EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusFail; + C * pObj = static_cast<C *>(&CSystemManager::GetInstance()); + if (pObj) { // LCOV_EXCL_BR_LINE 5 : new error + l_eStatus = (pObj->*M)(hApp); + } + return l_eStatus; +} + +template<typename C, eFrameworkunifiedStatus (C::*M)(HANDLE, UI_32)> +EFrameworkunifiedStatus SysMgrCbType2(HANDLE hApp, UI_32 f_UI_32) { + EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusFail; + C * pObj = static_cast<C *>(&CSystemManager::GetInstance()); + if (pObj) { // LCOV_EXCL_BR_LINE 5 : new error + l_eStatus = (pObj->*M)(hApp, f_UI_32); + } + return l_eStatus; +} + +template<typename C, BOOL (C::*M)(UI_32)> +BOOL SysMgrCbType3(UI_32 f_UI_32) { + BOOL l_bValue = FALSE; + C * pObj = static_cast<C *>(&CSystemManager::GetInstance()); + if (pObj) { // LCOV_EXCL_BR_LINE 5 : new error + l_bValue = (pObj->*M)(f_UI_32); + } + return l_bValue; +} + +enum { + POWERON = TRUE, + POWEROFF = FALSE +}; + +VOID CSystemManager::LogGroupModulesState(UI_32 f_groupId, std::string pStr) { + if (IS_ZONE_SET(ZONE_INFO)) { // LCOV_EXCL_BR_LINE 6: Because the applicable variable cannot be changed from the external API (only evaluated by the initial value) + // LCOV_EXCL_START 6: Because the applicable variable cannot be changed from the external API (only evaluated by the initial value) + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+"); + + GroupLaunchMapIter l_GroupIterator = m_MapProclaunchGrps.find(f_groupId); + if (l_GroupIterator == m_MapProclaunchGrps.end()) { + FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, + " Error: Group %d not found; 'm_MapProclaunchGrps' is empty", + f_groupId); + } else { + std::string sIsOKFlag; + TEXT(__FUNCTION__, " Group %d/%s, %ld modules: %s, %s", f_groupId, + l_GroupIterator->second.name.c_str(), + l_GroupIterator->second.modules.size(), pStr.c_str(), + GetStr(m_SMCurrentState).c_str()); + + ModuleLaunchListIter l_ModuleListIterator = l_GroupIterator->second.modules.begin(); + for (int i = 1; + l_ModuleListIterator != l_GroupIterator->second.modules.end(); + l_ModuleListIterator++, i++) { + sIsOKFlag = GetModuleCondition(l_ModuleListIterator) ? " " : // 'blank' means OK + "X"; // 'X' means state mismatch + + TEXT(__FUNCTION__, + " %2d: %-24s Start Req'd: %-5s %s %-24s %3dms, %3dms, %d", + i, l_ModuleListIterator->name.c_str(), + l_ModuleListIterator->is_start_required ? + "TRUE" : "FALSE", sIsOKFlag.c_str(), + l_ModuleListIterator->ModuleStateStr().c_str(), + static_cast<SI_16>(l_ModuleListIterator->m_startReason.GetDelta()), + static_cast<SI_16>(l_ModuleListIterator->m_stopReason.GetDelta()), + l_ModuleListIterator->pid); + } + } + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-"); + // LCOV_EXCL_STOP + } +} // End of VOID CSystemManager::LogGroupModulesState( UI_32 f_groupId, std::string pStr) + +VOID CSystemManager::LogAllGroupModulesState(std::string pStr) { + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+"); + + std::string l_sIsOKFlag; + GroupLaunchMapIter l_GroupIterator = m_MapProclaunchGrps.begin(); + + std::stringstream l_comStream; + + l_comStream << pStr << "," << GetStr(m_SMCurrentState); + + std::string l_comStr = l_comStream.str(); + SystemmanagerLogString(ZONE_STATE, __FUNCTION__, l_comStr); + + while (l_GroupIterator != m_MapProclaunchGrps.end()) { + std::stringstream l_tblStream; + l_tblStream << "G" << l_GroupIterator->second.id << "/" << l_GroupIterator->second.name; + + ModuleLaunchListIter l_ModuleListIterator = l_GroupIterator->second.modules.begin(); + + for (int i = 1; + l_ModuleListIterator != l_GroupIterator->second.modules.end(); + l_ModuleListIterator++, i++) { + // Since NPPService exceptionally transitions to STARTED when StartReq'd = N, it is not checked + l_sIsOKFlag = + GetModuleCondition(l_ModuleListIterator) + | (FRAMEWORKUNIFIED_NS_NPSERVICE == l_ModuleListIterator->name) ? + " " : // 'blank' means OK + "X"; // 'X' means state mismatch + + std::string l_isStartReqd = l_ModuleListIterator->is_start_required ? "T" : "F"; + + l_tblStream << endl << " " << std::setw(2) << std::right << i << ":" + << l_ModuleListIterator->pid << " " + << l_ModuleListIterator->name << " " << "StartReq:" + << l_isStartReqd << " " << l_sIsOKFlag + << l_ModuleListIterator->ModuleStateStr(); + + if (l_ModuleListIterator->is_start_required && (FRAMEWORKUNIFIED_NS_NPSERVICE != l_ModuleListIterator->name)) { // LCOV_EXCL_BR_LINE 6: Because the condition cannot be set // NOLINT(whitespace/line_length) + l_tblStream << " " + << static_cast<SI_32>(l_ModuleListIterator->m_startReason.GetDelta()) + << "ms " + << static_cast<SI_32>(l_ModuleListIterator->m_stopReason.GetDelta()) + << "ms"; + } + } + + l_GroupIterator++; + + // Outputs each GROUP so that buffers do not overflow. + std::string l_logMsgStr = l_tblStream.str(); + SystemmanagerLogString(ZONE_STATE, __FUNCTION__, l_logMsgStr); + } + + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-"); +} // End of VOID CSystemManager::LogAllGroupModulesState(std::string pStr) + +BOOL CSystemManager::GetModuleCondition(ModuleLaunchListIter & f_ModuleIter) { + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+"); + BOOL l_bIsModuleStateGood = TRUE; + + switch (m_SMCurrentState) { // LCOV_EXCL_BR_LINE 6: As no values are passed into the default case + case SS_SM_READY_TO_LAUNCH_APP: + l_bIsModuleStateGood = f_ModuleIter->IsModuleState(MODULE_STATE_INVALID); + break; + + case SS_SM_APPS_LAUNCH_IN_PROGRESS: + l_bIsModuleStateGood = f_ModuleIter->IsModuleState(MODULE_STATE_SKIPPED) + || f_ModuleIter->IsModuleState(MODULE_STATE_LAUNCH_FAILED) + || f_ModuleIter->IsModuleState(MODULE_STATE_LAUNCHING) + || f_ModuleIter->IsModuleState(MODULE_STATE_LAUNCHED); + break; + + case SS_SM_APPS_LAUNCHED_READY_TO_START: + l_bIsModuleStateGood = f_ModuleIter->IsModuleState(MODULE_STATE_SKIPPED) + || f_ModuleIter->IsModuleState(MODULE_STATE_LAUNCH_FAILED) + || f_ModuleIter->IsModuleState(MODULE_STATE_CONNECTED) + || f_ModuleIter->IsModuleState(MODULE_STATE_LAUNCHED); + break; + + case SS_SM_APPS_START_IN_PROGRESS: + l_bIsModuleStateGood = f_ModuleIter->IsModuleState(MODULE_STATE_SKIPPED) + || f_ModuleIter->IsModuleState(MODULE_STATE_LAUNCH_FAILED) + || (f_ModuleIter->is_start_required + && (f_ModuleIter->IsModuleState(MODULE_STATE_START_SENT) + || f_ModuleIter->IsModuleState( + MODULE_STATE_STARTED))) + || (!f_ModuleIter->is_start_required + && (f_ModuleIter->IsModuleState(MODULE_STATE_LAUNCHED) + || f_ModuleIter->IsModuleState( + MODULE_STATE_CONNECTED))); + break; + + case SS_SM_APPS_START_COMPLETE: + l_bIsModuleStateGood = + ((f_ModuleIter->IsModuleState(MODULE_STATE_SKIPPED) == TRUE) + || (f_ModuleIter->IsModuleState(MODULE_STATE_LAUNCH_FAILED) == TRUE) + || ((f_ModuleIter->is_start_required == TRUE) + && (f_ModuleIter->IsModuleState(MODULE_STATE_STARTED) == TRUE)) + || ((f_ModuleIter->is_start_required == FALSE) + && ((f_ModuleIter->IsModuleState(MODULE_STATE_LAUNCHED) == TRUE) + || (f_ModuleIter->IsModuleState(MODULE_STATE_CONNECTED) == TRUE)))) ? (BOOL) TRUE : (BOOL) FALSE; + break; + + case SS_SM_APPS_PRE_START_IN_PROGRESS: + l_bIsModuleStateGood = + ((f_ModuleIter->IsModuleState(MODULE_STATE_SKIPPED) == TRUE) + || (f_ModuleIter->IsModuleState(MODULE_STATE_LAUNCH_FAILED) == TRUE) + || ((f_ModuleIter->is_start_required == TRUE) + && ((f_ModuleIter->IsModuleState(MODULE_STATE_START_PRE_SENT) == TRUE) + || (f_ModuleIter->IsModuleState(MODULE_STATE_STARTED_PRE) == TRUE))) + || ((f_ModuleIter->is_start_required == FALSE) + && ((f_ModuleIter->IsModuleState(MODULE_STATE_LAUNCHED) == TRUE) + || (f_ModuleIter->IsModuleState(MODULE_STATE_CONNECTED) == TRUE)))) ? (BOOL) TRUE : (BOOL) FALSE; + break; + + case SS_SM_APPS_PRE_STOP_IN_PROGRESS: + l_bIsModuleStateGood = + ((f_ModuleIter->IsModuleState(MODULE_STATE_SKIPPED) == TRUE) + || (f_ModuleIter->IsModuleState(MODULE_STATE_LAUNCH_FAILED) == TRUE) + || ((f_ModuleIter->is_start_required == TRUE) + && ((f_ModuleIter->IsModuleState(MODULE_STATE_STOP_PRE_SENT) == TRUE) + || (f_ModuleIter->IsModuleState(MODULE_STATE_STOPPED_PRE) == TRUE))) + || ((f_ModuleIter->is_start_required == FALSE) + && ((f_ModuleIter->IsModuleState(MODULE_STATE_LAUNCHED) == TRUE) + || (f_ModuleIter->IsModuleState(MODULE_STATE_CONNECTED) == TRUE)))) ? (BOOL) TRUE : (BOOL) FALSE; + break; + + case SS_SM_APPS_PRE_RUN_COMPLETE: + l_bIsModuleStateGood = + ((f_ModuleIter->IsModuleState(MODULE_STATE_SKIPPED) == TRUE) + || (f_ModuleIter->IsModuleState(MODULE_STATE_LAUNCH_FAILED) == TRUE) + || ((f_ModuleIter->is_start_required == TRUE) + && ((f_ModuleIter->IsModuleState(MODULE_STATE_STARTED_PRE) == TRUE) + || (f_ModuleIter->IsModuleState(MODULE_STATE_STOPPED_PRE) == TRUE))) + || ((f_ModuleIter->is_start_required == FALSE) + && ((f_ModuleIter->IsModuleState(MODULE_STATE_LAUNCHED) == TRUE) + || (f_ModuleIter->IsModuleState(MODULE_STATE_CONNECTED) == TRUE)))) ? (BOOL) TRUE : (BOOL) FALSE; + break; + + case SS_SM_APPS_BACKGROUND_START_IN_PROGRESS: + l_bIsModuleStateGood = + ((f_ModuleIter->IsModuleState(MODULE_STATE_SKIPPED) == TRUE) + || (f_ModuleIter->IsModuleState(MODULE_STATE_LAUNCH_FAILED) == TRUE) + || ((f_ModuleIter->is_start_required == TRUE) + && ((f_ModuleIter->IsModuleState(MODULE_STATE_START_BACKGROUND_SENT) == TRUE) + || (f_ModuleIter->IsModuleState(MODULE_STATE_STARTED_BACKGROUND) == TRUE))) + || ((f_ModuleIter->is_start_required == FALSE) + && ((f_ModuleIter->IsModuleState(MODULE_STATE_LAUNCHED) == TRUE) + || (f_ModuleIter->IsModuleState(MODULE_STATE_CONNECTED) == TRUE)))) ? (BOOL) TRUE : (BOOL) FALSE; + break; + + case SS_SM_APPS_BACKGROUND_STOP_IN_PROGRESS: + l_bIsModuleStateGood = + ((f_ModuleIter->IsModuleState(MODULE_STATE_SKIPPED) == TRUE) + || (f_ModuleIter->IsModuleState(MODULE_STATE_LAUNCH_FAILED) == TRUE) + || ((f_ModuleIter->is_start_required == TRUE) + && ((f_ModuleIter->IsModuleState(MODULE_STATE_STOP_BACKGROUND_SENT) == TRUE) + || (f_ModuleIter->IsModuleState(MODULE_STATE_STOPPED_BACKGROUND) == TRUE))) + || ((f_ModuleIter->is_start_required == FALSE) + && ((f_ModuleIter->IsModuleState(MODULE_STATE_LAUNCHED) == TRUE) + || (f_ModuleIter->IsModuleState(MODULE_STATE_CONNECTED) == TRUE)))) ? (BOOL) TRUE : (BOOL) FALSE; + break; + case SS_SM_APPS_BACKGROUND_RUN_COMPLETE: + l_bIsModuleStateGood = + ((f_ModuleIter->IsModuleState(MODULE_STATE_SKIPPED) == TRUE) + || (f_ModuleIter->IsModuleState(MODULE_STATE_LAUNCH_FAILED) == TRUE) + || ((f_ModuleIter->is_start_required == TRUE) + && ((f_ModuleIter->IsModuleState(MODULE_STATE_STARTED_BACKGROUND) == TRUE) + || (f_ModuleIter->IsModuleState(MODULE_STATE_STOPPED_BACKGROUND) == TRUE))) + || ((f_ModuleIter->is_start_required == FALSE) + && ((f_ModuleIter->IsModuleState(MODULE_STATE_LAUNCHED) == TRUE) + || (f_ModuleIter->IsModuleState(MODULE_STATE_CONNECTED) == TRUE)))) ? (BOOL) TRUE : (BOOL) FALSE; + break; + + case SS_SM_APPS_STOPPING_AT__CWORD56__REQ: + case SS_SM_APPS_STOPPING_AT_INTERNAL_REQ: + l_bIsModuleStateGood = f_ModuleIter->IsModuleState(MODULE_STATE_SKIPPED) + || f_ModuleIter->IsModuleState(MODULE_STATE_LAUNCH_FAILED) + || (f_ModuleIter->is_start_required + && (f_ModuleIter->IsModuleState(MODULE_STATE_STOP_SENT) + || f_ModuleIter->IsModuleState( + MODULE_STATE_STOPPED))) + || (!f_ModuleIter->is_start_required + && (f_ModuleIter->IsModuleState(MODULE_STATE_LAUNCHED) + || f_ModuleIter->IsModuleState( + MODULE_STATE_CONNECTED))); + break; + + case SS_SM_WAITING_FOR_CRITICAL_APPS_AT__CWORD56__REQ: + case SS_SM_WAITING_FOR_CRITICAL_APPS_AT_INTERNAL_REQ: + l_bIsModuleStateGood = f_ModuleIter->IsModuleState(MODULE_STATE_SKIPPED) + || f_ModuleIter->IsModuleState(MODULE_STATE_LAUNCH_FAILED) + || (f_ModuleIter->is_start_required + && f_ModuleIter->IsModuleState(MODULE_STATE_STOPPED)) + || (!f_ModuleIter->is_start_required + && (f_ModuleIter->IsModuleState(MODULE_STATE_LAUNCHED) + || f_ModuleIter->IsModuleState( + MODULE_STATE_CONNECTED))); + break; + + // default: Don't code a 'default' here - let the compiler + // issue a warning ( set via -Wall or -Wswitch ) when the set of + // enumerations changes - then the maintainer will + // automagically know to update this switch statement. + } + + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-"); + return l_bIsModuleStateGood; +} // End of BOOL CSystemManager::GetModuleCondition( ModuleLaunchListIter & f_ModuleIter ) + +/***************************************************************************** + @ingroup: CSystemManager + @brief: Post Termination handler + @note: . + @param void + @return void +*****************************************************************************/ +EFrameworkunifiedStatus CSystemManager::SendRequestToHeartBeat(HANDLE hApp, + EHBProtocolMessages tRequest, VOID *tReqMessageData, + UI_32 u32SizeofMessage) { + EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK; + BOOL bValid = FALSE; + + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+"); + switch (tRequest) { + case SS_HEARTBEAT_START: + bValid = TRUE; + FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__, "SS_HEARTBEAT_START"); + break; + + case SS_HEARTBEAT_STOP: + bValid = TRUE; + FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__, "SS_HEARTBEAT_STOP"); + tReqMessageData = NULL; + break; + + case SS_HEARTBEAT_DELETE_MODULE_ENTRY: + bValid = TRUE; + FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__, "SS_HEARTBEAT_DELETE_MODULE_ENTRY"); + break; + + case SS_HEARTBEAT_APPEND_MODULE_ENTRY: + bValid = TRUE; + FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__, "SS_HEARTBEAT_APPEND_MODULE_ENTRY"); + break; + + default: + bValid = FALSE; + l_eStatus = eFrameworkunifiedStatusInvldParam; + FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, " Error : Ignored Invalid message id 0x%X", tRequest); + break; + } + + if (TRUE == bValid) { // LCOV_EXCL_BR_LINE 200:tRequest cannot be default, so bValid cannot be false + if (INVALID_HANDLE != m_hHeartbeatThread.m_ThreadHdl) { // LCOV_EXCL_BR_LINE 200:m_ThreadHdl cannot be null + if (eFrameworkunifiedStatusOK != (l_eStatus = FrameworkunifiedSendChild(hApp, m_hHeartbeatThread.m_ThreadHdl, tRequest, u32SizeofMessage, tReqMessageData))) { // LCOV_EXCL_BR_LINE 4:NSFW error case //NOLINT (whitespace/line_length) + // LCOV_EXCL_START 4: nsfw error + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + LOG_ERROR("FrameworkunifiedSendChild()"); // LCOV_EXCL_BR_LINE 15: marco defined in ss_templates.h // NOLINT(whitespace/line_length) + // LCOV_EXCL_STOP + } + } else { + // LCOV_EXCL_START 200: m_ThreadHdl cannot be null + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + l_eStatus = eFrameworkunifiedStatusInvldHandle; + FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, " Error : Invalid Heartbeat Thread Handle, cannot send message"); + // LCOV_EXCL_STOP + } + } + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-"); + return l_eStatus; +} + +/////////////////////////////////////////////////////////////////////////////// +/// \ingroup OnModuleConnectWaitTimeout +/// SM maintains timer (40 sec) to check if all modules opened session with him whoever requires Start. +/// This timer is common to all modules. After timeout it checks the status of every module in group map. +/// If a module requires start and does not connect, SM will initiate error event logging followed by Soft Reset +/// \param [in] +/// +/// +/// \return EFrameworkunifiedStatus +/// Success ==> eFrameworkunifiedStatusOK +/// Failure ==> Other values +/////////////////////////////////////////////////////////////////////////////// +EFrameworkunifiedStatus CSystemManager::OnModuleConnectWaitTimeout(HANDLE hApp) { + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+"); + EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK; + + static SI_32 l_NumTimesChecked = 0; + { + char l_cFormat[] = " Received from (Timer expiration %d)"; + char l_cBuf[sizeof(l_cFormat) + 1]; + snprintf(l_cBuf, sizeof(l_cBuf), l_cFormat, l_NumTimesChecked + 1); + FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__, l_cBuf); + } + + std::string l_ProcName; + + SetCmdHist("SM_TIMER_MODULE_CONNECT_WAIT_TIMER", m_TimerCmdHist, // LCOV_EXCL_BR_LINE 11:unexpected branch // NOLINT(whitespace/line_length) + m_TimerHistIter, FrameworkunifiedGetMsgSrc(hApp)); // LCOV_EXCL_BR_LINE 11:unexpected branch // NOLINT(whitespace/line_length) + + BOOL l_bModuleConnMissed = false; + + GroupLaunchMap::reverse_iterator l_grp_riter = m_MapProclaunchGrps.rbegin(); + + ModuleLaunchList::reverse_iterator l_mod_riter; + + if (l_grp_riter == m_MapProclaunchGrps.rend()) { // LCOV_EXCL_BR_LINE 200: group cannot be empty + // LCOV_EXCL_START 200: group cannot be empty + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "Error: Group Map is Empty"); // LCOV_EXCL_BR_LINE 15: marco defined in ns_logger_if.h // NOLINT(whitespace/line_length) + l_eStatus = eFrameworkunifiedStatusDbRecNotFound; + // LCOV_EXCL_STOP + } else { + // scan the group map in reverse order + for (; l_grp_riter != m_MapProclaunchGrps.rend(); l_grp_riter++) { + l_mod_riter = l_grp_riter->second.modules.rbegin(); + for (; l_mod_riter != l_grp_riter->second.modules.rend(); + l_mod_riter++) { + SMModuleState l_ModuleState = l_mod_riter->GetModuleState(); + // if the module is still in MODULE_STATE_LAUNCHED state at + // this point though it requires start something is wrong with + // the module. SM initiates error event logging followed by + // soft rest + if (l_mod_riter->is_start_required + && ((l_ModuleState == MODULE_STATE_INVALID) + || (l_ModuleState == MODULE_STATE_SKIPPED) + || (l_ModuleState == MODULE_STATE_LAUNCHING) + || (l_ModuleState == MODULE_STATE_LAUNCHED) + || (l_ModuleState == MODULE_STATE_LAUNCH_FAILED))) { + FRAMEWORKUNIFIEDLOG(ZONE_WARN, __FUNCTION__, + " Module %s/%s is not connected", + l_mod_riter->name.c_str(), + l_mod_riter->ModuleStateStr().c_str()); + l_bModuleConnMissed = true; + l_ProcName.assign(l_mod_riter->name); + + if (l_ModuleState == MODULE_STATE_LAUNCHED) { + CALL_AND_LOG_STATUS_IF_ERRORED( // LCOV_EXCL_BR_LINE 15: marco defined in ss_templates.h // NOLINT(whitespace/line_length) + l_mod_riter->SetPriority( // LCOV_EXCL_BR_LINE 15: marco defined in ss_templates.h // NOLINT(whitespace/line_length) + m_SystemManagerPriority - 1)); // LCOV_EXCL_BR_LINE 15: marco defined in ss_templates.h // NOLINT(whitespace/line_length) + } + } + } + } + } + + PreLaunchModuleListIter l_itr; + for (l_itr = m_PreLaunchModuleList.begin(); + m_PreLaunchModuleList.end() != l_itr; l_itr++) { + if ((-1 == l_itr->pid) && (l_itr->critical)) { // LCOV_EXCL_BR_LINE 200: all prelaunch mode is not critical // NOLINT(whitespace/line_length) + // LCOV_EXCL_START 200: all prelaunch mode is not critical + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + FRAMEWORKUNIFIEDLOG(ZONE_WARN, __FUNCTION__, " Module %s is not launched", // LCOV_EXCL_BR_LINE 15: marco defined in ns_logger_if.h // NOLINT(whitespace/line_length) + l_itr->name.c_str()); // LCOV_EXCL_BR_LINE 15: marco defined in ns_logger_if.h // NOLINT(whitespace/line_length) + l_bModuleConnMissed = true; + l_ProcName.assign(l_itr->name); + } + // LCOV_EXCL_STOP + } + + l_NumTimesChecked++; + if (true == l_bModuleConnMissed) { + if (l_NumTimesChecked < m_SMConfig.MCConfig.ModuleConnectionNumTimesToCheck) { + char l_cFormat[] = + " l_NumTimesChecked %d < ModuleConnectionNumTimesToCheck %d, " + "will re-check in %d seconds. "; + char l_cBuf[sizeof(l_cFormat) + 1 + 1 + 1]; + snprintf(l_cBuf, sizeof(l_cBuf), l_cFormat, l_NumTimesChecked, + m_SMConfig.MCConfig.ModuleConnectionNumTimesToCheck, + m_SMConfig.MCConfig.ModuleConnectionTimeOutSec); + FRAMEWORKUNIFIEDLOG(ZONE_WARN, __FUNCTION__, l_cBuf); + + } else { + l_eStatus = eFrameworkunifiedStatusBadConnection; + char l_cFormat[] = + " Module connection timeout for %s and " + "l_NumTimesChecked %d == ModuleConnectionNumTimesToCheck %d. " + " Stopping ModuleConnectTimeOut timer and resetting _CWORD102_."; + char l_cBuf[sizeof(l_cFormat) + MAX_NAME_SIZE_APP + 1 + 1]; + snprintf(l_cBuf, sizeof(l_cBuf), l_cFormat, l_ProcName.c_str(), + l_NumTimesChecked, + m_SMConfig.MCConfig.ModuleConnectionNumTimesToCheck); + LOG_ERROR(l_cBuf); // LCOV_EXCL_BR_LINE 15: marco defined in ss_templates.h // NOLINT(whitespace/line_length) + + m_GroupLaunchTimer->StopTimer(m_aTimerIDs[eSM_TIMER_MODULE_CONNECT_WAIT_TIMER]); // LCOV_EXCL_BR_LINE 11:unexpected branch // NOLINT(whitespace/line_length) + + SMLoggingInfo l_loggingInfo; // LCOV_EXCL_BR_LINE 11:unexpected branch // NOLINT(whitespace/line_length) + l_loggingInfo.resetReason = e_SS_SM_CPU_RESET_REASON_GENERIC_ERR; // LCOV_EXCL_BR_LINE 11:unexpected branch // NOLINT(whitespace/line_length) + + // initiate error event logging + l_eStatus = ErrorEventEnqueue(hApp, eErrorEventTypeModConnFailed, + l_ProcName, eErrorEventResetTypeHard, l_loggingInfo); + FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, " Error: ModConnFailed %s", + l_ProcName.c_str()); + fprintf(stderr, "SS_SysManager/%s/Error: ModConnFailed %s\n", // LCOV_EXCL_BR_LINE 11:unexpected branch // NOLINT(whitespace/line_length) + __FUNCTION__, l_ProcName.c_str()); // LCOV_EXCL_BR_LINE 11:unexpected branch // NOLINT(whitespace/line_length) + LOG_STATUS_REC_HIST_IF_ERRORED(l_eStatus, // LCOV_EXCL_BR_LINE 15: marco defined in ss_system_manager.h // NOLINT(whitespace/line_length) + "ErrorEventEnqueue(eErrorEventTypeModConnFailed)"); // LCOV_EXCL_BR_LINE 15: marco defined in ss_system_manager.h // NOLINT(whitespace/line_length) + } + } else { + char l_cFormat[] = + " l_NumTimesChecked = %d, ModuleConnectionNumTimesToCheck = %d. " + "All modules connected. Stopping ModuleConnectTimeOut timer."; + char l_cBuf[sizeof(l_cFormat) + 1 + 1]; + snprintf(l_cBuf, sizeof(l_cBuf), l_cFormat, l_NumTimesChecked, + m_SMConfig.MCConfig.ModuleConnectionNumTimesToCheck); + FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__, l_cBuf); + + m_GroupLaunchTimer->StopTimer(m_aTimerIDs[eSM_TIMER_MODULE_CONNECT_WAIT_TIMER]); // LCOV_EXCL_BR_LINE 11:unexpected branch // NOLINT(whitespace/line_length) + } + + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-"); + return l_eStatus; +} // End of EFrameworkunifiedStatus CSystemManager::OnModuleConnectWaitTimeout( HANDLE hApp ) + +/////////////////////////////////////////////////////////////////////////////// +/// \ingroup OnClientStartMonitorTimerExpiry +/// +/// +/// \param [in] +/// +/// +/// \return EFrameworkunifiedStatus +/// Success ==> eFrameworkunifiedStatusOK +/// Failure ==> Other values +/////////////////////////////////////////////////////////////////////////////// +EFrameworkunifiedStatus CSystemManager::OnClientStartMonitorTimerExpiry(HANDLE hApp) { + EFrameworkunifiedStatus l_eStatus; + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+"); + + FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__, " Received from group %d" + //, m_ActiveGroupId); + , m_SystemStarter.get_id()); + + char cBuf[100]; + SetCmdHist("SM_TIMER_CLIENT_START_MONITOR", m_TimerCmdHist, m_TimerHistIter, FrameworkunifiedGetMsgSrc(hApp)); // LCOV_EXCL_BR_LINE 11:unexpected branch // NOLINT(whitespace/line_length) + // sprintf( cBuf, "ProcessGroupAsStarted(%d)", m_ActiveGroupId); + sprintf(cBuf, "ProcessGroupAsStarted(%d)", m_SystemStarter.get_id()); // NOLINT + l_eStatus = ProcessGroupAsStarted(hApp, m_SystemStarter.get_id()); + LOG_STATUS_REC_HIST_IF_ERRORED(l_eStatus, cBuf); // LCOV_EXCL_BR_LINE 15: marco defined in ss_system_manager.h // NOLINT(whitespace/line_length) + + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-"); + + + return l_eStatus; +} + +/////////////////////////////////////////////////////////////////////////////// +/// \ingroup send_power_request_complete_response +/// send power request completion response to power +/// +/// \param [in] +/// +/// \return EFrameworkunifiedStatus +/// Success ==> eFrameworkunifiedStatusOK +/// Failure ==> Other values +/////////////////////////////////////////////////////////////////////////////// +EFrameworkunifiedStatus CSystemManager::send_power_request_complete_response(HANDLE hApp, std::string pStr) { + EFrameworkunifiedStatus l_eStatus; + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+"); + + // send Wake-up complete response to Power + l_eStatus = FrameworkunifiedSendMsg(m_hPowerServiceSession, + SS_SM_WAKEUP_MODULES_CMPL_RSPN, sizeof(wakeInfo), (PVOID) & m_Wake); + LOG_STATUS_REC_HIST_IF_ERRORED(l_eStatus, "FrameworkunifiedSendMsg(SS_SM_WAKEUP_MODULES_CMPL_RSPN)"); // LCOV_EXCL_BR_LINE 15: marco defined in ss_system_manager.h // NOLINT(whitespace/line_length) + + LogAllGroupModulesState(pStr); + + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-"); + return l_eStatus; +} // End of EFrameworkunifiedStatus CSystemManager::send_power_request_complete_response( HANDLE hApp ) + +/////////////////////////////////////////////////////////////////////////////// +/// \ingroup OnNPPStatusCheckMonitorTimerExpiry +/// +/// \brief Called when NPP fails to provide a ready status in the specified. +/// amount of time. This function will periodically request a new status +/// ACK from NPP service until one is received. See OnNPPReadyStatusCallback(). +/// +/// Note: NPP usually pushes a ready event to SM and the reversion to +/// polling the NPP ready ACK is for additional robustness. Failure +/// to receive an NPP ready ACK will prevent system startup. +/// +/// \param [in] hApp - Handle to framework application. +/// +/// \return EFrameworkunifiedStatus +/// Success ==> eFrameworkunifiedStatusOK +/// Failure ==> Other values +/////////////////////////////////////////////////////////////////////////////// +EFrameworkunifiedStatus CSystemManager::OnNPPStatusCheckMonitorTimerExpiry(HANDLE hApp) { + EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK; + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+"); + + SetCmdHist("SM_TIMER_NPP_STATUS_CHECK_MONITOR", m_TimerCmdHist, // LCOV_EXCL_BR_LINE 11:unexpected branch // NOLINT(whitespace/line_length) + m_TimerHistIter, FrameworkunifiedGetMsgSrc(hApp)); // LCOV_EXCL_BR_LINE 11:unexpected branch // NOLINT(whitespace/line_length) + + FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__, " m_bIsNPP_ServicesStarted is '%s'", + GetStr(m_bIsNPP_ServicesStarted).c_str()); + + if (FALSE == m_bIsNPP_ServicesStarted) { + l_eStatus = FrameworkunifiedNPGetReadyStatusOfNPP(hApp); + LOG_ERROR_REC_HIST_IF_ERRORED(l_eStatus, "FrameworkunifiedNPGetReadyStatusOfNPP()"); // LCOV_EXCL_BR_LINE 15: marco defined in ss_system_manager.h // NOLINT(whitespace/line_length) + } + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-"); + return l_eStatus; +} + +/////////////////////////////////////////////////////////////////////////////// +/// \ingroup OnNPPReadyStatusCallback +/// +/// \brief Called when NPP returns a status ACK indicating that the service is +/// operational and ready to respond to subsequent requests. +/// +/// \param [in] hApp - Handle to framework application. +/// +/// \return EFrameworkunifiedStatus +/// Success ==> eFrameworkunifiedStatusOK +/// Failure ==> Other values +/////////////////////////////////////////////////////////////////////////////// +EFrameworkunifiedStatus CSystemManager::OnNPPReadyStatusCallback(HANDLE hApp) { // LCOV_EXCL_START 6: Because the condition cannot be set + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+"); + EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK; + INTERFACEUNIFIEDLOG_RECEIVED_FROM(hApp); // LCOV_EXCL_BR_LINE 15: marco defined in ns_logger_if.h // NOLINT(whitespace/line_length) + FRAMEWORKUNIFIEDLOG(ZONE_PERFORMANCE, __FUNCTION__, "from %s", FrameworkunifiedGetMsgSrc(hApp)); + + SetCmdHist("NPS_GET_READYSTATUS_ACK", m_SMCmdHist, m_SMHistIter, FrameworkunifiedGetMsgSrc(hApp)); + + l_eStatus = OnNPPReadyEventCallback(hApp); + LOG_ERROR_REC_HIST_IF_ERRORED(l_eStatus, "OnNPPReadyEventCallback()"); // LCOV_EXCL_BR_LINE 15: marco defined in ss_system_manager.h // NOLINT(whitespace/line_length) + + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-"); + return l_eStatus; +} +// LCOV_EXCL_STOP + +EFrameworkunifiedStatus CSystemManager::OnNPPReadyEventCallback(HANDLE hApp) { + EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK; + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+"); + PCSTR l_moduleName = FrameworkunifiedGetMsgSrc(hApp); + FRAMEWORKUNIFIEDLOG(ZONE_PERFORMANCE, __FUNCTION__, "from %s", l_moduleName); + + SetCmdHist("NPS_NPP_READY_EVENT", m_SMCmdHist, m_SMHistIter, l_moduleName); // LCOV_EXCL_BR_LINE 11:unexpected branch // NOLINT(whitespace/line_length) + if (TRUE == m_bIsNPP_ServicesStarted) { + l_eStatus = eFrameworkunifiedStatusMsgNotProcessed; + LOG_ERROR("TRUE == m_bIsNPP_ServicesStarted"); // LCOV_EXCL_BR_LINE 15: marco defined in ss_templates.h // NOLINT(whitespace/line_length) + } else { + ModuleLaunchListIter l_ModuleListIter; + m_bIsNPP_ServicesStarted = TRUE; + FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__, " m_bIsNPP_ServicesStarted set 'TRUE'"); + m_GroupLaunchTimer->StopTimer(m_aTimerIDs[eSM_TIMER_NPP_STATUS_CHECK_MONITOR]); + + UI_32 l_cbCmdIdArrayNPPService[] = { NPS_NPP_READY_EVENT, NPS_GET_READYSTATUS_ACK }; + + if (eFrameworkunifiedStatusOK != (l_eStatus = FrameworkunifiedDetachCallbacksFromDispatcher(hApp, FRAMEWORKUNIFIED_NS_NPSERVICE, l_cbCmdIdArrayNPPService, static_cast<UI_32>(_countof(l_cbCmdIdArrayNPPService))))) { // LCOV_EXCL_BR_LINE 4:NSFW error case //NOLINT (whitespace/line_length) + // LCOV_EXCL_START 4: nsfw error code + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + LOG_ERROR("FrameworkunifiedDetachCallbacksFromDispatcher()"); // LCOV_EXCL_BR_LINE 15: marco defined in ss_templates.h // NOLINT(whitespace/line_length) + // LCOV_EXCL_STOP + } else if (eFrameworkunifiedStatusOK != (l_eStatus = register_all_notification_callbacks(hApp))) { // LCOV_EXCL_BR_LINE 4:NSFW error case //NOLINT (whitespace/line_length) + // LCOV_EXCL_START 4: nsfw error code + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + LOG_ERROR("register_all_notification_callbacks()"); // LCOV_EXCL_BR_LINE 15: marco defined in ss_templates.h // NOLINT(whitespace/line_length) + // LCOV_EXCL_STOP + } else if (eFrameworkunifiedStatusOK != (l_eStatus = GetModuleIterator(l_moduleName, l_ModuleListIter))) { // LCOV_EXCL_BR_LINE 200:NPP always in launch map //NOLINT (whitespace/line_length) + // LCOV_EXCL_START 200 : NPP service always in launch map + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, // LCOV_EXCL_BR_LINE 15: marco defined in ns_logger_if.h // NOLINT(whitespace/line_length) + " Error: Module %s not found in Group Launch Map", // LCOV_EXCL_BR_LINE 15: marco defined in ns_logger_if.h // NOLINT(whitespace/line_length) + l_moduleName); // LCOV_EXCL_BR_LINE 15: marco defined in ns_logger_if.h // NOLINT(whitespace/line_length) + // LCOV_EXCL_STOP + } else { + l_ModuleListIter->SetModuleState(MODULE_STATE_STARTED); + + if (m_oSystemLauncher.get_id() == 1) { + m_oSystemLauncher.advance_id(); + } + + l_eStatus = OnLaunchGroup(hApp); + LOG_ERROR_REC_HIST_IF_ERRORED(l_eStatus, "OnLaunchGroup(hApp)"); // LCOV_EXCL_BR_LINE 15: marco defined in ss_system_manager.h // NOLINT(whitespace/line_length) + if (eFrameworkunifiedStatusOK == l_eStatus) { // LCOV_EXCL_BR_LINE 200: OnLaunchGroup() return ok + FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__, " successful"); + } + } + } + + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-"); + return l_eStatus; +} // End of EFrameworkunifiedStatus CSystemManager::OnNPPReadyEventCallback( HANDLE hApp ) + +/////////////////////////////////////////////////////////////////////////////// +/// \ingroup OnBackupMgrAvailCallback +/// BackupManager Availability Notification Callback +/// +/// \param [in] +/// +/// +/// \return EFrameworkunifiedStatus +/// Success ==> eFrameworkunifiedStatusOK +/// Failure ==> Other values +/////////////////////////////////////////////////////////////////////////////// +EFrameworkunifiedStatus CSystemManager::OnBackupMgrAvailCallback(HANDLE hApp) { + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+"); + EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK; + + if (sizeof(ServiceAvailability) != FrameworkunifiedGetMsgLength(hApp)) { // LCOV_EXCL_BR_LINE 4: nsfw error + // LCOV_EXCL_START 4: nsfw error + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + SS_ASERT(0); // LCOV_EXCL_BR_LINE 15: marco defined in ss_templates.h // NOLINT(whitespace/line_length) + // LCOV_EXCL_STOP + l_eStatus = eFrameworkunifiedStatusFail; + } else if (strcmp(FrameworkunifiedGetLastNotification(hApp), NTFY_BackupMgr_Availability) != 0) { // LCOV_EXCL_BR_LINE 200:cannot be false //NOLINT (whitespace/line_length) + // LCOV_EXCL_START 200: cannot be false + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + SS_ASERT(0); // LCOV_EXCL_BR_LINE 15: marco defined in ss_templates.h // NOLINT(whitespace/line_length) + l_eStatus = eFrameworkunifiedStatusFail; + // LCOV_EXCL_STOP + } else { + m_bIsBackupAvail = FrameworkunifiedIsServiceAvailable(hApp); + FRAMEWORKUNIFIEDLOG(ZONE_STATE, __FUNCTION__, "BackupAvail:%s", m_bIsBackupAvail ? "T" : "F"); + + l_eStatus = OnLaunchGroup(hApp); + LOG_ERROR_REC_HIST_IF_ERRORED(l_eStatus, "OnLaunchGroup(hApp)"); // LCOV_EXCL_BR_LINE 15: marco defined in ss_system_manager.h // NOLINT(whitespace/line_length) + } + + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-"); + return l_eStatus; +} // End of EFrameworkunifiedStatus CSystemManager::OnBackupMgrAvailCallback(HANDLE hApp) + +/////////////////////////////////////////////////////////////////////////////// +/// \ingroup OnPowerRequestCallback +/// PowerRequest callback handler +/// +/// \param [in] +/// +/// +/// \return EFrameworkunifiedStatus +/// Success ==> eFrameworkunifiedStatusOK +/// Failure ==> Other values +/////////////////////////////////////////////////////////////////////////////// +EFrameworkunifiedStatus CSystemManager::OnPowerRequestCallback(HANDLE hApp) { + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+"); + EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK; + Pwr_ServiceSetInterface tServiceIf; + INTERFACEUNIFIEDLOG_RECEIVED_FROM(hApp); // LCOV_EXCL_BR_LINE 15: marco defined in ns_logger_if.h // NOLINT(whitespace/line_length) + + SetCmdHist("SS_SM_POWER_REQUEST_MSG", m__CWORD56_CmdHist, m__CWORD56_HistIter, FrameworkunifiedGetMsgSrc(hApp)); + + // OnSystemManagerDebugDump(hApp); + // ReadMsg(): * + // Check hApp ptr, msg size, msg reception, read msg if all ok. * + // Report any errors found. * + // * + if (eFrameworkunifiedStatusOK != (l_eStatus = ReadMsg < Pwr_ServiceSetInterface > (hApp, tServiceIf))) { // LCOV_EXCL_BR_LINE 4:NSFW error case //NOLINT (whitespace/line_length) + // LCOV_EXCL_START 4: nsfw error + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + LOG_ERROR("ReadMsg()"); // LCOV_EXCL_BR_LINE 15: marco defined in ss_templates.h // NOLINT(whitespace/line_length) + // LCOV_EXCL_STOP + } else { + // NOTE: interface_unified always set userMode as 0. so don't use m_lastUserMode. + m_lastUserMode = tServiceIf.data.powerRequestMsg.userMode; + // + // 2012 December 04 Temporary hack ( I hope ) to set m_Wake to nominal + // values. At present, the 'Power Request Message Response' is sent + // back to Power Services via the 'send_power_request_complete_response()' + // function, which uses m_Wake. + m_Wake.powerupType = + m_SSBool_to_PowerTypeEnumMap[m_SSUserMode_to_SSBoolEnumMap[m_lastUserMode]]; + + m_Wake.up.factor = tServiceIf.data.powerRequestMsg.startupReason; + + if (epswfINVALID != m_Wake.up.factor) { + m_StartUpReason = m_Wake.up.factor; + } + + m_userModeChangeReason = tServiceIf.data.powerRequestMsg.userModeChangeReason; + m_Wake.up.userModeChangeReason = m_userModeChangeReason; + + FRAMEWORKUNIFIEDLOG(ZONE_STATE, __FUNCTION__, "UserMode:%s, SM State:%s", + GetStr(m_lastUserMode).c_str(), + GetStr(m_SMCurrentState).c_str()); + FRAMEWORKUNIFIEDLOG(ZONE_PERFORMANCE, __FUNCTION__, "UserMode:%s, SM State:%s", + GetStr(m_lastUserMode).c_str(), + GetStr(m_SMCurrentState).c_str()); + CALL_AND_LOG_STATUS(PublishPowerOnOffNotification(hApp)); // LCOV_EXCL_BR_LINE 15: marco defined in ss_templates.h // NOLINT(whitespace/line_length) + + switch (m_SMCurrentState) { // LCOV_EXCL_BR_LINE 6: As not all cases can be passed through + case SS_SM_READY_TO_LAUNCH_APP: + FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, + " Error: Received a PowerRequest command while still in " + "the '%s' state !!!", + GetStr(m_SMCurrentState).c_str()); + l_eStatus = eFrameworkunifiedStatusErrOther; + break; + + case SS_SM_APPS_LAUNCH_IN_PROGRESS: + // When Start is received while processes are launching, we + // need to send the Start request later, once the 'Open + // Session Request' is received from the application. + //***** + // Deliberate commenting-out of case-break to allow this case to + // use following case's logic. + // break; + //***** + + case SS_SM_APPS_LAUNCHED_READY_TO_START: + case SS_SM_APPS_START_COMPLETE: + case SS_SM_APPS_PRE_RUN_COMPLETE: + case SS_SM_APPS_BACKGROUND_RUN_COMPLETE: + case SS_SM_APPS_START_IN_PROGRESS: + case SS_SM_APPS_PRE_START_IN_PROGRESS: + case SS_SM_APPS_PRE_STOP_IN_PROGRESS: + case SS_SM_APPS_BACKGROUND_START_IN_PROGRESS: + case SS_SM_APPS_BACKGROUND_STOP_IN_PROGRESS: + FRAMEWORKUNIFIEDLOG(ZONE_PERFORMANCE, __FUNCTION__, "Startup Reason is '%s'", GetStr(m_StartUpReason).c_str()); + if ((m_userModeChangeReason == epsumcrPARKING_B) + || ((m_userModeChangeReason == epsumcrPRE_BA) && (m_SMCurrentState == SS_SM_APPS_PRE_RUN_COMPLETE)) + || ((m_userModeChangeReason == epsumcrNORMAL) && (m_SMCurrentState == SS_SM_APPS_START_COMPLETE)) + || ((m_userModeChangeReason == epsumcrBACKGROUND_BA) + && (m_SMCurrentState == SS_SM_APPS_BACKGROUND_RUN_COMPLETE))) { + // send the Power Request complete response to PowerService + // LCOV_EXCL_BR_START 15: Excluded due to inlined functions + CALL_AND_LOG_STATUS_IF_ERRORED(send_power_request_complete_response(hApp, "Power Request")); + // LCOV_EXCL_BR_STOP 15: Excluded due to inlined functions + } else { + // + // Publish the UserMode 'Off' notification now for those + // applications that need immediate notification ( HMI ) + if (m_lastUserMode == epsumOFF) { + CALL_AND_LOG_STATUS(PublishUserModeNotification(hApp)); // LCOV_EXCL_BR_LINE 15: marco defined in ss_templates.h // NOLINT(whitespace/line_length) + } + + CALL_AND_LOG_STATUS(BeginStartup(hApp)); // LCOV_EXCL_BR_LINE 15: marco defined in ss_templates.h // NOLINT(whitespace/line_length) + } + break; + + case SS_SM_APPS_STOPPING_AT__CWORD56__REQ: + case SS_SM_WAITING_FOR_CRITICAL_APPS_AT__CWORD56__REQ: + // Abort the Stop. + // Reset System Manager to handle (re)starting as if this is a + // nominal start. + m_GroupLaunchTimer->StopTimer(m_aTimerIDs[eSM_TIMER_CLIENT_STOP_MONITOR]); + + FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__, " Aborted %s, resetting to %s," + " restarting Application groups at group %d", + GetStr(m_SMCurrentState).c_str(), + GetStr(SS_SM_APPS_START_IN_PROGRESS).c_str() + , m_SystemStarter.get_id()); + + CALL_AND_LOG_STATUS(BeginStartup(hApp)); // LCOV_EXCL_BR_LINE 15: marco defined in ss_templates.h // NOLINT(whitespace/line_length) + + break; + + case SS_SM_APPS_STOPPING_AT_INTERNAL_REQ: + case SS_SM_WAITING_FOR_CRITICAL_APPS_AT_INTERNAL_REQ: // LCOV_EXCL_START 8: As no value is set + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + FRAMEWORKUNIFIEDLOG(ZONE_WARN, __FUNCTION__, + " Warning: System Manager state is %d/'%s', ignoring " + "PowerRequest command", m_SMCurrentState, + GetStr(m_SMCurrentState).c_str()); + break; + } // LCOV_EXCL_STOP + } + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-"); + return l_eStatus; +} // End of EFrameworkunifiedStatus CSystemManager::OnPowerRequestCallback( HANDLE hApp ) + +/////////////////////////////////////////////////////////////////////////////// +/// \ingroup +/// Begin the Startup process +/// +/// \param [in] +/// +/// +/// \return EFrameworkunifiedStatus +/// Success ==> eFrameworkunifiedStatusOK +/// Failure ==> Other values +/////////////////////////////////////////////////////////////////////////////// +EFrameworkunifiedStatus CSystemManager::BeginStartup(HANDLE hApp) { + EFrameworkunifiedStatus l_eStatus; + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+"); + + if ((m_userModeChangeReason != epsumcrPARKING_B) && + (m_userModeChangeReason != epsumcrPRE_BA) && + (m_userModeChangeReason != epsumcrNORMAL) && + (m_userModeChangeReason != epsumcrBACKGROUND_BA)) { + // Not a power state transition request. + return eFrameworkunifiedStatusOK; + } + + switch (m_userModeChangeReason) { // LCOV_EXCL_BR_LINE 6: Excluded because it has been guarded to prevent out-of-range values from entering immediately before. + case epsumcrPRE_BA: + // LCOV_EXCL_BR_START 6: This function is an internal function, and it is guarded so that the value outside the range is not entered by the caller, so it is excluded. + if ((m_SMCurrentState == SS_SM_APPS_START_COMPLETE) || (m_SMCurrentState == SS_SM_APPS_BACKGROUND_RUN_COMPLETE)) { + // LCOV_EXCL_BR_STOP 6: This function is an internal function, and it is guarded so that the value outside the range is not entered by the caller, so it is excluded. + m_SystemStarter.to_end(); + SMSetState(hApp, SS_SM_APPS_PRE_STOP_IN_PROGRESS); + } else { + m_SystemStarter.to_begin(); + SMSetState(hApp, SS_SM_APPS_PRE_START_IN_PROGRESS); + } + break; + case epsumcrNORMAL: + m_SystemStarter.to_begin(); + SMSetState(hApp, SS_SM_APPS_START_IN_PROGRESS); + break; + case epsumcrBACKGROUND_BA: + if (m_SMCurrentState == SS_SM_APPS_START_COMPLETE) { + m_SystemStarter.to_end(); + SMSetState(hApp, SS_SM_APPS_BACKGROUND_STOP_IN_PROGRESS); + } else { + m_SystemStarter.to_begin(); + SMSetState(hApp, SS_SM_APPS_BACKGROUND_START_IN_PROGRESS); + } + break; + default: + break; + } + + FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__, + " Starting 'Start Resp Monitor' Timer with '%d' sec", + m_SMConfig.MCConfig.ModuleStartRespTimeOutSec); + + m_GroupLaunchTimer->StartTimer( + m_aTimerIDs[eSM_TIMER_START_RESP_MONITOR_WAIT_TIMER], + m_SMConfig.MCConfig.ModuleStartRespTimeOutSec, 0, 0, 0); + + l_eStatus = start_all_modules_of_group(hApp, m_SystemStarter.get_id()); + if (eFrameworkunifiedStatusOK != l_eStatus) { + FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, + " Error: start_all_modules_of_group(%d) errored: %d/'%s'", + m_SystemStarter.get_id(), l_eStatus, GetStr(l_eStatus).c_str()); + } + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-"); + return l_eStatus; +} // End of EFrameworkunifiedStatus CSystemManager::BeginStartup( HANDLE hApp ) + +/////////////////////////////////////////////////////////////////////////////// +/// \ingroup OnWakeupCallback +/// WakeUp callback handler +/// +/// \param [in] +/// +/// +/// \return EFrameworkunifiedStatus +/// Success ==> eFrameworkunifiedStatusOK +/// Failure ==> Other values +/////////////////////////////////////////////////////////////////////////////// +EFrameworkunifiedStatus CSystemManager::OnWakeupCallback(HANDLE hApp) { // LCOV_EXCL_START 6: Because the condition cannot be set + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusFail; + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+"); + INTERFACEUNIFIEDLOG_RECEIVED_FROM(hApp); + FRAMEWORKUNIFIEDLOG(ZONE_PERFORMANCE, __FUNCTION__, "Received from %s", FrameworkunifiedGetMsgSrc(hApp)); + + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-"); + return l_eStatus; +} // End of EFrameworkunifiedStatus CSystemManager::OnWakeupCallback( HANDLE hApp ) +// LCOV_EXCL_STOP + +/////////////////////////////////////////////////////////////////////////////// +/// \ingroup OnModuleStartCompleteResponse +/// Start Response\Ack Handlers +/// +/// \param [in] +/// +/// +/// \return EFrameworkunifiedStatus +/// Success ==> eFrameworkunifiedStatusOK +/// Failure ==> Other values +/////////////////////////////////////////////////////////////////////////////// +EFrameworkunifiedStatus CSystemManager::OnModuleStartCompleteResponse(HANDLE hApp) { + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+"); + EFrameworkunifiedStatus l_eStatus; + INTERFACEUNIFIEDLOG_RECEIVED_FROM(hApp); // LCOV_EXCL_BR_LINE 15: marco defined in ns_logger_if.h // NOLINT(whitespace/line_length) + FRAMEWORKUNIFIEDLOG(ZONE_PERFORMANCE, __FUNCTION__, "%s", FrameworkunifiedGetMsgSrc(hApp)); + + SetCmdHist("system_manager protocol completion response", m_SMCmdHist, m_SMHistIter, FrameworkunifiedGetMsgSrc(hApp)); // LCOV_EXCL_BR_LINE 11:unexpected branch // NOLINT(whitespace/line_length) + + ModuleLaunchListIter l_ModuleListIter; + std::string l_moduleName = FrameworkunifiedGetMsgSrc(hApp); + l_eStatus = GetModuleIterator(l_moduleName.c_str(), l_ModuleListIter); + if (eFrameworkunifiedStatusOK != l_eStatus) { // LCOV_EXCL_BR_LINE 200:always be eFrameworkunifiedStatusOK + // LCOV_EXCL_START 200: always be eFrameworkunifiedStatusOK + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, + " Error: Module %s not found in Group Launch Map", + l_moduleName.c_str()); + // LCOV_EXCL_STOP + } else { + switch (m_SMCurrentState) { // LCOV_EXCL_BR_LINE 200: cannot be SS_SM_READY_TO_LAUNCH_APP + case SS_SM_READY_TO_LAUNCH_APP: + // LCOV_EXCL_START 200: cannot be SS_SM_READY_TO_LAUNCH_APP + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, + " Error: Received while in the '%s' state !!!", + GetStr(m_SMCurrentState).c_str()); + l_eStatus = eFrameworkunifiedStatusErrOther; + break; + // LCOV_EXCL_STOP + + case SS_SM_APPS_LAUNCH_IN_PROGRESS: + case SS_SM_APPS_LAUNCHED_READY_TO_START: + case SS_SM_APPS_START_IN_PROGRESS: + case SS_SM_APPS_PRE_START_IN_PROGRESS: + case SS_SM_APPS_PRE_STOP_IN_PROGRESS: + case SS_SM_APPS_BACKGROUND_START_IN_PROGRESS: + case SS_SM_APPS_BACKGROUND_STOP_IN_PROGRESS: + { + const SMModuleState l_state = InProgressStateToState(); // LCOV_EXCL_BR_LINE 11: Gcov constraints (because exception-handling routes are automatically generated) // NOLINT(whitespace/line_length) + if (l_state != MODULE_STATE_INVALID) { + const PCSTR l_loglist[] = {"start", "pre start", "pre stop", "background start", "background stop", ""}; + PCSTR l_logtxt; + switch (l_state) { // LCOV_EXCL_BR_LINE 6: As no other value is returned + case MODULE_STATE_STARTED: + l_logtxt = l_loglist[0]; + break; + case MODULE_STATE_STARTED_PRE: + l_logtxt = l_loglist[1]; + break; + case MODULE_STATE_STOPPED_PRE: + l_logtxt = l_loglist[2]; + break; + case MODULE_STATE_STARTED_BACKGROUND: + l_logtxt = l_loglist[3]; + break; + case MODULE_STATE_STOPPED_BACKGROUND: + l_logtxt = l_loglist[4]; + break; + // LCOV_EXCL_START 6: As no other value is returned + default: + AGL_ASSERT_NOT_TESTED(); + l_logtxt = l_loglist[5]; + break; + // LCOV_EXCL_STOP 6: As no other value is returned + } + l_eStatus = ModuleCompleteResponse(hApp, l_ModuleListIter, l_state, // LCOV_EXCL_BR_LINE 11: Gcov constraints (because exception-handling routes are automatically generated) // NOLINT(whitespace/line_length) + SysMgrCbType3<CSystemManager, &CSystemManager::IsGroupStarted>, + SysMgrCbType2<CSystemManager, &CSystemManager::ProcessGroupAsStarted>, + l_logtxt); + } + } + break; + + case SS_SM_APPS_STOPPING_AT__CWORD56__REQ: + case SS_SM_APPS_STOPPING_AT_INTERNAL_REQ: + case SS_SM_WAITING_FOR_CRITICAL_APPS_AT__CWORD56__REQ: + case SS_SM_WAITING_FOR_CRITICAL_APPS_AT_INTERNAL_REQ: + // SystemManager changed state while this module was starting; + // tell this module to stop. + if (!l_ModuleListIter->IsModuleState(MODULE_STATE_STOP_SENT) + && !l_ModuleListIter->IsModuleState(MODULE_STATE_STOPPED)) { + T_SS_SM_STOP_DataStructType l_SM_STOP_Struct; + l_SM_STOP_Struct.shutdownTrigger = m_shutdownTrigger; + l_SM_STOP_Struct.lastUserMode = m_lastUserMode; + + CALL_AND_LOG_STATUS( // LCOV_EXCL_BR_LINE 15: marco defined in ss_templates.h // NOLINT(whitespace/line_length) + l_ModuleListIter->SendMsgAndUpdateState( + &l_SM_STOP_Struct)); + } + break; + default: + FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, " Error: Received while in the '%s' state !!!", GetStr(m_SMCurrentState).c_str()); + l_eStatus = eFrameworkunifiedStatusErrOther; + break; + } // End switch ( m_SMCurrentState ) + } + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-"); + return l_eStatus; +} // End of EFrameworkunifiedStatus CSystemManager::OnModuleStartCompleteResponse( HANDLE hApp ) + +/////////////////////////////////////////////////////////////////////////////// +/// \ingroup ModuleCompleteResponse +/// Start Response\Ack Handlers +/// +/// \param [in] +/// +/// +/// \return EFrameworkunifiedStatus +/// Success ==> eFrameworkunifiedStatusOK +/// Failure ==> Other values +/////////////////////////////////////////////////////////////////////////////// +EFrameworkunifiedStatus CSystemManager::ModuleCompleteResponse(HANDLE hApp, + ModuleLaunchListIter f_ModuleListIter, SMModuleState f_moduleState, + FncCbType3 f_isGroupDoneFnc, FncCbType2 f_groupDoneFnc, + PCSTR f_sCompleteTypeText) { + EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK; + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+"); + std::string l_moduleName = FrameworkunifiedGetMsgSrc(hApp); + FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__, + " Received from %s, m_SystemStarter.get_id() is %d", + l_moduleName.c_str() + , m_SystemStarter.get_id()); + + f_ModuleListIter->SetModuleState(f_moduleState); + if (f_ModuleListIter->group_id != m_SystemStarter.get_id()) { + // In PastModel002, it is assumed that there is no service that returns a FrameworkunifiedOnStop reply after the NPP service. + // However, since _CWORD71_ does not assume this, completion of waiting for termination of the CRITICAL service must be + // judged even when services other than the Group1 service terminate last. + // Initially, SS_SM_WAITING_FOR_CRITICAL_APPS_AT_XXXX should be handled separately by ProcessModuleStopCompleteResponse(), + // but this is limited to ModuleCompleteResponse in order to avoid code deviation from PastModel002 and limit the scope of effect. + // LCOV_EXCL_BR_START 200 : m_SMCurrentState can't be SS_SM_WAITING_FOR_CRITICAL_APPS_AT__CWORD56__REQ and SS_SM_WAITING_FOR_CRITICAL_APPS_AT_INTERNAL_REQ // NOLINT(whitespace/line_length) + if ((MODULE_STATE_STOPPED == f_moduleState) + && ((m_SMCurrentState + == SS_SM_WAITING_FOR_CRITICAL_APPS_AT__CWORD56__REQ) + || (m_SMCurrentState + == SS_SM_WAITING_FOR_CRITICAL_APPS_AT_INTERNAL_REQ))) { + // LCOV_EXCL_BR_STOP 200 : m_SMCurrentState can't be SS_SM_WAITING_FOR_CRITICAL_APPS_AT__CWORD56__REQ and SS_SM_WAITING_FOR_CRITICAL_APPS_AT_INTERNAL_REQ // NOLINT(whitespace/line_length) + // LCOV_EXCL_START 200 : m_SMCurrentState can't be SS_SM_WAITING_FOR_CRITICAL_APPS_AT__CWORD56__REQ and SS_SM_WAITING_FOR_CRITICAL_APPS_AT_INTERNAL_REQ // NOLINT(whitespace/line_length) + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + check_all_groups_have_stopped(hApp); + // LCOV_EXCL_STOP + } else { + FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__, + " %s ( group %d ) received out-of-synch; m_SystemStarter.get_id() is %d", + l_moduleName.c_str(), f_ModuleListIter->group_id + , m_SystemStarter.get_id()); + } + } else { + if ((*f_isGroupDoneFnc)(f_ModuleListIter->group_id)) { // LCOV_EXCL_BR_LINE 11: Gcov constraints (because exception-handling routes are automatically generated) // NOLINT(whitespace/line_length) + l_eStatus = (*f_groupDoneFnc)(hApp, f_ModuleListIter->group_id); // LCOV_EXCL_BR_LINE 11:unexpected branch // NOLINT(whitespace/line_length) + } else if (IS_ZONE_SET(ZONE_INFO)) { // LCOV_EXCL_BR_LINE 6: Because the applicable variable cannot be changed from the external API (only evaluated by the initial value) + // LCOV_EXCL_START 6: Because the applicable variable cannot be changed from the external API (only evaluated by the initial value) + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + TEXT(__FUNCTION__, // LCOV_EXCL_BR_LINE 15: marco defined in ns_logger_if.h // NOLINT(whitespace/line_length) + " Group %d %s incomplete, m_SystemStarter.get_id() is %d", // LCOV_EXCL_BR_LINE 15: marco defined in ns_logger_if.h // NOLINT(whitespace/line_length) + f_ModuleListIter->group_id, f_sCompleteTypeText // LCOV_EXCL_BR_LINE 15: marco defined in ns_logger_if.h // NOLINT(whitespace/line_length) + , m_SystemStarter.get_id()); // LCOV_EXCL_BR_LINE 15: marco defined in ns_logger_if.h // NOLINT(whitespace/line_length) + char cBuf[100]; + sprintf(cBuf, "%s incomplete", f_sCompleteTypeText); // NOLINT + LogGroupModulesState(f_ModuleListIter->group_id, cBuf); // LCOV_EXCL_BR_LINE 11:unexpected branch // NOLINT(whitespace/line_length) + // LCOV_EXCL_STOP + } + } + + const SMModuleState l_transition_state = InProgressStateToState(); // LCOV_EXCL_BR_LINE 11: Gcov constraints (because exception-handling routes are automatically generated) // NOLINT(whitespace/line_length) + if (l_transition_state == f_moduleState) { // LCOV_EXCL_BR_LINE 6: As no other value is returned + if (have_all_services_start_completed(l_transition_state) == TRUE) { + if ((m_SMCurrentState == SS_SM_APPS_PRE_START_IN_PROGRESS) + || (m_SMCurrentState == SS_SM_APPS_PRE_STOP_IN_PROGRESS)) { + SMSetState(hApp, SS_SM_APPS_PRE_RUN_COMPLETE); // LCOV_EXCL_BR_LINE 11: Gcov constraints (because exception-handling routes are automatically generated) // NOLINT(whitespace/line_length) + } else if ((m_SMCurrentState == SS_SM_APPS_BACKGROUND_START_IN_PROGRESS) + || (m_SMCurrentState == SS_SM_APPS_BACKGROUND_STOP_IN_PROGRESS)) { + SMSetState(hApp, SS_SM_APPS_BACKGROUND_RUN_COMPLETE); // LCOV_EXCL_BR_LINE 11: Gcov constraints (because exception-handling routes are automatically generated) // NOLINT(whitespace/line_length) + } else { + SMSetState(hApp, SS_SM_APPS_START_COMPLETE); // LCOV_EXCL_BR_LINE 11: Gcov constraints (because exception-handling routes are automatically generated) // NOLINT(whitespace/line_length) + } + } + } + + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-"); + return l_eStatus; +} // End of EFrameworkunifiedStatus CSystemManager::ModuleCompleteResponse( + +/////////////////////////////////////////////////////////////////////////////// +/// \ingroup OnStartRespMonitorTimeout +/// SM maintains timer to check if all modules sent start response to him whoever requires Start. +/// This timer is common to all modules. After timeout it checks the status of every module in group map. +/// If a module sent start and does not respond, SM will initiate error event logging followed by Soft Reset +/// \param [in] +/// +/// +/// \return EFrameworkunifiedStatus +/// Success ==> eFrameworkunifiedStatusOK +/// Failure ==> Other values +/////////////////////////////////////////////////////////////////////////////// +EFrameworkunifiedStatus CSystemManager::OnStartRespMonitorTimeout(HANDLE hApp) { // LCOV_EXCL_START 6: Because the condition cannot be set + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK; + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+"); + INTERFACEUNIFIEDLOG_RECEIVED_FROM(hApp); // LCOV_EXCL_BR_LINE 15: marco defined in ns_logger_if.h // NOLINT(whitespace/line_length) + FRAMEWORKUNIFIEDLOG(ZONE_PERFORMANCE, __FUNCTION__, "from %s", FrameworkunifiedGetMsgSrc(hApp)); + + std::string l_ProcName; + BOOL l_isStartRespNotReceived = false; + + SetCmdHist("SM_TIMER_START_RESP_MONITOR_WAIT_TIMER", m_TimerCmdHist, + m_TimerHistIter, FrameworkunifiedGetMsgSrc(hApp)); + GroupLaunchMap::reverse_iterator l_grp_riter = m_MapProclaunchGrps.rbegin(); + ModuleLaunchList::reverse_iterator l_mod_riter; + + if (l_grp_riter == m_MapProclaunchGrps.rend()) { + FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "Error: Group Map is Empty"); + } else { + // scan the group map in reverse order + for (; l_grp_riter != m_MapProclaunchGrps.rend(); l_grp_riter++) { + l_mod_riter = l_grp_riter->second.modules.rbegin(); + for (; l_mod_riter != l_grp_riter->second.modules.rend(); l_mod_riter++) { + // if a module sent start and not received response from module SM wait for "ModuleStartRespTimeout" + // and initiated error event + // logging followed by soft reset + + if (l_mod_riter->is_start_required) { + if (l_mod_riter->IsModuleState(MODULE_STATE_START_SENT)) { + FRAMEWORKUNIFIEDLOG(ZONE_WARN, __FUNCTION__, + " Module [%s] did not respond(%s) to SM in allocated time [%d] sec", + l_mod_riter->name.c_str(), + l_mod_riter->ModuleStateStr().c_str(), + m_SMConfig.MCConfig.ModuleStartRespTimeOutSec); + l_isStartRespNotReceived = true; + l_ProcName.assign(l_mod_riter->name); + } + } + } + } + } + + if (true == l_isStartRespNotReceived) { + char l_cFormat[] = " Error. Module '%s' start response timeout."; + char l_cBuf[sizeof(l_cFormat) + MAX_NAME_SIZE_APP]; + snprintf(l_cBuf, sizeof(l_cBuf), l_cFormat, l_ProcName.c_str()); + TEXT(__FUNCTION__, l_cBuf); // LCOV_EXCL_BR_LINE 15: marco defined in ns_logger_if.h // NOLINT(whitespace/line_length) + FRAMEWORKUNIFIEDLOG(ZONE_PERFORMANCE, __FUNCTION__, l_cBuf); + + SMLoggingInfo l_loggingInfo; + l_loggingInfo.resetReason = e_SS_SM_CPU_RESET_REASON_GENERIC_ERR; + + // initate error event logging + l_eStatus = ErrorEventEnqueue(hApp, eErrorEventTypeStartRespFailed, + l_ProcName, eErrorEventResetTypeHard, l_loggingInfo); + FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, " Error: StartRespFailed %s", l_ProcName.c_str()); + fprintf(stderr, "SS_SysManager/%s/Error: StartRespFailed %s\n", + __FUNCTION__, l_ProcName.c_str()); + LOG_ERROR_REC_HIST_IF_ERRORED(l_eStatus, // LCOV_EXCL_BR_LINE 15: marco defined in ss_system_manager.h // NOLINT(whitespace/line_length) + "ErrorEventEnqueue(eErrorEventTypeStartRespFailed)"); // LCOV_EXCL_BR_LINE 15: marco defined in ss_system_manager.h // NOLINT(whitespace/line_length) + } else { + FRAMEWORKUNIFIEDLOG(ZONE_PERFORMANCE, __FUNCTION__, + " All modules returned Start Response."); + + l_eStatus = FrameworkunifiedSendChild(hApp, m_hHeartbeatThread.m_ThreadHdl, + SS_HEARTBEAT_AVAIL_CHECK_REQ, 0, NULL); + SS_ASERT(l_eStatus == eFrameworkunifiedStatusOK); // LCOV_EXCL_BR_LINE 15: marco defined in ss_templates.h // NOLINT(whitespace/line_length) + } + + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-"); + return l_eStatus; +} // End of EFrameworkunifiedStatus CSystemManager::OnStartRespMonitorTimeout(HANDLE hApp) +// LCOV_EXCL_STOP + +/////////////////////////////////////////////////////////////////////////////// +/// \ingroup OnShutdownCompleteMonitorTimeout +/// SM maintains timer to check if all modules sent start response to him whoever requires Start. +/// This timer is common to all modules. After timeout it checks the status of every module in group map. +/// If a module sent start and does not respond, SM will initiate error event logging followed by Soft Reset +/// \param [in] +/// +/// +/// \return EFrameworkunifiedStatus +/// Success ==> eFrameworkunifiedStatusOK +/// Failure ==> Other values +/////////////////////////////////////////////////////////////////////////////// +EFrameworkunifiedStatus CSystemManager::OnShutdownCompleteMonitorTimeout(HANDLE hApp) { + EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK; + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+"); + INTERFACEUNIFIEDLOG_RECEIVED_FROM(hApp); // LCOV_EXCL_BR_LINE 15: marco defined in ns_logger_if.h // NOLINT(whitespace/line_length) + + FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "Error: Reset Timeout"); + + l_eStatus = SecureChipOff(); + if (eFrameworkunifiedStatusOK != l_eStatus) { + FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "Error: SecureChipOff Failed"); + } + + m_ResetFactor = PSM_FACTOR_AGL_WITH_HISTORY; + + l_eStatus = perform_force_reset(hApp); + + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-"); + return l_eStatus; +} // End of EFrameworkunifiedStatus CSystemManager::OnShutdownCompleteMonitorTimeout(HANDLE hApp) + +/////////////////////////////////////////////////////////////////////////////// +/// \ingroup start_all_modules_of_group +/// Send START to all modules of the given group +/// +/// \param [in] +/// +/// +/// \return EFrameworkunifiedStatus +/// Success ==> eFrameworkunifiedStatusOK +/// Failure ==> Other values +/////////////////////////////////////////////////////////////////////////////// +EFrameworkunifiedStatus CSystemManager::start_all_modules_of_group(HANDLE hApp, UI_32 f_ui32GroupNumber) { + EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK; + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+"); + + GroupLaunchMapIter l_GroupIterator = m_MapProclaunchGrps.find( + f_ui32GroupNumber); + if (l_GroupIterator == m_MapProclaunchGrps.end()) { // LCOV_EXCL_BR_LINE 6: Because the condition cannot be set + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + FRAMEWORKUNIFIEDLOG(ZONE_ERR, + __FUNCTION__ + , " Error: Group %d not found; 'm_MapProclaunchGrps' is empty", + f_ui32GroupNumber); + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + l_eStatus = eFrameworkunifiedStatusInvldParam; // LCOV_EXCL_LINE 6: Because the condition cannot be set + } else { + T_SS_SM_START_DataStructType f_startupData(m_StartUpReason, + m_PowerType_to_SSBoolEnumMap[m_Wake.powerupType], + m_DataResetMode, m_startUpConfirmationMsg.securityStatus, + m_startUpConfirmationMsg.wakeupType, m_DramBackupStatus, + m_ResetStatus, m_ResetCount); + + UI_32 l_numModulesMessaged = 0; + FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__, + " Attempting to send Start Requests to Group %d/'%s'", + f_ui32GroupNumber, l_GroupIterator->second.name.c_str()); + + for (ModuleLaunchListIter l_ModuleListIterator = + l_GroupIterator->second.modules.begin(); + l_ModuleListIterator != l_GroupIterator->second.modules.end(); + l_ModuleListIterator++) { + // + // Every branch below must ZONE_INFO log how it dispenses w/ + // the module. + // Note: ModuleLaunchParams::SetModuleState() performs that + // ZONE_INFO logging internally. + if (!l_ModuleListIterator->is_start_required) { + if (FRAMEWORKUNIFIED_NS_NPSERVICE == l_ModuleListIterator->name) { + const SMModuleState l_transition_state = InProgressStateToState(); // LCOV_EXCL_BR_LINE 11:Gcov constraints (because exception-handling routes are automatically generated) + l_ModuleListIterator->SetModuleState(l_transition_state); // LCOV_EXCL_BR_LINE 11:Gcov constraints (because exception-handling routes are automatically generated) + } else { + // Not an error + FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__, + " %s 'is_start_required' is False;" + " leaving state as '%s'", + l_ModuleListIterator->name.c_str(), + l_ModuleListIterator->ModuleStateStr().c_str()); + } + l_eStatus = eFrameworkunifiedStatusOK; + } else if (NULL == l_ModuleListIterator->hsession) { // LCOV_EXCL_BR_LINE 6: hsession can not be null. + l_eStatus = eFrameworkunifiedStatusOK; // Log a message. But its not a failure + FRAMEWORKUNIFIEDLOG(ZONE_WARN, __FUNCTION__, " Warning: NULL == hsession;" + " %s not connected yet", + l_ModuleListIterator->name.c_str()); + } else { + switch (l_ModuleListIterator->GetModuleState()) { // LCOV_EXCL_BR_LINE 6: As not all cases can be passed through + case MODULE_STATE_INVALID: + case MODULE_STATE_SKIPPED: + case MODULE_STATE_LAUNCH_FAILED: + // LCOV_EXCL_START 6: Because the state of the corresponding variable cannot be set + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + l_eStatus = eFrameworkunifiedStatusOK; // Log a message. But its not a failure + FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__, + " %s is %s, NOT sending system_manager protocol message", + l_ModuleListIterator->name.c_str(), + l_ModuleListIterator->ModuleStateStr().c_str()); + break; + // LCOV_EXCL_STOP + + case MODULE_STATE_START_SENT: + case MODULE_STATE_START_PRE_SENT: + case MODULE_STATE_STOP_PRE_SENT: + case MODULE_STATE_START_BACKGROUND_SENT: + case MODULE_STATE_STOP_BACKGROUND_SENT: + l_eStatus = eFrameworkunifiedStatusOK; + FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__, + " %s is %s, NOT sending system_manager protocol message", + l_ModuleListIterator->name.c_str(), + l_ModuleListIterator->ModuleStateStr().c_str()); + l_numModulesMessaged++; + break; + + case MODULE_STATE_LAUNCHING: + case MODULE_STATE_LAUNCHED: + // LCOV_EXCL_START 6: Because the state of the corresponding variable cannot be set + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + l_eStatus = eFrameworkunifiedStatusOK; // Log a message. But its not a failure + FRAMEWORKUNIFIEDLOG(ZONE_WARN, __FUNCTION__, + " %s is %s, NOT sending system_manager protocol message", + l_ModuleListIterator->name.c_str(), + l_ModuleListIterator->ModuleStateStr().c_str()); + break; + // LCOV_EXCL_STOP + + case MODULE_STATE_CONNECTED: + case MODULE_STATE_STARTED: + case MODULE_STATE_START_FAILED: + case MODULE_STATE_STOP_FAILED: + case MODULE_STATE_STOP_SENT: + case MODULE_STATE_STOPPED: + case MODULE_STATE_STARTED_PRE: + case MODULE_STATE_START_PRE_FAILED: + case MODULE_STATE_STOPPED_PRE: + case MODULE_STATE_STOP_PRE_FAILED: + case MODULE_STATE_STARTED_BACKGROUND: + case MODULE_STATE_START_BACKGROUND_FAILED: + case MODULE_STATE_STOPPED_BACKGROUND: + case MODULE_STATE_STOP_BACKGROUND_FAILED: + { + const UI_32 l_iCmd = InProgressStateToSendMsg(); // LCOV_EXCL_BR_LINE 11:Gcov constraints (because exception-handling routes are automatically generated) + if (l_iCmd != SS_SYSTEM_MANAGER_PROTOCOL_ENDING_INDEX) { // LCOV_EXCL_BR_LINE 6: Excluded due to value never returned at present + // LCOV_EXCL_BR_START 15: Excluded due to inlined functions + CALL_AND_LOG_STATUS_IF_ERRORED(l_ModuleListIterator->SendMsgAndUpdateState(l_iCmd, &f_startupData)); + // LCOV_EXCL_BR_STOP 15: Excluded due to inlined functions + l_numModulesMessaged++; + } + } + break; + // default: Don't code a 'default' here - let the compiler + // detect when the set of module_state enumerations changes - + // then the System Service's System Manager maintainer will + // automagically know to update this switch statement. + } + } + } + + if (0 == l_numModulesMessaged) { + LogGroupModulesState(f_ui32GroupNumber, " Warning: NO modules were sent system_manager protocol message"); // LCOV_EXCL_BR_LINE 11:Gcov constraints (because exception-handling routes are automatically generated) + + char l_cBuf[100]; + snprintf(l_cBuf, sizeof(l_cBuf), "ProcessGroupAsStarted(%d)", l_GroupIterator->second.id); + l_eStatus = ProcessGroupAsStarted(hApp, l_GroupIterator); + LOG_STATUS_REC_HIST_IF_ERRORED(l_eStatus, l_cBuf); // LCOV_EXCL_BR_LINE 6: Because the condition cannot be set + } else { + m_GroupLaunchTimer->StartTimer( + m_aTimerIDs[eSM_TIMER_CLIENT_START_MONITOR], + SS_CLIENT_START_MONITOR_TIMER_CONFIG, 0, 0, 0); + } + } + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-"); + return l_eStatus; +} // End of EFrameworkunifiedStatus CSystemManager::start_all_modules_of_group(HANDLE hApp, UI_32 f_ui32GroupNumber) + +/////////////////////////////////////////////////////////////////////////////// +/// \ingroup start_all_modules_of_group +/// mark the specified group as started. If there is another group to start, +/// do so, else send Start Complete Response to the Start Requester. +/// +/// \param [in] +/// +/// +/// \return EFrameworkunifiedStatus +/// Success ==> eFrameworkunifiedStatusOK +/// Failure ==> Other values +/////////////////////////////////////////////////////////////////////////////// +EFrameworkunifiedStatus CSystemManager::ProcessGroupAsStarted(HANDLE hApp, UI_32 f_groupId) { + EFrameworkunifiedStatus l_eStatus; + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+"); + + GroupLaunchMapIter l_GroupIterator = m_MapProclaunchGrps.find(f_groupId); + if (l_GroupIterator == m_MapProclaunchGrps.end()) { + FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, + " Error: Group %d not found; 'm_MapProclaunchGrps' is empty", f_groupId); + l_eStatus = eFrameworkunifiedStatusInvldParam; + } else { + l_eStatus = ProcessGroupAsStarted(hApp, l_GroupIterator); + } + + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-"); + return l_eStatus; +} // End of EFrameworkunifiedStatus CSystemManager::ProcessGroupAsStarted( HANDLE hApp, UI_32 f_groupId ) + +/////////////////////////////////////////////////////////////////////////////// +/// \ingroup start_all_modules_of_group +/// mark the specified group as started. If there is another group to start, +/// do so, else send Start Complete Response to the Start Requester. +/// +/// \param [in] +/// +/// +/// \return EFrameworkunifiedStatus +/// Success ==> eFrameworkunifiedStatusOK +/// Failure ==> Other values +/////////////////////////////////////////////////////////////////////////////// +EFrameworkunifiedStatus CSystemManager::ProcessGroupAsStarted(HANDLE hApp, + GroupLaunchMapIter f_GroupIterator) { + EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK; + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+"); + UI_32 l_groupID = m_SystemStarter.get_id(); + + + m_GroupLaunchTimer->StopTimer(m_aTimerIDs[eSM_TIMER_CLIENT_START_MONITOR]); + + FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__, + " Group %d/%s start completed, m_SystemStarter.get_id() is %d", + f_GroupIterator->second.id, f_GroupIterator->second.name.c_str(), + l_groupID); + + if (f_GroupIterator->second.id != l_groupID) { + FRAMEWORKUNIFIEDLOG(ZONE_INFO, + __FUNCTION__ + , " The just-started group ( %d/%s ) is not the current Active " + " Group ( %d ); not starting next group's modules", + f_GroupIterator->second.id, + f_GroupIterator->second.name.c_str(), l_groupID); + } else { + if ((m_SMCurrentState == SS_SM_APPS_START_IN_PROGRESS) + || (m_SMCurrentState == SS_SM_APPS_PRE_START_IN_PROGRESS) + || (m_SMCurrentState == SS_SM_APPS_BACKGROUND_START_IN_PROGRESS)) { + // check if WakeUp Level has been achieved + if (m_SystemStarter.is_end() == FALSE) { + // Start modules from next group + l_groupID = m_SystemStarter.advance_id(); // LCOV_EXCL_BR_LINE 11:Gcov constraints (because exception-handling routes are automatically generated) + char l_cBuf[100] = {0}; + snprintf(l_cBuf, sizeof(l_cBuf), "start_all_modules_of_group(%u)", l_groupID); + l_eStatus = start_all_modules_of_group(hApp, l_groupID); // LCOV_EXCL_BR_LINE 11:Gcov constraints (because exception-handling routes are automatically generated) + LOG_STATUS_REC_HIST_IF_ERRORED(l_eStatus, l_cBuf); // LCOV_EXCL_BR_LINE 6: Because the condition cannot be set + } + } else if ((m_SMCurrentState == SS_SM_APPS_PRE_STOP_IN_PROGRESS) + || (m_SMCurrentState == SS_SM_APPS_BACKGROUND_STOP_IN_PROGRESS)) { + if (m_SystemStarter.is_begin() == FALSE) { + // Stop modules from next group + l_groupID = m_SystemStarter.decrement_id(); // LCOV_EXCL_BR_LINE 11:Gcov constraints (because exception-handling routes are automatically generated) + char l_cBuf[100] = {0}; + snprintf(l_cBuf, sizeof(l_cBuf), "stop_all_modules_of_group(%u)", l_groupID); + l_eStatus = start_all_modules_of_group(hApp, l_groupID); // LCOV_EXCL_BR_LINE 11:Gcov constraints (because exception-handling routes are automatically generated) + LOG_STATUS_REC_HIST_IF_ERRORED(l_eStatus, l_cBuf); // LCOV_EXCL_BR_LINE 6: Because the condition cannot be set + } + } else { + // MISRA C++-2008 Rule 6-4-2 + // NOP + } + } + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-"); + return l_eStatus; +} // End of EFrameworkunifiedStatus CSystemManager::ProcessGroupAsStarted( GroupLaunchMapIter f_GroupIterator ) + +/////////////////////////////////////////////////////////////////////////////// +/// \ingroup calculate_max_shutdown_time +/// Calculate maximum shutdown time of apps critical to shutdown +/// from the launch group map +/// +/// \param [in] +/// +/// \return UI_32 +/// Max Value of critical shutdown apps shutdown time +/////////////////////////////////////////////////////////////////////////////// +UI_32 CSystemManager::calculate_max_shutdown_time() { + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+"); + UI_32 l_MaxShutdownTimeValue = 0; + std::string moduleName; + + GroupLaunchMapIter l_GroupIterator = m_MapProclaunchGrps.begin(); + for (; l_GroupIterator != m_MapProclaunchGrps.end(); l_GroupIterator++) { + ModuleLaunchListIter l_ModuleListIterator = + l_GroupIterator->second.modules.begin(); + for (; l_ModuleListIterator != l_GroupIterator->second.modules.end(); + l_ModuleListIterator++) { + if (l_ModuleListIterator->shutdown_critical) { + if (l_MaxShutdownTimeValue < l_ModuleListIterator->shutdown_wait_time) { + moduleName = l_ModuleListIterator->name; + l_MaxShutdownTimeValue = l_ModuleListIterator->shutdown_wait_time; + } + } + } + } + FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__, " Max time: Module %s, time %d s", + moduleName.c_str(), l_MaxShutdownTimeValue); + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-"); + return l_MaxShutdownTimeValue; +} + +/////////////////////////////////////////////////////////////////////////////// +/// \ingroup OnShutdownModulesRequest +/// Send Shutdown to all modules in reverse order of group +/// +/// \param [in] +/// +/// \return EFrameworkunifiedStatus +/// Success ==> eFrameworkunifiedStatusOK +/// Failure ==> Other values +/////////////////////////////////////////////////////////////////////////////// +EFrameworkunifiedStatus CSystemManager::OnShutdownModulesRequest(HANDLE hApp) { + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+"); + EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK; + + FRAMEWORKUNIFIEDLOG(ZONE_STATE, __FUNCTION__, + " Received from %s, m_SystemStarter.get_id() is %d", + FrameworkunifiedGetMsgSrc(hApp) + , m_SystemStarter.get_id()); + + FRAMEWORKUNIFIEDLOG(ZONE_PERFORMANCE, __FUNCTION__, "m_SystemStarter.get_id() is %d", m_SystemStarter.get_id()); + + SetCmdHist("SS_SM_SHUTDOWN_MODULES", m__CWORD56_CmdHist, m__CWORD56_HistIter, FrameworkunifiedGetMsgSrc(hApp)); // LCOV_EXCL_BR_LINE 11:unexpected branch // NOLINT(whitespace/line_length) + + Pwr_ServiceSetInterface l_tServiceSetIf; + // ReadMsg(): * + // Check hApp ptr, msg size, msg reception, read msg if all ok. * + if (eFrameworkunifiedStatusOK != (l_eStatus = ReadMsg < Pwr_ServiceSetInterface > (hApp, l_tServiceSetIf))) { // LCOV_EXCL_BR_LINE 4: nsfw error + // LCOV_EXCL_START 4: nsfw error + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + LOG_ERROR("ReadMsg()"); // LCOV_EXCL_BR_LINE 15: marco defined in ss_templates.h // NOLINT(whitespace/line_length) + // LCOV_EXCL_STOP + } else { + BOOL isImmShutdown = FALSE; + + // If the Shutdown is not completed after the Shutdown is requested, it is forcibly reset. + m_GroupLaunchTimer->StartTimer( + m_aTimerIDs[eSM_TIMER_SHUTDOWN_COMPLETE_MONITOR], + SM_SHUTDOWN_COMPLETE_MONITOR_TIMEOUT, 0, 0, 0); + + if (m_isImmResetReq) { + FRAMEWORKUNIFIEDLOG(ZONE_STATE, __FUNCTION__, " ImmReset"); + isImmShutdown = TRUE; + } + + switch (l_tServiceSetIf.data.shutdownRequestMsg.lastUserMode) { + case epsumINVALID: + FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, + " Error: shutdownRequestMsg.lastUserMode == epsumINVALID"); + l_eStatus = eFrameworkunifiedStatusInvldParam; + break; + + case epsumOFF: + case epsumON: { + switch (m_SMCurrentState) { + case SS_SM_READY_TO_LAUNCH_APP: + case SS_SM_APPS_LAUNCH_IN_PROGRESS: + case SS_SM_APPS_LAUNCHED_READY_TO_START: + isImmShutdown = TRUE; + case SS_SM_APPS_START_COMPLETE: + case SS_SM_APPS_START_IN_PROGRESS: + case SS_SM_APPS_PRE_START_IN_PROGRESS: + case SS_SM_APPS_PRE_STOP_IN_PROGRESS: + case SS_SM_APPS_PRE_RUN_COMPLETE: + case SS_SM_APPS_BACKGROUND_START_IN_PROGRESS: + case SS_SM_APPS_BACKGROUND_STOP_IN_PROGRESS: + case SS_SM_APPS_BACKGROUND_RUN_COMPLETE: + + if (l_tServiceSetIf.data.shutdownRequestMsg.shutdownTrigger == + epssdmsdtIGN_OFF) { + m_ResetCount = 0; + if (PowerHalSetResetInfo(AGL_RESET_COUNTER, m_ResetCount)) { // LCOV_EXCL_BR_LINE 11:Gcov constraints (because exception-handling routes are automatically generated) + FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, + "Could not back up m_ResetCount(%lu) to power_hal", m_ResetCount); + } + + if (PowerHalSetResetInfo(AGL_ERRLOG_COUNTER, 0)) { // LCOV_EXCL_BR_LINE 11:Gcov constraints (because exception-handling routes are automatically generated) + FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, + "Could not reset AGL_ERRLOG_COUNTER"); + } + } + if (!m_isPrevErrEventCompleted + || ((!((m_SMCurrentState == SS_SM_APPS_START_COMPLETE) + || (m_SMCurrentState == SS_SM_APPS_PRE_RUN_COMPLETE) + || (m_SMCurrentState == SS_SM_APPS_BACKGROUND_RUN_COMPLETE))) + && (l_tServiceSetIf.data.shutdownRequestMsg.shutdownTrigger + == epssdmsdtIGN_OFF + || l_tServiceSetIf.data.shutdownRequestMsg.shutdownTrigger + == epssdmsdtNORMAL_RESET))) { + FRAMEWORKUNIFIEDLOG(ZONE_STATE, __FUNCTION__, "shutdown pending"); + if (!m_dqDeferMsg.empty()) { + SS_ASERT(0); // LCOV_EXCL_BR_LINE 15: marco defined in ss_templates.h // NOLINT(whitespace/line_length) + } else { + SM_POWER_EVENT_INFO deferMsg(SS_SM_SHUTDOWN_MODULES, l_tServiceSetIf); + m_dqDeferMsg.push(deferMsg); + } + } else { + // The shutdownTrigger has already been validated by + // Power::OnShutdownRequestMsg() + m_shutdownTrigger = l_tServiceSetIf.data.shutdownRequestMsg.shutdownTrigger; + m_lastUserMode = l_tServiceSetIf.data.shutdownRequestMsg.lastUserMode; + + // Notify services ShutDownTrigger the FrameworkunifiedOnStop, if dataResetMode is configured + // When using FastSleep, be aware that it may be overwritten here + switch (m_DataResetMode) { + case e_SS_SM_DATA_RESET_MODE_FACTORY: + m_shutdownTrigger = epssdmsdtFACTORY_DATA_RESET; + break; + case e_SS_SM_DATA_RESET_MODE_USER: + m_shutdownTrigger = epssdmsdtUSER_DATA_RESET; + break; + default: + break; + } + + if (isImmShutdown) { + m_GroupLaunchTimer->StopTimer(m_aTimerIDs[eSM_TIMER_GROUP_LAUNCH_WAIT_TIMER]); + + // Do not use m_shutdownTrigger because it is updated on DataReset + switch (l_tServiceSetIf.data.shutdownRequestMsg.shutdownTrigger) { + case epssdmsdtGENERIC_ERROR_RESET: + case epssdmsdtFATAL_ERROR_RESET: + CALL_AND_LOG_STATUS((*m_pfStopCompleteHandler)(hApp)); // LCOV_EXCL_BR_LINE 15: marco defined in ss_templates.h // NOLINT(whitespace/line_length) + break; + default: + FRAMEWORKUNIFIEDLOG(ZONE_WARN, __FUNCTION__, + " Warning: Received a Shutdown command while in " + "the '%s' state - returning Shutdown " + "Response msg now", + GetStr(m_SMCurrentState).c_str()); + + CALL_AND_LOG_STATUS(SendShutdownResponseMessage(hApp)); // LCOV_EXCL_BR_LINE 15: marco defined in ss_templates.h // NOLINT(whitespace/line_length) + break; + } + + } else { + InitiateAllGroupsShutdown(hApp); + } + } + break; + + case SS_SM_APPS_STOPPING_AT__CWORD56__REQ: + case SS_SM_APPS_STOPPING_AT_INTERNAL_REQ: + case SS_SM_WAITING_FOR_CRITICAL_APPS_AT__CWORD56__REQ: + case SS_SM_WAITING_FOR_CRITICAL_APPS_AT_INTERNAL_REQ: + FRAMEWORKUNIFIEDLOG(ZONE_WARN, __FUNCTION__, + " Warning: Received a Shutdown command while already in " + "the '%s' state !!!", + GetStr(m_SMCurrentState).c_str()); + break; + } // End switch ( m_SMCurrentState ) + break; + } // End case epsumOFF | epsumON + } // End switch (m_lastUserMode ) + } + + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-"); + return l_eStatus; +} // End of EFrameworkunifiedStatus CSystemManager::OnShutdownModulesRequest( HANDLE hApp ) + +/////////////////////////////////////////////////////////////////////////////// +/// \ingroup SendSystemModeInfoResponse +/// send SystemModeInfo to +/// _CWORD56_ ( via Power Service-> PSMShadow ) as an IPC 'Start Notification' +/// message, informing _CWORD56_ of the startup state of the _CWORD102_. +/// +/// \param [in] HANDLE hApp +/// +/// \return EFrameworkunifiedStatus +/// Success ==> eFrameworkunifiedStatusOK +/// Failure ==> Other values +/////////////////////////////////////////////////////////////////////////////// +EFrameworkunifiedStatus CSystemManager::SendSystemModeInfoResponse(HANDLE hApp, EPWR_STARTUP_STAGE_TYPE f_startupStage) { + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+"); + EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK; + SystemModeInfo l_SystemModeInfo; + + memcpy(&l_SystemModeInfo, &m_SystemModeInfo, sizeof(l_SystemModeInfo)); + + FRAMEWORKUNIFIEDLOG(ZONE_STATE, __FUNCTION__, "stage:%d", f_startupStage); + l_SystemModeInfo.startupStage = f_startupStage; + + l_eStatus = FrameworkunifiedSendMsg(m_hPowerServiceSession, SS_SM_SYSTEM_MODE_INFO_RSPN, + sizeof(l_SystemModeInfo), (PVOID) & l_SystemModeInfo); + + if (eFrameworkunifiedStatusOK != l_eStatus) { // LCOV_EXCL_BR_LINE 4: NSFW error case. + FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, + " Error: SendSystemModeInfoResponse(%s) errored: 0x%X", + GetStr(l_SystemModeInfo.startupStage).c_str(), l_eStatus); + } else { + // LCOV_EXCL_START 4: NSFW error case. + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__, + " SendSystemModeInfoResponse(%s) successful", + GetStr(l_SystemModeInfo.startupStage).c_str()); + // LCOV_EXCL_STOP + } + + LOG_STATUS(l_eStatus, "FrameworkunifiedSendMsg(SS_SM_SYSTEM_MODE_INFO_RSPN)"); // LCOV_EXCL_BR_LINE 15: marco defined in ss_templates.h // NOLINT(whitespace/line_length) + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-"); + return l_eStatus; +} // End of EFrameworkunifiedStatus CSystemManager::SendSystemModeInfoResponse( HANDLE hApp ) + +/////////////////////////////////////////////////////////////////////////////// +/// \ingroup OnSystemModeInfoRequest +/// Handle System Mode Info request. Send System Mode Info read from NVM +/// +/// \param [in] HANDLE hApp +/// +/// \return EFrameworkunifiedStatus +/// Success ==> eFrameworkunifiedStatusOK +/// Failure ==> Other values +/////////////////////////////////////////////////////////////////////////////// +EFrameworkunifiedStatus CSystemManager::OnSystemModeInfoRequest(HANDLE hApp) { + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+"); + EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK; + INTERFACEUNIFIEDLOG_RECEIVED_FROM(hApp); // LCOV_EXCL_BR_LINE 15: marco defined in ns_logger_if.h // NOLINT(whitespace/line_length) + FRAMEWORKUNIFIEDLOG(ZONE_PERFORMANCE, __FUNCTION__, "from %s", FrameworkunifiedGetMsgSrc(hApp)); + m_isRcvModeInfo = TRUE; + + SetCmdHist("SS_SM_SYSTEM_MODE_INFO_REQ", m__CWORD56_CmdHist, m__CWORD56_HistIter, FrameworkunifiedGetMsgSrc(hApp)); + + if (m_SystemModeInfo.startupStage == epssusfINVALID) { + // Transitioning to SYSTEM_SERVICES_STARTED if startupStage == INVALID + m_SystemModeInfo.startupStage = epssusSYSTEM_SERVICES_STARTED; + } + + l_eStatus = SendSystemModeInfoResponse(hApp, epssusSYSTEM_SERVICES_STARTED); + LOG_STATUS(l_eStatus, "SendSystemModeInfoResponse()"); // LCOV_EXCL_BR_LINE 15: marco defined in ss_templates.h // NOLINT(whitespace/line_length) + + if (TRUE == m_isRstPending) { + ESMCpuResetReason l_resetReason = m_rstPendingInfo.resetReason; + std::string l_messageStr = m_rstPendingInfo.messageStr; + + m_isRstPending = FALSE; + m_rstPendingInfo.resetReason = e_SS_SM_CPU_RESET_REASON_INVALID; + memset(m_rstPendingInfo.messageStr, 0, sizeof(m_rstPendingInfo.messageStr)); + + l_eStatus = PerformCpuReset(hApp, l_resetReason, l_messageStr); + LOG_STATUS(l_eStatus, "PerformCpuReset()"); // LCOV_EXCL_BR_LINE 6: Because it is executed only once and cannot see all branches + } + + if (m_SystemModeInfo.startupStage == epssusALL_SERVICES_LAUNCHED) { + // If startupStage == ALL_SERVICES_LAUNCHED + // Notify here because Launch of all SVCs is completed first. + l_eStatus = SendSystemModeInfoResponse(hApp, epssusALL_SERVICES_LAUNCHED); + LOG_STATUS(l_eStatus, "SendSystemModeInfoResponse()"); // LCOV_EXCL_BR_LINE 15: marco defined in ss_templates.h // NOLINT(whitespace/line_length) + } + + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-"); + return l_eStatus; +} // End of EFrameworkunifiedStatus CSystemManager::OnSystemModeInfoRequest( HANDLE hApp ) + +/////////////////////////////////////////////////////////////////////////////// +/// \ingroup OnInitCompReportCallback +/// Handle InitComp report. +/// +/// \param [in] HANDLE hApp +/// +/// \return EFrameworkunifiedStatus +/// Success ==> eFrameworkunifiedStatusOK +/// Failure ==> Other values +/////////////////////////////////////////////////////////////////////////////// +EFrameworkunifiedStatus CSystemManager::OnInitCompReportCallback(HANDLE hApp) { + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+"); + EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK; + INTERFACEUNIFIEDLOG_RECEIVED_FROM(hApp); // LCOV_EXCL_BR_LINE 15: marco defined in ns_logger_if.h // NOLINT(whitespace/line_length) + FRAMEWORKUNIFIEDLOG(ZONE_PERFORMANCE, __FUNCTION__, "from %s", FrameworkunifiedGetMsgSrc(hApp)); + + SetCmdHist("SS_SM_INITCOMP_REP", m__CWORD56_CmdHist, m__CWORD56_HistIter, FrameworkunifiedGetMsgSrc(hApp)); + + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-"); + return l_eStatus; +} // End of EFrameworkunifiedStatus CSystemManager::OnInitCompReportCallback( HANDLE hApp ) + +/////////////////////////////////////////////////////////////////////////////// +/// \ingroup have_all_services_start_completed +/// check if state of all services is MODULE_STATE_STARTED +/// +/// \param [in] +/// +/// +/// \return BOOL +/// Success ==> TRUE +/// Failure ==> FALSE +/////////////////////////////////////////////////////////////////////////////// +BOOL CSystemManager::have_all_services_start_completed(const SMModuleState f_moduleState) { + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+"); + BOOL bIsStartCompleted = TRUE; + SMModuleState l_failedState = MODULE_STATE_INVALID; + + switch (f_moduleState) { + case MODULE_STATE_STARTED: + l_failedState = MODULE_STATE_START_FAILED; + break; + case MODULE_STATE_STARTED_PRE: + l_failedState = MODULE_STATE_START_PRE_FAILED; + break; + case MODULE_STATE_STOPPED_PRE: + l_failedState = MODULE_STATE_STOP_PRE_FAILED; + break; + case MODULE_STATE_STARTED_BACKGROUND: + l_failedState = MODULE_STATE_START_BACKGROUND_FAILED; + break; + case MODULE_STATE_STOPPED_BACKGROUND: + l_failedState = MODULE_STATE_STOP_BACKGROUND_FAILED; + break; + default: + bIsStartCompleted = FALSE; + break; + } + if (l_failedState != MODULE_STATE_INVALID) { + GroupLaunchMapIter l_GroupIterator = m_MapProclaunchGrps.begin(); + for (; l_GroupIterator != m_MapProclaunchGrps.end(); l_GroupIterator++) { + ModuleLaunchListIter l_ModuleListIterator = l_GroupIterator->second.modules.begin(); + for (; l_ModuleListIterator != l_GroupIterator->second.modules.end(); l_ModuleListIterator++) { + if ((l_ModuleListIterator->is_start_required == TRUE) + && ((l_ModuleListIterator->IsModuleState(f_moduleState) == FALSE) // LCOV_EXCL_BR_LINE 11:Gcov constraints (because exception-handling routes are automatically generated) + && (l_ModuleListIterator->IsModuleState(MODULE_STATE_SKIPPED) == FALSE) // LCOV_EXCL_BR_LINE 11:Gcov constraints (because exception-handling routes are automatically generated) + && (l_ModuleListIterator->IsModuleState(l_failedState) == FALSE))) { // LCOV_EXCL_BR_LINE 11:Gcov constraints (because exception-handling routes are automatically generated) + // Allow _SKIPPED/START_FAILED for StartRespMonitor conditions + bIsStartCompleted = FALSE; + break; + } + } + } + } + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-"); + return bIsStartCompleted; +} + +/////////////////////////////////////////////////////////////////////////////// +/// \ingroup is_critical_service_stopped +/// +/// +/// \param [in] +/// +/// +/// \return BOOL +/// Success ==> TRUE +/// Failure ==> FALSE +/////////////////////////////////////////////////////////////////////////////// +BOOL CSystemManager::is_service_shutdown_ready(ModuleLaunchListIter &modIte) { + if (((modIte->shutdown_critical && modIte->is_start_required) + || (modIte->name == FRAMEWORKUNIFIED_NS_NPSERVICE)) + && modIte->IsModuleState(MODULE_STATE_STOPPED) == FALSE) { + // Not shutdown_ready if NPP or shutdown_critical services are not STOPPED. + return FALSE; + } + return TRUE; +} + +/////////////////////////////////////////////////////////////////////////////// +/// \ingroup have_critical_services_stopped +/// check if state of all critical services is MODULE_STATE_STOPPED +/// +/// \param [in] +/// +/// +/// \return BOOL +/// Success ==> TRUE +/// Failure ==> FALSE +/////////////////////////////////////////////////////////////////////////////// +BOOL CSystemManager::have_critical_services_stopped() { + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+"); + uint numStoppingModules = 0; + + GroupLaunchMapIter l_GroupIterator = m_MapProclaunchGrps.begin(); + for (; l_GroupIterator != m_MapProclaunchGrps.end(); l_GroupIterator++) { + ModuleLaunchListIter l_ModuleListIterator = l_GroupIterator->second.modules.begin(); + for (; l_ModuleListIterator != l_GroupIterator->second.modules.end(); l_ModuleListIterator++) { + if (l_ModuleListIterator->IsModuleState(MODULE_STATE_STOP_SENT) + && l_ModuleListIterator->shutdown_critical) { + numStoppingModules++; + } + } + } + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-"); + return (numStoppingModules == 0); +} + +/////////////////////////////////////////////////////////////////////////////// +/// \ingroup perform_force_reset +/// +/// +/// \param [in] +/// +/// +/// \return EFrameworkunifiedStatus +/// Success ==> eFrameworkunifiedStatusOK +/// Failure ==> Other values +/////////////////////////////////////////////////////////////////////////////// +EFrameworkunifiedStatus CSystemManager::perform_force_reset(HANDLE hApp) { + EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK; + FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "+"); + + // Since initialization must be performed by the PSMs during FactReset, do not NaviDet them as much as possible. + if (e_SS_SM_DATA_RESET_MODE_FACTORY == m_DataResetMode) { + fprintf(stderr, + "SS_SysManager/%s/NO NAVIDET!! but SendShutdownComp for FactReset\n", __FUNCTION__); + FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, + "NO NAVIDET!! but SendShutdownComp for FactReset"); + CALL_AND_LOG_STATUS(send_shutdown_complete_response(hApp)); // LCOV_EXCL_BR_LINE 15: marco defined in ss_templates.h // NOLINT(whitespace/line_length) + sleep(60); + } else if (access("/nv/BS/ss/system_manager/rwdata/ss_debug", F_OK) == 0) { + fprintf(stderr, "SS_SysManager/%s/NO NAVIDET!! but SendShutdownComp\n", __FUNCTION__); + FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "NO NAVIDET!! but SendShutdownComp"); + CALL_AND_LOG_STATUS(send_shutdown_complete_response(hApp)); // LCOV_EXCL_BR_LINE 15: marco defined in ss_templates.h // NOLINT(whitespace/line_length) + sleep(60); + } + + fflush(stderr); + usleep(100 * 1000); + + if (0 == PsmNaviResetPower(hApp, m_ResetFactor)) { // LCOV_EXCL_BR_LINE 200: power_hal if, can not to be error. + SS_ASERT_ERRNO(0); // LCOV_EXCL_BR_LINE 15: marco defined in ss_templates.h // NOLINT(whitespace/line_length) + } else { + usleep(300 * 1000); + fprintf(stderr, "SS_SysManager/%s/Error: Not Reset !!!\n", __FUNCTION__); + l_eStatus = eFrameworkunifiedStatusFail; + } + + send_shutdown_complete_response(hApp); // Try to NAVI_RESET even if ignored + + FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "-"); + return l_eStatus; +} + +/////////////////////////////////////////////////////////////////////////////// + +/////////////////////////////////////////////////////////////////////////////// +/// \ingroup send_shutdown_complete_response +/// +/// +/// \param [in] +/// +/// +/// \return EFrameworkunifiedStatus +/// Success ==> eFrameworkunifiedStatusOK +/// Failure ==> Other values +/////////////////////////////////////////////////////////////////////////////// +EFrameworkunifiedStatus CSystemManager::send_shutdown_complete_response(HANDLE hApp) { + EFrameworkunifiedStatus l_eStatus; + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+"); + + CALL_AND_LOG_STATUS(ResetModulesStateToConnected(hApp)); // LCOV_EXCL_BR_LINE 15: marco defined in ss_templates.h // NOLINT(whitespace/line_length) + + SMSetState(hApp, SS_SM_APPS_LAUNCHED_READY_TO_START); + // m_ActiveGroupId = SS_SM_INITIAL_GROUP; + + // all the modules have stopped, send Shutdown Response to Power Service + FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__, + " All critical services have stopped, Active Group ID is now %d", + m_SystemStarter.get_id()); +#if 1 + CALL_AND_LOG_STATUS(SendShutdownResponseMessage(hApp)); // LCOV_EXCL_BR_LINE 15: marco defined in ss_templates.h // NOLINT(whitespace/line_length) +#else + // + // Normal, production flow is to call SendShutdownResponseMessage(), which + // sends the Shutdown Response message to the _CWORD56_, causing the _CWORD56_ to + // remove power from the _CWORD102_ before queued-up FRAMEWORKUNIFIEDLOG messages can be // LCOV_EXCL_BR_LINE 15: marco defined in ns_logger_if.h // NOLINT(whitespace/line_length) + // processed by SS_LoggerService. + // + // Optional development flow is to NOT call SendShutdownResponseMessage(), + // thus giving the _CWORD102_ time to process its FRAMEWORKUNIFIEDLOG messages. Since this is an // LCOV_EXCL_BR_LINE 15: marco defined in ns_logger_if.h // NOLINT(whitespace/line_length) + // abnormal, 'bad' condition of NOT sending a Shutdown Response message to + // the _CWORD56_, be very obvious about this state by displaying both + // compile-time and run-time warning messages. + // +#warning NOT calling SendShutdownResponseMessage(hApp) ! + FRAMEWORKUNIFIEDLOG(ZONE_WARN, __FUNCTION__, // LCOV_EXCL_BR_LINE 15: marco defined in ns_logger_if.h // NOLINT(whitespace/line_length) + " Warning: SendShutdownResponseMessage( hApp ) " + "#def'f out; ShutdownResponse NOT sent to _CWORD56_"); +#endif + + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-"); + return l_eStatus; +} + +/////////////////////////////////////////////////////////////////////////////// +/// +/////////////////////////////////////////////////////////////////////////////// +EFrameworkunifiedStatus CSystemManager::SendShutdownResponseMessage(HANDLE hApp) { + EFrameworkunifiedStatus l_eStatus; + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+"); + l_eStatus = FrameworkunifiedSendMsg(m_hPowerServiceSession, // LCOV_EXCL_BR_LINE 15: marco defined in ns_logger_if.h // NOLINT(whitespace/line_length) + SS_SM_SHUTDOWN_MODULES_CMPL_RSPN, 0, (PVOID) NULL); // LCOV_EXCL_BR_LINE 15: marco defined in ns_logger_if.h // NOLINT(whitespace/line_length) + LOG_STATUS_REC_HIST_IF_ERRORED(l_eStatus, // LCOV_EXCL_BR_LINE 15: marco defined in ss_system_manager.h // NOLINT(whitespace/line_length) + "FrameworkunifiedSendMsg(PowerService,SS_SM_SHUTDOWN_MODULES_CMPL_RSPN)"); // LCOV_EXCL_BR_LINE 15: marco defined in ss_system_manager.h // NOLINT(whitespace/line_length) + + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-"); + return l_eStatus; +} // End of EFrameworkunifiedStatus CSystemManager::SendShutdownResponseMessage( HANDLE hApp ) + + +PsmFactorT CSystemManager::GetResetFactor(PCSTR f_module_name, BOOL f_user_reset) { + PsmFactorT l_reset_factor = PSM_FACTOR_NONE; + EFrameworkunifiedStatus l_eStatus; + ModuleLaunchListIter l_moduleIter; + l_eStatus = GetModuleIterator(f_module_name, l_moduleIter); // LCOV_EXCL_BR_LINE 11:Gcov constraints (because exception-handling routes are automatically generated) + if (eFrameworkunifiedStatusOK != l_eStatus) { + LOG_ERROR("GetModuleIterator()"); // LCOV_EXCL_BR_LINE 15: marco defined in ss_templates.h // NOLINT(whitespace/line_length) + } else { + l_reset_factor = GetResetFactor(l_moduleIter, f_user_reset); + } + return l_reset_factor; +} // End of PsmFactorT CSystemManager::GetResetFactor(PCSTR f_module_name) + + +PsmFactorT CSystemManager::GetResetFactor(const ModuleLaunchListIter f_module_iter, BOOL f_user_reset) { + PsmFactorT l_reset_factor; + if (f_module_iter->IsAGLUnit() == TRUE) { + if (f_module_iter->IsAGLResetHistoryDisable() == TRUE) { + l_reset_factor = PSM_FACTOR_AGL; + } else { + l_reset_factor = PSM_FACTOR_AGL_WITH_HISTORY; + } + } else { + if (f_module_iter->IsNonAGLResetHistoryDisable() == TRUE) { + l_reset_factor = PSM_FACTOR_TIER1; + } else { + l_reset_factor = PSM_FACTOR_TIER1_WITH_HISTORY; + } + } + + if (f_user_reset == TRUE) { + if ((l_reset_factor == PSM_FACTOR_AGL) || (l_reset_factor == PSM_FACTOR_TIER1)) { + l_reset_factor = PSM_FACTOR_USER; + } else { + l_reset_factor = PSM_FACTOR_USER_WITH_HISTORY; + } + } + return l_reset_factor; +} // End of PsmFactorT GetResetFactor(ModuleLaunchListIter & f_module_iter) +/////////////////////////////////////////////////////////////////////////////// +/// \ingroup OnClientStopMonitorTimerExpiry +/// +/// +/// \param [in] +/// +/// +/// \return EFrameworkunifiedStatus +/// Success ==> eFrameworkunifiedStatusOK +/// Failure ==> Other values +/////////////////////////////////////////////////////////////////////////////// +EFrameworkunifiedStatus CSystemManager::OnClientStopMonitorTimerExpiry(HANDLE hApp) { + EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK; + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+"); + + FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__, " Received from group %d", m_SystemStarter.get_id()); + + SetCmdHist("SM_TIMER_CLIENT_STOP_MONITOR", m_TimerCmdHist, m_TimerHistIter, FrameworkunifiedGetMsgSrc(hApp)); // LCOV_EXCL_BR_LINE 11:unexpected branch // NOLINT(whitespace/line_length) + + if ((m_SMCurrentState == SS_SM_WAITING_FOR_CRITICAL_APPS_AT__CWORD56__REQ) + || (m_SMCurrentState == SS_SM_WAITING_FOR_CRITICAL_APPS_AT_INTERNAL_REQ) + || m_SystemStarter.get_id() <= SS_SM_THIRD_GROUP) { + FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, " Error: StopCompTimeout:gid:%d", m_SystemStarter.get_id()); + fprintf(stderr, "SS_SysManager/%s/Error: StopCompTimeout:gid:%d\n", __FUNCTION__, m_SystemStarter.get_id()); + + for (GroupLaunchMapIter l_GroupIterator = m_MapProclaunchGrps.begin(); + l_GroupIterator != m_MapProclaunchGrps.end(); + l_GroupIterator++) { + for (ModuleLaunchListIter l_ModuleListIterator = l_GroupIterator->second.modules.begin(); + l_ModuleListIterator != l_GroupIterator->second.modules.end(); + l_ModuleListIterator++) { + if (l_ModuleListIterator->group_id >= m_SystemStarter.get_id() + && is_service_shutdown_ready(l_ModuleListIterator) == FALSE) { + FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, " Error: %s", l_ModuleListIterator->name.c_str()); + fprintf(stderr, "SS_SysManager/%s/Error: %s\n", __FUNCTION__, l_ModuleListIterator->name.c_str()); // LCOV_EXCL_BR_LINE 11:unexpected branch // NOLINT(whitespace/line_length) + } + } + } + + if (!m_SystemStarter.is_begin()) { + // Continue termination processing to perform BackupManager termination processing. + m_SystemStarter.decrement_id(); + check_all_groups_have_stopped(hApp); + } else { + // DEAD CODE + fprintf(stderr, "SS_SysManager/%s:SVC stop timeout\n", __FUNCTION__); + FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, " SVC stop timeout"); + l_eStatus = CallStopCompleteHandler(hApp); + LOG_STATUS_REC_HIST_IF_ERRORED(l_eStatus, "CallStopCompleteHandler( hApp )"); // LCOV_EXCL_BR_LINE 15: marco defined in ss_system_manager.h // NOLINT(whitespace/line_length) + } + } else { + // The current m_ActiveGroupId group just timed out. If possible, + // decrement it, and then see if there are more groups to send + // stop requests to. + if (!m_SystemStarter.is_begin()) { + m_SystemStarter.decrement_id(); + } + check_all_groups_have_stopped(hApp); + } + + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-"); + return l_eStatus; +} // End of EFrameworkunifiedStatus CSystemManager::OnClientStopMonitorTimerExpiry( HANDLE hApp ) + +/////////////////////////////////////////////////////////////////////////////// +/// \ingroup check_all_groups_have_stopped +/// check that all the groups has stopped +/// +/// \param [in] +/// +/// +/// \return VOID +/////////////////////////////////////////////////////////////////////////////// +VOID CSystemManager::check_all_groups_have_stopped(HANDLE hApp) { + EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK; + UI_32 l_ActiveGroupId = m_SystemStarter.get_id(); + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+"); + FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__, + " m_SystemStarter.get_id() is %d, 'm_NPPStopSent' is '%s'" + , m_SystemStarter.get_id(), GetStr(m_NPPStopSent).c_str()); + + // send stop to next group in reverse order +// FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__, " m_NPPStopSent is %s", GetStr(m_NPPStopSent).c_str()); // LCOV_EXCL_BR_LINE 15: marco defined in ns_logger_if.h // NOLINT(whitespace/line_length) + if (!m_NPPStopSent) { + l_eStatus = stop_all_modules_of_group(hApp); + if (eFrameworkunifiedStatusOK != l_eStatus) { + FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, + " Error: stop_all_modules_of_group(%d) errored: %d/'%s'", + l_ActiveGroupId, l_eStatus, GetStr(l_eStatus).c_str()); + } + } else { // (m_ActiveGroupId < SS_SM_INITIAL_GROUP) + BOOL l_bIsDetectTimeout; + + if ((l_bIsDetectTimeout = !have_critical_services_stopped())) { + // If the Critical service is not terminated even when the final GROUP is completed, DUMP the applicable service and issue NAVI_DET. + FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, " FinalCriticalCheck"); + fprintf(stderr, "SS_SysManager/%s:FinalCriticalCheck\n", __FUNCTION__); // LCOV_EXCL_BR_LINE 15: marco defined in ns_logger_if.h // NOLINT(whitespace/line_length) + + for (GroupLaunchMapIter l_GroupIterator = m_MapProclaunchGrps.begin(); + l_GroupIterator != m_MapProclaunchGrps.end(); + l_GroupIterator++) { + for (ModuleLaunchListIter l_ModuleListIterator = l_GroupIterator->second.modules.begin(); + l_ModuleListIterator != l_GroupIterator->second.modules.end(); + l_ModuleListIterator++) { + if (is_service_shutdown_ready(l_ModuleListIterator) == FALSE) { + FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, " Error: %s", + l_ModuleListIterator->name.c_str()); + fprintf(stderr, "SS_SysManager/%s/Error: %s\n", // LCOV_EXCL_BR_LINE 11:unexpected branch // NOLINT(whitespace/line_length) + __FUNCTION__, + l_ModuleListIterator->name.c_str()); // LCOV_EXCL_BR_LINE 11:unexpected branch // NOLINT(whitespace/line_length) + } + } + } + fprintf(stderr, "SS_SysManager/%s:critical service no stop\n", __FUNCTION__); + FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "critical service no stop"); + } + + CALL_AND_LOG_STATUS(CallStopCompleteHandler(hApp, l_bIsDetectTimeout)); // LCOV_EXCL_BR_LINE 15: marco defined in ss_templates.h // NOLINT(whitespace/line_length) + + // In PastModel002, there was a transition to WAITING_FOR_CRITICAL_APPS in the following processing, but in _CWORD71_, + // the transition to WAITING_FOR_CRITICAL_APPS was eliminated by revising the termination processing. + } + + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-"); + return; +} // End of VOID CSystemManager::check_all_groups_have_stopped( HANDLE hApp ) + +/////////////////////////////////////////////////////////////////////////////// +/// \ingroup MarkModuleStateStopped +/// Sets Module State to STOP COMPLETE +/// +/// \param [in] +/// +/// +/// \return EFrameworkunifiedStatus +/// Success ==> eFrameworkunifiedStatusOK +/// Failure ==> Other values +/////////////////////////////////////////////////////////////////////////////// + + +/////////////////////////////////////////////////////////////////////////////// +/// \ingroup OnNppStopComplete +/// Npp Stop Complete complete Response\Ack Handlers +/// +/// \param [in] +/// +/// +/// \return EFrameworkunifiedStatus +/// Success ==> eFrameworkunifiedStatusOK +/// Failure ==> Other values +/////////////////////////////////////////////////////////////////////////////// +EFrameworkunifiedStatus CSystemManager::OnNppStopComplete(HANDLE hApp) { + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+"); + EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK; + INTERFACEUNIFIEDLOG_RECEIVED_FROM(hApp); // LCOV_EXCL_BR_LINE 15: marco defined in ns_logger_if.h // NOLINT(whitespace/line_length) + FRAMEWORKUNIFIEDLOG(ZONE_PERFORMANCE, __FUNCTION__, "from %s", FrameworkunifiedGetMsgSrc(hApp)); + + SetCmdHist("NPS_NPP_STOP_ACK", m_SMCmdHist, m_SMHistIter, FrameworkunifiedGetMsgSrc(hApp)); // LCOV_EXCL_BR_LINE 11:unexpected branch // NOLINT(whitespace/line_length) + + char l_cBuf[100]; + snprintf(l_cBuf, sizeof(l_cBuf), "ProcessModuleStopCompleteResponse(%s)", FRAMEWORKUNIFIED_NS_NPSERVICE); + l_eStatus = ProcessModuleStopCompleteResponse(hApp, FRAMEWORKUNIFIED_NS_NPSERVICE); + LOG_STATUS_REC_HIST_IF_ERRORED(l_eStatus, l_cBuf); // LCOV_EXCL_BR_LINE 15: marco defined in ss_system_manager.h // NOLINT(whitespace/line_length) + + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-"); + return eFrameworkunifiedStatusOK; +} + +EFrameworkunifiedStatus CSystemManager::GetModuleIterator(PCSTR f_moduleName, ModuleLaunchListIter &f_moduleIter) { + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+"); + EFrameworkunifiedStatus l_eStatus; + + ModuleLaunchListIter l_moduleIter; +// static int l_numTimesEntered = 0 ; +// l_numTimesEntered++ ; +// FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__ // LCOV_EXCL_BR_LINE 15: marco defined in ns_logger_if.h // NOLINT(whitespace/line_length) +// , " NTE %d: Looking for %s" +// , l_numTimesEntered +// , f_moduleName); + + BOOL l_bIsFound = FALSE; + for (GroupLaunchMapIter l_GroupIter = m_MapProclaunchGrps.begin(); + !l_bIsFound && l_GroupIter != m_MapProclaunchGrps.end(); + l_GroupIter++) { +// FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__ // LCOV_EXCL_BR_LINE 15: marco defined in ns_logger_if.h // NOLINT(whitespace/line_length) +// , " NTE %d: Checking group %d/%s" +// , l_numTimesEntered +// , l_GroupIter->second.id +// , l_GroupIter->second.name.c_str()); + + for (l_moduleIter = l_GroupIter->second.modules.begin(); + !l_bIsFound && (l_moduleIter != l_GroupIter->second.modules.end()); + l_moduleIter++) { +// FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__ // LCOV_EXCL_BR_LINE 15: marco defined in ns_logger_if.h // NOLINT(whitespace/line_length) +// , " NTE %d: Checking PCSTR '%s' against std::string '%s': %d, %s" +// , l_numTimesEntered +// , f_moduleName +// , l_moduleIter->name.c_str() +// , strcmp(l_moduleIter->name.c_str(), f_moduleName) +// , (0 == strcmp(l_moduleIter->name.c_str(), f_moduleName) ? "True" : "False")); + + l_bIsFound = + (0 == strcmp(l_moduleIter->name.c_str(), f_moduleName)); + if (l_bIsFound) { + f_moduleIter = l_moduleIter; +// FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__, // LCOV_EXCL_BR_LINE 15: marco defined in ns_logger_if.h // NOLINT(whitespace/line_length) +//// " NTE %d:" +// " '%s' is in group %d/%s" +//// , l_numTimesEntered +// , f_moduleIter->name.c_str() +// , l_GroupIter->second.id +// , l_GroupIter->second.name.c_str()); + l_eStatus = eFrameworkunifiedStatusOK; + } + } + } + + if (!l_bIsFound) { + FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, +// " NTE %d:" + " Error: '%s' is not in group map 'm_MapProclaunchGrps'" +// , l_numTimesEntered + , f_moduleName); + if (0 != strcmp(f_moduleName, SERVICE_SYSMANAGER)) { + SysMgrConfiguration m_launchConfig; + m_launchConfig.PrintAllInfo(m_MapProclaunchGrps); + } + l_eStatus = eFrameworkunifiedStatusDbRecNotFound; + } + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-"); + return l_eStatus; +} // End of EFrameworkunifiedStatus CSystemManager::GetModuleIterator( PCSTR f_moduleName + +BOOL CSystemManager::IsGroupStarted(UI_32 f_groupID) { + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+"); + BOOL l_bIsStarted = TRUE; + + GroupLaunchMapIter l_GroupIter = m_MapProclaunchGrps.find(f_groupID); + if (l_GroupIter == m_MapProclaunchGrps.end()) { + FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, " Error: Group Map Empty; was looking for group %d", f_groupID); + } else { + ModuleLaunchListIter l_ModuleListIter = l_GroupIter->second.modules.begin(); + const SMModuleState l_dest_state = InProgressStateToState(); // LCOV_EXCL_BR_LINE 11: Gcov constraints (because exception-handling routes are automatically generated) // NOLINT(whitespace/line_length) + if (l_dest_state != MODULE_STATE_INVALID) { + for (; l_ModuleListIter != l_GroupIter->second.modules.end(); l_ModuleListIter++) { + if (((l_ModuleListIter->IsModuleState(l_dest_state) == FALSE) // LCOV_EXCL_BR_START 11:Gcov constraints (because exception-handling routes are automatically generated) + && (l_ModuleListIter->IsModuleState(MODULE_STATE_START_FAILED) == FALSE) + && (l_ModuleListIter->IsModuleState(MODULE_STATE_START_PRE_FAILED) == FALSE) + && (l_ModuleListIter->IsModuleState(MODULE_STATE_STOP_PRE_FAILED) == FALSE) + && (l_ModuleListIter->IsModuleState(MODULE_STATE_START_BACKGROUND_FAILED) == FALSE) + && (l_ModuleListIter->IsModuleState(MODULE_STATE_STOP_BACKGROUND_FAILED) == FALSE) + && (l_ModuleListIter->IsModuleState(MODULE_STATE_STOP_FAILED) == FALSE)) + // LCOV_EXCL_BR_STOP 11:Gcov constraints (because exception-handling routes are automatically generated) + || ((l_ModuleListIter->is_start_required == TRUE) + // LCOV_EXCL_START 6: Because the value cannot be stored to make the condition true + && ((l_ModuleListIter->IsModuleState(MODULE_STATE_LAUNCHING) == TRUE) + || (l_ModuleListIter->IsModuleState(MODULE_STATE_CONNECTED) == TRUE) + || (l_ModuleListIter->IsModuleState(MODULE_STATE_LAUNCHED) == TRUE)))) { + // LCOV_EXCL_STOP 6: Because the value cannot be stored to make the condition true + l_bIsStarted = FALSE; + FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__, " No: '%s' in group %d/%s is '%s'", l_ModuleListIter->name.c_str(), + l_GroupIter->second.id, l_GroupIter->second.name.c_str(), + l_ModuleListIter->ModuleStateStr().c_str()); + break; + } + } + } + } + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-"); + return l_bIsStarted; +} // End of BOOL CSystemManager::IsGroupStarted(UI_32 f_groupId) + +BOOL CSystemManager::IsGroupStopped(UI_32 f_groupID) { + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+"); + BOOL l_bIsStopped = TRUE; + ModuleLaunchListIter l_ModuleListIter; + + GroupLaunchMapIter l_GroupIter = m_MapProclaunchGrps.find(f_groupID); + if (l_GroupIter == m_MapProclaunchGrps.end()) { + FRAMEWORKUNIFIEDLOG(ZONE_WARN, __FUNCTION__, + " Warning: Group Map Empty; was looking for group %d", + f_groupID); + } else { + for (l_ModuleListIter = l_GroupIter->second.modules.begin(); + l_bIsStopped + && l_ModuleListIter != l_GroupIter->second.modules.end(); + l_ModuleListIter++) { + if (l_ModuleListIter->IsModuleState(MODULE_STATE_STOP_SENT)) { + l_bIsStopped = FALSE; + } + } + } + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-"); + return l_bIsStopped; +} // End of BOOL CSystemManager::IsGroupStopped(UI_32 f_groupId) + +/////////////////////////////////////////////////////////////////////////////// +/// \ingroup OnStopComplete +/// Shutdown complete Response\Ack Handlers +/// +/// \param [in] +/// +/// +/// \return EFrameworkunifiedStatus +/// Success ==> eFrameworkunifiedStatusOK +/// Failure ==> Other values +/////////////////////////////////////////////////////////////////////////////// +EFrameworkunifiedStatus CSystemManager::OnModuleStopCompleteResponse(HANDLE hApp) { + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+"); + EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusErrOther; + INTERFACEUNIFIEDLOG_RECEIVED_FROM(hApp); // LCOV_EXCL_BR_LINE 15: marco defined in ns_logger_if.h // NOLINT(whitespace/line_length) + + PCSTR l_moduleName = FrameworkunifiedGetMsgSrc(hApp); + + FRAMEWORKUNIFIEDLOG(ZONE_PERFORMANCE, __FUNCTION__, "from %s", l_moduleName); + SetCmdHist("SS_SM_STOP_COMPL_RSPN", m_SMCmdHist, m_SMHistIter, l_moduleName); + + char l_cBuf[100]; + snprintf(l_cBuf, sizeof(l_cBuf), "ProcessModuleStopCompleteResponse(%s)", l_moduleName); + l_eStatus = ProcessModuleStopCompleteResponse(hApp, l_moduleName); + LOG_STATUS_REC_HIST_IF_ERRORED(l_eStatus, l_cBuf); // LCOV_EXCL_BR_LINE 15: marco defined in ss_system_manager.h // NOLINT(whitespace/line_length) + + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-"); + return l_eStatus; +} // End of EFrameworkunifiedStatus CSystemManager::OnModuleStopCompleteResponse( HANDLE hApp ) + +/////////////////////////////////////////////////////////////////////////////// +/// \ingroup OnGetStartExtInfo +/// +/// \param [in] +/// +/// +/// \return EFrameworkunifiedStatus +/// Success ==> eFrameworkunifiedStatusOK +/// Failure ==> Other values +/////////////////////////////////////////////////////////////////////////////// +EFrameworkunifiedStatus CSystemManager::OnGetStartExtInfo(HANDLE hApp) { + EFrameworkunifiedStatus l_eStatus; + T_SS_SM_START_ExtDataStructType l_extInfo = { 0 }; + + SS_STATIC_ASERT(sizeof(T_SS_SM_START_ExtDataStructType) == SS_SM_START_EXT_INFO_SIZE); // LCOV_EXCL_BR_LINE 15: marco defined in ss_templates.h // NOLINT(whitespace/line_length) + + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+ "); + + SetCmdHist("SS_SM_GET_START_EXT_INFO", m_SMCmdHist, m_SMHistIter, FrameworkunifiedGetMsgSrc(hApp)); + + l_extInfo.isProgUpdated = + (m_ProgUpdateState & SS_SM_PROG_UPDATE_STATE_UPDATED) ? TRUE : FALSE; + l_extInfo.isMapUpdated = + (m_ProgUpdateState & SS_SM_PROG_UPDATE_STATE_MAP_UPDATED) ? TRUE : FALSE; // LCOV_EXCL_BR_LINE 11:unexpected branch // NOLINT(whitespace/line_length) + l_extInfo.isMapDiffUpdated = + (m_ProgUpdateState & SS_SM_PROG_UPDATE_STATE_MAPDIFF_UPDATED) ? TRUE : FALSE; // LCOV_EXCL_BR_LINE 11:unexpected branch // NOLINT(whitespace/line_length) + + ModuleLaunchListIter l_ModuleListIter; + + l_eStatus = GetModuleIterator(FrameworkunifiedGetMsgSrc(hApp), l_ModuleListIter); + if (eFrameworkunifiedStatusOK != l_eStatus) { + FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, " Error: %s not found", FrameworkunifiedGetMsgSrc(hApp)); + } else { + switch (l_ModuleListIter->relaunch_status) { + case NotRelaunched: + l_extInfo.relaunchStatus = e_SS_SM_RELAUNCH_STATUS_NONE; + break; + case RelaunchSafe: + // LCOV_EXCL_START 6: Because the applicable variable cannot be changed from the external API (only evaluated by the initial value) + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + l_extInfo.relaunchStatus = e_SS_SM_RELAUNCH_STATUS_SAFE; + break; + case RelaunchErr: + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + l_extInfo.relaunchStatus = e_SS_SM_RELAUNCH_STATUS_ERR; + break; + default: + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + SS_ASERT(0); // LCOV_EXCL_BR_LINE 15: marco defined in ss_templates.h // NOLINT(whitespace/line_length) + l_extInfo.relaunchStatus = e_SS_SM_RELAUNCH_STATUS_NONE; + break; + // LCOV_EXCL_STOP + } + } + + // Instead of sending Return Message, this function must call FrameworkunifiedSetSyncResponseData() + // because this request is sent by FrameworkunifiedInvokeSync() + l_eStatus = FrameworkunifiedSetSyncResponseData(hApp, &l_extInfo, sizeof(l_extInfo)); + LOG_STATUS_IF_ERRORED(l_eStatus, "FrameworkunifiedSetSyncResponseData()"); // LCOV_EXCL_BR_LINE 15: marco defined in ss_templates.h // NOLINT(whitespace/line_length) + + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-"); + return l_eStatus; +} // End of EFrameworkunifiedStatus CSystemManager::OnGetStartExtInfo( HANDLE hApp ) + +/////////////////////////////////////////////////////////////////////////////// +/// \ingroup OnGetStopExtInfo +/// +/// \param [in] +/// +/// +/// \return EFrameworkunifiedStatus +/// Success ==> eFrameworkunifiedStatusOK +/// Failure ==> Other values +/////////////////////////////////////////////////////////////////////////////// +EFrameworkunifiedStatus CSystemManager::OnGetStopExtInfo(HANDLE hApp) { + EFrameworkunifiedStatus l_eStatus; + T_SS_SM_STOP_ExtDataStructType l_extInfo = { 0 }; + + SS_STATIC_ASERT(sizeof(T_SS_SM_STOP_ExtDataStructType) == SS_SM_STOP_EXT_INFO_SIZE); // LCOV_EXCL_BR_LINE 15: marco defined in ss_templates.h // NOLINT(whitespace/line_length) + + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+ "); + + SetCmdHist("SS_SM_GET_STOP_EXT_INFO", m_SMCmdHist, m_SMHistIter, FrameworkunifiedGetMsgSrc(hApp)); + + l_extInfo.isProgUpdated = + (m_ProgUpdateState & SS_SM_PROG_UPDATE_STATE_UPDATED) ? TRUE : FALSE; + + // Instead of sending Return Message, this function must call FrameworkunifiedSetSyncResponseData() + // because this request is sent by FrameworkunifiedInvokeSync() + l_eStatus = FrameworkunifiedSetSyncResponseData(hApp, &l_extInfo, sizeof(l_extInfo)); + LOG_STATUS_IF_ERRORED(l_eStatus, "FrameworkunifiedSetSyncResponseData()"); // LCOV_EXCL_BR_LINE 15: marco defined in ss_templates.h // NOLINT(whitespace/line_length) + + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-"); + return l_eStatus; +} // End of EFrameworkunifiedStatus CSystemManager::OnGetStopExtInfo( HANDLE hApp ) + +/////////////////////////////////////////////////////////////////////////////// +/// \ingroup OnModuleStopCompleteNotification +/// +/// \param [in] +/// +/// +/// \return EFrameworkunifiedStatus +/// Success ==> eFrameworkunifiedStatusOK +/// Failure ==> Other values +/////////////////////////////////////////////////////////////////////////////// +EFrameworkunifiedStatus CSystemManager::OnModuleStopCompleteNotification(HANDLE hApp) { // LCOV_EXCL_START 6: Because the condition cannot be set + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + EFrameworkunifiedStatus l_eStatus; + + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+ "); + INTERFACEUNIFIEDLOG_RECEIVED_FROM(hApp); // LCOV_EXCL_BR_LINE 15: marco defined in ns_logger_if.h // NOLINT(whitespace/line_length) + FRAMEWORKUNIFIEDLOG(ZONE_PERFORMANCE, __FUNCTION__, "from %s", FrameworkunifiedGetMsgSrc(hApp)); + + ShutdownComplete l_shutdownNotif; /// \file frameworkunified_framework_types.h + // ReadMsg(): * + // Check hApp ptr, msg size, msg reception, read msg if all ok. * + // Report any errors found. * + // * + if (eFrameworkunifiedStatusOK != (l_eStatus = ReadMsg < ShutdownComplete > (hApp, l_shutdownNotif))) { + LOG_ERROR("ReadMsg()"); // LCOV_EXCL_BR_LINE 15: marco defined in ss_templates.h // NOLINT(whitespace/line_length) + } else { + PCSTR l_moduleName = l_shutdownNotif.cServiceName; + FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__, + " '%s' 'Shutdown Complete Status' is 0x%X", l_moduleName, + l_shutdownNotif.eShutdownCompleteStatus); + + char l_cBuf[100]; + snprintf(l_cBuf, sizeof(l_cBuf), + "ProcessModuleStopCompleteResponse(%s)", l_moduleName); + l_eStatus = ProcessModuleStopCompleteResponse(hApp, l_moduleName); + LOG_STATUS_REC_HIST_IF_ERRORED(l_eStatus, l_cBuf); // LCOV_EXCL_BR_LINE 15: marco defined in ss_system_manager.h // NOLINT(whitespace/line_length) + } + + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-"); + return l_eStatus; +} // End of EFrameworkunifiedStatus CSystemManager::onmodulestopcompletenotification( HANDLE hApp ) +// LCOV_EXCL_STOP + +EFrameworkunifiedStatus CSystemManager::ProcessModuleStopCompleteResponse(HANDLE hApp, PCSTR f_moduleName) { + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+"); + EFrameworkunifiedStatus l_eStatus; + + ModuleLaunchListIter l_ModuleListIter; + l_eStatus = GetModuleIterator(f_moduleName, l_ModuleListIter); + if (eFrameworkunifiedStatusOK != l_eStatus) { + FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, " Error: Module %s not found in Group Launch Map", f_moduleName); + } else { + switch (m_SMCurrentState) { + case SS_SM_READY_TO_LAUNCH_APP: + case SS_SM_APPS_LAUNCH_IN_PROGRESS: + case SS_SM_APPS_LAUNCHED_READY_TO_START: + FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, + " Error: Received from client while in " + "the '%s' state !!!", + GetStr(m_SMCurrentState).c_str()); + l_eStatus = eFrameworkunifiedStatusErrOther; + break; + + case SS_SM_APPS_STOPPING_AT__CWORD56__REQ: + case SS_SM_APPS_STOPPING_AT_INTERNAL_REQ: + case SS_SM_WAITING_FOR_CRITICAL_APPS_AT__CWORD56__REQ: + case SS_SM_WAITING_FOR_CRITICAL_APPS_AT_INTERNAL_REQ: + if (m_SystemStarter.get_id() == SS_SM_THIRD_GROUP) { + // Execute shutdown_critical services termination synchronization prior to CoreModule(backupManager termination processing + l_ModuleListIter->SetModuleState(MODULE_STATE_STOPPED); + if (have_critical_services_stopped()) { // Transition after all critical services have ended + ProcessGroupOnModuleStopResponse(hApp, m_SystemStarter.get_id()); + } + } else { + l_eStatus = ModuleCompleteResponse(hApp, l_ModuleListIter, + MODULE_STATE_STOPPED, + (SysMgrCbType3<CSystemManager, + &CSystemManager::IsGroupStopped>), + (SysMgrCbType2<CSystemManager, + &CSystemManager::ProcessGroupOnModuleStopResponse>), + "stop"); + } + break; + + case SS_SM_APPS_START_COMPLETE: + case SS_SM_APPS_START_IN_PROGRESS: + case SS_SM_APPS_PRE_RUN_COMPLETE: + case SS_SM_APPS_PRE_START_IN_PROGRESS: + case SS_SM_APPS_PRE_STOP_IN_PROGRESS: + case SS_SM_APPS_BACKGROUND_RUN_COMPLETE: + case SS_SM_APPS_BACKGROUND_START_IN_PROGRESS: + case SS_SM_APPS_BACKGROUND_STOP_IN_PROGRESS: + FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, + " Error: Received from client while in " + "the '%s' state !!!", + GetStr(m_SMCurrentState).c_str()); + l_eStatus = eFrameworkunifiedStatusErrOther; + break; + } // End switch ( m_SMCurrentState ) + } + + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-"); + return l_eStatus; +} // End of EFrameworkunifiedStatus CSystemManager::ProcessModuleStopCompleteResponse( + +EFrameworkunifiedStatus CSystemManager::ProcessGroupOnModuleStopResponse(HANDLE hApp, UI_32 f_groupID) { + EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK; + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+"); + UI_32 l_ActiveGroupId = m_SystemStarter.get_id(); + + m_GroupLaunchTimer->StopTimer(m_aTimerIDs[eSM_TIMER_CLIENT_STOP_MONITOR]); + + if (f_groupID != l_ActiveGroupId) { + FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__, + " Group %d stop complete, but m_SystemStarter.get_id() is %d", + f_groupID + // , m_ActiveGroupId); // LCOV_EXCL_BR_LINE 15: marco defined in ns_logger_if.h // NOLINT(whitespace/line_length) + , l_ActiveGroupId); + } else { + if (!m_SystemStarter.is_begin()) { + m_SystemStarter.decrement_id(); + } + check_all_groups_have_stopped(hApp); + } + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-"); + return l_eStatus; +} // End of EFrameworkunifiedStatus CSystemManager::ProcessGroupOnModuleStopResponse( HANDLE hApp + +/////////////////////////////////////////////////////////////////////////////// +/// \ingroup stop_all_modules_of_group +/// Send SS_SM_STOP to all modules of the given group +/// +/// \param [in] +/// +/// +/// \return VOID +/////////////////////////////////////////////////////////////////////////////// +EFrameworkunifiedStatus CSystemManager::stop_all_modules_of_group(HANDLE hApp) { + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+"); + EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK; + ModuleLaunchList::reverse_iterator l_revIter; + + UI_32 l_uiMaxGroupWaitTime_sec = 0; + UI_32 l_uiMaxGroupWaitTime_msec = 0; + UI_32 l_uiModuleWaitTime = 0; + + // GroupLaunchMapIter l_GroupIterator = m_MapProclaunchGrps.find(m_ActiveGroupId); + GroupLaunchMapIter l_GroupIterator = m_MapProclaunchGrps.find(m_SystemStarter.get_id()); + if (l_GroupIterator == m_MapProclaunchGrps.end()) { + FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, + " Error: Group %d not found; 'm_MapProclaunchGrps' is empty" + //, m_ActiveGroupId); // LCOV_EXCL_BR_LINE 15: marco defined in ns_logger_if.h // NOLINT(whitespace/line_length) + , m_SystemStarter.get_id()); + l_eStatus = eFrameworkunifiedStatusDbRecNotFound; + } else { + int l_numModulesMessaged = 0; + FRAMEWORKUNIFIEDLOG(ZONE_STATE, __FUNCTION__, "StopReq grp:%d", m_SystemStarter.get_id()); + + T_SS_SM_STOP_DataStructType l_SM_STOP_Struct; + l_SM_STOP_Struct.shutdownTrigger = m_shutdownTrigger; + l_SM_STOP_Struct.lastUserMode = m_lastUserMode; + + for (l_revIter = l_GroupIterator->second.modules.rbegin(); + l_revIter != l_GroupIterator->second.modules.rend(); + l_revIter++) { + // LCOV_EXCL_BR_START 11: Excluded due to gcov constraints (others) + if ((l_revIter->IsModuleState(MODULE_STATE_START_SENT) == TRUE) + || (l_revIter->IsModuleState(MODULE_STATE_STARTED) == TRUE) + || (l_revIter->IsModuleState(MODULE_STATE_START_PRE_SENT) == TRUE) + || (l_revIter->IsModuleState(MODULE_STATE_STARTED_PRE) == TRUE) + || (l_revIter->IsModuleState(MODULE_STATE_STOP_PRE_SENT) == TRUE) + || (l_revIter->IsModuleState(MODULE_STATE_STOPPED_PRE) == TRUE) + || (l_revIter->IsModuleState(MODULE_STATE_START_BACKGROUND_SENT) == TRUE) + || (l_revIter->IsModuleState(MODULE_STATE_STARTED_BACKGROUND) == TRUE) + || (l_revIter->IsModuleState(MODULE_STATE_STOP_BACKGROUND_SENT) == TRUE) + || (l_revIter->IsModuleState(MODULE_STATE_STOPPED_BACKGROUND) == TRUE)) { + // LCOV_EXCL_BR_STOP 11: Excluded due to gcov constraints (others) + if (FRAMEWORKUNIFIED_NS_NPSERVICE == l_revIter->name) { + if (epssdmsdtFACTORY_DATA_RESET == m_shutdownTrigger) { + CALL_AND_LOG_STATUS(FrameworkunifiedSendStopToNSNPP(hApp, eFrameworkunifiedDataResetShutdown, eFrameworkunifiedUserData | eFrameworkunifiedFactoryData)); // LCOV_EXCL_BR_LINE 15: marco defined in ss_templates.h // NOLINT(whitespace/line_length) + } else if (epssdmsdtUSER_DATA_RESET == m_shutdownTrigger) { + CALL_AND_LOG_STATUS(FrameworkunifiedSendStopToNSNPP(hApp, eFrameworkunifiedDataResetShutdown, eFrameworkunifiedUserData)); // LCOV_EXCL_BR_LINE 15: marco defined in ss_templates.h // NOLINT(whitespace/line_length) + } else if (epssdmsdtFAST_SLEEP_MODE == m_shutdownTrigger) { + CALL_AND_LOG_STATUS(FrameworkunifiedSendStopToNSNPP(hApp, eFrameworkunifiedQuickShutdown)); // LCOV_EXCL_BR_LINE 15: marco defined in ss_templates.h // NOLINT(whitespace/line_length) + } else { + CALL_AND_LOG_STATUS(FrameworkunifiedSendStopToNSNPP(hApp, eFrameworkunifiedNormalShutdown)); // LCOV_EXCL_BR_LINE 15: marco defined in ss_templates.h // NOLINT(whitespace/line_length) + } + + if (eFrameworkunifiedStatusOK != l_eStatus) { + l_revIter->SetModuleState(MODULE_STATE_STOP_FAILED); + } else { + l_revIter->SetModuleState(MODULE_STATE_STOP_SENT); + l_numModulesMessaged++; + } + + m_NPPStopSent = TRUE; + FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__, " m_NPPStopSent is %s", GetStr(m_NPPStopSent).c_str()); // LCOV_EXCL_BR_LINE 15: marco defined in ns_logger_if.h // NOLINT(whitespace/line_length) + // End else if ( FRAMEWORKUNIFIED_NS_NPSERVICE == l_ModuleListIter->name ) + } else { + l_eStatus = l_revIter->SendMsgAndUpdateState(&l_SM_STOP_Struct); + LOG_STATUS_REC_HIST_IF_ERRORED(l_eStatus, "l_revIter->SendMsgAndUpdateState(&l_SM_STOP_Struct)"); // LCOV_EXCL_BR_LINE 15: marco defined in ss_system_manager.h // NOLINT(whitespace/line_length) + if (eFrameworkunifiedStatusOK == l_eStatus) { + if (epssdmsdtFAST_SLEEP_MODE == m_shutdownTrigger) { + l_uiModuleWaitTime = l_revIter->fast_shutdown_wait_time; + + } else { + l_uiModuleWaitTime = l_revIter->shutdown_wait_time; + } + if (l_uiModuleWaitTime > l_uiMaxGroupWaitTime_sec) { + l_uiMaxGroupWaitTime_sec = l_uiModuleWaitTime; + } + l_numModulesMessaged++; + } + } // End if MODULE_STATE_STARTED || MODULE_STATE_START_SENT + } else if (l_revIter->IsModuleState(MODULE_STATE_INVALID) + && FRAMEWORKUNIFIED_NS_NPSERVICE == l_revIter->name) { + m_NPPStopSent = TRUE; + FRAMEWORKUNIFIEDLOG(ZONE_STATE, __FUNCTION__, "StopNotSent:%s is INVALID", FRAMEWORKUNIFIED_NS_NPSERVICE); + } else { + FRAMEWORKUNIFIEDLOG(ZONE_STATE, __FUNCTION__, "StopNotSent:%s is %s", + l_revIter->name.c_str(), + l_revIter->ModuleStateStr().c_str()); + } + } + + if (0 == l_numModulesMessaged) { + LogGroupModulesState(m_SystemStarter.get_id() // m_ActiveGroupId // LCOV_EXCL_BR_LINE 11:unexpected branch // NOLINT(whitespace/line_length) + , " Warning: NO modules were sent SS_SM_STOP"); + + FRAMEWORKUNIFIEDLOG(ZONE_STATE, __FUNCTION__, "StopComp grp:%d", l_GroupIterator->second.id); + + if (m_SystemStarter.get_id() > SS_SM_INITIAL_GROUP) { + m_SystemStarter.decrement_id(); + FRAMEWORKUNIFIEDLOG(ZONE_STATE, __FUNCTION__, " m_ActiveGroupId is now %d", m_SystemStarter.get_id()); + + check_all_groups_have_stopped(hApp); + } + } else { + if (epssdmsdtFAST_SLEEP_MODE == m_shutdownTrigger) { + // fast shutdown wait time always comes in milli seconds + UI_32 l_uiTotalWaitTime = l_uiMaxGroupWaitTime_sec; + l_uiMaxGroupWaitTime_sec = l_uiTotalWaitTime / 1000; + l_uiMaxGroupWaitTime_msec = l_uiTotalWaitTime % 1000; + } else { + // Other types of shutdown except fast shutdown always comes in seconds. + l_uiMaxGroupWaitTime_msec = 0; + } + + FRAMEWORKUNIFIEDLOG(ZONE_STATE, __FUNCTION__, "StopTimer grp:%d time:%d.%d", + m_SystemStarter.get_id(), l_uiMaxGroupWaitTime_sec, + l_uiMaxGroupWaitTime_msec); + m_GroupLaunchTimer->StartTimerMulti( + m_aTimerIDs[eSM_TIMER_CLIENT_STOP_MONITOR], + l_uiMaxGroupWaitTime_sec, l_uiMaxGroupWaitTime_msec, 0, 0, + m_SystemStarter.get_id()); + } + } + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-"); + return l_eStatus; +} // End of VOID CSystemManager::stop_all_modules_of_group(HANDLE hApp) + +EFrameworkunifiedStatus CSystemManager::ValidateUserModeMessage(HANDLE hApp, EPWR_USER_MODE_TYPE &l_eUserModeState) { // LCOV_EXCL_START 6: Because the condition cannot be set // NOLINT(whitespace/line_length) + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+"); + EFrameworkunifiedStatus l_eStatus; + Pwr_ServiceSetInterface tServiceSetIf; + EPWR_USER_MODE_TYPE l_my_eUserModeState; + + // ReadMsg(): * + // Check hApp ptr, msg size, msg reception, read msg if all ok. * + if (eFrameworkunifiedStatusOK != (l_eStatus = ReadMsg < Pwr_ServiceSetInterface > (hApp, tServiceSetIf))) { + LOG_ERROR("ReadMsg()"); // LCOV_EXCL_BR_LINE 15: marco defined in ss_templates.h // NOLINT(whitespace/line_length) + } else { + l_my_eUserModeState = tServiceSetIf.data.user_mode.mode; + switch (l_my_eUserModeState) { + case epsumINVALID: + FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, " Error: l_eUserModeState == epsumINVALID"); + l_eStatus = eFrameworkunifiedStatusInvldParam; + break; + + case epsumOFF: + case epsumON: + FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__, " Validated '%s'", + l_my_eUserModeState == epsumON ? "epsumON" : "epsumOFF"); + l_eUserModeState = l_my_eUserModeState; + l_eStatus = eFrameworkunifiedStatusOK; + break; + + // default: Don't code a 'default' here - let the compiler + // issue a warning ( set via -Wall or -Wswitch ) when the set of + // enumerations changes - then the maintainer will + // automagically know to update this switch statement. + } // End switch + } + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-"); + return l_eStatus; +} // End of EFrameworkunifiedStatus CSystemManager::ValidateUserModeMessage( HANDLE hApp, EPWR_USER_MODE_TYPE &l_eUserModeState ) +// LCOV_EXCL_STOP + +//***************************************************************************** +// Next Wakeup Type Set Protocol functions * +// * +EFrameworkunifiedStatus CSystemManager::OnSetNextWakeupTypeRequest(HANDLE hApp) { + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+"); + EFrameworkunifiedStatus l_eStatus; + ESMNextWakeupType l_wakeupType; + + INTERFACEUNIFIEDLOG_RECEIVED_FROM(hApp); // LCOV_EXCL_BR_LINE 15: marco defined in ns_logger_if.h // NOLINT(whitespace/line_length) + FRAMEWORKUNIFIEDLOG(ZONE_STATE, __FUNCTION__, "from %s", FrameworkunifiedGetMsgSrc(hApp)); + SetCmdHist("SS_SM_NEXT_WAKEUP_TYPE_SET_REQ", m_SMCmdHist, m_SMHistIter, FrameworkunifiedGetMsgSrc(hApp)); + + if (eFrameworkunifiedStatusOK != (l_eStatus = ReadMsg < ESMNextWakeupType > (hApp, l_wakeupType))) { + LOG_ERROR("ReadMsg()"); // LCOV_EXCL_BR_LINE 15: marco defined in ss_templates.h // NOLINT(whitespace/line_length) + } else { + switch (l_wakeupType) { + case e_SS_SM_NEXT_WAKEUP_TYPE_NONE: + case e_SS_SM_NEXT_WAKEUP_TYPE_COLD: + case e_SS_SM_NEXT_WAKEUP_TYPE_HOT: + break; + default: + FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "unknown type(%d)", l_wakeupType); + l_eStatus = eFrameworkunifiedStatusInvldParam; + } + } + l_eStatus = FrameworkunifiedSetSyncResponseData(hApp, &l_eStatus, sizeof(l_eStatus)); + LOG_STATUS_IF_ERRORED(l_eStatus, "FrameworkunifiedSetSyncResponseData()"); // LCOV_EXCL_BR_LINE 15: marco defined in ss_templates.h // NOLINT(whitespace/line_length) + + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-"); + return l_eStatus; +} // End of EFrameworkunifiedStatus CSystemManager::OnSetNextWakeupTypeRequest( HANDLE hApp ) + +// * +// End of Boot Mode Protocol functions * +//***************************************************************************** + + +//***************************************************************************** +// Data Reset Mode Protocol functions * +// * +EFrameworkunifiedStatus CSystemManager::OnSetDataResetModeRequest(HANDLE hApp) { + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+"); + EFrameworkunifiedStatus l_eStatus; + ESMDataResetModeInfo l_dataResetMode; + INTERFACEUNIFIEDLOG_RECEIVED_FROM(hApp); // LCOV_EXCL_BR_LINE 15: marco defined in ns_logger_if.h // NOLINT(whitespace/line_length) + FRAMEWORKUNIFIEDLOG(ZONE_STATE, __FUNCTION__, "from %s", FrameworkunifiedGetMsgSrc(hApp)); + + SetCmdHist("SS_SM_DATA_RESET_MODE_SET_REQ", m_SMCmdHist, m_SMHistIter, FrameworkunifiedGetMsgSrc(hApp)); + + if (eFrameworkunifiedStatusOK != (l_eStatus = ReadMsg < ESMDataResetModeInfo > (hApp, l_dataResetMode))) { + LOG_ERROR("ReadMsg()"); // LCOV_EXCL_BR_LINE 15: marco defined in ss_templates.h // NOLINT(whitespace/line_length) + } else { + uint32_t tmp; + m_DataResetMode = l_dataResetMode; + tmp = static_cast<uint32_t>(m_DataResetMode); + if (PowerHalSetResetInfo(AGL_DATARESET_STATE, tmp)) { // LCOV_EXCL_BR_LINE 11:Gcov constraints (because exception-handling routes are automatically generated) + FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "Could not set AGL_DATARESET_STATE."); + // Return error to client of system_manager. + l_eStatus = eFrameworkunifiedStatusFail; + } + } + // + // Instead of sending Return Message, this function must call FrameworkunifiedSetSyncResponseData() + // because this request is sent by FrameworkunifiedInvokeSync() + // + l_eStatus = FrameworkunifiedSetSyncResponseData(hApp, &l_eStatus, sizeof(l_eStatus)); + LOG_STATUS_IF_ERRORED(l_eStatus, "FrameworkunifiedSetSyncResponseData()"); // LCOV_EXCL_BR_LINE 15: marco defined in ss_templates.h // NOLINT(whitespace/line_length) + + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-"); + return l_eStatus; +} // End of EFrameworkunifiedStatus CSystemManager::OnSetDataResetModeRequest( HANDLE hApp ) + +EFrameworkunifiedStatus CSystemManager::OnSetProgUpdateStateRequest(HANDLE hApp) { + EFrameworkunifiedStatus l_eStatus; + SMProgUpdateState l_progUpdateState; + + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+"); + FRAMEWORKUNIFIEDLOG(ZONE_STATE, __FUNCTION__, "from %s", FrameworkunifiedGetMsgSrc(hApp)); + + SetCmdHist("SS_SM_PROG_UPDATE_STATE_SET_REQ", m_SMCmdHist, m_SMHistIter, FrameworkunifiedGetMsgSrc(hApp)); + + if (eFrameworkunifiedStatusOK != (l_eStatus = ReadMsg < SMProgUpdateState > (hApp, l_progUpdateState))) { // LCOV_EXCL_BR_LINE 4: nsfw error + // LCOV_EXCL_START 4: nsfw error + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + LOG_ERROR("ReadMsg()"); // LCOV_EXCL_BR_LINE 15: marco defined in ss_templates.h // NOLINT(whitespace/line_length) + // LCOV_EXCL_STOP + } else { + m_ProgUpdateState |= l_progUpdateState; + if (PowerHalSetResetInfo(AGL_PROGUPDATE_STATE, m_ProgUpdateState)) { // LCOV_EXCL_BR_LINE 11:Gcov constraints (because exception-handling routes are automatically generated) + FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "Could not set AGL_PROGUPDATE_STATE."); + // return Error to client of system_manager. + l_eStatus = eFrameworkunifiedStatusFail; + } + } + // Instead of sending Return Message, this function must call FrameworkunifiedSetSyncResponseData() + // because this request is sent by FrameworkunifiedInvokeSync() + l_eStatus = FrameworkunifiedSetSyncResponseData(hApp, &l_eStatus, sizeof(l_eStatus)); + LOG_STATUS_IF_ERRORED(l_eStatus, "FrameworkunifiedSetSyncResponseData()"); // LCOV_EXCL_BR_LINE 15: marco defined in ss_templates.h // NOLINT(whitespace/line_length) + + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-"); + return l_eStatus; +} // End of EFrameworkunifiedStatus CSystemManager::OnSetProgUpdateStateRequest( HANDLE hApp ) + +EFrameworkunifiedStatus CSystemManager::CallStopCompleteHandler(HANDLE hApp, BOOL bIsDetectTimeout /* = FALSE */) { + FRAMEWORKUNIFIEDLOG(ZONE_STATE, __FUNCTION__, "+"); + EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK; + + + if (bIsDetectTimeout) { + fprintf(stderr, "SS_SysManager/%s/State StopComplete(timeout)\n", __FUNCTION__); + } else { + fprintf(stderr, "SS_SysManager/%s/State StopComplete\n", __FUNCTION__); + } + + l_eStatus = SecureChipOff(); + if (eFrameworkunifiedStatusOK != l_eStatus) { + FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "Error: SecureChipOff Failed"); + } + + l_eStatus = (*m_pfStopCompleteHandler)(hApp); + + FRAMEWORKUNIFIEDLOG(ZONE_STATE, __FUNCTION__, "-"); + return l_eStatus; +} // End of EFrameworkunifiedStatus CSystemManager::CallStopCompleteHandler( HANDLE hApp ) + + +//***************************************************************************** +// Soft Reset Protocol functions * +// * +static char *get_line(const char *filepath) { + char line[LINE_MAX]; + FILE *fp; + + if ((fp = fopen(filepath, "rb")) == NULL) + return NULL; + if (fgets(line, LINE_MAX, fp) == NULL) { // LCOV_EXCL_BR_LINE 5:fgets error + // LCOV_EXCL_START 5: fgets error + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + fclose(fp); + return NULL; + // LCOV_EXCL_STOP + } + fclose(fp); + + return strdup(line); +} + +EFrameworkunifiedStatus CSystemManager::PerformCpuReset(HANDLE hApp, + ESMCpuResetReason f_eSmCpuResetReason, std::string f_messageStr) { + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+"); + EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK; + if (FALSE == m_isRcvModeInfo) { + // If the condition for implementing the CpuReset request is not satisfied, keep the request. + FRAMEWORKUNIFIEDLOG(ZONE_STATE, __FUNCTION__, "Cpu Reset Pending"); + m_isRstPending = TRUE; + m_rstPendingInfo.resetReason = f_eSmCpuResetReason; + snprintf(m_rstPendingInfo.messageStr, + sizeof(m_rstPendingInfo.messageStr), "%s", f_messageStr.c_str()); + } else { + switch (f_eSmCpuResetReason) { + case e_SS_SM_CPU_RESET_REASON_CRITICAL_ERR: + case e_SS_SM_CPU_RESET_REASON_GENERIC_ERR: + case e_SS_SM_CPU_RESET_REASON_DSP_ERR: + m_isImmResetReq = TRUE; + FRAMEWORKUNIFIEDLOG(ZONE_STATE, __FUNCTION__, " will reset immediately"); + // The break is omitted because the same process as for a normal reboot is performed. + case e_SS_SM_CPU_RESET_REASON_USER_FORCE_RESET: + m_pfStopCompleteHandler = (SysMgrCallback<CSystemManager, &CSystemManager::perform_force_reset>); + case e_SS_SM_CPU_RESET_REASON_NORMAL: { + TSystemManagerCpuResetInfo l_resetInfo; + + l_resetInfo.resetReason = f_eSmCpuResetReason; + snprintf(l_resetInfo.messageStr, SS_SM_RESET_MSG_STR_SIZE, "%s", f_messageStr.c_str()); + l_eStatus = FrameworkunifiedSendMsg(m_hPowerServiceSession, SS_SM_CPU_RESET_REQ, + sizeof(l_resetInfo), (PVOID) & l_resetInfo); + LOG_STATUS(l_eStatus, // LCOV_EXCL_BR_LINE 6: Because the condition cannot be set + "FrameworkunifiedSendMsg(m_hPowerServiceSession, SS_SM_CPU_RESET_REQ)"); + } + break; + case e_SS_SM_CPU_RESET_REASON_DATA_RESET: { + ESMDataResetType l_eSmDataResetType; + + switch (m_DataResetMode) { + case e_SS_SM_DATA_RESET_MODE_FACTORY: + l_eSmDataResetType = e_SS_SM_DATA_RESET_TYPE_FACTORY; + break; + case e_SS_SM_DATA_RESET_MODE_USER: + l_eSmDataResetType = e_SS_SM_DATA_RESET_TYPE_USER; + l_eStatus = FrameworkunifiedBroadcastEvent(hApp, SS_SM_EVENT_USER_DATA_RESET, NULL, 0); + LOG_STATUS(l_eStatus, "FrameworkunifiedBroadcastEvent(SS_SM_EVENT_USER_DATA_RESET)"); // LCOV_EXCL_BR_LINE 15: marco defined in ss_templates.h // NOLINT(whitespace/line_length) + break; + default: + SS_ASERT_LOG(0, "unexpected data reset mode : %d", m_DataResetMode); // LCOV_EXCL_BR_LINE 15: marco defined in ss_templates.h // NOLINT(whitespace/line_length) + l_eStatus = eFrameworkunifiedStatusInvldParam; + break; + } + if (l_eStatus == eFrameworkunifiedStatusOK) { + l_eStatus = FrameworkunifiedSendMsg(m_hPowerServiceSession, + SS_SM_REMOTE_DATA_RESET_REQ, sizeof(l_eSmDataResetType), + (PVOID) & l_eSmDataResetType); + LOG_STATUS(l_eStatus, "FrameworkunifiedSendMsg(m_hPowerServiceSession, SS_SM_REMOTE_DATA_RESET_REQ)"); // LCOV_EXCL_BR_LINE 15: marco defined in ss_templates.h // NOLINT(whitespace/line_length) + } + } + break; + case e_SS_SM_CPU_RESET_REASON_INVALID: + default: + SS_ASERT_LOG(0, " Error: Unknown CPU reset request type: 0x%X/%d", // LCOV_EXCL_BR_LINE 15: marco defined in ss_templates.h // NOLINT(whitespace/line_length) + f_eSmCpuResetReason, f_eSmCpuResetReason); + l_eStatus = eFrameworkunifiedStatusInvldParam; + break; + } + } + + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-"); + return l_eStatus; +} // End of EFrameworkunifiedStatus CSystemManager::PerformCpuReset( ESMCpuResetReason f_eSmCpuResetReason ) + +//***************************************************************************** +// CPU Reset Protocol functions * +// * +EFrameworkunifiedStatus CSystemManager::OnCpuResetRequest(HANDLE hApp) { // SS_SM_CPU_RESET_REQ + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+"); + EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusFail; + std::string l_moduleName = FrameworkunifiedGetMsgSrc(hApp); + INTERFACEUNIFIEDLOG_RECEIVED_FROM(hApp); // LCOV_EXCL_BR_LINE 15: marco defined in ns_logger_if.h // NOLINT(whitespace/line_length) + FRAMEWORKUNIFIEDLOG(ZONE_STATE, __FUNCTION__, "from %s", l_moduleName.c_str()); + + // If you implement FastSleep, + // ShutdownTrigger of FrameworkunifiedOnStop needs to be changed to FAST_SLEEP_MODE, + // and also MaxShutdownTime needs to be changed to CriticalAppsMaxShutdownTimeFastSleep + + try { + TSystemManagerCpuResetInfo l_resetInfo; + SetCmdHist("SS_SM_CPU_RESET_REQ", m_SMCmdHist, m_SMHistIter, // LCOV_EXCL_BR_LINE 11:unexpected branch // NOLINT(whitespace/line_length) + FrameworkunifiedGetMsgSrc(hApp)); // LCOV_EXCL_BR_LINE 11:unexpected branch // NOLINT(whitespace/line_length) + if (eFrameworkunifiedStatusOK != (l_eStatus = ReadMsg < TSystemManagerCpuResetInfo > (hApp, l_resetInfo))) { + LOG_ERROR("ReadMsg()"); // LCOV_EXCL_BR_LINE 15: marco defined in ss_templates.h // NOLINT(whitespace/line_length) + } else { + char l_cBuf[100]; + EErrorEventType l_errorEventType; + SMLoggingInfo l_loggingInfo; // LCOV_EXCL_BR_LINE 11:unexpected branch // NOLINT(whitespace/line_length) + + l_loggingInfo.messageStr = l_resetInfo.messageStr; + l_loggingInfo.suffixStr = l_resetInfo.suffixStr; + + FRAMEWORKUNIFIEDLOG(ZONE_STATE, __FUNCTION__, + " CPU Reset Reason: '%d'/'%s' from %s", + l_resetInfo.resetReason, + GetStr(l_resetInfo.resetReason).c_str(), + FrameworkunifiedGetMsgSrc(hApp)); + + if (e_SS_SM_CPU_RESET_REASON_IMMRESET_NORMAL == l_resetInfo.resetReason) { + m_isImmResetReq = TRUE; + l_resetInfo.resetReason = e_SS_SM_CPU_RESET_REASON_NORMAL; + } + switch (l_resetInfo.resetReason) { + case e_SS_SM_CPU_RESET_REASON_DATA_RESET: + switch (m_DataResetMode) { + case e_SS_SM_DATA_RESET_MODE_FACTORY: + case e_SS_SM_DATA_RESET_MODE_USER: + break; + case e_SS_SM_DATA_RESET_MODE_NONE: + default: + FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "unexpected data reset mode : %d", m_DataResetMode); + throw eFrameworkunifiedStatusInvldParam; + } + case e_SS_SM_CPU_RESET_REASON_CRITICAL_ERR: + case e_SS_SM_CPU_RESET_REASON_GENERIC_ERR: + case e_SS_SM_CPU_RESET_REASON_DSP_ERR: + case e_SS_SM_CPU_RESET_REASON_NORMAL: + l_errorEventType = eErrorEventTypeModuleInvokedResetRequest; + l_loggingInfo.resetReason = l_resetInfo.resetReason; + break; + case e_SS_SM_CPU_RESET_REASON_USER_FORCE_RESET: + // Separate ErrorEventType only for USER_FORCE_RESET, because the logs to be saved differ. + l_errorEventType = eErrorEventTypeUserInvokedUserForceReset; + l_loggingInfo.resetReason = e_SS_SM_CPU_RESET_REASON_USER_FORCE_RESET; + break; + case e_SS_SM_CPU_RESET_REASON_INVALID: + default: + FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, + " Error: Unknown CPU reset request type: 0x%X/%d", + l_resetInfo.resetReason, l_resetInfo.resetReason); + throw eFrameworkunifiedStatusInvldParam; + } + + l_eStatus = ErrorEventEnqueue(hApp, l_errorEventType, l_moduleName, + eErrorEventResetTypeHard, l_loggingInfo); + + snprintf(l_cBuf, sizeof(l_cBuf), "ErrorEventEnqueue(%s)", + GetStr(l_errorEventType).c_str()); // LCOV_EXCL_BR_LINE 11:unexpected branch // NOLINT(whitespace/line_length) + LOG_STATUS_REC_HIST_IF_ERRORED(l_eStatus, l_cBuf); // LCOV_EXCL_BR_LINE 15: marco defined in ss_system_manager.h // NOLINT(whitespace/line_length) + } + } catch (EFrameworkunifiedStatus e) { + l_eStatus = e; + } + + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-"); + return l_eStatus; +} +// * +// End of CPU Reset Protocol functions * +//***************************************************************************** + +VOID CSystemManager::InitiateAllGroupsShutdown(HANDLE hApp) { + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+"); + EFrameworkunifiedStatus l_eStatus; + + // Prioritize safe termination sequence and do not save logs during termination + m_errorEventQueueLocked = TRUE; + + m_MaxShutdownTime = calculate_max_shutdown_time(); + + l_eStatus = FrameworkunifiedNPPublishNotification(hApp, NTFY_SSSystemMgrShutdownStarted, NULL, 0); + + SetCmdHist(NTFY_SSSystemMgrShutdownStarted, m_PubCmdHist, m_PubHistIter, ""); // LCOV_EXCL_BR_LINE 11:unexpected branch // NOLINT(whitespace/line_length) + + LOG_ERROR_REC_HIST_IF_ERRORED(l_eStatus, // LCOV_EXCL_BR_LINE 15: marco defined in ss_system_manager.h // NOLINT(whitespace/line_length) + "FrameworkunifiedNPPublishNotification(" NTFY_SSSystemMgrShutdownStarted ")"); + + m_GroupLaunchTimer->StopTimer(m_aTimerIDs[eSM_TIMER_START_RESP_MONITOR_WAIT_TIMER]); + m_GroupLaunchTimer->StopTimer(m_aTimerIDs[eSM_TIMER_CLIENT_START_MONITOR]); + + // Stop Heartbeat thread activity + l_eStatus = SendRequestToHeartBeat(hApp, SS_HEARTBEAT_STOP, NULL, 0); + LOG_ERROR_REC_HIST_IF_ERRORED(l_eStatus, "SendRequestToHeartBeat(SS_HEARTBEAT_STOP)"); // LCOV_EXCL_BR_LINE 15: marco defined in ss_system_manager.h // NOLINT(whitespace/line_length) + + SMSetState(hApp, SS_SM_APPS_STOPPING_AT__CWORD56__REQ); + + FRAMEWORKUNIFIEDLOG(ZONE_STATE, __FUNCTION__, "shutdownTrigger:%s, lastUserMode:%s", + GetStr(m_shutdownTrigger).c_str(), GetStr(m_lastUserMode).c_str()); + + fprintf(stderr, // LCOV_EXCL_BR_LINE 11:unexpected branch // NOLINT(whitespace/line_length) + "SS_SysManager/%s/State shutdownTrigger:%s, lastUserMode:%s\n", // LCOV_EXCL_BR_LINE 11:unexpected branch // NOLINT(whitespace/line_length) + __FUNCTION__, GetStr(m_shutdownTrigger).c_str(), // LCOV_EXCL_BR_LINE 11:unexpected branch // NOLINT(whitespace/line_length) + GetStr(m_lastUserMode).c_str()); // LCOV_EXCL_BR_LINE 11:unexpected branch // NOLINT(whitespace/line_length) + + /// Send SS_SM_STOP to all modules, starting with the m_ActiveGroupId group + m_NPPStopSent = FALSE; + check_all_groups_have_stopped(hApp); + + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-"); + return; +} // End of EFrameworkunifiedStatus CSystemManager::InitiateAllGroupsShutdown(HANDLE hApp) + +VOID CSystemManager::SendDeferMsg(HANDLE hApp) { + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+"); + + if (!m_dqDeferMsg.empty()) { + EFrameworkunifiedStatus l_eStatus; + SM_POWER_EVENT_INFO deferMsg; + + deferMsg = m_dqDeferMsg.front(); + m_dqDeferMsg.pop(); + + HANDLE hSender = McOpenSender(SERVICE_SYSMANAGER); + if (hSender == NULL) { // LCOV_EXCL_BR_LINE 4: nsfw error + // LCOV_EXCL_START 4: nsfw error + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, " Error: McOpenSender(SERVICE_SYSMANAGER)"); + // LCOV_EXCL_STOP + } else { + CALL_AND_LOG_STATUS_IF_ERRORED( // LCOV_EXCL_BR_LINE 15: marco defined in ss_templates.h // NOLINT(whitespace/line_length) + McSend(hSender, SERVICE_POWER, deferMsg.first, + sizeof(Pwr_ServiceSetInterface), + (PVOID) & deferMsg.second)); + CALL_AND_LOG_STATUS_IF_ERRORED(McClose(hSender)); // LCOV_EXCL_BR_LINE 15: marco defined in ss_templates.h // NOLINT(whitespace/line_length) + } + } + + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+"); + return; +} // End of VOID CSystemManager::SendDeferMsg(HANDLE hApp) + +/////////////////////////////////////////////////////////////////////////////// +/// \ingroup PublishPowerOnOffNotification +/// Power Off notification handler +/// +/// \param [in] +/// +/// \return EFrameworkunifiedStatus +/// Success ==> eFrameworkunifiedStatusOK +/// Failure ==> Other values +/////////////////////////////////////////////////////////////////////////////// +EFrameworkunifiedStatus CSystemManager::PublishPowerOnOffNotification(HANDLE hApp) { + EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK; + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+"); + + l_eStatus = PerformPowerOnOffUserModePublication(hApp, NTFY_SSSystemMgrPowerOnOff); + + SetCmdHist(NTFY_SSSystemMgrPowerOnOff, m_PubCmdHist, m_PubHistIter, ""); + LOG_STATUS_REC_HIST_IF_ERRORED(l_eStatus, "PerformPowerOnOffUserModePublication()"); // LCOV_EXCL_BR_LINE 15: marco defined in ss_system_manager.h // NOLINT(whitespace/line_length) + + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-"); + return l_eStatus; +} + +EFrameworkunifiedStatus CSystemManager::PublishUserModeNotification(HANDLE hApp) { + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+"); + EFrameworkunifiedStatus l_eStatus; + + l_eStatus = PerformPowerOnOffUserModePublication(hApp, NTFY_SSSystemMgrUserMode); + + SetCmdHist(NTFY_SSSystemMgrUserMode, m_PubCmdHist, m_PubHistIter, ""); + LOG_STATUS_REC_HIST_IF_ERRORED(l_eStatus, "PerformPowerOnOffUserModePublication()"); // LCOV_EXCL_BR_LINE 15: marco defined in ss_system_manager.h // NOLINT(whitespace/line_length) + + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-"); + return l_eStatus; +} // End of EFrameworkunifiedStatus CSystemManager::PublishUserModeNotification( + +EFrameworkunifiedStatus CSystemManager::PerformPowerOnOffUserModePublication(HANDLE hApp, const char * p_NotificationStr) { + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+"); + EFrameworkunifiedStatus l_eStatus; + char l_cBuf[500] = { 0 }; + + if (m_SMConfig.UMConfig.IsUserModeNotificationABOOL) { + BOOL l_bUuserMode(m_PowerType_to_SSBoolEnumMap[m_Wake.powerupType]); + + snprintf(l_cBuf, sizeof(l_cBuf), "FrameworkunifiedNPPublishNotification(%s, %s)", + p_NotificationStr, GetStr(l_bUuserMode).c_str()); + l_eStatus = FrameworkunifiedNPPublishNotification(hApp, p_NotificationStr, + &l_bUuserMode, sizeof(l_bUuserMode)); + } else { + T_SS_SM_UserModeOnOffNotification_Struct l_UserModeOnOffStruct( + m_PowerType_to_SSBoolEnumMap[m_Wake.powerupType], + m_StartUpReason, m_userModeChangeReason); + + snprintf(l_cBuf, sizeof(l_cBuf), + "FrameworkunifiedNPPublishNotification(%s, %s, %s, %s)", p_NotificationStr, + GetStr(l_UserModeOnOffStruct.isUserModeOn).c_str(), + GetStr(m_StartUpReason).c_str(), + GetStr(m_userModeChangeReason).c_str()); + l_eStatus = FrameworkunifiedNPPublishNotification(hApp, p_NotificationStr, + &l_UserModeOnOffStruct, sizeof(l_UserModeOnOffStruct)); + } + + SetCmdHist(p_NotificationStr, m_PubCmdHist, m_PubHistIter, ""); + LOG_STATUS(l_eStatus, l_cBuf); // LCOV_EXCL_BR_LINE 15: marco defined in ss_templates.h // NOLINT(whitespace/line_length) + + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-"); + return l_eStatus; +} // End of EFrameworkunifiedStatus CSystemManager::PerformPowerOnOffUserModePublication( + +EFrameworkunifiedStatus CSystemManager::ResetModulesStateToConnected(HANDLE hApp) { + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+"); + EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK; + ModuleLaunchListIter l_moduleIter; + for (GroupLaunchMapIter l_GroupIter = m_MapProclaunchGrps.begin(); + l_GroupIter != m_MapProclaunchGrps.end(); l_GroupIter++) { + for (l_moduleIter = l_GroupIter->second.modules.begin(); + l_moduleIter != l_GroupIter->second.modules.end(); + l_moduleIter++) { + if (l_moduleIter->name == FRAMEWORKUNIFIED_NS_NPSERVICE) { + FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__, " %s ( Group %d/%s ) is %s", + l_moduleIter->name.c_str(), l_GroupIter->second.id, + l_GroupIter->second.name.c_str(), + l_moduleIter->ModuleStateStr().c_str()); + l_moduleIter->SetModuleState(MODULE_STATE_STARTED); // LCOV_EXCL_BR_LINE 15: marco defined in ns_logger_if.h // NOLINT(whitespace/line_length) + // End else if ( FRAMEWORKUNIFIED_NS_NPSERVICE == l_ModuleListIter->name ) + } else { + switch (l_moduleIter->GetModuleState()) { + case MODULE_STATE_INVALID: + case MODULE_STATE_SKIPPED: + case MODULE_STATE_LAUNCHING: + case MODULE_STATE_LAUNCHED: + case MODULE_STATE_LAUNCH_FAILED: + FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__, + " %s ( Group %d/%s ) is %s, NOT setting to " + "MODULE_STATE_CONNECTED", + l_moduleIter->name.c_str(), l_GroupIter->second.id, + l_GroupIter->second.name.c_str(), + l_moduleIter->ModuleStateStr().c_str()); // LCOV_EXCL_BR_LINE 15: marco defined in ns_logger_if.h // NOLINT(whitespace/line_length) + break; + + case MODULE_STATE_STARTED: + case MODULE_STATE_START_SENT: + case MODULE_STATE_CONNECTED: + case MODULE_STATE_START_FAILED: + case MODULE_STATE_STOP_FAILED: + case MODULE_STATE_STOP_SENT: + case MODULE_STATE_STOPPED: + case MODULE_STATE_START_PRE_SENT: + case MODULE_STATE_START_PRE_FAILED: + case MODULE_STATE_STARTED_PRE: + case MODULE_STATE_STOP_PRE_SENT: + case MODULE_STATE_STOP_PRE_FAILED: + case MODULE_STATE_STOPPED_PRE: + case MODULE_STATE_START_BACKGROUND_SENT: + case MODULE_STATE_START_BACKGROUND_FAILED: + case MODULE_STATE_STARTED_BACKGROUND: + case MODULE_STATE_STOP_BACKGROUND_SENT: + case MODULE_STATE_STOP_BACKGROUND_FAILED: + case MODULE_STATE_STOPPED_BACKGROUND: + FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__, " %s ( Group %d/%s ) is %s", + l_moduleIter->name.c_str(), l_GroupIter->second.id, + l_GroupIter->second.name.c_str(), + l_moduleIter->ModuleStateStr().c_str()); + l_moduleIter->SetModuleState(MODULE_STATE_CONNECTED); + break; + // default: Don't code a 'default' here - let the compiler + // issue a warning ( set via -Wall or -Wswitch ) when the set of + // enumerations changes - then the maintainer will + // automagically know to update this switch statement. + } + } + } + } + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-"); + return l_eStatus; +} // End of EFrameworkunifiedStatus CSystemManager::ResetModulesStateToConnected(HANDLE hApp) + +EFrameworkunifiedStatus CSystemManager::On_CWORD56_HeartBeatRequest(HANDLE hApp) { + FRAMEWORKUNIFIEDLOG(ZONE_PERIODIC_FUNC, __FUNCTION__, "+"); + EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK; + + PCSTR l_senderName = FrameworkunifiedGetMsgSrc(hApp); + + SetCmdHist("SS_SM__CWORD56__HEARTBEAT_REQ", m_SMCmdHist, m_SMHistIter, l_senderName); + + FRAMEWORKUNIFIEDLOG(ZONE_PERIODIC_INFO, __FUNCTION__, " Received from %s", l_senderName); + EPWR_HB_REQ_MSG_STRUCT l_hbReq; + + if (eFrameworkunifiedStatusOK != (l_eStatus = ReadMsg < EPWR_HB_REQ_MSG_STRUCT > (hApp, l_hbReq))) { + LOG_ERROR("ReadMsg()"); // LCOV_EXCL_BR_LINE 15: marco defined in ss_templates.h // NOLINT(whitespace/line_length) + } else { + + m_GroupLaunchTimer->StopTimer(m_aTimerIDs[eSM_TIMER__CWORD56__HEARTBEAT_RESPONSE]); + + if (l_hbReq.IntervalSec > 0) { + m_GroupLaunchTimer->StartTimer( + m_aTimerIDs[eSM_TIMER__CWORD56__HEARTBEAT_RESPONSE], 0, 0, + l_hbReq.IntervalSec, 0); + } else if (l_hbReq.IntervalSec == 0) { // LCOV_EXCL_BR_LINE 8: As the condition is never false + l_eStatus = FrameworkunifiedSendMsg(m_hPowerServiceSession, SS_SM__CWORD56__HEARTBEAT_RSPN, 0, NULL); + + LOG_STATUS(l_eStatus, "FrameworkunifiedSendMsg(m_hPowerServiceSession, SS_SM__CWORD56__HEARTBEAT_RSPN)"); // LCOV_EXCL_BR_LINE 15: marco defined in ss_templates.h // NOLINT(whitespace/line_length) + } + } + FRAMEWORKUNIFIEDLOG(ZONE_PERIODIC_FUNC, __FUNCTION__, "-"); + return (l_eStatus); +} + +EFrameworkunifiedStatus CSystemManager::On_CWORD56_HeartBeatResponseIntervalTimerExpiry(HANDLE hApp) { + FRAMEWORKUNIFIEDLOG(ZONE_PERIODIC_FUNC, __FUNCTION__, "+"); + EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK; + + SetCmdHist("SM_TIMER__CWORD56__HEARTBEAT_RESPONSE", m_TimerCmdHist, m_TimerHistIter, FrameworkunifiedGetMsgSrc(hApp)); // LCOV_EXCL_BR_LINE 11:unexpected branch // NOLINT(whitespace/line_length) + + l_eStatus = FrameworkunifiedSendMsg(m_hPowerServiceSession, SS_SM__CWORD56__HEARTBEAT_RSPN, 0, NULL); + + LOG_STATUS(l_eStatus, "FrameworkunifiedSendMsg(m_hPowerServiceSession, SS_SM__CWORD56__HEARTBEAT_RSPN)"); // LCOV_EXCL_BR_LINE 15: marco defined in ss_templates.h // NOLINT(whitespace/line_length) + + FRAMEWORKUNIFIEDLOG(ZONE_PERIODIC_FUNC, __FUNCTION__, "-"); + return l_eStatus; +} + +// EOF of /SS_SystemManager/src/ss_system_manager_callbacks.cpp + diff --git a/video_in_hal/systemservice/system_manager/server/src/ss_system_manager_error_event.cpp b/video_in_hal/systemservice/system_manager/server/src/ss_system_manager_error_event.cpp new file mode 100755 index 0000000..131b86a --- /dev/null +++ b/video_in_hal/systemservice/system_manager/server/src/ss_system_manager_error_event.cpp @@ -0,0 +1,945 @@ +/* + * @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_SystemManager +/// \brief This file provides support for IAT error event logging. +/// +/////////////////////////////////////////////////////////////////////////////// +#include <stdlib.h> +#include <stdio.h> +#include <fcntl.h> +#include <dirent.h> +#include <sys/mman.h> +#include <sys/procfs.h> +#include <libgen.h> +#include <spawn.h> +#include <errno.h> +#include <sys/timeb.h> +#include <system_service/ss_system_manager_notifications.h> +#include <native_service/frameworkunified_framework_if.h> +#include <native_service/frameworkunified_multithreading.h> +#include <system_service/ss_services.h> +#include <system_service/ss_client_names.h> +#include <system_service/ss_power_service_if.h> +#include <processlauncher/ProcessLauncher_if.h> +#include <processlauncher/ss_sm_process_launcher_protocol.h> +#include <processlauncher/ss_sm_process_launcher.h> +#include <heartbeat/ss_hb_if.h> +#include <system_service/ss_heartbeat_service_protocol.h> +#include <system_service/ss_power_service_notifications.h> +#include <system_service/ss_power_service_protocol.h> +#include <stub/ss_diag.h> +#include <system_service/ss_test_clients.h> +#include <native_service/ns_np_service_protocol.h> +#include <native_service/frameworkunified_application.h> + +#include <system_service/ss_sm_thread_names.h> +#include <system_service/ss_templates.h> +#include <native_service/ns_plogger_if.h> +#include <native_service/frameworkunified_thread_priority.h> +#include <native_service/ns_np_service_nor_persistence.h> +#include <boost/bind.hpp> +#include <string> +#include "ss_system_manager.h" +#include "ss_sm_systemmanagerlog.h" +#include "ss_sm_default_paths.h" +#include "ss_sm_version.h" + +template<typename C, eFrameworkunifiedStatus (C::*M)(HANDLE)> + EFrameworkunifiedStatus SysMgrCallback(HANDLE hApp) { // LCOV_EXCL_START 6: Can not set condition + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusFail; + C * pObj = static_cast<C *>(&CSystemManager::GetInstance()); + if (pObj) { + l_eStatus = (pObj->*M)(hApp); + } + return l_eStatus; +} +// LCOV_EXCL_STOP + +//****************************************************************************** +void Init_EErrorEventReset_StrMap(std::map<EErrorEventResetType, SS_String> & m_strMap) { // NOLINT + MAP_ENTRY(m_strMap, eErrorEventResetTypeNone); // LCOV_EXCL_BR_LINE 15: marco defined in ss_templates.h // NOLINT(whitespace/line_length) + MAP_ENTRY(m_strMap, eErrorEventResetTypeHard); // LCOV_EXCL_BR_LINE 15: marco defined in ss_templates.h // NOLINT(whitespace/line_length) +} +class EnumStringMap<EErrorEventResetType, Init_EErrorEventReset_StrMap> m_oEErrorEventResetTypeMap; +SS_String GetStr(EErrorEventResetType f_enum) { // LCOV_EXCL_START 6: Can not set condition + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + return m_oEErrorEventResetTypeMap.GetStr(f_enum); +} +// LCOV_EXCL_STOP + +/////////////////////////////////////////////////////////////////////////////// +/// \ingroup ErrorEventInit +/// This function initializes the error event handling subsystem. +/// This function MUST be called by System Manager initialization. +/// +/// \param HANDLE f_hApp AGL FW application handle. +/// +/// \return Status +/// EFrameworkunifiedStatus - success or error +/////////////////////////////////////////////////////////////////////////////// +EFrameworkunifiedStatus CSystemManager::ErrorEventInit(HANDLE f_hApp) { + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+"); + EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK; + Timer *l_pTimer; + + m_isPrevErrEventCompleted = TRUE; + m_errorEventResult = eFrameworkunifiedStatusOK; + m_errorEventQueueLocked = FALSE; + m_errorEventCurrentIter = m_errorEventQueue.end(); + + l_pTimer = &m_errorEventTimers[eSM_ERROR_EVENT_TIMER_LOGGER_START_REQ]; + l_pTimer->Initialize(f_hApp, SS_SM_ERROR_EVENT_TIMER_ID_LOGGER_START_REQ, + boost::bind(&CSystemManager::OnErrorEventLoggerStartRequestTimeout, this, _1)); // LCOV_EXCL_BR_LINE 11:unexpected branch // NOLINT(whitespace/line_length) + + l_pTimer = &m_errorEventTimers[eSM_ERROR_EVENT_TIMER_DEBUG_DUMP_RSPN]; + l_pTimer->Initialize(f_hApp, SS_SM_ERROR_EVENT_TIMER_ID_DEBUG_DUMP_RSPN, + boost::bind(&CSystemManager::OnDebugDumpCompleteTimeout, this, _1)); // LCOV_EXCL_BR_LINE 11:unexpected branch // NOLINT(whitespace/line_length) + + l_pTimer = &m_errorEventTimers[eSM_ERROR_EVENT_TIMER_BOOT_MICRO_LOG_RSPN]; + l_pTimer->Initialize(f_hApp, SS_SM_ERROR_EVENT_TIMER_ID_BOOT_MICRO_LOG_RSPN, + boost::bind(&CSystemManager::OnErrorEventBootMicroLogResponseTimeout, this, _1)); // LCOV_EXCL_BR_LINE 11:unexpected branch // NOLINT(whitespace/line_length) + + l_pTimer = &m_errorEventTimers[eSM_ERROR_EVENT_TIMER_CORE_FILE_POLL]; + l_pTimer->Initialize(f_hApp, SS_SM_ERROR_EVENT_TIMER_ID_CORE_FILE_POLL, + boost::bind(&CSystemManager::OnErrorEventCoreFilePollTimeout, this, _1)); // LCOV_EXCL_BR_LINE 11:unexpected branch // NOLINT(whitespace/line_length) + + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-"); + return (l_eStatus); +} + +/////////////////////////////////////////////////////////////////////////////// +/// \ingroup ErrorEventEnqueue +/// Conditional queue error events for processing by the error event state +/// machine. +/// +/// \param f_hApp Handle to AGL application. +/// +/// \param f_eventType Error event type. +/// +/// \param f_moduleQueueName Error event trigger module queue name. +/// +/// \param f_resetType Error event reset type (none, hard). +/// +/// \param f_loggingInfo Logging information if applicable (optional). +/// +/// \return EFrameworkunifiedStatus +/// Success ==> eFrameworkunifiedStatusOK +/// Failure ==> Other values +/////////////////////////////////////////////////////////////////////////////// +EFrameworkunifiedStatus CSystemManager::ErrorEventEnqueue(HANDLE f_hApp, + EErrorEventType f_eventType, std::string &f_moduleQueueName, + EErrorEventResetType f_resetType, const SMLoggingInfo &f_loggingInfo) { + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+"); + EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK; + ERROR_EVENT_INFO l_errorEventInfo; + ERROR_EVENT_QUEUE_ITER l_errorEventIter; + ERROR_EVENT_QUEUE_RET l_retVal; + BOOL isErrorReset = FALSE; + + if (eErrorEventResetTypeHard == f_resetType) { + // Forced reset if shutdown process is not completed after Reboot requesting + m_GroupLaunchTimer->StartTimer( + m_aTimerIDs[eSM_TIMER_SHUTDOWN_COMPLETE_MONITOR], + SM_SHUTDOWN_COMPLETE_MONITOR_TIMEOUT, 0, 0, 0); + + switch (f_loggingInfo.resetReason) { + case e_SS_SM_CPU_RESET_REASON_GENERIC_ERR: + case e_SS_SM_CPU_RESET_REASON_DSP_ERR: + isErrorReset = TRUE; + break; + default: + break; + } + // LCOV_EXCL_START 6:This variable cannot be modified by external API + if ((m_ResetCount > SS_SM_ERR_NAVI_RESET_LIMIT) && isErrorReset) { + // LCOV_EXCL_BR_STOP + // LCOV_EXCL_START 6:This variable cannot be modified by external API (evaluated only initial value) + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + fprintf(stderr, + "SS_SysManager/%s:will NAVIDET as continuous error(%d) \n", __FUNCTION__, m_ResetCount); + FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "will NAVIDET as continuous error(%d)", m_ResetCount); + m_pfStopCompleteHandler = (SysMgrCallback<CSystemManager, &CSystemManager::perform_force_reset>); + // LCOV_EXCL_STOP + } + } + + if (TRUE == m_errorEventQueueLocked) { + l_eStatus = eFrameworkunifiedStatusAccessError; + FRAMEWORKUNIFIEDLOG(ZONE_WARN, __FUNCTION__, + " Warning. The Error Event Queue has been locked. No further items may be enqueued. System reset pending."); // LCOV_EXCL_BR_LINE 15: marco defined in ns_logger_if.h // NOLINT(whitespace/line_length) + } else { + GetTimeStamp(l_errorEventInfo.m_eventEnqueueTimeStamp); + + l_errorEventInfo.m_moduleQueueName = f_moduleQueueName; + l_errorEventInfo.m_eventType = f_eventType; + l_errorEventInfo.m_errorEventResetType = f_resetType; + l_errorEventInfo.m_loggingInfo = f_loggingInfo; + l_errorEventInfo.m_prio = eErrorEventPrioDefault; // Make Prios of all ErrorEvent first-win as default + // It needs to add eErrorEventPrioxxx properly if design modification about priority required + + if (eErrorEventResetTypeNone != f_resetType) { + FRAMEWORKUNIFIEDLOG(ZONE_STATE, __FUNCTION__, " System will reset after logging"); + } + + l_retVal = m_errorEventQueue.insert(l_errorEventInfo); + if (FALSE == l_retVal.second) { + std::string l_errorEventName = GetStr(l_errorEventInfo.m_eventType); + TEXT(__FUNCTION__, // LCOV_EXCL_BR_LINE 15: marco defined in ns_logger_if.h // NOLINT(whitespace/line_length) + " ERROR EVENT: %s is already queued or is in progress. Event dropped.", // LCOV_EXCL_BR_LINE 15: marco defined in ns_logger_if.h // NOLINT(whitespace/line_length) + l_errorEventName.c_str()); // LCOV_EXCL_BR_LINE 15: marco defined in ns_logger_if.h // NOLINT(whitespace/line_length) + } + + l_eStatus = ErrorEventProcessNext(f_hApp); + LOG_ERROR_REC_HIST_IF_ERRORED(l_eStatus, "ErrorEventProcessNext()"); // LCOV_EXCL_BR_LINE 15: marco defined in ss_system_manager.h // NOLINT(whitespace/line_length) + } + + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-"); + return (l_eStatus); +} + +/////////////////////////////////////////////////////////////////////////////// +/// \ingroup PerformResetAfterLogging +/// perform CPU reset after logging complete +/// +/// \param f_hApp Handle to AGL application. +/// f_eCpuResetReason CPU reset reason +/// f_messageStr Error message string +/// +/// \return EFrameworkunifiedStatus +/// Success ==> eFrameworkunifiedStatusOK +/// Failure ==> Other values +/// +/// +/////////////////////////////////////////////////////////////////////////////// +EFrameworkunifiedStatus CSystemManager::PerformResetAfterLogging(HANDLE f_hApp, + ESMCpuResetReason f_eCpuResetReason, std::string f_messageStr) { + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+"); + EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK; + + l_eStatus = PerformCpuReset(f_hApp, f_eCpuResetReason, f_messageStr); + LOG_STATUS_REC_HIST_IF_ERRORED(l_eStatus, "PerformCpuReset()"); // LCOV_EXCL_BR_LINE 15: marco defined in ss_system_manager.h // NOLINT(whitespace/line_length) + // LCOV_EXCL_BR_START 200: Can not satisfy the condition for calling from caller + if (eFrameworkunifiedStatusOK != l_eStatus) { + // LCOV_EXCL_BR_STOP + // LCOV_EXCL_START 200: Can not satisfy the condition for calling from caller + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + SS_ASERT_LOG(0, "PerformCpuReset() : %d", l_eStatus); + // Erasing ErrorEvent only if resetting process is failed + m_errorEventQueue.erase(m_errorEventCurrentIter); // Erase last processed event. + // LCOV_EXCL_STOP + } else { + m_errorEventQueueLocked = TRUE; // Permanent lock until post reset. + m_errorEventQueue.clear(); // Drop queued events. + SendDeferMsg(f_hApp); + } + + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-"); + return (l_eStatus); +} + +/////////////////////////////////////////////////////////////////////////////// +/// \ingroup ErrorEventProcessNext +/// Process the next error event from error event queue. +/// +/// \param f_hApp Handle to AGL application. +/// +/// \return EFrameworkunifiedStatus +/// Success ==> eFrameworkunifiedStatusOK +/// Failure ==> Other values +/// +/// \Notes (1) Removal from the queue occurs AFTER the entry has been processed +/// AND just before the NEXT entry is to be obtained. Therefore, +/// the first item enqueued MUST not be removed since it has not +/// been processed. This is ensured by setting the iterator to END +/// during module initialization. After processing the first event, +/// the iterator will no longer be END until all events have been +/// processed. +/////////////////////////////////////////////////////////////////////////////// +EFrameworkunifiedStatus CSystemManager::ErrorEventProcessNext(HANDLE f_hApp) { + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+"); + EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK; + ERROR_EVENT_QUEUE_ITER l_errorEventIter; + SMErrorEventNtfData l_errorEventNtfData; + + if (TRUE == m_isPrevErrEventCompleted) { // Remove last completed item from front of queue. + // See Note #1. + if ((0 != m_errorEventQueue.size()) && + (m_errorEventQueue.end() != m_errorEventCurrentIter)) { + // Completed logging by ErrorEvent + switch (m_errorEventCurrentIter->m_errorEventResetType) { + case eErrorEventResetTypeNone: + switch (m_errorEventCurrentIter->m_eventType) { + case eErrorEventTypeInterfaceunifiedEmmcLogs: + case eErrorEventTypeUserInvokedClearLogs: + if (eFrameworkunifiedStatusOK == m_errorEventResult) { + if (PowerHalSetResetInfo(AGL_ERRLOG_COUNTER, 0)) { + // Logging only. + FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, + "Could not reset AGL_ERRLOG_COUNTER"); + } + } + break; + default: + break; + } + + if (eErrorEventTypeInterfaceunifiedEmmcLogs == m_errorEventCurrentIter->m_eventType) { + HANDLE hSession = FrameworkunifiedMcOpenSender(f_hApp, + m_errorEventCurrentIter->m_moduleQueueName.c_str()); + + if (hSession == NULL) { // 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 + SS_ASERT(0); // LCOV_EXCL_BR_LINE 15: marco defined in ss_templates.h // NOLINT(whitespace/line_length) + // LCOV_EXCL_STOP + } else { + if (eFrameworkunifiedStatusOK // LCOV_EXCL_BR_LINE 4: NSFW error case + != FrameworkunifiedSendMsg(hSession, + SS_SM_ERROR_EVENT_INTERFACEUNIFIED_EMMC_LOGS_RSPN, + sizeof(m_errorEventResult), + &m_errorEventResult)) { + // LCOV_EXCL_START 4: NSFW error case + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + SS_ASERT(0); // LCOV_EXCL_BR_LINE 15: marco defined in ss_templates.h // NOLINT(whitespace/line_length) + // LCOV_EXCL_STOP + } + if (eFrameworkunifiedStatusOK != FrameworkunifiedMcClose(hSession)) { // 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 + SS_ASERT(0); // LCOV_EXCL_BR_LINE 15: marco defined in ss_templates.h // NOLINT(whitespace/line_length) + // LCOV_EXCL_STOP + } + } + } + m_errorEventQueue.erase(m_errorEventCurrentIter); // Erase last processed event. + break; + case eErrorEventResetTypeHard: + TEXT(__FUNCTION__, "ERROR EVENT: Hard reset required for previously processed error event." // LCOV_EXCL_BR_LINE 15: marco defined in ns_logger_if.h // NOLINT(whitespace/line_length) + "Initiating reset and flushing logging queue."); // LCOV_EXCL_BR_LINE 15: marco defined in ns_logger_if.h // NOLINT(whitespace/line_length) + + if (eFrameworkunifiedStatusOK != m_errorEventResult) { + // Logging at next launching by setting L to NaviDet if logging failed before rebooting + fprintf(stderr, + "SS_SysManager/%s:will NAVIDET as LOG save failed\n", __FUNCTION__); + FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, + "will NAVIDET as LOG save failed"); + m_pfStopCompleteHandler = (SysMgrCallback<CSystemManager, + &CSystemManager::perform_force_reset>); + } + + if ((m_errorEventCurrentIter->m_loggingInfo.resetReason == e_SS_SM_CPU_RESET_REASON_CRITICAL_ERR) || + (m_errorEventCurrentIter->m_loggingInfo.resetReason == e_SS_SM_CPU_RESET_REASON_GENERIC_ERR) || + (m_errorEventCurrentIter->m_loggingInfo.resetReason == e_SS_SM_CPU_RESET_REASON_DSP_ERR) || + (m_errorEventCurrentIter->m_loggingInfo.resetReason == e_SS_SM_CPU_RESET_REASON_USER_FORCE_RESET)) { + BOOL l_user_reset = FALSE; + if (m_errorEventCurrentIter->m_loggingInfo.resetReason == e_SS_SM_CPU_RESET_REASON_USER_FORCE_RESET) { + l_user_reset = TRUE; + } + m_ResetFactor = GetResetFactor(m_errorEventCurrentIter->m_moduleQueueName.c_str(), l_user_reset); + } + + l_eStatus = PerformResetAfterLogging(f_hApp, + m_errorEventCurrentIter->m_loggingInfo.resetReason, + m_errorEventCurrentIter->m_loggingInfo.messageStr); // LCOV_EXCL_BR_LINE 11:unexpected branch // NOLINT(whitespace/line_length) + LOG_STATUS_REC_HIST_IF_ERRORED(l_eStatus, // LCOV_EXCL_BR_LINE 15: marco defined in ss_system_manager.h // NOLINT(whitespace/line_length) + "PerformResetAfterLogging()"); // LCOV_EXCL_BR_LINE 15: marco defined in ss_system_manager.h // NOLINT(whitespace/line_length) + + break; + // LCOV_EXCL_START 6:Can not satisfy condition to branch + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + default: + FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, + " Error. Unknown reset type encountered: 0x%X/%d. No action taken.", + m_errorEventCurrentIter->m_errorEventResetType, + m_errorEventCurrentIter->m_errorEventResetType); + break; + // LCOV_EXCL_STOP + } + } + + // Check if a new work item exists. + if (0 != m_errorEventQueue.size()) { + // ErrorEvent startup process + m_errorEventCurrentIter = m_errorEventQueue.begin(); + + l_errorEventNtfData.EventType = m_errorEventCurrentIter->m_eventType; + + if (eErrorEventResetTypeHard == m_errorEventCurrentIter->m_errorEventResetType) { + l_errorEventNtfData.isNeedReboot = TRUE; + } else { + l_errorEventNtfData.isNeedReboot = FALSE; + } + + // Check BufferSize + size_t modl_len = sizeof(l_errorEventNtfData.ModuleName) - 1; + + // SS Logger uses the l_errorEventNtfData.ModuleName as the LOGGERSERVICE_EMMC_LOGS and + // EEL_EXPORT destination path. eErrorEventTypeDiagEvent sends the destination path. + // For all other event types, the binary name is sent to logger. + // LCOV_EXCL_BR_START 6: Because the applicable variable cannot be changed from the external API (only evaluated by the initial value) + if ((eErrorEventTypeInterfaceunifiedEmmcLogs + == m_errorEventCurrentIter->m_eventType) || + (eErrorEventTypeEelExport + == m_errorEventCurrentIter->m_eventType) || + (eErrorEventTypeDiagEvent + == m_errorEventCurrentIter->m_eventType)) { + // LCOV_EXCL_BR_STOP + strncpy(l_errorEventNtfData.ModuleName, + m_errorEventCurrentIter->m_loggingInfo.path.c_str(), + sizeof(l_errorEventNtfData.ModuleName) - 1); + + size_t path_len = strlen(m_errorEventCurrentIter->m_loggingInfo.path.c_str()); + if (path_len > modl_len) { + FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, + "Input buffer size over. input : %ld, enable : %ld", + path_len, modl_len); + } + l_errorEventNtfData.ModuleName[sizeof(l_errorEventNtfData.ModuleName) - 1] = 0; + } else { + strncpy(l_errorEventNtfData.ModuleName, + m_errorEventCurrentIter->m_loggingInfo.suffixStr.c_str(), + sizeof(l_errorEventNtfData.ModuleName) - 1); + } + + // When the Reboot process is started during the execution of the LOG save sequence, an undefined value was set + // in m_errorEventCurrentIter. Therefore, the Reboot start timing due to an error in SS_Loger was changed from + // the time of ErrorEvent queuing to the time of dequeuing. + + // LCOV_EXCL_BR_START 6: Because the following conditions cannot be satisfied when called from an external API + if ((SERVICE_LOGGER == m_errorEventCurrentIter->m_moduleQueueName) + && ((eErrorEventTypeProcessCrash + == m_errorEventCurrentIter->m_eventType) + || (eErrorEventTypeProcessExit + == m_errorEventCurrentIter->m_eventType) + || (eErrorEventTypeHeartBeatFailure + == m_errorEventCurrentIter->m_eventType) + || (eErrorEventTypeModConnFailed + == m_errorEventCurrentIter->m_eventType) + || (eErrorEventTypeStartRespFailed + == m_errorEventCurrentIter->m_eventType))) { + // LCOV_EXCL_BR_STOP + // LCOV_EXCL_START 6: Because the following conditions cannot be satisfied when called from an external API + // Note: If logger crashes, a core file will exist. + std::string l_hmiDispStr; + l_hmiDispStr = SERVICE_LOGGER; + if (eErrorEventResetTypeNone != m_errorEventCurrentIter->m_errorEventResetType) { + l_hmiDispStr += " - Shutting down, check for core file."; + + // Since LOG save cannot be performed when an SSL error is detected, the LOG is saved at the next startup + // by rebooting with NaviDet = L after completion of the process. + fprintf(stderr, "SS_SysManager/%s:will NAVIDET as SSL dead\n", __FUNCTION__); + FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "will NAVIDET as SSL dead"); + m_pfStopCompleteHandler = (SysMgrCallback<CSystemManager, + &CSystemManager::perform_force_reset>); + + m_ResetFactor = GetResetFactor(SERVICE_LOGGER, FALSE); + + l_eStatus = PerformResetAfterLogging(f_hApp, + e_SS_SM_CPU_RESET_REASON_GENERIC_ERR); + LOG_STATUS_REC_HIST_IF_ERRORED(l_eStatus, "PerformResetAfterLogging()"); + } else { + l_hmiDispStr += " - Check for core file."; + } + + SMErrorEventNtfData l_errorEventNtfData; + l_errorEventNtfData.EventType = m_errorEventCurrentIter->m_eventType; + l_errorEventNtfData.isNeedReboot = FALSE; + snprintf(l_errorEventNtfData.ModuleName, + sizeof(l_errorEventNtfData.ModuleName), "%s", + l_hmiDispStr.c_str()); + + l_eStatus = FrameworkunifiedPublishEvent(f_hApp, // Show indication on HMI. + SS_SM_EVENT_ERROR, + NULL, &l_errorEventNtfData, sizeof(l_errorEventNtfData)); + + LOG_ERROR_REC_HIST_IF_ERRORED(l_eStatus, + "FrameworkunifiedPublishEvent(SS_SM_EVENT_ERROR)"); + } else if (m_errorEventCurrentIter->m_eventType == eErrorEventTypeModuleInvokedResetRequest + && (m_errorEventCurrentIter->m_loggingInfo.resetReason == e_SS_SM_CPU_RESET_REASON_NORMAL + || m_errorEventCurrentIter->m_loggingInfo.resetReason == e_SS_SM_CPU_RESET_REASON_DATA_RESET)) { + l_eStatus = PerformResetAfterLogging(f_hApp, + m_errorEventCurrentIter->m_loggingInfo.resetReason, + m_errorEventCurrentIter->m_loggingInfo.messageStr); // LCOV_EXCL_BR_LINE 11:unexpected branch // NOLINT(whitespace/line_length) + LOG_STATUS_REC_HIST_IF_ERRORED(l_eStatus, "PerformResetAfterLogging()"); // LCOV_EXCL_BR_LINE 15: marco defined in ss_system_manager.h // NOLINT(whitespace/line_length) + } else { + BOOL bIsNeedLogging = TRUE; + + { + UI_32 l_ErrLogCount = 0; + if (PowerHalGetResetInfo(AGL_ERRLOG_COUNTER, &l_ErrLogCount)) { + FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, + "Could not get AGL_ERRLOG_COUNTER form power_hal, assume to 0."); + l_ErrLogCount = 0; + } + + { + if ((l_ErrLogCount >= SS_SM_ERR_LOGGING_LIMIT) + && (eErrorEventResetTypeHard == m_errorEventCurrentIter->m_errorEventResetType)) { + fprintf(stderr, "SS_SysManager/%s:Skip Logging by continuous error \n", __FUNCTION__); + FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "Skip Logging by continuous error "); + + m_ResetFactor = PSM_FACTOR_AGL_WITH_HISTORY; + + l_eStatus = + PerformResetAfterLogging(f_hApp, + m_errorEventCurrentIter->m_loggingInfo.resetReason, + m_errorEventCurrentIter->m_loggingInfo.messageStr); + LOG_STATUS_REC_HIST_IF_ERRORED(l_eStatus, "PerformResetAfterLogging()"); + bIsNeedLogging = FALSE; + } else if (eErrorEventResetTypeHard + == m_errorEventCurrentIter->m_errorEventResetType) { + l_ErrLogCount++; + if (PowerHalSetResetInfo(AGL_ERRLOG_COUNTER, l_ErrLogCount)) { + FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, + "Could not set AGL_ERRLOG_COUNTER to power_hal."); + } + } + } + } + + if (bIsNeedLogging) { + m_isPrevErrEventCompleted = FALSE; + m_errorEventResult = eFrameworkunifiedStatusOK; + BOOL result = + m_errorEventTimers[eSM_ERROR_EVENT_TIMER_LOGGER_START_REQ].Start( + SS_ERROR_EVENT_START_REQ_TO_SEC, 0, 0, 0); + if (FALSE == result) { // LCOV_EXCL_BR_LINE 6: Because the applicable variable cannot be changed from the external API (only evaluated by the initial value) + // LCOV_EXCL_START 6: Because the applicable variable cannot be changed from the external API (only evaluated by the initial value) + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, + " Error. Failed to start timer eSM_ERROR_EVENT_TIMER_LOGGER_START_REQ."); + // LCOV_EXCL_STOP + } + + l_eStatus = FrameworkunifiedPublishEvent(f_hApp, + SS_SM_EVENT_ERROR_TO_SSL, + NULL, &l_errorEventNtfData, + sizeof(l_errorEventNtfData)); + + if (l_eStatus != eFrameworkunifiedStatusOK) { // 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_INFO, __FUNCTION__, + " FrameworkunifiedPublishEvent(SS_SM_EVENT_ERROR_TO_SSL, " + "module name (optional): '%s', " + "event type: %d) returned '%d'/'%s'", + l_errorEventNtfData.ModuleName, + l_errorEventNtfData.EventType, l_eStatus, + GetStr(l_eStatus).c_str()); + // LCOV_EXCL_STOP 4: NSFW error case. + } + } + } + } + + // If Reboot has been started up to this point, m_errorEventQueue is cleared and checking is performed at the end because m_errorEventQueue is cleared. + if (0 == m_errorEventQueue.size()) { + FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__, + " Info. Error Event queue empty. Error logging complete."); + m_errorEventCurrentIter = m_errorEventQueue.end(); // Invalidate iterator in case of spurious events. + SendDeferMsg(f_hApp); + } + } + + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-"); + return (l_eStatus); +} + +/////////////////////////////////////////////////////////////////////////////// +/// \ingroup OnLoggingStartRequestFromSL +/// This function gets called when System Logger initiates artifact +/// collection for a trigger source that originates within System +/// Logger or as a result of System Manager raising a logging +/// event notification to System Logger. +/// +/// \param [in] hApp +/// HANDLE - Handle of the Client Application +/// +/// \return Status +/// EFrameworkunifiedStatus - success or error +/////////////////////////////////////////////////////////////////////////////// +EFrameworkunifiedStatus CSystemManager::OnLoggingStartRequest(HANDLE f_hApp) { + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+"); + EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK; + ModuleLaunchListIter l_ModuleListIter; + HANDLE l_hLoggerServiceSession; + EErrorEventType l_eventType; + SMErrorEventNtfData l_errorEventNtfData; + + m_errorEventTimers[eSM_ERROR_EVENT_TIMER_LOGGER_START_REQ].Stop(); + + INTERFACEUNIFIEDLOG_RECEIVED_FROM(f_hApp); + + if (eFrameworkunifiedStatusOK + != (l_eStatus = ReadMsg < EErrorEventType > (f_hApp, l_eventType))) { + LOG_ERROR("ReadMsg()"); + } else { + if (0 == m_errorEventQueue.size()) { + FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, + " Error. Logging start request received for event type: %d/'%s', " + "but the logging queue is empty.!", l_eventType, + GetStr(l_eventType).c_str()); + l_eStatus = eFrameworkunifiedStatusFail; + } else if (m_errorEventCurrentIter == m_errorEventQueue.end()) { + FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, + " Error. Logging start request received for event type: %d/'%s', " + "but the current event iterator is invalid.", + l_eventType, GetStr(l_eventType).c_str()); + l_eStatus = eFrameworkunifiedStatusFail; + } else if (m_errorEventCurrentIter->m_eventType != l_eventType) { + FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, + " Error. Logging start request received for event type: %d/'%s', " + "but current work item is for event type: %d/'%s'.", + l_eventType, GetStr(l_eventType).c_str(), + m_errorEventCurrentIter->m_eventType, + GetStr(m_errorEventCurrentIter->m_eventType).c_str()); + l_eStatus = eFrameworkunifiedStatusFail; + } else { + l_errorEventNtfData.EventType = l_eventType; + l_errorEventNtfData.isNeedReboot = FALSE; + + // For boot micro reset, customize the string as per the reset reason. + if (l_eventType == eErrorEventTypeBootMicroReset) { + switch (m_BootMicroResetReason) { + case SS_SM_BOOT_MICRO_RESET_REASON_SELF_RESET: + (void) snprintf(l_errorEventNtfData.ModuleName, + sizeof(l_errorEventNtfData.ModuleName), + "Boot Micro Reset. Reason: %d, Self Reset", + m_BootMicroResetReason); + break; + + case SS_SM_BOOT_MICRO_RESET_REASON_USER_FORCE_RESET: // User Force Reset timeout. + (void) snprintf(l_errorEventNtfData.ModuleName, + sizeof(l_errorEventNtfData.ModuleName), + "Boot Micro Reset. Reason: %d, UFR Timeout", + m_BootMicroResetReason); + break; + + case SS_SM_BOOT_MICRO_RESET_REASON_DSP_RESET: + (void) snprintf(l_errorEventNtfData.ModuleName, + sizeof(l_errorEventNtfData.ModuleName), + "Boot Micro Reset. Reason: %d, DSP Reset", + m_BootMicroResetReason); + break; + + case SS_SM_BOOT_MICRO_RESET_REASON_HB_TIMEOUT: + (void) snprintf(l_errorEventNtfData.ModuleName, + sizeof(l_errorEventNtfData.ModuleName), + "Boot Micro Reset. Reason: %d, HB Timeout", + m_BootMicroResetReason); + break; + + default: + (void) snprintf(l_errorEventNtfData.ModuleName, + sizeof(l_errorEventNtfData.ModuleName), + "Boot Micro Reset. Reason: %d, Unknown", + m_BootMicroResetReason); + break; + } + } else { + // All other error event types format = + // Binary Name <circumstantial> PID: TID: Additional info: </circumstantial> + std::string l_hmiDispStr = ErrorEventCreateHmiDisplayString(); + + (void) snprintf(l_errorEventNtfData.ModuleName, + sizeof(l_errorEventNtfData.ModuleName), "%s", + l_hmiDispStr.c_str()); + } + + l_eStatus = FrameworkunifiedPublishEvent(f_hApp, SS_SM_EVENT_ERROR, // To HMI + NULL, &l_errorEventNtfData, sizeof(l_errorEventNtfData)); + + LOG_ERROR_REC_HIST_IF_ERRORED(l_eStatus, + "FrameworkunifiedPublishEvent(SS_SM_EVENT_ERROR)"); + } + + if (eFrameworkunifiedStatusOK + != (l_eStatus = GetModuleIterator(SERVICE_LOGGER, l_ModuleListIter))) { + FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, + " Error: GetModuleIterator(%s) errored: %d/'%s'", + SERVICE_LOGGER, l_eStatus, GetStr(l_eStatus).c_str()); + } else { + l_hLoggerServiceSession = l_ModuleListIter->hsession; + + l_eStatus = FrameworkunifiedSendMsg(l_hLoggerServiceSession, + SS_SM_ERROR_EVENT_LOGGING_START_RSPN, 0, NULL); + + LOG_ERROR_REC_HIST_IF_ERRORED(l_eStatus, + "FrameworkunifiedSendMsg(SS_SM_ERROR_EVENT_LOGGING_START_RSPN)"); + } + } + + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-"); + return (l_eStatus); +} + +/////////////////////////////////////////////////////////////////////////////// +/// \ingroup OnErrorEventLoggerStartRequestTimeout +/// +/// \brief This function is called if System Logger fails to respond in a +/// timely fashion to the published logger start request event +/// SS_SM_EVENT_ERROR_TO_SSL. See OnLoggingStartRequest() which +/// is the expected path should the timer period NOT expire. +/// +/// \param [in] hApp +/// HANDLE - Handle of the Client Application +/// +/// \return Status +/// EFrameworkunifiedStatus - success or error +/////////////////////////////////////////////////////////////////////////////// +EFrameworkunifiedStatus CSystemManager::OnErrorEventLoggerStartRequestTimeout(HANDLE f_hApp) { + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+"); + EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK; + SMErrorEventNtfData l_errorEventNtfData; + + FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, + " Error. Logger failed to respond to message SS_SM_EVENT_ERROR_TO_SSL in a timely fashion. Logging aborted."); + + // Publish to HMI even if the error event will not be processed. + // In this way, developers can be made aware of the error condition + // and determine why logging did not proceed as expected. + if (m_errorEventCurrentIter != m_errorEventQueue.end()) { + l_errorEventNtfData.EventType = m_errorEventCurrentIter->m_eventType; + l_errorEventNtfData.isNeedReboot = FALSE; + + std::string l_hmiDispStr = ErrorEventCreateHmiDisplayString(); + snprintf(l_errorEventNtfData.ModuleName, + sizeof(l_errorEventNtfData.ModuleName), "%s.", l_hmiDispStr.c_str()); + + l_eStatus = FrameworkunifiedPublishEvent(f_hApp, SS_SM_EVENT_ERROR, // To HMI + NULL, &l_errorEventNtfData, sizeof(l_errorEventNtfData)); // LCOV_EXCL_BR_LINE 11:unexpected branch // NOLINT(whitespace/line_length) + + LOG_ERROR_REC_HIST_IF_ERRORED(l_eStatus, "FrameworkunifiedPublishEvent(SS_SM_EVENT_ERROR)"); // LCOV_EXCL_BR_LINE 15: marco defined in ss_system_manager.h // NOLINT(whitespace/line_length) + } + + m_isPrevErrEventCompleted = TRUE; + m_errorEventResult = eFrameworkunifiedStatusFail; + l_eStatus = ErrorEventProcessNext(f_hApp); + LOG_ERROR_REC_HIST_IF_ERRORED(l_eStatus, "ErrorEventProcessNext()"); // LCOV_EXCL_BR_LINE 15: marco defined in ss_system_manager.h // NOLINT(whitespace/line_length) + + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-"); + return (l_eStatus); +} + +EFrameworkunifiedStatus CSystemManager::OnErrorEventLoggingComplete(HANDLE f_hApp) { + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+"); + EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK; + HANDLE l_hLoggerServiceSession; + ModuleLaunchListIter l_ModuleListIter; + + // If logger does not send a logging start and instead immediately + // sends a logging complete response, then the start timer must be + // stopped to prevent a start response timeout from occuring. + m_errorEventTimers[eSM_ERROR_EVENT_TIMER_LOGGER_START_REQ].Stop(); + + m_errorEventResult = eFrameworkunifiedStatusFail; + if (sizeof(m_errorEventResult) != FrameworkunifiedGetMsgLength(f_hApp)) { + LOG_ERROR("DataSize mismatch"); + } else if (eFrameworkunifiedStatusOK + != (l_eStatus = FrameworkunifiedGetMsgDataOfSize(f_hApp, &m_errorEventResult, + sizeof(m_errorEventResult), eSMRRelease))) { + LOG_ERROR("FrameworkunifiedGetMsgDataOfSize()"); + } else { + FRAMEWORKUNIFIEDLOG(ZONE_STATE, __FUNCTION__, "m_errorEventResult = %d", m_errorEventResult); + } + m_isPrevErrEventCompleted = TRUE; + + if (eFrameworkunifiedStatusOK + != (l_eStatus = GetModuleIterator(SERVICE_LOGGER, l_ModuleListIter))) { + FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, + " Error: GetModuleIterator(%s) errored: %d/'%s'", + SERVICE_LOGGER, l_eStatus, GetStr(l_eStatus).c_str()); + } else { + l_hLoggerServiceSession = l_ModuleListIter->hsession; + + l_eStatus = FrameworkunifiedSendMsg(l_hLoggerServiceSession, + SS_SM_ERROR_EVENT_LOGGING_COMPLETE_RSPN, 0, NULL); + + LOG_ERROR_REC_HIST_IF_ERRORED(l_eStatus, + "FrameworkunifiedSendMsg(SS_SM_ERROR_EVENT_LOGGING_START_RSPN)"); + } + + FRAMEWORKUNIFIEDLOG(ZONE_STATE, __FUNCTION__, " Info. Done processing error event %s.", + GetStr(m_errorEventCurrentIter->m_eventType).c_str()); + + l_eStatus = ErrorEventProcessNext(f_hApp); + LOG_ERROR_REC_HIST_IF_ERRORED(l_eStatus, "ErrorEventProcessNext()"); + + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-"); + return (l_eStatus); +} + +/////////////////////////////////////////////////////////////////////////////// +/// \ingroup ActOnModuleFailure +/// This function is called to take appropriate action of the failure +/// reported by heart beat or crash detector. Attributes set in +/// Launch configuration file are considered while taking action +/// on the failed module. +/// +/// \param f_hApp AGL FW application handle. +/// f_moduleName Failed module name. +/// f_refSoftResetRequired Return parameter indicating if a +/// soft reset will be required. +/// \return Status +/// EFrameworkunifiedStatus - success or error +/////////////////////////////////////////////////////////////////////////////// +const CHAR RestartModule[] = "me"; + +EFrameworkunifiedStatus CSystemManager::ActOnModuleFailure(HANDLE f_hApp, + SS_String f_moduleName, BOOL &f_refResetRequired) { + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+"); + ModuleLaunchListIter l_ModuleListIter; + EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK; + ESMPLThreadCommandIds l_PLCmd = ePLThrdCmd_NONE; + SS_String l_PLCmdStr = ""; + + f_refResetRequired = FALSE; + + l_eStatus = GetModuleIterator(f_moduleName.c_str(), l_ModuleListIter); + if (l_eStatus != eFrameworkunifiedStatusOK) { + FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, + " Error: Module %s not found in Group Launch Map", f_moduleName.c_str()); + + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-"); + return (eFrameworkunifiedStatusDbRecNotFound); + } + + // LCOV_EXCL_BR_START 6: Because the condition cannot be set + if (eFrameworkunifiedStatusOK + != (l_eStatus = RemoveModuleEntryFromHB(f_hApp, + l_ModuleListIter->name.c_str()))) { + // LCOV_EXCL_BR_STOP + // LCOV_EXCL_START 6: Because the condition cannot be set + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, + " Error: RemoveModuleEntryFromHB(%s) errored: %d/'%s'", + l_ModuleListIter->name.c_str(), l_eStatus, + GetStr(l_eStatus).c_str()); + // LCOV_EXCL_STOP + } + + if (TRUE == l_ModuleListIter->critical + && (l_ModuleListIter->relaunch_count >= l_ModuleListIter->retry_cnt)) { + FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, + " Error: Critical module '%s' re-launch counter exceeded limit (%d).", + l_ModuleListIter->name.c_str(), l_ModuleListIter->retry_cnt); + + l_ModuleListIter->SetModuleState(MODULE_STATE_SKIPPED); + + // Module has crossed re-launched limit and is not going to be re-launched. + // It must however still be terminated. + l_PLCmd = ePLThrdCmd_TERMINATE_MODULE_REQST; + l_PLCmdStr = "ePLThrdCmd_TERMINATE_MODULE_REQST"; + + // Module is critical. Restart system. + f_refResetRequired = TRUE; + // Restart required? + } else if (0 == std::strcmp(l_ModuleListIter->restart.c_str(), RestartModule)) { // LCOV_EXCL_BR_LINE 6: Because the condition cannot be set // NOLINT(whitespace/line_length) + // LCOV_EXCL_START 6: Because the condition cannot be set + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + FRAMEWORKUNIFIEDLOG(ZONE_STATE, __FUNCTION__, "Module: %s, relaunch_count: %d", + l_ModuleListIter->name.c_str(), + l_ModuleListIter->relaunch_count); + + if (l_ModuleListIter->relaunch_count < l_ModuleListIter->retry_cnt) { + SS_String l_ModulePath = (m_BinaryFilesPath + l_ModuleListIter->path); + + FRAMEWORKUNIFIEDLOG(ZONE_STATE, __FUNCTION__, + " Requesting ReLaunch of '%s' '%s'", + l_ModuleListIter->name.c_str(), l_ModulePath.c_str()); + + l_PLCmd = ePLThrdCmd_RELAUNCH_MODULE_REQST; + l_PLCmdStr = "ePLThrdCmd_RELAUNCH_MODULE_REQST"; + l_ModuleListIter->relaunch_count++; + l_ModuleListIter->relaunch_status = RelaunchErr; + } else if ((FALSE == l_ModuleListIter->critical) + && (l_ModuleListIter->relaunch_count + >= l_ModuleListIter->retry_cnt)) { + FRAMEWORKUNIFIEDLOG(ZONE_WARN, __FUNCTION__, + " Warning: Skipping re-launch of non-critical %s module, " + "re-launch counter exceeded limit(%d). Terminating module.", + l_ModuleListIter->name.c_str(), + l_ModuleListIter->retry_cnt); + + l_ModuleListIter->SetModuleState(MODULE_STATE_SKIPPED); + + // non critical module has crossed re-launched limit and is not going to be re-launched. + // We must terminate the module in the event that it has become non responsive. + l_PLCmd = ePLThrdCmd_TERMINATE_MODULE_REQST; + l_PLCmdStr = "ePLThrdCmd_TERMINATE_MODULE_REQST"; + } + // LCOV_EXCL_STOP + } else { // LCOV_EXCL_BR_LINE 6: Because the condition cannot be set + // LCOV_EXCL_START 6: Because the condition cannot be set + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + FRAMEWORKUNIFIEDLOG(ZONE_WARN, __FUNCTION__, + " Warning: %s is not required to be re-launched, " + "skipping re-launch and terminating module.", + l_ModuleListIter->name.c_str()); + + l_ModuleListIter->SetModuleState(MODULE_STATE_SKIPPED); + + // Module restart not required. + // We must terminate the module in the event that it has become non responsive. + l_PLCmd = ePLThrdCmd_TERMINATE_MODULE_REQST; + l_PLCmdStr = "ePLThrdCmd_TERMINATE_MODULE_REQST"; + // LCOV_EXCL_STOP + } + + + if (ePLThrdCmd_NONE != l_PLCmd) { + l_eStatus = SendRequestToLauncher(f_hApp, l_ModuleListIter, l_PLCmd, l_PLCmdStr); // LCOV_EXCL_BR_LINE 11:unexpected branch // NOLINT(whitespace/line_length) + + LOG_ERROR_REC_HIST_IF_ERRORED(l_eStatus, "SendRequestToLauncher()"); // LCOV_EXCL_BR_LINE 15: marco defined in ss_system_manager.h // NOLINT(whitespace/line_length) + } + + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-"); + return (l_eStatus); +} + +/////////////////////////////////////////////////////////////////////////////// +/// \ingroup ErrorEventCreateHmiDisplayString +/// +/// \brief Create error event HMI colored square display string. +/// +/// \return Error Display String. +/////////////////////////////////////////////////////////////////////////////// +std::string CSystemManager::ErrorEventCreateHmiDisplayString(void) { + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+"); + std::stringstream l_displayNamess; // LCOV_EXCL_BR_LINE 11:unexpected branch // NOLINT(whitespace/line_length) + std::stringstream l_pidss; // LCOV_EXCL_BR_LINE 11:unexpected branch // NOLINT(whitespace/line_length) + std::stringstream l_hmiDispStr; // LCOV_EXCL_BR_LINE 11:unexpected branch // NOLINT(whitespace/line_length) + + if (0 != strncmp("", + m_errorEventCurrentIter->m_loggingInfo.binaryFileName, + sizeof(m_errorEventCurrentIter->m_loggingInfo.binaryFileName))) { + l_displayNamess << m_errorEventCurrentIter->m_loggingInfo.binaryFileName; // LCOV_EXCL_BR_LINE 11:unexpected branch // NOLINT(whitespace/line_length) + } else { + l_displayNamess << m_errorEventCurrentIter->m_moduleQueueName; + } + + if (m_errorEventCurrentIter->m_loggingInfo.pid != 0) { + l_pidss << " PID: " << m_errorEventCurrentIter->m_loggingInfo.pid; + } + + + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-"); + return (l_hmiDispStr.str()); +} // LCOV_EXCL_BR_LINE 10:The final line + diff --git a/video_in_hal/systemservice/system_manager/server/src/ss_system_manager_error_event_responses.cpp b/video_in_hal/systemservice/system_manager/server/src/ss_system_manager_error_event_responses.cpp new file mode 100755 index 0000000..28e8dbf --- /dev/null +++ b/video_in_hal/systemservice/system_manager/server/src/ss_system_manager_error_event_responses.cpp @@ -0,0 +1,1007 @@ +/* + * @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 SS_SM_Logging +/// \brief This file supports SM logging. +/// +/////////////////////////////////////////////////////////////////////////////// +#include <native_service/frameworkunified_types.h> +#include <native_service/ns_plogger_if.h> +#include <stub/ss_diag.h> +#include <system_service/ss_ver.h> +#include <system_service/ss_services.h> +#include <system_service/ss_templates.h> +#include <system_service/ss_client_names.h> +#include <system_service/ss_sm_client_if.h> + +#include <stdint.h> +#include <sys/stat.h> +#include <sys/types.h> +#include <sys/statvfs.h> +#include <fcntl.h> +#include <dirent.h> +#include <errno.h> +#include <sys/wait.h> +#include <boost/algorithm/string.hpp> +#include <fstream> +#include <iostream> +#include <iomanip> +#include <string> +#include <list> + +#include "ss_system_manager.h" + +/////////////////////////////////////////////////////////////////////////// +// Function : OnObtainLoggerserviceLogRequest +// brief : Collect frameworkunifiedlog artifact and return a response to +// SS_Logger. +/////////////////////////////////////////////////////////////////////////// +static int getExecedString(char* const argv[], std::stringstream &ss) { + int ret; + int pipeFd[2]; // 0:read, 1:write + pid_t pid; + ret = pipe(pipeFd); + if (ret != 0) { // LCOV_EXCL_BR_LINE 5:pipe's error case + // LCOV_EXCL_START 5:pipe's error case + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200:test assert + SS_ASERT_ERRNO(0); // LCOV_EXCL_BR_LINE 15: marco defined in ss_templates.h // NOLINT(whitespace/line_length) + goto error_exit; + // LCOV_EXCL_STOP + } + + pid = fork(); + if (pid == -1) { // LCOV_EXCL_BR_LINE 5:fork's error case + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200:test assert + SS_ASERT_ERRNO(0); // LCOV_EXCL_LINE 15: marco defined in ss_templates.h // NOLINT(whitespace/line_length) + } else if (pid == 0) { + close(pipeFd[0]); // unnecessary pile (closing read) + close(1); // closing stdout + dup2(pipeFd[1], 1); // take stdout to pipe + execve(argv[0], argv, environ); + SS_ASERT_ERRNO(0); // LCOV_EXCL_BR_LINE 15: marco defined in ss_templates.h // NOLINT(whitespace/line_length) + exit(EXIT_FAILURE); + } else { + char readBuf[256]; + ssize_t rs; + SS_ASERT_ERRNO(0 == close(pipeFd[1])); // LCOV_EXCL_BR_LINE 15: marco defined in ss_templates.h // NOLINT(whitespace/line_length) + + fd_set rfds; + FD_ZERO(&rfds); // LCOV_EXCL_BR_LINE 15: marco defined in ns_logger_if.h // NOLINT(whitespace/line_length) + FD_SET(pipeFd[0], &rfds); // LCOV_EXCL_BR_LINE 15: marco defined in ns_logger_if.h // NOLINT(whitespace/line_length) + struct timeval timeout; + timeout.tv_sec = 2; + timeout.tv_usec = 0; + + int selRet = select(pipeFd[0] + 1, &rfds, NULL, NULL, &timeout); + switch (selRet) { + case 1: + if (FD_ISSET(pipeFd[0], &rfds)) { + do { + rs = read(pipeFd[0], readBuf, sizeof(readBuf) - 1); + if (rs > 0) { + readBuf[rs] = '\0'; + ss << readBuf; + } else if (rs == -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 + if (errno != EINTR) { + SS_ASERT_ERRNO(0); // LCOV_EXCL_BR_LINE 15: marco defined in ss_templates.h // NOLINT(whitespace/line_length) + ret = -1; + break; + } + // LCOV_EXCL_STOP + } + } while (rs != 0); + } else { + SS_ASERT(0); // LCOV_EXCL_BR_LINE 15: marco defined in ss_templates.h // NOLINT(whitespace/line_length) + } + break; + case -1: + SS_ASERT_ERRNO(0); // LCOV_EXCL_BR_LINE 15: marco defined in ss_templates.h // NOLINT(whitespace/line_length) + break; + default: + // LCOV_EXCL_START 5:never be this case + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200:test assert + if (0 == selRet) { + ss << "timeout" << std::endl; + } else { + ss << "ERR:rslt=" << selRet << std::endl; + } + break; + // LCOV_EXCL_STOP + } + + // SM leaves processing to OnProcessExitDetected when using child process + // SS_ASERT_ERRNO(-1 != waitpid(pid,&status,0)); + } + SS_ASERT_ERRNO(0 == close(pipeFd[0])); // LCOV_EXCL_BR_LINE 15: marco defined in ss_templates.h // NOLINT(whitespace/line_length) +error_exit: + return ret; +} + +static int saveProcsMemInfo(std::ofstream &fo) { + DIR *dir = NULL; + int ret = 0; + + try { + struct dirent dent, *next; + // LCOV_EXCL_BR_START 11:unexpected branch // NOLINT(whitespace/line_length) + { + fo << "******** mem info **********" << std::endl; + std::ifstream fin("/proc/meminfo"); + std::string line; + while (fin && std::getline(fin, line)) { + fo << line << endl; + } + } + + { + fo << "******** slab info **********" << std::endl; + std::ifstream fin("/proc/slabinfo"); + std::string line; + while (fin && std::getline(fin, line)) { + fo << line << endl; + } + } + + { + fo << "******** zone info **********" << std::endl; + std::ifstream fin("/proc/zoneinfo"); + std::string line; + while (fin && std::getline(fin, line)) { + fo << line << endl; + } + } + // LCOV_EXCL_BR_STOP + + // Linux dependency codes + dir = opendir("/proc"); // LCOV_EXCL_BR_LINE 11:unexpected branch // NOLINT(whitespace/line_length) + if (dir == NULL) { // LCOV_EXCL_BR_LINE 5:opendir's error case + // LCOV_EXCL_START 11:opendir's error case + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200:test assert + SS_ASERT_ERRNO(0); // LCOV_EXCL_BR_LINE 15: marco defined in ss_templates.h // NOLINT(whitespace/line_length) + throw eFrameworkunifiedStatusFail; + // LCOV_EXCL_STOP + } + + fo << "******** proc status **********" << std::endl; + while (0 == readdir_r(dir, &dent, &next) && next) { + if (DT_DIR == dent.d_type) { + struct stat statbuf; + std::string statPath("/proc/"); // LCOV_EXCL_BR_LINE 11:unexpected branch // NOLINT(whitespace/line_length) + statPath += dent.d_name; + statPath += "/status"; + + if (stat(statPath.c_str(), &statbuf) == 0) { + std::ifstream fin(statPath.c_str()); // LCOV_EXCL_BR_LINE 11:unexpected branch // NOLINT(whitespace/line_length) + std::string line; + while (fin && std::getline(fin, line)) { + if (strstr(line.c_str(), "Name") != NULL + || strstr(line.c_str(), "Pid") != NULL + || strstr(line.c_str(), "Vm") != NULL) { + fo << line << endl; + } + } + fo << "************************************" << std::endl; + } + } + } + SS_ASERT_ERRNO(0 == closedir(dir)); // LCOV_EXCL_BR_LINE 15: marco defined in ss_templates.h // NOLINT(whitespace/line_length) + } catch (...) { + if (dir) { // LCOV_EXCL_BR_LINE 5:opendir's error case + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200:test assert + SS_ASERT_ERRNO(0 == closedir(dir)); // LCOV_EXCL_LINE 15: marco defined in ss_templates.h // NOLINT(whitespace/line_length) + } + ret = -1; + } + return ret; +} + +/////////////////////////////////////////////////////////////////////////// +// Function : OnObtainLoggerserviceLogRequest +// brief : Collect frameworkunifiedlog artifact and return a response to +// SS_Logger. +/////////////////////////////////////////////////////////////////////////// +EFrameworkunifiedStatus CSystemManager::SendLogArtifactResponseToLogger(HANDLE f_hApp, + EArtifactId f_artifactId, std::string f_artifactFilePathAndName) { + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+"); + EFrameworkunifiedStatus l_eStatus; + HANDLE l_hLoggerServiceSession; + ModuleLaunchListIter l_ModuleListIter; + ARTIFACT_RESPONSE l_artifactResponse; + + l_artifactResponse.ArtifactId = f_artifactId; + + strncpy(l_artifactResponse.FilePathAndName, + f_artifactFilePathAndName.c_str(), + sizeof(l_artifactResponse.FilePathAndName) - 1); + + if (eFrameworkunifiedStatusOK + != (l_eStatus = GetModuleIterator(SERVICE_LOGGER, l_ModuleListIter))) { + FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, + " Error: GetModuleIterator(%s) errored: %d/'%s'", + SERVICE_LOGGER, l_eStatus, GetStr(l_eStatus).c_str()); + } else { + l_hLoggerServiceSession = l_ModuleListIter->hsession; + + l_eStatus = FrameworkunifiedSendMsg(l_hLoggerServiceSession, + SS_SM_ERROR_EVENT_ARTIFACT_RSPN, sizeof(l_artifactResponse), + &l_artifactResponse); + + LOG_ERROR_REC_HIST_IF_ERRORED(l_eStatus, // LCOV_EXCL_BR_LINE 15: marco defined in ss_system_manager.h // NOLINT(whitespace/line_length) + "FrameworkunifiedSendMsg(SS_SM_ERROR_EVENT_ARTIFACT_RSPN)"); // LCOV_EXCL_BR_LINE 15: marco defined in ss_system_manager.h // NOLINT(whitespace/line_length) + } + + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-"); + return (l_eStatus); +} + +/////////////////////////////////////////////////////////////////////////////// +/// \ingroup OnErrorEventArtifactRequest +/// Dispatch logging requests to the various handlers. +/// +/// \param f_hApp Framework application handle. +/// +/// \return EFrameworkunifiedStatus +/// Success ==> eFrameworkunifiedStatusOK +/// Failure ==> Other values +/////////////////////////////////////////////////////////////////////////////// +EFrameworkunifiedStatus CSystemManager::OnErrorEventArtifactRequest(HANDLE hApp) { + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+"); + EFrameworkunifiedStatus l_eStatus; + INTERFACEUNIFIEDLOG_RECEIVED_FROM(hApp); // LCOV_EXCL_BR_LINE 15: marco defined in ss_templates.h // NOLINT(whitespace/line_length) + + if (eFrameworkunifiedStatusOK + != (l_eStatus = ReadMsg < EArtifactId + > (hApp, m_requestedArtifactId))) { // LCOV_EXCL_BR_LINE 200:NSFW error case + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200:test assert + LOG_ERROR("ReadMsg()"); // LCOV_EXCL_LINE 15: marco defined in ss_templates.h // NOLINT(whitespace/line_length) + } else { + switch (m_requestedArtifactId) { + case eArtifactIdBootMicroLog: + l_eStatus = OnObtainBootMicroLog(hApp); + LOG_ERROR_REC_HIST_IF_ERRORED(l_eStatus, "OnObtainBootMicroLog()"); // LCOV_EXCL_BR_LINE 15: marco defined in ss_system_manager.h // NOLINT(whitespace/line_length) + break; + + case eArtifactIdSystemDataCsv: + l_eStatus = OnObtainSystemmanagerSystemDataCsv(hApp); + LOG_ERROR_REC_HIST_IF_ERRORED(l_eStatus, "OnObtainSystemmanagerSystemDataCsv()"); // LCOV_EXCL_BR_LINE 15: marco defined in ss_system_manager.h // NOLINT(whitespace/line_length) + break; + + case eArtifactIdShowMemTxt: + l_eStatus = OnObtainShowMemTxt(hApp); + LOG_ERROR_REC_HIST_IF_ERRORED(l_eStatus, "OnObtainShowMemTxt()"); // LCOV_EXCL_BR_LINE 15: marco defined in ss_system_manager.h // NOLINT(whitespace/line_length) + break; + + case eArtifactIdProcessCore: + SS_ASERT(0); // Never called in Linux PF // LCOV_EXCL_BR_LINE 15: marco defined in ss_templates.h // NOLINT(whitespace/line_length) + break; + + case eArtifactIdDebugDumpLog: + l_eStatus = OnObtainDebugDumpLog(hApp); + LOG_ERROR_REC_HIST_IF_ERRORED(l_eStatus, "OnObtainDebugDumpLog()"); // LCOV_EXCL_BR_LINE 15: marco defined in ss_system_manager.h // NOLINT(whitespace/line_length) + break; + + default: + FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, + " Error: Unsupported logging artifact requested: %d.", + m_requestedArtifactId); + break; + } + } + + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-"); + return (l_eStatus); +} + +/////////////////////////////////////////////////////////////////////////////// +/// \ingroup OnObtainBootMicroLog +/// Obtain the boot micro log content, write file to disk, and send filename to SL. +/// +/// \param [in] f_hApp - Application handle. +/// +/// \return EFrameworkunifiedStatus +/// Success ==> eFrameworkunifiedStatusOK +/// Failure ==> Other values +/////////////////////////////////////////////////////////////////////////////// +EFrameworkunifiedStatus CSystemManager::OnObtainBootMicroLog(HANDLE f_hApp) { + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+"); + EFrameworkunifiedStatus l_eStatus; + INTERFACEUNIFIEDLOG_RECEIVED_FROM(f_hApp); // LCOV_EXCL_BR_LINE 15: marco defined in ss_templates.h // NOLINT(whitespace/line_length) + FRAMEWORKUNIFIEDLOG(ZONE_STATE, __FUNCTION__, "from %s", FrameworkunifiedGetMsgSrc(f_hApp)); + + l_eStatus = RequestBootMicroLog(f_hApp); + LOG_ERROR_REC_HIST_IF_ERRORED(l_eStatus, "RequestBootMicroLog"); // LCOV_EXCL_BR_LINE 15: marco defined in ss_system_manager.h // NOLINT(whitespace/line_length) + + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-"); + return (l_eStatus); +} + +/////////////////////////////////////////////////////////////////////////////// +/// \ingroup OnBootMicroLogResponse +/// Boot micro log response sent from the logging shadow. +/// +/// \param [in] f_hApp - Application handle. +/// +/// \return EFrameworkunifiedStatus +/// Success ==> eFrameworkunifiedStatusOK +/// Failure ==> Other values +/////////////////////////////////////////////////////////////////////////////// +EFrameworkunifiedStatus CSystemManager::OnBootMicroLogResponse(HANDLE f_hApp) { + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+"); + EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK; + UI_32 l_len; + std::string l_artifactFilePathAndName; + + m_errorEventTimers[eSM_ERROR_EVENT_TIMER_BOOT_MICRO_LOG_RSPN].Stop(); // LCOV_EXCL_BR_LINE 11:unexpected branch // NOLINT(whitespace/line_length) + + INTERFACEUNIFIEDLOG_RECEIVED_FROM(f_hApp); // LCOV_EXCL_BR_LINE 15: marco defined in ss_templates.h // NOLINT(whitespace/line_length) + FRAMEWORKUNIFIEDLOG(ZONE_STATE, __FUNCTION__, "from %s", FrameworkunifiedGetMsgSrc(f_hApp)); + + if (0 == strcmp(TIMER_SERVICE_NAME, FrameworkunifiedGetMsgSrc(f_hApp))) { + FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__, + " Info. Timer expired while waiting for the boot micro log."); + } else if (0 == (l_len = FrameworkunifiedGetMsgLength(f_hApp))) { // LCOV_EXCL_BR_LINE 200:restricted by ss_sm_client + // LCOV_EXCL_START 200:restricted by ss_sm_client + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200:test assert + FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, + " Error: Invalid log response received. Length cannot be 0."); + // LCOV_EXCL_STOP + } else { + char l_buf[l_len]; // NOLINT + l_eStatus = FrameworkunifiedGetMsgDataOfSize(f_hApp, l_buf, static_cast<UI_32>(sizeof(l_buf)), eSMRRelease); // LCOV_EXCL_BR_LINE 11:unexpected branch // NOLINT(whitespace/line_length) + if (eFrameworkunifiedStatusOK != l_eStatus) { // LCOV_EXCL_BR_LINE 200:NSFW error case + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200:test assert + LOG_ERROR("FrameworkunifiedGetMsgDataOfSize()"); // LCOV_EXCL_LINE 15: marco defined in ss_templates.h // NOLINT(whitespace/line_length) + } else { + l_artifactFilePathAndName = "/tmp/bootmicro.log"; + l_len = static_cast<UI_32>(strlen((const char *) l_buf)); + std::ofstream l_stream(l_artifactFilePathAndName.c_str()); // LCOV_EXCL_BR_LINE 11:unexpected branch // NOLINT(whitespace/line_length) + l_stream.write(l_buf, l_len); // LCOV_EXCL_BR_LINE 11:unexpected branch // NOLINT(whitespace/line_length) + l_stream.close(); // LCOV_EXCL_BR_LINE 11:unexpected branch // NOLINT(whitespace/line_length) + } + } + + l_eStatus = SendLogArtifactResponseToLogger(f_hApp, m_requestedArtifactId, + l_artifactFilePathAndName); // LCOV_EXCL_BR_LINE 11:unexpected branch // NOLINT(whitespace/line_length) + + if (l_eStatus != eFrameworkunifiedStatusOK) { + FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, + " Error: SendLogArtifactResponseToLogger(Artifact '%d', '%s') " + "errored: %d/'%s'", m_requestedArtifactId, + l_artifactFilePathAndName.c_str(), l_eStatus, + GetStr(l_eStatus).c_str()); + } + + return (l_eStatus); +} + +/////////////////////////////////////////////////////////////////////////////// +/// \ingroup OnErrorEventBootMicroLogResponseTimeout +/// Called when the boot micro log request timer expires (e.g. no response). +/// +/// \param [in] f_hApp - Application handle. +/// +/// \return EFrameworkunifiedStatus +/// Success ==> eFrameworkunifiedStatusOK +/// Failure ==> Other values +/////////////////////////////////////////////////////////////////////////////// +EFrameworkunifiedStatus CSystemManager::OnErrorEventBootMicroLogResponseTimeout(HANDLE f_hApp) { + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+"); + EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK; + std::string l_artifactFilePathAndName = ""; + + FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, + " Error: Boot micro log response timed out. Sending empty artifact response to SSL."); + + l_eStatus = SendLogArtifactResponseToLogger(f_hApp, m_requestedArtifactId, + l_artifactFilePathAndName); // LCOV_EXCL_BR_LINE 11:unexpected branch // NOLINT(whitespace/line_length) + + if (l_eStatus != eFrameworkunifiedStatusOK) { + FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, + " Error: SendLogArtifactResponseToLogger(Artifact '%d', '%s') " + "errored: %d/'%s'", m_requestedArtifactId, + l_artifactFilePathAndName.c_str(), l_eStatus, + GetStr(l_eStatus).c_str()); + } + + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-"); + return (l_eStatus); +} + +/////////////////////////////////////////////////////////////////////////////// +/// \ingroup OnObtainSystemmanagerSystemDataCsv +/// Obtain system content, write file to disk, and send filename to SL. +/// +/// \param [in] f_hApp - Application handle. +/// +/// \return EFrameworkunifiedStatus +/// Success ==> eFrameworkunifiedStatusOK +/// Failure ==> Other values +/////////////////////////////////////////////////////////////////////////////// +EFrameworkunifiedStatus CSystemManager::OnObtainSystemmanagerSystemDataCsv(HANDLE f_hApp) { + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+"); + EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK; + // std::string l_artifactFilePathAndName = "/tmp/frameworkunified_systemdata.csv"; + // std::ofstream l_stream(l_artifactFilePathAndName.c_str()); + std::stringstream l_stream; + char *l_pSignalName; + INTERFACEUNIFIEDLOG_RECEIVED_FROM(f_hApp); // LCOV_EXCL_BR_LINE 15: marco defined in ss_templates.h // NOLINT(whitespace/line_length) + + // Output version info + { + // LCOV_EXCL_BR_START 11:unexpected branch // NOLINT(whitespace/line_length) + CSSVer ver; + l_stream << "********** PACKAGE VERSIONS **********\n"; + l_stream << left; + l_stream << setw(16) << "PACKAGE" << setw(24) << "VERSION" << setw(10) + << "DATE" << endl; + for (SSVerPkgListIter ite = ver.begin(); ite != ver.end(); ite++) { + l_stream << setw(16) << ite->first; + l_stream << setw(24) << ite->second.version; + l_stream << setw(10) << ite->second.date << std::endl; + } + // LCOV_EXCL_BR_STOP + FRAMEWORKUNIFIEDLOG(ZONE_SYSLOG, __FUNCTION__, "\n%s", l_stream.str().c_str()); + l_stream.str(""); // LCOV_EXCL_BR_LINE 11:unexpected branch // NOLINT(whitespace/line_length) + l_stream.clear(); // LCOV_EXCL_BR_LINE 11:unexpected branch // NOLINT(whitespace/line_length) + } + + // LCOV_EXCL_BR_START 11:unexpected branch // NOLINT(whitespace/line_length) + l_stream << "********** Error Description Start ***********" << endl; + l_stream << "Error Event Type," + << GetStr(m_errorEventCurrentIter->m_eventType) << endl; + l_stream << m_errorEventCurrentIter->m_eventEnqueueTimeStamp.c_str() << endl; + l_stream << "MessageStr," + << m_errorEventCurrentIter->m_loggingInfo.messageStr.c_str() << endl; + // LCOV_EXCL_BR_STOP + + { + UI_32 l_ErrLogCount = 0; + if (PowerHalGetResetInfo(AGL_ERRLOG_COUNTER, &l_ErrLogCount)) { // LCOV_EXCL_BR_LINE 11:Gcov constraints (because exception-handling routes are automatically generated) + FRAMEWORKUNIFIEDLOG(ZONE_SYSLOG, __FUNCTION__, + "Could not get AGL_ERRLOG_COUNTER from power_hal."); + } + + { + l_stream << "ErrLogCount," << l_ErrLogCount << "/" + << SS_SM_ERR_LOGGING_LIMIT << endl; // LCOV_EXCL_BR_LINE 11:unexpected branch // NOLINT(whitespace/line_length) + } + } + + switch (m_errorEventCurrentIter->m_eventType) { + case eErrorEventTypeProcessCrash: + l_stream << "Crash Failure Binary Name," + << m_errorEventCurrentIter->m_loggingInfo.binaryFileName << endl; // LCOV_EXCL_BR_LINE 11:unexpected branch // NOLINT(whitespace/line_length) + l_stream << "Module PID," << m_errorEventCurrentIter->m_loggingInfo.pid << endl; + l_stream << "Exit Value," + << m_errorEventCurrentIter->m_loggingInfo.exitValue << endl; // LCOV_EXCL_BR_LINE 11:unexpected branch // NOLINT(whitespace/line_length) + + l_pSignalName = strsignal( + m_errorEventCurrentIter->m_loggingInfo.signalNumber); + if (NULL != l_pSignalName) { + l_stream << "Exit Signal," + << m_errorEventCurrentIter->m_loggingInfo.signalNumber // LCOV_EXCL_BR_LINE 11:unexpected branch // NOLINT(whitespace/line_length) + << "," << l_pSignalName << endl; // LCOV_EXCL_BR_LINE 11:unexpected branch // NOLINT(whitespace/line_length) + } + + break; + + case eErrorEventTypeProcessExit: + l_stream << "Exit Binary Name," + << m_errorEventCurrentIter->m_loggingInfo.binaryFileName << endl; // LCOV_EXCL_BR_LINE 11:unexpected branch // NOLINT(whitespace/line_length) + l_stream << "Module PID," << m_errorEventCurrentIter->m_loggingInfo.pid << endl; // LCOV_EXCL_BR_LINE 11:unexpected branch // NOLINT(whitespace/line_length) + l_stream << "Exit Value," + << m_errorEventCurrentIter->m_loggingInfo.exitValue << endl; // LCOV_EXCL_BR_LINE 11:unexpected branch // NOLINT(whitespace/line_length) + break; + + case eErrorEventTypeHeartBeatFailure: + l_stream << "HB Failure Module Queue Name," + << m_errorEventCurrentIter->m_moduleQueueName.c_str() << endl; // LCOV_EXCL_BR_LINE 11:unexpected branch // NOLINT(whitespace/line_length) + l_stream << "***************** HB Information Start *******************" << endl; // LCOV_EXCL_BR_LINE 11:unexpected branch // NOLINT(whitespace/line_length) + l_stream << "Entire State," << m_HBReport.eEntireState << endl; // LCOV_EXCL_BR_LINE 11:unexpected branch // NOLINT(whitespace/line_length) + l_stream << "Module Name,HB State,Retry Count" << endl; // LCOV_EXCL_BR_LINE 11:unexpected branch // NOLINT(whitespace/line_length) + + for (UI_32 i = 0; i < m_HBReport.nNumOfModules; i++) { + if (0 != m_HBReport.tModuleList[i].HeartBeatRetryCount) { + l_stream << m_HBReport.tModuleList[i].ProcQueueName << "," // LCOV_EXCL_BR_LINE 11:unexpected branch // NOLINT(whitespace/line_length) + << m_HBReport.tModuleList[i].ProcHBState << "," // LCOV_EXCL_BR_LINE 11:unexpected branch // NOLINT(whitespace/line_length) + << m_HBReport.tModuleList[i].HeartBeatRetryCount // LCOV_EXCL_BR_LINE 11:unexpected branch // NOLINT(whitespace/line_length) + << endl; // LCOV_EXCL_BR_LINE 11:unexpected branch // NOLINT(whitespace/line_length) + } + } + l_stream << "***************** HB Information End *******************" << endl; + break; + + case eErrorEventTypeSystemLowMemory: + l_stream << "Free Memory Available (Byte)," << m_FreeMemAvailable << endl; + break; + + case eErrorEventTypeBootMicroReset: + l_stream << "Boot Micro Reset Reason," << m_BootMicroResetReason << endl; // LCOV_EXCL_BR_LINE 11:unexpected branch // NOLINT(whitespace/line_length) + break; + + case eErrorEventTypeModConnFailed: + l_stream << "Failed Module Queue Name," + << m_errorEventCurrentIter->m_moduleQueueName.c_str() << endl; // LCOV_EXCL_BR_LINE 11:unexpected branch // NOLINT(whitespace/line_length) + break; + + case eErrorEventTypeStartRespFailed: + l_stream << "Failed Module Queue Name," + << m_errorEventCurrentIter->m_moduleQueueName.c_str() << endl; // LCOV_EXCL_BR_LINE 11:unexpected branch // NOLINT(whitespace/line_length) + break; + + // No additional event specific log information to add. + case eErrorEventTypeUserInvokedCollectAllLogs: + case eErrorEventTypeUserInvokedCollectScreenShot: + case eErrorEventTypeUserInvokedCollectInterfaceunifiedLogs: + case eErrorEventTypeUserInvokedUserForceReset: + case eErrorEventTypeUserInvokedCollectDevLogs: + default: + break; + } + + { + std::ifstream finNum("/proc/sys/vm/nr_oom_kill_process"); + std::string strNum; + if (finNum && std::getline(finNum, strNum)) { // LCOV_EXCL_BR_LINE 200:will not be this case + // LCOV_EXCL_START 200:will not be this case + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200:test assert + char *endptr = NULL; + long lNum = strtol(strNum.c_str(), &endptr, 10); // NOLINT + if (('\0' != *endptr) || (lNum < 0)) { + SS_ASERT(0); // LCOV_EXCL_BR_LINE 15: marco defined in ss_templates.h // NOLINT(whitespace/line_length) + } else { + l_stream << "nr_oom_kill_process," << strNum.c_str() << endl; // LCOV_EXCL_BR_LINE 11:unexpected branch // NOLINT(whitespace/line_length) + if (0 != lNum) { + std::ifstream finLast("/proc/sys/vm/last_oom_kill_victim"); // LCOV_EXCL_BR_LINE 11:unexpected branch // NOLINT(whitespace/line_length) + std::string strLast; + if (finLast && std::getline(finLast, strLast)) { + l_stream << "last_oom_kill_victim," << strLast.c_str() << endl; // LCOV_EXCL_BR_LINE 11:unexpected branch // NOLINT(whitespace/line_length) + } + } + } + } + // LCOV_EXCL_STOP + } + + l_stream << "********** Error Description End ***********" << endl << endl; + FRAMEWORKUNIFIEDLOG(ZONE_SYSLOG, __FUNCTION__, "\n%s", l_stream.str().c_str()); + + fprintf(stderr, "SS_SysManager/\n%s", l_stream.str().c_str()); // LCOV_EXCL_BR_LINE 11:unexpected branch // NOLINT(whitespace/line_length) + + l_stream.str(""); // LCOV_EXCL_BR_LINE 11:unexpected branch // NOLINT(whitespace/line_length) + l_stream.clear(); // LCOV_EXCL_BR_LINE 11:unexpected branch // NOLINT(whitespace/line_length) + + l_stream << "********** Variant Code Start ***********" << endl; + if (NULL != m_pVarCodeStr) { + l_stream << m_pVarCodeStr << endl; // LCOV_EXCL_BR_LINE 11:unexpected branch // NOLINT(whitespace/line_length) + } else { + l_stream << "Variant coding not available." << endl; + } + l_stream << "********** Variant Code End ***********" << endl << endl; + FRAMEWORKUNIFIEDLOG(ZONE_SYSLOG, __FUNCTION__, "\n%s", l_stream.str().c_str()); + l_stream.str(""); // LCOV_EXCL_BR_LINE 11:unexpected branch // NOLINT(whitespace/line_length) + l_stream.clear(); // LCOV_EXCL_BR_LINE 11:unexpected branch // NOLINT(whitespace/line_length) + + l_stream << "********** File System Information Start ***********" << endl; + l_stream << "== mounts info start==" << endl; + { + std::ifstream fin("/proc/mounts"); // LCOV_EXCL_BR_LINE 11:unexpected branch // NOLINT(whitespace/line_length) + std::string line; + while (fin && std::getline(fin, line)) { + l_stream << line << endl; + } + } + l_stream << "== mounts info end ==" << endl; + FRAMEWORKUNIFIEDLOG(ZONE_SYSLOG, __FUNCTION__, "\n%s", l_stream.str().c_str()); + l_stream.str(""); // LCOV_EXCL_BR_LINE 11:unexpected branch // NOLINT(whitespace/line_length) + l_stream.clear(); // LCOV_EXCL_BR_LINE 11:unexpected branch // NOLINT(whitespace/line_length) + + l_stream << "== DF info start==" << endl; + { + char* const argv[] = { const_cast<char*>("/bin/df"), const_cast<char*>("-a"), static_cast<char*>(NULL), }; + SS_ASERT(0 == getExecedString(argv, l_stream)); // LCOV_EXCL_BR_LINE 15: marco defined in ss_templates.h // NOLINT(whitespace/line_length) + } + l_stream << "== DF info end==" << endl; + + FRAMEWORKUNIFIEDLOG(ZONE_SYSLOG, __FUNCTION__, "\n%s", l_stream.str().c_str()); + l_stream.str(""); // LCOV_EXCL_BR_LINE 11:unexpected branch // NOLINT(whitespace/line_length) + l_stream.clear(); // LCOV_EXCL_BR_LINE 11:unexpected branch // NOLINT(whitespace/line_length) + +#if 0 // Need to install lsblk if requested so that it is not installed + l_stream << "== lsblk info start==" << endl; + { + char* const argv[] = { + const_cast<char*>("/usr/debug/bin/lsblk"), + const_cast<char*>("-o"), + const_cast<char*>("NAME,KNAME,MAJ:MIN,FSTYPE,PARTLABEL,MODEL,SERIAL,REV,VENDOR"), + const_cast<char*>(NULL), + }; + SS_ASERT(0 == getExecedString(argv, l_stream)); + } + l_stream << "== lsblk info end==" << endl; + FRAMEWORKUNIFIEDLOG(ZONE_SYSLOG, __FUNCTION__, "\n%s", l_stream.str().c_str()); + l_stream.str(""); + l_stream.clear(); +#endif + + l_stream << "== proc info start==" << endl; + { + char* const argv[] = { const_cast<char*>("/bin/ps"), const_cast<char*>("auxc"), + const_cast<char*>("-L"), static_cast<char*>(NULL), }; + SS_ASERT(0 == getExecedString(argv, l_stream)); // LCOV_EXCL_BR_LINE 15: marco defined in ss_templates.h // NOLINT(whitespace/line_length) + } + l_stream << "== proc info end==" << endl; + { + // Output is splitted so that the FRAMEWORKUNIFIEDLOG can not write data over 4K Bytes at a time + std::list<std::string> strList; + boost::split(strList, static_cast<const std::string>(l_stream.str()), + boost::is_any_of("\n")); // LCOV_EXCL_BR_LINE 11:unexpected branch // NOLINT(whitespace/line_length) + + int ii = 0; + std::stringstream ss; // LCOV_EXCL_BR_LINE 11:unexpected branch // NOLINT(whitespace/line_length) + for (std::list<std::string>::iterator ite = strList.begin(); + ite != strList.end(); ite++) { + ss << *ite << endl; + ii++; + if (ii > 20) { + FRAMEWORKUNIFIEDLOG(ZONE_SYSLOG, __FUNCTION__, "\n%s", ss.str().c_str()); + ss.str(""); // LCOV_EXCL_BR_LINE 11:unexpected branch // NOLINT(whitespace/line_length) + ss.clear(); // LCOV_EXCL_BR_LINE 11:unexpected branch // NOLINT(whitespace/line_length) + ii = 0; + } + } + FRAMEWORKUNIFIEDLOG(ZONE_SYSLOG, __FUNCTION__, "\n%s", ss.str().c_str()); + } + l_stream.str(""); // LCOV_EXCL_BR_LINE 11:unexpected branch // NOLINT(whitespace/line_length) + l_stream.clear(); // LCOV_EXCL_BR_LINE 11:unexpected branch // NOLINT(whitespace/line_length) + + l_eStatus = SendLogArtifactResponseToLogger(f_hApp, m_requestedArtifactId, ""); // LCOV_EXCL_BR_LINE 11:unexpected branch // NOLINT(whitespace/line_length) + + if (l_eStatus != eFrameworkunifiedStatusOK) { + FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, + " Error: SendLogArtifactResponseToLogger(Artifact '%d') " + "errored: %d/'%s'", m_requestedArtifactId, l_eStatus, + GetStr(l_eStatus).c_str()); + } + + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-"); + return (l_eStatus); +} + +/////////////////////////////////////////////////////////////////////////////// +/// \ingroup OnObtainShowMemTxt +/// Obtain showmem content, write file to disk, and send filename to SL. +/// +/// \param [in] f_hApp - Application handle. +/// +/// \return EFrameworkunifiedStatus +/// Success ==> eFrameworkunifiedStatusOK +/// Failure ==> Other values +/////////////////////////////////////////////////////////////////////////////// +EFrameworkunifiedStatus CSystemManager::OnObtainShowMemTxt(HANDLE f_hApp) { + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+"); + EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK; + INTERFACEUNIFIEDLOG_RECEIVED_FROM(f_hApp); // LCOV_EXCL_BR_LINE 15: marco defined in ns_logger_if.h // NOLINT(whitespace/line_length) + + std::string l_artifactFilePathAndName = "/tmp/showmem.txt"; + { + std::ofstream fo(l_artifactFilePathAndName.c_str()); // LCOV_EXCL_BR_LINE 11:unexpected branch // NOLINT(whitespace/line_length) + saveProcsMemInfo(fo); // LCOV_EXCL_BR_LINE 11:unexpected branch // NOLINT(whitespace/line_length) + } + + l_eStatus = SendLogArtifactResponseToLogger(f_hApp, m_requestedArtifactId, + l_artifactFilePathAndName); // LCOV_EXCL_BR_LINE 11:unexpected branch // NOLINT(whitespace/line_length) + + if (l_eStatus != eFrameworkunifiedStatusOK) { + FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, + " Error: SendLogArtifactResponseToLogger(Artifact '%d', '%s') " + "errored: %d/'%s'", m_requestedArtifactId, + l_artifactFilePathAndName.c_str(), l_eStatus, + GetStr(l_eStatus).c_str()); + } + + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-"); + return (l_eStatus); +} + +/////////////////////////////////////////////////////////////////////////////// +/// \ingroup OnErrorEventCoreFilePollTimeout +/// Called periodically to verify whether the process core file has completed +/// being written to disk. When complete, this function sends an artifact +/// response to SSL. +/// +/// \param [in] f_hApp - Application handle. +/// +/// \return EFrameworkunifiedStatus +/// Success ==> eFrameworkunifiedStatusOK +/// Failure ==> Other values +/////////////////////////////////////////////////////////////////////////////// +EFrameworkunifiedStatus CSystemManager::OnErrorEventCoreFilePollTimeout(HANDLE f_hApp) { // LCOV_EXCL_START 8:dead code + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200:test assert + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+"); + EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK; + BOOL l_sendResponse = FALSE; + std::string l_artifactFilePathAndName = ""; + std::ostringstream l_coreFilePathAndName; // LCOV_EXCL_BR_LINE 11:unexpected branch // NOLINT(whitespace/line_length) + +// struct stat l_fileInfo; + struct stat64 l_fileInfo; + int l_result; + off_t l_coreFileSize; + INTERFACEUNIFIEDLOG_RECEIVED_FROM(f_hApp); // LCOV_EXCL_BR_LINE 15: marco defined in ss_templates.h // NOLINT(whitespace/line_length) + + l_coreFilePathAndName << "/debug/" + << m_errorEventCurrentIter->m_loggingInfo.binaryFileName << ".core.gz"; // LCOV_EXCL_BR_LINE 11:unexpected branch // NOLINT(whitespace/line_length) + + +// l_result = stat(l_coreFilePathAndName.str().c_str(), &l_fileInfo); + l_result = stat64(l_coreFilePathAndName.str().c_str(), &l_fileInfo); + if (l_result == 0) { + l_coreFileSize = l_fileInfo.st_size; + if ((l_coreFileSize > m_coreFileSizeBytes) || // Core file grew from last read. + (l_coreFileSize == 0)) { // Core file not yet updated externally. + m_coreFileSizeBytes = l_coreFileSize; // Wait until file stops growing. + bool result = + m_errorEventTimers[eSM_ERROR_EVENT_TIMER_CORE_FILE_POLL].Start( // LCOV_EXCL_BR_LINE 11:unexpected branch // NOLINT(whitespace/line_length) + 0, SS_ERROR_EVENT_CORE_FILE_POLL_TO_MS, 0, 0); // LCOV_EXCL_BR_LINE 11:unexpected branch // NOLINT(whitespace/line_length) + if (FALSE == result) { + FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, + " Error: Failed to start timer SS_ERROR_EVENT_CORE_FILE_POLL_TO_MS."); + l_sendResponse = TRUE; + } else { + FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__, + " Info. Core file: %s, size: %ld still growing.", + l_coreFilePathAndName.str().c_str(), + m_coreFileSizeBytes); + + l_sendResponse = FALSE; + } + } else { // File has stopped growing. + FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__, + " Info. Core file: %s, size: %ld write complete. Sending artifact response.", + l_coreFilePathAndName.str().c_str(), m_coreFileSizeBytes); + + l_artifactFilePathAndName = l_coreFilePathAndName.str(); + l_sendResponse = TRUE; + } + } else { + FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, + " Info. Core file: %s, unable to determine size. Sending empty artifact response to SSL.", + l_coreFilePathAndName.str().c_str()); + + l_sendResponse = TRUE; + } + + if (TRUE == l_sendResponse) { + l_eStatus = SendLogArtifactResponseToLogger(f_hApp, // Error getting file size. Send empty path to SSL. + m_requestedArtifactId, l_artifactFilePathAndName); // LCOV_EXCL_BR_LINE 11:unexpected branch // NOLINT(whitespace/line_length) + + if (l_eStatus != eFrameworkunifiedStatusOK) { + FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, + " Error: SendLogArtifactResponseToLogger(Artifact '%d', '%s') " + "errored: %d/'%s'", m_requestedArtifactId, + l_artifactFilePathAndName.c_str(), l_eStatus, + GetStr(l_eStatus).c_str()); + } + } + + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-"); + return (l_eStatus); +} +// LCOV_EXCL_STOP + +/////////////////////////////////////////////////////////////////////////////// +/// \ingroup OnObtainDebugDumpLog +/// Obtain debug dump content, write file to disk, and send filename to SL. +/// See OnModuleDebugDumpResponse(). +/// +/// \param [in] f_hApp - Application handle. +/// +/// \return EFrameworkunifiedStatus +/// Success ==> eFrameworkunifiedStatusOK +/// Failure ==> Other values +/////////////////////////////////////////////////////////////////////////////// +EFrameworkunifiedStatus CSystemManager::OnObtainDebugDumpLog(HANDLE f_hApp) { + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+"); + EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK; + INTERFACEUNIFIEDLOG_RECEIVED_FROM(f_hApp); // LCOV_EXCL_BR_LINE 15: marco defined in ss_templates.h // NOLINT(whitespace/line_length) + + ModuleLaunchListIter l_moduleIter; + + m_NbrDebugDumpRspnRecv = 0; + + for (GroupLaunchMapIter l_GroupIter = m_MapProclaunchGrps.begin(); + l_GroupIter != m_MapProclaunchGrps.end(); l_GroupIter++) { + for (l_moduleIter = l_GroupIter->second.modules.begin(); + l_moduleIter != l_GroupIter->second.modules.end(); + l_moduleIter++) { + const BOOL isModuleConnected = l_moduleIter->IsModuleConnected(); // LCOV_EXCL_BR_LINE 11:Gcov constraints (because exception-handling routes are automatically generated) + if ((SERVICE_NS_NPP != l_moduleIter->name) && // NPP is a special case and does NOT session connect with SM. + (TRUE == isModuleConnected)) { + l_eStatus = FrameworkunifiedSendMsg(l_moduleIter->hsession, SS_SM_DEBUG_DUMP, + 0, NULL); + + if (eFrameworkunifiedStatusOK == l_eStatus) { // LCOV_EXCL_BR_LINE 200:NSFW error case + FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__, + " Info. FrameworkunifiedSendMsg(SS_SM_DEBUG_DUMP) to %s succeeded.", // LCOV_EXCL_BR_LINE 15: marco defined in ns_logger_if.h // NOLINT(whitespace/line_length) + l_moduleIter->name.c_str()); // LCOV_EXCL_BR_LINE 15: marco defined in ns_logger_if.h // NOLINT(whitespace/line_length) + } else { + // LCOV_EXCL_START 200:NSFW error case + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200:test assert + FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, + " Error: FrameworkunifiedSendMsg(%p, SS_SM_DEBUG_DUMP) to %s errored: %d/'%s'", + (void *) l_moduleIter->hsession, + l_moduleIter->name.c_str(), l_eStatus, + GetStr(l_eStatus).c_str()); + // LCOV_EXCL_STOP + } + } + } + } + + // Call debug dump handler for SM. + l_eStatus = OnSystemManagerDebugDump(f_hApp); + LOG_STATUS(l_eStatus, "OnSystemManagerDebugDump()"); // LCOV_EXCL_BR_LINE 15: marco defined in ss_templates.h // NOLINT(whitespace/line_length) + + // Refresh debug dump timeout timer after each debug dump response received. + // Non AGL framework modules will have the remaining time after the last + // received response to complete their debug dump. + bool result = + m_errorEventTimers[eSM_ERROR_EVENT_TIMER_DEBUG_DUMP_RSPN].Start( + SS_ERROR_EVENT_DEBUG_DUMP_RSPN_TO_SEC, 0, 0, 0); + if (FALSE == result) { // LCOV_EXCL_BR_LINE 200:will not be this case + // LCOV_EXCL_START 200:will not be this case + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200:test assert + FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, + " Error: Failed to start timer eSM_TIMER_DEBUG_DUMP_RSPN_MONITOR."); + // LCOV_EXCL_STOP + } + + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-"); + return (l_eStatus); +} + +/////////////////////////////////////////////////////////////////////////////// +/// \ingroup OnDebugDumpResponseReceived +/// Debug Dump complete Response handler. +/// See OnDebugDumpCompleteTimeout(). +/// +/// \param [in] f_hApp - Application handle. +/// +/// \return EFrameworkunifiedStatus +/// Success ==> eFrameworkunifiedStatusOK +/// Failure ==> Other values +/////////////////////////////////////////////////////////////////////////////// +EFrameworkunifiedStatus CSystemManager::OnDebugDumpResponseReceived(HANDLE f_hApp) { + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+"); + EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK; + ModuleLaunchListIter l_ModuleListIter; + UI_32 l_len; + INTERFACEUNIFIEDLOG_RECEIVED_FROM(f_hApp); // LCOV_EXCL_BR_LINE 15: marco defined in ns_logger_if.h // NOLINT(whitespace/line_length) + + std::string l_moduleName = FrameworkunifiedGetMsgSrc(f_hApp); + FRAMEWORKUNIFIEDLOG(ZONE_STATE, __FUNCTION__, "from %s", l_moduleName.c_str()); + + SetCmdHist("SS_SM_DEBUG_DUMP_RSPN", m_SMCmdHist, m_SMHistIter, FrameworkunifiedGetMsgSrc(f_hApp)); // LCOV_EXCL_BR_LINE 11:unexpected branch // NOLINT(whitespace/line_length) + + // SM is not launched by SM and is therefore not in the process list. + // SM does however use the same debug dump mechanism as other processes. + if (l_moduleName != SERVICE_SYSMANAGER) { + l_eStatus = GetModuleIterator(l_moduleName.c_str(), l_ModuleListIter); + if (eFrameworkunifiedStatusOK != l_eStatus) { + FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, + " Error: Module %s not found in Group Launch Map", l_moduleName.c_str()); + } else { + l_ModuleListIter->SetModuleDebugDumpState(MODULE_DEBUG_DUMP_STATE_RESPONSE_RECEIVED); + } + } + + if (0 == (l_len = FrameworkunifiedGetMsgLength(f_hApp))) { // LCOV_EXCL_BR_LINE 200:restricted by ss_sm_client + // LCOV_EXCL_START 200:restricted by ss_sm_client + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200:test assert + l_eStatus = eFrameworkunifiedStatusInvldBufSize; + LOG_ERROR("0 == FrameworkunifiedGetMsgLength(f_hApp)"); // LCOV_EXCL_BR_LINE 15: marco defined in ss_templates.h // NOLINT(whitespace/line_length) + // LCOV_EXCL_STOP + } else { + FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__, + " Received debug dump response from %s, size: %d bytes. " + "Total number of responses received: %d", + l_moduleName.c_str(), l_len, m_NbrDebugDumpRspnRecv); + + UI_8 l_buf[l_len]; // NOLINT + l_eStatus = FrameworkunifiedGetMsgDataOfSize(f_hApp, l_buf, static_cast<UI_32>(sizeof(l_buf)), + eSMRRelease); + if (eFrameworkunifiedStatusOK != l_eStatus) { + LOG_ERROR("FrameworkunifiedGetMsgDataOfSize()"); // LCOV_EXCL_BR_LINE 15: marco defined in ss_templates.h // NOLINT(whitespace/line_length) + } else { + ios_base::openmode l_mode; + if (0 == m_NbrDebugDumpRspnRecv) { + // Create new file. + l_mode = std::ios_base::trunc; + } else { + // Append existing file. + l_mode = std::ios_base::app; + } + + std::ofstream l_stream("/tmp/systemmanager_debugdump.log", l_mode); // LCOV_EXCL_BR_LINE 11:unexpected branch // NOLINT(whitespace/line_length) + l_stream << l_buf << endl; // LCOV_EXCL_BR_LINE 11:unexpected branch // NOLINT(whitespace/line_length) + l_stream.close(); // LCOV_EXCL_BR_LINE 11:unexpected branch // NOLINT(whitespace/line_length) + } + + m_NbrDebugDumpRspnRecv++; + + // Refresh debug dump timeout timer after each debug dump response received. + // Non AGL framework modules will have the remaining time after the last + // received response to complete their debug dump. + bool result = + m_errorEventTimers[eSM_ERROR_EVENT_TIMER_DEBUG_DUMP_RSPN].Start( // LCOV_EXCL_BR_LINE 11:unexpected branch // NOLINT(whitespace/line_length) + SS_ERROR_EVENT_DEBUG_DUMP_RSPN_TO_SEC, 0, 0, 0); // LCOV_EXCL_BR_LINE 11:unexpected branch // NOLINT(whitespace/line_length) + if (FALSE == result) { // LCOV_EXCL_BR_LINE 200:will not be this case + // LCOV_EXCL_START 200:will not be this case + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200:test assert + FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, + " Error: Failed to start timer eSM_TIMER_DEBUG_DUMP_RSPN_MONITOR."); + l_eStatus = OnDebugDumpCompleteTimeout(f_hApp); // LCOV_EXCL_BR_LINE 11:unexpected branch // NOLINT(whitespace/line_length) + LOG_ERROR_REC_HIST_IF_ERRORED(l_eStatus, // LCOV_EXCL_BR_LINE 15: marco defined in ss_system_manager.h // NOLINT(whitespace/line_length) + "OnDebugDumpCompleteTimeout()"); // LCOV_EXCL_BR_LINE 15: marco defined in ss_system_manager.h // NOLINT(whitespace/line_length) + // LCOV_EXCL_STOP + } + } + + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-"); + return l_eStatus; +} + +/////////////////////////////////////////////////////////////////////////////// +/// \ingroup OnDebugDumpCompleteTimeout +/// Called after the last debug dump message is received, or when the debug +/// dump monitor timer expires. +/// +/// \param [in] f_hApp - Application handle. +/// +/// \return EFrameworkunifiedStatus +/// Success ==> eFrameworkunifiedStatusOK +/// Failure ==> Other values +/////////////////////////////////////////////////////////////////////////////// +EFrameworkunifiedStatus CSystemManager::OnDebugDumpCompleteTimeout(HANDLE f_hApp) { + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+"); + EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK; + std::string l_artifactFilePathAndName = "/tmp/systemmanager_debugdump.log"; + INTERFACEUNIFIEDLOG_RECEIVED_FROM(f_hApp); // LCOV_EXCL_BR_LINE 15: marco defined in ss_templates.h // NOLINT(whitespace/line_length) + + m_errorEventTimers[eSM_ERROR_EVENT_TIMER_DEBUG_DUMP_RSPN].Stop(); // LCOV_EXCL_BR_LINE 11:unexpected branch // NOLINT(whitespace/line_length) + + FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__, "Received '%d' Debug Dump responses.", + m_NbrDebugDumpRspnRecv); + + l_eStatus = SendLogArtifactResponseToLogger(f_hApp, m_requestedArtifactId, + l_artifactFilePathAndName); // LCOV_EXCL_BR_LINE 11:unexpected branch // NOLINT(whitespace/line_length) + + if (l_eStatus != eFrameworkunifiedStatusOK) { + FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, + " Error: SendLogArtifactResponseToLogger(Artifact '%d', '%s') " + "errored: %d/'%s'", m_requestedArtifactId, + l_artifactFilePathAndName.c_str(), l_eStatus, + GetStr(l_eStatus).c_str()); + } + + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-"); + return l_eStatus; +} + diff --git a/video_in_hal/systemservice/system_manager/server/src/ss_system_manager_error_event_triggers.cpp b/video_in_hal/systemservice/system_manager/server/src/ss_system_manager_error_event_triggers.cpp new file mode 100755 index 0000000..385a628 --- /dev/null +++ b/video_in_hal/systemservice/system_manager/server/src/ss_system_manager_error_event_triggers.cpp @@ -0,0 +1,1093 @@ +/* + * @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_SystemManager +/// \brief This file provides support for IAT error event logging. +/// +/////////////////////////////////////////////////////////////////////////////// +#include <system_service/ss_system_manager_notifications.h> +#include <native_service/frameworkunified_framework_if.h> +#include <native_service/frameworkunified_multithreading.h> +#include <system_service/ss_services.h> +#include <system_service/ss_client_names.h> +#include <system_service/ss_power_service_if.h> +#include <processlauncher/ProcessLauncher_if.h> +#include <processlauncher/ss_sm_process_launcher_protocol.h> +#include <processlauncher/ss_sm_process_launcher.h> +#include <heartbeat/ss_hb_if.h> +#include <system_service/ss_heartbeat_service_protocol.h> +#include <string.h> +#include <system_service/ss_power_service_notifications.h> +#include <system_service/ss_power_service_protocol.h> +#include <stub/ss_diag.h> +#include <system_service/ss_test_clients.h> +#include <native_service/ns_np_service_protocol.h> +#include <native_service/frameworkunified_application.h> +#include <system_service/ss_sm_thread_names.h> +#include <system_service/ss_templates.h> +#include <native_service/ns_plogger_if.h> +#include <native_service/frameworkunified_thread_priority.h> +#include <native_service/ns_np_service_nor_persistence.h> +#include <native_service/cl_process.h> +#include <stdlib.h> +#include <stdio.h> +#include <fcntl.h> +#include <dirent.h> +#include <sys/mman.h> +#include <sys/procfs.h> +#include <libgen.h> +#include <spawn.h> +#include <errno.h> +#include <sys/timeb.h> +#include <string> +#include "ss_system_manager.h" +#include "ss_sm_systemmanagerlog.h" +#include "ss_sm_signals.h" +#include "ss_sm_default_paths.h" +#include "ss_sm_version.h" + +/////////////////////////////////////////////////////////////////////////////// +/// \ingroup OnHeartBeatErrorDetected +/// This function gets called when a heartbeat failure is detected. +/// +/// \param [in] f_hApp +/// HANDLE - Handle of the Client Application +/// +/// \return Status +/// EFrameworkunifiedStatus - success or error +/////////////////////////////////////////////////////////////////////////////// +EFrameworkunifiedStatus CSystemManager::OnHeartBeatErrorDetected(HANDLE f_hApp) { + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+"); + EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK; + BOOL l_resetRequired; + EErrorEventResetType l_resetType; + SMLoggingInfo l_loggingInfo; + std::string l_moduleBinaryName; + UI_32 l_ix; + THbReportData l_HBReport; + + INTERFACEUNIFIEDLOG_RECEIVED_FROM(f_hApp); // LCOV_EXCL_BR_LINE 15: marco defined in ss_templates.h // NOLINT(whitespace/line_length) + + if (eFrameworkunifiedStatusOK != (l_eStatus = ReadMsg < THbReportData > (f_hApp, l_HBReport))) { + LOG_ERROR("ReadMsg()"); // LCOV_EXCL_BR_LINE 15: marco defined in ss_templates.h // NOLINT(whitespace/line_length) + } else { + FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__, " Report contains : %d entries.", l_HBReport.nNumOfModules); + + for (l_ix = 0; l_ix < l_HBReport.nNumOfModules; l_ix++) { + if (HB_STATUS_TIMEOUT == l_HBReport.tModuleList[l_ix].ProcHBState) { + std::string l_moduleQueueName = l_HBReport.tModuleList[l_ix].ProcQueueName; // LCOV_EXCL_BR_LINE 11:unexpected branch // NOLINT(whitespace/line_length) + + m_HBReport.eEntireState = l_HBReport.eEntireState; + m_HBReport.nNumOfModules = l_HBReport.nNumOfModules; + memcpy(&m_HBReport.tModuleList[l_ix], &l_HBReport.tModuleList[l_ix], sizeof(TSmModuleInfo)); + + TEXT(__FUNCTION__, // LCOV_EXCL_BR_LINE 15: marco defined in ns_logger_if.h // NOLINT(whitespace/line_length) + " ERROR EVENT: Heartbeat error detected from: %s.", // LCOV_EXCL_BR_LINE 15: marco defined in ns_logger_if.h // NOLINT(whitespace/line_length) + l_moduleQueueName.c_str()); // LCOV_EXCL_BR_LINE 15: marco defined in ns_logger_if.h // NOLINT(whitespace/line_length) + + l_eStatus = GetBinaryNameOfProcess(l_moduleQueueName, l_moduleBinaryName); // LCOV_EXCL_BR_LINE 11:unexpected branch // NOLINT(whitespace/line_length) + + if (eFrameworkunifiedStatusOK != l_eStatus) { + FRAMEWORKUNIFIEDLOG(ZONE_WARN, __FUNCTION__, + " Warning. Unable to identify binary name for SM child process with queue name: %s." + " The process name will be missing from the .csv and the core file will not be archived.", + l_moduleQueueName.c_str()); + } else { + strncpy(l_loggingInfo.binaryFileName, + l_moduleBinaryName.c_str(), + sizeof(l_loggingInfo.binaryFileName) - 1); + } + + if (eFrameworkunifiedStatusOK != (l_eStatus = ActOnModuleFailure(f_hApp, l_moduleQueueName, l_resetRequired))) { + FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, + " Error. ActOnModuleFailure(%s,%d) errored: %d/'%s'", + l_moduleQueueName.c_str(), l_resetRequired, + l_eStatus, GetStr(l_eStatus).c_str()); + } + + l_resetType = + (FALSE == l_resetRequired) ? + eErrorEventResetTypeNone : + eErrorEventResetTypeHard; + + if (eErrorEventResetTypeNone != l_resetType) { + l_loggingInfo.resetReason = + e_SS_SM_CPU_RESET_REASON_GENERIC_ERR; + } + + l_eStatus = ErrorEventEnqueue(f_hApp, + eErrorEventTypeHeartBeatFailure, l_moduleQueueName, + l_resetType, l_loggingInfo); + + LOG_ERROR_REC_HIST_IF_ERRORED(l_eStatus, // LCOV_EXCL_BR_LINE 15: marco defined in ss_system_manager.h // NOLINT(whitespace/line_length) + "ErrorEventEnqueue(eErrorEventTypeHeartBeatFailure)"); // LCOV_EXCL_BR_LINE 15: marco defined in ss_system_manager.h // NOLINT(whitespace/line_length) + } + } + } + + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-"); + return (l_eStatus); +} + +/////////////////////////////////////////////////////////////////////////////// +/// \ingroup OnProcessTermDetected +/// +/// +/// +/// \param Handle to AGL application. +/// +/// \return EFrameworkunifiedStatus +/// Success ==> eFrameworkunifiedStatusOK +/// Failure ==> Other values +/////////////////////////////////////////////////////////////////////////////// +EFrameworkunifiedStatus CSystemManager::OnProcessTermDetected(HANDLE f_hApp) { + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+"); + EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK; + int l_clRet; + int l_count = 0; + + // When multiple child processes terminate, CL_ProcessCleanup() returns 1. If 1 is returned, it repeats. + do { + CL_ProcessCleanupInfo_t l_procInfo; + + l_count++; + + l_clRet = CL_ProcessCleanup(m_ClProcessSigFd, &l_procInfo); + if (l_clRet != 0 && l_clRet != 1) { + FRAMEWORKUNIFIEDLOG(ZONE_WARN, __FUNCTION__, + " Warning: CL_ProcessCleanup(%d):%s", l_clRet, + strerror(errno)); + l_eStatus = eFrameworkunifiedStatusFail; + break; + } + + FRAMEWORKUNIFIEDLOG(ZONE_STATE, __FUNCTION__, "PID:%d code:%d status:%d", + l_procInfo.pid, l_procInfo.code, l_procInfo.status); + + // Terminate a process group to reclaim descendants of an anomaly terminated process + SS_ASERT_ERRNO(0 == CL_ProcessAbortGroup(l_procInfo.pid)); // LCOV_EXCL_BR_LINE 15: marco defined in ss_templates.h // NOLINT(whitespace/line_length) + + BOOL bIsExited = (CLD_EXITED == l_procInfo.code) ? TRUE : FALSE; // LCOV_EXCL_BR_LINE 11:unexpected branch // NOLINT(whitespace/line_length) + SMProcessExitInfo l_procExitInfo; + memset(&l_procExitInfo, 0, sizeof(l_procExitInfo)); + l_procExitInfo.pid = l_procInfo.pid; + // Process exit value when si_code == CLD_EXITED, else delivered signal number. + l_procExitInfo.exitValue = l_procInfo.status; + l_procExitInfo.signalNumber = SS_SM_ABORT_SIGNAL; + + // If GroupRelaunch is required, kill the remaining services + SS_String l_moduleQueueName(""); + if (eFrameworkunifiedStatusOK == FindNameOfTerminatedProcess(l_procExitInfo.pid, l_moduleQueueName)) { + for (GroupRelaunchModuleListIter l_itr = + m_GroupRelaunchModuleList.begin(); + m_GroupRelaunchModuleList.end() != l_itr; l_itr++) { + if (l_itr->name == l_moduleQueueName) { + if (l_itr->bIsKilled) { // LCOV_EXCL_BR_LINE 200: relaunch module bIsKilled is always false + // LCOV_EXCL_START 200: relaunch module bIsKilled is always false + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + // Normal during forced Relaunch + l_procExitInfo.exitValue = SS_SM_EXIT_RELAUNCH; + bIsExited = TRUE; + l_itr->bIsKilled = FALSE; + // LCOV_EXCL_STOP + } else { + FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "GroupRelaunch(%d/%d)", + m_GroupRelaunchCount, m_GroupRelaunchLimit); + + if (m_GroupRelaunchCount < m_GroupRelaunchLimit) { + SS_ASERT( // LCOV_EXCL_BR_LINE 15: marco defined in ss_templates.h // NOLINT(whitespace/line_length) + FrameworkunifiedNPPublishNotification(f_hApp, // LCOV_EXCL_BR_LINE 15: marco defined in ss_templates.h // NOLINT(whitespace/line_length) + NTFY_SSNeedAplRestart, NULL, 0)); // LCOV_EXCL_BR_LINE 15: marco defined in ss_templates.h // NOLINT(whitespace/line_length) + + // Issue ErrorEvent + SMLoggingInfo l_loggingInfo; // LCOV_EXCL_BR_LINE 11:unexpected branch // NOLINT(whitespace/line_length) + SS_String l_moduleBinaryName(""); // LCOV_EXCL_BR_LINE 11:unexpected branch // NOLINT(whitespace/line_length) + + l_loggingInfo.pid = l_procExitInfo.pid; + l_loggingInfo.exitValue = l_procExitInfo.exitValue; + l_loggingInfo.signalNumber = SS_SM_ABORT_SIGNAL; + if (eFrameworkunifiedStatusOK != GetBinaryNameOfProcess(l_moduleQueueName, l_moduleBinaryName)) { // LCOV_EXCL_BR_LINE 200: cannot be error + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + SS_ASERT(0); // LCOV_EXCL_LINE 200: cannot be error + } else { + snprintf(l_loggingInfo.binaryFileName, + sizeof(l_loggingInfo.binaryFileName), + "%s", l_moduleBinaryName.c_str()); + } + + l_eStatus = ErrorEventEnqueue(f_hApp, + eErrorEventTypeGroupRelaunch, l_itr->name, + eErrorEventResetTypeNone, l_loggingInfo); + LOG_ERROR_REC_HIST_IF_ERRORED(l_eStatus, // LCOV_EXCL_BR_LINE 15: marco defined in ss_system_manager.h // NOLINT(whitespace/line_length) + "ErrorEventEnqueue()"); // LCOV_EXCL_BR_LINE 15: marco defined in ss_system_manager.h // NOLINT(whitespace/line_length) + + // Relaunch normally and do not leave anomaly LOGs + l_procExitInfo.exitValue = SS_SM_EXIT_RELAUNCH; + bIsExited = TRUE; + + for (GroupRelaunchModuleListIter l_itr = + m_GroupRelaunchModuleList.begin(); + m_GroupRelaunchModuleList.end() != l_itr; + l_itr++) { + if (l_itr->name != l_moduleQueueName) { // LCOV_EXCL_BR_LINE 200: name always be equal because of outer if judge // NOLINT(whitespace/line_length) + // LCOV_EXCL_START 200: name always be equal + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + ModuleLaunchListIter l_ModuleListIter; + if (eFrameworkunifiedStatusOK + != GetModuleIterator( + l_itr->name.c_str(), + l_ModuleListIter)) { + SS_ASERT(0); // LCOV_EXCL_BR_LINE 15: marco defined in ss_templates.h // NOLINT(whitespace/line_length) + } else { + killpg(l_ModuleListIter->pid, + SS_SM_TERMINATE_SIGNAL); + l_itr->bIsKilled = TRUE; + } + // LCOV_EXCL_STOP + } + } + + m_GroupRelaunchCount++; + } else { + // Reboot system + ModuleLaunchListIter l_ModuleListIter; + if (eFrameworkunifiedStatusOK == GetModuleIterator(l_moduleQueueName.c_str(), l_ModuleListIter)) { // LCOV_EXCL_BR_LINE 200:cannot be error // NOLINT(whitespace/line_length) + l_ModuleListIter->relaunch_count = l_ModuleListIter->retry_cnt; + } else { + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + SS_ASERT(0); // LCOV_EXCL_LINE 200: cannot be error + } + } + break; + } + } + } + } + + if (isPreLaunchedProcess(l_procExitInfo.pid)) { // LCOV_EXCL_BR_LINE 200:prelaunch mode is not valid at UT test //NOLINT (whitespace/line_length) + // LCOV_EXCL_START 200 :prelaunch mode is not valid at UT test + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + l_eStatus = OnPreLaunchedProcessTermDetected(f_hApp, l_procExitInfo, bIsExited); // LCOV_EXCL_BR_LINE 11:unexpected branch // NOLINT(whitespace/line_length) + if (eFrameworkunifiedStatusOK != l_eStatus) { + LOG_ERROR("OnPreLaunchedProcessTermDetected()"); // LCOV_EXCL_BR_LINE 15: marco defined in ss_templates.h // NOLINT(whitespace/line_length) + l_eStatus = eFrameworkunifiedStatusFail; + // If an error occurs here, the zombie process may be collected and continued. + } + // LCOV_EXCL_STOP + } else if (bIsExited) { + l_eStatus = OnProcessExitDetected(f_hApp, l_procExitInfo); // LCOV_EXCL_BR_LINE 11:unexpected branch // NOLINT(whitespace/line_length) + if (eFrameworkunifiedStatusOK != l_eStatus) { + LOG_ERROR("OnProcessExitDetected()"); // LCOV_EXCL_BR_LINE 15: marco defined in ss_templates.h // NOLINT(whitespace/line_length) + l_eStatus = eFrameworkunifiedStatusFail; + // If an error occurs here, the zombie process may be collected and continued. + } + } else { + l_eStatus = OnProcessCrashDetected(f_hApp, l_procExitInfo); // LCOV_EXCL_BR_LINE 11:unexpected branch // NOLINT(whitespace/line_length) + if (eFrameworkunifiedStatusOK != l_eStatus) { + LOG_ERROR("OnProcessCrashDetected()"); // LCOV_EXCL_BR_LINE 15: marco defined in ss_templates.h // NOLINT(whitespace/line_length) + l_eStatus = eFrameworkunifiedStatusFail; + // If an error occurs here, the zombie process may be collected and continued. + } + } + } while (l_clRet == 1 && l_count < 50); + + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-"); + return (l_eStatus); +} + +BOOL CSystemManager::isPreLaunchedProcess(int f_pid) { + BOOL l_bIsExist = FALSE; + + PreLaunchModuleListIter l_itr; + for (l_itr = m_PreLaunchModuleList.begin(); + m_PreLaunchModuleList.end() != l_itr; l_itr++) { + if (l_itr->pid == f_pid) { // LCOV_EXCL_BR_LINE 200:prelaunch mode is not valid at UT test //NOLINT (whitespace/line_length) + // LCOV_EXCL_START 200 :prelaunch mode is not valid at UT test + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + l_bIsExist = TRUE; + break; + // LCOV_EXCL_STOP + } + } + return l_bIsExist; +} + +EFrameworkunifiedStatus CSystemManager::OnPreLaunchedProcessTermDetected(HANDLE f_hApp, SMProcessExitInfo &f_procExitInfo, BOOL f_bIsExited) { // LCOV_EXCL_START 200 :prelaunch mode is not valid at UT test // NOLINT(whitespace/line_length) + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK; + + PreLaunchModuleListIter l_itr; + for (l_itr = m_PreLaunchModuleList.begin(); + m_PreLaunchModuleList.end() != l_itr; l_itr++) { + if (l_itr->pid == static_cast<int>(f_procExitInfo.pid)) { + break; + } + } + + try { + if (m_PreLaunchModuleList.end() == l_itr) { + SS_ASERT(0); // LCOV_EXCL_BR_LINE 15: marco defined in ss_templates.h // NOLINT(whitespace/line_length) + throw eFrameworkunifiedStatusFail; + } + + BOOL l_bIsNeedRelaunched = FALSE; + + if ((SS_SM_RELAUNCH_NO_LIMIT == l_itr->relaunchLimit) + || (l_itr->relaunchLimit > l_itr->relaunchCount)) { + l_itr->relaunchCount++; + FRAMEWORKUNIFIEDLOG(ZONE_STATE, __FUNCTION__, "Relaunch %s(%d/%d)", + l_itr->name.c_str(), l_itr->relaunchCount, + l_itr->relaunchLimit); + if (-1 == (l_itr->pid = l_itr->LaunchFunc())) { + FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "Relaunch %s Failed", + l_itr->name.c_str()); + } else { + l_bIsNeedRelaunched = TRUE; + } + } + + if (!l_bIsNeedRelaunched) { + if (l_itr->critical) { + SMLoggingInfo l_loggingInfo; // LCOV_EXCL_BR_LINE 11:unexpected branch // NOLINT(whitespace/line_length) + EErrorEventType l_ErrorType; + + l_itr->pid = -1; + + l_loggingInfo.pid = f_procExitInfo.pid; + l_loggingInfo.exitValue = f_procExitInfo.exitValue; + l_loggingInfo.signalNumber = f_procExitInfo.signalNumber; + l_loggingInfo.resetReason = + e_SS_SM_CPU_RESET_REASON_GENERIC_ERR; + snprintf(l_loggingInfo.binaryFileName, + sizeof(l_loggingInfo.binaryFileName), "%s", + l_itr->binaryFileName.c_str()); + + if (f_bIsExited) { + FRAMEWORKUNIFIEDLOG(ZONE_STATE, __FUNCTION__, "%s exited", + l_itr->name.c_str()); + l_ErrorType = eErrorEventTypeProcessExit; + } else { + FRAMEWORKUNIFIEDLOG(ZONE_STATE, __FUNCTION__, "%s crashed", + l_itr->name.c_str()); + l_ErrorType = eErrorEventTypeProcessCrash; + } + + l_eStatus = ErrorEventEnqueue(f_hApp, l_ErrorType, l_itr->name, + eErrorEventResetTypeHard, l_loggingInfo); + LOG_ERROR_REC_HIST_IF_ERRORED(l_eStatus, "ErrorEventEnqueue()"); // LCOV_EXCL_BR_LINE 15: marco defined in ss_system_manager.h // NOLINT(whitespace/line_length) + } else { + FRAMEWORKUNIFIEDLOG(ZONE_STATE, __FUNCTION__, "%s removed", + l_itr->name.c_str()); + l_itr->pid = -1; + } + } + } catch (EFrameworkunifiedStatus e) { + l_eStatus = e; + } + + return l_eStatus; +} +// LCOV_EXCL_STOP + +/////////////////////////////////////////////////////////////////////////////// +/// \ingroup OnProcessCrashDetected +/// Initiate logging and recovery for an abnormal process termination. +/// The terminated process may or may not be a child of system manager. +/// If the process is a child of SM, then a validation check must ensue +/// to ensure that the process crash is not the result of a failed heartbeat +/// and subsequent termination signal sent from System Manager. This function +/// is NOT called for processes that exit normally. +/// +/// See OnProcessCrashDetected. +/// +/// \param Handle to AGL application. +/// +/// \return EFrameworkunifiedStatus +/// Success ==> eFrameworkunifiedStatusOK +/// Failure ==> Other values +/////////////////////////////////////////////////////////////////////////////// +EFrameworkunifiedStatus CSystemManager::OnProcessCrashDetected(HANDLE f_hApp, + SMProcessExitInfo &f_procExitInfo) { + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+"); + EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusFail; + BOOL l_resetRequired = TRUE; + SS_String l_moduleQueueName(""); + SS_String l_moduleBinaryName(""); // LCOV_EXCL_BR_LINE 11:unexpected branch // NOLINT(whitespace/line_length) + EErrorEventResetType l_resetType; + + INTERFACEUNIFIEDLOG_RECEIVED_FROM(f_hApp); // LCOV_EXCL_BR_LINE 15: marco defined in ss_templates.h // NOLINT(whitespace/line_length) + + TEXT(__FUNCTION__, " PROCESS CRASH: Process PID: %d", f_procExitInfo.pid); // LCOV_EXCL_BR_LINE 15: marco defined in ss_templates.h // NOLINT(whitespace/line_length) + + if (eFrameworkunifiedStatusOK + != (l_eStatus = FindNameOfTerminatedProcess(f_procExitInfo.pid, l_moduleQueueName))) { + // Normally, logging COULD continue, but stopping logging also solves a PosixBasedOS001 errata + // where a process crashes and is removed from the SM process launch map and is ALSO + // detected by the exit detector as a 'normal' exit. The FindNameOfTerminatedProcess() + // will continue properly IF a crash and removal from the map has not occurred + // for the same process. + FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, + " Error. FindNameOfTerminatedProcess() returned error: %d/'%s' for PID: %d." + " No recovery possible. Logging has been suspended for this event.", + l_eStatus, GetStr(l_eStatus).c_str(), f_procExitInfo.pid); + } else { + l_eStatus = GetBinaryNameOfProcess(l_moduleQueueName, l_moduleBinaryName); // LCOV_EXCL_BR_LINE 11:unexpected branch // NOLINT(whitespace/line_length) + if (eFrameworkunifiedStatusOK != l_eStatus) { // LCOV_EXCL_BR_LINE 200: cannot be error + // LCOV_EXCL_START 200: cannot be error + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + FRAMEWORKUNIFIEDLOG(ZONE_WARN, __FUNCTION__, + " Warning. Unable to identify binary for SM child process PID: %d, Queue Name: %s." + " The process binary name will be missing from the .csv file.", + f_procExitInfo.pid, l_moduleQueueName.c_str()); + // LCOV_EXCL_STOP + } else { + strncpy(f_procExitInfo.binaryFileName, l_moduleBinaryName.c_str(), + sizeof(f_procExitInfo.binaryFileName) - 1); + + f_procExitInfo.binaryFileName[sizeof(f_procExitInfo.binaryFileName) - 1] = '\0'; + } + + if (eFrameworkunifiedStatusOK + != (l_eStatus = ActOnModuleFailure(f_hApp, l_moduleQueueName, + l_resetRequired))) { + FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, + " Error. ActOnModuleFailure(%s,%d) errored: %d/'%s'", + l_moduleQueueName.c_str(), l_resetRequired, l_eStatus, + GetStr(l_eStatus).c_str()); + } else { + FRAMEWORKUNIFIEDLOG(ZONE_STATE, __FUNCTION__, + "Info. ActOnModuleFailure() returned reset status: %d/'%s'.", + l_resetRequired, GetStr(l_resetRequired).c_str()); + } + + l_resetType = + (FALSE == l_resetRequired) ? + eErrorEventResetTypeNone : eErrorEventResetTypeHard; + + SMLoggingInfo l_loggingInfo; // LCOV_EXCL_BR_LINE 11:unexpected branch // NOLINT(whitespace/line_length) + + l_loggingInfo.pid = f_procExitInfo.pid; + l_loggingInfo.exitValue = f_procExitInfo.exitValue; + l_loggingInfo.signalNumber = f_procExitInfo.signalNumber; + snprintf(l_loggingInfo.binaryFileName, + sizeof(l_loggingInfo.binaryFileName), "%s", + f_procExitInfo.binaryFileName); + if (eErrorEventResetTypeNone != l_resetType) { + l_loggingInfo.resetReason = e_SS_SM_CPU_RESET_REASON_GENERIC_ERR; + } + + l_eStatus = ErrorEventEnqueue(f_hApp, eErrorEventTypeProcessCrash, + l_moduleQueueName, l_resetType, l_loggingInfo); + + LOG_ERROR_REC_HIST_IF_ERRORED(l_eStatus, // LCOV_EXCL_BR_LINE 15: marco defined in ss_system_manager.h // NOLINT(whitespace/line_length) + "ErrorEventEnqueue(eErrorEventTypeProcessCrash)"); // LCOV_EXCL_BR_LINE 15: marco defined in ss_system_manager.h // NOLINT(whitespace/line_length) + } + + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-"); + return (l_eStatus); +} + +/////////////////////////////////////////////////////////////////////////////// +/// \ingroup OnProcessExitDetected +/// Initiate logging and recovery for System Manager child processes that +/// exit normally via the last brace of main(), exit(), or have their last +/// thread exit. This function is NOT called for processes that terminate +/// unexpectedly. +/// +/// See OnProcessExitDetected. +/// +/// \param Handle to AGL application. +/// +/// \return EFrameworkunifiedStatus +/// Success ==> eFrameworkunifiedStatusOK +/// Failure ==> Other values +/////////////////////////////////////////////////////////////////////////////// +EFrameworkunifiedStatus CSystemManager::OnProcessExitDetected(HANDLE f_hApp, + SMProcessExitInfo &f_procExitInfo) { + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+"); + EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusFail; + SS_String l_moduleQueueName(""); + + INTERFACEUNIFIEDLOG_RECEIVED_FROM(f_hApp); // LCOV_EXCL_BR_LINE 15: marco defined in ss_templates.h // NOLINT(whitespace/line_length) + + TEXT(__FUNCTION__, "PROCESS EXIT: PID:%d exitValue:%d", f_procExitInfo.pid, // LCOV_EXCL_BR_LINE 15: marco defined in ss_templates.h // NOLINT(whitespace/line_length) + f_procExitInfo.exitValue); // LCOV_EXCL_BR_LINE 15: marco defined in ss_templates.h // NOLINT(whitespace/line_length) + + if (eFrameworkunifiedStatusOK + != (l_eStatus = FindNameOfTerminatedProcess(f_procExitInfo.pid, + l_moduleQueueName))) { + // This happens when SMs to EXEC debugging commands, etc. + // Since this is not an error, set LOGs to WARN levels and set the return codes to OK. + FRAMEWORKUNIFIEDLOG(ZONE_WARN, __FUNCTION__, "%s: pid:%d is unknown service", + GetStr(l_eStatus).c_str(), f_procExitInfo.pid); + l_eStatus = eFrameworkunifiedStatusOK; + } else { + if (0 == f_procExitInfo.exitValue) { + ModuleLaunchListIter l_moduleListIter; + + if (eFrameworkunifiedStatusOK != (l_eStatus = RemoveModuleEntryFromHB(f_hApp, l_moduleQueueName.c_str()))) { // 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: RemoveModuleEntryFromHB(%s) errored: %d/'%s'", + l_moduleQueueName.c_str(), l_eStatus, + GetStr(l_eStatus).c_str()); + // LCOV_EXCL_STOP + } + + l_eStatus = GetModuleIterator(l_moduleQueueName.c_str(), + l_moduleListIter); + if (eFrameworkunifiedStatusOK != l_eStatus) { // LCOV_EXCL_BR_LINE 200:cannot be error + // LCOV_EXCL_START 200:cannot be error + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, + " Error: Module %s not found in Group Launch Map", + l_moduleQueueName.c_str()); + // LCOV_EXCL_STOP + } else { + l_eStatus = SendRequestToLauncher(f_hApp, l_moduleListIter, // LCOV_EXCL_BR_LINE 11:unexpected branch // NOLINT(whitespace/line_length) + ePLThrdCmd_TERMINATE_MODULE_REQST, // LCOV_EXCL_BR_LINE 11:unexpected branch // NOLINT(whitespace/line_length) + "ePLThrdCmd_TERMINATE_MODULE_REQST"); // LCOV_EXCL_BR_LINE 11:unexpected branch // NOLINT(whitespace/line_length) + + LOG_ERROR_REC_HIST_IF_ERRORED(l_eStatus, // LCOV_EXCL_BR_LINE 15: marco defined in ss_system_manager.h // NOLINT(whitespace/line_length) + "SendRequestToLauncher()"); // LCOV_EXCL_BR_LINE 15: marco defined in ss_system_manager.h // NOLINT(whitespace/line_length) + + // Do not add relaunch_count for normal termination. + l_moduleListIter->relaunch_status = RelaunchSafe; + } + } else if (SS_SM_EXIT_RELAUNCH == f_procExitInfo.exitValue) { + ModuleLaunchListIter l_moduleListIter; + + if (eFrameworkunifiedStatusOK != (l_eStatus = RemoveModuleEntryFromHB(f_hApp, l_moduleQueueName.c_str()))) { // LCOV_EXCL_BR_LINE 4: nsfw error // NOLINT(whitespace/line_length) + // LCOV_EXCL_START 4: nsfw error + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, + " Error: RemoveModuleEntryFromHB(%s) errored: %d/'%s'", + l_moduleQueueName.c_str(), l_eStatus, + GetStr(l_eStatus).c_str()); + // LCOV_EXCL_STOP + } + + l_eStatus = GetModuleIterator(l_moduleQueueName.c_str(), + l_moduleListIter); + if (eFrameworkunifiedStatusOK != l_eStatus) { // LCOV_EXCL_BR_LINE 200:cannot be error + // LCOV_EXCL_START 200:cannot be error + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, + " Error: Module %s not found in Group Launch Map", + l_moduleQueueName.c_str()); + // LCOV_EXCL_STOP + } else { + l_eStatus = SendRequestToLauncher(f_hApp, l_moduleListIter, // LCOV_EXCL_BR_LINE 11:unexpected branch // NOLINT(whitespace/line_length) + ePLThrdCmd_RELAUNCH_MODULE_REQST, // LCOV_EXCL_BR_LINE 11:unexpected branch // NOLINT(whitespace/line_length) + "ePLThrdCmd_RELAUNCH_MODULE_REQST"); // LCOV_EXCL_BR_LINE 11:unexpected branch // NOLINT(whitespace/line_length) + + LOG_ERROR_REC_HIST_IF_ERRORED(l_eStatus, // LCOV_EXCL_BR_LINE 15: marco defined in ss_system_manager.h // NOLINT(whitespace/line_length) + "SendRequestToLauncher()"); // LCOV_EXCL_BR_LINE 15: marco defined in ss_system_manager.h // NOLINT(whitespace/line_length) + + // Do not add relaunch_count for normal Relaunch + l_moduleListIter->relaunch_status = RelaunchSafe; + } + } else { + SS_String l_moduleBinaryName(""); // LCOV_EXCL_BR_LINE 11:unexpected branch // NOLINT(whitespace/line_length) + BOOL l_resetRequired = TRUE; + EErrorEventResetType l_resetType; + + l_eStatus = GetBinaryNameOfProcess(l_moduleQueueName, l_moduleBinaryName); // LCOV_EXCL_BR_LINE 11:unexpected branch // NOLINT(whitespace/line_length) + if (eFrameworkunifiedStatusOK != l_eStatus) { // LCOV_EXCL_BR_LINE 200: cannot be error + // LCOV_EXCL_START 200: cannot be error + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + FRAMEWORKUNIFIEDLOG(ZONE_WARN, __FUNCTION__, + " Warning. Unable to identify binary for SM child process PID: %d, Queue Name: %s." + " The process binary name will be missing from the .csv file.", + f_procExitInfo.pid, l_moduleQueueName.c_str()); + // LCOV_EXCL_STOP + } else { + strncpy(f_procExitInfo.binaryFileName, + l_moduleBinaryName.c_str(), + sizeof(f_procExitInfo.binaryFileName) - 1); + + f_procExitInfo.binaryFileName[sizeof(f_procExitInfo.binaryFileName) + - 1] = '\0'; + } + + if (eFrameworkunifiedStatusOK + != (l_eStatus = ActOnModuleFailure(f_hApp, + l_moduleQueueName, l_resetRequired))) { + FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, + " Error. ActOnModuleFailure(%s,%d) errored: %d/'%s'", + l_moduleQueueName.c_str(), l_resetRequired, l_eStatus, + GetStr(l_eStatus).c_str()); + } + + l_resetType = + (FALSE == l_resetRequired) ? + eErrorEventResetTypeNone : eErrorEventResetTypeHard; + + SMLoggingInfo l_loggingInfo; // LCOV_EXCL_BR_LINE 11:unexpected branch // NOLINT(whitespace/line_length) + + l_loggingInfo.pid = f_procExitInfo.pid; + l_loggingInfo.exitValue = f_procExitInfo.exitValue; + l_loggingInfo.signalNumber = f_procExitInfo.signalNumber; + snprintf(l_loggingInfo.binaryFileName, + sizeof(l_loggingInfo.binaryFileName), "%s", + f_procExitInfo.binaryFileName); + if (eErrorEventResetTypeNone != l_resetType) { + l_loggingInfo.resetReason = e_SS_SM_CPU_RESET_REASON_GENERIC_ERR; + } + + l_eStatus = ErrorEventEnqueue(f_hApp, eErrorEventTypeProcessExit, + l_moduleQueueName, l_resetType, l_loggingInfo); + LOG_ERROR_REC_HIST_IF_ERRORED(l_eStatus, // LCOV_EXCL_BR_LINE 15: marco defined in ss_system_manager.h // NOLINT(whitespace/line_length) + "ErrorEventEnqueue(eErrorEventTypeProcessExit)"); // LCOV_EXCL_BR_LINE 15: marco defined in ss_system_manager.h // NOLINT(whitespace/line_length) + } + } + + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-"); + return (l_eStatus); +} + +/////////////////////////////////////////////////////////////////////////////// +/// \ingroup OnBootMicroResetNotification +/// Called from the logging shadow when the boot micro notifies the shadow of +/// an unexpected boot micro reset during the last power cycle. +/// +/// \param [in] hApp - Application handle. +/// +/// \return EFrameworkunifiedStatus +/// Success ==> eFrameworkunifiedStatusOK +/// Failure ==> Other values +/////////////////////////////////////////////////////////////////////////////// +EFrameworkunifiedStatus CSystemManager::OnBootMicroResetNotification(HANDLE hApp) { + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+"); + std::string l_moduleName; + EFrameworkunifiedStatus l_eStatus; + + INTERFACEUNIFIEDLOG_RECEIVED_FROM(hApp); // LCOV_EXCL_BR_LINE 15: marco defined in ss_templates.h // NOLINT(whitespace/line_length) + + if (eFrameworkunifiedStatusOK != (l_eStatus = ReadMsg < eSMBootMicroResetReason > (hApp, m_BootMicroResetReason))) { + LOG_ERROR("ReadMsg()"); // LCOV_EXCL_BR_LINE 15: marco defined in ss_templates.h // NOLINT(whitespace/line_length) + } else { + l_moduleName = FrameworkunifiedGetMsgSrc(hApp); // LCOV_EXCL_BR_LINE 11:unexpected branch // NOLINT(whitespace/line_length) + + TEXT(__FUNCTION__, // LCOV_EXCL_BR_LINE 15: marco defined in ns_logger_if.h // NOLINT(whitespace/line_length) + " ERROR EVENT: A boot micro reset has occurred. Reset reason: %d/'%s'.", // LCOV_EXCL_BR_LINE 15: marco defined in ns_logger_if.h // NOLINT(whitespace/line_length) + m_BootMicroResetReason, GetStr(m_BootMicroResetReason).c_str()); // LCOV_EXCL_BR_LINE 15: marco defined in ns_logger_if.h // NOLINT(whitespace/line_length) + + l_eStatus = ErrorEventEnqueue(hApp, eErrorEventTypeBootMicroReset, l_moduleName); // LCOV_EXCL_BR_LINE 11:unexpected branch // NOLINT(whitespace/line_length) + + LOG_ERROR_REC_HIST_IF_ERRORED(l_eStatus, // LCOV_EXCL_BR_LINE 15: marco defined in ss_system_manager.h // NOLINT(whitespace/line_length) + "ErrorEventEnqueue(eErrorEventTypeBootMicroReset)"); // LCOV_EXCL_BR_LINE 15: marco defined in ss_system_manager.h // NOLINT(whitespace/line_length) + } + + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-"); + return (l_eStatus); +} + +/////////////////////////////////////////////////////////////////////////////// +/// \ingroup RequestBootMicroLog +/// Request boot micro log from the logging shadow. +/// +/// \param [in] hApp - Application handle. +/// +/// \return EFrameworkunifiedStatus +/// Success ==> eFrameworkunifiedStatusOK +/// Failure ==> Other values +/////////////////////////////////////////////////////////////////////////////// +EFrameworkunifiedStatus CSystemManager::RequestBootMicroLog(HANDLE hApp) { + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+"); + EFrameworkunifiedStatus l_eStatus; + + l_eStatus = FrameworkunifiedPublishEvent(hApp, // Event received by PS Logging Shadow + SS_SM_BOOT_MICRO_LOG_REQ, + NULL, + NULL, 0); + + LOG_ERROR_REC_HIST_IF_ERRORED(l_eStatus, // LCOV_EXCL_BR_LINE 15: marco defined in ss_system_manager.h // NOLINT(whitespace/line_length) + "FrameworkunifiedPublishEvent(SS_SM_BOOT_MICRO_LOG_REQ)"); // LCOV_EXCL_BR_LINE 15: marco defined in ss_system_manager.h // NOLINT(whitespace/line_length) + + bool result = + m_errorEventTimers[eSM_ERROR_EVENT_TIMER_BOOT_MICRO_LOG_RSPN].Start( + SS_ERROR_EVENT_BOOT_MICRO_LOG_RESPONSE_TO_SEC, 0, 0, 0); + if (FALSE == result) { + FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, + " Error. Failed to start timer eSM_TIMER_BOOT_MICRO_LOG_RESPONSE."); + } + + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-"); + return (l_eStatus); +} + +/////////////////////////////////////////////////////////////////////////////// +/// \ingroup OnLowSystemMemory +/// Called when a low memory error has been detected. +/// +/// \param [in] hApp - Application handle. +/// +/// \return EFrameworkunifiedStatus +/// Success ==> eFrameworkunifiedStatusOK +/// Failure ==> Other values +/////////////////////////////////////////////////////////////////////////////// +EFrameworkunifiedStatus CSystemManager::OnLowSystemMemory(HANDLE hApp) { + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+"); + SysMem l_SysMem; + std::string l_moduleName; + EFrameworkunifiedStatus l_eStatus; + SMLoggingInfo l_loggingInfo; // LCOV_EXCL_BR_LINE 11:unexpected branch // NOLINT(whitespace/line_length) + + if (eFrameworkunifiedStatusOK != (l_eStatus = ReadMsg < SysMem > (hApp, l_SysMem))) { + LOG_ERROR("ReadMsg()"); // LCOV_EXCL_BR_LINE 15: marco defined in ss_templates.h // NOLINT(whitespace/line_length) + } else { + m_FreeMemAvailable = l_SysMem.FreeMemoryBytes; + + TEXT(__FUNCTION__, // LCOV_EXCL_BR_LINE 15: marco defined in ns_logger_if.h // NOLINT(whitespace/line_length) + " ERROR EVENT: System Low Memory detected. Remaining memory: %d.", // LCOV_EXCL_BR_LINE 15: marco defined in ns_logger_if.h // NOLINT(whitespace/line_length) + m_FreeMemAvailable); // LCOV_EXCL_BR_LINE 15: marco defined in ns_logger_if.h // NOLINT(whitespace/line_length) + + l_moduleName = FrameworkunifiedGetMsgSrc(hApp); // LCOV_EXCL_BR_LINE 11:unexpected branch // NOLINT(whitespace/line_length) + l_loggingInfo.resetReason = e_SS_SM_CPU_RESET_REASON_GENERIC_ERR; + l_eStatus = ErrorEventEnqueue(hApp, eErrorEventTypeSystemLowMemory, + l_moduleName, eErrorEventResetTypeHard, l_loggingInfo); + + LOG_ERROR_REC_HIST_IF_ERRORED(l_eStatus, // LCOV_EXCL_BR_LINE 15: marco defined in ss_system_manager.h // NOLINT(whitespace/line_length) + "ErrorEventEnqueue(eErrorEventTypeSystemLowMemory)"); // LCOV_EXCL_BR_LINE 15: marco defined in ss_system_manager.h // NOLINT(whitespace/line_length) + } + + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-"); + return l_eStatus; +} // End of EFrameworkunifiedStatus CSystemManager::OnLowSystemMemory( HANDLE hApp ) + +EFrameworkunifiedStatus CSystemManager::OnPropagateSystemError(HANDLE hApp) { + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+"); + EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK; + + INTERFACEUNIFIEDLOG_RECEIVED_FROM(hApp); // LCOV_EXCL_BR_LINE 15: marco defined in ss_templates.h // NOLINT(whitespace/line_length) + + SS_ASERT(0); // LCOV_EXCL_BR_LINE 15: marco defined in ss_templates.h // NOLINT(whitespace/line_length) + + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-"); + return (l_eStatus); +} + +/////////////////////////////////////////////////////////////////////////////// +/// \ingroup OnUserInvokedLoggingRequest +/// Called when the end user invokes a error event logging request by means +/// of hard key or other direct input method. +/// +/// \param [in] hApp - Application handle. +/// +/// \return EFrameworkunifiedStatus +/// Success ==> eFrameworkunifiedStatusOK +/// Failure ==> Other values +/////////////////////////////////////////////////////////////////////////////// +EFrameworkunifiedStatus CSystemManager::OnUserInvokedLoggingRequest(HANDLE f_hApp) { + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+"); + TSystemManagerLoggingRequestInfo l_logInfo; + EErrorEventType l_errorEventType; + std::string l_moduleName; + EFrameworkunifiedStatus l_eStatus; + SMLoggingInfo l_loggingInfo; // LCOV_EXCL_BR_LINE 11:unexpected branch // NOLINT(whitespace/line_length) + + if (eFrameworkunifiedStatusOK != (l_eStatus = ReadMsg < TSystemManagerLoggingRequestInfo > (f_hApp, l_logInfo))) { // LCOV_EXCL_BR_LINE 4: NSFW error case // NOLINT(whitespace/line_length) + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + LOG_ERROR("ReadMsg()"); // LCOV_EXCL_LINE 4: NSFW error case + } else { + l_moduleName = FrameworkunifiedGetMsgSrc(f_hApp); // LCOV_EXCL_BR_LINE 11:unexpected branch // NOLINT(whitespace/line_length) + l_loggingInfo.messageStr = l_logInfo.messageStr; + l_loggingInfo.suffixStr = l_logInfo.suffixStr; + + switch (l_logInfo.logType) { + case e_SS_SM_CAPTURE_ALL_LOGS: + l_errorEventType = eErrorEventTypeUserInvokedCollectAllLogs; + break; + + case e_SS_SM_SCREEN_CAPTURE: + l_errorEventType = eErrorEventTypeUserInvokedCollectScreenShot; + break; + + case e_SS_SM_CAPTURE_INTERFACEUNIFIED_LOGS: + l_errorEventType = eErrorEventTypeUserInvokedCollectInterfaceunifiedLogs; + break; + + case e_SS_SM_CAPTURE_DEV_LOGS: + l_errorEventType = eErrorEventTypeUserInvokedCollectDevLogs; + break; + + case e_SS_SM_CAPTURE_MODULE_LOGS: + l_errorEventType = eErrorEventTypeModuleInvokedCollectDebugLogs; + break; + + case e_SS_SM_CAPTURE_DTC_LOGS: + l_errorEventType = eErrorEventTypeDtcEvent; + break; + + case e_SS_SM_CAPTURE_NAVI_LOGS: + l_errorEventType = eErrorEventTypeUserInvokedCollectNaviLog; + break; + + case e_SS_SM_CAPTURE_GROUP_RELAUNCH: + l_errorEventType = eErrorEventTypeGroupRelaunch; + break; + + default: + l_errorEventType = eErrorEventTypeMaxValue; + FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, + " Error. Received unknown user invoked log type: %d. Dropping request.", + l_logInfo.logType); + break; + } + + if (eErrorEventTypeMaxValue != l_errorEventType) { // LCOV_EXCL_BR_LINE 200: will not be the else case + TEXT(__FUNCTION__, // LCOV_EXCL_BR_LINE 15: marco defined in ss_system_manager.h // NOLINT(whitespace/line_length) + " ERROR EVENT: User invoked logging request %d/'%s' received. " // LCOV_EXCL_BR_LINE 15: marco defined in ss_system_manager.h // NOLINT(whitespace/line_length) + "Adding the request to the event queue.", // LCOV_EXCL_BR_LINE 15: marco defined in ss_system_manager.h // NOLINT(whitespace/line_length) + l_logInfo.logType, GetStr(l_logInfo.logType).c_str()); // LCOV_EXCL_BR_LINE 15: marco defined in ns_logger_if.h // NOLINT(whitespace/line_length) + + l_eStatus = ErrorEventEnqueue(f_hApp, l_errorEventType, + l_moduleName, eErrorEventResetTypeNone, l_loggingInfo); + + LOG_ERROR_REC_HIST_IF_ERRORED(l_eStatus, // LCOV_EXCL_BR_LINE 15: marco defined in ss_system_manager.h // NOLINT(whitespace/line_length) + "ErrorEventEnqueue(UserInvoked)"); // LCOV_EXCL_BR_LINE 15: marco defined in ss_system_manager.h // NOLINT(whitespace/line_length) + } + } + + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-"); + return (l_eStatus); +} + +/////////////////////////////////////////////////////////////////////////////// +/// \ingroup OnEelExportRequest +/// Called when a removable device is inserted and contains the EEL_Export +/// trigger. +/// +/// \param [in] hApp - Application handle. +/// +/// \return EFrameworkunifiedStatus +/// Success ==> eFrameworkunifiedStatusOK +/// Failure ==> Other values +/////////////////////////////////////////////////////////////////////////////// +EFrameworkunifiedStatus CSystemManager::OnEelExportRequest(HANDLE f_hApp) { + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+"); + EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK; + UI_32 l_strlen = FrameworkunifiedGetMsgLength(f_hApp); + CHAR l_path[l_strlen]; // NOLINT + + if (l_strlen == 0) { // LCOV_EXCL_BR_LINE 200: restricted by iterface_unified + // LCOV_EXCL_START 200: restricted by iterface_unified + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200:test assert + SS_ASERT(0); // LCOV_EXCL_BR_LINE 15: marco defined in ss_templates.h // NOLINT(whitespace/line_length) + return eFrameworkunifiedStatusFail; + // LCOV_EXCL_STOP + } + + if (sizeof(l_path) != FrameworkunifiedGetMsgLength(f_hApp)) { // LCOV_EXCL_BR_LINE 6: must be equal + // LCOV_EXCL_START 6: must be equal + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + LOG_ERROR("DataSize mismatch"); // LCOV_EXCL_BR_LINE 15: marco defined in ss_templates.h // NOLINT(whitespace/line_length) + // LCOV_EXCL_STOP + } else if (eFrameworkunifiedStatusOK // LCOV_EXCL_BR_LINE 4: NSFW error case + != (l_eStatus = FrameworkunifiedGetMsgDataOfSize(f_hApp, &l_path[0], + static_cast<UI_32>(sizeof(l_path)), eSMRRelease))) { + // LCOV_EXCL_START 4: NSFW error case + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + LOG_ERROR("FrameworkunifiedGetMsgDataOfSize()"); // LCOV_EXCL_BR_LINE 15: marco defined in ss_templates.h // NOLINT(whitespace/line_length) + // LCOV_EXCL_STOP + } else { + TEXT(__FUNCTION__, + " ERROR EVENT: EelExport request received. Adding the request to the event queue."); // LCOV_EXCL_BR_LINE 15: marco defined in ns_logger_if.h // NOLINT(whitespace/line_length) + std::string l_moduleName = FrameworkunifiedGetMsgSrc(f_hApp); + SMLoggingInfo l_loggingInfo; // LCOV_EXCL_BR_LINE 11:unexpected branch // NOLINT(whitespace/line_length) + + l_path[l_strlen - 1] = '\0'; + l_loggingInfo.path = l_path; + + l_eStatus = ErrorEventEnqueue(f_hApp, eErrorEventTypeEelExport, + l_moduleName, eErrorEventResetTypeNone, l_loggingInfo); + + LOG_ERROR_REC_HIST_IF_ERRORED(l_eStatus, // LCOV_EXCL_BR_LINE 15: marco defined in ss_system_manager.h // NOLINT(whitespace/line_length) + "ErrorEventEnqueue(eErrorEventTypeEelExport)"); // LCOV_EXCL_BR_LINE 15: marco defined in ss_system_manager.h // NOLINT(whitespace/line_length) + } + + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-"); + return (l_eStatus); +} + +/////////////////////////////////////////////////////////////////////////////// +/// \ingroup OnSystemmanagerEmmcLogsRequest +/// Called when a removable device is inserted and contains the LOGGERSERVICE_EMMC_LOGS +/// trigger. +/// +/// \param [in] hApp - Application handle. +/// +/// \return EFrameworkunifiedStatus +/// Success ==> eFrameworkunifiedStatusOK +/// Failure ==> Other values +/////////////////////////////////////////////////////////////////////////////// +EFrameworkunifiedStatus CSystemManager::OnSystemmanagerEmmcLogsRequest(HANDLE f_hApp) { + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+"); + EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK; + UI_32 l_strlen = FrameworkunifiedGetMsgLength(f_hApp); + CHAR l_path[l_strlen]; // NOLINT + + if (l_strlen == 0) { // LCOV_EXCL_BR_LINE 4:NSFW + // LCOV_EXCL_START 4:NSFW + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + SS_ASERT(0); + return eFrameworkunifiedStatusFail; + // LCOV_EXCL_STOP + } + + if (sizeof(l_path) != FrameworkunifiedGetMsgLength(f_hApp)) { // LCOV_EXCL_BR_LINE 8: CHAR l_path[l_strlen] + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + LOG_ERROR("DataSize mismatch"); // LCOV_EXCL_LINE 8: CHAR l_path[l_strlen] + } else if (eFrameworkunifiedStatusOK != (l_eStatus = FrameworkunifiedGetMsgDataOfSize(f_hApp, &l_path[0], static_cast<UI_32>(sizeof(l_path)), eSMRRelease))) { // LCOV_EXCL_BR_LINE 4:NSFW error case // NOLINT(whitespace/line_length) + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + LOG_ERROR("FrameworkunifiedGetMsgDataOfSize()"); // LCOV_EXCL_LINE 4:NSFW error case + } else { + TEXT(__FUNCTION__, // LCOV_EXCL_BR_LINE 15: marco defined in ns_logger_if.h // NOLINT(whitespace/line_length) + " ERROR EVENT: LOGGERSERVICE_EMMC_LOGS request received. Adding the request to the event queue."); // LCOV_EXCL_BR_LINE 15: marco defined in ns_logger_if.h // NOLINT(whitespace/line_length) + std::string l_moduleName = FrameworkunifiedGetMsgSrc(f_hApp); // LCOV_EXCL_BR_LINE 11:unexpected branch // NOLINT(whitespace/line_length) + SMLoggingInfo l_loggingInfo; + + l_path[l_strlen - 1u] = '\0'; + l_loggingInfo.path = l_path; + + l_eStatus = ErrorEventEnqueue(f_hApp, eErrorEventTypeInterfaceunifiedEmmcLogs, + l_moduleName, eErrorEventResetTypeNone, l_loggingInfo); + + LOG_ERROR_REC_HIST_IF_ERRORED(l_eStatus, // LCOV_EXCL_BR_LINE 15: marco defined in ss_system_manager.h // NOLINT(whitespace/line_length) + "ErrorEventEnqueue(eErrorEventTypeInterfaceunifiedEmmcLogs)"); // LCOV_EXCL_BR_LINE 15: marco defined in ss_system_manager.h // NOLINT(whitespace/line_length) + } + + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-"); + return (l_eStatus); +} + +/////////////////////////////////////////////////////////////////////////////// +/// \ingroup OnSystemmanagerClearLogsRequest +/// Called when a clear LOGGERSERVICE_EMMC_LOGS requested +/// trigger. +/// +/// \param [in] hApp - Application handle. +/// +/// \return EFrameworkunifiedStatus +/// Success ==> eFrameworkunifiedStatusOK +/// Failure ==> Other values +/////////////////////////////////////////////////////////////////////////////// +EFrameworkunifiedStatus CSystemManager::OnSystemmanagerClearLogsRequest(HANDLE f_hApp) { + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+"); + EFrameworkunifiedStatus l_eStatus; + std::string l_moduleName = FrameworkunifiedGetMsgSrc(f_hApp); + + l_eStatus = ErrorEventEnqueue(f_hApp, eErrorEventTypeUserInvokedClearLogs, // LCOV_EXCL_BR_LINE 11:unexpected branch // NOLINT(whitespace/line_length) + l_moduleName, eErrorEventResetTypeNone); // LCOV_EXCL_BR_LINE 11:unexpected branch // NOLINT(whitespace/line_length) + + LOG_ERROR_REC_HIST_IF_ERRORED(l_eStatus, // LCOV_EXCL_BR_LINE 15: marco defined in ss_system_manager.h // NOLINT(whitespace/line_length) + "ErrorEventEnqueue(eErrorEventTypeUserInvokedClearLogs)"); // LCOV_EXCL_BR_LINE 15: marco defined in ss_system_manager.h // NOLINT(whitespace/line_length) + + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-"); + return (l_eStatus); +} + +/////////////////////////////////////////////////////////////////////////////// +/// \ingroup OnDiagLoggingRequest +/// Called by logger to initiate log artifact collection and storage on behalf +/// of diagnostic services. +/// +/// \param [in] hApp - Application handle. +/// +/// \return EFrameworkunifiedStatus +/// Success ==> eFrameworkunifiedStatusOK +/// Failure ==> Other values +/////////////////////////////////////////////////////////////////////////////// +EFrameworkunifiedStatus CSystemManager::OnDiagLoggingRequest(HANDLE f_hApp) { + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+"); + EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK; + UI_32 l_strlen = FrameworkunifiedGetMsgLength(f_hApp); + CHAR l_path[l_strlen]; // NOLINT + + if (l_strlen == 0) { // LCOV_EXCL_BR_LINE 200: restricted by iterface_unified + // LCOV_EXCL_START 200: restricted by iterface_unified + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200:test assert + SS_ASERT(0); // LCOV_EXCL_BR_LINE 15: marco defined in ss_templates.h // NOLINT(whitespace/line_length) + return eFrameworkunifiedStatusFail; + // LCOV_EXCL_STOP + } + + if (sizeof(l_path) != FrameworkunifiedGetMsgLength(f_hApp)) { // LCOV_EXCL_BR_LINE 6: must be equal + // LCOV_EXCL_START 6: must be equal + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + LOG_ERROR("DataSize mismatch"); // LCOV_EXCL_BR_LINE 15: marco defined in ss_templates.h // NOLINT(whitespace/line_length) + // LCOV_EXCL_STOP + } else if (eFrameworkunifiedStatusOK // LCOV_EXCL_BR_LINE 4: NSFW error case + != (l_eStatus = FrameworkunifiedGetMsgDataOfSize(f_hApp, &l_path[0], + static_cast<UI_32>(sizeof(l_path)), eSMRRelease))) { // NOLINT + // LCOV_EXCL_START 4: NSFW error case + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + LOG_ERROR("FrameworkunifiedGetMsgDataOfSize()"); // LCOV_EXCL_BR_LINE 15: marco defined in ss_templates.h // NOLINT(whitespace/line_length) + // LCOV_EXCL_STOP + } else { + TEXT(__FUNCTION__, // LCOV_EXCL_BR_LINE 15: marco defined in ns_logger_if.h // NOLINT(whitespace/line_length) + " ERROR EVENT: SS_SM_ERROR_EVENT_DIAG_LOG_REQ request received. Adding the request to the event queue."); // LCOV_EXCL_BR_LINE 15: marco defined in ns_logger_if.h // NOLINT(whitespace/line_length) + std::string l_moduleName = FrameworkunifiedGetMsgSrc(f_hApp); + SMLoggingInfo l_loggingInfo; // LCOV_EXCL_BR_LINE 11:unexpected branch // NOLINT(whitespace/line_length) + + l_path[l_strlen - 1u] = '\0'; + l_loggingInfo.path = l_path; + + l_eStatus = ErrorEventEnqueue(f_hApp, eErrorEventTypeDiagEvent, + l_moduleName, eErrorEventResetTypeNone, l_loggingInfo); + + LOG_ERROR_REC_HIST_IF_ERRORED(l_eStatus, // LCOV_EXCL_BR_LINE 15: marco defined in ss_system_manager.h // NOLINT(whitespace/line_length) + "ErrorEventEnqueue(eErrorEventTypeDiagEvent)"); // LCOV_EXCL_BR_LINE 15: marco defined in ss_system_manager.h // NOLINT(whitespace/line_length) + } + + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-"); + return (l_eStatus); +} + +/////////////////////////////////////////////////////////////////////////////// +/// \ingroup OnCanLoggingRequest +/// This function is called by logger to initiate log artifact collection +/// and storage when signaled via CAN. +/// +/// \param [in] hApp - Application handle. +/// +/// \return EFrameworkunifiedStatus +/// Success ==> eFrameworkunifiedStatusOK +/// Failure ==> Other values +/////////////////////////////////////////////////////////////////////////////// +EFrameworkunifiedStatus CSystemManager::OnCANLoggingRequest(HANDLE f_hApp) { + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+"); + EFrameworkunifiedStatus l_eStatus; + std::string l_moduleName; + + l_moduleName = FrameworkunifiedGetMsgSrc(f_hApp); // LCOV_EXCL_BR_LINE 11:unexpected branch // NOLINT(whitespace/line_length) + + TEXT(__FUNCTION__, // LCOV_EXCL_BR_LINE 15: marco defined in ns_logger_if.h // NOLINT(whitespace/line_length) + " ERROR EVENT: SS_SM_ERROR_EVENT_CAN_LOG_REQ received from %s.", // LCOV_EXCL_BR_LINE 15: marco defined in ns_logger_if.h // NOLINT(whitespace/line_length) + l_moduleName.c_str()); // LCOV_EXCL_BR_LINE 15: marco defined in ns_logger_if.h // NOLINT(whitespace/line_length) + + l_eStatus = ErrorEventEnqueue(f_hApp, eErrorEventTypeCanEvent, l_moduleName); // LCOV_EXCL_BR_LINE 11:unexpected branch // NOLINT(whitespace/line_length) + + LOG_ERROR_REC_HIST_IF_ERRORED(l_eStatus, // LCOV_EXCL_BR_LINE 15: marco defined in ss_system_manager.h // NOLINT(whitespace/line_length) + "ErrorEventEnqueue(eErrorEventTypeCanEvent)"); // LCOV_EXCL_BR_LINE 15: marco defined in ss_system_manager.h // NOLINT(whitespace/line_length) + + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-"); + return (l_eStatus); +} + diff --git a/video_in_hal/systemservice/system_manager/server/src/ss_system_memory_monitor.cpp b/video_in_hal/systemservice/system_manager/server/src/ss_system_memory_monitor.cpp new file mode 100755 index 0000000..7ea9b71 --- /dev/null +++ b/video_in_hal/systemservice/system_manager/server/src/ss_system_memory_monitor.cpp @@ -0,0 +1,362 @@ +/* + * @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_SystemManager +/// \brief This file provides support for System Manager System Low Memory +/// detection. +/// +/////////////////////////////////////////////////////////////////////////////// +#include <native_service/frameworkunified_framework_if.h> +#include <native_service/frameworkunified_multithreading.h> +#include <native_service/frameworkunified_thread_priority.h> +#include <system_service/ss_sm_thread_names_local.h> +#include <system_service/ss_templates.h> +#include <stub/Clock_API.h> + +#include <sys/stat.h> +#include <errno.h> +#include <sys/resource.h> +#include <boost/bind.hpp> +#include <fstream> +#include <sstream> +#include <string> + +#include "ss_system_memory_monitor.h" +#include "ss_sm_systemmanagerlog.h" + +CSysMemoryMonitor::CSysMemoryMonitor() : + m_hThread(NULL), + m_hParentApp(NULL), + m_SLMCheckCounter(0), + m_siPriority(-1), + m_NbrSamplesBeforeSystemmanagerlog(0), + m_memMonitorThreadName(SS_SMLowMemMonitor), + m_resmSession(-1) { // LCOV_EXCL_BR_LINE 11:unexpected branch // NOLINT(whitespace/line_length) + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+"); + m_SLMConfig.SLMTimerValue = 0; + m_SLMConfig.SLMMaxRetryCount = 0; + m_SLMConfig.SLMThresholdValue = 0; + m_SLMConfig.SLMSystemmanagerLogIntervalMs = 0; + bzero(&m_sysMemInfoLast, sizeof(m_sysMemInfoLast)); + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-"); +} + +CSysMemoryMonitor::~CSysMemoryMonitor(void) { + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+"); + StopAndFreeObjects(m_hParentApp); + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-"); +} + +EFrameworkunifiedStatus CSysMemoryMonitor::Initialize(HANDLE f_hApp) { + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+"); + EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK; + + if (NULL == f_hApp) { // LCOV_EXCL_BR_LINE 4:NSFW + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + l_eStatus = eFrameworkunifiedStatusNullPointer; // LCOV_EXCL_LINE 4:NSFW + FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, " Error. Argument f_hApp passed NULL pointer."); + } else if (NULL == (m_hThread = FrameworkunifiedCreateChildThreadWithPriority(f_hApp, SS_SMLowMemMonitor, boost::bind(&CSysMemoryMonitor::CPUMemThreadStart, this, _1), boost::bind(&CSysMemoryMonitor::CPUMemThreadStop, this, _1), PR_SMLOWMEMMON))) { // LCOV_EXCL_BR_LINE 4:NSFW // NOLINT(whitespace/line_length) + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + l_eStatus = eFrameworkunifiedStatusInvldHandle; // LCOV_EXCL_LINE 4:NSFW + LOG_ERROR("FrameworkunifiedCreateChildThreadWithPriority()"); // LCOV_EXCL_LINE 4:NSFW + } else if (eFrameworkunifiedStatusOK != (l_eStatus = FrameworkunifiedStartChildThread(f_hApp, m_hThread, 0, NULL))) { // LCOV_EXCL_BR_LINE 4:NSFW // NOLINT(whitespace/line_length) + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + LOG_ERROR("FrameworkunifiedStartChildThread()"); // LCOV_EXCL_LINE 4:NSFW + } else { + m_hParentApp = f_hApp; + m_sysMemInfoLast.TotalMemoryBytes = GetSystemRamSize(); + FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__, " Info. SLM thread successfully initialized."); + } + + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-"); + return (l_eStatus); +} + +EFrameworkunifiedStatus CSysMemoryMonitor::StopAndFreeObjects(HANDLE f_hApp) { + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+"); + EFrameworkunifiedStatus l_eStatus; + + CALL_AND_LOG_STATUS(FrameworkunifiedStopChildThread(f_hApp, m_hThread, 0, NULL)); // LCOV_EXCL_BR_LINE 15: marco defined in ss_templates.h // NOLINT(whitespace/line_length) + CALL_AND_LOG_STATUS(FrameworkunifiedDestroyChildThread(f_hApp, m_hThread)); // LCOV_EXCL_BR_LINE 15: marco defined in ss_templates.h // NOLINT(whitespace/line_length) + + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-"); + return (l_eStatus); +} + +const std::string CSysMemoryMonitor::GetThreadName(void) { + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+"); + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-"); + return (m_memMonitorThreadName); +} + +void CSysMemoryMonitor::SetSLMConfigData(SLMConfigParameters & f_ConfigData) { + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+"); + + m_SLMConfig.SLMTimerValue = f_ConfigData.SLMTimerValue; + m_SLMConfig.SLMMaxRetryCount = f_ConfigData.SLMMaxRetryCount; + m_SLMConfig.SLMThresholdValue = f_ConfigData.SLMThresholdValue; + m_SLMConfig.SLMSystemmanagerLogIntervalMs = f_ConfigData.SLMSystemmanagerLogIntervalMs; + + FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__, + "Timer value '%d', Retry Count '%d', threshold '%d', log interval '%dms'", + m_SLMConfig.SLMTimerValue, m_SLMConfig.SLMMaxRetryCount, + m_SLMConfig.SLMThresholdValue, m_SLMConfig.SLMSystemmanagerLogIntervalMs); + + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-"); +} + +EFrameworkunifiedStatus CSysMemoryMonitor::CPUMemThreadStart(HANDLE f_hThread) { + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+"); + EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK; + + l_eStatus = FrameworkunifiedSubscribeNotificationWithCallback(f_hThread, + NTFY_ResourceMgr_Availability, + boost::bind(&CSysMemoryMonitor::OnAvailability, this, _1)); + if (l_eStatus != eFrameworkunifiedStatusOK) { // LCOV_EXCL_BR_LINE 4:NSFW + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + SS_ASERT(0); // LCOV_EXCL_LINE 4:NSFW + } + + if (FALSE == (m_memMonitorTimer.Initialize(f_hThread, SS_SLM_MEM_MONITOR_TIMER_ID, boost::bind(&CSysMemoryMonitor::OnMemoryTimerExpiry, this, _1)))) { // LCOV_EXCL_BR_LINE 4:NSFW // NOLINT(whitespace/line_length) + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + l_eStatus = eFrameworkunifiedStatusBadConnection; // LCOV_EXCL_LINE 4:NSFW + LOG_ERROR("m_memMonitorTimer.Initialize() returned 'FALSE'"); // LCOV_EXCL_LINE 4:NSFW + } else if (FALSE == (m_systemmanagerlogTimer.Initialize(f_hThread, SS_SLM_SYSTEMMANAGERLOG_TIMER_ID, boost::bind(&CSysMemoryMonitor::OnSystemmanagerlogTimerExpiry, this, _1)))) { // LCOV_EXCL_BR_LINE 4:NSFW // NOLINT(whitespace/line_length) + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + l_eStatus = eFrameworkunifiedStatusBadConnection; // LCOV_EXCL_LINE 4:NSFW + LOG_ERROR("m_systemmanagerlogTimer.Initialize() returned 'FALSE'"); // LCOV_EXCL_LINE 4:NSFW + } else { + if (m_SLMConfig.SLMTimerValue > 0) { + m_memMonitorTimer.SetTime(m_SLMConfig.SLMTimerValue / 1000, + m_SLMConfig.SLMTimerValue % 1000, + m_SLMConfig.SLMTimerValue / 1000, + m_SLMConfig.SLMTimerValue % 1000); + } else { + // default timer settings + m_memMonitorTimer.SetTime(SS_MEMORY_TIMER_CONFIG_MS / 1000, + SS_MEMORY_TIMER_CONFIG_MS % 1000, + SS_MEMORY_TIMER_CONFIG_MS / 1000, + SS_MEMORY_TIMER_CONFIG_MS % 1000); + + FRAMEWORKUNIFIEDLOG(ZONE_WARN, __FUNCTION__, + " Warning. SLM monitor timer configuration invalid. Using default values."); + } + + if (m_SLMConfig.SLMSystemmanagerLogIntervalMs > 0) { + m_systemmanagerlogTimer.SetTime(m_SLMConfig.SLMSystemmanagerLogIntervalMs / 1000, + m_SLMConfig.SLMSystemmanagerLogIntervalMs % 1000, + m_SLMConfig.SLMSystemmanagerLogIntervalMs / 1000, + m_SLMConfig.SLMSystemmanagerLogIntervalMs % 1000); + } else { + // default timer settings + m_systemmanagerlogTimer.SetTime(SS_SYSTEMMANAGERLOG_TIMER_CONFIG_MS / 1000, + SS_SYSTEMMANAGERLOG_TIMER_CONFIG_MS % 1000, + SS_SYSTEMMANAGERLOG_TIMER_CONFIG_MS / 1000, + SS_SYSTEMMANAGERLOG_TIMER_CONFIG_MS % 1000); + + FRAMEWORKUNIFIEDLOG(ZONE_WARN, __FUNCTION__, + " Warning. SLM FRAMEWORKUNIFIEDLOG timer configuration invalid. Using default values."); + } + + if (FALSE == (m_memMonitorTimer.Start())) { // LCOV_EXCL_BR_LINE 4:NSFW + // LCOV_EXCL_START 4:NSFW + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + l_eStatus = eFrameworkunifiedStatusFault; + LOG_ERROR("m_memMonitorTimer.Start() returned 'FALSE'"); + // LCOV_EXCL_STOP 4:NSFW + } else if (FALSE == (m_systemmanagerlogTimer.Start())) { // LCOV_EXCL_BR_LINE 4:NSFW + // LCOV_EXCL_START 4:NSFW + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + l_eStatus = eFrameworkunifiedStatusFault; + LOG_ERROR("m_systemmanagerlogTimer.Start() returned 'FALSE'"); + // LCOV_EXCL_STOP 4:NSFW + } else { + FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__, " Success."); + } + } + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-"); + return (l_eStatus); +} + +EFrameworkunifiedStatus CSysMemoryMonitor::CPUMemThreadStop(HANDLE f_hThread) { + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+"); + EFrameworkunifiedStatus l_eStatus; + + l_eStatus = StopTimers(); + LOG_STATUS_IF_ERRORED(l_eStatus, "StopTimers"); // LCOV_EXCL_BR_LINE 15: marco defined in ss_templates.h // NOLINT(whitespace/line_length) + if ((uint32_t) -1 != m_resmSession) { + if (RESM_E_OK != RESM_Close(m_resmSession)) { + l_eStatus = eFrameworkunifiedStatusFault; + LOG_ERROR("RESM_Close()"); // LCOV_EXCL_BR_LINE 15: marco defined in ss_templates.h // NOLINT(whitespace/line_length) + } + } + + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-"); + return (l_eStatus); +} + +EFrameworkunifiedStatus CSysMemoryMonitor::StopTimers(void) { + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+"); + EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK; + + if (FALSE == (m_memMonitorTimer.Stop())) { // LCOV_EXCL_BR_LINE 4:NSFW's error + l_eStatus = eFrameworkunifiedStatusFault; + LOG_ERROR("m_memMonitorTimer.Stop() returned 'FALSE'"); // LCOV_EXCL_BR_LINE 15: marco defined in ss_templates.h // NOLINT(whitespace/line_length) + } + + if (FALSE == (m_systemmanagerlogTimer.Stop())) { // LCOV_EXCL_BR_LINE 4:NSFW's error + l_eStatus = eFrameworkunifiedStatusFault; + LOG_ERROR("m_systemmanagerlogTimer.Stop() returned 'FALSE'"); // LCOV_EXCL_BR_LINE 15: marco defined in ss_templates.h // NOLINT(whitespace/line_length) + } + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-"); + return (l_eStatus); +} + +EFrameworkunifiedStatus CSysMemoryMonitor::OnMemoryTimerExpiry(HANDLE hThread) { + FRAMEWORKUNIFIEDLOG(ZONE_PERIODIC_FUNC, __FUNCTION__, "+"); + EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK; + RESM_STATUS_t l_resmStatus; + + if ((uint32_t) -1 == m_resmSession) { + return eFrameworkunifiedStatusOK; + } + + if (RESM_E_OK != RESM_GetStatus(m_resmSession, &l_resmStatus)) { + LOG_ERROR("RESM_GetStatus()"); // LCOV_EXCL_BR_LINE 15: marco defined in ss_templates.h // NOLINT(whitespace/line_length) + l_eStatus = eFrameworkunifiedStatusFail; + } else { + m_sysMemInfoLast.FreeMemoryBytes = l_resmStatus.restMemSize; + if ((m_sysMemInfoLast.FreeMemoryBytes * 1024) + < (UI_32) m_SLMConfig.SLMThresholdValue) { + m_SLMCheckCounter++; + + FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, " Low Memory detected(%d/%d).", + m_SLMCheckCounter, m_SLMConfig.SLMMaxRetryCount); + + if (m_SLMCheckCounter >= m_SLMConfig.SLMMaxRetryCount) { + l_eStatus = FrameworkunifiedSendParent(hThread, + eSysMemThrdCmd_SYS_LOW_MEMORY, sizeof(m_sysMemInfoLast), + &m_sysMemInfoLast); + LOG_STATUS_IF_ERRORED(l_eStatus, // LCOV_EXCL_BR_LINE 15: marco defined in ns_logger_if.h // NOLINT(whitespace/line_length) + "FrameworkunifiedSendParent(eSysMemThrdCmd_SYS_LOW_MEMORY)"); // LCOV_EXCL_BR_LINE 15: marco defined in ss_templates.h // NOLINT(whitespace/line_length) + + l_eStatus = StopTimers(); + LOG_STATUS_IF_ERRORED(l_eStatus, "StopTimers"); // LCOV_EXCL_BR_LINE 15: marco defined in ss_templates.h // NOLINT(whitespace/line_length) + } + } else { + m_SLMCheckCounter = 0; + } + } + + FRAMEWORKUNIFIEDLOG(ZONE_PERIODIC_FUNC, __FUNCTION__, "-"); + return (l_eStatus); +} + +EFrameworkunifiedStatus CSysMemoryMonitor::OnSystemmanagerlogTimerExpiry(HANDLE hThread) { + FRAMEWORKUNIFIEDLOG(ZONE_PERIODIC_FUNC, __FUNCTION__, "+"); + EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK; + UI_32 l_freeMemoryObfuscated; + UI_32 l_totalMemoryObfuscated; + + l_freeMemoryObfuscated = BitReverse32(m_sysMemInfoLast.FreeMemoryBytes); + l_totalMemoryObfuscated = BitReverse32(m_sysMemInfoLast.TotalMemoryBytes); + + // Print to ZONE_WARN as per IAT requirement see WI 219056. + FRAMEWORKUNIFIEDLOG(ZONE_WARN, __FUNCTION__, "FM: [%d/%d].", l_freeMemoryObfuscated, + l_totalMemoryObfuscated); + + static int count = 0; + + if (!(count %= 2)) { + CHAR l_format[256]; + uint32_t timebuf; + uint8_t status; + struct tm gmt; + struct tm local; + Clock_getSystemTimeY2K38(&timebuf, &status); + Clock_CnvSecToDateY2K38(&timebuf, &gmt); + Clock_getLocalTimeY2K38(&timebuf, &local); + + sprintf(l_format, " G%02d %02d%02d%02d L%02d %02d%02d%02d", gmt.tm_mday, // NOLINT + gmt.tm_hour, gmt.tm_min, gmt.tm_sec, local.tm_mday, + local.tm_hour, local.tm_min, local.tm_sec); + + FRAMEWORKUNIFIEDLOG(ZONE_STATE, __FUNCTION__, "%s", l_format); + } + + count++; + + FRAMEWORKUNIFIEDLOG(ZONE_PERIODIC_FUNC, __FUNCTION__, "-"); + return (l_eStatus); +} + +EFrameworkunifiedStatus CSysMemoryMonitor::OnAvailability(HANDLE hThread) { + if (FrameworkunifiedIsServiceAvailable(hThread)) { + if (m_resmSession == (uint32_t) -1) { + if (RESM_E_OK != RESM_Open(NULL, &m_resmSession)) { + m_resmSession = -1; + SS_ASERT(0); // LCOV_EXCL_BR_LINE 15: marco defined in ss_templates.h // NOLINT(whitespace/line_length) + } + } + } + return eFrameworkunifiedStatusOK; +} + +UI_32 CSysMemoryMonitor::GetSystemRamSize(void) { + UI_32 l_ramTotalBytes = 0; + std::ifstream l_sFile("/proc/meminfo"); + + if (l_sFile.fail()) { // LCOV_EXCL_BR_LINE 5: Standard lib error + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "Open /proc/meminfo"); + } else { + ssize_t l_position; + std::string l_str; + + while (getline(l_sFile, l_str)) { + +// if (std::string::npos +// != (l_position = static_cast<unsigned int>(l_str.find("MemTotal:", 0)))) { + if (0 <= (l_position = l_str.find("MemTotal:", 0))) { // LCOV_EXCL_BR_LINE 200:linux system information + + l_str.erase(l_position, l_position + strlen("MemTotal:")); // LCOV_EXCL_BR_LINE 11:unexpected branch // NOLINT(whitespace/line_length) + + if (std::string::npos != (l_position = static_cast<unsigned int>(l_str.find("kB", 0)))) { // LCOV_EXCL_BR_LINE 200:linux system information + l_str.erase(l_position, l_position + strlen("kB")); // LCOV_EXCL_BR_LINE 11:unexpected branch // NOLINT(whitespace/line_length) + } + + std::istringstream l_istr(l_str); // LCOV_EXCL_BR_LINE 11:unexpected branch // NOLINT(whitespace/line_length) + + l_istr >> l_ramTotalBytes; + + break; + } + } + } + + return (l_ramTotalBytes); +} + +UI_32 CSysMemoryMonitor::BitReverse32(UI_32 f_val) { + // Don't print FRAMEWORKUNIFIEDLOG(ZONE_FUNC) to prevent obfuscation method from being revealed. + f_val = (((f_val & 0xaaaaaaaa) >> 1) | ((f_val & 0x55555555) << 1)); + f_val = (((f_val & 0xcccccccc) >> 2) | ((f_val & 0x33333333) << 2)); + f_val = (((f_val & 0xf0f0f0f0) >> 4) | ((f_val & 0x0f0f0f0f) << 4)); + f_val = (((f_val & 0xff00ff00) >> 8) | ((f_val & 0x00ff00ff) << 8)); + f_val = (f_val >> 16) | (f_val << 16); + return (f_val); +} diff --git a/video_in_hal/systemservice/system_manager/server/src/systemmanager_application.cpp b/video_in_hal/systemservice/system_manager/server/src/systemmanager_application.cpp new file mode 100755 index 0000000..506bb2c --- /dev/null +++ b/video_in_hal/systemservice/system_manager/server/src/systemmanager_application.cpp @@ -0,0 +1,237 @@ +/* + * @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_SystemManager +/// \brief This file contains the standard set functions called by the NS +// dispatcher on application initialization, cleanup and wakeup. +/// +/////////////////////////////////////////////////////////////////////////////// + +#include <native_service/frameworkunified_application.h> +#include <native_service/frameworkunified_framework_if.h> +#include <native_service/frameworkunified_service_protocol.h> +#include <system_service/ss_templates.h> + +#include "ss_sm_systemmanagerlog.h" +#include "ss_system_manager.h" + +#include <sys/types.h> +#include <sys/time.h> +#include <sys/resource.h> +#include <errno.h> + +////////////////////////////////////////// +// Function : FrameworkunifiedOnInitialization +////////////////////////////////////////// +EFrameworkunifiedStatus FrameworkunifiedOnInitialization(HANDLE hApp) { + EFrameworkunifiedStatus eStatus = eFrameworkunifiedStatusOK; + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+"); + + eStatus = CSystemManager::GetInstance().Initialize(hApp); + struct rlimit setrl = {RLIM_INFINITY, RLIM_INFINITY}; + struct rlimit getrl = {}; + int ret = prlimit(getpid(), RLIMIT_MSGQUEUE, &setrl, &getrl); + if (ret != 0) { + FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "prlimit ret%d", ret); + FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "Previous limits: soft=%lld; hard=%lld", (long long) getrl.rlim_cur, + (long long) getrl.rlim_max); + } + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-"); + return eStatus; +} + +////////////////////////////////////////// +// Function : FrameworkunifiedOnWakeup +////////////////////////////////////////// +EFrameworkunifiedStatus FrameworkunifiedOnWakeup(HANDLE hApp) { + EFrameworkunifiedStatus eStatus = eFrameworkunifiedStatusOK; + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+"); + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-"); + return eStatus; +} + +////////////////////////////////////////// +// Function : FrameworkunifiedOnShutdown +////////////////////////////////////////// +EFrameworkunifiedStatus FrameworkunifiedOnShutdown(HANDLE hApp) { + EFrameworkunifiedStatus eStatus = eFrameworkunifiedStatusOK; + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+"); + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-"); + return eStatus; +} + +//////////////////////////////////////////////////////////////////////////////////////////// +/// FrameworkunifiedOnDestroy +/// \todo Add behavior to this function +//////////////////////////////////////////////////////////////////////////////////////////// +EFrameworkunifiedStatus FrameworkunifiedOnDestroy(HANDLE hApp) { // LCOV_EXCL_START 14:Resident process, not called by NSFW + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + EFrameworkunifiedStatus eStatus = eFrameworkunifiedStatusOK; + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+"); + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-"); + return eStatus; +} +// LCOV_EXCL_STOP + +//////////////////////////////////////////////////////////////////////////////////////////// +/// FrameworkunifiedOnEShutdown +/// \todo Add behavior to this function +//////////////////////////////////////////////////////////////////////////////////////////// +EFrameworkunifiedStatus FrameworkunifiedOnEShutdown(HANDLE hApp) { + EFrameworkunifiedStatus eStatus = eFrameworkunifiedStatusOK; + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+"); + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-"); + return eStatus; +} + +EFrameworkunifiedStatus FrameworkunifiedOnDebugDump(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, __FUNCTION__, "+"); + + CSystemManager* l_instance = &CSystemManager::GetInstance(); + if (l_instance !=NULL) { + l_instance->SystemManagerDebugDump(hApp); + } else { + l_eStatus = eFrameworkunifiedStatusInvldHandle; + LOG_STATUS(l_eStatus, "Unable to acquire SM instance. Debug Dump handler not called."); // LCOV_EXCL_BR_LINE 15: marco defined in ss_templates.h // NOLINT(whitespace/line_length) + } + + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-"); + return l_eStatus; +} +// LCOV_EXCL_STOP + +/** + * 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__, "+"); + FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__, "This method has not been implemented, return: eFrameworkunifiedStatusOK!"); + 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) { + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+"); + FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__, "This method has not been implemented, return: eFrameworkunifiedStatusOK!"); + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-"); + return eFrameworkunifiedStatusOK; +} + +/** + * EFrameworkunifiedStatus FrameworkunifiedOnPreStart(HANDLE h_app) + * + * @param h_app Handle to the SS_Power Framework Obj. + * + * @return method status of completion or failure. + */ + +EFrameworkunifiedStatus FrameworkunifiedOnPreStart(HANDLE hApp) { + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+"); + FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__, "This method has not been implemented, return: eFrameworkunifiedStatusOK!"); + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-"); + return eFrameworkunifiedStatusOK; +} + +/** + * EFrameworkunifiedStatus FrameworkunifiedOnPreStop(HANDLE h_app) + * + * @param h_app Handle to the SS_Power Framework Obj. + * + * @return method status of completion or failure. + */ + +EFrameworkunifiedStatus FrameworkunifiedOnPreStop(HANDLE hApp) { + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+"); + FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__, "This method has not been implemented, return: eFrameworkunifiedStatusOK!"); + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-"); + return eFrameworkunifiedStatusOK; +} + +/** + * EFrameworkunifiedStatus FrameworkunifiedOnBackgroundStart(HANDLE h_app) + * + * @param h_app Handle to the SS_Power Framework Obj. + * + * @return method status of completion or failure. + */ + +EFrameworkunifiedStatus FrameworkunifiedOnBackgroundStart(HANDLE hApp) { + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+"); + FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__, "This method has not been implemented, return: eFrameworkunifiedStatusOK!"); + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-"); + return eFrameworkunifiedStatusOK; +} + +/** + * EFrameworkunifiedStatus FrameworkunifiedOnBackgroundStop(HANDLE h_app) + * + * @param h_app Handle to the SS_Power Framework Obj. + * + * @return method status of completion or failure. + */ + +EFrameworkunifiedStatus FrameworkunifiedOnBackgroundStop(HANDLE hApp) { + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+"); + FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__, "This method has not been implemented, return: eFrameworkunifiedStatusOK!"); + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-"); + return eFrameworkunifiedStatusOK; +} + +/** + * 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) { + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+"); + FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__, "This method has not been implemented, return: eFrameworkunifiedStatusOK!"); + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-"); + return eFrameworkunifiedStatusOK; +} + +//////////////////////////////////////////////////////////////////////////////////////////// +/// +/// +//////////////////////////////////////////////////////////////////////////////////////////// +EFrameworkunifiedStatus SystemmanagerCloseApplication(HANDLE hApp) { + EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK; + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+"); + + l_eStatus = CSystemManager::GetInstance().CloseApplication(hApp); + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-"); + return l_eStatus; +} +// EOF + diff --git a/video_in_hal/systemservice/system_manager/server/src/systemmanager_main.cpp b/video_in_hal/systemservice/system_manager/server/src/systemmanager_main.cpp new file mode 100755 index 0000000..d12aecc --- /dev/null +++ b/video_in_hal/systemservice/system_manager/server/src/systemmanager_main.cpp @@ -0,0 +1,120 @@ +/* + * @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_SystemManager +/// \brief Application entry point. +/// +/////////////////////////////////////////////////////////////////////////////// +#include <system_service/ss_system_if.h> +#include <native_service/frameworkunified_dispatcher.h> +#include <native_service/ns_version_if.h> +#include <system_service/ss_services.h> +#include <system_service/ss_string_maps.h> +#include <system_service/ss_version.h> +#include <system_service/ss_system_types.h> +#include <stdio.h> +#include <errno.h> +#include <fcntl.h> +#include <sys/types.h> +#include <sys/stat.h> +#include <cstdlib> +#include <fstream> + +#include "ss_sm_systemmanagerlog.h" +#include "ss_system_manager.h" + + +CFrameworkunifiedVersion g_FrameworkunifiedVersion(MAJORNO, MINORNO, REVISION); + +/// \brief: Name of the Queue that will be used to read data from. +const CHAR AppName[] = SERVICE_SYSMANAGER; + +static EFrameworkunifiedStatus ArgumentParser(SI_32 cc, PCHAR str) { + switch (cc) { + case 'b': + CSystemManager::m_bootOpt += str; + break; + default: + break; + } + return eFrameworkunifiedStatusOK; +} + +////////////////////////////////////////// +// Function : main +////////////////////////////////////////// +int main(int argc, char *argv[]) { + EFrameworkunifiedStatus l_eStatus; + FrameworkunifiedDefaultCallbackHandler cbFuncs; + FRAMEWORKUNIFIED_MAKE_DEFAULT_CALLBACK(cbFuncs); // LCOV_EXCL_BR_LINE 15: marco defined in ss-system_if.h // NOLINT(whitespace/line_length) + int fd; +/* + if (geteuid() == 0) { // LCOV_EXCL_BR_LINE 200: process cannot be executed by root + // LCOV_EXCL_START 200: process cannot be executed by root + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + printf("System cannot be started by root user!!\n" + "You can start system: \n" + " # sm > /dev/null &\n" + " or \n" + " # sm &\n"); + // LCOV_EXCL_STOP + return -1; + } +*/ + fd = open("/dev/null", O_RDONLY); // LCOV_EXCL_BR_LINE 11:unexpected branch // NOLINT(whitespace/line_length) + if (fd > 0) { // LCOV_EXCL_BR_LINE 5: open file error case. + int ret; + ret = dup2(fd, 0); + if (ret == -1) perror("dup2"); // LCOV_EXCL_BR_LINE 5: dup2 error case. + ret = close(fd); // LCOV_EXCL_BR_LINE 11:unexpected branch // NOLINT(whitespace/line_length) + if (ret == -1) perror("close"); // LCOV_EXCL_BR_LINE 5: close error case. + } else { + // LCOV_EXCL_START 5: open file error case. + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + perror("open"); // LCOV_EXCL_LINE 5: open file error case. + // LCOV_EXCL_STOP + } + + // This allows overriding the already-passed-in System Manager's command + // line arguments by having a file exist named + // "/agl/rwdata/<this_file's_base_name>.args". + // For example, when this file is named 'SS_SystemManager', then + // if '/agl/rwdata/SS_SystemManager.args' is present, then the + // '/agl/rwdata/SS_SystemManager.args' strings are read as command line + // values and are passed to the FrameworkunifiedDispatcher() function. + // -m + // 0xFFFFFFFF,0xFFFFFFFF, where each bit represents a logging Zone. + // -c + // [configuration file..] + + struct sched_param l_schedParam; + + l_schedParam.sched_priority = PR_SS_SYSMANAGER; + + if (0 != sched_setscheduler(getpid(), SCHED_FIFO, &l_schedParam)) { // LCOV_EXCL_BR_LINE 5: sched_setscheduler error case. // NOLINT(whitespace/line_length) + printf("ASSERT %d:%s\n", errno, strerror(errno)); // LCOV_EXCL_BR_LINE 11:unexpected branch // NOLINT(whitespace/line_length) + } + + CustomCommandLineOptions l_tCmdLineOptions = { "b:", NULL, ArgumentParser }; // cShortOptions,rsv,callback + { + l_eStatus = FrameworkunifiedDispatcherWithArguments(AppName, argc, argv, &cbFuncs, &l_tCmdLineOptions); // LCOV_EXCL_BR_LINE 11:unexpected branch // NOLINT(whitespace/line_length) + } + printf("SM: Line %d: FrameworkunifiedDispatcherWithArguments() returned l_eStatus: '%d'/'%s'\n", // LCOV_EXCL_BR_LINE 11:unexpected branch // NOLINT(whitespace/line_length) + __LINE__, l_eStatus, GetStr(l_eStatus).c_str()); // LCOV_EXCL_BR_LINE 11:unexpected branch // NOLINT(whitespace/line_length) + + return l_eStatus; +} // LCOV_EXCL_BR_LINE 11:unexpected branch // NOLINT(whitespace/line_length) |