summaryrefslogtreecommitdiffstats
path: root/systemservice/system_manager/server/src/processlauncher/ProcessLauncher_if.cpp
blob: 3d9b2e92bf3854e78a5d0a2c82378f38fa4778cd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
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