summaryrefslogtreecommitdiffstats
path: root/systemservice/system_manager/server/src/ss_system_manager_callbacks.cpp
blob: 2e597ce62241b121ecbfb2f10097b1cb1f05c4d1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
2562
2563
2564
2565
2566
2567
2568
2569
2570
2571
2572
2573
2574
2575
2576
2577
2578
2579
2580
2581
2582
2583
2584
2585
2586
2587
2588
2589
2590
2591
2592
2593
2594
2595
2596
2597
2598
2599
2600
2601
2602
2603
2604
2605
2606
2607
2608
2609
2610
2611
2612
2613
2614
2615
2616
2617
2618
2619
2620
2621
2622
2623
2624
2625
2626
2627
2628
2629
2630
2631
2632
2633
2634
2635
2636
2637
2638
2639
2640
2641
2642
2643
2644
2645
2646
2647
2648
2649
2650
2651
2652
2653
2654
2655
2656
2657
2658
2659
2660
2661
2662
2663
2664
2665
2666
2667
2668
2669
2670
2671
2672
2673
2674
2675
2676
2677
2678
2679
2680
2681
2682
2683
2684
2685
2686
2687
2688
2689
2690
2691
2692
2693
2694
2695
2696
2697
2698
2699
2700
2701
2702
2703
2704
2705
2706
2707
2708
2709
2710
2711
2712
2713
2714
2715
2716
2717
2718
2719
2720
2721
2722
2723
2724
2725
2726
2727
2728
2729
2730
2731
2732
2733
2734
2735
2736
2737
2738
2739
2740
2741
2742
2743
2744
2745
2746
2747
2748
2749
2750
2751
2752
2753
2754
2755
2756
2757
2758
2759
2760
2761
2762
2763
2764
2765
2766
2767
2768
2769
2770
2771
2772
2773
2774
2775
2776
2777
2778
2779
2780
2781
2782
2783
2784
2785
2786
2787
2788
2789
2790
2791
2792
2793
2794
2795
2796
2797
2798
2799
2800
2801
2802
2803
2804
2805
2806
2807
2808
2809
2810
2811
2812
2813
2814
2815
2816
2817
2818
2819
2820
2821
2822
2823
2824
2825
2826
2827
2828
2829
2830
2831
2832
2833
2834
2835
2836
2837
2838
2839
2840
2841
2842
2843
2844
2845
2846
2847
2848
2849
2850
2851
2852
2853
2854
2855
2856
2857
2858
2859
2860
2861
2862
2863
2864
2865
2866
2867
2868
2869
2870
2871
2872
2873
2874
2875
2876
2877
2878
2879
2880
2881
2882
2883
2884
2885
2886
2887
2888
2889
2890
2891
2892
2893
2894
2895
2896
2897
2898
2899
2900
2901
2902
2903
2904
2905
2906
2907
2908
2909
2910
2911
2912
2913
2914
2915
2916
2917
2918
2919
2920
2921
2922
2923
2924
2925
2926
2927
2928
2929
2930
2931
2932
2933
2934
2935
2936
2937
2938
2939
2940
2941
2942
2943
2944
2945
2946
2947
2948
2949
2950
2951
2952
2953
2954
2955
2956
2957
2958
2959
2960
2961
2962
2963
2964
2965
2966
2967
2968
2969
2970
2971
2972
2973
2974
2975
2976
2977
2978
2979
2980
2981
2982
2983
2984
2985
2986
2987
2988
2989
2990
2991
2992
2993
2994
2995
2996
2997
2998
2999
3000
3001
3002
3003
3004
3005
3006
3007
3008
3009
3010
3011
3012
3013
3014
3015
3016
3017
3018
3019
3020
3021
3022
3023
3024
3025
3026
3027
3028
3029
3030
3031
3032
3033
3034
3035
3036
3037
3038
3039
3040
3041
3042
3043
3044
3045
3046
3047
3048
3049
3050
3051
3052
3053
3054
3055
3056
3057
3058
3059
3060
3061
3062
3063
3064
3065
3066
3067
3068
3069
3070
3071
3072
3073
3074
3075
3076
3077
3078
3079
3080
3081
3082
3083
3084
3085
3086
3087
3088
3089
3090
3091
3092
3093
3094
3095
3096
3097
3098
3099
3100
3101
3102
3103
3104
3105
3106
3107
3108
3109
3110
3111
3112
3113
3114
3115
3116
3117
3118
3119
3120
3121
3122
3123
3124
3125
3126
3127
3128
3129
3130
3131
3132
3133
3134
3135
3136
3137
3138
3139
3140
3141
3142
3143
3144
3145
3146
3147
3148
3149
3150
3151
3152
3153
3154
3155
3156
3157
3158
3159
3160
3161
3162
3163
3164
3165
3166
3167
3168
3169
3170
3171
3172
3173
3174
3175
3176
3177
3178
3179
3180
3181
3182
3183
3184
3185
3186
3187
3188
3189
3190
3191
3192
3193
3194
3195
3196
3197
3198
3199
3200
3201
3202
3203
3204
3205
3206
3207
3208
3209
3210
3211
3212
3213
3214
3215
3216
3217
3218
3219
3220
3221
3222
3223
3224
3225
3226
3227
3228
3229
3230
3231
3232
3233
3234
3235
3236
3237
3238
3239
3240
3241
3242
3243
3244
3245
3246
3247
3248
3249
3250
3251
3252
3253
3254
3255
3256
3257
3258
3259
3260
3261
3262
3263
3264
3265
3266
3267
3268
3269
3270
3271
3272
3273
3274
3275
3276
3277
3278
3279
3280
3281
3282
3283
3284
3285
3286
3287
3288
3289
3290
3291
3292
3293
3294
3295
3296
3297
3298
3299
3300
3301
3302
3303
3304
3305
3306
3307
3308
3309
3310
3311
3312
3313
3314
3315
3316
3317
3318
3319
3320
3321
3322
3323
3324
3325
3326
3327
3328
3329
3330
3331
3332
3333
3334
3335
3336
3337
3338
3339
3340
3341
3342
3343
3344
3345
3346
3347
3348
3349
3350
3351
3352
3353
3354
3355
3356
3357
3358
3359
3360
3361
3362
3363
3364
3365
3366
3367
3368
3369
3370
3371
3372
3373
3374
3375
3376
3377
3378
3379
3380
3381
3382
3383
3384
3385
3386
3387
3388
3389
3390
3391
3392
3393
3394
3395
3396
3397
3398
3399
3400
3401
3402
3403
3404
3405
3406
3407
3408
3409
3410
3411
/*
 * @copyright Copyright (c) 2016-2020 TOYOTA MOTOR CORPORATION.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

///////////////////////////////////////////////////////////////////////////////
/// \ingroup  tag_SystemManager
/// \brief    This file provides support for System Manager business logic.
///
///////////////////////////////////////////////////////////////////////////////
#include <system_service/ss_heartbeat_service_protocol.h>
#include <system_service/ss_system_manager_if.h>
#include <system_service/ss_system_manager_if_local.h>
#include <native_service/frameworkunified_multithreading.h>
#include <sys/wait.h>
#include <system_service/ss_system_manager_notifications.h>
#include <system_service/ss_system_manager_notifications_local.h>
#include <native_service/frameworkunified_framework_if.h>
#include <system_service/ss_services.h>
#include <system_service/ss_power_service_if.h>
#include <processlauncher/ProcessLauncher.h>
#include <processlauncher/ss_sm_process_launcher_protocol.h>
#include <processlauncher/ss_sm_process_launcher.h>
#include <heartbeat/ss_hb_thread.h>

#include <system_service/ss_power_service_notifications.h>
#include <system_service/ss_power_service_protocol.h>

#include <native_service/ns_np_service.h>
#include <native_service/ns_np_service_protocol.h>
#include <native_service/ns_backup.h>

#include <stub/ss_diag.h>

#include <system_service/ss_error_message.h>
#include <system_service/ss_test_clients.h>
#include <system_service/ss_templates.h>
#include <native_service/ns_plogger_if.h>

#include <stdlib.h>
#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <string>

#include "ss_system_manager_callbacks.h"
#include "ss_system_manager.h"
#include "ss_sm_systemmanagerlog.h"
#include "ss_sm_config.h"

using namespace std;  // NOLINT

extern SS_String GetStr(SS_SMModuleState f_enum);

template<typename C, eFrameworkunifiedStatus (C::*M)(HANDLE)> EFrameworkunifiedStatus SysMgrCallback(HANDLE hApp) {
  EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusFail;
  C * pObj = static_cast<C *>(&CSystemManager::GetInstance());
  if (pObj) {  // LCOV_EXCL_BR_LINE 5 : new error
    l_eStatus = (pObj->*M)(hApp);
  }
  return l_eStatus;
}

template<typename C, eFrameworkunifiedStatus (C::*M)(HANDLE, UI_32)>
EFrameworkunifiedStatus SysMgrCbType2(HANDLE hApp, UI_32 f_UI_32) {
  EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusFail;
  C * pObj = static_cast<C *>(&CSystemManager::GetInstance());
  if (pObj) {  // LCOV_EXCL_BR_LINE 5 : new error
    l_eStatus = (pObj->*M)(hApp, f_UI_32);
  }
  return l_eStatus;
}

template<typename C, BOOL (C::*M)(UI_32)>
BOOL SysMgrCbType3(UI_32 f_UI_32) {
  BOOL l_bValue = FALSE;
  C * pObj = static_cast<C *>(&CSystemManager::GetInstance());
  if (pObj) {  // LCOV_EXCL_BR_LINE 5 : new error
    l_bValue = (pObj->*M)(f_UI_32);
  }
  return l_bValue;
}

enum {
  POWERON = TRUE,
  POWEROFF = FALSE
};

VOID CSystemManager::LogGroupModulesState(UI_32 f_groupId, std::string pStr) {
  if (IS_ZONE_SET(ZONE_INFO)) {  // LCOV_EXCL_BR_LINE 6: Because the applicable variable cannot be changed from the external API (only evaluated by the initial value)
    // LCOV_EXCL_START 6: Because the applicable variable cannot be changed from the external API (only evaluated by the initial value)
    AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
    FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+");

    GroupLaunchMapIter l_GroupIterator = m_MapProclaunchGrps.find(f_groupId);
    if (l_GroupIterator == m_MapProclaunchGrps.end()) {
      FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__,
             " Error: Group %d not found; 'm_MapProclaunchGrps' is empty",
             f_groupId);
    } else {
      std::string sIsOKFlag;
      TEXT(__FUNCTION__, " Group %d/%s, %ld modules: %s, %s", f_groupId,
          l_GroupIterator->second.name.c_str(),
          l_GroupIterator->second.modules.size(), pStr.c_str(),
          GetStr(m_SMCurrentState).c_str());

      ModuleLaunchListIter l_ModuleListIterator = l_GroupIterator->second.modules.begin();
      for (int i = 1;
          l_ModuleListIterator != l_GroupIterator->second.modules.end();
          l_ModuleListIterator++, i++) {
        sIsOKFlag = GetModuleCondition(l_ModuleListIterator) ? " " :  // 'blank' means OK
            "X";  // 'X' means state mismatch

        TEXT(__FUNCTION__,
          "   %2d: %-24s Start Req'd: %-5s %s %-24s %3dms, %3dms, %d",
          i, l_ModuleListIterator->name.c_str(),
        l_ModuleListIterator->is_start_required ?
                "TRUE" : "FALSE", sIsOKFlag.c_str(),
        l_ModuleListIterator->ModuleStateStr().c_str(),
        static_cast<SI_16>(l_ModuleListIterator->m_startReason.GetDelta()),
        static_cast<SI_16>(l_ModuleListIterator->m_stopReason.GetDelta()),
        l_ModuleListIterator->pid);
      }
    }
    FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-");
    // LCOV_EXCL_STOP
  }
}  // End of VOID CSystemManager::LogGroupModulesState( UI_32 f_groupId, std::string pStr)

VOID CSystemManager::LogAllGroupModulesState(std::string pStr) {
  FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+");

  std::string l_sIsOKFlag;
  GroupLaunchMapIter l_GroupIterator = m_MapProclaunchGrps.begin();

  std::stringstream l_comStream;

  l_comStream << pStr << "," << GetStr(m_SMCurrentState);

  std::string l_comStr = l_comStream.str();
  SystemmanagerLogString(ZONE_STATE, __FUNCTION__, l_comStr);

  while (l_GroupIterator != m_MapProclaunchGrps.end()) {
    std::stringstream l_tblStream;
    l_tblStream << "G" << l_GroupIterator->second.id << "/" << l_GroupIterator->second.name;

    ModuleLaunchListIter l_ModuleListIterator = l_GroupIterator->second.modules.begin();

    for (int i = 1;
        l_ModuleListIterator != l_GroupIterator->second.modules.end();
        l_ModuleListIterator++, i++) {
      // Since NPPService exceptionally transitions to STARTED when StartReq'd = N, it is not checked
      l_sIsOKFlag =
          GetModuleCondition(l_ModuleListIterator)
              | (FRAMEWORKUNIFIED_NS_NPSERVICE == l_ModuleListIterator->name) ?
              " " :  // 'blank' means OK
              "X";   // 'X' means state mismatch

      std::string l_isStartReqd = l_ModuleListIterator->is_start_required ? "T" : "F";

      l_tblStream << endl << " " << std::setw(2) << std::right << i << ":"
          << l_ModuleListIterator->pid << " "
          << l_ModuleListIterator->name << " " << "StartReq:"
          << l_isStartReqd << " " << l_sIsOKFlag
          << l_ModuleListIterator->ModuleStateStr();

      if (l_ModuleListIterator->is_start_required && (FRAMEWORKUNIFIED_NS_NPSERVICE != l_ModuleListIterator->name)) {  // LCOV_EXCL_BR_LINE 6: Because the condition cannot be set // NOLINT(whitespace/line_length)
        l_tblStream << " "
            << static_cast<SI_32>(l_ModuleListIterator->m_startReason.GetDelta())
            << "ms "
            << static_cast<SI_32>(l_ModuleListIterator->m_stopReason.GetDelta())
            << "ms";
      }
    }

    l_GroupIterator++;

    // Outputs each GROUP so that buffers do not overflow.
    std::string l_logMsgStr = l_tblStream.str();
    SystemmanagerLogString(ZONE_STATE, __FUNCTION__, l_logMsgStr);
  }

  FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-");
}  // End of VOID CSystemManager::LogAllGroupModulesState(std::string pStr)

BOOL CSystemManager::GetModuleCondition(ModuleLaunchListIter & f_ModuleIter) {
  FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+");
  BOOL l_bIsModuleStateGood = TRUE;

  switch (m_SMCurrentState) {  // LCOV_EXCL_BR_LINE 6: As no values are passed into the default case
  case SS_SM_READY_TO_LAUNCH_APP:
    l_bIsModuleStateGood = f_ModuleIter->IsModuleState(MODULE_STATE_INVALID);
    break;

  case SS_SM_APPS_LAUNCH_IN_PROGRESS:
    l_bIsModuleStateGood = f_ModuleIter->IsModuleState(MODULE_STATE_SKIPPED)
        || f_ModuleIter->IsModuleState(MODULE_STATE_LAUNCH_FAILED)
        || f_ModuleIter->IsModuleState(MODULE_STATE_LAUNCHING)
        || f_ModuleIter->IsModuleState(MODULE_STATE_LAUNCHED);
    break;

  case SS_SM_APPS_LAUNCHED_READY_TO_START:
    l_bIsModuleStateGood = f_ModuleIter->IsModuleState(MODULE_STATE_SKIPPED)
        || f_ModuleIter->IsModuleState(MODULE_STATE_LAUNCH_FAILED)
        || f_ModuleIter->IsModuleState(MODULE_STATE_CONNECTED)
        || f_ModuleIter->IsModuleState(MODULE_STATE_LAUNCHED);
    break;

  case SS_SM_APPS_START_IN_PROGRESS:
    l_bIsModuleStateGood = f_ModuleIter->IsModuleState(MODULE_STATE_SKIPPED)
        || f_ModuleIter->IsModuleState(MODULE_STATE_LAUNCH_FAILED)
        || (f_ModuleIter->is_start_required
            && (f_ModuleIter->IsModuleState(MODULE_STATE_START_SENT)
                || f_ModuleIter->IsModuleState(
                    MODULE_STATE_STARTED)))
        || (!f_ModuleIter->is_start_required
            && (f_ModuleIter->IsModuleState(MODULE_STATE_LAUNCHED)
                || f_ModuleIter->IsModuleState(
                    MODULE_STATE_CONNECTED)));
    break;

  case SS_SM_APPS_START_COMPLETE:
      l_bIsModuleStateGood =
          ((f_ModuleIter->IsModuleState(MODULE_STATE_SKIPPED) == TRUE)
              || (f_ModuleIter->IsModuleState(MODULE_STATE_LAUNCH_FAILED) == TRUE)
              || ((f_ModuleIter->is_start_required == TRUE)
                  && (f_ModuleIter->IsModuleState(MODULE_STATE_STARTED) == TRUE))
              || ((f_ModuleIter->is_start_required == FALSE)
                  && ((f_ModuleIter->IsModuleState(MODULE_STATE_LAUNCHED) == TRUE)
                      || (f_ModuleIter->IsModuleState(MODULE_STATE_CONNECTED) == TRUE)))) ? (BOOL) TRUE : (BOOL) FALSE;
    break;

  case SS_SM_APPS_PRE_START_IN_PROGRESS:
      l_bIsModuleStateGood =
          ((f_ModuleIter->IsModuleState(MODULE_STATE_SKIPPED) == TRUE)
              || (f_ModuleIter->IsModuleState(MODULE_STATE_LAUNCH_FAILED) == TRUE)
              || ((f_ModuleIter->is_start_required == TRUE)
                  && ((f_ModuleIter->IsModuleState(MODULE_STATE_START_PRE_SENT) == TRUE)
                      || (f_ModuleIter->IsModuleState(MODULE_STATE_STARTED_PRE) == TRUE)))
              || ((f_ModuleIter->is_start_required == FALSE)
                  && ((f_ModuleIter->IsModuleState(MODULE_STATE_LAUNCHED) == TRUE)
                      || (f_ModuleIter->IsModuleState(MODULE_STATE_CONNECTED) == TRUE)))) ? (BOOL) TRUE : (BOOL) FALSE;
    break;

    case SS_SM_APPS_PRE_STOP_IN_PROGRESS:
      l_bIsModuleStateGood =
          ((f_ModuleIter->IsModuleState(MODULE_STATE_SKIPPED) == TRUE)
              || (f_ModuleIter->IsModuleState(MODULE_STATE_LAUNCH_FAILED) == TRUE)
              || ((f_ModuleIter->is_start_required == TRUE)
                  && ((f_ModuleIter->IsModuleState(MODULE_STATE_STOP_PRE_SENT) == TRUE)
                      || (f_ModuleIter->IsModuleState(MODULE_STATE_STOPPED_PRE) == TRUE)))
              || ((f_ModuleIter->is_start_required == FALSE)
                  && ((f_ModuleIter->IsModuleState(MODULE_STATE_LAUNCHED) == TRUE)
                      || (f_ModuleIter->IsModuleState(MODULE_STATE_CONNECTED) == TRUE)))) ? (BOOL) TRUE : (BOOL) FALSE;
      break;

    case SS_SM_APPS_PRE_RUN_COMPLETE:
      l_bIsModuleStateGood =
          ((f_ModuleIter->IsModuleState(MODULE_STATE_SKIPPED) == TRUE)
              || (f_ModuleIter->IsModuleState(MODULE_STATE_LAUNCH_FAILED) == TRUE)
              || ((f_ModuleIter->is_start_required == TRUE)
                  && ((f_ModuleIter->IsModuleState(MODULE_STATE_STARTED_PRE) == TRUE)
                      || (f_ModuleIter->IsModuleState(MODULE_STATE_STOPPED_PRE) == TRUE)))
              || ((f_ModuleIter->is_start_required == FALSE)
                  && ((f_ModuleIter->IsModuleState(MODULE_STATE_LAUNCHED) == TRUE)
                      || (f_ModuleIter->IsModuleState(MODULE_STATE_CONNECTED) == TRUE)))) ? (BOOL) TRUE : (BOOL) FALSE;
      break;

    case SS_SM_APPS_BACKGROUND_START_IN_PROGRESS:
      l_bIsModuleStateGood =
          ((f_ModuleIter->IsModuleState(MODULE_STATE_SKIPPED) == TRUE)
              || (f_ModuleIter->IsModuleState(MODULE_STATE_LAUNCH_FAILED) == TRUE)
              || ((f_ModuleIter->is_start_required == TRUE)
                  && ((f_ModuleIter->IsModuleState(MODULE_STATE_START_BACKGROUND_SENT) == TRUE)
                      || (f_ModuleIter->IsModuleState(MODULE_STATE_STARTED_BACKGROUND) == TRUE)))
              || ((f_ModuleIter->is_start_required == FALSE)
                  && ((f_ModuleIter->IsModuleState(MODULE_STATE_LAUNCHED) == TRUE)
                      || (f_ModuleIter->IsModuleState(MODULE_STATE_CONNECTED) == TRUE)))) ? (BOOL) TRUE : (BOOL) FALSE;
      break;

    case SS_SM_APPS_BACKGROUND_STOP_IN_PROGRESS:
      l_bIsModuleStateGood =
          ((f_ModuleIter->IsModuleState(MODULE_STATE_SKIPPED) == TRUE)
              || (f_ModuleIter->IsModuleState(MODULE_STATE_LAUNCH_FAILED) == TRUE)
              || ((f_ModuleIter->is_start_required == TRUE)
                  && ((f_ModuleIter->IsModuleState(MODULE_STATE_STOP_BACKGROUND_SENT) == TRUE)
                      || (f_ModuleIter->IsModuleState(MODULE_STATE_STOPPED_BACKGROUND) == TRUE)))
              || ((f_ModuleIter->is_start_required == FALSE)
                  && ((f_ModuleIter->IsModuleState(MODULE_STATE_LAUNCHED) == TRUE)
                      || (f_ModuleIter->IsModuleState(MODULE_STATE_CONNECTED) == TRUE)))) ? (BOOL) TRUE : (BOOL) FALSE;
      break;
    case SS_SM_APPS_BACKGROUND_RUN_COMPLETE:
      l_bIsModuleStateGood =
          ((f_ModuleIter->IsModuleState(MODULE_STATE_SKIPPED) == TRUE)
              || (f_ModuleIter->IsModuleState(MODULE_STATE_LAUNCH_FAILED) == TRUE)
              || ((f_ModuleIter->is_start_required == TRUE)
                  && ((f_ModuleIter->IsModuleState(MODULE_STATE_STARTED_BACKGROUND) == TRUE)
                      || (f_ModuleIter->IsModuleState(MODULE_STATE_STOPPED_BACKGROUND) == TRUE)))
              || ((f_ModuleIter->is_start_required == FALSE)
                  && ((f_ModuleIter->IsModuleState(MODULE_STATE_LAUNCHED) == TRUE)
                      || (f_ModuleIter->IsModuleState(MODULE_STATE_CONNECTED) == TRUE)))) ? (BOOL) TRUE : (BOOL) FALSE;
      break;

  case SS_SM_APPS_STOPPING_AT__CWORD56__REQ:
  case SS_SM_APPS_STOPPING_AT_INTERNAL_REQ:
    l_bIsModuleStateGood = f_ModuleIter->IsModuleState(MODULE_STATE_SKIPPED)
        || f_ModuleIter->IsModuleState(MODULE_STATE_LAUNCH_FAILED)
        || (f_ModuleIter->is_start_required
            && (f_ModuleIter->IsModuleState(MODULE_STATE_STOP_SENT)
                || f_ModuleIter->IsModuleState(
                    MODULE_STATE_STOPPED)))
        || (!f_ModuleIter->is_start_required
            && (f_ModuleIter->IsModuleState(MODULE_STATE_LAUNCHED)
                || f_ModuleIter->IsModuleState(
                    MODULE_STATE_CONNECTED)));
    break;

  case SS_SM_WAITING_FOR_CRITICAL_APPS_AT__CWORD56__REQ:
  case SS_SM_WAITING_FOR_CRITICAL_APPS_AT_INTERNAL_REQ:
    l_bIsModuleStateGood = f_ModuleIter->IsModuleState(MODULE_STATE_SKIPPED)
        || f_ModuleIter->IsModuleState(MODULE_STATE_LAUNCH_FAILED)
        || (f_ModuleIter->is_start_required
            && f_ModuleIter->IsModuleState(MODULE_STATE_STOPPED))
        || (!f_ModuleIter->is_start_required
            && (f_ModuleIter->IsModuleState(MODULE_STATE_LAUNCHED)
                || f_ModuleIter->IsModuleState(
                    MODULE_STATE_CONNECTED)));
    break;

    // default:  Don't code a 'default' here - let the compiler
    // issue a warning ( set via -Wall or -Wswitch ) when the set of
    // enumerations changes - then the maintainer will
    // automagically know to update this switch statement.
  }

  FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-");
  return l_bIsModuleStateGood;
}  // End of BOOL CSystemManager::GetModuleCondition( ModuleLaunchListIter & f_ModuleIter )

/*****************************************************************************
 @ingroup: CSystemManager
 @brief: Post Termination handler
 @note: .
 @param void
 @return void
*****************************************************************************/
EFrameworkunifiedStatus CSystemManager::SendRequestToHeartBeat(HANDLE hApp,
        EHBProtocolMessages tRequest, VOID *tReqMessageData,
        UI_32 u32SizeofMessage) {
  EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK;
  BOOL bValid = FALSE;

  FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+");
  switch (tRequest) {
  case SS_HEARTBEAT_START:
    bValid = TRUE;
    FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__, "SS_HEARTBEAT_START");
    break;

  case SS_HEARTBEAT_STOP:
    bValid = TRUE;
    FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__, "SS_HEARTBEAT_STOP");
    tReqMessageData = NULL;
    break;

  case SS_HEARTBEAT_DELETE_MODULE_ENTRY:
    bValid = TRUE;
    FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__, "SS_HEARTBEAT_DELETE_MODULE_ENTRY");
    break;

  case SS_HEARTBEAT_APPEND_MODULE_ENTRY:
    bValid = TRUE;
    FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__, "SS_HEARTBEAT_APPEND_MODULE_ENTRY");
    break;

  default:
    bValid = FALSE;
    l_eStatus = eFrameworkunifiedStatusInvldParam;
    FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, " Error : Ignored Invalid message id 0x%X", tRequest);
    break;
  }

  if (TRUE == bValid) {  // LCOV_EXCL_BR_LINE 200:tRequest cannot be default, so bValid cannot be false
    if (INVALID_HANDLE != m_hHeartbeatThread.m_ThreadHdl) {  // LCOV_EXCL_BR_LINE 200:m_ThreadHdl cannot be null
      if (eFrameworkunifiedStatusOK != (l_eStatus = FrameworkunifiedSendChild(hApp, m_hHeartbeatThread.m_ThreadHdl, tRequest, u32SizeofMessage, tReqMessageData))) {  // LCOV_EXCL_BR_LINE 4:NSFW error case  //NOLINT (whitespace/line_length)
        // LCOV_EXCL_START 4: nsfw error
        AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
        LOG_ERROR("FrameworkunifiedSendChild()");  // LCOV_EXCL_BR_LINE 15: marco defined in ss_templates.h  // NOLINT(whitespace/line_length)
        // LCOV_EXCL_STOP
      }
    } else {
      // LCOV_EXCL_START 200: m_ThreadHdl cannot be null
      AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
      l_eStatus = eFrameworkunifiedStatusInvldHandle;
      FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, " Error : Invalid Heartbeat Thread Handle, cannot send message");
      // LCOV_EXCL_STOP
    }
  }
  FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-");
  return l_eStatus;
}

