summaryrefslogtreecommitdiffstats
path: root/task_manager/client/libprimary/src/pri_api.cpp
blob: ca1b40e3d60dbefcad6ee93370e71e74fc48c0e7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
/*
 * @copyright Copyright (c) 2016-2020 TOYOTA MOTOR CORPORATION.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#include "system_service/tskm_local_type.h"
#include "system_service/INI_API.hpp"
#include "tskm_debug.h"
#include "pri_main.h"

BOOL __thread isMain = FALSE;  // Check for accessibility from the main thread context

TSKM_STATIC BOOL isInitPrmValid(const T_PRIM_PRM* p_prm) {
  if (p_prm == NULL) {
    TSKM_ASSERT(0);
    return FALSE;
  } else if (p_prm->shmTbl == NULL) {
    TSKM_ASSERT(0);
    return FALSE;
  } else if (p_prm->wakeupExFuncTbl == NULL) {
    TSKM_ASSERT(0);
    return FALSE;
  } else if (p_prm->downExFuncTbl == NULL) {
    TSKM_ASSERT(0);
    return FALSE;
  } else if (p_prm->onInit == NULL) {
    TSKM_ASSERT(0);
    return FALSE;
  } else if (p_prm->onDestory == NULL) {
    TSKM_ASSERT(0);
    return FALSE;
  } else if (p_prm->onDebugDump == NULL) {
    TSKM_ASSERT(0);
    return FALSE;
  } else if (p_prm->onTouch == NULL) {
    TSKM_ASSERT(0);
    return FALSE;
  }

  return TRUE;
}

/******************************************************************************
 *      APIs for implementing the main thread on the service side
 *******************************************************************************/
/*********************************************************
 *  Primary library initialization
 *********************************************************/
int32_t INI_Init(T_PRIM_PRM* p_prm, int argc, char* argv[], int *fdNum,
                 int fdlist[INI_FD_MAX]) {
  isMain = TRUE;
  if (isInitPrmValid(p_prm) == FALSE) {
    TSKM_ASSERT(0);
    return INI_FALSE;
  }
  pri_init(p_prm, argc, argv, fdNum, fdlist);
  return INI_SUCCESS;
}

/***********************************************************
 *  Primary library / Event handler
 *  ret:TRUE  Running
 *  ret:FALSE Finished (Terminated a process with INI_Term())
 ************************************************************/
BOOL INI_Handler(fd_set* p_fds) {
  if (!isMain || NULL == p_fds) {
    TSKM_ASSERT(0);
    return FALSE;
  }

  return pri_handler(p_fds);
}

/***********************************************************
 *  Primary (Processing finished)
 ************************************************************/
void INI_Term(void) {
  pri_term();
}

/***********************************************************
 *  Primary (State setting for watching Services)
 ************************************************************/
int32_t INI_SetMonitorState(T_PRIM_MONITOR_PRM *p_prm) {
  if (!p_prm) {
    TSKM_ASSERT(0);
    goto ERROR;
  }

  return pri_setMonitorState(p_prm->bIsRun, p_prm->timeout);
  ERROR: return INI_FALSE;
}

/******************************************************************************
 *      Hiding the Main Thread in the Primary Library
 *******************************************************************************/
/************************************
 *  Startup FW MainLoop
 ************************************/
int INI_Main(T_PRIM_PRM* p_prm, int argc, char* argv[]) {
  if (isInitPrmValid(p_prm) == FALSE) {  // LCOV_EXCL_BR_LINE 6: Checked by Init()
    TSKM_ASSERT(0);
    return INI_FALSE;
  }

  isMain = TRUE;

  return pri_main(p_prm, argc, argv);
}

/******************************************************************************
 *      Common API
 *******************************************************************************/
/************************************
 *  Process termination
 ************************************/
void INI_ExitStart(void * rsv) {
  static int isCalled = 0;
  if (isCalled) {
    return;
  }
  isCalled = 1;
  pri_exitStart(rsv);
}

void INI_ExitDone(int status) {
  static int isCalled = 0;
  if (isCalled) {
    return;
  }
  isCalled = 1;
  pri_exitDone(status);
}

/************************************
 *  Private Info Acquisition
 ************************************/
void* INI_GetPrivate() {
  return pri_getPrivate();
}

/************************************
 *  Applicastion Handle Aquisition
 ************************************/
HANDLE INI_GetHandle() {
  return pri_getHandle();
}

/************************************
 *  Timeout setting for service monitoring status setting
 ************************************/
int32_t INI_SetMonitorTimeout(uint32_t timeout) {
  return pri_setMonitorTimeout(timeout);
}

/************************************
 *  Event completion notification at startup
 ************************************/
int32_t INI_StepForkComp(uint64_t compId) {
  return pri_stepForkComp(compId);
}

/************************************
 *  Event completion notification at termination
 ************************************/
int32_t INI_AccOffComp(uint64_t compId) {
  return pri_accOffComp(compId);
}

/************************************
 *  BOOT Info Acquisition
 ************************************/
int32_t INI_GetBootInfo(T_SS_SM_START_DataStructType *info) {
  if (info == NULL) {
    TSKM_ASSERT(0);
    return INI_FALSE;
  }
  return pri_getBootInfo(info);
}

/************************************
 *  Extended BOOT Info Acquisition
 ************************************/
int32_t INI_GetExtBootInfo(T_SS_SM_START_ExtDataStructType *info) {
  if (info == NULL) {
    TSKM_ASSERT(0);
    return INI_FALSE;
  }
  return pri_getExtBootInfo(info);
}

/************************************
 *  DebugDump Responding
 ************************************/
void _INI_DEBUGDUMP(BOOL bIsNeedSvcName, PCSTR cFormat, ...) {  // LCOV_EXCL_START 7: for debugging
  AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
  va_list argList;
  char buf[TSKM_EV_DEBUGDUMP_SIZE] = { 0 };

  if (bIsNeedSvcName) {
    snprintf(buf, TSKM_EV_DEBUGDUMP_SIZE, "%s/",
             FrameworkunifiedGetAppName(pri_getHandle()));
  }

  va_start(argList, cFormat);
  vsnprintf(&buf[strlen(buf)], TSKM_EV_DEBUGDUMP_SIZE - strlen(buf), cFormat,
            argList);
  va_end(argList);

  return pri_sendDebugDumpRes(buf);
}
// LCOV_EXCL_STOP 7