summaryrefslogtreecommitdiffstats
path: root/logger_service/server/src/ss_logger_error_event.cpp
blob: 6e82da7fa748367ed0158c6da58c76ddfd1ef847 (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
/*
 * @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_SS_LoggerService
/// \brief    This file supports error event logging.
///
///////////////////////////////////////////////////////////////////////////////
#include "ss_logger_error_event.h"
#include <string.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <boost/bind.hpp>
#include <unistd.h>
#include <sys/wait.h>
#include <native_service/frameworkunified_framework_if.h>
#include <system_service/ss_sm_client_if.h>
#include <system_service/ss_client_names.h>
#include <system_service/ss_logger_service_protocol.h>
#include <system_service/ss_logger_service.h>
#include <system_service/ss_services.h>
#include <system_service/ss_templates.h>
#include <stub/el_mem.h>
#include <native_service/cl_process.h>
#include <stub/Clock_API.h>
#include <string>
#include "loggerservicedebug_loggerservicelog.h"
#include "loggerservicedebug_thread_if.h"
#include "ss_logger_service_callbacks.h"
#include "ss_logger_error_event_archive.h"
#include "ss_logger_common.h"
#include "ss_logger_types.h"
#include "ss_logger_fs_directory.h"

CErrorEvent::CErrorEvent()
    : m_hApp(NULL),
      m_bIsPrevEventCompleted(true),
      m_errorEventNtfData(),
      m_pLoggerCfg(NULL),
      m_pReaderWriterControl(NULL),
      m_ServiceName(""),
      m_time(0),
      m_currentEventTriggerNumber(0),
      m_diagsessionhandle(NULL),
      m_thrdEvntLogWriter(NULL),
      m_sfd(-1) {  // LCOV_EXCL_BR_LINE 11:Unexpected branch
  FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+");
  FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-");
}  // LCOV_EXCL_BR_LINE 11:Unexpected branch

CErrorEvent::~CErrorEvent() {  // LCOV_EXCL_START 14:globle instance
  AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
  FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+");
  FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-");
}
// LCOV_EXCL_STOP

EFrameworkunifiedStatus CErrorEvent::Initialize(HANDLE f_hApp, CLoggerCfg *f_pLoggerCfg,
                                   CReaderWriterControl *f_pReaderWriterControl,
                                   HANDLE f_thrdEvntLogWriter,
                                   std::string f_strEvntLogQueWorkerName) {
  FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+");
  EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK;
  Timer *l_pTimer;

  m_sfd = CL_ProcessInit();
  if (m_sfd == -1) {  // LCOV_EXCL_BR_LINE 8:Because the process initialization is guaranteed to be successful
    AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
    FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, " Error. m_sfd CL_ProcessInit() failed \n.");  // LCOV_EXCL_LINE 8:Because the process initialization is guaranteed to be successful
  }

  SS_LoggerServerEvents l_errorEventStateEvents[] = {
      SS_LOGGER_SCREENCAPTURE_EVT };

  FrameworkunifiedProtocolCallbackHandler l_smCallbacks[] = {
  // Logging Protocol Callbacks
      { SS_SM_EVENT_ERROR_TO_SSL, boost::bind(&CErrorEvent::OnStartLogging,
                                              this, _1) }, {
          SS_SM_ERROR_EVENT_LOGGING_START_RSPN, boost::bind(
              &CErrorEvent::OnLogStartResponse, this, _1) }, {
          SS_SM_ERROR_EVENT_ARTIFACT_RSPN, boost::bind(
              &CErrorEvent::OnArtifactResponse, this, _1) } };  // LCOV_EXCL_BR_LINE 11:Unexpected branch

  FrameworkunifiedProtocolCallbackHandler l_selfCallbacks[] = {
  // Logging Protocol Callbacks
      { SS_LOGGER_ERROR_EVENT_ARTIFACT_REQ, boost::bind(
          &CErrorEvent::OnArtifactRequest, this, _1) }, {
          SS_SM_ERROR_EVENT_ARTIFACT_RSPN, boost::bind(
              &CErrorEvent::OnArtifactResponse, this, _1) } };  // LCOV_EXCL_BR_LINE 11:Unexpected branch

  FrameworkunifiedProtocolCallbackHandler l_requesterCallbacks[] = { {
      SS_LOGGER_SCREENCAPTURE_EVT_ACK, boost::bind(
          &CErrorEvent::OnObtainScreenShotResponse, this, _1) } };  // LCOV_EXCL_BR_LINE 11:Unexpected branch

  FrameworkunifiedProtocolCallbackHandler l_storageThreadCallbacks[] = { {
      eLoggerStorageThreadCmdOK, boost::bind(&CErrorEvent::OnStorageResponseOk,
                                             this, _1) }, {
      eLoggerStorageThreadCmdWriteFailed, boost::bind(
          &CErrorEvent::OnStorageResponseWriteFailed, this, _1) }, {
      eLoggerStorageThreadCmdNotFound, boost::bind(
          &CErrorEvent::OnStorageResponseNotFound, this, _1) }, {
      eLoggerStorageThreadCmdNoWritten, boost::bind(
          &CErrorEvent::OnStorageResponseNoWritten, this, _1) } };  // LCOV_EXCL_BR_LINE 11:Unexpected branch
  for (UI_32 i = 0; i < _countof(l_requesterCallbacks); i++) {
    m_requesterCallbacksVec.push_back(l_requesterCallbacks[i]);  // LCOV_EXCL_BR_LINE 11:Unexpected branch
  }

  if (NULL == f_hApp) {  // LCOV_EXCL_BR_LINE 6:As it is not always NULL
    // LCOV_EXCL_START 6:As it is not always NULL
    AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
    l_eStatus = eFrameworkunifiedStatusInvldHandle;
    FRAMEWORKUNIFIEDLOG(
        ZONE_ERR, __FUNCTION__,
        " Error. Argument f_hApp passed NULL pointer. Initialization failed.");
    // LCOV_EXCL_STOP
  } else if (NULL == (m_thrdEvntLogWriter = f_thrdEvntLogWriter)) {  // LCOV_EXCL_BR_LINE 6:As it is not always NULL
    // LCOV_EXCL_START 6:As it is not always NULL
    AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
    l_eStatus = eFrameworkunifiedStatusInvldHandle;
    FRAMEWORKUNIFIEDLOG(
        ZONE_ERR, __FUNCTION__,
        " Error. Argument f_hApp passed NULL pointer. Initialization failed.");
    // LCOV_EXCL_STOP
  } else if (eFrameworkunifiedStatusOK != (l_eStatus = m_errorEventCfg.Initialize(f_pLoggerCfg))) {  // LCOV_EXCL_BR_LINE 200:To ensure success
    // LCOV_EXCL_START 200:To ensure success
    AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
    FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__,
           " Error. m_errorEventCfg.Initialize() returned: %d.", l_eStatus);
    // LCOV_EXCL_STOP
  } else if (eFrameworkunifiedStatusOK != (l_eStatus = FrameworkunifiedAttachCallbacksToDispatcher(f_hApp, SERVICE_LOGGER, l_selfCallbacks, _countof(l_selfCallbacks)))) {  // LCOV_EXCL_BR_LINE 4:NSFW  // NOLINT[whitespace/line_length]
    // LCOV_EXCL_START 4:NSFW
    AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
    FRAMEWORKUNIFIEDLOG(
        ZONE_ERR,
        __FUNCTION__,
        " Error. FrameworkunifiedAttachCallbacksToDispatcher(SERVICE_SYSMANAGER) returned: %d.",
        l_eStatus);
    // LCOV_EXCL_STOP
  } else if (eFrameworkunifiedStatusOK != (l_eStatus = FrameworkunifiedAttachCallbacksToDispatcher(f_hApp, SERVICE_SYSMANAGER, l_smCallbacks, _countof(l_smCallbacks)))) {  // LCOV_EXCL_BR_LINE 4:NSFW  // NOLINT[whitespace/line_length]
    // LCOV_EXCL_START 4:NSFW
    AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
    FRAMEWORKUNIFIEDLOG(
        ZONE_ERR,
        __FUNCTION__,
        " Error. FrameworkunifiedAttachCallbacksToDispatcher(SERVICE_SYSMANAGER) returned: %d.",
        l_eStatus);
    // LCOV_EXCL_STOP
  } else if (eFrameworkunifiedStatusOK != (l_eStatus = FrameworkunifiedDefineStateEvents(f_hApp, &l_errorEventStateEvents, static_cast<UI_32>(_countof(l_errorEventStateEvents))))) {  // LCOV_EXCL_BR_LINE 4:NSFW  // NOLINT[whitespace/line_length]
    // LCOV_EXCL_START 4:NSFW
    AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
    FRAMEWORKUNIFIEDLOG(
        ZONE_ERR,
        __FUNCTION__,
        " Error. FrameworkunifiedDefineStateEvents(SS_LOGGER_SCREENCAPTURE_EVT) returned: %d",
        l_eStatus);
    // LCOV_EXCL_STOP
  } else if (NULL == f_pLoggerCfg) {  // LCOV_EXCL_BR_LINE 200:As it is not always NULL
    // LCOV_EXCL_START 200:As it is not always NULL
    AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
    l_eStatus = eFrameworkunifiedStatusNullPointer;
    FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, " Error. f_pLoggerCfg passed NULL pointer.");
    // LCOV_EXCL_STOP
  } else if (eFrameworkunifiedStatusOK != (l_eStatus = m_loggerPopups.Initialize(f_pLoggerCfg))) {  // LCOV_EXCL_BR_LINE 200:To ensure success  // NOLINT[whitespace/line_length]
    // LCOV_EXCL_START 200:To ensure success
    AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
    FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__,
           " Error. m_loggerPopups.Initialize(f_pLoggerCfg) returned: %d.",
           l_eStatus);
    // LCOV_EXCL_STOP
  } else if (NULL == f_pReaderWriterControl) {  // LCOV_EXCL_BR_LINE 200:As it is not always NULL
    // LCOV_EXCL_START 200:As it is not always NULL
    AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
    l_eStatus = eFrameworkunifiedStatusNullPointer;
    FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__,
           " Error. Argument f_pReaderWriterControl passed NULL pointer.");
    // LCOV_EXCL_STOP
  } else if (eFrameworkunifiedStatusOK != (l_eStatus = m_loggerStorage.Initialize(f_hApp, AppName, f_pLoggerCfg))) {  // LCOV_EXCL_BR_LINE 200:To ensure success  // NOLINT[whitespace/line_length]
    // LCOV_EXCL_START 200:To ensure success
    AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
    FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__,
           " Error. m_loggerPopups.Initialize(f_pLoggerCfg) returned: %d.",
           l_eStatus);
    // LCOV_EXCL_STOP
  } else if (eFrameworkunifiedStatusOK != (l_eStatus = FrameworkunifiedAttachCallbacksToDispatcher( f_hApp, ERROR_EVENT_STORAGE_QUEUE_NAME, l_storageThreadCallbacks, _countof(l_storageThreadCallbacks)))) {  // LCOV_EXCL_BR_LINE 4:NSFW  // NOLINT[whitespace/line_length]
    // LCOV_EXCL_START 4:NSFW
    AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
    FRAMEWORKUNIFIEDLOG(
        ZONE_ERR,
        __FUNCTION__,
        " Error. FrameworkunifiedAttachCallbacksToDispatcher(ERROR_EVENT_STORAGE_QUEUE_NAME) returned: %d.",
        l_eStatus);
    // LCOV_EXCL_STOP
  } else if (eFrameworkunifiedStatusOK != (l_eStatus = m_loggerCanEvent.Initialize(f_pLoggerCfg))) {  // LCOV_EXCL_BR_LINE 200:To ensure success  // NOLINT[whitespace/line_length]
    // LCOV_EXCL_START 200:To ensure success
    AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
    FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__,
           " Error. m_loggerCanEvent.Initialize() returned: %d.", l_eStatus);
    // LCOV_EXCL_STOP
  } else {
    m_hApp = f_hApp;
    m_pLoggerCfg = f_pLoggerCfg;
    m_pReaderWriterControl = f_pReaderWriterControl;
    l_eStatus = m_loggerUtil.Initialize(m_pLoggerCfg);  // LCOV_EXCL_BR_LINE 11:Unexpected branch
    LOG_STATUS_IF_ERRORED(l_eStatus,  // LCOV_EXCL_BR_LINE 5:macro
                          "CLoggerUtil::m_loggerUtil.Initialize(m_pLoggerCfg)");

    l_pTimer = &m_errorEventTimers[kSSL_ERROR_EVENT_TIMER_LOGGING_START_RSPN];
    l_pTimer->Initialize(
        f_hApp, SS_LOGGER_ERROR_EVENT_TIMER_ID_LOGGING_START_RSPN,
        boost::bind(&CErrorEvent::OnLogStartResponseTimeout, this, _1));  // LCOV_EXCL_BR_LINE 11:Unexpected branch

    l_pTimer = &m_errorEventTimers[kSSL_ERROR_EVENT_TIMER_ARTIFACT_RSPN];
    l_pTimer->Initialize(
        f_hApp, SS_LOGGER_ERROR_EVENT_TIMER_ID_ARTIFACT_RESPONSE,
        boost::bind(&CErrorEvent::OnArtifactResponseTimeout, this, _1));  // LCOV_EXCL_BR_LINE 11:Unexpected branch
    m_ServiceName = "";
  }

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

///////////////////////////////////////////////////////////////////////////
//  Function : RegisterSessionErrorEvent
//  brief    : Register session event. This function is called within the
//             context of the System Manager session acknowledgment handler.
///////////////////////////////////////////////////////////////////////////
EFrameworkunifiedStatus CErrorEvent::RegisterSessionErrorEvent(HANDLE f_hSession) {
  FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+");
  EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK;

  l_eStatus = FrameworkunifiedRegisterEvent(f_hSession, SS_SM_EVENT_ERROR_TO_SSL);
  LOG_STATUS_IF_ERRORED(l_eStatus, "FrameworkunifiedRegisterEvent(SS_SM_EVENT_ERROR_TO_SSL)");  // LCOV_EXCL_BR_LINE 5:macro

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

///////////////////////////////////////////////////////////////////////////
//  Function : OnOpenSession
//  brief    : Called when a requester opens a session with SS_Logger
//             service.  This function attaches error event callbacks
//             to the dispatcher with the source set to the requester.
///////////////////////////////////////////////////////////////////////////
EFrameworkunifiedStatus CErrorEvent::OnOpenSession(HANDLE f_hApp, PCSTR f_pRequesterName,
                                      HANDLE f_hSession) {
  FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+");
  EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK;

  l_eStatus = FrameworkunifiedAttachCallbacksToDispatcher(f_hApp, f_pRequesterName,
                                             &m_requesterCallbacksVec[0],
                                             static_cast<UI_32>(m_requesterCallbacksVec.size()),
                                             f_hSession);

  LOG_STATUS_IF_ERRORED(l_eStatus, "FrameworkunifiedAttachCallbacksToDispatcher(f_hSession)");  // LCOV_EXCL_BR_LINE 5:macro

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

///////////////////////////////////////////////////////////////////////////
//  Function : OnOpenSession
//  brief    : Called when a requester opens a session with SS_Logger
//             service.  This function attaches error event callbacks
//             to the dispatcher with the source set to the requester.
///////////////////////////////////////////////////////////////////////////
EFrameworkunifiedStatus CErrorEvent::OnCloseSession(HANDLE f_hApp, PCSTR f_pRequesterName,
                                       HANDLE f_hSession) {
  FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+");
  EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK;
  UI_32 l_cmdIdArr[m_requesterCallbacksVec.size()]; // NOLINT (runtime/arrays)

  for (UI_32 i = 0; i < m_requesterCallbacksVec.size(); i++) {
    l_cmdIdArr[i] = m_requesterCallbacksVec[i].iCmd;
  }

  l_eStatus = FrameworkunifiedDetachCallbacksFromDispatcher(f_hApp, f_pRequesterName,
                                               l_cmdIdArr,
                                               static_cast<UI_32>(m_requesterCallbacksVec.size()),
                                               f_hSession);

  LOG_STATUS_IF_ERRORED(l_eStatus, "FrameworkunifiedAttachCallbacksToDispatcher()");  // LCOV_EXCL_BR_LINE 5:macro

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

///////////////////////////////////////////////////////////////////////////
//  Function : OnStartLogging
//  brief    : Called by SS_Logger and external services to begin logging
//             artifact collection. This function sends a logging request
//             to System Manager. See SS_SM_EVENT_ERROR_TO_SSL.
///////////////////////////////////////////////////////////////////////////
EFrameworkunifiedStatus CErrorEvent::OnStartLogging(HANDLE f_hApp) {
  FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+");
  EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK;
  SMErrorEventNtfData l_eventErrorNtfData;

  INTERFACEUNIFIEDLOG_RECEIVED_FROM(f_hApp);  // LCOV_EXCL_BR_LINE 5:macro

  if (eFrameworkunifiedStatusOK != (l_eStatus = ReadMsg<SMErrorEventNtfData>(f_hApp, l_eventErrorNtfData))) {  // LCOV_EXCL_BR_LINE 200:To ensure success  // NOLINT[whitespace/line_length]
    // when failed to ReadMsg, we can't know event-type for action, so nothing is able to do.
    AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
    LOG_ERROR("ReadMsg()");  // LCOV_EXCL_LINE 200:To ensure success
  } else {
    if (TRUE == this->m_pLoggerCfg->IsLoggingEnabled()) {  // LCOV_EXCL_BR_LINE 200:As it is always TRUE
      if (TRUE == m_bIsPrevEventCompleted) {
        TLoggerErrorEvent l_eventData = l_eventErrorNtfData;

        if (IsNeedVerify(l_eventData.EventType)) {
          // if need output log to external storage, check whether device is authenticated or not.
          VerifyExtStorage(l_eventData);
        }

        uint8_t status;
        Clock_getSystemTimeY2K38(&m_time, &status);
        m_currentEventTriggerNumber = m_pLoggerCfg->GetUserInvokedCounter();
        l_eStatus = m_loggerUtil.checkDestinationAvailable(l_eventData);
        if (eFrameworkunifiedStatusOK == l_eStatus) {
          m_bIsPrevEventCompleted = false; /* See timer start / timeout handler below.             */

          m_artifactResponseVec.clear();

          m_errorEventNtfData = l_eventErrorNtfData; /* Overwrite m_eventErrorNtfData when logging complete. */
          m_errorEventNtfData.EventBitMask = m_errorEventCfg
              .GetEventsForErrorEvent(l_eventErrorNtfData.EventType);
          l_eStatus = SendLogStartRequestToSystemManager(
              m_errorEventNtfData.EventType);
          LOG_STATUS_IF_ERRORED(l_eStatus,
                                "SendLogStartRequestToSystemManager()");
          l_eStatus = m_loggerCanEvent.PublishStartEvent(f_hApp,
                                                         m_errorEventNtfData);
          LOG_STATUS_IF_ERRORED(
              l_eStatus,
              "m_loggerCanEvent.PublishStartEvent(f_hApp,m_errorEventNtfData);");

          bool result =
              m_errorEventTimers[kSSL_ERROR_EVENT_TIMER_LOGGING_START_RSPN]
                  .Start(m_loggingStartRspnToSec, 0, 0, 0);
          if (FALSE == result) {  // LCOV_EXCL_BR_LINE 200:As it is always TRUE
            // LCOV_EXCL_START 200:As it is always TRUE
            AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
            FRAMEWORKUNIFIEDLOG(
                ZONE_ERR,
                __FUNCTION__,
                " Error. Failed to start timer kSSL_ERROR_EVENT_TIMER_LOGGING_START_RSPN.");
            // LCOV_EXCL_STOP
          }
        } else {
          FRAMEWORKUNIFIEDLOG(ZONE_WARN, __FUNCTION__,
                 " Warning. Destination not available. ");
          m_errorEventNtfData = l_eventErrorNtfData; /* Overwrite m_eventErrorNtfData when logging complete. */
          m_errorEventNtfData.EventBitMask = m_errorEventCfg
              .GetEventsForErrorEvent(l_eventErrorNtfData.EventType);
          l_eStatus = OnStorageResponseNotFound(f_hApp);
          LOG_STATUS_IF_ERRORED(l_eStatus, "OnStorageResponseNotFound(f_hApp)");
        }
      } else {
        // Not-Need Resp to SM, because of keep logging sequance.
        FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__,
               " Error. Logging already in progress. Event dropped.");
      }
    } else {
      // LCOV_EXCL_START 200:As it is always TRUE
      AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
      if (l_eventErrorNtfData.isNeedReboot == TRUE) {
        FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__,
               "System will reboot soon, so stop logging function.");
        StopLoggingFunction(f_hApp);
      }
      FRAMEWORKUNIFIEDLOG(
          ZONE_INFO,
          __FUNCTION__,
          "Logging is disabled! Dropping Event. Sending Complete to SS_SystemManager");
      l_eStatus = SendLogCompleteRequestToSystemManager(eFrameworkunifiedStatusFail);
      LOG_STATUS_IF_ERRORED(l_eStatus,
                            "SendLogCompleteRequestToSystemManager()");
      // LCOV_EXCL_STOP
    }
  }

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