///////////////////////////////////////////////////////////////////////////////
/// \ingroup OnModuleConnectWaitTimeout
///  SM maintains timer (40 sec) to check if all modules opened session with him whoever requires Start.
///  This timer is common to all modules. After timeout it checks the status of every module in group map.
///  If a module requires start and does not connect, SM will initiate error event logging followed by Soft Reset
/// \param [in]
///
///
/// \return EFrameworkunifiedStatus
/// Success ==> eFrameworkunifiedStatusOK
/// Failure ==> Other values
///////////////////////////////////////////////////////////////////////////////
EFrameworkunifiedStatus CSystemManager::OnModuleConnectWaitTimeout(HANDLE hApp) {
  FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+");
  EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK;

  static SI_32 l_NumTimesChecked = 0;
  {
    char l_cFormat[] = " Received from (Timer expiration %d)";
    char l_cBuf[sizeof(l_cFormat) + 1];
    snprintf(l_cBuf, sizeof(l_cBuf), l_cFormat, l_NumTimesChecked + 1);
    FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__, l_cBuf);
  }

  std::string l_ProcName;

  SetCmdHist("SM_TIMER_MODULE_CONNECT_WAIT_TIMER", m_TimerCmdHist, // LCOV_EXCL_BR_LINE 11:unexpected branch  // NOLINT(whitespace/line_length)
      m_TimerHistIter, FrameworkunifiedGetMsgSrc(hApp)); // LCOV_EXCL_BR_LINE 11:unexpected branch  // NOLINT(whitespace/line_length)

  BOOL l_bModuleConnMissed = false;

  GroupLaunchMap::reverse_iterator l_grp_riter = m_MapProclaunchGrps.rbegin();

  ModuleLaunchList::reverse_iterator l_mod_riter;

  if (l_grp_riter == m_MapProclaunchGrps.rend()) {  // LCOV_EXCL_BR_LINE 200: group cannot be empty
    // LCOV_EXCL_START 200: group cannot be empty
    AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
    FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "Error: Group Map is Empty");  // LCOV_EXCL_BR_LINE 15: marco defined in ns_logger_if.h  // NOLINT(whitespace/line_length)
    l_eStatus = eFrameworkunifiedStatusDbRecNotFound;
    // LCOV_EXCL_STOP
  } else {
    // scan the group map in reverse order
    for (; l_grp_riter != m_MapProclaunchGrps.rend(); l_grp_riter++) {
      l_mod_riter = l_grp_riter->second.modules.rbegin();
      for (; l_mod_riter != l_grp_riter->second.modules.rend();
          l_mod_riter++) {
        SMModuleState l_ModuleState = l_mod_riter->GetModuleState();
        // if the module is still in MODULE_STATE_LAUNCHED state at
        // this point though it requires start something is wrong with
        // the module. SM initiates error event logging followed by
        // soft rest
        if (l_mod_riter->is_start_required
            && ((l_ModuleState == MODULE_STATE_INVALID)
                || (l_ModuleState == MODULE_STATE_SKIPPED)
                || (l_ModuleState == MODULE_STATE_LAUNCHING)
                || (l_ModuleState == MODULE_STATE_LAUNCHED)
                || (l_ModuleState == MODULE_STATE_LAUNCH_FAILED))) {
          FRAMEWORKUNIFIEDLOG(ZONE_WARN, __FUNCTION__,
              " Module %s/%s is not connected",
              l_mod_riter->name.c_str(),
              l_mod_riter->ModuleStateStr().c_str());
          l_bModuleConnMissed = true;
          l_ProcName.assign(l_mod_riter->name);

          if (l_ModuleState == MODULE_STATE_LAUNCHED) {
            CALL_AND_LOG_STATUS_IF_ERRORED(  // LCOV_EXCL_BR_LINE 15: marco defined in ss_templates.h  // NOLINT(whitespace/line_length)
                l_mod_riter->SetPriority(  // LCOV_EXCL_BR_LINE 15: marco defined in ss_templates.h  // NOLINT(whitespace/line_length)
                    m_SystemManagerPriority - 1));  // LCOV_EXCL_BR_LINE 15: marco defined in ss_templates.h  // NOLINT(whitespace/line_length)
          }
        }
      }
    }
  }

  PreLaunchModuleListIter l_itr;
  for (l_itr = m_PreLaunchModuleList.begin();
      m_PreLaunchModuleList.end() != l_itr; l_itr++) {
    if ((-1 == l_itr->pid) && (l_itr->critical)) {  // LCOV_EXCL_BR_LINE 200: all prelaunch mode is not critical  // NOLINT(whitespace/line_length)
      // LCOV_EXCL_START 200: all prelaunch mode is not critical
      AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
      FRAMEWORKUNIFIEDLOG(ZONE_WARN, __FUNCTION__, " Module %s is not launched",  // LCOV_EXCL_BR_LINE 15: marco defined in ns_logger_if.h  // NOLINT(whitespace/line_length)
          l_itr->name.c_str());  // LCOV_EXCL_BR_LINE 15: marco defined in ns_logger_if.h  // NOLINT(whitespace/line_length)
      l_bModuleConnMissed = true;
      l_ProcName.assign(l_itr->name);
    }
    // LCOV_EXCL_STOP
  }

  l_NumTimesChecked++;
  if (true == l_bModuleConnMissed) {
    if (l_NumTimesChecked < m_SMConfig.MCConfig.ModuleConnectionNumTimesToCheck) {
      char l_cFormat[] =
          " l_NumTimesChecked %d < ModuleConnectionNumTimesToCheck %d, "
              "will re-check in %d seconds. ";
      char l_cBuf[sizeof(l_cFormat) + 1 + 1 + 1];
      snprintf(l_cBuf, sizeof(l_cBuf), l_cFormat, l_NumTimesChecked,
          m_SMConfig.MCConfig.ModuleConnectionNumTimesToCheck,
          m_SMConfig.MCConfig.ModuleConnectionTimeOutSec);
      FRAMEWORKUNIFIEDLOG(ZONE_WARN, __FUNCTION__, l_cBuf);

    } else {
      l_eStatus = eFrameworkunifiedStatusBadConnection;
      char l_cFormat[] =
          " Module connection timeout for %s and "
              "l_NumTimesChecked %d == ModuleConnectionNumTimesToCheck %d. "
              " Stopping ModuleConnectTimeOut timer and resetting _CWORD102_.";
      char l_cBuf[sizeof(l_cFormat) + MAX_NAME_SIZE_APP + 1 + 1];
      snprintf(l_cBuf, sizeof(l_cBuf), l_cFormat, l_ProcName.c_str(),
          l_NumTimesChecked,
          m_SMConfig.MCConfig.ModuleConnectionNumTimesToCheck);
      LOG_ERROR(l_cBuf);  // LCOV_EXCL_BR_LINE 15: marco defined in ss_templates.h  // NOLINT(whitespace/line_length)

      m_GroupLaunchTimer->StopTimer(m_aTimerIDs[eSM_TIMER_MODULE_CONNECT_WAIT_TIMER]); // LCOV_EXCL_BR_LINE 11:unexpected branch  // NOLINT(whitespace/line_length)

      SMLoggingInfo l_loggingInfo; // LCOV_EXCL_BR_LINE 11:unexpected branch  // NOLINT(whitespace/line_length)
      l_loggingInfo.resetReason = e_SS_SM_CPU_RESET_REASON_GENERIC_ERR; // LCOV_EXCL_BR_LINE 11:unexpected branch  // NOLINT(whitespace/line_length)

      // initiate error event logging
      l_eStatus = ErrorEventEnqueue(hApp, eErrorEventTypeModConnFailed,
          l_ProcName, eErrorEventResetTypeHard, l_loggingInfo);
      FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, " Error: ModConnFailed %s",
          l_ProcName.c_str());
      fprintf(stderr, "SS_SysManager/%s/Error: ModConnFailed %s\n", // LCOV_EXCL_BR_LINE 11:unexpected branch  // NOLINT(whitespace/line_length)
          __FUNCTION__, l_ProcName.c_str()); // LCOV_EXCL_BR_LINE 11:unexpected branch  // NOLINT(whitespace/line_length)
      LOG_STATUS_REC_HIST_IF_ERRORED(l_eStatus,  // LCOV_EXCL_BR_LINE 15: marco defined in ss_system_manager.h  // NOLINT(whitespace/line_length)
          "ErrorEventEnqueue(eErrorEventTypeModConnFailed)");  // LCOV_EXCL_BR_LINE 15: marco defined in ss_system_manager.h  // NOLINT(whitespace/line_length)
    }
  } else {
    char l_cFormat[] =
        " l_NumTimesChecked = %d, ModuleConnectionNumTimesToCheck = %d. "
            "All modules connected. Stopping ModuleConnectTimeOut timer.";
    char l_cBuf[sizeof(l_cFormat) + 1 + 1];
    snprintf(l_cBuf, sizeof(l_cBuf), l_cFormat, l_NumTimesChecked,
        m_SMConfig.MCConfig.ModuleConnectionNumTimesToCheck);
    FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__, l_cBuf);

    m_GroupLaunchTimer->StopTimer(m_aTimerIDs[eSM_TIMER_MODULE_CONNECT_WAIT_TIMER]); // LCOV_EXCL_BR_LINE 11:unexpected branch  // NOLINT(whitespace/line_length)
  }

  FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-");
  return l_eStatus;
}  // End of EFrameworkunifiedStatus CSystemManager::OnModuleConnectWaitTimeout( HANDLE hApp )

///////////////////////////////////////////////////////////////////////////////
/// \ingroup OnClientStartMonitorTimerExpiry
///
///
/// \param [in]
///
///
/// \return EFrameworkunifiedStatus
/// Success ==> eFrameworkunifiedStatusOK
/// Failure ==> Other values
///////////////////////////////////////////////////////////////////////////////
EFrameworkunifiedStatus CSystemManager::OnClientStartMonitorTimerExpiry(HANDLE hApp) {
  EFrameworkunifiedStatus l_eStatus;
  FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+");

  FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__, " Received from group %d"
    //, m_ActiveGroupId);
      , m_SystemStarter.get_id());

  char cBuf[100];
  SetCmdHist("SM_TIMER_CLIENT_START_MONITOR", m_TimerCmdHist, m_TimerHistIter, FrameworkunifiedGetMsgSrc(hApp)); // LCOV_EXCL_BR_LINE 11:unexpected branch  // NOLINT(whitespace/line_length)
  // sprintf( cBuf, "ProcessGroupAsStarted(%d)", m_ActiveGroupId);
  sprintf(cBuf, "ProcessGroupAsStarted(%d)", m_SystemStarter.get_id());  // NOLINT
  l_eStatus = ProcessGroupAsStarted(hApp, m_SystemStarter.get_id());
  LOG_STATUS_REC_HIST_IF_ERRORED(l_eStatus, cBuf);  // LCOV_EXCL_BR_LINE 15: marco defined in ss_system_manager.h  // NOLINT(whitespace/line_length)

  FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-");


  return l_eStatus;
}

///////////////////////////////////////////////////////////////////////////////
/// \ingroup send_power_request_complete_response
/// send power request completion response to power
///
/// \param [in]
///
/// \return EFrameworkunifiedStatus
/// Success ==> eFrameworkunifiedStatusOK
/// Failure ==> Other values
///////////////////////////////////////////////////////////////////////////////
EFrameworkunifiedStatus CSystemManager::send_power_request_complete_response(HANDLE hApp, std::string pStr) {
  EFrameworkunifiedStatus l_eStatus;
  FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+");

  // send Wake-up complete response to Power
  l_eStatus = FrameworkunifiedSendMsg(m_hPowerServiceSession,
      SS_SM_WAKEUP_MODULES_CMPL_RSPN, sizeof(wakeInfo), (PVOID) & m_Wake);
  LOG_STATUS_REC_HIST_IF_ERRORED(l_eStatus, "FrameworkunifiedSendMsg(SS_SM_WAKEUP_MODULES_CMPL_RSPN)");  // LCOV_EXCL_BR_LINE 15: marco defined in ss_system_manager.h  // NOLINT(whitespace/line_length)

  LogAllGroupModulesState(pStr);

  FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-");
  return l_eStatus;
}  // End of EFrameworkunifiedStatus CSystemManager::send_power_request_complete_response( HANDLE hApp )

///////////////////////////////////////////////////////////////////////////////
/// \ingroup OnNPPStatusCheckMonitorTimerExpiry
///
/// \brief Called when NPP fails to provide a ready status in the specified.
///        amount of time.  This function will periodically request a new status
///        ACK from NPP service until one is received. See OnNPPReadyStatusCallback().
///
///        Note: NPP usually pushes a ready event to SM and the reversion to
///              polling the NPP ready ACK is for additional robustness. Failure
///              to receive an NPP ready ACK will prevent system startup.
///
/// \param [in] hApp - Handle to framework application.
///
/// \return EFrameworkunifiedStatus
/// Success ==> eFrameworkunifiedStatusOK
/// Failure ==> Other values
///////////////////////////////////////////////////////////////////////////////
EFrameworkunifiedStatus CSystemManager::OnNPPStatusCheckMonitorTimerExpiry(HANDLE hApp) {
  EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK;
  FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+");

  SetCmdHist("SM_TIMER_NPP_STATUS_CHECK_MONITOR", m_TimerCmdHist, // LCOV_EXCL_BR_LINE 11:unexpected branch  // NOLINT(whitespace/line_length)
      m_TimerHistIter, FrameworkunifiedGetMsgSrc(hApp)); // LCOV_EXCL_BR_LINE 11:unexpected branch  // NOLINT(whitespace/line_length)

  FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__, " m_bIsNPP_ServicesStarted is '%s'",
      GetStr(m_bIsNPP_ServicesStarted).c_str());

  if (FALSE == m_bIsNPP_ServicesStarted) {
    l_eStatus = FrameworkunifiedNPGetReadyStatusOfNPP(hApp);
    LOG_ERROR_REC_HIST_IF_ERRORED(l_eStatus, "FrameworkunifiedNPGetReadyStatusOfNPP()");  // LCOV_EXCL_BR_LINE 15: marco defined in ss_system_manager.h  // NOLINT(whitespace/line_length)
  }
  FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-");
  return l_eStatus;
}

///////////////////////////////////////////////////////////////////////////////
/// \ingroup OnNPPReadyStatusCallback
///
/// \brief Called when NPP returns a status ACK indicating that the service is
///        operational and ready to respond to subsequent requests.
///
/// \param [in] hApp - Handle to framework application.
///
/// \return EFrameworkunifiedStatus
/// Success ==> eFrameworkunifiedStatusOK
/// Failure ==> Other values
///////////////////////////////////////////////////////////////////////////////
EFrameworkunifiedStatus CSystemManager::OnNPPReadyStatusCallback(HANDLE hApp) {  // LCOV_EXCL_START 6: Because the condition cannot be set
  AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
  FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+");
  EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK;
  INTERFACEUNIFIEDLOG_RECEIVED_FROM(hApp);  // LCOV_EXCL_BR_LINE 15: marco defined in ns_logger_if.h  // NOLINT(whitespace/line_length)
  FRAMEWORKUNIFIEDLOG(ZONE_PERFORMANCE, __FUNCTION__, "from %s", FrameworkunifiedGetMsgSrc(hApp));

  SetCmdHist("NPS_GET_READYSTATUS_ACK", m_SMCmdHist, m_SMHistIter, FrameworkunifiedGetMsgSrc(hApp));

  l_eStatus = OnNPPReadyEventCallback(hApp);
  LOG_ERROR_REC_HIST_IF_ERRORED(l_eStatus, "OnNPPReadyEventCallback()");  // LCOV_EXCL_BR_LINE 15: marco defined in ss_system_manager.h  // NOLINT(whitespace/line_length)

  FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-");
  return l_eStatus;
}
// LCOV_EXCL_STOP

EFrameworkunifiedStatus CSystemManager::OnNPPReadyEventCallback(HANDLE hApp) {
  EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK;
  FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+");
  PCSTR l_moduleName = FrameworkunifiedGetMsgSrc(hApp);
  FRAMEWORKUNIFIEDLOG(ZONE_PERFORMANCE, __FUNCTION__, "from %s", l_moduleName);

  SetCmdHist("NPS_NPP_READY_EVENT", m_SMCmdHist, m_SMHistIter, l_moduleName); // LCOV_EXCL_BR_LINE 11:unexpected branch  // NOLINT(whitespace/line_length)
  if (TRUE == m_bIsNPP_ServicesStarted) {
    l_eStatus = eFrameworkunifiedStatusMsgNotProcessed;
    LOG_ERROR("TRUE == m_bIsNPP_ServicesStarted");  // LCOV_EXCL_BR_LINE 15: marco defined in ss_templates.h  // NOLINT(whitespace/line_length)
  } else {
    ModuleLaunchListIter l_ModuleListIter;
    m_bIsNPP_ServicesStarted = TRUE;
    FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__, " m_bIsNPP_ServicesStarted set 'TRUE'");
    m_GroupLaunchTimer->StopTimer(m_aTimerIDs[eSM_TIMER_NPP_STATUS_CHECK_MONITOR]);

    UI_32 l_cbCmdIdArrayNPPService[] = { NPS_NPP_READY_EVENT, NPS_GET_READYSTATUS_ACK };

    if (eFrameworkunifiedStatusOK != (l_eStatus = FrameworkunifiedDetachCallbacksFromDispatcher(hApp, FRAMEWORKUNIFIED_NS_NPSERVICE, l_cbCmdIdArrayNPPService, static_cast<UI_32>(_countof(l_cbCmdIdArrayNPPService))))) {  // LCOV_EXCL_BR_LINE 4:NSFW error case  //NOLINT (whitespace/line_length)
      // LCOV_EXCL_START 4: nsfw error code
      AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
      LOG_ERROR("FrameworkunifiedDetachCallbacksFromDispatcher()");  // LCOV_EXCL_BR_LINE 15: marco defined in ss_templates.h  // NOLINT(whitespace/line_length)
      // LCOV_EXCL_STOP
    } else if (eFrameworkunifiedStatusOK != (l_eStatus = register_all_notification_callbacks(hApp))) {    // LCOV_EXCL_BR_LINE 4:NSFW error case  //NOLINT (whitespace/line_length)
      // LCOV_EXCL_START 4: nsfw error code
      AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
      LOG_ERROR("register_all_notification_callbacks()");  // LCOV_EXCL_BR_LINE 15: marco defined in ss_templates.h  // NOLINT(whitespace/line_length)
      // LCOV_EXCL_STOP
    } else if (eFrameworkunifiedStatusOK != (l_eStatus = GetModuleIterator(l_moduleName, l_ModuleListIter))) {  // LCOV_EXCL_BR_LINE 200:NPP always in launch map  //NOLINT (whitespace/line_length)
      // LCOV_EXCL_START 200 : NPP service always in launch map
      AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
      FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__,  // LCOV_EXCL_BR_LINE 15: marco defined in ns_logger_if.h  // NOLINT(whitespace/line_length)
          " Error: Module %s not found in Group Launch Map",  // LCOV_EXCL_BR_LINE 15: marco defined in ns_logger_if.h  // NOLINT(whitespace/line_length)
          l_moduleName);  // LCOV_EXCL_BR_LINE 15: marco defined in ns_logger_if.h  // NOLINT(whitespace/line_length)
      // LCOV_EXCL_STOP
    } else {
      l_ModuleListIter->SetModuleState(MODULE_STATE_STARTED);

      if (m_oSystemLauncher.get_id() == 1) {
        m_oSystemLauncher.advance_id();
      }

      l_eStatus = OnLaunchGroup(hApp);
      LOG_ERROR_REC_HIST_IF_ERRORED(l_eStatus, "OnLaunchGroup(hApp)");  // LCOV_EXCL_BR_LINE 15: marco defined in ss_system_manager.h  // NOLINT(whitespace/line_length)
      if (eFrameworkunifiedStatusOK == l_eStatus) {   // LCOV_EXCL_BR_LINE 200: OnLaunchGroup() return ok
        FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__, " successful");
      }
    }
  }

  FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-");
  return l_eStatus;
}  // End of EFrameworkunifiedStatus CSystemManager::OnNPPReadyEventCallback( HANDLE hApp )

///////////////////////////////////////////////////////////////////////////////
/// \ingroup OnBackupMgrAvailCallback
/// BackupManager Availability Notification Callback
///
/// \param [in]
///
///
/// \return EFrameworkunifiedStatus
/// Success ==> eFrameworkunifiedStatusOK
/// Failure ==> Other values
///////////////////////////////////////////////////////////////////////////////
EFrameworkunifiedStatus CSystemManager::OnBackupMgrAvailCallback(HANDLE hApp) {
  FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+");
  EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK;

  if (sizeof(ServiceAvailability) != FrameworkunifiedGetMsgLength(hApp)) {  // LCOV_EXCL_BR_LINE 4: nsfw error
    // LCOV_EXCL_START 4: nsfw error
    AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
    SS_ASERT(0);  // LCOV_EXCL_BR_LINE 15: marco defined in ss_templates.h  // NOLINT(whitespace/line_length)
    // LCOV_EXCL_STOP
    l_eStatus = eFrameworkunifiedStatusFail;
  } else if (strcmp(FrameworkunifiedGetLastNotification(hApp), NTFY_BackupMgr_Availability) != 0) {  // LCOV_EXCL_BR_LINE 200:cannot be false //NOLINT (whitespace/line_length)
    // LCOV_EXCL_START 200: cannot be false
    AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
    SS_ASERT(0);  // LCOV_EXCL_BR_LINE 15: marco defined in ss_templates.h  // NOLINT(whitespace/line_length)
    l_eStatus = eFrameworkunifiedStatusFail;
    // LCOV_EXCL_STOP
  } else {
    m_bIsBackupAvail = FrameworkunifiedIsServiceAvailable(hApp);
    FRAMEWORKUNIFIEDLOG(ZONE_STATE, __FUNCTION__, "BackupAvail:%s", m_bIsBackupAvail ? "T" : "F");

    l_eStatus = OnLaunchGroup(hApp);
    LOG_ERROR_REC_HIST_IF_ERRORED(l_eStatus, "OnLaunchGroup(hApp)");  // LCOV_EXCL_BR_LINE 15: marco defined in ss_system_manager.h  // NOLINT(whitespace/line_length)
  }

  FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-");
  return l_eStatus;
}  // End of EFrameworkunifiedStatus CSystemManager::OnBackupMgrAvailCallback(HANDLE hApp)

