common_library: gettid is multiple declaration in cl_error
[staging/basesystem.git] / video_in_hal / vehicleservice / positioning_base_library / library / src / _CWORD64_api.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  * @file
19  *      _CWORD64_api.cpp
20  */
21
22 /*---------------------------------------------------------------------------------*
23  * Include Files                                                                   *
24  *---------------------------------------------------------------------------------*/
25 #include <vehicle_service/positioning_base_library.h>
26 #include <native_service/frameworkunified_framework_if.h>
27 #include <native_service/cl_lock.h>
28 #include <native_service/cl_lockid.h>
29 #include "tchar.h"
30 #include "WPF_STD_private.h"
31
32
33
34 /*---------------------------------------------------------------------------------*
35  * Function Prototype                                                              *
36  *---------------------------------------------------------------------------------*/
37 extern RET_API MutexInit(void);
38 extern RET_API SemaphoreInit(void);
39 extern RET_API MemoryInit(void);
40 extern RET_API EventInit(void);
41 extern RET_API MsgInit(void);
42 extern RET_API ErrTrapInit(void);
43 extern RET_API TimerInit(HANDLE h_app);
44 extern void MsgTerm(void);
45
46 static void BaseCreateMutex(void);
47 static void BaseLockMutex(void);
48 static void BaseUnlockMutex(void);
49
50 /*---------------------------------------------------------------------------------*
51  * Grobal Value                                                                    *
52  *---------------------------------------------------------------------------------*/
53 /** Handle for locking Base API setups */
54 static HANDLE g_h_mtx = NULL;
55
56 /*---------------------------------------------------------------------------------*
57  * Function                                                                        *
58  *---------------------------------------------------------------------------------*/
59 /**
60  * @brief
61  *   Setup Base API
62  *
63  *   Perform the processing required to use the Base API.(Call per process)
64  *
65  * @param[in]  h_app Application handle
66  *
67  * @return  RET_NORMAL Normal completion
68  */
69 RET_API _pb_Setup_CWORD64_API(HANDLE h_app) {    // NOLINT(readability/nolint)  API
70     RET_API result;
71     static int8 i = 0;
72     int32 ret;
73
74     if (i != 0) {
75         /* If the process has already initialized */
76         /* nop */
77     } else {
78         /* Interprocess lock initialization(CLS) */
79         ret = CL_LockProcessInit();  // LCOV_EXCL_BR_LINE 4: nsfw error
80         if (ret != 0) {  // LCOV_EXCL_BR_LINE 4: nsfw error
81             FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "CL_LockProcessInit ERROR!! [ret=%d]", ret);
82             AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
83             _pb_Exit();  // LCOV_EXCL_LINE 4: nsfw error
84             /* don't arrive here. */
85         }
86
87         BaseCreateMutex(); /* Create Mutex */
88         BaseLockMutex(); /* Get Mutex */
89
90         /* Recheck during getting Mutex */
91         if (i == 0) {  // LCOV_EXCL_BR_LINE 6: i can not be other value
92             /* Not initialized */
93             FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__, "_pb_Setup_CWORD64_API Entered.");
94
95             /* Mutex function initialization */
96             result = MutexInit();
97             if (result != RET_NORMAL) {  // LCOV_EXCL_BR_LINE 200: can not be not normal
98                 FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "MutexInit ERROR!! [result=%d]", result);
99                 AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
100                 _pb_Exit();  // LCOV_EXCL_LINE 200: function can not be not normal
101             }
102
103             /* Semaphore function initialization */
104             result = SemaphoreInit();
105             if (result != RET_NORMAL) {  // LCOV_EXCL_BR_LINE 200: can not be not normal
106                 FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "SemaphoreInit ERROR!! [result=%d]", \
107                     result);
108                 AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
109                 _pb_Exit();  // LCOV_EXCL_LINE 200: function can not be not normal
110             }
111
112             /* Memory function initialization */
113             result = MemoryInit();
114             if (result != RET_NORMAL) {  // LCOV_EXCL_BR_LINE 200: can not be not normal
115                 FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "MemoryInit ERROR!! [result=%d]", result);
116                 AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
117                 _pb_Exit();  // LCOV_EXCL_LINE 200: can not be not normal
118             }
119
120             /* Event function initialization */
121             result = EventInit();
122             if (result != RET_NORMAL) {  // LCOV_EXCL_BR_LINE 200: can not be not normal
123                 FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "EventInit ERROR!! [result=%d]", result);
124                 AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
125                 _pb_Exit();  // LCOV_EXCL_LINE 200: function can not be not normal
126             }
127
128             /* Message function initialization */
129             result = MsgInit();
130             if (result != RET_NORMAL) {  // LCOV_EXCL_BR_LINE 200: can not be not normal
131                 FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "MsgInit ERROR!! [result=%d]", result);
132                 AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
133                 _pb_Exit();  // LCOV_EXCL_LINE 200: can not be not normal
134             }
135
136             result = ErrTrapInit();
137             if (result != RET_NORMAL) {  // LCOV_EXCL_BR_LINE 200: can not be not normal
138                 FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "ErrTrapInit ERROR!! [result=%d]", result);
139                 AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
140                 _pb_Exit();  // LCOV_EXCL_LINE 200: can not be not normal
141             }
142
143             /* For Positioning processes */
144             if (_tcscmp("Positioning", FrameworkunifiedGetAppName(h_app)) == 0) {  // LCOV_EXCL_BR_LINE 200: can not be other value
145                 /* Timer function initialization */
146                 result = TimerInit(h_app);
147                 if (result != RET_NORMAL) {  // LCOV_EXCL_BR_LINE 200: can not be not normal
148                     FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, \
149                     "TimerInit ERROR!! [result=%d]", result);
150                     AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
151                     _pb_Exit();  // LCOV_EXCL_LINE 200: can not be not normal
152                 }
153             }
154
155             i = 1;
156         }
157
158         BaseUnlockMutex(); /* Release Mutex */
159     }
160
161     /* Set application handle */
162     _pb_SetAppHandle(h_app);
163
164     return RET_NORMAL;
165 }
166
167 /**
168  * @brief
169  *   Teardown Base API
170  *
171  *   Base API termination processing (Call per process)
172  *
173  * @param[in]  none
174  *
175  * @return none
176  */
177 void _pb_Teardown_CWORD64_API(void) {   // NOLINT(readability/nolint)  API  // LCOV_EXCL_START 8:dead code
178     AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
179     /* Interprocess Lock Control(CLS) */
180
181
182     /*
183        Resources cannot be released unless it is guaranteed that other processes do not call the Positioning API.
184        Even if the resource is not released at the time of termination, it will not lead to illegal operation such as memory leak.
185        Comment out release processing.
186      */
187
188     /* Mutex */
189     /* Semaphore */
190     /* Memory */
191     /* Event */
192     /* Message */
193
194     /* Timer */
195
196     return;
197 }
198 // LCOV_EXCL_STOP
199
200
201 /**
202  * @brief
203  *   Create Mutex for Base API setups
204  */
205 static void BaseCreateMutex(void) {
206     g_h_mtx = (HANDLE)CL_LockMap(LOCK_POS_MTX_1);  // LCOV_EXCL_BR_LINE 4: nsfw error
207     if (g_h_mtx == NULL) {  // LCOV_EXCL_BR_LINE 4: nsfw error
208         FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "CL_LockMap ERROR [g_h_mtx:%p]", g_h_mtx);
209         AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
210         _pb_Exit();  // LCOV_EXCL_LINE 4: nsfw error
211         /* don't arrive here. */
212     }
213
214     return;
215 }
216
217 /**
218  * @brief
219  *   Get Mutex for Base API setups
220  */
221 static void BaseLockMutex(void) {
222     int32 ret;
223
224     ret = CL_LockGet(g_h_mtx);  // LCOV_EXCL_BR_LINE 4: nsfw error
225     if (ret != 0) {  // LCOV_EXCL_BR_LINE 4: nsfw error
226         FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "CL_LockGet ERROR [g_h_mtx:%p, ret:%d]", \
227             g_h_mtx, ret);
228         AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
229         _pb_Exit();  // LCOV_EXCL_LINE 4: nsfw error
230         /* don't arrive here. */
231     }
232
233     return;
234 }
235
236 /**
237  * @brief
238  *   Release Mutex for Base API Setup
239  */
240 static void BaseUnlockMutex(void) {
241     int32 ret;
242
243     ret = CL_LockRelease(g_h_mtx);  // LCOV_EXCL_BR_LINE 4: nsfw error
244     if (ret != 0) {  // LCOV_EXCL_BR_LINE 4: nsfw error
245         FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "CL_LockRelease ERROR [g_h_mtx:%p, ret:%d]", \
246             g_h_mtx, ret);
247         AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
248         _pb_Exit();  // LCOV_EXCL_LINE 4: nsfw error
249         /* don't arrive here. */
250     }
251
252     return;
253 }
254