common_library: gettid is multiple declaration in cl_error
[staging/basesystem.git] / video_in_hal / systemservice / task_manager / server / src / tskm_watch.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_watch.h"
18 #include <agl_thread.h>
19
20 #include "tskm_debug.h"
21 #include "tskm_port_pf.h"
22 #include "tskm_comm.h"
23
24
25 #define WATCH_CYCLE 5
26
27 #define TIMER_THREAD_NAME "SS_TskmTimer"
28
29 /*******************************************************************
30  *    Periodic Timer-Thread MAIN Function
31  *******************************************************************/
32 void *
33 watchMain(void *arg) {
34   int connFd = -1;
35
36   connFd = tskm_cliSockConnect(TSKM_SOCKET_NAME);
37   if (connFd < 0) {  // LCOV_EXCL_BR_LINE 5: system function(uinx) "socket" fail process
38     // LCOV_EXCL_START 5: system function(uinx) "socket" fail process
39     AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
40     TSKM_ASSERT(0);
41     goto ERROR;
42     // LCOV_EXCL_STOP 5
43   }
44
45   while (1) {
46     int ret;
47     TSKM_EVENT_INFO_t ev;
48
49     sleep(WATCH_CYCLE);
50
51     ev.event = TSKM_EV_LCL_REP_POLLING;
52     ev.errCode = TSKM_E_OK;
53     ret = tskm_sockSend(connFd, &ev);
54     if (ret <= 0) {  // LCOV_EXCL_BR_LINE 5: system function(uinx) "send" fail process
55     // LCOV_EXCL_START 5: system function(uinx) "send" fail process
56     AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
57       TSKM_ASSERT(0);
58       goto ERROR;
59       // LCOV_EXCL_STOP 5
60     }
61   }
62
63   // LCOV_EXCL_START 6: system function(uinx) call fail process
64   ERROR:
65   AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
66   if (connFd != -1) {
67     tskm_sockDestory(connFd);
68   }
69
70   return 0;
71   // LCOV_EXCL_STOP
72 }
73
74 /*******************************************************************
75  *    Periodic Timer thread start
76  *******************************************************************/
77 int tskm_watch_startTimer() {
78   int ret;
79   pthread_t thId = { 0 };
80
81   ret = tskm_pf_createThread(watchMain, NULL, PR_SS_TSKMTIMER,
82                              TIMER_THREAD_NAME, &thId);
83   if (ret != 0) {  // LCOV_EXCL_BR_LINE 5: system function(uinx) "pthread_*" fail process
84     // LCOV_EXCL_START 5: system function(uinx) "pthread_*" fail process
85     AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
86     TSKM_ASSERT(0);
87     goto ERROR;
88     // LCOV_EXCL_STOP 5
89   } else {
90     TSKM_PRINTF(TSKM_LOG_STATE, "watch thread created.");
91   }
92
93   return 0;
94
95   // LCOV_EXCL_LINE 6: system function(uinx) "pthread_*" fail process
96   ERROR:
97   AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
98   return -1;
99   // LCOV_EXCL_STOP
100 }
101