///////////////////////////////////////////////////////////////////////////////
/// \ingroup OnPowerRequestCallback
/// PowerRequest callback handler
///
/// \param [in]
///
///
/// \return EFrameworkunifiedStatus
/// Success ==> eFrameworkunifiedStatusOK
/// Failure ==> Other values
///////////////////////////////////////////////////////////////////////////////
EFrameworkunifiedStatus CSystemManager::OnPowerRequestCallback(HANDLE hApp) {
  FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+");
  EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK;
  Pwr_ServiceSetInterface tServiceIf;
  INTERFACEUNIFIEDLOG_RECEIVED_FROM(hApp);  // LCOV_EXCL_BR_LINE 15: marco defined in ns_logger_if.h  // NOLINT(whitespace/line_length)

  SetCmdHist("SS_SM_POWER_REQUEST_MSG", m__CWORD56_CmdHist, m__CWORD56_HistIter, FrameworkunifiedGetMsgSrc(hApp));

  //  OnSystemManagerDebugDump(hApp);
  // ReadMsg():                                                        *
  //     Check hApp ptr, msg size, msg reception, read msg if all ok.  *
  //     Report any errors found.                                      *
  //                                                                   *
  if (eFrameworkunifiedStatusOK != (l_eStatus = ReadMsg < Pwr_ServiceSetInterface > (hApp, tServiceIf))) {  // LCOV_EXCL_BR_LINE 4:NSFW error case  //NOLINT (whitespace/line_length)
    // LCOV_EXCL_START 4: nsfw error
    AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
    LOG_ERROR("ReadMsg()");  // LCOV_EXCL_BR_LINE 15: marco defined in ss_templates.h  // NOLINT(whitespace/line_length)
    // LCOV_EXCL_STOP
  } else {
    // NOTE: interface_unified always set userMode as 0. so don't use m_lastUserMode.
    m_lastUserMode = tServiceIf.data.powerRequestMsg.userMode;
    //
    // 2012 December 04 Temporary hack ( I hope ) to set m_Wake to nominal
    // values. At present, the 'Power Request Message Response' is sent
    // back to Power Services via the 'send_power_request_complete_response()'
    // function, which uses m_Wake.
    m_Wake.powerupType =
        m_SSBool_to_PowerTypeEnumMap[m_SSUserMode_to_SSBoolEnumMap[m_lastUserMode]];

    m_Wake.up.factor = tServiceIf.data.powerRequestMsg.startupReason;

    if (epswfINVALID != m_Wake.up.factor) {
      m_StartUpReason = m_Wake.up.factor;
    }

    m_userModeChangeReason = tServiceIf.data.powerRequestMsg.userModeChangeReason;
    m_Wake.up.userModeChangeReason = m_userModeChangeReason;

    FRAMEWORKUNIFIEDLOG(ZONE_STATE, __FUNCTION__, "UserMode:%s, SM State:%s",
        GetStr(m_lastUserMode).c_str(),
        GetStr(m_SMCurrentState).c_str());
    FRAMEWORKUNIFIEDLOG(ZONE_PERFORMANCE, __FUNCTION__, "UserMode:%s, SM State:%s",
        GetStr(m_lastUserMode).c_str(),
        GetStr(m_SMCurrentState).c_str());
    CALL_AND_LOG_STATUS(PublishPowerOnOffNotification(hApp));  // LCOV_EXCL_BR_LINE 15: marco defined in ss_templates.h  // NOLINT(whitespace/line_length)

    switch (m_SMCurrentState) {  // LCOV_EXCL_BR_LINE 6: As not all cases can be passed through
      case SS_SM_READY_TO_LAUNCH_APP:
        FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__,
            " Error: Received a PowerRequest command while still in "
            "the '%s' state !!!",
            GetStr(m_SMCurrentState).c_str());
        l_eStatus = eFrameworkunifiedStatusErrOther;
        break;

      case SS_SM_APPS_LAUNCH_IN_PROGRESS:
        // When Start is received while processes are launching, we
        // need to send the Start request later, once the 'Open
        // Session Request' is received from the application.
        //*****
        // Deliberate commenting-out of case-break to allow this case to
        // use following case's logic.
        // break;
        //*****

      case SS_SM_APPS_LAUNCHED_READY_TO_START:
      case SS_SM_APPS_START_COMPLETE:
      case SS_SM_APPS_PRE_RUN_COMPLETE:
      case SS_SM_APPS_BACKGROUND_RUN_COMPLETE:
      case SS_SM_APPS_START_IN_PROGRESS:
      case SS_SM_APPS_PRE_START_IN_PROGRESS:
      case SS_SM_APPS_PRE_STOP_IN_PROGRESS:
      case SS_SM_APPS_BACKGROUND_START_IN_PROGRESS:
      case SS_SM_APPS_BACKGROUND_STOP_IN_PROGRESS:
        FRAMEWORKUNIFIEDLOG(ZONE_PERFORMANCE, __FUNCTION__, "Startup Reason is '%s'", GetStr(m_StartUpReason).c_str());
        if ((m_userModeChangeReason == epsumcrPARKING_B)
            || ((m_userModeChangeReason == epsumcrPRE_BA) && (m_SMCurrentState == SS_SM_APPS_PRE_RUN_COMPLETE))
            || ((m_userModeChangeReason == epsumcrNORMAL) && (m_SMCurrentState == SS_SM_APPS_START_COMPLETE))
            || ((m_userModeChangeReason == epsumcrBACKGROUND_BA)
                && (m_SMCurrentState == SS_SM_APPS_BACKGROUND_RUN_COMPLETE))) {
          // send the Power Request complete response to PowerService
          // LCOV_EXCL_BR_START 15: Excluded due to inlined functions
          CALL_AND_LOG_STATUS_IF_ERRORED(send_power_request_complete_response(hApp, "Power Request"));
          // LCOV_EXCL_BR_STOP 15: Excluded due to inlined functions
        } else {
          //
          // Publish the UserMode 'Off' notification now for those
          // applications that need immediate notification ( HMI )
          if (m_lastUserMode == epsumOFF) {
            CALL_AND_LOG_STATUS(PublishUserModeNotification(hApp));  // LCOV_EXCL_BR_LINE 15: marco defined in ss_templates.h  // NOLINT(whitespace/line_length)
          }

          CALL_AND_LOG_STATUS(BeginStartup(hApp));  // LCOV_EXCL_BR_LINE 15: marco defined in ss_templates.h  // NOLINT(whitespace/line_length)
        }
        break;

      case SS_SM_APPS_STOPPING_AT__CWORD56__REQ:
      case SS_SM_WAITING_FOR_CRITICAL_APPS_AT__CWORD56__REQ:
        // Abort the Stop.
        // Reset System Manager to handle (re)starting as if this is a
        // nominal start.
        m_GroupLaunchTimer->StopTimer(m_aTimerIDs[eSM_TIMER_CLIENT_STOP_MONITOR]);

        FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__, " Aborted %s, resetting to %s,"
            " restarting Application groups at group %d",
            GetStr(m_SMCurrentState).c_str(),
            GetStr(SS_SM_APPS_START_IN_PROGRESS).c_str()
            , m_SystemStarter.get_id());

        CALL_AND_LOG_STATUS(BeginStartup(hApp));  // LCOV_EXCL_BR_LINE 15: marco defined in ss_templates.h  // NOLINT(whitespace/line_length)

        break;

      case SS_SM_APPS_STOPPING_AT_INTERNAL_REQ:
      case SS_SM_WAITING_FOR_CRITICAL_APPS_AT_INTERNAL_REQ:  // LCOV_EXCL_START 8: As no value is set
          AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
          FRAMEWORKUNIFIEDLOG(ZONE_WARN, __FUNCTION__,
              " Warning: System Manager state is %d/'%s', ignoring "
              "PowerRequest command", m_SMCurrentState,
              GetStr(m_SMCurrentState).c_str());
          break;
      }  // LCOV_EXCL_STOP
    }
    FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-");
    return l_eStatus;
}  // End of EFrameworkunifiedStatus CSystemManager::OnPowerRequestCallback( HANDLE hApp )

///////////////////////////////////////////////////////////////////////////////
/// \ingroup
/// Begin the Startup process
///
/// \param [in]
///
///
/// \return EFrameworkunifiedStatus
/// Success ==> eFrameworkunifiedStatusOK
/// Failure ==> Other values
///////////////////////////////////////////////////////////////////////////////
EFrameworkunifiedStatus CSystemManager::BeginStartup(HANDLE hApp) {
  EFrameworkunifiedStatus l_eStatus;
  FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+");

  if ((m_userModeChangeReason != epsumcrPARKING_B) &&
      (m_userModeChangeReason != epsumcrPRE_BA) &&
      (m_userModeChangeReason != epsumcrNORMAL) &&
      (m_userModeChangeReason != epsumcrBACKGROUND_BA)) {
    // Not a power state transition request.
    return eFrameworkunifiedStatusOK;
  }

  switch (m_userModeChangeReason) {  // LCOV_EXCL_BR_LINE 6: Excluded because it has been guarded to prevent out-of-range values from entering immediately before.
  case epsumcrPRE_BA:
    // LCOV_EXCL_BR_START 6: This function is an internal function, and it is guarded so that the value outside the range is not entered by the caller, so it is excluded.
    if ((m_SMCurrentState == SS_SM_APPS_START_COMPLETE) || (m_SMCurrentState == SS_SM_APPS_BACKGROUND_RUN_COMPLETE)) {
      // LCOV_EXCL_BR_STOP 6: This function is an internal function, and it is guarded so that the value outside the range is not entered by the caller, so it is excluded.
      m_SystemStarter.to_end();
      SMSetState(hApp, SS_SM_APPS_PRE_STOP_IN_PROGRESS);
    } else {
      m_SystemStarter.to_begin();
      SMSetState(hApp, SS_SM_APPS_PRE_START_IN_PROGRESS);
    }
    break;
  case epsumcrNORMAL:
    m_SystemStarter.to_begin();
    SMSetState(hApp, SS_SM_APPS_START_IN_PROGRESS);
    break;
  case epsumcrBACKGROUND_BA:
    if (m_SMCurrentState == SS_SM_APPS_START_COMPLETE) {
      m_SystemStarter.to_end();
      SMSetState(hApp, SS_SM_APPS_BACKGROUND_STOP_IN_PROGRESS);
    } else {
      m_SystemStarter.to_begin();
      SMSetState(hApp, SS_SM_APPS_BACKGROUND_START_IN_PROGRESS);
    }
    break;
  default:
    break;
  }

  FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__,
      " Starting 'Start Resp Monitor' Timer with '%d' sec",
      m_SMConfig.MCConfig.ModuleStartRespTimeOutSec);

  m_GroupLaunchTimer->StartTimer(
      m_aTimerIDs[eSM_TIMER_START_RESP_MONITOR_WAIT_TIMER],
      m_SMConfig.MCConfig.ModuleStartRespTimeOutSec, 0, 0, 0);

  l_eStatus = start_all_modules_of_group(hApp, m_SystemStarter.get_id());
  if (eFrameworkunifiedStatusOK != l_eStatus) {
    FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__,
        " Error: start_all_modules_of_group(%d) errored: %d/'%s'",
        m_SystemStarter.get_id(), l_eStatus, GetStr(l_eStatus).c_str());
  }
  FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-");
  return l_eStatus;
}  // End of EFrameworkunifiedStatus CSystemManager::BeginStartup( HANDLE hApp )

///////////////////////////////////////////////////////////////////////////////
/// \ingroup OnWakeupCallback
/// WakeUp callback handler
///
/// \param [in]
///
///
/// \return EFrameworkunifiedStatus
/// Success ==> eFrameworkunifiedStatusOK
/// Failure ==> Other values
///////////////////////////////////////////////////////////////////////////////
EFrameworkunifiedStatus CSystemManager::OnWakeupCallback(HANDLE hApp) {  // LCOV_EXCL_START 6: Because the condition cannot be set
  AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
  EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusFail;
  FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+");
  INTERFACEUNIFIEDLOG_RECEIVED_FROM(hApp);
  FRAMEWORKUNIFIEDLOG(ZONE_PERFORMANCE, __FUNCTION__, "Received from %s", FrameworkunifiedGetMsgSrc(hApp));

  FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-");
  return l_eStatus;
}  // End of EFrameworkunifiedStatus CSystemManager::OnWakeupCallback( HANDLE hApp )
// LCOV_EXCL_STOP

///////////////////////////////////////////////////////////////////////////////
/// \ingroup OnModuleStartCompleteResponse
/// Start Response\Ack Handlers
///
/// \param [in]
///
///
/// \return EFrameworkunifiedStatus
/// Success ==> eFrameworkunifiedStatusOK
/// Failure ==> Other values
///////////////////////////////////////////////////////////////////////////////
EFrameworkunifiedStatus CSystemManager::OnModuleStartCompleteResponse(HANDLE hApp) {
  FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+");
  EFrameworkunifiedStatus l_eStatus;
  INTERFACEUNIFIEDLOG_RECEIVED_FROM(hApp);  // LCOV_EXCL_BR_LINE 15: marco defined in ns_logger_if.h  // NOLINT(whitespace/line_length)
  FRAMEWORKUNIFIEDLOG(ZONE_PERFORMANCE, __FUNCTION__, "%s", FrameworkunifiedGetMsgSrc(hApp));

  SetCmdHist("system_manager protocol completion response", m_SMCmdHist, m_SMHistIter, FrameworkunifiedGetMsgSrc(hApp));  // LCOV_EXCL_BR_LINE 11:unexpected branch  // NOLINT(whitespace/line_length)

  ModuleLaunchListIter l_ModuleListIter;
  std::string l_moduleName = FrameworkunifiedGetMsgSrc(hApp);
  l_eStatus = GetModuleIterator(l_moduleName.c_str(), l_ModuleListIter);
  if (eFrameworkunifiedStatusOK != l_eStatus) {  // LCOV_EXCL_BR_LINE 200:always be eFrameworkunifiedStatusOK
    // LCOV_EXCL_START 200: always be eFrameworkunifiedStatusOK
    AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
    FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__,
        " Error: Module %s not found in Group Launch Map",
        l_moduleName.c_str());
    // LCOV_EXCL_STOP
  } else {
    switch (m_SMCurrentState) {  // LCOV_EXCL_BR_LINE 200: cannot be SS_SM_READY_TO_LAUNCH_APP
    case SS_SM_READY_TO_LAUNCH_APP:
      // LCOV_EXCL_START 200: cannot be SS_SM_READY_TO_LAUNCH_APP
      AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
      FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__,
          " Error: Received while in the '%s' state !!!",
          GetStr(m_SMCurrentState).c_str());
      l_eStatus = eFrameworkunifiedStatusErrOther;
      break;
      // LCOV_EXCL_STOP

    case SS_SM_APPS_LAUNCH_IN_PROGRESS:
    case SS_SM_APPS_LAUNCHED_READY_TO_START:
    case SS_SM_APPS_START_IN_PROGRESS:
    case SS_SM_APPS_PRE_START_IN_PROGRESS:
    case SS_SM_APPS_PRE_STOP_IN_PROGRESS:
    case SS_SM_APPS_BACKGROUND_START_IN_PROGRESS:
    case SS_SM_APPS_BACKGROUND_STOP_IN_PROGRESS:
      {
        const SMModuleState l_state = InProgressStateToState();  // LCOV_EXCL_BR_LINE 11: Gcov constraints (because exception-handling routes are automatically generated) // NOLINT(whitespace/line_length)
        if (l_state != MODULE_STATE_INVALID) {
          const PCSTR l_loglist[] = {"start", "pre start", "pre stop", "background start", "background stop", ""};
          PCSTR l_logtxt;
          switch (l_state) {  // LCOV_EXCL_BR_LINE 6: As no other value is returned
          case MODULE_STATE_STARTED:
            l_logtxt = l_loglist[0];
            break;
          case MODULE_STATE_STARTED_PRE:
            l_logtxt = l_loglist[1];
            break;
          case MODULE_STATE_STOPPED_PRE:
            l_logtxt = l_loglist[2];
            break;
          case MODULE_STATE_STARTED_BACKGROUND:
            l_logtxt = l_loglist[3];
            break;
          case MODULE_STATE_STOPPED_BACKGROUND:
            l_logtxt = l_loglist[4];
            break;
          // LCOV_EXCL_START 6: As no other value is returned
          default:
            AGL_ASSERT_NOT_TESTED();
            l_logtxt = l_loglist[5];
            break;
          // LCOV_EXCL_STOP 6: As no other value is returned
          }
          l_eStatus = ModuleCompleteResponse(hApp, l_ModuleListIter, l_state,  // LCOV_EXCL_BR_LINE 11: Gcov constraints (because exception-handling routes are automatically generated) // NOLINT(whitespace/line_length)
                                             SysMgrCbType3<CSystemManager, &CSystemManager::IsGroupStarted>,
                                             SysMgrCbType2<CSystemManager, &CSystemManager::ProcessGroupAsStarted>,
                                             l_logtxt);
        }
      }
      break;

    case SS_SM_APPS_STOPPING_AT__CWORD56__REQ:
    case SS_SM_APPS_STOPPING_AT_INTERNAL_REQ:
    case SS_SM_WAITING_FOR_CRITICAL_APPS_AT__CWORD56__REQ:
    case SS_SM_WAITING_FOR_CRITICAL_APPS_AT_INTERNAL_REQ:
      // SystemManager changed state while this module was starting;
      // tell this module to stop.
      if (!l_ModuleListIter->IsModuleState(MODULE_STATE_STOP_SENT)
          && !l_ModuleListIter->IsModuleState(MODULE_STATE_STOPPED)) {
        T_SS_SM_STOP_DataStructType l_SM_STOP_Struct;
        l_SM_STOP_Struct.shutdownTrigger = m_shutdownTrigger;
        l_SM_STOP_Struct.lastUserMode = m_lastUserMode;

        CALL_AND_LOG_STATUS(                               // LCOV_EXCL_BR_LINE 15: marco defined in ss_templates.h  // NOLINT(whitespace/line_length)
            l_ModuleListIter->SendMsgAndUpdateState(
                &l_SM_STOP_Struct));
      }
      break;
    default:
      FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, " Error: Received while in the '%s' state !!!", GetStr(m_SMCurrentState).c_str());
      l_eStatus = eFrameworkunifiedStatusErrOther;
      break;
    }        // End switch ( m_SMCurrentState )
  }
  FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-");
  return l_eStatus;
}  // End of EFrameworkunifiedStatus CSystemManager::OnModuleStartCompleteResponse( HANDLE hApp )

///////////////////////////////////////////////////////////////////////////////
/// \ingroup ModuleCompleteResponse
/// Start Response\Ack Handlers
///
/// \param [in]
///
///
/// \return EFrameworkunifiedStatus
/// Success ==> eFrameworkunifiedStatusOK
/// Failure ==> Other values
///////////////////////////////////////////////////////////////////////////////
EFrameworkunifiedStatus CSystemManager::ModuleCompleteResponse(HANDLE hApp,
        ModuleLaunchListIter f_ModuleListIter, SMModuleState f_moduleState,
        FncCbType3 f_isGroupDoneFnc, FncCbType2 f_groupDoneFnc,
        PCSTR f_sCompleteTypeText) {
  EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK;
  FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+");
  std::string l_moduleName = FrameworkunifiedGetMsgSrc(hApp);
  FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__,
      " Received from %s, m_SystemStarter.get_id() is %d",
      l_moduleName.c_str()
      , m_SystemStarter.get_id());

  f_ModuleListIter->SetModuleState(f_moduleState);
  if (f_ModuleListIter->group_id != m_SystemStarter.get_id()) {
    // In PastModel002, it is assumed that there is no service that returns a FrameworkunifiedOnStop reply after the NPP service.
    // However, since _CWORD71_ does not assume this, completion of waiting for termination of the CRITICAL service must be
    // judged even when services other than the Group1 service terminate last.
    // Initially, SS_SM_WAITING_FOR_CRITICAL_APPS_AT_XXXX should be handled separately by ProcessModuleStopCompleteResponse(),
    // but this is limited to ModuleCompleteResponse in order to avoid code deviation from PastModel002 and limit the scope of effect.
    // LCOV_EXCL_BR_START 200 : m_SMCurrentState can't be SS_SM_WAITING_FOR_CRITICAL_APPS_AT__CWORD56__REQ and SS_SM_WAITING_FOR_CRITICAL_APPS_AT_INTERNAL_REQ  // NOLINT(whitespace/line_length)
    if ((MODULE_STATE_STOPPED == f_moduleState)
        && ((m_SMCurrentState
            == SS_SM_WAITING_FOR_CRITICAL_APPS_AT__CWORD56__REQ)
            || (m_SMCurrentState
                == SS_SM_WAITING_FOR_CRITICAL_APPS_AT_INTERNAL_REQ))) {
    // LCOV_EXCL_BR_STOP 200 : m_SMCurrentState can't be SS_SM_WAITING_FOR_CRITICAL_APPS_AT__CWORD56__REQ and SS_SM_WAITING_FOR_CRITICAL_APPS_AT_INTERNAL_REQ  // NOLINT(whitespace/line_length)
      // LCOV_EXCL_START 200 : m_SMCurrentState can't be SS_SM_WAITING_FOR_CRITICAL_APPS_AT__CWORD56__REQ and SS_SM_WAITING_FOR_CRITICAL_APPS_AT_INTERNAL_REQ  // NOLINT(whitespace/line_length)
      AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
      check_all_groups_have_stopped(hApp);
      // LCOV_EXCL_STOP
    } else {
      FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__,
          " %s ( group %d ) received out-of-synch; m_SystemStarter.get_id() is %d",
          l_moduleName.c_str(), f_ModuleListIter->group_id
          , m_SystemStarter.get_id());
    }
  } else {
    if ((*f_isGroupDoneFnc)(f_ModuleListIter->group_id)) {  // LCOV_EXCL_BR_LINE 11: Gcov constraints (because exception-handling routes are automatically generated) // NOLINT(whitespace/line_length)
      l_eStatus = (*f_groupDoneFnc)(hApp, f_ModuleListIter->group_id); // LCOV_EXCL_BR_LINE 11:unexpected branch  // NOLINT(whitespace/line_length)
    } else if (IS_ZONE_SET(ZONE_INFO)) {  // LCOV_EXCL_BR_LINE 6: Because the applicable variable cannot be changed from the external API (only evaluated by the initial value)
      // LCOV_EXCL_START 6: Because the applicable variable cannot be changed from the external API (only evaluated by the initial value)
      AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
      TEXT(__FUNCTION__,  // LCOV_EXCL_BR_LINE 15: marco defined in ns_logger_if.h  // NOLINT(whitespace/line_length)
          " Group %d %s incomplete, m_SystemStarter.get_id() is %d",  // LCOV_EXCL_BR_LINE 15: marco defined in ns_logger_if.h  // NOLINT(whitespace/line_length)
          f_ModuleListIter->group_id, f_sCompleteTypeText  // LCOV_EXCL_BR_LINE 15: marco defined in ns_logger_if.h  // NOLINT(whitespace/line_length)
          , m_SystemStarter.get_id());  // LCOV_EXCL_BR_LINE 15: marco defined in ns_logger_if.h  // NOLINT(whitespace/line_length)
      char cBuf[100];
      sprintf(cBuf, "%s incomplete", f_sCompleteTypeText);  // NOLINT
      LogGroupModulesState(f_ModuleListIter->group_id, cBuf);  // LCOV_EXCL_BR_LINE 11:unexpected branch  // NOLINT(whitespace/line_length)
      // LCOV_EXCL_STOP
    }
  }

  const SMModuleState l_transition_state = InProgressStateToState();  // LCOV_EXCL_BR_LINE 11: Gcov constraints (because exception-handling routes are automatically generated) // NOLINT(whitespace/line_length)
  if (l_transition_state == f_moduleState) {  // LCOV_EXCL_BR_LINE 6:  As no other value is returned
    if (have_all_services_start_completed(l_transition_state) == TRUE) {
      if ((m_SMCurrentState == SS_SM_APPS_PRE_START_IN_PROGRESS)
          || (m_SMCurrentState == SS_SM_APPS_PRE_STOP_IN_PROGRESS)) {
        SMSetState(hApp, SS_SM_APPS_PRE_RUN_COMPLETE);  // LCOV_EXCL_BR_LINE 11: Gcov constraints (because exception-handling routes are automatically generated) // NOLINT(whitespace/line_length)
      } else if ((m_SMCurrentState == SS_SM_APPS_BACKGROUND_START_IN_PROGRESS)
          || (m_SMCurrentState == SS_SM_APPS_BACKGROUND_STOP_IN_PROGRESS)) {
        SMSetState(hApp, SS_SM_APPS_BACKGROUND_RUN_COMPLETE);  // LCOV_EXCL_BR_LINE 11: Gcov constraints (because exception-handling routes are automatically generated) // NOLINT(whitespace/line_length)
      } else {
        SMSetState(hApp, SS_SM_APPS_START_COMPLETE);  // LCOV_EXCL_BR_LINE 11: Gcov constraints (because exception-handling routes are automatically generated) // NOLINT(whitespace/line_length)
      }
    }
  }

  FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-");
  return l_eStatus;
}  // End of EFrameworkunifiedStatus CSystemManager::ModuleCompleteResponse(

