Init basesystem source codes.
[staging/basesystem.git] / video_in_hal / systemservice / logger_service / server / src / loggerservicedebug_child_thread.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_InterfaceunifiedLogCapture
19 /// \brief    Class that threads for usb, and readers use to AGL and get
20 ///           information from the parent.
21 ///
22 ///////////////////////////////////////////////////////////////////////////////
23 // System Headers
24 #include <loggerservicedebug_thread_if.h>
25 #include <new>
26
27 const CHAR g_strLogQueReaderWorkerName[] = "pdg.LogQueR";
28 const CHAR g_strTransmitQueReaderWorkerName[] = "pdg.TransQueR";
29 const CHAR g_strPerformanceQueReaderWorkerName[] = "pdg.PerformQueR";
30 const CHAR g_strUsbEjectWorkerName[] = "pdg.UsbEject";
31 const CHAR g_strUsbLogCaptureWorkerName[] = "pdg.UsbLogCapt";
32 const CHAR g_strCaptureLogScriptExeName[] = "pdg.CaptLogScri";
33
34 LoggerserviceDebugChildThread::LoggerserviceDebugChildThread() {
35   names[LoggerserviceDebugChildThread::kLoggerserviceDebugLogQueReader] =
36       g_strLogQueReaderWorkerName;
37   names[LoggerserviceDebugChildThread::kLoggerserviceDebugTransmitQueReader] =
38       g_strTransmitQueReaderWorkerName;
39   names[LoggerserviceDebugChildThread::kLoggerserviceDebugCaptureLogScript] =
40       g_strCaptureLogScriptExeName;
41   names[LoggerserviceDebugChildThread::kLoggerservicePerformanceLogQueReader] =
42       g_strPerformanceQueReaderWorkerName;
43
44   threads[LoggerserviceDebugChildThread::kLoggerserviceDebugLogQueReader] = NULL;
45   threads[LoggerserviceDebugChildThread::kLoggerserviceDebugTransmitQueReader] = NULL;
46   threads[LoggerserviceDebugChildThread::kLoggerserviceDebugCaptureLogScript] = NULL;
47   threads[LoggerserviceDebugChildThread::kLoggerservicePerformanceLogQueReader] = NULL;
48 }  // LCOV_EXCL_BR_LINE 10:the last line
49
50 LoggerserviceDebugChildThread::~LoggerserviceDebugChildThread() {  // LCOV_EXCL_START 14:global instance
51   AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
52 }
53 // LCOV_EXCL_STOP
54
55 BOOL LoggerserviceDebugChildThread::Start(ELoggerserviceDebugThreads id, const char* parentsName,
56                                 const char * sendDataToQue,
57                                 void* (*routine)(void*),
58                                 const char * sendToUdpQue) {  // LCOV_EXCL_START 7:debug code
59   AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
60   BOOL rtn = FALSE;
61   if (id < LoggerserviceDebugChildThread::kLoggerserviceDebugMax && id > -1) {
62     if (threads[id] == NULL) {
63       if ( NULL
64           != (threads[id] = new (std::nothrow) CChild(parentsName,
65                                                       sendDataToQue,
66                                                       names[id].c_str(),
67                                                       routine, sendToUdpQue))) {
68         rtn = TRUE;
69       }
70     } else {
71       rtn = TRUE;
72     }
73   }
74
75   return rtn;
76 }
77 // LCOV_EXCL_STOP
78
79 void LoggerserviceDebugChildThread::Stop(ELoggerserviceDebugThreads id) {  // LCOV_EXCL_START 7:debug code
80   AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
81   if (id < LoggerserviceDebugChildThread::kLoggerserviceDebugMax && id > -1) {
82     if (threads[id] != NULL) {
83       delete threads[id];
84       threads[id] = NULL;
85     }
86   }
87 }
88 // LCOV_EXCL_STOP
89
90 BOOL LoggerserviceDebugChildThread::Running(ELoggerserviceDebugThreads id) const {  // LCOV_EXCL_START 7:debug code
91   AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
92   BOOL rtn = FALSE;
93   if (id < LoggerserviceDebugChildThread::kLoggerserviceDebugMax && id > -1) {
94     if (threads[id] != NULL) {
95       rtn = TRUE;
96     }
97   }
98
99   return rtn;
100 }
101 // LCOV_EXCL_STOP
102
103 void LoggerserviceDebugChildThread::StopAll() {  // LCOV_EXCL_START 7:debug code
104   AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
105   for (int id = kLoggerserviceDebugLogQueReader; id < kLoggerserviceDebugMax; id++) {
106     if (threads[id] != NULL) {
107       threads[id]->Join();
108       delete threads[id];
109       threads[id] = NULL;
110     }
111   }
112 }
113 // LCOV_EXCL_STOP
114
115 const char * LoggerserviceDebugChildThread::Name(ELoggerserviceDebugThreads id) {  // LCOV_EXCL_START 7:debug code
116   AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
117   if (id < LoggerserviceDebugChildThread::kLoggerserviceDebugMax && id > -1) {
118     return names[id].c_str();
119   }
120
121   return NULL;
122 }
123 // LCOV_EXCL_STOP
124
125 void LoggerserviceDebugChildThread::LiftWaitBarrier(ELoggerserviceDebugThreads id) {  // LCOV_EXCL_START 7:debug code
126   AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
127   if (id < LoggerserviceDebugChildThread::kLoggerserviceDebugMax && id > -1) {
128     if (threads[id] != NULL) {
129       threads[id]->IsValidWaitBarrier();
130     }
131   }
132 }
133 // LCOV_EXCL_STOP
134