Remove unused directories and files in video_in_hal
[staging/basesystem.git] / service / system / logger_service / server / include / loggerservicedebug_writer_Evntworker.h
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 #ifndef LOGGER_SERVICE_SERVER_INCLUDE_LOGGERSERVICEDEBUG_WRITER_EVNTWORKER_H_
24 #define LOGGER_SERVICE_SERVER_INCLUDE_LOGGERSERVICEDEBUG_WRITER_EVNTWORKER_H_
25
26 #include <stdlib.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>
33 #include <map>
34 #include <iostream>
35 #include <deque>
36 #include "loggerservicedebug_thread_if.h"
37
38
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[];
47
48 typedef struct _TevntWriterInfo {
49   static const UI_32 FN_LEN = 256;
50   UI_32 max_filelen;
51   CHAR base_cnt_filename[FN_LEN];
52   CHAR mileage_filename[FN_LEN];
53 } TEvntWriterInfo;
54
55 typedef enum _eDatatype_ {
56   COMMON_DATA,
57   EVENT_SPECIFIC_DATA
58 } EDatatype_SS;
59
60 typedef enum _eSystemPhase_ {
61   STARTUP_SS = 0x21,
62   NORMAL_SS = 0x22,
63   SHUTDOWN_SS = 0x23
64 } ESystemPhase_SS;
65
66 #pragma pack(1)
67 typedef struct _stLogEventFull_ {
68   UI_32 ts;
69   UI_8 grp_ID;
70   UI_8 event_id;
71   UI_8 data[4];
72   ESystemPhase_SS phase;
73   UI_16 cnt_ID;
74   EDatatype_SS typeofdata;
75 } st_LogEvent_full;
76 #pragma pack(0)
77
78 // Deque to hold the Event information
79 typedef std::deque<st_LogEvent_ss> DEQUE_Event_Type;
80
81 // Map to hold the Counter information on phase
82 typedef std::map<UI_16, UI_32> Counter;
83
84 /*Map to hold the all the counter information */
85 typedef std::map<EStatCounterGroupID, Counter> CounterInformation;
86
87 class CEvntWriterWorker {
88  public:
89   CEvntWriterWorker();
90   CEvntWriterWorker(TEvntWriterInfo & wi);  // NOLINT (runtime/references)
91   virtual ~CEvntWriterWorker();
92   // initialize the object
93   EFrameworkunifiedStatus Initialize(HANDLE hThread);
94
95   /// Copy event logs to USB request from parent thread
96   EFrameworkunifiedStatus OnCmdWriteEventFilesToUsb(HANDLE hThread);
97
98   /// Event logging request from NS logger
99   EFrameworkunifiedStatus OnCmdEventLog(UI_8* pbuf);
100
101   /// Clear event logs request from parent thread
102   EFrameworkunifiedStatus OnCmdClearEventLogs(HANDLE hThread);
103
104   /// Read statistical counter request from parent thread
105   EFrameworkunifiedStatus OnCmdReadStatisticalCounter(HANDLE hThread);
106
107   /// Read statistical counter based on counter group ID
108   EFrameworkunifiedStatus ReadStatisticalCounter(EStatCounterGroupID eStatCounterGroupID,
109                                     SStatisticalCounter& buffer);  // NOLINT (runtime/references)
110
111   /// Reset statistical counter request from parent thread
112   EFrameworkunifiedStatus OnCmdResetStatisticalCounter(HANDLE hThread);
113
114   /// Reset statistical counter based on counter group ID
115   EFrameworkunifiedStatus ResetStatisticalCounter(EStatCounterGroupID eStatCounterGroupID);
116
117   EFrameworkunifiedStatus OnCmdStop(HANDLE hThread);
118
119   EFrameworkunifiedStatus OnCmdStart(HANDLE hThread);
120
121   /// Counter logging request from NS logger
122   EFrameworkunifiedStatus OnCmdIncrcount(UI_8* pbuf);
123
124   /// Event and Counter logging request from NS logger
125   EFrameworkunifiedStatus OnCmdIncrwriteevent(UI_8* pbuf);
126
127   /// Reading counter value from file based on phase
128   EFrameworkunifiedStatus readCountFromFile(PCSTR filename);
129
130   /// Writing counter value from file based on phase
131   EFrameworkunifiedStatus writeCountToFile(PCSTR filename);
132
133   /// Writing event value from file based on phase
134   EFrameworkunifiedStatus write_event_to_file(const CHAR* filename);
135
136   /// Copy event files to USB based onUSB device number
137   UI_8 copy_event_files_to_usb(TThrdEvtLogStore *pStUSBIndo);
138
139   /// Functioncall to populate the counter value to map
140   VOID OnCmdIncrcount_phase(st_LogCount *cnt);
141
142   /// Function call to populate the event value to deque
143   VOID OnCmdWriteEventLogs(st_LogEvent_ss *ev);
144
145   /// Set the VIN number
146   EFrameworkunifiedStatus OnCmdSetVIN(HANDLE hThread);
147
148   /// Get the VIN number
149   VOID OnCmdGetVIN(STVIN_NUMBER& f_stVIN_Number);  // NOLINT (runtime/references)
150
151   /// Functional call to write events from deque to local buffer
152   VOID write_events_to_buffer(STEventLogPersistBuffer* f_stEvtLogBuf);
153
154   /// Functional call to read events from buffer to deque
155   VOID read_events_from_buffer(STEventLogPersistBuffer* f_stEvtLogBuf);
156
157   /// Functional call to immediate persist event log
158   EFrameworkunifiedStatus immediate_persist_event_log(HANDLE hThread);
159
160   /// Functional call to set mileage information in Evt thread space
161   EFrameworkunifiedStatus EvtThd_SetMileage(HANDLE hThread);
162
163   /// Functional call to write mileage data to file for persisting
164   EFrameworkunifiedStatus write_mileage_to_file(const CHAR* filename);
165
166   /// Functional call to read mileage data from persistent file during startup
167   EFrameworkunifiedStatus read_mileage_from_file(const CHAR* filename);
168
169   EFrameworkunifiedStatus OnCmdReadNumberOfEventsLogged(HANDLE hThread);
170
171   EFrameworkunifiedStatus EventLogRegisterCbHandlers(HANDLE hThread);
172
173   EFrameworkunifiedStatus OnCmdUploadEventLog(HANDLE hThread);
174
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;
179
180  private:
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,
186                                      UI_32 value);
187   EFrameworkunifiedStatus writeGroupToFile(FILE *fp, EStatCounterGroupID group);
188 };
189
190 /// Event logging Child thread start and shut down functions
191 EFrameworkunifiedStatus EvntWriterWorkerOnStart(HANDLE hThread);
192 EFrameworkunifiedStatus EvntWriterWorkerOnStop(HANDLE hThread);
193
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);
199
200 inline void u16copy(PUI_8 pDest, UI_16 Source) {
201   *(pDest++) = (UI_8) (Source & 0x00FF);
202   *(pDest++) = (UI_8) ((Source & 0xFF00) >> 8);
203 }
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);
209 }
210
211 #endif  // LOGGER_SERVICE_SERVER_INCLUDE_LOGGERSERVICEDEBUG_WRITER_EVNTWORKER_H_