///////////////////////////////////////////////////////////////////////////////
/// \ingroup OnStartRespMonitorTimeout
///  SM maintains timer to check if all modules sent start response to him whoever requires Start.
///  This timer is common to all modules. After timeout it checks the status of every module in group map.
///  If a module sent start and does not respond, SM will initiate error event logging followed by Soft Reset
/// \param [in]
///
///
/// \return EFrameworkunifiedStatus
/// Success ==> eFrameworkunifiedStatusOK
/// Failure ==> Other values
///////////////////////////////////////////////////////////////////////////////
EFrameworkunifiedStatus CSystemManager::OnStartRespMonitorTimeout(HANDLE hApp) {  // LCOV_EXCL_START 6: Because the condition cannot be set
  AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
  EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK;
  FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+");
  INTERFACEUNIFIEDLOG_RECEIVED_FROM(hApp);  // LCOV_EXCL_BR_LINE 15: marco defined in ns_logger_if.h  // NOLINT(whitespace/line_length)
  FRAMEWORKUNIFIEDLOG(ZONE_PERFORMANCE, __FUNCTION__, "from %s", FrameworkunifiedGetMsgSrc(hApp));

  std::string l_ProcName;
  BOOL l_isStartRespNotReceived = false;

  SetCmdHist("SM_TIMER_START_RESP_MONITOR_WAIT_TIMER", m_TimerCmdHist,
      m_TimerHistIter, FrameworkunifiedGetMsgSrc(hApp));
  GroupLaunchMap::reverse_iterator l_grp_riter = m_MapProclaunchGrps.rbegin();
  ModuleLaunchList::reverse_iterator l_mod_riter;

  if (l_grp_riter == m_MapProclaunchGrps.rend()) {
    FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "Error: Group Map is Empty");
  } else {
    // scan the group map in reverse order
    for (; l_grp_riter != m_MapProclaunchGrps.rend(); l_grp_riter++) {
      l_mod_riter = l_grp_riter->second.modules.rbegin();
      for (; l_mod_riter != l_grp_riter->second.modules.rend(); l_mod_riter++) {
        // if a module sent start and not received response from module SM wait for "ModuleStartRespTimeout"
        // and initiated error event
        // logging followed by soft reset

        if (l_mod_riter->is_start_required) {
          if (l_mod_riter->IsModuleState(MODULE_STATE_START_SENT)) {
            FRAMEWORKUNIFIEDLOG(ZONE_WARN, __FUNCTION__,
                " Module [%s] did not respond(%s) to SM in allocated time [%d] sec",
                l_mod_riter->name.c_str(),
                l_mod_riter->ModuleStateStr().c_str(),
                m_SMConfig.MCConfig.ModuleStartRespTimeOutSec);
            l_isStartRespNotReceived = true;
            l_ProcName.assign(l_mod_riter->name);
          }
        }
      }
    }
  }

  if (true == l_isStartRespNotReceived) {
    char l_cFormat[] = " Error. Module '%s' start response timeout.";
    char l_cBuf[sizeof(l_cFormat) + MAX_NAME_SIZE_APP];
    snprintf(l_cBuf, sizeof(l_cBuf), l_cFormat, l_ProcName.c_str());
    TEXT(__FUNCTION__, l_cBuf);  // LCOV_EXCL_BR_LINE 15: marco defined in ns_logger_if.h  // NOLINT(whitespace/line_length)
    FRAMEWORKUNIFIEDLOG(ZONE_PERFORMANCE, __FUNCTION__, l_cBuf);

    SMLoggingInfo l_loggingInfo;
    l_loggingInfo.resetReason = e_SS_SM_CPU_RESET_REASON_GENERIC_ERR;

    // initate error event logging
    l_eStatus = ErrorEventEnqueue(hApp, eErrorEventTypeStartRespFailed,
        l_ProcName, eErrorEventResetTypeHard, l_loggingInfo);
    FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, " Error: StartRespFailed %s", l_ProcName.c_str());
    fprintf(stderr, "SS_SysManager/%s/Error: StartRespFailed %s\n",
        __FUNCTION__, l_ProcName.c_str());
    LOG_ERROR_REC_HIST_IF_ERRORED(l_eStatus,  // LCOV_EXCL_BR_LINE 15: marco defined in ss_system_manager.h  // NOLINT(whitespace/line_length)
        "ErrorEventEnqueue(eErrorEventTypeStartRespFailed)");  // LCOV_EXCL_BR_LINE 15: marco defined in ss_system_manager.h  // NOLINT(whitespace/line_length)
  } else {
    FRAMEWORKUNIFIEDLOG(ZONE_PERFORMANCE, __FUNCTION__,
        " All modules returned Start Response.");

    l_eStatus = FrameworkunifiedSendChild(hApp, m_hHeartbeatThread.m_ThreadHdl,
        SS_HEARTBEAT_AVAIL_CHECK_REQ, 0, NULL);
    SS_ASERT(l_eStatus == eFrameworkunifiedStatusOK);  // LCOV_EXCL_BR_LINE 15: marco defined in ss_templates.h  // NOLINT(whitespace/line_length)
  }

  FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-");
  return l_eStatus;
}  // End of EFrameworkunifiedStatus CSystemManager::OnStartRespMonitorTimeout(HANDLE hApp)
// LCOV_EXCL_STOP

///////////////////////////////////////////////////////////////////////////////
/// \ingroup OnShutdownCompleteMonitorTimeout
///  SM maintains timer to check if all modules sent start response to him whoever requires Start.
///  This timer is common to all modules. After timeout it checks the status of every module in group map.
///  If a module sent start and does not respond, SM will initiate error event logging followed by Soft Reset
/// \param [in]
///
///
/// \return EFrameworkunifiedStatus
/// Success ==> eFrameworkunifiedStatusOK
/// Failure ==> Other values
///////////////////////////////////////////////////////////////////////////////
EFrameworkunifiedStatus CSystemManager::OnShutdownCompleteMonitorTimeout(HANDLE hApp) {
  EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK;
  FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+");
  INTERFACEUNIFIEDLOG_RECEIVED_FROM(hApp);  // LCOV_EXCL_BR_LINE 15: marco defined in ns_logger_if.h  // NOLINT(whitespace/line_length)

  FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "Error: Reset Timeout");

  l_eStatus = SecureChipOff();
  if (eFrameworkunifiedStatusOK != l_eStatus) {
    FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "Error: SecureChipOff Failed");
  }

  m_ResetFactor = PSM_FACTOR_AGL_WITH_HISTORY;

  l_eStatus = perform_force_reset(hApp);

  FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-");
  return l_eStatus;
}  // End of EFrameworkunifiedStatus CSystemManager::OnShutdownCompleteMonitorTimeout(HANDLE hApp)

///////////////////////////////////////////////////////////////////////////////
/// \ingroup start_all_modules_of_group
/// Send START to all modules of the given group
///
/// \param [in]
///
///
/// \return EFrameworkunifiedStatus
/// Success ==> eFrameworkunifiedStatusOK
/// Failure ==> Other values
///////////////////////////////////////////////////////////////////////////////
EFrameworkunifiedStatus CSystemManager::start_all_modules_of_group(HANDLE hApp, UI_32 f_ui32GroupNumber) {
  EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK;
  FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+");

  GroupLaunchMapIter l_GroupIterator = m_MapProclaunchGrps.find(
      f_ui32GroupNumber);
  if (l_GroupIterator == m_MapProclaunchGrps.end()) {  // LCOV_EXCL_BR_LINE 6: Because the condition cannot be set
    AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
    FRAMEWORKUNIFIEDLOG(ZONE_ERR,
        __FUNCTION__
        , " Error: Group %d not found; 'm_MapProclaunchGrps' is empty",
        f_ui32GroupNumber);
    AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
    l_eStatus = eFrameworkunifiedStatusInvldParam;  // LCOV_EXCL_LINE 6: Because the condition cannot be set
  } else {
    T_SS_SM_START_DataStructType f_startupData(m_StartUpReason,
        m_PowerType_to_SSBoolEnumMap[m_Wake.powerupType],
        m_DataResetMode, m_startUpConfirmationMsg.securityStatus,
        m_startUpConfirmationMsg.wakeupType, m_DramBackupStatus,
        m_ResetStatus, m_ResetCount);

    UI_32 l_numModulesMessaged = 0;
    FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__,
        " Attempting to send Start Requests to Group %d/'%s'",
        f_ui32GroupNumber, l_GroupIterator->second.name.c_str());

    for (ModuleLaunchListIter l_ModuleListIterator =
        l_GroupIterator->second.modules.begin();
        l_ModuleListIterator != l_GroupIterator->second.modules.end();
        l_ModuleListIterator++) {
      //
      // Every branch below must ZONE_INFO log how it dispenses w/
      // the module.
      //  Note: ModuleLaunchParams::SetModuleState() performs that
      //    ZONE_INFO logging internally.
      if (!l_ModuleListIterator->is_start_required) {
        if (FRAMEWORKUNIFIED_NS_NPSERVICE == l_ModuleListIterator->name) {
          const SMModuleState l_transition_state = InProgressStateToState();  // LCOV_EXCL_BR_LINE 11:Gcov constraints (because exception-handling routes are automatically generated)
          l_ModuleListIterator->SetModuleState(l_transition_state);  // LCOV_EXCL_BR_LINE 11:Gcov constraints (because exception-handling routes are automatically generated)
        } else {
          // Not an error
          FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__,
              " %s 'is_start_required' is False;"
                  " leaving state as '%s'",
              l_ModuleListIterator->name.c_str(),
              l_ModuleListIterator->ModuleStateStr().c_str());
        }
        l_eStatus = eFrameworkunifiedStatusOK;
      } else if (NULL == l_ModuleListIterator->hsession) {  // LCOV_EXCL_BR_LINE 6: hsession can not be null.
        l_eStatus = eFrameworkunifiedStatusOK;  // Log a message. But its not a failure
        FRAMEWORKUNIFIEDLOG(ZONE_WARN, __FUNCTION__, " Warning: NULL == hsession;"
            " %s not connected yet",
            l_ModuleListIterator->name.c_str());
      } else {
        switch (l_ModuleListIterator->GetModuleState()) {  // LCOV_EXCL_BR_LINE 6: As not all cases can be passed through
        case MODULE_STATE_INVALID:
        case MODULE_STATE_SKIPPED:
        case MODULE_STATE_LAUNCH_FAILED:
          // LCOV_EXCL_START 6: Because the state of the corresponding variable cannot be set
          AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
          l_eStatus = eFrameworkunifiedStatusOK;  // Log a message. But its not a failure
          FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__,
              " %s is %s, NOT sending system_manager protocol message",
              l_ModuleListIterator->name.c_str(),
              l_ModuleListIterator->ModuleStateStr().c_str());
          break;
          // LCOV_EXCL_STOP

        case MODULE_STATE_START_SENT:
        case MODULE_STATE_START_PRE_SENT:
        case MODULE_STATE_STOP_PRE_SENT:
        case MODULE_STATE_START_BACKGROUND_SENT:
        case MODULE_STATE_STOP_BACKGROUND_SENT:
          l_eStatus = eFrameworkunifiedStatusOK;
          FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__,
              " %s is %s, NOT sending system_manager protocol message",
              l_ModuleListIterator->name.c_str(),
              l_ModuleListIterator->ModuleStateStr().c_str());
          l_numModulesMessaged++;
          break;

        case MODULE_STATE_LAUNCHING:
        case MODULE_STATE_LAUNCHED:
          // LCOV_EXCL_START 6: Because the state of the corresponding variable cannot be set
          AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
          l_eStatus = eFrameworkunifiedStatusOK;  // Log a message. But its not a failure
          FRAMEWORKUNIFIEDLOG(ZONE_WARN, __FUNCTION__,
              " %s is %s, NOT sending system_manager protocol message",
              l_ModuleListIterator->name.c_str(),
              l_ModuleListIterator->ModuleStateStr().c_str());
          break;
          // LCOV_EXCL_STOP

        case MODULE_STATE_CONNECTED:
        case MODULE_STATE_STARTED:
        case MODULE_STATE_START_FAILED:
        case MODULE_STATE_STOP_FAILED:
        case MODULE_STATE_STOP_SENT:
        case MODULE_STATE_STOPPED:
        case MODULE_STATE_STARTED_PRE:
        case MODULE_STATE_START_PRE_FAILED:
        case MODULE_STATE_STOPPED_PRE:
        case MODULE_STATE_STOP_PRE_FAILED:
        case MODULE_STATE_STARTED_BACKGROUND:
        case MODULE_STATE_START_BACKGROUND_FAILED:
        case MODULE_STATE_STOPPED_BACKGROUND:
        case MODULE_STATE_STOP_BACKGROUND_FAILED:
          {
            const UI_32 l_iCmd = InProgressStateToSendMsg();  // LCOV_EXCL_BR_LINE 11:Gcov constraints (because exception-handling routes are automatically generated)
            if (l_iCmd != SS_SYSTEM_MANAGER_PROTOCOL_ENDING_INDEX) {  // LCOV_EXCL_BR_LINE 6: Excluded due to value never returned at present
              // LCOV_EXCL_BR_START 15: Excluded due to inlined functions
              CALL_AND_LOG_STATUS_IF_ERRORED(l_ModuleListIterator->SendMsgAndUpdateState(l_iCmd, &f_startupData));
              // LCOV_EXCL_BR_STOP 15: Excluded due to inlined functions
              l_numModulesMessaged++;
            }
          }
          break;
          // default:  Don't code a 'default' here - let the compiler
          // detect when the set of module_state enumerations changes -
          // then the System Service's System Manager maintainer will
          // automagically know to update this switch statement.
        }
      }
    }

    if (0 == l_numModulesMessaged) {
      LogGroupModulesState(f_ui32GroupNumber, " Warning: NO modules were sent system_manager protocol message");  // LCOV_EXCL_BR_LINE 11:Gcov constraints (because exception-handling routes are automatically generated)

      char l_cBuf[100];
      snprintf(l_cBuf, sizeof(l_cBuf), "ProcessGroupAsStarted(%d)", l_GroupIterator->second.id);
      l_eStatus = ProcessGroupAsStarted(hApp, l_GroupIterator);
      LOG_STATUS_REC_HIST_IF_ERRORED(l_eStatus, l_cBuf);  // LCOV_EXCL_BR_LINE 6: Because the condition cannot be set
    } else {
      m_GroupLaunchTimer->StartTimer(
          m_aTimerIDs[eSM_TIMER_CLIENT_START_MONITOR],
          SS_CLIENT_START_MONITOR_TIMER_CONFIG, 0, 0, 0);
    }
  }
  FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-");
  return l_eStatus;
}  // End of EFrameworkunifiedStatus CSystemManager::start_all_modules_of_group(HANDLE hApp, UI_32 f_ui32GroupNumber)

///////////////////////////////////////////////////////////////////////////////
/// \ingroup start_all_modules_of_group
/// mark the specified group as started. If there is another group to start,
/// do so, else send Start Complete Response to the Start Requester.
///
/// \param [in]
///
///
/// \return EFrameworkunifiedStatus
/// Success ==> eFrameworkunifiedStatusOK
/// Failure ==> Other values
///////////////////////////////////////////////////////////////////////////////
EFrameworkunifiedStatus CSystemManager::ProcessGroupAsStarted(HANDLE hApp, UI_32 f_groupId) {
  EFrameworkunifiedStatus l_eStatus;
  FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+");

  GroupLaunchMapIter l_GroupIterator = m_MapProclaunchGrps.find(f_groupId);
  if (l_GroupIterator == m_MapProclaunchGrps.end()) {
    FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__,
        " Error: Group %d not found; 'm_MapProclaunchGrps' is empty", f_groupId);
    l_eStatus = eFrameworkunifiedStatusInvldParam;
  } else {
    l_eStatus = ProcessGroupAsStarted(hApp, l_GroupIterator);
  }

  FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-");
  return l_eStatus;
}  // End of EFrameworkunifiedStatus CSystemManager::ProcessGroupAsStarted( HANDLE hApp, UI_32 f_groupId )

///////////////////////////////////////////////////////////////////////////////
/// \ingroup start_all_modules_of_group
/// mark the specified group as started. If there is another group to start,
/// do so, else send Start Complete Response to the Start Requester.
///
/// \param [in]
///
///
/// \return EFrameworkunifiedStatus
/// Success ==> eFrameworkunifiedStatusOK
/// Failure ==> Other values
///////////////////////////////////////////////////////////////////////////////
EFrameworkunifiedStatus CSystemManager::ProcessGroupAsStarted(HANDLE hApp,
        GroupLaunchMapIter f_GroupIterator) {
  EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK;
  FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+");
  UI_32 l_groupID = m_SystemStarter.get_id();


  m_GroupLaunchTimer->StopTimer(m_aTimerIDs[eSM_TIMER_CLIENT_START_MONITOR]);

  FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__,
      " Group %d/%s start completed, m_SystemStarter.get_id() is %d",
      f_GroupIterator->second.id, f_GroupIterator->second.name.c_str(),
      l_groupID);

  if (f_GroupIterator->second.id != l_groupID) {
    FRAMEWORKUNIFIEDLOG(ZONE_INFO,
        __FUNCTION__
        , " The just-started group ( %d/%s ) is not the current Active "
            " Group ( %d ); not starting next group's modules",
        f_GroupIterator->second.id,
        f_GroupIterator->second.name.c_str(), l_groupID);
  } else {
    if ((m_SMCurrentState == SS_SM_APPS_START_IN_PROGRESS)
        || (m_SMCurrentState == SS_SM_APPS_PRE_START_IN_PROGRESS)
        || (m_SMCurrentState == SS_SM_APPS_BACKGROUND_START_IN_PROGRESS)) {
      // check if WakeUp Level has been achieved
      if (m_SystemStarter.is_end() == FALSE) {
        // Start modules from next group
        l_groupID = m_SystemStarter.advance_id();  // LCOV_EXCL_BR_LINE 11:Gcov constraints (because exception-handling routes are automatically generated)
        char l_cBuf[100] = {0};
        snprintf(l_cBuf, sizeof(l_cBuf), "start_all_modules_of_group(%u)", l_groupID);
        l_eStatus = start_all_modules_of_group(hApp, l_groupID);  // LCOV_EXCL_BR_LINE 11:Gcov constraints (because exception-handling routes are automatically generated)
        LOG_STATUS_REC_HIST_IF_ERRORED(l_eStatus, l_cBuf);   // LCOV_EXCL_BR_LINE 6: Because the condition cannot be set
      }
    } else if ((m_SMCurrentState == SS_SM_APPS_PRE_STOP_IN_PROGRESS)
        || (m_SMCurrentState == SS_SM_APPS_BACKGROUND_STOP_IN_PROGRESS)) {
      if (m_SystemStarter.is_begin() == FALSE) {
        // Stop modules from next group
        l_groupID = m_SystemStarter.decrement_id();  // LCOV_EXCL_BR_LINE 11:Gcov constraints (because exception-handling routes are automatically generated)
        char l_cBuf[100] = {0};
        snprintf(l_cBuf, sizeof(l_cBuf), "stop_all_modules_of_group(%u)", l_groupID);
        l_eStatus = start_all_modules_of_group(hApp, l_groupID);  // LCOV_EXCL_BR_LINE 11:Gcov constraints (because exception-handling routes are automatically generated)
        LOG_STATUS_REC_HIST_IF_ERRORED(l_eStatus, l_cBuf);   // LCOV_EXCL_BR_LINE 6: Because the condition cannot be set
      }
    } else {
      // MISRA C++-2008 Rule 6-4-2
      // NOP
    }
  }
  FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-");
  return l_eStatus;
}  // End of EFrameworkunifiedStatus CSystemManager::ProcessGroupAsStarted( GroupLaunchMapIter f_GroupIterator )

///////////////////////////////////////////////////////////////////////////////
/// \ingroup calculate_max_shutdown_time
/// Calculate maximum shutdown time of apps critical to shutdown
/// from the launch group map
///
/// \param [in]
///
/// \return UI_32
/// Max Value of critical shutdown apps shutdown time
///////////////////////////////////////////////////////////////////////////////
UI_32 CSystemManager::calculate_max_shutdown_time() {
  FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+");
  UI_32 l_MaxShutdownTimeValue = 0;
  std::string moduleName;

  GroupLaunchMapIter l_GroupIterator = m_MapProclaunchGrps.begin();
  for (; l_GroupIterator != m_MapProclaunchGrps.end(); l_GroupIterator++) {
    ModuleLaunchListIter l_ModuleListIterator =
        l_GroupIterator->second.modules.begin();
    for (; l_ModuleListIterator != l_GroupIterator->second.modules.end();
        l_ModuleListIterator++) {
      if (l_ModuleListIterator->shutdown_critical) {
        if (l_MaxShutdownTimeValue < l_ModuleListIterator->shutdown_wait_time) {
          moduleName = l_ModuleListIterator->name;
          l_MaxShutdownTimeValue = l_ModuleListIterator->shutdown_wait_time;
        }
      }
    }
  }
  FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__, " Max time: Module %s, time %d s",
      moduleName.c_str(), l_MaxShutdownTimeValue);
  FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-");
  return l_MaxShutdownTimeValue;
}