///////////////////////////////////////////////////////////////////////////
//  Function : OnLogStartResponse
//  brief    : Called by System Manager after the acknowledgment of the
//             logging session start request.  This function starts the
//             artifact collection process. See
//             SS_SM_ERROR_EVENT_LOGGING_START_RSPN.
///////////////////////////////////////////////////////////////////////////
EFrameworkunifiedStatus CErrorEvent::OnLogStartResponse(HANDLE f_hApp) {
  FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+");
  EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK;
  m_errorEventTimers[kSSL_ERROR_EVENT_TIMER_LOGGING_START_RSPN].Stop();
  m_errorEventCfg.GetArtifactRequestVec(m_errorEventNtfData.EventType,
                                        m_artifactRequestVec);

  l_eStatus = RequestNextArtifact(f_hApp);
  LOG_STATUS_IF_ERRORED(l_eStatus, "RequestNextArtifact()");

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

///////////////////////////////////////////////////////////////////////////
//  Function : OnLogStartResponseTimeout
//  brief    : Called when / if SM fails to respond to a logging start
//             request and the logging star response timer expires.
///////////////////////////////////////////////////////////////////////////
EFrameworkunifiedStatus CErrorEvent::OnLogStartResponseTimeout(HANDLE f_hApp) {
  FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+");
  EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK;

  FRAMEWORKUNIFIEDLOG(
      ZONE_ERR,
      __FUNCTION__,
      " Error. SM failed to respond to a logging start request in the required amount of time.");

  m_bIsPrevEventCompleted = TRUE;

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

///////////////////////////////////////////////////////////////////////////
//  Function : RequestNextArtifact
//  brief    : This function requests the next artifact from the service
//             that owns the artifact.  If no artifacts remain, this
//             function performs initiates artifact post processing.
///////////////////////////////////////////////////////////////////////////
EFrameworkunifiedStatus CErrorEvent::RequestNextArtifact(HANDLE f_hApp) {
  FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+");
  EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK;
  UI_32 l_timeoutSec;
  UI_32 l_timeoutMs;

  if (0 != m_artifactRequestVec.size()) {
    TLoggingArtifact &l_nextArtifact = m_artifactRequestVec.back();
    l_eStatus = m_loggerPopups.ShowStartPopup(
        f_hApp, m_errorEventNtfData, &m_artifactRequestVec,
        m_loggerUtil.getDestination(m_errorEventNtfData));

    LOG_STATUS_IF_ERRORED(
        l_eStatus,
        "m_loggerPopups.ShowStartPopup(f_hApp,m_errorEventNtfData,&m_artifactRequestVec )");

    TEXT(__FUNCTION__,
         "Requesting next artifact ID:%d from:%s, with timeout:%d ms.",
         l_nextArtifact.ArtifactId,
         l_nextArtifact.Information.OwnerServiceName.c_str(),
         l_nextArtifact.Information.RequestTimeoutMs);

    l_timeoutSec = l_nextArtifact.Information.RequestTimeoutMs / 1000;
    l_timeoutMs = l_nextArtifact.Information.RequestTimeoutMs % 1000;
    bool result =
        m_errorEventTimers[kSSL_ERROR_EVENT_TIMER_ARTIFACT_RSPN].Start(
            l_timeoutSec, l_timeoutMs, 0, 0);
    if (FALSE == result) {  // LCOV_EXCL_BR_LINE 200:As it is always TRUE
      // LCOV_EXCL_START 200:As it is always TRUE
      AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
      FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__,
             "Failed to start timer kSSL_ERROR_EVENT_TIMER_ARTIFACT_RSPN.");
      // LCOV_EXCL_STOP
    }
    switch (l_nextArtifact.Information.Cb.Type) {
      case eCbTypePath: {
        l_eStatus = CheckPathForArtifact(f_hApp, l_nextArtifact);
      }
        break;

      case eCbTypeFunction: {
        if (l_nextArtifact.Information.Cb.Function == NULL) {  // LCOV_EXCL_BR_LINE 200:As it is not always NULL
          AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
          l_eStatus = eFrameworkunifiedStatusNullPointer;  // LCOV_EXCL_LINE 200:As it is not always NULL
        } else {
          l_eStatus = l_nextArtifact.Information.Cb.Function(f_hApp,
                                                             l_nextArtifact);
          LOG_STATUS_IF_ERRORED(
              l_eStatus,
              "l_nextArtifact.Information.Cb.Function(f_hApp, l_nextArtifact)");
        }
      }
        break;

      case eCbTypeInvalid:
      default:
      {
        FRAMEWORKUNIFIEDLOG(
            ZONE_ERR,
            __FUNCTION__,
            " Error. Unknown artifact or artifact owner for artifact ID:"
            " %d. Invalid logging artifact configuration likely.",
            l_nextArtifact.ArtifactId);
      }
        break;
    }
  } else {
    if ((m_errorEventNtfData.EventType == eErrorEventTypeUserInvokedClearLogs)
        || (m_errorEventNtfData.EventType
            == eErrorEventTypeUserInvokedCollectNaviLog)) {
      l_eStatus = this->OnStorageResponseOk(f_hApp);
      return (l_eStatus);
    }
    uint8_t status;
    Clock_getSystemTimeY2K38(&m_time, &status);
    FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__,
           " Info. All logging error event artifacts have been collected.");
    l_eStatus = m_loggerUtil.checkDestinationAvailable(m_errorEventNtfData);
    LOG_STATUS_IF_ERRORED(
        l_eStatus,
        "m_loggerUtil.checkDestinationAvailable(m_errorEventNtfData)");
    if (eFrameworkunifiedStatusOK == l_eStatus) {
      /* Check one last time after all logs have been collected   */
      /* if we should show popup for archiving and writing to USB */
      l_eStatus = m_loggerPopups.ShowStartPopup(
          f_hApp, m_errorEventNtfData, &m_artifactRequestVec,
          m_loggerUtil.getDestination(m_errorEventNtfData));
      LOG_STATUS_IF_ERRORED(
          l_eStatus,
          "m_loggerPopups.ShowStartPopup(f_hApp,m_errorEventNtfData,&m_artifactRequestVec )");

      l_eStatus = m_loggerUtil.getFilePathAndName(f_hApp, m_errorEventNtfData,
                                                  m_time, m_archiveDestination);
      LOG_STATUS_IF_ERRORED(
          l_eStatus,
          "m_loggerUtil.getFilePathAndName()");

      std::string destination_path = m_loggerUtil.getDestination(
          m_errorEventNtfData);
      if (destination_path.compare(m_pLoggerCfg->m_emmcOutputPath) == 0) {
        if (eFrameworkunifiedStatusOK
            != m_loggerUtil.deleteOldEmmcLog(m_archiveDestination,
                                             m_errorEventNtfData.EventType)) {
          FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__,
                 " Error. m_loggerUtil.deleteOldEmmcLog()");
        }
      }

      l_eStatus = this->m_loggerStorage.Start(m_archiveDestination,
                                              this->m_artifactResponseVec,
                                              m_time);
      LOG_STATUS_IF_ERRORED(
          l_eStatus,
          "m_loggerStorage.Start()");
      if (l_eStatus != eFrameworkunifiedStatusOK) {
        l_eStatus = this->OnStorageResponseWriteFailed(f_hApp);
        LOG_STATUS_IF_ERRORED(l_eStatus,
                              "this->OnStorageResponseWriteFailed(f_hApp)");
      }
    } else {
      l_eStatus = this->OnStorageResponseNotFound(f_hApp);
      LOG_STATUS_IF_ERRORED(
          l_eStatus,
          "this->OnStorageResponseNotFound(f_hApp)");
    }
  }

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

