Fix path to various non-standard directories
[staging/basesystem.git] / service / system / system_manager / server / src / ss_system_manager.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
23 #include <native_service/cl_lock.h>
24 #include <native_service/cl_process.h>
25 #include <native_service/cl_monitor.h>
26
27 #include <native_service/frameworkunified_application.h>
28 #include <native_service/frameworkunified_framework_if.h>
29 #include <native_service/frameworkunified_multithreading.h>
30 #include <native_service/frameworkunified_thread_priority.h>
31
32 #include <native_service/ns_np_service_nor_persistence.h>
33 #include <native_service/ns_np_service_protocol.h>
34 #include <native_service/ns_plogger_if.h>
35 #include <native_service/ns_np_service_if.h>
36 #include <native_service/ns_backup.h>
37
38 #include <heartbeat/ss_hb_if.h>
39
40 #include <processlauncher/ProcessLauncher_if.h>
41 #include <processlauncher/ss_sm_process_launcher.h>
42 #include <processlauncher/ss_sm_process_launcher_protocol.h>
43
44 #include <system_service/ss_system_manager_conf.h>
45 #include <stub/ss_diag.h>
46
47 #include <system_service/ss_client_names.h>
48 #include <system_service/ss_heartbeat_service_protocol.h>
49 #include <system_service/ss_power_service_if.h>
50 #include <system_service/ss_power_service_notifications.h>
51 #include <system_service/ss_power_service_protocol.h>
52 #include <system_service/ss_services.h>
53 #include <system_service/ss_sm_thread_names.h>
54 #include <system_service/ss_sm_thread_names_local.h>
55 #include <system_service/ss_sm_client_if.h>
56 #include <system_service/ss_string_maps.h>
57 #include <system_service/ss_system_manager_notifications.h>
58 #include <system_service/ss_system_manager_notifications_local.h>
59 #include <system_service/ss_templates.h>
60 #include <system_service/ss_sm_client_if_local.h>
61 #include <system_service/ss_test_clients.h>
62 #include <stub/Clock_API.h>
63 #include <power_hal.h>
64 #include <dirent.h>
65 #include <errno.h>
66 #include <fcntl.h>
67 #include <stdio.h>
68 #include <stdlib.h>
69 #include <sys/mman.h>
70 #include <sys/resource.h>
71 #include <sys/procfs.h>
72 #include <sys/timeb.h>
73 #include <sys/wait.h>
74 #include <inttypes.h>
75 #include <libgen.h>
76 #include <spawn.h>
77 #include <pthread.h>
78 #include <linux/oom.h>
79 #include <sys/stat.h>
80 #include <sys/types.h>
81 #include <sys/ioctl.h>
82 #include <sched.h>
83 #include <other_service/itoa.h>
84 #include <iomanip>
85 #include <fstream>
86 #include <string>
87 #include <map>
88 #include <vector>
89 #include "ss_sm_signals.h"
90 #include "ss_sm_default_paths.h"
91 #include "ss_sm_systemmanagerlog.h"
92 #include "ss_sm_version.h"
93 #include "ss_system_manager.h"
94 using namespace std;  // NOLINT
95
96 static CSystemManager g_oSystemManger;
97
98 #define SS_SM_TEMP_FILE_FOR_STORE_LOGS "/var/local/lib/basesystem/nv/BS/ss/system_manager/rwdata/sm_tempStoreLogs"
99 #define TR_USB_PATH "/usr/agl/bin/realtimeUsbLog"
100
101 // \brief: public structure that is used for logging by NSLogger.
102 FRAMEWORKUNIFIEDLOGPARAM g_FrameworkunifiedLogParams = {
103   FRAMEWORKUNIFIEDLOGOPTIONS,
104   {
105     ZONE_TEXT_10, ZONE_TEXT_11, ZONE_TEXT_12,
106     ZONE_TEXT_13, ZONE_TEXT_14, ZONE_TEXT_15,
107     ZONE_TEXT_16, ZONE_TEXT_17, ZONE_TEXT_18,
108     ZONE_TEXT_19, ZONE_TEXT_20, ZONE_TEXT_21,
109     ZONE_TEXT_22, ZONE_TEXT_23, ZONE_TEXT_24,
110     ZONE_TEXT_25, ZONE_TEXT_26, ZONE_TEXT_27,
111     ZONE_TEXT_28, ZONE_TEXT_29, ZONE_TEXT_30,
112     ZONE_TEXT_31
113   },
114   FRAMEWORKUNIFIEDLOGZONES
115 };
116
117 std::string NumberToString(int Number) {  // LCOV_EXCL_START 8: dead code
118   AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
119   std::ostringstream ss;
120   ss << Number;
121   return ss.str();
122 }
123 // LCOV_EXCL_STOP
124
125 /* Check if "Mount Point" exsists as Directory */
126 /*****************************************************************************/
127 /**
128  @ingroup: CSystemManager
129  @brief: No Argument Constructor.
130  @note: .
131  @param void
132  @return void
133  */
134 /*****************************************************************************/
135 template<typename C, eFrameworkunifiedStatus (C::*M)(HANDLE)> EFrameworkunifiedStatus SysMgrCallback(HANDLE hApp) {
136   EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusFail;
137   C * pObj = static_cast<C *>(&g_oSystemManger);
138   if (pObj) {
139     l_eStatus = (pObj->*M)(hApp);
140   }
141   return l_eStatus;
142 }
143
144 //**************************************************************************
145 //  System Manager State String Map                                        *
146 //                                                                         *
147 void Init_SS_SMModuleState_StrMap(std::map<SS_SMModuleState, SS_String> & m_strMap) {  // NOLINT
148   MAP_ENTRY(m_strMap, SS_SM_READY_TO_LAUNCH_APP);
149   MAP_ENTRY(m_strMap, SS_SM_APPS_LAUNCH_IN_PROGRESS);
150   MAP_ENTRY(m_strMap, SS_SM_APPS_LAUNCHED_READY_TO_START);
151   MAP_ENTRY(m_strMap, SS_SM_APPS_START_IN_PROGRESS);
152   MAP_ENTRY(m_strMap, SS_SM_APPS_START_COMPLETE);
153   MAP_ENTRY(m_strMap, SS_SM_APPS_STOPPING_AT__CWORD56__REQ);
154   MAP_ENTRY(m_strMap, SS_SM_APPS_STOPPING_AT_INTERNAL_REQ);
155   MAP_ENTRY(m_strMap, SS_SM_WAITING_FOR_CRITICAL_APPS_AT__CWORD56__REQ);
156   MAP_ENTRY(m_strMap, SS_SM_WAITING_FOR_CRITICAL_APPS_AT_INTERNAL_REQ);
157   MAP_ENTRY(m_strMap, SS_SM_APPS_PRE_START_IN_PROGRESS);
158   MAP_ENTRY(m_strMap, SS_SM_APPS_PRE_STOP_IN_PROGRESS);
159   MAP_ENTRY(m_strMap, SS_SM_APPS_PRE_RUN_COMPLETE);
160   MAP_ENTRY(m_strMap, SS_SM_APPS_BACKGROUND_START_IN_PROGRESS);
161   MAP_ENTRY(m_strMap, SS_SM_APPS_BACKGROUND_STOP_IN_PROGRESS);
162   MAP_ENTRY(m_strMap, SS_SM_APPS_BACKGROUND_RUN_COMPLETE);
163 }  // End of void Init_SS_SMModuleState_StrMap(std::map<SS_SMModuleState,
164
165 class EnumStringMap<SS_SMModuleState, Init_SS_SMModuleState_StrMap>
166                     m_oSS_SMModuleStateStrMap;
167 SS_String GetStr(SS_SMModuleState f_enum) {
168   return m_oSS_SMModuleStateStrMap.GetStr(f_enum);  // LCOV_EXCL_BR_LINE 11:unexpected branch  // NOLINT(whitespace/line_length)
169 }  // End of SS_String :GetStr(SS_SMModuleState f_enum)
170 //                                                                         *
171 //  End of System Manager State String Map                                 *
172 //**************************************************************************
173
174 std::string CSystemManager::m_bootOpt;  // NOLINT
175
176 /*****************************************************************************/
177 /**
178  @ingroup: CSystemManager
179  @brief: No Argument Constructor.
180  @note: .
181  @param void
182  @return void
183  */
184 /*****************************************************************************/
185 CSystemManager & CSystemManager::GetInstance() {
186   return g_oSystemManger;
187 }
188
189 /*****************************************************************************/
190 /**
191  @ingroup: CSystemManager
192  @brief: No Argument Constructor.
193  @note: .
194  @param void
195  @return void
196  */
197 /*****************************************************************************/
198 CSystemManager::CSystemManager() :
199   m_hHeartbeatThread(INVALID_HANDLE, eSM_ThreadNotExist),
200   m_hProcLauncherThread(INVALID_HANDLE, eSM_ThreadNotExist),
201   m_SystemLaunchProgress(SS_SM_INITIAL_GROUP),
202   m_GroupLaunchTimer(NULL),
203   m_GroupRelaunchCount(0),
204   m_GroupRelaunchLimit(0),
205   m_hPowerServiceSession(NULL),
206   m_ActiveGroupId(SS_SM_INITIAL_GROUP),
207   m_StartUpReason(epswfINVALID),
208   m_DataResetMode(e_SS_SM_DATA_RESET_MODE_NONE),
209   m_ProgUpdateState(SS_SM_PROG_UPDATE_STATE_NONE),
210   m_NextWakeupType(e_SS_SM_NEXT_WAKEUP_TYPE_NONE),
211   m_DramBackupStatus(e_SS_SM_DRAM_BACKUP_NG),
212   m_isIlgReset(FALSE),
213   m_ResetStatus(e_SS_SM_RESET_STATUS_NONE),
214   m_ResetCount(0),
215   m_SMCurrentState(SS_SM_READY_TO_LAUNCH_APP),
216
217   m_MaxShutdownTime(0),
218   m_NbrDebugDumpRspnRecv(0),
219   m_isRcvModeInfo(FALSE),
220   m_BinaryFilesPath(""),
221   m_ConfigFilesPath(""),
222   m_pfStopCompleteHandler(
223       SysMgrCallback<CSystemManager, &CSystemManager::send_shutdown_complete_response>),
224   m_VersionNumberStruct(0, eFrameworkunifiedStatusErrOther),
225   m_BuildInfoStr(""),
226   m_isRstPending(FALSE),
227   m_rstPendingInfo(),
228   m_UsingVMPlayer(FALSE),
229   NVM_VALID_SIGNATURE(0xBA5EBA11),
230   m_lastUserMode(epsumON),
231   m_shutdownTrigger(epssdmsdtINVALID),
232   m_isImmediateReset(FALSE),
233   m_isImmResetReq(FALSE),
234   m_needReNotifyStartPrm(FALSE),
235   m_pVarCodeStr(NULL),
236   m_SSLGroupLaunchMapIterator(NULL),
237   m_ModuleLaunchListIter(NULL),
238   m_bIsNPP_ServicesStarted(FALSE),
239   m_bIsBackupAvail(FALSE),
240   m_oSystemLauncher(),
241   m_SystemStarter(),
242   m_NPPStopSent(FALSE),
243   m_userModeChangeReason(epsumcrNOT_AVAILABLE),
244   m__CWORD56_CmdHist(SS_SM__CWORD56__CMD_HIST_SIZE),
245   m_SMCmdHist(SS_SM_CMD_HIST_SIZE),
246   m_TimerCmdHist(SS_SM_TIMER_CMD_HIST_SIZE),
247   m_PubCmdHist(SS_SM_PUB_CMD_HIST_SIZE),
248   m_ErrHist(SS_SM_ERR_HIST_SIZE),
249   m_ClProcessSigFd(-1),
250   m_SysMemMonitor(),
251   m_FreeMemAvailable(0),
252   m_coreFileSizeBytes(0),
253   m_BootMicroResetReason(SS_SM_BOOT_MICRO_RESET_REASON_SELF_RESET),
254   m_errorEventQueueLocked(FALSE),
255   m_isPrevErrEventCompleted(TRUE),
256   m_errorEventResult(eFrameworkunifiedStatusOK),
257   m_requestedArtifactId(eArtifactIdInterfaceunifiedDebugLog) {  // LCOV_EXCL_BR_LINE 11:unexpected branch  // NOLINT(whitespace/line_length)
258   m_InitialBoot = true;
259
260   m_ResetFactor = PSM_FACTOR_NONE;
261
262   m_Wake.powerupType = epswsPWRON;
263   m_Wake.up.level = epswlFULLRUN;
264
265   m_SystemModeInfo.lastUserMode = m_lastUserMode;
266   m_SystemModeInfo.limpHomeCutoff = epslhcINVALID;
267   m_SystemModeInfo.productionMode = epspmINVALID;
268   m_SystemModeInfo.transportMode = epstmINVALID;
269   m_SystemModeInfo.systemMode = epssinfINVALID;
270   m_SystemModeInfo.startupStage = epssusfINVALID;
271
272   bzero(&m_SMConfig, sizeof(m_SMConfig));
273   bzero(&m_startUpConfirmationMsg, sizeof(m_startUpConfirmationMsg));
274   bzero(&m_HBReport, sizeof(m_HBReport));
275
276   m__CWORD56_HistIter = m__CWORD56_CmdHist.begin();
277   m_TimerHistIter = m_TimerCmdHist.begin();
278   m_SMHistIter = m_SMCmdHist.begin();
279   m_PubHistIter = m_PubCmdHist.begin();
280   m_ErrHistIter = m_ErrHist.begin();
281
282   ////******************************************************************////
283   ////       Initialization of enum<=>enum and enum=>string maps        ////
284   ////                                                                  ////
285
286   //
287   // **** Initialization of powerupType enum maps ****
288   // Map of System Services powerupType to BOOL enum values
289   m_PowerType_to_SSBoolEnumMap[epswsPWRON] = TRUE;
290   m_PowerType_to_SSBoolEnumMap[epswsPWROFF] = FALSE;
291   //
292   // Map of System Services powerupType to System Services User Mode enum values
293   m_PowerType_to_SSUserModeEnumMap[epswsPWRON] = epsumON;
294   m_PowerType_to_SSUserModeEnumMap[epswsPWROFF] = epsumOFF;
295   //
296   // Map of BOOL to System Services powerupType enum values
297   m_SSBool_to_PowerTypeEnumMap[TRUE] = epswsPWRON;
298   m_SSBool_to_PowerTypeEnumMap[FALSE] = epswsPWROFF;
299   //
300   // **** Initialization of User Mode ( aka Last User Mode ) maps ****
301   // Map of BOOL to System Services User Mode enum values
302   m_SSBool_to_SSUserModeEnumMap[FALSE] = epsumOFF;
303   m_SSBool_to_SSUserModeEnumMap[TRUE] = epsumON;
304   //
305   // Map of BOOL to System Services User Mode enum values
306   m_SSUserMode_to_SSBoolEnumMap[epsumOFF] = FALSE;
307   m_SSUserMode_to_SSBoolEnumMap[epsumON] = TRUE;
308
309   // LCOV_EXCL_BR_STOP
310   ////                                                                  ////
311   ////    End of Initialization of enum<=>enum and enum=>string maps    ////
312   ////******************************************************************////
313
314   m_startUpConfirmationMsg.wakeupType = epsstINVALID;
315   m_startUpConfirmationMsg.coldStartRequest = epsscrtINVALID;
316   m_startUpConfirmationMsg.HWVersion = UINT32_MAX;
317   m_startUpConfirmationMsg.matchedHardwareType = UINT32_MAX;
318   m_startUpConfirmationMsg.softwareType = UINT32_MAX;
319   m_startUpConfirmationMsg.imageType = UINT32_MAX;
320   m_startUpConfirmationMsg.majorVersion = UINT32_MAX;
321   m_startUpConfirmationMsg.minorVersion = UINT32_MAX;
322
323   m_SystemManagerPriority = PR_SS_SYSMANAGER;
324 }
325
326 /*****************************************************************************/
327 /**
328  @ingroup: CSystemManager
329  @brief: Destructor
330  @note: .
331  @param void
332  @return void
333  */
334 /*****************************************************************************/
335 CSystemManager::~CSystemManager() {  // LCOV_EXCL_BR_LINE 11:unexpected branch  // NOLINT(whitespace/line_length)
336   if (NULL != m_pVarCodeStr) {
337     delete[] m_pVarCodeStr;  // LCOV_EXCL_BR_LINE 11:unexpected branch  // NOLINT(whitespace/line_length)
338   }
339 }
340
341 /*****************************************************************************/
342 /**
343  @ingroup: CSystemManager
344  @brief: Initialize_memory Memory initialization processing
345  @note: .
346  @param
347  @return void
348  */
349 /*****************************************************************************/
350 void CSystemManager::Initialize_memory(HANDLE hApp, bool* l_isInitFail, EFrameworkunifiedStatus* l_eStatus_work, BOOL isIllReset) {
351   int ret;
352   EFrameworkunifiedStatus l_eStatus;
353
354   /// Start Process for Realtime USB Logging
355   {
356     PreLaunchModuleParams l_rtuparam;
357     l_rtuparam.LaunchFunc     = CreateRtUsb;
358     l_rtuparam.relaunchLimit  = 1;
359     l_rtuparam.name           = "realtimeUsbLog";
360     l_rtuparam.binaryFileName = TR_USB_PATH;
361 /*    l_rtuparam.pid = CreateRtUsb();
362     if (l_rtuparam.pid == 1) {
363       FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, " Error: CreateRtUsb()");
364     }  */
365     m_PreLaunchModuleList.push_back(l_rtuparam);
366   }
367
368   FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+");
369
370   int fd = open("/dev/urandom", O_RDONLY);  // LCOV_EXCL_BR_LINE 5: standard lib error
371   if (fd == -1) {  // LCOV_EXCL_BR_LINE 5: standard lib error
372     AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
373     SS_ASERT_ERRNO(0);  // LCOV_EXCL_LINE 5: standard lib error
374   } else {
375     char buf[4];
376     ret = static_cast<int>(read(fd, buf, 4));  // LCOV_EXCL_BR_LINE 5: standard lib error
377     if (-1 == ret) {  // LCOV_EXCL_BR_LINE 5: standard lib error
378       AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
379       SS_ASERT_ERRNO(0);  // LCOV_EXCL_LINE 5: standard lib error
380     } else if (4 != ret) {  // LCOV_EXCL_BR_LINE 5: standard lib error
381       AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
382       SS_ASERT(0);  // LCOV_EXCL_LINE 5: standard lib error
383     } else {
384       fprintf(stderr, "WakeupID:%X%X%X%X\n", buf[0], buf[1], buf[2], buf[3]);
385       FRAMEWORKUNIFIEDLOG(ZONE_STATE, __FUNCTION__, "WakeupID:%X%X%X%X", buf[0], buf[1], buf[2], buf[3]);
386     }
387     close(fd);
388   }
389
390   FRAMEWORKUNIFIEDLOG(ZONE_STATE, __FUNCTION__, "bootOpt:%s", m_bootOpt.c_str());
391
392   *l_eStatus_work = FrameworkunifiedAttachCallbackToDispatcherWithFd(hApp, m_ClProcessSigFd,  // LCOV_EXCL_BR_LINE 4: nsfw error
393         SysMgrCallback<CSystemManager, &CSystemManager::OnProcessTermDetected>);
394
395   if (eFrameworkunifiedStatusOK != *l_eStatus_work) {  // LCOV_EXCL_BR_LINE 4: nsfw error
396     // LCOV_EXCL_START 4: nsfw error
397     AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
398     LOG_ERROR("FrameworkunifiedAttachCallbackToDispatcherWithFd()");
399     *l_isInitFail = true;
400     // LCOV_EXCL_STOP
401   }
402
403   pthread_mutex_init(&sm_hist_mutex, NULL);
404
405   ReadPathFromEnvironmentVariables();
406   ReadUsingVMPlayerEnvironmentVariable();
407
408   // FIXME : Dump information from power_hal by using
409
410   if (eFrameworkunifiedStatusOK != (*l_eStatus_work = SetSystemModeInfoStruct())) {
411     LOG_ERROR("SetSystemModeInfoStruct()");  // LCOV_EXCL_BR_LINE 15: marco defined in ss_templates.h  // NOLINT(whitespace/line_length)
412     *l_isInitFail = true;
413   }
414
415   // Select configuration file for wakeup services
416   BOOL bIsVupMode = (m_SystemModeInfo.systemMode == epssinfPROGRAMMING) ? TRUE : FALSE;  // LCOV_EXCL_BR_LINE 11:unexpected branch  // NOLINT(whitespace/line_length)
417
418   T_SS_SM_INIT_HOOK_IN_PARAM inPrm;
419
420   std::memset(&inPrm, 0, sizeof(inPrm));
421   inPrm.bIsVupMode = bIsVupMode;
422
423   if (eFrameworkunifiedStatusOK != (*l_eStatus_work = ss_sm_initHook(hApp, &inPrm, &m_productCustomPrm))) {
424     SS_ASERT_LOG(0, "ERROR: ss_sm_initHook()");  // LCOV_EXCL_BR_LINE 15: marco defined in ss_templates.h  // NOLINT(whitespace/line_length)
425     *l_isInitFail = true;
426   }
427
428   SetEnvVariableForVupMode(bIsVupMode);
429
430   // Get the Version Number
431   // GetVersionNumber() will report any errors
432   m_VersionNumberStruct.m_eSystemmanagerStatus = GetVersionNumber(m_VersionNumberStruct.m_VersionNumber);
433
434   *l_eStatus_work = GetBuildInfo(m_BuildInfoStr);
435   l_eStatus = *l_eStatus_work;
436
437   LOG_ERROR_REC_HIST_IF_ERRORED(l_eStatus, "GetBuildInfo()");  // LCOV_EXCL_BR_LINE 15: marco defined in ss_system_manager.h  // NOLINT(whitespace/line_length)
438
439   INTERFACEUNIFIEDLOG_WHEN_COMPILED;  // LCOV_EXCL_BR_LINE 15: marco defined in ss_system_manager.h  // NOLINT(whitespace/line_length)
440
441   FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__, " %s priority is %d", SERVICE_SYSMANAGER, m_SystemManagerPriority);
442   FRAMEWORKUNIFIEDLOG(ZONE_PERFORMANCE, __FUNCTION__, " %s was compiled at %s @ %s", __FILE__, __DATE__, __TIME__);
443
444   FRAMEWORKUNIFIEDLOG(ZONE_PERFORMANCE, __FUNCTION__, " Host Processor Software Version is '0x%016llX'",
445          m_VersionNumberStruct.m_VersionNumber);
446
447   FRAMEWORKUNIFIEDLOG(ZONE_PERFORMANCE, __FUNCTION__, " Host Processor Build Version is '%s'", m_BuildInfoStr.c_str());
448
449   LogESystemmanagerStatusEnums();
450   LogProtocolIDs();
451 }
452
453 /*****************************************************************************/
454 /**
455  @ingroup: CSystemManager
456  @brief: Initialize_callbacks Callback enrollment process
457  @note: .
458  @param
459  @return void
460  */
461 /*****************************************************************************/
462 void CSystemManager::Initialize_callbacks(HANDLE hApp, bool *l_isInitFail, EFrameworkunifiedStatus *l_eStatus_work) {
463   EFrameworkunifiedStatus l_eStatus;
464
465   m_GroupLaunchTimer = new (std::nothrow) TimerCtrl(eSM_TIMERS_END);  // LCOV_EXCL_BR_LINE 11:unexpected branch  // NOLINT(whitespace/line_length)
466     if (NULL == m_GroupLaunchTimer) {  // LCOV_EXCL_BR_LINE 5: Because new doesn't pass the failure case
467     // LCOV_EXCL_START 5: Because new doesn't pass the failure case
468     AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
469     *l_eStatus_work = eFrameworkunifiedStatusNullPointer;
470     LOG_ERROR("new(std::nothrow)TimerCtrl(eSM_TIMERS_END)");
471     *l_isInitFail = true;
472     // LCOV_EXCL_STOP
473   }
474
475   // LCOV_EXCL_BR_START 11:unexpected branch  // NOLINT(whitespace/line_length)
476   m_GroupLaunchTimer->Initialize(hApp);
477   m_aTimerIDs[eSM_TIMER_GROUP_MONITOR] =
478       m_GroupLaunchTimer->CreateTimer(SysMgrCallback<CSystemManager, &CSystemManager::OnGroupLaunchTimerExpiry>);
479   m_aTimerIDs[eSM_TIMER_PROCESS_LAUNCH_MONITOR] =
480       m_GroupLaunchTimer->CreateTimer(SysMgrCallback<CSystemManager, &CSystemManager::OnProcessLaunchTimerExpiry>);
481   m_aTimerIDs[eSM_TIMER_HEARTBEAT_MONITOR] =
482       m_GroupLaunchTimer->CreateTimer(SysMgrCallback<CSystemManager, &CSystemManager::OnHeartBeatMonitorTimerExpiry>);
483   m_aTimerIDs[eSM_TIMER_PROCESSLAUNCHER_MONITOR] =
484       m_GroupLaunchTimer->CreateTimer(SysMgrCallback<CSystemManager,
485                                       &CSystemManager::OnProcessLaunchMonitorTimerExpiry>);
486   m_aTimerIDs[eSM_TIMER_CLIENT_START_MONITOR] =
487       m_GroupLaunchTimer->CreateTimer(SysMgrCallback<CSystemManager,
488                                       &CSystemManager::OnClientStartMonitorTimerExpiry>);
489   m_aTimerIDs[eSM_TIMER_NPP_STATUS_CHECK_MONITOR] =
490       m_GroupLaunchTimer->CreateTimer(SysMgrCallback<CSystemManager,
491                                       &CSystemManager::OnNPPStatusCheckMonitorTimerExpiry>);
492   m_aTimerIDs[eSM_TIMER__CWORD56__HEARTBEAT_RESPONSE] =
493       m_GroupLaunchTimer->CreateTimer(SysMgrCallback<CSystemManager,
494                                       &CSystemManager::On_CWORD56_HeartBeatResponseIntervalTimerExpiry>);
495   m_aTimerIDs[eSM_TIMER_LAUNCH_GROUP_TRIGGER_PROC_RESP_TIMER] =
496       m_GroupLaunchTimer->CreateTimer(SysMgrCallback<CSystemManager,
497                                       &CSystemManager::OnLaunchGroupTriggerProcessResponseTimerExpiry>);
498   m_aTimerIDs[eSM_TIMER_GROUP_LAUNCH_WAIT_TIMER] =
499       m_GroupLaunchTimer->CreateTimer(SysMgrCallback<CSystemManager, &CSystemManager::OnGroupLaunchWaitTimeout>);
500   m_aTimerIDs[eSM_TIMER_MODULE_CONNECT_WAIT_TIMER] =
501       m_GroupLaunchTimer->CreateTimer(SysMgrCallback<CSystemManager, &CSystemManager::OnModuleConnectWaitTimeout>);
502   m_aTimerIDs[eSM_TIMER_START_RESP_MONITOR_WAIT_TIMER] =
503       m_GroupLaunchTimer->CreateTimer(SysMgrCallback<CSystemManager, &CSystemManager::OnStartRespMonitorTimeout>);
504   m_aTimerIDs[eSM_TIMER_SHUTDOWN_COMPLETE_MONITOR] =
505       m_GroupLaunchTimer->CreateTimer(SysMgrCallback<CSystemManager,
506                                       &CSystemManager::OnShutdownCompleteMonitorTimeout>);
507   m_aTimerIDs[eSM_TIMER_CLIENT_STOP_MONITOR] =
508       m_GroupLaunchTimer->CreateTimer(SysMgrCallback<CSystemManager, &CSystemManager::OnClientStopMonitorTimerExpiry>);
509
510   FrameworkunifiedProtocolCallbackHandler l_cbArrayAnySource[] = {
511       // Command ID,                   Call back functions
512     { SS_SM_PROTOCOL_OPEN_SESSION_REQ, SysMgrCallback<CSystemManager, &CSystemManager::OnOpenSession> },
513     { SS_SM_CPU_RESET_REQ,             SysMgrCallback<CSystemManager, &CSystemManager::OnCpuResetRequest> }
514   };
515
516   FrameworkunifiedProtocolCallbackHandler l_cbArrayGroupLaunchService[] = {
517       // Command ID,              Call back functions
518     { SS_SM_GROUP_LAUNCH_TRIGGER, SysMgrCallback<CSystemManager, &CSystemManager::OnLaunchGroupTriggerProcessResponse> }
519   };
520
521   FrameworkunifiedProtocolCallbackHandler l_cbArrayNPPService[] = {
522       // Command ID,           Call back functions
523     { NPS_NPP_READY_EVENT,     SysMgrCallback<CSystemManager, &CSystemManager::OnNPPReadyEventCallback> },
524     { NPS_GET_READYSTATUS_ACK, SysMgrCallback<CSystemManager, &CSystemManager::OnNPPReadyStatusCallback> },
525     { NPS_NPP_STOP_ACK,        SysMgrCallback<CSystemManager, &CSystemManager::OnNppStopComplete> }
526   };
527
528   FrameworkunifiedProtocolCallbackHandler l_cbArrayPowerService[] = {
529       // Command ID,              Call back functions
530     { SS_SM_POWER_REQUEST_MSG,    SysMgrCallback<CSystemManager, &CSystemManager::OnPowerRequestCallback> },
531     { SS_SM_WAKEUP_MODULES,       SysMgrCallback<CSystemManager, &CSystemManager::OnWakeupCallback> },
532     { SS_SM_SYSTEM_MODE_INFO_REQ, SysMgrCallback<CSystemManager, &CSystemManager::OnSystemModeInfoRequest> },
533     { SS_SM_INITCOMP_REP,         SysMgrCallback<CSystemManager, &CSystemManager::OnInitCompReportCallback> },
534     { SS_SM_SHUTDOWN_MODULES,     SysMgrCallback<CSystemManager, &CSystemManager::OnShutdownModulesRequest> },
535     { SS_SM_FWD_STARTUP_CONFIRMATION_MSG_REQ,
536                             SysMgrCallback<CSystemManager, &CSystemManager::OnSetStartupConfirmationDataRequest> }
537   };
538
539   FrameworkunifiedProtocolCallbackHandler l_cbArraySystemManager[] = {
540       // Command ID,        Call back functions
541     { SS_SM_SendTriggerToSelf, SysMgrCallback<CSystemManager, &CSystemManager::OnLaunchGroupSelfTrigger> },
542     { SS_SM_DEBUG_DUMP_RSPN, SysMgrCallback<CSystemManager,   &CSystemManager::OnDebugDumpResponseReceived> }
543   };
544   // LCOV_EXCL_BR_STOP
545
546 #define ATTACH_CBS_TO_DISPATCHER(L_ARRAY, CALLING_SERVICE_NAME)       \
547     *l_eStatus_work = l_eStatus = FrameworkunifiedAttachCallbacksToDispatcher(hApp,           \
548                           CALLING_SERVICE_NAME,   \
549                           L_ARRAY,          \
550                           static_cast<UI_32>_countof(L_ARRAY));     \
551     if (eFrameworkunifiedStatusOK != l_eStatus) {                  \
552     FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__,                    \
553        " Error: FrameworkunifiedAttachCallbacksToDispatcher(%s) errored: %d/'%s'",   \
554        #L_ARRAY,                            \
555        l_eStatus,                             \
556        GetStr(l_eStatus).c_str());                    \
557        *l_isInitFail = true;                       \
558     }
559 // End of #define ATTACH_CBS_TO_DISPATCHER( CALLING_SERVICE_NAME, L_ARRAY )
560
561   // LCOV_EXCL_BR_START 15: marco defined above
562   // Note: This macro will exit this function if the embedded fnc errors.
563   ATTACH_CBS_TO_DISPATCHER(l_cbArrayAnySource, FRAMEWORKUNIFIED_ANY_SOURCE);
564
565   // Note: This macro will exit this function if the embedded fnc errors.
566   ATTACH_CBS_TO_DISPATCHER(l_cbArrayGroupLaunchService, SS_GROUP_LAUNCH_TRIGGER);
567
568   // Note: This macro will exit this function if the embedded fnc errors.
569   ATTACH_CBS_TO_DISPATCHER(l_cbArrayNPPService, FRAMEWORKUNIFIED_NS_NPSERVICE);
570
571   // Note: This macro will exit this function if the embedded fnc errors.
572   ATTACH_CBS_TO_DISPATCHER(l_cbArrayPowerService, SERVICE_POWER);
573
574   // Note: This macro will exit this function if the embedded fnc errors.
575   ATTACH_CBS_TO_DISPATCHER(l_cbArraySystemManager, SERVICE_SYSMANAGER);
576   // LCOV_EXCL_BR_STOP
577
578   {
579     char pathBuf[128];
580     // LCOV_EXCL_BR_START 11:unexpected branch  // NOLINT(whitespace/line_length)
581     snprintf(pathBuf, sizeof(pathBuf), "/proc/%d/oom_score_adj", getpid());
582     std::ofstream fo(pathBuf);
583     fo << OOM_SCORE_ADJ_MIN << endl;
584     fo.close();
585     // LCOV_EXCL_BR_STOP
586     FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__, "set OOM_SCORE_ADJ_MIN(SS_SysManager/%d)", getpid());
587   }
588
589 #undef ATTACH_CBS_TO_DISPATCHER
590
591   // LCOV_EXCL_BR_START 4: nsfw error
592   *l_eStatus_work = FrameworkunifiedSubscribeNotificationWithCallback(hApp, NTFY_BackupMgr_Availability,
593           SysMgrCallback<CSystemManager, &CSystemManager::OnBackupMgrAvailCallback>);
594   // LCOV_EXCL_BR_STOP
595   if (eFrameworkunifiedStatusOK != *l_eStatus_work) {  // LCOV_EXCL_BR_LINE 4: nsfw error
596     // LCOV_EXCL_START 4: nsfw error
597     AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
598     LOG_ERROR("FrameworkunifiedSubscribeNotificationWithCallback()");
599     *l_isInitFail = true;
600     // LCOV_EXCL_STOP
601   }
602
603   if (eFrameworkunifiedStatusOK != (*l_eStatus_work = ErrorEventInit(hApp))) {  // LCOV_EXCL_BR_LINE 6: function do not return error
604     // LCOV_EXCL_START 6: function do not return error
605     AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
606     LOG_ERROR("ErrorEventInit()");
607     *l_isInitFail = true;
608     // LCOV_EXCL_STOP
609   }
610
611 #ifndef SS_SM_SKIP_HEARTBEAT_INIT
612   // LCOV_EXCL_BR_START 6: function do not return error, expect nsfw error
613   if (eFrameworkunifiedStatusOK != (*l_eStatus_work = init_Heartbeat(hApp))) {
614   // LCOV_EXCL_BR_STOP
615     // LCOV_EXCL_START 6: function do not return error, expect nsfw error
616     AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
617     LOG_ERROR("init_HeartBeat()");
618     *l_isInitFail = true;
619     // LCOV_EXCL_STOP
620   }
621 #else
622 #warning Test code - NOT calling init_Heartbeat(hApp)
623   FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, " Error: NOT calling init_Heartbeat(hApp)");
624 #endif
625 #undef SS_SM_SKIP_HEARTBEAT_INIT
626
627   // LCOV_EXCL_BR_START 6: function do not return error, expect nsfw error
628   if (eFrameworkunifiedStatusOK != (*l_eStatus_work = init_process_launcher(hApp))) {
629   // LCOV_EXCL_BR_STOP
630     // LCOV_EXCL_START 6: function do not return error, expect nsfw error
631     AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
632     LOG_ERROR("init_process_launcher()");
633     *l_isInitFail = true;
634     // LCOV_EXCL_STOP
635   }
636
637   // LCOV_EXCL_BR_START 6: function do not return error, expect init error
638   if (eFrameworkunifiedStatusOK != (*l_eStatus_work = start_process_launching(hApp))) {
639   // LCOV_EXCL_BR_STOP
640     // LCOV_EXCL_START 6: function do not return error, expect init error
641     AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
642     LOG_ERROR("start_process_launching()");
643     *l_isInitFail = true;
644     // LCOV_EXCL_STOP
645   }
646
647   // LCOV_EXCL_BR_START 6: function do not return error, expect nsfw error
648   if (eFrameworkunifiedStatusOK != (*l_eStatus_work = init_sysmem_monitor(hApp))) {
649   // LCOV_EXCL_BR_STOP
650     // LCOV_EXCL_START 6: function do not return error, expect nsfw error
651     AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
652     LOG_ERROR("init_sysmem_monitor()");
653     *l_isInitFail = true;
654     // LCOV_EXCL_STOP
655   }
656
657   /// Internal thread monitoring start
658   // LCOV_EXCL_BR_START 11:unexpected branch  // NOLINT(whitespace/line_length)
659   m_GroupLaunchTimer->StartTimer(m_aTimerIDs[eSM_TIMER_HEARTBEAT_MONITOR],
660       SS_HEARTBEAT_MONITOR_TIMER_CONFIG, 0,
661       SS_HEARTBEAT_MONITOR_TIMER_CONFIG, 0);
662
663   m_GroupLaunchTimer->StartTimer(
664       m_aTimerIDs[eSM_TIMER_PROCESSLAUNCHER_MONITOR],
665       SS_PROCESSLAUNCHER_MONITOR_TIMER_CONFIG, 0,
666       SS_PROCESSLAUNCHER_MONITOR_TIMER_CONFIG, 0);
667
668   m_GroupLaunchTimer->StartTimer(
669       m_aTimerIDs[eSM_TIMER_NPP_STATUS_CHECK_MONITOR],
670       SS_NPP_STATUS_CHECK_MONITOR_TIME_SEC, 0,
671       SS_NPP_STATUS_CHECK_MONITOR_TIME_SEC, 0);
672   // LCOV_EXCL_BR_STOP
673 }
674
675
676 /*****************************************************************************/
677 /**
678  @ingroup: CSystemManager
679  @brief: Initialization
680  @note: .
681  @param HANDLE hApp
682  @return void
683  */
684 /*****************************************************************************/
685 EFrameworkunifiedStatus CSystemManager::Initialize(HANDLE hApp) {
686   bool l_isInitFail = false;
687   EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK;
688   int ret;
689   PsmFactorT      l_startup_factor;
690
691   // Need to call Lock System Initialize API once in the system
692   ret = CL_LockSystemInit();
693   if (ret != 0) {
694     fprintf(stderr, "SS_SysManager/%s/Error: CL_LockSystemInit() errored: %d\n", __FUNCTION__, ret);
695   }
696
697   ret = CL_LockProcessInit();
698   if (ret != 0) {
699     fprintf(stderr, "SS_SysManager/%s/Error: CL_LockProcessInit() errored: %d\n", __FUNCTION__, ret);
700     l_isInitFail = true;
701   }
702
703   ret = PsmGetStartupFactor(hApp, &l_startup_factor);
704   if (ret == 0) {
705     if ((static_cast<UI_32>(l_startup_factor) & PSM_RESET_HISTORY) == PSM_RESET_HISTORY) {
706       DGCODE_RET_API  l_ret = DGCODE_RET_ERROR;
707       uint64_t l_SystemResetRobCode = 0;
708       DGCODE_ROB_SSR_INFO  l_info;
709       if (l_startup_factor == PSM_FACTOR_AGL_WITH_HISTORY) {
710         l_SystemResetRobCode = 0x2219;                // AGL cause
711       } else if (l_startup_factor == PSM_FACTOR_TIER1_WITH_HISTORY) {
712         l_SystemResetRobCode = 0x221A;                // Tier1 cause
713       } else if (l_startup_factor == PSM_FACTOR_USER_WITH_HISTORY) {
714         l_SystemResetRobCode = 0x8027;                // USER cause
715       } else {
716         // No processing
717       }
718
719       if (l_SystemResetRobCode != 0) {
720         memset(&l_info, 0x00, sizeof(DGCODE_ROB_SSR_INFO));
721
722         l_ret = Diag_PutRoBInfo(hApp, l_SystemResetRobCode, &l_info);
723         if (l_ret == DGCODE_RET_ERROR) {
724           LOG_ERROR("Diag_PutRoBInfo()");
725         }
726       }
727     }
728   } else {
729     (void)fprintf(stderr, "SS_SysManager/%s/ERROR:start-up factor not get\n", __FUNCTION__);
730   }
731
732   m_isIlgReset = (false == GetSyscomPowerStatusInfo(hApp)) ? TRUE : FALSE;
733   if (m_isIlgReset || ("elog" == m_bootOpt)) {
734     fprintf(stderr, "SS_SysManager/%s/Error: ILGRST LOG SAVE\n", __func__);
735     StoreDebugLogs(hApp, SS_STORELOGS_ILLEGAL);
736   } else {
737     StoreDebugLogs(hApp, SS_STORELOGS_ACCOFFON);
738   }
739
740   if (m_isIlgReset == TRUE) {
741     // overwrite AGL_ILLRESET_FLAG.
742     uint32_t tmp = static_cast<uint32_t>(m_isIlgReset);
743     if (PowerHalSetResetInfo(AGL_ILLRESET_FLAG, tmp)) {
744       FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__,
745            "Could not set AGL_ILLRESET_FLAG to power_hal");
746     }
747   } else {
748     // keep last value of AGL_ILLRESET_FLAG.
749   }
750
751   FRAMEWORKUNIFIED_SET_ZONES();
752   NsLogSetLogMethod(LPRINT | LMSGQ);
753   // FRAMEWORKUNIFIEDLOG can not be used until this line
754
755   m_ClProcessSigFd = CL_ProcessInit();  // LCOV_EXCL_BR_LINE 4: nsfw error
756   if (m_ClProcessSigFd == -1) {  // LCOV_EXCL_BR_LINE 4: nsfw error
757     // LCOV_EXCL_START 4: nsfw error
758     AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
759     FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, " Error: CL_ProcessInit()");
760     l_isInitFail = true;
761     // LCOV_EXCL_STOP
762   }
763
764   ret = CL_MonitorInit(CL_MONITOR_INIT_SYSTEM);
765   if(ret != 0) {
766     fprintf(stderr, "SS_SysManager/%s/Error: CL_MonitorInit() errored: %d\n", __FUNCTION__, ret);
767     l_isInitFail = true;
768   }
769
770   // Threads MUST NOT be started until this line
771 // ===== Initialization No.1
772   Initialize_memory(hApp, &l_isInitFail, &l_eStatus, m_isIlgReset);
773
774 // ===== Initialization No.2
775   Initialize_callbacks(hApp, &l_isInitFail, &l_eStatus);
776
777   FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-");
778
779   return l_eStatus;
780 }
781
782 EFrameworkunifiedStatus CSystemManager::SetEnvVariableForVupMode(BOOL bIsVupMode) {
783   EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK;
784   const CHAR SmVupModeEnvVariable[] = "SM_VUP_MODE";
785   const CHAR *l_pValue = bIsVupMode ? "y" : "n";  // LCOV_EXCL_BR_LINE 11:unexpected branch  // NOLINT(whitespace/line_length)
786
787   if (0 != setenv(SmVupModeEnvVariable, l_pValue, 1)) {  // LCOV_EXCL_BR_LINE 5: standard lib error
788     // LCOV_EXCL_START 5: standard lib error
789     AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
790     SS_ASERT_ERRNO(0);
791     l_eStatus = eFrameworkunifiedStatusFail;
792     // LCOV_EXCL_STOP
793   }
794
795   return l_eStatus;
796 }
797
798 int CSystemManager::CreateRtUsb(void) {// LCOV_EXCL_START 8: dead code
799   AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
800   int pid = -1;
801   int ret;
802
803   ret = mkdir("/var/run", 0775);
804   if ((ret < 0) && (errno != EEXIST)) {
805     return -1;
806   }
807   pid = fork();
808   switch (pid) {
809     case 0: /* child process */
810     {
811       struct sched_param param;
812       int policy;
813       const char *exec;
814       exec = const_cast<char *>(TR_USB_PATH);
815       param.sched_priority = 0;
816       policy = SCHED_OTHER;
817       if (sched_setscheduler(getpid(), policy, &param) < 0) {
818         SS_ASERT(0);
819         _exit(-1);
820       }
821       if (setpriority(PRIO_PROCESS, getpid(), 0) < 0) {
822         SS_ASERT(0);
823         _exit(-1);
824       }
825       // exec
826       if (execlp(exec, exec, NULL) < 0) {
827         SS_ASERT(0);
828         _exit(-1);
829       }
830       _exit(0);
831     }
832     break;
833
834     case -1: /* error */
835       SS_ASERT(0);
836       goto ERROR;
837
838     default: /* parent process */
839       break;
840   }
841
842 ERROR:
843   return pid;
844 }// LCOV_EXCL_STOP
845
846 bool CSystemManager::StoreDebugLogs(const HANDLE h_app,
847                                                    SS_STORELOGS_OPE_TYPE type) {
848   bool isMountRamd = false;
849   EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK;
850   int pid;
851
852   if (!GetDramPowerStatusInfo(h_app)) {
853     goto ERROR;
854   } else if (access(SS_SM_TEMP_FILE_FOR_STORE_LOGS, F_OK) == 0) {
855     fprintf(stderr, "SS_SysManager/%s/Error: Skip StoreDebugLogs\n", __FUNCTION__);
856     goto ERROR;
857   }
858
859   isMountRamd = true;
860
861   if (type == SS_STORELOGS_ILLEGAL) {
862     UI_32 l_ErrLogCount = 0;
863     if (PowerHalGetResetInfo(AGL_ERRLOG_COUNTER, &l_ErrLogCount)) {
864       fprintf(stderr, "SS_SysManager/%s/Error: "
865         "Could not read AGL_ERRLOG_COUNTER from power_hal\n", __FUNCTION__);
866       goto ERROR;
867     }
868
869     if (l_ErrLogCount >= SS_SM_ERR_LOGGING_LIMIT) {
870       fprintf(stderr, "SS_SysManager/%s/Error: "
871         "Skip StoreDebugLogs by continuous error l_ErrLogCount=%lu\n",
872         __FUNCTION__, l_ErrLogCount);
873       goto ERROR;
874     }
875
876     l_ErrLogCount++;
877     if (PowerHalSetResetInfo(AGL_ERRLOG_COUNTER, l_ErrLogCount)) {
878       // Just logging, don't go to  ERROR.
879       fprintf(stderr, "SS_SysManager/%s/Error: "
880         "Could not write AGL_ERRLOG_COUNTER to power_hal\n", __FUNCTION__);
881     }
882   } else if (type == SS_STORELOGS_ACCOFFON) {
883     if (0 != unlink(SS_LOGGER_SAVE_INTERFACEUNIFIEDLOG_FLAG)) {
884       fprintf(stderr, "SS_SysManager/%s/Error: ACCOFFON LOG SAVE\n", __FUNCTION__);
885     } else {
886       goto ERROR;
887     }
888   }
889
890   pid = fork();
891   if (pid == 0) {
892     int fd = open(SS_SM_TEMP_FILE_FOR_STORE_LOGS,
893         O_CREAT | O_TRUNC | O_RDWR, 00664);
894     if (-1 == fd) {  // LCOV_EXCL_BR_LINE 5:fd must not be -1
895       fprintf(stderr, "SS_SysManager/%s/Error: Failed open %s errno: %d\n",
896               __FUNCTION__, SS_SM_TEMP_FILE_FOR_STORE_LOGS, errno);
897     } else {
898       fsync(fd);
899       close(fd);
900     }
901     FRAMEWORKUNIFIED_SET_ZONES();  // LCOV_EXCL_BR_LINE 15: marco defined in ns_logger_if.h  // NOLINT(whitespace/line_length)
902     NsLogSetLogMethod(LPRINT | LMSGQ);
903
904     if (eFrameworkunifiedStatusOK != (l_eStatus = SS_LoggerStoreLogs(type))) {  // LCOV_EXCL_BR_LINE 200: always return OK
905       AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
906       fprintf(stderr, "SS_SysManager/%s/Error: SS_LoggerStoreDebugLogs() errored: %d\n", __FUNCTION__, l_eStatus);  // LCOV_EXCL_LINE 200: always return OK  // NOLINT(whitespace/line_length)
907     }
908     // Close accessing the RAMD by FRAMEWORKUNIFIEDLOG for RAMD initialization
909     NsForceClose();
910
911     if (0 != unlink(SS_SM_TEMP_FILE_FOR_STORE_LOGS)) {
912       SS_ASERT_ERRNO(0);  // LCOV_EXCL_BR_LINE 15: marco defined in ss_templates.h  // NOLINT(whitespace/line_length)
913     }
914
915     exit(0);
916   } else if (pid == -1) {  // LCOV_EXCL_BR_LINE 5:fork error case
917     // LCOV_EXCL_START 5:fork error case
918     AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
919     fprintf(stderr, "SS_SysManager/%s/Error: ASSERT %d\n", __FUNCTION__, __LINE__);
920     // LCOV_EXCL_STOP
921   } else {
922     if (-1 == waitpid(pid, NULL, 0)) {    // LCOV_EXCL_BR_LINE 5:waitpid error case
923       // LCOV_EXCL_START 5:waitpid error case
924       AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
925       fprintf(stderr, "SS_SysManager/%s/Error: ASSERT %d\n", __FUNCTION__, __LINE__);
926       // LCOV_EXCL_STOP
927     }
928   }
929  ERROR:
930   return isMountRamd;
931 }
932
933 #define SS_SM_SCAC_DEVICE_NODE      "/dev/scac_driver"
934 #define SS_SM_SCAC_CMD_SHUTDOWN     0x3000
935
936 EFrameworkunifiedStatus CSystemManager::SecureChipOff() {
937   static bool isOffDone = false;
938   EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK;
939   int32_t fd;
940   int32_t res;
941
942   if (!isOffDone) {
943     fd = open(SS_SM_SCAC_DEVICE_NODE, O_RDWR);
944     if (fd < 0) {
945       FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "open(%s) ERR", SS_SM_SCAC_DEVICE_NODE);
946       l_eStatus = eFrameworkunifiedStatusFail;
947     } else {
948       res = ioctl(fd, SS_SM_SCAC_CMD_SHUTDOWN);
949       if (res < 0) {  // LCOV_EXCL_BR_LINE 5: standard lib error
950         // LCOV_EXCL_START 5: standard lib error
951         AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
952         FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "ioctl(SS_SM_SCAC_CMD_SHUTDOWN) ERR");
953         l_eStatus = eFrameworkunifiedStatusFail;
954         // LCOV_EXCL_STOP
955       }
956
957       close(fd);
958     }
959
960     isOffDone = true;
961   } else {
962     FRAMEWORKUNIFIEDLOG(ZONE_STATE, __FUNCTION__, "Skip Chip Off");
963   }
964
965   return l_eStatus;
966 }
967
968 UI_32 CSystemManager::InProgressStateToSendMsg() const {
969   UI_32 l_iCmd = SS_SYSTEM_MANAGER_PROTOCOL_ENDING_INDEX;
970   switch (m_SMCurrentState) {
971   case SS_SM_APPS_PRE_START_IN_PROGRESS:
972     l_iCmd = SS_SM_PRE_START;
973     break;
974   case SS_SM_APPS_PRE_STOP_IN_PROGRESS:
975     l_iCmd = SS_SM_PRE_STOP;
976     break;
977   case SS_SM_APPS_BACKGROUND_START_IN_PROGRESS:
978     l_iCmd = SS_SM_BACKGROUND_START;
979     break;
980   case SS_SM_APPS_BACKGROUND_STOP_IN_PROGRESS:
981     l_iCmd = SS_SM_BACKGROUND_STOP;
982     break;
983   case SS_SM_APPS_START_IN_PROGRESS:
984     l_iCmd = SS_SM_START;
985     break;
986   default:
987     break;
988   }
989   return l_iCmd;
990 }
991
992 SMModuleState CSystemManager::InProgressStateToState() const {
993   SMModuleState l_state = MODULE_STATE_INVALID;
994   switch (m_SMCurrentState) {
995   case SS_SM_APPS_PRE_START_IN_PROGRESS:
996     l_state = MODULE_STATE_STARTED_PRE;
997     break;
998   case SS_SM_APPS_PRE_STOP_IN_PROGRESS:
999     l_state = MODULE_STATE_STOPPED_PRE;
1000     break;
1001   case SS_SM_APPS_BACKGROUND_START_IN_PROGRESS:
1002     l_state = MODULE_STATE_STARTED_BACKGROUND;
1003     break;
1004   case SS_SM_APPS_BACKGROUND_STOP_IN_PROGRESS:
1005     l_state = MODULE_STATE_STOPPED_BACKGROUND;
1006     break;
1007   case SS_SM_APPS_START_IN_PROGRESS:
1008     l_state = MODULE_STATE_STARTED;
1009     break;
1010   default:
1011     break;
1012   }
1013   return l_state;
1014 }
1015
1016 ///////////////////////////////////////////////////////////////////////////////
1017 /// \ingroup SetSystemModeInfoStruct
1018 /// Read ( or initialize ) NVM and set the SystemModeInfo structure
1019 ///
1020 /// \return EFrameworkunifiedStatus
1021 /// Success ==> eFrameworkunifiedStatusOK
1022 /// Failure ==> Other values
1023 ///////////////////////////////////////////////////////////////////////////////
1024 EFrameworkunifiedStatus CSystemManager::SetSystemModeInfoStruct() {
1025   FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+");
1026   EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK;
1027
1028   if (m_UsingVMPlayer) {
1029     FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__, " 'm_UsingVMPlayer' is True,"
1030         " using default SystemModeInfo values");
1031     m_SystemModeInfo.limpHomeCutoff = epslhcDISABLED;
1032     m_SystemModeInfo.productionMode = epspmDISABLED;
1033     m_SystemModeInfo.transportMode = epstmDISABLED;
1034     m_SystemModeInfo.systemMode = epssinfNORMAL;
1035     m_DataResetMode = e_SS_SM_DATA_RESET_MODE_NONE;
1036     m_ResetCount = 0;
1037     m_ProgUpdateState = SS_SM_PROG_UPDATE_STATE_NONE;
1038     // Don't change the m_SystemModeInfo.startupStage.
1039     // It is set dynamically as System Manager initializes the _CWORD102_.
1040   } else {
1041     uint32_t tmp = 0;
1042     if (PowerHalGetResetInfo(AGL_RESET_COUNTER, &m_ResetCount)) {
1043       FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__,
1044             "Could not read AGLRESET_COUNTER from power_hal, assume to 0");
1045       m_ResetCount = 0;
1046     }
1047
1048     if (PowerHalGetResetInfo(AGL_PROGUPDATE_STATE, &m_ProgUpdateState)) {
1049       FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__,
1050             "Could not read AGL_PROGUPDATE_STATE from power_hal, "
1051             "assume to SS_SM_PROG_UPDATE_STATE_NONE");
1052       m_ProgUpdateState = SS_SM_PROG_UPDATE_STATE_NONE;
1053     }
1054
1055     if (PowerHalGetResetInfo(AGL_DATARESET_STATE, &tmp)) {
1056       FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__,
1057             "Could not read AGL_DATARESET_STATE from power_hal, "
1058             "assume to e_SS_SM_DATA_REESET_MODE_NONE");
1059       m_DataResetMode = e_SS_SM_DATA_RESET_MODE_NONE;
1060     } else {
1061       m_DataResetMode = static_cast<ESMDataResetModeInfo>(tmp);
1062     }
1063     m_SystemModeInfo.systemMode = epssinfNORMAL;
1064   }  // End else ! m_UsingVMPlayer
1065
1066   FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-");
1067   return l_eStatus;
1068 }  // End of EFrameworkunifiedStatus CSystemManager::SetSystemModeInfoStruct()
1069
1070 ///////////////////////////////////////////////////////////////////////////////
1071 /// \ingroup ClearDramBackupInfo
1072 ///
1073 /// \param [in]
1074 ///
1075 ///
1076 /// \return EFrameworkunifiedStatus
1077 /// Success ==> eFrameworkunifiedStatusOK
1078 /// Failure ==> Other values
1079 ///////////////////////////////////////////////////////////////////////////////
1080 EFrameworkunifiedStatus CSystemManager::ClearDramBackupInfo(HANDLE hApp) {
1081   EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK;
1082   int ret;
1083   FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+");
1084
1085   FRAMEWORKUNIFIEDLOG(ZONE_STATE, __FUNCTION__, "PsmClrRamJudgeFlgPower()");
1086   ret = PsmClrRamJudgeFlgPower(hApp);
1087   if (ret != 0) {  // LCOV_EXCL_BR_LINE 11: Excluded due to gcov constraints (others)
1088     SS_ASERT_ERRNO(0);  // LCOV_EXCL_BR_LINE 15: marco defined in ss_templates.h  // NOLINT(whitespace/line_length)
1089     l_eStatus = eFrameworkunifiedStatusFail;
1090   }
1091
1092   FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-");
1093   return l_eStatus;
1094 }
1095
1096 ///////////////////////////////////////////////////////////////////////////////
1097 /// \ingroup CloseApplication
1098 /// Process request to close Application
1099 ///
1100 /// \param [in]
1101 ///
1102 ///
1103 /// \return EFrameworkunifiedStatus
1104 /// Success ==> eFrameworkunifiedStatusOK
1105 /// Failure ==> Other values
1106 ///////////////////////////////////////////////////////////////////////////////
1107 EFrameworkunifiedStatus CSystemManager::CloseApplication(HANDLE hApp) {  // LCOV_EXCL_START 6: Because the condition cannot be set
1108   AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
1109   EFrameworkunifiedStatus l_eStatus;
1110
1111   FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+");
1112
1113   if (eFrameworkunifiedStatusOK
1114       != (l_eStatus = FrameworkunifiedPublishServiceAvailability(hApp, FALSE))) {
1115     LOG_ERROR("FrameworkunifiedPublishServiceAvailability(hApp,FALSE)");
1116   } else if (eFrameworkunifiedStatusOK != (l_eStatus =
1117       FrameworkunifiedUnRegisterServiceAvailabilityNotification(hApp))) {
1118     LOG_ERROR("FrameworkunifiedUnRegisterServiceAvailabilityNotification(hApp)");
1119   } else {
1120     FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__, " Successful");
1121   }
1122
1123   FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-");
1124   return l_eStatus;
1125 }  // End of EFrameworkunifiedStatus CSystemManager::CloseApplication(HANDLE hApp)
1126 // LCOV_EXCL_STOP
1127
1128 ///////////////////////////////////////////////////////////////////////////////
1129 /// \ingroup SMStateStartCompleteEntry
1130 ///     entry for SM module state(SS_SM_APPS_START_COMPLETE)
1131 ///
1132 /// \param
1133 ///
1134 /// \return EFrameworkunifiedStatus
1135 ///////////////////////////////////////////////////////////////////////////////
1136 VOID CSystemManager::SMStateStartCompleteEntry(HANDLE hApp) {
1137   EFrameworkunifiedStatus l_eStatus;
1138
1139   FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__,
1140       "All %d groups have been sent system_manager protocol message, sending Start Complete to _CWORD56_",
1141       m_SystemStarter.get_id());
1142   CALL_AND_LOG_STATUS_IF_ERRORED(  // LCOV_EXCL_BR_LINE 15: marco defined in ss_templates.h  // NOLINT(whitespace/line_length)
1143       send_power_request_complete_response(hApp, "Startup"));  // LCOV_EXCL_BR_LINE 15: marco defined in ss_templates.h  // NOLINT(whitespace/line_length)
1144
1145   CALL_AND_LOG_STATUS(PublishPowerOnOffNotification(hApp));  // LCOV_EXCL_BR_LINE 15: marco defined in ss_templates.h  // NOLINT(whitespace/line_length)
1146
1147   if (m_InitialBoot == true) {
1148     m_InitialBoot = false;
1149
1150     const ESMServiceWakeupStatus l_svcWupStatus = e_SS_SM_SVC_WAKEUP_STATUS_COMPLETE;
1151
1152     CALL_AND_LOG_STATUS(  // LCOV_EXCL_BR_LINE 15: marco defined in ss_templates.h  // NOLINT(whitespace/line_length)
1153         FrameworkunifiedNPPublishNotification(hApp, NTFY_SSServiceWakeupStatus,  // LCOV_EXCL_BR_LINE 15: marco defined in ss_templates.h  // NOLINT(whitespace/line_length)
1154             &l_svcWupStatus, sizeof(ESMServiceWakeupStatus)));  // LCOV_EXCL_BR_LINE 15: marco defined in ss_templates.h  // NOLINT(whitespace/line_length)
1155
1156     // If all modules are restarted, a passive warning will be issued
1157     // indicating that Heartbeat is already running.
1158
1159     UI_32 l_list_num = static_cast<UI_32>(m_HBList.size());
1160     if (SS_MAX_NUM_MODULES < l_list_num) {
1161       l_list_num = SS_MAX_NUM_MODULES;
1162       FRAMEWORKUNIFIEDLOG(ZONE_WARN, __FUNCTION__,
1163           " Warn: SS_MAX_NUM_MODULES '%d' <  m_HBList.size '%d'",
1164           SS_MAX_NUM_MODULES, l_list_num);
1165     }
1166
1167     CHAR send_data[sizeof(l_list_num)
1168         + (l_list_num * SS_SM_HB_MAX_PROC_NAME_SIZE)
1169         + sizeof(m_SMConfig.HBConfig)];
1170     CHAR* p_prm = &send_data[0];
1171
1172     memcpy(p_prm, reinterpret_cast<char *>(&m_SMConfig.HBConfig), sizeof(m_SMConfig.HBConfig));
1173     p_prm = p_prm + sizeof(m_SMConfig.HBConfig);
1174     memcpy(p_prm, reinterpret_cast<char *>(&l_list_num), sizeof(l_list_num));
1175     p_prm = p_prm + sizeof(l_list_num);
1176
1177     for (UI_32 i = 0; i < l_list_num; i++) {
1178       snprintf(p_prm, SS_SM_HB_MAX_PROC_NAME_SIZE, "%s", m_HBList[i].c_str());
1179       p_prm = p_prm + SS_SM_HB_MAX_PROC_NAME_SIZE;
1180     }
1181     l_eStatus = SendRequestToHeartBeat(hApp, SS_HEARTBEAT_START, &send_data, static_cast<UI_32>(sizeof(send_data)));  // LCOV_EXCL_BR_LINE 11:unexpected branch  // NOLINT(whitespace/line_length)
1182     LOG_ERROR_REC_HIST_IF_ERRORED(l_eStatus, "SendRequestToHeartBeat()");  // LCOV_EXCL_BR_LINE 15: marco defined in ss_templates.h  // NOLINT(whitespace/line_length)
1183
1184     m_DataResetMode = e_SS_SM_DATA_RESET_MODE_NONE;
1185     {
1186       uint32_t tmp = static_cast<uint32_t>(m_DataResetMode);
1187       if (PowerHalSetResetInfo(AGL_DATARESET_STATE, tmp)) {
1188         FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__,
1189              "Could not set AGL_DATARESET_STATE to power_hal");
1190       }
1191     }
1192
1193     m_ProgUpdateState = SS_SM_PROG_UPDATE_STATE_NONE;
1194     if (PowerHalSetResetInfo(AGL_PROGUPDATE_STATE, m_ProgUpdateState)) {
1195       FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__,
1196              "Could not set AGL_PROGUPDATE_STATE to power_hal");
1197     }
1198
1199     m_isIlgReset = FALSE;
1200     {
1201       uint32_t tmp = static_cast<uint32_t>(m_isIlgReset);
1202       if (PowerHalSetResetInfo(AGL_ILLRESET_FLAG, tmp)) {
1203         FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__,
1204              "Could not set AGL_ILLRESET_FLAG to power_hal");
1205       }
1206     }
1207
1208     if (access(SS_SM_TEMP_FILE_FOR_STORE_LOGS, F_OK) == 0) {
1209       SS_ASERT_ERRNO(0 == unlink(SS_SM_TEMP_FILE_FOR_STORE_LOGS));  // LCOV_EXCL_BR_LINE 15: marco defined in ss_templates.h  // NOLINT(whitespace/line_length)
1210     }
1211   }
1212
1213   for (vector<std::string>::iterator protectedSvc =
1214       m_productCustomPrm.protectedSvcs.begin();
1215       protectedSvc != m_productCustomPrm.protectedSvcs.end();
1216       protectedSvc++) {
1217     ModuleLaunchListIter l_ModuleListIter;
1218     l_eStatus = GetModuleIterator(protectedSvc->c_str(), l_ModuleListIter);
1219     if (eFrameworkunifiedStatusOK == l_eStatus) {
1220       if ((l_ModuleListIter->IsModuleState(MODULE_STATE_STARTED))
1221           || (l_ModuleListIter->IsModuleState(MODULE_STATE_LAUNCHED)
1222               && !l_ModuleListIter->is_start_required)) {
1223         char pathBuf[128];
1224
1225         snprintf(pathBuf, 128, "/proc/%d/oom_score_adj", l_ModuleListIter->pid);  // NOLINT
1226         std::ofstream fo(pathBuf);  // LCOV_EXCL_BR_LINE 11:unexpected branch  // NOLINT(whitespace/line_length)
1227         fo << OOM_SCORE_ADJ_MIN << endl;  // LCOV_EXCL_BR_LINE 11:unexpected branch  // NOLINT(whitespace/line_length)
1228         fo.close();  // LCOV_EXCL_BR_LINE 11:unexpected branch  // NOLINT(whitespace/line_length)
1229         FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__, "set OOM_SCORE_ADJ_MIN(%s/%d)",
1230             l_ModuleListIter->name.c_str(), l_ModuleListIter->pid);
1231       } else {
1232         SS_ASERT(0);  // LCOV_EXCL_BR_LINE 15: marco defined in ss_templates.h  // NOLINT(whitespace/line_length)
1233       }
1234     }
1235   }
1236
1237   for (vector<std::string>::iterator groupRelaunchSvc =
1238       m_productCustomPrm.groupRelaunchSvcs.begin();
1239       groupRelaunchSvc != m_productCustomPrm.groupRelaunchSvcs.end();
1240       groupRelaunchSvc++) {
1241     ModuleLaunchListIter l_ModuleListIter;
1242     l_eStatus = GetModuleIterator(groupRelaunchSvc->c_str(), l_ModuleListIter);
1243     if (eFrameworkunifiedStatusOK == l_eStatus) {
1244       if ((l_ModuleListIter->IsModuleState(MODULE_STATE_STARTED))
1245           || (l_ModuleListIter->IsModuleState(MODULE_STATE_LAUNCHED)
1246               && !l_ModuleListIter->is_start_required)) {
1247         GroupRelaunchModuleParams l_param;  // LCOV_EXCL_BR_LINE 11:unexpected branch  // NOLINT(whitespace/line_length)
1248         l_param.name = l_ModuleListIter->name.c_str();
1249         m_GroupRelaunchModuleList.push_back(l_param);
1250
1251         if (l_ModuleListIter->retry_cnt > m_GroupRelaunchLimit) {
1252           m_GroupRelaunchLimit = l_ModuleListIter->retry_cnt;
1253         }
1254
1255         FRAMEWORKUNIFIEDLOG(ZONE_STATE, __FUNCTION__, "GroupRelaunchSvcs:%s(%d)",
1256             l_ModuleListIter->name.c_str(), l_ModuleListIter->pid);
1257       } else {
1258         FRAMEWORKUNIFIEDLOG(ZONE_STATE, __FUNCTION__, "%s is not Launched", groupRelaunchSvc->c_str());
1259       }
1260     } else {
1261       FRAMEWORKUNIFIEDLOG(ZONE_STATE, __FUNCTION__, "%s is not exist", groupRelaunchSvc->c_str());
1262     }
1263   }
1264   FRAMEWORKUNIFIEDLOG(ZONE_STATE, __FUNCTION__, "GroupRelaunchLimit:%d", m_GroupRelaunchLimit);
1265
1266   SendDeferMsg(hApp);  // LCOV_EXCL_BR_LINE 11:unexpected branch  // NOLINT(whitespace/line_length)
1267 }  // End of VOID CSystemManager::SMStateStartCompleteEntry()
1268
1269 ///////////////////////////////////////////////////////////////////////////////
1270 /// \ingroup SMStateEntry
1271 ///     entry for SM module state
1272 ///
1273 /// \param
1274 ///
1275 /// \return EFrameworkunifiedStatus
1276 ///////////////////////////////////////////////////////////////////////////////
1277 VOID CSystemManager::SMStateEntry(HANDLE hApp, SS_SMModuleState l_SMState) {
1278   switch (l_SMState) {
1279   case SS_SM_APPS_START_COMPLETE:
1280   case SS_SM_APPS_PRE_RUN_COMPLETE:
1281   case SS_SM_APPS_BACKGROUND_RUN_COMPLETE:
1282     SMStateStartCompleteEntry(hApp);
1283     break;
1284   default:
1285     break;
1286   }
1287 }  // End of VOID CSystemManager::SMStateEntry(SS_SMModuleState l_SMState)
1288
1289 ///////////////////////////////////////////////////////////////////////////////
1290 /// \ingroup SMStateExit
1291 ///     exit for SM module state
1292 ///
1293 /// \param
1294 ///
1295 /// \return EFrameworkunifiedStatus
1296 ///////////////////////////////////////////////////////////////////////////////
1297 VOID CSystemManager::SMStateExit(HANDLE hApp, SS_SMModuleState l_SMState) {
1298   switch (l_SMState) {
1299   case SS_SM_APPS_START_COMPLETE:
1300     break;
1301   default:
1302     break;
1303   }
1304 }  // End of VOID CSystemManager::SMStateExit(SS_SMModuleState l_SMState)
1305
1306 ///////////////////////////////////////////////////////////////////////////////
1307 /// \ingroup SMSetState
1308 ///     set module state
1309 ///
1310 /// \param
1311 ///
1312 /// \return EFrameworkunifiedStatus
1313 ///////////////////////////////////////////////////////////////////////////////
1314 VOID CSystemManager::SMSetState(HANDLE hApp, SS_SMModuleState l_SMNewState) {
1315   // FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+");
1316   FRAMEWORKUNIFIEDLOG(ZONE_STATE, __FUNCTION__, "%s -> %s",
1317       GetStr(m_SMCurrentState).c_str(), GetStr(l_SMNewState).c_str());
1318
1319   if (l_SMNewState != m_SMCurrentState) {
1320     SMStateExit(hApp, m_SMCurrentState);
1321
1322     m_SMCurrentState = l_SMNewState;
1323
1324     SMStateEntry(hApp, m_SMCurrentState);
1325   }
1326   // FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-");
1327 }
1328
1329 ///////////////////////////////////////////////////////////////////////////////
1330 /// \ingroup register_all_notification_callbacks
1331 ///     register all notifications and callbacks with NP_NPS
1332 ///   this function gets called when NP_NPS reply launch complete
1333 ///
1334 /// \param
1335 ///
1336 /// \return EFrameworkunifiedStatus
1337 ///////////////////////////////////////////////////////////////////////////////
1338 EFrameworkunifiedStatus CSystemManager::register_all_notification_callbacks(HANDLE hApp) {
1339   EFrameworkunifiedStatus l_eStatus;
1340   FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+");
1341
1342   FrameworkunifiedNotificationsList userModeNotificationsBOOL[] = { {
1343       NTFY_SSSystemMgrPowerOnOff, sizeof(BOOL), eFrameworkunifiedStateVar }, {
1344       NTFY_SSSystemMgrUserMode, sizeof(BOOL), eFrameworkunifiedStateVar } };
1345
1346   FrameworkunifiedNotificationsList userModeNotificationsStruct[] = { {
1347       NTFY_SSSystemMgrPowerOnOff,
1348       sizeof(T_SS_SM_UserModeOnOffNotification_Struct), eFrameworkunifiedStateVar }, {
1349       NTFY_SSSystemMgrUserMode,
1350       sizeof(T_SS_SM_UserModeOnOffNotification_Struct), eFrameworkunifiedStateVar } };
1351
1352   FrameworkunifiedNotificationsList sm_notifications[] = {
1353       { NTFY_SSSystemMgrStartUpType, sizeof(EPWR_SC_WAKEUP_TYPE), eFrameworkunifiedStateVar },
1354       { NTFY_SSSystemMgrDataReset, sizeof(ESMDataResetType), eFrameworkunifiedStateVar },
1355       { NTFY_SSSystemMgrShutdownStarted, 0, eFrameworkunifiedStateVar },
1356       { NTFY_SSServiceWakeupStatus, sizeof(ESMServiceWakeupStatus), eFrameworkunifiedStateVar },
1357       { NTFY_SSNeedAplRestart, 0, eFrameworkunifiedStateVar } };
1358
1359   if (m_SMConfig.UMConfig.IsUserModeNotificationABOOL) {
1360     l_eStatus = FrameworkunifiedNPRegisterNotifications(hApp, userModeNotificationsBOOL,
1361         static_cast<UI_32>(_countof(userModeNotificationsBOOL)));
1362   } else {
1363     l_eStatus = FrameworkunifiedNPRegisterNotifications(hApp,
1364         userModeNotificationsStruct,
1365         static_cast<UI_32>(_countof(userModeNotificationsStruct)));
1366   }
1367
1368   if (eFrameworkunifiedStatusOK != l_eStatus) {
1369     LOG_ERROR("FrameworkunifiedNPRegisterNotifications(userModeNotifications)");  // LCOV_EXCL_BR_LINE 15: marco defined in ss_templates.h  // NOLINT(whitespace/line_length)
1370   } else if (eFrameworkunifiedStatusOK != (l_eStatus = FrameworkunifiedNPRegisterNotifications(hApp, sm_notifications, static_cast<UI_32>(_countof(sm_notifications))))) {  // LCOV_EXCL_BR_LINE 4:NSFW error case  //NOLINT (whitespace/line_length)
1371     // LCOV_EXCL_START 4: nsfw error code
1372     AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
1373     LOG_ERROR("FrameworkunifiedNPRegisterNotifications(sm_notifications)");  // LCOV_EXCL_BR_LINE 15: marco defined in ss_templates.h  // NOLINT(whitespace/line_length)
1374     // LCOV_EXCL_STOP
1375   } else if (eFrameworkunifiedStatusOK != (l_eStatus = FrameworkunifiedRegisterServiceAvailabilityNotification(hApp, NTFY_SSSystemMgrAvailability))) {  // LCOV_EXCL_BR_LINE 4:NSFW error case  //NOLINT (whitespace/line_length)
1376     // LCOV_EXCL_START 4: nsfw error code
1377     AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
1378     LOG_ERROR("FrameworkunifiedRegisterServiceAvailabilityNotification("  // LCOV_EXCL_BR_LINE 15: marco defined in ss_templates.h  // NOLINT(whitespace/line_length)
1379         NTFY_SSSystemMgrAvailability ")");  // LCOV_EXCL_BR_LINE 15: marco defined in ss_templates.h  // NOLINT(whitespace/line_length)
1380     // LCOV_EXCL_STOP
1381   } else if (eFrameworkunifiedStatusOK != (l_eStatus = FrameworkunifiedPublishServiceAvailability(hApp, TRUE))) {  // LCOV_EXCL_BR_LINE 4:NSFW error case  //NOLINT (whitespace/line_length)
1382     // LCOV_EXCL_START 4: nsfw error code
1383     AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
1384     LOG_ERROR("FrameworkunifiedPublishServiceAvailability('NTFY_SSSystemMgrAvailability ', TRUE)");  // LCOV_EXCL_BR_LINE 15: marco defined in ss_templates.h  // NOLINT(whitespace/line_length)
1385     // LCOV_EXCL_STOP
1386   } else {
1387     LOG_SUCCESS("FrameworkunifiedPublishServiceAvailability('NTFY_SSSystemMgrAvailability ', TRUE)");  // LCOV_EXCL_BR_LINE 15: marco defined in ss_templates.h  // NOLINT(whitespace/line_length)
1388
1389     REC_HIST_IF_SUCCESSFUL(NTFY_SSSystemMgrAvailability, m_PubCmdHist,  // LCOV_EXCL_BR_LINE 15: marco defined in ss_templates.h  // NOLINT(whitespace/line_length)
1390     m_PubHistIter, "", l_eStatus);  // LCOV_EXCL_BR_LINE 15: marco defined in ss_templates.h  // NOLINT(whitespace/line_length)
1391   }
1392
1393   FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-");
1394   return l_eStatus;
1395 }
1396
1397 ///////////////////////////////////////////////////////////////////////////////
1398 /// \ingroup
1399 ///
1400 /// \param
1401 ///
1402 /// \return
1403 ///////////////////////////////////////////////////////////////////////////////
1404 EFrameworkunifiedStatus CSystemManager::init_Heartbeat(HANDLE hApp) {
1405   EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK;
1406   FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+");
1407
1408   FrameworkunifiedProtocolCallbackHandler hb_protocol_callbacks[] = { {
1409     SS_HEARTBEAT_PERIODIC_RESP, SysMgrCallback<CSystemManager,
1410             &CSystemManager::OnHeartBeatThreadHeartbeatResponse> }, {
1411     SS_HEARTBEAT_ERROR_DETECTED, SysMgrCallback<CSystemManager,
1412             &CSystemManager::OnHeartBeatErrorDetected> }, {
1413     SS_HEARTBEAT_AVAIL_CHECK_RESP, SysMgrCallback<CSystemManager,
1414             &CSystemManager::OnCheckAvailResponse> } };  // LCOV_EXCL_BR_LINE 11:unexpected branch
1415
1416   //  Subscribe to Notifications (All required notifications)
1417   if (eFrameworkunifiedStatusOK != (l_eStatus = FrameworkunifiedAttachCallbacksToDispatcher(hApp, SS_SMHeartbeat, hb_protocol_callbacks, static_cast<UI_32>(_countof(hb_protocol_callbacks))))) {  // LCOV_EXCL_BR_LINE 4:NSFW error case  //NOLINT (whitespace/line_length)
1418     // LCOV_EXCL_START 4: nsfw error
1419     AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
1420     LOG_ERROR("FrameworkunifiedAttachCallbacksToDispatcher(hb_notification_handlers)");
1421     // LCOV_EXCL_STOP
1422   } else if (NULL == (m_hHeartbeatThread.m_ThreadHdl = FrameworkunifiedCreateChildThreadWithPriority(hApp, SS_SMHeartbeat, HBThreadStart, HBThreadStop, PR_SMHEARTBEAT))) {  // LCOV_EXCL_BR_LINE 4:NSFW error case  //NOLINT (whitespace/line_length)
1423     // LCOV_EXCL_START 4: nsfw error
1424     AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
1425     l_eStatus = eFrameworkunifiedStatusThreadNotExist;
1426     m_hHeartbeatThread.m_ThreadState = eSM_ThreadNotExist;
1427     LOG_ERROR("FrameworkunifiedCreateChildThreadWithPriority(hApp, SS_SMHeartbeat)");
1428     // LCOV_EXCL_STOP
1429   } else if (eFrameworkunifiedStatusOK != (l_eStatus = FrameworkunifiedStartChildThread(hApp, m_hHeartbeatThread.m_ThreadHdl, 0, NULL))) {  // LCOV_EXCL_BR_LINE 4:NSFW error case  //NOLINT (whitespace/line_length)
1430     // LCOV_EXCL_START 4: nsfw error
1431     AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
1432     m_hHeartbeatThread.m_ThreadState = eSM_ThreadNotExist;
1433     LOG_ERROR("FrameworkunifiedStartChildThread(SS_SMHeartbeat)");
1434     // LCOV_EXCL_STOP
1435   } else {
1436     m_hHeartbeatThread.m_ThreadState = eSMThreadIsFine;
1437   }
1438
1439   FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-");
1440   return l_eStatus;
1441 }
1442
1443 EFrameworkunifiedStatus CSystemManager::init_sysmem_monitor(HANDLE hApp) {
1444   EFrameworkunifiedStatus l_eStatus;
1445   FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+");
1446
1447   FrameworkunifiedProtocolCallbackHandler sysmem_protocol_callbacks[] = { {
1448       eSysMemThrdCmd_SYS_LOW_MEMORY, SysMgrCallback<CSystemManager,
1449             &CSystemManager::OnLowSystemMemory> } }; // LCOV_EXCL_BR_LINE 11:unexpected branch  // NOLINT(whitespace/line_length)
1450   // LCOV_EXCL_BR_START 4: For setting the initialization conditions at SystemManager startup
1451   if (eFrameworkunifiedStatusOK
1452       != (l_eStatus = FrameworkunifiedAttachCallbacksToDispatcher(
1453             hApp,
1454             m_SysMemMonitor.GetThreadName().c_str(), sysmem_protocol_callbacks,
1455   static_cast<UI_32>(_countof(sysmem_protocol_callbacks))))) {
1456   // LCOV_EXCL_BR_STOP
1457     AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
1458     LOG_ERROR("FrameworkunifiedAttachCallbacksToDispatcher()");  // LCOV_EXCL_LINE 4: For setting the initialization conditions at SystemManager startup
1459   } else {
1460     m_SysMemMonitor.SetSLMConfigData(m_SMConfig.SLMConfig);  // LCOV_EXCL_BR_LINE 11:unexpected branch  // NOLINT(whitespace/line_length)
1461     l_eStatus = m_SysMemMonitor.Initialize(hApp);  // LCOV_EXCL_BR_LINE 11:unexpected branch  // NOLINT(whitespace/line_length)
1462     LOG_ERROR_REC_HIST_IF_ERRORED  // LCOV_EXCL_BR_LINE 6: For setting the initialization conditions at SystemManager startup
1463     (l_eStatus, "m_SysMemMonitor.Initialize(hApp);");  // LCOV_EXCL_BR_LINE 6: For setting the initialization conditions at SystemManager startup
1464   }
1465
1466   FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-");
1467   return l_eStatus;
1468 }
1469
1470 ///////////////////////////////////////////////////////////////////////////////
1471 /// \ingroup
1472 ///
1473 /// \param
1474 ///
1475 /// \return
1476 ///////////////////////////////////////////////////////////////////////////////
1477 EFrameworkunifiedStatus CSystemManager::OnGroupLaunchTimerExpiry(HANDLE hThread) {  // LCOV_EXCL_START 6: Because the condition cannot be set
1478   AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
1479   EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK;
1480   FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+");
1481   UI_32 l_launchID = m_oSystemLauncher.get_id();
1482
1483   FRAMEWORKUNIFIEDLOG(ZONE_PERFORMANCE, __FUNCTION__, " Received from group %d", l_launchID);
1484   REC_HIST_IF_SUCCESSFUL("SM_TIMER_GROUP_MONITOR", m_TimerCmdHist,
1485           m_TimerHistIter, "TIMER", l_eStatus);
1486
1487   LogGroupModulesState(l_launchID,
1488           " Group launch timer expired, processing next group.");
1489
1490   if (NULL == hThread) {
1491     l_eStatus = eFrameworkunifiedStatusInvldParam;
1492     LOG_ERROR("NULL == hThread");
1493   } else {
1494     //    FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "Timer expired for group id,%d",m_oSystemLauncher.get_id());
1495     if (!m_oSystemLauncher.is_end()) {
1496       l_launchID = m_oSystemLauncher.advance_id();
1497       if (eFrameworkunifiedStatusOK != (l_eStatus = OnLaunchGroup(hThread))) {
1498         FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__,
1499             " Error: OnLaunchGroup(%d) errored: %d/'%s'", l_launchID,
1500             l_eStatus, GetStr(l_eStatus).c_str());
1501       }
1502     }
1503   }
1504
1505   FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-");
1506   return l_eStatus;
1507 }  // End of EFrameworkunifiedStatus CSystemManager::OnGroupLaunchTimerExpiry( HANDLE hThread )
1508 // LCOV_EXCL_STOP
1509
1510 ///////////////////////////////////////////////////////////////////////////////
1511 /// \ingroup
1512 ///
1513 /// \param
1514 ///
1515 /// \return
1516 ///////////////////////////////////////////////////////////////////////////////
1517 EFrameworkunifiedStatus CSystemManager::FindNameOfTerminatedProcess(SI_32 f_pid, SS_String &f_ModuleName) {
1518   EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusDbRecNotFound;
1519   FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+");
1520
1521   GroupLaunchMapIter l_GroupIterator = m_MapProclaunchGrps.begin();
1522   if (l_GroupIterator == m_MapProclaunchGrps.end()) {  // LCOV_EXCL_BR_LINE 200: Group Map cannot be empty
1523     // LCOV_EXCL_START 200: Group Map cannot be empty
1524     AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
1525     FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "Error : Group Map empty");  // LCOV_EXCL_BR_LINE 15: marco defined in ns_logger_if.h  // NOLINT(whitespace/line_length)
1526     l_eStatus = eFrameworkunifiedStatusInvldParam;
1527     // LCOV_EXCL_STOP
1528   } else {
1529     BOOL l_bModuleFound = FALSE;
1530     for (; (FALSE == l_bModuleFound)
1531                 && (l_GroupIterator != m_MapProclaunchGrps.end());
1532         l_GroupIterator++) {
1533       ModuleLaunchListIter l_ModuleListIterator =
1534             l_GroupIterator->second.modules.begin();
1535       for (; (FALSE == l_bModuleFound)
1536                     && (l_ModuleListIterator
1537                             != l_GroupIterator->second.modules.end());
1538             l_ModuleListIterator++) {
1539         if (l_ModuleListIterator->pid == f_pid) {
1540             l_bModuleFound = TRUE;
1541             f_ModuleName = l_ModuleListIterator->name;
1542             l_eStatus = eFrameworkunifiedStatusOK;
1543         }
1544       }
1545     }
1546   }
1547   FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-");
1548   return l_eStatus;
1549 }
1550 ///////////////////////////////////////////////////////////////////////////////
1551 /// \ingroup
1552 ///
1553 /// \param
1554 ///
1555 /// \return
1556 ///////////////////////////////////////////////////////////////////////////////
1557 EFrameworkunifiedStatus CSystemManager::GetBinaryNameOfProcess(SS_String f_ModuleQueueName,
1558     SS_String &f_ModuleBinaryName) {
1559   FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+");
1560   EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusFail;
1561   ModuleLaunchListIter l_moduleIter;
1562
1563   f_ModuleBinaryName = "";
1564   l_eStatus = GetModuleIterator(f_ModuleQueueName.c_str(), l_moduleIter);
1565   if (eFrameworkunifiedStatusOK != l_eStatus) {
1566     LOG_ERROR("GetModuleIterator()");  // LCOV_EXCL_BR_LINE 15: marco defined in ss_templates.h  // NOLINT(whitespace/line_length)
1567   } else {
1568     size_t l_pos = l_moduleIter->path.find_last_of("\\/");
1569     if (std::string::npos == l_pos) {  // LCOV_EXCL_BR_LINE 5: stdlib error case.
1570       // LCOV_EXCL_START 5: stdlib error case.
1571       AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
1572       FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__,
1573           " Error. Unable to parse binary name from path %s.",
1574           l_moduleIter->path.c_str());
1575       // LCOV_EXCL_STOP
1576     } else {
1577       f_ModuleBinaryName = l_moduleIter->path.substr(l_pos + 1);
1578       l_eStatus = eFrameworkunifiedStatusOK;
1579     }
1580   }
1581
1582   FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-");
1583   return l_eStatus;
1584 }
1585
1586 ///////////////////////////////////////////////////////////////////////////////
1587 /// \ingroup
1588 ///
1589 /// \param
1590 ///
1591 /// \return
1592 ///////////////////////////////////////////////////////////////////////////////
1593 EFrameworkunifiedStatus CSystemManager::init_process_launcher(HANDLE hApp) {
1594   FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+");
1595   EFrameworkunifiedStatus l_eStatus;
1596   UI_32 TODO = 0;
1597
1598   FrameworkunifiedProtocolCallbackHandler process_launcher_protocol_callbacks[] = {
1599       // Command ID,                      Call back functions
1600       { ePLThrdCmd_LAUNCH_MODULE_RESP,    SysMgrCallback<CSystemManager,
1601                                           &CSystemManager::OnModuleLaunchResponse> },
1602       { ePLThrdCmd_TERMINATE_MODULE_RESP, SysMgrCallback<CSystemManager,
1603                                           &CSystemManager::OnTerminateModuleResponse> },
1604       { ePLThrdCmd_RELAUNCH_MODULE_RESP,  SysMgrCallback<CSystemManager,
1605                                           &CSystemManager::OnReLaunchModuleResponse> },
1606       { ePLThrdCmd_THREAD_STATUS_RESP,    SysMgrCallback<CSystemManager,
1607                                           &CSystemManager::OnProcessLauncherThreadHeartbeatResponse> } }; // LCOV_EXCL_BR_LINE 11:unexpected branch  // NOLINT(whitespace/line_length)
1608
1609   // setup call backs for my children
1610   if (eFrameworkunifiedStatusOK != (l_eStatus = FrameworkunifiedAttachCallbacksToDispatcher(hApp, SS_SMLauncher, process_launcher_protocol_callbacks, static_cast<UI_32>(_countof(process_launcher_protocol_callbacks))))) {  // LCOV_EXCL_BR_LINE 4:NSFW error case  //NOLINT (whitespace/line_length)
1611     AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
1612     LOG_ERROR("FrameworkunifiedAttachCallbacksToDispatcher()");  // LCOV_EXCL_LINE 4: For setting the initialization conditions at SystemManager startup
1613   ////////  Create Writer Child Threads handles the writing of data
1614   } else if (NULL == (m_hProcLauncherThread.m_ThreadHdl = FrameworkunifiedCreateChildThreadWithPriority(hApp, SS_SMLauncher, ProcessLauncherOnStart, ProcessLauncherOnStop, PR_SMPROCLAUNCH))) {  // LCOV_EXCL_BR_LINE 4:NSFW error case  //NOLINT (whitespace/line_length)
1615     // LCOV_EXCL_START 4: For setting the initialization conditions at SystemManager startup
1616     AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
1617     l_eStatus = eFrameworkunifiedStatusNullPointer;
1618     m_hProcLauncherThread.m_ThreadState = eSM_ThreadNotExist;
1619     FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__,
1620         " Error: FrameworkunifiedCreateChildThreadWithPriority(%s) errored: %d/'%s'",
1621         SS_SMLauncher, l_eStatus, GetStr(l_eStatus).c_str());
1622     // LCOV_EXCL_STOP
1623   } else if (eFrameworkunifiedStatusOK != (l_eStatus = FrameworkunifiedStartChildThread(hApp, m_hProcLauncherThread.m_ThreadHdl, sizeof(UI_32), &TODO))) {  // LCOV_EXCL_BR_LINE 4:NSFW error case  //NOLINT (whitespace/line_length)
1624     AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
1625     m_hProcLauncherThread.m_ThreadState =  // LCOV_EXCL_LINE 4: For setting the initialization conditions at SystemManager startup
1626         eSM_ThreadNotExist;  // LCOV_EXCL_LINE 4: For setting the initialization conditions at SystemManager startup
1627     LOG_ERROR("FrameworkunifiedStartChildThread()");  // LCOV_EXCL_LINE 4: For setting the initialization conditions at SystemManager startup
1628   } else {
1629     m_hProcLauncherThread.m_ThreadState = eSMThreadIsFine;
1630   }
1631   FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-");
1632   return l_eStatus;
1633 }
1634
1635 EFrameworkunifiedStatus CSystemManager::OnGroupLaunchWaitTimeout(HANDLE hApp) {
1636   FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+");
1637   EFrameworkunifiedStatus l_eStatus;
1638   SetCmdHist("SM_TIMER_GROUP_LAUNCH_WAIT_TIMER", m_TimerCmdHist, m_TimerHistIter, FrameworkunifiedGetMsgSrc(hApp)); // LCOV_EXCL_BR_LINE 11:unexpected branch  // NOLINT(whitespace/line_length)
1639   CALL_AND_LOG_STATUS(OnLaunchGroup(hApp));  // LCOV_EXCL_BR_LINE 15: marco defined in ss_templates.h  // NOLINT(whitespace/line_length)
1640   FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-");
1641   return l_eStatus;
1642 }
1643
1644 ///////////////////////////////////////////////////////////////////////////////
1645 /// \ingroup
1646 ///
1647 /// \param
1648 ///
1649 /// \return
1650 ///////////////////////////////////////////////////////////////////////////////
1651 EFrameworkunifiedStatus CSystemManager::OnModuleLaunchResponse(HANDLE hApp) {
1652   FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+");
1653   EFrameworkunifiedStatus l_eStatus;
1654   INTERFACEUNIFIEDLOG_RECEIVED_FROM(hApp);  // LCOV_EXCL_BR_LINE 15: marco defined in ns_logger_if.h  // NOLINT(whitespace/line_length)
1655   FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__, "from %s", FrameworkunifiedGetMsgSrc(hApp));
1656
1657   GroupLaunchMapIter l_GroupIter;
1658   ModuleLaunchListIter l_ModuleIter;
1659   UI_32 l_launchID = m_oSystemLauncher.get_id();
1660
1661   l_eStatus = PerformModuleLaunchRespProcessing(hApp, l_GroupIter, l_ModuleIter, "ML");
1662   if (eFrameworkunifiedStatusOK != l_eStatus) {
1663     LOG_ERROR("PerformModuleLaunchRespProcessing()");  // LCOV_EXCL_BR_LINE 15: marco defined in ss_templates.h  // NOLINT(whitespace/line_length)
1664   } else if (l_GroupIter->second.id == l_launchID) {
1665     BOOL IsGroupLaunchComplete = TRUE;
1666     // Search the group for any module that has not completed launching.
1667     for (l_ModuleIter = l_GroupIter->second.modules.begin();
1668          IsGroupLaunchComplete && (l_ModuleIter != l_GroupIter->second.modules.end());
1669          l_ModuleIter++) {
1670       IsGroupLaunchComplete = !l_ModuleIter->IsModuleState(MODULE_STATE_LAUNCHING);
1671     }
1672
1673     if (IsGroupLaunchComplete) {
1674       m_GroupLaunchTimer->StopTimer(m_aTimerIDs[eSM_TIMER_GROUP_MONITOR]);
1675       l_GroupIter->second.launch_complete = TRUE;
1676       FRAMEWORKUNIFIEDLOG(ZONE_STATE, __FUNCTION__, "Group%d LaunchComp", l_GroupIter->second.id);
1677
1678       if (!m_oSystemLauncher.is_end()) {
1679         l_launchID = m_oSystemLauncher.advance_id();
1680         FRAMEWORKUNIFIEDLOG(ZONE_STATE, __FUNCTION__, "Next group:%d", l_launchID);
1681         if (FALSE == l_GroupIter->second.grp_wait_for_trigger) {
1682           UI_32 l_Sec = (l_GroupIter->second.grp_launch_wait) / (1000 * 1000);
1683           UI_32 l_mSec = 0;
1684           if (l_Sec > 0) {
1685               l_mSec = ((l_GroupIter->second.grp_launch_wait) % (1000 * 1000)) / 1000;
1686           } else {
1687               l_mSec = (l_GroupIter->second.grp_launch_wait) / 1000;
1688           }
1689           m_GroupLaunchTimer->StartTimer(
1690                   m_aTimerIDs[eSM_TIMER_GROUP_LAUNCH_WAIT_TIMER], l_Sec, l_mSec, 0, 0);
1691         } else {
1692           // Start the timer for group trigger... added for optimization
1693           m_GroupLaunchTimer->StartTimer(
1694                   m_aTimerIDs[eSM_TIMER_LAUNCH_GROUP_TRIGGER_PROC_RESP_TIMER],
1695                   SS_LAUNCH_GROUP_TRIGGER_TIMER_CONFIG, 0, 0, 0);
1696         }
1697       }
1698     } else {
1699       FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__, " Group %d/%s LaunchIncomp", l_launchID,
1700           l_GroupIter->second.name.c_str());
1701     }
1702   } else {
1703     FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__,
1704         " '%s' ( Group %d/%s ) Launch Response received late - "
1705                 "group id is now %d", l_ModuleIter->name.c_str(),
1706         l_GroupIter->second.id, l_GroupIter->second.name.c_str()
1707         , l_launchID);
1708   }
1709   FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-");
1710   return l_eStatus;
1711 }
1712
1713 EFrameworkunifiedStatus CSystemManager::OnReLaunchModuleResponse(HANDLE hApp) {
1714   FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+");
1715   EFrameworkunifiedStatus l_eStatus;
1716   INTERFACEUNIFIEDLOG_RECEIVED_FROM(hApp);  // LCOV_EXCL_BR_LINE 15: marco defined in ss_templates.h  // NOLINT(whitespace/line_length)
1717   FRAMEWORKUNIFIEDLOG(ZONE_PERFORMANCE, __FUNCTION__, "from %s", FrameworkunifiedGetMsgSrc(hApp));
1718
1719   GroupLaunchMapIter l_GroupIter;
1720   ModuleLaunchListIter l_ModuleIter;
1721
1722   l_eStatus = PerformModuleLaunchRespProcessing(hApp, l_GroupIter, l_ModuleIter, "RL");
1723   LOG_ERROR_REC_HIST_IF_ERRORED(l_eStatus, "PerformModuleLaunchRespProcessing()");  // LCOV_EXCL_BR_LINE 15: marco defined in ss_system_manager.h  // NOLINT(whitespace/line_length)
1724
1725   FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-");
1726   return l_eStatus;
1727 }  // End of EFrameworkunifiedStatus CSystemManager::OnReLaunchModuleResponse( HANDLE hApp )
1728
1729
1730 EFrameworkunifiedStatus CSystemManager::PerformModuleLaunchRespProcessing(HANDLE hApp,
1731         GroupLaunchMapIter & f_GroupIter, ModuleLaunchListIter & f_ModuleIter,
1732         PCSTR p_sPPD_tag) {
1733   FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+");
1734   EFrameworkunifiedStatus l_eStatus;
1735   T_ProcessLaunchResp l_LaunchRespData;
1736
1737   // ReadMsg():                                                        *
1738   //     Check hApp ptr, msg size, msg reception, read msg if all ok.  *
1739   //     Report any errors found.                                      *
1740   //                                                                   *
1741   if (eFrameworkunifiedStatusOK != (l_eStatus = ReadMsg < T_ProcessLaunchResp > (hApp, l_LaunchRespData))) {  // LCOV_EXCL_BR_LINE 4: nsfw error  // NOLINT(whitespace/line_length)
1742     AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
1743     LOG_ERROR("ReadMsg()");  // LCOV_EXCL_LINE 4: nsfw error
1744   } else {
1745     BOOL b_DidModuleLaunch = FALSE;
1746     f_GroupIter = l_LaunchRespData.groupIterator;
1747     f_ModuleIter = l_LaunchRespData.moduleIterator;
1748     SS_String l_ModulePath = l_LaunchRespData.path;
1749
1750     FRAMEWORKUNIFIEDLOG(ZONE_PERFORMANCE, __FUNCTION__, "%s(%d)", l_LaunchRespData.name, l_LaunchRespData.pid);
1751
1752     if (l_LaunchRespData.pid == -1) {
1753       f_ModuleIter->pid = -1;
1754
1755       FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, " Error: Process launch failed: %s, %s",
1756           f_ModuleIter->name.c_str(), l_ModulePath.c_str());
1757
1758       /// TODO
1759       /// If PID is -1, launch had failed. Add logic to do necessary action.
1760
1761       f_ModuleIter->SetModuleState(MODULE_STATE_LAUNCH_FAILED);
1762     } else if (l_LaunchRespData.pid == 0x7FFFFFFF) {
1763       FRAMEWORKUNIFIEDLOG(ZONE_WARN, __FUNCTION__, " Warning: '%s', '%s' already launched",
1764           f_ModuleIter->name.c_str(), l_ModulePath.c_str());
1765
1766       b_DidModuleLaunch = TRUE;
1767     } else {
1768       f_ModuleIter->pid = l_LaunchRespData.pid;
1769       b_DidModuleLaunch = TRUE;
1770     }
1771
1772     if (b_DidModuleLaunch) {
1773       //
1774       // Module state could already be MODULE_STATE_CONNECTED if
1775       // module process ran before process launcher thread completed;
1776       // don't overwrite/reset the MODULE_STATE_CONNECTED state.
1777       if (f_ModuleIter->IsModuleState(MODULE_STATE_LAUNCHING)) {
1778         f_ModuleIter->SetModuleState(MODULE_STATE_LAUNCHED);
1779       }
1780
1781       l_eStatus = f_ModuleIter->GetPriority(f_ModuleIter->current_priority);
1782       if (eFrameworkunifiedStatusOK != l_eStatus) {
1783         FRAMEWORKUNIFIEDLOG(ZONE_WARN, __FUNCTION__, " Warning: f_ModuleIter->GetPriority( "
1784                "f_ModuleIter->current_priority ) returned %d/'%s'. "
1785                "Setting 'current_priority' = 'configuration_priority' %d.",
1786                l_eStatus, GetStr(l_eStatus).c_str(),
1787                f_ModuleIter->configuration_priority);
1788         f_ModuleIter->current_priority = f_ModuleIter->configuration_priority;
1789         l_eStatus = eFrameworkunifiedStatusOK;
1790       }
1791     }
1792   }
1793   FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-");
1794   return l_eStatus;
1795 }  // End of EFrameworkunifiedStatus CSystemManager::PerformModuleLaunchRespProcessing(
1796
1797 ///////////////////////////////////////////////////////////////////////////////
1798 /// \ingroup OnTerminateModuleResponse
1799 ///
1800 /// \param HANDLE hApp
1801 ///
1802 /// \return EFrameworkunifiedStatus
1803 ///////////////////////////////////////////////////////////////////////////////
1804 EFrameworkunifiedStatus CSystemManager::OnTerminateModuleResponse(HANDLE hApp) {
1805   FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+");
1806   EFrameworkunifiedStatus l_eStatus;
1807   T_ProcessLauncherTerminationResp l_TerminateRespData;
1808   INTERFACEUNIFIEDLOG_RECEIVED_FROM(hApp);  // LCOV_EXCL_BR_LINE 15: marco defined in ss_templates.h  // NOLINT(whitespace/line_length)
1809   FRAMEWORKUNIFIEDLOG(ZONE_STATE, __FUNCTION__, " from %s", FrameworkunifiedGetMsgSrc(hApp));
1810
1811   // ReadMsg():                                                        *
1812   //     Check hApp ptr, msg size, msg reception, read msg if all ok.  *
1813   //     Report any errors found.                                      *
1814   //                                                                   *
1815   if (eFrameworkunifiedStatusOK != (l_eStatus = ReadMsg < T_ProcessLauncherTerminationResp
1816                        > (hApp, l_TerminateRespData))) {
1817     LOG_ERROR("ReadMsg()");  // LCOV_EXCL_BR_LINE 15: marco defined in ss_templates.h  // NOLINT(whitespace/line_length)
1818   } else {
1819     ModuleLaunchListIter l_ModuleIter = l_TerminateRespData.moduleIterator;
1820
1821     SS_String l_ModulePath = m_BinaryFilesPath + l_ModuleIter->path;
1822
1823     if ((0 == strcmp(l_ModulePath.c_str(), l_TerminateRespData.path))
1824         && (0 == strcmp(l_ModuleIter->arguments.c_str(),
1825                         l_TerminateRespData.args))) {
1826       l_ModuleIter->pid = 0;
1827       FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__, " %s Termination successful",
1828              l_ModuleIter->name.c_str());
1829     } else {
1830       if (0 != strcmp(l_ModulePath.c_str(), l_TerminateRespData.path)) {
1831         FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__,
1832             " Error: ModuleIter->path != l_TerminateRespData.path"
1833             " \" '%s' != '%s' \"", l_ModuleIter->path.c_str(),
1834             l_TerminateRespData.path);
1835       }
1836       if (0 != strcmp(l_ModuleIter->arguments.c_str(),
1837                       l_TerminateRespData.args)) {
1838         FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, " Error: ModuleIter->arguments != "
1839             "l_TerminateRespData.args, \" '%s' != '%s' \"",
1840             l_ModuleIter->arguments.c_str(), l_TerminateRespData.args);
1841       }
1842     }
1843   }
1844
1845   FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-");
1846   return l_eStatus;
1847 }  // End of EFrameworkunifiedStatus CSystemManager::OnTerminateModuleResponse( HANDLE hApp )
1848
1849 ///////////////////////////////////////////////////////////////////////
1850 /// \ingroup ReadPathAndFileNameEnvironmentVariables
1851 ///
1852 /// \param
1853 ///
1854 /// \return VOID
1855 ///////////////////////////////////////////////////////////////////////////////
1856 VOID CSystemManager::ReadPathFromEnvironmentVariables() {
1857   FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+");  // LCOV_EXCL_BR_LINE 15: marco defined in ns_logger_if.h  // NOLINT(whitespace/line_length)
1858   CHAR *l_pEnvVariable = NULL;
1859
1860   // read Path from environment variable
1861   if (NULL == (l_pEnvVariable = std::getenv(BaseDirPathEnvVariable))) {
1862     // Environment variable not set, set it to default path
1863     FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__, "Using Default path for Binary Files : %s", DefaultBasePath);
1864     m_BinaryFilesPath = DefaultBasePath;
1865
1866     FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__, "Using Default path for Config Files : %s%s",
1867         DefaultBasePath, DefaultConfigFilesPath);
1868     m_ConfigFilesPath = DefaultBasePath;
1869   } else {
1870     // set path of binary files
1871     m_BinaryFilesPath = l_pEnvVariable;
1872
1873     // set path of configuration files
1874     m_ConfigFilesPath = l_pEnvVariable;
1875   }
1876   // set path of configuration files
1877   m_ConfigFilesPath += DefaultConfigFilesPath;
1878
1879   FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-");
1880   return;
1881 }
1882
1883 ///////////////////////////////////////////////////////////////////////
1884 /// \ingroup GetConfigDataFileNameFromEnvironmentVariable
1885 ///
1886 /// \param
1887 ///
1888 /// \return SS_String
1889 ///////////////////////////////////////////////////////////////////////////////
1890 SS_String CSystemManager::ReadLaunchConfigFileNameFromEnvironmentVariable() {
1891   FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+");
1892   CHAR *l_pEnvVariable = NULL;
1893   SS_String l_FileName;
1894
1895   // read Launch Config File Name from environment variable
1896   // LCOV_EXCL_BR_START 5: standard lib error
1897   if (NULL == (l_pEnvVariable = std::getenv(LaunchConfigFileNameEnvVariable))) {
1898   // LCOV_EXCL_BR_STOP
1899     // Environment variable not set, set it to default file name
1900     // LCOV_EXCL_START 5: standard lib error
1901     AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
1902     FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__, " Using Default Launch Configuration file : %s",
1903         DefaultLaunchConfigFileName);
1904     l_FileName = DefaultLaunchConfigFileName;
1905     // LCOV_EXCL_STOP
1906   } else {
1907     l_FileName = l_pEnvVariable;
1908   }
1909
1910   FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__, " Using Launch Configuration file: %s", l_FileName.c_str());
1911
1912   SS_String retStr = m_ConfigFilesPath + l_FileName; // LCOV_EXCL_BR_LINE 11:unexpected branch  // NOLINT(whitespace/line_length)
1913   if (access(retStr.c_str(), F_OK) != 0) {  // LCOV_EXCL_BR_LINE 5: standard lib error
1914     // LCOV_EXCL_START 5: standard lib error
1915     AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
1916     FRAMEWORKUNIFIEDLOG(ZONE_WARN, __FUNCTION__, "no found %s", retStr.c_str());
1917     SS_ASERT(0);
1918     // LCOV_EXCL_STOP
1919   }
1920   return retStr;
1921 }
1922
1923 ///////////////////////////////////////////////////////////////////////
1924 /// \ingroup GetConfigDataFileNameFromEnvironmentVariable
1925 ///
1926 /// \param
1927 ///
1928 /// \return SS_String
1929 ///////////////////////////////////////////////////////////////////////////////
1930 SS_String CSystemManager::ReadConfigDataFileNameFromEnvironmentVariable() {
1931   FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+");
1932   CHAR *l_pEnvVariable = NULL;
1933   SS_String l_FileName = "";
1934
1935   // read SM Config Data File Name from environment variable
1936   // LCOV_EXCL_BR_START 5: standard lib error
1937   if (NULL == (l_pEnvVariable = std::getenv(SMConfigDataFileNameEnvVariable))) {
1938   // LCOV_EXCL_BR_STOP 5: standard lib error
1939     // LCOV_EXCL_START 5: standard lib error
1940     AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
1941     // Environment variable not set, set it to default file name
1942     FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__, "Using Default Configuration Data file : %s", DefaultSMConfigFileName);
1943     l_FileName = DefaultSMConfigFileName;
1944     // LCOV_EXCL_STOP
1945   } else {
1946     l_FileName = l_pEnvVariable;
1947   }
1948
1949   SS_String retStr = m_ConfigFilesPath + l_FileName; // LCOV_EXCL_BR_LINE 11:unexpected branch  // NOLINT(whitespace/line_length)
1950   if (access(retStr.c_str(), F_OK) != 0) {  // LCOV_EXCL_BR_LINE 5: standard lib error
1951     // LCOV_EXCL_START 5: standard lib error
1952     AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
1953     FRAMEWORKUNIFIEDLOG(ZONE_WARN, __FUNCTION__, "no found %s", retStr.c_str());
1954     SS_ASERT(0);
1955     // LCOV_EXCL_STOP
1956   }
1957   FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-");
1958   return retStr;
1959 }
1960
1961 ///////////////////////////////////////////////////////////////////////
1962 /// \ingroup ReadUsingVMPlayerEnvironmentVariable
1963 ///
1964 /// \param
1965 ///
1966 /// \return VOID
1967 ///////////////////////////////////////////////////////////////////////////////
1968 VOID CSystemManager::ReadUsingVMPlayerEnvironmentVariable() {
1969   FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+");
1970   CHAR *l_pEnvVariable = std::getenv(UsingVMPlayerVariable);
1971   m_UsingVMPlayer = (NULL != l_pEnvVariable);
1972   FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__, " %sunning on a VMPlayer",
1973       m_UsingVMPlayer ? "R" : "Not r");
1974   FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-");
1975   return;
1976 }  // End of VOID CSystemManager::ReadUsingVMPlayerEnvironmentVariable()
1977
1978 ///////////////////////////////////////////////////////////////////////////////
1979 /// \ingroup
1980 ///
1981 /// \param
1982 ///
1983 /// \return
1984 ///////////////////////////////////////////////////////////////////////////////
1985 EFrameworkunifiedStatus CSystemManager::start_process_launching(HANDLE hApp) {
1986   FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+");
1987   EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK;
1988   BOOL l_bIsGoodRc;
1989   SS_String l_SMConfigFile(ReadConfigDataFileNameFromEnvironmentVariable());
1990   SMConfigParams SMConfigData;
1991   SS_String l_LaunchConfigFile(ReadLaunchConfigFileNameFromEnvironmentVariable()); // LCOV_EXCL_BR_LINE 11:unexpected branch  // NOLINT(whitespace/line_length)
1992   SysMgrConfiguration l_launchConfig;
1993
1994   FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__, " Reading %s Configuration Data from %s",
1995       SERVICE_SYSMANAGER, l_SMConfigFile.c_str());
1996
1997   l_bIsGoodRc = SMConfigData.LoadSMConfigParameters(m_SMConfig, l_SMConfigFile);
1998
1999   if (!l_bIsGoodRc) {  // LCOV_EXCL_BR_LINE 6: For setting the initialization conditions at SystemManager startup
2000     // LCOV_EXCL_START 6: For setting the initialization conditions at SystemManager startup
2001     AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
2002     FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__,
2003         " Error: SMConfigData.LoadSMConfigParameters(m_SMConfig, "
2004                 " %s) returned FALSE", l_SMConfigFile.c_str());
2005     l_eStatus = eFrameworkunifiedStatusFileLoadError;
2006     // LCOV_EXCL_STOP
2007   } else {
2008     SMSetState(hApp, SS_SM_APPS_LAUNCH_IN_PROGRESS);  // LCOV_EXCL_BR_LINE 11:unexpected branch  // NOLINT(whitespace/line_length)
2009     FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__, " Reading Launch Configuration Data from %s",
2010         l_LaunchConfigFile.c_str());
2011
2012     SS_String l_launchOrderName = "DEFAULT";  // LCOV_EXCL_BR_LINE 11:unexpected branch  // NOLINT(whitespace/line_length)
2013     LaunchOrderedVector l_OrderList;
2014
2015     l_bIsGoodRc = l_launchConfig.LoadParametersCfg(m_MapProclaunchGrps,
2016         m_MapProcNames, l_OrderList, l_launchOrderName, l_LaunchConfigFile);
2017
2018     if (l_OrderList.size() != 0) {  // LCOV_EXCL_BR_LINE 6: For setting the initialization conditions at SystemManager startup
2019       AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
2020       FRAMEWORKUNIFIEDLOG(ZONE_STATE, __FUNCTION__, "wakeup order:%s",
2021           l_launchOrderName.c_str());
2022     } else {
2023       FRAMEWORKUNIFIEDLOG(ZONE_STATE, __FUNCTION__, "wakeup order:DEFAULT");
2024     }
2025
2026     if (!l_bIsGoodRc) {  // LCOV_EXCL_BR_LINE 6: For setting the initialization conditions at SystemManager startup
2027       // LCOV_EXCL_START 6: For setting the initialization conditions at SystemManager startup
2028       AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
2029       FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, " Error: l_launchConfig.LoadParametersCfg( "
2030           "m_MapProclaunchGrps, m_MapProcNames, %s ) returned FALSE",
2031           l_LaunchConfigFile.c_str());
2032       l_eStatus = eFrameworkunifiedStatusFileLoadError;
2033       // LCOV_EXCL_STOP
2034     } else {
2035       m_SystemLaunchProgress = SS_SM_INITIAL_GROUP;
2036       // l_launchConfig.PrintAllInfo( m_MapProclaunchGrps );
2037
2038       FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__, " System Launch Started");
2039       // Don't use DynamicLaunch because its dependency on the services table is complex
2040       SS_SOURCE source_type = SS_SOURCE_FM;
2041
2042       m_oSystemLauncher.configure_dynamic_launch(source_type, m_MapProclaunchGrps, l_OrderList);
2043       m_oSystemLauncher.copyDynOrderedVector(m_SystemStarter);
2044       // m_SystemStarter.print_info();
2045
2046       // start the timer upon successful launching of first process
2047       FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__,
2048           "Starting Module Connection Timeout timer with %d sec period",
2049           m_SMConfig.MCConfig.ModuleConnectionTimeOutSec);
2050       m_GroupLaunchTimer->StartTimer(
2051           m_aTimerIDs[eSM_TIMER_MODULE_CONNECT_WAIT_TIMER],
2052           m_SMConfig.MCConfig.ModuleConnectionTimeOutSec, 0,
2053           m_SMConfig.MCConfig.ModuleConnectionTimeOutSec, 0);  // LCOV_EXCL_BR_LINE 11:unexpected branch  // NOLINT(whitespace/line_length)
2054       CALL_AND_LOG_STATUS(OnLaunchGroup(hApp));  // LCOV_EXCL_BR_LINE 6: For setting the initialization conditions at SystemManager startup
2055     }
2056   }
2057
2058   FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-");
2059   return l_eStatus;
2060 }
2061
2062
2063 EFrameworkunifiedStatus CSystemManager::GetLastSourceInfo(SS_SOURCE &source_type) {  // LCOV_EXCL_START 8: Because the condition cannot be set
2064   AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
2065   FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+");
2066   EFrameworkunifiedStatus l_eStatus;
2067
2068   CHAR LastSource[64 + 1] = { '\0' };
2069   l_eStatus = NPSynchronousReadPersistentData(SERVICE_AS_MODE,
2070               NTFY_SSLastSourceType, LastSource, static_cast<UI_32>(sizeof(LastSource) - 1));
2071   if (eFrameworkunifiedStatusOK != l_eStatus) {
2072     LOG_ERROR("NPSynchronousReadPersistentData("
2073               SERVICE_AS_MODE "," NTFY_SSLastSourceType);
2074   } else {
2075     std::string tempstr(LastSource);
2076     FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__, " String got from persistence %s", LastSource);
2077     UI_32 pos = static_cast<UI_32>(tempstr.find("_"));
2078     std::string tempstr2 = tempstr.substr(0, pos);
2079     UI_64 value = strtoull(tempstr2.c_str(), 0, 10);
2080     source_type = static_cast<SS_SOURCE>((UI_32)(value >> 32) & 0x0000FFFF);
2081   }
2082   FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-");
2083   return l_eStatus;
2084 }
2085
2086 EFrameworkunifiedStatus CSystemManager::OnLaunchGroupTriggerProcessResponse(HANDLE hApp) {
2087   AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
2088   FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+");
2089   EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK;
2090   INTERFACEUNIFIEDLOG_RECEIVED_FROM(hApp);
2091   UI_32 l_groupID;
2092
2093   FRAMEWORKUNIFIEDLOG(ZONE_STATE, __FUNCTION__, "from %s", FrameworkunifiedGetMsgSrc(hApp));
2094   SetCmdHist("SS_SM_GROUP_LAUNCH_TRIGGER", m_SMCmdHist, m_SMHistIter, FrameworkunifiedGetMsgSrc(hApp));
2095   // stop group launch trigger process response timer
2096   m_GroupLaunchTimer->StopTimer(m_aTimerIDs[eSM_TIMER_LAUNCH_GROUP_TRIGGER_PROC_RESP_TIMER]);
2097
2098   if (eFrameworkunifiedStatusOK != (l_eStatus = ReadMsg < UI_32 > (hApp, l_groupID))) {
2099     LOG_ERROR("ReadMsg()");
2100   } else {
2101     SS_SOURCE source_type = SS_SOURCE_NA;
2102     l_eStatus = GetLastSourceInfo(source_type);
2103
2104     if ((SS_SOURCE_AM == source_type) || (SS_SOURCE_FM == source_type)
2105      || (SS_SOURCE_FM_DAB == source_type) || (SS_SOURCE_SDARS == source_type)) {
2106       if (l_groupID == m_oSystemLauncher.get_id()) {
2107         CALL_AND_LOG_STATUS(OnLaunchGroup(hApp));
2108       } else {
2109         FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__,
2110             " Error: Received Group ID %d != Sys Mgr Group ID %d", l_groupID,
2111             m_oSystemLauncher.get_id());
2112         l_eStatus = eFrameworkunifiedStatusInvldParam;
2113      }
2114     } else {  // media is last source
2115       CALL_AND_LOG_STATUS(OnLaunchGroup(hApp));
2116     }
2117   }
2118
2119   FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-");
2120   return l_eStatus;
2121 }
2122
2123 EFrameworkunifiedStatus CSystemManager::OnLaunchGroupTriggerProcessResponseTimerExpiry(HANDLE hApp) {
2124   AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
2125   FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+");
2126   EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK;
2127   INTERFACEUNIFIEDLOG_RECEIVED_FROM(hApp);
2128   REC_HIST_IF_SUCCESSFUL("SM_TIMER_LAUNCH_GROUP_TRIGGER", m_TimerCmdHist,
2129                          m_TimerHistIter, FrameworkunifiedGetMsgSrc(hApp), l_eStatus);
2130   CALL_AND_LOG_STATUS(OnLaunchGroup(hApp));
2131
2132   FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-");
2133   return l_eStatus;
2134 }
2135
2136 ///////////////////////////////////////////////////////////////////////////////
2137 /// \ingroup
2138 ///
2139 /// \param
2140 ///
2141 /// \return
2142 ///////////////////////////////////////////////////////////////////////////////
2143 EFrameworkunifiedStatus CSystemManager::OnLaunchGroupSelfTrigger(HANDLE hApp) {
2144   AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
2145   FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+");
2146   EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK;
2147
2148   FRAMEWORKUNIFIEDLOG(ZONE_STATE, __FUNCTION__, "from %s", FrameworkunifiedGetMsgSrc(hApp));
2149
2150   REC_HIST_IF_SUCCESSFUL("SS_SM_SendTriggerToSelf", m_SMCmdHist, m_SMHistIter,
2151                          FrameworkunifiedGetMsgSrc(hApp), l_eStatus);
2152
2153   CALL_AND_LOG_STATUS(OnLaunchGroup(hApp));
2154
2155   FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-");
2156   return l_eStatus;
2157 }
2158 // LCOV_EXCL_STOP
2159
2160 ///////////////////////////////////////////////////////////////////////////////
2161 /// \ingroup
2162 ///
2163 /// \param
2164 ///
2165 /// \return
2166 ///////////////////////////////////////////////////////////////////////////////
2167 EFrameworkunifiedStatus CSystemManager::OnLaunchGroup(HANDLE hApp) {
2168   FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+");
2169   EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK;
2170   GroupLaunchMapIter l_GroupIter;
2171   UI_32 l_launch_ID = m_oSystemLauncher.get_id();
2172
2173   //  FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__, " Launching group %d", l_launch_ID );
2174
2175   l_GroupIter = m_MapProclaunchGrps.find(l_launch_ID);
2176
2177   if (l_GroupIter->second.launch_complete == FALSE) {  // LCOV_EXCL_BR_LINE 6: Because it is not called for a condition that results in "TRUE"
2178     // FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__
2179     //     , " m_bIsNPP_ServicesStarted ? %s, group.id: %d, Launch_Group: %d"
2180     //     , m_bIsNPP_ServicesStarted ? "Yes" : "No"
2181     //     , l_GroupIter->second.id
2182     //     , m_SystemLaunchProgress );
2183
2184     if ((m_bIsNPP_ServicesStarted && m_bIsBackupAvail) || (l_GroupIter->second.id <= 2)) {  // LCOV_EXCL_BR_LINE 6: Because it is not called for the condition that results in "FALSE" // NOLINT(whitespace/line_length)
2185       ModuleLaunchListIter l_ModuleListIterator = l_GroupIter->second.modules.begin();
2186       if (l_ModuleListIterator != l_GroupIter->second.modules.end()) {  // LCOV_EXCL_BR_LINE 6: For setting the initialization conditions at SystemManager startup // NOLINT(whitespace/line_length)
2187         // FRAMEWORKUNIFIEDLOG(ZONE_PERFORMANCE, __FUNCTION__, "GRPLCH,(start),%d,%s",
2188         //        l_GroupIter->second.id,l_GroupIter->second.name.c_str());
2189
2190         FRAMEWORKUNIFIEDLOG(ZONE_STATE, __FUNCTION__, "Launching Group%d/%s",
2191             l_GroupIter->second.id, l_GroupIter->second.name.c_str());
2192         SS_String l_ModulePath;
2193         for (; l_ModuleListIterator != l_GroupIter->second.modules.end(); l_ModuleListIterator++) {
2194           if (l_ModuleListIterator->IsModuleState(MODULE_STATE_INVALID)) {
2195             char l_cFormat[] = "SendRequestToLauncher(%s, "
2196                     "ePLThrdCmd_LAUNCH_MODULE_REQST)";
2197             char l_cBuf[sizeof(l_cFormat) + MAX_NAME_SIZE_APP];
2198             snprintf(l_cBuf, sizeof(l_cBuf), l_cFormat,
2199                     l_ModuleListIterator->name.c_str());
2200
2201             l_eStatus = SendRequestToLauncher(hApp, l_ModuleListIterator,  // LCOV_EXCL_BR_LINE 11:unexpected branch  // NOLINT(whitespace/line_length)
2202                     ePLThrdCmd_LAUNCH_MODULE_REQST,  // LCOV_EXCL_BR_LINE 11:unexpected branch  // NOLINT(whitespace/line_length)
2203                     "ePLThrdCmd_LAUNCH_MODULE_REQST");  // LCOV_EXCL_BR_LINE 11:unexpected branch  // NOLINT(whitespace/line_length)
2204
2205             if (eFrameworkunifiedStatusOK != l_eStatus) {  // LCOV_EXCL_BR_LINE 6: For setting the initialization conditions at SystemManager startup // NOLINT(whitespace/line_length)
2206               // LCOV_EXCL_START 6: For setting the initialization conditions at SystemManager startup // NOLINT(whitespace/line_length)
2207               AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
2208               l_ModuleListIterator->SetModuleState(
2209                       MODULE_STATE_LAUNCH_FAILED);
2210               SetCmdHist(l_cBuf, m_ErrHist, m_ErrHistIter,
2211                       GetStr(l_eStatus).c_str());
2212               // LCOV_EXCL_STOP
2213             } else {
2214               l_ModuleListIterator->SetModuleState(MODULE_STATE_LAUNCHING);
2215             }
2216           } else {
2217             l_ModulePath = (m_BinaryFilesPath + l_ModuleListIterator->path);  // LCOV_EXCL_BR_LINE 11:unexpected branch  // NOLINT(whitespace/line_length)
2218             FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__,
2219                     " Not launching %s: module state is %s",
2220                     l_ModulePath.c_str(),
2221                     l_ModuleListIterator->ModuleStateStr().c_str());
2222           }
2223         }
2224
2225         // LCOV_EXCL_BR_START 6: For setting the initialization conditions at SystemManager startup // NOLINT(whitespace/line_length)
2226         if (FALSE ==
2227             l_GroupIter->second.grp_wait_for_trigger) {
2228         // LCOV_EXCL_BR_STOP
2229           m_GroupLaunchTimer->StartTimer(m_aTimerIDs[eSM_TIMER_GROUP_MONITOR],
2230                   SS_GROUP_LAUNCH_TIMER_CONFIG, 0, 0, 0);  // LCOV_EXCL_BR_LINE 11:unexpected branch  // NOLINT(whitespace/line_length)
2231         }
2232       }
2233     }
2234
2235     if (m_oSystemLauncher.is_end()) {  // LCOV_EXCL_BR_LINE 6: For setting the initialization conditions at SystemManager startup // NOLINT(whitespace/line_length)
2236       FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__, "System Launch Completed");
2237
2238       if (epssusSYSTEM_SERVICES_STARTED == m_SystemModeInfo.startupStage) {
2239         // If startupStage == SYSTEM_SERVICES_STARTED, a notification is requested because there are SVCs required for notification to the _CWORD56_.
2240         l_eStatus = SendSystemModeInfoResponse(hApp, epssusALL_SERVICES_LAUNCHED);
2241         LOG_ERROR_REC_HIST_IF_ERRORED(l_eStatus,  // LCOV_EXCL_BR_LINE 15: marco defined in ss_system_manager.h  // NOLINT(whitespace/line_length)
2242             "UpdateStartupStageState_SendSystemModeInfoResponse"  // LCOV_EXCL_BR_LINE 15: marco defined in ss_system_manager.h  // NOLINT(whitespace/line_length)
2243             "( epssusALL_SERVICES_LAUNCHED )");  // LCOV_EXCL_BR_LINE 15: marco defined in ss_system_manager.h  // NOLINT(whitespace/line_length)
2244       }
2245
2246       m_SystemModeInfo.startupStage = epssusALL_SERVICES_LAUNCHED;
2247
2248       if (is_current_state(SS_SM_APPS_LAUNCH_IN_PROGRESS)) {
2249          SMSetState(hApp, SS_SM_APPS_LAUNCHED_READY_TO_START);
2250       }
2251       // SysMgrConfiguration config;
2252       // config.PrintAllInfo( m_MapProclaunchGrps );
2253     }
2254   }
2255   FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-");
2256   return l_eStatus;
2257 }  // End of EFrameworkunifiedStatus CSystemManager::OnLaunchGroup(HANDLE hApp)
2258
2259 ///////////////////////////////////////////////////////////////////////////////
2260 /// \ingroup    OnProcessLaunchTimerExpiry
2261 ///
2262 /// \param      HANDLE hApp
2263 ///
2264 /// \return     EFrameworkunifiedStatus
2265 ///////////////////////////////////////////////////////////////////////////////
2266 EFrameworkunifiedStatus CSystemManager::OnProcessLaunchTimerExpiry(HANDLE hApp) {  // LCOV_EXCL_START 8:  Because the condition cannot be set
2267   AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
2268   EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK;
2269   // ToDo 2013_05_17 Jay When used ? Dead code ? Don't see a StartTimer call.
2270   REC_HIST_IF_SUCCESSFUL("SM_TIMER_PROCESS_LAUNCH_MONITOR", m_TimerCmdHist,
2271                          m_TimerHistIter, FrameworkunifiedGetMsgSrc(hApp), l_eStatus);
2272   m_GroupLaunchTimer->StopTimer(m_aTimerIDs[eSM_TIMER_PROCESS_LAUNCH_MONITOR]);
2273   return eFrameworkunifiedStatusOK;
2274 }
2275 // LCOV_EXCL_STOP
2276
2277 ///////////////////////////////////////////////////////////////////////////////
2278 /// \ingroup    OnHeartBeatMonitorTimerExpiry
2279 ///
2280 /// \param      HANDLE hApp
2281 ///
2282 /// \return     EFrameworkunifiedStatus
2283 ///////////////////////////////////////////////////////////////////////////////
2284 EFrameworkunifiedStatus CSystemManager::OnHeartBeatMonitorTimerExpiry(HANDLE hApp) {
2285   FRAMEWORKUNIFIEDLOG(ZONE_PERIODIC_FUNC, __FUNCTION__, "+");
2286   FRAMEWORKUNIFIEDLOG(ZONE_PERIODIC_INFO, __FUNCTION__, " Received from %s", FrameworkunifiedGetMsgSrc(hApp));
2287   EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK;  // LCOV_EXCL_BR_LINE 15: marco defined in ns_logger_if.h  // NOLINT(whitespace/line_length)
2288   REC_HIST_IF_SUCCESSFUL("SM_TIMER_HEARTBEAT_MONITOR", m_TimerCmdHist,  // LCOV_EXCL_BR_LINE 15: marco defined in ss_system_manager.h  // NOLINT(whitespace/line_length)
2289                          m_TimerHistIter, FrameworkunifiedGetMsgSrc(hApp), l_eStatus);  // LCOV_EXCL_BR_LINE 15: marco defined in ss_system_manager.h  // NOLINT(whitespace/line_length)
2290
2291   // LCOV_EXCL_BR_START 4: nsfw error
2292   if (eFrameworkunifiedStatusOK != (l_eStatus = FrameworkunifiedSendChild(hApp, m_hHeartbeatThread.m_ThreadHdl,
2293                       SS_HEARTBEAT_PERIODIC_STATUS_REQ, 0, NULL))) {
2294   // LCOV_EXCL_BR_STOP 4: nsfw error
2295     AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
2296     LOG_ERROR("FrameworkunifiedSendChild(m_hHeartbeatThread.m_ThreadHdl, "  // LCOV_EXCL_LINE 4: nsfw error
2297               "SS_HEARTBEAT_PERIODIC_STATUS_REQ)");  // LCOV_EXCL_BR_LINE 15: marco defined in ss_templates.h  // NOLINT(whitespace/line_length)
2298   } else {
2299     m_hHeartbeatThread.m_ThreadState = eSMWaitForHeartbeat;
2300   }
2301
2302   FRAMEWORKUNIFIEDLOG(ZONE_PERIODIC_FUNC, __FUNCTION__, "-");
2303   return l_eStatus;
2304 }
2305
2306 ///////////////////////////////////////////////////////////////////////////////
2307 /// \ingroup SystemManagerDebugDump
2308 ///     implement post mortem function
2309 ///
2310 /// \param
2311 ///
2312 /// \return void
2313 ///////////////////////////////////////////////////////////////////////////////
2314
2315 VOID CSystemManager::SystemManagerDebugDump(HANDLE hApp) {
2316   std::stringstream l_debugDumpBuf;
2317   cmdHistIter i;
2318
2319   // LCOV_EXCL_BR_START 11:unexpected branch  // NOLINT(whitespace/line_length)
2320   l_debugDumpBuf << FrameworkunifiedGetAppName(hApp) << "/" << endl
2321       << " <SYSTEM MANAGER DUMP DATA> " << endl << endl << " ***internals*** " << endl
2322       << endl << " SM state: "
2323       << GetStr(m_SMCurrentState).c_str() << endl << " SM  startup reason: "
2324       << GetStr(m_StartUpReason).c_str() << endl << " SM shutdown reason: "
2325       << GetStr(m_shutdownTrigger).c_str() << endl << " LUM: "
2326       << GetStr(m_lastUserMode).c_str() << endl << " TPM: "
2327       << GetStr(m_SystemModeInfo.transportMode).c_str() << endl << " LPH: "
2328       << GetStr(m_SystemModeInfo.limpHomeCutoff).c_str() << endl << " PMode: "
2329       << GetStr(m_SystemModeInfo.productionMode).c_str() << endl << " ActiveGroup: "
2330       << m_ActiveGroupId << endl << " m_MaxShutdownTime: " << m_MaxShutdownTime
2331       << endl << " NPP: " << (m_bIsNPP_ServicesStarted ? "Started" : "notStarted")
2332       << endl
2333       << endl << " ***Error history***" << endl;
2334   // LCOV_EXCL_BR_STOP
2335
2336   for (i = m_ErrHist.begin(); i != m_ErrHist.end(); ++i) {
2337     l_debugDumpBuf << endl << " " << i->m_cmd.c_str() << " @ " << i->m_time  // LCOV_EXCL_BR_LINE 11:unexpected branch  // NOLINT(whitespace/line_length)
2338         << "ms EC:" << i->m_sender.c_str() << endl;  // LCOV_EXCL_BR_LINE 11:unexpected branch  // NOLINT(whitespace/line_length)
2339   }
2340
2341   l_debugDumpBuf << endl << " ***_CWORD56_ command history***" << endl;
2342
2343   for (i = m__CWORD56_CmdHist.begin(); i != m__CWORD56_CmdHist.end(); ++i) {
2344     l_debugDumpBuf << endl << " " << i->m_cmd.c_str() << " @ " << i->m_time << "ms" << endl;  // LCOV_EXCL_BR_LINE 11:unexpected branch  // NOLINT(whitespace/line_length)
2345   }
2346
2347   l_debugDumpBuf << endl << " ***Timer history***" << endl;
2348
2349   for (i = m_TimerCmdHist.begin(); i != m_TimerCmdHist.end(); ++i) {
2350     l_debugDumpBuf << endl << " " << i->m_cmd.c_str() << " @ " << i->m_time << "ms" << endl;  // LCOV_EXCL_BR_LINE 11:unexpected branch  // NOLINT(whitespace/line_length)
2351   }
2352
2353   l_debugDumpBuf << endl << " ***SM message history***" << endl;
2354
2355   for (i = m_SMCmdHist.begin(); i != m_SMCmdHist.end(); ++i) {
2356     l_debugDumpBuf << endl << " " << i->m_cmd.c_str() << " @ " << i->m_time << "ms "  // LCOV_EXCL_BR_LINE 11:unexpected branch  // NOLINT(whitespace/line_length)
2357         << i->m_sender.c_str() << endl;  // LCOV_EXCL_BR_LINE 11:unexpected branch  // NOLINT(whitespace/line_length)
2358   }
2359
2360   l_debugDumpBuf << endl << " ***Publishshing history***" << endl;
2361
2362   for (i = m_PubCmdHist.begin(); i != m_PubCmdHist.end(); ++i) {
2363     l_debugDumpBuf << endl << " " << i->m_cmd.c_str() << " @ " << i->m_time << "ms "  // LCOV_EXCL_BR_LINE 11:unexpected branch  // NOLINT(whitespace/line_length)
2364         << i->m_sender.c_str() << endl;  // LCOV_EXCL_BR_LINE 11:unexpected branch  // NOLINT(whitespace/line_length)
2365   }
2366
2367   l_debugDumpBuf << endl << " ***SM start table***" << endl;    // LCOV_EXCL_BR_LINE 11:unexpected branch  // NOLINT(whitespace/line_length)
2368
2369   // LCOV_EXCL_BR_START 11:unexpected branch  // NOLINT(whitespace/line_length)
2370   l_debugDumpBuf << endl
2371     << " index | name | start required? | isOKFlag | Module state | start sent "
2372         "| start resposne received |start delta | stop sent | reply received | stop delta | PID"
2373     << endl;
2374   // LCOV_EXCL_BR_STOP
2375
2376   for (UI_32 k = 1u; (k <= m_MapProclaunchGrps.size()); k++) {
2377     GroupLaunchMapIter l_GroupIterator = m_MapProclaunchGrps.find(k);
2378
2379     if (l_GroupIterator != m_MapProclaunchGrps.end()) {
2380       ModuleLaunchListIter l_ModuleListIterator = l_GroupIterator->second.modules.begin();
2381
2382       for (int i = 1u; l_ModuleListIterator != l_GroupIterator->second.modules.end();
2383             l_ModuleListIterator++, i++) {
2384       // LCOV_EXCL_BR_START 11:unexpected branch  // NOLINT(whitespace/line_length)
2385         std::string sIsOKFlag = GetModuleCondition(l_ModuleListIterator) ? " " :  // 'blank' means OK
2386                 "X";  // 'X' means state mismatch
2387
2388         l_debugDumpBuf << " " << std::setw(2) << std::right << i << " | "
2389             << std::setw(24) << std::left << l_ModuleListIterator->name.c_str()
2390             << " | " << std::setw(5) << std::left
2391             << (l_ModuleListIterator->is_start_required ? "TRUE" : "FALSE")
2392
2393             << " | " << sIsOKFlag.c_str() << " | " << std::setw(24) << std::left
2394             << l_ModuleListIterator->ModuleStateStr().c_str() << " | "
2395             << l_ModuleListIterator->m_startReason.GetInitial() << " | "
2396             << l_ModuleListIterator->m_startReason.GetFinal() << " | "
2397             << std::setw(3) << std::right
2398             << static_cast<SI_16>(l_ModuleListIterator->m_startReason.GetDelta())
2399             << "ms" << " | " << l_ModuleListIterator->m_stopReason.GetInitial()
2400             << " | " << l_ModuleListIterator->m_stopReason.GetFinal() << " | "
2401             << std::setw(3)
2402             << static_cast<SI_16>(l_ModuleListIterator->m_stopReason.GetDelta())
2403             << "ms" << " | " << l_ModuleListIterator->pid << endl;
2404       // LCOV_EXCL_BR_STOP
2405       }
2406     }
2407   }
2408
2409   l_debugDumpBuf << endl << " ***Heartbeat information***" << endl;
2410
2411   l_debugDumpBuf << endl << " Entire State:" << m_HBReport.eEntireState << endl;  // LCOV_EXCL_BR_LINE 11:unexpected branch  // NOLINT(whitespace/line_length)
2412
2413   l_debugDumpBuf << endl << " Number of Modules:" << m_HBReport.nNumOfModules << endl;
2414
2415   for (UI_32 j = 0; j < m_HBReport.nNumOfModules; j++) {  // LCOV_EXCL_BR_LINE 11:unexpected branch  // NOLINT(whitespace/line_length)
2416     // LCOV_EXCL_START 6: Because the applicable variable cannot be changed from the external API (only evaluated by the initial value)
2417     AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
2418     if (0 != m_HBReport.tModuleList[j].HeartBeatRetryCount) {
2419       l_debugDumpBuf << endl << " " << m_HBReport.tModuleList[j].ProcQueueName << ","
2420           << m_HBReport.tModuleList[j].ProcHBState << ", "
2421           << m_HBReport.tModuleList[j].HeartBeatRetryCount << endl;
2422     }
2423     // LCOV_EXCL_STOP
2424   }
2425
2426   std::string l_debugDumpStr = l_debugDumpBuf.str();
2427
2428   SendDebugDumpResponseToSystemManager(l_debugDumpStr);  // LCOV_EXCL_BR_LINE 11:unexpected branch  // NOLINT(whitespace/line_length)
2429 }
2430
2431 ///////////////////////////////////////////////////////////////////////////////
2432 /// \ingroup   OnProcessLaunchMonitorTimerExpiry
2433 ///           This sends request to launcher thread to confirm that it
2434 ///           is still responsive.
2435 ///
2436 /// \param [in] hApp
2437 ///         HANDLE - Handle of the Client Application
2438 ///
2439 /// \return Status
2440 ///         EFrameworkunifiedStatus - success or error
2441 ///////////////////////////////////////////////////////////////////////////////
2442 EFrameworkunifiedStatus CSystemManager::OnProcessLaunchMonitorTimerExpiry(HANDLE hApp) {
2443   FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+");
2444   FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__, " Received from %s", FrameworkunifiedGetMsgSrc(hApp));
2445   EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK;
2446
2447   REC_HIST_IF_SUCCESSFUL("TIMER_PROCESSLAUNCHER_MONITOR", m_TimerCmdHist,  // LCOV_EXCL_BR_LINE 15: marco defined in ss_system_manager.h  // NOLINT(whitespace/line_length)
2448         m_TimerHistIter, FrameworkunifiedGetMsgSrc(hApp), l_eStatus);  // LCOV_EXCL_BR_LINE 15: marco defined in ss_system_manager.h  // NOLINT(whitespace/line_length)
2449
2450   // LCOV_EXCL_BR_START 4: nsfw error
2451   if (eFrameworkunifiedStatusOK != (l_eStatus = FrameworkunifiedSendChild(hApp, m_hProcLauncherThread.m_ThreadHdl,
2452         ePLThrdCmd_THREAD_STATUS_REQST, 0, NULL))) {
2453   // LCOV_EXCL_BR_STOP 4: nsfw error
2454     AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
2455     LOG_ERROR("FrameworkunifiedSendChild(m_hProcLauncherThread.m_ThreadHdl,"  // LCOV_EXCL_LINE 4: nsfw error
2456         "ePLThrdCmd_THREAD_STATUS_REQST)");  // LCOV_EXCL_BR_LINE 15: marco defined in ss_templates.h  // NOLINT(whitespace/line_length)
2457   } else {
2458     m_hProcLauncherThread.m_ThreadState = eSMWaitForHeartbeat;
2459   }
2460
2461   FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-");
2462   return l_eStatus;
2463 }
2464
2465 ///////////////////////////////////////////////////////////////////////////////
2466 /// \ingroup  SendRequestToLauncher
2467 ///           This function is used for sending request to launcher thread from
2468 ///           System Manager.
2469 ///
2470 /// \param HANDLE hApp
2471 ///      ModuleLaunchListIter f_ModuleListIterator => iterator node from map for the module
2472 ///        ESMPLThreadCommandIds f_CommandId         => command id to send
2473 ///        SS_String f_ModulePath                    => Path of the Module
2474 ///
2475 /// \return Status
2476 ///         EFrameworkunifiedStatus - success or error
2477 ///////////////////////////////////////////////////////////////////////////////
2478 EFrameworkunifiedStatus CSystemManager::PerformLaunchProcedure(HANDLE hApp,
2479   ModuleLaunchListIter f_ModuleIterator, SS_String & f_stopCompName) {
2480   EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK;
2481
2482   SS_String s_ModuleStatus2;
2483
2484   // Register for Stop Complete notification
2485   if (!f_ModuleIterator->shutdown_critical) {
2486     s_ModuleStatus2 = "is not shutdown_critical";
2487   // LCOV_EXCL_BR_START 6: For setting the initialization conditions at SystemManager startup
2488
2489   } else if (eFrameworkunifiedStatusOK != (l_eStatus =
2490       FrameworkunifiedSubscribeNotificationWithCallback(
2491                 hApp,
2492                 f_stopCompName.c_str(),
2493                 SysMgrCallback<CSystemManager, &CSystemManager::OnModuleStopCompleteNotification>))) {
2494   // LCOV_EXCL_BR_STOP
2495     // LCOV_EXCL_START 6: For setting the initialization conditions at SystemManager startup
2496     AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
2497     FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__,
2498          " Error: FrameworkunifiedSubscribeNotificationWithCallback(hApp, %s) errored: %d/'%s'",
2499     f_stopCompName.c_str(), l_eStatus, GetStr(l_eStatus).c_str());
2500
2501     s_ModuleStatus2 = "is shutdown_critical but errored";
2502     // LCOV_EXCL_STOP
2503   } else {
2504     s_ModuleStatus2 = f_stopCompName + " is now registered";  // LCOV_EXCL_BR_LINE 11:unexpected branch  // NOLINT(whitespace/line_length)
2505   }
2506
2507   FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__, "%s", s_ModuleStatus2.c_str());
2508
2509   return l_eStatus;
2510 }
2511
2512 ///////////////////////////////////////////////////////////////////////////////
2513 /// \ingroup   PerformTerminateProcedure
2514 ///           Perform Procedure for Service Terminate.
2515 ///
2516 /// \param HANDLE hApp
2517 ///        ModuleLaunchListIter f_ModuleListIterator => iterator node from map for the module
2518 ///        SS_String & f_availabilityName            => Availability Name
2519 ///        SS_String & f_stopCompName                => Stop Complete Notification Name
2520 ///
2521 /// \return Status
2522 ///         EFrameworkunifiedStatus - success or error
2523 ///////////////////////////////////////////////////////////////////////////////
2524 EFrameworkunifiedStatus CSystemManager::PerformTerminateProcedure(HANDLE hApp,
2525         ModuleLaunchListIter f_ModuleIterator, SS_String & f_availabilityName,
2526         SS_String & f_stopCompName) {
2527   EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK;
2528
2529   // close session
2530   f_ModuleIterator->SetModuleState(MODULE_STATE_INVALID);
2531   f_ModuleIterator->pid = 0;
2532   if (NULL != f_ModuleIterator->hsession) {  // LCOV_EXCL_BR_LINE 200:hsession must not be NULL.
2533     l_eStatus = FrameworkunifiedMcClose(f_ModuleIterator->hsession);  // LCOV_EXCL_BR_LINE 4: nsfw error
2534     if (eFrameworkunifiedStatusOK != l_eStatus) {  // LCOV_EXCL_BR_LINE 4: nsfw error
2535       // LCOV_EXCL_START 4: nsfw error
2536       AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
2537       FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, " Error: FrameworkunifiedMcClose(%s) errored: %d/'%s'",
2538           f_ModuleIterator->name.c_str(), l_eStatus, GetStr(l_eStatus).c_str());
2539       // LCOV_EXCL_STOP
2540     }
2541     f_ModuleIterator->hsession = NULL;
2542   }
2543
2544   // Availability
2545   if (f_ModuleIterator->is_start_required) {
2546     // Initialize Availability
2547     HANDLE pPublishMq = McOpenSender(FRAMEWORKUNIFIED_NS_NPSERVICE);  // LCOV_EXCL_BR_LINE 4: nsfw error
2548     if (NULL == pPublishMq) {  // LCOV_EXCL_BR_LINE 4: nsfw error
2549       AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
2550       SS_ASERT(0);  // LCOV_EXCL_LINE 4: nsfw error
2551     } else {
2552       ServiceAvailability tServiceAvailability;
2553
2554       snprintf(tServiceAvailability.cServiceName, MAX_NAME_SIZE_APP, "%s",
2555           f_ModuleIterator->name.c_str());
2556       tServiceAvailability.eServiceAvailability = eFrameworkunifiedServiceNotAvailable;
2557
2558       l_eStatus = NPPublishNotification(pPublishMq, f_ModuleIterator->name.c_str(),  // LCOV_EXCL_BR_LINE 4: nsfw error
2559                   f_availabilityName.c_str(), &tServiceAvailability,  // LCOV_EXCL_BR_LINE 4: nsfw error
2560         sizeof(tServiceAvailability));  // LCOV_EXCL_BR_LINE 4: nsfw error
2561       if (eFrameworkunifiedStatusOK != l_eStatus) {  // LCOV_EXCL_BR_LINE 4: nsfw error
2562         // LCOV_EXCL_START 4: nsfw error
2563         AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
2564         FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, " Error: NPPublishNotification(%s)",
2565             f_availabilityName.c_str());
2566         // LCOV_EXCL_STOP
2567       }
2568
2569       l_eStatus = McClose(pPublishMq);  // LCOV_EXCL_BR_LINE 4: nsfw error
2570       if (eFrameworkunifiedStatusOK != l_eStatus) {
2571         // LCOV_EXCL_START 4: nsfw error
2572         AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
2573         SS_ASERT(0);  // LCOV_EXCL_BR_LINE 15: marco defined in ss_templates.h  // NOLINT(whitespace/line_length)
2574         // LCOV_EXCL_STOP
2575       }
2576     }
2577   }
2578
2579   if (f_ModuleIterator->shutdown_critical) {
2580     // Unregister Stop Complete notification
2581     if (eFrameworkunifiedStatusOK != (l_eStatus = FrameworkunifiedUnsubscribeNotificationWithCallback(hApp, f_stopCompName.c_str()))) {  // LCOV_EXCL_BR_LINE 4: nsfw error  // NOLINT(whitespace/line_length)
2582       // LCOV_EXCL_START 4: nsfw error
2583       AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
2584       FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__,
2585           " Error: FrameworkunifiedUnsubscribeNotificationWithCallback(hApp, %s) errored: %d/'%s'",
2586           f_stopCompName.c_str(), l_eStatus, GetStr(l_eStatus).c_str());
2587       // LCOV_EXCL_STOP
2588     } else {
2589       SS_String s_ModuleStatus2 = f_stopCompName + " is now unregistered ";
2590       FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__, "%s", s_ModuleStatus2.c_str());
2591     }
2592   }
2593
2594   return l_eStatus;
2595 }
2596
2597 ///////////////////////////////////////////////////////////////////////////////
2598 /// \ingroup  SendRequestToLauncher
2599 ///           This function is used for sending request to launcher thread from
2600 ///           System Manager.
2601 ///
2602 /// \param HANDLE hApp
2603 ///      ModuleLaunchListIter f_ModuleListIterator => iterator node from map for the module
2604 ///        ESMPLThreadCommandIds f_CommandId         => command id to send
2605 ///        SS_String f_ModulePath                    => Path of the Module
2606 ///
2607 /// \return Status
2608 ///         EFrameworkunifiedStatus - success or error
2609 ///////////////////////////////////////////////////////////////////////////////
2610 EFrameworkunifiedStatus CSystemManager::SendRequestToLauncher(HANDLE hApp,
2611         ModuleLaunchListIter f_ModuleIterator, ESMPLThreadCommandIds f_CommandId,
2612         SS_String f_CommandIdStr) {
2613   EFrameworkunifiedStatus l_eStatus;
2614   FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+");
2615   SS_String l_ModulePath = m_BinaryFilesPath + f_ModuleIterator->path;
2616
2617   T_ProcessLauncherLaunchReq l_ModuleLaunchReq = { };
2618   strcpy(l_ModuleLaunchReq.name, f_ModuleIterator->name.c_str());  // NOLINT
2619   strcpy(l_ModuleLaunchReq.path, l_ModulePath.c_str());  // NOLINT
2620   strncpy(l_ModuleLaunchReq.args, f_ModuleIterator->arguments.c_str(),  // NOLINT
2621   sizeof(l_ModuleLaunchReq.args) - 1);
2622   strcpy(l_ModuleLaunchReq.logging_mask,  // NOLINT
2623   f_ModuleIterator->logging_msk_str.c_str());
2624   l_ModuleLaunchReq.priority = f_ModuleIterator->configuration_priority;
2625   l_ModuleLaunchReq.cpu_assign = f_ModuleIterator->cpu_assign;
2626   l_ModuleLaunchReq.groupIterator = m_MapProclaunchGrps.find(
2627   f_ModuleIterator->group_id);
2628   l_ModuleLaunchReq.moduleIterator = f_ModuleIterator;
2629
2630   FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__,
2631       "Queue:%s, path:%s, args:%s, lmsk:%s, prio:%d, cmd:%s", l_ModuleLaunchReq.name,
2632   l_ModuleLaunchReq.path, l_ModuleLaunchReq.args, l_ModuleLaunchReq.logging_mask,
2633   l_ModuleLaunchReq.priority, f_CommandIdStr.c_str());
2634
2635   if (eFrameworkunifiedStatusOK != (l_eStatus = FrameworkunifiedSendChild(hApp, m_hProcLauncherThread.m_ThreadHdl, f_CommandId, sizeof(l_ModuleLaunchReq), reinterpret_cast<void *>(&l_ModuleLaunchReq)))) {  // LCOV_EXCL_BR_LINE 4: Because an initialization condition is set at SystemManager startup and the branching condition cannot be satisfied // NOLINT(whitespace/line_length)
2636     // LCOV_EXCL_START 4: Because an initialization condition is set at SystemManager startup and the branching condition cannot be satisfied
2637     AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
2638     FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__,
2639         " Error: FrameworkunifiedSendChild( %s, %s ) errored: %d/'%s'", l_ModulePath.c_str(),
2640         f_CommandIdStr.c_str(), l_eStatus, GetStr(l_eStatus).c_str());
2641     // LCOV_EXCL_STOP
2642   } else {
2643     SS_String l_availabilityName = f_ModuleIterator->name + "/Availability";  // LCOV_EXCL_BR_LINE 11:unexpected branch  // NOLINT(whitespace/line_length)
2644     SS_String l_stopCompName = f_ModuleIterator->name + "/StopComp";  // LCOV_EXCL_BR_LINE 11:unexpected branch  // NOLINT(whitespace/line_length)
2645     // Perform command-specific processing
2646     switch (f_CommandId) {  // LCOV_EXCL_BR_LINE 6: Because the case is fixed on the call from the SystemManager::Initialize
2647       // LCOV_EXCL_START 6: Because the case is fixed on the call from the SystemManager::Initialize
2648       case ePLThrdCmd_RELAUNCH_MODULE_REQST:
2649         AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
2650         l_eStatus = PerformTerminateProcedure(hApp, f_ModuleIterator,
2651                     l_availabilityName, l_stopCompName);
2652         if (eFrameworkunifiedStatusOK != l_eStatus) {
2653           SS_ASERT(0);
2654         }
2655
2656         l_eStatus = PerformLaunchProcedure(hApp, f_ModuleIterator, l_stopCompName);
2657         if (eFrameworkunifiedStatusOK != l_eStatus) {
2658           SS_ASERT(0);
2659         }
2660         break;
2661       // LCOV_EXCL_STOP
2662
2663       case ePLThrdCmd_LAUNCH_MODULE_REQST:
2664         l_eStatus = PerformLaunchProcedure(hApp, f_ModuleIterator, l_stopCompName);
2665         if (eFrameworkunifiedStatusOK != l_eStatus) {  // LCOV_EXCL_BR_LINE 6: For setting the initialization conditions at SystemManager startup
2666           AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
2667           SS_ASERT(0);  // LCOV_EXCL_LINE 6: For setting the initialization conditions at SystemManager startup
2668         }
2669         break;
2670
2671       case ePLThrdCmd_TERMINATE_MODULE_REQST:
2672         l_eStatus = PerformTerminateProcedure(hApp, f_ModuleIterator,
2673                     l_availabilityName, l_stopCompName);  // LCOV_EXCL_BR_LINE 11:unexpected branch  // NOLINT(whitespace/line_length)
2674         if (eFrameworkunifiedStatusOK != l_eStatus) {
2675           SS_ASERT(0);  // LCOV_EXCL_BR_LINE 15: marco defined in ss_templates.h  // NOLINT(whitespace/line_length)
2676         }
2677         break;
2678
2679       // LCOV_EXCL_START 6: Because the case is fixed on the call from the SystemManager::Initialize
2680       AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
2681       case ePLThrdCmd_LAUNCH_MODULE_RESP:
2682       case ePLThrdCmd_MODULE_STATUS_REQST:
2683       case ePLThrdCmd_RELAUNCH_MODULE_RESP:
2684       case ePLThrdCmd_TERMINATE_MODULE_RESP:
2685       case ePLThrdCmd_THREAD_STATUS_REQST:
2686       case ePLThrdCmd_THREAD_STATUS_RESP:
2687       case ePLThrdCmd_NONE:
2688         break;
2689       // default:  Don't code a 'default' here - let the compiler
2690       // issue a warning ( set via -Wall or -Wswitch ) when the set of
2691       // enumerations changes - then the maintainer will
2692       // automagically know to update this switch statement.
2693       // LCOV_EXCL_STOP
2694     }
2695   }
2696
2697   FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-");
2698   return l_eStatus;
2699 }  // End of EFrameworkunifiedStatus CSystemManager::SendRequestToLauncher(
2700
2701 ///////////////////////////////////////////////////////////////////////////////
2702 /// \ingroup RemoveModuleEntryFromHB
2703 ///          This function is called to send module information to heart beat thread
2704 ///          which is to be removed from its list of services to be monitored.
2705 ///
2706 /// \param   HANDLE hApp,
2707 ///      const CHAR *f_ModuleName  => Module Name
2708 ///
2709 /// \return Status
2710 ///         EFrameworkunifiedStatus - success or error
2711 ///////////////////////////////////////////////////////////////////////////////
2712 EFrameworkunifiedStatus CSystemManager::RemoveModuleEntryFromHB(HANDLE hApp, const CHAR *f_ModuleName) {
2713   EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK;
2714   FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+");
2715
2716   HBListIter l_HBIter = std::find(m_HBList.begin(), m_HBList.end(), f_ModuleName);
2717   if (l_HBIter != m_HBList.end()) {
2718     m_HBList.erase(l_HBIter);
2719   }
2720
2721   TSMRequestMessage l_ModuleDetails;
2722   strncpy(l_ModuleDetails.pstModuleName, f_ModuleName,
2723           sizeof(l_ModuleDetails.pstModuleName) - 1);
2724   l_ModuleDetails.pstModuleName[sizeof(l_ModuleDetails.pstModuleName) - 1] = '\0';
2725   l_eStatus = SendRequestToHeartBeat(hApp, SS_HEARTBEAT_DELETE_MODULE_ENTRY,
2726                 &l_ModuleDetails, sizeof(TSMRequestMessage));
2727
2728   FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-");
2729   return l_eStatus;
2730 }
2731 ///////////////////////////////////////////////////////////////////////////////
2732 /// \ingroup OnHeartBeatThreadHeartbeatResponse
2733 ///          This function gets called when heart beat thread replies the
2734 ///          heart beat query sent by the System Manager.
2735 /// \param [in] hApp
2736 ///         HANDLE - Handle of the Client Application
2737 ///
2738 /// \return Status
2739 ///         EFrameworkunifiedStatus - success or error
2740 ///////////////////////////////////////////////////////////////////////////////
2741 EFrameworkunifiedStatus CSystemManager::OnHeartBeatThreadHeartbeatResponse(HANDLE hApp) {
2742   FRAMEWORKUNIFIEDLOG(ZONE_PERIODIC_INFO, __FUNCTION__, "HeartBeat HeartBeat Received");
2743   m_hHeartbeatThread.m_ThreadState = eSMThreadIsFine;
2744   return eFrameworkunifiedStatusOK;
2745 }
2746
2747 ///////////////////////////////////////////////////////////////////////////////
2748 /// \ingroup OnCheckAvailResponse
2749 ///          This function gets service's availability status from HBThread
2750 /// \param [in] hApp
2751 ///         HANDLE - Handle of the Client Application
2752 ///
2753 /// \return Status
2754 ///         EFrameworkunifiedStatus - success or error
2755 ///////////////////////////////////////////////////////////////////////////////
2756 EFrameworkunifiedStatus CSystemManager::OnCheckAvailResponse(HANDLE hApp) {
2757   EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK;
2758   THbAvailCheck result;
2759
2760   if (eFrameworkunifiedStatusOK != (l_eStatus = ReadMsg < THbAvailCheck > (hApp, result))) {
2761     LOG_ERROR("ReadMsg()");  // LCOV_EXCL_BR_LINE 15: marco defined in ss_tempaltes.h // NOLINT(whitespace/line_length)
2762   } else if (result.isOk == FALSE) {
2763   }
2764   return eFrameworkunifiedStatusOK;
2765 }
2766
2767 ///////////////////////////////////////////////////////////////////////////////
2768 /// \ingroup OnProcessLauncherThreadHeartbeatResponse
2769 ///          This function gets called when launcher thread replies the
2770 ///          heart beat query sent by the System Manager.
2771 /// \param [in] hApp
2772 ///         HANDLE - Handle of the Client Application
2773 ///
2774 /// \return Status
2775 ///         EFrameworkunifiedStatus - success or error
2776 ///////////////////////////////////////////////////////////////////////////////
2777 EFrameworkunifiedStatus CSystemManager::OnProcessLauncherThreadHeartbeatResponse(HANDLE hApp) {
2778   FRAMEWORKUNIFIEDLOG(ZONE_PERIODIC_INFO, __FUNCTION__, "ProcessLaunch HeartBeat Received");
2779   m_hProcLauncherThread.m_ThreadState = eSMThreadIsFine;
2780   return eFrameworkunifiedStatusOK;
2781 }
2782
2783 ///////////////////////////////////////////////////////////////////////////////
2784 /// \ingroup RegisterCallbacksForRequester
2785 /// Register callbacks for External Protocol commands
2786 ///
2787 /// \param [in]
2788 ///
2789 ///
2790 /// \return EFrameworkunifiedStatus
2791 /// Success ==> eFrameworkunifiedStatusOK
2792 /// Failure ==> Other values
2793 ///////////////////////////////////////////////////////////////////////////////
2794 EFrameworkunifiedStatus CSystemManager::RegisterCallbacksForRequester(HANDLE hApp, PCSTR f_pRequester) {
2795   EFrameworkunifiedStatus l_eStatus;
2796   FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+");
2797
2798   // Attach Session Protocol messages.
2799   FrameworkunifiedProtocolCallbackHandler l_sm_protocol_handlers[] = {
2800     // Command ID,              Call back functions
2801      { SS_SM_START_COMPL_RSPN,
2802          SysMgrCallback<CSystemManager, &CSystemManager::OnModuleStartCompleteResponse> },
2803      { SS_SM_STOP_COMPL_RSPN,
2804          SysMgrCallback<CSystemManager, &CSystemManager::OnModuleStopCompleteResponse> },
2805      { SS_SM_PRE_START_COMPL_RSPN,
2806          SysMgrCallback<CSystemManager, &CSystemManager::OnModuleStartCompleteResponse> },
2807      { SS_SM_PRE_STOP_COMPL_RSPN,
2808          SysMgrCallback<CSystemManager, &CSystemManager::OnModuleStartCompleteResponse> },
2809      { SS_SM_BACKGROUND_START_COMPL_RSPN,
2810          SysMgrCallback<CSystemManager, &CSystemManager::OnModuleStartCompleteResponse> },
2811      { SS_SM_BACKGROUND_STOP_COMPL_RSPN,
2812          SysMgrCallback<CSystemManager, &CSystemManager::OnModuleStartCompleteResponse> },
2813     { SS_SM_GET_START_EXT_INFO, SysMgrCallback<CSystemManager,
2814                                 &CSystemManager::OnGetStartExtInfo> },
2815     { SS_SM_GET_STOP_EXT_INFO,  SysMgrCallback<CSystemManager,
2816                                 &CSystemManager::OnGetStopExtInfo> },
2817     { SS_SM_CRNT_STATE_QUERY,   SysMgrCallback<CSystemManager,
2818                                 &CSystemManager::OnCurrentSMStateQuery> },
2819     { SS_SM_DATA_RESET_MODE_SET_REQ, SysMgrCallback<CSystemManager,
2820                                 &CSystemManager::OnSetDataResetModeRequest> },
2821     { SS_SM_PROG_UPDATE_STATE_SET_REQ, SysMgrCallback<CSystemManager,
2822                                 &CSystemManager::OnSetProgUpdateStateRequest> },
2823
2824     { SS_SM__CWORD56__HEARTBEAT_REQ, SysMgrCallback<CSystemManager,
2825                                 &CSystemManager::On_CWORD56_HeartBeatRequest> },
2826     { SS_SM_NEXT_WAKEUP_TYPE_SET_REQ, SysMgrCallback<CSystemManager,
2827                                 &CSystemManager::OnSetNextWakeupTypeRequest> },
2828       // Error Event Logging
2829     { SS_SM_ERROR_EVENT_LOGGING_START_REQ, SysMgrCallback<CSystemManager,
2830                                 &CSystemManager::OnLoggingStartRequest> },
2831     { SS_SM_ERROR_EVENT_ARTIFACT_REQ, SysMgrCallback<CSystemManager,
2832                                 &CSystemManager::OnErrorEventArtifactRequest> },
2833     { SS_SM_ERROR_EVENT_LOGGING_COMPLETE, SysMgrCallback<CSystemManager,
2834                                 &CSystemManager::OnErrorEventLoggingComplete> },
2835     { SS_SM_DEBUG_DUMP_RSPN,    SysMgrCallback<CSystemManager,
2836                                 &CSystemManager::OnDebugDumpResponseReceived> },
2837     { SS_SM_PROPAGATE_SYSTEM_ERROR, SysMgrCallback<CSystemManager,
2838                                 &CSystemManager::OnPropagateSystemError> },
2839     { SS_SM_BOOT_MICRO_RESET_NTF,   SysMgrCallback<CSystemManager,
2840                                 &CSystemManager::OnBootMicroResetNotification> },
2841     { SS_SM_BOOT_MICRO_LOG_RSP, SysMgrCallback<CSystemManager,
2842                                 &CSystemManager::OnBootMicroLogResponse> },
2843     { SS_SM_USER_INVOKED_LOG_REQ, SysMgrCallback<CSystemManager,
2844                                 &CSystemManager::OnUserInvokedLoggingRequest> },
2845     { SS_SM_ERROR_EVENT_EEL_EXPORT_REQ, SysMgrCallback<CSystemManager,
2846                                 &CSystemManager::OnEelExportRequest> },
2847     { SS_SM_ERROR_EVENT_INTERFACEUNIFIED_EMMC_LOGS_REQ, SysMgrCallback<CSystemManager,
2848                                 &CSystemManager::OnSystemmanagerEmmcLogsRequest> },
2849     { SS_SM_ERROR_EVENT_CLR_LOGS_REQ, SysMgrCallback<CSystemManager,
2850                                 &CSystemManager::OnSystemmanagerClearLogsRequest> },
2851     { SS_SM_ERROR_EVENT_DIAG_LOG_REQ, SysMgrCallback<CSystemManager,
2852                                 &CSystemManager::OnDiagLoggingRequest> },
2853     { SS_SM_ERROR_EVENT_CAN_LOG_REQ, SysMgrCallback<CSystemManager,
2854                                 &CSystemManager::OnCANLoggingRequest> } };  // LCOV_EXCL_BR_LINE 11:unexpected branch  // NOLINT(whitespace/line_length)
2855
2856     l_eStatus = FrameworkunifiedAttachCallbacksToDispatcher(hApp, f_pRequester,
2857                 l_sm_protocol_handlers, static_cast<UI_32>(_countof(l_sm_protocol_handlers)));  // LCOV_EXCL_BR_LINE 11:unexpected branch  // NOLINT(whitespace/line_length)
2858
2859   if (eFrameworkunifiedStatusOK != l_eStatus) {
2860     FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__,
2861         " Error: FrameworkunifiedAttachCallbacksToDispatcher(%s) errored: %d/'%s'", f_pRequester,
2862         l_eStatus, GetStr(l_eStatus).c_str());
2863   }
2864   FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-");
2865   return l_eStatus;
2866 }  // End of EFrameworkunifiedStatus CSystemManager::RegisterCallbacksForRequester( HANDLE hApp, PCSTR f_pRequester)
2867
2868 ///////////////////////////////////////////////////////////////////////////////
2869 /// \ingroup open_session_with_sm_test_client
2870 /// Process request to open session with sm test client
2871 ///
2872 /// \param [in]
2873 ///
2874 ///
2875 /// \return EFrameworkunifiedStatus
2876 /// Success ==> eFrameworkunifiedStatusOK
2877 /// Failure ==> Other values
2878 ///////////////////////////////////////////////////////////////////////////////
2879 EFrameworkunifiedStatus CSystemManager::open_session_with_sm_test_client(HANDLE hApp, PCSTR pRequester) {
2880   EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusFail;
2881   UI_32 const l_ui32DefaultSessionID = 0;
2882   OpenSessionAck tOpenAck = { };
2883
2884 /*
2885  * Here pRequester is SMTesteClient with whom session is opened and its handle is stored in m_hPowerServiceSession handle.
2886  * This case comes only while testing SystemManager through SMTestClient (PowerService should not be running).
2887  */
2888   // Validate session handle
2889   if (NULL == m_hPowerServiceSession) {
2890     FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__,
2891         " Error: Session Handle NULL, calling FrameworkunifiedMcOpenSender for %s", pRequester);
2892
2893     m_hPowerServiceSession = FrameworkunifiedMcOpenSender(hApp, pRequester);
2894   //
2895   // Set the Session Handle for Framework so FrameworkunifiedSendResponse won't error due to a null
2896   // session handle.
2897   //
2898     // LCOV_EXCL_BR_START 4:NSFW's error
2899     if (eFrameworkunifiedStatusOK != (l_eStatus = FrameworkunifiedSetSessionHandle(hApp,
2900         pRequester,                  // [in] PCSTR - Name of the associated service name
2901         m_hPowerServiceSession))) {  // [in] HANDLE - Session handle
2902     // LCOV_EXCL_BR_STOP
2903       // LCOV_EXCL_START 4:NSFW's error
2904       AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
2905       FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__,
2906           " Error: FrameworkunifiedSetSessionHandle(%s) errored: %d/'%s'", pRequester,
2907           l_eStatus, GetStr(l_eStatus).c_str());
2908       FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-");
2909       return l_eStatus;
2910       // LCOV_EXCL_STOP
2911     }
2912   }
2913
2914   if (m_hPowerServiceSession == NULL) {  // LCOV_EXCL_BR_LINE 200:m_hPowerServiceSession must not be NULL
2915     // LCOV_EXCL_START 200:m_hPowerServiceSession must not be NULL
2916     AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
2917     FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__,
2918         " Error: Invalid Session Handle to service (%s) ", pRequester);
2919     // LCOV_EXCL_STOP
2920   } else {
2921     FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__, "Session opened with %s", pRequester);
2922
2923     // Copy session name to data structure
2924     strncpy(tOpenAck.cSessionName, FrameworkunifiedGetAppName(hApp),
2925             sizeof(tOpenAck.cSessionName) - 1);
2926     tOpenAck.eStatus = eFrameworkunifiedStatusOK;
2927     tOpenAck.sessionId = l_ui32DefaultSessionID;
2928
2929     FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__, "About to send Open Session ACK");
2930     // send OpenSession ACK
2931     // LCOV_EXCL_BR_START 4:NSFW's error
2932     if (eFrameworkunifiedStatusOK != (l_eStatus = FrameworkunifiedSendMsg(m_hPowerServiceSession,
2933             PROTOCOL_OPEN_SESSION_ACK, sizeof(OpenSessionAck),
2934             (PVOID) & tOpenAck))) {
2935     // LCOV_EXCL_BR_STOP
2936       // LCOV_EXCL_START 4:NSFW's error
2937       AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
2938       LOG_ERROR("FrameworkunifiedSendMsg(PROTOCOL_OPEN_SESSION_ACK)");
2939
2940       // Close the message queue handle
2941       if (NULL != m_hPowerServiceSession) {
2942         CALL_AND_LOG_STATUS_IF_ERRORED(FrameworkunifiedMcClose(m_hPowerServiceSession));
2943         m_hPowerServiceSession = NULL;
2944       }
2945       // LCOV_EXCL_STOP
2946     } else {
2947       CALL_AND_LOG_STATUS_IF_ERRORED(RegisterCallbacksForRequester(hApp, pRequester));
2948     }
2949   }  // end of else block of if(l_ModuleListIterator->hsession == NULL)
2950
2951   FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-");
2952   return l_eStatus;
2953 }
2954
2955 ///////////////////////////////////////////////////////////////////////////////
2956 /// \ingroup OnOpenSession
2957 /// Process request to open session
2958 ///
2959 /// \param [in]
2960 ///
2961 ///
2962 /// \return EFrameworkunifiedStatus
2963 /// Success ==> eFrameworkunifiedStatusOK
2964 /// Failure ==> Other values
2965 ///////////////////////////////////////////////////////////////////////////////
2966 EFrameworkunifiedStatus CSystemManager::OnOpenSession(HANDLE hApp) {
2967   FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+");
2968   INTERFACEUNIFIEDLOG_RECEIVED_FROM(hApp);  // LCOV_EXCL_BR_LINE 15: marco defined in ss_templates.h  // NOLINT(whitespace/line_length)
2969   EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK;
2970   UI_32 const l_ui32DefaultSessionID = 0;
2971   UI_32 const l_ui32DefaultSessionType = 0;
2972   OpenSessionAck tOpenAck = { };
2973   PCSTR pRequester = FrameworkunifiedGetMsgSrc(hApp);
2974   FRAMEWORKUNIFIEDLOG(ZONE_PERFORMANCE, __FUNCTION__, "%s", pRequester);
2975
2976   ModuleLaunchListIter l_ModuleListIter;
2977
2978   REC_HIST_IF_SUCCESSFUL("PROTOCOL_OPEN_SESSION_REQ", m_SMCmdHist, m_SMHistIter,  // LCOV_EXCL_BR_LINE 15: marco defined in ss_system_manager.h  // NOLINT(whitespace/line_length)
2979     FrameworkunifiedGetMsgSrc(hApp), l_eStatus);  // LCOV_EXCL_BR_LINE 15: marco defined in ss_system_manager.h  // NOLINT(whitespace/line_length)
2980
2981   l_eStatus = GetModuleIterator(pRequester, l_ModuleListIter);
2982
2983   if (eFrameworkunifiedStatusOK != l_eStatus) {
2984     // Special handling for open session request from SMTestClient.
2985     if ((0 == strcmp(TC_SysManager, pRequester))) {
2986       open_session_with_sm_test_client(hApp, pRequester);
2987     } else {
2988       FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, " Error: %s not found in Group Launch Map",
2989           pRequester);
2990     }
2991   } else {
2992     /**********************************************************************/
2993     if (0 != l_ModuleListIter->pid) {
2994       UI_32 l_ClientPriority;
2995       l_eStatus = l_ModuleListIter->GetPriority(l_ClientPriority);
2996
2997       if (eFrameworkunifiedStatusOK != l_eStatus) {
2998         LOG_ERROR("l_ModuleListIter->GetPriority( l_ClientPriority )");  // LCOV_EXCL_BR_LINE 15: marco defined in ss_templates.h  // NOLINT(whitespace/line_length)
2999       } else if (l_ClientPriority != l_ModuleListIter->configuration_priority) {
3000         FRAMEWORKUNIFIEDLOG(ZONE_WARN, __FUNCTION__, " Changing %s's priority from %d to %d",
3001             pRequester, l_ClientPriority,
3002             l_ModuleListIter->configuration_priority);
3003         CALL_AND_LOG_STATUS_IF_ERRORED( // LCOV_EXCL_BR_LINE 15: marco defined in ss_templates.h  // NOLINT(whitespace/line_length)
3004             l_ModuleListIter->SetPriority( // LCOV_EXCL_BR_LINE 15: marco defined in ss_templates.h  // NOLINT(whitespace/line_length)
3005                     l_ModuleListIter->configuration_priority));  // LCOV_EXCL_BR_LINE 15: marco defined in ss_templates.h  // NOLINT(whitespace/line_length)
3006       }
3007     }
3008     /**********************************************************************/
3009
3010     // ToDo Jay 2013 Jan 09 REPLACE WITH CORRECT SERVICE / SESSION HANDLE
3011     //                      LOGIC
3012     // validate session handle
3013     if (NULL == l_ModuleListIter->hsession) {
3014       // LCOV_EXCL_BR_START 4: nsfw error
3015       if (NULL == (l_ModuleListIter->hsession = FrameworkunifiedMcOpenSender(hApp, pRequester))) {
3016       // LCOV_EXCL_BR_STOP 4: nsfw error
3017         // LCOV_EXCL_START 4: nsfw error
3018         AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
3019         FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__,
3020             " Error: FrameworkunifiedMcOpenSender(App %s, %s) returned NULL",
3021             FrameworkunifiedGetAppName(hApp), pRequester);
3022         return eFrameworkunifiedStatusInvldHandle;
3023         // LCOV_EXCL_STOP
3024       }
3025     } else {
3026     /*
3027      * Currently System Manager does not support multiple sessions from same client.
3028      * When a client gets restarted after Crash or after missing HeartBeat, System Manager
3029      * would receive OpenSession request from that client even when System Manager already
3030      * has a open session with that client.
3031      */
3032       FRAMEWORKUNIFIEDLOG(ZONE_WARN, __FUNCTION__,
3033           " Warning: Repeated Session Opening Request from %s", pRequester);
3034     }
3035     if (eFrameworkunifiedStatusOK != (l_eStatus = RegisterCallbacksForRequester(hApp, pRequester))) {
3036       // Close the message queue handle
3037       if (NULL != l_ModuleListIter->hsession) {  // LCOV_EXCL_BR_LINE 6: Due to NULL checking
3038         if (eFrameworkunifiedStatusOK != (l_eStatus = FrameworkunifiedMcClose(l_ModuleListIter->hsession))) {
3039           LOG_ERROR("FrameworkunifiedMcClose()");  // LCOV_EXCL_BR_LINE 11:unexpected branch  // NOLINT(whitespace/line_length)
3040         }
3041         l_ModuleListIter->hsession = NULL;
3042       }
3043       FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-");
3044       return l_eStatus;
3045     }
3046
3047     // Copy session name to data structure
3048     strncpy(tOpenAck.cSessionName, FrameworkunifiedGetAppName(hApp), sizeof(tOpenAck.cSessionName) - 1);
3049     tOpenAck.eStatus = eFrameworkunifiedStatusOK;
3050     tOpenAck.sessionId = l_ui32DefaultSessionID;
3051     tOpenAck.sessionType = l_ui32DefaultSessionType;
3052
3053     // send OpenSession ACK
3054     // LCOV_EXCL_BR_START 4: nsfw error
3055     if (eFrameworkunifiedStatusOK
3056         != (l_eStatus = FrameworkunifiedSendMsg(l_ModuleListIter->hsession,
3057             SS_SM_PROTOCOL_OPEN_SESSION_ACK, sizeof(OpenSessionAck),
3058             (PVOID) & tOpenAck))) {  // LCOV_EXCL_BR_STOP
3059       // LCOV_EXCL_START 4: nsfw error
3060       AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
3061       FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__,
3062           " Error: FrameworkunifiedSendMsg( %s, SS_SM_PROTOCOL_OPEN_SESSION_ACK)"
3063           " errored: %d/'%s'", l_ModuleListIter->name.c_str(), l_eStatus,
3064           GetStr(l_eStatus).c_str());
3065
3066       if (NULL != l_ModuleListIter->hsession) {
3067         // Close the message queue handle
3068         if (eFrameworkunifiedStatusOK != (l_eStatus = FrameworkunifiedMcClose(l_ModuleListIter->hsession))) {
3069           FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__,
3070               " Error: FrameworkunifiedMcClose(%s) errored: %d/'%s'",
3071               l_ModuleListIter->name.c_str(), l_eStatus,
3072               GetStr(l_eStatus).c_str());
3073           FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-");
3074         }
3075         l_ModuleListIter->hsession = NULL;
3076       }
3077       // LCOV_EXCL_STOP
3078     } else {
3079       // Store PowerService session handle in class so it can be accessed faster
3080       // to use opened session while replying to PowerService.
3081       if ((0 == strcmp(SERVICE_POWER, pRequester))) {
3082         m_hPowerServiceSession = l_ModuleListIter->hsession;
3083       }
3084
3085       l_ModuleListIter->SetModuleState(MODULE_STATE_CONNECTED);
3086
3087       FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__, " SM State: %s, %s.is_start_required: %s",
3088           GetStr(m_SMCurrentState).c_str(), l_ModuleListIter->name.c_str(),
3089           GetStr(l_ModuleListIter->is_start_required).c_str());
3090
3091       if (l_ModuleListIter->is_start_required
3092           && ((SS_SM_APPS_START_IN_PROGRESS == m_SMCurrentState)
3093           || (SS_SM_APPS_START_COMPLETE == m_SMCurrentState))) {
3094           T_SS_SM_START_DataStructType f_startupData(m_StartUpReason,
3095             m_PowerType_to_SSBoolEnumMap[m_Wake.powerupType], m_DataResetMode,
3096             m_startUpConfirmationMsg.securityStatus,
3097             m_startUpConfirmationMsg.wakeupType, m_DramBackupStatus,
3098             m_ResetStatus, m_ResetCount);
3099           const UI_32 l_iCmd = InProgressStateToSendMsg();
3100           if (l_iCmd != SS_SYSTEM_MANAGER_PROTOCOL_ENDING_INDEX) {
3101             CALL_AND_LOG_STATUS_IF_ERRORED(l_ModuleListIter->SendMsgAndUpdateState(l_iCmd, &f_startupData));  // LCOV_EXCL_BR_LINE 11: Gcov constraints (because exception-handling routes are automatically generated) // NOLINT(whitespace/line_length)
3102           }
3103       }
3104     }
3105   }
3106
3107   if (eFrameworkunifiedStatusOK == l_eStatus) {
3108     std::string l_Subscriber;
3109     l_Subscriber = FrameworkunifiedGetMsgSrc(hApp);
3110
3111     // check if the heart beat subscriber is already in list
3112     HBListIter l_HBIter = std::find(m_HBList.begin(), m_HBList.end(), l_Subscriber);
3113     if (l_HBIter == m_HBList.end()) {
3114       m_HBList.push_back(l_Subscriber);
3115     }
3116     if (m_SMCurrentState == SS_SM_APPS_START_COMPLETE) {
3117       TSMRequestMessage l_ModuleDetails;
3118       snprintf(l_ModuleDetails.pstModuleName, sizeof(l_ModuleDetails.pstModuleName),
3119           "%s", l_Subscriber.c_str());
3120       l_eStatus = SendRequestToHeartBeat(hApp, SS_HEARTBEAT_APPEND_MODULE_ENTRY,
3121           &l_ModuleDetails, sizeof(TSMRequestMessage));
3122       LOG_ERROR_REC_HIST_IF_ERRORED(l_eStatus, "SendRequestToHeartBeat()");  // LCOV_EXCL_BR_LINE 15: marco defined in ss_templates.h  // NOLINT(whitespace/line_length)
3123     }
3124   }
3125
3126   FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-");
3127   return l_eStatus;
3128 }
3129
3130 ///////////////////////////////////////////////////////////////////////
3131 /// ConstructGetResultResponse
3132 ///
3133 ///
3134 //////////////////////////////////////////////////////////////////////
3135 EFrameworkunifiedStatus CSystemManager::add_state_information_to_response(CHAR *f_MessageResponse) const {
3136   const CHAR ReadyToLaunchAppDescription[] = "_READY_TO_LAUNCH:";
3137   const CHAR StartInProgressDescription[] = "_START_IN_PROGRESS:";
3138   const CHAR LaunchInProgressDescription[] = "_LAUNCH_IN_PROGRESS:";
3139   const CHAR LaunchedReadyToStartDescription[] = "_READY_TO_START:";
3140   const CHAR StopInProgressDescription[] = "_STOP_IN_PROGRESS:";
3141   const CHAR StartCompleteDescription[] = "_START_COMPLETED:";
3142   const CHAR WaitingForCriticalAppsToStopDescription[] = "_WAITING_FOR_CRITICAL_APPS_TO_STOP:";
3143   const CHAR PreStartInProgressDescription[] = "_PRE_START_IN_PROGRESS:";
3144   const CHAR PreStopInProgressDescription[] = "_PRE_STOP_IN_PROGRESS:";
3145   const CHAR PreRunCompleteDescription[] = "_PRE_RUN_COMPLETE:";
3146   const CHAR BackgroundStartInProgressDescription[] = "_BACKGROUND_START_IN_PROGRESS:";
3147   const CHAR BackgroundStopInProgressDescription[] = "_BACKGROUND_STOP_IN_PROGRESS:";
3148   const CHAR BackgroundRunCompleteDescription[] = "_BACKGROUND_RUN_COMPLETE:";
3149   EFrameworkunifiedStatus eStatus = eFrameworkunifiedStatusOK;
3150   FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+");
3151   CHAR l_Buffer[5];
3152   UI_32 l_Index = 0;
3153
3154   std::map<SS_SMModuleState, std::string> StateMap;   // State Map
3155   StateMap[SS_SM_READY_TO_LAUNCH_APP] = ReadyToLaunchAppDescription;
3156   StateMap[SS_SM_APPS_LAUNCH_IN_PROGRESS] = LaunchInProgressDescription;
3157   StateMap[SS_SM_APPS_LAUNCHED_READY_TO_START] = LaunchedReadyToStartDescription;
3158   StateMap[SS_SM_APPS_START_IN_PROGRESS] = StartInProgressDescription;
3159   StateMap[SS_SM_APPS_START_COMPLETE] = StartCompleteDescription;
3160   StateMap[SS_SM_APPS_STOPPING_AT__CWORD56__REQ] = StopInProgressDescription;
3161   StateMap[SS_SM_APPS_STOPPING_AT_INTERNAL_REQ] = StopInProgressDescription;
3162   StateMap[SS_SM_WAITING_FOR_CRITICAL_APPS_AT_INTERNAL_REQ] =
3163       WaitingForCriticalAppsToStopDescription;
3164   StateMap[SS_SM_WAITING_FOR_CRITICAL_APPS_AT__CWORD56__REQ] =
3165       WaitingForCriticalAppsToStopDescription;
3166   StateMap[SS_SM_APPS_PRE_START_IN_PROGRESS] = PreStartInProgressDescription;
3167   StateMap[SS_SM_APPS_PRE_STOP_IN_PROGRESS] = PreStopInProgressDescription;
3168   StateMap[SS_SM_APPS_PRE_RUN_COMPLETE] = PreRunCompleteDescription;
3169   StateMap[SS_SM_APPS_BACKGROUND_START_IN_PROGRESS] = BackgroundStartInProgressDescription;
3170   StateMap[SS_SM_APPS_BACKGROUND_STOP_IN_PROGRESS] = BackgroundStopInProgressDescription;
3171   StateMap[SS_SM_APPS_BACKGROUND_RUN_COMPLETE] = BackgroundRunCompleteDescription;
3172
3173   itoa(m_SMCurrentState, l_Buffer, 16);
3174   while (l_Buffer[l_Index]) {
3175     l_Buffer[l_Index] = toupper(l_Buffer[l_Index]);
3176     l_Index++;
3177   }
3178
3179   if (SS_SM_MAX_RESP_MSG_SIZE > (strlen(f_MessageResponse) + sizeof(l_Buffer)
3180       + StateMap[m_SMCurrentState].length() + 1)) {
3181     strncat(f_MessageResponse, l_Buffer, sizeof(l_Buffer));
3182     strncat(f_MessageResponse, StateMap[m_SMCurrentState].c_str(),
3183     StateMap[m_SMCurrentState].length());
3184   } else {
3185     eStatus = eFrameworkunifiedStatusFail;
3186   }
3187
3188   FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-");
3189   return eStatus;
3190 }
3191
3192 ///////////////////////////////////////////////////////////////////////
3193 /// ConstructGetResultResponse
3194 ///
3195 ///
3196 //////////////////////////////////////////////////////////////////////
3197 EFrameworkunifiedStatus CSystemManager::construct_get_result_response(CHAR *f_MessageResponse) {
3198   FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+");
3199   const EFrameworkunifiedStatus  eStatus = add_state_information_to_response(f_MessageResponse);
3200   if (eFrameworkunifiedStatusOK == eStatus) {
3201     FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__, "Response Constructed");
3202   }
3203
3204   FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-");
3205   return eStatus;
3206 }
3207
3208 ///////////////////////////////////////////////////////////////////////
3209 /// REC_HIST_IF_SUCCESSFUL / SetCmdHist
3210 ///
3211 ///
3212 //////////////////////////////////////////////////////////////////////
3213 void CSystemManager::SetCmdHist(std::string cmd, cmdHist &hist, cmdHistIter &it, std::string sender) {
3214   UI_64 l_time = 0XDEAD;
3215   CTimeSpan* timerClass = new (std::nothrow) CTimeSpan();  // LCOV_EXCL_BR_LINE 5: Because new cannot fail
3216   if (NULL == timerClass) {  // LCOV_EXCL_BR_LINE 5: Because new cannot fail
3217     // LCOV_EXCL_START 5: Because new cannot fail
3218     AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
3219     FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__,
3220         " 'new (std::nothrow) CTimeSpan()' returned NULL, "
3221         "'it->m_time' being set to 0xDEAD");
3222     // LCOV_EXCL_STOP
3223   } else {
3224     l_time = timerClass->GetTimeMilliseconds();
3225   }
3226
3227   pthread_mutex_lock(&sm_hist_mutex);
3228
3229   it->m_time = l_time;
3230   it->m_cmd = cmd;
3231   it->m_sender = sender;
3232   it++;
3233
3234   if (it != hist.end()) {  // LCOV_EXCL_BR_LINE 5: std: because it is a member of a vector and it is difficult to create a failing condition
3235     it = hist.begin();
3236   }
3237
3238   pthread_mutex_unlock(&sm_hist_mutex);
3239
3240   delete timerClass;  // LCOV_EXCL_BR_LINE 5: Because the delete cannot fail
3241 }
3242
3243 ///////////////////////////////////////////////////////////////////////
3244 /// OnCurrentPowerStateQuery
3245 ///
3246 ///
3247 //////////////////////////////////////////////////////////////////////
3248 EFrameworkunifiedStatus CSystemManager::OnCurrentSMStateQuery(HANDLE hApp) {
3249   EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK;
3250   FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+");
3251   INTERFACEUNIFIEDLOG_RECEIVED_FROM(hApp);
3252   FRAMEWORKUNIFIEDLOG(ZONE_STATE, __FUNCTION__, "Received from %s", FrameworkunifiedGetMsgSrc(hApp));
3253
3254   SS_SMCurrentState l_CurrentState;
3255
3256   REC_HIST_IF_SUCCESSFUL("SS_SM_CRNT_STATE_QUERY", m_SMCmdHist, m_SMHistIter,
3257                          FrameworkunifiedGetMsgSrc(hApp), l_eStatus);
3258   if (eFrameworkunifiedStatusOK != (l_eStatus = ReadMsg < SS_SMCurrentState > (hApp, l_CurrentState))) {
3259     LOG_ERROR("ReadMsg()");  // LCOV_EXCL_BR_LINE 11:unexpected branch  // NOLINT(whitespace/line_length)
3260   } else {
3261     construct_get_result_response(l_CurrentState.respMsgString);
3262
3263     ModuleLaunchListIter l_ModuleListIter;
3264     PCSTR l_moduleName = FrameworkunifiedGetMsgSrc(hApp);
3265     if (eFrameworkunifiedStatusOK != (l_eStatus = GetModuleIterator(l_moduleName, l_ModuleListIter))) {  // LCOV_EXCL_BR_LINE 200: can not be other value  // NOLINT (whitespace/line_length)
3266       // LCOV_EXCL_START 200: can not be other value
3267       AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
3268       FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__,
3269           " Error: Module %s not found in Group Launch Map", l_moduleName);
3270       // LCOV_EXCL_STOP
3271     } else if (l_ModuleListIter->hsession != NULL) {  // LCOV_EXCL_BR_LINE 200: can not be NULL // NOLINT (whitespace/line_length)
3272       if (eFrameworkunifiedStatusOK != (l_eStatus = FrameworkunifiedSendMsg(l_ModuleListIter->hsession,  // LCOV_EXCL_BR_LINE 4: nsfw error
3273                 SS_SM_CRNT_STATE_QUERY_RSPN, sizeof(SS_SMCurrentState),
3274                 (PVOID) & l_CurrentState))) {
3275         AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
3276         LOG_ERROR("FrameworkunifiedSendMsg(SS_SM_CRNT_STATE_QUERY_RSPN)");  // LCOV_EXCL_LINE 4: nsfw error
3277       }
3278     } else {
3279       // LCOV_EXCL_START 200: can not be NUL
3280       AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
3281       FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, " NULL == hsession; %s not connected yet",
3282           l_ModuleListIter->name.c_str());
3283       // LCOV_EXCL_STOP
3284     }
3285   }
3286
3287   FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-");
3288   return l_eStatus;
3289 }
3290
3291 EFrameworkunifiedStatus CSystemManager::GetVersionNumber(SS_VersionNumberType & f_VersionNumber) {
3292   FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+");
3293   EFrameworkunifiedStatus l_eStatus;
3294
3295   CSMVersion cVersion;
3296   if (eFrameworkunifiedStatusOK != (l_eStatus = cVersion.get_version(f_VersionNumber))) {  // LCOV_EXCL_BR_LINE 6: For setting the initialization conditions at SystemManager startup // NOLINT(whitespace/line_length)
3297     LOG_ERROR("cVersion.get_version()");  // LCOV_EXCL_BR_LINE 6: For setting the initialization conditions at SystemManager startup // NOLINT(whitespace/line_length)
3298   }
3299   FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-");
3300   return l_eStatus;
3301 }  // End of EFrameworkunifiedStatus CSystemManager::GetVersionNumber( SS_VersionNumberType
3302
3303 EFrameworkunifiedStatus CSystemManager::GetBuildInfo(std::string &f_BuildInfoStr) {
3304   FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+");
3305   EFrameworkunifiedStatus l_eStatus;
3306
3307   CSMVersion cVersion;
3308   if (eFrameworkunifiedStatusOK != (l_eStatus = cVersion.get_build_info(f_BuildInfoStr))) {  // LCOV_EXCL_BR_LINE 6: For setting the initialization conditions at SystemManager startup // NOLINT(whitespace/line_length)
3309     LOG_ERROR("cVersion.get_build_info()");  // LCOV_EXCL_BR_LINE 6:For setting the initialization conditions at SystemManager startup // NOLINT(whitespace/line_length)
3310   }
3311   FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-");
3312   return l_eStatus;
3313 }  // End of EFrameworkunifiedStatus CSystemManager::GetBuildInfo(std::string)
3314
3315 bool CSystemManager::GetDramPowerStatusInfo(const HANDLE h_app) {
3316   PsmDramStsT l_dram_sts = PSM_DRAM_STS_NORMAL;
3317   bool ret = false;
3318
3319   // Checking dram power status.
3320   if (PsmGetDramPowerSupplyAbnormalityCheckResultPower(h_app, &l_dram_sts))
3321     return ret;
3322
3323   if (l_dram_sts == PSM_DRAM_STS_NORMAL)
3324     ret = true;
3325
3326   return ret;
3327 }
3328
3329 bool CSystemManager::GetDramStoreStatusInfo(const HANDLE h_app) {
3330   PsmSysupDramT l_dram1 = PSM_SYSUP_DRAM_NORMAL;
3331   PsmSysupDramT l_dram2 = PSM_SYSUP_DRAM_NORMAL;
3332   PsmSysupDramT l_dram3 = PSM_SYSUP_DRAM_NORMAL;
3333   PsmStartStatusT l_sts = PSM_START_STATUS_FACTRESET;
3334
3335   bool ret = false;
3336
3337   // Checking factory shipment status
3338   if (PsmGetStartStatusPower(h_app, &l_sts))
3339     return ret;
3340
3341   if (l_sts == PSM_START_STATUS_FACTRESET) {
3342     ret = true;
3343     goto finish;
3344   }
3345
3346   // Checking dram power
3347   if (!GetDramPowerStatusInfo(h_app))
3348     goto finish;
3349
3350   // Checking dram status.
3351   if (PsmGetDramBackupStatusPower(h_app, &l_dram1, &l_dram2, &l_dram3))
3352     goto finish;
3353
3354   // l_dram2 and l_dram3 would be ignored.
3355   if (l_dram1 == PSM_SYSUP_DRAM_NORMAL)
3356     ret = true;
3357
3358   if (l_dram2 == PSM_SYSUP_DRAM_SFTERRSR)
3359     ret = true;
3360
3361 finish:
3362   return ret;
3363 }
3364
3365 bool CSystemManager::GetSyscomPowerStatusInfo(const HANDLE h_app) {
3366   PsmComStsT l_syscom_sts = PSM_COM_STS_NORMAL;
3367   bool ret = false;
3368
3369   if (PsmGetSyscomStatusPower(h_app, &l_syscom_sts))
3370     return ret;
3371
3372   if (l_syscom_sts == PSM_COM_STS_NORMAL)
3373     ret = true;
3374
3375   return ret;
3376 }
3377
3378 EFrameworkunifiedStatus CSystemManager::OnSetStartupConfirmationDataRequest(HANDLE hApp) {
3379   FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+");
3380   INTERFACEUNIFIEDLOG_RECEIVED_FROM(hApp);  // LCOV_EXCL_BR_LINE 15: marco defined in ss_templates.h  // NOLINT(whitespace/line_length)
3381   FRAMEWORKUNIFIEDLOG(ZONE_PERFORMANCE, __FUNCTION__, "from %s", FrameworkunifiedGetMsgSrc(hApp));
3382   EFrameworkunifiedStatus l_eStatus;
3383   Pwr_ServiceSetInterface tServiceSetIf;
3384   // ReadMsg():                                                        *
3385   //     Check hApp ptr, msg size, msg reception, read msg if all ok.  *
3386   //     Report any errors found.                                      *
3387   //                                                                   *
3388   if (eFrameworkunifiedStatusOK
3389       != (l_eStatus = ReadMsg < Pwr_ServiceSetInterface > (hApp, tServiceSetIf))) {  // LCOV_EXCL_BR_LINE 4:NSFW's error
3390     // LCOV_EXCL_START 4:NSFW's error
3391     AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
3392     LOG_ERROR("ReadMsg()");  // LCOV_EXCL_BR_LINE 15: marco defined in ss_templates.h  // NOLINT(whitespace/line_length)
3393     // LCOV_EXCL_STOP
3394   } else {
3395     m_startUpConfirmationMsg = tServiceSetIf.data.startupConfirmationMsg;
3396     FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__, " %s Startup Confirmation data:", FrameworkunifiedGetMsgSrc(hApp));
3397     SYSTEMMANAGERLOG_StartupConfirmationMsg(m_startUpConfirmationMsg);  // LCOV_EXCL_BR_LINE 15: marco defined in ns_logger_if.h  // NOLINT(whitespace/line_length)
3398     DGCODE_RET_API  l_ret = DGCODE_RET_ERROR;
3399
3400     l_ret = Diag_StartupAllStatusOfDTC();
3401     if (l_ret == DGCODE_RET_ERROR) {
3402       LOG_ERROR("Diag_StartupAllStatusOfDTC()");  // LCOV_EXCL_BR_LINE 15: marco defined in ss_templates.h  // NOLINT(whitespace/line_length)
3403     }
3404
3405     if ((e_SS_SM_NEXT_WAKEUP_TYPE_COLD == m_NextWakeupType) && (epsstCOLDSTART != m_startUpConfirmationMsg.wakeupType)) {  //  LCOV_EXCL_BR_LINE 6: Because the above formula cannot be set to true // NOLINT(whitespace/line_length)
3406       // LCOV_EXCL_START 6: Because the condition cannot be set
3407       AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
3408       FRAMEWORKUNIFIEDLOG(ZONE_STATE, __FUNCTION__, "WakeupType Change to Cold by Svc Request");
3409       m_startUpConfirmationMsg.wakeupType = epsstCOLDSTART;
3410       // LCOV_EXCL_STOP
3411     }
3412
3413     m_ResetStatus = ((m_isIlgReset == TRUE) ?
3414                      e_SS_SM_RESET_STATUS_NG :
3415                     ((m_isImmediateReset == TRUE) ?
3416                      e_SS_SM_RESET_STATUS_IMMEDIATE : e_SS_SM_RESET_STATUS_NONE));
3417     if (e_SS_SM_RESET_STATUS_NG == m_ResetStatus) {
3418       FRAMEWORKUNIFIEDLOG(ZONE_ERR, __PRETTY_FUNCTION__,
3419           "ResetStatus NG   illRst:%s lastErr:Not Support",
3420           m_isIlgReset ? "TRUE" : "FALSE");
3421       m_ResetCount++;
3422       if (PowerHalSetResetInfo(AGL_RESET_COUNTER, m_ResetCount)) {
3423         FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__,
3424           "Could not back up m_ResetCount(%lu) to power_hal", m_ResetCount);
3425       }
3426     }
3427
3428     m_DramBackupStatus =
3429             ((epsstWARMSTART != m_startUpConfirmationMsg.wakeupType)
3430             || (e_SS_SM_DATA_RESET_MODE_FACTORY == m_DataResetMode)
3431             || (GetDramStoreStatusInfo(hApp) == false)) ?
3432             e_SS_SM_DRAM_BACKUP_NG : e_SS_SM_DRAM_BACKUP_OK;
3433
3434     if (e_SS_SM_DRAM_BACKUP_NG == m_DramBackupStatus) {
3435       FRAMEWORKUNIFIEDLOG(ZONE_ERR, __PRETTY_FUNCTION__,
3436           "DramBackup NG  wakeupType:%s dataResetMode:%s",
3437           (epsstWARMSTART == m_startUpConfirmationMsg.wakeupType) ?
3438           "WARM" : "COLD",
3439           (e_SS_SM_DATA_RESET_MODE_FACTORY == m_DataResetMode) ?
3440           "FACTORY" : "NotFactory");
3441     }
3442
3443     if (m_needReNotifyStartPrm) {  //  LCOV_EXCL_BR_LINE 6: Because the condition cannot be satisfied from the external API
3444       // LCOV_EXCL_BR_START 6: Because both sides are not FALSE
3445       if (e_SS_SM_DRAM_BACKUP_NG == m_DramBackupStatus) {
3446       // LCOV_EXCL_BR_STOP
3447         m_DramBackupStatus = e_SS_SM_DRAM_BACKUP_NG;
3448       }
3449     }
3450
3451     if (m_needReNotifyStartPrm) {  //  LCOV_EXCL_BR_LINE 6: Because the condition cannot be satisfied from the external API
3452       if (e_SS_SM_RESET_STATUS_NG == m_ResetStatus) {
3453         // do nothing, keep m_ResetStatus.
3454       } else if (e_SS_SM_RESET_STATUS_IMMEDIATE == m_ResetStatus) {
3455         // do nothing, keep m_ResetStatus.
3456       } else {
3457         m_ResetStatus = e_SS_SM_RESET_STATUS_NONE;
3458       }
3459
3460       if (epsstWARMSTART != m_startUpConfirmationMsg.wakeupType) {  //  LCOV_EXCL_BR_LINE 6: Because the above condition cannot be satisfied // NOLINT(whitespace/line_length)
3461         m_startUpConfirmationMsg.wakeupType = epsstCOLDSTART;
3462       }
3463     }
3464
3465     CALL_AND_LOG_STATUS(ClearDramBackupInfo(hApp));  // LCOV_EXCL_BR_LINE 15: marco defined in ss_templates.h  // NOLINT(whitespace/line_length)
3466
3467     FRAMEWORKUNIFIEDLOG(ZONE_STATE, __FUNCTION__, "\n"
3468       "start prm\n"
3469       "dramBackupStatus = %s\n"
3470       "wakeupType       = %s\n"
3471       "dataResetMode    = %s\n"
3472       "resetStatus      = %s\n"
3473       "resetCount       = %d\n"
3474       "progUpdateState  = %d",
3475       (m_DramBackupStatus == e_SS_SM_DRAM_BACKUP_OK) ? "OK" : "NG",
3476       (m_startUpConfirmationMsg.wakeupType == epsstWARMSTART) ? "WARM" : "COLD",
3477       (m_DataResetMode == e_SS_SM_DATA_RESET_MODE_FACTORY) ? "FACT" :
3478       (m_DataResetMode == e_SS_SM_DATA_RESET_MODE_USER) ? "USER" :
3479       (m_DataResetMode == e_SS_SM_DATA_RESET_MODE_PROGUPDATE) ? "PROG" : "NONE",
3480       (m_ResetStatus == e_SS_SM_RESET_STATUS_IMMEDIATE) ? "IMM" :
3481       (m_ResetStatus == e_SS_SM_RESET_STATUS_NONE) ? "NONE" : "NG", m_ResetCount,
3482       m_ProgUpdateState);
3483
3484     if (eFrameworkunifiedStatusOK != (l_eStatus = FrameworkunifiedNPPublishNotification(hApp, NTFY_SSSystemMgrStartUpType, &m_startUpConfirmationMsg.wakeupType, sizeof(EPWR_SC_WAKEUP_TYPE)))) {  // LCOV_EXCL_BR_LINE 4:NSFW error case  //NOLINT (whitespace/line_length)
3485       // LCOV_EXCL_START 4: nsfw error
3486       AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
3487       FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__,
3488           " Error: FrameworkunifiedNPPublishNotification(%s, %s) errored: %d/'%s'",
3489           NTFY_SSSystemMgrStartUpType,
3490           GetStr(m_startUpConfirmationMsg.wakeupType).c_str(), l_eStatus,
3491           GetStr(l_eStatus).c_str());
3492       // LCOV_EXCL_STOP
3493     } else {
3494       FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__, " FrameworkunifiedNPPublishNotification(%s, %s) successful",
3495           NTFY_SSSystemMgrStartUpType,
3496           GetStr(m_startUpConfirmationMsg.wakeupType).c_str());
3497
3498       // LCOV_EXCL_BR_START 200: As there are no cases other than eFrameworkunifiedStatusOK
3499       REC_HIST_IF_SUCCESSFUL("SM/StartUpType",
3500                              m_PubCmdHist, m_PubHistIter, "", l_eStatus);
3501       // LCOV_EXCL_BR_STOP
3502     }
3503   }
3504
3505   EFrameworkunifiedStatus l_responseStatus = l_eStatus;
3506
3507   ModuleLaunchListIter l_ModuleListIter;
3508   PCSTR l_moduleName = FrameworkunifiedGetMsgSrc(hApp);
3509   if (eFrameworkunifiedStatusOK != (l_eStatus = GetModuleIterator(l_moduleName, l_ModuleListIter))) {
3510     FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__,
3511         " Error: Module %s not found in Group Launch Map", l_moduleName);
3512   } else if (l_ModuleListIter->hsession != NULL) {
3513     if (eFrameworkunifiedStatusOK != (l_eStatus = FrameworkunifiedSendMsg(l_ModuleListIter->hsession,  // LCOV_EXCL_BR_LINE 4:NSFW's error
3514             SS_SM_FWD_START_CONFIRMATION_MSG_RESP, sizeof(EFrameworkunifiedStatus),
3515             (PVOID) & l_responseStatus))) {
3516       // LCOV_EXCL_START 4:NSFW's error
3517       AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
3518       LOG_ERROR("FrameworkunifiedSendMsg(SS_SM_FWD_START_CONFIRMATION_MSG_RESP)");  // LCOV_EXCL_BR_LINE 15: marco defined in ss_templates.h  // NOLINT(whitespace/line_length)
3519       // LCOV_EXCL_STOP
3520     }
3521   } else {
3522     FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, " NULL == hsession; %s not connected yet", l_ModuleListIter->name.c_str());
3523   }
3524   FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-");
3525   return l_eStatus;
3526 }  // End of EFrameworkunifiedStatus CSystemManager::OnSetStartupConfirmationDataRequest( HANDLE hApp )
3527
3528 EFrameworkunifiedStatus CSystemManager::GetTimeStamp(std::string& TimeStamp) {
3529   FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+");
3530   EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK;
3531
3532   CHAR format[256] = { '\0' };
3533   CHAR l_format[256] = { '\0' };
3534   struct timeb timebuf;
3535   uint32_t time;
3536   uint8_t status;
3537   struct tm theTime;
3538   ftime(&timebuf);
3539   Clock_getSystemTimeY2K38(&time, &status);
3540   CLOCK_RETURN clock_ret = Clock_CnvSecToDateY2K38(&time, &theTime);
3541
3542   if (CLOCK_OK != clock_ret) {
3543     return eFrameworkunifiedStatusNullPointer;
3544   }
3545
3546   sprintf(l_format, "GMT Time,%04d-%02d-%02d %02d:%02d:%02d.%hu\n",  // NOLINT
3547   theTime.tm_year + 1900, theTime.tm_mon + 1, theTime.tm_mday,
3548   theTime.tm_hour, theTime.tm_min, theTime.tm_sec, timebuf.millitm);
3549
3550   struct timespec timeSpec;
3551
3552   if (0 != clock_gettime(CLOCK_MONOTONIC, &timeSpec)) {
3553     SS_ASERT_ERRNO(0);  // LCOV_EXCL_BR_LINE 15: marco defined in ss_templates.h  // NOLINT(whitespace/line_length)
3554   } else {
3555     time_t timeInSecs = timeSpec.tv_sec;
3556     sprintf(format, "Elaps Time,%ld:%02ld:%02ld\n", (timeInSecs / 3600),  // NOLINT
3557             ((timeInSecs % 3600) / 60), (timeInSecs % 60));
3558   }
3559
3560   TimeStamp.clear();
3561   TimeStamp.assign(format);
3562   TimeStamp.append(l_format);
3563
3564   FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-");
3565   return l_eStatus;
3566 }
3567
3568 VOID CSystemManager::SYSTEMMANAGERLOG_StartupConfirmationMsg(EPWR_SC_MSG_STRUCT & f_scMsg) {
3569   std::stringstream l_enumStr;
3570   l_enumStr << endl;
3571   l_enumStr << " HostProcSoftVer:" << hex << std::setw(16) << std::setfill('0')
3572       << m_VersionNumberStruct.m_VersionNumber << endl;
3573   l_enumStr << "  _CWORD56_ Boot Mode:" << GetStr(f_scMsg._CWORD56_BootMode) << endl; // LCOV_EXCL_BR_LINE 11:unexpected branch  // NOLINT(whitespace/line_length)
3574   l_enumStr << "  wakeupType    :" << GetStr(f_scMsg.wakeupType); // LCOV_EXCL_BR_LINE 11:unexpected branch  // NOLINT(whitespace/line_length)
3575
3576   FRAMEWORKUNIFIEDLOG(ZONE_STATE, __FUNCTION__, "%s", l_enumStr.str().c_str());
3577 }  // End of VOID CSystemManager::SYSTEMMANAGERLOG_StartupConfirmationMsg( EPWR_SC_MSG_STRUCT & f_scMsg )
3578
3579 VOID CSystemManager::LogESystemmanagerStatusEnums() {
3580   #define INITIAL_INDEX eFrameworkunifiedStatusEmptyMediaList
3581   #define FINAL_INDEX   eFrameworkunifiedStatusErrNoEINTR
3582
3583   FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+");
3584   std::stringstream l_enumStr;
3585   for (int i = INITIAL_INDEX; i <= FINAL_INDEX; i++) {
3586     // LCOV_EXCL_BR_START 11:unexpected branch  // NOLINT(whitespace/line_length)
3587     l_enumStr << "\n" << "0x" << std::setfill('0') << std::setw(8) << hex << i
3588       << "/" << std::setfill(' ') << std::setw(2) << dec << i << ": "
3589       << GetStr(static_cast<EFrameworkunifiedStatus>(i));
3590     // LCOV_EXCL_BR_STOP
3591   }
3592
3593   std::string l_logMsg = l_enumStr.str();
3594   SystemmanagerLogString(ZONE_INFO, __FUNCTION__, l_logMsg); // LCOV_EXCL_BR_LINE 11:unexpected branch  // NOLINT(whitespace/line_length)
3595   FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-");
3596
3597 #undef INITIAL_INDEX
3598 #undef FINAL_INDEX
3599 }  // End of VOID CSystemManager::LogESystemmanagerStatusEnums()
3600
3601 VOID CSystemManager::LogProtocolIDs() {
3602 #define INITIAL_INDEX SS_SYSTEM_MANAGER_PROTOCOL_BEGINNING_INDEX
3603 #define FINAL_INDEX   SS_SYSTEM_MANAGER_PROTOCOL_ENDING_INDEX
3604
3605   FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+");
3606   std::stringstream l_enumStr;
3607   for (int i = INITIAL_INDEX; i <= FINAL_INDEX; i++) {
3608     // LCOV_EXCL_BR_START 11:unexpected branch  // NOLINT(whitespace/line_length)
3609     l_enumStr << "\n" << "0x" << std::setfill('0') << std::setw(8) << hex << i
3610       << "/" << std::setfill(' ') << std::setw(2) << dec << i << ": "
3611       << GetStr(static_cast<SS_SystemManagerProtocol>(i));
3612     // LCOV_EXCL_BR_STOP
3613   }
3614
3615   std::string l_logMsg = l_enumStr.str();
3616   SystemmanagerLogString(ZONE_INFO, __FUNCTION__, l_logMsg);  // LCOV_EXCL_BR_LINE 11:unexpected branch  // NOLINT(whitespace/line_length)
3617   FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-");
3618
3619 #undef INITIAL_INDEX
3620 #undef FINAL_INDEX
3621 }  // End of VOID CSystemManager::LogProtocolIDs()
3622
3623 VOID CSystemManager::SystemmanagerLogString(TFrameworkunifiedZone f_zone, PCSTR f_func, std::string &f_text) {
3624   FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+");
3625   UI_32 l_offset = 0;
3626   UI_32 l_msgLenMax = MAX_QUEUE_MSG_SIZE - 512;  // Leave space for the appending of
3627                                                  // the NSLog date/time/service/line string.
3628
3629   if (f_text.at(f_text.length() - 1) == '\n') {  // LCOV_EXCL_BR_LINE 6: For setting the initialization conditions at SystemManager startup
3630     AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
3631     f_text.erase(f_text.length() - 1);  // LCOV_EXCL_LINE 6: For setting the initialization conditions at SystemManager startup
3632   }
3633
3634   while (l_offset < f_text.size()) {
3635     UI_32 l_charsRem = static_cast<UI_32>(f_text.size() - l_offset);
3636     UI_32 l_msgLen = (l_charsRem > l_msgLenMax) ?  // LCOV_EXCL_BR_LINE 6: For setting the initialization conditions at SystemManager startup
3637         l_msgLenMax : l_charsRem;  // LCOV_EXCL_BR_LINE 6: For setting the initialization conditions at SystemManager startup
3638     std::string l_msgStr = f_text.substr(l_offset, l_msgLen);
3639     size_t l_newLinePos = l_msgStr.find_last_of("\n", l_msgLen);
3640     if ((l_newLinePos != std::string::npos) && (l_charsRem > l_msgLenMax)) {  // LCOV_EXCL_BR_LINE 6: For setting the initialization conditions at SystemManager startup // NOLINT(whitespace/line_length)
3641       // LCOV_EXCL_START 6: For setting the initialization conditions at SystemManager startup
3642       AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
3643       l_msgStr = f_text.substr(l_offset, l_newLinePos);
3644       l_offset += static_cast<UI_32>(l_newLinePos);
3645       // LCOV_EXCL_STOP
3646     } else {
3647       l_offset += l_msgLen;
3648     }
3649
3650     FRAMEWORKUNIFIEDLOG(f_zone, f_func, l_msgStr.c_str());
3651   }
3652   FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-");
3653 }  // LCOV_EXCL_BR_LINE 10: Final line
3654
3655 // End of /SS_SystemManager/src/ss_system_manager.cpp