///////////////////////////////////////////////////////////////////////////////
/// \ingroup OnShutdownModulesRequest
/// Send Shutdown to all modules in reverse order of group
///
/// \param [in]
///
/// \return EFrameworkunifiedStatus
/// Success ==> eFrameworkunifiedStatusOK
/// Failure ==> Other values
///////////////////////////////////////////////////////////////////////////////
EFrameworkunifiedStatus CSystemManager::OnShutdownModulesRequest(HANDLE hApp) {
  FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+");
  EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK;

  FRAMEWORKUNIFIEDLOG(ZONE_STATE, __FUNCTION__,
      " Received from %s, m_SystemStarter.get_id() is %d",
      FrameworkunifiedGetMsgSrc(hApp)
      , m_SystemStarter.get_id());

  FRAMEWORKUNIFIEDLOG(ZONE_PERFORMANCE, __FUNCTION__, "m_SystemStarter.get_id() is %d", m_SystemStarter.get_id());

  SetCmdHist("SS_SM_SHUTDOWN_MODULES", m__CWORD56_CmdHist, m__CWORD56_HistIter, FrameworkunifiedGetMsgSrc(hApp)); // LCOV_EXCL_BR_LINE 11:unexpected branch  // NOLINT(whitespace/line_length)

  Pwr_ServiceSetInterface l_tServiceSetIf;
  // ReadMsg():                              *
  //   Check hApp ptr, msg size, msg reception, read msg if all ok.    *
  if (eFrameworkunifiedStatusOK != (l_eStatus = ReadMsg < Pwr_ServiceSetInterface > (hApp, l_tServiceSetIf))) {   // LCOV_EXCL_BR_LINE 4: nsfw error
    // LCOV_EXCL_START 4: nsfw error
    AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
    LOG_ERROR("ReadMsg()");  // LCOV_EXCL_BR_LINE 15: marco defined in ss_templates.h  // NOLINT(whitespace/line_length)
    // LCOV_EXCL_STOP
  } else {
    BOOL isImmShutdown = FALSE;

    // If the Shutdown is not completed after the Shutdown is requested, it is forcibly reset.
    m_GroupLaunchTimer->StartTimer(
        m_aTimerIDs[eSM_TIMER_SHUTDOWN_COMPLETE_MONITOR],
        SM_SHUTDOWN_COMPLETE_MONITOR_TIMEOUT, 0, 0, 0);

    if (m_isImmResetReq) {
      FRAMEWORKUNIFIEDLOG(ZONE_STATE, __FUNCTION__, " ImmReset");
      isImmShutdown = TRUE;
    }

    switch (l_tServiceSetIf.data.shutdownRequestMsg.lastUserMode) {
    case epsumINVALID:
      FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__,
          " Error: shutdownRequestMsg.lastUserMode == epsumINVALID");
      l_eStatus = eFrameworkunifiedStatusInvldParam;
      break;

    case epsumOFF:
    case epsumON: {
      switch (m_SMCurrentState) {
      case SS_SM_READY_TO_LAUNCH_APP:
      case SS_SM_APPS_LAUNCH_IN_PROGRESS:
      case SS_SM_APPS_LAUNCHED_READY_TO_START:
        isImmShutdown = TRUE;
      case SS_SM_APPS_START_COMPLETE:
      case SS_SM_APPS_START_IN_PROGRESS:
      case SS_SM_APPS_PRE_START_IN_PROGRESS:
      case SS_SM_APPS_PRE_STOP_IN_PROGRESS:
      case SS_SM_APPS_PRE_RUN_COMPLETE:
      case SS_SM_APPS_BACKGROUND_START_IN_PROGRESS:
      case SS_SM_APPS_BACKGROUND_STOP_IN_PROGRESS:
      case SS_SM_APPS_BACKGROUND_RUN_COMPLETE:

        if (l_tServiceSetIf.data.shutdownRequestMsg.shutdownTrigger ==
                                                            epssdmsdtIGN_OFF) {
          m_ResetCount = 0;
          if (PowerHalSetResetInfo(AGL_RESET_COUNTER, m_ResetCount)) {  // LCOV_EXCL_BR_LINE 11:Gcov constraints (because exception-handling routes are automatically generated)
            FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__,
              "Could not back up m_ResetCount(%lu) to power_hal", m_ResetCount);
          }

          if (PowerHalSetResetInfo(AGL_ERRLOG_COUNTER, 0)) {  // LCOV_EXCL_BR_LINE 11:Gcov constraints (because exception-handling routes are automatically generated)
            FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__,
              "Could not reset AGL_ERRLOG_COUNTER");
          }
        }
        if (!m_isPrevErrEventCompleted
            || ((!((m_SMCurrentState == SS_SM_APPS_START_COMPLETE)
                || (m_SMCurrentState == SS_SM_APPS_PRE_RUN_COMPLETE)
                || (m_SMCurrentState == SS_SM_APPS_BACKGROUND_RUN_COMPLETE)))
                && (l_tServiceSetIf.data.shutdownRequestMsg.shutdownTrigger
                    == epssdmsdtIGN_OFF
                    || l_tServiceSetIf.data.shutdownRequestMsg.shutdownTrigger
                        == epssdmsdtNORMAL_RESET))) {
          FRAMEWORKUNIFIEDLOG(ZONE_STATE, __FUNCTION__, "shutdown pending");
          if (!m_dqDeferMsg.empty()) {
            SS_ASERT(0);  // LCOV_EXCL_BR_LINE 15: marco defined in ss_templates.h  // NOLINT(whitespace/line_length)
          } else {
            SM_POWER_EVENT_INFO deferMsg(SS_SM_SHUTDOWN_MODULES, l_tServiceSetIf);
            m_dqDeferMsg.push(deferMsg);
          }
        } else {
          // The shutdownTrigger has already been validated by
          // Power::OnShutdownRequestMsg()
          m_shutdownTrigger = l_tServiceSetIf.data.shutdownRequestMsg.shutdownTrigger;
          m_lastUserMode = l_tServiceSetIf.data.shutdownRequestMsg.lastUserMode;

          // Notify services ShutDownTrigger the FrameworkunifiedOnStop, if dataResetMode is configured
          // When using FastSleep, be aware that it may be overwritten here
          switch (m_DataResetMode) {
          case e_SS_SM_DATA_RESET_MODE_FACTORY:
            m_shutdownTrigger = epssdmsdtFACTORY_DATA_RESET;
            break;
          case e_SS_SM_DATA_RESET_MODE_USER:
            m_shutdownTrigger = epssdmsdtUSER_DATA_RESET;
            break;
          default:
            break;
          }

          if (isImmShutdown) {
            m_GroupLaunchTimer->StopTimer(m_aTimerIDs[eSM_TIMER_GROUP_LAUNCH_WAIT_TIMER]);

            // Do not use m_shutdownTrigger because it is updated on DataReset
            switch (l_tServiceSetIf.data.shutdownRequestMsg.shutdownTrigger) {
            case epssdmsdtGENERIC_ERROR_RESET:
            case epssdmsdtFATAL_ERROR_RESET:
              CALL_AND_LOG_STATUS((*m_pfStopCompleteHandler)(hApp));  // LCOV_EXCL_BR_LINE 15: marco defined in ss_templates.h  // NOLINT(whitespace/line_length)
              break;
            default:
              FRAMEWORKUNIFIEDLOG(ZONE_WARN, __FUNCTION__,
                  " Warning: Received a Shutdown command while in "
                  "the '%s' state - returning Shutdown "
                  "Response msg now",
                  GetStr(m_SMCurrentState).c_str());

              CALL_AND_LOG_STATUS(SendShutdownResponseMessage(hApp));  // LCOV_EXCL_BR_LINE 15: marco defined in ss_templates.h  // NOLINT(whitespace/line_length)
              break;
            }

          } else {
            InitiateAllGroupsShutdown(hApp);
          }
        }
        break;

      case SS_SM_APPS_STOPPING_AT__CWORD56__REQ:
      case SS_SM_APPS_STOPPING_AT_INTERNAL_REQ:
      case SS_SM_WAITING_FOR_CRITICAL_APPS_AT__CWORD56__REQ:
      case SS_SM_WAITING_FOR_CRITICAL_APPS_AT_INTERNAL_REQ:
        FRAMEWORKUNIFIEDLOG(ZONE_WARN, __FUNCTION__,
            " Warning: Received a Shutdown command while already in "
            "the '%s' state !!!",
            GetStr(m_SMCurrentState).c_str());
        break;
      }  // End switch ( m_SMCurrentState )
      break;
    }  // End case epsumOFF | epsumON
    }  // End switch (m_lastUserMode )
  }

  FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-");
  return l_eStatus;
}  // End of EFrameworkunifiedStatus CSystemManager::OnShutdownModulesRequest( HANDLE hApp )

///////////////////////////////////////////////////////////////////////////////
/// \ingroup SendSystemModeInfoResponse
/// send SystemModeInfo to
/// _CWORD56_ ( via Power Service-> PSMShadow ) as an IPC 'Start Notification'
/// message, informing _CWORD56_ of the startup state of the _CWORD102_.
///
/// \param [in] HANDLE hApp
///
/// \return EFrameworkunifiedStatus
/// Success ==> eFrameworkunifiedStatusOK
/// Failure ==> Other values
///////////////////////////////////////////////////////////////////////////////
EFrameworkunifiedStatus CSystemManager::SendSystemModeInfoResponse(HANDLE hApp, EPWR_STARTUP_STAGE_TYPE f_startupStage) {
  FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+");
  EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK;
  SystemModeInfo l_SystemModeInfo;

  memcpy(&l_SystemModeInfo, &m_SystemModeInfo, sizeof(l_SystemModeInfo));

  FRAMEWORKUNIFIEDLOG(ZONE_STATE, __FUNCTION__, "stage:%d", f_startupStage);
  l_SystemModeInfo.startupStage = f_startupStage;

  l_eStatus = FrameworkunifiedSendMsg(m_hPowerServiceSession, SS_SM_SYSTEM_MODE_INFO_RSPN,
      sizeof(l_SystemModeInfo), (PVOID) & l_SystemModeInfo);

  if (eFrameworkunifiedStatusOK != l_eStatus) {  // LCOV_EXCL_BR_LINE 4: NSFW error case.
    FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__,
        " Error: SendSystemModeInfoResponse(%s) errored: 0x%X",
        GetStr(l_SystemModeInfo.startupStage).c_str(), l_eStatus);
  } else {
    // LCOV_EXCL_START 4: NSFW error case.
    AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
    FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__,
        " SendSystemModeInfoResponse(%s) successful",
        GetStr(l_SystemModeInfo.startupStage).c_str());
    // LCOV_EXCL_STOP
  }

  LOG_STATUS(l_eStatus, "FrameworkunifiedSendMsg(SS_SM_SYSTEM_MODE_INFO_RSPN)");  // LCOV_EXCL_BR_LINE 15: marco defined in ss_templates.h  // NOLINT(whitespace/line_length)
  FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-");
  return l_eStatus;
}  // End of EFrameworkunifiedStatus CSystemManager::SendSystemModeInfoResponse( HANDLE hApp )

///////////////////////////////////////////////////////////////////////////////
/// \ingroup OnSystemModeInfoRequest
/// Handle System Mode Info request. Send System Mode Info read from NVM
///
/// \param [in] HANDLE hApp
///
/// \return EFrameworkunifiedStatus
/// Success ==> eFrameworkunifiedStatusOK
/// Failure ==> Other values
///////////////////////////////////////////////////////////////////////////////
EFrameworkunifiedStatus CSystemManager::OnSystemModeInfoRequest(HANDLE hApp) {
  FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+");
  EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK;
  INTERFACEUNIFIEDLOG_RECEIVED_FROM(hApp);  // LCOV_EXCL_BR_LINE 15: marco defined in ns_logger_if.h  // NOLINT(whitespace/line_length)
  FRAMEWORKUNIFIEDLOG(ZONE_PERFORMANCE, __FUNCTION__, "from %s", FrameworkunifiedGetMsgSrc(hApp));
  m_isRcvModeInfo = TRUE;

  SetCmdHist("SS_SM_SYSTEM_MODE_INFO_REQ", m__CWORD56_CmdHist, m__CWORD56_HistIter, FrameworkunifiedGetMsgSrc(hApp));

  if (m_SystemModeInfo.startupStage == epssusfINVALID) {
    // Transitioning to SYSTEM_SERVICES_STARTED if startupStage == INVALID
    m_SystemModeInfo.startupStage = epssusSYSTEM_SERVICES_STARTED;
  }

  l_eStatus = SendSystemModeInfoResponse(hApp, epssusSYSTEM_SERVICES_STARTED);
  LOG_STATUS(l_eStatus, "SendSystemModeInfoResponse()");  // LCOV_EXCL_BR_LINE 15: marco defined in ss_templates.h  // NOLINT(whitespace/line_length)

  if (TRUE == m_isRstPending) {
    ESMCpuResetReason l_resetReason = m_rstPendingInfo.resetReason;
    std::string l_messageStr = m_rstPendingInfo.messageStr;

    m_isRstPending = FALSE;
    m_rstPendingInfo.resetReason = e_SS_SM_CPU_RESET_REASON_INVALID;
    memset(m_rstPendingInfo.messageStr, 0, sizeof(m_rstPendingInfo.messageStr));

    l_eStatus = PerformCpuReset(hApp, l_resetReason, l_messageStr);
    LOG_STATUS(l_eStatus, "PerformCpuReset()");  // LCOV_EXCL_BR_LINE 6: Because it is executed only once and cannot see all branches
  }

  if (m_SystemModeInfo.startupStage == epssusALL_SERVICES_LAUNCHED) {
    // If startupStage == ALL_SERVICES_LAUNCHED
    // Notify here because Launch of all SVCs is completed first.
    l_eStatus = SendSystemModeInfoResponse(hApp, epssusALL_SERVICES_LAUNCHED);
    LOG_STATUS(l_eStatus, "SendSystemModeInfoResponse()");  // LCOV_EXCL_BR_LINE 15: marco defined in ss_templates.h  // NOLINT(whitespace/line_length)
  }

  FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-");
  return l_eStatus;
}  // End of EFrameworkunifiedStatus CSystemManager::OnSystemModeInfoRequest( HANDLE hApp )

///////////////////////////////////////////////////////////////////////////////
/// \ingroup OnInitCompReportCallback
/// Handle InitComp report.
///
/// \param [in] HANDLE hApp
///
/// \return EFrameworkunifiedStatus
/// Success ==> eFrameworkunifiedStatusOK
/// Failure ==> Other values
///////////////////////////////////////////////////////////////////////////////
EFrameworkunifiedStatus CSystemManager::OnInitCompReportCallback(HANDLE hApp) {
  FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+");
  EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK;
  INTERFACEUNIFIEDLOG_RECEIVED_FROM(hApp);  // LCOV_EXCL_BR_LINE 15: marco defined in ns_logger_if.h  // NOLINT(whitespace/line_length)
  FRAMEWORKUNIFIEDLOG(ZONE_PERFORMANCE, __FUNCTION__, "from %s", FrameworkunifiedGetMsgSrc(hApp));

  SetCmdHist("SS_SM_INITCOMP_REP", m__CWORD56_CmdHist, m__CWORD56_HistIter, FrameworkunifiedGetMsgSrc(hApp));

  FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-");
  return l_eStatus;
}  // End of EFrameworkunifiedStatus CSystemManager::OnInitCompReportCallback( HANDLE hApp )

///////////////////////////////////////////////////////////////////////////////
/// \ingroup have_all_services_start_completed
///  check if state of all services is MODULE_STATE_STARTED
///
/// \param [in]
///
///
/// \return BOOL
/// Success ==> TRUE
/// Failure ==> FALSE
///////////////////////////////////////////////////////////////////////////////
BOOL CSystemManager::have_all_services_start_completed(const SMModuleState f_moduleState) {
  FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+");
  BOOL bIsStartCompleted = TRUE;
  SMModuleState l_failedState = MODULE_STATE_INVALID;

  switch (f_moduleState) {
    case MODULE_STATE_STARTED:
      l_failedState = MODULE_STATE_START_FAILED;
      break;
    case MODULE_STATE_STARTED_PRE:
      l_failedState = MODULE_STATE_START_PRE_FAILED;
      break;
    case MODULE_STATE_STOPPED_PRE:
      l_failedState = MODULE_STATE_STOP_PRE_FAILED;
      break;
    case MODULE_STATE_STARTED_BACKGROUND:
      l_failedState = MODULE_STATE_START_BACKGROUND_FAILED;
      break;
    case MODULE_STATE_STOPPED_BACKGROUND:
      l_failedState = MODULE_STATE_STOP_BACKGROUND_FAILED;
      break;
    default:
      bIsStartCompleted = FALSE;
      break;
  }
  if (l_failedState != MODULE_STATE_INVALID) {
    GroupLaunchMapIter l_GroupIterator = m_MapProclaunchGrps.begin();
    for (; l_GroupIterator != m_MapProclaunchGrps.end(); l_GroupIterator++) {
      ModuleLaunchListIter l_ModuleListIterator = l_GroupIterator->second.modules.begin();
      for (; l_ModuleListIterator != l_GroupIterator->second.modules.end(); l_ModuleListIterator++) {
        if ((l_ModuleListIterator->is_start_required == TRUE)
            && ((l_ModuleListIterator->IsModuleState(f_moduleState) == FALSE)  // LCOV_EXCL_BR_LINE 11:Gcov constraints (because exception-handling routes are automatically generated)
                && (l_ModuleListIterator->IsModuleState(MODULE_STATE_SKIPPED) == FALSE)  // LCOV_EXCL_BR_LINE 11:Gcov constraints (because exception-handling routes are automatically generated)
                && (l_ModuleListIterator->IsModuleState(l_failedState) == FALSE))) {  // LCOV_EXCL_BR_LINE 11:Gcov constraints (because exception-handling routes are automatically generated)
          // Allow _SKIPPED/START_FAILED for StartRespMonitor conditions
          bIsStartCompleted = FALSE;
          break;
        }
      }
    }
  }
  FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-");
  return bIsStartCompleted;
}

///////////////////////////////////////////////////////////////////////////////
/// \ingroup is_critical_service_stopped
///
///
/// \param [in]
///
///
/// \return BOOL
/// Success ==> TRUE
/// Failure ==> FALSE
///////////////////////////////////////////////////////////////////////////////
BOOL CSystemManager::is_service_shutdown_ready(ModuleLaunchListIter &modIte) {
  if (((modIte->shutdown_critical && modIte->is_start_required)
      || (modIte->name == FRAMEWORKUNIFIED_NS_NPSERVICE))
      && modIte->IsModuleState(MODULE_STATE_STOPPED) == FALSE) {
    // Not shutdown_ready if NPP or shutdown_critical services are not STOPPED.
    return FALSE;
  }
  return TRUE;
}

///////////////////////////////////////////////////////////////////////////////
/// \ingroup have_critical_services_stopped
///  check if state of all critical services is MODULE_STATE_STOPPED
///
/// \param [in]
///
///
/// \return BOOL
/// Success ==> TRUE
/// Failure ==> FALSE
///////////////////////////////////////////////////////////////////////////////
BOOL CSystemManager::have_critical_services_stopped() {
  FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+");
  uint numStoppingModules = 0;

  GroupLaunchMapIter l_GroupIterator = m_MapProclaunchGrps.begin();
  for (; l_GroupIterator != m_MapProclaunchGrps.end(); l_GroupIterator++) {
    ModuleLaunchListIter l_ModuleListIterator = l_GroupIterator->second.modules.begin();
    for (; l_ModuleListIterator != l_GroupIterator->second.modules.end(); l_ModuleListIterator++) {
      if (l_ModuleListIterator->IsModuleState(MODULE_STATE_STOP_SENT)
          && l_ModuleListIterator->shutdown_critical) {
        numStoppingModules++;
      }
    }
  }
  FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-");
  return (numStoppingModules == 0);
}

///////////////////////////////////////////////////////////////////////////////
/// \ingroup perform_force_reset
///
///
/// \param [in]
///
///
/// \return EFrameworkunifiedStatus
/// Success ==> eFrameworkunifiedStatusOK
/// Failure ==> Other values
///////////////////////////////////////////////////////////////////////////////
EFrameworkunifiedStatus CSystemManager::perform_force_reset(HANDLE hApp) {
  EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK;
  FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "+");

  // Since initialization must be performed by the PSMs during FactReset, do not NaviDet them as much as possible.
  if (e_SS_SM_DATA_RESET_MODE_FACTORY == m_DataResetMode) {
    fprintf(stderr,
        "SS_SysManager/%s/NO NAVIDET!! but SendShutdownComp for FactReset\n", __FUNCTION__);
    FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__,
        "NO NAVIDET!! but SendShutdownComp for FactReset");
    CALL_AND_LOG_STATUS(send_shutdown_complete_response(hApp));  // LCOV_EXCL_BR_LINE 15: marco defined in ss_templates.h  // NOLINT(whitespace/line_length)
    sleep(60);
  } else if (access("/nv/BS/ss/system_manager/rwdata/ss_debug", F_OK) == 0) {
    fprintf(stderr, "SS_SysManager/%s/NO NAVIDET!! but SendShutdownComp\n", __FUNCTION__);
    FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "NO NAVIDET!! but SendShutdownComp");
    CALL_AND_LOG_STATUS(send_shutdown_complete_response(hApp));  // LCOV_EXCL_BR_LINE 15: marco defined in ss_templates.h  // NOLINT(whitespace/line_length)
    sleep(60);
  }

  fflush(stderr);
  usleep(100 * 1000);

  if (0 == PsmNaviResetPower(hApp, m_ResetFactor)) {  // LCOV_EXCL_BR_LINE 200: power_hal if, can not to be error.
    SS_ASERT_ERRNO(0);  // LCOV_EXCL_BR_LINE 15: marco defined in ss_templates.h  // NOLINT(whitespace/line_length)
  } else {
    usleep(300 * 1000);
    fprintf(stderr, "SS_SysManager/%s/Error: Not Reset !!!\n", __FUNCTION__);
    l_eStatus = eFrameworkunifiedStatusFail;
  }

  send_shutdown_complete_response(hApp);  // Try to NAVI_RESET even if ignored

  FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "-");
  return l_eStatus;
}

///////////////////////////////////////////////////////////////////////////////

///////////////////////////////////////////////////////////////////////////////
/// \ingroup send_shutdown_complete_response
///
///
/// \param [in]
///
///
/// \return EFrameworkunifiedStatus
/// Success ==> eFrameworkunifiedStatusOK
/// Failure ==> Other values
///////////////////////////////////////////////////////////////////////////////
EFrameworkunifiedStatus CSystemManager::send_shutdown_complete_response(HANDLE hApp) {
  EFrameworkunifiedStatus l_eStatus;
  FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+");

  CALL_AND_LOG_STATUS(ResetModulesStateToConnected(hApp));  // LCOV_EXCL_BR_LINE 15: marco defined in ss_templates.h  // NOLINT(whitespace/line_length)

  SMSetState(hApp, SS_SM_APPS_LAUNCHED_READY_TO_START);
  // m_ActiveGroupId = SS_SM_INITIAL_GROUP;

  // all the modules have stopped, send Shutdown Response to Power Service
  FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__,
      " All critical services have stopped, Active Group ID is now %d",
      m_SystemStarter.get_id());
#if 1
    CALL_AND_LOG_STATUS(SendShutdownResponseMessage(hApp));  // LCOV_EXCL_BR_LINE 15: marco defined in ss_templates.h  // NOLINT(whitespace/line_length)
#else
  //
  // Normal, production flow is to call SendShutdownResponseMessage(), which
  // sends the Shutdown Response message to the _CWORD56_, causing the _CWORD56_ to
  // remove power from the _CWORD102_ before queued-up FRAMEWORKUNIFIEDLOG messages can be  // LCOV_EXCL_BR_LINE 15: marco defined in ns_logger_if.h  // NOLINT(whitespace/line_length)
  // processed by SS_LoggerService.
  //
  // Optional development flow is to NOT call SendShutdownResponseMessage(),
  // thus giving the _CWORD102_ time to process its FRAMEWORKUNIFIEDLOG messages. Since this is an  // LCOV_EXCL_BR_LINE 15: marco defined in ns_logger_if.h  // NOLINT(whitespace/line_length)
  // abnormal, 'bad' condition of NOT sending a Shutdown Response message to
  // the _CWORD56_, be very obvious about this state by displaying both
  // compile-time and run-time warning messages.
  //
#warning NOT calling SendShutdownResponseMessage(hApp) !
  FRAMEWORKUNIFIEDLOG(ZONE_WARN, __FUNCTION__,  // LCOV_EXCL_BR_LINE 15: marco defined in ns_logger_if.h  // NOLINT(whitespace/line_length)
      " Warning: SendShutdownResponseMessage( hApp ) "
      "#def'f out; ShutdownResponse NOT sent to _CWORD56_");
#endif

  FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-");
  return l_eStatus;
}

///////////////////////////////////////////////////////////////////////////////
///
///////////////////////////////////////////////////////////////////////////////
EFrameworkunifiedStatus CSystemManager::SendShutdownResponseMessage(HANDLE hApp) {
  EFrameworkunifiedStatus l_eStatus;
  FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+");
  l_eStatus = FrameworkunifiedSendMsg(m_hPowerServiceSession,  // LCOV_EXCL_BR_LINE 15: marco defined in ns_logger_if.h  // NOLINT(whitespace/line_length)
      SS_SM_SHUTDOWN_MODULES_CMPL_RSPN, 0, (PVOID) NULL);  // LCOV_EXCL_BR_LINE 15: marco defined in ns_logger_if.h  // NOLINT(whitespace/line_length)
  LOG_STATUS_REC_HIST_IF_ERRORED(l_eStatus,  // LCOV_EXCL_BR_LINE 15: marco defined in ss_system_manager.h  // NOLINT(whitespace/line_length)
      "FrameworkunifiedSendMsg(PowerService,SS_SM_SHUTDOWN_MODULES_CMPL_RSPN)");  // LCOV_EXCL_BR_LINE 15: marco defined in ss_system_manager.h  // NOLINT(whitespace/line_length)

  FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-");
  return l_eStatus;
}  // End of EFrameworkunifiedStatus CSystemManager::SendShutdownResponseMessage( HANDLE hApp )


PsmFactorT CSystemManager::GetResetFactor(PCSTR f_module_name, BOOL f_user_reset) {
  PsmFactorT  l_reset_factor = PSM_FACTOR_NONE;
  EFrameworkunifiedStatus l_eStatus;
  ModuleLaunchListIter l_moduleIter;
  l_eStatus = GetModuleIterator(f_module_name, l_moduleIter);  // LCOV_EXCL_BR_LINE 11:Gcov constraints (because exception-handling routes are automatically generated)
  if (eFrameworkunifiedStatusOK != l_eStatus) {
    LOG_ERROR("GetModuleIterator()");  // LCOV_EXCL_BR_LINE 15: marco defined in ss_templates.h  // NOLINT(whitespace/line_length)
  } else {
    l_reset_factor = GetResetFactor(l_moduleIter, f_user_reset);
  }
  return l_reset_factor;
}   // End of PsmFactorT CSystemManager::GetResetFactor(PCSTR f_module_name)


