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 This file supports the logging thread interface.
21 ///////////////////////////////////////////////////////////////////////////////
22 #ifndef LOGGER_SERVICE_SERVER_INCLUDE_LOGGERSERVICEDEBUG_THREAD_IF_H_
23 #define LOGGER_SERVICE_SERVER_INCLUDE_LOGGERSERVICEDEBUG_THREAD_IF_H_
28 #include <sys/neutrino.h>
29 #include <sys/dispatch.h>
34 #include <native_service/frameworkunified_types.h>
35 #include <native_service/frameworkunified_thread_priority.h>
36 #include <system_service/ss_logger_service.h>
37 #include <system_service/ss_logger_service_local.h>
39 #include "loggerservicedebug_loggerservicelog.h"
41 typedef std::string ThreadName; //< service name
43 typedef enum _EThreadCommandIds {
44 eThrdCmdUsbEject = 5463, ///< USB eject --> frameworkunifieddebug
45 eThrdCmdUsbCaptureLogs, ///< USB Capture log --> frameworkunifieddebug
46 eThrdCmdUsbStoreLogs, ///< USB Store log --> frameworkunifieddebug
47 eThrdCmdWriteFilesToUsb, ///< frameworkunifieddebug --> Writer
48 eThrdCmdWriteDataToFile, ///< Reader --> Writer
49 eThrdCmdWriterStop, ///< frameworkunifieddebug --> Writer (Stop writing to the file)
50 eThrdCmdWriterResume, ///< frameworkunifieddebug --> Writer (Continue writing to the file)
51 eThrdCmdCaptureLogScriptExit, ///< LogCaptureScript - > frameworkunifieddebug
52 eThrdCmdWriteEvntFilesToUsb, ///< Wreite Event files to USB
54 eThrdCmdClearEvntLogs, ///< Clear event logs
55 eThrdCmdStatisticalCounter, ///< Read statistical counter
56 eThrdCmdStatisticalCounterSuccessResp, ///< Statistical counter positiv Response from child thread
57 eThrdCmdStatisticalCounterErrorResp, ///< Statistical counter Negative Response from child thread
58 eThrdCmdResetStatisticalCntrs,
59 eThrdCmdCopyEventLogUSBResponse, ///< Copy event logs to usb response from child thread
60 eThrdCmdClearEventLogResponse, ///< Clear event logs response fromchild thread
61 eThrdCmdPersistLogs, ///< Statistical counter Response fromchild thread
63 eThrdCmdImmPersistEvtLog,
65 eThrdCmdGetNumberOfEventsLogged,
66 eThrdCmdNumberOfEventsLoggedResponse,
67 eThrdCmdUploadEventLog,
68 eThrdCmdUploadEventLogResponse,
69 eThrdCmdCopyEvntLogToTmp,
70 eThrdCmdCopyEvntLogToTmpResponse
73 typedef struct _TThrdWriteDataToFileEvt {
74 static const UI_32 LN_LEN = 1024;
77 } TThrdWriteLogDataToFileEvt, TThrdWriteTransmitDataToFileEvt;
79 typedef struct _TThrdWriteFilesToUsbEvt {
80 static const UI_32 LOC_PATH_LEN = 256;
81 CHAR location[LOC_PATH_LEN]; ///< full path where files should be copied too
83 } TThrdWriteLogFilesToUsbEvt, TThrdWriteTransmitFilesToUsbEvt;
85 typedef struct _TThrdCaptureLogsEvt {
86 static const UI_32 FN_LEN = 256;
87 CHAR location[FN_LEN];
88 CHAR parse_fn[FN_LEN]; ///< full path an name of the file that should be parsed for event actions.
89 } TThrdCaptureLogsEvt;
91 // Structure to hold the USB device informaton
92 typedef struct _TThrdEvtLogStore {
93 BOOL IsDeviceAvailable;
94 static const UI_32 FN_LEN = 256;
95 CHAR location[FN_LEN];
96 CHAR parse_fn[FN_LEN]; ///< full path an name of the file that should be parsed for event actions.
99 typedef struct _TInitFlag {
100 UI_8 mileage_flagbit :1;
101 UI_8 statcounter_flagbit :1;
102 UI_8 eventlog_flagbit :1;
103 UI_8 reghandlers_flagbit :1;
106 typedef struct _TSessionData {
107 std::string strSrcName;
111 typedef struct _TEvntNumber {
112 TSessionData stSessiondata;
113 UI_16 u16numberofeventslogged;
116 typedef struct _TWriteFilesToUsbCmdData {
117 TSessionData stSessiondata;
118 EEvtLogUSBDevNumber eDevId;
119 } TWriteFilesToUsbCmdData;
121 typedef struct _TWriteFilesToUsbCmdResponse {
122 TSessionData stSessiondata;
124 } TWriteFilesToUsbCmdResponse;
126 typedef struct _TClearEvntLogCmdResponse {
127 TSessionData stSessiondata;
129 } TClearEvntLogCmdResponse;
131 typedef struct _TStatisticalCountersCmd {
132 TSessionData stSessiondata;
133 EStatCounterGroupID eGroupId;
134 } TStatisticalCountersCmd;
136 typedef struct _TStatisticalCntCmdSuccessResp {
137 TSessionData stSessiondata;
138 SStatisticalCounter stBuffer;
139 } TStatisticalCntCmdSuccessResp;
141 typedef struct _TUploadEventLogResp {
142 TSessionData stSessiondata;
143 STEventLogPersistBuffer stEventLogBuffer;
144 } TUploadEventLogResp;
146 typedef struct _TEventLogCopyStatus {
147 static const UI_8 FilePathSize = 64;
148 CHAR EventLogFilePath[FilePathSize];
150 } TEventLogCopyStatus;
152 typedef enum _ECaptureLogScriptResp {
153 ekCLSStatusCompleteSuccessful,
154 ekCLSStatusInitError,
155 ekCLSStatusExecuteError,
156 ekCLSStatusCopyError,
157 ekCLSStatusChmodError,
158 } ECaptureLogScriptResp;
160 class ThreadWrapper {
163 ThreadWrapper(const char* t_name, void* (*routine)(void*), void* arg) { // LCOV_EXCL_START 8:ThreadWrapper class is never used
164 AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert
166 struct sched_param params;
168 if (EOK != pthread_attr_init(&attr)) {
169 FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__,
170 "Error: pthread_attr_init failed errno: %d", errno);
172 if (EOK != pthread_attr_getschedparam(&attr, ¶ms)) {
173 FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__,
174 "Error: pthread_attr_getschedparam failed errno: %d", errno);
176 SI_32 prio = frameworkunified::framework::CFrameworkunifiedThreadPriorities::GetPriority(
177 std::string(t_name));
179 params.sched_priority = prio;
180 if (EOK != pthread_attr_setinheritsched(&attr, PTHREAD_EXPLICIT_SCHED)) {
181 FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__,
182 "Error: pthread_attr_setinheritsched failed errno: %d", errno);
184 if (EOK != pthread_attr_setschedparam(&attr, ¶ms)) {
185 FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__,
186 "Error: pthread_attr_setschedparam failed errno: %d", errno);
190 if (EOK != pthread_create(&m_thread, &attr, routine, arg)) {
191 FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "Error: pthread_create failed errno: %d",
198 ~ThreadWrapper() { // LCOV_EXCL_START 8:ThreadWrapper class is never used
199 AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert
200 // todo: Need a clean way to cleanup thread in case class closes
205 operator pthread_t() const { // LCOV_EXCL_START 8:ThreadWrapper class is never used
206 AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert
218 CChild(const char* parentsName, const char * sendDataToQue,
219 const char * clientsName, void* (*routine)(void*),
220 const char * sendToUdpQue = "")
221 : m_clientName(clientsName),
222 m_parentName(parentsName),
223 m_sendDataToQueuName(sendDataToQue),
224 m_sendDataToUdpQueName(sendToUdpQue),
225 m_barInit(InitBarrier()),
226 m_thread(clientsName, routine, reinterpret_cast<void*>(this)) { // LCOV_EXCL_START 7:debug code
227 AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert
231 void Join() { // LCOV_EXCL_START 7:debug code
232 AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert
233 if (EOK != pthread_join(m_thread, NULL)) {
234 FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "Error: pthread_join failed errno: %d",
240 const char * ParentName() { // LCOV_EXCL_START 7:debug code
241 AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert
242 return m_parentName.c_str();
246 const char * ClientName() { // LCOV_EXCL_START 7:debug code
247 AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert
248 return m_clientName.c_str();
252 const char * SendDataToQue() { // LCOV_EXCL_START 7:debug code
253 AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert
254 return m_sendDataToQueuName.c_str();
258 const char * SendDataToUdpQueue() { // LCOV_EXCL_START 7:debug code
259 AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert
260 return m_sendDataToUdpQueName.c_str();
264 bool IsValidWaitBarrier() { // LCOV_EXCL_START 7:debug code
265 AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert
267 int wbret = pthread_barrier_wait(&m_barrier);
268 return ( PTHREAD_BARRIER_SERIAL_THREAD == wbret) || (0 == wbret);
276 bool InitBarrier() { // LCOV_EXCL_START 7:debug code
277 AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert
278 /// Note: the count value should match the number of threads that are readers and usb notifiers
279 return (EOK == pthread_barrier_init(&m_barrier, NULL, 2) ? true : false);
284 ThreadName m_clientName;
285 ThreadName m_parentName;
286 ThreadName m_sendDataToQueuName;
287 ThreadName m_sendDataToUdpQueName;
289 ThreadWrapper m_thread;
290 pthread_barrier_t m_barrier;
293 class LoggerserviceDebugChildThread {
296 kLoggerserviceDebugLogQueReader,
297 kLoggerserviceDebugTransmitQueReader,
298 kLoggerservicePerformanceLogQueReader,
299 kLoggerserviceDebugCaptureLogScript,
300 kLoggerserviceDebugEventLogque,
301 kLoggerserviceDebugMax
302 } ELoggerserviceDebugThreads;
304 LoggerserviceDebugChildThread();
305 virtual ~LoggerserviceDebugChildThread();
306 BOOL Start(ELoggerserviceDebugThreads id, const char* parentsName,
307 const char * sendDataToQue, void* (*routine)(void*),
308 const char * sendToUdpQue = "");
309 void Stop(ELoggerserviceDebugThreads id);
311 const char * Name(ELoggerserviceDebugThreads id);
312 void LiftWaitBarrier(ELoggerserviceDebugThreads id);
313 BOOL Running(ELoggerserviceDebugThreads id) const;
315 ThreadName names[kLoggerserviceDebugMax];
316 CChild * threads[kLoggerserviceDebugMax];
319 #endif // LOGGER_SERVICE_SERVER_INCLUDE_LOGGERSERVICEDEBUG_THREAD_IF_H_