Remove unused directories and files in video_in_hal
[staging/basesystem.git] / service / system / task_manager / server / src / tskm_port_subsys.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 #include "tskm_port_subsys.h"
18 #include <pthread.h>
19 #include <string.h>
20 #include <stdlib.h>
21 #include <errno.h>
22
23 #include <native_service/cl_monitor.h>
24 #include <system_service/ss_sm_client_if.h>
25 #include <system_service/resm.h>
26 //#include <stub/ss_diag.h>
27 #include <string>
28
29 #include "agl_thread.h"
30
31 #include "tskm_main.h"
32 #include "tskm_debug.h"
33 #include "tskm_util.h"
34 #include "tskm_port_pf.h"
35
36
37 #ifndef oops_name2pid
38   #define oops_name2pid(processname) syscall(OOPSTRACE_SYSCALL, 17, processname)
39 #endif
40
41
42 typedef struct {
43   CL_MonitorSearch_t clMonSearch;
44   uint32_t resmId;        // Session ID of RESM
45 } SUB_SYS_CTX_t;
46
47 static SUB_SYS_CTX_t g_sub;
48
49 /******************************************************************
50  *        Subsystem initialization
51  ******************************************************************/
52 int tskm_sub_init(void) {
53   int clRet;
54   SUB_SYS_CTX_t* p_ctx = &g_sub;
55
56   clRet = CL_MonitorSearchInit(&p_ctx->clMonSearch);
57   if (clRet != 0) {  // LCOV_EXCL_BR_LINE 6: For processing intializing process
58     // LCOV_EXCL_START 6:For processing initializing process
59     AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
60     TSKM_ASSERT_ERRNO(0);
61     goto ERROR;
62     // LCOV_EXCL_STOP 6: For processing initializing process
63   }
64
65   return 0;
66   // LCOV_EXCL_START 6:For processing initializing process
67   ERROR:
68   AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
69   return 1;
70   // LCOV_EXCL_STOP
71 }
72
73 /******************************************************************
74  *        Subsystem termination
75  ******************************************************************/
76 int tskm_sub_term(void) {
77   int ret;
78   SUB_SYS_CTX_t* p_ctx = &g_sub;
79
80   ret = CL_MonitorSearchDestroy(&p_ctx->clMonSearch);
81   if (ret != 0) {
82     TSKM_ASSERT_ERRNO(0);
83   }
84
85   return 0;
86 }
87 /*********************************************************
88  *        REBOOT
89  *********************************************************/
90 void tskm_sub_reboot(const TSKM_ERROR_REBOOT_t* p_info) {
91   EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK;
92
93   TSKM_ASSERT(0);
94
95   l_eStatus = SendCpuResetRequestToSystemManager(
96       e_SS_SM_CPU_RESET_REASON_GENERIC_ERR, p_info->log.messageStr);
97   if (eFrameworkunifiedStatusOK != l_eStatus) {
98     TSKM_ASSERT(0);
99   }
100 }
101
102 /*********************************************************
103  *        REBOOT NORMAL
104  *********************************************************/
105 void tskm_sub_reboot_normal(void) {
106   EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK;
107
108   l_eStatus = SendCpuResetRequestToSystemManager(
109       e_SS_SM_CPU_RESET_REASON_NORMAL);
110   if (l_eStatus != eFrameworkunifiedStatusOK) {
111     TSKM_ASSERT(0);
112   }
113 }
114
115 /*********************************************************
116  *        LOGGING
117  *********************************************************/
118 void tskm_sub_logging(const TSKM_LOGGING_INFO_t* p_info) {
119   EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK;
120   eSMUserLogType l_eType;
121
122   switch (p_info->type) {
123     case TSKM_LOGGING_TYPE_GRP_RELAUNCH:
124       l_eType = e_SS_SM_CAPTURE_GROUP_RELAUNCH;
125       break;
126     case TSKM_LOGGING_TYPE_MODULE_LOGS:
127     default:
128       l_eType = e_SS_SM_CAPTURE_MODULE_LOGS;
129       break;
130   }
131
132   l_eStatus = SendUserInvokedLoggingRequestToSystemManager(l_eType,
133                                                            p_info->messageStr);
134   if (eFrameworkunifiedStatusOK != l_eStatus) {
135     TSKM_ASSERT(0);
136   }
137 }
138
139 /*********************************************************
140  *        DEBUG DUMP
141  *********************************************************/
142 void tskm_sub_debugDumpRes(BOOL bIsNeedSvcName, const char *p_dumpMsg) {
143   if (bIsNeedSvcName) {  // LCOV_EXCL_BR_LINE 8: As the bIsNeedSvcName is set to FALSE only
144     AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
145     SSDEBUGDUMP("%s", p_dumpMsg);  // LCOV_EXCL_LINE 8: As the bIsNeedSvcName is set to FALSE only
146   } else {
147     SSDEBUGDUMP_RAW("%s", p_dumpMsg);
148   }
149 }
150
151 /*********************************************************
152  *        EXT BOOT INFO
153  *********************************************************/
154 int tskm_sub_getExtBootInfo(T_SS_SM_START_ExtDataStructType *p_info) {
155   EFrameworkunifiedStatus l_eStatus;
156   T_SS_SM_START_ExtDataStructType extStartupInfo;
157
158   l_eStatus = GetInterfaceunifiedOnStartExtInfo(extStartupInfo);
159   if (l_eStatus != eFrameworkunifiedStatusOK) {
160     TSKM_ASSERT(0);
161     goto ERROR;
162   }
163
164   memcpy(p_info, &extStartupInfo, sizeof(extStartupInfo));
165
166   return 0;
167   ERROR: return -1;
168 }
169
170 /*********************************************************
171  *        Service Error Monitoring Check
172  *********************************************************/
173 TSKM_HUNG_INFO_t*
174 tskm_sub_searchHungSvcs() {
175   int ret;
176   TSKM_HUNG_INFO_t *p_hungList = NULL;
177   SUB_SYS_CTX_t* p_ctx = &g_sub;
178
179   ret = CL_MonitorSearchTimeout(&p_ctx->clMonSearch);
180   if (ret == -1) {
181     TSKM_ASSERT_ERRNO(0);
182     goto ERROR;
183   }
184
185   if (0 < p_ctx->clMonSearch.entry_num) {
186     int ii;
187
188     TSKM_PRINTF(TSKM_LOG_DEBUG, "TimeoutSvcNum = %d",
189                 p_ctx->clMonSearch.entry_num);
190
191     if (NULL == p_ctx->clMonSearch.entry_list) {
192       TSKM_ASSERT(0);
193       goto ERROR;
194     }
195
196     p_hungList = (TSKM_HUNG_INFO_t *) malloc(  // NOLINT (readability/casting)
197         sizeof(TSKM_HUNG_INFO_t) * (p_ctx->clMonSearch.entry_num + 1));
198     if (p_hungList == NULL) {  // LCOV_EXCL_BR_LINE 5: malloc's error case.
199       // LCOV_EXCL_START 5: Checked in Death testing, but it is not reflected in the coverage and excluded
200       AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
201       TSKM_ASSERT_ERRNO(0);
202       goto ERROR;
203       // LCOV_EXCL_STOP
204     }
205
206     for (ii = 0; ii < p_ctx->clMonSearch.entry_num; ii++) {
207       p_hungList[ii].pid = p_ctx->clMonSearch.entry_list[ii].pid;
208       p_hungList[ii].type = p_ctx->clMonSearch.entry_list[ii].type;
209     }
210     // set "-1" to pid at the end of list.
211     p_hungList[p_ctx->clMonSearch.entry_num].pid = -1;
212   }
213
214   ERROR: return p_hungList;
215 }
216
217 /*********************************************************
218  *        RESM Initialization
219  *********************************************************/
220 int tskm_sub_resmInit(void) {  // LCOV_EXCL_START 6: Because the condition cannot be set
221   AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
222   int redmFd;
223   SUB_SYS_CTX_t* p_ctx = &g_sub;
224   RESM_ERR_t resmRet = RESM_E_OK;
225   RESM_REQ_EVENT_t ev;
226
227   int pid;
228
229   resmRet = RESM_Open(NULL, &(p_ctx->resmId));
230   if (RESM_E_OK != resmRet) {
231     TSKM_ASSERT(0);
232
233 #warning RESM backtrace disabled, because 'print_backtrace_pid' not support.
234 #if 0
235     // Backtrace outoutput of the RESM
236     pid = oops_name2pid(MN_SS_RESOURCEMGR);
237     if(pid > 0){
238       TSKM_ASSERT(-1 != print_backtrace_pid(pid));
239     }else{
240       TSKM_PRINTF(TSKM_LOG_ERROR, "ERR : oops_name2pid %d , err:%d, msg:%s",
241                   pid, errno, strerror(errno));
242     }
243 #endif
244
245     goto ERROR;
246   }
247
248   resmRet = RESM_GetEventFd(p_ctx->resmId, &redmFd);
249   if (RESM_E_OK != resmRet) {
250     TSKM_ASSERT(0);
251     goto ERROR;
252   }
253
254   ev.reqEvent = RESM_EV_MEM;
255   ev.prm.restMemThresh = 512;  // Threshold(BYTE)
256
257   resmRet = RESM_ReqEvent(p_ctx->resmId, &ev);
258   if (RESM_E_OK != resmRet) {
259     TSKM_ASSERT(0);
260     goto ERROR;
261   }
262
263   return redmFd;
264   ERROR: return -1;
265 }
266 // LCOV_EXCL_STOP
267 /*********************************************************
268  *        Get EV of RESM
269  *********************************************************/
270 int tskm_sub_resmRcv(TSKM_EVENT_INFO_t* p_ev) {
271   SUB_SYS_CTX_t* p_ctx = &g_sub;
272   RESM_ERR_t resmRet = RESM_E_OK;
273   RESM_EV_t evFlag;
274
275   resmRet = RESM_GetEvent(p_ctx->resmId, &evFlag);
276   if (RESM_E_OK != resmRet) {
277     TSKM_ASSERT(0);
278     goto ERROR;
279   }
280
281   if (RESM_EV_MEM != evFlag) {
282     TSKM_ASSERT(0);
283     goto ERROR;
284   }
285
286   TSKM_PRINTF(TSKM_LOG_ERROR, "Detect LowMem");
287
288   p_ev->event = TSKM_EV_LCL_REP_LOWMEM;
289
290   return 0;
291   ERROR: return -1;
292 }
293
294 int tskm_sub_setWakeupOrder(const char* p_order) {
295   // Under consideration
296   return 0;
297 }  // LCOV_EXCL_BR_LINE 10: Gcov constraints (last row)