PsmFactorT CSystemManager::GetResetFactor(const ModuleLaunchListIter f_module_iter, BOOL f_user_reset) {
  PsmFactorT  l_reset_factor;
  if (f_module_iter->IsAGLUnit() == TRUE) {
    if (f_module_iter->IsAGLResetHistoryDisable() == TRUE) {
      l_reset_factor = PSM_FACTOR_AGL;
    } else {
      l_reset_factor = PSM_FACTOR_AGL_WITH_HISTORY;
    }
  } else {
    if (f_module_iter->IsNonAGLResetHistoryDisable() == TRUE) {
      l_reset_factor = PSM_FACTOR_TIER1;
    } else {
      l_reset_factor = PSM_FACTOR_TIER1_WITH_HISTORY;
    }
  }

  if (f_user_reset == TRUE) {
    if ((l_reset_factor == PSM_FACTOR_AGL) || (l_reset_factor == PSM_FACTOR_TIER1)) {
      l_reset_factor = PSM_FACTOR_USER;
    } else {
      l_reset_factor = PSM_FACTOR_USER_WITH_HISTORY;
    }
  }
  return l_reset_factor;
}   // End of PsmFactorT GetResetFactor(ModuleLaunchListIter & f_module_iter)
///////////////////////////////////////////////////////////////////////////////
/// \ingroup OnClientStopMonitorTimerExpiry
///
///
/// \param [in]
///
///
/// \return EFrameworkunifiedStatus
/// Success ==> eFrameworkunifiedStatusOK
/// Failure ==> Other values
///////////////////////////////////////////////////////////////////////////////
EFrameworkunifiedStatus CSystemManager::OnClientStopMonitorTimerExpiry(HANDLE hApp) {
  EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK;
  FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+");

  FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__, " Received from group %d", m_SystemStarter.get_id());

  SetCmdHist("SM_TIMER_CLIENT_STOP_MONITOR", m_TimerCmdHist, m_TimerHistIter, FrameworkunifiedGetMsgSrc(hApp));  // LCOV_EXCL_BR_LINE 11:unexpected branch  // NOLINT(whitespace/line_length)

  if ((m_SMCurrentState == SS_SM_WAITING_FOR_CRITICAL_APPS_AT__CWORD56__REQ)
      || (m_SMCurrentState == SS_SM_WAITING_FOR_CRITICAL_APPS_AT_INTERNAL_REQ)
      || m_SystemStarter.get_id() <= SS_SM_THIRD_GROUP) {
    FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, " Error: StopCompTimeout:gid:%d", m_SystemStarter.get_id());
    fprintf(stderr, "SS_SysManager/%s/Error: StopCompTimeout:gid:%d\n", __FUNCTION__, m_SystemStarter.get_id());

    for (GroupLaunchMapIter l_GroupIterator = m_MapProclaunchGrps.begin();
        l_GroupIterator != m_MapProclaunchGrps.end();
        l_GroupIterator++) {
      for (ModuleLaunchListIter l_ModuleListIterator = l_GroupIterator->second.modules.begin();
          l_ModuleListIterator != l_GroupIterator->second.modules.end();
          l_ModuleListIterator++) {
        if (l_ModuleListIterator->group_id >= m_SystemStarter.get_id()
            && is_service_shutdown_ready(l_ModuleListIterator) == FALSE) {
          FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, " Error: %s", l_ModuleListIterator->name.c_str());
          fprintf(stderr, "SS_SysManager/%s/Error: %s\n", __FUNCTION__, l_ModuleListIterator->name.c_str());  // LCOV_EXCL_BR_LINE 11:unexpected branch  // NOLINT(whitespace/line_length)
        }
      }
    }

    if (!m_SystemStarter.is_begin()) {
      // Continue termination processing to perform BackupManager termination processing.
      m_SystemStarter.decrement_id();
      check_all_groups_have_stopped(hApp);
    } else {
      // DEAD CODE
      fprintf(stderr, "SS_SysManager/%s:SVC stop timeout\n", __FUNCTION__);
      FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, " SVC stop timeout");
      l_eStatus = CallStopCompleteHandler(hApp);
      LOG_STATUS_REC_HIST_IF_ERRORED(l_eStatus, "CallStopCompleteHandler( hApp )");  // LCOV_EXCL_BR_LINE 15: marco defined in ss_system_manager.h  // NOLINT(whitespace/line_length)
    }
  } else {
    // The current m_ActiveGroupId group just timed out. If possible,
    // decrement it, and then see if there are more groups to send
    // stop requests to.
    if (!m_SystemStarter.is_begin()) {
      m_SystemStarter.decrement_id();
    }
    check_all_groups_have_stopped(hApp);
  }

  FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-");
  return l_eStatus;
}  // End of EFrameworkunifiedStatus CSystemManager::OnClientStopMonitorTimerExpiry( HANDLE hApp )

///////////////////////////////////////////////////////////////////////////////
/// \ingroup check_all_groups_have_stopped
/// check that all the groups has stopped
///
/// \param [in]
///
///
/// \return VOID
///////////////////////////////////////////////////////////////////////////////
VOID CSystemManager::check_all_groups_have_stopped(HANDLE hApp) {
  EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK;
  UI_32 l_ActiveGroupId = m_SystemStarter.get_id();
  FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+");
  FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__,
      " m_SystemStarter.get_id() is %d, 'm_NPPStopSent' is '%s'"
      , m_SystemStarter.get_id(), GetStr(m_NPPStopSent).c_str());

  // send stop to next group in reverse order
//  FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__, " m_NPPStopSent is %s", GetStr(m_NPPStopSent).c_str());  // LCOV_EXCL_BR_LINE 15: marco defined in ns_logger_if.h  // NOLINT(whitespace/line_length)
  if (!m_NPPStopSent) {
    l_eStatus = stop_all_modules_of_group(hApp);
    if (eFrameworkunifiedStatusOK != l_eStatus) {
      FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__,
          " Error: stop_all_modules_of_group(%d) errored: %d/'%s'",
          l_ActiveGroupId, l_eStatus, GetStr(l_eStatus).c_str());
    }
  } else {  // (m_ActiveGroupId < SS_SM_INITIAL_GROUP)
    BOOL l_bIsDetectTimeout;

    if ((l_bIsDetectTimeout = !have_critical_services_stopped())) {
      // If the Critical service is not terminated even when the final GROUP is completed, DUMP the applicable service and issue NAVI_DET.
      FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, " FinalCriticalCheck");
      fprintf(stderr, "SS_SysManager/%s:FinalCriticalCheck\n", __FUNCTION__);  // LCOV_EXCL_BR_LINE 15: marco defined in ns_logger_if.h  // NOLINT(whitespace/line_length)

      for (GroupLaunchMapIter l_GroupIterator = m_MapProclaunchGrps.begin();
          l_GroupIterator != m_MapProclaunchGrps.end();
          l_GroupIterator++) {
        for (ModuleLaunchListIter l_ModuleListIterator = l_GroupIterator->second.modules.begin();
            l_ModuleListIterator != l_GroupIterator->second.modules.end();
            l_ModuleListIterator++) {
          if (is_service_shutdown_ready(l_ModuleListIterator) == FALSE) {
            FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, " Error: %s",
                l_ModuleListIterator->name.c_str());
            fprintf(stderr, "SS_SysManager/%s/Error: %s\n",  // LCOV_EXCL_BR_LINE 11:unexpected branch  // NOLINT(whitespace/line_length)
                __FUNCTION__,
                l_ModuleListIterator->name.c_str());  // LCOV_EXCL_BR_LINE 11:unexpected branch  // NOLINT(whitespace/line_length)
          }
        }
      }
      fprintf(stderr, "SS_SysManager/%s:critical service no stop\n", __FUNCTION__);
      FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "critical service no stop");
    }

    CALL_AND_LOG_STATUS(CallStopCompleteHandler(hApp, l_bIsDetectTimeout));  // LCOV_EXCL_BR_LINE 15: marco defined in ss_templates.h  // NOLINT(whitespace/line_length)

    // In PastModel002, there was a transition to WAITING_FOR_CRITICAL_APPS in the following processing, but in _CWORD71_,
    // the transition to WAITING_FOR_CRITICAL_APPS was eliminated by revising the termination processing.
  }

  FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-");
  return;
}  // End of VOID CSystemManager::check_all_groups_have_stopped( HANDLE hApp )

///////////////////////////////////////////////////////////////////////////////
/// \ingroup MarkModuleStateStopped
/// Sets Module State to STOP COMPLETE
///
/// \param [in]
///
///
/// \return EFrameworkunifiedStatus
/// Success ==> eFrameworkunifiedStatusOK
/// Failure ==> Other values
///////////////////////////////////////////////////////////////////////////////


///////////////////////////////////////////////////////////////////////////////
/// \ingroup OnNppStopComplete
/// Npp Stop Complete complete Response\Ack Handlers
///
/// \param [in]
///
///
/// \return EFrameworkunifiedStatus
/// Success ==> eFrameworkunifiedStatusOK
/// Failure ==> Other values
///////////////////////////////////////////////////////////////////////////////
EFrameworkunifiedStatus CSystemManager::OnNppStopComplete(HANDLE hApp) {
  FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+");
  EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK;
  INTERFACEUNIFIEDLOG_RECEIVED_FROM(hApp);  // LCOV_EXCL_BR_LINE 15: marco defined in ns_logger_if.h  // NOLINT(whitespace/line_length)
  FRAMEWORKUNIFIEDLOG(ZONE_PERFORMANCE, __FUNCTION__, "from %s", FrameworkunifiedGetMsgSrc(hApp));

  SetCmdHist("NPS_NPP_STOP_ACK", m_SMCmdHist, m_SMHistIter, FrameworkunifiedGetMsgSrc(hApp));  // LCOV_EXCL_BR_LINE 11:unexpected branch  // NOLINT(whitespace/line_length)

  char l_cBuf[100];
  snprintf(l_cBuf, sizeof(l_cBuf), "ProcessModuleStopCompleteResponse(%s)", FRAMEWORKUNIFIED_NS_NPSERVICE);
  l_eStatus = ProcessModuleStopCompleteResponse(hApp, FRAMEWORKUNIFIED_NS_NPSERVICE);
  LOG_STATUS_REC_HIST_IF_ERRORED(l_eStatus, l_cBuf);  // LCOV_EXCL_BR_LINE 15: marco defined in ss_system_manager.h  // NOLINT(whitespace/line_length)

  FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-");
  return eFrameworkunifiedStatusOK;
}

EFrameworkunifiedStatus CSystemManager::GetModuleIterator(PCSTR f_moduleName, ModuleLaunchListIter &f_moduleIter) {
  FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+");
  EFrameworkunifiedStatus l_eStatus;

  ModuleLaunchListIter l_moduleIter;
//  static int l_numTimesEntered = 0 ;
//  l_numTimesEntered++ ;
//  FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__  // LCOV_EXCL_BR_LINE 15: marco defined in ns_logger_if.h  // NOLINT(whitespace/line_length)
//       , " NTE %d: Looking for %s"
//       , l_numTimesEntered
//       , f_moduleName);

  BOOL l_bIsFound = FALSE;
  for (GroupLaunchMapIter l_GroupIter = m_MapProclaunchGrps.begin();
      !l_bIsFound && l_GroupIter != m_MapProclaunchGrps.end();
      l_GroupIter++) {
//    FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__  // LCOV_EXCL_BR_LINE 15: marco defined in ns_logger_if.h  // NOLINT(whitespace/line_length)
//       , " NTE %d: Checking group %d/%s"
//       , l_numTimesEntered
//       , l_GroupIter->second.id
//       , l_GroupIter->second.name.c_str());

    for (l_moduleIter = l_GroupIter->second.modules.begin();
        !l_bIsFound && (l_moduleIter != l_GroupIter->second.modules.end());
        l_moduleIter++) {
//    FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__  // LCOV_EXCL_BR_LINE 15: marco defined in ns_logger_if.h  // NOLINT(whitespace/line_length)
//       , " NTE %d: Checking PCSTR '%s' against std::string '%s': %d, %s"
//       , l_numTimesEntered
//       , f_moduleName
//       , l_moduleIter->name.c_str()
//       , strcmp(l_moduleIter->name.c_str(), f_moduleName)
//       , (0 == strcmp(l_moduleIter->name.c_str(), f_moduleName) ? "True" : "False"));

      l_bIsFound =
          (0 == strcmp(l_moduleIter->name.c_str(), f_moduleName));
      if (l_bIsFound) {
        f_moduleIter = l_moduleIter;
//        FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__,  // LCOV_EXCL_BR_LINE 15: marco defined in ns_logger_if.h  // NOLINT(whitespace/line_length)
////            " NTE %d:"
//               " '%s' is in group %d/%s"
////           , l_numTimesEntered
//           , f_moduleIter->name.c_str()
//           , l_GroupIter->second.id
//           , l_GroupIter->second.name.c_str());
        l_eStatus = eFrameworkunifiedStatusOK;
      }
    }
  }

  if (!l_bIsFound) {
    FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__,
//      " NTE %d:"
        " Error: '%s' is not in group map 'm_MapProclaunchGrps'"
//       , l_numTimesEntered
        , f_moduleName);
    if (0 != strcmp(f_moduleName, SERVICE_SYSMANAGER)) {
      SysMgrConfiguration m_launchConfig;
      m_launchConfig.PrintAllInfo(m_MapProclaunchGrps);
    }
    l_eStatus = eFrameworkunifiedStatusDbRecNotFound;
  }
  FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-");
  return l_eStatus;
}  // End of EFrameworkunifiedStatus CSystemManager::GetModuleIterator( PCSTR f_moduleName

BOOL CSystemManager::IsGroupStarted(UI_32 f_groupID) {
  FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+");
  BOOL l_bIsStarted = TRUE;

  GroupLaunchMapIter l_GroupIter = m_MapProclaunchGrps.find(f_groupID);
  if (l_GroupIter == m_MapProclaunchGrps.end()) {
    FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, " Error: Group Map Empty; was looking for group %d", f_groupID);
  } else {
    ModuleLaunchListIter l_ModuleListIter = l_GroupIter->second.modules.begin();
    const SMModuleState l_dest_state = InProgressStateToState();  // LCOV_EXCL_BR_LINE 11: Gcov constraints (because exception-handling routes are automatically generated) // NOLINT(whitespace/line_length)
    if (l_dest_state != MODULE_STATE_INVALID) {
      for (; l_ModuleListIter != l_GroupIter->second.modules.end(); l_ModuleListIter++) {
        if (((l_ModuleListIter->IsModuleState(l_dest_state) == FALSE)  // LCOV_EXCL_BR_START 11:Gcov constraints (because exception-handling routes are automatically generated)
            && (l_ModuleListIter->IsModuleState(MODULE_STATE_START_FAILED) == FALSE)
            && (l_ModuleListIter->IsModuleState(MODULE_STATE_START_PRE_FAILED) == FALSE)
            && (l_ModuleListIter->IsModuleState(MODULE_STATE_STOP_PRE_FAILED) == FALSE)
            && (l_ModuleListIter->IsModuleState(MODULE_STATE_START_BACKGROUND_FAILED) == FALSE)
            && (l_ModuleListIter->IsModuleState(MODULE_STATE_STOP_BACKGROUND_FAILED) == FALSE)
            && (l_ModuleListIter->IsModuleState(MODULE_STATE_STOP_FAILED) == FALSE))
            // LCOV_EXCL_BR_STOP 11:Gcov constraints (because exception-handling routes are automatically generated)
            || ((l_ModuleListIter->is_start_required == TRUE)
                // LCOV_EXCL_START 6: Because the value cannot be stored to make the condition true
                && ((l_ModuleListIter->IsModuleState(MODULE_STATE_LAUNCHING) == TRUE)
                    || (l_ModuleListIter->IsModuleState(MODULE_STATE_CONNECTED) == TRUE)
                    || (l_ModuleListIter->IsModuleState(MODULE_STATE_LAUNCHED) == TRUE)))) {
                // LCOV_EXCL_STOP 6: Because the value cannot be stored to make the condition true
          l_bIsStarted = FALSE;
          FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__, " No: '%s' in group %d/%s is '%s'", l_ModuleListIter->name.c_str(),
                 l_GroupIter->second.id, l_GroupIter->second.name.c_str(),
                 l_ModuleListIter->ModuleStateStr().c_str());
          break;
        }
      }
    }
  }
  FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-");
  return l_bIsStarted;
}  // End of BOOL CSystemManager::IsGroupStarted(UI_32 f_groupId)

BOOL CSystemManager::IsGroupStopped(UI_32 f_groupID) {
  FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+");
  BOOL l_bIsStopped = TRUE;
  ModuleLaunchListIter l_ModuleListIter;

  GroupLaunchMapIter l_GroupIter = m_MapProclaunchGrps.find(f_groupID);
  if (l_GroupIter == m_MapProclaunchGrps.end()) {
    FRAMEWORKUNIFIEDLOG(ZONE_WARN, __FUNCTION__,
        " Warning: Group Map Empty; was looking for group %d",
        f_groupID);
  } else {
    for (l_ModuleListIter = l_GroupIter->second.modules.begin();
        l_bIsStopped
            && l_ModuleListIter != l_GroupIter->second.modules.end();
        l_ModuleListIter++) {
      if (l_ModuleListIter->IsModuleState(MODULE_STATE_STOP_SENT)) {
        l_bIsStopped = FALSE;
      }
    }
  }
  FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-");
  return l_bIsStopped;
}  // End of BOOL CSystemManager::IsGroupStopped(UI_32 f_groupId)

///////////////////////////////////////////////////////////////////////////////
/// \ingroup OnStopComplete
/// Shutdown complete Response\Ack Handlers
///
/// \param [in]
///
///
/// \return EFrameworkunifiedStatus
/// Success ==> eFrameworkunifiedStatusOK
/// Failure ==> Other values
///////////////////////////////////////////////////////////////////////////////
EFrameworkunifiedStatus CSystemManager::OnModuleStopCompleteResponse(HANDLE hApp) {
  FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+");
  EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusErrOther;
  INTERFACEUNIFIEDLOG_RECEIVED_FROM(hApp);  // LCOV_EXCL_BR_LINE 15: marco defined in ns_logger_if.h  // NOLINT(whitespace/line_length)

  PCSTR l_moduleName = FrameworkunifiedGetMsgSrc(hApp);

  FRAMEWORKUNIFIEDLOG(ZONE_PERFORMANCE, __FUNCTION__, "from %s", l_moduleName);
  SetCmdHist("SS_SM_STOP_COMPL_RSPN", m_SMCmdHist, m_SMHistIter, l_moduleName);

  char l_cBuf[100];
  snprintf(l_cBuf, sizeof(l_cBuf), "ProcessModuleStopCompleteResponse(%s)", l_moduleName);
  l_eStatus = ProcessModuleStopCompleteResponse(hApp, l_moduleName);
  LOG_STATUS_REC_HIST_IF_ERRORED(l_eStatus, l_cBuf);  // LCOV_EXCL_BR_LINE 15: marco defined in ss_system_manager.h  // NOLINT(whitespace/line_length)

  FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-");
  return l_eStatus;
}  // End of EFrameworkunifiedStatus CSystemManager::OnModuleStopCompleteResponse( HANDLE hApp )

///////////////////////////////////////////////////////////////////////////////
/// \ingroup OnGetStartExtInfo
///
/// \param [in]
///
///
/// \return EFrameworkunifiedStatus
/// Success ==> eFrameworkunifiedStatusOK
/// Failure ==> Other values
///////////////////////////////////////////////////////////////////////////////
EFrameworkunifiedStatus CSystemManager::OnGetStartExtInfo(HANDLE hApp) {
  EFrameworkunifiedStatus l_eStatus;
  T_SS_SM_START_ExtDataStructType l_extInfo = { 0 };

  SS_STATIC_ASERT(sizeof(T_SS_SM_START_ExtDataStructType) == SS_SM_START_EXT_INFO_SIZE);  // LCOV_EXCL_BR_LINE 15: marco defined in ss_templates.h  // NOLINT(whitespace/line_length)

  FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+ ");

  SetCmdHist("SS_SM_GET_START_EXT_INFO", m_SMCmdHist, m_SMHistIter, FrameworkunifiedGetMsgSrc(hApp));

  l_extInfo.isProgUpdated =
      (m_ProgUpdateState & SS_SM_PROG_UPDATE_STATE_UPDATED) ? TRUE : FALSE;
  l_extInfo.isMapUpdated =
      (m_ProgUpdateState & SS_SM_PROG_UPDATE_STATE_MAP_UPDATED) ? TRUE : FALSE;  // LCOV_EXCL_BR_LINE 11:unexpected branch  // NOLINT(whitespace/line_length)
  l_extInfo.isMapDiffUpdated =
      (m_ProgUpdateState & SS_SM_PROG_UPDATE_STATE_MAPDIFF_UPDATED) ? TRUE : FALSE;  // LCOV_EXCL_BR_LINE 11:unexpected branch  // NOLINT(whitespace/line_length)

  ModuleLaunchListIter l_ModuleListIter;

  l_eStatus = GetModuleIterator(FrameworkunifiedGetMsgSrc(hApp), l_ModuleListIter);
  if (eFrameworkunifiedStatusOK != l_eStatus) {
    FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, " Error: %s not found", FrameworkunifiedGetMsgSrc(hApp));
  } else {
    switch (l_ModuleListIter->relaunch_status) {
    case NotRelaunched:
      l_extInfo.relaunchStatus = e_SS_SM_RELAUNCH_STATUS_NONE;
      break;
    case RelaunchSafe:
      // LCOV_EXCL_START 6: Because the applicable variable cannot be changed from the external API (only evaluated by the initial value)
      AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
      l_extInfo.relaunchStatus = e_SS_SM_RELAUNCH_STATUS_SAFE;
      break;
    case RelaunchErr:
      AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
      l_extInfo.relaunchStatus = e_SS_SM_RELAUNCH_STATUS_ERR;
      break;
    default:
      AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
      SS_ASERT(0);  // LCOV_EXCL_BR_LINE 15: marco defined in ss_templates.h  // NOLINT(whitespace/line_length)
      l_extInfo.relaunchStatus = e_SS_SM_RELAUNCH_STATUS_NONE;
      break;
      // LCOV_EXCL_STOP
    }
  }

  // Instead of sending Return Message, this function must call FrameworkunifiedSetSyncResponseData()
  // because this request is sent by FrameworkunifiedInvokeSync()
  l_eStatus = FrameworkunifiedSetSyncResponseData(hApp, &l_extInfo, sizeof(l_extInfo));
  LOG_STATUS_IF_ERRORED(l_eStatus, "FrameworkunifiedSetSyncResponseData()");  // LCOV_EXCL_BR_LINE 15: marco defined in ss_templates.h  // NOLINT(whitespace/line_length)

  FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-");
  return l_eStatus;
}  // End of EFrameworkunifiedStatus CSystemManager::OnGetStartExtInfo( HANDLE hApp )

///////////////////////////////////////////////////////////////////////////////
/// \ingroup OnGetStopExtInfo
///
/// \param [in]
///
///
/// \return EFrameworkunifiedStatus
/// Success ==> eFrameworkunifiedStatusOK
/// Failure ==> Other values
///////////////////////////////////////////////////////////////////////////////
EFrameworkunifiedStatus CSystemManager::OnGetStopExtInfo(HANDLE hApp) {
  EFrameworkunifiedStatus l_eStatus;
  T_SS_SM_STOP_ExtDataStructType l_extInfo = { 0 };

  SS_STATIC_ASERT(sizeof(T_SS_SM_STOP_ExtDataStructType) == SS_SM_STOP_EXT_INFO_SIZE);  // LCOV_EXCL_BR_LINE 15: marco defined in ss_templates.h  // NOLINT(whitespace/line_length)

  FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+ ");

  SetCmdHist("SS_SM_GET_STOP_EXT_INFO", m_SMCmdHist, m_SMHistIter, FrameworkunifiedGetMsgSrc(hApp));

  l_extInfo.isProgUpdated =
      (m_ProgUpdateState & SS_SM_PROG_UPDATE_STATE_UPDATED) ? TRUE : FALSE;

  // Instead of sending Return Message, this function must call FrameworkunifiedSetSyncResponseData()
  // because this request is sent by FrameworkunifiedInvokeSync()
  l_eStatus = FrameworkunifiedSetSyncResponseData(hApp, &l_extInfo, sizeof(l_extInfo));
  LOG_STATUS_IF_ERRORED(l_eStatus, "FrameworkunifiedSetSyncResponseData()");  // LCOV_EXCL_BR_LINE 15: marco defined in ss_templates.h  // NOLINT(whitespace/line_length)

  FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-");
  return l_eStatus;
}  // End of EFrameworkunifiedStatus CSystemManager::OnGetStopExtInfo( HANDLE hApp )

///////////////////////////////////////////////////////////////////////////////
/// \ingroup OnModuleStopCompleteNotification
///
/// \param [in]
///
///
/// \return EFrameworkunifiedStatus
/// Success ==> eFrameworkunifiedStatusOK
/// Failure ==> Other values
///////////////////////////////////////////////////////////////////////////////
EFrameworkunifiedStatus CSystemManager::OnModuleStopCompleteNotification(HANDLE hApp) {  // LCOV_EXCL_START 6: Because the condition cannot be set
  AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
  EFrameworkunifiedStatus l_eStatus;

  FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+ ");
  INTERFACEUNIFIEDLOG_RECEIVED_FROM(hApp);  // LCOV_EXCL_BR_LINE 15: marco defined in ns_logger_if.h  // NOLINT(whitespace/line_length)
  FRAMEWORKUNIFIEDLOG(ZONE_PERFORMANCE, __FUNCTION__, "from %s", FrameworkunifiedGetMsgSrc(hApp));

  ShutdownComplete l_shutdownNotif;   /// \file   frameworkunified_framework_types.h
  // ReadMsg():                                                      *
  //   Check hApp ptr, msg size, msg reception, read msg if all ok.  *
  //   Report any errors found.                                      *
  //                                                                 *
  if (eFrameworkunifiedStatusOK != (l_eStatus = ReadMsg < ShutdownComplete > (hApp, l_shutdownNotif))) {
    LOG_ERROR("ReadMsg()");  // LCOV_EXCL_BR_LINE 15: marco defined in ss_templates.h  // NOLINT(whitespace/line_length)
  } else {
    PCSTR l_moduleName = l_shutdownNotif.cServiceName;
    FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__,
        " '%s' 'Shutdown Complete Status' is 0x%X", l_moduleName,
        l_shutdownNotif.eShutdownCompleteStatus);

    char l_cBuf[100];
    snprintf(l_cBuf, sizeof(l_cBuf),
        "ProcessModuleStopCompleteResponse(%s)", l_moduleName);
    l_eStatus = ProcessModuleStopCompleteResponse(hApp, l_moduleName);
    LOG_STATUS_REC_HIST_IF_ERRORED(l_eStatus, l_cBuf);  // LCOV_EXCL_BR_LINE 15: marco defined in ss_system_manager.h  // NOLINT(whitespace/line_length)
  }

  FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-");
  return l_eStatus;
}  // End of EFrameworkunifiedStatus CSystemManager::onmodulestopcompletenotification( HANDLE hApp )
// LCOV_EXCL_STOP

