Fix path to various non-standard directories
[staging/basesystem.git] / service / system / system_manager / server / src / ss_system_manager_callbacks.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 System Manager business logic.
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 <native_service/frameworkunified_multithreading.h>
26 #include <sys/wait.h>
27 #include <system_service/ss_system_manager_notifications.h>
28 #include <system_service/ss_system_manager_notifications_local.h>
29 #include <native_service/frameworkunified_framework_if.h>
30 #include <system_service/ss_services.h>
31 #include <system_service/ss_power_service_if.h>
32 #include <processlauncher/ProcessLauncher.h>
33 #include <processlauncher/ss_sm_process_launcher_protocol.h>
34 #include <processlauncher/ss_sm_process_launcher.h>
35 #include <heartbeat/ss_hb_thread.h>
36
37 #include <system_service/ss_power_service_notifications.h>
38 #include <system_service/ss_power_service_protocol.h>
39
40 #include <native_service/ns_np_service.h>
41 #include <native_service/ns_np_service_protocol.h>
42 #include <native_service/ns_backup.h>
43
44 #include <stub/ss_diag.h>
45
46 #include <system_service/ss_error_message.h>
47 #include <system_service/ss_test_clients.h>
48 #include <system_service/ss_templates.h>
49 #include <native_service/ns_plogger_if.h>
50
51 #include <stdlib.h>
52 #include <stdio.h>
53 #include <sys/types.h>
54 #include <sys/stat.h>
55 #include <fcntl.h>
56 #include <iomanip>
57 #include <vector>
58 #include <algorithm>
59 #include <string>
60
61 #include "ss_system_manager_callbacks.h"
62 #include "ss_system_manager.h"
63 #include "ss_sm_systemmanagerlog.h"
64 #include "ss_sm_config.h"
65
66 using namespace std;  // NOLINT
67
68 extern SS_String GetStr(SS_SMModuleState f_enum);
69
70 template<typename C, eFrameworkunifiedStatus (C::*M)(HANDLE)> EFrameworkunifiedStatus SysMgrCallback(HANDLE hApp) {
71   EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusFail;
72   C * pObj = static_cast<C *>(&CSystemManager::GetInstance());
73   if (pObj) {  // LCOV_EXCL_BR_LINE 5 : new error
74     l_eStatus = (pObj->*M)(hApp);
75   }
76   return l_eStatus;
77 }
78
79 template<typename C, eFrameworkunifiedStatus (C::*M)(HANDLE, UI_32)>
80 EFrameworkunifiedStatus SysMgrCbType2(HANDLE hApp, UI_32 f_UI_32) {
81   EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusFail;
82   C * pObj = static_cast<C *>(&CSystemManager::GetInstance());
83   if (pObj) {  // LCOV_EXCL_BR_LINE 5 : new error
84     l_eStatus = (pObj->*M)(hApp, f_UI_32);
85   }
86   return l_eStatus;
87 }
88
89 template<typename C, BOOL (C::*M)(UI_32)>
90 BOOL SysMgrCbType3(UI_32 f_UI_32) {
91   BOOL l_bValue = FALSE;
92   C * pObj = static_cast<C *>(&CSystemManager::GetInstance());
93   if (pObj) {  // LCOV_EXCL_BR_LINE 5 : new error
94     l_bValue = (pObj->*M)(f_UI_32);
95   }
96   return l_bValue;
97 }
98
99 enum {
100   POWERON = TRUE,
101   POWEROFF = FALSE
102 };
103
104 VOID CSystemManager::LogGroupModulesState(UI_32 f_groupId, std::string pStr) {
105   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)
106     // LCOV_EXCL_START 6: Because the applicable variable cannot be changed from the external API (only evaluated by the initial value)
107     AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
108     FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+");
109
110     GroupLaunchMapIter l_GroupIterator = m_MapProclaunchGrps.find(f_groupId);
111     if (l_GroupIterator == m_MapProclaunchGrps.end()) {
112       FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__,
113              " Error: Group %d not found; 'm_MapProclaunchGrps' is empty",
114              f_groupId);
115     } else {
116       std::string sIsOKFlag;
117       TEXT(__FUNCTION__, " Group %d/%s, %ld modules: %s, %s", f_groupId,
118           l_GroupIterator->second.name.c_str(),
119           l_GroupIterator->second.modules.size(), pStr.c_str(),
120           GetStr(m_SMCurrentState).c_str());
121
122       ModuleLaunchListIter l_ModuleListIterator = l_GroupIterator->second.modules.begin();
123       for (int i = 1;
124           l_ModuleListIterator != l_GroupIterator->second.modules.end();
125           l_ModuleListIterator++, i++) {
126         sIsOKFlag = GetModuleCondition(l_ModuleListIterator) ? " " :  // 'blank' means OK
127             "X";  // 'X' means state mismatch
128
129         TEXT(__FUNCTION__,
130           "   %2d: %-24s Start Req'd: %-5s %s %-24s %3dms, %3dms, %d",
131           i, l_ModuleListIterator->name.c_str(),
132         l_ModuleListIterator->is_start_required ?
133                 "TRUE" : "FALSE", sIsOKFlag.c_str(),
134         l_ModuleListIterator->ModuleStateStr().c_str(),
135         static_cast<SI_16>(l_ModuleListIterator->m_startReason.GetDelta()),
136         static_cast<SI_16>(l_ModuleListIterator->m_stopReason.GetDelta()),
137         l_ModuleListIterator->pid);
138       }
139     }
140     FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-");
141     // LCOV_EXCL_STOP
142   }
143 }  // End of VOID CSystemManager::LogGroupModulesState( UI_32 f_groupId, std::string pStr)
144
145 VOID CSystemManager::LogAllGroupModulesState(std::string pStr) {
146   FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+");
147
148   std::string l_sIsOKFlag;
149   GroupLaunchMapIter l_GroupIterator = m_MapProclaunchGrps.begin();
150
151   std::stringstream l_comStream;
152
153   l_comStream << pStr << "," << GetStr(m_SMCurrentState);
154
155   std::string l_comStr = l_comStream.str();
156   SystemmanagerLogString(ZONE_STATE, __FUNCTION__, l_comStr);
157
158   while (l_GroupIterator != m_MapProclaunchGrps.end()) {
159     std::stringstream l_tblStream;
160     l_tblStream << "G" << l_GroupIterator->second.id << "/" << l_GroupIterator->second.name;
161
162     ModuleLaunchListIter l_ModuleListIterator = l_GroupIterator->second.modules.begin();
163
164     for (int i = 1;
165         l_ModuleListIterator != l_GroupIterator->second.modules.end();
166         l_ModuleListIterator++, i++) {
167       // Since NPPService exceptionally transitions to STARTED when StartReq'd = N, it is not checked
168       l_sIsOKFlag =
169           GetModuleCondition(l_ModuleListIterator)
170               | (FRAMEWORKUNIFIED_NS_NPSERVICE == l_ModuleListIterator->name) ?
171               " " :  // 'blank' means OK
172               "X";   // 'X' means state mismatch
173
174       std::string l_isStartReqd = l_ModuleListIterator->is_start_required ? "T" : "F";
175
176       l_tblStream << endl << " " << std::setw(2) << std::right << i << ":"
177           << l_ModuleListIterator->pid << " "
178           << l_ModuleListIterator->name << " " << "StartReq:"
179           << l_isStartReqd << " " << l_sIsOKFlag
180           << l_ModuleListIterator->ModuleStateStr();
181
182       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)
183         l_tblStream << " "
184             << static_cast<SI_32>(l_ModuleListIterator->m_startReason.GetDelta())
185             << "ms "
186             << static_cast<SI_32>(l_ModuleListIterator->m_stopReason.GetDelta())
187             << "ms";
188       }
189     }
190
191     l_GroupIterator++;
192
193     // Outputs each GROUP so that buffers do not overflow.
194     std::string l_logMsgStr = l_tblStream.str();
195     SystemmanagerLogString(ZONE_STATE, __FUNCTION__, l_logMsgStr);
196   }
197
198   FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-");
199 }  // End of VOID CSystemManager::LogAllGroupModulesState(std::string pStr)
200
201 BOOL CSystemManager::GetModuleCondition(ModuleLaunchListIter & f_ModuleIter) {
202   FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+");
203   BOOL l_bIsModuleStateGood = TRUE;
204
205   switch (m_SMCurrentState) {  // LCOV_EXCL_BR_LINE 6: As no values are passed into the default case
206   case SS_SM_READY_TO_LAUNCH_APP:
207     l_bIsModuleStateGood = f_ModuleIter->IsModuleState(MODULE_STATE_INVALID);
208     break;
209
210   case SS_SM_APPS_LAUNCH_IN_PROGRESS:
211     l_bIsModuleStateGood = f_ModuleIter->IsModuleState(MODULE_STATE_SKIPPED)
212         || f_ModuleIter->IsModuleState(MODULE_STATE_LAUNCH_FAILED)
213         || f_ModuleIter->IsModuleState(MODULE_STATE_LAUNCHING)
214         || f_ModuleIter->IsModuleState(MODULE_STATE_LAUNCHED);
215     break;
216
217   case SS_SM_APPS_LAUNCHED_READY_TO_START:
218     l_bIsModuleStateGood = f_ModuleIter->IsModuleState(MODULE_STATE_SKIPPED)
219         || f_ModuleIter->IsModuleState(MODULE_STATE_LAUNCH_FAILED)
220         || f_ModuleIter->IsModuleState(MODULE_STATE_CONNECTED)
221         || f_ModuleIter->IsModuleState(MODULE_STATE_LAUNCHED);
222     break;
223
224   case SS_SM_APPS_START_IN_PROGRESS:
225     l_bIsModuleStateGood = f_ModuleIter->IsModuleState(MODULE_STATE_SKIPPED)
226         || f_ModuleIter->IsModuleState(MODULE_STATE_LAUNCH_FAILED)
227         || (f_ModuleIter->is_start_required
228             && (f_ModuleIter->IsModuleState(MODULE_STATE_START_SENT)
229                 || f_ModuleIter->IsModuleState(
230                     MODULE_STATE_STARTED)))
231         || (!f_ModuleIter->is_start_required
232             && (f_ModuleIter->IsModuleState(MODULE_STATE_LAUNCHED)
233                 || f_ModuleIter->IsModuleState(
234                     MODULE_STATE_CONNECTED)));
235     break;
236
237   case SS_SM_APPS_START_COMPLETE:
238       l_bIsModuleStateGood =
239           ((f_ModuleIter->IsModuleState(MODULE_STATE_SKIPPED) == TRUE)
240               || (f_ModuleIter->IsModuleState(MODULE_STATE_LAUNCH_FAILED) == TRUE)
241               || ((f_ModuleIter->is_start_required == TRUE)
242                   && (f_ModuleIter->IsModuleState(MODULE_STATE_STARTED) == TRUE))
243               || ((f_ModuleIter->is_start_required == FALSE)
244                   && ((f_ModuleIter->IsModuleState(MODULE_STATE_LAUNCHED) == TRUE)
245                       || (f_ModuleIter->IsModuleState(MODULE_STATE_CONNECTED) == TRUE)))) ? (BOOL) TRUE : (BOOL) FALSE;
246     break;
247
248   case SS_SM_APPS_PRE_START_IN_PROGRESS:
249       l_bIsModuleStateGood =
250           ((f_ModuleIter->IsModuleState(MODULE_STATE_SKIPPED) == TRUE)
251               || (f_ModuleIter->IsModuleState(MODULE_STATE_LAUNCH_FAILED) == TRUE)
252               || ((f_ModuleIter->is_start_required == TRUE)
253                   && ((f_ModuleIter->IsModuleState(MODULE_STATE_START_PRE_SENT) == TRUE)
254                       || (f_ModuleIter->IsModuleState(MODULE_STATE_STARTED_PRE) == TRUE)))
255               || ((f_ModuleIter->is_start_required == FALSE)
256                   && ((f_ModuleIter->IsModuleState(MODULE_STATE_LAUNCHED) == TRUE)
257                       || (f_ModuleIter->IsModuleState(MODULE_STATE_CONNECTED) == TRUE)))) ? (BOOL) TRUE : (BOOL) FALSE;
258     break;
259
260     case SS_SM_APPS_PRE_STOP_IN_PROGRESS:
261       l_bIsModuleStateGood =
262           ((f_ModuleIter->IsModuleState(MODULE_STATE_SKIPPED) == TRUE)
263               || (f_ModuleIter->IsModuleState(MODULE_STATE_LAUNCH_FAILED) == TRUE)
264               || ((f_ModuleIter->is_start_required == TRUE)
265                   && ((f_ModuleIter->IsModuleState(MODULE_STATE_STOP_PRE_SENT) == TRUE)
266                       || (f_ModuleIter->IsModuleState(MODULE_STATE_STOPPED_PRE) == TRUE)))
267               || ((f_ModuleIter->is_start_required == FALSE)
268                   && ((f_ModuleIter->IsModuleState(MODULE_STATE_LAUNCHED) == TRUE)
269                       || (f_ModuleIter->IsModuleState(MODULE_STATE_CONNECTED) == TRUE)))) ? (BOOL) TRUE : (BOOL) FALSE;
270       break;
271
272     case SS_SM_APPS_PRE_RUN_COMPLETE:
273       l_bIsModuleStateGood =
274           ((f_ModuleIter->IsModuleState(MODULE_STATE_SKIPPED) == TRUE)
275               || (f_ModuleIter->IsModuleState(MODULE_STATE_LAUNCH_FAILED) == TRUE)
276               || ((f_ModuleIter->is_start_required == TRUE)
277                   && ((f_ModuleIter->IsModuleState(MODULE_STATE_STARTED_PRE) == TRUE)
278                       || (f_ModuleIter->IsModuleState(MODULE_STATE_STOPPED_PRE) == TRUE)))
279               || ((f_ModuleIter->is_start_required == FALSE)
280                   && ((f_ModuleIter->IsModuleState(MODULE_STATE_LAUNCHED) == TRUE)
281                       || (f_ModuleIter->IsModuleState(MODULE_STATE_CONNECTED) == TRUE)))) ? (BOOL) TRUE : (BOOL) FALSE;
282       break;
283
284     case SS_SM_APPS_BACKGROUND_START_IN_PROGRESS:
285       l_bIsModuleStateGood =
286           ((f_ModuleIter->IsModuleState(MODULE_STATE_SKIPPED) == TRUE)
287               || (f_ModuleIter->IsModuleState(MODULE_STATE_LAUNCH_FAILED) == TRUE)
288               || ((f_ModuleIter->is_start_required == TRUE)
289                   && ((f_ModuleIter->IsModuleState(MODULE_STATE_START_BACKGROUND_SENT) == TRUE)
290                       || (f_ModuleIter->IsModuleState(MODULE_STATE_STARTED_BACKGROUND) == TRUE)))
291               || ((f_ModuleIter->is_start_required == FALSE)
292                   && ((f_ModuleIter->IsModuleState(MODULE_STATE_LAUNCHED) == TRUE)
293                       || (f_ModuleIter->IsModuleState(MODULE_STATE_CONNECTED) == TRUE)))) ? (BOOL) TRUE : (BOOL) FALSE;
294       break;
295
296     case SS_SM_APPS_BACKGROUND_STOP_IN_PROGRESS:
297       l_bIsModuleStateGood =
298           ((f_ModuleIter->IsModuleState(MODULE_STATE_SKIPPED) == TRUE)
299               || (f_ModuleIter->IsModuleState(MODULE_STATE_LAUNCH_FAILED) == TRUE)
300               || ((f_ModuleIter->is_start_required == TRUE)
301                   && ((f_ModuleIter->IsModuleState(MODULE_STATE_STOP_BACKGROUND_SENT) == TRUE)
302                       || (f_ModuleIter->IsModuleState(MODULE_STATE_STOPPED_BACKGROUND) == TRUE)))
303               || ((f_ModuleIter->is_start_required == FALSE)
304                   && ((f_ModuleIter->IsModuleState(MODULE_STATE_LAUNCHED) == TRUE)
305                       || (f_ModuleIter->IsModuleState(MODULE_STATE_CONNECTED) == TRUE)))) ? (BOOL) TRUE : (BOOL) FALSE;
306       break;
307     case SS_SM_APPS_BACKGROUND_RUN_COMPLETE:
308       l_bIsModuleStateGood =
309           ((f_ModuleIter->IsModuleState(MODULE_STATE_SKIPPED) == TRUE)
310               || (f_ModuleIter->IsModuleState(MODULE_STATE_LAUNCH_FAILED) == TRUE)
311               || ((f_ModuleIter->is_start_required == TRUE)
312                   && ((f_ModuleIter->IsModuleState(MODULE_STATE_STARTED_BACKGROUND) == TRUE)
313                       || (f_ModuleIter->IsModuleState(MODULE_STATE_STOPPED_BACKGROUND) == TRUE)))
314               || ((f_ModuleIter->is_start_required == FALSE)
315                   && ((f_ModuleIter->IsModuleState(MODULE_STATE_LAUNCHED) == TRUE)
316                       || (f_ModuleIter->IsModuleState(MODULE_STATE_CONNECTED) == TRUE)))) ? (BOOL) TRUE : (BOOL) FALSE;
317       break;
318
319   case SS_SM_APPS_STOPPING_AT__CWORD56__REQ:
320   case SS_SM_APPS_STOPPING_AT_INTERNAL_REQ:
321     l_bIsModuleStateGood = f_ModuleIter->IsModuleState(MODULE_STATE_SKIPPED)
322         || f_ModuleIter->IsModuleState(MODULE_STATE_LAUNCH_FAILED)
323         || (f_ModuleIter->is_start_required
324             && (f_ModuleIter->IsModuleState(MODULE_STATE_STOP_SENT)
325                 || f_ModuleIter->IsModuleState(
326                     MODULE_STATE_STOPPED)))
327         || (!f_ModuleIter->is_start_required
328             && (f_ModuleIter->IsModuleState(MODULE_STATE_LAUNCHED)
329                 || f_ModuleIter->IsModuleState(
330                     MODULE_STATE_CONNECTED)));
331     break;
332
333   case SS_SM_WAITING_FOR_CRITICAL_APPS_AT__CWORD56__REQ:
334   case SS_SM_WAITING_FOR_CRITICAL_APPS_AT_INTERNAL_REQ:
335     l_bIsModuleStateGood = f_ModuleIter->IsModuleState(MODULE_STATE_SKIPPED)
336         || f_ModuleIter->IsModuleState(MODULE_STATE_LAUNCH_FAILED)
337         || (f_ModuleIter->is_start_required
338             && f_ModuleIter->IsModuleState(MODULE_STATE_STOPPED))
339         || (!f_ModuleIter->is_start_required
340             && (f_ModuleIter->IsModuleState(MODULE_STATE_LAUNCHED)
341                 || f_ModuleIter->IsModuleState(
342                     MODULE_STATE_CONNECTED)));
343     break;
344
345     // default:  Don't code a 'default' here - let the compiler
346     // issue a warning ( set via -Wall or -Wswitch ) when the set of
347     // enumerations changes - then the maintainer will
348     // automagically know to update this switch statement.
349   }
350
351   FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-");
352   return l_bIsModuleStateGood;
353 }  // End of BOOL CSystemManager::GetModuleCondition( ModuleLaunchListIter & f_ModuleIter )
354
355 /*****************************************************************************
356  @ingroup: CSystemManager
357  @brief: Post Termination handler
358  @note: .
359  @param void
360  @return void
361 *****************************************************************************/
362 EFrameworkunifiedStatus CSystemManager::SendRequestToHeartBeat(HANDLE hApp,
363         EHBProtocolMessages tRequest, VOID *tReqMessageData,
364         UI_32 u32SizeofMessage) {
365   EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK;
366   BOOL bValid = FALSE;
367
368   FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+");
369   switch (tRequest) {
370   case SS_HEARTBEAT_START:
371     bValid = TRUE;
372     FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__, "SS_HEARTBEAT_START");
373     break;
374
375   case SS_HEARTBEAT_STOP:
376     bValid = TRUE;
377     FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__, "SS_HEARTBEAT_STOP");
378     tReqMessageData = NULL;
379     break;
380
381   case SS_HEARTBEAT_DELETE_MODULE_ENTRY:
382     bValid = TRUE;
383     FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__, "SS_HEARTBEAT_DELETE_MODULE_ENTRY");
384     break;
385
386   case SS_HEARTBEAT_APPEND_MODULE_ENTRY:
387     bValid = TRUE;
388     FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__, "SS_HEARTBEAT_APPEND_MODULE_ENTRY");
389     break;
390
391   default:
392     bValid = FALSE;
393     l_eStatus = eFrameworkunifiedStatusInvldParam;
394     FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, " Error : Ignored Invalid message id 0x%X", tRequest);
395     break;
396   }
397
398   if (TRUE == bValid) {  // LCOV_EXCL_BR_LINE 200:tRequest cannot be default, so bValid cannot be false
399     if (INVALID_HANDLE != m_hHeartbeatThread.m_ThreadHdl) {  // LCOV_EXCL_BR_LINE 200:m_ThreadHdl cannot be null
400       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)
401         // LCOV_EXCL_START 4: nsfw error
402         AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
403         LOG_ERROR("FrameworkunifiedSendChild()");  // LCOV_EXCL_BR_LINE 15: marco defined in ss_templates.h  // NOLINT(whitespace/line_length)
404         // LCOV_EXCL_STOP
405       }
406     } else {
407       // LCOV_EXCL_START 200: m_ThreadHdl cannot be null
408       AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
409       l_eStatus = eFrameworkunifiedStatusInvldHandle;
410       FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, " Error : Invalid Heartbeat Thread Handle, cannot send message");
411       // LCOV_EXCL_STOP
412     }
413   }
414   FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-");
415   return l_eStatus;
416 }
417
418 ///////////////////////////////////////////////////////////////////////////////
419 /// \ingroup OnModuleConnectWaitTimeout
420 ///  SM maintains timer (40 sec) to check if all modules opened session with him whoever requires Start.
421 ///  This timer is common to all modules. After timeout it checks the status of every module in group map.
422 ///  If a module requires start and does not connect, SM will initiate error event logging followed by Soft Reset
423 /// \param [in]
424 ///
425 ///
426 /// \return EFrameworkunifiedStatus
427 /// Success ==> eFrameworkunifiedStatusOK
428 /// Failure ==> Other values
429 ///////////////////////////////////////////////////////////////////////////////
430 EFrameworkunifiedStatus CSystemManager::OnModuleConnectWaitTimeout(HANDLE hApp) {
431   FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+");
432   EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK;
433
434   static SI_32 l_NumTimesChecked = 0;
435   {
436     char l_cFormat[] = " Received from (Timer expiration %d)";
437     char l_cBuf[sizeof(l_cFormat) + 1];
438     snprintf(l_cBuf, sizeof(l_cBuf), l_cFormat, l_NumTimesChecked + 1);
439     FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__, l_cBuf);
440   }
441
442   std::string l_ProcName;
443
444   SetCmdHist("SM_TIMER_MODULE_CONNECT_WAIT_TIMER", m_TimerCmdHist, // LCOV_EXCL_BR_LINE 11:unexpected branch  // NOLINT(whitespace/line_length)
445       m_TimerHistIter, FrameworkunifiedGetMsgSrc(hApp)); // LCOV_EXCL_BR_LINE 11:unexpected branch  // NOLINT(whitespace/line_length)
446
447   BOOL l_bModuleConnMissed = false;
448
449   GroupLaunchMap::reverse_iterator l_grp_riter = m_MapProclaunchGrps.rbegin();
450
451   ModuleLaunchList::reverse_iterator l_mod_riter;
452
453   if (l_grp_riter == m_MapProclaunchGrps.rend()) {  // LCOV_EXCL_BR_LINE 200: group cannot be empty
454     // LCOV_EXCL_START 200: group cannot be empty
455     AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
456     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)
457     l_eStatus = eFrameworkunifiedStatusDbRecNotFound;
458     // LCOV_EXCL_STOP
459   } else {
460     // scan the group map in reverse order
461     for (; l_grp_riter != m_MapProclaunchGrps.rend(); l_grp_riter++) {
462       l_mod_riter = l_grp_riter->second.modules.rbegin();
463       for (; l_mod_riter != l_grp_riter->second.modules.rend();
464           l_mod_riter++) {
465         SMModuleState l_ModuleState = l_mod_riter->GetModuleState();
466         // if the module is still in MODULE_STATE_LAUNCHED state at
467         // this point though it requires start something is wrong with
468         // the module. SM initiates error event logging followed by
469         // soft rest
470         if (l_mod_riter->is_start_required
471             && ((l_ModuleState == MODULE_STATE_INVALID)
472                 || (l_ModuleState == MODULE_STATE_SKIPPED)
473                 || (l_ModuleState == MODULE_STATE_LAUNCHING)
474                 || (l_ModuleState == MODULE_STATE_LAUNCHED)
475                 || (l_ModuleState == MODULE_STATE_LAUNCH_FAILED))) {
476           FRAMEWORKUNIFIEDLOG(ZONE_WARN, __FUNCTION__,
477               " Module %s/%s is not connected",
478               l_mod_riter->name.c_str(),
479               l_mod_riter->ModuleStateStr().c_str());
480           l_bModuleConnMissed = true;
481           l_ProcName.assign(l_mod_riter->name);
482
483           if (l_ModuleState == MODULE_STATE_LAUNCHED) {
484             CALL_AND_LOG_STATUS_IF_ERRORED(  // LCOV_EXCL_BR_LINE 15: marco defined in ss_templates.h  // NOLINT(whitespace/line_length)
485                 l_mod_riter->SetPriority(  // LCOV_EXCL_BR_LINE 15: marco defined in ss_templates.h  // NOLINT(whitespace/line_length)
486                     m_SystemManagerPriority - 1));  // LCOV_EXCL_BR_LINE 15: marco defined in ss_templates.h  // NOLINT(whitespace/line_length)
487           }
488         }
489       }
490     }
491   }
492
493   PreLaunchModuleListIter l_itr;
494   for (l_itr = m_PreLaunchModuleList.begin();
495       m_PreLaunchModuleList.end() != l_itr; l_itr++) {
496     if ((-1 == l_itr->pid) && (l_itr->critical)) {  // LCOV_EXCL_BR_LINE 200: all prelaunch mode is not critical  // NOLINT(whitespace/line_length)
497       // LCOV_EXCL_START 200: all prelaunch mode is not critical
498       AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
499       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)
500           l_itr->name.c_str());  // LCOV_EXCL_BR_LINE 15: marco defined in ns_logger_if.h  // NOLINT(whitespace/line_length)
501       l_bModuleConnMissed = true;
502       l_ProcName.assign(l_itr->name);
503     }
504     // LCOV_EXCL_STOP
505   }
506
507   l_NumTimesChecked++;
508   if (true == l_bModuleConnMissed) {
509     if (l_NumTimesChecked < m_SMConfig.MCConfig.ModuleConnectionNumTimesToCheck) {
510       char l_cFormat[] =
511           " l_NumTimesChecked %d < ModuleConnectionNumTimesToCheck %d, "
512               "will re-check in %d seconds. ";
513       char l_cBuf[sizeof(l_cFormat) + 1 + 1 + 1];
514       snprintf(l_cBuf, sizeof(l_cBuf), l_cFormat, l_NumTimesChecked,
515           m_SMConfig.MCConfig.ModuleConnectionNumTimesToCheck,
516           m_SMConfig.MCConfig.ModuleConnectionTimeOutSec);
517       FRAMEWORKUNIFIEDLOG(ZONE_WARN, __FUNCTION__, l_cBuf);
518
519     } else {
520       l_eStatus = eFrameworkunifiedStatusBadConnection;
521       char l_cFormat[] =
522           " Module connection timeout for %s and "
523               "l_NumTimesChecked %d == ModuleConnectionNumTimesToCheck %d. "
524               " Stopping ModuleConnectTimeOut timer and resetting _CWORD102_.";
525       char l_cBuf[sizeof(l_cFormat) + MAX_NAME_SIZE_APP + 1 + 1];
526       snprintf(l_cBuf, sizeof(l_cBuf), l_cFormat, l_ProcName.c_str(),
527           l_NumTimesChecked,
528           m_SMConfig.MCConfig.ModuleConnectionNumTimesToCheck);
529       LOG_ERROR(l_cBuf);  // LCOV_EXCL_BR_LINE 15: marco defined in ss_templates.h  // NOLINT(whitespace/line_length)
530
531       m_GroupLaunchTimer->StopTimer(m_aTimerIDs[eSM_TIMER_MODULE_CONNECT_WAIT_TIMER]); // LCOV_EXCL_BR_LINE 11:unexpected branch  // NOLINT(whitespace/line_length)
532
533       SMLoggingInfo l_loggingInfo; // LCOV_EXCL_BR_LINE 11:unexpected branch  // NOLINT(whitespace/line_length)
534       l_loggingInfo.resetReason = e_SS_SM_CPU_RESET_REASON_GENERIC_ERR; // LCOV_EXCL_BR_LINE 11:unexpected branch  // NOLINT(whitespace/line_length)
535
536       // initiate error event logging
537       l_eStatus = ErrorEventEnqueue(hApp, eErrorEventTypeModConnFailed,
538           l_ProcName, eErrorEventResetTypeHard, l_loggingInfo);
539       FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, " Error: ModConnFailed %s",
540           l_ProcName.c_str());
541       fprintf(stderr, "SS_SysManager/%s/Error: ModConnFailed %s\n", // LCOV_EXCL_BR_LINE 11:unexpected branch  // NOLINT(whitespace/line_length)
542           __FUNCTION__, l_ProcName.c_str()); // LCOV_EXCL_BR_LINE 11:unexpected branch  // NOLINT(whitespace/line_length)
543       LOG_STATUS_REC_HIST_IF_ERRORED(l_eStatus,  // LCOV_EXCL_BR_LINE 15: marco defined in ss_system_manager.h  // NOLINT(whitespace/line_length)
544           "ErrorEventEnqueue(eErrorEventTypeModConnFailed)");  // LCOV_EXCL_BR_LINE 15: marco defined in ss_system_manager.h  // NOLINT(whitespace/line_length)
545     }
546   } else {
547     char l_cFormat[] =
548         " l_NumTimesChecked = %d, ModuleConnectionNumTimesToCheck = %d. "
549             "All modules connected. Stopping ModuleConnectTimeOut timer.";
550     char l_cBuf[sizeof(l_cFormat) + 1 + 1];
551     snprintf(l_cBuf, sizeof(l_cBuf), l_cFormat, l_NumTimesChecked,
552         m_SMConfig.MCConfig.ModuleConnectionNumTimesToCheck);
553     FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__, l_cBuf);
554
555     m_GroupLaunchTimer->StopTimer(m_aTimerIDs[eSM_TIMER_MODULE_CONNECT_WAIT_TIMER]); // LCOV_EXCL_BR_LINE 11:unexpected branch  // NOLINT(whitespace/line_length)
556   }
557
558   FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-");
559   return l_eStatus;
560 }  // End of EFrameworkunifiedStatus CSystemManager::OnModuleConnectWaitTimeout( HANDLE hApp )
561
562 ///////////////////////////////////////////////////////////////////////////////
563 /// \ingroup OnClientStartMonitorTimerExpiry
564 ///
565 ///
566 /// \param [in]
567 ///
568 ///
569 /// \return EFrameworkunifiedStatus
570 /// Success ==> eFrameworkunifiedStatusOK
571 /// Failure ==> Other values
572 ///////////////////////////////////////////////////////////////////////////////
573 EFrameworkunifiedStatus CSystemManager::OnClientStartMonitorTimerExpiry(HANDLE hApp) {
574   EFrameworkunifiedStatus l_eStatus;
575   FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+");
576
577   FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__, " Received from group %d"
578     //, m_ActiveGroupId);
579       , m_SystemStarter.get_id());
580
581   char cBuf[100];
582   SetCmdHist("SM_TIMER_CLIENT_START_MONITOR", m_TimerCmdHist, m_TimerHistIter, FrameworkunifiedGetMsgSrc(hApp)); // LCOV_EXCL_BR_LINE 11:unexpected branch  // NOLINT(whitespace/line_length)
583   // sprintf( cBuf, "ProcessGroupAsStarted(%d)", m_ActiveGroupId);
584   sprintf(cBuf, "ProcessGroupAsStarted(%d)", m_SystemStarter.get_id());  // NOLINT
585   l_eStatus = ProcessGroupAsStarted(hApp, m_SystemStarter.get_id());
586   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)
587
588   FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-");
589
590
591   return l_eStatus;
592 }
593
594 ///////////////////////////////////////////////////////////////////////////////
595 /// \ingroup send_power_request_complete_response
596 /// send power request completion response to power
597 ///
598 /// \param [in]
599 ///
600 /// \return EFrameworkunifiedStatus
601 /// Success ==> eFrameworkunifiedStatusOK
602 /// Failure ==> Other values
603 ///////////////////////////////////////////////////////////////////////////////
604 EFrameworkunifiedStatus CSystemManager::send_power_request_complete_response(HANDLE hApp, std::string pStr) {
605   EFrameworkunifiedStatus l_eStatus;
606   FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+");
607
608   // send Wake-up complete response to Power
609   l_eStatus = FrameworkunifiedSendMsg(m_hPowerServiceSession,
610       SS_SM_WAKEUP_MODULES_CMPL_RSPN, sizeof(wakeInfo), (PVOID) & m_Wake);
611   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)
612
613   LogAllGroupModulesState(pStr);
614
615   FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-");
616   return l_eStatus;
617 }  // End of EFrameworkunifiedStatus CSystemManager::send_power_request_complete_response( HANDLE hApp )
618
619 ///////////////////////////////////////////////////////////////////////////////
620 /// \ingroup OnNPPStatusCheckMonitorTimerExpiry
621 ///
622 /// \brief Called when NPP fails to provide a ready status in the specified.
623 ///        amount of time.  This function will periodically request a new status
624 ///        ACK from NPP service until one is received. See OnNPPReadyStatusCallback().
625 ///
626 ///        Note: NPP usually pushes a ready event to SM and the reversion to
627 ///              polling the NPP ready ACK is for additional robustness. Failure
628 ///              to receive an NPP ready ACK will prevent system startup.
629 ///
630 /// \param [in] hApp - Handle to framework application.
631 ///
632 /// \return EFrameworkunifiedStatus
633 /// Success ==> eFrameworkunifiedStatusOK
634 /// Failure ==> Other values
635 ///////////////////////////////////////////////////////////////////////////////
636 EFrameworkunifiedStatus CSystemManager::OnNPPStatusCheckMonitorTimerExpiry(HANDLE hApp) {
637   EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK;
638   FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+");
639
640   SetCmdHist("SM_TIMER_NPP_STATUS_CHECK_MONITOR", m_TimerCmdHist, // LCOV_EXCL_BR_LINE 11:unexpected branch  // NOLINT(whitespace/line_length)
641       m_TimerHistIter, FrameworkunifiedGetMsgSrc(hApp)); // LCOV_EXCL_BR_LINE 11:unexpected branch  // NOLINT(whitespace/line_length)
642
643   FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__, " m_bIsNPP_ServicesStarted is '%s'",
644       GetStr(m_bIsNPP_ServicesStarted).c_str());
645
646   if (FALSE == m_bIsNPP_ServicesStarted) {
647     l_eStatus = FrameworkunifiedNPGetReadyStatusOfNPP(hApp);
648     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)
649   }
650   FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-");
651   return l_eStatus;
652 }
653
654 ///////////////////////////////////////////////////////////////////////////////
655 /// \ingroup OnNPPReadyStatusCallback
656 ///
657 /// \brief Called when NPP returns a status ACK indicating that the service is
658 ///        operational and ready to respond to subsequent requests.
659 ///
660 /// \param [in] hApp - Handle to framework application.
661 ///
662 /// \return EFrameworkunifiedStatus
663 /// Success ==> eFrameworkunifiedStatusOK
664 /// Failure ==> Other values
665 ///////////////////////////////////////////////////////////////////////////////
666 EFrameworkunifiedStatus CSystemManager::OnNPPReadyStatusCallback(HANDLE hApp) {  // LCOV_EXCL_START 6: Because the condition cannot be set
667   AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
668   FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+");
669   EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK;
670   INTERFACEUNIFIEDLOG_RECEIVED_FROM(hApp);  // LCOV_EXCL_BR_LINE 15: marco defined in ns_logger_if.h  // NOLINT(whitespace/line_length)
671   FRAMEWORKUNIFIEDLOG(ZONE_PERFORMANCE, __FUNCTION__, "from %s", FrameworkunifiedGetMsgSrc(hApp));
672
673   SetCmdHist("NPS_GET_READYSTATUS_ACK", m_SMCmdHist, m_SMHistIter, FrameworkunifiedGetMsgSrc(hApp));
674
675   l_eStatus = OnNPPReadyEventCallback(hApp);
676   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)
677
678   FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-");
679   return l_eStatus;
680 }
681 // LCOV_EXCL_STOP
682
683 EFrameworkunifiedStatus CSystemManager::OnNPPReadyEventCallback(HANDLE hApp) {
684   EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK;
685   FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+");
686   PCSTR l_moduleName = FrameworkunifiedGetMsgSrc(hApp);
687   FRAMEWORKUNIFIEDLOG(ZONE_PERFORMANCE, __FUNCTION__, "from %s", l_moduleName);
688
689   SetCmdHist("NPS_NPP_READY_EVENT", m_SMCmdHist, m_SMHistIter, l_moduleName); // LCOV_EXCL_BR_LINE 11:unexpected branch  // NOLINT(whitespace/line_length)
690   if (TRUE == m_bIsNPP_ServicesStarted) {
691     l_eStatus = eFrameworkunifiedStatusMsgNotProcessed;
692     LOG_ERROR("TRUE == m_bIsNPP_ServicesStarted");  // LCOV_EXCL_BR_LINE 15: marco defined in ss_templates.h  // NOLINT(whitespace/line_length)
693   } else {
694     ModuleLaunchListIter l_ModuleListIter;
695     m_bIsNPP_ServicesStarted = TRUE;
696     FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__, " m_bIsNPP_ServicesStarted set 'TRUE'");
697     m_GroupLaunchTimer->StopTimer(m_aTimerIDs[eSM_TIMER_NPP_STATUS_CHECK_MONITOR]);
698
699     UI_32 l_cbCmdIdArrayNPPService[] = { NPS_NPP_READY_EVENT, NPS_GET_READYSTATUS_ACK };
700
701     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)
702       // LCOV_EXCL_START 4: nsfw error code
703       AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
704       LOG_ERROR("FrameworkunifiedDetachCallbacksFromDispatcher()");  // LCOV_EXCL_BR_LINE 15: marco defined in ss_templates.h  // NOLINT(whitespace/line_length)
705       // LCOV_EXCL_STOP
706     } else if (eFrameworkunifiedStatusOK != (l_eStatus = register_all_notification_callbacks(hApp))) {    // LCOV_EXCL_BR_LINE 4:NSFW error case  //NOLINT (whitespace/line_length)
707       // LCOV_EXCL_START 4: nsfw error code
708       AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
709       LOG_ERROR("register_all_notification_callbacks()");  // LCOV_EXCL_BR_LINE 15: marco defined in ss_templates.h  // NOLINT(whitespace/line_length)
710       // LCOV_EXCL_STOP
711     } else if (eFrameworkunifiedStatusOK != (l_eStatus = GetModuleIterator(l_moduleName, l_ModuleListIter))) {  // LCOV_EXCL_BR_LINE 200:NPP always in launch map  //NOLINT (whitespace/line_length)
712       // LCOV_EXCL_START 200 : NPP service always in launch map
713       AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
714       FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__,  // LCOV_EXCL_BR_LINE 15: marco defined in ns_logger_if.h  // NOLINT(whitespace/line_length)
715           " 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)
716           l_moduleName);  // LCOV_EXCL_BR_LINE 15: marco defined in ns_logger_if.h  // NOLINT(whitespace/line_length)
717       // LCOV_EXCL_STOP
718     } else {
719       l_ModuleListIter->SetModuleState(MODULE_STATE_STARTED);
720
721       if (m_oSystemLauncher.get_id() == 1) {
722         m_oSystemLauncher.advance_id();
723       }
724
725       l_eStatus = OnLaunchGroup(hApp);
726       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)
727       if (eFrameworkunifiedStatusOK == l_eStatus) {   // LCOV_EXCL_BR_LINE 200: OnLaunchGroup() return ok
728         FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__, " successful");
729       }
730     }
731   }
732
733   FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-");
734   return l_eStatus;
735 }  // End of EFrameworkunifiedStatus CSystemManager::OnNPPReadyEventCallback( HANDLE hApp )
736
737 ///////////////////////////////////////////////////////////////////////////////
738 /// \ingroup OnBackupMgrAvailCallback
739 /// BackupManager Availability Notification Callback
740 ///
741 /// \param [in]
742 ///
743 ///
744 /// \return EFrameworkunifiedStatus
745 /// Success ==> eFrameworkunifiedStatusOK
746 /// Failure ==> Other values
747 ///////////////////////////////////////////////////////////////////////////////
748 EFrameworkunifiedStatus CSystemManager::OnBackupMgrAvailCallback(HANDLE hApp) {
749   FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+");
750   EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK;
751
752   if (sizeof(ServiceAvailability) != FrameworkunifiedGetMsgLength(hApp)) {  // LCOV_EXCL_BR_LINE 4: nsfw error
753     // LCOV_EXCL_START 4: nsfw error
754     AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
755     SS_ASERT(0);  // LCOV_EXCL_BR_LINE 15: marco defined in ss_templates.h  // NOLINT(whitespace/line_length)
756     // LCOV_EXCL_STOP
757     l_eStatus = eFrameworkunifiedStatusFail;
758   } else if (strcmp(FrameworkunifiedGetLastNotification(hApp), NTFY_BackupMgr_Availability) != 0) {  // LCOV_EXCL_BR_LINE 200:cannot be false //NOLINT (whitespace/line_length)
759     // LCOV_EXCL_START 200: cannot be false
760     AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
761     SS_ASERT(0);  // LCOV_EXCL_BR_LINE 15: marco defined in ss_templates.h  // NOLINT(whitespace/line_length)
762     l_eStatus = eFrameworkunifiedStatusFail;
763     // LCOV_EXCL_STOP
764   } else {
765     m_bIsBackupAvail = FrameworkunifiedIsServiceAvailable(hApp);
766     FRAMEWORKUNIFIEDLOG(ZONE_STATE, __FUNCTION__, "BackupAvail:%s", m_bIsBackupAvail ? "T" : "F");
767
768     l_eStatus = OnLaunchGroup(hApp);
769     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)
770   }
771
772   FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-");
773   return l_eStatus;
774 }  // End of EFrameworkunifiedStatus CSystemManager::OnBackupMgrAvailCallback(HANDLE hApp)
775
776 ///////////////////////////////////////////////////////////////////////////////
777 /// \ingroup OnPowerRequestCallback
778 /// PowerRequest callback handler
779 ///
780 /// \param [in]
781 ///
782 ///
783 /// \return EFrameworkunifiedStatus
784 /// Success ==> eFrameworkunifiedStatusOK
785 /// Failure ==> Other values
786 ///////////////////////////////////////////////////////////////////////////////
787 EFrameworkunifiedStatus CSystemManager::OnPowerRequestCallback(HANDLE hApp) {
788   FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+");
789   EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK;
790   Pwr_ServiceSetInterface tServiceIf;
791   INTERFACEUNIFIEDLOG_RECEIVED_FROM(hApp);  // LCOV_EXCL_BR_LINE 15: marco defined in ns_logger_if.h  // NOLINT(whitespace/line_length)
792
793   SetCmdHist("SS_SM_POWER_REQUEST_MSG", m__CWORD56_CmdHist, m__CWORD56_HistIter, FrameworkunifiedGetMsgSrc(hApp));
794
795   //  OnSystemManagerDebugDump(hApp);
796   // ReadMsg():                                                        *
797   //     Check hApp ptr, msg size, msg reception, read msg if all ok.  *
798   //     Report any errors found.                                      *
799   //                                                                   *
800   if (eFrameworkunifiedStatusOK != (l_eStatus = ReadMsg < Pwr_ServiceSetInterface > (hApp, tServiceIf))) {  // LCOV_EXCL_BR_LINE 4:NSFW error case  //NOLINT (whitespace/line_length)
801     // LCOV_EXCL_START 4: nsfw error
802     AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
803     LOG_ERROR("ReadMsg()");  // LCOV_EXCL_BR_LINE 15: marco defined in ss_templates.h  // NOLINT(whitespace/line_length)
804     // LCOV_EXCL_STOP
805   } else {
806     // NOTE: interface_unified always set userMode as 0. so don't use m_lastUserMode.
807     m_lastUserMode = tServiceIf.data.powerRequestMsg.userMode;
808     //
809     // 2012 December 04 Temporary hack ( I hope ) to set m_Wake to nominal
810     // values. At present, the 'Power Request Message Response' is sent
811     // back to Power Services via the 'send_power_request_complete_response()'
812     // function, which uses m_Wake.
813     m_Wake.powerupType =
814         m_SSBool_to_PowerTypeEnumMap[m_SSUserMode_to_SSBoolEnumMap[m_lastUserMode]];
815
816     m_Wake.up.factor = tServiceIf.data.powerRequestMsg.startupReason;
817
818     if (epswfINVALID != m_Wake.up.factor) {
819       m_StartUpReason = m_Wake.up.factor;
820     }
821
822     m_userModeChangeReason = tServiceIf.data.powerRequestMsg.userModeChangeReason;
823     m_Wake.up.userModeChangeReason = m_userModeChangeReason;
824
825     FRAMEWORKUNIFIEDLOG(ZONE_STATE, __FUNCTION__, "UserMode:%s, SM State:%s",
826         GetStr(m_lastUserMode).c_str(),
827         GetStr(m_SMCurrentState).c_str());
828     FRAMEWORKUNIFIEDLOG(ZONE_PERFORMANCE, __FUNCTION__, "UserMode:%s, SM State:%s",
829         GetStr(m_lastUserMode).c_str(),
830         GetStr(m_SMCurrentState).c_str());
831     CALL_AND_LOG_STATUS(PublishPowerOnOffNotification(hApp));  // LCOV_EXCL_BR_LINE 15: marco defined in ss_templates.h  // NOLINT(whitespace/line_length)
832
833     switch (m_SMCurrentState) {  // LCOV_EXCL_BR_LINE 6: As not all cases can be passed through
834       case SS_SM_READY_TO_LAUNCH_APP:
835         FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__,
836             " Error: Received a PowerRequest command while still in "
837             "the '%s' state !!!",
838             GetStr(m_SMCurrentState).c_str());
839         l_eStatus = eFrameworkunifiedStatusErrOther;
840         break;
841
842       case SS_SM_APPS_LAUNCH_IN_PROGRESS:
843         // When Start is received while processes are launching, we
844         // need to send the Start request later, once the 'Open
845         // Session Request' is received from the application.
846         //*****
847         // Deliberate commenting-out of case-break to allow this case to
848         // use following case's logic.
849         // break;
850         //*****
851
852       case SS_SM_APPS_LAUNCHED_READY_TO_START:
853       case SS_SM_APPS_START_COMPLETE:
854       case SS_SM_APPS_PRE_RUN_COMPLETE:
855       case SS_SM_APPS_BACKGROUND_RUN_COMPLETE:
856       case SS_SM_APPS_START_IN_PROGRESS:
857       case SS_SM_APPS_PRE_START_IN_PROGRESS:
858       case SS_SM_APPS_PRE_STOP_IN_PROGRESS:
859       case SS_SM_APPS_BACKGROUND_START_IN_PROGRESS:
860       case SS_SM_APPS_BACKGROUND_STOP_IN_PROGRESS:
861         FRAMEWORKUNIFIEDLOG(ZONE_PERFORMANCE, __FUNCTION__, "Startup Reason is '%s'", GetStr(m_StartUpReason).c_str());
862         if ((m_userModeChangeReason == epsumcrPARKING_B)
863             || ((m_userModeChangeReason == epsumcrPRE_BA) && (m_SMCurrentState == SS_SM_APPS_PRE_RUN_COMPLETE))
864             || ((m_userModeChangeReason == epsumcrNORMAL) && (m_SMCurrentState == SS_SM_APPS_START_COMPLETE))
865             || ((m_userModeChangeReason == epsumcrBACKGROUND_BA)
866                 && (m_SMCurrentState == SS_SM_APPS_BACKGROUND_RUN_COMPLETE))) {
867           // send the Power Request complete response to PowerService
868           // LCOV_EXCL_BR_START 15: Excluded due to inlined functions
869           CALL_AND_LOG_STATUS_IF_ERRORED(send_power_request_complete_response(hApp, "Power Request"));
870           // LCOV_EXCL_BR_STOP 15: Excluded due to inlined functions
871         } else {
872           //
873           // Publish the UserMode 'Off' notification now for those
874           // applications that need immediate notification ( HMI )
875           if (m_lastUserMode == epsumOFF) {
876             CALL_AND_LOG_STATUS(PublishUserModeNotification(hApp));  // LCOV_EXCL_BR_LINE 15: marco defined in ss_templates.h  // NOLINT(whitespace/line_length)
877           }
878
879           CALL_AND_LOG_STATUS(BeginStartup(hApp));  // LCOV_EXCL_BR_LINE 15: marco defined in ss_templates.h  // NOLINT(whitespace/line_length)
880         }
881         break;
882
883       case SS_SM_APPS_STOPPING_AT__CWORD56__REQ:
884       case SS_SM_WAITING_FOR_CRITICAL_APPS_AT__CWORD56__REQ:
885         // Abort the Stop.
886         // Reset System Manager to handle (re)starting as if this is a
887         // nominal start.
888         m_GroupLaunchTimer->StopTimer(m_aTimerIDs[eSM_TIMER_CLIENT_STOP_MONITOR]);
889
890         FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__, " Aborted %s, resetting to %s,"
891             " restarting Application groups at group %d",
892             GetStr(m_SMCurrentState).c_str(),
893             GetStr(SS_SM_APPS_START_IN_PROGRESS).c_str()
894             , m_SystemStarter.get_id());
895
896         CALL_AND_LOG_STATUS(BeginStartup(hApp));  // LCOV_EXCL_BR_LINE 15: marco defined in ss_templates.h  // NOLINT(whitespace/line_length)
897
898         break;
899
900       case SS_SM_APPS_STOPPING_AT_INTERNAL_REQ:
901       case SS_SM_WAITING_FOR_CRITICAL_APPS_AT_INTERNAL_REQ:  // LCOV_EXCL_START 8: As no value is set
902           AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
903           FRAMEWORKUNIFIEDLOG(ZONE_WARN, __FUNCTION__,
904               " Warning: System Manager state is %d/'%s', ignoring "
905               "PowerRequest command", m_SMCurrentState,
906               GetStr(m_SMCurrentState).c_str());
907           break;
908       }  // LCOV_EXCL_STOP
909     }
910     FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-");
911     return l_eStatus;
912 }  // End of EFrameworkunifiedStatus CSystemManager::OnPowerRequestCallback( HANDLE hApp )
913
914 ///////////////////////////////////////////////////////////////////////////////
915 /// \ingroup
916 /// Begin the Startup process
917 ///
918 /// \param [in]
919 ///
920 ///
921 /// \return EFrameworkunifiedStatus
922 /// Success ==> eFrameworkunifiedStatusOK
923 /// Failure ==> Other values
924 ///////////////////////////////////////////////////////////////////////////////
925 EFrameworkunifiedStatus CSystemManager::BeginStartup(HANDLE hApp) {
926   EFrameworkunifiedStatus l_eStatus;
927   FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+");
928
929   if ((m_userModeChangeReason != epsumcrPARKING_B) &&
930       (m_userModeChangeReason != epsumcrPRE_BA) &&
931       (m_userModeChangeReason != epsumcrNORMAL) &&
932       (m_userModeChangeReason != epsumcrBACKGROUND_BA)) {
933     // Not a power state transition request.
934     return eFrameworkunifiedStatusOK;
935   }
936
937   switch (m_userModeChangeReason) {  // LCOV_EXCL_BR_LINE 6: Excluded because it has been guarded to prevent out-of-range values from entering immediately before.
938   case epsumcrPRE_BA:
939     // 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.
940     if ((m_SMCurrentState == SS_SM_APPS_START_COMPLETE) || (m_SMCurrentState == SS_SM_APPS_BACKGROUND_RUN_COMPLETE)) {
941       // 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.
942       m_SystemStarter.to_end();
943       SMSetState(hApp, SS_SM_APPS_PRE_STOP_IN_PROGRESS);
944     } else {
945       m_SystemStarter.to_begin();
946       SMSetState(hApp, SS_SM_APPS_PRE_START_IN_PROGRESS);
947     }
948     break;
949   case epsumcrNORMAL:
950     m_SystemStarter.to_begin();
951     SMSetState(hApp, SS_SM_APPS_START_IN_PROGRESS);
952     break;
953   case epsumcrBACKGROUND_BA:
954     if (m_SMCurrentState == SS_SM_APPS_START_COMPLETE) {
955       m_SystemStarter.to_end();
956       SMSetState(hApp, SS_SM_APPS_BACKGROUND_STOP_IN_PROGRESS);
957     } else {
958       m_SystemStarter.to_begin();
959       SMSetState(hApp, SS_SM_APPS_BACKGROUND_START_IN_PROGRESS);
960     }
961     break;
962   default:
963     break;
964   }
965
966   FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__,
967       " Starting 'Start Resp Monitor' Timer with '%d' sec",
968       m_SMConfig.MCConfig.ModuleStartRespTimeOutSec);
969
970   m_GroupLaunchTimer->StartTimer(
971       m_aTimerIDs[eSM_TIMER_START_RESP_MONITOR_WAIT_TIMER],
972       m_SMConfig.MCConfig.ModuleStartRespTimeOutSec, 0, 0, 0);
973
974   l_eStatus = start_all_modules_of_group(hApp, m_SystemStarter.get_id());
975   if (eFrameworkunifiedStatusOK != l_eStatus) {
976     FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__,
977         " Error: start_all_modules_of_group(%d) errored: %d/'%s'",
978         m_SystemStarter.get_id(), l_eStatus, GetStr(l_eStatus).c_str());
979   }
980   FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-");
981   return l_eStatus;
982 }  // End of EFrameworkunifiedStatus CSystemManager::BeginStartup( HANDLE hApp )
983
984 ///////////////////////////////////////////////////////////////////////////////
985 /// \ingroup OnWakeupCallback
986 /// WakeUp callback handler
987 ///
988 /// \param [in]
989 ///
990 ///
991 /// \return EFrameworkunifiedStatus
992 /// Success ==> eFrameworkunifiedStatusOK
993 /// Failure ==> Other values
994 ///////////////////////////////////////////////////////////////////////////////
995 EFrameworkunifiedStatus CSystemManager::OnWakeupCallback(HANDLE hApp) {  // LCOV_EXCL_START 6: Because the condition cannot be set
996   AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
997   EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusFail;
998   FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+");
999   INTERFACEUNIFIEDLOG_RECEIVED_FROM(hApp);
1000   FRAMEWORKUNIFIEDLOG(ZONE_PERFORMANCE, __FUNCTION__, "Received from %s", FrameworkunifiedGetMsgSrc(hApp));
1001
1002   FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-");
1003   return l_eStatus;
1004 }  // End of EFrameworkunifiedStatus CSystemManager::OnWakeupCallback( HANDLE hApp )
1005 // LCOV_EXCL_STOP
1006
1007 ///////////////////////////////////////////////////////////////////////////////
1008 /// \ingroup OnModuleStartCompleteResponse
1009 /// Start Response\Ack Handlers
1010 ///
1011 /// \param [in]
1012 ///
1013 ///
1014 /// \return EFrameworkunifiedStatus
1015 /// Success ==> eFrameworkunifiedStatusOK
1016 /// Failure ==> Other values
1017 ///////////////////////////////////////////////////////////////////////////////
1018 EFrameworkunifiedStatus CSystemManager::OnModuleStartCompleteResponse(HANDLE hApp) {
1019   FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+");
1020   EFrameworkunifiedStatus l_eStatus;
1021   INTERFACEUNIFIEDLOG_RECEIVED_FROM(hApp);  // LCOV_EXCL_BR_LINE 15: marco defined in ns_logger_if.h  // NOLINT(whitespace/line_length)
1022   FRAMEWORKUNIFIEDLOG(ZONE_PERFORMANCE, __FUNCTION__, "%s", FrameworkunifiedGetMsgSrc(hApp));
1023
1024   SetCmdHist("system_manager protocol completion response", m_SMCmdHist, m_SMHistIter, FrameworkunifiedGetMsgSrc(hApp));  // LCOV_EXCL_BR_LINE 11:unexpected branch  // NOLINT(whitespace/line_length)
1025
1026   ModuleLaunchListIter l_ModuleListIter;
1027   std::string l_moduleName = FrameworkunifiedGetMsgSrc(hApp);
1028   l_eStatus = GetModuleIterator(l_moduleName.c_str(), l_ModuleListIter);
1029   if (eFrameworkunifiedStatusOK != l_eStatus) {  // LCOV_EXCL_BR_LINE 200:always be eFrameworkunifiedStatusOK
1030     // LCOV_EXCL_START 200: always be eFrameworkunifiedStatusOK
1031     AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
1032     FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__,
1033         " Error: Module %s not found in Group Launch Map",
1034         l_moduleName.c_str());
1035     // LCOV_EXCL_STOP
1036   } else {
1037     switch (m_SMCurrentState) {  // LCOV_EXCL_BR_LINE 200: cannot be SS_SM_READY_TO_LAUNCH_APP
1038     case SS_SM_READY_TO_LAUNCH_APP:
1039       // LCOV_EXCL_START 200: cannot be SS_SM_READY_TO_LAUNCH_APP
1040       AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
1041       FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__,
1042           " Error: Received while in the '%s' state !!!",
1043           GetStr(m_SMCurrentState).c_str());
1044       l_eStatus = eFrameworkunifiedStatusErrOther;
1045       break;
1046       // LCOV_EXCL_STOP
1047
1048     case SS_SM_APPS_LAUNCH_IN_PROGRESS:
1049     case SS_SM_APPS_LAUNCHED_READY_TO_START:
1050     case SS_SM_APPS_START_IN_PROGRESS:
1051     case SS_SM_APPS_PRE_START_IN_PROGRESS:
1052     case SS_SM_APPS_PRE_STOP_IN_PROGRESS:
1053     case SS_SM_APPS_BACKGROUND_START_IN_PROGRESS:
1054     case SS_SM_APPS_BACKGROUND_STOP_IN_PROGRESS:
1055       {
1056         const SMModuleState l_state = InProgressStateToState();  // LCOV_EXCL_BR_LINE 11: Gcov constraints (because exception-handling routes are automatically generated) // NOLINT(whitespace/line_length)
1057         if (l_state != MODULE_STATE_INVALID) {
1058           const PCSTR l_loglist[] = {"start", "pre start", "pre stop", "background start", "background stop", ""};
1059           PCSTR l_logtxt;
1060           switch (l_state) {  // LCOV_EXCL_BR_LINE 6: As no other value is returned
1061           case MODULE_STATE_STARTED:
1062             l_logtxt = l_loglist[0];
1063             break;
1064           case MODULE_STATE_STARTED_PRE:
1065             l_logtxt = l_loglist[1];
1066             break;
1067           case MODULE_STATE_STOPPED_PRE:
1068             l_logtxt = l_loglist[2];
1069             break;
1070           case MODULE_STATE_STARTED_BACKGROUND:
1071             l_logtxt = l_loglist[3];
1072             break;
1073           case MODULE_STATE_STOPPED_BACKGROUND:
1074             l_logtxt = l_loglist[4];
1075             break;
1076           // LCOV_EXCL_START 6: As no other value is returned
1077           default:
1078             AGL_ASSERT_NOT_TESTED();
1079             l_logtxt = l_loglist[5];
1080             break;
1081           // LCOV_EXCL_STOP 6: As no other value is returned
1082           }
1083           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)
1084                                              SysMgrCbType3<CSystemManager, &CSystemManager::IsGroupStarted>,
1085                                              SysMgrCbType2<CSystemManager, &CSystemManager::ProcessGroupAsStarted>,
1086                                              l_logtxt);
1087         }
1088       }
1089       break;
1090
1091     case SS_SM_APPS_STOPPING_AT__CWORD56__REQ:
1092     case SS_SM_APPS_STOPPING_AT_INTERNAL_REQ:
1093     case SS_SM_WAITING_FOR_CRITICAL_APPS_AT__CWORD56__REQ:
1094     case SS_SM_WAITING_FOR_CRITICAL_APPS_AT_INTERNAL_REQ:
1095       // SystemManager changed state while this module was starting;
1096       // tell this module to stop.
1097       if (!l_ModuleListIter->IsModuleState(MODULE_STATE_STOP_SENT)
1098           && !l_ModuleListIter->IsModuleState(MODULE_STATE_STOPPED)) {
1099         T_SS_SM_STOP_DataStructType l_SM_STOP_Struct;
1100         l_SM_STOP_Struct.shutdownTrigger = m_shutdownTrigger;
1101         l_SM_STOP_Struct.lastUserMode = m_lastUserMode;
1102
1103         CALL_AND_LOG_STATUS(                               // LCOV_EXCL_BR_LINE 15: marco defined in ss_templates.h  // NOLINT(whitespace/line_length)
1104             l_ModuleListIter->SendMsgAndUpdateState(
1105                 &l_SM_STOP_Struct));
1106       }
1107       break;
1108     default:
1109       FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, " Error: Received while in the '%s' state !!!", GetStr(m_SMCurrentState).c_str());
1110       l_eStatus = eFrameworkunifiedStatusErrOther;
1111       break;
1112     }        // End switch ( m_SMCurrentState )
1113   }
1114   FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-");
1115   return l_eStatus;
1116 }  // End of EFrameworkunifiedStatus CSystemManager::OnModuleStartCompleteResponse( HANDLE hApp )
1117
1118 ///////////////////////////////////////////////////////////////////////////////
1119 /// \ingroup ModuleCompleteResponse
1120 /// Start Response\Ack Handlers
1121 ///
1122 /// \param [in]
1123 ///
1124 ///
1125 /// \return EFrameworkunifiedStatus
1126 /// Success ==> eFrameworkunifiedStatusOK
1127 /// Failure ==> Other values
1128 ///////////////////////////////////////////////////////////////////////////////
1129 EFrameworkunifiedStatus CSystemManager::ModuleCompleteResponse(HANDLE hApp,
1130         ModuleLaunchListIter f_ModuleListIter, SMModuleState f_moduleState,
1131         FncCbType3 f_isGroupDoneFnc, FncCbType2 f_groupDoneFnc,
1132         PCSTR f_sCompleteTypeText) {
1133   EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK;
1134   FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+");
1135   std::string l_moduleName = FrameworkunifiedGetMsgSrc(hApp);
1136   FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__,
1137       " Received from %s, m_SystemStarter.get_id() is %d",
1138       l_moduleName.c_str()
1139       , m_SystemStarter.get_id());
1140
1141   f_ModuleListIter->SetModuleState(f_moduleState);
1142   if (f_ModuleListIter->group_id != m_SystemStarter.get_id()) {
1143     // In PastModel002, it is assumed that there is no service that returns a FrameworkunifiedOnStop reply after the NPP service.
1144     // However, since _CWORD71_ does not assume this, completion of waiting for termination of the CRITICAL service must be
1145     // judged even when services other than the Group1 service terminate last.
1146     // Initially, SS_SM_WAITING_FOR_CRITICAL_APPS_AT_XXXX should be handled separately by ProcessModuleStopCompleteResponse(),
1147     // but this is limited to ModuleCompleteResponse in order to avoid code deviation from PastModel002 and limit the scope of effect.
1148     // 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)
1149     if ((MODULE_STATE_STOPPED == f_moduleState)
1150         && ((m_SMCurrentState
1151             == SS_SM_WAITING_FOR_CRITICAL_APPS_AT__CWORD56__REQ)
1152             || (m_SMCurrentState
1153                 == SS_SM_WAITING_FOR_CRITICAL_APPS_AT_INTERNAL_REQ))) {
1154     // 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)
1155       // 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)
1156       AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
1157       check_all_groups_have_stopped(hApp);
1158       // LCOV_EXCL_STOP
1159     } else {
1160       FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__,
1161           " %s ( group %d ) received out-of-synch; m_SystemStarter.get_id() is %d",
1162           l_moduleName.c_str(), f_ModuleListIter->group_id
1163           , m_SystemStarter.get_id());
1164     }
1165   } else {
1166     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)
1167       l_eStatus = (*f_groupDoneFnc)(hApp, f_ModuleListIter->group_id); // LCOV_EXCL_BR_LINE 11:unexpected branch  // NOLINT(whitespace/line_length)
1168     } 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)
1169       // LCOV_EXCL_START 6: Because the applicable variable cannot be changed from the external API (only evaluated by the initial value)
1170       AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
1171       TEXT(__FUNCTION__,  // LCOV_EXCL_BR_LINE 15: marco defined in ns_logger_if.h  // NOLINT(whitespace/line_length)
1172           " 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)
1173           f_ModuleListIter->group_id, f_sCompleteTypeText  // LCOV_EXCL_BR_LINE 15: marco defined in ns_logger_if.h  // NOLINT(whitespace/line_length)
1174           , m_SystemStarter.get_id());  // LCOV_EXCL_BR_LINE 15: marco defined in ns_logger_if.h  // NOLINT(whitespace/line_length)
1175       char cBuf[100];
1176       sprintf(cBuf, "%s incomplete", f_sCompleteTypeText);  // NOLINT
1177       LogGroupModulesState(f_ModuleListIter->group_id, cBuf);  // LCOV_EXCL_BR_LINE 11:unexpected branch  // NOLINT(whitespace/line_length)
1178       // LCOV_EXCL_STOP
1179     }
1180   }
1181
1182   const SMModuleState l_transition_state = InProgressStateToState();  // LCOV_EXCL_BR_LINE 11: Gcov constraints (because exception-handling routes are automatically generated) // NOLINT(whitespace/line_length)
1183   if (l_transition_state == f_moduleState) {  // LCOV_EXCL_BR_LINE 6:  As no other value is returned
1184     if (have_all_services_start_completed(l_transition_state) == TRUE) {
1185       if ((m_SMCurrentState == SS_SM_APPS_PRE_START_IN_PROGRESS)
1186           || (m_SMCurrentState == SS_SM_APPS_PRE_STOP_IN_PROGRESS)) {
1187         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)
1188       } else if ((m_SMCurrentState == SS_SM_APPS_BACKGROUND_START_IN_PROGRESS)
1189           || (m_SMCurrentState == SS_SM_APPS_BACKGROUND_STOP_IN_PROGRESS)) {
1190         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)
1191       } else {
1192         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)
1193       }
1194     }
1195   }
1196
1197   FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-");
1198   return l_eStatus;
1199 }  // End of EFrameworkunifiedStatus CSystemManager::ModuleCompleteResponse(
1200
1201 ///////////////////////////////////////////////////////////////////////////////
1202 /// \ingroup OnStartRespMonitorTimeout
1203 ///  SM maintains timer to check if all modules sent start response to him whoever requires Start.
1204 ///  This timer is common to all modules. After timeout it checks the status of every module in group map.
1205 ///  If a module sent start and does not respond, SM will initiate error event logging followed by Soft Reset
1206 /// \param [in]
1207 ///
1208 ///
1209 /// \return EFrameworkunifiedStatus
1210 /// Success ==> eFrameworkunifiedStatusOK
1211 /// Failure ==> Other values
1212 ///////////////////////////////////////////////////////////////////////////////
1213 EFrameworkunifiedStatus CSystemManager::OnStartRespMonitorTimeout(HANDLE hApp) {  // LCOV_EXCL_START 6: Because the condition cannot be set
1214   AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
1215   EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK;
1216   FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+");
1217   INTERFACEUNIFIEDLOG_RECEIVED_FROM(hApp);  // LCOV_EXCL_BR_LINE 15: marco defined in ns_logger_if.h  // NOLINT(whitespace/line_length)
1218   FRAMEWORKUNIFIEDLOG(ZONE_PERFORMANCE, __FUNCTION__, "from %s", FrameworkunifiedGetMsgSrc(hApp));
1219
1220   std::string l_ProcName;
1221   BOOL l_isStartRespNotReceived = false;
1222
1223   SetCmdHist("SM_TIMER_START_RESP_MONITOR_WAIT_TIMER", m_TimerCmdHist,
1224       m_TimerHistIter, FrameworkunifiedGetMsgSrc(hApp));
1225   GroupLaunchMap::reverse_iterator l_grp_riter = m_MapProclaunchGrps.rbegin();
1226   ModuleLaunchList::reverse_iterator l_mod_riter;
1227
1228   if (l_grp_riter == m_MapProclaunchGrps.rend()) {
1229     FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "Error: Group Map is Empty");
1230   } else {
1231     // scan the group map in reverse order
1232     for (; l_grp_riter != m_MapProclaunchGrps.rend(); l_grp_riter++) {
1233       l_mod_riter = l_grp_riter->second.modules.rbegin();
1234       for (; l_mod_riter != l_grp_riter->second.modules.rend(); l_mod_riter++) {
1235         // if a module sent start and not received response from module SM wait for "ModuleStartRespTimeout"
1236         // and initiated error event
1237         // logging followed by soft reset
1238
1239         if (l_mod_riter->is_start_required) {
1240           if (l_mod_riter->IsModuleState(MODULE_STATE_START_SENT)) {
1241             FRAMEWORKUNIFIEDLOG(ZONE_WARN, __FUNCTION__,
1242                 " Module [%s] did not respond(%s) to SM in allocated time [%d] sec",
1243                 l_mod_riter->name.c_str(),
1244                 l_mod_riter->ModuleStateStr().c_str(),
1245                 m_SMConfig.MCConfig.ModuleStartRespTimeOutSec);
1246             l_isStartRespNotReceived = true;
1247             l_ProcName.assign(l_mod_riter->name);
1248           }
1249         }
1250       }
1251     }
1252   }
1253
1254   if (true == l_isStartRespNotReceived) {
1255     char l_cFormat[] = " Error. Module '%s' start response timeout.";
1256     char l_cBuf[sizeof(l_cFormat) + MAX_NAME_SIZE_APP];
1257     snprintf(l_cBuf, sizeof(l_cBuf), l_cFormat, l_ProcName.c_str());
1258     TEXT(__FUNCTION__, l_cBuf);  // LCOV_EXCL_BR_LINE 15: marco defined in ns_logger_if.h  // NOLINT(whitespace/line_length)
1259     FRAMEWORKUNIFIEDLOG(ZONE_PERFORMANCE, __FUNCTION__, l_cBuf);
1260
1261     SMLoggingInfo l_loggingInfo;
1262     l_loggingInfo.resetReason = e_SS_SM_CPU_RESET_REASON_GENERIC_ERR;
1263
1264     // initate error event logging
1265     l_eStatus = ErrorEventEnqueue(hApp, eErrorEventTypeStartRespFailed,
1266         l_ProcName, eErrorEventResetTypeHard, l_loggingInfo);
1267     FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, " Error: StartRespFailed %s", l_ProcName.c_str());
1268     fprintf(stderr, "SS_SysManager/%s/Error: StartRespFailed %s\n",
1269         __FUNCTION__, l_ProcName.c_str());
1270     LOG_ERROR_REC_HIST_IF_ERRORED(l_eStatus,  // LCOV_EXCL_BR_LINE 15: marco defined in ss_system_manager.h  // NOLINT(whitespace/line_length)
1271         "ErrorEventEnqueue(eErrorEventTypeStartRespFailed)");  // LCOV_EXCL_BR_LINE 15: marco defined in ss_system_manager.h  // NOLINT(whitespace/line_length)
1272   } else {
1273     FRAMEWORKUNIFIEDLOG(ZONE_PERFORMANCE, __FUNCTION__,
1274         " All modules returned Start Response.");
1275
1276     l_eStatus = FrameworkunifiedSendChild(hApp, m_hHeartbeatThread.m_ThreadHdl,
1277         SS_HEARTBEAT_AVAIL_CHECK_REQ, 0, NULL);
1278     SS_ASERT(l_eStatus == eFrameworkunifiedStatusOK);  // LCOV_EXCL_BR_LINE 15: marco defined in ss_templates.h  // NOLINT(whitespace/line_length)
1279   }
1280
1281   FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-");
1282   return l_eStatus;
1283 }  // End of EFrameworkunifiedStatus CSystemManager::OnStartRespMonitorTimeout(HANDLE hApp)
1284 // LCOV_EXCL_STOP
1285
1286 ///////////////////////////////////////////////////////////////////////////////
1287 /// \ingroup OnShutdownCompleteMonitorTimeout
1288 ///  SM maintains timer to check if all modules sent start response to him whoever requires Start.
1289 ///  This timer is common to all modules. After timeout it checks the status of every module in group map.
1290 ///  If a module sent start and does not respond, SM will initiate error event logging followed by Soft Reset
1291 /// \param [in]
1292 ///
1293 ///
1294 /// \return EFrameworkunifiedStatus
1295 /// Success ==> eFrameworkunifiedStatusOK
1296 /// Failure ==> Other values
1297 ///////////////////////////////////////////////////////////////////////////////
1298 EFrameworkunifiedStatus CSystemManager::OnShutdownCompleteMonitorTimeout(HANDLE hApp) {
1299   EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK;
1300   FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+");
1301   INTERFACEUNIFIEDLOG_RECEIVED_FROM(hApp);  // LCOV_EXCL_BR_LINE 15: marco defined in ns_logger_if.h  // NOLINT(whitespace/line_length)
1302
1303   FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "Error: Reset Timeout");
1304
1305   l_eStatus = SecureChipOff();
1306   if (eFrameworkunifiedStatusOK != l_eStatus) {
1307     FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "Error: SecureChipOff Failed");
1308   }
1309
1310   m_ResetFactor = PSM_FACTOR_AGL_WITH_HISTORY;
1311
1312   l_eStatus = perform_force_reset(hApp);
1313
1314   FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-");
1315   return l_eStatus;
1316 }  // End of EFrameworkunifiedStatus CSystemManager::OnShutdownCompleteMonitorTimeout(HANDLE hApp)
1317
1318 ///////////////////////////////////////////////////////////////////////////////
1319 /// \ingroup start_all_modules_of_group
1320 /// Send START to all modules of the given group
1321 ///
1322 /// \param [in]
1323 ///
1324 ///
1325 /// \return EFrameworkunifiedStatus
1326 /// Success ==> eFrameworkunifiedStatusOK
1327 /// Failure ==> Other values
1328 ///////////////////////////////////////////////////////////////////////////////
1329 EFrameworkunifiedStatus CSystemManager::start_all_modules_of_group(HANDLE hApp, UI_32 f_ui32GroupNumber) {
1330   EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK;
1331   FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+");
1332
1333   GroupLaunchMapIter l_GroupIterator = m_MapProclaunchGrps.find(
1334       f_ui32GroupNumber);
1335   if (l_GroupIterator == m_MapProclaunchGrps.end()) {  // LCOV_EXCL_BR_LINE 6: Because the condition cannot be set
1336     AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
1337     FRAMEWORKUNIFIEDLOG(ZONE_ERR,
1338         __FUNCTION__
1339         , " Error: Group %d not found; 'm_MapProclaunchGrps' is empty",
1340         f_ui32GroupNumber);
1341     AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
1342     l_eStatus = eFrameworkunifiedStatusInvldParam;  // LCOV_EXCL_LINE 6: Because the condition cannot be set
1343   } else {
1344     T_SS_SM_START_DataStructType f_startupData(m_StartUpReason,
1345         m_PowerType_to_SSBoolEnumMap[m_Wake.powerupType],
1346         m_DataResetMode, m_startUpConfirmationMsg.securityStatus,
1347         m_startUpConfirmationMsg.wakeupType, m_DramBackupStatus,
1348         m_ResetStatus, m_ResetCount);
1349
1350     UI_32 l_numModulesMessaged = 0;
1351     FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__,
1352         " Attempting to send Start Requests to Group %d/'%s'",
1353         f_ui32GroupNumber, l_GroupIterator->second.name.c_str());
1354
1355     for (ModuleLaunchListIter l_ModuleListIterator =
1356         l_GroupIterator->second.modules.begin();
1357         l_ModuleListIterator != l_GroupIterator->second.modules.end();
1358         l_ModuleListIterator++) {
1359       //
1360       // Every branch below must ZONE_INFO log how it dispenses w/
1361       // the module.
1362       //  Note: ModuleLaunchParams::SetModuleState() performs that
1363       //    ZONE_INFO logging internally.
1364       if (!l_ModuleListIterator->is_start_required) {
1365         if (FRAMEWORKUNIFIED_NS_NPSERVICE == l_ModuleListIterator->name) {
1366           const SMModuleState l_transition_state = InProgressStateToState();  // LCOV_EXCL_BR_LINE 11:Gcov constraints (because exception-handling routes are automatically generated)
1367           l_ModuleListIterator->SetModuleState(l_transition_state);  // LCOV_EXCL_BR_LINE 11:Gcov constraints (because exception-handling routes are automatically generated)
1368         } else {
1369           // Not an error
1370           FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__,
1371               " %s 'is_start_required' is False;"
1372                   " leaving state as '%s'",
1373               l_ModuleListIterator->name.c_str(),
1374               l_ModuleListIterator->ModuleStateStr().c_str());
1375         }
1376         l_eStatus = eFrameworkunifiedStatusOK;
1377       } else if (NULL == l_ModuleListIterator->hsession) {  // LCOV_EXCL_BR_LINE 6: hsession can not be null.
1378         l_eStatus = eFrameworkunifiedStatusOK;  // Log a message. But its not a failure
1379         FRAMEWORKUNIFIEDLOG(ZONE_WARN, __FUNCTION__, " Warning: NULL == hsession;"
1380             " %s not connected yet",
1381             l_ModuleListIterator->name.c_str());
1382       } else {
1383         switch (l_ModuleListIterator->GetModuleState()) {  // LCOV_EXCL_BR_LINE 6: As not all cases can be passed through
1384         case MODULE_STATE_INVALID:
1385         case MODULE_STATE_SKIPPED:
1386         case MODULE_STATE_LAUNCH_FAILED:
1387           // LCOV_EXCL_START 6: Because the state of the corresponding variable cannot be set
1388           AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
1389           l_eStatus = eFrameworkunifiedStatusOK;  // Log a message. But its not a failure
1390           FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__,
1391               " %s is %s, NOT sending system_manager protocol message",
1392               l_ModuleListIterator->name.c_str(),
1393               l_ModuleListIterator->ModuleStateStr().c_str());
1394           break;
1395           // LCOV_EXCL_STOP
1396
1397         case MODULE_STATE_START_SENT:
1398         case MODULE_STATE_START_PRE_SENT:
1399         case MODULE_STATE_STOP_PRE_SENT:
1400         case MODULE_STATE_START_BACKGROUND_SENT:
1401         case MODULE_STATE_STOP_BACKGROUND_SENT:
1402           l_eStatus = eFrameworkunifiedStatusOK;
1403           FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__,
1404               " %s is %s, NOT sending system_manager protocol message",
1405               l_ModuleListIterator->name.c_str(),
1406               l_ModuleListIterator->ModuleStateStr().c_str());
1407           l_numModulesMessaged++;
1408           break;
1409
1410         case MODULE_STATE_LAUNCHING:
1411         case MODULE_STATE_LAUNCHED:
1412           // LCOV_EXCL_START 6: Because the state of the corresponding variable cannot be set
1413           AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
1414           l_eStatus = eFrameworkunifiedStatusOK;  // Log a message. But its not a failure
1415           FRAMEWORKUNIFIEDLOG(ZONE_WARN, __FUNCTION__,
1416               " %s is %s, NOT sending system_manager protocol message",
1417               l_ModuleListIterator->name.c_str(),
1418               l_ModuleListIterator->ModuleStateStr().c_str());
1419           break;
1420           // LCOV_EXCL_STOP
1421
1422         case MODULE_STATE_CONNECTED:
1423         case MODULE_STATE_STARTED:
1424         case MODULE_STATE_START_FAILED:
1425         case MODULE_STATE_STOP_FAILED:
1426         case MODULE_STATE_STOP_SENT:
1427         case MODULE_STATE_STOPPED:
1428         case MODULE_STATE_STARTED_PRE:
1429         case MODULE_STATE_START_PRE_FAILED:
1430         case MODULE_STATE_STOPPED_PRE:
1431         case MODULE_STATE_STOP_PRE_FAILED:
1432         case MODULE_STATE_STARTED_BACKGROUND:
1433         case MODULE_STATE_START_BACKGROUND_FAILED:
1434         case MODULE_STATE_STOPPED_BACKGROUND:
1435         case MODULE_STATE_STOP_BACKGROUND_FAILED:
1436           {
1437             const UI_32 l_iCmd = InProgressStateToSendMsg();  // LCOV_EXCL_BR_LINE 11:Gcov constraints (because exception-handling routes are automatically generated)
1438             if (l_iCmd != SS_SYSTEM_MANAGER_PROTOCOL_ENDING_INDEX) {  // LCOV_EXCL_BR_LINE 6: Excluded due to value never returned at present
1439               // LCOV_EXCL_BR_START 15: Excluded due to inlined functions
1440               CALL_AND_LOG_STATUS_IF_ERRORED(l_ModuleListIterator->SendMsgAndUpdateState(l_iCmd, &f_startupData));
1441               // LCOV_EXCL_BR_STOP 15: Excluded due to inlined functions
1442               l_numModulesMessaged++;
1443             }
1444           }
1445           break;
1446           // default:  Don't code a 'default' here - let the compiler
1447           // detect when the set of module_state enumerations changes -
1448           // then the System Service's System Manager maintainer will
1449           // automagically know to update this switch statement.
1450         }
1451       }
1452     }
1453
1454     if (0 == l_numModulesMessaged) {
1455       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)
1456
1457       char l_cBuf[100];
1458       snprintf(l_cBuf, sizeof(l_cBuf), "ProcessGroupAsStarted(%d)", l_GroupIterator->second.id);
1459       l_eStatus = ProcessGroupAsStarted(hApp, l_GroupIterator);
1460       LOG_STATUS_REC_HIST_IF_ERRORED(l_eStatus, l_cBuf);  // LCOV_EXCL_BR_LINE 6: Because the condition cannot be set
1461     } else {
1462       m_GroupLaunchTimer->StartTimer(
1463           m_aTimerIDs[eSM_TIMER_CLIENT_START_MONITOR],
1464           SS_CLIENT_START_MONITOR_TIMER_CONFIG, 0, 0, 0);
1465     }
1466   }
1467   FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-");
1468   return l_eStatus;
1469 }  // End of EFrameworkunifiedStatus CSystemManager::start_all_modules_of_group(HANDLE hApp, UI_32 f_ui32GroupNumber)
1470
1471 ///////////////////////////////////////////////////////////////////////////////
1472 /// \ingroup start_all_modules_of_group
1473 /// mark the specified group as started. If there is another group to start,
1474 /// do so, else send Start Complete Response to the Start Requester.
1475 ///
1476 /// \param [in]
1477 ///
1478 ///
1479 /// \return EFrameworkunifiedStatus
1480 /// Success ==> eFrameworkunifiedStatusOK
1481 /// Failure ==> Other values
1482 ///////////////////////////////////////////////////////////////////////////////
1483 EFrameworkunifiedStatus CSystemManager::ProcessGroupAsStarted(HANDLE hApp, UI_32 f_groupId) {
1484   EFrameworkunifiedStatus l_eStatus;
1485   FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+");
1486
1487   GroupLaunchMapIter l_GroupIterator = m_MapProclaunchGrps.find(f_groupId);
1488   if (l_GroupIterator == m_MapProclaunchGrps.end()) {
1489     FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__,
1490         " Error: Group %d not found; 'm_MapProclaunchGrps' is empty", f_groupId);
1491     l_eStatus = eFrameworkunifiedStatusInvldParam;
1492   } else {
1493     l_eStatus = ProcessGroupAsStarted(hApp, l_GroupIterator);
1494   }
1495
1496   FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-");
1497   return l_eStatus;
1498 }  // End of EFrameworkunifiedStatus CSystemManager::ProcessGroupAsStarted( HANDLE hApp, UI_32 f_groupId )
1499
1500 ///////////////////////////////////////////////////////////////////////////////
1501 /// \ingroup start_all_modules_of_group
1502 /// mark the specified group as started. If there is another group to start,
1503 /// do so, else send Start Complete Response to the Start Requester.
1504 ///
1505 /// \param [in]
1506 ///
1507 ///
1508 /// \return EFrameworkunifiedStatus
1509 /// Success ==> eFrameworkunifiedStatusOK
1510 /// Failure ==> Other values
1511 ///////////////////////////////////////////////////////////////////////////////
1512 EFrameworkunifiedStatus CSystemManager::ProcessGroupAsStarted(HANDLE hApp,
1513         GroupLaunchMapIter f_GroupIterator) {
1514   EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK;
1515   FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+");
1516   UI_32 l_groupID = m_SystemStarter.get_id();
1517
1518
1519   m_GroupLaunchTimer->StopTimer(m_aTimerIDs[eSM_TIMER_CLIENT_START_MONITOR]);
1520
1521   FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__,
1522       " Group %d/%s start completed, m_SystemStarter.get_id() is %d",
1523       f_GroupIterator->second.id, f_GroupIterator->second.name.c_str(),
1524       l_groupID);
1525
1526   if (f_GroupIterator->second.id != l_groupID) {
1527     FRAMEWORKUNIFIEDLOG(ZONE_INFO,
1528         __FUNCTION__
1529         , " The just-started group ( %d/%s ) is not the current Active "
1530             " Group ( %d ); not starting next group's modules",
1531         f_GroupIterator->second.id,
1532         f_GroupIterator->second.name.c_str(), l_groupID);
1533   } else {
1534     if ((m_SMCurrentState == SS_SM_APPS_START_IN_PROGRESS)
1535         || (m_SMCurrentState == SS_SM_APPS_PRE_START_IN_PROGRESS)
1536         || (m_SMCurrentState == SS_SM_APPS_BACKGROUND_START_IN_PROGRESS)) {
1537       // check if WakeUp Level has been achieved
1538       if (m_SystemStarter.is_end() == FALSE) {
1539         // Start modules from next group
1540         l_groupID = m_SystemStarter.advance_id();  // LCOV_EXCL_BR_LINE 11:Gcov constraints (because exception-handling routes are automatically generated)
1541         char l_cBuf[100] = {0};
1542         snprintf(l_cBuf, sizeof(l_cBuf), "start_all_modules_of_group(%u)", l_groupID);
1543         l_eStatus = start_all_modules_of_group(hApp, l_groupID);  // LCOV_EXCL_BR_LINE 11:Gcov constraints (because exception-handling routes are automatically generated)
1544         LOG_STATUS_REC_HIST_IF_ERRORED(l_eStatus, l_cBuf);   // LCOV_EXCL_BR_LINE 6: Because the condition cannot be set
1545       }
1546     } else if ((m_SMCurrentState == SS_SM_APPS_PRE_STOP_IN_PROGRESS)
1547         || (m_SMCurrentState == SS_SM_APPS_BACKGROUND_STOP_IN_PROGRESS)) {
1548       if (m_SystemStarter.is_begin() == FALSE) {
1549         // Stop modules from next group
1550         l_groupID = m_SystemStarter.decrement_id();  // LCOV_EXCL_BR_LINE 11:Gcov constraints (because exception-handling routes are automatically generated)
1551         char l_cBuf[100] = {0};
1552         snprintf(l_cBuf, sizeof(l_cBuf), "stop_all_modules_of_group(%u)", l_groupID);
1553         l_eStatus = start_all_modules_of_group(hApp, l_groupID);  // LCOV_EXCL_BR_LINE 11:Gcov constraints (because exception-handling routes are automatically generated)
1554         LOG_STATUS_REC_HIST_IF_ERRORED(l_eStatus, l_cBuf);   // LCOV_EXCL_BR_LINE 6: Because the condition cannot be set
1555       }
1556     } else {
1557       // MISRA C++-2008 Rule 6-4-2
1558       // NOP
1559     }
1560   }
1561   FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-");
1562   return l_eStatus;
1563 }  // End of EFrameworkunifiedStatus CSystemManager::ProcessGroupAsStarted( GroupLaunchMapIter f_GroupIterator )
1564
1565 ///////////////////////////////////////////////////////////////////////////////
1566 /// \ingroup calculate_max_shutdown_time
1567 /// Calculate maximum shutdown time of apps critical to shutdown
1568 /// from the launch group map
1569 ///
1570 /// \param [in]
1571 ///
1572 /// \return UI_32
1573 /// Max Value of critical shutdown apps shutdown time
1574 ///////////////////////////////////////////////////////////////////////////////
1575 UI_32 CSystemManager::calculate_max_shutdown_time() {
1576   FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+");
1577   UI_32 l_MaxShutdownTimeValue = 0;
1578   std::string moduleName;
1579
1580   GroupLaunchMapIter l_GroupIterator = m_MapProclaunchGrps.begin();
1581   for (; l_GroupIterator != m_MapProclaunchGrps.end(); l_GroupIterator++) {
1582     ModuleLaunchListIter l_ModuleListIterator =
1583         l_GroupIterator->second.modules.begin();
1584     for (; l_ModuleListIterator != l_GroupIterator->second.modules.end();
1585         l_ModuleListIterator++) {
1586       if (l_ModuleListIterator->shutdown_critical) {
1587         if (l_MaxShutdownTimeValue < l_ModuleListIterator->shutdown_wait_time) {
1588           moduleName = l_ModuleListIterator->name;
1589           l_MaxShutdownTimeValue = l_ModuleListIterator->shutdown_wait_time;
1590         }
1591       }
1592     }
1593   }
1594   FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__, " Max time: Module %s, time %d s",
1595       moduleName.c_str(), l_MaxShutdownTimeValue);
1596   FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-");
1597   return l_MaxShutdownTimeValue;
1598 }
1599
1600 ///////////////////////////////////////////////////////////////////////////////
1601 /// \ingroup OnShutdownModulesRequest
1602 /// Send Shutdown to all modules in reverse order of group
1603 ///
1604 /// \param [in]
1605 ///
1606 /// \return EFrameworkunifiedStatus
1607 /// Success ==> eFrameworkunifiedStatusOK
1608 /// Failure ==> Other values
1609 ///////////////////////////////////////////////////////////////////////////////
1610 EFrameworkunifiedStatus CSystemManager::OnShutdownModulesRequest(HANDLE hApp) {
1611   FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+");
1612   EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK;
1613
1614   FRAMEWORKUNIFIEDLOG(ZONE_STATE, __FUNCTION__,
1615       " Received from %s, m_SystemStarter.get_id() is %d",
1616       FrameworkunifiedGetMsgSrc(hApp)
1617       , m_SystemStarter.get_id());
1618
1619   FRAMEWORKUNIFIEDLOG(ZONE_PERFORMANCE, __FUNCTION__, "m_SystemStarter.get_id() is %d", m_SystemStarter.get_id());
1620
1621   SetCmdHist("SS_SM_SHUTDOWN_MODULES", m__CWORD56_CmdHist, m__CWORD56_HistIter, FrameworkunifiedGetMsgSrc(hApp)); // LCOV_EXCL_BR_LINE 11:unexpected branch  // NOLINT(whitespace/line_length)
1622
1623   Pwr_ServiceSetInterface l_tServiceSetIf;
1624   // ReadMsg():                              *
1625   //   Check hApp ptr, msg size, msg reception, read msg if all ok.    *
1626   if (eFrameworkunifiedStatusOK != (l_eStatus = ReadMsg < Pwr_ServiceSetInterface > (hApp, l_tServiceSetIf))) {   // LCOV_EXCL_BR_LINE 4: nsfw error
1627     // LCOV_EXCL_START 4: nsfw error
1628     AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
1629     LOG_ERROR("ReadMsg()");  // LCOV_EXCL_BR_LINE 15: marco defined in ss_templates.h  // NOLINT(whitespace/line_length)
1630     // LCOV_EXCL_STOP
1631   } else {
1632     BOOL isImmShutdown = FALSE;
1633
1634     // If the Shutdown is not completed after the Shutdown is requested, it is forcibly reset.
1635     m_GroupLaunchTimer->StartTimer(
1636         m_aTimerIDs[eSM_TIMER_SHUTDOWN_COMPLETE_MONITOR],
1637         SM_SHUTDOWN_COMPLETE_MONITOR_TIMEOUT, 0, 0, 0);
1638
1639     if (m_isImmResetReq) {
1640       FRAMEWORKUNIFIEDLOG(ZONE_STATE, __FUNCTION__, " ImmReset");
1641       isImmShutdown = TRUE;
1642     }
1643
1644     switch (l_tServiceSetIf.data.shutdownRequestMsg.lastUserMode) {
1645     case epsumINVALID:
1646       FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__,
1647           " Error: shutdownRequestMsg.lastUserMode == epsumINVALID");
1648       l_eStatus = eFrameworkunifiedStatusInvldParam;
1649       break;
1650
1651     case epsumOFF:
1652     case epsumON: {
1653       switch (m_SMCurrentState) {
1654       case SS_SM_READY_TO_LAUNCH_APP:
1655       case SS_SM_APPS_LAUNCH_IN_PROGRESS:
1656       case SS_SM_APPS_LAUNCHED_READY_TO_START:
1657         isImmShutdown = TRUE;
1658       case SS_SM_APPS_START_COMPLETE:
1659       case SS_SM_APPS_START_IN_PROGRESS:
1660       case SS_SM_APPS_PRE_START_IN_PROGRESS:
1661       case SS_SM_APPS_PRE_STOP_IN_PROGRESS:
1662       case SS_SM_APPS_PRE_RUN_COMPLETE:
1663       case SS_SM_APPS_BACKGROUND_START_IN_PROGRESS:
1664       case SS_SM_APPS_BACKGROUND_STOP_IN_PROGRESS:
1665       case SS_SM_APPS_BACKGROUND_RUN_COMPLETE:
1666
1667         if (l_tServiceSetIf.data.shutdownRequestMsg.shutdownTrigger ==
1668                                                             epssdmsdtIGN_OFF) {
1669           m_ResetCount = 0;
1670           if (PowerHalSetResetInfo(AGL_RESET_COUNTER, m_ResetCount)) {  // LCOV_EXCL_BR_LINE 11:Gcov constraints (because exception-handling routes are automatically generated)
1671             FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__,
1672               "Could not back up m_ResetCount(%lu) to power_hal", m_ResetCount);
1673           }
1674
1675           if (PowerHalSetResetInfo(AGL_ERRLOG_COUNTER, 0)) {  // LCOV_EXCL_BR_LINE 11:Gcov constraints (because exception-handling routes are automatically generated)
1676             FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__,
1677               "Could not reset AGL_ERRLOG_COUNTER");
1678           }
1679         }
1680         if (!m_isPrevErrEventCompleted
1681             || ((!((m_SMCurrentState == SS_SM_APPS_START_COMPLETE)
1682                 || (m_SMCurrentState == SS_SM_APPS_PRE_RUN_COMPLETE)
1683                 || (m_SMCurrentState == SS_SM_APPS_BACKGROUND_RUN_COMPLETE)))
1684                 && (l_tServiceSetIf.data.shutdownRequestMsg.shutdownTrigger
1685                     == epssdmsdtIGN_OFF
1686                     || l_tServiceSetIf.data.shutdownRequestMsg.shutdownTrigger
1687                         == epssdmsdtNORMAL_RESET))) {
1688           FRAMEWORKUNIFIEDLOG(ZONE_STATE, __FUNCTION__, "shutdown pending");
1689           if (!m_dqDeferMsg.empty()) {
1690             SS_ASERT(0);  // LCOV_EXCL_BR_LINE 15: marco defined in ss_templates.h  // NOLINT(whitespace/line_length)
1691           } else {
1692             SM_POWER_EVENT_INFO deferMsg(SS_SM_SHUTDOWN_MODULES, l_tServiceSetIf);
1693             m_dqDeferMsg.push(deferMsg);
1694           }
1695         } else {
1696           // The shutdownTrigger has already been validated by
1697           // Power::OnShutdownRequestMsg()
1698           m_shutdownTrigger = l_tServiceSetIf.data.shutdownRequestMsg.shutdownTrigger;
1699           m_lastUserMode = l_tServiceSetIf.data.shutdownRequestMsg.lastUserMode;
1700
1701           // Notify services ShutDownTrigger the FrameworkunifiedOnStop, if dataResetMode is configured
1702           // When using FastSleep, be aware that it may be overwritten here
1703           switch (m_DataResetMode) {
1704           case e_SS_SM_DATA_RESET_MODE_FACTORY:
1705             m_shutdownTrigger = epssdmsdtFACTORY_DATA_RESET;
1706             break;
1707           case e_SS_SM_DATA_RESET_MODE_USER:
1708             m_shutdownTrigger = epssdmsdtUSER_DATA_RESET;
1709             break;
1710           default:
1711             break;
1712           }
1713
1714           if (isImmShutdown) {
1715             m_GroupLaunchTimer->StopTimer(m_aTimerIDs[eSM_TIMER_GROUP_LAUNCH_WAIT_TIMER]);
1716
1717             // Do not use m_shutdownTrigger because it is updated on DataReset
1718             switch (l_tServiceSetIf.data.shutdownRequestMsg.shutdownTrigger) {
1719             case epssdmsdtGENERIC_ERROR_RESET:
1720             case epssdmsdtFATAL_ERROR_RESET:
1721               CALL_AND_LOG_STATUS((*m_pfStopCompleteHandler)(hApp));  // LCOV_EXCL_BR_LINE 15: marco defined in ss_templates.h  // NOLINT(whitespace/line_length)
1722               break;
1723             default:
1724               FRAMEWORKUNIFIEDLOG(ZONE_WARN, __FUNCTION__,
1725                   " Warning: Received a Shutdown command while in "
1726                   "the '%s' state - returning Shutdown "
1727                   "Response msg now",
1728                   GetStr(m_SMCurrentState).c_str());
1729
1730               CALL_AND_LOG_STATUS(SendShutdownResponseMessage(hApp));  // LCOV_EXCL_BR_LINE 15: marco defined in ss_templates.h  // NOLINT(whitespace/line_length)
1731               break;
1732             }
1733
1734           } else {
1735             InitiateAllGroupsShutdown(hApp);
1736           }
1737         }
1738         break;
1739
1740       case SS_SM_APPS_STOPPING_AT__CWORD56__REQ:
1741       case SS_SM_APPS_STOPPING_AT_INTERNAL_REQ:
1742       case SS_SM_WAITING_FOR_CRITICAL_APPS_AT__CWORD56__REQ:
1743       case SS_SM_WAITING_FOR_CRITICAL_APPS_AT_INTERNAL_REQ:
1744         FRAMEWORKUNIFIEDLOG(ZONE_WARN, __FUNCTION__,
1745             " Warning: Received a Shutdown command while already in "
1746             "the '%s' state !!!",
1747             GetStr(m_SMCurrentState).c_str());
1748         break;
1749       }  // End switch ( m_SMCurrentState )
1750       break;
1751     }  // End case epsumOFF | epsumON
1752     }  // End switch (m_lastUserMode )
1753   }
1754
1755   FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-");
1756   return l_eStatus;
1757 }  // End of EFrameworkunifiedStatus CSystemManager::OnShutdownModulesRequest( HANDLE hApp )
1758
1759 ///////////////////////////////////////////////////////////////////////////////
1760 /// \ingroup SendSystemModeInfoResponse
1761 /// send SystemModeInfo to
1762 /// _CWORD56_ ( via Power Service-> PSMShadow ) as an IPC 'Start Notification'
1763 /// message, informing _CWORD56_ of the startup state of the _CWORD102_.
1764 ///
1765 /// \param [in] HANDLE hApp
1766 ///
1767 /// \return EFrameworkunifiedStatus
1768 /// Success ==> eFrameworkunifiedStatusOK
1769 /// Failure ==> Other values
1770 ///////////////////////////////////////////////////////////////////////////////
1771 EFrameworkunifiedStatus CSystemManager::SendSystemModeInfoResponse(HANDLE hApp, EPWR_STARTUP_STAGE_TYPE f_startupStage) {
1772   FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+");
1773   EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK;
1774   SystemModeInfo l_SystemModeInfo;
1775
1776   memcpy(&l_SystemModeInfo, &m_SystemModeInfo, sizeof(l_SystemModeInfo));
1777
1778   FRAMEWORKUNIFIEDLOG(ZONE_STATE, __FUNCTION__, "stage:%d", f_startupStage);
1779   l_SystemModeInfo.startupStage = f_startupStage;
1780
1781   l_eStatus = FrameworkunifiedSendMsg(m_hPowerServiceSession, SS_SM_SYSTEM_MODE_INFO_RSPN,
1782       sizeof(l_SystemModeInfo), (PVOID) & l_SystemModeInfo);
1783
1784   if (eFrameworkunifiedStatusOK != l_eStatus) {  // LCOV_EXCL_BR_LINE 4: NSFW error case.
1785     FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__,
1786         " Error: SendSystemModeInfoResponse(%s) errored: 0x%X",
1787         GetStr(l_SystemModeInfo.startupStage).c_str(), l_eStatus);
1788   } else {
1789     // LCOV_EXCL_START 4: NSFW error case.
1790     AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
1791     FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__,
1792         " SendSystemModeInfoResponse(%s) successful",
1793         GetStr(l_SystemModeInfo.startupStage).c_str());
1794     // LCOV_EXCL_STOP
1795   }
1796
1797   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)
1798   FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-");
1799   return l_eStatus;
1800 }  // End of EFrameworkunifiedStatus CSystemManager::SendSystemModeInfoResponse( HANDLE hApp )
1801
1802 ///////////////////////////////////////////////////////////////////////////////
1803 /// \ingroup OnSystemModeInfoRequest
1804 /// Handle System Mode Info request. Send System Mode Info read from NVM
1805 ///
1806 /// \param [in] HANDLE hApp
1807 ///
1808 /// \return EFrameworkunifiedStatus
1809 /// Success ==> eFrameworkunifiedStatusOK
1810 /// Failure ==> Other values
1811 ///////////////////////////////////////////////////////////////////////////////
1812 EFrameworkunifiedStatus CSystemManager::OnSystemModeInfoRequest(HANDLE hApp) {
1813   FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+");
1814   EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK;
1815   INTERFACEUNIFIEDLOG_RECEIVED_FROM(hApp);  // LCOV_EXCL_BR_LINE 15: marco defined in ns_logger_if.h  // NOLINT(whitespace/line_length)
1816   FRAMEWORKUNIFIEDLOG(ZONE_PERFORMANCE, __FUNCTION__, "from %s", FrameworkunifiedGetMsgSrc(hApp));
1817   m_isRcvModeInfo = TRUE;
1818
1819   SetCmdHist("SS_SM_SYSTEM_MODE_INFO_REQ", m__CWORD56_CmdHist, m__CWORD56_HistIter, FrameworkunifiedGetMsgSrc(hApp));
1820
1821   if (m_SystemModeInfo.startupStage == epssusfINVALID) {
1822     // Transitioning to SYSTEM_SERVICES_STARTED if startupStage == INVALID
1823     m_SystemModeInfo.startupStage = epssusSYSTEM_SERVICES_STARTED;
1824   }
1825
1826   l_eStatus = SendSystemModeInfoResponse(hApp, epssusSYSTEM_SERVICES_STARTED);
1827   LOG_STATUS(l_eStatus, "SendSystemModeInfoResponse()");  // LCOV_EXCL_BR_LINE 15: marco defined in ss_templates.h  // NOLINT(whitespace/line_length)
1828
1829   if (TRUE == m_isRstPending) {
1830     ESMCpuResetReason l_resetReason = m_rstPendingInfo.resetReason;
1831     std::string l_messageStr = m_rstPendingInfo.messageStr;
1832
1833     m_isRstPending = FALSE;
1834     m_rstPendingInfo.resetReason = e_SS_SM_CPU_RESET_REASON_INVALID;
1835     memset(m_rstPendingInfo.messageStr, 0, sizeof(m_rstPendingInfo.messageStr));
1836
1837     l_eStatus = PerformCpuReset(hApp, l_resetReason, l_messageStr);
1838     LOG_STATUS(l_eStatus, "PerformCpuReset()");  // LCOV_EXCL_BR_LINE 6: Because it is executed only once and cannot see all branches
1839   }
1840
1841   if (m_SystemModeInfo.startupStage == epssusALL_SERVICES_LAUNCHED) {
1842     // If startupStage == ALL_SERVICES_LAUNCHED
1843     // Notify here because Launch of all SVCs is completed first.
1844     l_eStatus = SendSystemModeInfoResponse(hApp, epssusALL_SERVICES_LAUNCHED);
1845     LOG_STATUS(l_eStatus, "SendSystemModeInfoResponse()");  // LCOV_EXCL_BR_LINE 15: marco defined in ss_templates.h  // NOLINT(whitespace/line_length)
1846   }
1847
1848   FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-");
1849   return l_eStatus;
1850 }  // End of EFrameworkunifiedStatus CSystemManager::OnSystemModeInfoRequest( HANDLE hApp )
1851
1852 ///////////////////////////////////////////////////////////////////////////////
1853 /// \ingroup OnInitCompReportCallback
1854 /// Handle InitComp report.
1855 ///
1856 /// \param [in] HANDLE hApp
1857 ///
1858 /// \return EFrameworkunifiedStatus
1859 /// Success ==> eFrameworkunifiedStatusOK
1860 /// Failure ==> Other values
1861 ///////////////////////////////////////////////////////////////////////////////
1862 EFrameworkunifiedStatus CSystemManager::OnInitCompReportCallback(HANDLE hApp) {
1863   FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+");
1864   EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK;
1865   INTERFACEUNIFIEDLOG_RECEIVED_FROM(hApp);  // LCOV_EXCL_BR_LINE 15: marco defined in ns_logger_if.h  // NOLINT(whitespace/line_length)
1866   FRAMEWORKUNIFIEDLOG(ZONE_PERFORMANCE, __FUNCTION__, "from %s", FrameworkunifiedGetMsgSrc(hApp));
1867
1868   SetCmdHist("SS_SM_INITCOMP_REP", m__CWORD56_CmdHist, m__CWORD56_HistIter, FrameworkunifiedGetMsgSrc(hApp));
1869
1870   FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-");
1871   return l_eStatus;
1872 }  // End of EFrameworkunifiedStatus CSystemManager::OnInitCompReportCallback( HANDLE hApp )
1873
1874 ///////////////////////////////////////////////////////////////////////////////
1875 /// \ingroup have_all_services_start_completed
1876 ///  check if state of all services is MODULE_STATE_STARTED
1877 ///
1878 /// \param [in]
1879 ///
1880 ///
1881 /// \return BOOL
1882 /// Success ==> TRUE
1883 /// Failure ==> FALSE
1884 ///////////////////////////////////////////////////////////////////////////////
1885 BOOL CSystemManager::have_all_services_start_completed(const SMModuleState f_moduleState) {
1886   FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+");
1887   BOOL bIsStartCompleted = TRUE;
1888   SMModuleState l_failedState = MODULE_STATE_INVALID;
1889
1890   switch (f_moduleState) {
1891     case MODULE_STATE_STARTED:
1892       l_failedState = MODULE_STATE_START_FAILED;
1893       break;
1894     case MODULE_STATE_STARTED_PRE:
1895       l_failedState = MODULE_STATE_START_PRE_FAILED;
1896       break;
1897     case MODULE_STATE_STOPPED_PRE:
1898       l_failedState = MODULE_STATE_STOP_PRE_FAILED;
1899       break;
1900     case MODULE_STATE_STARTED_BACKGROUND:
1901       l_failedState = MODULE_STATE_START_BACKGROUND_FAILED;
1902       break;
1903     case MODULE_STATE_STOPPED_BACKGROUND:
1904       l_failedState = MODULE_STATE_STOP_BACKGROUND_FAILED;
1905       break;
1906     default:
1907       bIsStartCompleted = FALSE;
1908       break;
1909   }
1910   if (l_failedState != MODULE_STATE_INVALID) {
1911     GroupLaunchMapIter l_GroupIterator = m_MapProclaunchGrps.begin();
1912     for (; l_GroupIterator != m_MapProclaunchGrps.end(); l_GroupIterator++) {
1913       ModuleLaunchListIter l_ModuleListIterator = l_GroupIterator->second.modules.begin();
1914       for (; l_ModuleListIterator != l_GroupIterator->second.modules.end(); l_ModuleListIterator++) {
1915         if ((l_ModuleListIterator->is_start_required == TRUE)
1916             && ((l_ModuleListIterator->IsModuleState(f_moduleState) == FALSE)  // LCOV_EXCL_BR_LINE 11:Gcov constraints (because exception-handling routes are automatically generated)
1917                 && (l_ModuleListIterator->IsModuleState(MODULE_STATE_SKIPPED) == FALSE)  // LCOV_EXCL_BR_LINE 11:Gcov constraints (because exception-handling routes are automatically generated)
1918                 && (l_ModuleListIterator->IsModuleState(l_failedState) == FALSE))) {  // LCOV_EXCL_BR_LINE 11:Gcov constraints (because exception-handling routes are automatically generated)
1919           // Allow _SKIPPED/START_FAILED for StartRespMonitor conditions
1920           bIsStartCompleted = FALSE;
1921           break;
1922         }
1923       }
1924     }
1925   }
1926   FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-");
1927   return bIsStartCompleted;
1928 }
1929
1930 ///////////////////////////////////////////////////////////////////////////////
1931 /// \ingroup is_critical_service_stopped
1932 ///
1933 ///
1934 /// \param [in]
1935 ///
1936 ///
1937 /// \return BOOL
1938 /// Success ==> TRUE
1939 /// Failure ==> FALSE
1940 ///////////////////////////////////////////////////////////////////////////////
1941 BOOL CSystemManager::is_service_shutdown_ready(ModuleLaunchListIter &modIte) {
1942   if (((modIte->shutdown_critical && modIte->is_start_required)
1943       || (modIte->name == FRAMEWORKUNIFIED_NS_NPSERVICE))
1944       && modIte->IsModuleState(MODULE_STATE_STOPPED) == FALSE) {
1945     // Not shutdown_ready if NPP or shutdown_critical services are not STOPPED.
1946     return FALSE;
1947   }
1948   return TRUE;
1949 }
1950
1951 ///////////////////////////////////////////////////////////////////////////////
1952 /// \ingroup have_critical_services_stopped
1953 ///  check if state of all critical services is MODULE_STATE_STOPPED
1954 ///
1955 /// \param [in]
1956 ///
1957 ///
1958 /// \return BOOL
1959 /// Success ==> TRUE
1960 /// Failure ==> FALSE
1961 ///////////////////////////////////////////////////////////////////////////////
1962 BOOL CSystemManager::have_critical_services_stopped() {
1963   FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+");
1964   uint numStoppingModules = 0;
1965
1966   GroupLaunchMapIter l_GroupIterator = m_MapProclaunchGrps.begin();
1967   for (; l_GroupIterator != m_MapProclaunchGrps.end(); l_GroupIterator++) {
1968     ModuleLaunchListIter l_ModuleListIterator = l_GroupIterator->second.modules.begin();
1969     for (; l_ModuleListIterator != l_GroupIterator->second.modules.end(); l_ModuleListIterator++) {
1970       if (l_ModuleListIterator->IsModuleState(MODULE_STATE_STOP_SENT)
1971           && l_ModuleListIterator->shutdown_critical) {
1972         numStoppingModules++;
1973       }
1974     }
1975   }
1976   FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-");
1977   return (numStoppingModules == 0);
1978 }
1979
1980 ///////////////////////////////////////////////////////////////////////////////
1981 /// \ingroup perform_force_reset
1982 ///
1983 ///
1984 /// \param [in]
1985 ///
1986 ///
1987 /// \return EFrameworkunifiedStatus
1988 /// Success ==> eFrameworkunifiedStatusOK
1989 /// Failure ==> Other values
1990 ///////////////////////////////////////////////////////////////////////////////
1991 EFrameworkunifiedStatus CSystemManager::perform_force_reset(HANDLE hApp) {
1992   EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK;
1993   FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "+");
1994
1995   // Since initialization must be performed by the PSMs during FactReset, do not NaviDet them as much as possible.
1996   if (e_SS_SM_DATA_RESET_MODE_FACTORY == m_DataResetMode) {
1997     fprintf(stderr,
1998         "SS_SysManager/%s/NO NAVIDET!! but SendShutdownComp for FactReset\n", __FUNCTION__);
1999     FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__,
2000         "NO NAVIDET!! but SendShutdownComp for FactReset");
2001     CALL_AND_LOG_STATUS(send_shutdown_complete_response(hApp));  // LCOV_EXCL_BR_LINE 15: marco defined in ss_templates.h  // NOLINT(whitespace/line_length)
2002     sleep(60);
2003   } else if (access("/var/local/lib/basesystem/nv/BS/ss/system_manager/rwdata/ss_debug", F_OK) == 0) {
2004     fprintf(stderr, "SS_SysManager/%s/NO NAVIDET!! but SendShutdownComp\n", __FUNCTION__);
2005     FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "NO NAVIDET!! but SendShutdownComp");
2006     CALL_AND_LOG_STATUS(send_shutdown_complete_response(hApp));  // LCOV_EXCL_BR_LINE 15: marco defined in ss_templates.h  // NOLINT(whitespace/line_length)
2007     sleep(60);
2008   }
2009
2010   fflush(stderr);
2011   usleep(100 * 1000);
2012
2013   if (0 == PsmNaviResetPower(hApp, m_ResetFactor)) {  // LCOV_EXCL_BR_LINE 200: power_hal if, can not to be error.
2014     SS_ASERT_ERRNO(0);  // LCOV_EXCL_BR_LINE 15: marco defined in ss_templates.h  // NOLINT(whitespace/line_length)
2015   } else {
2016     usleep(300 * 1000);
2017     fprintf(stderr, "SS_SysManager/%s/Error: Not Reset !!!\n", __FUNCTION__);
2018     l_eStatus = eFrameworkunifiedStatusFail;
2019   }
2020
2021   send_shutdown_complete_response(hApp);  // Try to NAVI_RESET even if ignored
2022
2023   FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "-");
2024   return l_eStatus;
2025 }
2026
2027 ///////////////////////////////////////////////////////////////////////////////
2028
2029 ///////////////////////////////////////////////////////////////////////////////
2030 /// \ingroup send_shutdown_complete_response
2031 ///
2032 ///
2033 /// \param [in]
2034 ///
2035 ///
2036 /// \return EFrameworkunifiedStatus
2037 /// Success ==> eFrameworkunifiedStatusOK
2038 /// Failure ==> Other values
2039 ///////////////////////////////////////////////////////////////////////////////
2040 EFrameworkunifiedStatus CSystemManager::send_shutdown_complete_response(HANDLE hApp) {
2041   EFrameworkunifiedStatus l_eStatus;
2042   FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+");
2043
2044   CALL_AND_LOG_STATUS(ResetModulesStateToConnected(hApp));  // LCOV_EXCL_BR_LINE 15: marco defined in ss_templates.h  // NOLINT(whitespace/line_length)
2045
2046   SMSetState(hApp, SS_SM_APPS_LAUNCHED_READY_TO_START);
2047   // m_ActiveGroupId = SS_SM_INITIAL_GROUP;
2048
2049   // all the modules have stopped, send Shutdown Response to Power Service
2050   FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__,
2051       " All critical services have stopped, Active Group ID is now %d",
2052       m_SystemStarter.get_id());
2053 #if 1
2054     CALL_AND_LOG_STATUS(SendShutdownResponseMessage(hApp));  // LCOV_EXCL_BR_LINE 15: marco defined in ss_templates.h  // NOLINT(whitespace/line_length)
2055 #else
2056   //
2057   // Normal, production flow is to call SendShutdownResponseMessage(), which
2058   // sends the Shutdown Response message to the _CWORD56_, causing the _CWORD56_ to
2059   // 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)
2060   // processed by SS_LoggerService.
2061   //
2062   // Optional development flow is to NOT call SendShutdownResponseMessage(),
2063   // 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)
2064   // abnormal, 'bad' condition of NOT sending a Shutdown Response message to
2065   // the _CWORD56_, be very obvious about this state by displaying both
2066   // compile-time and run-time warning messages.
2067   //
2068 #warning NOT calling SendShutdownResponseMessage(hApp) !
2069   FRAMEWORKUNIFIEDLOG(ZONE_WARN, __FUNCTION__,  // LCOV_EXCL_BR_LINE 15: marco defined in ns_logger_if.h  // NOLINT(whitespace/line_length)
2070       " Warning: SendShutdownResponseMessage( hApp ) "
2071       "#def'f out; ShutdownResponse NOT sent to _CWORD56_");
2072 #endif
2073
2074   FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-");
2075   return l_eStatus;
2076 }
2077
2078 ///////////////////////////////////////////////////////////////////////////////
2079 ///
2080 ///////////////////////////////////////////////////////////////////////////////
2081 EFrameworkunifiedStatus CSystemManager::SendShutdownResponseMessage(HANDLE hApp) {
2082   EFrameworkunifiedStatus l_eStatus;
2083   FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+");
2084   l_eStatus = FrameworkunifiedSendMsg(m_hPowerServiceSession,  // LCOV_EXCL_BR_LINE 15: marco defined in ns_logger_if.h  // NOLINT(whitespace/line_length)
2085       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)
2086   LOG_STATUS_REC_HIST_IF_ERRORED(l_eStatus,  // LCOV_EXCL_BR_LINE 15: marco defined in ss_system_manager.h  // NOLINT(whitespace/line_length)
2087       "FrameworkunifiedSendMsg(PowerService,SS_SM_SHUTDOWN_MODULES_CMPL_RSPN)");  // LCOV_EXCL_BR_LINE 15: marco defined in ss_system_manager.h  // NOLINT(whitespace/line_length)
2088
2089   FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-");
2090   return l_eStatus;
2091 }  // End of EFrameworkunifiedStatus CSystemManager::SendShutdownResponseMessage( HANDLE hApp )
2092
2093
2094 PsmFactorT CSystemManager::GetResetFactor(PCSTR f_module_name, BOOL f_user_reset) {
2095   PsmFactorT  l_reset_factor = PSM_FACTOR_NONE;
2096   EFrameworkunifiedStatus l_eStatus;
2097   ModuleLaunchListIter l_moduleIter;
2098   l_eStatus = GetModuleIterator(f_module_name, l_moduleIter);  // LCOV_EXCL_BR_LINE 11:Gcov constraints (because exception-handling routes are automatically generated)
2099   if (eFrameworkunifiedStatusOK != l_eStatus) {
2100     LOG_ERROR("GetModuleIterator()");  // LCOV_EXCL_BR_LINE 15: marco defined in ss_templates.h  // NOLINT(whitespace/line_length)
2101   } else {
2102     l_reset_factor = GetResetFactor(l_moduleIter, f_user_reset);
2103   }
2104   return l_reset_factor;
2105 }   // End of PsmFactorT CSystemManager::GetResetFactor(PCSTR f_module_name)
2106
2107
2108 PsmFactorT CSystemManager::GetResetFactor(const ModuleLaunchListIter f_module_iter, BOOL f_user_reset) {
2109   PsmFactorT  l_reset_factor;
2110   if (f_module_iter->IsAGLUnit() == TRUE) {
2111     if (f_module_iter->IsAGLResetHistoryDisable() == TRUE) {
2112       l_reset_factor = PSM_FACTOR_AGL;
2113     } else {
2114       l_reset_factor = PSM_FACTOR_AGL_WITH_HISTORY;
2115     }
2116   } else {
2117     if (f_module_iter->IsNonAGLResetHistoryDisable() == TRUE) {
2118       l_reset_factor = PSM_FACTOR_TIER1;
2119     } else {
2120       l_reset_factor = PSM_FACTOR_TIER1_WITH_HISTORY;
2121     }
2122   }
2123
2124   if (f_user_reset == TRUE) {
2125     if ((l_reset_factor == PSM_FACTOR_AGL) || (l_reset_factor == PSM_FACTOR_TIER1)) {
2126       l_reset_factor = PSM_FACTOR_USER;
2127     } else {
2128       l_reset_factor = PSM_FACTOR_USER_WITH_HISTORY;
2129     }
2130   }
2131   return l_reset_factor;
2132 }   // End of PsmFactorT GetResetFactor(ModuleLaunchListIter & f_module_iter)
2133 ///////////////////////////////////////////////////////////////////////////////
2134 /// \ingroup OnClientStopMonitorTimerExpiry
2135 ///
2136 ///
2137 /// \param [in]
2138 ///
2139 ///
2140 /// \return EFrameworkunifiedStatus
2141 /// Success ==> eFrameworkunifiedStatusOK
2142 /// Failure ==> Other values
2143 ///////////////////////////////////////////////////////////////////////////////
2144 EFrameworkunifiedStatus CSystemManager::OnClientStopMonitorTimerExpiry(HANDLE hApp) {
2145   EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK;
2146   FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+");
2147
2148   FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__, " Received from group %d", m_SystemStarter.get_id());
2149
2150   SetCmdHist("SM_TIMER_CLIENT_STOP_MONITOR", m_TimerCmdHist, m_TimerHistIter, FrameworkunifiedGetMsgSrc(hApp));  // LCOV_EXCL_BR_LINE 11:unexpected branch  // NOLINT(whitespace/line_length)
2151
2152   if ((m_SMCurrentState == SS_SM_WAITING_FOR_CRITICAL_APPS_AT__CWORD56__REQ)
2153       || (m_SMCurrentState == SS_SM_WAITING_FOR_CRITICAL_APPS_AT_INTERNAL_REQ)
2154       || m_SystemStarter.get_id() <= SS_SM_THIRD_GROUP) {
2155     FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, " Error: StopCompTimeout:gid:%d", m_SystemStarter.get_id());
2156     fprintf(stderr, "SS_SysManager/%s/Error: StopCompTimeout:gid:%d\n", __FUNCTION__, m_SystemStarter.get_id());
2157
2158     for (GroupLaunchMapIter l_GroupIterator = m_MapProclaunchGrps.begin();
2159         l_GroupIterator != m_MapProclaunchGrps.end();
2160         l_GroupIterator++) {
2161       for (ModuleLaunchListIter l_ModuleListIterator = l_GroupIterator->second.modules.begin();
2162           l_ModuleListIterator != l_GroupIterator->second.modules.end();
2163           l_ModuleListIterator++) {
2164         if (l_ModuleListIterator->group_id >= m_SystemStarter.get_id()
2165             && is_service_shutdown_ready(l_ModuleListIterator) == FALSE) {
2166           FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, " Error: %s", l_ModuleListIterator->name.c_str());
2167           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)
2168         }
2169       }
2170     }
2171
2172     if (!m_SystemStarter.is_begin()) {
2173       // Continue termination processing to perform BackupManager termination processing.
2174       m_SystemStarter.decrement_id();
2175       check_all_groups_have_stopped(hApp);
2176     } else {
2177       // DEAD CODE
2178       fprintf(stderr, "SS_SysManager/%s:SVC stop timeout\n", __FUNCTION__);
2179       FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, " SVC stop timeout");
2180       l_eStatus = CallStopCompleteHandler(hApp);
2181       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)
2182     }
2183   } else {
2184     // The current m_ActiveGroupId group just timed out. If possible,
2185     // decrement it, and then see if there are more groups to send
2186     // stop requests to.
2187     if (!m_SystemStarter.is_begin()) {
2188       m_SystemStarter.decrement_id();
2189     }
2190     check_all_groups_have_stopped(hApp);
2191   }
2192
2193   FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-");
2194   return l_eStatus;
2195 }  // End of EFrameworkunifiedStatus CSystemManager::OnClientStopMonitorTimerExpiry( HANDLE hApp )
2196
2197 ///////////////////////////////////////////////////////////////////////////////
2198 /// \ingroup check_all_groups_have_stopped
2199 /// check that all the groups has stopped
2200 ///
2201 /// \param [in]
2202 ///
2203 ///
2204 /// \return VOID
2205 ///////////////////////////////////////////////////////////////////////////////
2206 VOID CSystemManager::check_all_groups_have_stopped(HANDLE hApp) {
2207   EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK;
2208   UI_32 l_ActiveGroupId = m_SystemStarter.get_id();
2209   FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+");
2210   FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__,
2211       " m_SystemStarter.get_id() is %d, 'm_NPPStopSent' is '%s'"
2212       , m_SystemStarter.get_id(), GetStr(m_NPPStopSent).c_str());
2213
2214   // send stop to next group in reverse order
2215 //  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)
2216   if (!m_NPPStopSent) {
2217     l_eStatus = stop_all_modules_of_group(hApp);
2218     if (eFrameworkunifiedStatusOK != l_eStatus) {
2219       FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__,
2220           " Error: stop_all_modules_of_group(%d) errored: %d/'%s'",
2221           l_ActiveGroupId, l_eStatus, GetStr(l_eStatus).c_str());
2222     }
2223   } else {  // (m_ActiveGroupId < SS_SM_INITIAL_GROUP)
2224     BOOL l_bIsDetectTimeout;
2225
2226     if ((l_bIsDetectTimeout = !have_critical_services_stopped())) {
2227       // If the Critical service is not terminated even when the final GROUP is completed, DUMP the applicable service and issue NAVI_DET.
2228       FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, " FinalCriticalCheck");
2229       fprintf(stderr, "SS_SysManager/%s:FinalCriticalCheck\n", __FUNCTION__);  // LCOV_EXCL_BR_LINE 15: marco defined in ns_logger_if.h  // NOLINT(whitespace/line_length)
2230
2231       for (GroupLaunchMapIter l_GroupIterator = m_MapProclaunchGrps.begin();
2232           l_GroupIterator != m_MapProclaunchGrps.end();
2233           l_GroupIterator++) {
2234         for (ModuleLaunchListIter l_ModuleListIterator = l_GroupIterator->second.modules.begin();
2235             l_ModuleListIterator != l_GroupIterator->second.modules.end();
2236             l_ModuleListIterator++) {
2237           if (is_service_shutdown_ready(l_ModuleListIterator) == FALSE) {
2238             FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, " Error: %s",
2239                 l_ModuleListIterator->name.c_str());
2240             fprintf(stderr, "SS_SysManager/%s/Error: %s\n",  // LCOV_EXCL_BR_LINE 11:unexpected branch  // NOLINT(whitespace/line_length)
2241                 __FUNCTION__,
2242                 l_ModuleListIterator->name.c_str());  // LCOV_EXCL_BR_LINE 11:unexpected branch  // NOLINT(whitespace/line_length)
2243           }
2244         }
2245       }
2246       fprintf(stderr, "SS_SysManager/%s:critical service no stop\n", __FUNCTION__);
2247       FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "critical service no stop");
2248     }
2249
2250     CALL_AND_LOG_STATUS(CallStopCompleteHandler(hApp, l_bIsDetectTimeout));  // LCOV_EXCL_BR_LINE 15: marco defined in ss_templates.h  // NOLINT(whitespace/line_length)
2251
2252     // In PastModel002, there was a transition to WAITING_FOR_CRITICAL_APPS in the following processing, but in _CWORD71_,
2253     // the transition to WAITING_FOR_CRITICAL_APPS was eliminated by revising the termination processing.
2254   }
2255
2256   FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-");
2257   return;
2258 }  // End of VOID CSystemManager::check_all_groups_have_stopped( HANDLE hApp )
2259
2260 ///////////////////////////////////////////////////////////////////////////////
2261 /// \ingroup MarkModuleStateStopped
2262 /// Sets Module State to STOP COMPLETE
2263 ///
2264 /// \param [in]
2265 ///
2266 ///
2267 /// \return EFrameworkunifiedStatus
2268 /// Success ==> eFrameworkunifiedStatusOK
2269 /// Failure ==> Other values
2270 ///////////////////////////////////////////////////////////////////////////////
2271
2272
2273 ///////////////////////////////////////////////////////////////////////////////
2274 /// \ingroup OnNppStopComplete
2275 /// Npp Stop Complete complete Response\Ack Handlers
2276 ///
2277 /// \param [in]
2278 ///
2279 ///
2280 /// \return EFrameworkunifiedStatus
2281 /// Success ==> eFrameworkunifiedStatusOK
2282 /// Failure ==> Other values
2283 ///////////////////////////////////////////////////////////////////////////////
2284 EFrameworkunifiedStatus CSystemManager::OnNppStopComplete(HANDLE hApp) {
2285   FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+");
2286   EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK;
2287   INTERFACEUNIFIEDLOG_RECEIVED_FROM(hApp);  // LCOV_EXCL_BR_LINE 15: marco defined in ns_logger_if.h  // NOLINT(whitespace/line_length)
2288   FRAMEWORKUNIFIEDLOG(ZONE_PERFORMANCE, __FUNCTION__, "from %s", FrameworkunifiedGetMsgSrc(hApp));
2289
2290   SetCmdHist("NPS_NPP_STOP_ACK", m_SMCmdHist, m_SMHistIter, FrameworkunifiedGetMsgSrc(hApp));  // LCOV_EXCL_BR_LINE 11:unexpected branch  // NOLINT(whitespace/line_length)
2291
2292   char l_cBuf[100];
2293   snprintf(l_cBuf, sizeof(l_cBuf), "ProcessModuleStopCompleteResponse(%s)", FRAMEWORKUNIFIED_NS_NPSERVICE);
2294   l_eStatus = ProcessModuleStopCompleteResponse(hApp, FRAMEWORKUNIFIED_NS_NPSERVICE);
2295   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)
2296
2297   FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-");
2298   return eFrameworkunifiedStatusOK;
2299 }
2300
2301 EFrameworkunifiedStatus CSystemManager::GetModuleIterator(PCSTR f_moduleName, ModuleLaunchListIter &f_moduleIter) {
2302   FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+");
2303   EFrameworkunifiedStatus l_eStatus;
2304
2305   ModuleLaunchListIter l_moduleIter;
2306 //  static int l_numTimesEntered = 0 ;
2307 //  l_numTimesEntered++ ;
2308 //  FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__  // LCOV_EXCL_BR_LINE 15: marco defined in ns_logger_if.h  // NOLINT(whitespace/line_length)
2309 //       , " NTE %d: Looking for %s"
2310 //       , l_numTimesEntered
2311 //       , f_moduleName);
2312
2313   BOOL l_bIsFound = FALSE;
2314   for (GroupLaunchMapIter l_GroupIter = m_MapProclaunchGrps.begin();
2315       !l_bIsFound && l_GroupIter != m_MapProclaunchGrps.end();
2316       l_GroupIter++) {
2317 //    FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__  // LCOV_EXCL_BR_LINE 15: marco defined in ns_logger_if.h  // NOLINT(whitespace/line_length)
2318 //       , " NTE %d: Checking group %d/%s"
2319 //       , l_numTimesEntered
2320 //       , l_GroupIter->second.id
2321 //       , l_GroupIter->second.name.c_str());
2322
2323     for (l_moduleIter = l_GroupIter->second.modules.begin();
2324         !l_bIsFound && (l_moduleIter != l_GroupIter->second.modules.end());
2325         l_moduleIter++) {
2326 //    FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__  // LCOV_EXCL_BR_LINE 15: marco defined in ns_logger_if.h  // NOLINT(whitespace/line_length)
2327 //       , " NTE %d: Checking PCSTR '%s' against std::string '%s': %d, %s"
2328 //       , l_numTimesEntered
2329 //       , f_moduleName
2330 //       , l_moduleIter->name.c_str()
2331 //       , strcmp(l_moduleIter->name.c_str(), f_moduleName)
2332 //       , (0 == strcmp(l_moduleIter->name.c_str(), f_moduleName) ? "True" : "False"));
2333
2334       l_bIsFound =
2335           (0 == strcmp(l_moduleIter->name.c_str(), f_moduleName));
2336       if (l_bIsFound) {
2337         f_moduleIter = l_moduleIter;
2338 //        FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__,  // LCOV_EXCL_BR_LINE 15: marco defined in ns_logger_if.h  // NOLINT(whitespace/line_length)
2339 ////            " NTE %d:"
2340 //               " '%s' is in group %d/%s"
2341 ////           , l_numTimesEntered
2342 //           , f_moduleIter->name.c_str()
2343 //           , l_GroupIter->second.id
2344 //           , l_GroupIter->second.name.c_str());
2345         l_eStatus = eFrameworkunifiedStatusOK;
2346       }
2347     }
2348   }
2349
2350   if (!l_bIsFound) {
2351     FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__,
2352 //      " NTE %d:"
2353         " Error: '%s' is not in group map 'm_MapProclaunchGrps'"
2354 //       , l_numTimesEntered
2355         , f_moduleName);
2356     if (0 != strcmp(f_moduleName, SERVICE_SYSMANAGER)) {
2357       SysMgrConfiguration m_launchConfig;
2358       m_launchConfig.PrintAllInfo(m_MapProclaunchGrps);
2359     }
2360     l_eStatus = eFrameworkunifiedStatusDbRecNotFound;
2361   }
2362   FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-");
2363   return l_eStatus;
2364 }  // End of EFrameworkunifiedStatus CSystemManager::GetModuleIterator( PCSTR f_moduleName
2365
2366 BOOL CSystemManager::IsGroupStarted(UI_32 f_groupID) {
2367   FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+");
2368   BOOL l_bIsStarted = TRUE;
2369
2370   GroupLaunchMapIter l_GroupIter = m_MapProclaunchGrps.find(f_groupID);
2371   if (l_GroupIter == m_MapProclaunchGrps.end()) {
2372     FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, " Error: Group Map Empty; was looking for group %d", f_groupID);
2373   } else {
2374     ModuleLaunchListIter l_ModuleListIter = l_GroupIter->second.modules.begin();
2375     const SMModuleState l_dest_state = InProgressStateToState();  // LCOV_EXCL_BR_LINE 11: Gcov constraints (because exception-handling routes are automatically generated) // NOLINT(whitespace/line_length)
2376     if (l_dest_state != MODULE_STATE_INVALID) {
2377       for (; l_ModuleListIter != l_GroupIter->second.modules.end(); l_ModuleListIter++) {
2378         if (((l_ModuleListIter->IsModuleState(l_dest_state) == FALSE)  // LCOV_EXCL_BR_START 11:Gcov constraints (because exception-handling routes are automatically generated)
2379             && (l_ModuleListIter->IsModuleState(MODULE_STATE_START_FAILED) == FALSE)
2380             && (l_ModuleListIter->IsModuleState(MODULE_STATE_START_PRE_FAILED) == FALSE)
2381             && (l_ModuleListIter->IsModuleState(MODULE_STATE_STOP_PRE_FAILED) == FALSE)
2382             && (l_ModuleListIter->IsModuleState(MODULE_STATE_START_BACKGROUND_FAILED) == FALSE)
2383             && (l_ModuleListIter->IsModuleState(MODULE_STATE_STOP_BACKGROUND_FAILED) == FALSE)
2384             && (l_ModuleListIter->IsModuleState(MODULE_STATE_STOP_FAILED) == FALSE))
2385             // LCOV_EXCL_BR_STOP 11:Gcov constraints (because exception-handling routes are automatically generated)
2386             || ((l_ModuleListIter->is_start_required == TRUE)
2387                 // LCOV_EXCL_START 6: Because the value cannot be stored to make the condition true
2388                 && ((l_ModuleListIter->IsModuleState(MODULE_STATE_LAUNCHING) == TRUE)
2389                     || (l_ModuleListIter->IsModuleState(MODULE_STATE_CONNECTED) == TRUE)
2390                     || (l_ModuleListIter->IsModuleState(MODULE_STATE_LAUNCHED) == TRUE)))) {
2391                 // LCOV_EXCL_STOP 6: Because the value cannot be stored to make the condition true
2392           l_bIsStarted = FALSE;
2393           FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__, " No: '%s' in group %d/%s is '%s'", l_ModuleListIter->name.c_str(),
2394                  l_GroupIter->second.id, l_GroupIter->second.name.c_str(),
2395                  l_ModuleListIter->ModuleStateStr().c_str());
2396           break;
2397         }
2398       }
2399     }
2400   }
2401   FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-");
2402   return l_bIsStarted;
2403 }  // End of BOOL CSystemManager::IsGroupStarted(UI_32 f_groupId)
2404
2405 BOOL CSystemManager::IsGroupStopped(UI_32 f_groupID) {
2406   FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+");
2407   BOOL l_bIsStopped = TRUE;
2408   ModuleLaunchListIter l_ModuleListIter;
2409
2410   GroupLaunchMapIter l_GroupIter = m_MapProclaunchGrps.find(f_groupID);
2411   if (l_GroupIter == m_MapProclaunchGrps.end()) {
2412     FRAMEWORKUNIFIEDLOG(ZONE_WARN, __FUNCTION__,
2413         " Warning: Group Map Empty; was looking for group %d",
2414         f_groupID);
2415   } else {
2416     for (l_ModuleListIter = l_GroupIter->second.modules.begin();
2417         l_bIsStopped
2418             && l_ModuleListIter != l_GroupIter->second.modules.end();
2419         l_ModuleListIter++) {
2420       if (l_ModuleListIter->IsModuleState(MODULE_STATE_STOP_SENT)) {
2421         l_bIsStopped = FALSE;
2422       }
2423     }
2424   }
2425   FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-");
2426   return l_bIsStopped;
2427 }  // End of BOOL CSystemManager::IsGroupStopped(UI_32 f_groupId)
2428
2429 ///////////////////////////////////////////////////////////////////////////////
2430 /// \ingroup OnStopComplete
2431 /// Shutdown complete Response\Ack Handlers
2432 ///
2433 /// \param [in]
2434 ///
2435 ///
2436 /// \return EFrameworkunifiedStatus
2437 /// Success ==> eFrameworkunifiedStatusOK
2438 /// Failure ==> Other values
2439 ///////////////////////////////////////////////////////////////////////////////
2440 EFrameworkunifiedStatus CSystemManager::OnModuleStopCompleteResponse(HANDLE hApp) {
2441   FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+");
2442   EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusErrOther;
2443   INTERFACEUNIFIEDLOG_RECEIVED_FROM(hApp);  // LCOV_EXCL_BR_LINE 15: marco defined in ns_logger_if.h  // NOLINT(whitespace/line_length)
2444
2445   PCSTR l_moduleName = FrameworkunifiedGetMsgSrc(hApp);
2446
2447   FRAMEWORKUNIFIEDLOG(ZONE_PERFORMANCE, __FUNCTION__, "from %s", l_moduleName);
2448   SetCmdHist("SS_SM_STOP_COMPL_RSPN", m_SMCmdHist, m_SMHistIter, l_moduleName);
2449
2450   char l_cBuf[100];
2451   snprintf(l_cBuf, sizeof(l_cBuf), "ProcessModuleStopCompleteResponse(%s)", l_moduleName);
2452   l_eStatus = ProcessModuleStopCompleteResponse(hApp, l_moduleName);
2453   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)
2454
2455   FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-");
2456   return l_eStatus;
2457 }  // End of EFrameworkunifiedStatus CSystemManager::OnModuleStopCompleteResponse( HANDLE hApp )
2458
2459 ///////////////////////////////////////////////////////////////////////////////
2460 /// \ingroup OnGetStartExtInfo
2461 ///
2462 /// \param [in]
2463 ///
2464 ///
2465 /// \return EFrameworkunifiedStatus
2466 /// Success ==> eFrameworkunifiedStatusOK
2467 /// Failure ==> Other values
2468 ///////////////////////////////////////////////////////////////////////////////
2469 EFrameworkunifiedStatus CSystemManager::OnGetStartExtInfo(HANDLE hApp) {
2470   EFrameworkunifiedStatus l_eStatus;
2471   T_SS_SM_START_ExtDataStructType l_extInfo = { 0 };
2472
2473   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)
2474
2475   FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+ ");
2476
2477   SetCmdHist("SS_SM_GET_START_EXT_INFO", m_SMCmdHist, m_SMHistIter, FrameworkunifiedGetMsgSrc(hApp));
2478
2479   l_extInfo.isProgUpdated =
2480       (m_ProgUpdateState & SS_SM_PROG_UPDATE_STATE_UPDATED) ? TRUE : FALSE;
2481   l_extInfo.isMapUpdated =
2482       (m_ProgUpdateState & SS_SM_PROG_UPDATE_STATE_MAP_UPDATED) ? TRUE : FALSE;  // LCOV_EXCL_BR_LINE 11:unexpected branch  // NOLINT(whitespace/line_length)
2483   l_extInfo.isMapDiffUpdated =
2484       (m_ProgUpdateState & SS_SM_PROG_UPDATE_STATE_MAPDIFF_UPDATED) ? TRUE : FALSE;  // LCOV_EXCL_BR_LINE 11:unexpected branch  // NOLINT(whitespace/line_length)
2485
2486   ModuleLaunchListIter l_ModuleListIter;
2487
2488   l_eStatus = GetModuleIterator(FrameworkunifiedGetMsgSrc(hApp), l_ModuleListIter);
2489   if (eFrameworkunifiedStatusOK != l_eStatus) {
2490     FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, " Error: %s not found", FrameworkunifiedGetMsgSrc(hApp));
2491   } else {
2492     switch (l_ModuleListIter->relaunch_status) {
2493     case NotRelaunched:
2494       l_extInfo.relaunchStatus = e_SS_SM_RELAUNCH_STATUS_NONE;
2495       break;
2496     case RelaunchSafe:
2497       // LCOV_EXCL_START 6: Because the applicable variable cannot be changed from the external API (only evaluated by the initial value)
2498       AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
2499       l_extInfo.relaunchStatus = e_SS_SM_RELAUNCH_STATUS_SAFE;
2500       break;
2501     case RelaunchErr:
2502       AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
2503       l_extInfo.relaunchStatus = e_SS_SM_RELAUNCH_STATUS_ERR;
2504       break;
2505     default:
2506       AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
2507       SS_ASERT(0);  // LCOV_EXCL_BR_LINE 15: marco defined in ss_templates.h  // NOLINT(whitespace/line_length)
2508       l_extInfo.relaunchStatus = e_SS_SM_RELAUNCH_STATUS_NONE;
2509       break;
2510       // LCOV_EXCL_STOP
2511     }
2512   }
2513
2514   // Instead of sending Return Message, this function must call FrameworkunifiedSetSyncResponseData()
2515   // because this request is sent by FrameworkunifiedInvokeSync()
2516   l_eStatus = FrameworkunifiedSetSyncResponseData(hApp, &l_extInfo, sizeof(l_extInfo));
2517   LOG_STATUS_IF_ERRORED(l_eStatus, "FrameworkunifiedSetSyncResponseData()");  // LCOV_EXCL_BR_LINE 15: marco defined in ss_templates.h  // NOLINT(whitespace/line_length)
2518
2519   FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-");
2520   return l_eStatus;
2521 }  // End of EFrameworkunifiedStatus CSystemManager::OnGetStartExtInfo( HANDLE hApp )
2522
2523 ///////////////////////////////////////////////////////////////////////////////
2524 /// \ingroup OnGetStopExtInfo
2525 ///
2526 /// \param [in]
2527 ///
2528 ///
2529 /// \return EFrameworkunifiedStatus
2530 /// Success ==> eFrameworkunifiedStatusOK
2531 /// Failure ==> Other values
2532 ///////////////////////////////////////////////////////////////////////////////
2533 EFrameworkunifiedStatus CSystemManager::OnGetStopExtInfo(HANDLE hApp) {
2534   EFrameworkunifiedStatus l_eStatus;
2535   T_SS_SM_STOP_ExtDataStructType l_extInfo = { 0 };
2536
2537   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)
2538
2539   FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+ ");
2540
2541   SetCmdHist("SS_SM_GET_STOP_EXT_INFO", m_SMCmdHist, m_SMHistIter, FrameworkunifiedGetMsgSrc(hApp));
2542
2543   l_extInfo.isProgUpdated =
2544       (m_ProgUpdateState & SS_SM_PROG_UPDATE_STATE_UPDATED) ? TRUE : FALSE;
2545
2546   // Instead of sending Return Message, this function must call FrameworkunifiedSetSyncResponseData()
2547   // because this request is sent by FrameworkunifiedInvokeSync()
2548   l_eStatus = FrameworkunifiedSetSyncResponseData(hApp, &l_extInfo, sizeof(l_extInfo));
2549   LOG_STATUS_IF_ERRORED(l_eStatus, "FrameworkunifiedSetSyncResponseData()");  // LCOV_EXCL_BR_LINE 15: marco defined in ss_templates.h  // NOLINT(whitespace/line_length)
2550
2551   FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-");
2552   return l_eStatus;
2553 }  // End of EFrameworkunifiedStatus CSystemManager::OnGetStopExtInfo( HANDLE hApp )
2554
2555 ///////////////////////////////////////////////////////////////////////////////
2556 /// \ingroup OnModuleStopCompleteNotification
2557 ///
2558 /// \param [in]
2559 ///
2560 ///
2561 /// \return EFrameworkunifiedStatus
2562 /// Success ==> eFrameworkunifiedStatusOK
2563 /// Failure ==> Other values
2564 ///////////////////////////////////////////////////////////////////////////////
2565 EFrameworkunifiedStatus CSystemManager::OnModuleStopCompleteNotification(HANDLE hApp) {  // LCOV_EXCL_START 6: Because the condition cannot be set
2566   AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
2567   EFrameworkunifiedStatus l_eStatus;
2568
2569   FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+ ");
2570   INTERFACEUNIFIEDLOG_RECEIVED_FROM(hApp);  // LCOV_EXCL_BR_LINE 15: marco defined in ns_logger_if.h  // NOLINT(whitespace/line_length)
2571   FRAMEWORKUNIFIEDLOG(ZONE_PERFORMANCE, __FUNCTION__, "from %s", FrameworkunifiedGetMsgSrc(hApp));
2572
2573   ShutdownComplete l_shutdownNotif;   /// \file   frameworkunified_framework_types.h
2574   // ReadMsg():                                                      *
2575   //   Check hApp ptr, msg size, msg reception, read msg if all ok.  *
2576   //   Report any errors found.                                      *
2577   //                                                                 *
2578   if (eFrameworkunifiedStatusOK != (l_eStatus = ReadMsg < ShutdownComplete > (hApp, l_shutdownNotif))) {
2579     LOG_ERROR("ReadMsg()");  // LCOV_EXCL_BR_LINE 15: marco defined in ss_templates.h  // NOLINT(whitespace/line_length)
2580   } else {
2581     PCSTR l_moduleName = l_shutdownNotif.cServiceName;
2582     FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__,
2583         " '%s' 'Shutdown Complete Status' is 0x%X", l_moduleName,
2584         l_shutdownNotif.eShutdownCompleteStatus);
2585
2586     char l_cBuf[100];
2587     snprintf(l_cBuf, sizeof(l_cBuf),
2588         "ProcessModuleStopCompleteResponse(%s)", l_moduleName);
2589     l_eStatus = ProcessModuleStopCompleteResponse(hApp, l_moduleName);
2590     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)
2591   }
2592
2593   FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-");
2594   return l_eStatus;
2595 }  // End of EFrameworkunifiedStatus CSystemManager::onmodulestopcompletenotification( HANDLE hApp )
2596 // LCOV_EXCL_STOP
2597
2598 EFrameworkunifiedStatus CSystemManager::ProcessModuleStopCompleteResponse(HANDLE hApp, PCSTR f_moduleName) {
2599   FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+");
2600   EFrameworkunifiedStatus l_eStatus;
2601
2602   ModuleLaunchListIter l_ModuleListIter;
2603   l_eStatus = GetModuleIterator(f_moduleName, l_ModuleListIter);
2604   if (eFrameworkunifiedStatusOK != l_eStatus) {
2605     FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, " Error: Module %s not found in Group Launch Map", f_moduleName);
2606   } else {
2607     switch (m_SMCurrentState) {
2608     case SS_SM_READY_TO_LAUNCH_APP:
2609     case SS_SM_APPS_LAUNCH_IN_PROGRESS:
2610     case SS_SM_APPS_LAUNCHED_READY_TO_START:
2611       FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__,
2612           " Error: Received from client while in "
2613           "the '%s' state !!!",
2614           GetStr(m_SMCurrentState).c_str());
2615       l_eStatus = eFrameworkunifiedStatusErrOther;
2616       break;
2617
2618     case SS_SM_APPS_STOPPING_AT__CWORD56__REQ:
2619     case SS_SM_APPS_STOPPING_AT_INTERNAL_REQ:
2620     case SS_SM_WAITING_FOR_CRITICAL_APPS_AT__CWORD56__REQ:
2621     case SS_SM_WAITING_FOR_CRITICAL_APPS_AT_INTERNAL_REQ:
2622       if (m_SystemStarter.get_id() == SS_SM_THIRD_GROUP) {
2623         // Execute shutdown_critical services termination synchronization prior to CoreModule(backupManager termination processing
2624         l_ModuleListIter->SetModuleState(MODULE_STATE_STOPPED);
2625         if (have_critical_services_stopped()) {  // Transition after all critical services have ended
2626           ProcessGroupOnModuleStopResponse(hApp, m_SystemStarter.get_id());
2627         }
2628       } else {
2629         l_eStatus = ModuleCompleteResponse(hApp, l_ModuleListIter,
2630                 MODULE_STATE_STOPPED,
2631                 (SysMgrCbType3<CSystemManager,
2632                     &CSystemManager::IsGroupStopped>),
2633                 (SysMgrCbType2<CSystemManager,
2634                     &CSystemManager::ProcessGroupOnModuleStopResponse>),
2635                 "stop");
2636       }
2637       break;
2638
2639     case SS_SM_APPS_START_COMPLETE:
2640     case SS_SM_APPS_START_IN_PROGRESS:
2641     case SS_SM_APPS_PRE_RUN_COMPLETE:
2642     case SS_SM_APPS_PRE_START_IN_PROGRESS:
2643     case SS_SM_APPS_PRE_STOP_IN_PROGRESS:
2644     case SS_SM_APPS_BACKGROUND_RUN_COMPLETE:
2645     case SS_SM_APPS_BACKGROUND_START_IN_PROGRESS:
2646     case SS_SM_APPS_BACKGROUND_STOP_IN_PROGRESS:
2647       FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__,
2648           " Error: Received from client while in "
2649           "the '%s' state !!!",
2650           GetStr(m_SMCurrentState).c_str());
2651       l_eStatus = eFrameworkunifiedStatusErrOther;
2652       break;
2653     }  // End switch ( m_SMCurrentState )
2654   }
2655
2656   FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-");
2657   return l_eStatus;
2658 }  // End of EFrameworkunifiedStatus CSystemManager::ProcessModuleStopCompleteResponse(
2659
2660 EFrameworkunifiedStatus CSystemManager::ProcessGroupOnModuleStopResponse(HANDLE hApp, UI_32 f_groupID) {
2661   EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK;
2662   FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+");
2663   UI_32 l_ActiveGroupId = m_SystemStarter.get_id();
2664
2665   m_GroupLaunchTimer->StopTimer(m_aTimerIDs[eSM_TIMER_CLIENT_STOP_MONITOR]);
2666
2667   if (f_groupID != l_ActiveGroupId) {
2668     FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__,
2669         " Group %d stop complete, but m_SystemStarter.get_id() is %d",
2670         f_groupID
2671         // , m_ActiveGroupId);  // LCOV_EXCL_BR_LINE 15: marco defined in ns_logger_if.h  // NOLINT(whitespace/line_length)
2672         , l_ActiveGroupId);
2673   } else {
2674     if (!m_SystemStarter.is_begin()) {
2675       m_SystemStarter.decrement_id();
2676     }
2677     check_all_groups_have_stopped(hApp);
2678   }
2679   FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-");
2680   return l_eStatus;
2681 }  // End of EFrameworkunifiedStatus CSystemManager::ProcessGroupOnModuleStopResponse( HANDLE hApp
2682
2683 ///////////////////////////////////////////////////////////////////////////////
2684 /// \ingroup stop_all_modules_of_group
2685 /// Send SS_SM_STOP to all modules of the given group
2686 ///
2687 /// \param [in]
2688 ///
2689 ///
2690 /// \return VOID
2691 ///////////////////////////////////////////////////////////////////////////////
2692 EFrameworkunifiedStatus CSystemManager::stop_all_modules_of_group(HANDLE hApp) {
2693   FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+");
2694   EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK;
2695   ModuleLaunchList::reverse_iterator l_revIter;
2696
2697   UI_32 l_uiMaxGroupWaitTime_sec = 0;
2698   UI_32 l_uiMaxGroupWaitTime_msec = 0;
2699   UI_32 l_uiModuleWaitTime = 0;
2700
2701   // GroupLaunchMapIter l_GroupIterator = m_MapProclaunchGrps.find(m_ActiveGroupId);
2702   GroupLaunchMapIter l_GroupIterator = m_MapProclaunchGrps.find(m_SystemStarter.get_id());
2703   if (l_GroupIterator == m_MapProclaunchGrps.end()) {
2704     FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__,
2705         " Error: Group %d not found; 'm_MapProclaunchGrps' is empty"
2706         //, m_ActiveGroupId);  // LCOV_EXCL_BR_LINE 15: marco defined in ns_logger_if.h  // NOLINT(whitespace/line_length)
2707         , m_SystemStarter.get_id());
2708     l_eStatus = eFrameworkunifiedStatusDbRecNotFound;
2709   } else {
2710     int l_numModulesMessaged = 0;
2711     FRAMEWORKUNIFIEDLOG(ZONE_STATE, __FUNCTION__, "StopReq grp:%d", m_SystemStarter.get_id());
2712
2713     T_SS_SM_STOP_DataStructType l_SM_STOP_Struct;
2714     l_SM_STOP_Struct.shutdownTrigger = m_shutdownTrigger;
2715     l_SM_STOP_Struct.lastUserMode = m_lastUserMode;
2716
2717     for (l_revIter = l_GroupIterator->second.modules.rbegin();
2718         l_revIter != l_GroupIterator->second.modules.rend();
2719         l_revIter++) {
2720       // LCOV_EXCL_BR_START 11: Excluded due to gcov constraints (others)
2721       if ((l_revIter->IsModuleState(MODULE_STATE_START_SENT) == TRUE)
2722           || (l_revIter->IsModuleState(MODULE_STATE_STARTED) == TRUE)
2723           || (l_revIter->IsModuleState(MODULE_STATE_START_PRE_SENT) == TRUE)
2724           || (l_revIter->IsModuleState(MODULE_STATE_STARTED_PRE) == TRUE)
2725           || (l_revIter->IsModuleState(MODULE_STATE_STOP_PRE_SENT) == TRUE)
2726           || (l_revIter->IsModuleState(MODULE_STATE_STOPPED_PRE) == TRUE)
2727           || (l_revIter->IsModuleState(MODULE_STATE_START_BACKGROUND_SENT) == TRUE)
2728           || (l_revIter->IsModuleState(MODULE_STATE_STARTED_BACKGROUND) == TRUE)
2729           || (l_revIter->IsModuleState(MODULE_STATE_STOP_BACKGROUND_SENT) == TRUE)
2730           || (l_revIter->IsModuleState(MODULE_STATE_STOPPED_BACKGROUND) == TRUE)) {
2731         // LCOV_EXCL_BR_STOP 11: Excluded due to gcov constraints (others)
2732         if (FRAMEWORKUNIFIED_NS_NPSERVICE == l_revIter->name) {
2733           if (epssdmsdtFACTORY_DATA_RESET == m_shutdownTrigger) {
2734             CALL_AND_LOG_STATUS(FrameworkunifiedSendStopToNSNPP(hApp, eFrameworkunifiedDataResetShutdown, eFrameworkunifiedUserData | eFrameworkunifiedFactoryData));  // LCOV_EXCL_BR_LINE 15: marco defined in ss_templates.h  // NOLINT(whitespace/line_length)
2735           } else if (epssdmsdtUSER_DATA_RESET == m_shutdownTrigger) {
2736             CALL_AND_LOG_STATUS(FrameworkunifiedSendStopToNSNPP(hApp, eFrameworkunifiedDataResetShutdown, eFrameworkunifiedUserData));  // LCOV_EXCL_BR_LINE 15: marco defined in ss_templates.h  // NOLINT(whitespace/line_length)
2737           } else if (epssdmsdtFAST_SLEEP_MODE == m_shutdownTrigger) {
2738             CALL_AND_LOG_STATUS(FrameworkunifiedSendStopToNSNPP(hApp, eFrameworkunifiedQuickShutdown));  // LCOV_EXCL_BR_LINE 15: marco defined in ss_templates.h  // NOLINT(whitespace/line_length)
2739           } else {
2740             CALL_AND_LOG_STATUS(FrameworkunifiedSendStopToNSNPP(hApp, eFrameworkunifiedNormalShutdown));  // LCOV_EXCL_BR_LINE 15: marco defined in ss_templates.h  // NOLINT(whitespace/line_length)
2741           }
2742
2743           if (eFrameworkunifiedStatusOK != l_eStatus) {
2744             l_revIter->SetModuleState(MODULE_STATE_STOP_FAILED);
2745           } else {
2746             l_revIter->SetModuleState(MODULE_STATE_STOP_SENT);
2747             l_numModulesMessaged++;
2748           }
2749
2750           m_NPPStopSent = TRUE;
2751           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)
2752         // End else if ( FRAMEWORKUNIFIED_NS_NPSERVICE == l_ModuleListIter->name )
2753         } else {
2754           l_eStatus = l_revIter->SendMsgAndUpdateState(&l_SM_STOP_Struct);
2755           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)
2756           if (eFrameworkunifiedStatusOK == l_eStatus) {
2757             if (epssdmsdtFAST_SLEEP_MODE == m_shutdownTrigger) {
2758               l_uiModuleWaitTime = l_revIter->fast_shutdown_wait_time;
2759
2760             } else {
2761               l_uiModuleWaitTime = l_revIter->shutdown_wait_time;
2762             }
2763             if (l_uiModuleWaitTime > l_uiMaxGroupWaitTime_sec) {
2764               l_uiMaxGroupWaitTime_sec = l_uiModuleWaitTime;
2765             }
2766             l_numModulesMessaged++;
2767           }
2768         }  // End if MODULE_STATE_STARTED || MODULE_STATE_START_SENT
2769       } else if (l_revIter->IsModuleState(MODULE_STATE_INVALID)
2770           && FRAMEWORKUNIFIED_NS_NPSERVICE == l_revIter->name) {
2771         m_NPPStopSent = TRUE;
2772         FRAMEWORKUNIFIEDLOG(ZONE_STATE, __FUNCTION__, "StopNotSent:%s is INVALID", FRAMEWORKUNIFIED_NS_NPSERVICE);
2773       } else {
2774         FRAMEWORKUNIFIEDLOG(ZONE_STATE, __FUNCTION__, "StopNotSent:%s is %s",
2775             l_revIter->name.c_str(),
2776             l_revIter->ModuleStateStr().c_str());
2777       }
2778     }
2779
2780     if (0 == l_numModulesMessaged) {
2781       LogGroupModulesState(m_SystemStarter.get_id()  // m_ActiveGroupId  // LCOV_EXCL_BR_LINE 11:unexpected branch  // NOLINT(whitespace/line_length)
2782           , " Warning: NO modules were sent SS_SM_STOP");
2783
2784       FRAMEWORKUNIFIEDLOG(ZONE_STATE, __FUNCTION__, "StopComp grp:%d", l_GroupIterator->second.id);
2785
2786       if (m_SystemStarter.get_id() > SS_SM_INITIAL_GROUP) {
2787         m_SystemStarter.decrement_id();
2788         FRAMEWORKUNIFIEDLOG(ZONE_STATE, __FUNCTION__, " m_ActiveGroupId is now %d", m_SystemStarter.get_id());
2789
2790         check_all_groups_have_stopped(hApp);
2791       }
2792     } else {
2793       if (epssdmsdtFAST_SLEEP_MODE == m_shutdownTrigger) {
2794         // fast shutdown wait time always comes in milli seconds
2795         UI_32 l_uiTotalWaitTime = l_uiMaxGroupWaitTime_sec;
2796         l_uiMaxGroupWaitTime_sec = l_uiTotalWaitTime / 1000;
2797         l_uiMaxGroupWaitTime_msec = l_uiTotalWaitTime % 1000;
2798       } else {
2799         // Other types of shutdown except fast shutdown always comes in seconds.
2800         l_uiMaxGroupWaitTime_msec = 0;
2801       }
2802
2803       FRAMEWORKUNIFIEDLOG(ZONE_STATE, __FUNCTION__, "StopTimer grp:%d time:%d.%d",
2804           m_SystemStarter.get_id(), l_uiMaxGroupWaitTime_sec,
2805           l_uiMaxGroupWaitTime_msec);
2806       m_GroupLaunchTimer->StartTimerMulti(
2807           m_aTimerIDs[eSM_TIMER_CLIENT_STOP_MONITOR],
2808           l_uiMaxGroupWaitTime_sec, l_uiMaxGroupWaitTime_msec, 0, 0,
2809           m_SystemStarter.get_id());
2810     }
2811   }
2812   FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-");
2813   return l_eStatus;
2814 }  // End of VOID CSystemManager::stop_all_modules_of_group(HANDLE hApp)
2815
2816 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)
2817   AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
2818   FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+");
2819   EFrameworkunifiedStatus l_eStatus;
2820   Pwr_ServiceSetInterface tServiceSetIf;
2821   EPWR_USER_MODE_TYPE l_my_eUserModeState;
2822
2823   // ReadMsg():                                                          *
2824   //   Check hApp ptr, msg size, msg reception, read msg if all ok.      *
2825   if (eFrameworkunifiedStatusOK != (l_eStatus = ReadMsg < Pwr_ServiceSetInterface > (hApp, tServiceSetIf))) {
2826     LOG_ERROR("ReadMsg()");  // LCOV_EXCL_BR_LINE 15: marco defined in ss_templates.h  // NOLINT(whitespace/line_length)
2827   } else {
2828     l_my_eUserModeState = tServiceSetIf.data.user_mode.mode;
2829     switch (l_my_eUserModeState) {
2830     case epsumINVALID:
2831       FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, " Error: l_eUserModeState == epsumINVALID");
2832       l_eStatus = eFrameworkunifiedStatusInvldParam;
2833       break;
2834
2835     case epsumOFF:
2836     case epsumON:
2837       FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__, " Validated '%s'",
2838           l_my_eUserModeState == epsumON ? "epsumON" : "epsumOFF");
2839       l_eUserModeState = l_my_eUserModeState;
2840       l_eStatus = eFrameworkunifiedStatusOK;
2841       break;
2842
2843       // default:  Don't code a 'default' here - let the compiler
2844       // issue a warning ( set via -Wall or -Wswitch ) when the set of
2845       // enumerations changes - then the maintainer will
2846       // automagically know to update this switch statement.
2847     }  // End switch
2848   }
2849   FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-");
2850   return l_eStatus;
2851 }  // End of EFrameworkunifiedStatus CSystemManager::ValidateUserModeMessage( HANDLE hApp, EPWR_USER_MODE_TYPE &l_eUserModeState )
2852 // LCOV_EXCL_STOP
2853
2854 //*****************************************************************************
2855 // Next Wakeup Type Set Protocol functions                                    *
2856 //                                                                            *
2857 EFrameworkunifiedStatus CSystemManager::OnSetNextWakeupTypeRequest(HANDLE hApp) {
2858   FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+");
2859   EFrameworkunifiedStatus l_eStatus;
2860   ESMNextWakeupType l_wakeupType;
2861
2862   INTERFACEUNIFIEDLOG_RECEIVED_FROM(hApp);  // LCOV_EXCL_BR_LINE 15: marco defined in ns_logger_if.h  // NOLINT(whitespace/line_length)
2863   FRAMEWORKUNIFIEDLOG(ZONE_STATE, __FUNCTION__, "from %s", FrameworkunifiedGetMsgSrc(hApp));
2864   SetCmdHist("SS_SM_NEXT_WAKEUP_TYPE_SET_REQ", m_SMCmdHist, m_SMHistIter, FrameworkunifiedGetMsgSrc(hApp));
2865
2866   if (eFrameworkunifiedStatusOK != (l_eStatus = ReadMsg < ESMNextWakeupType > (hApp, l_wakeupType))) {
2867     LOG_ERROR("ReadMsg()");  // LCOV_EXCL_BR_LINE 15: marco defined in ss_templates.h  // NOLINT(whitespace/line_length)
2868   } else {
2869     switch (l_wakeupType) {
2870     case e_SS_SM_NEXT_WAKEUP_TYPE_NONE:
2871     case e_SS_SM_NEXT_WAKEUP_TYPE_COLD:
2872     case e_SS_SM_NEXT_WAKEUP_TYPE_HOT:
2873       break;
2874     default:
2875       FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "unknown type(%d)", l_wakeupType);
2876       l_eStatus = eFrameworkunifiedStatusInvldParam;
2877     }
2878   }
2879   l_eStatus = FrameworkunifiedSetSyncResponseData(hApp, &l_eStatus, sizeof(l_eStatus));
2880   LOG_STATUS_IF_ERRORED(l_eStatus, "FrameworkunifiedSetSyncResponseData()");  // LCOV_EXCL_BR_LINE 15: marco defined in ss_templates.h  // NOLINT(whitespace/line_length)
2881
2882   FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-");
2883   return l_eStatus;
2884 }  // End of EFrameworkunifiedStatus CSystemManager::OnSetNextWakeupTypeRequest( HANDLE hApp )
2885
2886 //                                                                            *
2887 // End of Boot Mode Protocol functions                                        *
2888 //*****************************************************************************
2889
2890
2891 //*****************************************************************************
2892 // Data Reset Mode Protocol functions                                         *
2893 //                                                                            *
2894 EFrameworkunifiedStatus CSystemManager::OnSetDataResetModeRequest(HANDLE hApp) {
2895   FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+");
2896   EFrameworkunifiedStatus l_eStatus;
2897   ESMDataResetModeInfo l_dataResetMode;
2898   INTERFACEUNIFIEDLOG_RECEIVED_FROM(hApp);  // LCOV_EXCL_BR_LINE 15: marco defined in ns_logger_if.h  // NOLINT(whitespace/line_length)
2899   FRAMEWORKUNIFIEDLOG(ZONE_STATE, __FUNCTION__, "from %s", FrameworkunifiedGetMsgSrc(hApp));
2900
2901   SetCmdHist("SS_SM_DATA_RESET_MODE_SET_REQ", m_SMCmdHist, m_SMHistIter, FrameworkunifiedGetMsgSrc(hApp));
2902
2903   if (eFrameworkunifiedStatusOK != (l_eStatus = ReadMsg < ESMDataResetModeInfo > (hApp, l_dataResetMode))) {
2904     LOG_ERROR("ReadMsg()");  // LCOV_EXCL_BR_LINE 15: marco defined in ss_templates.h  // NOLINT(whitespace/line_length)
2905   } else {
2906     uint32_t tmp;
2907     m_DataResetMode = l_dataResetMode;
2908     tmp = static_cast<uint32_t>(m_DataResetMode);
2909     if (PowerHalSetResetInfo(AGL_DATARESET_STATE, tmp)) {  // LCOV_EXCL_BR_LINE 11:Gcov constraints (because exception-handling routes are automatically generated)
2910       FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "Could not set AGL_DATARESET_STATE.");
2911       // Return error to client of system_manager.
2912       l_eStatus = eFrameworkunifiedStatusFail;
2913     }
2914   }
2915   //
2916   // Instead of sending Return Message, this function must call FrameworkunifiedSetSyncResponseData()
2917   // because this request is sent by FrameworkunifiedInvokeSync()
2918   //
2919   l_eStatus = FrameworkunifiedSetSyncResponseData(hApp, &l_eStatus, sizeof(l_eStatus));
2920   LOG_STATUS_IF_ERRORED(l_eStatus, "FrameworkunifiedSetSyncResponseData()");  // LCOV_EXCL_BR_LINE 15: marco defined in ss_templates.h  // NOLINT(whitespace/line_length)
2921
2922   FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-");
2923   return l_eStatus;
2924 }  // End of EFrameworkunifiedStatus CSystemManager::OnSetDataResetModeRequest( HANDLE hApp )
2925
2926 EFrameworkunifiedStatus CSystemManager::OnSetProgUpdateStateRequest(HANDLE hApp) {
2927   EFrameworkunifiedStatus l_eStatus;
2928   SMProgUpdateState l_progUpdateState;
2929
2930   FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+");
2931   FRAMEWORKUNIFIEDLOG(ZONE_STATE, __FUNCTION__, "from %s", FrameworkunifiedGetMsgSrc(hApp));
2932
2933   SetCmdHist("SS_SM_PROG_UPDATE_STATE_SET_REQ", m_SMCmdHist, m_SMHistIter, FrameworkunifiedGetMsgSrc(hApp));
2934
2935   if (eFrameworkunifiedStatusOK != (l_eStatus = ReadMsg < SMProgUpdateState > (hApp, l_progUpdateState))) {  // LCOV_EXCL_BR_LINE 4: nsfw error
2936     // LCOV_EXCL_START 4: nsfw error
2937     AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
2938     LOG_ERROR("ReadMsg()");  // LCOV_EXCL_BR_LINE 15: marco defined in ss_templates.h  // NOLINT(whitespace/line_length)
2939     // LCOV_EXCL_STOP
2940   } else {
2941     m_ProgUpdateState |= l_progUpdateState;
2942     if (PowerHalSetResetInfo(AGL_PROGUPDATE_STATE, m_ProgUpdateState)) {  // LCOV_EXCL_BR_LINE 11:Gcov constraints (because exception-handling routes are automatically generated)
2943       FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "Could not set AGL_PROGUPDATE_STATE.");
2944       // return Error to client of system_manager.
2945       l_eStatus = eFrameworkunifiedStatusFail;
2946     }
2947   }
2948   // Instead of sending Return Message, this function must call FrameworkunifiedSetSyncResponseData()
2949   // because this request is sent by FrameworkunifiedInvokeSync()
2950   l_eStatus = FrameworkunifiedSetSyncResponseData(hApp, &l_eStatus, sizeof(l_eStatus));
2951   LOG_STATUS_IF_ERRORED(l_eStatus, "FrameworkunifiedSetSyncResponseData()");  // LCOV_EXCL_BR_LINE 15: marco defined in ss_templates.h  // NOLINT(whitespace/line_length)
2952
2953   FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-");
2954   return l_eStatus;
2955 }  // End of EFrameworkunifiedStatus CSystemManager::OnSetProgUpdateStateRequest( HANDLE hApp )
2956
2957 EFrameworkunifiedStatus CSystemManager::CallStopCompleteHandler(HANDLE hApp, BOOL bIsDetectTimeout /* = FALSE */) {
2958   FRAMEWORKUNIFIEDLOG(ZONE_STATE, __FUNCTION__, "+");
2959   EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK;
2960
2961
2962   if (bIsDetectTimeout) {
2963     fprintf(stderr, "SS_SysManager/%s/State StopComplete(timeout)\n", __FUNCTION__);
2964   } else {
2965     fprintf(stderr, "SS_SysManager/%s/State StopComplete\n", __FUNCTION__);
2966   }
2967
2968   l_eStatus = SecureChipOff();
2969   if (eFrameworkunifiedStatusOK != l_eStatus) {
2970     FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "Error: SecureChipOff Failed");
2971   }
2972
2973   l_eStatus = (*m_pfStopCompleteHandler)(hApp);
2974
2975   FRAMEWORKUNIFIEDLOG(ZONE_STATE, __FUNCTION__, "-");
2976   return l_eStatus;
2977 }  // End of EFrameworkunifiedStatus CSystemManager::CallStopCompleteHandler( HANDLE hApp )
2978
2979
2980 //*****************************************************************************
2981 // Soft Reset Protocol functions                                              *
2982 //                                                                            *
2983 static char *get_line(const char *filepath) {
2984   char line[LINE_MAX];
2985   FILE *fp;
2986
2987   if ((fp = fopen(filepath, "rb")) == NULL)
2988     return NULL;
2989   if (fgets(line, LINE_MAX, fp) == NULL) {  // LCOV_EXCL_BR_LINE 5:fgets error
2990     // LCOV_EXCL_START 5: fgets error
2991     AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
2992     fclose(fp);
2993     return NULL;
2994     // LCOV_EXCL_STOP
2995   }
2996   fclose(fp);
2997
2998   return strdup(line);
2999 }
3000
3001 EFrameworkunifiedStatus CSystemManager::PerformCpuReset(HANDLE hApp,
3002         ESMCpuResetReason f_eSmCpuResetReason, std::string f_messageStr) {
3003   FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+");
3004   EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK;
3005   if (FALSE == m_isRcvModeInfo) {
3006     // If the condition for implementing the CpuReset request is not satisfied, keep the request.
3007     FRAMEWORKUNIFIEDLOG(ZONE_STATE, __FUNCTION__, "Cpu Reset Pending");
3008     m_isRstPending = TRUE;
3009     m_rstPendingInfo.resetReason = f_eSmCpuResetReason;
3010     snprintf(m_rstPendingInfo.messageStr,
3011         sizeof(m_rstPendingInfo.messageStr), "%s", f_messageStr.c_str());
3012   } else {
3013     switch (f_eSmCpuResetReason) {
3014     case e_SS_SM_CPU_RESET_REASON_CRITICAL_ERR:
3015     case e_SS_SM_CPU_RESET_REASON_GENERIC_ERR:
3016     case e_SS_SM_CPU_RESET_REASON_DSP_ERR:
3017       m_isImmResetReq = TRUE;
3018       FRAMEWORKUNIFIEDLOG(ZONE_STATE, __FUNCTION__, " will reset immediately");
3019       // The break is omitted because the same process as for a normal reboot is performed.
3020     case e_SS_SM_CPU_RESET_REASON_USER_FORCE_RESET:
3021       m_pfStopCompleteHandler = (SysMgrCallback<CSystemManager, &CSystemManager::perform_force_reset>);
3022     case e_SS_SM_CPU_RESET_REASON_NORMAL: {
3023         TSystemManagerCpuResetInfo l_resetInfo;
3024
3025         l_resetInfo.resetReason = f_eSmCpuResetReason;
3026         snprintf(l_resetInfo.messageStr, SS_SM_RESET_MSG_STR_SIZE, "%s", f_messageStr.c_str());
3027         l_eStatus = FrameworkunifiedSendMsg(m_hPowerServiceSession, SS_SM_CPU_RESET_REQ,
3028             sizeof(l_resetInfo), (PVOID) & l_resetInfo);
3029         LOG_STATUS(l_eStatus,  // LCOV_EXCL_BR_LINE 6: Because the condition cannot be set
3030             "FrameworkunifiedSendMsg(m_hPowerServiceSession, SS_SM_CPU_RESET_REQ)");
3031       }
3032       break;
3033     case e_SS_SM_CPU_RESET_REASON_DATA_RESET: {
3034         ESMDataResetType l_eSmDataResetType;
3035
3036         switch (m_DataResetMode) {
3037         case e_SS_SM_DATA_RESET_MODE_FACTORY:
3038           l_eSmDataResetType = e_SS_SM_DATA_RESET_TYPE_FACTORY;
3039           break;
3040         case e_SS_SM_DATA_RESET_MODE_USER:
3041           l_eSmDataResetType = e_SS_SM_DATA_RESET_TYPE_USER;
3042           l_eStatus = FrameworkunifiedBroadcastEvent(hApp, SS_SM_EVENT_USER_DATA_RESET, NULL, 0);
3043           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)
3044           break;
3045         default:
3046           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)
3047           l_eStatus = eFrameworkunifiedStatusInvldParam;
3048         break;
3049         }
3050         if (l_eStatus == eFrameworkunifiedStatusOK) {
3051           l_eStatus = FrameworkunifiedSendMsg(m_hPowerServiceSession,
3052               SS_SM_REMOTE_DATA_RESET_REQ, sizeof(l_eSmDataResetType),
3053               (PVOID) & l_eSmDataResetType);
3054           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)
3055         }
3056       }
3057       break;
3058     case e_SS_SM_CPU_RESET_REASON_INVALID:
3059     default:
3060       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)
3061           f_eSmCpuResetReason, f_eSmCpuResetReason);
3062       l_eStatus = eFrameworkunifiedStatusInvldParam;
3063       break;
3064     }
3065   }
3066
3067   FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-");
3068   return l_eStatus;
3069 }  // End of EFrameworkunifiedStatus CSystemManager::PerformCpuReset( ESMCpuResetReason f_eSmCpuResetReason )
3070
3071 //*****************************************************************************
3072 // CPU Reset Protocol functions                                               *
3073 //                                                                            *
3074 EFrameworkunifiedStatus CSystemManager::OnCpuResetRequest(HANDLE hApp) {  // SS_SM_CPU_RESET_REQ
3075   FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+");
3076   EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusFail;
3077   std::string l_moduleName = FrameworkunifiedGetMsgSrc(hApp);
3078   INTERFACEUNIFIEDLOG_RECEIVED_FROM(hApp);  // LCOV_EXCL_BR_LINE 15: marco defined in ns_logger_if.h  // NOLINT(whitespace/line_length)
3079   FRAMEWORKUNIFIEDLOG(ZONE_STATE, __FUNCTION__, "from %s", l_moduleName.c_str());
3080
3081   // If you implement FastSleep,
3082   // ShutdownTrigger of FrameworkunifiedOnStop needs to be changed to FAST_SLEEP_MODE,
3083   // and also MaxShutdownTime needs to be changed to CriticalAppsMaxShutdownTimeFastSleep
3084
3085   try {
3086     TSystemManagerCpuResetInfo l_resetInfo;
3087     SetCmdHist("SS_SM_CPU_RESET_REQ", m_SMCmdHist, m_SMHistIter,  // LCOV_EXCL_BR_LINE 11:unexpected branch  // NOLINT(whitespace/line_length)
3088         FrameworkunifiedGetMsgSrc(hApp));  // LCOV_EXCL_BR_LINE 11:unexpected branch  // NOLINT(whitespace/line_length)
3089     if (eFrameworkunifiedStatusOK != (l_eStatus = ReadMsg < TSystemManagerCpuResetInfo > (hApp, l_resetInfo))) {
3090       LOG_ERROR("ReadMsg()");  // LCOV_EXCL_BR_LINE 15: marco defined in ss_templates.h  // NOLINT(whitespace/line_length)
3091     } else {
3092       char l_cBuf[100];
3093       EErrorEventType l_errorEventType;
3094       SMLoggingInfo l_loggingInfo;  // LCOV_EXCL_BR_LINE 11:unexpected branch  // NOLINT(whitespace/line_length)
3095
3096       l_loggingInfo.messageStr = l_resetInfo.messageStr;
3097       l_loggingInfo.suffixStr = l_resetInfo.suffixStr;
3098
3099       FRAMEWORKUNIFIEDLOG(ZONE_STATE, __FUNCTION__,
3100           " CPU Reset Reason: '%d'/'%s' from %s",
3101           l_resetInfo.resetReason,
3102           GetStr(l_resetInfo.resetReason).c_str(),
3103           FrameworkunifiedGetMsgSrc(hApp));
3104
3105       if (e_SS_SM_CPU_RESET_REASON_IMMRESET_NORMAL == l_resetInfo.resetReason) {
3106         m_isImmResetReq = TRUE;
3107         l_resetInfo.resetReason = e_SS_SM_CPU_RESET_REASON_NORMAL;
3108       }
3109       switch (l_resetInfo.resetReason) {
3110       case e_SS_SM_CPU_RESET_REASON_DATA_RESET:
3111         switch (m_DataResetMode) {
3112         case e_SS_SM_DATA_RESET_MODE_FACTORY:
3113         case e_SS_SM_DATA_RESET_MODE_USER:
3114           break;
3115         case e_SS_SM_DATA_RESET_MODE_NONE:
3116         default:
3117           FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "unexpected data reset mode : %d", m_DataResetMode);
3118           throw eFrameworkunifiedStatusInvldParam;
3119         }
3120       case e_SS_SM_CPU_RESET_REASON_CRITICAL_ERR:
3121       case e_SS_SM_CPU_RESET_REASON_GENERIC_ERR:
3122       case e_SS_SM_CPU_RESET_REASON_DSP_ERR:
3123       case e_SS_SM_CPU_RESET_REASON_NORMAL:
3124         l_errorEventType = eErrorEventTypeModuleInvokedResetRequest;
3125         l_loggingInfo.resetReason = l_resetInfo.resetReason;
3126         break;
3127       case e_SS_SM_CPU_RESET_REASON_USER_FORCE_RESET:
3128         // Separate ErrorEventType only for USER_FORCE_RESET, because the logs to be saved differ.
3129         l_errorEventType = eErrorEventTypeUserInvokedUserForceReset;
3130         l_loggingInfo.resetReason = e_SS_SM_CPU_RESET_REASON_USER_FORCE_RESET;
3131         break;
3132       case e_SS_SM_CPU_RESET_REASON_INVALID:
3133       default:
3134         FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__,
3135             " Error: Unknown CPU reset request type: 0x%X/%d",
3136             l_resetInfo.resetReason, l_resetInfo.resetReason);
3137         throw eFrameworkunifiedStatusInvldParam;
3138       }
3139
3140       l_eStatus = ErrorEventEnqueue(hApp, l_errorEventType, l_moduleName,
3141           eErrorEventResetTypeHard, l_loggingInfo);
3142
3143       snprintf(l_cBuf, sizeof(l_cBuf), "ErrorEventEnqueue(%s)",
3144                GetStr(l_errorEventType).c_str());  // LCOV_EXCL_BR_LINE 11:unexpected branch  // NOLINT(whitespace/line_length)
3145       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)
3146     }
3147   } catch (EFrameworkunifiedStatus e) {
3148     l_eStatus = e;
3149   }
3150
3151   FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-");
3152   return l_eStatus;
3153 }
3154 //                                                                            *
3155 // End of CPU Reset Protocol functions                                        *
3156 //*****************************************************************************
3157
3158 VOID CSystemManager::InitiateAllGroupsShutdown(HANDLE hApp) {
3159   FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+");
3160   EFrameworkunifiedStatus l_eStatus;
3161
3162   // Prioritize safe termination sequence and do not save logs during termination
3163   m_errorEventQueueLocked = TRUE;
3164
3165   m_MaxShutdownTime = calculate_max_shutdown_time();
3166
3167   l_eStatus = FrameworkunifiedNPPublishNotification(hApp, NTFY_SSSystemMgrShutdownStarted, NULL, 0);
3168
3169   SetCmdHist(NTFY_SSSystemMgrShutdownStarted, m_PubCmdHist, m_PubHistIter, "");  // LCOV_EXCL_BR_LINE 11:unexpected branch  // NOLINT(whitespace/line_length)
3170
3171   LOG_ERROR_REC_HIST_IF_ERRORED(l_eStatus,  // LCOV_EXCL_BR_LINE 15: marco defined in ss_system_manager.h  // NOLINT(whitespace/line_length)
3172       "FrameworkunifiedNPPublishNotification(" NTFY_SSSystemMgrShutdownStarted ")");
3173
3174   m_GroupLaunchTimer->StopTimer(m_aTimerIDs[eSM_TIMER_START_RESP_MONITOR_WAIT_TIMER]);
3175   m_GroupLaunchTimer->StopTimer(m_aTimerIDs[eSM_TIMER_CLIENT_START_MONITOR]);
3176
3177   // Stop Heartbeat thread activity
3178   l_eStatus = SendRequestToHeartBeat(hApp, SS_HEARTBEAT_STOP, NULL, 0);
3179   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)
3180
3181   SMSetState(hApp, SS_SM_APPS_STOPPING_AT__CWORD56__REQ);
3182
3183   FRAMEWORKUNIFIEDLOG(ZONE_STATE, __FUNCTION__, "shutdownTrigger:%s, lastUserMode:%s",
3184       GetStr(m_shutdownTrigger).c_str(), GetStr(m_lastUserMode).c_str());
3185
3186   fprintf(stderr,  // LCOV_EXCL_BR_LINE 11:unexpected branch  // NOLINT(whitespace/line_length)
3187       "SS_SysManager/%s/State shutdownTrigger:%s, lastUserMode:%s\n",  // LCOV_EXCL_BR_LINE 11:unexpected branch  // NOLINT(whitespace/line_length)
3188       __FUNCTION__, GetStr(m_shutdownTrigger).c_str(),  // LCOV_EXCL_BR_LINE 11:unexpected branch  // NOLINT(whitespace/line_length)
3189       GetStr(m_lastUserMode).c_str());  // LCOV_EXCL_BR_LINE 11:unexpected branch  // NOLINT(whitespace/line_length)
3190
3191   /// Send SS_SM_STOP to all modules, starting with the m_ActiveGroupId group
3192   m_NPPStopSent = FALSE;
3193   check_all_groups_have_stopped(hApp);
3194
3195   FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-");
3196   return;
3197 }  // End of EFrameworkunifiedStatus CSystemManager::InitiateAllGroupsShutdown(HANDLE hApp)
3198
3199 VOID CSystemManager::SendDeferMsg(HANDLE hApp) {
3200   FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+");
3201
3202   if (!m_dqDeferMsg.empty()) {
3203     EFrameworkunifiedStatus l_eStatus;
3204     SM_POWER_EVENT_INFO deferMsg;
3205
3206     deferMsg = m_dqDeferMsg.front();
3207     m_dqDeferMsg.pop();
3208
3209     HANDLE hSender = McOpenSender(SERVICE_SYSMANAGER);
3210     if (hSender == NULL) {  // LCOV_EXCL_BR_LINE 4: nsfw error
3211       // LCOV_EXCL_START 4: nsfw error
3212       AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
3213       FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, " Error: McOpenSender(SERVICE_SYSMANAGER)");
3214       // LCOV_EXCL_STOP
3215     } else {
3216       CALL_AND_LOG_STATUS_IF_ERRORED(  // LCOV_EXCL_BR_LINE 15: marco defined in ss_templates.h  // NOLINT(whitespace/line_length)
3217           McSend(hSender, SERVICE_POWER, deferMsg.first,
3218               sizeof(Pwr_ServiceSetInterface),
3219               (PVOID) & deferMsg.second));
3220       CALL_AND_LOG_STATUS_IF_ERRORED(McClose(hSender));  // LCOV_EXCL_BR_LINE 15: marco defined in ss_templates.h  // NOLINT(whitespace/line_length)
3221     }
3222   }
3223
3224   FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+");
3225   return;
3226 }  // End of VOID CSystemManager::SendDeferMsg(HANDLE hApp)
3227
3228 ///////////////////////////////////////////////////////////////////////////////
3229 /// \ingroup PublishPowerOnOffNotification
3230 /// Power Off notification handler
3231 ///
3232 /// \param [in]
3233 ///
3234 /// \return EFrameworkunifiedStatus
3235 /// Success ==> eFrameworkunifiedStatusOK
3236 /// Failure ==> Other values
3237 ///////////////////////////////////////////////////////////////////////////////
3238 EFrameworkunifiedStatus CSystemManager::PublishPowerOnOffNotification(HANDLE hApp) {
3239   EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK;
3240   FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+");
3241
3242   l_eStatus = PerformPowerOnOffUserModePublication(hApp, NTFY_SSSystemMgrPowerOnOff);
3243
3244   SetCmdHist(NTFY_SSSystemMgrPowerOnOff, m_PubCmdHist, m_PubHistIter, "");
3245   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)
3246
3247   FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-");
3248   return l_eStatus;
3249 }
3250
3251 EFrameworkunifiedStatus CSystemManager::PublishUserModeNotification(HANDLE hApp) {
3252   FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+");
3253   EFrameworkunifiedStatus l_eStatus;
3254
3255   l_eStatus = PerformPowerOnOffUserModePublication(hApp, NTFY_SSSystemMgrUserMode);
3256
3257   SetCmdHist(NTFY_SSSystemMgrUserMode, m_PubCmdHist, m_PubHistIter, "");
3258   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)
3259
3260   FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-");
3261   return l_eStatus;
3262 }  // End of EFrameworkunifiedStatus CSystemManager::PublishUserModeNotification(
3263
3264 EFrameworkunifiedStatus CSystemManager::PerformPowerOnOffUserModePublication(HANDLE hApp, const char * p_NotificationStr) {
3265   FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+");
3266   EFrameworkunifiedStatus l_eStatus;
3267   char l_cBuf[500] = { 0 };
3268
3269   if (m_SMConfig.UMConfig.IsUserModeNotificationABOOL) {
3270     BOOL l_bUuserMode(m_PowerType_to_SSBoolEnumMap[m_Wake.powerupType]);
3271
3272     snprintf(l_cBuf, sizeof(l_cBuf), "FrameworkunifiedNPPublishNotification(%s, %s)",
3273         p_NotificationStr, GetStr(l_bUuserMode).c_str());
3274     l_eStatus = FrameworkunifiedNPPublishNotification(hApp, p_NotificationStr,
3275         &l_bUuserMode, sizeof(l_bUuserMode));
3276   } else {
3277     T_SS_SM_UserModeOnOffNotification_Struct l_UserModeOnOffStruct(
3278         m_PowerType_to_SSBoolEnumMap[m_Wake.powerupType],
3279         m_StartUpReason, m_userModeChangeReason);
3280
3281     snprintf(l_cBuf, sizeof(l_cBuf),
3282         "FrameworkunifiedNPPublishNotification(%s, %s, %s, %s)", p_NotificationStr,
3283         GetStr(l_UserModeOnOffStruct.isUserModeOn).c_str(),
3284         GetStr(m_StartUpReason).c_str(),
3285         GetStr(m_userModeChangeReason).c_str());
3286     l_eStatus = FrameworkunifiedNPPublishNotification(hApp, p_NotificationStr,
3287         &l_UserModeOnOffStruct, sizeof(l_UserModeOnOffStruct));
3288   }
3289
3290   SetCmdHist(p_NotificationStr, m_PubCmdHist, m_PubHistIter, "");
3291   LOG_STATUS(l_eStatus, l_cBuf);  // LCOV_EXCL_BR_LINE 15: marco defined in ss_templates.h  // NOLINT(whitespace/line_length)
3292
3293   FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-");
3294   return l_eStatus;
3295 }  // End of EFrameworkunifiedStatus CSystemManager::PerformPowerOnOffUserModePublication(
3296
3297 EFrameworkunifiedStatus CSystemManager::ResetModulesStateToConnected(HANDLE hApp) {
3298   FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+");
3299   EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK;
3300   ModuleLaunchListIter l_moduleIter;
3301   for (GroupLaunchMapIter l_GroupIter = m_MapProclaunchGrps.begin();
3302       l_GroupIter != m_MapProclaunchGrps.end(); l_GroupIter++) {
3303     for (l_moduleIter = l_GroupIter->second.modules.begin();
3304         l_moduleIter != l_GroupIter->second.modules.end();
3305         l_moduleIter++) {
3306       if (l_moduleIter->name == FRAMEWORKUNIFIED_NS_NPSERVICE) {
3307         FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__, " %s ( Group %d/%s ) is %s",
3308             l_moduleIter->name.c_str(), l_GroupIter->second.id,
3309             l_GroupIter->second.name.c_str(),
3310             l_moduleIter->ModuleStateStr().c_str());
3311         l_moduleIter->SetModuleState(MODULE_STATE_STARTED);  // LCOV_EXCL_BR_LINE 15: marco defined in ns_logger_if.h  // NOLINT(whitespace/line_length)
3312       // End else if ( FRAMEWORKUNIFIED_NS_NPSERVICE == l_ModuleListIter->name )
3313       } else {
3314         switch (l_moduleIter->GetModuleState()) {
3315         case MODULE_STATE_INVALID:
3316         case MODULE_STATE_SKIPPED:
3317         case MODULE_STATE_LAUNCHING:
3318         case MODULE_STATE_LAUNCHED:
3319         case MODULE_STATE_LAUNCH_FAILED:
3320           FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__,
3321               " %s ( Group %d/%s ) is %s, NOT setting to "
3322               "MODULE_STATE_CONNECTED",
3323               l_moduleIter->name.c_str(), l_GroupIter->second.id,
3324               l_GroupIter->second.name.c_str(),
3325               l_moduleIter->ModuleStateStr().c_str());  // LCOV_EXCL_BR_LINE 15: marco defined in ns_logger_if.h  // NOLINT(whitespace/line_length)
3326           break;
3327
3328         case MODULE_STATE_STARTED:
3329         case MODULE_STATE_START_SENT:
3330         case MODULE_STATE_CONNECTED:
3331         case MODULE_STATE_START_FAILED:
3332         case MODULE_STATE_STOP_FAILED:
3333         case MODULE_STATE_STOP_SENT:
3334         case MODULE_STATE_STOPPED:
3335         case MODULE_STATE_START_PRE_SENT:
3336         case MODULE_STATE_START_PRE_FAILED:
3337         case MODULE_STATE_STARTED_PRE:
3338         case MODULE_STATE_STOP_PRE_SENT:
3339         case MODULE_STATE_STOP_PRE_FAILED:
3340         case MODULE_STATE_STOPPED_PRE:
3341         case MODULE_STATE_START_BACKGROUND_SENT:
3342         case MODULE_STATE_START_BACKGROUND_FAILED:
3343         case MODULE_STATE_STARTED_BACKGROUND:
3344         case MODULE_STATE_STOP_BACKGROUND_SENT:
3345         case MODULE_STATE_STOP_BACKGROUND_FAILED:
3346         case MODULE_STATE_STOPPED_BACKGROUND:
3347           FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__, " %s ( Group %d/%s ) is %s",
3348               l_moduleIter->name.c_str(), l_GroupIter->second.id,
3349               l_GroupIter->second.name.c_str(),
3350               l_moduleIter->ModuleStateStr().c_str());
3351           l_moduleIter->SetModuleState(MODULE_STATE_CONNECTED);
3352           break;
3353           // default:  Don't code a 'default' here - let the compiler
3354           // issue a warning ( set via -Wall or -Wswitch ) when the set of
3355           // enumerations changes - then the maintainer will
3356           // automagically know to update this switch statement.
3357         }
3358       }
3359     }
3360   }
3361   FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-");
3362   return l_eStatus;
3363 }  // End of EFrameworkunifiedStatus CSystemManager::ResetModulesStateToConnected(HANDLE hApp)
3364
3365 EFrameworkunifiedStatus CSystemManager::On_CWORD56_HeartBeatRequest(HANDLE hApp) {
3366   FRAMEWORKUNIFIEDLOG(ZONE_PERIODIC_FUNC, __FUNCTION__, "+");
3367   EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK;
3368
3369   PCSTR l_senderName = FrameworkunifiedGetMsgSrc(hApp);
3370
3371   SetCmdHist("SS_SM__CWORD56__HEARTBEAT_REQ", m_SMCmdHist, m_SMHistIter, l_senderName);
3372
3373   FRAMEWORKUNIFIEDLOG(ZONE_PERIODIC_INFO, __FUNCTION__, " Received from %s", l_senderName);
3374   EPWR_HB_REQ_MSG_STRUCT l_hbReq;
3375
3376   if (eFrameworkunifiedStatusOK != (l_eStatus = ReadMsg < EPWR_HB_REQ_MSG_STRUCT > (hApp, l_hbReq))) {
3377     LOG_ERROR("ReadMsg()");  // LCOV_EXCL_BR_LINE 15: marco defined in ss_templates.h  // NOLINT(whitespace/line_length)
3378   } else {
3379
3380     m_GroupLaunchTimer->StopTimer(m_aTimerIDs[eSM_TIMER__CWORD56__HEARTBEAT_RESPONSE]);
3381
3382     if (l_hbReq.IntervalSec > 0) {
3383       m_GroupLaunchTimer->StartTimer(
3384           m_aTimerIDs[eSM_TIMER__CWORD56__HEARTBEAT_RESPONSE], 0, 0,
3385           l_hbReq.IntervalSec, 0);
3386     } else if (l_hbReq.IntervalSec == 0) {  // LCOV_EXCL_BR_LINE 8: As the condition is never false
3387       l_eStatus = FrameworkunifiedSendMsg(m_hPowerServiceSession, SS_SM__CWORD56__HEARTBEAT_RSPN, 0, NULL);
3388
3389       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)
3390     }
3391   }
3392   FRAMEWORKUNIFIEDLOG(ZONE_PERIODIC_FUNC, __FUNCTION__, "-");
3393   return (l_eStatus);
3394 }
3395
3396 EFrameworkunifiedStatus CSystemManager::On_CWORD56_HeartBeatResponseIntervalTimerExpiry(HANDLE hApp) {
3397   FRAMEWORKUNIFIEDLOG(ZONE_PERIODIC_FUNC, __FUNCTION__, "+");
3398   EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK;
3399
3400   SetCmdHist("SM_TIMER__CWORD56__HEARTBEAT_RESPONSE", m_TimerCmdHist, m_TimerHistIter, FrameworkunifiedGetMsgSrc(hApp));  // LCOV_EXCL_BR_LINE 11:unexpected branch  // NOLINT(whitespace/line_length)
3401
3402   l_eStatus = FrameworkunifiedSendMsg(m_hPowerServiceSession, SS_SM__CWORD56__HEARTBEAT_RSPN, 0, NULL);
3403
3404   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)
3405
3406   FRAMEWORKUNIFIEDLOG(ZONE_PERIODIC_FUNC, __FUNCTION__, "-");
3407   return l_eStatus;
3408 }
3409
3410 // EOF of /SS_SystemManager/src/ss_system_manager_callbacks.cpp
3411