diff options
author | ToshikazuOhiwa <toshikazu_ohiwa@mail.toyota.co.jp> | 2020-03-30 09:42:55 +0900 |
---|---|---|
committer | ToshikazuOhiwa <toshikazu_ohiwa@mail.toyota.co.jp> | 2020-03-30 09:42:55 +0900 |
commit | 7ba873861b02b878d0dcefa3104981c57e71deac (patch) | |
tree | 14dd72c4875ee1de16f07b73a1f3e38ea2d3f4a0 /task_manager/client | |
parent | 706ad73eb02caf8532deaf5d38995bd258725cb8 (diff) |
ss-taskmanager branch
Diffstat (limited to 'task_manager/client')
30 files changed, 3430 insertions, 0 deletions
diff --git a/task_manager/client/Makefile b/task_manager/client/Makefile new file mode 100644 index 00000000..c550ea9d --- /dev/null +++ b/task_manager/client/Makefile @@ -0,0 +1,26 @@ +# +# @copyright Copyright (c) 2016-2019 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. +# + +SUBDIRS = libtskmcfg ss_data_init libtskm libprimary + +VPATH = ../server/include/$(COMPONENT_NAME) + +######### install headers(*.h) ############# +INST_HEADERS = INI_API.h INI_API.hpp Primary_common.h tskm.h tskm_type.h tskm_local_type.h +INST_HEADERS += sysup_from.h sysup.h tskm_svc.h +INST_HEADERS += task_manager.h + +include ../../system_service.mk diff --git a/task_manager/client/libprimary/Makefile b/task_manager/client/libprimary/Makefile new file mode 100644 index 00000000..6f21c550 --- /dev/null +++ b/task_manager/client/libprimary/Makefile @@ -0,0 +1,37 @@ +# +# @copyright Copyright (c) 2016-2019 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. +# +VPATH = ./src ./../../server/src +####################################### +INST_SHLIBS = libprimary + +libprimary_SRCS = pri_main.c pri_api.c tskm_port_pf.c tskm_comm.c tskm_debug.c +LDFLAGS += -Wl,--no-as-needed +######### linked library (dynamic) ############# +LDLIBS += -lpthread +LDLIBS += -lstdc++ +LDLIBS += -lrt +LDLIBS += -lSS_SystemIfUnified +LDLIBS += -lNS_FrameworkUnified +LDLIBS += -lcommon + +######### add library path ############# + + +CPPFLAGS = -I./include/ -I./../../include-share -I./../../server/include -I./../libtskmcfg/include + +CPPFLAGS += -fno-exceptions + +include ../../../system_service.mk diff --git a/task_manager/client/libprimary/include/pri_main.h b/task_manager/client/libprimary/include/pri_main.h new file mode 100644 index 00000000..e4777618 --- /dev/null +++ b/task_manager/client/libprimary/include/pri_main.h @@ -0,0 +1,48 @@ +/* + * @copyright Copyright (c) 2016-2019 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. + */ + +#ifndef TASK_MANAGER_CLIENT_LIBPRIMARY_INCLUDE_PRI_MAIN_H_ +#define TASK_MANAGER_CLIENT_LIBPRIMARY_INCLUDE_PRI_MAIN_H_ + +#include <native_service/frameworkunified_types.h> + +#include "system_service/tskm_type.h" +#include "system_service/Primary_common.h" +#include "system_service/INI_API.hpp" + +int pri_main(T_PRIM_PRM* p_prm, int argc, char* argv[]); +void pri_exitStart(void* rsv); +void pri_exitDone(int status); +void* pri_getPrivate(); +HANDLE pri_getHandle(); +int32_t pri_setMonitorTimeout(uint32_t timeout); + +int32_t pri_stepForkComp(uint64_t id); +int32_t pri_accOffComp(uint64_t id); + +int32_t pri_getBootInfo(T_SS_SM_START_DataStructType *info); +int32_t pri_getExtBootInfo(T_SS_SM_START_ExtDataStructType *info); +void pri_sendDebugDumpRes(const char *buf); + +void pri_init(T_PRIM_PRM* p_prm, int argc, char* argv[], int *fdNum, + int fdlist[INI_FD_MAX]); +BOOL pri_handler(fd_set* p_fds); +void pri_term(void); +int pri_setMonitorState(BOOL bIsRun, uint32_t timeout); +void pri_getAppHandle(void); + +#endif // TASK_MANAGER_CLIENT_LIBPRIMARY_INCLUDE_PRI_MAIN_H_ + diff --git a/task_manager/client/libprimary/libprimary.ver b/task_manager/client/libprimary/libprimary.ver new file mode 100644 index 00000000..707508e7 --- /dev/null +++ b/task_manager/client/libprimary/libprimary.ver @@ -0,0 +1,22 @@ +/* + * @copyright Copyright (c) 2016-2019 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. + */ + +{ + global: + INI_*; + _INI_DEBUGDUMP*; + local: *; +}; diff --git a/task_manager/client/libprimary/src/pri_api.cpp b/task_manager/client/libprimary/src/pri_api.cpp new file mode 100644 index 00000000..8434026d --- /dev/null +++ b/task_manager/client/libprimary/src/pri_api.cpp @@ -0,0 +1,224 @@ +/* + * @copyright Copyright (c) 2016-2019 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 + diff --git a/task_manager/client/libprimary/src/pri_main.cpp b/task_manager/client/libprimary/src/pri_main.cpp new file mode 100644 index 00000000..d3f067bb --- /dev/null +++ b/task_manager/client/libprimary/src/pri_main.cpp @@ -0,0 +1,873 @@ +/* + * @copyright Copyright (c) 2016-2019 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 "pri_main.h" +#include <sys/eventfd.h> +#include <native_service/frameworkunified_dispatcher.h> +#include <system_service/ss_system_if.h> +#include <string.h> +#include <errno.h> +#include <pthread.h> +#include <stdlib.h> +#include "tskm_debug.h" +#include "tskm_comm.h" +#include "tskm_port_pf.h" +#include "tskm_port_subsys.h" +#include "tskm_util.h" + + +#define PRI_PROC_NAME_MAX 32 + +// Context +typedef struct { + T_PRIM_PRM prm; + + TSKM_SVCID_t svcId; // Set valid value by REQ_WAKEUP + char procName[PRI_PROC_NAME_MAX]; + // State + TSKM_BOOL_t isExec; + T_SS_SM_START_DataStructType bootInfo; + T_SS_SM_START_ExtDataStructType extBootInfo; TSKM_BOOL_t isDynamic; + uint32_t wakeupStepDone; // Performed Local Step + TSKM_BOOL_t shmDone; + uint32_t downStepDone; // Performed Local Step + TSKM_BOOL_t isExitStart; + +#define PRI_MONITOR_DEFAULT_TIMEOUT 50 + uint32_t timeout; // Service monitoring timeout period (valid only for the INI_Main type service) + + // Resources + int connFd; // TSKM communication sockets + int nsFd; // NSFW sockets + int pipeFd[2]; // For exitDone + HANDLE hApp; // appHandle +} PRI_CTX_t; + +static PRI_CTX_t g_pri; + +/********************************************* + * Create Shared Memory + *********************************************/ +TSKM_STATIC void shmMake(PRI_CTX_t* p_ctx) { + const PRIM_SHAREDATA_TBL* shmEntry; + for (shmEntry = p_ctx->prm.shmTbl; shmEntry->shmName[0] != '\0'; shmEntry++) { + int ret; + ret = tskm_pf_shmCreate(shmEntry->shmName, shmEntry->size, NULL); + if (ret != 0) { // LCOV_EXCL_BR_LINE 5: Checked by Death testing, but it is not reflected in the coverage and excluded + // LCOV_EXCL_START 5: Checked by Death testing, but it is not reflected in the coverage and excluded + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + TSKM_ASSERT(0); + goto ERROR; + // LCOV_EXCL_STOP + } + } + p_ctx->shmDone = TSKM_TRUE; + return; + + // LCOV_EXCL_START 6: Checked by Death testing, but it is not reflected in the coverage and excluded + ERROR: + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + tskm_pf_abort(); + // LCOV_EXCL_STOP +} + +/********************************************* + * Call Backup Check CB + *********************************************/ +TSKM_STATIC uint32_t wakeupExFuncCallback(PRI_CTX_t* p_ctx, + TSKM_EV_PRI_REQ_WAKEUP_PRM_t* p_prm) { + const PRIM_EXFUNC_TBL* funcEntry; + uint32_t maxStep = 0; + + for (funcEntry = p_ctx->prm.wakeupExFuncTbl; funcEntry->localStep != 0; + funcEntry++) { + if (funcEntry->localStep == p_prm->localStep) { + funcEntry->func(funcEntry->prm); + } + maxStep = TSKM_MAX(maxStep, funcEntry->localStep); + } + return maxStep; +} + +/********************************************* + * Gradual Start Request + *********************************************/ +TSKM_STATIC void wakeupRequest(PRI_CTX_t* p_ctx, + TSKM_EV_PRI_REQ_WAKEUP_PRM_t* p_prm) { + TSKM_EV_PRI_REQ_WAKEUP_PRM_t prm = *p_prm; + uint32_t max = 0; + + // Execute one step at a time + for (prm.localStep = p_ctx->wakeupStepDone + 1; + (prm.localStep <= p_prm->localStep && prm.localStep < PRIM_STEPFORK_MAX); + prm.localStep++) { + max = wakeupExFuncCallback(p_ctx, &prm); + } + + if (max <= p_prm->localStep) { + // Gradual start completed + p_ctx->wakeupStepDone = PRIM_STEPFORK_MAX; + } else { + p_ctx->wakeupStepDone = p_prm->localStep; + } +} + +/********************************************* + * All startup requests + *********************************************/ +TSKM_STATIC void allWakeup(PRI_CTX_t* p_ctx, + TSKM_EV_PRI_REQ_WAKEUP_PRM_t* p_prm) { + if (!p_ctx->shmDone) { + shmMake(p_ctx); + } + + if (p_ctx->wakeupStepDone < PRIM_STEPFORK_MAX) { + wakeupRequest(p_ctx, p_prm); + } +} + +/********************************************* + * Startup request handle + *********************************************/ +TSKM_STATIC void wakeupRequestHandle(PRI_CTX_t* p_ctx, + TSKM_EV_PRI_REQ_WAKEUP_PRM_t* p_prm) { + TSKM_EVENT_INFO_t ev; + int ret; + + bzero(&ev, sizeof(ev)); + + p_ctx->svcId = p_prm->svcId; + memcpy(&p_ctx->bootInfo, &p_prm->bootInfo, sizeof(p_ctx->bootInfo)); + memcpy(&p_ctx->extBootInfo, &p_prm->extBootInfo, sizeof(p_ctx->extBootInfo)); + p_ctx->isDynamic = p_prm->isDynamic; + + if (p_prm->localStep == TSKM_LSTEP_ALL) { + allWakeup(p_ctx, p_prm); + } else if (p_prm->localStep == TSKM_LSTEP_LAST) { + wakeupRequest(p_ctx, p_prm); + } else if (p_prm->localStep == TSKM_LSTEP_SHM) { + shmMake(p_ctx); + } else { + wakeupRequest(p_ctx, p_prm); + } + + ev.prm.resWakeup.isShmDone = p_ctx->shmDone; + ev.prm.resWakeup.isStepDone = + (p_ctx->wakeupStepDone >= PRIM_STEPFORK_MAX) ? + TSKM_TRUE : TSKM_FALSE; + + // LCOV_EXCL_BR_START 6: Because it depends on the test order + if (ev.prm.resWakeup.isShmDone && ev.prm.resWakeup.isStepDone) { + // LCOV_EXCL_BR_STOP + ev.prm.resWakeup.isLast = TSKM_TRUE; + } + + ev.event = TSKM_EV_PRI_RES_WAKEUP; + ev.errCode = TSKM_E_OK; + ret = tskm_sockSend(p_ctx->connFd, &ev); + if (ret <= 0) { // LCOV_EXCL_BR_LINE 5: Checked by Death testing, but it is not reflected in the coverage and excluded + // LCOV_EXCL_START 5: Checked by Death testing, but it is not reflected in the coverage and excluded + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + TSKM_ASSERT(0); + tskm_pf_abort(); + // LCOV_EXCL_STOP + } +} + +/********************************************* + * Gradual Termination CALLBACK + *********************************************/ +TSKM_STATIC uint32_t downExFuncCallback(PRI_CTX_t* p_ctx, + TSKM_EV_PRI_REQ_DOWN_PRM_t* p_prm) { + const PRIM_EXFUNC_TBL* funcEntry; + uint32_t maxStep = 0; + + for (funcEntry = p_ctx->prm.downExFuncTbl; funcEntry->localStep != 0; + funcEntry++) { + if (funcEntry->localStep == p_prm->localStep) { + funcEntry->func(funcEntry->prm); + } + maxStep = TSKM_MAX(maxStep, funcEntry->localStep); + } + return maxStep; +} + +/********************************************* + * Gradual Termination Request + *********************************************/ +TSKM_STATIC void downRequest(PRI_CTX_t* p_ctx, + TSKM_EV_PRI_REQ_DOWN_PRM_t* p_prm) { + TSKM_EV_PRI_REQ_DOWN_PRM_t prm = *p_prm; + uint32_t max = 0; + + // Execute one step at a time + for (prm.localStep = p_ctx->downStepDone + 1; + (prm.localStep <= p_prm->localStep && prm.localStep < PRIM_ACCOFF_MAX); + prm.localStep++) { + max = downExFuncCallback(p_ctx, &prm); + } + + if (max <= p_prm->localStep) { + p_ctx->downStepDone = PRIM_ACCOFF_MAX; // Completed all steps + } else { + p_ctx->downStepDone = p_prm->localStep; + } +} + +TSKM_STATIC void downRequestHandle(PRI_CTX_t* p_ctx, + TSKM_EV_PRI_REQ_DOWN_PRM_t* p_prm) { + TSKM_EVENT_INFO_t ev; + int ret; + + bzero(&ev, sizeof(ev)); + + if (p_prm->localStep == TSKM_LSTEP_ALL || p_prm->localStep == TSKM_LSTEP_LAST) { + downRequest(p_ctx, p_prm); + } else if (p_prm->localStep == TSKM_LSTEP_SHM) { + TSKM_ASSERT(0); + } else if (p_prm->localStep == TSKM_LSTEP_BUPCHK) { + TSKM_ASSERT(0); + } else { + downRequest(p_ctx, p_prm); + } + + if (p_ctx->downStepDone >= PRIM_ACCOFF_MAX) { + /* It is not notified when the last function is executed, and it is left to the exitDone. + TSKM_PRINTF(TSKM_LOG_DEBUG,"ACCOFF DONE"); + ev.prm.resDown.isLast = TSKM_TRUE; + p_ctx->isExec = TSKM_FALSE; + ret = tskm_sockSend(p_ctx->connFd,&ev); + if(ret <= 0){ + TSKM_ASSERT(0); + tskm_pf_abort(); + } + */ + } else { + ev.event = TSKM_EV_PRI_RES_DOWN; + ev.errCode = TSKM_E_OK; + ret = tskm_sockSend(p_ctx->connFd, &ev); + if (ret <= 0) { // LCOV_EXCL_BR_LINE 5: Checked by Death testing, but it is not reflected in the coverage and excluded + // LCOV_EXCL_START 5: Checked by Death testing, but it is not reflected in the coverage and excluded + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + TSKM_ASSERT(0); + tskm_pf_abort(); + // LCOV_EXCL_STOP + } + } +} + +/********************************************* + * Termination completion is notified to the TSKM + *********************************************/ +TSKM_STATIC void sendLastDoneRes(PRI_CTX_t* p_ctx) { + int ret; + TSKM_EVENT_INFO_t ev; + + bzero(&ev, sizeof(ev)); + + ev.event = TSKM_EV_PRI_RES_DOWN; + ev.errCode = TSKM_E_OK; + ev.prm.resDown.isLast = TSKM_TRUE; + ret = tskm_sockSend(p_ctx->connFd, &ev); + if (ret <= 0) { // LCOV_EXCL_BR_LINE 5: Termination completion is notified to the TSKM. + // LCOV_EXCL_START 5: Termination completion is notified to the TSKM. + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + TSKM_ASSERT(0); + tskm_pf_abort(); + // LCOV_EXCL_STOP + } +} + +/********************************************* + * Invocation of Touch CB + *********************************************/ +TSKM_STATIC void touchService(PRI_CTX_t* p_ctx) { + char touchName[32]; + + if (p_ctx->isExitStart) { + // If termination processing has already begun, the system does not respond Touch but TIMEOUT the processing for retrying. + return; + } + + p_ctx->prm.onTouch(p_ctx->hApp); + + tskm_pf_mkTouchFileName(getpid(), touchName); + + if ((access(touchName, F_OK) == 0)) { + // Synchronize by deleting files. + TSKM_PRINTF(TSKM_LOG_STATE, "del:%s", touchName); + unlink(touchName); + } else { + TSKM_ASSERT_PRINT(0, "%s", touchName); + } +} + +/********************************************* + * Invocation of Debugdump CB + *********************************************/ +TSKM_STATIC void callDebugDump(PRI_CTX_t* p_ctx) { + if (!p_ctx->prm.onDebugDump) { // LCOV_EXCL_BR_LINE 6: As NULL checked by INI_Init + // LCOV_EXCL_START 6: As NULL checked by INI_Init + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + TSKM_ASSERT(0); + // LCOV_EXCL_STOP + } else { + p_ctx->prm.onDebugDump(p_ctx->hApp); + } +} + +/********************************************* + * Invocation of LowMemory detection CB + *********************************************/ +TSKM_STATIC void callLowMem(PRI_CTX_t* p_ctx) { + if (!p_ctx->prm.onLowMem) { + TSKM_ASSERT(0); + } else if (!p_ctx->isExitStart) { + // Notify LowMemory only when the process is finished + p_ctx->prm.onLowMem(p_ctx->hApp); + } +} + +/********************************************* + * Event Handle + *********************************************/ +TSKM_STATIC void eventHandle(PRI_CTX_t* p_ctx, TSKM_EVENT_INFO_t* p_ev) { + // Processing according to the request + switch (p_ev->event) { + case TSKM_EV_PRI_REQ_WAKEUP: + wakeupRequestHandle(p_ctx, &p_ev->prm.reqWakeup); + break; + case TSKM_EV_PRI_REQ_DOWN: + downRequestHandle(p_ctx, &p_ev->prm.reqDown); + break; + case TSKM_EV_PRI_REQ_TOUCH: + touchService(p_ctx); + break; + case TSKM_EV_PRI_REQ_DEBUGDUMP: + callDebugDump(p_ctx); + break; + case TSKM_EV_PRI_REP_LOWMEM: + callLowMem(p_ctx); + break; + default: + TSKM_ASSERT(0); + break; + } +} + +/********************************************* + * Initialize Context + *********************************************/ +TSKM_STATIC void initCtx(T_PRIM_PRM* p_prm, PRI_CTX_t* p_ctx, int argc, + char* argv[]) { + FrameworkunifiedDefaultCallbackHandler cbFuncs; + + p_ctx->prm = *p_prm; + + cbFuncs.onInitilization = p_ctx->prm.onInit; + cbFuncs.onDestroy = p_ctx->prm.onDestory; + cbFuncs.onDebugDump = p_ctx->prm.onDebugDump; + cbFuncs.onStart = FrameworkunifiedOnStart; + cbFuncs.onStop = FrameworkunifiedOnStop; + cbFuncs.onPreStart = FrameworkunifiedOnPreStart; + cbFuncs.onPreStop = FrameworkunifiedOnPreStop; + cbFuncs.onBackgroundStart = FrameworkunifiedOnBackgroundStart; + cbFuncs.onBackgroundStop = FrameworkunifiedOnBackgroundStop; + cbFuncs.createStateMachine = FrameworkunifiedCreateStateMachine; + cbFuncs.ssFrameworkInterface = FrameworkunifiedSSFrameworkInterface; + + EFrameworkunifiedStatus taskmanagerRet; + taskmanagerRet = FrameworkunifiedCreateDispatcherWithoutLoop(p_ctx->prm.name, p_ctx->hApp, argc, + argv, &cbFuncs, FALSE); + if (eFrameworkunifiedStatusOK != taskmanagerRet) { // LCOV_EXCL_BR_LINE 5: Checked by Death testing, but it is not reflected in the coverage and excluded + // LCOV_EXCL_START 5: Checked by Death testing, but it is not reflected in the coverage and excluded + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + TSKM_ASSERT_PRINT(0, "%d", taskmanagerRet); + goto ERROR; + // LCOV_EXCL_STOP + } + + taskmanagerRet = FrameworkunifiedGetDispatcherFD(p_ctx->hApp, &p_ctx->nsFd); + if (taskmanagerRet != eFrameworkunifiedStatusOK) { + TSKM_ASSERT_PRINT(0, "%d", taskmanagerRet); + exit(EXIT_FAILURE); + } + + p_ctx->connFd = tskm_cliSockConnect(TSKM_SOCKET_NAME); + if (p_ctx->connFd < 0) { // LCOV_EXCL_BR_LINE 5: Checked by Death testing, but it is not reflected in the coverage and excluded + // LCOV_EXCL_START 5: Checked by Death testing, but it is not reflected in the coverage and excluded + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + TSKM_ASSERT(0); + goto ERROR; + // LCOV_EXCL_STOP + } + if (pipe(p_ctx->pipeFd) != 0) { // LCOV_EXCL_BR_LINE 5: Checked by Death testing, but it is not reflected in the coverage and excluded + // LCOV_EXCL_START 5: Checked by Death testing, but it is not reflected in the coverage and excluded + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + TSKM_ASSERT_ERRNO(0); + goto ERROR; + // LCOV_EXCL_STOP + } + + return; + // LCOV_EXCL_START 5: Checked by Death testing, but it is not reflected in the coverage and excluded + ERROR: + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + tskm_pf_abort(); + // LCOV_EXCL_STOP +} + +/********************************************* + * Destroy Context + *********************************************/ +TSKM_STATIC void termCtx(PRI_CTX_t* p_ctx) { + if (p_ctx->shmDone) { // LCOV_EXCL_BR_LINE 6: Since it has been set to True by INI_Handler and cannot be changed + const PRIM_SHAREDATA_TBL* shmEntry = p_ctx->prm.shmTbl; + for (shmEntry = p_ctx->prm.shmTbl; shmEntry->shmName[0] != '\0'; + shmEntry++) { + TSKM_ASSERT(0 == tskm_pf_shmDelete(shmEntry->shmName)); // LCOV_EXCL_BR_LINE 8: For processing in which only return value 0 is set + } + } + + if (p_ctx->connFd > 0) { // LCOV_EXCL_BR_LINE 6: As it is already set by INI_Init and cannot be changed + tskm_sockDestory(p_ctx->connFd); + } + + EFrameworkunifiedStatus taskmanagerRet; + taskmanagerRet = FrameworkunifiedDestroyDispatcherWithoutLoop(p_ctx->hApp); + TSKM_ASSERT(taskmanagerRet == eFrameworkunifiedStatusOK); + + if (p_ctx->isDynamic) { + TSKM_PRINTF(TSKM_LOG_STATE, "EXIT %s", p_ctx->procName); + } else { + // Hung up running services to prevent adversely affecting to system termination processing during process termination processing + sleep(TSKM_CFG_WAIT_SHUTDOWN); + } +} + +/******************************************************************* + * PRI Context Initialization + *******************************************************************/ +void pri_init(T_PRIM_PRM* p_prm, int argc, char* argv[], int *fdNum, + int fdlist[INI_FD_MAX]) { + int ret = 0; + PRI_CTX_t* p_ctx = &g_pri; + + strncpy(p_ctx->procName, basename(argv[0]), sizeof(p_ctx->procName) - 1); + + ret = tskm_pf_procInit(); + if (ret != 0) { // LCOV_EXCL_BR_LINE 6: Return value of 0 only + // LCOV_EXCL_START 6: Return value of 0 only + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + TSKM_ASSERT(0); + goto ERROR; + // LCOV_EXCL_STOP + } + + ret = tskm_comm_procInit(); + if (ret != 0) { // LCOV_EXCL_BR_LINE 5: Checked by Death testing, but it is not reflected in the coverage and excluded + // LCOV_EXCL_START 5: Checked by Death testing, but it is not reflected in the coverage and excluded + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + TSKM_ASSERT(0); + goto ERROR; + // LCOV_EXCL_STOP + } + + initCtx(p_prm, p_ctx, argc, argv); + + *fdNum = 3; + fdlist[0] = p_ctx->connFd; + fdlist[1] = p_ctx->pipeFd[0]; + fdlist[2] = p_ctx->nsFd; + + p_ctx->svcId = TSKM_SVCID_NONE; + p_ctx->isExec = TSKM_TRUE; + + p_ctx->bootInfo.startupReason = epswfINVALID; + p_ctx->bootInfo.isUserModeOn = FALSE; + p_ctx->bootInfo.dataResetMode = e_SS_SM_DATA_RESET_MODE_NONE; + p_ctx->bootInfo.securityStatus = epsssINVALID; + p_ctx->bootInfo.wakeupType = epsstINVALID; + p_ctx->bootInfo.dramBackupStatus = e_SS_SM_DRAM_BACKUP_UNSET; + p_ctx->bootInfo.resetStatus = e_SS_SM_RESET_STATUS_UNSET; + + memset(&p_ctx->extBootInfo, 0, sizeof(p_ctx->extBootInfo)); + + p_ctx->timeout = PRI_MONITOR_DEFAULT_TIMEOUT; + + return; + // LCOV_EXCL_START 5: Checked by Death testing, but it is not reflected in the coverage and excluded + ERROR: + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + tskm_pf_abort(); // ABORT + // LCOV_EXCL_STOP +} + +/******************************************************************* + * Primary Library Handler + *******************************************************************/ +BOOL pri_handler(fd_set* p_fds) { + PRI_CTX_t* p_ctx = &g_pri; + + if (FD_ISSET(p_ctx->connFd, p_fds)) { + int ret; + TSKM_EVENT_INFO_t ev; + ret = tskm_sockRcv(p_ctx->connFd, &ev); + // LCOV_EXCL_BR_START 5: Condition is true. False condition is checked in Death tests, but not reflected in coverage and excluded + if (ret > 0) { + // LCOV_EXCL_BR_STOP + eventHandle(p_ctx, &ev); + } else { // LCOV_EXCL_BR_LINE 5: Checked by Death testing, but it is not reflected in the coverage and excluded + // LCOV_EXCL_START 5: Checked by Death testing, but it is not reflected in the coverage and excluded + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + TSKM_ASSERT(0); + goto ERROR; + // LCOV_EXCL_STOP + } + } + + if (FD_ISSET(p_ctx->pipeFd[0], p_fds)) { + // only use exitDone + uint32_t tmp; + TSKM_ASSERT(sizeof(tmp) == read(p_ctx->pipeFd[0], &tmp, sizeof(tmp))); + TSKM_ASSERT(p_ctx->downStepDone == PRIM_ACCOFF_MAX); // Check if all exit functions are complete + if (p_ctx->isDynamic) { + // A nonresident service completes its termination processing by terminating the process. + // (because the SIGNAL will overtake the sockets) + } else { + // The resident service is a termination notice and completes termination processing. + // (Do not terminate processes to reduce the impact on system termination) + sendLastDoneRes(p_ctx); + } + p_ctx->isExec = TSKM_FALSE; + } + + if (FD_ISSET(p_ctx->nsFd, p_fds)) { + FrameworkunifiedDispatchProcessWithoutLoop(p_ctx->hApp); + } + return p_ctx->isExec; + + // LCOV_EXCL_START 5: Checked by Death testing, but it is not reflected in the coverage and excluded + ERROR: + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + tskm_pf_abort(); // ABORT + return 0; + // LCOV_EXCL_STOP +} + +/******************************************************************* + * Process termination + *******************************************************************/ +void pri_term(void) { + PRI_CTX_t* p_ctx = &g_pri; + termCtx(p_ctx); +} + +/******************************************************************* + * Service Monitoring Status Setting + *******************************************************************/ +int pri_setMonitorState(BOOL bIsRun, uint32_t timeout) { + PRI_CTX_t* p_ctx = &g_pri; + int ret = INI_SUCCESS; + + if (TSKM_SVCID_NONE == p_ctx->svcId) { + // Ignore requests until svcId is acquired. + } else if ((TRUE == bIsRun) && (0 == timeout)) { + // When RUN is specified with timeout = 0, monitoring is disabled. + } else { + ret = tskm_comm_setSvcWatchState(p_ctx->svcId, bIsRun, timeout); + if (INI_SUCCESS != ret) { + TSKM_ASSERT(0); + } + } + + return ret; +} + +/******************************************************************* + * MAIN Function + *******************************************************************/ +int pri_main(T_PRIM_PRM* p_prm, int argc, char* argv[]) { + int mainRet = -1; + int fdlist[INI_FD_MAX]; + int fdNum; + int ii; + BOOL isExec = TRUE; + + pri_init(p_prm, argc, argv, &fdNum, fdlist); + + while (isExec) { + PRI_CTX_t* p_ctx = &g_pri; + int maxFd = 0; + fd_set fds; + int ret; + + FD_ZERO(&fds); + + for (ii = 0; ii < fdNum; ii++) { + FD_SET(fdlist[ii], &fds); + maxFd = TSKM_MAX(fdlist[ii], maxFd); + } + + TSKM_ASSERT(INI_SUCCESS == pri_setMonitorState(FALSE, 0)); + ret = select(maxFd + 1, &fds, NULL, NULL, NULL); + TSKM_ASSERT(INI_SUCCESS == pri_setMonitorState(TRUE, p_ctx->timeout)); + if (ret < 1) { + // LCOV_EXCL_START 5: Select's Error-Handling Process + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + if (errno != EINTR) { + TSKM_ASSERT(0); + } + continue; + // LCOV_EXCL_STOP + } + + isExec = pri_handler(&fds); + } + + mainRet = 0; + + pri_term(); + return mainRet; +} + +/******************************************************************* + * Termination Request + *******************************************************************/ +void pri_exitStart(void *rsv) { + int ret; + PRI_CTX_t* p_ctx = &g_pri; + TSKM_EVENT_INFO_t ev; + + bzero(&ev, sizeof(ev)); + p_ctx->isExitStart = TRUE; + ev.event = TSKM_EV_PRI_REQ_EXIT; + ev.errCode = TSKM_E_OK; + + ret = tskm_sockSend(p_ctx->connFd, &ev); + if (ret <= 0) { // LCOV_EXCL_BR_LINE 5: The caller's external API does not execute the second or subsequent processing and cannot be checked. + // LCOV_EXCL_START 5: The caller's external API does not execute the second or subsequent processing and cannot be checked. + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + TSKM_ASSERT(0); + goto ERROR; + // LCOV_EXCL_STOP + } + + return; + // LCOV_EXCL_START 6: The caller's external API does not execute the second or subsequent processing and cannot be checked. + ERROR: + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + tskm_pf_abort(); + // LCOV_EXCL_STOP +} + +void pri_exitDone(int status) { + PRI_CTX_t* p_ctx = &g_pri; + uint32_t l_status = (uint32_t) status; + + if (p_ctx->pipeFd[1] > 0) { // LCOV_EXCL_BR_LINE 6: The caller's external API does not execute the second or subsequent processing and cannot be checked + // LCOV_EXCL_BR_START 6: The caller's external API does not execute the second or subsequent processing and cannot be checked + TSKM_ASSERT_ERRNO( + write(p_ctx->pipeFd[1], &l_status, sizeof(l_status)) + == sizeof(l_status)); + // LCOV_EXCL_BR_STOP + } else { + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + TSKM_ASSERT(0); // LCOV_EXCL_LINE 6: The caller's external API does not execute the second or subsequent processing and cannot be checked. + } +} + +/******************************************************************* + * Event completion notification at startup + *******************************************************************/ +int32_t pri_stepForkComp(uint64_t id) { + int ret; + PRI_CTX_t* p_ctx = &g_pri; + TSKM_EVENT_INFO_t ev; + + bzero(&ev, sizeof(ev)); + ev.event = TSKM_EV_PRI_REP_WAKEUP_COMP; + ev.errCode = TSKM_E_OK; + ev.prm.repWakeupComp.compId = id; + ret = tskm_sockSend(p_ctx->connFd, &ev); + if (ret <= 0) { + TSKM_ASSERT(0); + goto ERROR; + } + return INI_SUCCESS; + ERROR: return INI_FALSE; +} + +/******************************************************************* + * Event completion notification at termination + *******************************************************************/ +int32_t pri_accOffComp(uint64_t id) { + int ret; + PRI_CTX_t* p_ctx = &g_pri; + TSKM_EVENT_INFO_t ev; + + bzero(&ev, sizeof(ev)); + + ev.event = TSKM_EV_PRI_REP_DOWN_COMP; + ev.errCode = TSKM_E_OK; + ev.prm.repDownComp.compId = id; + ret = tskm_sockSend(p_ctx->connFd, &ev); + if (ret <= 0) { + TSKM_ASSERT(0); + goto ERROR; + } + return INI_SUCCESS; + ERROR: return INI_FALSE; +} + +/******************************************************************* + * Private Information Acquisition + *******************************************************************/ +void* +pri_getPrivate() { + PRI_CTX_t* p_ctx = &g_pri; + return p_ctx->prm.priv; +} + +/******************************************************************* + * App Handle Acquisition + *******************************************************************/ +HANDLE pri_getHandle() { + PRI_CTX_t* p_ctx = &g_pri; + return p_ctx->hApp; +} + +/******************************************************************* + * Timeout setting for Service monitoring status setting + *******************************************************************/ +int32_t pri_setMonitorTimeout(uint32_t timeout) { + PRI_CTX_t* p_ctx = &g_pri; + p_ctx->timeout = timeout; + return INI_SUCCESS; +} + +/******************************************************************* + * BOOT Info Acquisition + *******************************************************************/ +int32_t pri_getBootInfo(T_SS_SM_START_DataStructType *info) { + PRI_CTX_t* p_ctx = &g_pri; + + if (p_ctx->bootInfo.startupReason == epswfINVALID) { + TSKM_ASSERT(0); + return INI_FALSE; + } + + *info = p_ctx->bootInfo; + + return INI_SUCCESS; +} + +/******************************************************************* + * Extended BOOT Info Acquisition + *******************************************************************/ +int32_t pri_getExtBootInfo(T_SS_SM_START_ExtDataStructType *info) { + PRI_CTX_t* p_ctx = &g_pri; + + if (p_ctx->bootInfo.startupReason == epswfINVALID) { + TSKM_ASSERT(0); + return INI_FALSE; + } + + *info = p_ctx->extBootInfo; + + return INI_SUCCESS; +} + +/******************************************************************* + * DebugDump Responding + *******************************************************************/ +void pri_sendDebugDumpRes(const char *buf) { // LCOV_EXCL_START 7: for debugging + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + int ret; + PRI_CTX_t* p_ctx = &g_pri; + TSKM_EVENT_INFO_t ev; + TSKM_EV_PRI_EX_RES_DEBUGDUMP_PRM_t *p_prm; + + ev.event = TSKM_EV_PRI_RES_DEBUGDUMP; + ev.errCode = TSKM_E_OK; + ev.hasExtend = TSKM_TRUE; + + ev.extendPrm = malloc(sizeof(TSKM_EV_PRI_EX_RES_DEBUGDUMP_PRM_t)); + if (!ev.extendPrm) { + TSKM_ASSERT(0); + goto ERROR; + } + + ev.extendSize = sizeof(TSKM_EV_PRI_EX_RES_DEBUGDUMP_PRM_t); + + p_prm = (TSKM_EV_PRI_EX_RES_DEBUGDUMP_PRM_t *) ev.extendPrm; // NOLINT ( ) + snprintf(p_prm->dumpMsg, TSKM_EV_DEBUGDUMP_SIZE, "%s", buf); + + ret = tskm_sockSend(p_ctx->connFd, &ev); + if (ret <= 0) { + TSKM_ASSERT(0); + } + + ERROR: return; +} +// LCOV_EXCL_STOP +/************************************************* + * Empty functions implemented for building software + **************************************************/ +EFrameworkunifiedStatus FrameworkunifiedOnStart(HANDLE hApp) { // LCOV_EXCL_START 6: Because the condition cannot be set + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK; + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+"); + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-"); + return l_eStatus; +} +// LCOV_EXCL_STOP +EFrameworkunifiedStatus FrameworkunifiedOnStop(HANDLE hApp) { // LCOV_EXCL_START 6: Because the condition cannot be set + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK; + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+"); + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-"); + return l_eStatus; +} +// LCOV_EXCL_STOP +EFrameworkunifiedStatus FrameworkunifiedOnPreStart(HANDLE hApp) { + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+"); + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-"); + return eFrameworkunifiedStatusOK; +} +EFrameworkunifiedStatus FrameworkunifiedOnPreStop(HANDLE hApp) { + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+"); + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-"); + return eFrameworkunifiedStatusOK; +} +EFrameworkunifiedStatus FrameworkunifiedOnBackgroundStart(HANDLE hApp) { + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+"); + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-"); + return eFrameworkunifiedStatusOK; +} +EFrameworkunifiedStatus FrameworkunifiedOnBackgroundStop(HANDLE hApp) { + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+"); + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-"); + return eFrameworkunifiedStatusOK; +} +EFrameworkunifiedStatus FrameworkunifiedCreateStateMachine(HANDLE hApp) { // LCOV_EXCL_START 6: Because the condition cannot be set + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK; + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+"); + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-"); + return l_eStatus; +} +// LCOV_EXCL_STOP diff --git a/task_manager/client/libtskm/Makefile b/task_manager/client/libtskm/Makefile new file mode 100644 index 00000000..aa5c0fea --- /dev/null +++ b/task_manager/client/libtskm/Makefile @@ -0,0 +1,35 @@ +# +# @copyright Copyright (c) 2016-2019 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. +# + +VPATH = ./ ./src + +INST_SHLIBS = libtskm + +RPC_API := TSKM + +libtskm_SRCS = tskm_api_stub.c +libtskm_SRCS += tskm_api_lib.cpp + +CPPFLAGS += -I. -I../../include-share -I./ -I../../server/include -I./../libtskmcfg/include + +######## add compile option ######## +CPPFLAGS += -fno-exceptions +LDFLAGS += -Wl,--no-as-needed +######### linked library (dynamic) ############# +LDLIBS += -lrpc +LDLIBS += -Wl,-Bdynamic -lNS_FrameworkUnified + +include ../../../system_service.mk diff --git a/task_manager/client/libtskm/TSKM.api b/task_manager/client/libtskm/TSKM.api new file mode 100644 index 00000000..023f53b0 --- /dev/null +++ b/task_manager/client/libtskm/TSKM.api @@ -0,0 +1,9 @@ +INCLUDE <system_service/tskm.h> + +RPC_Result _TSKM_SvcCtl(TSKM_SVCID_t svcId,const TSKM_SVC_CTL_t* ctl); +RPC_Result TSKM_SvcGetInfo(TSKM_SVCID_t svcId,TSKM_SVC_INFO_t* svcInfo); +RPC_Result _TSKM_ErrorReboot(const TSKM_ERROR_REBOOT_t* p_info); +RPC_Result TSKM_Reboot(const TSKM_RSV_t * p_rsv); +RPC_Result TSKM_Logging(const TSKM_LOGGING_INFO_t* p_info); +RPC_Result TSKM_SetWakeupOrder(const TSKM_WAKEUP_ORDER_t* p_order); + diff --git a/task_manager/client/libtskm/libtskm.ver b/task_manager/client/libtskm/libtskm.ver new file mode 100644 index 00000000..48c2e3d5 --- /dev/null +++ b/task_manager/client/libtskm/libtskm.ver @@ -0,0 +1,21 @@ +/* + * @copyright Copyright (c) 2016-2019 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. + */ + +{ + global: + TSKM_*; + local: *; +}; diff --git a/task_manager/client/libtskm/src/tskm_api_lib.cpp b/task_manager/client/libtskm/src/tskm_api_lib.cpp new file mode 100644 index 00000000..dda5ceec --- /dev/null +++ b/task_manager/client/libtskm/src/tskm_api_lib.cpp @@ -0,0 +1,90 @@ +/* + * @copyright Copyright (c) 2016-2019 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 <unistd.h> +#include <signal.h> + +#include <native_service/frameworkunified_framework_if.h> + +#include "tskm_debug.h" +#include "tskm_api.h" + +TSKM_ERR_t TSKM_SvcCtl(TSKM_SVCID_t svcId, const TSKM_SVC_CTL_t* ctl) { + TSKM_ERR_t tskmRet; + int ii; + + for (ii = 0; ii < 3; ii++) { + // Retry three times + tskmRet = _TSKM_SvcCtl(svcId, ctl); + if (tskmRet == TSKM_E_RETRY) { + usleep(300 * 1000); // 300ms wait + } else { + break; + } + } + + return tskmRet; +} + +TSKM_ERR_t TSKM_ErrorReboot(const TSKM_ERROR_REBOOT_t* p_info) { + TSKM_ERR_t tskmRet = TSKM_E_OK; + RPC_Result rpcRet; + + rpcRet = _TSKM_ErrorReboot(p_info); + if (RPC_OK != rpcRet) { + tskmRet = TSKM_E_PAR; + } + + return tskmRet; +} + +TSKM_ERR_t TSKM_DataInit(HANDLE hApp, const TSKM_DATAINIT_t *p_info) { + TSKM_ERR_t tskmRet = TSKM_E_NG; + TSKM_PRINTF(TSKM_LOG_API, "%s()", __FUNCTION__) + + if (!p_info || !hApp || (p_info->type != TSKM_DATAINIT_TYPE_USER) + || !(p_info->onCompInit)) { + TSKM_ASSERT(0); + return TSKM_E_PAR; + } + + // LCOV_EXCL_BR_START 10: Due to compiler dependency + EFrameworkunifiedStatus l_eStatus = FrameworkunifiedAttachCallbackToDispatcher(hApp, + SS_TASK_MANAGER, + TSKM_DATAINIT_RESP, + p_info->onCompInit); + // LCOV_EXCL_BR_STOP + if (eFrameworkunifiedStatusOK != l_eStatus) { + TSKM_ASSERT(0); + } else { + HANDLE hSvc = FrameworkunifiedOpenService(hApp, SS_TASK_MANAGER); + if (hSvc == NULL) { + TSKM_ASSERT(0); + tskmRet = TSKM_E_STATE; + } else { + if (eFrameworkunifiedStatusOK != FrameworkunifiedSendMsg(hSvc, TSKM_DATAINIT_REQ, 0, NULL)) { + TSKM_ASSERT(0); + } else { + tskmRet = TSKM_E_OK; + } + } + + TSKM_ASSERT(eFrameworkunifiedStatusOK == FrameworkunifiedCloseService(hApp, hSvc)); + } + + return tskmRet; +} // LCOV_EXCL_BR_LINE 10: Final line + diff --git a/task_manager/client/libtskmcfg/Makefile b/task_manager/client/libtskmcfg/Makefile new file mode 100644 index 00000000..40a1ca65 --- /dev/null +++ b/task_manager/client/libtskmcfg/Makefile @@ -0,0 +1,97 @@ +# +# @copyright Copyright (c) 2016-2019 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. +# + +SVCONF_DIR=$(DESTDIR)/usr/agl/conf/tm_launch +THREADCONF_DIR=$(DESTDIR)/usr/agl/conf/thread +WAKESHUTCONF_DIR=./conf + +VPATH = ./src ./include/$(COMPONENT_NAME) + +INST_SHLIBS = libtskmcfg +INST_HEADERS = tskm_xml_data.h tskm_svcid.h task_manager_libtskmcfg.h +libtskmcfg_SRCS = tskm_xml_data.cpp + + +CPPFLAGS = -I./ -I./include -I./../../include-share -I./../../server/include +LDFLAGS += -Wl,--no-as-needed +LDLIBS += -Wl,-Bdynamic -lNS_FrameworkUnified + + +#============ XML PARSE ============ +XMLOUTFILE= tskm_auto_build.h + +CLEAN_FILES+=$(XMLOUTFILE) $(PARSEXMLCMD) $(CONFIG_FILES) top.xml + +#TOOLS +HOST_CPP=cpp +XMLCHECKER=xmllint +XMLCHECKEROPT=--noout --valid +PARSEXMLCMD=parsexml +HOSTCC=gcc +XMLFILETOP=tskm_cfg.xml + +install:install-pre install-pre-header +build-lib:install-pre install-pre-header +install-lib:install-pre install-pre-header +install-pre: + install -d -m 775 $(DESTDIR)/usr/agl/conf/tm_launch;\ + install -d -m 775 $(DESTDIR)/usr/agl/conf/thread;\ + install -m 644 -t $(DESTDIR)/usr/agl/conf/tm_launch $(WAKESHUTCONF_DIR)/tskm_launch.xml;\ + install -m 644 -t $(DESTDIR)/usr/agl/conf/thread $(SDKTARGETSYSROOT)/usr/agl/include/agl_thread.h + +CONFIG_FILES:=tskm_wakeup.xml tskm_shutdown.xml tskm_wakeup_vup.xml tskm_shutdown_vup.xml tskm_launch.xml tskm_svcid.h agl_thread.h + +#install-header:$(XMLOUTFILE) +install-pre-header:$(XMLOUTFILE) + +#TOPFILE +top.xml:$(XMLFILETOP) + ln -fs $< $@ + +#CONFIG RULES +tskm_wakeup.xml:$(WAKESHUTCONF_DIR)/tskm_wakeup.xml + ln -fs $< $@ + +tskm_shutdown.xml:$(WAKESHUTCONF_DIR)/tskm_shutdown.xml + ln -fs $< $@ + +tskm_wakeup_vup.xml:$(WAKESHUTCONF_DIR)/tskm_wakeup_vup.xml + ln -fs $< $@ + +tskm_shutdown_vup.xml:$(WAKESHUTCONF_DIR)/tskm_shutdown_vup.xml + ln -fs $< $@ + +#tskm_svcid.h:$(SVCONF_DIR)/tskm_svcid.h +# ln -fs $< $@ + +agl_thread.h:$(THREADCONF_DIR)/agl_thread.h + ln -fs $< $@ + + +tskm_launch.xml:$(SVCONF_DIR)/tskm_launch.xml agl_thread.h + $(HOST_CPP) -P -include agl_thread.h $< > $@ +#tskm_launch.xml:$(SVCONF_DIR)/tskm_launch.xml $(SDKTARGETSYSROOT)/usr/agl/include/agl_thread.h +# $(HOST_CPP) -P -include agl_thread.h $< > $@ + +$(XMLOUTFILE):top.xml $(PARSEXMLCMD) $(CONFIG_FILES) + $(XMLCHECKER) $(XMLCHECKEROPT) $< + ./$(PARSEXMLCMD) $< + +$(PARSEXMLCMD):$(PARSEXMLCMD).c + $(HOSTCC) -o $@ $< -lexpat + +include ../../../system_service.mk + diff --git a/task_manager/client/libtskmcfg/conf/tskm_launch.xml b/task_manager/client/libtskmcfg/conf/tskm_launch.xml new file mode 100644 index 00000000..d4ab06ce --- /dev/null +++ b/task_manager/client/libtskmcfg/conf/tskm_launch.xml @@ -0,0 +1,106 @@ +<service_list> + <service + svcid="TSKM_SVCID_ACTIVITYMGR" + name=MN_ACTIVITYMANAGER + path="/usr/agl/bin/acmsrv" + prio=PR_ACTIVITYMANAGER_S + policy="tss" + life_cycle="always" + user="" + shutdown_wait="yes" /> + + <service + svcid="TSKM_SVCID_TE_RESIDENT" + name=MN_RESIDENT_SVC + path="/usr/agl/bin/resident" + prio=PR_RESIDENT_SVC_S + policy="tss" + life_cycle="always" + user="" + shutdown_wait="no" /> + + <service + svcid="TSKM_SVCID_TE_TRANSIENT" + name =MN_TRANSIENT_SVC + path="/usr/agl/bin/transient" + prio=PR_TRANSIENT_SVC_S + policy="tss" + user="" + shutdown_wait="no" /> + + + <service + svcid="TSKM_SVCID__CWORD58_" + name =MN__CWORD58_SERVICE + path="/usr/agl/bin/_CWORD58_Service" + prio=PR__CWORD58_SERVICE_S + policy="tss" + retry_cnt="-1" + user="" + shutdown_wait="yes" /> + + <service + svcid="TSKM_SVCID_SYSUPDATE" + name =MN_PS_SYSUPDATE + path="/usr/bin/sysupdate" + prio=PR_PS_SYSUPDATE_S + policy="tss" + user="" + shutdown_wait="no" /> + + <service + svcid="TSKM_SVCID_NANDUPDATE" + name =MN_SS_NANDUPDATE + path="/usr/bin/nandupdate" + prio=PR_SS_NANDUPDATE_S + policy="tss" + user="" + shutdown_wait="no" /> + + <service + svcid="TSKM_SVCID_XMVUPSRV" + name =MN_XMVUPSERVICE + path="/usr/agl/bin/radio_xm_update" + prio=PR_XMVUPSERVICE_S + policy="tss" + user="" + shutdown_wait="no" /> + + <service + svcid="TSKM_SVCID_BTPHONESRV" + name =MN_BTPHONESRV + path="/usr/agl/bin/BT_PhoneSrv" + prio=PR_BTPHONESRV_S + policy="tss" + user="" + shutdown_wait="no" /> + + <service + svcid="TSKM_SVCID_BTPBKSRV" + name =MN_BTPBKSRV + path="/usr/agl/bin/BT_PbkSrv" + prio=PR_BTPBKSRV_S + policy="tss" + user="" + shutdown_wait="no" /> + + <service + svcid="TSKM_SVCID_BTMSGSRV" + name =MN_BTMSGSRV + path="/usr/agl/bin/BT_MsgSrv" + prio=PR_BTMSGSRV_S + policy="tss" + user="" + shutdown_wait="no" /> + + <service + svcid="TSKM_SVCID_DTVVUPSRV" + name =MN_DTVVUPSERVICE + path="/usr/agl/bin/DtvVupService" + prio=PR_DTVVUPSERVICE_S + policy="tss" + user="" + shutdown_wait="no" /> + +</service_list> + diff --git a/task_manager/client/libtskmcfg/conf/tskm_shutdown.xml b/task_manager/client/libtskmcfg/conf/tskm_shutdown.xml new file mode 100644 index 00000000..4f724f75 --- /dev/null +++ b/task_manager/client/libtskmcfg/conf/tskm_shutdown.xml @@ -0,0 +1,11 @@ +<normal_shutdown> + <global_step> + <request_list> + <request svcid="TSKM_SVCID_TE_RESIDENT" local_step="last" /> + <!-- <request svcid="TSKM_SVCID_ACTIVITYMGR" local_step="last" /> --> + </request_list> + + <next_trans_condition cond="INI_TERMCOMP_TRANSIENT" /> + </global_step> +</normal_shutdown> + diff --git a/task_manager/client/libtskmcfg/conf/tskm_shutdown_vup.xml b/task_manager/client/libtskmcfg/conf/tskm_shutdown_vup.xml new file mode 100644 index 00000000..71a30c82 --- /dev/null +++ b/task_manager/client/libtskmcfg/conf/tskm_shutdown_vup.xml @@ -0,0 +1,6 @@ +<vup_shutdown> + <global_step> + <next_trans_condition cond="INI_TERMCOMP_TRANSIENT" /> + </global_step> +</vup_shutdown> + diff --git a/task_manager/client/libtskmcfg/conf/tskm_wakeup.xml b/task_manager/client/libtskmcfg/conf/tskm_wakeup.xml new file mode 100644 index 00000000..aeb35485 --- /dev/null +++ b/task_manager/client/libtskmcfg/conf/tskm_wakeup.xml @@ -0,0 +1,8 @@ +<normal_wakeup> + <global_step> + <next_trans_condition cond="INI_INITCOMP_ON_START" /> + </global_step> + <global_step> + <next_trans_condition cond="INI_INITCOMP_NVM_ACCESS" /> + </global_step> +</normal_wakeup> diff --git a/task_manager/client/libtskmcfg/conf/tskm_wakeup_vup.xml b/task_manager/client/libtskmcfg/conf/tskm_wakeup_vup.xml new file mode 100644 index 00000000..7162fdf3 --- /dev/null +++ b/task_manager/client/libtskmcfg/conf/tskm_wakeup_vup.xml @@ -0,0 +1,5 @@ +<vup_wakeup> + <global_step> + <next_trans_condition cond="INI_INITCOMP_NVM_ACCESS" /> + </global_step> +</vup_wakeup> diff --git a/task_manager/client/libtskmcfg/include/system_service/task_manager_libtskmcfg.h b/task_manager/client/libtskmcfg/include/system_service/task_manager_libtskmcfg.h new file mode 100644 index 00000000..2b765bca --- /dev/null +++ b/task_manager/client/libtskmcfg/include/system_service/task_manager_libtskmcfg.h @@ -0,0 +1,40 @@ +/* + * @copyright Copyright (c) 2017-2019 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. + */ +/** + * @file task_manager_libtskmcfg.h + * @brief \~english This file include tskm_svcid.h file and tskm_xml_data.h file + */ +/** @addtogroup BaseSystem + * @{ + */ +/** @addtogroup system_service + * @ingroup BaseSystem + * @{ + */ +/** @addtogroup task_manager + * @ingroup system_service + * @{ + */ +#ifndef SYSTEMSERVICE_TASKMNAGERLIBTASKMCFG_H_ // NOLINT(build/header_guard) +#define SYSTEMSERVICE_TASKMNAGERLIBTASKMCFG_H_ + +#include "system_service/tskm_svcid.h" +#include "system_service/tskm_xml_data.h" + +#endif // SYSTEMSERVICE_TASKMNAGERLIBTASKMCFG_H_ +/** @}*/ +/** @}*/ +/** @}*/ diff --git a/task_manager/client/libtskmcfg/include/system_service/tskm_svcid.h b/task_manager/client/libtskmcfg/include/system_service/tskm_svcid.h new file mode 100644 index 00000000..633d2b4d --- /dev/null +++ b/task_manager/client/libtskmcfg/include/system_service/tskm_svcid.h @@ -0,0 +1,59 @@ +/* + * @copyright Copyright (c) 2016-2019 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. + */ +/** + * @file tskm_svcid.h + * @brief \~english This file contains declaration of TSKM_SVC ID + */ +/** @addtogroup BaseSystem + * @{ + */ +/** @addtogroup system_service + * @ingroup BaseSystem + * @{ + */ +/** @addtogroup task_manager + * @ingroup system_service + * @{ + */ +/* + * Service ID + */ +#ifndef TASK_MANAGER_CLIENT_LIBTSKMCFG_INCLUDE_SYSTEM_SERVICE_TSKM_SVCID_H_ +#define TASK_MANAGER_CLIENT_LIBTSKMCFG_INCLUDE_SYSTEM_SERVICE_TSKM_SVCID_H_ + + +#define TSKM_SVCID_NONE 0x00000000U +#define TSKM_SVCID_TE_RESIDENT 0x00000001U // for test +#define TSKM_SVCID_TE_TRANSIENT 0x00000002U // for test +#define TSKM_SVCID_ACTIVITYMGR 0x00000003U +#define TSKM_SVCID_SYSVUP 0x00000004U // for vup +#define TSKM_SVCID__CWORD52_VUP 0x00000005U // for vup +#define TSKM_SVCID_ROOTFSVUP 0x00000006U // for vup +#define TSKM_SVCID_VUPPROGUI 0x00000007U // for vup +#define TSKM_SVCID_NORVUP 0x00000008U // for vup +#define TSKM_SVCID__CWORD58_ 0x00000009U // for _CWORD76_ +#define TSKM_SVCID_SYSUPDATE 0x0000000AU // for repro vup +#define TSKM_SVCID_NANDUPDATE 0x0000000BU // for repro vup +#define TSKM_SVCID_BTPHONESRV 0x0000000CU +#define TSKM_SVCID_BTPBKSRV 0x0000000DU +#define TSKM_SVCID_BTMSGSRV 0x0000000EU +#define TSKM_SVCID_DTVVUPSRV 0x0000000FU // fot peaks vup +#define TSKM_SVCID_XMVUPSRV 0x00000020U // fot XM_outer_update vup + +#endif // TASK_MANAGER_CLIENT_LIBTSKMCFG_INCLUDE_SYSTEM_SERVICE_TSKM_SVCID_H_ +/** @}*/ +/** @}*/ +/** @}*/ diff --git a/task_manager/client/libtskmcfg/include/system_service/tskm_xml_data.h b/task_manager/client/libtskmcfg/include/system_service/tskm_xml_data.h new file mode 100644 index 00000000..d1d3407e --- /dev/null +++ b/task_manager/client/libtskmcfg/include/system_service/tskm_xml_data.h @@ -0,0 +1,173 @@ +/* + * @copyright Copyright (c) 2016-2019 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. + */ +/** + * @file tskm_xml_data.h + * @brief \~english This file provide api to operating task manager with XML data + */ +/** @addtogroup BaseSystem + * @{ + */ +/** @addtogroup system_service + * @ingroup BaseSystem + * @{ + */ +/** @addtogroup task_manager + * @ingroup system_service + * @{ + */ +#ifndef TASK_MANAGER_CLIENT_LIBTSKMCFG_INCLUDE_SYSTEM_SERVICE_TSKM_XML_DATA_H_ +#define TASK_MANAGER_CLIENT_LIBTSKMCFG_INCLUDE_SYSTEM_SERVICE_TSKM_XML_DATA_H_ + +#include "system_service/tskm_type.h" +#include "system_service/tskm_svc.h" + + +#ifdef __cplusplus +extern "C" { +#endif + + ///////////////////////////////////////////////////////////////////////////////////// + /// \ingroup tskm_initServiceList + /// \~english @par Summary + /// init started services list + /// \~english @param [out] p_svcs + /// p_svcs - pointer of service list + /// \~english @par + /// p_svcs TSKM_SVCS_CTX_t* + /// \~english @code + /// typedef struct { + /// uint32_t svcNum; // service num + /// TSKM_SVC_CTX_t *svcList; // services list pointer + /// } TSKM_SVCS_CTX_t; + /// @endcode + /// \~english @param [in] iFd + /// iFd - the file descriptor return by inotify_init1(). + /// \~english @par + /// p_svcs int + /// \~english @retval 0 Success + /// \~english @retval -1 Failed + /// \~english @par Preconditions + /// - called in the ctxCreate() + /// \~english @par Change of the internal state + /// - The internal state is not changed. + /// \~english @par Causes of failures + /// - if srvId in serviceList greater than TSKM_SVC_ID_MAX_SIZE. [-1] + /// \~english @par Classification + /// - public + /// \~english @par Type + /// - sync only + /// \~english @par Detail + /// Init started services list\n + /// Get the started services list from static variable serviceList and init by input parameter iFd\n + /// If envirment is NFS, change the path after /tmp to CAP path.\n + /// + /// \~english @see None + //////////////////////////////////////////////////////////////////////////////////// +int tskm_initServiceList(TSKM_SVCS_CTX_t* p_svcs, int iFd); + + ///////////////////////////////////////////////////////////////////////////////////// + /// \ingroup tskm_initWakeupCtx + /// \~english @par Summary + /// Get state of started step. + /// \~english @param [out] p_wakeup + /// p_wakeup - pointer of TSKM_GSTEP_CTX_t + /// \~english @par + /// p_wakeup TSKM_GSTEP_CTX_t* + /// \~english @code + /// typedef struct { + /// uint32_t gstepIdx; // step Index + /// uint32_t gstepNum; // number of step + /// TSKM_GSTEP_t* gstep; // step start/stop info + /// uint64_t compState; + /// } TSKM_GSTEP_CTX_t; + /// @endcode + /// \~english @param [in] isVupMode + /// isVupMode - version up flag + /// \~english @par + /// isVupMode BOOL + /// TRUE version up mode + /// FALSE not versoin up mode + /// \~english @retval void + /// + /// \~english @par Preconditions + /// - called in ctxCreate() + /// \~english @par Change of the internal state + /// - The internal state is not changed. + /// \~english @par Causes of failures + /// - none + /// \~english @par Classification + /// - public + /// \~english @par Type + /// - sync only + /// \~english @par Detail + /// Get state of started step.\n + /// if version up mode is TRUE, retrun the wakeupGstepVup.\n + /// if version up mode is FALSE, return the wakeupGstep.\n + /// + /// \~english @see None + //////////////////////////////////////////////////////////////////////////////////// +void tskm_initWakeupCtx(TSKM_GSTEP_CTX_t* p_wakeup, BOOL isVupMode); + + + ///////////////////////////////////////////////////////////////////////////////////// + /// \ingroup tskm_initDownCtx + /// \~english @par Summary + /// Get state of down step. + /// \~english @param [out] p_down + /// p_down - pointer of TSKM_GSTEP_CTX_t + /// \~english @par + /// p_wakeup TSKM_GSTEP_CTX_t* + /// \~english @code + /// typedef struct { + /// uint32_t gstepIdx; // step Index + /// uint32_t gstepNum; // number of step + /// TSKM_GSTEP_t* gstep; // step start/stop info + /// uint64_t compState; + /// } TSKM_GSTEP_CTX_t; + /// @endcode + /// \~english @param [in] isVupMode + /// isVupMode - version up mode flag + /// \~english @par + /// isVupMode BOOL + /// TRUE version up mode + /// FALSE not versoin up mode + /// \~english @retval + /// \~english @par Preconditions + /// - called in ctxCreate(). + /// \~english @par Change of the internal state + /// - The internal state is not changed. + /// \~english @par Causes of failures + /// - none + /// \~english @par Classification + /// - public + /// \~english @par Type + /// - sync only + /// \~english @par Detail + /// Get state of down step.\n + /// if version up mode is TRUE, retrun the downGstepVup.\n + /// if version up mode is FALSE, return the downGstep.\n + /// \~english @see None + //////////////////////////////////////////////////////////////////////////////////// +void tskm_initDownCtx(TSKM_GSTEP_CTX_t* p_down, BOOL isVupMode); + +#ifdef __cplusplus +} +#endif + +#endif // TASK_MANAGER_CLIENT_LIBTSKMCFG_INCLUDE_SYSTEM_SERVICE_TSKM_XML_DATA_H_ +/** @}*/ +/** @}*/ +/** @}*/ diff --git a/task_manager/client/libtskmcfg/libtskmcfg.ver b/task_manager/client/libtskmcfg/libtskmcfg.ver new file mode 100644 index 00000000..696d5078 --- /dev/null +++ b/task_manager/client/libtskmcfg/libtskmcfg.ver @@ -0,0 +1,21 @@ +/* + * @copyright Copyright (c) 2016-2019 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. + */ + +{ + global: + tskm_init*; + local: *; +}; diff --git a/task_manager/client/libtskmcfg/src/parsexml.c b/task_manager/client/libtskmcfg/src/parsexml.c new file mode 100644 index 00000000..e67cd5c2 --- /dev/null +++ b/task_manager/client/libtskmcfg/src/parsexml.c @@ -0,0 +1,879 @@ +/* + * @copyright Copyright (c) 2016-2019 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 <stdio.h> +#include <stdlib.h> +#include <stdint.h> +#include <sys/types.h> +#include <sys/stat.h> +#include <string.h> +#include <unistd.h> +#include <errno.h> +#include <libgen.h> + +#include <expat.h> + +#define BUFSIZE 4096 +#define OUTFILE "tskm_auto_build.h" +#define TMPFILE "parsexml.tmp" + +typedef uint32_t ELE_STATE_t; +#define ELE_NONE 0x00000000U +#define ELE_TSKM_CFG 0x10000000U +#define ELE_SERVICE_LIST 0x11000000U +#define ELE_SERVICE 0x11100000U +#define ELE_SUBGID_LIST 0x11110000U + +#define ELE_COMMON_GSTEP 0x00100000U +#define ELE_COMMON_EXEC 0x00010000U +#define ELE_COMMON_REQ 0x00020000U + +#define ELE_NORMAL_WAKEUP 0x12000000U +#define ELE_NORMAL_W_GSTEP (ELE_NORMAL_WAKEUP|ELE_COMMON_GSTEP) +#define ELE_NORMAL_W_EXEC (ELE_NORMAL_WAKEUP|ELE_COMMON_GSTEP|ELE_COMMON_EXEC) +#define ELE_NORMAL_W_REQ (ELE_NORMAL_WAKEUP|ELE_COMMON_GSTEP|ELE_COMMON_REQ) + +#define ELE_NORMAL_SHUTDOWN 0x13000000U +#define ELE_NORMAL_D_GSTEP (ELE_NORMAL_SHUTDOWN|ELE_COMMON_GSTEP) +#define ELE_NORMAL_D_REQ (ELE_NORMAL_SHUTDOWN|ELE_COMMON_GSTEP|ELE_COMMON_REQ) + +#define ELE_VUP_WAKEUP 0x14000000U +#define ELE_VUP_W_GSTEP (ELE_VUP_WAKEUP|ELE_COMMON_GSTEP) +#define ELE_VUP_W_EXEC (ELE_VUP_WAKEUP|ELE_COMMON_GSTEP|ELE_COMMON_EXEC) +#define ELE_VUP_W_REQ (ELE_VUP_WAKEUP|ELE_COMMON_GSTEP|ELE_COMMON_REQ) + +#define ELE_VUP_SHUTDOWN 0x15000000U +#define ELE_VUP_D_GSTEP (ELE_VUP_SHUTDOWN|ELE_COMMON_GSTEP) +#define ELE_VUP_D_REQ (ELE_VUP_SHUTDOWN|ELE_COMMON_GSTEP|ELE_COMMON_REQ) + + +#define ELE_MASK0 0xF0000000U +#define ELE_MASK1 0x0F000000U +#define ELE_MASK2 0x00F00000U +#define ELE_MASK3 0x000F0000U + +#define PARSE_ASSERT_EXIT(x) \ + if(!(x)){ \ + printf("ASSERT %s:%s:%d\n",__FILE__,__FUNCTION__,__LINE__); \ + exit(-1); \ + } + +#define VALUE_NAME_MAX 255 +typedef struct { + int step; + char gstepIdStr[VALUE_NAME_MAX]; + int execSvcNum; + int reqNum; + char nextStepCondStr[VALUE_NAME_MAX]; + char execSvcName[VALUE_NAME_MAX]; + char reqTableName[VALUE_NAME_MAX]; +} PARSE_GSTEP_t; + + +typedef struct { + char svcid[VALUE_NAME_MAX]; + char name[VALUE_NAME_MAX]; + char path[VALUE_NAME_MAX]; + char type[VALUE_NAME_MAX]; + char life_cycle[VALUE_NAME_MAX]; + char retry_cnt[VALUE_NAME_MAX]; + char cpu_assign[VALUE_NAME_MAX]; + char prio[VALUE_NAME_MAX]; + char policy[VALUE_NAME_MAX]; + char user[VALUE_NAME_MAX]; + char runtime_limit[VALUE_NAME_MAX]; + char cpu_limit[VALUE_NAME_MAX]; + char mem_limit[VALUE_NAME_MAX]; + int subgidNum; + char args[VALUE_NAME_MAX]; + char shutdown_wait[VALUE_NAME_MAX]; +} PARSE_SVC_t; + +/*************************************** + * Context + **************************************/ +typedef struct { + FILE* fp; // Output file pointer + FILE* tmpFp; // Temporary file + ELE_STATE_t state; + + PARSE_SVC_t svc; + + int svcNum; // Number of services + PARSE_GSTEP_t gstep; +} PARSE_CTX_t; + + +/*************************************** + * entryTskmCfg + **************************************/ +void +entryTskmCfg(PARSE_CTX_t* p_ctx,const XML_Char* atts[]) { + p_ctx->state = ELE_TSKM_CFG; +} + +/*************************************** + * exitTskmCfg + **************************************/ +void +exitTskmCfg(PARSE_CTX_t* p_ctx) { + p_ctx->state = ELE_NONE; +} + + +/*************************************** + * entryServiceList + **************************************/ +void +entryServiceList(PARSE_CTX_t* p_ctx,const XML_Char* atts[]) { + p_ctx->state = ELE_SERVICE_LIST; + + p_ctx->tmpFp = fopen(TMPFILE,"w"); + + fprintf(p_ctx->tmpFp, + "static TSKM_SVC_ATTR_t serviceAttr[]={" + "\n"); +} + +/*************************************** + * exitServiceList + **************************************/ +void +exitServiceList(PARSE_CTX_t* p_ctx) { + fprintf(p_ctx->tmpFp, + "};" + "\n\n"); + + fprintf(p_ctx->tmpFp, "#define TSKM_SVC_NUM (%d) \n\n",p_ctx->svcNum); + + fprintf(p_ctx->tmpFp, "static TSKM_SVC_CTX_t serviceList[TSKM_SVC_NUM]; \n\n"); + + fclose(p_ctx->tmpFp); + + fprintf(p_ctx->fp,"\n\n"); + + p_ctx->state = ELE_TSKM_CFG; +} + +/*************************************** + * handleServiceList + **************************************/ +void +entryService(PARSE_CTX_t* p_ctx,const XML_Char *name,const XML_Char* atts[]) { + PARSE_ASSERT_EXIT(strcmp(name,"service") == 0); + int ii; + char* tp; + p_ctx->state = ELE_SERVICE; + + memset(&p_ctx->svc,0,sizeof(p_ctx->svc)); + + for(ii=0; atts[ii]; ii+=2) { + const char* attr = atts[ii]; + const char* value = atts[ii+1]; + if(strcmp(attr,"svcid")==0) { + strcpy(p_ctx->svc.svcid,value); + } else if(strcmp(attr,"name")==0) { + strcpy(p_ctx->svc.name,value); + } else if(strcmp(attr,"path")==0) { + strcpy(p_ctx->svc.path,value); + } else if(strcmp(attr,"type")==0) { + const char* typeName = (strcmp(value,"native")==0) ? "TSKM_SVC_TYPE_NATIVE" : "TSKM_SVC_TYPE_UNKNONW"; + strcpy(p_ctx->svc.type,typeName); + } else if(strcmp(attr,"prio")==0) { + strcpy(p_ctx->svc.prio,value); + } else if(strcmp(attr,"policy")==0) { + const char* polName = (strcmp(value,"fifo")==0) ? "TSKM_SVC_POLICY_FIFO" : + (strcmp(value,"tss")==0) ? "TSKM_SVC_POLICY_TSS" : + (strcmp(value,"rr")==0) ? "TSKM_SVC_POLICY_RR" : "ERROR"; + strcpy(p_ctx->svc.policy,polName); + } else if(strcmp(attr,"life_cycle")==0) { + const char* lcName = (strcmp(value,"always")==0) ? "TSKM_SVC_LC_ALWAYS" : + (strcmp(value,"always_recoverable")==0) ? "TSKM_SVC_LC_ALWAYS_RECOVERABLE" : + (strcmp(value,"dynamic")==0) ? "TSKM_SVC_LC_DYNAMIC" : "ERROR"; + strcpy(p_ctx->svc.life_cycle,lcName); + } else if(strcmp(attr,"retry_cnt")==0) { + strcpy(p_ctx->svc.retry_cnt,value); + } else if(strcmp(attr,"cpu_assign")==0) { + const char* caName = (strcmp(value,"cpu0")==0) ? "TSKM_SVC_ASSIGN_CPU_0" : + (strcmp(value,"cpu1")==0) ? "TSKM_SVC_ASSIGN_CPU_1" : + (strcmp(value,"auto")==0) ? "TSKM_SVC_ASSIGN_CPU_AUTO" : "ERROR"; + strcpy(p_ctx->svc.cpu_assign,caName); + } else if(strcmp(attr,"user")==0) { + strcpy(p_ctx->svc.user,value); + } else if(strcmp(attr,"runtime_limit")==0) { + strcpy(p_ctx->svc.runtime_limit,value); + } else if(strcmp(attr,"cpu_limit")==0) { + strcpy(p_ctx->svc.cpu_limit,value); + } else if(strcmp(attr,"mem_limit")==0) { + strcpy(p_ctx->svc.mem_limit,value); + } else if(strcmp(attr,"args")==0) { + strcpy(p_ctx->svc.args,value); + } else if(strcmp(attr,"shutdown_wait")==0) { + const char* swStr = (strcmp(value,"yes")==0) ? "TSKM_TRUE" : + (strcmp(value,"no")==0) ? "TSKM_FALSE" : "ERROR"; + strcpy(p_ctx->svc.shutdown_wait,swStr); + } + } + + fprintf(p_ctx->fp,"char const *svcArgs%d[] = {",p_ctx->svcNum); + fprintf(p_ctx->fp,"\"%s\",",p_ctx->svc.path); + + // Output arguments + tp = strtok(p_ctx->svc.args," "); + while(tp != NULL) { + fprintf(p_ctx->fp,"\"%s\",",tp); + tp = strtok(NULL," "); + } + + fprintf(p_ctx->fp,"NULL"); + fprintf(p_ctx->fp,"};\n"); +} + +/*************************************** + * exitService + **************************************/ +void +exitService(PARSE_CTX_t* p_ctx) { + uint32_t ii; + fprintf(p_ctx->tmpFp,"{" ); + + fprintf(p_ctx->tmpFp,"%s",p_ctx->svc.svcid); + fprintf(p_ctx->tmpFp,", (const char *)\"%s\"",p_ctx->svc.name); + fprintf(p_ctx->tmpFp,", (const char *)\"%s\"",p_ctx->svc.path); + fprintf(p_ctx->tmpFp,", (char**)svcArgs%d",p_ctx->svcNum); + fprintf(p_ctx->tmpFp,", %s",p_ctx->svc.type); + fprintf(p_ctx->tmpFp,", %s",p_ctx->svc.prio); + fprintf(p_ctx->tmpFp,", %s",p_ctx->svc.policy); + fprintf(p_ctx->tmpFp,", %s",p_ctx->svc.life_cycle); + fprintf(p_ctx->tmpFp,", (uint32_t)%s",p_ctx->svc.retry_cnt); + fprintf(p_ctx->tmpFp,", %s",p_ctx->svc.cpu_assign); + fprintf(p_ctx->tmpFp,", (const char *)\"%s\"",p_ctx->svc.user); + fprintf(p_ctx->tmpFp,", %s",(p_ctx->svc.runtime_limit[0] != '\0') ? p_ctx->svc.runtime_limit : "0"); + fprintf(p_ctx->tmpFp,", %s",(p_ctx->svc.cpu_limit[0] != '\0') ? p_ctx->svc.cpu_limit : "0"); + fprintf(p_ctx->tmpFp,", %s",(p_ctx->svc.mem_limit[0] != '\0') ? p_ctx->svc.mem_limit : "0"); + fprintf(p_ctx->tmpFp,", %s",p_ctx->svc.shutdown_wait); + fprintf(p_ctx->tmpFp,", %d",p_ctx->svc.subgidNum); + if(p_ctx->svc.subgidNum) { + fprintf(p_ctx->tmpFp,", subgidList%d",p_ctx->svcNum); + } else { + fprintf(p_ctx->tmpFp,", NULL"); + } + + fprintf(p_ctx->tmpFp,"},\n"); + + p_ctx->svcNum++; + + p_ctx->state = ELE_SERVICE_LIST; +} + +/*************************************** + * entrySubgidList + **************************************/ +void +entrySubgidList(PARSE_CTX_t* p_ctx,const XML_Char* atts[]) { + p_ctx->state = ELE_SUBGID_LIST; + + fprintf(p_ctx->fp,"static gid_t subgidList%d[] = {",p_ctx->svcNum); + + +} + +/*************************************** + * handleSubgidList + **************************************/ +void +handleSubgidList(PARSE_CTX_t* p_ctx,const XML_Char *name,const XML_Char* atts[]) { + PARSE_ASSERT_EXIT(strcmp(name,"subgid") == 0); + int32_t ii; + + if(p_ctx->svc.subgidNum > 0) { + fprintf(p_ctx->fp,","); + } + for(ii=0; atts[ii]; ii+=2) { + const char* attr = atts[ii]; + const char* value = atts[ii+1]; + if(strcmp(attr,"gid")==0) { + fprintf(p_ctx->fp,"%s",value); + } else { + PARSE_ASSERT_EXIT(0); + } + } + p_ctx->svc.subgidNum++; +} + +/*************************************** + * exitSubgidList + **************************************/ +void +exitSubgidList(PARSE_CTX_t* p_ctx) { + + fprintf(p_ctx->fp,"};\n"); + + p_ctx->state = ELE_SERVICE; +} + + +/*************************************** + * entryNormalWakeup + **************************************/ +void +entryNormalWakeup(PARSE_CTX_t* p_ctx,const XML_Char* atts[]) { + p_ctx->state = ELE_NORMAL_WAKEUP; + memset(&p_ctx->gstep,0,sizeof(p_ctx->gstep)); + + sprintf(p_ctx->gstep.reqTableName,"wakeupReqList"); + sprintf(p_ctx->gstep.execSvcName,"wakeupExecSvcId"); + p_ctx->tmpFp = fopen(TMPFILE,"a"); + PARSE_ASSERT_EXIT(p_ctx->tmpFp); + + fprintf(p_ctx->tmpFp,"TSKM_GSTEP_t wakeupGstep[]={\n"); +} + +/*************************************** + * exitNormalWakeup + **************************************/ +void +exitNormalWakeup(PARSE_CTX_t* p_ctx) { + fprintf(p_ctx->tmpFp,"};\n\n"); + fclose(p_ctx->tmpFp); + + p_ctx->state = ELE_TSKM_CFG; +} + +/*************************************** + * entryVupWakeup + **************************************/ +void +entryVupWakeup(PARSE_CTX_t* p_ctx,const XML_Char* atts[]) { + p_ctx->state = ELE_VUP_WAKEUP; + memset(&p_ctx->gstep,0,sizeof(p_ctx->gstep)); + + sprintf(p_ctx->gstep.reqTableName,"wakeupReqListVup"); + sprintf(p_ctx->gstep.execSvcName,"wakeupExecSvcIdVup"); + p_ctx->tmpFp = fopen(TMPFILE,"a"); + PARSE_ASSERT_EXIT(p_ctx->tmpFp); + + fprintf(p_ctx->tmpFp,"TSKM_GSTEP_t wakeupGstepVup[]={\n"); +} + +/*************************************** + * exitVupWakeup + **************************************/ +void +exitVupWakeup(PARSE_CTX_t* p_ctx) { + fprintf(p_ctx->tmpFp,"};\n\n"); + fclose(p_ctx->tmpFp); + + p_ctx->state = ELE_TSKM_CFG; +} + +void +entryGstep(PARSE_CTX_t* p_ctx,const XML_Char* atts[]) { + + p_ctx->state &= ~ELE_MASK2; + p_ctx->state |= ELE_COMMON_GSTEP; + + PARSE_GSTEP_t *p_gstep = &p_ctx->gstep; + + if(atts[0] && strcmp(atts[0],"stepid") == 0) { + sprintf(p_gstep->gstepIdStr,"%s",atts[1]); + } else { + sprintf(p_gstep->gstepIdStr,"TSKM_GSTEP_NONE"); + } + p_gstep->execSvcNum = 0; + p_gstep->reqNum = 0; + sprintf(p_gstep->nextStepCondStr,"INI_INITCOMP_NONE"); +} + +void +handleGstep(PARSE_CTX_t* p_ctx,const XML_Char *name,const XML_Char* atts[]) { + PARSE_ASSERT_EXIT(strcmp(name,"next_trans_condition") == 0); + PARSE_GSTEP_t *p_gstep = &p_ctx->gstep; + + if(atts[0] && strcmp(atts[0],"cond") == 0) { + sprintf(p_gstep->nextStepCondStr,"%s",atts[1]); + } else { + PARSE_ASSERT_EXIT(0); + } +} + +void +exitGstep(PARSE_CTX_t* p_ctx) { + PARSE_GSTEP_t *p_gstep = &p_ctx->gstep; + + fprintf(p_ctx->tmpFp,"{"); + fprintf(p_ctx->tmpFp,"%s,",p_gstep->gstepIdStr); + fprintf(p_ctx->tmpFp,"%d,",p_gstep->execSvcNum); + if(p_gstep->execSvcNum) { + fprintf(p_ctx->tmpFp,"%s%d,",p_gstep->execSvcName,p_gstep->step); + } else { + fprintf(p_ctx->tmpFp,"NULL,"); + } + fprintf(p_ctx->tmpFp,"%d,",p_gstep->reqNum); + if(p_gstep->reqNum) { + fprintf(p_ctx->tmpFp,"%s%d,",p_gstep->reqTableName,p_gstep->step); + } else { + fprintf(p_ctx->tmpFp,"NULL,"); + } + fprintf(p_ctx->tmpFp,"%s",p_gstep->nextStepCondStr); + fprintf(p_ctx->tmpFp,"},\n"); + + p_gstep->step++; + + p_ctx->state &= ~ELE_MASK2; +} + +void +entryExec(PARSE_CTX_t* p_ctx,const XML_Char* atts[]) { + p_ctx->state &= ~ELE_MASK3; + p_ctx->state |= ELE_COMMON_EXEC; + + PARSE_GSTEP_t *p_gstep = &p_ctx->gstep; + fprintf(p_ctx->fp, + "static TSKM_SVCID_t %s%d[] = {",p_gstep->execSvcName,p_gstep->step); +} +void +handleExec(PARSE_CTX_t* p_ctx,const XML_Char *name,const XML_Char* atts[]) { + PARSE_ASSERT_EXIT(strcmp(name,"exec_svc") == 0); + PARSE_GSTEP_t *p_gstep = &p_ctx->gstep; + int ii; + + if(p_gstep->execSvcNum > 0) { + fprintf(p_ctx->fp,","); + } + + for(ii=0; atts[ii]; ii+=2) { + const char* attr = atts[ii]; + const char* value = atts[ii+1]; + PARSE_ASSERT_EXIT(strcmp(attr,"svcid") == 0); + fprintf(p_ctx->fp,"%s",value); + } + p_gstep->execSvcNum++; +} +void +exitExec(PARSE_CTX_t* p_ctx) { + fprintf(p_ctx->fp,"};\n\n"); + p_ctx->state &= ~ELE_MASK3; +} + +void +entryReq(PARSE_CTX_t* p_ctx,const XML_Char* atts[]) { + p_ctx->state &= ~ELE_MASK3; + p_ctx->state |= ELE_COMMON_REQ; + PARSE_GSTEP_t *p_gstep = &p_ctx->gstep; + + fprintf(p_ctx->fp,"static TSKM_GSTEP_REQ_INFO_t %s%d[] ={",p_gstep->reqTableName,p_gstep->step); +} +void +handleReq(PARSE_CTX_t* p_ctx,const XML_Char *name,const XML_Char* atts[]) { + PARSE_GSTEP_t *p_gstep = &p_ctx->gstep; + PARSE_ASSERT_EXIT(strcmp(name,"request") == 0); + int ii; + + fprintf(p_ctx->fp," {"); + + for(ii=0; atts[ii]; ii+=2) { + const char* attr = atts[ii]; + const char* value = atts[ii+1]; + if(strcmp(attr,"local_step") == 0) { + if(strcmp(value,"shm") == 0) { + fprintf(p_ctx->fp,"TSKM_LSTEP_SHM"); + } else if(strcmp(value,"bupchk") == 0) { + fprintf(p_ctx->fp,"TSKM_LSTEP_BUPCHK"); + } else if(strcmp(value,"last") == 0) { + fprintf(p_ctx->fp,"TSKM_LSTEP_LAST"); + } else if(strcmp(value,"all") == 0) { + fprintf(p_ctx->fp,"TSKM_LSTEP_ALL"); + } else { + fprintf(p_ctx->fp,"%s",value); + } + } else { + fprintf(p_ctx->fp,"%s",value); // Output of "," + } + fprintf(p_ctx->fp,"%s",(atts[ii+2])?",":""); // Outoput of "," + } + fprintf(p_ctx->fp,"},"); + p_gstep->reqNum++; +} +void +exitReq(PARSE_CTX_t* p_ctx) { + fprintf(p_ctx->fp,"};\n\n"); + p_ctx->state &= ~ELE_MASK3; +} + +/*************************************** + * entryNormalShutdown + **************************************/ +void +entryNormalShutdown(PARSE_CTX_t* p_ctx,const XML_Char* atts[]) { + p_ctx->state = ELE_NORMAL_SHUTDOWN; + + memset(&p_ctx->gstep,0,sizeof(p_ctx->gstep)); + sprintf(p_ctx->gstep.reqTableName,"downReqList"); + p_ctx->tmpFp = fopen(TMPFILE,"a"); + PARSE_ASSERT_EXIT(p_ctx->tmpFp); + + fprintf(p_ctx->tmpFp,"static TSKM_GSTEP_t downGstep[]={\n"); +} + +/*************************************** + * exitNormalShutdown + **************************************/ +void +exitNormalShutdown(PARSE_CTX_t* p_ctx) { + + fprintf(p_ctx->tmpFp,"};\n\n"); + fclose(p_ctx->tmpFp); + + p_ctx->state = ELE_TSKM_CFG; +} + +/*************************************** + * entryVupShutdown + **************************************/ +void +entryVupShutdown(PARSE_CTX_t* p_ctx,const XML_Char* atts[]) { + p_ctx->state = ELE_VUP_SHUTDOWN; + memset(&p_ctx->gstep,0,sizeof(p_ctx->gstep)); + + sprintf(p_ctx->gstep.reqTableName,"downReqListVup"); + p_ctx->tmpFp = fopen(TMPFILE,"a"); + PARSE_ASSERT_EXIT(p_ctx->tmpFp); + + fprintf(p_ctx->tmpFp,"static TSKM_GSTEP_t downGstepVup[]={\n"); +} + +/*************************************** + * exitVupShutdown + **************************************/ +void +exitVupShutdown(PARSE_CTX_t* p_ctx) { + fprintf(p_ctx->tmpFp,"};\n\n"); + fclose(p_ctx->tmpFp); + + p_ctx->state = ELE_TSKM_CFG; +} + +/*************************************** + * elementStart + **************************************/ +void +elementStart(void *userData, const XML_Char *name, const XML_Char *atts[]) { + PARSE_CTX_t *p_ctx = (PARSE_CTX_t*)userData; +#if 0 + int ii; + printf("[ELEMENT] %s Start!\n", name); + for(ii=0; atts[ii]; ii+=2) { + printf(" %s:%s \n", atts[ii],atts[ii+1]); + } +#endif + switch(p_ctx->state) { + case ELE_NONE: + if(strcmp(name,"tskm_cfg") == 0) { + entryTskmCfg(p_ctx,atts); + } else { + PARSE_ASSERT_EXIT(0); + } + break; + case ELE_TSKM_CFG: + if(strcmp(name,"service_list") == 0) { + entryServiceList(p_ctx,atts); + } else if(strcmp(name,"normal_wakeup") == 0) { + entryNormalWakeup(p_ctx,atts); + } else if(strcmp(name,"normal_shutdown") == 0) { + entryNormalShutdown(p_ctx,atts); + } else if(strcmp(name,"vup_wakeup") == 0) { + entryVupWakeup(p_ctx,atts); + } else if(strcmp(name,"vup_shutdown") == 0) { + entryVupShutdown(p_ctx,atts); + } else { + PARSE_ASSERT_EXIT(0); + } + break; + case ELE_SERVICE_LIST: + if(strcmp(name,"service") == 0) { + entryService(p_ctx,name,atts); + } + break; + case ELE_SERVICE: + if(strcmp(name,"subgid_list") == 0) { + entrySubgidList(p_ctx,atts); + } + break; + case ELE_SUBGID_LIST: + handleSubgidList(p_ctx,name,atts); + break; + case ELE_NORMAL_WAKEUP: + case ELE_NORMAL_SHUTDOWN: + case ELE_VUP_WAKEUP: + case ELE_VUP_SHUTDOWN: + if(strcmp(name,"global_step") == 0) { + entryGstep(p_ctx,atts); + } else { + PARSE_ASSERT_EXIT(0); + } + break; + case ELE_NORMAL_W_GSTEP: + case ELE_NORMAL_D_GSTEP: + case ELE_VUP_W_GSTEP: + case ELE_VUP_D_GSTEP: + if(strcmp(name,"exec_list") == 0) { + entryExec(p_ctx,atts); + } else if(strcmp(name,"request_list") == 0) { + entryReq(p_ctx,atts); + } else { + handleGstep(p_ctx,name,atts); + } + break; + case ELE_NORMAL_W_EXEC: + case ELE_VUP_W_EXEC: + handleExec(p_ctx,name,atts); + break; + case ELE_NORMAL_W_REQ: + case ELE_NORMAL_D_REQ: + case ELE_VUP_W_REQ: + case ELE_VUP_D_REQ: + handleReq(p_ctx,name,atts); + break; + } +} + + +/*************************************** + * elementEnd + **************************************/ +void +elementEnd(void *userData, const XML_Char *name) { + PARSE_CTX_t *p_ctx = (PARSE_CTX_t*)userData; + switch(p_ctx->state) { + case ELE_NONE: + PARSE_ASSERT_EXIT(0); + break; + case ELE_TSKM_CFG: + if(strcmp(name,"tskm_cfg") == 0) { + exitTskmCfg(p_ctx); + } else { + PARSE_ASSERT_EXIT(0); + } + break; + case ELE_SERVICE_LIST: + if(strcmp(name,"service_list") == 0) { + exitServiceList(p_ctx); + } + break; + case ELE_SERVICE: + if(strcmp(name,"service") == 0) { + exitService(p_ctx); + } + break; + case ELE_SUBGID_LIST: + if(strcmp(name,"subgid_list") == 0) { + exitSubgidList(p_ctx); + } + break; + case ELE_NORMAL_WAKEUP: + if(strcmp(name,"normal_wakeup") == 0) { + exitNormalWakeup(p_ctx); + } + break; + case ELE_NORMAL_SHUTDOWN: + if(strcmp(name,"normal_shutdown") == 0) { + exitNormalShutdown(p_ctx); + } + break; + case ELE_VUP_WAKEUP: + if(strcmp(name,"vup_wakeup") == 0) { + exitVupWakeup(p_ctx); + } + break; + case ELE_VUP_SHUTDOWN: + if(strcmp(name,"vup_shutdown") == 0) { + exitVupShutdown(p_ctx); + } + break; + case ELE_NORMAL_D_GSTEP: + case ELE_NORMAL_W_GSTEP: + case ELE_VUP_D_GSTEP: + case ELE_VUP_W_GSTEP: + if(strcmp(name,"global_step") == 0) { + exitGstep(p_ctx); + } + break; + case ELE_NORMAL_W_EXEC: + case ELE_VUP_W_EXEC: + if(strcmp(name,"exec_list") == 0) { + exitExec(p_ctx); + } + break; + case ELE_NORMAL_D_REQ: + case ELE_NORMAL_W_REQ: + case ELE_VUP_D_REQ: + case ELE_VUP_W_REQ: + if(strcmp(name,"request_list") == 0) { + exitReq(p_ctx); + } + break; + } +} +/*************************************** + * parseXmlFile + **************************************/ +int +parseXmlFile(const char* file,XML_Parser parser) { + int ret = -1; + FILE* fp = fopen(file, "r"); + if (fp == NULL) { + goto ERROR; + } + + while(1) { + char *buf = (char*) XML_GetBuffer(parser, BUFSIZE); + if (!buf) { + goto ERROR; + } + + size_t nread = fread(buf, sizeof(char), BUFSIZE, fp); + if (ferror(fp)) { + goto ERROR; + } + + if (!XML_ParseBuffer(parser, nread, feof(fp))) { + goto ERROR; + } + + if (feof(fp)) { + break; + } + } + ret = 0; +ERROR: + if(fp) { + fclose(fp); + } + return ret; +} + +/*************************************** + * externalHandler + **************************************/ +int +externalHandler(XML_Parser parser, + const XML_Char* content, const XML_Char* base, + const XML_Char* systemId, const XML_Char* publicId) { + printf("parse %s \n",systemId); + + int ret = XML_ERROR_EXTERNAL_ENTITY_HANDLING; + XML_Parser extparser = NULL; + + extparser = XML_ExternalEntityParserCreate(parser, content, NULL); + if(extparser ==NULL) { + goto ERROR; + } + + if(parseXmlFile(systemId,extparser) != 0) { + goto ERROR; + } + ret = XML_STATUS_OK; +ERROR: + if(extparser) { + XML_ParserFree(extparser); + } + return ret; +} + +/*************************************** + * usage + **************************************/ +void +usage(const char* cmd) { + printf("usage:%s xmlfile\n",cmd); +} + +/*************************************** + * main + **************************************/ +int +main (int argc, char *argv[]) { + struct stat statinfo; + int ret=-1; + int xmlRet; + const char* inpath; + char tmpstr1[255]; + char tmpstr2[255]; + const char* workdir; + const char* infile; + XML_Parser parser; + PARSE_CTX_t ctx; + + if(argc < 2) { + usage(argv[0]); + goto ERROR; + } + + inpath = argv[1]; + if(0 != stat(inpath,&statinfo)) { + fprintf(stderr, "%s:%s",strerror(errno),inpath); + goto ERROR; + } + memset(&ctx,0,sizeof(ctx)); + + strcpy(tmpstr1,inpath); + strcpy(tmpstr2,inpath); + workdir=dirname(tmpstr1); + infile=basename(tmpstr2); + + if(0 != chdir(workdir)) { + fprintf(stderr, "%s:%s",strerror(errno),workdir); + goto ERROR; + } + + ctx.fp = fopen(OUTFILE, "w"); + if (ctx.fp == NULL) { + goto ERROR; + } + fprintf(ctx.fp,"//This file is created automatically from %s.\n",inpath); + fprintf(ctx.fp,"//So you shall not modify this file immediately.\n"); + + /* create XML parser */ + if ((parser = XML_ParserCreate(NULL)) == NULL) { + fprintf(stderr, "parser creation error\n"); + goto ERROR; + } + XML_SetUserData(parser,&ctx); + XML_SetParamEntityParsing(parser,XML_PARAM_ENTITY_PARSING_ALWAYS); // Allow External Entities + XML_SetExternalEntityRefHandler(parser,externalHandler); + XML_SetElementHandler(parser, elementStart, elementEnd); + + if(parseXmlFile(infile,parser) != 0) { + goto ERROR; + } + ret = 0; + +ERROR: + if(parser) { + XML_ParserFree(parser); + } + if(ctx.fp) { + fclose(ctx.fp); + } + char buf[255]; + sprintf(buf,"cat %s >> %s",TMPFILE,OUTFILE); + printf("%s\n",buf); + system(buf); + unlink(TMPFILE); + return ret; +} + diff --git a/task_manager/client/libtskmcfg/src/tskm_xml_data.cpp b/task_manager/client/libtskmcfg/src/tskm_xml_data.cpp new file mode 100644 index 00000000..dbdfde84 --- /dev/null +++ b/task_manager/client/libtskmcfg/src/tskm_xml_data.cpp @@ -0,0 +1,140 @@ +/* + * @copyright Copyright (c) 2016-2019 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_xml_data.h" + +#include <boost/algorithm/string.hpp> +#include <fstream> +#include <iostream> +#include <string> +#include <list> + +#include "system_service/tskm_svc.h" + +#include "system_service/tskm_svcid.h" +#include "tskm_debug.h" +#include "tskm_comm.h" +#include "tskm_auto_build.h" // Generated data from XML + +// This size depends on the size of the TM area of CL_Monitor +#define TSKM_SVC_ID_MAX_SIZE 1024 + +/*********************************************************************** + * tskm_initServiceList + ***********************************************************************/ +int tskm_initServiceList(TSKM_SVCS_CTX_t* p_svcs, int iFd) { + uint32_t ii; + + p_svcs->svcNum = sizeof(serviceList) / sizeof(TSKM_SVC_CTX_t); + p_svcs->svcList = serviceList; + + // It is initialized with the Inotify floppy disk. + for (ii = 0; ii < p_svcs->svcNum; ii++) { + serviceList[ii].attr = &serviceAttr[ii]; + serviceList[ii].iFd = iFd; + if (serviceList[ii].attr->svcId >= TSKM_SVC_ID_MAX_SIZE) { + TSKM_ASSERT(0); + return -1; + } + } + + const char* nfsenv = getenv("AGL_NFS"); + bool isNfs = (nfsenv && strcmp(nfsenv, "y") == 0) ? true : false; + + // For NFS environments, replace the PATH with CAP with /tmp + if (isNfs) { + std::list<std::string> capFiles; + const std::string capPath("/usr/debug/share/target/cap.lst"); + std::ifstream fin(capPath.c_str()); + std::string line; + while (fin && std::getline(fin, line)) { + std::list<std::string> strList; + try { // throw exception by boost::split + boost::split(strList, line, boost::is_any_of("|")); + if (!strList.empty()) { + if (strList.front()[0] == '/') { // Only character strings beginning with '/' are considered PATH + capFiles.push_back(strList.front().c_str()); + } + } + } catch (...) { + TSKM_ASSERT(0); + } + } + + for (ii = 0; ii < p_svcs->svcNum; ii++) { + std::string binPath(serviceList[ii].attr->path); + + for (std::list<std::string>::iterator ite = capFiles.begin(); + ite != capFiles.end(); ite++) { + if (binPath == *ite) { + std::list<std::string> nodes; + try { // throw exception by boost::split + boost::split(nodes, binPath, boost::is_any_of("/")); + std::string *p_newPath = new std::string("/tmp/"); // Intent not to free up memory + *p_newPath += nodes.back(); + TSKM_PRINTF(TSKM_LOG_STATE, "EXCHG %s", p_newPath->c_str()); + serviceList[ii].attr->path = p_newPath->c_str(); + delete p_newPath; + p_newPath = NULL; + break; + } catch (...) { + TSKM_ASSERT(0); + } + } + } + } + } + + // If there is no socket resource equal to the number of services + 1 (internal control connection), a compilation error occurs + TSKM_STATIC_ASSERT(TSKM_COMM_CONNECT_MAX >= (TSKM_SVC_NUM+1)); + + return 0; +} + +/*********************************************************************** + * tskm_initWakeupCtx + ***********************************************************************/ +void tskm_initWakeupCtx(TSKM_GSTEP_CTX_t* p_wakeup, BOOL isVupMode) { + memset(p_wakeup, 0, sizeof(*p_wakeup)); + + if (isVupMode) { + p_wakeup->gstepNum = sizeof(wakeupGstepVup) / sizeof(TSKM_GSTEP_t); + p_wakeup->gstep = wakeupGstepVup; + } else { + p_wakeup->gstepNum = sizeof(wakeupGstep) / sizeof(TSKM_GSTEP_t); + p_wakeup->gstep = wakeupGstep; + } + + TSKM_PRINTF(TSKM_LOG_STATE, "gstep(wakeup):%d", p_wakeup->gstepNum); +} + +/*********************************************************************** + * tskm_initDownCtx + ***********************************************************************/ +void tskm_initDownCtx(TSKM_GSTEP_CTX_t* p_down, BOOL isVupMode) { + memset(p_down, 0, sizeof(*p_down)); + + if (isVupMode) { + p_down->gstepNum = sizeof(downGstepVup) / sizeof(TSKM_GSTEP_t); + p_down->gstep = downGstepVup; + } else { + p_down->gstepNum = sizeof(downGstep) / sizeof(TSKM_GSTEP_t); + p_down->gstep = downGstep; + } + + TSKM_PRINTF(TSKM_LOG_STATE, "gstep(down):%d", p_down->gstepNum); +} + diff --git a/task_manager/client/libtskmcfg/tskm_cfg.xml b/task_manager/client/libtskmcfg/tskm_cfg.xml new file mode 100644 index 00000000..2898f442 --- /dev/null +++ b/task_manager/client/libtskmcfg/tskm_cfg.xml @@ -0,0 +1,83 @@ +<?xml version="1.0" ?> + +<!DOCTYPE tskm_cfg [ + <!ELEMENT tskm_cfg (service_list,normal_wakeup,normal_shutdown,vup_wakeup,vup_shutdown) > + + <!-- service list --> + <!ELEMENT service_list (service+) > + <!ELEMENT service (subgid_list*) > + <!ATTLIST service + svcid ID #REQUIRED + name CDATA #REQUIRED + path CDATA #REQUIRED + type (native|unknown) "native" + prio CDATA #REQUIRED + policy (fifo|tss|rr) #REQUIRED + life_cycle (always|always_recoverable|dynamic) "dynamic" + retry_cnt CDATA "1" + cpu_assign (cpu0|cpu1|auto) "auto" + user CDATA #REQUIRED + runtime_limit CDATA #IMPLIED + cpu_limit CDATA #IMPLIED + mem_limit CDATA #IMPLIED + args CDATA #IMPLIED + shutdown_wait (yes|no) #REQUIRED + > + + <!ELEMENT subgid_list (subgid+) > + <!ELEMENT subgid EMPTY > + <!ATTLIST subgid + gid CDATA #REQUIRED + > + + + <!-- Starting/terminating of services --> + <!ELEMENT normal_wakeup (global_step+) > + <!ELEMENT normal_shutdown (global_step+) > + <!ELEMENT vup_wakeup (global_step+) > + <!ELEMENT vup_shutdown (global_step+) > + + <!ELEMENT global_step (exec_list?,request_list?,next_trans_condition?) > + <!ATTLIST global_step + stepid ID #IMPLIED + > + + <!ELEMENT exec_list (exec_svc+) > + <!ELEMENT exec_svc EMPTY > + + <!ATTLIST exec_svc + svcid IDREF #REQUIRED + > + + <!ELEMENT request_list (request+) > + <!ELEMENT request EMPTY > + <!ATTLIST request + svcid IDREF #REQUIRED + local_step (shm|bupchk|1|2|3|4|5|6|7|8|9|last|all) #REQUIRED + > + + <!ELEMENT next_trans_condition EMPTY> + <!ATTLIST next_trans_condition + cond CDATA #REQUIRED + > + + <!ENTITY service_list_xml SYSTEM "tskm_launch.xml"> + <!ENTITY normal_wakeup_xml SYSTEM "tskm_wakeup.xml"> + <!ENTITY normal_shutdown_xml SYSTEM "tskm_shutdown.xml"> + <!ENTITY vup_wakeup_xml SYSTEM "tskm_wakeup_vup.xml"> + <!ENTITY vup_shutdown_xml SYSTEM "tskm_shutdown_vup.xml"> +]> + + +<tskm_cfg> + &service_list_xml; + + &normal_wakeup_xml; + + &normal_shutdown_xml; + + &vup_wakeup_xml; + + &vup_shutdown_xml; + +</tskm_cfg> diff --git a/task_manager/client/ss_data_init/Makefile b/task_manager/client/ss_data_init/Makefile new file mode 100644 index 00000000..b6ebfd57 --- /dev/null +++ b/task_manager/client/ss_data_init/Makefile @@ -0,0 +1,43 @@ +# +# @copyright Copyright (c) 2016-2019 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. +# + +####################################### +####################################### +INST_SHLIBS := libss_data_init + +MKDATAINIT=mkdatainit.sh + +INST_HEADERS = tskm_data_init.h task_manager_libss_data_init.h + +VPATH = ./include/$(COMPONENT_NAME) +CPPFLAGS += -I./include/ -I./../../server/include -I./../libtskmcfg/include + +libss_data_init_SRCS := tskm_data_init.cpp +libss_data_init_PCOS := $(shell ls ./obj/*.os) + +$(libss_data_init_SRCS): $(libss_data_init_PCOS) + set -e ; \ + sh $(MKDATAINIT) + +######## add compile option ######## +LDFLAGS += -Wl,--no-as-needed +CPPFLAGS += -fno-exceptions + +CLEAN_FILES=$(libss_data_init_SRCS) + +LDLIBS = -Wl,-Bdynamic -lNS_FrameworkUnified + +include ../../../system_service.mk diff --git a/task_manager/client/ss_data_init/include/libss_data_init_taskmanagerlog.h b/task_manager/client/ss_data_init/include/libss_data_init_taskmanagerlog.h new file mode 100644 index 00000000..4c04ad7b --- /dev/null +++ b/task_manager/client/ss_data_init/include/libss_data_init_taskmanagerlog.h @@ -0,0 +1,78 @@ +/* + * @copyright Copyright (c) 2016-2019 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. + */ + +#ifndef TASK_MANAGER_CLIENT_SS_DATA_INIT_INCLUDE_LIBSS_DATA_INIT_TASKMANAGERLOG_H_ +#define TASK_MANAGER_CLIENT_SS_DATA_INIT_INCLUDE_LIBSS_DATA_INIT_TASKMANAGERLOG_H_ + +#include <native_service/ns_logger_if.h> + +#define ZONE_INIT ZONEMASK(10) // library common def +#define ZONE_FUNC ZONEMASK(11) // library common def +#define ZONE_MEM ZONEMASK(12) // library common def +#define ZONE_13 ZONEMASK(13) +#define ZONE_14 ZONEMASK(14) +#define ZONE_15 ZONEMASK(15) +#define ZONE_16 ZONEMASK(16) +#define ZONE_17 ZONEMASK(17) +#define ZONE_18 ZONEMASK(18) +#define ZONE_19 ZONEMASK(19) +#define ZONE_20 ZONEMASK(20) +#define ZONE_21 ZONEMASK(21) +#define ZONE_22 ZONEMASK(22) +#define ZONE_23 ZONEMASK(23) +#define ZONE_24 ZONEMASK(24) +#define ZONE_25 ZONEMASK(25) +#define ZONE_26 ZONEMASK(26) +#define ZONE_27 ZONEMASK(27) +#define ZONE_28 ZONEMASK(28) +#define ZONE_INFO ZONEMASK(29) // library common def +#define ZONE_WARN ZONEMASK(30) // library common def +#define ZONE_ERR ZONEMASK(31) // library common def + +#define ZONE_TEXT_10 "Init" +#define ZONE_TEXT_11 "Function" +#define ZONE_TEXT_12 "Memory" +#define ZONE_TEXT_13 "" +#define ZONE_TEXT_14 "" +#define ZONE_TEXT_15 "" +#define ZONE_TEXT_16 "" +#define ZONE_TEXT_17 "" +#define ZONE_TEXT_18 "" +#define ZONE_TEXT_19 "" +#define ZONE_TEXT_20 "" +#define ZONE_TEXT_21 "" +#define ZONE_TEXT_22 "" +#define ZONE_TEXT_23 "" +#define ZONE_TEXT_24 "" +#define ZONE_TEXT_25 "" +#define ZONE_TEXT_26 "" +#define ZONE_TEXT_27 "" +#define ZONE_TEXT_28 "" +#define ZONE_TEXT_29 "Info" +#define ZONE_TEXT_30 "Warning" +#define ZONE_TEXT_31 "Error" + +#ifndef FRAMEWORKUNIFIEDLOGOPTIONS +#define FRAMEWORKUNIFIEDLOGOPTIONS (LPRINT) // LPRINT +#endif + +#ifndef FRAMEWORKUNIFIEDLOGAPPZONES +#define FRAMEWORKUNIFIEDLOGAPPZONES ZONE_INFO +#endif /* FRAMEWORKUNIFIEDLOGAPPZONES */ + +extern FRAMEWORKUNIFIEDLOGPARAM g_FrameworkunifiedLogParams; + +#endif // TASK_MANAGER_CLIENT_SS_DATA_INIT_INCLUDE_LIBSS_DATA_INIT_TASKMANAGERLOG_H_ diff --git a/task_manager/client/ss_data_init/include/system_service/task_manager_libss_data_init.h b/task_manager/client/ss_data_init/include/system_service/task_manager_libss_data_init.h new file mode 100644 index 00000000..701df3d5 --- /dev/null +++ b/task_manager/client/ss_data_init/include/system_service/task_manager_libss_data_init.h @@ -0,0 +1,39 @@ +/* + * @copyright Copyright (c) 2017-2019 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. + */ +/** + * @file + * @brief \~english This file include tskm_data_init.h + */ +/** @addtogroup BaseSystem + * @{ + */ +/** @addtogroup system_service + * @ingroup BaseSystem + * @{ + */ +/** @addtogroup task_manager + * @ingroup system_service + * @{ + */ +#ifndef SYSTEMSERVICE_TASKMNAGERLIBSSDATAINIT_H_ // NOLINT(build/header_guard) +#define SYSTEMSERVICE_TASKMNAGERLIBSSDATAINIT_H_ + +#include "system_service/tskm_data_init.h" + +#endif // SYSTEMSERVICE_TASKMNAGERLIBSSDATAINIT_H_ +/** @}*/ +/** @}*/ +/** @}*/ diff --git a/task_manager/client/ss_data_init/include/system_service/tskm_data_init.h b/task_manager/client/ss_data_init/include/system_service/tskm_data_init.h new file mode 100644 index 00000000..2d609788 --- /dev/null +++ b/task_manager/client/ss_data_init/include/system_service/tskm_data_init.h @@ -0,0 +1,121 @@ +/* + * @copyright Copyright (c) 2016-2019 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. + */ + + +/** + * @file tskm_data_init.h + * @brief \~english This file contains API of initial task manager data + */ +/** @addtogroup BaseSystem + * @{ + */ +/** @addtogroup system_service + * @ingroup BaseSystem + * @{ + */ +/** @addtogroup task_manager + * @ingroup system_service + * @{ + */ + +#ifndef TASK_MANAGER_CLIENT_SS_DATA_INIT_INCLUDE_SYSTEM_SERVICE_TSKM_DATA_INIT_H_ +#define TASK_MANAGER_CLIENT_SS_DATA_INIT_INCLUDE_SYSTEM_SERVICE_TSKM_DATA_INIT_H_ + +#include <native_service/frameworkunified_types.h> +#include <system_service/ss_system_manager_if.h> +#include "system_service/tskm_type.h" + +///////////////////////////////////////////////////////////////////////////////////// +/// \ingroup TSKM_GetExtBootInfo +/// \~english @par Summary +/// Gets boot extended information. +/// \~english @param [in] p_info +/// T_SS_SM_START_ExtDataStructType * - Boot extended information +/// \~english @code +/// typedef struct { +/// BOOL isProgUpdated; +/// EMRelaunchStatus relaunchStatus; +/// BOOL isMapUpdated; +/// BOOL isMapDiffUpdated; +/// uint8_t reserved[]; +/// }T_SS_SM_START_ExtDataStructType; +/// @endcode +/// \~english @retval TSKM_E_OK Normal end +/// \~english @retval TSKM_E_PAR %Parameter error +/// \~english @par Preconditions +/// - None +/// \~english @par Change of the internal state +/// - The internal state is not changed. +/// \~english @par Causes of failures +/// - p_info is NULL. [TSKM_E_PAR] +/// \~english @par Classification +/// Public +/// \~english @par Type +/// Sync only +/// \~english @par Detail +/// Is available only at the functions defined by using TSKM_DATA_INIT_FUNC. +/// \~english @see TSKM_DATA_INIT_FUNC +//////////////////////////////////////////////////////////////////////////////////// +TSKM_ERR_t TSKM_GetExtBootInfo(T_SS_SM_START_ExtDataStructType *p_info); + +///////////////////////////////////////////////////////////////////////////////////// +/// \ingroup TSKM_DATA_INIT_FUNC +/// \~english @par Summary +/// Defines callback functions to initialize data. +/// \~english @param [in] serviceName +/// const char* - Service name +/// \~english @param [in] argName +/// const T_SS_SM_START_DataStructType* - Argument name +/// \~english @code +/// typedef struct T_SS_SM_START_DataStruct{ +/// EPWR_WAKEUP_FACTOR_TYPE startupReason; +/// BOOL isUserModeOn; +/// ESMDataResetModeInfo dataResetMode; +/// EPWR_SC_SECURITY_STATUS securityStatus; +/// EPWR_SC_WAKEUP_TYPE wakeupType; +/// ESMDramBackupStatus dramBackupStatus; +/// ESMResetStatus resetStatus; +/// UI_32 resetCount; +/// } T_SS_SM_START_DataStructType; +/// @endcode +/// \~english @retval eFrameworkunifiedStatusOK Normal +/// \~english @retval eFrameworkunifiedStatusFail Check error +/// \~english @par Preconditions +/// - None +/// \~english @par Change of the internal state +/// - The internal state is not changed. +/// \~english @par Causes of failures +/// - Return values depend on the mount of callback functions. [eFrameworkunifiedStatusFail] +/// \~english @par Classification +/// Public +/// \~english @par Detail +/// Defines the callback functions to initialize data. \n +/// The callback functions defined by this macro are executed at a timing +/// when boot factor is fixed after booting the system. \n +/// (Task_Manager executes Callback prior to the boot of ActivityManager.)\n +/// If each service mounts and installs initialization functions, Task_Manager boots it +/// at a timing when data initialization is necessary. \n +/// Each service can install the object file of initialization functions by setting them +/// to MAKE variables INST_DATAINITOBJ of Makefile. +/// \~english @see None +//////////////////////////////////////////////////////////////////////////////////// +#define TSKM_DATA_INIT_FUNC(ServiceName, ArgName) \ + EFrameworkunifiedStatus tskm_ ## ServiceName ## _data_init(T_SS_SM_START_DataStructType* ArgName) + +#endif // TASK_MANAGER_CLIENT_SS_DATA_INIT_INCLUDE_SYSTEM_SERVICE_TSKM_DATA_INIT_H_ +/** @}*/ // end of Task_Manager +/** @}*/ // end of SystemService +/** @}*/ // end of BaseSystem diff --git a/task_manager/client/ss_data_init/include/tskm_data_init_local.h b/task_manager/client/ss_data_init/include/tskm_data_init_local.h new file mode 100644 index 00000000..14fbdbdc --- /dev/null +++ b/task_manager/client/ss_data_init/include/tskm_data_init_local.h @@ -0,0 +1,25 @@ +/* + * @copyright Copyright (c) 2016-2019 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. + */ + +#ifndef TASK_MANAGER_CLIENT_SS_DATA_INIT_INCLUDE_TSKM_DATA_INIT_LOCAL_H_ +#define TASK_MANAGER_CLIENT_SS_DATA_INIT_INCLUDE_TSKM_DATA_INIT_LOCAL_H_ + +#include "system_service/tskm_data_init.h" + +extern void tskm_dataInitAll(T_SS_SM_START_DataStructType *arg, + T_SS_SM_START_ExtDataStructType *extArg); + +#endif // TASK_MANAGER_CLIENT_SS_DATA_INIT_INCLUDE_TSKM_DATA_INIT_LOCAL_H_ diff --git a/task_manager/client/ss_data_init/mkdatainit.sh b/task_manager/client/ss_data_init/mkdatainit.sh new file mode 100644 index 00000000..4d33a01e --- /dev/null +++ b/task_manager/client/ss_data_init/mkdatainit.sh @@ -0,0 +1,45 @@ +#!/bin/bash + +# +# Copyright (c) 2019 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. +# + +cp tskm_data_init.cpp.in tskm_data_init.cpp.tmp + +LF=$(printf '\\\012_') +LF=${LF%_} + +for files in `ls obj/*.os` +do + serviceName=`nm -C $files | grep " T " | grep -o "tskm_[0-9a-zA-Z_]\+_data_init" | sed -e "s/^tskm_//" | sed -e "s/_data_init\$//"` + + funcname="tskm_"$serviceName"_data_init" + + echo $serviceName $funcname + sed -i "s/@DATA_INIT_PROT@/EFrameworkunifiedStatus $funcname(T_SS_SM_START_DataStructType* );$LF@DATA_INIT_PROT@/g" tskm_data_init.cpp.tmp + sed -i "s/@DATA_INIT_TABLE@/{\"$serviceName\", $funcname},$LF @DATA_INIT_TABLE@/g" tskm_data_init.cpp.tmp + +done + +sed -i "s/@DATA_INIT_PROT@//g" tskm_data_init.cpp.tmp +sed "s/@DATA_INIT_TABLE@/{NULL , NULL},/g" tskm_data_init.cpp.tmp > tskm_data_init.cpp + +rm tskm_data_init.cpp.tmp + + + + + + diff --git a/task_manager/client/ss_data_init/tskm_data_init.cpp.in b/task_manager/client/ss_data_init/tskm_data_init.cpp.in new file mode 100644 index 00000000..fc28c67d --- /dev/null +++ b/task_manager/client/ss_data_init/tskm_data_init.cpp.in @@ -0,0 +1,66 @@ +/* + * @copyright Copyright (c) 2019 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_data_init.h> +#include "stdio.h" +#include "libss_data_init_taskmanagerlog.h" + + +#define ZONE_INFO ZONEMASK(29) + +typedef struct{ + const char *serviceName; + EFrameworkunifiedStatus (*dataInitFunc)(T_SS_SM_START_DataStructType *arg); +} FUNC_INFO_t; + +@DATA_INIT_PROT@ + +const FUNC_INFO_t g_funcTbl[] = { + @DATA_INIT_TABLE@ +}; + +static T_SS_SM_START_ExtDataStructType extBootInfo; + +TSKM_ERR_t TSKM_GetExtBootInfo(T_SS_SM_START_ExtDataStructType *p_info){ + TSKM_ERR_t ret = TSKM_E_OK; + + if(NULL == p_info){ + FRAMEWORKUNIFIEDLOG(ZONE_ERR,__FUNCTION__,"p_info = NULL"); + ret = TSKM_E_PAR; + }else{ + memcpy(p_info, &extBootInfo, sizeof(*p_info)); + } + + return ret; +} + +void tskm_dataInitAll(T_SS_SM_START_DataStructType *arg, T_SS_SM_START_ExtDataStructType *extArg){ + int i; + int itemNum = sizeof(g_funcTbl)/sizeof(FUNC_INFO_t) - 1; + + memcpy(&extBootInfo, extArg, sizeof(extBootInfo)); + + // LCOV_EXCL_START 10: Depends on reference information when building software + for(i=0;i<itemNum;i++){ + FRAMEWORKUNIFIEDLOG(ZONE_INFO,__FUNCTION__,"call datainit for %s",g_funcTbl[i].serviceName); + g_funcTbl[i].dataInitFunc(arg); + } + // LCOV_EXCL_STOP + + return; +} // LCOV_EXCL_BR_LINE 10: Final line + + |