EFrameworkunifiedStatus CSystemManager::ProcessModuleStopCompleteResponse(HANDLE hApp, PCSTR f_moduleName) {
  FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+");
  EFrameworkunifiedStatus l_eStatus;

  ModuleLaunchListIter l_ModuleListIter;
  l_eStatus = GetModuleIterator(f_moduleName, l_ModuleListIter);
  if (eFrameworkunifiedStatusOK != l_eStatus) {
    FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, " Error: Module %s not found in Group Launch Map", f_moduleName);
  } else {
    switch (m_SMCurrentState) {
    case SS_SM_READY_TO_LAUNCH_APP:
    case SS_SM_APPS_LAUNCH_IN_PROGRESS:
    case SS_SM_APPS_LAUNCHED_READY_TO_START:
      FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__,
          " Error: Received from client while in "
          "the '%s' state !!!",
          GetStr(m_SMCurrentState).c_str());
      l_eStatus = eFrameworkunifiedStatusErrOther;
      break;

    case SS_SM_APPS_STOPPING_AT__CWORD56__REQ:
    case SS_SM_APPS_STOPPING_AT_INTERNAL_REQ:
    case SS_SM_WAITING_FOR_CRITICAL_APPS_AT__CWORD56__REQ:
    case SS_SM_WAITING_FOR_CRITICAL_APPS_AT_INTERNAL_REQ:
      if (m_SystemStarter.get_id() == SS_SM_THIRD_GROUP) {
        // Execute shutdown_critical services termination synchronization prior to CoreModule(backupManager termination processing
        l_ModuleListIter->SetModuleState(MODULE_STATE_STOPPED);
        if (have_critical_services_stopped()) {  // Transition after all critical services have ended
          ProcessGroupOnModuleStopResponse(hApp, m_SystemStarter.get_id());
        }
      } else {
        l_eStatus = ModuleCompleteResponse(hApp, l_ModuleListIter,
                MODULE_STATE_STOPPED,
                (SysMgrCbType3<CSystemManager,
                    &CSystemManager::IsGroupStopped>),
                (SysMgrCbType2<CSystemManager,
                    &CSystemManager::ProcessGroupOnModuleStopResponse>),
                "stop");
      }
      break;

    case SS_SM_APPS_START_COMPLETE:
    case SS_SM_APPS_START_IN_PROGRESS:
    case SS_SM_APPS_PRE_RUN_COMPLETE:
    case SS_SM_APPS_PRE_START_IN_PROGRESS:
    case SS_SM_APPS_PRE_STOP_IN_PROGRESS:
    case SS_SM_APPS_BACKGROUND_RUN_COMPLETE:
    case SS_SM_APPS_BACKGROUND_START_IN_PROGRESS:
    case SS_SM_APPS_BACKGROUND_STOP_IN_PROGRESS:
      FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__,
          " Error: Received from client while in "
          "the '%s' state !!!",
          GetStr(m_SMCurrentState).c_str());
      l_eStatus = eFrameworkunifiedStatusErrOther;
      break;
    }  // End switch ( m_SMCurrentState )
  }

  FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-");
  return l_eStatus;
}  // End of EFrameworkunifiedStatus CSystemManager::ProcessModuleStopCompleteResponse(

EFrameworkunifiedStatus CSystemManager::ProcessGroupOnModuleStopResponse(HANDLE hApp, UI_32 f_groupID) {
  EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK;
  FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+");
  UI_32 l_ActiveGroupId = m_SystemStarter.get_id();

  m_GroupLaunchTimer->StopTimer(m_aTimerIDs[eSM_TIMER_CLIENT_STOP_MONITOR]);

  if (f_groupID != l_ActiveGroupId) {
    FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__,
        " Group %d stop complete, but m_SystemStarter.get_id() is %d",
        f_groupID
        // , m_ActiveGroupId);  // LCOV_EXCL_BR_LINE 15: marco defined in ns_logger_if.h  // NOLINT(whitespace/line_length)
        , l_ActiveGroupId);
  } else {
    if (!m_SystemStarter.is_begin()) {
      m_SystemStarter.decrement_id();
    }
    check_all_groups_have_stopped(hApp);
  }
  FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-");
  return l_eStatus;
}  // End of EFrameworkunifiedStatus CSystemManager::ProcessGroupOnModuleStopResponse( HANDLE hApp

///////////////////////////////////////////////////////////////////////////////
/// \ingroup stop_all_modules_of_group
/// Send SS_SM_STOP to all modules of the given group
///
/// \param [in]
///
///
/// \return VOID
///////////////////////////////////////////////////////////////////////////////
EFrameworkunifiedStatus CSystemManager::stop_all_modules_of_group(HANDLE hApp) {
  FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+");
  EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK;
  ModuleLaunchList::reverse_iterator l_revIter;

  UI_32 l_uiMaxGroupWaitTime_sec = 0;
  UI_32 l_uiMaxGroupWaitTime_msec = 0;
  UI_32 l_uiModuleWaitTime = 0;

  // GroupLaunchMapIter l_GroupIterator = m_MapProclaunchGrps.find(m_ActiveGroupId);
  GroupLaunchMapIter l_GroupIterator = m_MapProclaunchGrps.find(m_SystemStarter.get_id());
  if (l_GroupIterator == m_MapProclaunchGrps.end()) {
    FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__,
        " Error: Group %d not found; 'm_MapProclaunchGrps' is empty"
        //, m_ActiveGroupId);  // LCOV_EXCL_BR_LINE 15: marco defined in ns_logger_if.h  // NOLINT(whitespace/line_length)
        , m_SystemStarter.get_id());
    l_eStatus = eFrameworkunifiedStatusDbRecNotFound;
  } else {
    int l_numModulesMessaged = 0;
    FRAMEWORKUNIFIEDLOG(ZONE_STATE, __FUNCTION__, "StopReq grp:%d", m_SystemStarter.get_id());

    T_SS_SM_STOP_DataStructType l_SM_STOP_Struct;
    l_SM_STOP_Struct.shutdownTrigger = m_shutdownTrigger;
    l_SM_STOP_Struct.lastUserMode = m_lastUserMode;

    for (l_revIter = l_GroupIterator->second.modules.rbegin();
        l_revIter != l_GroupIterator->second.modules.rend();
        l_revIter++) {
      // LCOV_EXCL_BR_START 11: Excluded due to gcov constraints (others)
      if ((l_revIter->IsModuleState(MODULE_STATE_START_SENT) == TRUE)
          || (l_revIter->IsModuleState(MODULE_STATE_STARTED) == TRUE)
          || (l_revIter->IsModuleState(MODULE_STATE_START_PRE_SENT) == TRUE)
          || (l_revIter->IsModuleState(MODULE_STATE_STARTED_PRE) == TRUE)
          || (l_revIter->IsModuleState(MODULE_STATE_STOP_PRE_SENT) == TRUE)
          || (l_revIter->IsModuleState(MODULE_STATE_STOPPED_PRE) == TRUE)
          || (l_revIter->IsModuleState(MODULE_STATE_START_BACKGROUND_SENT) == TRUE)
          || (l_revIter->IsModuleState(MODULE_STATE_STARTED_BACKGROUND) == TRUE)
          || (l_revIter->IsModuleState(MODULE_STATE_STOP_BACKGROUND_SENT) == TRUE)
          || (l_revIter->IsModuleState(MODULE_STATE_STOPPED_BACKGROUND) == TRUE)) {
        // LCOV_EXCL_BR_STOP 11: Excluded due to gcov constraints (others)
        if (FRAMEWORKUNIFIED_NS_NPSERVICE == l_revIter->name) {
          if (epssdmsdtFACTORY_DATA_RESET == m_shutdownTrigger) {
            CALL_AND_LOG_STATUS(FrameworkunifiedSendStopToNSNPP(hApp, eFrameworkunifiedDataResetShutdown, eFrameworkunifiedUserData | eFrameworkunifiedFactoryData));  // LCOV_EXCL_BR_LINE 15: marco defined in ss_templates.h  // NOLINT(whitespace/line_length)
          } else if (epssdmsdtUSER_DATA_RESET == m_shutdownTrigger) {
            CALL_AND_LOG_STATUS(FrameworkunifiedSendStopToNSNPP(hApp, eFrameworkunifiedDataResetShutdown, eFrameworkunifiedUserData));  // LCOV_EXCL_BR_LINE 15: marco defined in ss_templates.h  // NOLINT(whitespace/line_length)
          } else if (epssdmsdtFAST_SLEEP_MODE == m_shutdownTrigger) {
            CALL_AND_LOG_STATUS(FrameworkunifiedSendStopToNSNPP(hApp, eFrameworkunifiedQuickShutdown));  // LCOV_EXCL_BR_LINE 15: marco defined in ss_templates.h  // NOLINT(whitespace/line_length)
          } else {
            CALL_AND_LOG_STATUS(FrameworkunifiedSendStopToNSNPP(hApp, eFrameworkunifiedNormalShutdown));  // LCOV_EXCL_BR_LINE 15: marco defined in ss_templates.h  // NOLINT(whitespace/line_length)
          }

          if (eFrameworkunifiedStatusOK != l_eStatus) {
            l_revIter->SetModuleState(MODULE_STATE_STOP_FAILED);
          } else {
            l_revIter->SetModuleState(MODULE_STATE_STOP_SENT);
            l_numModulesMessaged++;
          }

          m_NPPStopSent = TRUE;
          FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__, " m_NPPStopSent is %s", GetStr(m_NPPStopSent).c_str());  // LCOV_EXCL_BR_LINE 15: marco defined in ns_logger_if.h  // NOLINT(whitespace/line_length)
        // End else if ( FRAMEWORKUNIFIED_NS_NPSERVICE == l_ModuleListIter->name )
        } else {
          l_eStatus = l_revIter->SendMsgAndUpdateState(&l_SM_STOP_Struct);
          LOG_STATUS_REC_HIST_IF_ERRORED(l_eStatus, "l_revIter->SendMsgAndUpdateState(&l_SM_STOP_Struct)");  // LCOV_EXCL_BR_LINE 15: marco defined in ss_system_manager.h  // NOLINT(whitespace/line_length)
          if (eFrameworkunifiedStatusOK == l_eStatus) {
            if (epssdmsdtFAST_SLEEP_MODE == m_shutdownTrigger) {
              l_uiModuleWaitTime = l_revIter->fast_shutdown_wait_time;

            } else {
              l_uiModuleWaitTime = l_revIter->shutdown_wait_time;
            }
            if (l_uiModuleWaitTime > l_uiMaxGroupWaitTime_sec) {
              l_uiMaxGroupWaitTime_sec = l_uiModuleWaitTime;
            }
            l_numModulesMessaged++;
          }
        }  // End if MODULE_STATE_STARTED || MODULE_STATE_START_SENT
      } else if (l_revIter->IsModuleState(MODULE_STATE_INVALID)
          && FRAMEWORKUNIFIED_NS_NPSERVICE == l_revIter->name) {
        m_NPPStopSent = TRUE;
        FRAMEWORKUNIFIEDLOG(ZONE_STATE, __FUNCTION__, "StopNotSent:%s is INVALID", FRAMEWORKUNIFIED_NS_NPSERVICE);
      } else {
        FRAMEWORKUNIFIEDLOG(ZONE_STATE, __FUNCTION__, "StopNotSent:%s is %s",
            l_revIter->name.c_str(),
            l_revIter->ModuleStateStr().c_str());
      }
    }

    if (0 == l_numModulesMessaged) {
      LogGroupModulesState(m_SystemStarter.get_id()  // m_ActiveGroupId  // LCOV_EXCL_BR_LINE 11:unexpected branch  // NOLINT(whitespace/line_length)
          , " Warning: NO modules were sent SS_SM_STOP");

      FRAMEWORKUNIFIEDLOG(ZONE_STATE, __FUNCTION__, "StopComp grp:%d", l_GroupIterator->second.id);

      if (m_SystemStarter.get_id() > SS_SM_INITIAL_GROUP) {
        m_SystemStarter.decrement_id();
        FRAMEWORKUNIFIEDLOG(ZONE_STATE, __FUNCTION__, " m_ActiveGroupId is now %d", m_SystemStarter.get_id());

        check_all_groups_have_stopped(hApp);
      }
    } else {
      if (epssdmsdtFAST_SLEEP_MODE == m_shutdownTrigger) {
        // fast shutdown wait time always comes in milli seconds
        UI_32 l_uiTotalWaitTime = l_uiMaxGroupWaitTime_sec;
        l_uiMaxGroupWaitTime_sec = l_uiTotalWaitTime / 1000;
        l_uiMaxGroupWaitTime_msec = l_uiTotalWaitTime % 1000;
      } else {
        // Other types of shutdown except fast shutdown always comes in seconds.
        l_uiMaxGroupWaitTime_msec = 0;
      }

      FRAMEWORKUNIFIEDLOG(ZONE_STATE, __FUNCTION__, "StopTimer grp:%d time:%d.%d",
          m_SystemStarter.get_id(), l_uiMaxGroupWaitTime_sec,
          l_uiMaxGroupWaitTime_msec);
      m_GroupLaunchTimer->StartTimerMulti(
          m_aTimerIDs[eSM_TIMER_CLIENT_STOP_MONITOR],
          l_uiMaxGroupWaitTime_sec, l_uiMaxGroupWaitTime_msec, 0, 0,
          m_SystemStarter.get_id());
    }
  }
  FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-");
  return l_eStatus;
}  // End of VOID CSystemManager::stop_all_modules_of_group(HANDLE hApp)

EFrameworkunifiedStatus CSystemManager::ValidateUserModeMessage(HANDLE hApp, EPWR_USER_MODE_TYPE &l_eUserModeState) {  // LCOV_EXCL_START 6: Because the condition cannot be set // NOLINT(whitespace/line_length)
  AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
  FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+");
  EFrameworkunifiedStatus l_eStatus;
  Pwr_ServiceSetInterface tServiceSetIf;
  EPWR_USER_MODE_TYPE l_my_eUserModeState;

  // ReadMsg():                                                          *
  //   Check hApp ptr, msg size, msg reception, read msg if all ok.      *
  if (eFrameworkunifiedStatusOK != (l_eStatus = ReadMsg < Pwr_ServiceSetInterface > (hApp, tServiceSetIf))) {
    LOG_ERROR("ReadMsg()");  // LCOV_EXCL_BR_LINE 15: marco defined in ss_templates.h  // NOLINT(whitespace/line_length)
  } else {
    l_my_eUserModeState = tServiceSetIf.data.user_mode.mode;
    switch (l_my_eUserModeState) {
    case epsumINVALID:
      FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, " Error: l_eUserModeState == epsumINVALID");
      l_eStatus = eFrameworkunifiedStatusInvldParam;
      break;

    case epsumOFF:
    case epsumON:
      FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__, " Validated '%s'",
          l_my_eUserModeState == epsumON ? "epsumON" : "epsumOFF");
      l_eUserModeState = l_my_eUserModeState;
      l_eStatus = eFrameworkunifiedStatusOK;
      break;

      // default:  Don't code a 'default' here - let the compiler
      // issue a warning ( set via -Wall or -Wswitch ) when the set of
      // enumerations changes - then the maintainer will
      // automagically know to update this switch statement.
    }  // End switch
  }
  FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-");
  return l_eStatus;
}  // End of EFrameworkunifiedStatus CSystemManager::ValidateUserModeMessage( HANDLE hApp, EPWR_USER_MODE_TYPE &l_eUserModeState )
// LCOV_EXCL_STOP

//*****************************************************************************
// Next Wakeup Type Set Protocol functions                                    *
//                                                                            *
EFrameworkunifiedStatus CSystemManager::OnSetNextWakeupTypeRequest(HANDLE hApp) {
  FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+");
  EFrameworkunifiedStatus l_eStatus;
  ESMNextWakeupType l_wakeupType;

  INTERFACEUNIFIEDLOG_RECEIVED_FROM(hApp);  // LCOV_EXCL_BR_LINE 15: marco defined in ns_logger_if.h  // NOLINT(whitespace/line_length)
  FRAMEWORKUNIFIEDLOG(ZONE_STATE, __FUNCTION__, "from %s", FrameworkunifiedGetMsgSrc(hApp));
  SetCmdHist("SS_SM_NEXT_WAKEUP_TYPE_SET_REQ", m_SMCmdHist, m_SMHistIter, FrameworkunifiedGetMsgSrc(hApp));

  if (eFrameworkunifiedStatusOK != (l_eStatus = ReadMsg < ESMNextWakeupType > (hApp, l_wakeupType))) {
    LOG_ERROR("ReadMsg()");  // LCOV_EXCL_BR_LINE 15: marco defined in ss_templates.h  // NOLINT(whitespace/line_length)
  } else {
    switch (l_wakeupType) {
    case e_SS_SM_NEXT_WAKEUP_TYPE_NONE:
    case e_SS_SM_NEXT_WAKEUP_TYPE_COLD:
    case e_SS_SM_NEXT_WAKEUP_TYPE_HOT:
      break;
    default:
      FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "unknown type(%d)", l_wakeupType);
      l_eStatus = eFrameworkunifiedStatusInvldParam;
    }
  }
  l_eStatus = FrameworkunifiedSetSyncResponseData(hApp, &l_eStatus, sizeof(l_eStatus));
  LOG_STATUS_IF_ERRORED(l_eStatus, "FrameworkunifiedSetSyncResponseData()");  // LCOV_EXCL_BR_LINE 15: marco defined in ss_templates.h  // NOLINT(whitespace/line_length)

  FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-");
  return l_eStatus;
}  // End of EFrameworkunifiedStatus CSystemManager::OnSetNextWakeupTypeRequest( HANDLE hApp )

//                                                                            *
// End of Boot Mode Protocol functions                                        *
//*****************************************************************************


//*****************************************************************************
// Data Reset Mode Protocol functions                                         *
//                                                                            *
EFrameworkunifiedStatus CSystemManager::OnSetDataResetModeRequest(HANDLE hApp) {
  FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+");
  EFrameworkunifiedStatus l_eStatus;
  ESMDataResetModeInfo l_dataResetMode;
  INTERFACEUNIFIEDLOG_RECEIVED_FROM(hApp);  // LCOV_EXCL_BR_LINE 15: marco defined in ns_logger_if.h  // NOLINT(whitespace/line_length)
  FRAMEWORKUNIFIEDLOG(ZONE_STATE, __FUNCTION__, "from %s", FrameworkunifiedGetMsgSrc(hApp));

  SetCmdHist("SS_SM_DATA_RESET_MODE_SET_REQ", m_SMCmdHist, m_SMHistIter, FrameworkunifiedGetMsgSrc(hApp));

  if (eFrameworkunifiedStatusOK != (l_eStatus = ReadMsg < ESMDataResetModeInfo > (hApp, l_dataResetMode))) {
    LOG_ERROR("ReadMsg()");  // LCOV_EXCL_BR_LINE 15: marco defined in ss_templates.h  // NOLINT(whitespace/line_length)
  } else {
    uint32_t tmp;
    m_DataResetMode = l_dataResetMode;
    tmp = static_cast<uint32_t>(m_DataResetMode);
    if (PowerHalSetResetInfo(AGL_DATARESET_STATE, tmp)) {  // LCOV_EXCL_BR_LINE 11:Gcov constraints (because exception-handling routes are automatically generated)
      FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "Could not set AGL_DATARESET_STATE.");
      // Return error to client of system_manager.
      l_eStatus = eFrameworkunifiedStatusFail;
    }
  }
  //
  // Instead of sending Return Message, this function must call FrameworkunifiedSetSyncResponseData()
  // because this request is sent by FrameworkunifiedInvokeSync()
  //
  l_eStatus = FrameworkunifiedSetSyncResponseData(hApp, &l_eStatus, sizeof(l_eStatus));
  LOG_STATUS_IF_ERRORED(l_eStatus, "FrameworkunifiedSetSyncResponseData()");  // LCOV_EXCL_BR_LINE 15: marco defined in ss_templates.h  // NOLINT(whitespace/line_length)

  FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-");
  return l_eStatus;
}  // End of EFrameworkunifiedStatus CSystemManager::OnSetDataResetModeRequest( HANDLE hApp )

EFrameworkunifiedStatus CSystemManager::OnSetProgUpdateStateRequest(HANDLE hApp) {
  EFrameworkunifiedStatus l_eStatus;
  SMProgUpdateState l_progUpdateState;

  FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+");
  FRAMEWORKUNIFIEDLOG(ZONE_STATE, __FUNCTION__, "from %s", FrameworkunifiedGetMsgSrc(hApp));

  SetCmdHist("SS_SM_PROG_UPDATE_STATE_SET_REQ", m_SMCmdHist, m_SMHistIter, FrameworkunifiedGetMsgSrc(hApp));

  if (eFrameworkunifiedStatusOK != (l_eStatus = ReadMsg < SMProgUpdateState > (hApp, l_progUpdateState))) {  // LCOV_EXCL_BR_LINE 4: nsfw error
    // LCOV_EXCL_START 4: nsfw error
    AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
    LOG_ERROR("ReadMsg()");  // LCOV_EXCL_BR_LINE 15: marco defined in ss_templates.h  // NOLINT(whitespace/line_length)
    // LCOV_EXCL_STOP
  } else {
    m_ProgUpdateState |= l_progUpdateState;
    if (PowerHalSetResetInfo(AGL_PROGUPDATE_STATE, m_ProgUpdateState)) {  // LCOV_EXCL_BR_LINE 11:Gcov constraints (because exception-handling routes are automatically generated)
      FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "Could not set AGL_PROGUPDATE_STATE.");
      // return Error to client of system_manager.
      l_eStatus = eFrameworkunifiedStatusFail;
    }
  }
  // Instead of sending Return Message, this function must call FrameworkunifiedSetSyncResponseData()
  // because this request is sent by FrameworkunifiedInvokeSync()
  l_eStatus = FrameworkunifiedSetSyncResponseData(hApp, &l_eStatus, sizeof(l_eStatus));
  LOG_STATUS_IF_ERRORED(l_eStatus, "FrameworkunifiedSetSyncResponseData()");  // LCOV_EXCL_BR_LINE 15: marco defined in ss_templates.h  // NOLINT(whitespace/line_length)

  FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-");
  return l_eStatus;
}  // End of EFrameworkunifiedStatus CSystemManager::OnSetProgUpdateStateRequest( HANDLE hApp )

EFrameworkunifiedStatus CSystemManager::CallStopCompleteHandler(HANDLE hApp, BOOL bIsDetectTimeout /* = FALSE */) {
  FRAMEWORKUNIFIEDLOG(ZONE_STATE, __FUNCTION__, "+");
  EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK;


  if (bIsDetectTimeout) {
    fprintf(stderr, "SS_SysManager/%s/State StopComplete(timeout)\n", __FUNCTION__);
  } else {
    fprintf(stderr, "SS_SysManager/%s/State StopComplete\n", __FUNCTION__);
  }

  l_eStatus = SecureChipOff();
  if (eFrameworkunifiedStatusOK != l_eStatus) {
    FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "Error: SecureChipOff Failed");
  }

  l_eStatus = (*m_pfStopCompleteHandler)(hApp);

  FRAMEWORKUNIFIEDLOG(ZONE_STATE, __FUNCTION__, "-");
  return l_eStatus;
}  // End of EFrameworkunifiedStatus CSystemManager::CallStopCompleteHandler( HANDLE hApp )


//*****************************************************************************
// Soft Reset Protocol functions                                              *
//                                                                            *
static char *get_line(const char *filepath) {
  char line[LINE_MAX];
  FILE *fp;

  if ((fp = fopen(filepath, "rb")) == NULL)
    return NULL;
  if (fgets(line, LINE_MAX, fp) == NULL) {  // LCOV_EXCL_BR_LINE 5:fgets error
    // LCOV_EXCL_START 5: fgets error
    AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
    fclose(fp);
    return NULL;
    // LCOV_EXCL_STOP
  }
  fclose(fp);

  return strdup(line);
}