///////////////////////////////////////////////////////////////////////////
//  Function : OnArtifactResponse
//  brief    : This function is called when an artifact has been made ready
//             by the owning service.
///////////////////////////////////////////////////////////////////////////
EFrameworkunifiedStatus CErrorEvent::OnArtifactResponse(HANDLE f_hApp) {
  FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+");
  EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK;
  ARTIFACT_RESPONSE l_artifactResponse;

  if (eFrameworkunifiedStatusOK != (l_eStatus = ReadMsg<ARTIFACT_RESPONSE>(f_hApp, l_artifactResponse))) {  // LCOV_EXCL_BR_LINE 200:To ensure success  // NOLINT[whitespace/line_length]
    AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
    LOG_ERROR("ReadMsg()");  // LCOV_EXCL_LINE 200:To ensure success
  } else {
    m_errorEventTimers[kSSL_ERROR_EVENT_TIMER_ARTIFACT_RSPN].Stop();

    // Prevent processing of artifacts that arrive after the error event logging session has completed.
    if (m_artifactRequestVec.size() > 0) {
      TEXT(__FUNCTION__, "Artifact ID:%d received.",
           l_artifactResponse.ArtifactId);

      TLoggingArtifact &l_artifactCurr = m_artifactRequestVec.back();
      if (l_artifactCurr.ArtifactId != l_artifactResponse.ArtifactId) {
        TEXT(
            __FUNCTION__,
            "Failure collecting current artifact. Expected artifact ID:%d, received artifact ID:%d."
            " Ignoring received artifact.",
            l_artifactCurr.ArtifactId, l_artifactResponse.ArtifactId);
      } else {
        TLoggingArtifactResponse l_response;
        l_response.ArtifactId = l_artifactResponse.ArtifactId;
        l_response.Filepath = l_artifactResponse.FilePathAndName;
        l_response.Remove = l_artifactCurr.Information.Remove;
        m_artifactResponseVec.push_back(l_response);
        m_artifactRequestVec.pop_back();  // Remove received artifact from request vector.
        l_eStatus = RequestNextArtifact(f_hApp);
        LOG_STATUS_IF_ERRORED(l_eStatus, "RequestNextArtifact()");
      }
    } else {
      FRAMEWORKUNIFIEDLOG(
          ZONE_ERR,
          __FUNCTION__,
          " Error. Received spurious artifact ID: %d. No error event logging session active.",
          l_artifactResponse.ArtifactId);  // LCOV_EXCL_BR_LINE 5:macro
    }
  }

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

///////////////////////////////////////////////////////////////////////////
//  Function : OnArtifactResponseTimeout
//  brief    : This function is called when a requested artifact response
//             fails to arrive in the required amount of time.
///////////////////////////////////////////////////////////////////////////
EFrameworkunifiedStatus CErrorEvent::OnArtifactResponseTimeout(HANDLE f_hApp) {
  FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+");
  EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK;

  if (m_artifactRequestVec.size() > 0) {  // LCOV_EXCL_BR_LINE 200:As it cannot always be 0
    TLoggingArtifact &l_artifactCurr = m_artifactRequestVec.back();

    FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__,
           " Error. Artifact response timer expired for artifact ID: %d.",
           l_artifactCurr.ArtifactId);

    // Remove artifact from request vector.
    m_artifactRequestVec.pop_back();

    RequestNextArtifact(f_hApp);
  }

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

///////////////////////////////////////////////////////////////////////////
//  Function : OnArtifactRequest
//  brief    : This function services an artifact request generated by
//             the error event sub system.  The requested artifact will
//             be one of the artifacts owned by SSL.
///////////////////////////////////////////////////////////////////////////
EFrameworkunifiedStatus CErrorEvent::OnArtifactRequest(HANDLE f_hApp) {
  FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+");
  EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK;
  EArtifactId l_requestedArtifactId;

  if (eFrameworkunifiedStatusOK
      != (l_eStatus = ReadMsg<EArtifactId>(f_hApp, l_requestedArtifactId))) {
    LOG_ERROR("ReadMsg()");
  } else {
    switch (l_requestedArtifactId) {
      case eArtifactIdInterfaceunifiedDebugLog:
        l_eStatus = OnObtainLoggerserviceLogRequest(f_hApp);
        LOG_STATUS_IF_ERRORED(l_eStatus, "OnObtainLoggerserviceLogRequest()");
        break;

      case eArtifactIdTransmitLog:
        l_eStatus = OnObtainTransmitLogRequest(f_hApp);
        LOG_STATUS_IF_ERRORED(l_eStatus, "OnObtainTransmitLogRequest()");
        break;

      case eArtifactIdPerformanceLog:
        l_eStatus = OnObtainPerformanceLogRequest(f_hApp);
        LOG_STATUS_IF_ERRORED(l_eStatus, "OnObtainPerformanceLogRequest()");
        break;

      case eArtifactIdScreenShot:
        l_eStatus = OnObtainScreenShotRequest(f_hApp);
        LOG_STATUS_IF_ERRORED(l_eStatus, "OnObtainScreenShotRequest()");
        break;

      case eArtifactIdKernelLog:
        l_eStatus = OnObtainKernelLogInfoRequest(f_hApp);
        LOG_STATUS_IF_ERRORED(l_eStatus, "OnObtainKernelLogInfoRequest()");
        break;

      case eArtifactIdDRInitialLog:
        l_eStatus = OnObtainDRInitialLogRequest(f_hApp);
        LOG_STATUS_IF_ERRORED(l_eStatus, "OnObtainDRInitialLogRequest()");
        break;

      case eArtifactIdDRLocationLog:
        l_eStatus = OnObtainDRLocationLogRequest(f_hApp);
        LOG_STATUS_IF_ERRORED(l_eStatus, "OnObtainDRLocationLogRequest()");
        break;

      case eArtifactIdClearAllLog:
        l_eStatus = OnClearAllLogRequest(f_hApp);
        LOG_STATUS_IF_ERRORED(l_eStatus, "OnClearAllLogRequest()");
        break;

      case eArtifactIdNaviLog:
        l_eStatus = OnNaviLogRequest(f_hApp);
        LOG_STATUS_IF_ERRORED(l_eStatus, "OnNaviLogRequest()");
        break;

      default:
        FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__,
               " Error. Unsupported logging artifact requested: %d.",
               l_requestedArtifactId);
        break;
    }
  }

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

///////////////////////////////////////////////////////////////////////////
//  Function : OnStorageResponseOk
//  brief    : This function services response from the storage thread. It
//             is called when the logs have been stored successfully.
///////////////////////////////////////////////////////////////////////////
EFrameworkunifiedStatus CErrorEvent::OnStorageResponseOk(HANDLE f_hApp) {
  FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+");
  EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK;

  l_eStatus = this->m_loggerPopups.ShowEndPopup(f_hApp, m_errorEventNtfData,
                                                m_archiveDestination);
  LOG_STATUS_IF_ERRORED(
      l_eStatus,
      "this->m_loggerPopups.ShowEndPopup(f_hApp,m_errorEventNtfData,m_archiveDestination)");

  if (m_errorEventNtfData.EventType == eErrorEventTypeDiagEvent) {
    l_eStatus = sendDiagEventResponse();
    LOG_STATUS_IF_ERRORED(l_eStatus, "sendDiagEventResponse()");
  }
  if (m_errorEventNtfData.isNeedReboot == TRUE) {
    FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__,
           "System will reboot soon, so stop logging function.");
    StopLoggingFunction(f_hApp);
  }
  m_bIsPrevEventCompleted = true;
  l_eStatus = SendLogCompleteRequestToSystemManager(eFrameworkunifiedStatusOK);

  l_eStatus = m_loggerCanEvent.PublishEndEvent(f_hApp, m_errorEventNtfData,
                                               m_currentEventTriggerNumber,
                                               m_time);
  LOG_STATUS_IF_ERRORED(l_eStatus, "m_loggerCanEvent.PublishEndEvent();");
  LOG_STATUS_IF_ERRORED(l_eStatus, "SendLogCompleteRequestToSystemManager()");
  FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-");
  return (l_eStatus);
}

