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 "tskm_main.h"
20 #include <sys/select.h>
22 #include <sys/types.h>
25 #include <sys/inotify.h>
27 #include <system_service/ss_services.h>
28 #include <native_service/ns_version_if.h>
29 #include <native_service/ns_np_service_protocol.h>
30 #include <system_service/ss_system_if.h>
31 #include <system_service/ss_version.h>
32 #include <system_service/ss_templates.h>
33 #include <native_service/frameworkunified_dispatcher.h>
34 #include <other_service/rpc.h>
35 #include <system_service/resm.h>
37 #include "tskm_data_init_local.h"
38 #include "tskm_port_pf.h"
39 #include "tskm_port_subsys.h"
40 #include "tskm_debug.h"
41 #include "tskm_util.h"
42 #include "tskm_srvr.h"
43 #include "tskm_comm.h"
44 #include "tskm_watch.h"
45 #include "system_service/tskm_local_type.h"
46 #include "system_service/tskm_xml_data.h"
47 #include "tskm_state.h"
49 #define TSKM_DATA_KEY "TSKM_KEY"
51 TSKM_STATIC TSKM_MAIN_CTX_t g_mainCtx; // Main context
53 TSKM_STATIC BOOL s_isVupMode = FALSE;
55 CFrameworkunifiedVersion g_FrameworkunifiedVersion(MAJORNO, MINORNO, REVISION);
58 FRAMEWORKUNIFIEDLOGPARAM g_FrameworkunifiedLogParams = {
59 FRAMEWORKUNIFIEDLOGOPTIONS, {
60 ZONE_TEXT_10, ZONE_TEXT_11, ZONE_TEXT_12,
61 ZONE_TEXT_13, ZONE_TEXT_14, ZONE_TEXT_15,
62 ZONE_TEXT_16, ZONE_TEXT_17, ZONE_TEXT_18,
63 ZONE_TEXT_19, ZONE_TEXT_20, ZONE_TEXT_21,
64 ZONE_TEXT_22, ZONE_TEXT_23, ZONE_TEXT_24,
65 ZONE_TEXT_25, ZONE_TEXT_26, ZONE_TEXT_27,
66 ZONE_TEXT_28, ZONE_TEXT_29, ZONE_TEXT_30,
67 ZONE_TEXT_31 }, FRAMEWORKUNIFIEDLOGZONES };
69 EFrameworkunifiedStatus OnFinishLoadFile(HANDLE hApp) { // LCOV_EXCL_START 6: Because the condition cannot be set
70 AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert
71 EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK;
74 TSKM_MAIN_CTX_t* p_main = &g_mainCtx;
77 ret = tskm_pf_nvFileRead(hApp, &p_main->nvInfo);
82 // issure INI_INITCOMP_NVM_ACCESS
83 bzero(&ev, sizeof(ev));
84 ev.event = TSKM_EV_PRI_REP_WAKEUP_COMP;
85 ev.errCode = TSKM_E_OK;
86 ev.prm.repWakeupComp.compId = INI_INITCOMP_NVM_ACCESS;
87 tskm_handleEvent(p_main, &ev);
93 EFrameworkunifiedStatus onDataInitRequest(HANDLE hApp) {
94 TSKM_ERR_t l_tskmRet = TSKM_E_OK;
95 EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK;
96 TSKM_MAIN_CTX_t* p_main = tskm_getMainCtx();
98 TSKM_PRINTF(TSKM_LOG_API, "%s()", __FUNCTION__)
100 if (p_main->bootInfo.startupReason == epswfINVALID) {
101 // Before issuing FrameworkunifiedOnStart = Requests before TaskManager became Availabile are not accepted
103 l_tskmRet = TSKM_E_STATE;
105 T_SS_SM_START_DataStructType bootInfo(epswfIGN_ACC, TRUE,
106 e_SS_SM_DATA_RESET_MODE_USER,
107 epsssUNLOCK, epsstWARMSTART,
108 e_SS_SM_DRAM_BACKUP_OK,
109 e_SS_SM_RESET_STATUS_NONE, 0);
111 T_SS_SM_START_ExtDataStructType extBootInfo;
113 memcpy(&extBootInfo, &p_main->extBootInfo, sizeof(extBootInfo));
115 // After updating the program,
116 // FALSE is notified here because it is notified when data initialization I/F is called at startup
117 extBootInfo.isProgUpdated = FALSE;
119 tskm_dataInitAll(&bootInfo, &extBootInfo);
122 PCSTR l_senderName = FrameworkunifiedGetMsgSrc(hApp);
123 if (NULL != l_senderName) {
124 HANDLE hSession = FrameworkunifiedMcOpenSender(hApp, l_senderName);
125 if (hSession == NULL) {
129 eFrameworkunifiedStatusOK
130 == FrameworkunifiedSendMsg(hSession, TSKM_DATAINIT_RESP, sizeof(l_tskmRet),
132 TSKM_ASSERT(eFrameworkunifiedStatusOK == FrameworkunifiedMcClose(hSession));
139 EFrameworkunifiedStatus onTransStepRequest(HANDLE hApp) { // LCOV_EXCL_START 6:Because the condition cannot be set
140 AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert
141 TSKM_MAIN_CTX_t* p_main = &g_mainCtx;
142 EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK;
144 TSKM_EVENT_INFO_t ev;
145 bzero(&ev, sizeof(ev));
147 ev.event = TSKM_EV_LCL_REQ_TRANS_STEP;
148 ev.errCode = TSKM_E_OK;
149 tskm_handleEvent(p_main, &ev);
155 EFrameworkunifiedStatus OnResmAvailability(HANDLE hApp) { // LCOV_EXCL_START 6: Because the condition cannot be set
156 AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert
157 TSKM_MAIN_CTX_t* p_main = &g_mainCtx;
159 if (0 != strcmp(NTFY_ResourceMgr_Availability, FrameworkunifiedGetLastNotification(hApp))) {
161 } else if (FrameworkunifiedIsServiceAvailable(hApp)) {
162 // Availability = TRUE
164 p_main->resmFd = tskm_sub_resmInit();
165 if (-1 == p_main->resmFd) {
169 return eFrameworkunifiedStatusOK;
173 //************ NS Framework Callback : must implemet ******************
174 EFrameworkunifiedStatus FrameworkunifiedOnInitialization(HANDLE hApp) {
175 EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK;
176 TSKM_PRINTF(TSKM_LOG_STATE, "+");
178 l_eStatus = FrameworkunifiedRegisterServiceAvailabilityNotification(hApp, NTFY_SS_TaskManager_Availability);
179 if (eFrameworkunifiedStatusOK != l_eStatus) {
183 l_eStatus = FrameworkunifiedPublishServiceAvailability(hApp, FALSE);
184 if (eFrameworkunifiedStatusOK != l_eStatus) {
188 l_eStatus = FrameworkunifiedAttachCallbackToDispatcher(hApp, FRAMEWORKUNIFIED_NS_NPSERVICE,
189 NPS_GET_PERS_FILE_ACK,
191 if (eFrameworkunifiedStatusOK != l_eStatus) {
195 l_eStatus = FrameworkunifiedAttachCallbackToDispatcher(hApp, FRAMEWORKUNIFIED_ANY_SOURCE,
198 if (eFrameworkunifiedStatusOK != l_eStatus) {
202 l_eStatus = FrameworkunifiedAttachCallbackToDispatcher(hApp, FrameworkunifiedGetAppName(hApp),
205 if (eFrameworkunifiedStatusOK != l_eStatus) {
209 l_eStatus = FrameworkunifiedSubscribeNotificationWithCallback(hApp, NTFY_ResourceMgr_Availability, OnResmAvailability);
210 if (eFrameworkunifiedStatusOK != l_eStatus) {
214 TSKM_PRINTF(TSKM_LOG_STATE, "-");
219 EFrameworkunifiedStatus FrameworkunifiedOnStart(HANDLE hApp) {
220 EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK;
221 TSKM_PRINTF(TSKM_LOG_STATE, "+");
222 l_eStatus = OnStart(hApp);
223 TSKM_PRINTF(TSKM_LOG_STATE, "-");
227 EFrameworkunifiedStatus FrameworkunifiedOnPreStart(HANDLE hApp) {
228 EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK;
229 TSKM_PRINTF(TSKM_LOG_STATE, "+");
230 l_eStatus = OnStart(hApp);
231 TSKM_PRINTF(TSKM_LOG_STATE, "-");
235 EFrameworkunifiedStatus FrameworkunifiedOnBackgroundStart(HANDLE hApp) {
236 EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK;
237 TSKM_PRINTF(TSKM_LOG_STATE, "+");
238 l_eStatus = OnStart(hApp);
239 TSKM_PRINTF(TSKM_LOG_STATE, "-");
243 EFrameworkunifiedStatus FrameworkunifiedOnStop(HANDLE hApp) {
244 FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+");
245 TSKM_MAIN_CTX_t* p_main = &g_mainCtx;
246 // Returns Fail to send asynchronous STOP reply to SM
247 EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusFail;
249 TSKM_EVENT_INFO_t ev;
250 bzero(&ev, sizeof(ev));
252 ev.event = TSKM_EV_LCL_REQ_STOP;
253 ev.errCode = TSKM_E_OK;
254 tskm_handleEvent(p_main, &ev);
256 p_main->isOnStopDone = TSKM_TRUE;
258 FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-");
262 EFrameworkunifiedStatus FrameworkunifiedOnPreStop(HANDLE hApp) {
263 FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+");
264 FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-");
265 return eFrameworkunifiedStatusOK;
268 EFrameworkunifiedStatus FrameworkunifiedOnBackgroundStop(HANDLE hApp) {
269 FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+");
270 FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-");
271 return eFrameworkunifiedStatusOK;
274 EFrameworkunifiedStatus FrameworkunifiedOnDestroy(HANDLE hApp) {
275 EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK;
276 FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+");
277 FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-");
281 EFrameworkunifiedStatus FrameworkunifiedOnDebugDump(HANDLE hApp) {
282 EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK;
283 FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+");
284 TSKM_MAIN_CTX_t* p_main = &g_mainCtx;
285 TSKM_ERR_t l_tskmRet;
287 // Call DebugDump of all running SVCs
288 l_tskmRet = tskm_svcsCallDebugDump(&p_main->svcs);
289 if (TSKM_E_OK != l_tskmRet) {
293 FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-");
297 EFrameworkunifiedStatus FrameworkunifiedCreateStateMachine(HANDLE hApp) { // LCOV_EXCL_START 6: Because the condition cannot be set
298 AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert
299 EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK;
300 FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+");
301 FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-");
306 /*********************************************************
307 * System start process
308 *********************************************************/
309 EFrameworkunifiedStatus OnStart(const HANDLE hApp) {
310 TSKM_PRINTF(TSKM_LOG_STATE, "+");
311 TSKM_MAIN_CTX_t* const p_main = &g_mainCtx;
312 EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK;
314 if (p_main->isOnStartDone == TSKM_FALSE) {
315 T_SS_SM_START_DataStructType startupInfo;
316 TSKM_EVENT_INFO_t ev;
317 l_eStatus = ReadMsg<T_SS_SM_START_DataStructType>(hApp, startupInfo);
318 if (l_eStatus != eFrameworkunifiedStatusOK) {
321 memcpy(&p_main->bootInfo, &startupInfo, sizeof(T_SS_SM_START_DataStructType));
324 if (0 != tskm_sub_getExtBootInfo(&p_main->extBootInfo)) {
328 tskm_dataInitAll(&p_main->bootInfo, &p_main->extBootInfo);
330 tskm_svcsSetBootInfo(&p_main->svcs, &p_main->bootInfo, &p_main->extBootInfo);
331 p_main->isOnStartDone = TSKM_TRUE;
333 l_eStatus = FrameworkunifiedPublishServiceAvailability(hApp, TRUE);
334 if (l_eStatus != eFrameworkunifiedStatusOK) {
337 TSKM_PRINTF(TSKM_LOG_STATE, "Availability TRUE");
340 // Issure INI_INITCOMP_ON_START
341 bzero(&ev, sizeof(ev));
342 ev.event = TSKM_EV_PRI_REP_WAKEUP_COMP;
343 ev.errCode = TSKM_E_OK;
344 ev.prm.repWakeupComp.compId = INI_INITCOMP_ON_START;
345 tskm_handleEvent(p_main, &ev);
348 TSKM_PRINTF(TSKM_LOG_STATE, "-");
352 /*********************************************************
353 * Argument analysis process
354 *********************************************************/
355 TSKM_STATIC EFrameworkunifiedStatus argParser(SI_32 argument, PCHAR argumentValue) { // LCOV_EXCL_START 6: for process initialization processing
356 AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert
357 if ('v' == argument) {
361 return eFrameworkunifiedStatusOK;
364 /*********************************************************
365 * Creating process for TSKM internal context
366 *********************************************************/
367 TSKM_STATIC void ctxCreate(TSKM_MAIN_CTX_t* p_main, int argc, char* argv[]) {
369 EFrameworkunifiedStatus taskmanagerRet;
371 FrameworkunifiedDefaultCallbackHandler cbFuncs;
372 FRAMEWORKUNIFIED_MAKE_DEFAULT_CALLBACK(cbFuncs);
373 CustomCommandLineOptions cmdLineOpt = { "v", NULL, argParser };
375 p_main->state = TSKM_ST_ACCOFF;
376 p_main->isOnStartDone = TSKM_FALSE;
379 taskmanagerRet = FrameworkunifiedCreateDispatcherWithoutLoop(SS_TASK_MANAGER, p_main->hApp, argc,
380 argv, &cbFuncs, TRUE, &cmdLineOpt);
381 if (eFrameworkunifiedStatusOK != taskmanagerRet) { // LCOV_EXCL_BR_LINE 6: For process initialization processing
382 // LCOV_EXCL_START 6: For process initialization processing
383 AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert
384 TSKM_ASSERT_PRINT(0, "%d", taskmanagerRet);
389 TSKM_PRINTF(TSKM_LOG_STATE, "s_isVupMode :%s", s_isVupMode ? "TRUE" : "FALSE");
391 taskmanagerRet = FrameworkunifiedGetDispatcherFD(p_main->hApp, &p_main->nsFd);
392 if (taskmanagerRet != eFrameworkunifiedStatusOK) { // LCOV_EXCL_BR_LINE 6: For process initialization processing
393 // LCOV_EXCL_START 6: For process initialization processing
394 AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert
395 TSKM_ASSERT_PRINT(0, "%d", taskmanagerRet);
400 p_main->sigFd = tskm_pf_sysInit(); // Platform initialization
401 if (p_main->sigFd == -1) { // LCOV_EXCL_BR_LINE 6: For process initialization processing
402 // LCOV_EXCL_LINE 6: For process initialization processing
403 AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert
409 p_main->iFd = inotify_init1(IN_CLOEXEC);
410 if (p_main->sigFd == -1) { // LCOV_EXCL_BR_LINE 6: For process initialization processing
411 // LCOV_EXCL_LINE 6: For process initialization processing
412 AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert
413 TSKM_ASSERT_ERRNO(0);
418 // Obtain RESM FDs after waiting for Availability
421 tskmRet = tskm_srvSockCreate(TSKM_SOCKET_NAME, &p_main->sock);
422 TSKM_ERR_CHK(tskmRet, TSKM_E_OK, ERROR); // LCOV_EXCL_BR_LINE 6: For process initialization processing
424 ret = tskm_pf_nvFileInit(p_main->hApp);
425 if (ret != 0) { // LCOV_EXCL_BR_LINE 6: For process initialization processing
426 // LCOV_EXCL_START 6: For process initialization processing
427 AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert
433 ret = tskm_initServiceList(&p_main->svcs, p_main->iFd); // Service to be started
434 if (0 != ret) { // LCOV_EXCL_BR_LINE 6: For process initialization processing
435 // LCOV_EXCL_START 6: For For process initialization process
436 AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert
442 tskm_initWakeupCtx(&p_main->wakeup, s_isVupMode); // Gradual startup info
443 tskm_initDownCtx(&p_main->down, s_isVupMode); // Gradual termination info
446 // LCOV_EXCL_START 6: For process initialization processing
448 AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert
449 tskm_pf_exit(EXIT_FAILURE);
454 /*********************************************************
456 *********************************************************/
458 tskm_getMainCtx(void) {
462 /*********************************************************
463 * Process initialization process (MAIN function sub)
464 *********************************************************/
465 int Init_Process(int* rpcFd, int* sockFd, int* maxFd, fd_set* fds, TSKM_MAIN_CTX_t* p_main) {
469 TSKM_SRV_CONNENT_LIST_t* p_connList = &p_main->sock.connList;
474 *maxFd = TSKM_MAX(*rpcFd, *maxFd); // LCOV_EXCL_BR_LINE 6: For process initialization processing
476 FD_SET(*sockFd, fds);
477 *maxFd = TSKM_MAX(*sockFd, *maxFd); // LCOV_EXCL_BR_LINE 6: For process initialization processing
479 FD_SET(p_main->nsFd, fds);
480 *maxFd = TSKM_MAX(p_main->nsFd, *maxFd); // LCOV_EXCL_BR_LINE 6: For process initialization processing
482 FD_SET(p_main->sigFd, fds);
483 *maxFd = TSKM_MAX(p_main->sigFd, *maxFd); // LCOV_EXCL_BR_LINE 6: For process initialization processing
485 if (-1 != p_main->resmFd) { // LCOV_EXCL_BR_LINE 6: For process initialization processing
486 // LCOV_EXCL_START 6: For process initialization processing
487 AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert
488 FD_SET(p_main->resmFd, fds);
489 *maxFd = TSKM_MAX(p_main->resmFd, *maxFd);
493 for (ii = 0; ii < p_connList->num; ii++) { // LCOV_EXCL_BR_LINE 6: For process initialization processing
494 // LCOV_EXCL_START 6: For process initialization processing
495 AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert
496 TSKM_SRV_CONNENT_t* p_conn = &p_connList->conn[ii];
497 FD_SET(p_conn->connFd, fds);
498 *maxFd = TSKM_MAX(p_conn->connFd, *maxFd);
502 TSKM_PRINTF(TSKM_LOG_FUNC, "SELECT IN");
503 ret = select(*maxFd + 1, fds, NULL, NULL, NULL);
505 if (errno != EINTR) {
510 TSKM_PRINTF(TSKM_LOG_FUNC, "SELECT OUT");
514 /*********************************************************
515 * Receiving Messages from CONNECT Clients (MAIN Functions Sub)
516 *********************************************************/
517 void Recv_Msg_FromConnectClient(fd_set* fds, TSKM_MAIN_CTX_t* p_main) {
519 TSKM_SRV_CONNENT_LIST_t* p_connList = &p_main->sock.connList;
521 // Messages from CONNECT clients
522 for (ii = 0; ii < p_connList->num; ii++) {
523 TSKM_SRV_CONNENT_t* p_conn = &p_connList->conn[ii];
524 if (FD_ISSET(p_conn->connFd, fds)) {
525 TSKM_PRINTF(TSKM_LOG_FUNC, "connFd IN");
526 TSKM_EVENT_INFO_t ev;
528 ret = tskm_sockRcv(p_conn->connFd, &ev);
533 TSKM_SVC_CTX_t* p_svc;
537 TSKM_PRINTF(TSKM_LOG_STATE, "DISSCON pid:%d", p_conn->pid);
538 ev.event = TSKM_EV_PRI_REP_DISCONNECT;
539 ev.errCode = TSKM_E_OK;
540 ev.fromPid = p_conn->pid;
541 tskm_srvSockDisconnect(&p_main->sock, p_conn);
542 p_conn = NULL; // If the connection is lost, it cannot be referenced.
545 p_svc = tskm_svcsGetSvcByPid(&p_main->svcs, ev.fromPid);
546 if (p_svc) { // Events from service
548 tskmRet = tskm_svcEventHandle(p_svc, &ev); // Service handler
549 if (tskmRet != TSKM_E_OK) {
553 if (ev.event != TSKM_EV_NOP) {
554 tskm_handleEvent(p_main, &ev); // Main handler
557 TSKM_PRINTF(TSKM_LOG_FUNC, "connFd OUT");
562 /*********************************************************
563 * CONNECT Requests (MAIN Functions Sub)
564 *********************************************************/
565 void Recv_Req_Connect(fd_set* fds, TSKM_MAIN_CTX_t* p_main, int sockFd) {
567 if (FD_ISSET(sockFd, fds)) {
568 TSKM_PRINTF(TSKM_LOG_FUNC, "sockFd IN");
570 TSKM_SRV_CONNENT_t* conn;
571 conn = tskm_srvSockConnect(&p_main->sock);
575 TSKM_SVC_CTX_t* p_svc;
576 TSKM_PRINTF(TSKM_LOG_STATE, "CONNECT pid:%d", conn->pid);
578 p_svc = tskm_svcsGetSvcByPid(&p_main->svcs, conn->pid);
581 TSKM_EVENT_INFO_t ev;
583 ev.event = TSKM_EV_PRI_REP_CONNECT;
584 ev.errCode = TSKM_E_OK;
585 ev.fromPid = conn->pid;
586 ev.prm.repConnect.connFd = conn->connFd;
588 tskmRet = tskm_svcEventHandle(p_svc, &ev); // Service handler
589 if (tskmRet != TSKM_E_OK) {
591 } else if (ev.event != TSKM_EV_NOP) {
592 tskm_handleEvent(p_main, &ev); // Main hander
596 TSKM_PRINTF(TSKM_LOG_FUNC, "sockFd OUT");
600 /*********************************************************
602 *********************************************************/
603 int main(int argc, char* argv[]) {
604 RPC_ID rpcId = TSKM_RPC_ID;
609 TSKM_MAIN_CTX_t* p_main = &g_mainCtx;
612 FRAMEWORKUNIFIED_SET_ZONES();
614 ctxCreate(p_main, argc, argv); // Initialize context
616 tskm_sub_init(); // Initialize sub systems
618 RPC_START_SECURE_SERVER(rpcId);
619 RPC_get_fd(rpcId, &rpcFd);
629 if (RPC_OK != RPC_regist_credential(2, uid, 2, gid)) { // LCOV_EXCL_BR_LINE 6: For process initialization processing
630 AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert
631 TSKM_ASSERT(0); // LCOV_EXCL_LINE 6: For process initialization processing
634 // Start periodic timer thread
635 ret = tskm_watch_startTimer();
636 if (ret != 0) { // LCOV_EXCL_BR_LINE 6: For process initialization processing
637 AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert
638 TSKM_ASSERT(0); // LCOV_EXCL_LINE 6: For process initialization processing
641 tskm_stateTransit(p_main, TSKM_ST_ACCOFF, TSKM_ST_ACCON);
643 p_main->isExec = TSKM_TRUE;
644 while (p_main->isExec) { // LCOV_EXCL_BR_LINE 6: For process initialization processing
645 int sockFd = p_main->sock.sockFd;
647 // Initialization processing
648 if (Init_Process(&rpcFd, &sockFd, &maxFd, &fds, p_main) != 0) { // LCOV_EXCL_BR_LINE 6: For process initialization processing
649 AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert
650 continue; // LCOV_EXCL_LINE 6: For process initialization processing
654 if (FD_ISSET(rpcFd, &fds)) {
655 RPC_process_API_request(rpcId);
658 // Process termination signal
659 if (FD_ISSET(p_main->sigFd, &fds)) {
663 TSKM_EVENT_INFO_t ev;
664 ev.event = TSKM_EV_SVC_REP_TERM;
668 ret = tskm_pf_cleanupProc(p_main->sigFd, &ev.fromPid, &ev.errCode);
674 TSKM_SVC_CTX_t* p_svc;
676 p_svc = tskm_svcsGetSvcByPid(&p_main->svcs, ev.fromPid);
680 tskmRet = tskm_svcEventHandle(p_svc, &ev); // Service handler
681 if (tskmRet != TSKM_E_OK) {
684 if (ev.event != TSKM_EV_NOP) {
685 tskm_handleEvent(p_main, &ev); // Main handler
688 } while (ret == 1 && count < 50);
691 if (FD_ISSET(p_main->nsFd, &fds)) {
692 FrameworkunifiedDispatchProcessWithoutLoop(p_main->hApp);
696 if (-1 != p_main->resmFd) {
697 if (FD_ISSET(p_main->resmFd, &fds)) {
698 TSKM_EVENT_INFO_t ev;
700 ret = tskm_sub_resmRcv(&ev);
705 tskm_handleEvent(p_main, &ev);
710 // Messages from connected clients
711 Recv_Msg_FromConnectClient(&fds, p_main);
714 Recv_Req_Connect(&fds, p_main, sockFd);
717 tskm_srvSockDestory(&p_main->sock);
721 FrameworkunifiedDestroyDispatcherWithoutLoop(p_main->hApp);
722 TSKM_PRINTF(TSKM_LOG_STATE, "tskm end");
724 sleep(TSKM_CFG_WAIT_SHUTDOWN);
726 } // LCOV_EXCL_BR_LINE 10: Final line