2 * @copyright Copyright (c) 2016-2020 TOYOTA MOTOR CORPORATION.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 ///////////////////////////////////////////////////////////////////////////////
18 /// \ingroup tag_SystemManager
19 /// \brief This file provides support for process launching and termination.
21 ///////////////////////////////////////////////////////////////////////////////
22 #include <native_service/frameworkunified_framework_if.h>
24 #include "ProcessLauncher.h"
25 #include "ss_sm_process_launcher_protocol.h"
26 #include "ss_sm_systemmanagerlog.h"
28 template<typename C, eFrameworkunifiedStatus (C::*M)(HANDLE)> EFrameworkunifiedStatus ProcessLauncherCallback(HANDLE hThread) {
29 EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK;
31 C * pObj = static_cast<C *>(FrameworkunifiedGetThreadSpecificData(hThread));
33 if (pObj) { // LCOV_EXCL_BR_LINE 5:pObj must not be NULL
34 l_eStatus = (pObj->*M)(hThread);
40 EFrameworkunifiedStatus ProcessLauncherOnStart(HANDLE hThread) {
41 FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+");
42 EFrameworkunifiedStatus l_eStatus;
43 CProcessLauncher * pObj = new (std::nothrow) CProcessLauncher(NULL); // LCOV_EXCL_BR_LINE 11:unexpected branch // NOLINT(whitespace/line_length)
45 if (pObj) { // LCOV_EXCL_BR_LINE 5:new error
46 // LCOV_EXCL_BR_START 200:l_eStatus always return eFrameworkunifiedStatusOK
47 if (eFrameworkunifiedStatusOK != (l_eStatus = pObj->PLOnCmdStart(hThread))) {
49 // LCOV_EXCL_START 200:l_eStatus always return eFrameworkunifiedStatusOK
50 AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert
51 FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__,
52 " Error: pObj->PLOnCmdStart(hThread) errored: %d/'%s'",
53 l_eStatus, GetStr(l_eStatus).c_str());
56 FrameworkunifiedSetThreadSpecificData(hThread, pObj);
58 FrameworkunifiedProtocolCallbackHandler aParentHandlers[] = { {
59 ePLThrdCmd_LAUNCH_MODULE_REQST, ProcessLauncherCallback<
61 &CProcessLauncher::PLOnCmdLaunchModule> }, {
62 ePLThrdCmd_TERMINATE_MODULE_REQST, ProcessLauncherCallback<
64 &CProcessLauncher::PLOnCmdTerminateModule> }, {
65 ePLThrdCmd_RELAUNCH_MODULE_REQST, ProcessLauncherCallback<
67 &CProcessLauncher::PLOnCmdRelaunchModule> }, {
68 ePLThrdCmd_MODULE_STATUS_REQST, ProcessLauncherCallback<
70 &CProcessLauncher::PLOnCmdModuleStatus> }, {
71 ePLThrdCmd_THREAD_STATUS_REQST, ProcessLauncherCallback<
73 &CProcessLauncher::PLOnCmdHeartbeatStatusReq> } }; // LCOV_EXCL_BR_LINE 11:unexpected branch // NOLINT(whitespace/line_length)
75 // LCOV_EXCL_BR_START 4:NSFW error case
76 if (eFrameworkunifiedStatusOK
77 != (l_eStatus = FrameworkunifiedAttachParentCallbacksToDispatcher(hThread, aParentHandlers,
78 static_cast<UI_32>(_countof(aParentHandlers))))) {
80 // LCOV_EXCL_START 4:NSFW error case
81 AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert
82 FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__,
83 " Error: FrameworkunifiedAttachParentCallbacksToDispatcher() errored: %d/'%s'",
84 l_eStatus, GetStr(l_eStatus).c_str());
87 // Add other Attaches here!!!
90 } else { // LCOV_EXCL_BR_LINE 5::new operation failed
91 // LCOV_EXCL_START 5:new error
92 AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert
93 FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, " Error: new CProcessLauncher( NULL ) returned NULL");
94 l_eStatus = eFrameworkunifiedStatusNullPointer;
97 FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-");
101 // LCOV_EXCL_START 200:Thread which registered in init_process_launcher() is never stoppped.
102 EFrameworkunifiedStatus ProcessLauncherOnStop(HANDLE hThread) {
103 AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert
104 FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+");
105 EFrameworkunifiedStatus l_eStatus;
106 CProcessLauncher * pObj = static_cast<CProcessLauncher *>(FrameworkunifiedGetThreadSpecificData(hThread));
109 if (eFrameworkunifiedStatusOK != (l_eStatus = pObj->PLOnCmdStop(hThread))) {
110 LOG_ERROR("PLOnCmdStop()"); // LCOV_EXCL_BR_LINE 15: marco defined in ss_templates.h // NOLINT(whitespace/line_length)
116 FrameworkunifiedSetThreadSpecificData(hThread, NULL);
118 if (eFrameworkunifiedStatusOK != (l_eStatus = FrameworkunifiedDetachServiceFromDispatcher(hThread, FrameworkunifiedGetAppName(hThread)))) {
119 LOG_ERROR("FrameworkunifiedDetachServiceFromDispatcher()"); // LCOV_EXCL_BR_LINE 15: marco defined in ss_templates.h // NOLINT(whitespace/line_length)
122 FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-");