///////////////////////////////////////////////////////////////////////////
//  Function : OnStorageResponseWriteFailed
//  brief    : This function services response from the storage thread. It
//             is called when the logs failed to be written to the target
//             destination.
///////////////////////////////////////////////////////////////////////////
EFrameworkunifiedStatus CErrorEvent::OnStorageResponseWriteFailed(HANDLE f_hApp) {
  FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+");
  EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK;
  l_eStatus = m_loggerPopups.ShowErrorPopup(f_hApp, m_errorEventNtfData,
                                            (UI_16) eWriteToDeviceFailed);
  LOG_STATUS_IF_ERRORED(
      l_eStatus, "m_loggerPopups.ShowErrorPopup(f_hApp, eWriteToDeviceFailed)");

  if (m_errorEventNtfData.EventType == eErrorEventTypeDiagEvent) {
    sendDiagEventErrorResponse(eDEVICE_WRITE_ERROR);
  }
  if (m_errorEventNtfData.isNeedReboot == TRUE) {
    FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__,
           "System will reboot soon, so stop logging function.");
    StopLoggingFunction(f_hApp);
  }
  m_bIsPrevEventCompleted = true;
  l_eStatus = SendLogCompleteRequestToSystemManager(eFrameworkunifiedStatusFail);

  l_eStatus = m_loggerCanEvent.PublishErrorEvent(f_hApp, m_errorEventNtfData,
  TRUE,
                                                 m_currentEventTriggerNumber,
                                                 m_time);
  LOG_STATUS_IF_ERRORED(l_eStatus, "m_loggerCanEvent.PublishErrorEvent();");

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

