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 ///////////////////////////////////////////////////////////////////////////////
23 #ifndef LOGGER_SERVICE_SERVER_INCLUDE_LOGGERSERVICEDEBUG_WRITER_EVNTWORKER_H_
24 #define LOGGER_SERVICE_SERVER_INCLUDE_LOGGERSERVICEDEBUG_WRITER_EVNTWORKER_H_
27 #include <native_service/frameworkunified_types.h>
28 #include <native_service/frameworkunified_framework_if.h>
29 #include <native_service/frameworkunified_multithreading.h>
30 #include <system_service/ss_devicedetection_service_ifc.h>
31 #include <native_service/ns_logger_if.h>
32 #include <native_service/ns_eventlogger.h>
36 #include "loggerservicedebug_thread_if.h"
39 // File path names for Evnet and counter logs
40 extern const CHAR DEBUG_EVNTLOG_PATH_FN[];
41 extern const CHAR g_strEvntLogQueWorkerName[];
42 extern const CHAR DEBUG_LOG_PATH_FN[];
43 extern const CHAR Counter_LOG_PATH_FN[];
44 extern const CHAR Counter_LOG_PATH_STARTFN[];
45 extern const CHAR Counter_LOG_PATH_SHUTFN[];
46 extern const CHAR Mileage_LOG_PATH_FN[];
48 typedef struct _TevntWriterInfo {
49 static const UI_32 FN_LEN = 256;
51 CHAR base_cnt_filename[FN_LEN];
52 CHAR mileage_filename[FN_LEN];
55 typedef enum _eDatatype_ {
60 typedef enum _eSystemPhase_ {
67 typedef struct _stLogEventFull_ {
72 ESystemPhase_SS phase;
74 EDatatype_SS typeofdata;
78 // Deque to hold the Event information
79 typedef std::deque<st_LogEvent_ss> DEQUE_Event_Type;
81 // Map to hold the Counter information on phase
82 typedef std::map<UI_16, UI_32> Counter;
84 /*Map to hold the all the counter information */
85 typedef std::map<EStatCounterGroupID, Counter> CounterInformation;
87 class CEvntWriterWorker {
90 CEvntWriterWorker(TEvntWriterInfo & wi); // NOLINT (runtime/references)
91 virtual ~CEvntWriterWorker();
92 // initialize the object
93 EFrameworkunifiedStatus Initialize(HANDLE hThread);
95 /// Copy event logs to USB request from parent thread
96 EFrameworkunifiedStatus OnCmdWriteEventFilesToUsb(HANDLE hThread);
98 /// Event logging request from NS logger
99 EFrameworkunifiedStatus OnCmdEventLog(UI_8* pbuf);
101 /// Clear event logs request from parent thread
102 EFrameworkunifiedStatus OnCmdClearEventLogs(HANDLE hThread);
104 /// Read statistical counter request from parent thread
105 EFrameworkunifiedStatus OnCmdReadStatisticalCounter(HANDLE hThread);
107 /// Read statistical counter based on counter group ID
108 EFrameworkunifiedStatus ReadStatisticalCounter(EStatCounterGroupID eStatCounterGroupID,
109 SStatisticalCounter& buffer); // NOLINT (runtime/references)
111 /// Reset statistical counter request from parent thread
112 EFrameworkunifiedStatus OnCmdResetStatisticalCounter(HANDLE hThread);
114 /// Reset statistical counter based on counter group ID
115 EFrameworkunifiedStatus ResetStatisticalCounter(EStatCounterGroupID eStatCounterGroupID);
117 EFrameworkunifiedStatus OnCmdStop(HANDLE hThread);
119 EFrameworkunifiedStatus OnCmdStart(HANDLE hThread);
121 /// Counter logging request from NS logger
122 EFrameworkunifiedStatus OnCmdIncrcount(UI_8* pbuf);
124 /// Event and Counter logging request from NS logger
125 EFrameworkunifiedStatus OnCmdIncrwriteevent(UI_8* pbuf);
127 /// Reading counter value from file based on phase
128 EFrameworkunifiedStatus readCountFromFile(PCSTR filename);
130 /// Writing counter value from file based on phase
131 EFrameworkunifiedStatus writeCountToFile(PCSTR filename);
133 /// Writing event value from file based on phase
134 EFrameworkunifiedStatus write_event_to_file(const CHAR* filename);
136 /// Copy event files to USB based onUSB device number
137 UI_8 copy_event_files_to_usb(TThrdEvtLogStore *pStUSBIndo);
139 /// Functioncall to populate the counter value to map
140 VOID OnCmdIncrcount_phase(st_LogCount *cnt);
142 /// Function call to populate the event value to deque
143 VOID OnCmdWriteEventLogs(st_LogEvent_ss *ev);
145 /// Set the VIN number
146 EFrameworkunifiedStatus OnCmdSetVIN(HANDLE hThread);
148 /// Get the VIN number
149 VOID OnCmdGetVIN(STVIN_NUMBER& f_stVIN_Number); // NOLINT (runtime/references)
151 /// Functional call to write events from deque to local buffer
152 VOID write_events_to_buffer(STEventLogPersistBuffer* f_stEvtLogBuf);
154 /// Functional call to read events from buffer to deque
155 VOID read_events_from_buffer(STEventLogPersistBuffer* f_stEvtLogBuf);
157 /// Functional call to immediate persist event log
158 EFrameworkunifiedStatus immediate_persist_event_log(HANDLE hThread);
160 /// Functional call to set mileage information in Evt thread space
161 EFrameworkunifiedStatus EvtThd_SetMileage(HANDLE hThread);
163 /// Functional call to write mileage data to file for persisting
164 EFrameworkunifiedStatus write_mileage_to_file(const CHAR* filename);
166 /// Functional call to read mileage data from persistent file during startup
167 EFrameworkunifiedStatus read_mileage_from_file(const CHAR* filename);
169 EFrameworkunifiedStatus OnCmdReadNumberOfEventsLogged(HANDLE hThread);
171 EFrameworkunifiedStatus EventLogRegisterCbHandlers(HANDLE hThread);
173 EFrameworkunifiedStatus OnCmdUploadEventLog(HANDLE hThread);
175 EFrameworkunifiedStatus OnCmdCopyEvntLogToTmp(HANDLE hThread);
176 /// Static Members for Event and counter logging
177 static CounterInformation counter;
178 static DEQUE_Event_Type deque_event_info;
181 STVIN_NUMBER m_stVINnumber;
182 UI_32 m_u32MileageData;
183 UI_32 m_u32NumberEventsLogged;
184 TUploadEventLogResp m_stUploadEventLogResp;
185 EFrameworkunifiedStatus counterIncrementByValue(EStatCounterGroupID group, UI_16 id,
187 EFrameworkunifiedStatus writeGroupToFile(FILE *fp, EStatCounterGroupID group);
190 /// Event logging Child thread start and shut down functions
191 EFrameworkunifiedStatus EvntWriterWorkerOnStart(HANDLE hThread);
192 EFrameworkunifiedStatus EvntWriterWorkerOnStop(HANDLE hThread);
194 /// USBdevice detectioncall backs
195 EFrameworkunifiedStatus DD_USBSrvDetectionCallBack(HANDLE hApp);
196 EFrameworkunifiedStatus DD_USBServiceAvailabilityCallBack(HANDLE hThread);
197 EFrameworkunifiedStatus DD_USBOpenSessionAckCallBack(HANDLE hThread);
198 EFrameworkunifiedStatus DD_USBCloseSessionAckCallBack(HANDLE hApp);
200 inline void u16copy(PUI_8 pDest, UI_16 Source) {
201 *(pDest++) = (UI_8) (Source & 0x00FF);
202 *(pDest++) = (UI_8) ((Source & 0xFF00) >> 8);
204 inline void u32copy(PUI_8 pDest, UI_32 Source) {
205 *(pDest++) = (UI_8) (Source & 0x000000FF);
206 *(pDest++) = (UI_8) ((Source & 0x0000FF00) >> 8);
207 *(pDest++) = (UI_8) ((Source & 0x00FF0000) >> 16);
208 *(pDest++) = (UI_8) ((Source & 0xFF000000) >> 24);
211 #endif // LOGGER_SERVICE_SERVER_INCLUDE_LOGGERSERVICEDEBUG_WRITER_EVNTWORKER_H_