2 * @copyright Copyright (c) 2016-2020 TOYOTA MOTOR CORPORATION.
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
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.
22 ///////////////////////////////////////////////////////////////////////////////
24 #include "loggerservicedebug_writer_Evntworker.h"
29 #include <sys/timeb.h>
30 #include <boost/bind.hpp>
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>
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
57 // Temp path for event logs that used for copying to USB
58 const CHAR TMP_DEBUG_EVNTLOG_PATH_FN[] = "/tmp/loggerservice_Evntdebug.dat";
60 // Structure to hold the USB device information
61 TThrdEvtLogStore gSUSBDevInfo[MAX_USB_DEVICE] = { };
63 // Structure to hold the SD card device information
64 TThrdEvtLogStore gSSDCardevInfo = { };
66 // Object for device detection class
67 DeviceDetectionServiceIf m_device_detector_obj;
69 // Map container for startup phase counter
70 CounterInformation CEvntWriterWorker::counter;
72 // Deque container for event logging
73 DEQUE_Event_Type CEvntWriterWorker::deque_event_info;
75 static CEvntWriterWorker * pObj = new (std::nothrow) CEvntWriterWorker(); // LCOV_EXCL_BR_LINE 11:Unexpected branch
76 static TEvntWriterInfo wi = { };
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;
86 CEvntWriterWorker::CEvntWriterWorker()
87 : m_u32MileageData(0),
88 m_u32NumberEventsLogged(0) {
89 memset(m_stVINnumber.VINstr, 0, m_stVINnumber.VIN_LEN);
92 CEvntWriterWorker::~CEvntWriterWorker() { // LCOV_EXCL_START 14:global instance
93 AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert
97 EFrameworkunifiedStatus CEvntWriterWorker::Initialize(HANDLE hThread) {
98 return eFrameworkunifiedStatusOK;
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;
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,
123 eThrdCmdGetNumberOfEventsLogged, boost::bind(
124 &CEvntWriterWorker::OnCmdReadNumberOfEventsLogged, this, _1) }, {
125 eThrdCmdUploadEventLog, boost::bind(
126 &CEvntWriterWorker::OnCmdUploadEventLog, this, _1) } };
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);
135 // TO DO replace the queue name with macro EVENTLOG_MSGQ_NAME, after NS delivers it.
136 if (NULL != (g_hReceive = McOpenReceiverNotBlocked("/EvntLogQue"))) {
138 == (g_hEvtLogTimer = FrameworkunifiedAttachTimerCallback(hThread, 100, 1000,
139 ReadEventLogQueue))) {
140 LOG_ERROR("FrameworkunifiedAttachTimerCallback()");
143 LOG_ERROR("McOpenReceiverNotBlocked");
150 EFrameworkunifiedStatus ReadEventLogQueue(HANDLE hThread) {
151 FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+");
152 EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK;
153 CHAR source[MAX_QUEUE_NAME_SIZE];
155 UI_8 pbuf[MAX_QUEUE_MSG_SIZE];
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
161 if (eFrameworkunifiedStatusOK != (l_eStatus = McReceive(g_hReceive, source, &l_cmd,
169 if (eFrameworkunifiedStatusOK != (l_eStatus = pObj->OnCmdEventLog(pbuf))) {
170 LOG_ERROR("OnCmdEventLog()");
173 LOG_ERROR("pObj NULL");
177 case SS_MSG_LOGGERCNT:
179 if (eFrameworkunifiedStatusOK != (l_eStatus = pObj->OnCmdIncrcount(pbuf))) {
180 LOG_ERROR("OnCmdIncrcount()");
183 LOG_ERROR("pObj NULL");
187 case SS_MSG_LOGGER_CNT_EVTLOG:
189 if (eFrameworkunifiedStatusOK
190 != (l_eStatus = pObj->OnCmdIncrwriteevent(pbuf))) {
191 LOG_ERROR("OnCmdIncrwriteevent()");
194 LOG_ERROR("pObj NULL");
205 LOG_ERROR("Receive Handle NULL"); // LCOV_EXCL_BR_LINE 15:macro
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
213 FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-");
216 ///////////////////////////////////////////////////////////////////////
217 /// Function :EvntWriterWorkerOnStart
218 ///////////////////////////////////////////////////////////////////////
219 EFrameworkunifiedStatus EvntWriterWorkerOnStart(HANDLE hThread) {
220 FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __PRETTY_FUNCTION__, "+");
221 EFrameworkunifiedStatus eStatus = eFrameworkunifiedStatusFail;
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);
230 FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__,
231 "Successfully read handle from FrameWork Thread.\n"); // LCOV_EXCL_BR_LINE 15:macro
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));
239 if (eFrameworkunifiedStatusOK != (eStatus = m_device_detector_obj.NotifyOnDeviceDetectionAvailability( DD_USBServiceAvailabilityCallBack))) {
240 FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__,
241 "Error: ServiceAvailabilityCallback registration failed");
244 if (eFrameworkunifiedStatusOK != (eStatus = m_device_detector_obj.NotifyOnOpenSessionAck( DD_USBOpenSessionAckCallBack))) {
245 FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__,
246 "Error: OpenSessionAckCallback registration failed");
249 if (eFrameworkunifiedStatusOK != (eStatus = m_device_detector_obj.NotifyOnCloseSessionAck( DD_USBCloseSessionAckCallBack))) {
250 FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__,
251 "Error: CloseSessionCallback registration failed");
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!");
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");
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");
275 FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __PRETTY_FUNCTION__, "-");
279 ///////////////////////////////////////////////////////////////////////
280 /// Function :EvntWriterWorkerOnStop
281 ///////////////////////////////////////////////////////////////////////
282 EFrameworkunifiedStatus EvntWriterWorkerOnStop(HANDLE hThread) {
283 FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __PRETTY_FUNCTION__, "+");
284 EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusFail;
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;
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));
306 FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __PRETTY_FUNCTION__, "-");
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__, "+");
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);
325 FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __PRETTY_FUNCTION__, "Function call without parameter");
327 FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __PRETTY_FUNCTION__, "-");
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;
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,
345 OnCmdIncrcount_phase(&cnt);
347 FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __PRETTY_FUNCTION__, "Not recieved data from q");
349 FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __PRETTY_FUNCTION__, "-");
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;
361 st_LogEvent_ss ev = { };
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);
377 FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __PRETTY_FUNCTION__, "Not recieved data from q");
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);
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));
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__, "-");
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;
413 retVal = (((var & 0xFF000000) >> 24) | ((var & 0x00FF0000) >> 8)
414 | ((var & 0x0000FF00) << 8) | ((var & 0x000000FF) << 24));
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 = { };
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);
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],
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];
453 ev.data[3] = ev_full.data[0];
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];
460 OnCmdWriteEventLogs(&ev);
462 FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "Error: Invalid event");
465 // FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __PRETTY_FUNCTION__, "-");
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;
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;
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;
495 if (filename != NULL) {
496 FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__, "Open counter file:%s", filename);
497 if (NULL != (fp = ::fopen(filename, "r"))) {
499 EStatCounterGroupID group;
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,
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);
515 FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "Normal File failed to open");
516 eStatus = eFrameworkunifiedStatusFileLoadError;
519 FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "Filename is NULL-pointer");
520 eStatus = eFrameworkunifiedStatusAccessError;
522 FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-");
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;
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);
542 FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "Written %d entries for Group 0x%02X",
543 (UI_8)count.size(), (UI_8)group);
545 FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "Group 0x%02X is empty", (UI_8)group);
548 FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "Group not found in map");
551 FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "Parameter fp is NULL-pointer");
552 eStatus = eFrameworkunifiedStatusAccessError;
554 FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-");
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__, "+");
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();
572 (void) writeGroupToFile(fp, countInfIt->first);
577 FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "Error: Not valid file");
578 eStatus = eFrameworkunifiedStatusErrNoEBADF;
580 FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-");
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]);
598 FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__,
599 "Error: EventLog buffer size greater than EVT_BUFMAXSIZE");
602 FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__, "Size of DEQUE event is :%d",
603 static_cast<int>(deque_event_info.size()));
604 FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-");
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();
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));
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__, "-");
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;
652 st_LogEvent_ss Sevent_Info;
653 DEQUE_Event_Type::iterator deque_it;
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));
664 if (0x00 != deque_it->grp_ID) {
666 != (u32File_Size = static_cast<UI_32>(::fwrite(&Sevent_Info, sizeof(Sevent_Info), 1,
668 FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "Error: Writing in to file is failed");
669 eStatus = eFrameworkunifiedStatusFail;
677 FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "Error: File failed to open");
678 eStatus = eFrameworkunifiedStatusFileLoadError;
680 FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-");
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__, "+");
692 EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK;
693 TSessionData l_stSessionData;
694 TClearEvntLogCmdResponse l_stCmdResponse;
696 if (eFrameworkunifiedStatusOK
697 != (l_eStatus = ReadMsg<TSessionData>(hThread,
698 l_stCmdResponse.stSessiondata))) {
699 LOG_ERROR("ReadMsg()");
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;
705 l_stCmdResponse.u8Response = (UI_8) CLEAR_EVENT_LOG_SUCCESS;
707 if (eFrameworkunifiedStatusOK
708 != (l_eStatus = FrameworkunifiedSendParent(hThread, eThrdCmdClearEventLogResponse,
709 sizeof(TClearEvntLogCmdResponse),
710 &l_stCmdResponse))) {
711 LOG_ERROR("FrameworkunifiedSendParent()");
714 FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-");
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;
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));
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));
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;
756 TThrdEvtLogStore evt = { };
757 if (eFrameworkunifiedStatusOK
758 != (l_eStatus = ReadMsg<TWriteFilesToUsbCmdData>(hThread, l_stCmdData))) {
759 LOG_ERROR("ReadMsg()");
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));
766 l_eStatus = eFrameworkunifiedStatusInvldID;
767 LOG_ERROR("Invalid DeviceId()");
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()");
782 FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-");
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;
797 if (hThread != NULL) {
798 TStatisticalCountersCmd l_stCmdData;
799 if (eFrameworkunifiedStatusOK
800 != (l_eStatus = ReadMsg<TStatisticalCountersCmd>(hThread, l_stCmdData))) {
801 LOG_ERROR("ReadMsg()");
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()");
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()");
828 FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-");
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;
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));
855 counterVal = countIt->second;
856 u32copy(&buffer.StatisticalCountBuffer[size], counterVal);
857 size += static_cast<UI_16>( sizeof(counterVal));
860 eStatus = eFrameworkunifiedStatusInvldBuf;
861 FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__,
862 "Error: Too many counter elements %02d > 42 ", static_cast<int>(count.size()));
865 /*OK, here: empty buffer will be returned*/
868 FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-");
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;
882 if (hThread != NULL) {
883 if (eFrameworkunifiedStatusOK
884 != (l_eStatus = ReadMsg<TStatisticalCountersCmd>(hThread, l_stCmdData))) {
885 LOG_ERROR("ReadMsg()");
887 if (eFrameworkunifiedStatusOK
888 != (l_eStatus = ResetStatisticalCounter(l_stCmdData.eGroupId))) {
889 LOG_ERROR("ResetStatisticalCounter()");
894 FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-");
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);
915 l_eStatus = eFrameworkunifiedStatusInvldID;
917 FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-");
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__, "+");
931 struct tm local_time;
934 std::string l_strVIN = f_pstrVIN;
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);
940 != (l_len = static_cast<UI_8>(strftime(tbuf, sizeof(tbuf), "%Y-%m-%dT%H%M",
942 sprintf(TempFileName, "%s_%s_%04X.dat", l_strVIN.c_str(), tbuf, // NOLINT (runtime/printf)
945 FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__, "EventLog File Name :%s, tbuf_len = %d",
946 TempFileName, l_len);
947 FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-");
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;
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;
965 // Initializing all Char arrays.
966 memset(buffer, 0, 10);
967 memset(TempFileName, 0, MAX_SYS_INFO_SIZE);
969 if (pStUSBIndo->IsDeviceAvailable == TRUE) {
970 _filename = pStUSBIndo->location;
971 OnCmdGetVIN(l_stVIN_Number);
972 _filename += _GetCurrentTimeString(TempFileName, l_stVIN_Number.VINstr);
974 if (eFrameworkunifiedStatusOK != (l_eStatus = write_event_to_file(_filename.c_str()))) {
975 FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "Error: Write to file failed:%d",
977 u8Result = (UI_8) USB_DEVICE_WRITE_ERROR;
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;
986 FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __PRETTY_FUNCTION__, "-");
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__, "+");
998 EFrameworkunifiedStatus eStatus = eFrameworkunifiedStatusOK;
999 SS_MediaDetectInfo tMediaDetectInfo = { };
1000 std::string FilePathStr;
1003 if (eFrameworkunifiedStatusOK
1004 != (eStatus = FrameworkunifiedGetMsgDataOfSize(hApp, &tMediaDetectInfo,
1005 sizeof(tMediaDetectInfo)))) {
1006 FRAMEWORKUNIFIEDLOG(ZONE_ERR, __PRETTY_FUNCTION__,
1007 "MediaDetectCallBack FrameworkunifiedGetMsgDataOfSize Failed Status:0x%x ",
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);
1018 FilePathStr.append(tMediaDetectInfo.deviceMountpath);
1020 if (tMediaDetectInfo.dev_type == eUSB) {
1021 if (tMediaDetectInfo.bIsDeviceAvailable == TRUE) {
1022 u8Pos = static_cast<UI_8>(FilePathStr.find_last_of("/\\"));
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());
1039 FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__, "USB Detected :%s", FilePathStr.c_str());
1042 u8Pos = static_cast<UI_8>(FilePathStr.find_last_of("/\\"));
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;
1051 FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__, "USB Ejected :%s", FilePathStr.c_str());
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());
1064 FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__, "SD card Ejected ");
1065 gSSDCardevInfo.IsDeviceAvailable = FALSE;
1068 FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __PRETTY_FUNCTION__, "-");
1074 //////////////////////////////////////////
1075 // Function : DD_USBServiceAvailabilityCallBack
1076 //////////////////////////////////////////
1077 EFrameworkunifiedStatus DD_USBServiceAvailabilityCallBack(HANDLE hThread) {
1078 FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+");
1079 EFrameworkunifiedStatus eStatus = eFrameworkunifiedStatusOK;
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");
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");
1093 FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-");
1097 //////////////////////////////////////////
1098 // Function : DD_USBOpenSessionAckCallBack
1099 //////////////////////////////////////////
1100 EFrameworkunifiedStatus DD_USBOpenSessionAckCallBack(HANDLE hThread) {
1101 FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+");
1102 EFrameworkunifiedStatus eStatus = eFrameworkunifiedStatusOK;
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");
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");
1120 FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "Decode open session response failed");
1122 FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-");
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 = { };
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",
1145 FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-");
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) {
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);
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);
1174 if (count_it->second != MAX_CNT_VALUE) {
1175 count_it->second += value;
1177 FRAMEWORKUNIFIEDLOG(
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);
1184 FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-");
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;
1195 if (NULL != l_evtlogbuf) {
1197 pObj->write_events_to_buffer(l_evtlogbuf);
1199 FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__,
1200 "Error: CEvntWriterWorker Object handle is NULL");
1204 FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__,
1205 "Error: New failed to allocate memory, err: %s", strerror(errno));
1207 FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-");
1208 return eFrameworkunifiedStatusOK;
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;
1217 if (eFrameworkunifiedStatusOK
1218 != (l_eStatus = FrameworkunifiedGetMsgDataOfSize(hThread, &l_u32mileage,
1219 sizeof(l_u32mileage)))) {
1220 FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "FrameworkunifiedGetMsgDataOfSize Failed Status:%d ",
1222 FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-");
1225 m_u32MileageData = l_u32mileage;
1226 FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-");
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;
1241 if (-1 != (fd = ::open(filename, O_WRONLY | O_CREAT | O_TRUNC,
1242 S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP))) {
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;
1250 FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "Error: File failed to open");
1251 eStatus = eFrameworkunifiedStatusFileLoadError;
1253 FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-");
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;
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",
1273 l_eStatus = eFrameworkunifiedStatusFail;
1275 FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__, "m_u32MileageData = %d",
1280 FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "Error: File failed to open");
1281 l_eStatus = eFrameworkunifiedStatusFileLoadError;
1284 FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "Error: Filename is NULL");
1285 l_eStatus = eFrameworkunifiedStatusNullPointer;
1287 FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-");
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;
1301 if (eFrameworkunifiedStatusOK
1302 != (l_eStatus = ReadMsg<TSessionData>(hThread,
1303 l_stEventsLogged.stSessiondata))) {
1304 LOG_ERROR("ReadMsg()");
1306 l_stEventsLogged.u16numberofeventslogged = (UI_16) deque_event_info.size();
1307 FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__, "Number of Events Read: %d",
1308 l_stEventsLogged.u16numberofeventslogged);
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);
1318 FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-");
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;
1331 if (eFrameworkunifiedStatusOK
1332 != (l_eStatus = ReadMsg<TSessionData>(
1333 hThread, m_stUploadEventLogResp.stSessiondata))) {
1334 LOG_ERROR("ReadMsg()");
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()");
1345 FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__,
1346 "Error: CEvntWriterWorker Object handle is NULL");
1350 FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-");
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;