///////////////////////////////////////////////////////////////////////////
//  Function : OnStorageResponseNotFound
//  brief    : This function services response from the storage thread. It
//             is called when the logs failed to be written to the target
//             destination because the target was not found
///////////////////////////////////////////////////////////////////////////
EFrameworkunifiedStatus CErrorEvent::OnStorageResponseNotFound(HANDLE f_hApp) {
  FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+");
  EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK;
  l_eStatus = m_loggerPopups.ShowErrorPopup(f_hApp, m_errorEventNtfData,
                                            (UI_16) eSelectedDeviceNotFound);
  LOG_STATUS_IF_ERRORED(
      l_eStatus,
      "m_loggerPopups.ShowErrorPopup(f_hApp, eSelectedDeviceNotFound)");

  if (m_errorEventNtfData.EventType == eErrorEventTypeDiagEvent) {
    l_eStatus = sendDiagEventErrorResponse(eDEVICE_NOT_AVAILABLE);
    LOG_STATUS_IF_ERRORED(l_eStatus, "sendDiagEventErrorResponse(eDEVICE_NOT_AVAILABLE)");
  }
  if (m_errorEventNtfData.isNeedReboot == TRUE) {
    FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__,
           "System will reboot soon, so stop logging function.");
    StopLoggingFunction(f_hApp);
  }
  m_bIsPrevEventCompleted = true;
  l_eStatus = SendLogCompleteRequestToSystemManager(eFrameworkunifiedStatusFail);

  l_eStatus = m_loggerCanEvent.PublishErrorEvent(f_hApp, m_errorEventNtfData,
  TRUE,
                                                 m_currentEventTriggerNumber,
                                                 m_time);
  LOG_STATUS_IF_ERRORED(l_eStatus, "m_loggerCanEvent.PublishErrorEvent();");

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

