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.
22 /*---------------------------------------------------------------------------------*
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>
30 #include "WPF_STD_private.h"
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);
46 static void BaseCreateMutex(void);
47 static void BaseLockMutex(void);
48 static void BaseUnlockMutex(void);
50 /*---------------------------------------------------------------------------------*
52 *---------------------------------------------------------------------------------*/
53 /** Handle for locking Base API setups */
54 static HANDLE g_h_mtx = NULL;
56 /*---------------------------------------------------------------------------------*
58 *---------------------------------------------------------------------------------*/
63 * Perform the processing required to use the Base API.(Call per process)
65 * @param[in] h_app Application handle
67 * @return RET_NORMAL Normal completion
69 RET_API _pb_Setup_CWORD64_API(HANDLE h_app) { // NOLINT(readability/nolint) API
75 /* If the process has already initialized */
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. */
87 BaseCreateMutex(); /* Create Mutex */
88 BaseLockMutex(); /* Get Mutex */
90 /* Recheck during getting Mutex */
91 if (i == 0) { // LCOV_EXCL_BR_LINE 6: i can not be other value
93 FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__, "_pb_Setup_CWORD64_API Entered.");
95 /* Mutex function initialization */
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
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]", \
108 AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert
109 _pb_Exit(); // LCOV_EXCL_LINE 200: function can not be not normal
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
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
128 /* Message function initialization */
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
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
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
158 BaseUnlockMutex(); /* Release Mutex */
161 /* Set application handle */
162 _pb_SetAppHandle(h_app);
171 * Base API termination processing (Call per process)
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) */
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.
203 * Create Mutex for Base API setups
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. */
219 * Get Mutex for Base API setups
221 static void BaseLockMutex(void) {
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]", \
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. */
238 * Release Mutex for Base API Setup
240 static void BaseUnlockMutex(void) {
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]", \
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. */