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.
17 #include "system_service/tskm_local_type.h"
18 #include "system_service/INI_API.hpp"
19 #include "tskm_debug.h"
22 BOOL __thread isMain = FALSE; // Check for accessibility from the main thread context
24 TSKM_STATIC BOOL isInitPrmValid(const T_PRIM_PRM* p_prm) {
28 } else if (p_prm->shmTbl == NULL) {
31 } else if (p_prm->wakeupExFuncTbl == NULL) {
34 } else if (p_prm->downExFuncTbl == NULL) {
37 } else if (p_prm->onInit == NULL) {
40 } else if (p_prm->onDestory == NULL) {
43 } else if (p_prm->onDebugDump == NULL) {
46 } else if (p_prm->onTouch == NULL) {
54 /******************************************************************************
55 * APIs for implementing the main thread on the service side
56 *******************************************************************************/
57 /*********************************************************
58 * Primary library initialization
59 *********************************************************/
60 int32_t INI_Init(T_PRIM_PRM* p_prm, int argc, char* argv[], int *fdNum,
61 int fdlist[INI_FD_MAX]) {
63 if (isInitPrmValid(p_prm) == FALSE) {
67 pri_init(p_prm, argc, argv, fdNum, fdlist);
71 /***********************************************************
72 * Primary library / Event handler
74 * ret:FALSE Finished (Terminated a process with INI_Term())
75 ************************************************************/
76 BOOL INI_Handler(fd_set* p_fds) {
77 if (!isMain || NULL == p_fds) {
82 return pri_handler(p_fds);
85 /***********************************************************
86 * Primary (Processing finished)
87 ************************************************************/
92 /***********************************************************
93 * Primary (State setting for watching Services)
94 ************************************************************/
95 int32_t INI_SetMonitorState(T_PRIM_MONITOR_PRM *p_prm) {
101 return pri_setMonitorState(p_prm->bIsRun, p_prm->timeout);
102 ERROR: return INI_FALSE;
105 /******************************************************************************
106 * Hiding the Main Thread in the Primary Library
107 *******************************************************************************/
108 /************************************
109 * Startup FW MainLoop
110 ************************************/
111 int INI_Main(T_PRIM_PRM* p_prm, int argc, char* argv[]) {
112 if (isInitPrmValid(p_prm) == FALSE) { // LCOV_EXCL_BR_LINE 6: Checked by Init()
119 return pri_main(p_prm, argc, argv);
122 /******************************************************************************
124 *******************************************************************************/
125 /************************************
126 * Process termination
127 ************************************/
128 void INI_ExitStart(void * rsv) {
129 static int isCalled = 0;
137 void INI_ExitDone(int status) {
138 static int isCalled = 0;
143 pri_exitDone(status);
146 /************************************
147 * Private Info Acquisition
148 ************************************/
149 void* INI_GetPrivate() {
150 return pri_getPrivate();
153 /************************************
154 * Applicastion Handle Aquisition
155 ************************************/
156 HANDLE INI_GetHandle() {
157 return pri_getHandle();
160 /************************************
161 * Timeout setting for service monitoring status setting
162 ************************************/
163 int32_t INI_SetMonitorTimeout(uint32_t timeout) {
164 return pri_setMonitorTimeout(timeout);
167 /************************************
168 * Event completion notification at startup
169 ************************************/
170 int32_t INI_StepForkComp(uint64_t compId) {
171 return pri_stepForkComp(compId);
174 /************************************
175 * Event completion notification at termination
176 ************************************/
177 int32_t INI_AccOffComp(uint64_t compId) {
178 return pri_accOffComp(compId);
181 /************************************
182 * BOOT Info Acquisition
183 ************************************/
184 int32_t INI_GetBootInfo(T_SS_SM_START_DataStructType *info) {
189 return pri_getBootInfo(info);
192 /************************************
193 * Extended BOOT Info Acquisition
194 ************************************/
195 int32_t INI_GetExtBootInfo(T_SS_SM_START_ExtDataStructType *info) {
200 return pri_getExtBootInfo(info);
203 /************************************
204 * DebugDump Responding
205 ************************************/
206 void _INI_DEBUGDUMP(BOOL bIsNeedSvcName, PCSTR cFormat, ...) { // LCOV_EXCL_START 7: for debugging
207 AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert
209 char buf[TSKM_EV_DEBUGDUMP_SIZE] = { 0 };
211 if (bIsNeedSvcName) {
212 snprintf(buf, TSKM_EV_DEBUGDUMP_SIZE, "%s/",
213 FrameworkunifiedGetAppName(pri_getHandle()));
216 va_start(argList, cFormat);
217 vsnprintf(&buf[strlen(buf)], TSKM_EV_DEBUGDUMP_SIZE - strlen(buf), cFormat,
221 return pri_sendDebugDumpRes(buf);