EFrameworkunifiedStatus CSystemManager::PerformCpuReset(HANDLE hApp,
        ESMCpuResetReason f_eSmCpuResetReason, std::string f_messageStr) {
  FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+");
  EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK;
  if (FALSE == m_isRcvModeInfo) {
    // If the condition for implementing the CpuReset request is not satisfied, keep the request.
    FRAMEWORKUNIFIEDLOG(ZONE_STATE, __FUNCTION__, "Cpu Reset Pending");
    m_isRstPending = TRUE;
    m_rstPendingInfo.resetReason = f_eSmCpuResetReason;
    snprintf(m_rstPendingInfo.messageStr,
        sizeof(m_rstPendingInfo.messageStr), "%s", f_messageStr.c_str());
  } else {
    switch (f_eSmCpuResetReason) {
    case e_SS_SM_CPU_RESET_REASON_CRITICAL_ERR:
    case e_SS_SM_CPU_RESET_REASON_GENERIC_ERR:
    case e_SS_SM_CPU_RESET_REASON_DSP_ERR:
      m_isImmResetReq = TRUE;
      FRAMEWORKUNIFIEDLOG(ZONE_STATE, __FUNCTION__, " will reset immediately");
      // The break is omitted because the same process as for a normal reboot is performed.
    case e_SS_SM_CPU_RESET_REASON_USER_FORCE_RESET:
      m_pfStopCompleteHandler = (SysMgrCallback<CSystemManager, &CSystemManager::perform_force_reset>);
    case e_SS_SM_CPU_RESET_REASON_NORMAL: {
        TSystemManagerCpuResetInfo l_resetInfo;

        l_resetInfo.resetReason = f_eSmCpuResetReason;
        snprintf(l_resetInfo.messageStr, SS_SM_RESET_MSG_STR_SIZE, "%s", f_messageStr.c_str());
        l_eStatus = FrameworkunifiedSendMsg(m_hPowerServiceSession, SS_SM_CPU_RESET_REQ,
            sizeof(l_resetInfo), (PVOID) & l_resetInfo);
        LOG_STATUS(l_eStatus,  // LCOV_EXCL_BR_LINE 6: Because the condition cannot be set
            "FrameworkunifiedSendMsg(m_hPowerServiceSession, SS_SM_CPU_RESET_REQ)");
      }
      break;
    case e_SS_SM_CPU_RESET_REASON_DATA_RESET: {
        ESMDataResetType l_eSmDataResetType;

        switch (m_DataResetMode) {
        case e_SS_SM_DATA_RESET_MODE_FACTORY:
          l_eSmDataResetType = e_SS_SM_DATA_RESET_TYPE_FACTORY;
          break;
        case e_SS_SM_DATA_RESET_MODE_USER:
          l_eSmDataResetType = e_SS_SM_DATA_RESET_TYPE_USER;
          l_eStatus = FrameworkunifiedBroadcastEvent(hApp, SS_SM_EVENT_USER_DATA_RESET, NULL, 0);
          LOG_STATUS(l_eStatus, "FrameworkunifiedBroadcastEvent(SS_SM_EVENT_USER_DATA_RESET)");  // LCOV_EXCL_BR_LINE 15: marco defined in ss_templates.h  // NOLINT(whitespace/line_length)
          break;
        default:
          SS_ASERT_LOG(0, "unexpected data reset mode : %d", m_DataResetMode);  // LCOV_EXCL_BR_LINE 15: marco defined in ss_templates.h  // NOLINT(whitespace/line_length)
          l_eStatus = eFrameworkunifiedStatusInvldParam;
        break;
        }
        if (l_eStatus == eFrameworkunifiedStatusOK) {
          l_eStatus = FrameworkunifiedSendMsg(m_hPowerServiceSession,
              SS_SM_REMOTE_DATA_RESET_REQ, sizeof(l_eSmDataResetType),
              (PVOID) & l_eSmDataResetType);
          LOG_STATUS(l_eStatus, "FrameworkunifiedSendMsg(m_hPowerServiceSession, SS_SM_REMOTE_DATA_RESET_REQ)");  // LCOV_EXCL_BR_LINE 15: marco defined in ss_templates.h  // NOLINT(whitespace/line_length)
        }
      }
      break;
    case e_SS_SM_CPU_RESET_REASON_INVALID:
    default:
      SS_ASERT_LOG(0, " Error: Unknown CPU reset request type: 0x%X/%d",  // LCOV_EXCL_BR_LINE 15: marco defined in ss_templates.h  // NOLINT(whitespace/line_length)
          f_eSmCpuResetReason, f_eSmCpuResetReason);
      l_eStatus = eFrameworkunifiedStatusInvldParam;
      break;
    }
  }

  FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-");
  return l_eStatus;
}  // End of EFrameworkunifiedStatus CSystemManager::PerformCpuReset( ESMCpuResetReason f_eSmCpuResetReason )

//*****************************************************************************
// CPU Reset Protocol functions                                               *
//                                                                            *
EFrameworkunifiedStatus CSystemManager::OnCpuResetRequest(HANDLE hApp) {  // SS_SM_CPU_RESET_REQ
  FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+");
  EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusFail;
  std::string l_moduleName = FrameworkunifiedGetMsgSrc(hApp);
  INTERFACEUNIFIEDLOG_RECEIVED_FROM(hApp);  // LCOV_EXCL_BR_LINE 15: marco defined in ns_logger_if.h  // NOLINT(whitespace/line_length)
  FRAMEWORKUNIFIEDLOG(ZONE_STATE, __FUNCTION__, "from %s", l_moduleName.c_str());

  // If you implement FastSleep,
  // ShutdownTrigger of FrameworkunifiedOnStop needs to be changed to FAST_SLEEP_MODE,
  // and also MaxShutdownTime needs to be changed to CriticalAppsMaxShutdownTimeFastSleep

  try {
    TSystemManagerCpuResetInfo l_resetInfo;
    SetCmdHist("SS_SM_CPU_RESET_REQ", m_SMCmdHist, m_SMHistIter,  // LCOV_EXCL_BR_LINE 11:unexpected branch  // NOLINT(whitespace/line_length)
        FrameworkunifiedGetMsgSrc(hApp));  // LCOV_EXCL_BR_LINE 11:unexpected branch  // NOLINT(whitespace/line_length)
    if (eFrameworkunifiedStatusOK != (l_eStatus = ReadMsg < TSystemManagerCpuResetInfo > (hApp, l_resetInfo))) {
      LOG_ERROR("ReadMsg()");  // LCOV_EXCL_BR_LINE 15: marco defined in ss_templates.h  // NOLINT(whitespace/line_length)
    } else {
      char l_cBuf[100];
      EErrorEventType l_errorEventType;
      SMLoggingInfo l_loggingInfo;  // LCOV_EXCL_BR_LINE 11:unexpected branch  // NOLINT(whitespace/line_length)

      l_loggingInfo.messageStr = l_resetInfo.messageStr;
      l_loggingInfo.suffixStr = l_resetInfo.suffixStr;

      FRAMEWORKUNIFIEDLOG(ZONE_STATE, __FUNCTION__,
          " CPU Reset Reason: '%d'/'%s' from %s",
          l_resetInfo.resetReason,
          GetStr(l_resetInfo.resetReason).c_str(),
          FrameworkunifiedGetMsgSrc(hApp));

      if (e_SS_SM_CPU_RESET_REASON_IMMRESET_NORMAL == l_resetInfo.resetReason) {
        m_isImmResetReq = TRUE;
        l_resetInfo.resetReason = e_SS_SM_CPU_RESET_REASON_NORMAL;
      }
      switch (l_resetInfo.resetReason) {
      case e_SS_SM_CPU_RESET_REASON_DATA_RESET:
        switch (m_DataResetMode) {
        case e_SS_SM_DATA_RESET_MODE_FACTORY:
        case e_SS_SM_DATA_RESET_MODE_USER:
          break;
        case e_SS_SM_DATA_RESET_MODE_NONE:
        default:
          FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "unexpected data reset mode : %d", m_DataResetMode);
          throw eFrameworkunifiedStatusInvldParam;
        }
      case e_SS_SM_CPU_RESET_REASON_CRITICAL_ERR:
      case e_SS_SM_CPU_RESET_REASON_GENERIC_ERR:
      case e_SS_SM_CPU_RESET_REASON_DSP_ERR:
      case e_SS_SM_CPU_RESET_REASON_NORMAL:
        l_errorEventType = eErrorEventTypeModuleInvokedResetRequest;
        l_loggingInfo.resetReason = l_resetInfo.resetReason;
        break;
      case e_SS_SM_CPU_RESET_REASON_USER_FORCE_RESET:
        // Separate ErrorEventType only for USER_FORCE_RESET, because the logs to be saved differ.
        l_errorEventType = eErrorEventTypeUserInvokedUserForceReset;
        l_loggingInfo.resetReason = e_SS_SM_CPU_RESET_REASON_USER_FORCE_RESET;
        break;
      case e_SS_SM_CPU_RESET_REASON_INVALID:
      default:
        FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__,
            " Error: Unknown CPU reset request type: 0x%X/%d",
            l_resetInfo.resetReason, l_resetInfo.resetReason);
        throw eFrameworkunifiedStatusInvldParam;
      }

      l_eStatus = ErrorEventEnqueue(hApp, l_errorEventType, l_moduleName,
          eErrorEventResetTypeHard, l_loggingInfo);

      snprintf(l_cBuf, sizeof(l_cBuf), "ErrorEventEnqueue(%s)",
               GetStr(l_errorEventType).c_str());  // LCOV_EXCL_BR_LINE 11:unexpected branch  // NOLINT(whitespace/line_length)
      LOG_STATUS_REC_HIST_IF_ERRORED(l_eStatus, l_cBuf);  // LCOV_EXCL_BR_LINE 15: marco defined in ss_system_manager.h  // NOLINT(whitespace/line_length)
    }
  } catch (EFrameworkunifiedStatus e) {
    l_eStatus = e;
  }

  FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-");
  return l_eStatus;
}
//                                                                            *
// End of CPU Reset Protocol functions                                        *
//*****************************************************************************

VOID CSystemManager::InitiateAllGroupsShutdown(HANDLE hApp) {
  FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+");
  EFrameworkunifiedStatus l_eStatus;

  // Prioritize safe termination sequence and do not save logs during termination
  m_errorEventQueueLocked = TRUE;

  m_MaxShutdownTime = calculate_max_shutdown_time();

  l_eStatus = FrameworkunifiedNPPublishNotification(hApp, NTFY_SSSystemMgrShutdownStarted, NULL, 0);

  SetCmdHist(NTFY_SSSystemMgrShutdownStarted, m_PubCmdHist, m_PubHistIter, "");  // LCOV_EXCL_BR_LINE 11:unexpected branch  // NOLINT(whitespace/line_length)

  LOG_ERROR_REC_HIST_IF_ERRORED(l_eStatus,  // LCOV_EXCL_BR_LINE 15: marco defined in ss_system_manager.h  // NOLINT(whitespace/line_length)
      "FrameworkunifiedNPPublishNotification(" NTFY_SSSystemMgrShutdownStarted ")");

  m_GroupLaunchTimer->StopTimer(m_aTimerIDs[eSM_TIMER_START_RESP_MONITOR_WAIT_TIMER]);
  m_GroupLaunchTimer->StopTimer(m_aTimerIDs[eSM_TIMER_CLIENT_START_MONITOR]);

  // Stop Heartbeat thread activity
  l_eStatus = SendRequestToHeartBeat(hApp, SS_HEARTBEAT_STOP, NULL, 0);
  LOG_ERROR_REC_HIST_IF_ERRORED(l_eStatus, "SendRequestToHeartBeat(SS_HEARTBEAT_STOP)");  // LCOV_EXCL_BR_LINE 15: marco defined in ss_system_manager.h  // NOLINT(whitespace/line_length)

  SMSetState(hApp, SS_SM_APPS_STOPPING_AT__CWORD56__REQ);

  FRAMEWORKUNIFIEDLOG(ZONE_STATE, __FUNCTION__, "shutdownTrigger:%s, lastUserMode:%s",
      GetStr(m_shutdownTrigger).c_str(), GetStr(m_lastUserMode).c_str());

  fprintf(stderr,  // LCOV_EXCL_BR_LINE 11:unexpected branch  // NOLINT(whitespace/line_length)
      "SS_SysManager/%s/State shutdownTrigger:%s, lastUserMode:%s\n",  // LCOV_EXCL_BR_LINE 11:unexpected branch  // NOLINT(whitespace/line_length)
      __FUNCTION__, GetStr(m_shutdownTrigger).c_str(),  // LCOV_EXCL_BR_LINE 11:unexpected branch  // NOLINT(whitespace/line_length)
      GetStr(m_lastUserMode).c_str());  // LCOV_EXCL_BR_LINE 11:unexpected branch  // NOLINT(whitespace/line_length)

  /// Send SS_SM_STOP to all modules, starting with the m_ActiveGroupId group
  m_NPPStopSent = FALSE;
  check_all_groups_have_stopped(hApp);

  FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-");
  return;
}  // End of EFrameworkunifiedStatus CSystemManager::InitiateAllGroupsShutdown(HANDLE hApp)

VOID CSystemManager::SendDeferMsg(HANDLE hApp) {
  FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+");

  if (!m_dqDeferMsg.empty()) {
    EFrameworkunifiedStatus l_eStatus;
    SM_POWER_EVENT_INFO deferMsg;

    deferMsg = m_dqDeferMsg.front();
    m_dqDeferMsg.pop();

    HANDLE hSender = McOpenSender(SERVICE_SYSMANAGER);
    if (hSender == NULL) {  // LCOV_EXCL_BR_LINE 4: nsfw error
      // LCOV_EXCL_START 4: nsfw error
      AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
      FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, " Error: McOpenSender(SERVICE_SYSMANAGER)");
      // LCOV_EXCL_STOP
    } else {
      CALL_AND_LOG_STATUS_IF_ERRORED(  // LCOV_EXCL_BR_LINE 15: marco defined in ss_templates.h  // NOLINT(whitespace/line_length)
          McSend(hSender, SERVICE_POWER, deferMsg.first,
              sizeof(Pwr_ServiceSetInterface),
              (PVOID) & deferMsg.second));
      CALL_AND_LOG_STATUS_IF_ERRORED(McClose(hSender));  // LCOV_EXCL_BR_LINE 15: marco defined in ss_templates.h  // NOLINT(whitespace/line_length)
    }
  }

  FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+");
  return;
}  // End of VOID CSystemManager::SendDeferMsg(HANDLE hApp)

///////////////////////////////////////////////////////////////////////////////
/// \ingroup PublishPowerOnOffNotification
/// Power Off notification handler
///
/// \param [in]
///
/// \return EFrameworkunifiedStatus
/// Success ==> eFrameworkunifiedStatusOK
/// Failure ==> Other values
///////////////////////////////////////////////////////////////////////////////
EFrameworkunifiedStatus CSystemManager::PublishPowerOnOffNotification(HANDLE hApp) {
  EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK;
  FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+");

  l_eStatus = PerformPowerOnOffUserModePublication(hApp, NTFY_SSSystemMgrPowerOnOff);

  SetCmdHist(NTFY_SSSystemMgrPowerOnOff, m_PubCmdHist, m_PubHistIter, "");
  LOG_STATUS_REC_HIST_IF_ERRORED(l_eStatus, "PerformPowerOnOffUserModePublication()");  // LCOV_EXCL_BR_LINE 15: marco defined in ss_system_manager.h  // NOLINT(whitespace/line_length)

  FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-");
  return l_eStatus;
}

EFrameworkunifiedStatus CSystemManager::PublishUserModeNotification(HANDLE hApp) {
  FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+");
  EFrameworkunifiedStatus l_eStatus;

  l_eStatus = PerformPowerOnOffUserModePublication(hApp, NTFY_SSSystemMgrUserMode);

  SetCmdHist(NTFY_SSSystemMgrUserMode, m_PubCmdHist, m_PubHistIter, "");
  LOG_STATUS_REC_HIST_IF_ERRORED(l_eStatus, "PerformPowerOnOffUserModePublication()");  // LCOV_EXCL_BR_LINE 15: marco defined in ss_system_manager.h  // NOLINT(whitespace/line_length)

  FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-");
  return l_eStatus;
}  // End of EFrameworkunifiedStatus CSystemManager::PublishUserModeNotification(

EFrameworkunifiedStatus CSystemManager::PerformPowerOnOffUserModePublication(HANDLE hApp, const char * p_NotificationStr) {
  FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+");
  EFrameworkunifiedStatus l_eStatus;
  char l_cBuf[500] = { 0 };

  if (m_SMConfig.UMConfig.IsUserModeNotificationABOOL) {
    BOOL l_bUuserMode(m_PowerType_to_SSBoolEnumMap[m_Wake.powerupType]);

    snprintf(l_cBuf, sizeof(l_cBuf), "FrameworkunifiedNPPublishNotification(%s, %s)",
        p_NotificationStr, GetStr(l_bUuserMode).c_str());
    l_eStatus = FrameworkunifiedNPPublishNotification(hApp, p_NotificationStr,
        &l_bUuserMode, sizeof(l_bUuserMode));
  } else {
    T_SS_SM_UserModeOnOffNotification_Struct l_UserModeOnOffStruct(
        m_PowerType_to_SSBoolEnumMap[m_Wake.powerupType],
        m_StartUpReason, m_userModeChangeReason);

    snprintf(l_cBuf, sizeof(l_cBuf),
        "FrameworkunifiedNPPublishNotification(%s, %s, %s, %s)", p_NotificationStr,
        GetStr(l_UserModeOnOffStruct.isUserModeOn).c_str(),
        GetStr(m_StartUpReason).c_str(),
        GetStr(m_userModeChangeReason).c_str());
    l_eStatus = FrameworkunifiedNPPublishNotification(hApp, p_NotificationStr,
        &l_UserModeOnOffStruct, sizeof(l_UserModeOnOffStruct));
  }

  SetCmdHist(p_NotificationStr, m_PubCmdHist, m_PubHistIter, "");
  LOG_STATUS(l_eStatus, l_cBuf);  // LCOV_EXCL_BR_LINE 15: marco defined in ss_templates.h  // NOLINT(whitespace/line_length)

  FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-");
  return l_eStatus;
}  // End of EFrameworkunifiedStatus CSystemManager::PerformPowerOnOffUserModePublication(

EFrameworkunifiedStatus CSystemManager::ResetModulesStateToConnected(HANDLE hApp) {
  FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+");
  EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK;
  ModuleLaunchListIter l_moduleIter;
  for (GroupLaunchMapIter l_GroupIter = m_MapProclaunchGrps.begin();
      l_GroupIter != m_MapProclaunchGrps.end(); l_GroupIter++) {
    for (l_moduleIter = l_GroupIter->second.modules.begin();
        l_moduleIter != l_GroupIter->second.modules.end();
        l_moduleIter++) {
      if (l_moduleIter->name == FRAMEWORKUNIFIED_NS_NPSERVICE) {
        FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__, " %s ( Group %d/%s ) is %s",
            l_moduleIter->name.c_str(), l_GroupIter->second.id,
            l_GroupIter->second.name.c_str(),
            l_moduleIter->ModuleStateStr().c_str());
        l_moduleIter->SetModuleState(MODULE_STATE_STARTED);  // LCOV_EXCL_BR_LINE 15: marco defined in ns_logger_if.h  // NOLINT(whitespace/line_length)
      // End else if ( FRAMEWORKUNIFIED_NS_NPSERVICE == l_ModuleListIter->name )
      } else {
        switch (l_moduleIter->GetModuleState()) {
        case MODULE_STATE_INVALID:
        case MODULE_STATE_SKIPPED:
        case MODULE_STATE_LAUNCHING:
        case MODULE_STATE_LAUNCHED:
        case MODULE_STATE_LAUNCH_FAILED:
          FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__,
              " %s ( Group %d/%s ) is %s, NOT setting to "
              "MODULE_STATE_CONNECTED",
              l_moduleIter->name.c_str(), l_GroupIter->second.id,
              l_GroupIter->second.name.c_str(),
              l_moduleIter->ModuleStateStr().c_str());  // LCOV_EXCL_BR_LINE 15: marco defined in ns_logger_if.h  // NOLINT(whitespace/line_length)
          break;

        case MODULE_STATE_STARTED:
        case MODULE_STATE_START_SENT:
        case MODULE_STATE_CONNECTED:
        case MODULE_STATE_START_FAILED:
        case MODULE_STATE_STOP_FAILED:
        case MODULE_STATE_STOP_SENT:
        case MODULE_STATE_STOPPED:
        case MODULE_STATE_START_PRE_SENT:
        case MODULE_STATE_START_PRE_FAILED:
        case MODULE_STATE_STARTED_PRE:
        case MODULE_STATE_STOP_PRE_SENT:
        case MODULE_STATE_STOP_PRE_FAILED:
        case MODULE_STATE_STOPPED_PRE:
        case MODULE_STATE_START_BACKGROUND_SENT:
        case MODULE_STATE_START_BACKGROUND_FAILED:
        case MODULE_STATE_STARTED_BACKGROUND:
        case MODULE_STATE_STOP_BACKGROUND_SENT:
        case MODULE_STATE_STOP_BACKGROUND_FAILED:
        case MODULE_STATE_STOPPED_BACKGROUND:
          FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__, " %s ( Group %d/%s ) is %s",
              l_moduleIter->name.c_str(), l_GroupIter->second.id,
              l_GroupIter->second.name.c_str(),
              l_moduleIter->ModuleStateStr().c_str());
          l_moduleIter->SetModuleState(MODULE_STATE_CONNECTED);
          break;
          // default:  Don't code a 'default' here - let the compiler
          // issue a warning ( set via -Wall or -Wswitch ) when the set of
          // enumerations changes - then the maintainer will
          // automagically know to update this switch statement.
        }
      }
    }
  }
  FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-");
  return l_eStatus;
}  // End of EFrameworkunifiedStatus CSystemManager::ResetModulesStateToConnected(HANDLE hApp)

EFrameworkunifiedStatus CSystemManager::On_CWORD56_HeartBeatRequest(HANDLE hApp) {
  FRAMEWORKUNIFIEDLOG(ZONE_PERIODIC_FUNC, __FUNCTION__, "+");
  EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK;

  PCSTR l_senderName = FrameworkunifiedGetMsgSrc(hApp);

  SetCmdHist("SS_SM__CWORD56__HEARTBEAT_REQ", m_SMCmdHist, m_SMHistIter, l_senderName);

  FRAMEWORKUNIFIEDLOG(ZONE_PERIODIC_INFO, __FUNCTION__, " Received from %s", l_senderName);
  EPWR_HB_REQ_MSG_STRUCT l_hbReq;

  if (eFrameworkunifiedStatusOK != (l_eStatus = ReadMsg < EPWR_HB_REQ_MSG_STRUCT > (hApp, l_hbReq))) {
    LOG_ERROR("ReadMsg()");  // LCOV_EXCL_BR_LINE 15: marco defined in ss_templates.h  // NOLINT(whitespace/line_length)
  } else {

    m_GroupLaunchTimer->StopTimer(m_aTimerIDs[eSM_TIMER__CWORD56__HEARTBEAT_RESPONSE]);

    if (l_hbReq.IntervalSec > 0) {
      m_GroupLaunchTimer->StartTimer(
          m_aTimerIDs[eSM_TIMER__CWORD56__HEARTBEAT_RESPONSE], 0, 0,
          l_hbReq.IntervalSec, 0);
    } else if (l_hbReq.IntervalSec == 0) {  // LCOV_EXCL_BR_LINE 8: As the condition is never false
      l_eStatus = FrameworkunifiedSendMsg(m_hPowerServiceSession, SS_SM__CWORD56__HEARTBEAT_RSPN, 0, NULL);

      LOG_STATUS(l_eStatus, "FrameworkunifiedSendMsg(m_hPowerServiceSession, SS_SM__CWORD56__HEARTBEAT_RSPN)");  // LCOV_EXCL_BR_LINE 15: marco defined in ss_templates.h  // NOLINT(whitespace/line_length)
    }
  }
  FRAMEWORKUNIFIEDLOG(ZONE_PERIODIC_FUNC, __FUNCTION__, "-");
  return (l_eStatus);
}

EFrameworkunifiedStatus CSystemManager::On_CWORD56_HeartBeatResponseIntervalTimerExpiry(HANDLE hApp) {
  FRAMEWORKUNIFIEDLOG(ZONE_PERIODIC_FUNC, __FUNCTION__, "+");
  EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK;

  SetCmdHist("SM_TIMER__CWORD56__HEARTBEAT_RESPONSE", m_TimerCmdHist, m_TimerHistIter, FrameworkunifiedGetMsgSrc(hApp));  // LCOV_EXCL_BR_LINE 11:unexpected branch  // NOLINT(whitespace/line_length)

  l_eStatus = FrameworkunifiedSendMsg(m_hPowerServiceSession, SS_SM__CWORD56__HEARTBEAT_RSPN, 0, NULL);

  LOG_STATUS(l_eStatus, "FrameworkunifiedSendMsg(m_hPowerServiceSession, SS_SM__CWORD56__HEARTBEAT_RSPN)");  // LCOV_EXCL_BR_LINE 15: marco defined in ss_templates.h  // NOLINT(whitespace/line_length)

  FRAMEWORKUNIFIEDLOG(ZONE_PERIODIC_FUNC, __FUNCTION__, "-");
  return l_eStatus;
}

// EOF of /SS_SystemManager/src/ss_system_manager_callbacks.cpp