Fix the path to the host specific system configurations
[staging/basesystem.git] / service / system / system_manager / server / src / heartbeat / ss_hb_service_protocol.cpp
1 /*
2  * @copyright Copyright (c) 2016-2020 TOYOTA MOTOR CORPORATION.
3  *
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
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  */
16
17 ///////////////////////////////////////////////////////////////////////////////
18 /// \ingroup  tag_SystemManager
19 /// \brief    This file provides support for the application heartbeat system.
20 ///
21 ///////////////////////////////////////////////////////////////////////////////
22 #include <system_service/ss_heartbeat_service_protocol.h>
23 #include <system_service/ss_system_manager_if.h>
24 #include <system_service/ss_system_manager_if_local.h>
25 #include <stdlib.h>
26 #include <string.h>
27 #include <native_service/frameworkunified_framework_if.h>
28 #include <system_service/ss_services.h>
29 #include <system_service/ss_templates.h>
30
31 #include "ss_hb_thread.h"
32 #include "ss_sm_systemmanagerlog.h"
33
34 /*****************************************************************************
35  @ingroup: SS_SystemManager
36  @brief: HBOnTimerExpiry
37  @note: .
38  @param HANDLE  - Handle to message queue of HeartBeat Service.
39  @return EFrameworkunifiedStatus
40  *****************************************************************************/
41 EFrameworkunifiedStatus CHeartBeatThread::HBOnTimerExpiry(HANDLE f_hThread) {
42   FRAMEWORKUNIFIEDLOG(ZONE_PERIODIC_FUNC, __FUNCTION__, "+");
43   EFrameworkunifiedStatus l_eStatus;
44
45   // check heart beat replies received from clients.
46   l_eStatus = HBCheckHeartBeatResponses(f_hThread);
47   LOG_STATUS_IF_ERRORED(l_eStatus, "HBCheckHeartBeatResponses()");  // LCOV_EXCL_BR_LINE 15: marco defined in ss_templates.h  // NOLINT(whitespace/line_length)
48
49   // send heart beat requests to clients
50   l_eStatus = HBSendRequest(f_hThread);
51   LOG_STATUS_IF_ERRORED(l_eStatus, "HBSendRequest()");  // LCOV_EXCL_BR_LINE 15: marco defined in ss_templates.h  // NOLINT(whitespace/line_length)
52
53   FRAMEWORKUNIFIEDLOG(ZONE_PERIODIC_FUNC, __FUNCTION__, "-");
54   return (l_eStatus);
55 }
56
57 /*****************************************************************************
58  @ingroup: SS_SystemManager
59  @brief:   HBOnClientResponse
60  @note: .
61  @param HANDLE - Handle to message queue of HeartBeat Service.
62  @return EFrameworkunifiedStatus OK or Fail
63  *****************************************************************************/
64 EFrameworkunifiedStatus CHeartBeatThread::HBOnClientResponse(HANDLE f_hThread) {
65   EFrameworkunifiedStatus l_eStatus;
66   FRAMEWORKUNIFIEDLOG(ZONE_PERIODIC_FUNC, __FUNCTION__, "+");
67   l_eStatus = m_oSessionHandler.HBProcessClientResponse(f_hThread);
68   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)
69   FRAMEWORKUNIFIEDLOG(ZONE_PERIODIC_FUNC, __FUNCTION__, "-");
70   return l_eStatus;
71 }
72
73 /*****************************************************************************
74  @ingroup: SS_SystemManager
75  @brief: HBOnPeriodicStatusRequest
76  @note: .
77  @param  HANDLE - Handle to message queue of HeartBeat Service.
78  @return EFrameworkunifiedStatus OK or Fail
79  *****************************************************************************/
80 EFrameworkunifiedStatus CHeartBeatThread::HBOnPeriodicStatusRequest(HANDLE f_hThread) {
81   EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK;
82   FRAMEWORKUNIFIEDLOG(ZONE_PERIODIC_FUNC, __FUNCTION__, "+");
83   // LCOV_EXCL_BR_START 4: NSFW error case.
84   if (eFrameworkunifiedStatusOK != (l_eStatus = FrameworkunifiedSendParent(f_hThread, SS_HEARTBEAT_PERIODIC_RESP, 0, NULL))) {
85   // LCOV_EXCL_BR_STOP
86     AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
87     LOG_ERROR("FrameworkunifiedSendParent(SS_HEARTBEAT_PERIODIC_RESP)");  // LCOV_EXCL_LINE 4: NSFW error case.
88   } else {
89     FRAMEWORKUNIFIEDLOG(ZONE_PERIODIC_INFO, __FUNCTION__, "Successful");
90   }
91
92   FRAMEWORKUNIFIEDLOG(ZONE_PERIODIC_FUNC, __FUNCTION__, "-");
93   return l_eStatus;
94 }
95
96 /*****************************************************************************
97  @ingroup: SS_SystemManager
98  @brief: HBOnPeriodicStatusRequest
99  @note: .
100  @param  HANDLE - Handle to message queue of HeartBeat Service.
101  @return EFrameworkunifiedStatus OK or Fail
102  *****************************************************************************/
103 EFrameworkunifiedStatus CHeartBeatThread::HBOnAvailCheckRequest(HANDLE f_hThread) {
104   FRAMEWORKUNIFIEDLOG(ZONE_STATE, __FUNCTION__, "+");
105
106   EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK;
107   THbAvailCheck check;
108   l_eStatus = m_oSessionHandler.HBAvailableCheck(check);
109   SS_ASERT(l_eStatus == eFrameworkunifiedStatusOK);  // LCOV_EXCL_BR_LINE 15: marco defined in ss_templates.h  // NOLINT(whitespace/line_length)
110
111   // LCOV_EXCL_BR_START 4: NSFW error case.
112   if (eFrameworkunifiedStatusOK != (l_eStatus = FrameworkunifiedSendParent(f_hThread, SS_HEARTBEAT_AVAIL_CHECK_RESP, sizeof(check), &check))) {
113   // LCOV_EXCL_BR_STOP
114     AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
115     LOG_ERROR("FrameworkunifiedSendParent(SS_HEARTBEAT_AVAIL_CHECK_RESP)");  // LCOV_EXCL_LINE 4: NSFW error case.
116   }
117
118   return l_eStatus;
119 }
120
121 /*****************************************************************************
122  @ingroup: SS_SystemManager
123  @brief: HBOnRemoveModule
124  @note: .
125  @param  HANDLE - Handle to message queue of HeartBeat Service.
126  @return EFrameworkunifiedStatus OK or Fail
127  *****************************************************************************/
128 EFrameworkunifiedStatus CHeartBeatThread::HBOnRemoveModule(HANDLE f_hThread) {
129   EFrameworkunifiedStatus l_eStatus;
130   FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+");
131
132   TSMRequestMessage tReqMsgData;
133   // ReadMsg():                                                        *
134   //     Check hApp ptr, msg size, msg reception, read msg if all ok.  *
135   //     Report any errors found.                                      *
136   //                                                                   *
137   // LCOV_EXCL_BR_START 4: NSFW error case.
138   if (eFrameworkunifiedStatusOK != (l_eStatus = ReadMsg <TSMRequestMessage> (f_hThread, tReqMsgData))) {
139   // LCOV_EXCL_BR_STOP
140     AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
141     LOG_ERROR("ReadMsg()");  // LCOV_EXCL_LINE 4: NSFW error case.
142   } else {
143     FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__,
144         " %s is required to be Deleted from HeartBeat Monitor List", tReqMsgData.pstModuleName);
145
146     // delete module entry from map
147     l_eStatus = m_oSessionHandler.HBDeleteRegisteredClientEntry(f_hThread, tReqMsgData.pstModuleName);
148     LOG_STATUS_IF_ERRORED(l_eStatus, "m_oSessionHandler.HBDeleteRegisteredProcessEntry()");  // LCOV_EXCL_BR_LINE 15: marco defined in ss_templates.h  // NOLINT(whitespace/line_length)
149   }
150   FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-");
151   return l_eStatus;
152 }
153
154 /*****************************************************************************
155  @ingroup: SS_SystemManager
156  @brief: HBOnAppendModule
157  @note: .
158  @param  HANDLE - Handle to message queue of HeartBeat Service.
159  @return EFrameworkunifiedStatus OK or Fail
160  *****************************************************************************/
161 EFrameworkunifiedStatus CHeartBeatThread::HBOnAppendModule(HANDLE f_hThread) {
162   EFrameworkunifiedStatus l_eStatus;
163   FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+");
164
165   TSMRequestMessage tReqMsgData;
166   // ReadMsg():                                                        *
167   //     Check hApp ptr, msg size, msg reception, read msg if all ok.  *
168   //     Report any errors found.                                      *
169   //                                                                   *
170   if (eFrameworkunifiedStatusOK != (l_eStatus = ReadMsg < TSMRequestMessage > (f_hThread, tReqMsgData))) {
171     LOG_ERROR("ReadMsg()");
172   } else {
173     FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__,
174         " %s is required to be Appended from HeartBeat Monitor List", tReqMsgData.pstModuleName);
175
176     // append module entry from map
177     SubscriberName l_Subscriber = tReqMsgData.pstModuleName;
178     l_eStatus = m_oSessionHandler.HBEntrySubscriber(l_Subscriber);  // LCOV_EXCL_BR_LINE 11:unexpected branch  // NOLINT(whitespace/line_length)
179     LOG_STATUS_IF_ERRORED(l_eStatus, "m_oSessionHandler.HBEntrySubscriber()");  // LCOV_EXCL_BR_LINE 15: marco defined in ss_templates.h  // NOLINT(whitespace/line_length)
180   }
181   FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-");
182   return l_eStatus;
183 }
184 // EOF