Add gitlab issue/merge request templates
[staging/basesystem.git] / service / system / logger_service / server / src / loggerservicedebug_writer_Evntworker.cpp
1 /*
2  * @copyright Copyright (c) 2016-2020 TOYOTA MOTOR CORPORATION.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 ///////////////////////////////////////////////////////////////////////////////
18 /// \ingroup  tag_NS_LogTraceSender
19 /// \brief    frameworkunifieddebug writer thread class, handles writing a log file
20 ///           all really done by my_writer class.
21 ///
22 ///////////////////////////////////////////////////////////////////////////////
23 // System Headers
24 #include "loggerservicedebug_writer_Evntworker.h"
25 #include <string.h>
26 #include <unistd.h>
27 #include <fcntl.h>
28 #include <time.h>
29 #include <sys/timeb.h>
30 #include <boost/bind.hpp>
31 #include <errno.h>
32 #include <native_service/ns_np_service_protocol.h>
33 #include <native_service/frameworkunified_application.h>
34 #include <native_service/frameworkunified_framework_types.h>
35 #include <native_service/frameworkunified_timer.h>
36 #include <loggerservicedebug_thread_if.h>
37 #include <loggerservicedebug_loggerservicelog.h>
38 #include <system_service/ss_logger_service_notifications.h>
39 #include <system_service/ss_devicedetection_service_ifc.h>
40 #include <system_service/ss_logger_service_protocol.h>
41 #include <system_service/ss_logger_service.h>
42 #include <system_service/ss_templates.h>
43 #include <stub/Clock_API.h>
44 #include <new>
45 #include <utility>
46 #include <string>
47
48 /// Macros definition for the constants
49 #define SIZE_0 (size_t)0
50 #define SIZE_1 (size_t)1
51 #define COUNTER_SIZE 6            ///< Counter ID 2 bytes and Counter Value is 4 bytes
52 #define SINGLE_EVENT_INFO_SIZE 10    ///< Event log size
53 #define INITIAL_CNT_VALUE 0x00000001  ///< Init count value for counter logging
54 #define MAX_CNT_VALUE 0xFFFFFFFF    ///< Max count calue for counter logging
55 #define MAX_USB_DEVICE 2    ///< Max USB devices
56
57 // Temp path for event logs that used for copying to USB
58 const CHAR TMP_DEBUG_EVNTLOG_PATH_FN[] = "/tmp/loggerservice_Evntdebug.dat";
59
60 // Structure to hold the USB device information
61 TThrdEvtLogStore gSUSBDevInfo[MAX_USB_DEVICE] = { };
62
63 // Structure to hold the SD card device information
64 TThrdEvtLogStore gSSDCardevInfo = { };
65
66 // Object for device detection class
67 DeviceDetectionServiceIf m_device_detector_obj;
68
69 // Map container  for startup phase counter
70 CounterInformation CEvntWriterWorker::counter;
71
72 // Deque container for event logging
73 DEQUE_Event_Type CEvntWriterWorker::deque_event_info;
74
75 static CEvntWriterWorker * pObj = new (std::nothrow) CEvntWriterWorker();  // LCOV_EXCL_BR_LINE 11:Unexpected branch
76 static TEvntWriterInfo wi = { };
77
78 // Event Common Info global structure
79 extern UEvtLoggerCommonInfo g_uEvtLoggerCommonInfo;
80 extern UI_16 g_u16DiagId;
81 static EFrameworkunifiedStatus ReadEventLogQueue(HANDLE hThread);
82 // created global variables as they are used in non member function
83 HANDLE g_hReceive = NULL;
84 HANDLE g_hEvtLogTimer = NULL;
85
86 CEvntWriterWorker::CEvntWriterWorker()
87     : m_u32MileageData(0),
88       m_u32NumberEventsLogged(0) {
89   memset(m_stVINnumber.VINstr, 0, m_stVINnumber.VIN_LEN);
90 }
91
92 CEvntWriterWorker::~CEvntWriterWorker() {  // LCOV_EXCL_START 14:global instance
93   AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
94 }
95 // LCOV_EXCL_STOP
96
97 EFrameworkunifiedStatus CEvntWriterWorker::Initialize(HANDLE hThread) {
98   return eFrameworkunifiedStatusOK;
99 }
100
101 ///////////////////////////////////////////////////////////////////////
102 /// Function :EventLogRegisterCbHandlers
103 ///////////////////////////////////////////////////////////////////////
104 EFrameworkunifiedStatus CEvntWriterWorker::EventLogRegisterCbHandlers(HANDLE hThread) {  // LCOV_EXCL_START 8: dead code
105   AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
106   FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+");
107   EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK;
108
109   FrameworkunifiedProtocolCallbackHandler aParentHandlers[] = { {
110       eThrdCmdWriteEvntFilesToUsb, boost::bind(
111           &CEvntWriterWorker::OnCmdWriteEventFilesToUsb, this, _1) }, {
112       eThrdCmdClearEvntLogs, boost::bind(
113           &CEvntWriterWorker::OnCmdClearEventLogs, this, _1) }, {
114       eThrdCmdStatisticalCounter, boost::bind(
115           &CEvntWriterWorker::OnCmdReadStatisticalCounter, this, _1) }, {
116       eThrdCmdResetStatisticalCntrs, boost::bind(
117           &CEvntWriterWorker::OnCmdResetStatisticalCounter, this, _1) }, {
118       eThrdCmdSetVINnumber, boost::bind(&CEvntWriterWorker::OnCmdSetVIN, this,
119                                         _1) }, { eThrdCmdImmPersistEvtLog,
120       boost::bind(&CEvntWriterWorker::immediate_persist_event_log, this, _1) },
121       { eThrdCmdMileageData, boost::bind(&CEvntWriterWorker::EvtThd_SetMileage,
122                                          this, _1) }, {
123           eThrdCmdGetNumberOfEventsLogged, boost::bind(
124               &CEvntWriterWorker::OnCmdReadNumberOfEventsLogged, this, _1) }, {
125           eThrdCmdUploadEventLog, boost::bind(
126               &CEvntWriterWorker::OnCmdUploadEventLog, this, _1) } };
127
128   if (eFrameworkunifiedStatusOK
129       != (l_eStatus = FrameworkunifiedAttachParentCallbacksToDispatcher(
130           hThread, aParentHandlers, _countof(aParentHandlers)))) {
131     FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__,
132            "Error: parent call backs attach failed , err code: %d", l_eStatus);
133   }
134
135   // TO DO replace the queue name with macro EVENTLOG_MSGQ_NAME, after NS delivers it.
136   if (NULL != (g_hReceive = McOpenReceiverNotBlocked("/EvntLogQue"))) {
137     if (NULL
138         == (g_hEvtLogTimer = FrameworkunifiedAttachTimerCallback(hThread, 100, 1000,
139                                                     ReadEventLogQueue))) {
140       LOG_ERROR("FrameworkunifiedAttachTimerCallback()");
141     }
142   } else {
143     LOG_ERROR("McOpenReceiverNotBlocked");
144   }
145
146   return l_eStatus;
147 }
148 // LCOV_EXCL_STOP
149
150 EFrameworkunifiedStatus ReadEventLogQueue(HANDLE hThread) {
151   FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+");
152   EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK;
153   CHAR source[MAX_QUEUE_NAME_SIZE];
154   UI_32 l_cmd = 0;
155   UI_8 pbuf[MAX_QUEUE_MSG_SIZE];
156
157   if (NULL != g_hReceive) {  // LCOV_EXCL_BR_LINE 6: g_hReceive is always null
158     // LCOV_EXCL_START 8: dead code
159     AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
160     while (1) {
161       if (eFrameworkunifiedStatusOK != (l_eStatus = McReceive(g_hReceive, source, &l_cmd,
162       MAX_QUEUE_MSG_SIZE,
163                                                  pbuf))) {
164         break;
165       } else {
166         switch (l_cmd) {
167           case SS_MSG_EVTLOG:
168             if (pObj) {
169               if (eFrameworkunifiedStatusOK != (l_eStatus = pObj->OnCmdEventLog(pbuf))) {
170                 LOG_ERROR("OnCmdEventLog()");
171               }
172             } else {
173               LOG_ERROR("pObj NULL");
174             }
175             break;
176
177           case SS_MSG_LOGGERCNT:
178             if (pObj) {
179               if (eFrameworkunifiedStatusOK != (l_eStatus = pObj->OnCmdIncrcount(pbuf))) {
180                 LOG_ERROR("OnCmdIncrcount()");
181               }
182             } else {
183               LOG_ERROR("pObj NULL");
184             }
185             break;
186
187           case SS_MSG_LOGGER_CNT_EVTLOG:
188             if (pObj) {
189               if (eFrameworkunifiedStatusOK
190                   != (l_eStatus = pObj->OnCmdIncrwriteevent(pbuf))) {
191                 LOG_ERROR("OnCmdIncrwriteevent()");
192               }
193             } else {
194               LOG_ERROR("pObj NULL");
195             }
196             break;
197
198           default:
199             break;
200         }
201       }
202     }
203     // LCOV_EXCL_STOP
204   } else {
205     LOG_ERROR("Receive Handle NULL");  // LCOV_EXCL_BR_LINE 15:macro
206   }
207
208   if (eFrameworkunifiedStatusErrNoEAGAIN == l_eStatus) {  // LCOV_EXCL_BR_LINE 6: l_eStatus is always eFrameworkunifiedStatusOK
209     l_eStatus = eFrameworkunifiedStatusOK;  // LCOV_EXCL_LINE 6: l_eStatus is always eFrameworkunifiedStatusOK
210     AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
211   }
212
213   FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-");
214   return l_eStatus;
215 }
216 ///////////////////////////////////////////////////////////////////////
217 /// Function :EvntWriterWorkerOnStart
218 ///////////////////////////////////////////////////////////////////////
219 EFrameworkunifiedStatus EvntWriterWorkerOnStart(HANDLE hThread) {
220   FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __PRETTY_FUNCTION__, "+");
221   EFrameworkunifiedStatus eStatus = eFrameworkunifiedStatusFail;
222
223   if (eFrameworkunifiedStatusOK != (eStatus = FrameworkunifiedGetMsgDataOfSize(hThread, (PVOID) &wi, sizeof(wi), eSMRRelease))) {  // LCOV_EXCL_BR_LINE 4:NSFW  // NOLINT[whitespace/line_length]
224     // LCOV_EXCL_START 4:NSFW
225     AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
226     FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__,
227            "Error: Unable to read handle from FrameWork Thread.%d", eStatus);
228     // LCOV_EXCL_STOP
229   } else {
230     FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__,
231            "Successfully read handle from FrameWork Thread.\n");  // LCOV_EXCL_BR_LINE 15:macro
232   }
233
234   // Device Detection Obj initialization
235   if (m_device_detector_obj.Initialize(hThread)) {  // LCOV_EXCL_BR_LINE 200:To ensure success
236     memset(&gSUSBDevInfo, 0, sizeof(gSUSBDevInfo));
237     memset(&gSSDCardevInfo, 0, sizeof(gSSDCardevInfo));
238
239     if (eFrameworkunifiedStatusOK != (eStatus = m_device_detector_obj.NotifyOnDeviceDetectionAvailability( DD_USBServiceAvailabilityCallBack))) {
240       FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__,
241              "Error: ServiceAvailabilityCallback registration failed");
242     }
243
244     if (eFrameworkunifiedStatusOK != (eStatus = m_device_detector_obj.NotifyOnOpenSessionAck( DD_USBOpenSessionAckCallBack))) {
245       FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__,
246              "Error: OpenSessionAckCallback registration failed");
247     }
248
249     if (eFrameworkunifiedStatusOK != (eStatus = m_device_detector_obj.NotifyOnCloseSessionAck( DD_USBCloseSessionAckCallBack))) {
250       FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__,
251              "Error: CloseSessionCallback registration failed");
252     }
253   } else {
254     // LCOV_EXCL_START 200:To ensure success
255     AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
256     FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__,
257            "Error: Device Detection Object Initialization failed!");
258     // LCOV_EXCL_STOP
259   }
260
261   if (pObj) {  // LCOV_EXCL_BR_LINE 200:As it is always TRUE
262     FrameworkunifiedSetThreadSpecificData(hThread, pObj);
263     if (eFrameworkunifiedStatusOK != (eStatus = pObj->Initialize(hThread))) {
264       FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__,
265              "Error: CEvntWriterWorker Initialize Failed");
266     }
267   } else {
268     // LCOV_EXCL_START 200:As it is always TRUE
269     AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
270     eStatus = eFrameworkunifiedStatusNullPointer;
271     FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "pObj is NULL");
272     // LCOV_EXCL_STOP
273   }
274
275   FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __PRETTY_FUNCTION__, "-");
276   return eStatus;
277 }
278
279 ///////////////////////////////////////////////////////////////////////
280 /// Function :EvntWriterWorkerOnStop
281 ///////////////////////////////////////////////////////////////////////
282 EFrameworkunifiedStatus EvntWriterWorkerOnStop(HANDLE hThread) {
283   FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __PRETTY_FUNCTION__, "+");
284   EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusFail;
285
286   if (pObj) {  // LCOV_EXCL_BR_LINE 200:As it is always TRUE
287     if (NULL != g_hEvtLogTimer) {  // LCOV_EXCL_BR_LINE 200:As it is always NULL
288       // LCOV_EXCL_START 200:As it is always NULL
289       AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
290       CALL_AND_LOG_STATUS(FrameworkunifiedDetachTimerCallback(hThread, g_hEvtLogTimer));
291       g_hEvtLogTimer = NULL;
292       // LCOV_EXCL_STOP
293     }
294
295     /// To Read all msgs of EventLog queue on shutdown
296     CALL_AND_LOG_STATUS(ReadEventLogQueue(hThread));  // LCOV_EXCL_BR_LINE 11:Unexpected branch
297     /// Close ReadEventLog Queue receive handle
298     if (NULL != g_hReceive) {  // LCOV_EXCL_BR_LINE 200:As it is always NULL
299       // LCOV_EXCL_START 200:As it is always NULL
300       AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
301       CALL_AND_LOG_STATUS(McClose(g_hReceive));
302       g_hReceive = NULL;
303       // LCOV_EXCL_STOP
304     }
305   }
306   FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __PRETTY_FUNCTION__, "-");
307   return l_eStatus;
308 }
309
310 ///////////////////////////////////////////////////////////////////////
311 /// Function :OnCmdIncrcount_phase
312 ///////////////////////////////////////////////////////////////////////
313 VOID CEvntWriterWorker::OnCmdIncrcount_phase(st_LogCount *cnt) {  // LCOV_EXCL_START 8: dead code
314   AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
315   FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __PRETTY_FUNCTION__, "+");
316
317   if (NULL != cnt) {
318     EStatCounterGroupID group;
319     UI_16 counterID = ((*cnt).cnt_id);
320     group = static_cast<EStatCounterGroupID>((counterID >> 8) & 0x00FF);
321     FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __PRETTY_FUNCTION__,
322            "Increment counter(%04X) for group(%02X) by one", counterID, group);
323     counterIncrementByValue(group, counterID, 0x01u);
324   } else {
325     FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __PRETTY_FUNCTION__, "Function call without parameter");
326   }
327   FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __PRETTY_FUNCTION__, "-");
328 }
329 // LCOV_EXCL_STOP
330
331 ///////////////////////////////////////////////////////////////////////
332 /// Function :OnCmdIncrcount
333 ///////////////////////////////////////////////////////////////////////
334 EFrameworkunifiedStatus CEvntWriterWorker::OnCmdIncrcount(UI_8 *pbuf) {  // LCOV_EXCL_START 8: dead code
335   AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
336   FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __PRETTY_FUNCTION__, "+");
337   EFrameworkunifiedStatus eStatus = eFrameworkunifiedStatusOK;
338   st_LogCount cnt;
339
340   if (eFrameworkunifiedStatusOK
341       == (eStatus = McGetDataOfSize(pbuf, (PVOID) &cnt, sizeof(cnt)))) {
342     FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__,
343            "call increment function cnt.phase=%x,cnt.ID=%x", cnt.phase,
344            cnt.cnt_id);
345     OnCmdIncrcount_phase(&cnt);
346   } else {
347     FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __PRETTY_FUNCTION__, "Not recieved data from q");
348   }
349   FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __PRETTY_FUNCTION__, "-");
350   return eStatus;
351 }
352 // LCOV_EXCL_STOP
353
354 ///////////////////////////////////////////////////////////////////////
355 /// Function :OnCmdIncrwriteevent
356 ///////////////////////////////////////////////////////////////////////
357 EFrameworkunifiedStatus CEvntWriterWorker::OnCmdIncrwriteevent(UI_8* pbuf) {  // LCOV_EXCL_START 8: dead code
358   AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
359   EFrameworkunifiedStatus eStatus = eFrameworkunifiedStatusOK;
360   st_LogEvent EC;
361   st_LogEvent_ss ev = { };
362   st_LogCount C;
363
364   if (eFrameworkunifiedStatusOK
365       == (eStatus = McGetDataOfSize(pbuf, (PVOID) &EC, sizeof(EC)))) {
366     FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __PRETTY_FUNCTION__, "Successful increment");
367     ev.event_id = EC.event_id;
368     ev.data[0] = EC.data[0];
369     ev.data[1] = EC.data[1];
370     ev.data[2] = EC.data[2];
371     ev.data[3] = EC.data[3];
372     OnCmdWriteEventLogs(&ev);
373     C.phase = (SystemPhase) (EC.phase);
374     C.cnt_id = EC.cnt_ID;
375     OnCmdIncrcount_phase(&C);
376   } else {
377     FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __PRETTY_FUNCTION__, "Not recieved data from q");
378   }
379   return eStatus;
380 }
381 // LCOV_EXCL_STOP
382
383 ///////////////////////////////////////////////////////////////////////
384 /// Function :OnCmdWriteEventLogs
385 ///////////////////////////////////////////////////////////////////////
386 VOID CEvntWriterWorker::OnCmdWriteEventLogs(st_LogEvent_ss *ev) {  // LCOV_EXCL_START 8: dead code
387   AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
388 //  FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __PRETTY_FUNCTION__, "+");
389   UI_32 u32deque_size = 0;
390   u32deque_size = static_cast<UI_32>(deque_event_info.size());
391   u32deque_size = u32deque_size * SINGLE_EVENT_INFO_SIZE;  // Existing Event Info size
392   u32deque_size += SINGLE_EVENT_INFO_SIZE;
393   //  FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __PRETTY_FUNCTION__,"Deque size before write:%X ",u32deque_size);
394
395   if (u32deque_size > MAX_EVENTLOG_SIZE) {
396 //    FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __PRETTY_FUNCTION__,"Deque size will be exceeded after new event:%X ",u32deque_size);
397 //    FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __PRETTY_FUNCTION__,"Removed the oldest event and add latest event in the the end");
398     deque_event_info.pop_front();
399     u32deque_size = static_cast<UI_32>(deque_event_info.size());
400 //    FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __PRETTY_FUNCTION__,"Deque size after pop:%X ",(u32deque_size*SINGLE_EVENT_INFO_SIZE));
401   }
402   deque_event_info.push_back(*ev);
403 //  FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __PRETTY_FUNCTION__,"Deque size after write:%X ",
404 //  (deque_event_info.size()*SINGLE_EVENT_INFO_SIZE));
405 //  FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __PRETTY_FUNCTION__, "-");
406 }
407 // LCOV_EXCL_STOP
408
409 UI_32 LS_ConvertEndian(UI_32 * pvar) {  // LCOV_EXCL_START 8: dead code
410   AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
411   UI_32 retVal = (UI_32) 0;
412   UI_32 var = *pvar;
413   retVal = (((var & 0xFF000000) >> 24) | ((var & 0x00FF0000) >> 8)
414       | ((var & 0x0000FF00) << 8) | ((var & 0x000000FF) << 24));
415   return (retVal);
416 }
417 // LCOV_EXCL_STOP
418
419 ///////////////////////////////////////////////////////////////////////
420 /// Function :OnCmdEventLog
421 ///////////////////////////////////////////////////////////////////////
422 EFrameworkunifiedStatus CEvntWriterWorker::OnCmdEventLog(UI_8* pbuf) {  // LCOV_EXCL_START 8: dead code
423   AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
424   EFrameworkunifiedStatus eStatus = eFrameworkunifiedStatusOK;
425 //  FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __PRETTY_FUNCTION__, "+");
426   st_LogEvent_ss ev = { };
427   st_LogEvent_full ev_full = { };
428   UI_32 l_mileage;
429   if (eFrameworkunifiedStatusOK
430       == (eStatus = McGetDataOfSize(pbuf, &ev_full, sizeof(ev_full)))) {
431     if (0 != ev_full.grp_ID) {
432       if (0x01 == ev_full.grp_ID) {
433         // copied to local var as m_u32MileageData value is persisted
434         l_mileage = m_u32MileageData;
435         ev.ts = LS_ConvertEndian(&l_mileage);
436       } else {
437         ev.ts = ev_full.ts;
438       }
439       ev.grp_ID = ev_full.grp_ID;
440       ev.event_id = ev_full.event_id;
441       FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__, "TS %u, GRPID %d, EVTID %d", ev.ts,
442              ev.grp_ID, ev.event_id);
443       // FRAMEWORKUNIFIEDLOG_EVT(Zone,EventId,4,data0,data1,data2,data3)
444       // Data in tool should be represented in Little Endian format means data3(MSB)..data0(LSB)
445       // In the COMMON_DATA, 1st element of structure u_stEvtLoggerCommonInfo is stored in the CommonData[0],
446       // ie BodayCAN_Stat,
447       // in the data array, byte0=>MSB, byte3=>LSB in the tool
448       if (ev_full.typeofdata == COMMON_DATA) {
449         for (UI_8 j = 0; j < 3; j++) {
450           ev.data[j] = g_uEvtLoggerCommonInfo.CommonData[j];
451         }
452         // byte0 param
453         ev.data[3] = ev_full.data[0];
454       } else {
455         // in array data[0] => MSB in tool, data[3] => LSB in the tool
456         for (UI_8 i = 4, j = 0; i > 0 && j < 4; i--, j++) {
457           ev.data[i - 1] = ev_full.data[j];
458         }
459       }
460       OnCmdWriteEventLogs(&ev);
461     } else {
462       FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "Error: Invalid event");
463     }
464   }
465 //  FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __PRETTY_FUNCTION__, "-");
466   return eStatus;
467 }
468 // LCOV_EXCL_STOP
469
470 ///////////////////////////////////////////////////////////////////////
471 /// Function :OnCmdStop
472 ///////////////////////////////////////////////////////////////////////
473 EFrameworkunifiedStatus CEvntWriterWorker::OnCmdStop(HANDLE hThread) {  // LCOV_EXCL_START 8: dead code
474   AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
475   return eFrameworkunifiedStatusOK;
476 }
477 // LCOV_EXCL_STOP
478
479 EFrameworkunifiedStatus CEvntWriterWorker::OnCmdStart(HANDLE hThread) {  // LCOV_EXCL_START 8: dead code
480   AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
481   return eFrameworkunifiedStatusOK;
482 }
483 // LCOV_EXCL_STOP
484
485 ///////////////////////////////////////////////////////////////////////
486 /// Function :read_count_from_file
487 ///////////////////////////////////////////////////////////////////////
488 EFrameworkunifiedStatus CEvntWriterWorker::readCountFromFile(PCSTR filename) {  // LCOV_EXCL_START 8: dead code
489   AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
490   FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+");
491   EFrameworkunifiedStatus eStatus = eFrameworkunifiedStatusOK;
492   UI_32 counter_ID = 0;
493   UI_32 counter_val = 0;
494   FILE* fp;
495   if (filename != NULL) {
496     FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__, "Open counter file:%s", filename);
497     if (NULL != (fp = ::fopen(filename, "r"))) {
498       while (!feof(fp)) {
499         EStatCounterGroupID group;
500         UI_8 groupID;
501         UI_8 count = static_cast<UI_8>(::fscanf(fp, "%04X%08X", &counter_ID, &counter_val));
502         groupID = (counter_ID >> 8) & 0xFF;
503         FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "Read: 0x%04X 0x%08X", counter_ID,
504                counter_val);
505         if ((count == 2u)
506             && (groupID >= static_cast<UI_8>(STARTUP_SHUTDOWN_COUNTER_GROUP))
507             && (groupID <= static_cast<UI_8>(APP_USAGE_COUNTER_GROUP))) {
508           // Check if group is valid before casting it o EStatCounterGroup
509           group = static_cast<EStatCounterGroupID>(groupID);
510           counterIncrementByValue(group, static_cast<UI_16>(counter_ID), counter_val);
511         }
512       }
513       ::fclose(fp);
514     } else {
515       FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "Normal File failed to open");
516       eStatus = eFrameworkunifiedStatusFileLoadError;
517     }
518   } else {
519     FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "Filename is NULL-pointer");
520     eStatus = eFrameworkunifiedStatusAccessError;
521   }
522   FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-");
523   return eStatus;
524 }
525 // LCOV_EXCL_STOP
526
527 // LCOV_EXCL_START 8: dead code
528 EFrameworkunifiedStatus CEvntWriterWorker::writeGroupToFile(FILE *fp,
529                                                EStatCounterGroupID group) {
530   AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
531   FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+");
532   EFrameworkunifiedStatus eStatus = eFrameworkunifiedStatusOK;
533   if (fp != NULL) {
534     CounterInformation::iterator countInfIt = counter.find(group);
535     if (countInfIt != counter.end()) {
536       Counter count = countInfIt->second;
537       if (!count.empty()) {
538         Counter::iterator countIt;
539         for (countIt = count.begin(); countIt != count.end(); ++countIt) {
540           ::fprintf(fp, "%04X%08X\n", countIt->first, countIt->second);
541         }
542         FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "Written %d entries for Group 0x%02X",
543                (UI_8)count.size(), (UI_8)group);
544       } else {
545         FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "Group 0x%02X is empty", (UI_8)group);
546       }
547     } else {
548       FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "Group not found in map");
549     }
550   } else {
551     FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "Parameter fp is NULL-pointer");
552     eStatus = eFrameworkunifiedStatusAccessError;
553   }
554   FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-");
555   return eStatus;
556 }
557 // LCOV_EXCL_STOP
558
559 ///////////////////////////////////////////////////////////////////////
560 /// Function :writeCountToFile
561 ///////////////////////////////////////////////////////////////////////
562 EFrameworkunifiedStatus CEvntWriterWorker::writeCountToFile(PCSTR filename) {  // LCOV_EXCL_START 8: dead code
563   AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
564   FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+");
565   FILE *fp;
566   EFrameworkunifiedStatus eStatus = eFrameworkunifiedStatusOK;
567   CounterInformation::iterator countInfIt;
568   if (0 == strcmp(filename, Counter_LOG_PATH_FN)) {
569     if (NULL != (fp = ::fopen(filename, "w"))) {
570       for (countInfIt = counter.begin(); countInfIt != counter.end();
571           ++countInfIt) {
572         (void) writeGroupToFile(fp, countInfIt->first);
573       }
574       ::fclose(fp);
575     }
576   } else {
577     FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "Error: Not valid file");
578     eStatus = eFrameworkunifiedStatusErrNoEBADF;
579   }
580   FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-");
581   return eStatus;
582 }
583 // LCOV_EXCL_STOP
584
585 ///////////////////////////////////////////////////////////////////////
586 /// Function :read_events_from_buffer
587 ///////////////////////////////////////////////////////////////////////
588 // LCOV_EXCL_START 8: dead code
589 VOID CEvntWriterWorker::read_events_from_buffer(
590     STEventLogPersistBuffer* f_pstEvtLogBuf) {
591   AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
592   FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+");
593   deque_event_info.clear();
594   for (int i = 0; i < (f_pstEvtLogBuf->Current_Log_Size); i++) {
595     if (i < f_pstEvtLogBuf->EVT_BUFMAXSIZE) {
596       deque_event_info.push_back(f_pstEvtLogBuf->EvtLog_Buffer[i]);
597     } else {
598       FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__,
599              "Error: EventLog buffer size greater than EVT_BUFMAXSIZE");
600     }
601   }
602   FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__, "Size of DEQUE event is :%d",
603          static_cast<int>(deque_event_info.size()));
604   FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-");
605 }
606 // LCOV_EXCL_STOP
607
608 ///////////////////////////////////////////////////////////////////////
609 /// Function :write_events_to_buffer
610 ///////////////////////////////////////////////////////////////////////
611 // LCOV_EXCL_START 8: dead code
612 VOID CEvntWriterWorker::write_events_to_buffer(
613     STEventLogPersistBuffer* f_pstEvtLogBuf) {
614   AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
615 //  FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+");
616   st_LogEvent_ss l_event_info;
617   DEQUE_Event_Type::iterator deque_it;
618   deque_it = deque_event_info.begin();
619   int i = 0;
620
621   memset(f_pstEvtLogBuf, 0x00, sizeof(STEventLogPersistBuffer));
622   while (deque_it != deque_event_info.end()) {
623     if (0x00 != deque_it->grp_ID) {
624       l_event_info.ts = deque_it->ts;
625       l_event_info.grp_ID = deque_it->grp_ID;
626       l_event_info.event_id = deque_it->event_id;
627       memcpy(l_event_info.data, deque_it->data, sizeof(l_event_info.data));
628 //      FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __PRETTY_FUNCTION__,"Event record is:%X ",++EventRecordCnt);
629       if (i < f_pstEvtLogBuf->EVT_BUFMAXSIZE) {
630         memcpy(&f_pstEvtLogBuf->EvtLog_Buffer[i], &l_event_info,
631                sizeof(l_event_info));
632       }
633     }
634     deque_it++;
635     i++;
636   }
637   f_pstEvtLogBuf->Current_Log_Size = static_cast<UI_16>(deque_event_info.size());
638   FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__, "Size of DEQUE event is :%d",
639          static_cast<int>(deque_event_info.size()));
640 //  FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-");
641 }
642 // LCOV_EXCL_STOP
643
644 ///////////////////////////////////////////////////////////////////////
645 /// Function :write_event_to_file
646 ///////////////////////////////////////////////////////////////////////
647 EFrameworkunifiedStatus CEvntWriterWorker::write_event_to_file(const CHAR* filename) {  // LCOV_EXCL_START 8: dead code
648   AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
649   FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+");
650   EFrameworkunifiedStatus eStatus = eFrameworkunifiedStatusOK;
651   UI_32 u32File_Size;
652   st_LogEvent_ss Sevent_Info;
653   DEQUE_Event_Type::iterator deque_it;
654   FILE *fp;
655
656   if (NULL != (fp = ::fopen(filename, "wb"))) {
657     deque_it = deque_event_info.begin();
658     while (deque_it != deque_event_info.end()) {
659       Sevent_Info.ts = deque_it->ts;
660       Sevent_Info.grp_ID = deque_it->grp_ID;
661       Sevent_Info.event_id = deque_it->event_id;
662       memcpy(Sevent_Info.data, deque_it->data, sizeof(Sevent_Info.data));
663
664       if (0x00 != deque_it->grp_ID) {
665         if (SIZE_1
666             != (u32File_Size = static_cast<UI_32>(::fwrite(&Sevent_Info, sizeof(Sevent_Info), 1,
667                                         fp)))) {
668           FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "Error: Writing in to file is failed");
669           eStatus = eFrameworkunifiedStatusFail;
670           break;
671         }
672       }
673       deque_it++;
674     }
675     ::fclose(fp);
676   } else {
677     FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "Error: File failed to open");
678     eStatus = eFrameworkunifiedStatusFileLoadError;
679   }
680   FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-");
681   return eStatus;
682 }
683 // LCOV_EXCL_STOP
684
685 ///////////////////////////////////////////////////////////////////////
686 /// Function :OnCmdClearEventLogs
687 ///////////////////////////////////////////////////////////////////////
688 EFrameworkunifiedStatus CEvntWriterWorker::OnCmdClearEventLogs(HANDLE hThread) {  // LCOV_EXCL_START 8: dead code
689   AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
690   FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+");
691
692   EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK;
693   TSessionData l_stSessionData;
694   TClearEvntLogCmdResponse l_stCmdResponse;
695
696   if (eFrameworkunifiedStatusOK
697       != (l_eStatus = ReadMsg<TSessionData>(hThread,
698                                             l_stCmdResponse.stSessiondata))) {
699     LOG_ERROR("ReadMsg()");
700   } else {
701     deque_event_info.clear();
702     if (eFrameworkunifiedStatusOK != (l_eStatus = immediate_persist_event_log(hThread))) {
703       l_stCmdResponse.u8Response = (UI_8) CLEAR_EVENT_LOG_FAILED;
704     } else {
705       l_stCmdResponse.u8Response = (UI_8) CLEAR_EVENT_LOG_SUCCESS;
706     }
707     if (eFrameworkunifiedStatusOK
708         != (l_eStatus = FrameworkunifiedSendParent(hThread, eThrdCmdClearEventLogResponse,
709                                       sizeof(TClearEvntLogCmdResponse),
710                                       &l_stCmdResponse))) {
711       LOG_ERROR("FrameworkunifiedSendParent()");
712     }
713   }
714   FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-");
715   return l_eStatus;
716 }
717 // LCOV_EXCL_STOP 8
718
719 ///////////////////////////////////////////////////////////////////////
720 /// Function :OnCmdSetVIN
721 ///////////////////////////////////////////////////////////////////////
722 EFrameworkunifiedStatus CEvntWriterWorker::OnCmdSetVIN(HANDLE hThread) {  // LCOV_EXCL_START 8: dead code
723   AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
724   EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK;
725   STVIN_NUMBER l_stVIN_Number;
726
727   if (eFrameworkunifiedStatusOK
728       == (l_eStatus = FrameworkunifiedGetMsgDataOfSize(hThread, &l_stVIN_Number,
729                                           sizeof(l_stVIN_Number), eSMRRelease))) {
730     memcpy(&m_stVINnumber, &l_stVIN_Number, sizeof(STVIN_NUMBER));
731   }
732
733   return l_eStatus;
734 }
735 // LCOV_EXCL_STOP
736
737 ///////////////////////////////////////////////////////////////////////
738 /// Function :OnCmdGetVIN
739 ///////////////////////////////////////////////////////////////////////
740 VOID CEvntWriterWorker::OnCmdGetVIN(STVIN_NUMBER& f_stVIN_Number) {  // LCOV_EXCL_START 8: dead code
741   AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
742   memcpy(&f_stVIN_Number, &m_stVINnumber, sizeof(STVIN_NUMBER));
743 }
744 // LCOV_EXCL_STOP
745
746 ///////////////////////////////////////////////////////////////////////
747 /// Function :OnCmdWriteEventFilesToUsb
748 ///////////////////////////////////////////////////////////////////////
749 EFrameworkunifiedStatus CEvntWriterWorker::OnCmdWriteEventFilesToUsb(HANDLE hThread) {  // LCOV_EXCL_START 8: dead code
750   AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
751   FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+");
752   EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK;
753   TWriteFilesToUsbCmdData l_stCmdData;
754   TWriteFilesToUsbCmdResponse l_stCmdResponse;
755
756   TThrdEvtLogStore evt = { };
757   if (eFrameworkunifiedStatusOK
758       != (l_eStatus = ReadMsg<TWriteFilesToUsbCmdData>(hThread, l_stCmdData))) {
759     LOG_ERROR("ReadMsg()");
760   } else {
761     if ((USB0 == l_stCmdData.eDevId) || (USB1 == l_stCmdData.eDevId)) {
762       memcpy(&evt, &gSUSBDevInfo[l_stCmdData.eDevId], sizeof(TThrdEvtLogStore));
763     } else if (SD == l_stCmdData.eDevId) {
764       memcpy(&evt, &gSSDCardevInfo, sizeof(TThrdEvtLogStore));
765     } else {
766       l_eStatus = eFrameworkunifiedStatusInvldID;
767       LOG_ERROR("Invalid DeviceId()");
768     }
769     FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__,
770            "USB dev info:Available %d, Location %s, Parse %s ",
771            evt.IsDeviceAvailable, evt.parse_fn, evt.location);
772     l_stCmdResponse.u8Response = copy_event_files_to_usb(&evt);
773     l_stCmdResponse.stSessiondata.strSrcName = l_stCmdData.stSessiondata.strSrcName;
774     l_stCmdResponse.stSessiondata.session_id = l_stCmdData.stSessiondata.session_id;
775     if (eFrameworkunifiedStatusOK
776         != (l_eStatus = FrameworkunifiedSendParent(hThread, eThrdCmdCopyEventLogUSBResponse,
777                                       sizeof(TWriteFilesToUsbCmdResponse),
778                                       &l_stCmdResponse))) {
779       LOG_ERROR("FrameworkunifiedSendParent()");
780     }
781   }
782   FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-");
783   return l_eStatus;
784 }
785 // LCOV_EXCL_STOP
786
787 ///////////////////////////////////////////////////////////////////////
788 /// Function :OnCmdReadStatisticalCounter
789 ///////////////////////////////////////////////////////////////////////
790 EFrameworkunifiedStatus CEvntWriterWorker::OnCmdReadStatisticalCounter(HANDLE hThread) {  // LCOV_EXCL_START 8: dead code
791   AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
792   FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+");
793   EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK;
794   SStatisticalCounter buffer = { 0 };
795   TStatisticalCntCmdSuccessResp l_stCmdSuccessResp;
796
797   if (hThread != NULL) {
798     TStatisticalCountersCmd l_stCmdData;
799     if (eFrameworkunifiedStatusOK
800         != (l_eStatus = ReadMsg<TStatisticalCountersCmd>(hThread, l_stCmdData))) {
801       LOG_ERROR("ReadMsg()");
802     } else {
803       if (eFrameworkunifiedStatusOK
804           != (l_eStatus = ReadStatisticalCounter(l_stCmdData.eGroupId, buffer))) {
805         LOG_ERROR("ReadStatisticalCounter()");
806         if (eFrameworkunifiedStatusOK
807             != (l_eStatus = FrameworkunifiedSendParent(hThread,
808                                           eThrdCmdStatisticalCounterErrorResp,
809                                           sizeof(TSessionData),
810                                           &l_stCmdData.stSessiondata))) {
811           LOG_ERROR("FrameworkunifiedSendParent()");
812         }
813       } else {
814         (VOID) memcpy(&l_stCmdSuccessResp.stBuffer, &buffer,
815                       sizeof(SStatisticalCounter));
816         (VOID) memcpy(&l_stCmdSuccessResp.stSessiondata,
817                       &l_stCmdData.stSessiondata, sizeof(TSessionData));
818         if (eFrameworkunifiedStatusOK
819             != (l_eStatus = FrameworkunifiedSendParent(hThread,
820                                           eThrdCmdStatisticalCounterSuccessResp,
821                                           sizeof(TStatisticalCntCmdSuccessResp),
822                                           &l_stCmdSuccessResp))) {
823           LOG_ERROR("FrameworkunifiedSendParent()");
824         }
825       }
826     }
827   }
828   FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-");
829   return l_eStatus;
830 }
831 // LCOV_EXCL_STOP
832
833 ///////////////////////////////////////////////////////////////////////
834 /// Function :ReadStatisticalCounter
835 ///////////////////////////////////////////////////////////////////////
836 // LCOV_EXCL_START 8: dead code
837 EFrameworkunifiedStatus CEvntWriterWorker::ReadStatisticalCounter(
838     EStatCounterGroupID eCounterGroup, SStatisticalCounter& buffer) {
839   AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
840   FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+");
841   EFrameworkunifiedStatus eStatus = eFrameworkunifiedStatusOK;
842   UI_32 size = 0u;
843
844   CounterInformation::iterator countInfIt = counter.find(eCounterGroup);
845   if (counter.end() != countInfIt) {
846     Counter count = countInfIt->second;
847     Counter::iterator countIt;
848     if (((UI_16) count.size()) <= 40) {
849       for (countIt = count.begin(); countIt != count.end(); ++countIt) {
850         UI_16 counterID = countIt->first;
851         UI_32 counterVal = countIt->second;
852         u16copy(&buffer.StatisticalCountBuffer[size], counterID);
853         size += static_cast<UI_16>( sizeof(counterID));
854
855         counterVal = countIt->second;
856         u32copy(&buffer.StatisticalCountBuffer[size], counterVal);
857         size += static_cast<UI_16>( sizeof(counterVal));
858       }
859     } else {
860       eStatus = eFrameworkunifiedStatusInvldBuf;
861       FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__,
862              "Error: Too many counter elements %02d > 42 ", static_cast<int>(count.size()));
863     }
864   } else {
865     /*OK, here: empty buffer will be returned*/
866   }
867
868   FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-");
869   return eStatus;
870 }
871 // LCOV_EXCL_STOP
872
873 ///////////////////////////////////////////////////////////////////////
874 /// Function :OnCmdResetStatisticalCounter
875 ///////////////////////////////////////////////////////////////////////
876 EFrameworkunifiedStatus CEvntWriterWorker::OnCmdResetStatisticalCounter(HANDLE hThread) {  // LCOV_EXCL_START 8: dead code
877   AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
878   FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+");
879   EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK;
880   TStatisticalCountersCmd l_stCmdData;
881
882   if (hThread != NULL) {
883     if (eFrameworkunifiedStatusOK
884         != (l_eStatus = ReadMsg<TStatisticalCountersCmd>(hThread, l_stCmdData))) {
885       LOG_ERROR("ReadMsg()");
886     } else {
887       if (eFrameworkunifiedStatusOK
888           != (l_eStatus = ResetStatisticalCounter(l_stCmdData.eGroupId))) {
889         LOG_ERROR("ResetStatisticalCounter()");
890       }
891     }
892   }
893
894   FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-");
895   return l_eStatus;
896 }
897 // LCOV_EXCL_STOP
898 ///////////////////////////////////////////////////////////////////////
899 /// Function :ResetStatisticalCounter
900 ///////////////////////////////////////////////////////////////////////
901 // LCOV_EXCL_START 8: dead code
902 EFrameworkunifiedStatus CEvntWriterWorker::ResetStatisticalCounter(
903     EStatCounterGroupID eCounterGroup) {
904   AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
905   FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+");
906   EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK;
907   CounterInformation::iterator countInfIt;
908   countInfIt = counter.find(eCounterGroup);
909   if (counter.end() != countInfIt) {
910     countInfIt->second.clear();
911     counter.erase(countInfIt->first);
912     FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__, "Erased group: 0x%02X from map",
913            (UI_8)eCounterGroup);
914   } else {
915     l_eStatus = eFrameworkunifiedStatusInvldID;
916   }
917   FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-");
918   return l_eStatus;
919 }
920 // LCOV_EXCL_STOP
921
922 ///////////////////////////////////////////////////////////////////////
923 /// Function :_GetCurrentTimeString
924 ///////////////////////////////////////////////////////////////////////
925 PSTR _GetCurrentTimeString(PCHAR TempFileName, PSTR f_pstrVIN) { // LCOV_EXCL_START 8: dead code
926   AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
927   FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+");
928
929   uint32_t rawtime;
930   uint8_t status;
931   struct tm local_time;
932   CHAR tbuf[30];
933   UI_8 l_len = 0;
934   std::string l_strVIN = f_pstrVIN;
935
936   // Time string is based on current date and time. Time string format is <year-mon-dayThhmm>.
937   Clock_getSystemTimeY2K38(&rawtime, &status);
938   Clock_getLocalTimeY2K38(&rawtime, &local_time);
939   if (0
940       != (l_len = static_cast<UI_8>(strftime(tbuf, sizeof(tbuf), "%Y-%m-%dT%H%M",
941                            &local_time)))) {
942     sprintf(TempFileName, "%s_%s_%04X.dat", l_strVIN.c_str(), tbuf,  // NOLINT (runtime/printf)
943             g_u16DiagId);
944   }
945   FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__, "EventLog File Name :%s, tbuf_len = %d",
946          TempFileName, l_len);
947   FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-");
948   return TempFileName;
949 }
950 // LCOV_EXCL_STOP
951
952 ///////////////////////////////////////////////////////////////////////
953 /// Function :copy_event_files_to_usb
954 ///////////////////////////////////////////////////////////////////////
955 UI_8 CEvntWriterWorker::copy_event_files_to_usb(TThrdEvtLogStore *pStUSBIndo) {  // LCOV_EXCL_START 8: dead code
956   AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
957   FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+");
958   EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK;
959   CHAR buffer[10];
960   CHAR TempFileName[MAX_SYS_INFO_SIZE];
961   STVIN_NUMBER l_stVIN_Number;
962   std::string _filename("");
963   UI_8 u8Result = COPY_EVT_USB_SUCCESS;
964
965   // Initializing all Char arrays.
966   memset(buffer, 0, 10);
967   memset(TempFileName, 0, MAX_SYS_INFO_SIZE);
968
969   if (pStUSBIndo->IsDeviceAvailable == TRUE) {
970     _filename = pStUSBIndo->location;
971     OnCmdGetVIN(l_stVIN_Number);
972     _filename += _GetCurrentTimeString(TempFileName, l_stVIN_Number.VINstr);
973
974     if (eFrameworkunifiedStatusOK != (l_eStatus = write_event_to_file(_filename.c_str()))) {
975       FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "Error: Write to file failed:%d",
976              l_eStatus);
977       u8Result = (UI_8) USB_DEVICE_WRITE_ERROR;
978     }
979
980   } else {
981     FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__,
982            "Error: Device not available, so event logs can not be copied");
983     u8Result = (UI_8) USB_DEVICE_NOT_AVAILABLE;
984   }
985
986   FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __PRETTY_FUNCTION__, "-");
987   return u8Result;
988 }
989 // LCOV_EXCL_STOP
990
991 ///////////////////////////////////////////////////////////////////////
992 /// Function :DD_USBSrvDetectionCallBack
993 ///////////////////////////////////////////////////////////////////////
994 EFrameworkunifiedStatus DD_USBSrvDetectionCallBack(HANDLE hApp) {  // LCOV_EXCL_START 8: dead code
995   AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
996   FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __PRETTY_FUNCTION__, "+");
997
998   EFrameworkunifiedStatus eStatus = eFrameworkunifiedStatusOK;
999   SS_MediaDetectInfo tMediaDetectInfo = { };
1000   std::string FilePathStr;
1001   UI_8 u8Pos = 0;
1002
1003   if (eFrameworkunifiedStatusOK
1004       != (eStatus = FrameworkunifiedGetMsgDataOfSize(hApp, &tMediaDetectInfo,
1005                                         sizeof(tMediaDetectInfo)))) {
1006     FRAMEWORKUNIFIEDLOG(ZONE_ERR, __PRETTY_FUNCTION__,
1007            "MediaDetectCallBack FrameworkunifiedGetMsgDataOfSize Failed Status:0x%x ",
1008            eStatus);
1009   }
1010   FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__, " Device = %d", tMediaDetectInfo.dev_type);
1011   FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__, " Availability = %d",
1012          tMediaDetectInfo.bIsDeviceAvailable);
1013   FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__, " device path = %s",
1014          tMediaDetectInfo.deviceMountpath);
1015   FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__, " File path = %s",
1016          tMediaDetectInfo.filepathName);
1017
1018   FilePathStr.append(tMediaDetectInfo.deviceMountpath);
1019
1020   if (tMediaDetectInfo.dev_type == eUSB) {
1021     if (tMediaDetectInfo.bIsDeviceAvailable == TRUE) {
1022       u8Pos = static_cast<UI_8>(FilePathStr.find_last_of("/\\"));
1023
1024       if (FilePathStr.compare(u8Pos + 1, 12, "usb-00-d0-p0") == 0) {
1025         FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__, "USB1 Detected ");
1026         gSUSBDevInfo[0].IsDeviceAvailable = TRUE;
1027         snprintf(gSUSBDevInfo[0].parse_fn, gSUSBDevInfo[0].FN_LEN, "%s/",
1028                  FilePathStr.c_str());
1029         snprintf(gSUSBDevInfo[0].location, gSUSBDevInfo[0].FN_LEN, "%s/",
1030                  FilePathStr.c_str());
1031       } else if (FilePathStr.compare(u8Pos + 1, 12, "usb-01-d0-p0") == 0) {
1032         FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__, "USB2 Detected ");
1033         gSUSBDevInfo[1].IsDeviceAvailable = TRUE;
1034         snprintf(gSUSBDevInfo[1].parse_fn, gSUSBDevInfo[1].FN_LEN, "%s/",
1035                  FilePathStr.c_str());
1036         snprintf(gSUSBDevInfo[1].location, gSUSBDevInfo[1].FN_LEN, "%s/",
1037                  FilePathStr.c_str());
1038       } else {
1039         FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__, "USB Detected :%s", FilePathStr.c_str());
1040       }
1041     } else {
1042       u8Pos = static_cast<UI_8>(FilePathStr.find_last_of("/\\"));
1043
1044       if (FilePathStr.compare(u8Pos + 1, 12, "usb-00-d0-p0") == 0) {
1045         FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__, "USB1 Ejected ");
1046         gSUSBDevInfo[0].IsDeviceAvailable = FALSE;
1047       } else if (FilePathStr.compare(u8Pos + 1, 12, "usb-01-d0-p0") == 0) {
1048         FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__, "USB2 Ejected ");
1049         gSUSBDevInfo[1].IsDeviceAvailable = FALSE;
1050       } else {
1051         FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__, "USB Ejected :%s", FilePathStr.c_str());
1052       }
1053     }
1054
1055   } else if (tMediaDetectInfo.dev_type == eSD) {
1056     if (tMediaDetectInfo.bIsDeviceAvailable == TRUE) {
1057       FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__, "SD card Detected ");
1058       gSSDCardevInfo.IsDeviceAvailable = TRUE;
1059       snprintf(gSSDCardevInfo.parse_fn, gSSDCardevInfo.FN_LEN, "%s/",
1060                FilePathStr.c_str());
1061       snprintf(gSSDCardevInfo.location, gSSDCardevInfo.FN_LEN, "%s/",
1062                FilePathStr.c_str());
1063     } else {
1064       FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__, "SD card  Ejected ");
1065       gSSDCardevInfo.IsDeviceAvailable = FALSE;
1066     }
1067   }
1068   FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __PRETTY_FUNCTION__, "-");
1069
1070   return eStatus;
1071 }
1072 // LCOV_EXCL_STOP
1073
1074 //////////////////////////////////////////
1075 //  Function : DD_USBServiceAvailabilityCallBack
1076 //////////////////////////////////////////
1077 EFrameworkunifiedStatus DD_USBServiceAvailabilityCallBack(HANDLE hThread) {
1078   FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+");
1079   EFrameworkunifiedStatus eStatus = eFrameworkunifiedStatusOK;
1080
1081   if (FrameworkunifiedIsServiceAvailable(hThread)) {
1082     if (eFrameworkunifiedStatusOK  // LCOV_EXCL_BR_LINE:200 Because the IF of DetectionService is guaranteed to be successful
1083         != (eStatus = m_device_detector_obj.OpenSessionRequest())) {
1084       FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "Open session request failed");
1085     }
1086   } else {
1087     if (eFrameworkunifiedStatusOK  // LCOV_EXCL_BR_LINE:200 Because the IF of DetectionService is guaranteed to be successful
1088         != (eStatus = m_device_detector_obj.CloseSessionRequest())) {
1089       FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "Close session request failed");
1090     }
1091   }
1092
1093   FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-");
1094   return eStatus;
1095 }
1096
1097 //////////////////////////////////////////
1098 //  Function : DD_USBOpenSessionAckCallBack
1099 //////////////////////////////////////////
1100 EFrameworkunifiedStatus DD_USBOpenSessionAckCallBack(HANDLE hThread) {
1101   FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+");
1102   EFrameworkunifiedStatus eStatus = eFrameworkunifiedStatusOK;
1103
1104   if (eFrameworkunifiedStatusOK == (eStatus =  // LCOV_EXCL_BR_LINE:200 Because the IF of DetectionService is guaranteed to be successful
1105       m_device_detector_obj.DecodeOpenSessionResponse())) {
1106     if (eFrameworkunifiedStatusOK
1107         != (eStatus = m_device_detector_obj.RegisterForDeviceDetectionEvent(  // LCOV_EXCL_BR_LINE:200 Because the IF of DetectionService is guaranteed to be successful  // NOLINT[whitespace/line_length]
1108             SS_DEV_DETECT_ANY_USB_EV, DD_USBSrvDetectionCallBack))) {
1109       FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__,
1110              "Registration for SS_DEV_DETECT_ANY_USB_EV failed");
1111     }
1112
1113     if (eFrameworkunifiedStatusOK
1114         != (eStatus = m_device_detector_obj.RegisterForDeviceDetectionEvent(  // LCOV_EXCL_BR_LINE:200 Because the IF of DetectionService is guaranteed to be successful  // NOLINT[whitespace/line_length]
1115             SS_DEV_DETECT_ANY_SD_EV, DD_USBSrvDetectionCallBack))) {
1116       FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__,
1117              "Registration for SS_DEV_DETECT_ANY_SD_EV failed");
1118     }
1119   } else {
1120     FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "Decode open session response failed");
1121   }
1122   FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-");
1123   return eStatus;
1124 }
1125 //////////////////////////////////////////
1126 //  Function : DD_USBCloseSessionAckCallBack
1127 //////////////////////////////////////////
1128 EFrameworkunifiedStatus DD_USBCloseSessionAckCallBack(HANDLE hApp) {  // LCOV_EXCL_START 200: CloseSessionRequest can not be called  // NOLINT[whitespace/line_length]
1129   AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
1130   FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+");
1131   EFrameworkunifiedStatus eStatus = eFrameworkunifiedStatusOK;
1132   CloseSessionAck tCloseSessionAck = { };
1133
1134   if (hApp) {
1135     if (eFrameworkunifiedStatusOK
1136         == (eStatus = FrameworkunifiedGetMsgDataOfSize(hApp, &tCloseSessionAck,
1137                                           sizeof(tCloseSessionAck)))) {
1138       if (eFrameworkunifiedStatusOK == tCloseSessionAck.eStatus) {
1139         UI_32 l_uiSessionId = tCloseSessionAck.sessionId;
1140         FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__, "session  %d closed successfully",
1141                l_uiSessionId);
1142       }
1143     }
1144   }
1145   FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-");
1146   return eStatus;
1147 }
1148 // LCOV_EXCL_STOP
1149
1150 // LCOV_EXCL_START 8: dead code
1151 EFrameworkunifiedStatus CEvntWriterWorker::counterIncrementByValue(EStatCounterGroupID group,
1152                                                       UI_16 id, UI_32 value) {
1153   AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
1154   FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+");
1155   EFrameworkunifiedStatus result = eFrameworkunifiedStatusFail;
1156   CounterInformation::iterator count_inf_it;
1157   count_inf_it = counter.find(group);
1158   if (counter.end() == count_inf_it) {
1159     Counter newCounter;
1160     newCounter.insert(std::pair<UI_16, UI_32>(id, value));
1161     counter.insert(std::pair<EStatCounterGroupID, Counter>(group, newCounter));
1162     FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__,
1163            "Added new Counter for group %d, id: 0x%04X, value: 0x%08X",
1164            (UI_8)group, id, value);
1165   } else {
1166     Counter::iterator count_it;
1167     count_it = count_inf_it->second.find(id);
1168     if (count_inf_it->second.end() == count_it) {
1169       count_inf_it->second.insert(std::pair<UI_16, UI_32>(id, value));
1170       FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__,
1171              "Added new Entry for group %d, id: 0x%04X, value: 0x%08X",
1172              (UI_8)group, id, value);
1173     } else {
1174       if (count_it->second != MAX_CNT_VALUE) {
1175         count_it->second += value;
1176       }
1177       FRAMEWORKUNIFIEDLOG(
1178           ZONE_FUNC,
1179           __FUNCTION__,
1180           "Modified Entry for group %d, id: 0x%04X, by value: 0x%08X, new value: 0x%08X",
1181           (UI_8)group, id, value, count_it->second);
1182     }
1183   }
1184   FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-");
1185   return result;
1186 }
1187 // LCOV_EXCL_STOP
1188
1189 EFrameworkunifiedStatus CEvntWriterWorker::immediate_persist_event_log(HANDLE hThread) {  // LCOV_EXCL_START 8: dead code
1190   AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
1191   FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+");
1192   STEventLogPersistBuffer* l_evtlogbuf;
1193   l_evtlogbuf = new (std::nothrow) STEventLogPersistBuffer;
1194
1195   if (NULL != l_evtlogbuf) {
1196     if (pObj) {
1197       pObj->write_events_to_buffer(l_evtlogbuf);
1198     } else {
1199       FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__,
1200              "Error: CEvntWriterWorker Object handle is NULL");
1201     }
1202     delete l_evtlogbuf;
1203   } else {
1204     FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__,
1205            "Error: New failed to allocate memory, err: %s", strerror(errno));
1206   }
1207   FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-");
1208   return eFrameworkunifiedStatusOK;
1209 }
1210 // LCOV_EXCL_STOP
1211
1212 EFrameworkunifiedStatus CEvntWriterWorker::EvtThd_SetMileage(HANDLE hThread) {  // LCOV_EXCL_START 8: dead code
1213   AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
1214   FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+");
1215   EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK;
1216   UI_32 l_u32mileage;
1217   if (eFrameworkunifiedStatusOK
1218       != (l_eStatus = FrameworkunifiedGetMsgDataOfSize(hThread, &l_u32mileage,
1219                                           sizeof(l_u32mileage)))) {
1220     FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "FrameworkunifiedGetMsgDataOfSize Failed Status:%d ",
1221            l_eStatus);
1222     FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-");
1223     return l_eStatus;
1224   }
1225   m_u32MileageData = l_u32mileage;
1226   FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-");
1227   return l_eStatus;
1228 }
1229 // LCOV_EXCL_STOP
1230
1231 ///////////////////////////////////////////////////////////////////////
1232 /// Function :write_mileage_to_file
1233 ///////////////////////////////////////////////////////////////////////
1234 EFrameworkunifiedStatus CEvntWriterWorker::write_mileage_to_file(const CHAR* filename) {  // LCOV_EXCL_START 8: dead code
1235   AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
1236   FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+");
1237   EFrameworkunifiedStatus eStatus = eFrameworkunifiedStatusOK;
1238   UI_32 u32File_Size;
1239   SI_32 fd = -1;
1240
1241   if (-1 != (fd = ::open(filename, O_WRONLY | O_CREAT | O_TRUNC,
1242   S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP))) {
1243     if (SIZE_0
1244         >= (u32File_Size = static_cast<UI_32>(::write(fd, &m_u32MileageData, sizeof(UI_32))))) {
1245       FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "Error: Writing in to file is failed");
1246       eStatus = eFrameworkunifiedStatusFail;
1247     }
1248     ::close(fd);
1249   } else {
1250     FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "Error: File failed to open");
1251     eStatus = eFrameworkunifiedStatusFileLoadError;
1252   }
1253   FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-");
1254   return eStatus;
1255 }
1256 // LCOV_EXCL_STOP
1257
1258 ///////////////////////////////////////////////////////////////////////
1259 /// Function :read_mileage_from_file
1260 ///////////////////////////////////////////////////////////////////////
1261 EFrameworkunifiedStatus CEvntWriterWorker::read_mileage_from_file(const CHAR* filename) {  // LCOV_EXCL_START 8: dead code
1262   AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
1263   FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+");
1264   EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK;
1265 //  UI_32 u32File_Size;
1266   SI_32 fd = -1;
1267
1268   if (NULL != filename) {
1269     if (-1 != (fd = ::open(filename, O_RDONLY, S_IRUSR))) {
1270       if (-1 == ::read(fd, &m_u32MileageData, sizeof(UI_32))) {
1271         FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "Error: Reading file failed, %s",
1272                strerror(errno));
1273         l_eStatus = eFrameworkunifiedStatusFail;
1274       } else {
1275         FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__, "m_u32MileageData = %d",
1276                m_u32MileageData);
1277       }
1278       ::close(fd);
1279     } else {
1280       FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "Error: File failed to open");
1281       l_eStatus = eFrameworkunifiedStatusFileLoadError;
1282     }
1283   } else {
1284     FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "Error: Filename is NULL");
1285     l_eStatus = eFrameworkunifiedStatusNullPointer;
1286   }
1287   FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-");
1288   return l_eStatus;
1289 }
1290 // LCOV_EXCL_STOP
1291
1292 ///////////////////////////////////////////////////////////////////////
1293 /// Function :OnCmdReadNumberOfEventsLogged
1294 ///////////////////////////////////////////////////////////////////////
1295 EFrameworkunifiedStatus CEvntWriterWorker::OnCmdReadNumberOfEventsLogged(HANDLE hThread) {  // LCOV_EXCL_START 8: dead code
1296   AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
1297   FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+");
1298   EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK;
1299   TEvntsLogged l_stEventsLogged;
1300
1301   if (eFrameworkunifiedStatusOK
1302       != (l_eStatus = ReadMsg<TSessionData>(hThread,
1303                                             l_stEventsLogged.stSessiondata))) {
1304     LOG_ERROR("ReadMsg()");
1305   } else {
1306     l_stEventsLogged.u16numberofeventslogged = (UI_16) deque_event_info.size();
1307     FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__, "Number of Events Read: %d",
1308            l_stEventsLogged.u16numberofeventslogged);
1309
1310     if (eFrameworkunifiedStatusOK
1311         != (l_eStatus = FrameworkunifiedSendParent(hThread,
1312                                       eThrdCmdNumberOfEventsLoggedResponse,
1313                                       sizeof(TEvntsLogged), &l_stEventsLogged))) {
1314       FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__, "Error: FrameworkunifiedSendMsg failed %d", l_eStatus);
1315     }
1316   }
1317
1318   FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-");
1319   return l_eStatus;
1320 }
1321 // LCOV_EXCL_STOP
1322
1323 ///////////////////////////////////////////////////////////////////////
1324 /// Function :OnCmdUploadEventLog
1325 ///////////////////////////////////////////////////////////////////////
1326 EFrameworkunifiedStatus CEvntWriterWorker::OnCmdUploadEventLog(HANDLE hThread) {  // LCOV_EXCL_START 8: dead code
1327   AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
1328   FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+");
1329   EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK;
1330
1331   if (eFrameworkunifiedStatusOK
1332       != (l_eStatus = ReadMsg<TSessionData>(
1333           hThread, m_stUploadEventLogResp.stSessiondata))) {
1334     LOG_ERROR("ReadMsg()");
1335   } else {
1336     if (pObj) {
1337       pObj->write_events_to_buffer(&m_stUploadEventLogResp.stEventLogBuffer);
1338       if (eFrameworkunifiedStatusOK
1339           != (l_eStatus = FrameworkunifiedSendParent(hThread, eThrdCmdUploadEventLogResponse,
1340                                         sizeof(TUploadEventLogResp),
1341                                         &m_stUploadEventLogResp))) {
1342         LOG_ERROR("FrameworkunifiedSendParent()");
1343       }
1344     } else {
1345       FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__,
1346              "Error: CEvntWriterWorker Object handle is NULL");
1347     }
1348   }
1349
1350   FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-");
1351   return l_eStatus;
1352 }
1353 // LCOV_EXCL_STOP
1354
1355 ///////////////////////////////////////////////////////////////////////
1356 /// Function :OnCmdCopyEvntLogToTmp
1357 ///////////////////////////////////////////////////////////////////////
1358 EFrameworkunifiedStatus CEvntWriterWorker::OnCmdCopyEvntLogToTmp(HANDLE hThread) {  // LCOV_EXCL_START 8: dead code
1359   AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
1360   return eFrameworkunifiedStatusOK;
1361 }
1362 // LCOV_EXCL_STOP