summaryrefslogtreecommitdiffstats
path: root/systemservice/system_manager/server/src/heartbeat/ss_hb_service_protocol.cpp
blob: 5fb4e001abc12c23852c0fcd4b25c3a896041b04 (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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
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