///////////////////////////////////////////////////////////////////////////
//  Function : OnStorageResponseNoWritten
//  brief    : This function services response from the storage thread. It
//             is called when no logs where found.
///////////////////////////////////////////////////////////////////////////
EFrameworkunifiedStatus CErrorEvent::OnStorageResponseNoWritten(HANDLE f_hApp) {
  FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+");
  EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK;

  l_eStatus = m_loggerPopups.ShowErrorPopup(f_hApp, m_errorEventNtfData,
                                            (UI_16) eNoLogToStore);
  LOG_STATUS_IF_ERRORED(l_eStatus,
                        "m_loggerPopups.ShowErrorPopup(f_hApp, eNoLogToStore)");

  if (m_errorEventNtfData.EventType == eErrorEventTypeDiagEvent) {
    l_eStatus = sendDiagEventErrorResponse(eNO_ERROR_INFO);
    LOG_STATUS_IF_ERRORED(l_eStatus, "sendDiagEventErrorResponse(eNO_ERROR_INFO)");
  }
  if (m_errorEventNtfData.isNeedReboot == TRUE) {
    FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__,
           "System will reboot soon, so stop logging function.");
    StopLoggingFunction(f_hApp);
  }
  m_bIsPrevEventCompleted = true;
  l_eStatus = SendLogCompleteRequestToSystemManager(eFrameworkunifiedStatusOK);

  l_eStatus = m_loggerCanEvent.PublishErrorEvent(f_hApp, m_errorEventNtfData,
  TRUE,
                                                 m_currentEventTriggerNumber,
                                                 m_time);
  LOG_STATUS_IF_ERRORED(l_eStatus, "m_loggerCanEvent.PublishErrorEvent();");

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

EFrameworkunifiedStatus CErrorEvent::sendDiagEventErrorResponse(EELL_ErrorCode f_errCode) {
  FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+");
  EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK;
  if (this->m_ServiceName.length() > 0) {
    l_eStatus = sendDiagEventErrorResponse(f_errCode, this->m_ServiceName);
    this->m_ServiceName = "";
  }

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

EFrameworkunifiedStatus CErrorEvent::sendDiagEventErrorResponse(EELL_ErrorCode f_errCode,
                                                   std::string f_destName) {
  FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+");
  EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK;

  if (eFrameworkunifiedStatusOK != (l_eStatus = FrameworkunifiedSendMsg(m_diagsessionhandle, SS_LOGGERCOPYEMERGENCYLOGS_ERROR_RESP, sizeof(EELL_ErrorCode), &f_errCode))) {  // LCOV_EXCL_BR_LINE 4: NSFW error case.  // NOLINT[whitespace/line_length]
    // LCOV_EXCL_START 4: NSFW error case.
    AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
    FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__,
           "SS_LOGGERCOPYEMERGENCYLOGS_ERROR_RESP Msg send failed = %x",
           l_eStatus);
    // LCOV_EXCL_STOP
  }

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

EFrameworkunifiedStatus CErrorEvent::sendDiagEventResponse(void) {
  FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+");
  EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK;

  if (eFrameworkunifiedStatusOK != (l_eStatus = FrameworkunifiedSendMsg(m_diagsessionhandle, SS_LOGGERCOPYEMERGENCYLOGS_SUCCESS_RESP, 0, NULL))) {
    FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__,
           "SS_LOGGERCOPYEMERGENCYLOGS_SUCCESS_RESP Msg send failed = %x",
           l_eStatus);
  }

  m_ServiceName = "";

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

EFrameworkunifiedStatus CErrorEvent::SetDiagEventSourceName(std::string f_serviceName) {
  FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+");
  EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusFail;
  if ((f_serviceName.length() > 0)
      && (this->m_ServiceName.length() == 0)) {
    this->m_ServiceName = f_serviceName;
    l_eStatus = eFrameworkunifiedStatusOK;
  } else {
    FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__,
           " Error. f_serviceName(%s), m_serviceName(%s)",
           f_serviceName.c_str(), m_ServiceName.c_str());
  }

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

void CErrorEvent::SetDiagSessionHandle(HANDLE f_sessionhandle) {
  FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+");

  m_diagsessionhandle = f_sessionhandle;

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

void CErrorEvent::SetMileage(UI_32 f_mileage) {
  FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+");
  this->m_loggerUtil.SetMilage(f_mileage);
  FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-");
}

// LCOV_EXCL_START 200: 
EFrameworkunifiedStatus CErrorEvent::SaveNaviLog(EPWR_SHUTDOWN_TRIGGER_TYPE errType) {
  AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
  FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+");
  EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK;
  UI_32 l_logMaxNum = 0;
  std::string l_Filename = "";

  uint32_t l_time;
  uint8_t status;
  Clock_getSystemTimeY2K38(&l_time, &status);
  l_eStatus = m_loggerUtil.getEmmcNaviLogParams(l_time, errType, l_Filename,
                                                l_logMaxNum);

  if (eFrameworkunifiedStatusOK != l_eStatus) {
    FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__,
           " Error: getEmmcNaviLogParams NaviLog update failed %d", l_eStatus);
  } else {
    if (l_logMaxNum == 0) {
      /*OutputNaviLogNmlMax or OutputNaviLogErrMax = 0. */
      FRAMEWORKUNIFIEDLOG(
          ZONE_WARN,
          __FUNCTION__,
          " Warning: Not update NaviLog. OutputNaviLogNmlMax or OutputNaviLogErrMax = 0");
    } else {
      FILE *fp;
      void *p;
      p = EL_mem_exram_mmap_simple(EL_MEM_ID_NAVI_LOG, PROT_READ | PROT_WRITE,
      MAP_SHARED,
                                   EL_MEM_CACHE_INVALID);
      if (p == MAP_FAILED) {
        FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__,
               "Error : EL_mem_exram_mmap_simple MAP_FAILD");
        l_eStatus = eFrameworkunifiedStatusFail;
      } else {
        fp = fopen(l_Filename.c_str(), "wb");
        if (fp == NULL) {
          FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "Could not open file %s",
                 l_Filename.c_str());
          l_eStatus = eFrameworkunifiedStatusAccessError;
        } else {
          fwrite(p, sizeof(unsigned char), EL_mem_getLength(EL_MEM_ID_NAVI_LOG),
                 fp);
          fclose(fp);
        }
        if (0 != EL_mem_exram_munmap(p, EL_mem_getLength(EL_MEM_ID_NAVI_LOG))) {
          FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "Error : EL_mem_exram_munmap");
        }
      }
    }
  }

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

EFrameworkunifiedStatus CErrorEvent::VerifyExtStorage(TLoggerErrorEvent event) {
  FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+");
  EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusFail;
  std::string f_path;

  f_path = m_pLoggerCfg->getUsb0MountPath();

  if (eFrameworkunifiedStatusOK == l_eStatus) {
    l_eStatus = eFrameworkunifiedStatusFail;

    if (eFrameworkunifiedStatusFail == l_eStatus) {
      // timeout or error
      FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "Error : get secure log failed or timeout");
    }
  } else {
    // timeout
    FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "Error : ticket verify timeout.");
  }

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

bool CErrorEvent::IsNeedVerify(EErrorEventType type) {
  bool ret = false;
  switch (type) {
    case eErrorEventTypeUserInvokedCollectScreenShot:
    case eErrorEventTypeUserInvokedCollectAllLogs:
    case eErrorEventTypeUserInvokedCollectInterfaceunifiedLogs:
    case eErrorEventTypeInterfaceunifiedEmmcLogs:
    case eErrorEventTypeEelExport:
    case eErrorEventTypeDiagEvent:
    case eErrorEventTypeCanEvent:
      ret = true;
      break;
    default:
      break;
  }
  return ret;
}