From 8e0e00d21146a84c18f9cf9409e187b4fb0248aa Mon Sep 17 00:00:00 2001 From: Riku Nomoto Date: Thu, 19 Nov 2020 12:45:32 +0900 Subject: Init basesystem source codes. Signed-off-by: Riku Nomoto Change-Id: I55aa2f1406ce7f751ae14140b613b53b68995528 --- systemservice/task_manager/LICENSE | 177 +++ systemservice/task_manager/Makefile.client | 21 + systemservice/task_manager/Makefile.server | 21 + systemservice/task_manager/client/Makefile | 26 + .../task_manager/client/libprimary/Makefile | 37 + .../client/libprimary/include/pri_main.h | 48 + .../task_manager/client/libprimary/libprimary.ver | 22 + .../task_manager/client/libprimary/src/pri_api.cpp | 224 ++++ .../client/libprimary/src/pri_main.cpp | 873 +++++++++++++ systemservice/task_manager/client/libtskm/Makefile | 35 + systemservice/task_manager/client/libtskm/TSKM.api | 9 + .../task_manager/client/libtskm/libtskm.ver | 21 + .../client/libtskm/src/tskm_api_lib.cpp | 90 ++ .../task_manager/client/libtskmcfg/Makefile | 93 ++ .../client/libtskmcfg/conf/agl_thread.h | 1377 ++++++++++++++++++++ .../client/libtskmcfg/conf/tskm_launch.xml | 106 ++ .../client/libtskmcfg/conf/tskm_shutdown.xml | 11 + .../client/libtskmcfg/conf/tskm_shutdown_vup.xml | 6 + .../client/libtskmcfg/conf/tskm_wakeup.xml | 8 + .../client/libtskmcfg/conf/tskm_wakeup_vup.xml | 5 + .../system_service/task_manager_libtskmcfg.h | 40 + .../libtskmcfg/include/system_service/tskm_svcid.h | 59 + .../include/system_service/tskm_xml_data.h | 173 +++ .../task_manager/client/libtskmcfg/libtskmcfg.ver | 21 + .../task_manager/client/libtskmcfg/src/parsexml.c | 879 +++++++++++++ .../client/libtskmcfg/src/tskm_xml_data.cpp | 138 ++ .../task_manager/client/libtskmcfg/tskm_cfg.xml | 83 ++ .../task_manager/client/ss_data_init/Makefile | 43 + .../include/libss_data_init_taskmanagerlog.h | 78 ++ .../system_service/task_manager_libss_data_init.h | 39 + .../include/system_service/tskm_data_init.h | 121 ++ .../ss_data_init/include/tskm_data_init_local.h | 25 + .../task_manager/client/ss_data_init/mkdatainit.sh | 45 + .../client/ss_data_init/tskm_data_init.cpp.in | 66 + .../task_manager/include-share/tskm_gstep.h | 54 + .../task_manager/include-share/tskm_type_local.h | 52 + .../task_manager/include-share/tskm_util.h | 32 + systemservice/task_manager/server/Makefile | 67 + .../server/include/system_service/INI_API.h | 25 + .../server/include/system_service/INI_API.hpp | 738 +++++++++++ .../server/include/system_service/Primary_common.h | 148 +++ .../server/include/system_service/sysup.h | 41 + .../server/include/system_service/sysup_from.h | 41 + .../server/include/system_service/task_manager.h | 54 + .../server/include/system_service/tskm.h | 413 ++++++ .../include/system_service/tskm_local_type.h | 287 ++++ .../server/include/system_service/tskm_svc.h | 904 +++++++++++++ .../server/include/system_service/tskm_type.h | 123 ++ .../task_manager/server/include/tskm_comm.h | 59 + .../task_manager/server/include/tskm_debug.h | 208 +++ .../task_manager/server/include/tskm_main.h | 71 + .../task_manager/server/include/tskm_port_pf.h | 46 + .../task_manager/server/include/tskm_port_subsys.h | 42 + .../task_manager/server/include/tskm_shutdown.h | 27 + .../task_manager/server/include/tskm_state.h | 36 + .../task_manager/server/include/tskm_wakeup.h | 26 + .../task_manager/server/include/tskm_watch.h | 25 + systemservice/task_manager/server/src/pri_main.cpp | 840 ++++++++++++ systemservice/task_manager/server/src/tskm_api.cpp | 268 ++++ .../task_manager/server/src/tskm_comm.cpp | 402 ++++++ .../task_manager/server/src/tskm_debug.cpp | 286 ++++ .../task_manager/server/src/tskm_main.cpp | 727 +++++++++++ .../task_manager/server/src/tskm_port_pf.cpp | 884 +++++++++++++ .../task_manager/server/src/tskm_port_subsys.cpp | 297 +++++ .../task_manager/server/src/tskm_shutdown.cpp | 242 ++++ .../task_manager/server/src/tskm_state.cpp | 452 +++++++ systemservice/task_manager/server/src/tskm_svc.cpp | 970 ++++++++++++++ .../task_manager/server/src/tskm_wakeup.cpp | 201 +++ .../task_manager/server/src/tskm_watch.cpp | 101 ++ 69 files changed, 14209 insertions(+) create mode 100755 systemservice/task_manager/LICENSE create mode 100755 systemservice/task_manager/Makefile.client create mode 100755 systemservice/task_manager/Makefile.server create mode 100755 systemservice/task_manager/client/Makefile create mode 100755 systemservice/task_manager/client/libprimary/Makefile create mode 100755 systemservice/task_manager/client/libprimary/include/pri_main.h create mode 100755 systemservice/task_manager/client/libprimary/libprimary.ver create mode 100755 systemservice/task_manager/client/libprimary/src/pri_api.cpp create mode 100755 systemservice/task_manager/client/libprimary/src/pri_main.cpp create mode 100755 systemservice/task_manager/client/libtskm/Makefile create mode 100755 systemservice/task_manager/client/libtskm/TSKM.api create mode 100755 systemservice/task_manager/client/libtskm/libtskm.ver create mode 100755 systemservice/task_manager/client/libtskm/src/tskm_api_lib.cpp create mode 100755 systemservice/task_manager/client/libtskmcfg/Makefile create mode 100755 systemservice/task_manager/client/libtskmcfg/conf/agl_thread.h create mode 100755 systemservice/task_manager/client/libtskmcfg/conf/tskm_launch.xml create mode 100755 systemservice/task_manager/client/libtskmcfg/conf/tskm_shutdown.xml create mode 100755 systemservice/task_manager/client/libtskmcfg/conf/tskm_shutdown_vup.xml create mode 100755 systemservice/task_manager/client/libtskmcfg/conf/tskm_wakeup.xml create mode 100755 systemservice/task_manager/client/libtskmcfg/conf/tskm_wakeup_vup.xml create mode 100755 systemservice/task_manager/client/libtskmcfg/include/system_service/task_manager_libtskmcfg.h create mode 100755 systemservice/task_manager/client/libtskmcfg/include/system_service/tskm_svcid.h create mode 100755 systemservice/task_manager/client/libtskmcfg/include/system_service/tskm_xml_data.h create mode 100755 systemservice/task_manager/client/libtskmcfg/libtskmcfg.ver create mode 100755 systemservice/task_manager/client/libtskmcfg/src/parsexml.c create mode 100755 systemservice/task_manager/client/libtskmcfg/src/tskm_xml_data.cpp create mode 100755 systemservice/task_manager/client/libtskmcfg/tskm_cfg.xml create mode 100755 systemservice/task_manager/client/ss_data_init/Makefile create mode 100755 systemservice/task_manager/client/ss_data_init/include/libss_data_init_taskmanagerlog.h create mode 100755 systemservice/task_manager/client/ss_data_init/include/system_service/task_manager_libss_data_init.h create mode 100755 systemservice/task_manager/client/ss_data_init/include/system_service/tskm_data_init.h create mode 100755 systemservice/task_manager/client/ss_data_init/include/tskm_data_init_local.h create mode 100755 systemservice/task_manager/client/ss_data_init/mkdatainit.sh create mode 100755 systemservice/task_manager/client/ss_data_init/tskm_data_init.cpp.in create mode 100755 systemservice/task_manager/include-share/tskm_gstep.h create mode 100755 systemservice/task_manager/include-share/tskm_type_local.h create mode 100755 systemservice/task_manager/include-share/tskm_util.h create mode 100755 systemservice/task_manager/server/Makefile create mode 100755 systemservice/task_manager/server/include/system_service/INI_API.h create mode 100755 systemservice/task_manager/server/include/system_service/INI_API.hpp create mode 100755 systemservice/task_manager/server/include/system_service/Primary_common.h create mode 100755 systemservice/task_manager/server/include/system_service/sysup.h create mode 100755 systemservice/task_manager/server/include/system_service/sysup_from.h create mode 100755 systemservice/task_manager/server/include/system_service/task_manager.h create mode 100755 systemservice/task_manager/server/include/system_service/tskm.h create mode 100755 systemservice/task_manager/server/include/system_service/tskm_local_type.h create mode 100755 systemservice/task_manager/server/include/system_service/tskm_svc.h create mode 100755 systemservice/task_manager/server/include/system_service/tskm_type.h create mode 100755 systemservice/task_manager/server/include/tskm_comm.h create mode 100755 systemservice/task_manager/server/include/tskm_debug.h create mode 100755 systemservice/task_manager/server/include/tskm_main.h create mode 100755 systemservice/task_manager/server/include/tskm_port_pf.h create mode 100755 systemservice/task_manager/server/include/tskm_port_subsys.h create mode 100755 systemservice/task_manager/server/include/tskm_shutdown.h create mode 100755 systemservice/task_manager/server/include/tskm_state.h create mode 100755 systemservice/task_manager/server/include/tskm_wakeup.h create mode 100755 systemservice/task_manager/server/include/tskm_watch.h create mode 100755 systemservice/task_manager/server/src/pri_main.cpp create mode 100755 systemservice/task_manager/server/src/tskm_api.cpp create mode 100755 systemservice/task_manager/server/src/tskm_comm.cpp create mode 100755 systemservice/task_manager/server/src/tskm_debug.cpp create mode 100755 systemservice/task_manager/server/src/tskm_main.cpp create mode 100755 systemservice/task_manager/server/src/tskm_port_pf.cpp create mode 100755 systemservice/task_manager/server/src/tskm_port_subsys.cpp create mode 100755 systemservice/task_manager/server/src/tskm_shutdown.cpp create mode 100755 systemservice/task_manager/server/src/tskm_state.cpp create mode 100755 systemservice/task_manager/server/src/tskm_svc.cpp create mode 100755 systemservice/task_manager/server/src/tskm_wakeup.cpp create mode 100755 systemservice/task_manager/server/src/tskm_watch.cpp (limited to 'systemservice/task_manager') diff --git a/systemservice/task_manager/LICENSE b/systemservice/task_manager/LICENSE new file mode 100755 index 0000000..f433b1a --- /dev/null +++ b/systemservice/task_manager/LICENSE @@ -0,0 +1,177 @@ + + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS diff --git a/systemservice/task_manager/Makefile.client b/systemservice/task_manager/Makefile.client new file mode 100755 index 0000000..2c1628d --- /dev/null +++ b/systemservice/task_manager/Makefile.client @@ -0,0 +1,21 @@ +# +# @copyright Copyright (c) 2016-2020 TOYOTA MOTOR CORPORATION. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +SUBDIRS := client + +include ../system_service.mk + + diff --git a/systemservice/task_manager/Makefile.server b/systemservice/task_manager/Makefile.server new file mode 100755 index 0000000..245dcc5 --- /dev/null +++ b/systemservice/task_manager/Makefile.server @@ -0,0 +1,21 @@ +# +# @copyright Copyright (c) 2016-2020 TOYOTA MOTOR CORPORATION. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +SUBDIRS := server + +include ../system_service.mk + + diff --git a/systemservice/task_manager/client/Makefile b/systemservice/task_manager/client/Makefile new file mode 100755 index 0000000..7d90745 --- /dev/null +++ b/systemservice/task_manager/client/Makefile @@ -0,0 +1,26 @@ +# +# @copyright Copyright (c) 2016-2020 TOYOTA MOTOR CORPORATION. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +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/systemservice/task_manager/client/libprimary/Makefile b/systemservice/task_manager/client/libprimary/Makefile new file mode 100755 index 0000000..f58737c --- /dev/null +++ b/systemservice/task_manager/client/libprimary/Makefile @@ -0,0 +1,37 @@ +# +# @copyright Copyright (c) 2016-2020 TOYOTA MOTOR CORPORATION. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +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/systemservice/task_manager/client/libprimary/include/pri_main.h b/systemservice/task_manager/client/libprimary/include/pri_main.h new file mode 100755 index 0000000..c29a337 --- /dev/null +++ b/systemservice/task_manager/client/libprimary/include/pri_main.h @@ -0,0 +1,48 @@ +/* + * @copyright Copyright (c) 2016-2020 TOYOTA MOTOR CORPORATION. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef TASK_MANAGER_CLIENT_LIBPRIMARY_INCLUDE_PRI_MAIN_H_ +#define TASK_MANAGER_CLIENT_LIBPRIMARY_INCLUDE_PRI_MAIN_H_ + +#include + +#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/systemservice/task_manager/client/libprimary/libprimary.ver b/systemservice/task_manager/client/libprimary/libprimary.ver new file mode 100755 index 0000000..bebdc98 --- /dev/null +++ b/systemservice/task_manager/client/libprimary/libprimary.ver @@ -0,0 +1,22 @@ +/* + * @copyright Copyright (c) 2016-2020 TOYOTA MOTOR CORPORATION. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +{ + global: + INI_*; + _INI_DEBUGDUMP*; + local: *; +}; diff --git a/systemservice/task_manager/client/libprimary/src/pri_api.cpp b/systemservice/task_manager/client/libprimary/src/pri_api.cpp new file mode 100755 index 0000000..ca1b40e --- /dev/null +++ b/systemservice/task_manager/client/libprimary/src/pri_api.cpp @@ -0,0 +1,224 @@ +/* + * @copyright Copyright (c) 2016-2020 TOYOTA MOTOR CORPORATION. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "system_service/tskm_local_type.h" +#include "system_service/INI_API.hpp" +#include "tskm_debug.h" +#include "pri_main.h" + +BOOL __thread isMain = FALSE; // Check for accessibility from the main thread context + +TSKM_STATIC BOOL isInitPrmValid(const T_PRIM_PRM* p_prm) { + if (p_prm == NULL) { + TSKM_ASSERT(0); + return FALSE; + } else if (p_prm->shmTbl == NULL) { + TSKM_ASSERT(0); + return FALSE; + } else if (p_prm->wakeupExFuncTbl == NULL) { + TSKM_ASSERT(0); + return FALSE; + } else if (p_prm->downExFuncTbl == NULL) { + TSKM_ASSERT(0); + return FALSE; + } else if (p_prm->onInit == NULL) { + TSKM_ASSERT(0); + return FALSE; + } else if (p_prm->onDestory == NULL) { + TSKM_ASSERT(0); + return FALSE; + } else if (p_prm->onDebugDump == NULL) { + TSKM_ASSERT(0); + return FALSE; + } else if (p_prm->onTouch == NULL) { + TSKM_ASSERT(0); + return FALSE; + } + + return TRUE; +} + +/****************************************************************************** + * APIs for implementing the main thread on the service side + *******************************************************************************/ +/********************************************************* + * Primary library initialization + *********************************************************/ +int32_t INI_Init(T_PRIM_PRM* p_prm, int argc, char* argv[], int *fdNum, + int fdlist[INI_FD_MAX]) { + isMain = TRUE; + if (isInitPrmValid(p_prm) == FALSE) { + TSKM_ASSERT(0); + return INI_FALSE; + } + pri_init(p_prm, argc, argv, fdNum, fdlist); + return INI_SUCCESS; +} + +/*********************************************************** + * Primary library / Event handler + * ret:TRUE Running + * ret:FALSE Finished (Terminated a process with INI_Term()) + ************************************************************/ +BOOL INI_Handler(fd_set* p_fds) { + if (!isMain || NULL == p_fds) { + TSKM_ASSERT(0); + return FALSE; + } + + return pri_handler(p_fds); +} + +/*********************************************************** + * Primary (Processing finished) + ************************************************************/ +void INI_Term(void) { + pri_term(); +} + +/*********************************************************** + * Primary (State setting for watching Services) + ************************************************************/ +int32_t INI_SetMonitorState(T_PRIM_MONITOR_PRM *p_prm) { + if (!p_prm) { + TSKM_ASSERT(0); + goto ERROR; + } + + return pri_setMonitorState(p_prm->bIsRun, p_prm->timeout); + ERROR: return INI_FALSE; +} + +/****************************************************************************** + * Hiding the Main Thread in the Primary Library + *******************************************************************************/ +/************************************ + * Startup FW MainLoop + ************************************/ +int INI_Main(T_PRIM_PRM* p_prm, int argc, char* argv[]) { + if (isInitPrmValid(p_prm) == FALSE) { // LCOV_EXCL_BR_LINE 6: Checked by Init() + TSKM_ASSERT(0); + return INI_FALSE; + } + + isMain = TRUE; + + return pri_main(p_prm, argc, argv); +} + +/****************************************************************************** + * Common API + *******************************************************************************/ +/************************************ + * Process termination + ************************************/ +void INI_ExitStart(void * rsv) { + static int isCalled = 0; + if (isCalled) { + return; + } + isCalled = 1; + pri_exitStart(rsv); +} + +void INI_ExitDone(int status) { + static int isCalled = 0; + if (isCalled) { + return; + } + isCalled = 1; + pri_exitDone(status); +} + +/************************************ + * Private Info Acquisition + ************************************/ +void* INI_GetPrivate() { + return pri_getPrivate(); +} + +/************************************ + * Applicastion Handle Aquisition + ************************************/ +HANDLE INI_GetHandle() { + return pri_getHandle(); +} + +/************************************ + * Timeout setting for service monitoring status setting + ************************************/ +int32_t INI_SetMonitorTimeout(uint32_t timeout) { + return pri_setMonitorTimeout(timeout); +} + +/************************************ + * Event completion notification at startup + ************************************/ +int32_t INI_StepForkComp(uint64_t compId) { + return pri_stepForkComp(compId); +} + +/************************************ + * Event completion notification at termination + ************************************/ +int32_t INI_AccOffComp(uint64_t compId) { + return pri_accOffComp(compId); +} + +/************************************ + * BOOT Info Acquisition + ************************************/ +int32_t INI_GetBootInfo(T_SS_SM_START_DataStructType *info) { + if (info == NULL) { + TSKM_ASSERT(0); + return INI_FALSE; + } + return pri_getBootInfo(info); +} + +/************************************ + * Extended BOOT Info Acquisition + ************************************/ +int32_t INI_GetExtBootInfo(T_SS_SM_START_ExtDataStructType *info) { + if (info == NULL) { + TSKM_ASSERT(0); + return INI_FALSE; + } + return pri_getExtBootInfo(info); +} + +/************************************ + * DebugDump Responding + ************************************/ +void _INI_DEBUGDUMP(BOOL bIsNeedSvcName, PCSTR cFormat, ...) { // LCOV_EXCL_START 7: for debugging + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + va_list argList; + char buf[TSKM_EV_DEBUGDUMP_SIZE] = { 0 }; + + if (bIsNeedSvcName) { + snprintf(buf, TSKM_EV_DEBUGDUMP_SIZE, "%s/", + FrameworkunifiedGetAppName(pri_getHandle())); + } + + va_start(argList, cFormat); + vsnprintf(&buf[strlen(buf)], TSKM_EV_DEBUGDUMP_SIZE - strlen(buf), cFormat, + argList); + va_end(argList); + + return pri_sendDebugDumpRes(buf); +} +// LCOV_EXCL_STOP 7 + diff --git a/systemservice/task_manager/client/libprimary/src/pri_main.cpp b/systemservice/task_manager/client/libprimary/src/pri_main.cpp new file mode 100755 index 0000000..9c0dd95 --- /dev/null +++ b/systemservice/task_manager/client/libprimary/src/pri_main.cpp @@ -0,0 +1,873 @@ +/* + * @copyright Copyright (c) 2016-2020 TOYOTA MOTOR CORPORATION. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "pri_main.h" +#include +#include +#include +#include +#include +#include +#include +#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/systemservice/task_manager/client/libtskm/Makefile b/systemservice/task_manager/client/libtskm/Makefile new file mode 100755 index 0000000..b0f7e2f --- /dev/null +++ b/systemservice/task_manager/client/libtskm/Makefile @@ -0,0 +1,35 @@ +# +# @copyright Copyright (c) 2016-2020 TOYOTA MOTOR CORPORATION. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +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/systemservice/task_manager/client/libtskm/TSKM.api b/systemservice/task_manager/client/libtskm/TSKM.api new file mode 100755 index 0000000..023f53b --- /dev/null +++ b/systemservice/task_manager/client/libtskm/TSKM.api @@ -0,0 +1,9 @@ +INCLUDE + +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/systemservice/task_manager/client/libtskm/libtskm.ver b/systemservice/task_manager/client/libtskm/libtskm.ver new file mode 100755 index 0000000..4d68cee --- /dev/null +++ b/systemservice/task_manager/client/libtskm/libtskm.ver @@ -0,0 +1,21 @@ +/* + * @copyright Copyright (c) 2016-2020 TOYOTA MOTOR CORPORATION. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +{ + global: + TSKM_*; + local: *; +}; diff --git a/systemservice/task_manager/client/libtskm/src/tskm_api_lib.cpp b/systemservice/task_manager/client/libtskm/src/tskm_api_lib.cpp new file mode 100755 index 0000000..625b639 --- /dev/null +++ b/systemservice/task_manager/client/libtskm/src/tskm_api_lib.cpp @@ -0,0 +1,90 @@ +/* + * @copyright Copyright (c) 2016-2020 TOYOTA MOTOR CORPORATION. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include + +#include + +#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/systemservice/task_manager/client/libtskmcfg/Makefile b/systemservice/task_manager/client/libtskmcfg/Makefile new file mode 100755 index 0000000..9fe2ed3 --- /dev/null +++ b/systemservice/task_manager/client/libtskmcfg/Makefile @@ -0,0 +1,93 @@ +# +# @copyright Copyright (c) 2016-2020 TOYOTA MOTOR CORPORATION. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +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/BS/ss/task_manager/rodata;\ + install -m 644 -t $(DESTDIR)/usr/agl/conf/BS/ss/task_manager/rodata $(WAKESHUTCONF_DIR)/tskm_launch.xml;\ + +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:$(WAKESHUTCONF_DIR)/agl_thread.h + ln -fs $< $@ + + +tskm_launch.xml:$(WAKESHUTCONF_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/systemservice/task_manager/client/libtskmcfg/conf/agl_thread.h b/systemservice/task_manager/client/libtskmcfg/conf/agl_thread.h new file mode 100755 index 0000000..83ac087 --- /dev/null +++ b/systemservice/task_manager/client/libtskmcfg/conf/agl_thread.h @@ -0,0 +1,1377 @@ +/* + * @copyright Copyright (c) 2016-2020 TOYOTA MOTOR CORPORATION. + */ + +#ifndef __AGL_THREAD_H__ +#define __AGL_THREAD_H__ + +//MACRO +#define PR_TSS_S "0" +#define PR_TSS 0 + +/* + Main thread name. It need to be same as service name in sm_launch.xml or tskm_launch.xml + Max name length is 15 + #define MN_XXXXX "MainName" + + Thread name + Max name length is 15 + #define TN_XXXXX "ThreadName" + + Thread priority 0:TSS 1-99:FIFO + #define PR_XXXXX_S "(0-99)" //for xml + #define PR_XXXXX 0-99 //for program +*/ + +#define MN_SS_SYSMANAGER "SS_SysManager" +#define PR_SS_SYSMANAGER_S "20" +#define PR_SS_SYSMANAGER (20) + + #define TN_SMHEARTBEAT "SM.Heartbeat" + #define PR_SMHEARTBEAT_S "20" + #define PR_SMHEARTBEAT (20) + + #define TN_SMPROCLAUNCH "SM.ProcLaunch" + #define PR_SMPROCLAUNCH_S "20" + #define PR_SMPROCLAUNCH (20) + + #define TN_SMLOWMEMMON "SM.LowMemMon" + #define PR_SMLOWMEMMON_S "20" + #define PR_SMLOWMEMMON (20) + + #define TN_LOGGERRTIME "LoggerRtime" + #define PR_LOGGERRTIME_S PR_TSS_S + #define PR_LOGGERRTIME PR_TSS + + +//======= exec from system manager ============= +#define MN_NS_SHAREDMEM "NS_SharedMem" +#define PR_NS_SHAREDMEM_S "25" +#define PR_NS_SHAREDMEM (25) + + +#define MN_NS_NPPSERVICE "NS_NPPService" +#define PR_NS_NPPSERVICE_S "25" +#define PR_NS_NPPSERVICE (25) + + #define TN_NS_NPPREADWKR "NS_NPPReadWkr" + #define PR_NS_NPPREADWKR_S "25" + #define PR_NS_NPPREADWKR (25) + + #define TN_NS_NPPWRITEWKR "NS_NPPWriteWkr" + #define PR_NS_NPPWRITEWKR_S "25" + #define PR_NS_NPPWRITEWKR (25) + + #define TN_NS_NPPIPWKR "NS_NPPIPWkr" + #define PR_NS_NPPIPWKR_S "25" + #define PR_NS_NPPIPWKR (25) + +#define MN_NS_BACKUPMGR "NS_BackupMgr" +#define PR_NS_BACKUPMGR_S "25" +#define PR_NS_BACKUPMGR (25) + + #define TN_NS_BKUPNAND "NS_BkupNAND" + #define PR_NS_BKUPNAND_S "25" + #define PR_NS_BKUPNAND (25) + + #define TN_NS_BKUPDELAY "NS_BkupDelay" + #define PR_NS_BKUPDELAY_S "25" + #define PR_NS_BKUPDELAY (25) + +#define MN_SS_DEVDETECTSRV "SS_DevDetectSrv" +#define PR_SS_DEVDETECTSRV_S "20" +#define PR_SS_DEVDETECTSRV (20) + + #define TN_SS_DETECT_USB "SS_Detect_USB" + #define PR_SS_DETECT_USB_S "20" + #define PR_SS_DETECT_USB (20) + + #define TN_SS_DETECT_SD "SS_Detect_SD" + #define PR_SS_DETECT_SD_S "20" + #define PR_SS_DETECT_SD (20) + + #define TN_SS_MONITOR_OVC "SS_Monitor_OVC" + #define PR_SS_MONITOR_OVC_S "20" + #define PR_SS_MONITOR_OVC (20) + +#define MN_SS_LOGGERSRV "SS_LoggerSrv" +#define PR_SS_LOGGERSRV_S PR_TSS_S +#define PR_SS_LOGGERSRV PR_TSS + + #define TN_PDGLOGQUER "pdg.LogQueR" + #define PR_PDGLOGQUER_S PR_TSS_S + #define PR_PDGLOGQUER PR_TSS + + #define TN_PDGTRANSQUER "pdg.TransQueR" + #define PR_PDGTRANSQUER_S PR_TSS_S + #define PR_PDGTRANSQUER PR_TSS + + #define TN_PDGEVNTLOGQUE "pdg.EvntLogQue" + #define PR_PDGEVNTLOGQUE_S PR_TSS_S + #define PR_PDGEVNTLOGQUE PR_TSS + + #define TN_SSLOGGERSTRAGE "SSLoggerStrage" + #define PR_SSLOGGERSTRAGE_S PR_TSS_S + #define PR_SSLOGGERSTRAGE PR_TSS + + #define TN_PFDRECTHREAD "PFDRECThread" + #define PR_PFDRECTHREAD_S PR_TSS_S + #define PR_PFDRECTHREAD PR_TSS + +#define MN_PS_LOGGERSHADOW "PS_LoggerShadow" + #define PR_PSLOGGERSHADOW_S PR_TSS_S + #define PR_PSLOGGERSHADOW PR_TSS + +#define MN_UDEVD "udevd" +#define PR_UDEVD_S "1" +#define PR_UDEVD (1) + +#define MN_COMMUNICATION "Communication" +#define PR_COMMUNICATION_S "30" +#define PR_COMMUNICATION (30) + + #define TN_DEV_SYSCOM_TMR "DEV_SYSCOM_TMR" + #define PR_DEV_SYSCOM_TMR_S "30" + #define PR_DEV_SYSCOM_TMR (30) + + #define TN_DEV_SYSCOM_RCV "DEV_SYSCOM_RCV" + #define PR_DEV_SYSCOM_RCV_S "30" + #define PR_DEV_SYSCOM_RCV (30) + + #define TN_DEV_SYSCOM_MAIN "DEV_SYSCOM_MAIN" + #define PR_DEV_SYSCOM_MAIN_S "30" + #define PR_DEV_SYSCOM_MAIN (30) + + #define TN_TGWCOM "TGWCOM" + #define PR_TGWCOM_S "30" + #define PR_TGWCOM (30) + + #define TN_ICM "ICM" + #define PR_ICM_S "30" + #define PR_ICM (30) + + #define TN_CAN_COM_PROT "CAN_COM_PROT" + #define PR_CAN_COM_PROT_S "30" + #define PR_CAN_COM_PROT (30) + +#define MN_PS_PSMSHADOW "PS_PSMShadow" +#define PR_PS_PSMSHADOW_S "30" +#define PR_PS_PSMSHADOW (30) + +#define MN_COMMSH4A "CommSH4A" +#define PR_COMMSH4A_S "30" +#define PR_COMMSH4A (30) + + #define TN_DEV_SH4A_SND "DEV_SH4ACOM_SND" + #define PR_DEV_SH4A_SND_S "30" + #define PR_DEV_SH4A_SND (30) + + #define TN_DEV_SH4A_RCV "DEV_SH4ACOM_RCV" + #define PR_DEV_SH4A_RCV_S "30" + #define PR_DEV_SH4A_RCV (30) + + #define TN_DEV_SH4A_MON "DEV_SH4ACOM_MON" + #define PR_DEV_SH4A_MON_S "30" + #define PR_DEV_SH4A_MON (30) + +#define MN_PS_COMMUSB "PS_CommUSB" +#define PR_PS_COMMUSB_S "30" +#define PR_PS_COMMUSB (30) + + #define TN_COMMUSB_RCV "COMMUSB_RCV" + #define PR_COMMUSB_RCV_S "30" + #define PR_COMMUSB_RCV (30) + + #define TN_COMMUSB_DIAG "COMMUSB_DIAG" + #define PR_COMMUSB_DIAG_S "30" + #define PR_COMMUSB_DIAG (30) + +#define MN_PS_CANGW_M "CANGW_M" +#define PR_PS_CANGW_M_S PR_TSS_S +#define PR_PS_CANGW_M PR_TSS + + #define TN_CANGW_M_RCV "CANGW_M_RCV" + #define PR_CANGW_M_RCV_S PR_TSS_S + #define PR_CANGW_M_RCV PR_TSS + + #define TN_CANGW_M_DIAG "CANGW_M_DIAG" + #define PR_CANGW_M_DIAG_S PR_TSS_S + #define PR_CANGW_M_DIAG PR_TSS + +#define MN_PS_CANGW_S "CANGW_S" +#define PR_PS_CANGW_S_S PR_TSS_S +#define PR_PS_CANGW_S PR_TSS + + #define TN_CANGW_S_SND "CANGW_S_SND" + #define PR_CANGW_S_SND_S PR_TSS_S + #define PR_CANGW_S_SND PR_TSS + + #define TN_CANGW_S_DIAG "CANGW_S_DIAG" + #define PR_CANGW_S_DIAG_S PR_TSS_S + #define PR_CANGW_S_DIAG PR_TSS + +#define MN_LANSERVER "LanServer" +#define PR_LANSERVER_S "20" +#define PR_LANSERVER (20) + +#define MN_PS_CDR "ps_cdr" +#define PR_PS_CDR_S PR_TSS_S +#define PR_PS_CDR PR_TSS + + #define TN_PS_CDR_NBD "ps_cdr_nbd" + #define PR_PS_CDR_NBD_S PR_TSS_S + #define PR_PS_CDR_NBD PR_TSS + + #define TN_PS_CDR_DOIT "ps_cdr_doit" + #define PR_PS_CDR_DOIT_S PR_TSS_S + #define PR_PS_CDR_DOIT PR_TSS + + #define TN_PS_CDR_READ "ps_cdr_read" + #define PR_PS_CDR_READ_S PR_TSS_S + #define PR_PS_CDR_READ PR_TSS + +#define MN_POSITIONING "Positioning" +#define PR_POSITIONING_S PR_TSS_S +#define PR_POSITIONING PR_TSS + + #define TN_POSITIONING_GPS_MAIN "POS_Main" + #define PR_POSITIONING_GPS_MAIN_S PR_TSS_S + #define PR_POSITIONING_GPS_MAIN PR_TSS + + #define TN_POSITIONING_GPS_RECV "POS_Gps_Recv" + #define PR_POSITIONING_GPS_RECV_S PR_TSS_S + #define PR_POSITIONING_GPS_RECV PR_TSS + + #define TN_POSITIONING_GPS "POS_Gps" + #define PR_POSITIONING_GPS_S PR_TSS_S + #define PR_POSITIONING_GPS PR_TSS + + #define TN_POSITIONING_SENS "POS_Sens" + #define PR_POSITIONING_SENS_S PR_TSS_S + #define PR_POSITIONING_SENS PR_TSS + + #define TN_POSITIONING_GPS_ROLOVR "POS_Gps_Rolovr" + #define PR_POSITIONING_GPS_ROLOVR_S PR_TSS_S + #define PR_POSITIONING_GPS_ROLOVR PR_TSS + +#define MN_CLOCK "clock" +#define PR_CLOCK_S "20" +#define PR_CLOCK (20) + + #define TN_CLOCK_MNG "ClockMng" + #define PR_CLOCK_MNG_S "20" + #define PR_CLOCK_MNG (20) + +#define MN_VEHICLE "vehicle" +#define PR_VEHICLE_S "20" +#define PR_VEHICLE (20) + + #define TN_VEHICLE_SENS "VehicleSens" + #define PR_VEHICLE_SENS_S "20" + #define PR_VEHICLE_SENS (20) + + #define TN_LINE_SENS_DRV "LineSensDrv" + #define PR_LINE_SENS_DRV_S "20" + #define PR_LINE_SENS_DRV (20) + +#define MN_SS_POWERSERVICE "SS_PowerService" +#define PR_SS_POWERSERVICE_S "30" +#define PR_SS_POWERSERVICE (30) + +#define MN_SS_TASKMANAGER "SS_TaskManager" +#define PR_SS_TASKMANAGER_S "20" +#define PR_SS_TASKMANAGER (20) + + #define TN_SS_TSKMTIMER "SS_TskmTimer" + #define PR_SS_TSKMTIMER_S "20" + #define PR_SS_TSKMTIMER (20) + +#define MN_SOUND "Sound" +#define PR_SOUND_S "45" +#define PR_SOUND (45) + + #define TN_VG_SNDSRCMGR "VG_SNDSRCMGR" + #define PR_VG_SNDSRCMGR_S "40" + #define PR_VG_SNDSRCMGR (40) + + #define TN_SND_INPUTCTRL "SND_INPUTCTRL" + #define PR_SND_INPUTCTRL_S "40" + #define PR_SND_INPUTCTRL (40) + + #define TN_SND_DEVCTRL "SND_DEVCTRL" + #define PR_SND_DEVCTRL_S "40" + #define PR_SND_DEVCTRL (40) + + #define TN_SND_VCETRFCTRL "SND_VCETRFCTRL" + #define PR_SND_VCETRFCTRL_S "45" + #define PR_SND_VCETRFCTRL (45) + + #define TN_SND_VCETRFWRT1 "SND_VCETRFWRT1" + #define PR_SND_VCETRFWRT1_S "45" + #define PR_SND_VCETRFWRT1 (45) + + #define TN_SND_VCETRFWRT2 "SND_VCETRFWRT2" + #define PR_SND_VCETRFWRT2_S "45" + #define PR_SND_VCETRFWRT2 (45) + + #define TN_VG_SNDCTRL_BSCF "VG_SNDCTRL_BSCF" + #define PR_VG_SNDCTRL_BSCF_S "25" + #define PR_VG_SNDCTRL_BSCF (25) + + #define TN_VG_SNDCTRL_BSCR "VG_SNDCTRL_BSCR" + #define PR_VG_SNDCTRL_BSCR_S "25" + #define PR_VG_SNDCTRL_BSCR (25) + + #define TN_VG_SNDCTRL_ITRT "VG_SNDCTRL_ITRT" + #define PR_VG_SNDCTRL_ITRT_S "25" + #define PR_VG_SNDCTRL_ITRT (25) + + #define TN_CVRS_OPRT_OUT_1 "CVRS_OPRT_OUT_1" + #define PR_CVRS_OPRT_OUT_1_S "45" + #define PR_CVRS_OPRT_OUT_1 (45) + + #define TN_CVRS_OPRT_OUT_2 "CVRS_OPRT_OUT_2" + #define PR_CVRS_OPRT_OUT_2_S "45" + #define PR_CVRS_OPRT_OUT_2 (45) + + #define TN_CVRS_OPRT_OUT_3 "CVRS_OPRT_OUT_3" + #define PR_CVRS_OPRT_OUT_3_S "45" + #define PR_CVRS_OPRT_OUT_3 (45) + + #define TN_CVRS_OPRT_OUT_4 "CVRS_OPRT_OUT_4" + #define PR_CVRS_OPRT_OUT_4_S "45" + #define PR_CVRS_OPRT_OUT_4 (45) + + #define TN_CVRS_OPRT_IN_1 "CVRS_OPRT_IN_1" + #define PR_CVRS_OPRT_IN_1_S "45" + #define PR_CVRS_OPRT_IN_1 (45) + + #define TN_CVRS_OPRT_IN_2 "CVRS_OPRT_IN_2" + #define PR_CVRS_OPRT_IN_2_S "45" + #define PR_CVRS_OPRT_IN_2 (45) + + #define TN_CVRS_OPRT_IN_3 "CVRS_OPRT_IN_3" + #define PR_CVRS_OPRT_IN_3_S "45" + #define PR_CVRS_OPRT_IN_3 (45) + + #define TN_CVRS_OPRT_IN_4 "CVRS_OPRT_IN_4" + #define PR_CVRS_OPRT_IN_4_S "45" + #define PR_CVRS_OPRT_IN_4 (45) + + #define TN_CVRS_OPRT_IN_5 "CVRS_OPRT_IN_5" + #define PR_CVRS_OPRT_IN_5_S "45" + #define PR_CVRS_OPRT_IN_5 (45) + + #define TN_CVRS_OPRT_IN_6 "CVRS_OPRT_IN_6" + #define PR_CVRS_OPRT_IN_6_S "45" + #define PR_CVRS_OPRT_IN_6 (45) + + #define TN_CVRS_OPRT_IN_7 "CVRS_OPRT_IN_7" + #define PR_CVRS_OPRT_IN_7_S "45" + #define PR_CVRS_OPRT_IN_7 (45) + + #define TN_CVRS_OPRT_IN_8 "CVRS_OPRT_IN_8" + #define PR_CVRS_OPRT_IN_8_S "45" + #define PR_CVRS_OPRT_IN_8 (45) + + #define TN_CVRS_OPRT_BS_I "CVRS_OPRT_BS_I" + #define PR_CVRS_OPRT_BS_I_S "45" + #define PR_CVRS_OPRT_BS_I (45) + + #define TN_VR_NVR_RECO "VR_NVR_RECO" + #define PR_VR_NVR_RECO_S "20" + #define PR_VR_NVR_RECO (20) + + #define TN_SND_ECNR "SND_ECNR" + #define PR_SND_ECNR_S "40" + #define PR_SND_ECNR (40) + + #define TN_SNDAGENT_000 "SNDAGENT_000" + #define PR_SNDAGENT_000_S "45" + #define PR_SNDAGENT_000 (45) + + #define TN_SNDAGENT_001 "SNDAGENT_001" + #define PR_SNDAGENT_001_S "45" + #define PR_SNDAGENT_001 (45) + + #define TN_SNDAGENT_002 "SNDAGENT_002" + #define PR_SNDAGENT_002_S "45" + #define PR_SNDAGENT_002 (45) + + #define TN_SNDAGENT_003 "SNDAGENT_003" + #define PR_SNDAGENT_003_S "45" + #define PR_SNDAGENT_003 (45) + + #define TN_SNDAGENT_004 "SNDAGENT_004" + #define PR_SNDAGENT_004_S "45" + #define PR_SNDAGENT_004 (45) + + #define TN_SNDAGENT_005 "SNDAGENT_005" + #define PR_SNDAGENT_005_S "45" + #define PR_SNDAGENT_005 (45) + + #define TN_SNDAGENT_006 "SNDAGENT_006" + #define PR_SNDAGENT_006_S "45" + #define PR_SNDAGENT_006 (45) + + #define TN_SNDAGENT_007 "SNDAGENT_007" + #define PR_SNDAGENT_007_S "45" + #define PR_SNDAGENT_007 (45) + + #define TN_SNDAGENT_008 "SNDAGENT_008" + #define PR_SNDAGENT_008_S "45" + #define PR_SNDAGENT_008 (45) + + #define TN_SNDAGENT_009 "SNDAGENT_009" + #define PR_SNDAGENT_009_S "45" + #define PR_SNDAGENT_009 (45) + + #define TN_SNDAGENT_010 "SNDAGENT_010" + #define PR_SNDAGENT_010_S "45" + #define PR_SNDAGENT_010 (45) + + #define TN_SNDAGENT_011 "SNDAGENT_011" + #define PR_SNDAGENT_011_S "45" + #define PR_SNDAGENT_011 (45) + + #define TN_SNDAGENT_012 "SNDAGENT_012" + #define PR_SNDAGENT_012_S "45" + #define PR_SNDAGENT_012 (45) + + #define TN_SNDAGENT_013 "SNDAGENT_013" + #define PR_SNDAGENT_013_S "45" + #define PR_SNDAGENT_013 (45) + + #define TN_SNDAGENT_014 "SNDAGENT_014" + #define PR_SNDAGENT_014_S "45" + #define PR_SNDAGENT_014 (45) + + #define TN_SNDAGENT_015 "SNDAGENT_015" + #define PR_SNDAGENT_015_S "45" + #define PR_SNDAGENT_015 (45) + + #define TN_SNDAGENT_016 "SNDAGENT_016" + #define PR_SNDAGENT_016_S "45" + #define PR_SNDAGENT_016 (45) + + #define TN_SNDAGENT_017 "SNDAGENT_017" + #define PR_SNDAGENT_017_S "45" + #define PR_SNDAGENT_017 (45) + + #define TN_SNDAGENT_018 "SNDAGENT_018" + #define PR_SNDAGENT_018_S "45" + #define PR_SNDAGENT_018 (45) + + #define TN_SNDAGENT_019 "SNDAGENT_019" + #define PR_SNDAGENT_019_S "45" + #define PR_SNDAGENT_019 (45) + + #define TN_SNDAGENT_020 "SNDAGENT_020" + #define PR_SNDAGENT_020_S "45" + #define PR_SNDAGENT_020 (45) + + #define TN_SNDAGENT_021 "SNDAGENT_021" + #define PR_SNDAGENT_021_S "45" + #define PR_SNDAGENT_021 (45) + + #define TN_SNDAGENT_022 "SNDAGENT_022" + #define PR_SNDAGENT_022_S "45" + #define PR_SNDAGENT_022 (45) + + #define TN_SNDAGENT_023 "SNDAGENT_023" + #define PR_SNDAGENT_023_S "45" + #define PR_SNDAGENT_023 (45) + + #define TN_SNDAGENT_024 "SNDAGENT_024" + #define PR_SNDAGENT_024_S "45" + #define PR_SNDAGENT_024 (45) + + #define TN_SNDAGENT_025 "SNDAGENT_025" + #define PR_SNDAGENT_025_S "45" + #define PR_SNDAGENT_025 (45) + +#define MN_SS_RESOURCEMGR "SS_ResourceMgr" +#define PR_SS_RESOURCEMGR_S "49" +#define PR_SS_RESOURCEMGR (49) + + #define TN_RESOURCEHWDT "ResourceHWDT" + #define PR_RESOURCEHWDT_S "1" + #define PR_RESOURCEHWDT (1) + +#define MN_AS_AUDIOMANAGER "AS_AudioManager" +#define PR_AS_AUDIOMANAGER_S PR_TSS_S +#define PR_AS_AUDIOMANAGER PR_TSS + + #define TN_AS_SOUNDBEEP "AS_SoundBeep" + #define PR_AS_SOUNDBEEP_S PR_TSS_S + #define PR_AS_SOUNDBEEP PR_TSS + +#define MN_GRAPHICS "Graphics" +#define PR_GRAPHICS_S "4" +#define PR_GRAPHICS (4) + + #define TN_GR_MAIN_CTRL "Graphics_main" + #define PR_GR_MAIN_CTRL_S PR_TSS_S + #define PR_GR_MAIN_CTRL PR_TSS + + #define TN_GR_SEQ_CTRL "Graphics_seq" + #define PR_GR_SEQ_CTRL_S PR_TSS_S + #define PR_GR_SEQ_CTRL PR_TSS + + #define TN_GR_DEV_RCV_CTRL "Graphics_rcv" + #define PR_GR_DEV_RCV_CTRL_S PR_TSS_S + #define PR_GR_DEV_RCV_CTRL PR_TSS + + #define TN_GR_VCAP1_CTRL "Graphics_cap1" + #define PR_GR_VCAP1_CTRL_S "4" + #define PR_GR_VCAP1_CTRL (4) + + #define TN_GR_VCAP2_CTRL "Graphics_cap2" + #define PR_GR_VCAP2_CTRL_S "4" + #define PR_GR_VCAP2_CTRL (4) + +#define MN_VUPSERVICE "vupservice" +#define PR_VUPSERVICE_S PR_TSS_S +#define PR_VUPSERVICE PR_TSS + +#define MN_SS_UPDATESERVICE "UpdateService" +#define PR_SS_UPDATESERVICE_S PR_TSS_S +#define PR_SS_UPDATESERVICE PR_TSS + + #define TN_UPSERVICE_VERI "t_update_veri" + #define PR_UPSERVICE_VERI_S PR_TSS_S + #define PR_UPSERVICE_VERI PR_TSS + +#define MN_NW_MICSERVICE "NW_MicService" +#define PR_NW_MICSERVICE_S PR_TSS_S +#define PR_NW_MICSERVICE PR_TSS + +#define MN_NS_LOCKMGR "LockMgr" +#define PR_NS_LOCKMGR_S PR_TSS_S +#define PR_NS_LOCKMGR PR_TSS + +#define MN_PS_SWITCHHANDLER "SwitchHandler" +#define PR_PS_SWITCHHANDLER_S "30" +#define PR_PS_SWITCHHANDLER (30) + +#define MN_SS_WINSYS "SS_WinSys" +#define PR_SS_WINSYS_S "5" +#define PR_SS_WINSYS 5 + +#define MN_MODEMANAGER "modemanager" +#define PR_MODEMANAGER_S PR_TSS_S +#define PR_MODEMANAGER PR_TSS + +#define MN_BTSTACKMAIN "btstackmain" +#define PR_BTSTACKMAIN_S PR_TSS_S +#define PR_BTSTACKMAIN PR_TSS + +#define MN_MEDIASERVICE "MediaService" +#define PR_MEDIASERVICE_S PR_TSS_S +#define PR_MEDIASERVICE PR_TSS + +// REPRO START +#define MN_REPROSERVICE "ReproService" +#define PR_REPROSERVICE_S PR_TSS_S +#define PR_REPROSERVICE PR_TSS + + #define TN_REPROSEQUENCER "RPRS_Sequencer" + #define PR_REPROSEQUENCER_S PR_TSS_S + #define PR_REPROSEQUENCER PR_TSS + + #define TN_REPROCTRL "RPRS_Control" + #define PR_REPROCTRL_S PR_TSS_S + #define PR_REPROCTRL PR_TSS + + #define TN_REPROCENTERCOMM "RPRS_CenterComm" + #define PR_REPROCENTERCOMM_S PR_TSS_S + #define PR_REPROCENTERCOMM PR_TSS + + #define TN_REPROUNITCOMM "RPRS_UnitComm" + #define PR_REPROUNITCOMM_S PR_TSS_S + #define PR_REPROUNITCOMM PR_TSS + + #define TN_REPROWEBDAVMGR "RPRS_WebDAVMgr" + #define PR_REPROWEBDAVMGR_S PR_TSS_S + #define PR_REPROWEBDAVMGR PR_TSS + +#define MN_REPROAENDTEST "Repro_Testpro_Sender" +#define PR_REPROAENDTEST_S PR_TSS_S +#define PR_REPROAENDTEST PR_TSS + + #define TN_REPROAENDTESTTN "Repro_TestproT" + #define PR_REPROAENDTESTTN_S PR_TSS_S + #define PR_REPROAENDTESTTN PR_TSS + +#define MN_REPROBACKVUP "BackVupCtrl" +#define PR_REPROBACKVUP_S PR_TSS_S +#define PR_REPROBACKVUP PR_TSS + +#define MN_REPRODEVELOP "DevReproService" +#define PR_REPRODEVELOP_S PR_TSS_S +#define PR_REPRODEVELOP PR_TSS +// REPRO END + + #define TN_MED_MMCOM_PLAY "mmcom_play" + #define PR_MED_MMCOM_PLAY_S PR_TSS_S + #define PR_MED_MMCOM_PLAY PR_TSS + + #define TN_MED_MMCOM_MEDIA "mmcom_media" + #define PR_MED_MMCOM_MEDIA_S PR_TSS_S + #define PR_MED_MMCOM_MEDIA PR_TSS + + #define TN_MED_MMCOM_DB "mmcom_db" + #define PR_MED_MMCOM_DB_S PR_TSS_S + #define PR_MED_MMCOM_DB PR_TSS + + #define TN_MED_MMCOM_LIST "mmcom_list" + #define PR_MED_MMCOM_LIST_S PR_TSS_S + #define PR_MED_MMCOM_LIST PR_TSS + + #define TN_MED_MMCOM_DBUSB "mmcom_dbusb" + #define PR_MED_MMCOM_DBUSB_S PR_TSS_S + #define PR_MED_MMCOM_DBUSB PR_TSS + + #define TN_MED_MMCOM_DBSD "mmcom_dbsd" + #define PR_MED_MMCOM_DBSD_S PR_TSS_S + #define PR_MED_MMCOM_DBSD PR_TSS + + #define TN_MED_MMCOM_DBCD "mmcom_dbcd" + #define PR_MED_MMCOM_DBCD_S PR_TSS_S + #define PR_MED_MMCOM_DBCD PR_TSS + + #define TN_MED_MMCOM_PLAYRCV "mmcom_playrcv" + #define PR_MED_MMCOM_PLAYRCV_S PR_TSS_S + #define PR_MED_MMCOM_PLAYRCV PR_TSS + + #define TN_MED_RIPCOM_MNG "MngRipComm" + #define PR_MED_RIPCOM_MNG_S PR_TSS_S + #define PR_MED_RIPCOM_MNG PR_TSS + + #define TN_MED_RIPCOM_EXE01 "ExeRipComm01" + #define PR_MED_RIPCOM_EXE01_S PR_TSS_S + #define PR_MED_RIPCOM_EXE01 PR_TSS + + #define TN_MED_RIPCOM_EXE02 "ExeRipComm02" + #define PR_MED_RIPCOM_EXE02_S PR_TSS_S + #define PR_MED_RIPCOM_EXE02 PR_TSS + + #define TN_MED_DISCCOM_MAIN "disccom_main" + #define PR_MED_DISCCOM_MAIN_S PR_TSS_S + #define PR_MED_DISCCOM_MAIN PR_TSS + + #define TN_MED_DISCCOM_DB "disccom_db" + #define PR_MED_DISCCOM_DB_S PR_TSS_S + #define PR_MED_DISCCOM_DB PR_TSS + +#define MN_PLAYBACKSERVICE "PlaybackService" +#define PR_PLAYBACKSERVICE_S PR_TSS_S +#define PR_PLAYBACKSERVICE PR_TSS + + #define TN_PLAYSRV_AUDIO "playsrv_audio" + #define PR_PLAYSRV_AUDIO_S PR_TSS_S + #define PR_PLAYSRV_AUDIO PR_TSS + + #define TN_PLAYSRV_RIP "playsrv_rip" + #define PR_PLAYSRV_RIP_S PR_TSS_S + #define PR_PLAYSRV_RIP PR_TSS + + #define TN_PLAYSRV_PLAY "playsrv_play" + #define PR_PLAYSRV_PLAY_S PR_TSS_S + #define PR_PLAYSRV_PLAY PR_TSS + + #define TN_PLAYSRV_DISC "playsrv_disc" + #define PR_PLAYSRV_DISC_S PR_TSS_S + #define PR_PLAYSRV_DISC PR_TSS + + #define TN_PLAYSRV_ARTWORK "playsrv_artwork" + #define PR_PLAYSRV_ARTWORK_S PR_TSS_S + #define PR_PLAYSRV_ARTWORK PR_TSS + +#define MN_DISCSERVICE "DiscService" +#define PR_DISCSERVICE_S PR_TSS_S +#define PR_DISCSERVICE PR_TSS + +#define MN_RADIOSERVICE "RadioService" +#define PR_RADIOSERVICE_S PR_TSS_S +#define PR_RADIOSERVICE PR_TSS + +#define MN_RADIOHDARBITER "RadioHDArbiter" +#define PR_RADIOHDARBITER_S "20" +#define PR_RADIOHDARBITER (20) + +#define MN_HRDS_MANAGER "hrds_manager" +#define PR_HRDS_MANAGER_S PR_TSS_S +#define PR_HRDS_MANAGER PR_TSS + + #define TN_HRDS_HDMNG "hrds_hdmng" + #define PR_HRDS_HDMNG_S PR_TSS_S + #define PR_HRDS_HDMNG PR_TSS + + #define TN_HRDS_HDDEC "hrds_hddec" + #define PR_HRDS_HDDEC_S PR_TSS_S + #define PR_HRDS_HDDEC PR_TSS + + #define TN_HRDS_WEBMNG "hrds_webmng" + #define PR_HRDS_WEBMNG_S PR_TSS_S + #define PR_HRDS_WEBMNG PR_TSS + + #define TN_HRDS_WEBCOM "hrds_webcom" + #define PR_HRDS_WEBCOM_S PR_TSS_S + #define PR_HRDS_WEBCOM PR_TSS + +#define MN_BT_CONNECTIONSERVICE "BT_CnctSrv" +#define PR_BT_CONNECTIONSERVICE_S PR_TSS_S +#define PR_BT_CONNECTIONSERVICE PR_TSS + +#define MN_BT_PHONESERVICE "BT_PhoneSrv" +#define PR_BT_PHONESERVICE_S PR_TSS_S +#define PR_BT_PHONESERVICE PR_TSS + +#define MN_BT_PHONEBOOKSERVICE "BT_PbkSrv" +#define PR_BT_PHONEBOOKSERVICE_S PR_TSS_S +#define PR_BT_PHONEBOOKSERVICE PR_TSS + +#define MN_BT_MESSAGINGSERVICE "BT_MsgSrv" +#define PR_BT_MESSAGINGSERVICE_S PR_TSS_S +#define PR_BT_MESSAGINGSERVICE PR_TSS + +#define MN_BT_BLLSERVICE "TEL_BLLSrv" +#define PR_BT_BLLSERVICE_S PR_TSS_S +#define PR_BT_BLLSERVICE PR_TSS + +#define MN_BT_DCMPHONESERVICE "DCM_PhoneSrv" +#define PR_BT_DCMPHONESERVICE_S PR_TSS_S +#define PR_BT_DCMPHONESERVICE PR_TSS + + #define TN_BT_CONSRV_HFPMULTIQ1 "HFPMultiQ1" + #define PR_TN_BT_CONSRV_HFPMULTIQ1_S PR_TSS_S + #define PR_TN_BT_CONSRV_HFPMULTIQ1 PR_TSS + + #define TN_BT_CONSRV_HFPMULTIQ2 "HFPMultiQ2" + #define PR_TN_BT_CONSRV_HFPMULTIQ2_S PR_TSS_S + #define PR_TN_BT_CONSRV_HFPMULTIQ2 PR_TSS + + #define TN_BT_PBKSRV_DATABASE "BTPB_Database" + #define PR_TN_BT_PBKSRV_DATABASE_S PR_TSS_S + #define PR_TN_BT_PBKSRV_DATABASE PR_TSS + + #define TN_BT_PBKSRV_LOCALPBINST "LocalPBINST" + #define PR_TN_BT_PBKSRV_LOCALPBINST_S PR_TSS_S + #define PR_TN_BT_PBKSRV_LOCALPBINST PR_TSS + + #define TN_BT_PBKSRV_RESOLVENAME "ResolveName" + #define PR_TN_BT_PBKSRV_RESOLVENAME_S PR_TSS_S + #define PR_TN_BT_PBKSRV_RESOLVENAME PR_TSS + + #define TN_BT_PBKSRV_PBAPMULTIQ1 "PBAPMultiQ1" + #define PR_TN_BT_PBKSRV_PBAPMULTIQ1_S PR_TSS_S + #define PR_TN_BT_PBKSRV_PBAPMULTIQ1 PR_TSS + + #define TN_BT_PBKSRV_OPPMULTI "OPPMulti" + #define PR_TN_BT_PBKSRV_OPPMULTI_S PR_TSS_S + #define PR_TN_BT_PBKSRV_OPPMULTI PR_TSS + + #define TN_BT_PBKSRV_VCARDPARSER "VCardParser" + #define PR_TN_BT_PBKSRV_VCARDPARSER_S PR_TSS_S + #define PR_TN_BT_PBKSRV_VCARDPARSER PR_TSS + + #define TN_BT_MSGSRV_MSGCNTRLTHREAD0 "MsgCntrlThread0" + #define PR_TN_BT_MSGSRV_MSGCNTRLTHREAD0_S PR_TSS_S + #define PR_TN_BT_MSGSRV_MSGCNTRLTHREAD0 PR_TSS + + #define TN_BT_MSGSRV_MSGCNTRLTHREAD1 "MsgCntrlThread1" + #define PR_TN_BT_MSGSRV_MSGCNTRLTHREAD1_S PR_TSS_S + #define PR_TN_BT_MSGSRV_MSGCNTRLTHREAD1 PR_TSS + + #define TN_BT_MSGSRV_MAPMULTI "MapMulti" + #define PR_TN_BT_MSGSRV_MAPMULTI_S PR_TSS_S + #define PR_TN_BT_MSGSRV_MAPMULTI PR_TSS + +#define MN_DTVSERVICE "DtvService" +#define PR_DTVSERVICE_S PR_TSS_S +#define PR_DTVSERVICE PR_TSS + + #define TN_DTVTNC_TX "dtvtnc_tx" + #define PR_DTVTNC_TX_S PR_TSS_S + #define PR_DTVTNC_TX PR_TSS + + #define TN_DTVTNC_RCV "dtvtnc_rcv" + #define PR_DTVTNC_RCV_S PR_TSS_S + #define PR_DTVTNC_RCV PR_TSS + + #define TN_DTVTNC_TIMER "dtvtnc_timer" + #define PR_DTVTNC_TIMER_S PR_TSS_S + #define PR_DTVTNC_TIMER PR_TSS + + #define TN_DTVTNC_CTL "dtvtnc_ctl" + #define PR_DTVTNC_CTL_S PR_TSS_S + #define PR_DTVTNC_CTL PR_TSS + +#define MN_DTVVUPSERVICE "DtvVupService" +#define PR_DTVVUPSERVICE_S PR_TSS_S +#define PR_DTVVUPSERVICE PR_TSS + +#define MN_SETTINGSERVICE "SettingService" +#define PR_SETTINGSERVICE_S PR_TSS_S +#define PR_SETTINGSERVICE PR_TSS + +#define MN_INFOSETTINGSRV "InfoSettingSrv" +#define PR_INFOSETTINGSRV_S PR_TSS_S +#define PR_INFOSETTINGSRV PR_TSS + + #define TN_INFS_UIC "infs_uic" + #define PR_INFS_UIC_S PR_TSS_S + #define PR_INFS_UIC PR_TSS + +#define MN_DELPERSONALSRV "DelPersonalSrv" +#define PR_DELPERSONALSRV_S PR_TSS_S +#define PR_DELPERSONALSRV PR_TSS + +#define MN_MENUSERVICE "MenuService" +#define PR_MENUSERVICE_S PR_TSS_S +#define PR_MENUSERVICE PR_TSS + +#define MN_NAVIPROXY "NaviProxy" +#define PR_NAVIPROXY_S PR_TSS_S +#define PR_NAVIPROXY PR_TSS + +#define MN_AWBPROXY "AwbProxy" +#define PR_AWBPROXY_S PR_TSS_S +#define PR_AWBPROXY PR_TSS + +#define MN_TFFPROXY "TFFProxy" +#define PR_TFFPROXY_S PR_TSS_S +#define PR_TFFPROXY PR_TSS + +#define MN_TFFPROXYSLAVE "TFFProxySlave" +#define PR_TFFPROXYSLAVE_S PR_TSS_S +#define PR_TFFPROXYSLAVE PR_TSS + +#define MN_AWNPRIMARY "AwnPrimary" +#define PR_AWNPRIMARY_S PR_TSS_S +#define PR_AWNPRIMARY PR_TSS + +#define MN_AWBPRIMARY "AwbPrimary" +#define PR_AWBPRIMARY_S PR_TSS_S +#define PR_AWBPRIMARY PR_TSS + +#define MN_AWMPRIMARY "AwmPrimary" +#define PR_AWMPRIMARY_S PR_TSS_S +#define PR_AWMPRIMARY PR_TSS + +#define MN_AWTPRIMARY "AwtPrimary" +#define PR_AWTPRIMARY_S PR_TSS_S +#define PR_AWTPRIMARY PR_TSS + +#define MN_MISINKSERVICE "MisinkService" +#define PR_MISINKSERVICE_S PR_TSS_S +#define PR_MISINKSERVICE PR_TSS + +#define MN_TEXTCONVERTER "TextConverter" +#define PR_TEXTCONVERTER_S PR_TSS_S +#define PR_TEXTCONVERTER PR_TSS + +#define MN_HANDWRITING "HandWriting" +#define PR_HANDWRITING_S PR_TSS_S +#define PR_HANDWRITING PR_TSS + +#define MN_EXTUNITAUTH_D "EXTUNITAUTH_D" +#define PR_EXTUNITAUTH_D_S "29" +#define PR_EXTUNITAUTH_D 29 + + #define TN_VPSVC__CWORD84_ "VPSVC_D" + #define PR_VPSVC__CWORD84__S PR_TSS_S + #define PR_VPSVC__CWORD84_ PR_TSS + +#define MN_PROXYSERVICE "ProxyService" +#define PR_PROXYSERVICE_S PR_TSS_S +#define PR_PROXYSERVICE PR_TSS + +#define MN_FUELSERVICE "VS_FUCSrv" +#define PR_FUELSERVICE_S PR_TSS_S +#define PR_FUELSERVICE PR_TSS + +#define MN_ENERGYSERVICE "VS_ENMSrv" +#define PR_ENERGYSERVICE_S PR_TSS_S +#define PR_ENERGYSERVICE PR_TSS + +#define MN_CUSTOMIZESERVICE "VS_VSDSrv" +#define PR_CUSTOMIZESERVICE_S PR_TSS_S +#define PR_CUSTOMIZESERVICE PR_TSS + +#define MN_DMSSERVICE "VS_DMSSrv" +#define PR_DMSSERVICE_S PR_TSS_S +#define PR_DMSSERVICE PR_TSS + +#define MN_AIRCONSERVICE "VS_ACNSrv" +#define PR_AIRCONSERVICE_S PR_TSS_S +#define PR_AIRCONSERVICE PR_TSS + +#define MN_SEATSERVICE "VS_NMSSrv" +#define PR_SEATSERVICE_S PR_TSS_S +#define PR_SEATSERVICE PR_TSS + +#define MN_CAMERASERVICE "VS_CMRSrv" +#define PR_CAMERASERVICE_S PR_TSS_S +#define PR_CAMERASERVICE PR_TSS + + #define TN_CAMERAQUICKRVC "QuickRVCThread" + #define PR_CAMERAQUICKRVC_S PR_TSS_S + #define PR_CAMERAQUICKRVC PR_TSS + +#define MN_METSERVICE "VS_METSrv" +#define PR_METSERVICE_S PR_TSS_S +#define PR_METSERVICE PR_TSS + +#define MN_TMCSERVICE "VS_TMCSrv" +#define PR_TMCSERVICE_S PR_TSS_S +#define PR_TMCSERVICE PR_TSS + +#define MN_DASSERVICE "VS_DASSrv" +#define PR_DASSERVICE_S PR_TSS_S +#define PR_DASSERVICE PR_TSS + +#define MN_EXTUNITAUTH_M "EXTUNITAUTH_M" +#define PR_EXTUNITAUTH_M_S "29" +#define PR_EXTUNITAUTH_M 29 + +#define MN_DUMMYREAD "DummyRead" +#define PR_DUMMYREAD_S PR_TSS_S +#define PR_DUMMYREAD PR_TSS + +#define MN_SSTSERVICE "storage_access" +#define PR_SSTSERVICE_S PR_TSS_S +#define PR_SSTSERVICE PR_TSS + +#define MN_CCSAUDITD "ccs-auditd" +#define PR_CCSAUDITD_S PR_TSS_S +#define PR_CCSAUDITD PR_TSS + +//exec from task manager +#define MN_ACTIVITYMANAGER "ActivityManager" +#define PR_ACTIVITYMANAGER_S PR_TSS_S +#define PR_ACTIVITYMANAGER PR_TSS + +#define MN_RESIDENT_SVC "RESIDENT_SVC" +#define PR_RESIDENT_SVC_S PR_TSS_S +#define PR_RESIDENT_SVC PR_TSS + +#define MN_TRANSIENT_SVC "TRANSIENT_SVC" +#define PR_TRANSIENT_SVC_S PR_TSS_S +#define PR_TRANSIENT_SVC PR_TSS + +#define MN_WLANSERVICE "wlan_ctrl_0700" +#define PR_WLANSERVICE_S PR_TSS_S +#define PR_WLANSERVICE PR_TSS + +#define MN_WLANEVTTHR "WlanEvtThr" +#define PR_WLANEVTTHR_S PR_TSS_S +#define PR_WLANEVTTHR PR_TSS + +#define MN_WLANMIDDLESERVICE "WlanMiddle" +#define PR_WLANMIDDLESERVICE_S PR_TSS_S +#define PR_WLANMIDDLESERVICE PR_TSS + + #define TN_WLANMIDDLESERVICE0 "WM_MsgCtrlTh0" + #define PR_WLANMIDDLESERVICE0_S PR_TSS_S + #define PR_WLANMIDDLESERVICE0 PR_TSS + + #define TN_WLANMIDDLESERVICE1 "WM_MsgCtrlTh1" + #define PR_WLANMIDDLESERVICE1_S PR_TSS_S + #define PR_WLANMIDDLESERVICE1 PR_TSS + + #define TN_WLANMIDDLESERVICE2 "WM_MsgCtrlTh2" + #define PR_WLANMIDDLESERVICE2_S PR_TSS_S + #define PR_WLANMIDDLESERVICE2 PR_TSS + +#define MN_WLANSERVICE2 "wlan_ctrl_0701" +#define PR_WLANSERVICE2_S PR_TSS_S +#define PR_WLANSERVICE2 PR_TSS + +#define MN_WLANEVTTHR2 "WlanEvtThr2" +#define PR_WLANEVTTHR2_S PR_TSS_S +#define PR_WLANEVTTHR2 PR_TSS + +//exec from task manager, Test for vup +#define MN_PS__CWORD52_VUP "_CWORD52_vup" +#define PR_PS__CWORD52_VUP_S PR_TSS_S +#define PR_PS__CWORD52_VUP PR_TSS + +#define MN_PS_SYSVUP "sysvup" +#define PR_PS_SYSVUP_S PR_TSS_S +#define PR_PS_SYSVUP PR_TSS + +#define MN_SS_ROOTFSVUP "rootfsvup" +#define PR_SS_ROOTFSVUP_S PR_TSS_S +#define PR_SS_ROOTFSVUP PR_TSS + +#define MN_SS_VUPPROGUI "vupprogressui" +#define PR_SS_VUPPROGUI_S PR_TSS_S +#define PR_SS_VUPPROGUI PR_TSS + +#define MN_SS_NORVUP "norvup" +#define PR_SS_NORVUP_S PR_TSS_S +#define PR_SS_NORVUP PR_TSS + +// OUTER_UPDATE START +#define MN_XMVUPSERVICE "radio_xm_update" +#define PR_XMVUPSERVICE_S PR_TSS_S +#define PR_XMVUPSERVICE PR_TSS +// OUTER_UPDATE END + +#define MN_BTPHONESRV "BT_PhoneSrv" +#define PR_BTPHONESRV_S PR_TSS_S +#define PR_BTPHONESRV PR_TSS + +#define MN_BTPBKSRV "BT_PbkSrv" +#define PR_BTPBKSRV_S PR_TSS_S +#define PR_BTPBKSRV PR_TSS + +#define MN_BTMSGSRV "BT_MsgSrv" +#define PR_BTMSGSRV_S PR_TSS_S +#define PR_BTMSGSRV PR_TSS + +// NON-resident, exec from task manager, Repro update +#define MN_PS_SYSUPDATE "sysupdate" +#define PR_PS_SYSUPDATE_S PR_TSS_S +#define PR_PS_SYSUPDATE PR_TSS + +#define MN_SS_NANDUPDATE "nandupdate" +#define PR_SS_NANDUPDATE_S PR_TSS_S +#define PR_SS_NANDUPDATE PR_TSS + + #define TN_NANDUPDATE_CLD "t_nandcld" + #define PR_NANDUPDATE_CLD_S PR_TSS_S + #define PR_NANDUPDATE_CLD PR_TSS + +#define MN_BTPHONESRV "BT_PhoneSrv" +#define PR_BTPHONESRV_S PR_TSS_S +#define PR_BTPHONESRV PR_TSS + +#define MN_BTPBKSRV "BT_PbkSrv" +#define PR_BTPBKSRV_S PR_TSS_S +#define PR_BTPBKSRV PR_TSS + +#define MN_BTMSGSRV "BT_MsgSrv" +#define PR_BTMSGSRV_S PR_TSS_S +#define PR_BTMSGSRV PR_TSS + +//exec from diag +#define MN_DIAGSERVICE "DiagService" +#define PR_DIAGSERVICE_S PR_TSS_S +#define PR_DIAGSERVICE PR_TSS + +#define MN_DIAGWORKERTSK "diagworker_tsk" +#define PR_DIAGWORKERTSK_S PR_TSS_S +#define PR_DIAGWORKERTSK PR_TSS + +#define MN_DIAGTSK "diag_tsk" +#define PR_DIAGTSK_S PR_TSS_S +#define PR_DIAGTSK PR_TSS + +#define MN_DIAGMCTSK "diagmc_tsk" +#define PR_DIAGMCTSK_S PR_TSS_S +#define PR_DIAGMCTSK PR_TSS + +#define MN_DIAGUTCOL "diagutCol_tsk" +#define PR_DIAGUTCOL_S PR_TSS_S +#define PR_DIAGUTCOL PR_TSS + +#define MN_DIAGUTUPD "diagutUpd_tsk" +#define PR_DIAGUTUPD_S PR_TSS_S +#define PR_DIAGUTUPD PR_TSS + +//exec from Connectivity for _CWORD57_ +#define MN__CWORD57_UTILSERVICE "_CWORD57_UtilService" +#define PR__CWORD57_UTILSERVICE_S PR_TSS_S +#define PR__CWORD57_UTILSERVICE PR_TSS + + #define TN_CON_IPUT_DETECT "iputsrv_detect" + #define PR_CON_IPUT_DETECT_S PR_TSS_S + #define PR_CON_IPUT_DETECT PR_TSS + + #define TN_CON_IPUT_AUTH "iputsrv_auth" + #define PR_CON_IPUT_AUTH_S PR_TSS_S + #define PR_CON_IPUT_AUTH PR_TSS + + #define TN_CON_IPUT_SERIAL "iputsrv_serial" + #define PR_CON_IPUT_SERIAL_S PR_TSS_S + #define PR_CON_IPUT_SERIAL PR_TSS + + #define TN_CON_IPUT_USB_1 "iputsrv_usb1" + #define PR_CON_IPUT_USB_1_S PR_TSS_S + #define PR_CON_IPUT_USB_1 PR_TSS + + #define TN_CON_IPUT_USB_2 "iputsrv_usb2" + #define PR_CON_IPUT_USB_2_S PR_TSS_S + #define PR_CON_IPUT_USB_2 PR_TSS + + #define TN_CON_IPUT_SPP "iputsrv_spp" + #define PR_CON_IPUT_SPP_S PR_TSS_S + #define PR_CON_IPUT_SPP PR_TSS + +#define MN__CWORD57_DTSERVICE "_CWORD57_DTService" +#define PR__CWORD57_DTSERVICE_S PR_TSS_S +#define PR__CWORD57_DTSERVICE PR_TSS + + #define TN_CON_IPDT_SERIAL "ipdtsrv_serial" + #define PR_CON_IPDT_SERIAL_S PR_TSS_S + #define PR_CON_IPDT_SERIAL PR_TSS + + #define TN_CON_IPDT_USB_1 "ipdtsrv_usb1" + #define PR_CON_IPDT_USB_1_S PR_TSS_S + #define PR_CON_IPDT_USB_1 PR_TSS + + #define TN_CON_IPDT_USB_2 "ipdtsrv_usb2" + #define PR_CON_IPDT_USB_2_S PR_TSS_S + #define PR_CON_IPDT_USB_2 PR_TSS + + #define TN_CON_IPDT_SPP "ipdtsrv_spp" + #define PR_CON_IPDT_SPP_S PR_TSS_S + #define PR_CON_IPDT_SPP PR_TSS + +#define MN_WEBDAVMGR "webdavmgr" +#define PR_WEBDAVMGR_S PR_TSS_S +#define PR_WEBDAVMGR PR_TSS + +#define MN_DISPLAYSERVICE "DisplayService" +#define PR_DISPLAYSERVICE_S PR_TSS_S +#define PR_DISPLAYSERVICE PR_TSS + +#define MN_ENFORMSERVICE "EnformService" +#define PR_ENFORMSERVICE_S PR_TSS_S +#define PR_ENFORMSERVICE PR_TSS + +#define MN_CONNUTIL "ConnUtil" +#define PR_CONNUTIL_S PR_TSS_S +#define PR_CONNUTIL PR_TSS + +#define MN_CONNUTILSLAVE "ConnUtilSlave" +#define PR_CONNUTILSLAVE_S PR_TSS_S +#define PR_CONNUTILSLAVE PR_TSS + +#define MN_CONNMGR "ConnMgr" +#define PR_CONNMGR_S PR_TSS_S +#define PR_CONNMGR PR_TSS + +#define MN_SERVICEFLAGMGR "ServiceFlagMgr" +#define PR_SERVICEFLAGMGR_S PR_TSS_S +#define PR_SERVICEFLAGMGR PR_TSS + +//exec from VR +#define MN_VRMANAGER "vrmanager" +#define PR_VRMANAGER_S PR_TSS_S +#define PR_VRMANAGER PR_TSS + + #define TN_VR_WORKER "VrWorkerThread" + #define PR_VR_WORKER_S PR_TSS_S + #define PR_VR_WORKER PR_TSS + + #define TN_VBT_PROPDISPATCH "PropDispatchThread" + #define PR_VBT_PROPDISPATCH_S PR_TSS_S + #define PR_VBT_PROPDISPATCH PR_TSS + + #define TN_VBT_PROPRESPONSE "PropResponseThread" + #define PR_VBT_PROPRESPONSE_S PR_TSS_S + #define PR_VBT_PROPRESPONSE PR_TSS + + #define TN_VBT_PROPAUDIOPLAY "PropAudioPlayThread" + #define PR_VBT_PROPAUDIOPLAY_S PR_TSS_S + #define PR_VBT_PROPAUDIOPLAY PR_TSS + + #define TN_VBT_PROPAUDIORECORD "PropAudioRecordThread" + #define PR_VBT_PROPAUDIORECORD_S PR_TSS_S + #define PR_VBT_PROPAUDIORECORD PR_TSS + + #define TN_VBT_MAINTHREADPRIO "MainThreadPriority" + #define PR_VBT_MAINTHREADPRIO_S PR_TSS_S + #define PR_VBT_MAINTHREADPRIO PR_TSS + + #define TN_VBT_ASRMANAGERGRAMMAR "AsrManagerGrammarGenerationThread" + #define PR_VBT_ASRMANAGERGRAMMAR_S PR_TSS_S + #define PR_VBT_ASRMANAGERGRAMMAR PR_TSS + + #define TN_VBT_ASRVOCONRECO "AsrVoconRecoProcessThread" + #define PR_VBT_ASRVOCONRECO_S PR_TSS_S + #define PR_VBT_ASRVOCONRECO PR_TSS + + #define TN_VBT_BROADCASTREAD "BroadCastReadThread" + #define PR_VBT_BROADCASTREAD_S PR_TSS_S + #define PR_VBT_BROADCASTREAD PR_TSS + + #define TN_VBT_FILEAGGREGATOR "FileAggregatorDecompressThread" + #define PR_VBT_FILEAGGREGATOR_S PR_TSS_S + #define PR_VBT_FILEAGGREGATOR PR_TSS + + #define TN_VBT_HTTPCURLREQUEST "HttpCurlRequestThread" + #define PR_VBT_HTTPCURLREQUEST_S PR_TSS_S + #define PR_VBT_HTTPCURLREQUEST PR_TSS + + #define TN_VBT_HTTPDRIVERREQUEST "HttpDriverRequestThread" + #define PR_VBT_HTTPDRIVERREQUEST_S PR_TSS_S + #define PR_VBT_HTTPDRIVERREQUEST PR_TSS + + #define TN_VBT_HTTPREQUESTSESSION "HttpRequestSessionStateThread" + #define PR_VBT_HTTPREQUESTSESSION_S PR_TSS_S + #define PR_VBT_HTTPREQUESTSESSION PR_TSS + + #define TN_VBT_PLAYMGRSTOPASYNC "PlayMgrStopAsyncStreamThread" + #define PR_VBT_PLAYMGRSTOPASYNC_S PR_TSS_S + #define PR_VBT_PLAYMGRSTOPASYNC PR_TSS + + #define TN_VBT_RESOURCEMGRQUEUE "ResourceMgrQueueHandlerThread" + #define PR_VBT_RESOURCEMGRQUEUE_S PR_TSS_S + #define PR_VBT_RESOURCEMGRQUEUE PR_TSS + + #define TN_VBT_SMURFDRIVERTIMEOUT "SmurfDriverTimeoutThread" + #define PR_VBT_SMURFDRIVERTIMEOUT_S PR_TSS_S + #define PR_VBT_SMURFDRIVERTIMEOUT PR_TSS + + #define TN_NVR_NVRMAIN "NvrMainThread" + #define PR_NVR_NVRMAIN_S PR_TSS_S + #define PR_NVR_NVRMAIN PR_TSS + + #define TN_NVR_NVRRECO "NvrRecoThread" + #define PR_NVR_NVRRECO_S PR_TSS_S + #define PR_NVR_NVRRECO PR_TSS + + #define TN_NVR_NVRDICT "NvrDictThread" + #define PR_NVR_NVRDICT_S PR_TSS_S + #define PR_NVR_NVRDICT PR_TSS + + #define TN_NVR_NVRENC "NvrEncThread" + #define PR_NVR_NVRENC_S PR_TSS_S + #define PR_NVR_NVRENC PR_TSS + +//exec from VehicleInfo +#define MN_VEHICLEINFOSERVICE "VehicleInfoSrv" +#define PR_VEHICLEINFOSERVICE_S PR_TSS_S +#define PR_VEHICLEINFOSERVICE PR_TSS + +//exec from _CWORD76_ +#define MN__CWORD76_SERVICE "_CWORD76_Service" +#define PR__CWORD76_SERVICE_S PR_TSS_S +#define PR__CWORD76_SERVICE PR_TSS + + #define TN_APPDOWNLOADER "AppDownloader" + #define PR_APPDOWNLOADER_S PR_TSS_S + #define PR_APPDOWNLOADER PR_TSS + +//exec from _CWORD76_(_CWORD58_) +#define MN__CWORD58_SERVICE "_CWORD58_Service" +#define PR__CWORD58_SERVICE_S PR_TSS_S +#define PR__CWORD58_SERVICE PR_TSS + +#define MN__CWORD8_SRV "_CWORD8_Srv" +#define PR__CWORD8_SRV_S PR_TSS_S +#define PR__CWORD8_SRV PR_TSS + +#define MN_SPCSERVICE "SPCService" +#define PR_SPCSERVICE_S PR_TSS_S +#define PR_SPCSERVICE PR_TSS + +#define MN_LOCALSERVERPROXY "LSP" +#define PR_LOCALSERVERPROXY_S PR_TSS_S +#define PR_LOCALSERVERPROXY PR_TSS + +#define MN_EOMSERVICE "eOMService" +#define PR_EOMSERVICE_S PR_TSS_S +#define PR_EOMSERVICE PR_TSS + +//exec from NetworkManager +#define MN_NETWORKMANAGER "NetworkManager" +#define PR_NETWORKMANAGER_S PR_TSS_S +#define PR_NETWORKMANAGER PR_TSS + + #define TN_NWM_TH_CMDRCV "NWM_Th_CmdRcv" + #define PR_NWM_TH_CMDRCV_S PR_TSS_S + #define PR_NWM_TH_CMDRCV PR_TSS + + #define TN_NWM_TH_PROCMGR "NWM_Th_ProcMgr" + #define PR_NWM_TH_PROCMGR_S PR_TSS_S + #define PR_NWM_TH_PROCMGR PR_TSS + + #define TN_NWM_TH_CMDPROC "NWM_Th_CmdProc" + #define PR_NWM_TH_CMDPROC_S PR_TSS_S + #define PR_NWM_TH_CMDPROC PR_TSS + + #define TN_NWM_TH_DNSMGR "NWM_Th_DnsMgr" + #define PR_NWM_TH_DNSMGR_S PR_TSS_S + #define PR_NWM_TH_DNSMGR PR_TSS + + #define TN_NWM_TH_DHCPD "NWM_Th_Dhcpd" + #define PR_NWM_TH_DHCPD_S PR_TSS_S + #define PR_NWM_TH_DHCPD PR_TSS + +// DCM Service +#define MN_DCMSERVICE "DCMService" +#define PR_DCMSERVICE_S PR_TSS_S +#define PR_DCMSERVICE PR_TSS + + #define TN_DCM_TH_CMDRCV "DCM_Th_CmdRcv" + #define PR_DCM_TH_CMDRCV_S PR_TSS_S + #define PR_DCM_TH_CMDRCV PR_TSS + + #define TN_DCM_TH_MSGRCV "DCM_Th_MsgRcv" + #define PR_DCM_TH_MSGRCV_S PR_TSS_S + #define PR_DCM_TH_MSGRCV PR_TSS + + #define TN_DCM_TH_TIMER "DCM_Th_Timer" + #define PR_DCM_TH_TIMER_S PR_TSS_S + #define PR_DCM_TH_TIMER PR_TSS + +// HELP Service +#define MN_HELPSERVICE "HELPService" +#define PR_HELPSERVICE_S PR_TSS_S +#define PR_HELPSERVICE PR_TSS + +//exec from RemoteService +#define MN_REMOTESERVICE "RemoteService" +#define PR_REMOTESERVICE_S PR_TSS_S +#define PR_REMOTESERVICE PR_TSS + + #define TN_RS_TH_CANCTRL "RS_Th_CANCtrl" + #define PR_RS_TH_CANCTRL_S PR_TSS_S + #define PR_RS_TH_CANCTRL PR_TSS + + #define TN_RS_TH_DISPCTRL "RS_Th_DispCtrl" + #define PR_RS_TH_DISPCTRL_S PR_TSS_S + #define PR_RS_TH_DISPCTRL PR_TSS + + #define TN_RS_TH_PARTSCTRL "RS_Th_PartsCtrl" + #define PR_RS_TH_PARTSCTRL_S PR_TSS_S + #define PR_RS_TH_PARTSCTRL PR_TSS + + #define TN_RS_TH_HTTPPROC "RS_Th_HttpProc" + #define PR_RS_TH_HTTPPROC_S PR_TSS_S + #define PR_RS_TH_HTTPPROC PR_TSS + +//exec from VR +#define MN_CONTENTSMGR "contentsmgr" +#define PR_CONTENTSMGR_S PR_TSS_S +#define PR_CONTENTSMGR PR_TSS + + #define TN_CDB_CONTENDB "contendbThread" + #define PR_CDB_CONTENDB_S PR_TSS_S + #define PR_CDB_CONTENDB PR_TSS + +/* COMARB Service */ +#define MN_NW_COMARB "ComArbService" +#define PR_NW_COMARB_S PR_TSS_S +#define PR_NW_COMARB PR_TSS + +/* ASND_FRthread */ +#define MN_ASND_FRTH "ASND_FRthread" +#define PR_ASND_FRTH_S PR_SND_VCETRFCTRL_S +#define PR_ASND_FRTH PR_SND_VCETRFCTRL + +/* MLINK Service */ +#define MN_MLINKSERVICE "MlinkService" +#define PR_MLINKSERVICE_S PR_TSS_S +#define PR_MLINKSERVICE PR_TSS + +#define MN__CWORD74_SERVICE "_CWORD74_Service" +#define PR__CWORD74_SERVICE_S PR_TSS_S +#define PR__CWORD74_SERVICE PR_TSS +#endif //__AGL_THREAD_H__ diff --git a/systemservice/task_manager/client/libtskmcfg/conf/tskm_launch.xml b/systemservice/task_manager/client/libtskmcfg/conf/tskm_launch.xml new file mode 100755 index 0000000..d4ab06c --- /dev/null +++ b/systemservice/task_manager/client/libtskmcfg/conf/tskm_launch.xml @@ -0,0 +1,106 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/systemservice/task_manager/client/libtskmcfg/conf/tskm_shutdown.xml b/systemservice/task_manager/client/libtskmcfg/conf/tskm_shutdown.xml new file mode 100755 index 0000000..4f724f7 --- /dev/null +++ b/systemservice/task_manager/client/libtskmcfg/conf/tskm_shutdown.xml @@ -0,0 +1,11 @@ + + + + + + + + + + + diff --git a/systemservice/task_manager/client/libtskmcfg/conf/tskm_shutdown_vup.xml b/systemservice/task_manager/client/libtskmcfg/conf/tskm_shutdown_vup.xml new file mode 100755 index 0000000..71a30c8 --- /dev/null +++ b/systemservice/task_manager/client/libtskmcfg/conf/tskm_shutdown_vup.xml @@ -0,0 +1,6 @@ + + + + + + diff --git a/systemservice/task_manager/client/libtskmcfg/conf/tskm_wakeup.xml b/systemservice/task_manager/client/libtskmcfg/conf/tskm_wakeup.xml new file mode 100755 index 0000000..aeb3548 --- /dev/null +++ b/systemservice/task_manager/client/libtskmcfg/conf/tskm_wakeup.xml @@ -0,0 +1,8 @@ + + + + + + + + diff --git a/systemservice/task_manager/client/libtskmcfg/conf/tskm_wakeup_vup.xml b/systemservice/task_manager/client/libtskmcfg/conf/tskm_wakeup_vup.xml new file mode 100755 index 0000000..7162fdf --- /dev/null +++ b/systemservice/task_manager/client/libtskmcfg/conf/tskm_wakeup_vup.xml @@ -0,0 +1,5 @@ + + + + + diff --git a/systemservice/task_manager/client/libtskmcfg/include/system_service/task_manager_libtskmcfg.h b/systemservice/task_manager/client/libtskmcfg/include/system_service/task_manager_libtskmcfg.h new file mode 100755 index 0000000..c042fc8 --- /dev/null +++ b/systemservice/task_manager/client/libtskmcfg/include/system_service/task_manager_libtskmcfg.h @@ -0,0 +1,40 @@ +/* + * @copyright Copyright (c) 2017-2020 TOYOTA MOTOR CORPORATION. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +/** + * @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/systemservice/task_manager/client/libtskmcfg/include/system_service/tskm_svcid.h b/systemservice/task_manager/client/libtskmcfg/include/system_service/tskm_svcid.h new file mode 100755 index 0000000..d8f3e3d --- /dev/null +++ b/systemservice/task_manager/client/libtskmcfg/include/system_service/tskm_svcid.h @@ -0,0 +1,59 @@ +/* + * @copyright Copyright (c) 2016-2020 TOYOTA MOTOR CORPORATION. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +/** + * @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/systemservice/task_manager/client/libtskmcfg/include/system_service/tskm_xml_data.h b/systemservice/task_manager/client/libtskmcfg/include/system_service/tskm_xml_data.h new file mode 100755 index 0000000..0c8b75b --- /dev/null +++ b/systemservice/task_manager/client/libtskmcfg/include/system_service/tskm_xml_data.h @@ -0,0 +1,173 @@ +/* + * @copyright Copyright (c) 2016-2020 TOYOTA MOTOR CORPORATION. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +/** + * @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/systemservice/task_manager/client/libtskmcfg/libtskmcfg.ver b/systemservice/task_manager/client/libtskmcfg/libtskmcfg.ver new file mode 100755 index 0000000..c7bb97b --- /dev/null +++ b/systemservice/task_manager/client/libtskmcfg/libtskmcfg.ver @@ -0,0 +1,21 @@ +/* + * @copyright Copyright (c) 2016-2020 TOYOTA MOTOR CORPORATION. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +{ + global: + tskm_init*; + local: *; +}; diff --git a/systemservice/task_manager/client/libtskmcfg/src/parsexml.c b/systemservice/task_manager/client/libtskmcfg/src/parsexml.c new file mode 100755 index 0000000..7cb3929 --- /dev/null +++ b/systemservice/task_manager/client/libtskmcfg/src/parsexml.c @@ -0,0 +1,879 @@ +/* + * @copyright Copyright (c) 2016-2020 TOYOTA MOTOR CORPORATION. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include + +#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/systemservice/task_manager/client/libtskmcfg/src/tskm_xml_data.cpp b/systemservice/task_manager/client/libtskmcfg/src/tskm_xml_data.cpp new file mode 100755 index 0000000..531b701 --- /dev/null +++ b/systemservice/task_manager/client/libtskmcfg/src/tskm_xml_data.cpp @@ -0,0 +1,138 @@ +/* + * @copyright Copyright (c) 2016-2020 TOYOTA MOTOR CORPORATION. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "system_service/tskm_xml_data.h" + +#include +#include +#include +#include +#include + +#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 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 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::iterator ite = capFiles.begin(); + ite != capFiles.end(); ite++) { + if (binPath == *ite) { + std::list 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(); + 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/systemservice/task_manager/client/libtskmcfg/tskm_cfg.xml b/systemservice/task_manager/client/libtskmcfg/tskm_cfg.xml new file mode 100755 index 0000000..2898f44 --- /dev/null +++ b/systemservice/task_manager/client/libtskmcfg/tskm_cfg.xml @@ -0,0 +1,83 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +]> + + + + &service_list_xml; + + &normal_wakeup_xml; + + &normal_shutdown_xml; + + &vup_wakeup_xml; + + &vup_shutdown_xml; + + diff --git a/systemservice/task_manager/client/ss_data_init/Makefile b/systemservice/task_manager/client/ss_data_init/Makefile new file mode 100755 index 0000000..920fbea --- /dev/null +++ b/systemservice/task_manager/client/ss_data_init/Makefile @@ -0,0 +1,43 @@ +# +# @copyright Copyright (c) 2016-2020 TOYOTA MOTOR CORPORATION. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +####################################### +####################################### +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/systemservice/task_manager/client/ss_data_init/include/libss_data_init_taskmanagerlog.h b/systemservice/task_manager/client/ss_data_init/include/libss_data_init_taskmanagerlog.h new file mode 100755 index 0000000..39422e9 --- /dev/null +++ b/systemservice/task_manager/client/ss_data_init/include/libss_data_init_taskmanagerlog.h @@ -0,0 +1,78 @@ +/* + * @copyright Copyright (c) 2016-2020 TOYOTA MOTOR CORPORATION. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#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 + +#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/systemservice/task_manager/client/ss_data_init/include/system_service/task_manager_libss_data_init.h b/systemservice/task_manager/client/ss_data_init/include/system_service/task_manager_libss_data_init.h new file mode 100755 index 0000000..e3bdfc5 --- /dev/null +++ b/systemservice/task_manager/client/ss_data_init/include/system_service/task_manager_libss_data_init.h @@ -0,0 +1,39 @@ +/* + * @copyright Copyright (c) 2017-2020 TOYOTA MOTOR CORPORATION. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +/** + * @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/systemservice/task_manager/client/ss_data_init/include/system_service/tskm_data_init.h b/systemservice/task_manager/client/ss_data_init/include/system_service/tskm_data_init.h new file mode 100755 index 0000000..8cb49d6 --- /dev/null +++ b/systemservice/task_manager/client/ss_data_init/include/system_service/tskm_data_init.h @@ -0,0 +1,121 @@ +/* + * @copyright Copyright (c) 2016-2020 TOYOTA MOTOR CORPORATION. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + + +/** + * @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 +#include +#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/systemservice/task_manager/client/ss_data_init/include/tskm_data_init_local.h b/systemservice/task_manager/client/ss_data_init/include/tskm_data_init_local.h new file mode 100755 index 0000000..9d77d19 --- /dev/null +++ b/systemservice/task_manager/client/ss_data_init/include/tskm_data_init_local.h @@ -0,0 +1,25 @@ +/* + * @copyright Copyright (c) 2016-2020 TOYOTA MOTOR CORPORATION. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#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/systemservice/task_manager/client/ss_data_init/mkdatainit.sh b/systemservice/task_manager/client/ss_data_init/mkdatainit.sh new file mode 100755 index 0000000..802fbd9 --- /dev/null +++ b/systemservice/task_manager/client/ss_data_init/mkdatainit.sh @@ -0,0 +1,45 @@ +#!/bin/bash + +# +# Copyright (c) 2019-2020 TOYOTA MOTOR CORPORATION +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +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/systemservice/task_manager/client/ss_data_init/tskm_data_init.cpp.in b/systemservice/task_manager/client/ss_data_init/tskm_data_init.cpp.in new file mode 100755 index 0000000..072a486 --- /dev/null +++ b/systemservice/task_manager/client/ss_data_init/tskm_data_init.cpp.in @@ -0,0 +1,66 @@ +/* + * @copyright Copyright (c) 2019-2020 TOYOTA MOTOR CORPORATION. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#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;igstepNum == p_gstep->gstepIdx + 1) { + return TSKM_TRUE; + } + return TSKM_FALSE; +} + +/********************************************************* + * Get gradual startup current info + *********************************************************/ +inline TSKM_STATIC TSKM_GSTEP_t* +gstepGetCurrent(TSKM_GSTEP_CTX_t* p_gstep) { + if (p_gstep->gstepNum > p_gstep->gstepIdx) { + return &p_gstep->gstep[p_gstep->gstepIdx]; + } + return NULL; +} + +/********************************************************* + * Issue requests waiting for exec completion + *********************************************************/ +inline TSKM_STATIC TSKM_GSTEP_t* +changeNextStep(TSKM_GSTEP_CTX_t* p_gstep) { + p_gstep->gstepIdx++; + return gstepGetCurrent(p_gstep); +} + +#endif // TASK_MANAGER_INCLUDE_SHARE_TSKM_GSTEP_H_ + diff --git a/systemservice/task_manager/include-share/tskm_type_local.h b/systemservice/task_manager/include-share/tskm_type_local.h new file mode 100755 index 0000000..8ead34e --- /dev/null +++ b/systemservice/task_manager/include-share/tskm_type_local.h @@ -0,0 +1,52 @@ +/* + * @copyright Copyright (c) 2016-2020 TOYOTA MOTOR CORPORATION. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef TASK_MANAGER_INCLUDE_SHARE_TSKM_TYPE_LOCAL_H_ +#define TASK_MANAGER_INCLUDE_SHARE_TSKM_TYPE_LOCAL_H_ + +#define NTFY_SS_TaskManager_Availability SS_TASK_MANAGER"/Availability" + +//******************************************************* +// Legacy types: +// Definition is retained because it is referenced by another module +//****************************************************** + +// Shared LOG with version upgrade +#define STATEMGR__CWORD69_LOG_SIZE 176 /* STATEMGR__CWORD69_LOG */ +typedef struct { + uint8_t old_Ver[8]; + uint8_t new_Ver[8]; +} STATEMGR__CWORD69_LOG_VERSION_T; + +typedef struct { + STATEMGR__CWORD69_LOG_VERSION_T ver; + uint8_t status; + uint8_t dummy[3]; +} STATEMGR__CWORD69_LOG_VUPINFO_T; + +typedef struct { + uint32_t seqnum; /* Set value (for chequence check) */ + uint32_t normalnum; /* Set value (for route check) */ + uint32_t errornum; /* Set value (for NG check) */ +} STATEMGR__CWORD69_LOG_PROC; + +typedef struct { + STATEMGR__CWORD69_LOG_VUPINFO_T VerInfo[7]; /* Store version info */ + STATEMGR__CWORD69_LOG_PROC proc[3]; /* Store logs for analysis */ +} STATEMGR__CWORD69_LOG; + +#endif // TASK_MANAGER_INCLUDE_SHARE_TSKM_TYPE_LOCAL_H_ + diff --git a/systemservice/task_manager/include-share/tskm_util.h b/systemservice/task_manager/include-share/tskm_util.h new file mode 100755 index 0000000..83665aa --- /dev/null +++ b/systemservice/task_manager/include-share/tskm_util.h @@ -0,0 +1,32 @@ +/* + * @copyright Copyright (c) 2016-2020 TOYOTA MOTOR CORPORATION. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef TASK_MANAGER_INCLUDE_SHARE_TSKM_UTIL_H_ +#define TASK_MANAGER_INCLUDE_SHARE_TSKM_UTIL_H_ + +#include "system_service/tskm_local_type.h" +#include "tskm_main.h" + +// inline MACRO +#define TSKM_ERR_CHK(ret, expect, lavel) \ + if (ret != expect) {TSKM_ASSERT(0); goto lavel;} + +#define TSKM_ERR_CHK_DFT TSKM_ERR_CHK(tskmRet, TSKM_E_OK, ERROR) + +#define TSKM_MAX(a, b) ((a) > (b) ? (a) : (b)) + +#endif // TASK_MANAGER_INCLUDE_SHARE_TSKM_UTIL_H_ + diff --git a/systemservice/task_manager/server/Makefile b/systemservice/task_manager/server/Makefile new file mode 100755 index 0000000..7e7bfbd --- /dev/null +++ b/systemservice/task_manager/server/Makefile @@ -0,0 +1,67 @@ +# +# @copyright Copyright (c) 2016-2020 TOYOTA MOTOR CORPORATION. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + + +####################################### +INST_PROGS = tskmgr + +######### add source path ############# +######### add local value ############# +VPATH = ./src ./../client/libtskm ./../client/libtskmcfg/include/$(COMPONENT_NAME) + +tskmgr_SRCS += tskm_main.cpp + +######### compiled sources ############# +tskmgr_SRCS += tskm_api.cpp \ + tskm_state.cpp \ + tskm_wakeup.cpp \ + tskm_shutdown.cpp \ + tskm_svc.cpp \ + tskm_watch.cpp \ + tskm_debug.cpp \ + tskm_comm.cpp \ + tskm_port_pf.cpp \ + tskm_port_subsys.cpp \ + tskm_srvr_stub.cpp + + + +######### add include path ############# +CPPFLAGS = -I./include/ -I./../include-share/ -I./../client/ss_data_init/include/ -I./../client/libtskmcfg/include/ -I./../client/libtskm/ +######### add compile option ########### +CPPFLAGS += -fno-exceptions +CPPFLAGS += -DIMPL_AGL_APPLICATION_CALLBACKS_PRE_BACKGROUND +######### add library path ############# +LDFLAGS += -L./../client/ss_data_init -L./../client/libtskmcfg + +######### linked library (dynamic) ############# +LDLIBS += -Wl,-Bdynamic -lstdc++ +LDLIBS += -Wl,-Bdynamic -lrt # for mq_xxx +LDLIBS += -Wl,-Bdynamic -lss_data_init +LDLIBS += -Wl,-Bdynamic -lSS_SystemIfUnified +LDLIBS += -Wl,-Bdynamic -lNS_FrameworkUnified +LDLIBS += -Wl,-Bdynamic -lresm +LDLIBS += -Wl,-Bdynamic -lcommon +LDLIBS += -Wl,-Bdynamic -lvp +LDLIBS += -Wl,-Bdynamic -lrpc -lev + +#LDLIBS += -Wl,-Bdynamic -lDiagCodeAPI +LDLIBS += -Wl,-Bdynamic -ltskmcfg + + +LINK_CXX=Y + +include ../../system_service.mk diff --git a/systemservice/task_manager/server/include/system_service/INI_API.h b/systemservice/task_manager/server/include/system_service/INI_API.h new file mode 100755 index 0000000..871be5e --- /dev/null +++ b/systemservice/task_manager/server/include/system_service/INI_API.h @@ -0,0 +1,25 @@ +/* + * @copyright Copyright (c) 2016-2020 TOYOTA MOTOR CORPORATION. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +/** + * @file INI_API.h + * @brief \~english This file include INI_API.hpp + */ +#ifndef TASK_MANAGER_SERVER_INCLUDE_SYSTEM_SERVICE_INI_API_H_ +#define TASK_MANAGER_SERVER_INCLUDE_SYSTEM_SERVICE_INI_API_H_ + +#include "system_service/INI_API.hpp" + +#endif // TASK_MANAGER_SERVER_INCLUDE_SYSTEM_SERVICE_INI_API_H_ diff --git a/systemservice/task_manager/server/include/system_service/INI_API.hpp b/systemservice/task_manager/server/include/system_service/INI_API.hpp new file mode 100755 index 0000000..00fe733 --- /dev/null +++ b/systemservice/task_manager/server/include/system_service/INI_API.hpp @@ -0,0 +1,738 @@ +/* + * @copyright Copyright (c) 2016-2020 TOYOTA MOTOR CORPORATION. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * @file INI_API.hpp + * @brief \~english This file provide api to operating INI + */ + +/** @addtogroup BaseSystem + * @{ + */ +/** @addtogroup system_service + * @ingroup BaseSystem + * @{ + */ +/** @addtogroup task_manager + * @ingroup system_service + * @{ + */ + +#ifndef _INI_API_HPP_ +#define _INI_API_HPP_ + +#include +#include +#include "system_service/Primary_common.h" + +#define INI_SUCCESS 0 /* Normal */ +#define INI_FALSE -1 /* Failed */ + +#define INI_FD_MAX 3 + +// Only the information required for event completion notification is left +// Gradual startup +#define INI_INITCOMP_NONE 0x0000000000000000LLU +#define INI_INITCOMP_ON_START 0x0000000000000001LLU /* ON_START */ +#define INI_INITCOMP_NVM_ACCESS 0x0000000000000002LLU /* NVM ACCESS */ + +#define INI_INITCOMP_TEST0 0x1000000000000000LLU /* for test */ +#define INI_INITCOMP_TEST1 0x2000000000000000LLU /* for test */ +#define INI_INITCOMP_TEST2 0x4000000000000000LLU /* for test */ +#define INI_INITCOMP_TEST3 0x8000000000000000LLU /* for test */ + +// Gradual termination +#define INI_TERMCOMP_NONE 0x0000000000000000LLU +#define INI_TERMCOMP_ACTIVITYMGR 0x0000000000000001LLU /* Terminate ActivityManager */ +#define INI_TERMCOMP_RESIDENT 0x0000000000000002LLU /* Terminate regident SVC */ +#define INI_TERMCOMP_TRANSIENT 0x0000000000000004LLU /* Terminate non-regident SVC */ + +#define INI_TERMCOMP_TEST0 0x1000000000000000LLU /* for test */ +#define INI_TERMCOMP_TEST1 0x2000000000000000LLU /* for test */ +#define INI_TERMCOMP_TEST2 0x4000000000000000LLU /* for test */ +#define INI_TERMCOMP_TEST3 0x8000000000000000LLU /* for test */ + + + +typedef struct _T_PRIM_PRM{ + PCSTR name; + const PRIM_SHAREDATA_TBL* shmTbl; + const PRIM_EXFUNC_TBL* wakeupExFuncTbl; + const PRIM_EXFUNC_TBL* downExFuncTbl; + EFrameworkunifiedStatus (*onInit)(HANDLE hApp); + EFrameworkunifiedStatus (*onDestory)(HANDLE hApp); + EFrameworkunifiedStatus (*onDebugDump)(HANDLE hApp); + EFrameworkunifiedStatus (*onTouch)(HANDLE hApp); + EFrameworkunifiedStatus (*onLowMem)(HANDLE hApp); + void* priv; + _T_PRIM_PRM(){ + name = NULL; + shmTbl = NULL; + wakeupExFuncTbl = NULL; + downExFuncTbl = NULL; + onInit = NULL; + onDestory = NULL; + onDebugDump = NULL; + onTouch = NULL; + onLowMem = NULL; + priv = NULL; + } +}T_PRIM_PRM; + + +typedef struct { + BOOL bIsRun; + uint32_t timeout; +}T_PRIM_MONITOR_PRM; + +#ifdef __cplusplus +extern "C" { +#endif + +///////////////////////////////////////////////////////////////////////////////////// +/// \ingroup INI_Main +/// \~english @par Summary: +/// Runs the main thread of primary library. +/// \~english @param [in] p_prm +/// T_PRIM_PRM - The pointer to the parameter table of primary library +/// \~english @param [in] argc +/// int - The number of command parameters (The parameters passed to main functions must be set without processing.) +/// \~english @param [in] argv +/// char* - Command parameters (The parameters passed to main functions must be set without processing.) +/// \~english @par +/// - Shared memory creation table \n +/// In process running, register the shared memory to create.\n +/// This creates the shared memory to be registered in process running and releases it in process end.\n +/// This must terminate by adding {"\0"} into member shmName of table termination.\n +/// It is able to access to the shared memory to have been created by shm_open.\n +/// \~english @code +/// typedef struct { +/// char shmName[32]; /* Shared memory name */ +/// uint32_t size; /* Shared memory size (BYTE) */ +/// }PRIM_SHAREDATA_TBL; +/// @endcode +/// \~english @par +/// - Running extended function table / End extended function table \n +/// Registers callback functions to be called in process start and exit.\n +/// This must terminate by adding NULL into member func of table termination.\n +/// Parameters prm of callback functions are User private information and the pointer designated by prm is passed as input parameters [in].\n +/// Local phase numbers callback func by the designated phase numbers.\n +/// \~english @code +/// typedef struct { +/// void (* func)( void* prm); /* Callback functions for function extension */ +/// void* prm; /* The pointer to the parameters of Callback function func */ +/// uint8_t localStep; /* Local phase numbers */ +/// uint8_t rsv[3]; /* Reserve for alignment */ +/// }PRIM_EXFUNC_TBL; +/// @endcode +/// \~english @par +/// - %Parameter table of primary library\n +/// For FrameworkunifiedOnInitialization/FrameworkunifiedOnDestroy/FrameworkunifiedOnDebugDump/TaskmanagerOnTouch/FrameworkunifiedOnLowMemory, check the corresponding API specification.\n +/// It is able to get User private data by INI_GetPrivate().\n +/// \~english @code +/// typedef struct _T_PRIM_PRM{ +/// PCSTR name; /* Application name */ +/// const PRIM_SHAREDATA_TBL* shmTbl; /* The pointer to shared memory creation table */ +/// const PRIM_EXFUNC_TBL* wakeupExFuncTbl; /* The pointer to running extended function table */ +/// const PRIM_EXFUNC_TBL* downExFuncTbl; /* The pointer to end extended function table */ +/// EFrameworkunifiedStatus (*onInit)(HANDLE hApp); /* FrameworkunifiedOnInitialization callback function setting */ +/// EFrameworkunifiedStatus (*onDestory)(HANDLE hApp); /* FrameworkunifiedOnDestroy callback function setting */ +/// EFrameworkunifiedStatus (*onDebugDump)(HANDLE hApp); /* FrameworkunifiedOnDebugDump Callback function setting */ +/// EFrameworkunifiedStatus (*onTouch)(HANDLE hApp); /* TaskmanagerOnTouch callback function setting */ +/// EFrameworkunifiedStatus (*onLowMem)(HANDLE hApp); /* FrameworkunifiedOnLowMemory callback function setting */ +/// void* priv; /* User private data */ +/// }T_PRIM_PRM; +/// @endcode +/// \~english @retval INI_SUCCESS Normal end +/// \~english @retval INI_FALSE Abnormal end +/// \~english @par Preconditions: +/// - None +/// \~english @par Changes of the internal state: +/// - The internal state is not changed +/// \~english @par Causes of failures: +/// - The pointer to the parameter table of primary library is NULL [INI_FALSE] +/// - The pointer to the shared memory creation table inside the parameter table of primary library is NULL [INI_FALSE] +/// - The pointer to the running extended function table inside the parameter table of primary library is NULL [INI_FALSE] +/// - The pointer to the end extended function table inside the parameter table of primary library is NULL [INI_FALSE] +/// - The setting of FrameworkunifiedOnInitialization callback function inside the parameter table of primary library is NULL [INI_FALSE] +/// - The setting of FrameworkunifiedOnDestroy callback function inside the parameter table of primary library is NULL [INI_FALSE] +/// - The setting of FrameworkunifiedOnDebugDump callback function inside the parameter table of primary library is NULL [INI_FALSE] +/// - The setting of TaskmanagerOnTouch callback function inside the parameter table of primary library is NULL [INI_FALSE] +/// \~english @par Classification: +/// Public +/// \~english @par Type +/// Method only +/// \~english @par Detail: +/// This executes the main processing of primary library. Functions do not return until all of end processing of process is completed. \n +/// Normal end returns INI_SUCCESS and abnormal end does INI_FALSE. \n +/// User process must return this function's returned values as the returned values of main function and end main function. \n +/// \~english @see INI_Init +//////////////////////////////////////////////////////////////////////////////////// +int INI_Main(T_PRIM_PRM* p_prm,int argc,char* argv[]); + +///////////////////////////////////////////////////////////////////////////////////// +/// \ingroup INI_ExitStart +/// \~english @par Summary: +/// Starts the end processing of process. +/// \~english @param [in] rsv +/// void* - The pointer to reservation parameters (NULL must be appointed) +/// \~english @retval None +/// \~english @par Preconditions: +/// - None +/// \~english @par Changes 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: +/// Collects the resource which primary library got, does the end processing equal to local_step=all and end process. \n +/// (At the end processing in abnormality, process must be ended by not this function but exit(),_exit() function immediately) \n +/// When this API is called after this API is already called, do nothing to process. +/// \~english @par Supplemtent: +/// local_step is the information defined in default_wakeup.xml/default_shutdown.xml as the definition of running order / end order. \n +/// local_step defined in default_shutdown.xml has the following types. +/// - 1-9 : Designates local phase numbers (the phase numbers of end processing) +/// - last : This designates local phase numbers to be last. When there is the local phase processing not to be executed, this executes all. +/// - all : The same as last. +/// \~english @see INI_Main, INI_Init, INI_ExitDone +//////////////////////////////////////////////////////////////////////////////////// +void INI_ExitStart(void* rsv); // Termination process start + +///////////////////////////////////////////////////////////////////////////////////// +/// \ingroup INI_ExitDone +/// \~english @par Summary: +/// Notifies the completion of process end processing. +/// \~english @param [in] status +/// int - Unused (This is for future extension. 0 must be designated.) +/// \~english @retval None +/// \~english @par Preconditions: +/// - None +/// \~english @par Changes 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: +/// Notifies the completion of service end processing to TaskManager. \n +/// TaskManager ends the corresponding service by this notification. At the time, this callbacks FrameworkunifiedOnDestroy(). \n +/// \~english @see INI_Main, INI_Init, INI_ExitStart +//////////////////////////////////////////////////////////////////////////////////// +void INI_ExitDone(int status); // Termination process completed + +///////////////////////////////////////////////////////////////////////////////////// +/// \ingroup INI_GetPrivate +/// \~english @par Summary: +/// Gets private data. +/// \~english @param None +/// \~english @retval void* The pointer to user private data +/// \~english @par Preconditions: +/// - INI_Main or INI_Init must be called and user private data must be set. +/// \~english @par Changes 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: +/// Gets the private data designated at INI_Main/INI_Init from the inside of the context management information of the process inside primary library and returns it. +/// \~english @see INI_Main, INI_Init +//////////////////////////////////////////////////////////////////////////////////// +void* INI_GetPrivate(); + +///////////////////////////////////////////////////////////////////////////////////// +/// \ingroup INI_GetHandle +/// \~english @par Summary: +/// Gets the application handle of NSFW. +/// \~english @param None +/// \~english @retval void*(HANDLE) The application handle of NSFW +/// \~english @par Preconditions: +/// - INI_Main or INI_Init must be called and the application handle of NSFW must be generated. +/// \~english @par Changes 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: +/// Gets the application handle of NSFW from the inside of the context management information of the process inside primary library and returns it. +/// \~english @see INI_Main, INI_Init +//////////////////////////////////////////////////////////////////////////////////// +void* INI_GetHandle(); + +///////////////////////////////////////////////////////////////////////////////////// +/// \ingroup INI_SetMonitorTimeout +/// \~english @par Summary: +/// Requests the change for abnormality monitoring timeout time to Task Manager. \n +/// (This is used when main thread is not implemented at service side) +/// \~english @param [in] timeout +/// uint32_t - Abnormality monitoring timeout time (sec)(When 0 is designated, the service must be out of abnormality monitoring object.) +/// \~english @retval INI_SUCCESS Succeeded +/// \~english @par Preconditions: +/// - Main thread must be run at INI_Main() +/// \~english @par Changes 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: +/// Sets the abnormality monitoring timeout time designated by parameters inside the context management information of the process inside primary library and returns returned values and INI_SUCCESS. \n +/// Set timeout time becomes valid after the event waiting at the loop of main thread and this requests the change for service abnormality monitoring timeout time to TaskManager. In other words, this API can be used after running extended function Callback. \n +/// When process does not return to main thread past the timeout time designated by this function, TaskManager ends the service forcibly. When this function is not called, TaskManager treats the timeout of monitoring time as 50 seconds. +/// \~english @see INI_Main +//////////////////////////////////////////////////////////////////////////////////// +int32_t INI_SetMonitorTimeout(uint32_t timeout); + +// Event completion notification +///////////////////////////////////////////////////////////////////////////////////// +/// \ingroup INI_StepForkComp +/// \~english @par Summary: +/// Notifies the completion of running event to TaskManager. +/// \~english @param [in] compId +/// uint64_t - The comparison ID for phase running (Designates INI_INITCOMP_[a-zA-Z_]+ to define at INI_API.hpp) +/// \~english @par +/// The ID descripted at INI_API.hpp +/// \~english @code +/// - INI_INITCOMP_NONE: None +/// - INI_INITCOMP_ON_START: For ON Start +/// - INI_INITCOMP_NVM_ACCESS: For NVM access +/// @endcode +/// \~english @retval INI_SUCCESS Succeeded +/// \~english @retval INI_FALSE Failed +/// \~english @par Preconditions: +/// - INI_Main or INI_Init must be called. +/// \~english @par Changes of the internal state: +/// - The internal state is not changed +/// \~english @par Causes of failures: +/// - The sending of the completion notification of running event to TaskManager failed [INI_FALSE] +/// \~english @par Classification: +/// Public +/// \~english @par Type +/// Sync only +/// \~english @par Detail: +/// Sends the comparison ID for phase running as the completion notification of running event to TaskManager. If it succeeded, returns INI_SUCCESS and if it failed, does INI_FALSE. \n +/// TaskManager holds which completion notification of running event is notified and can add it to the transition conditions to next phase at phase running. \n +/// The way to add at TaskManager side depends on the definition of next_trans_condition element described in default_wakeup.xml as the definition of running order. +/// \~english @par Supplement: +/// next_trans_condition is the element to designate transition conditions to next phase. The transition to next phase is done when the following two conditions are met. \n +/// When the description of next_trans_condition element is omitted, transition is done only by condition 1. \n +/// 1. All of the phase running request processing set by request element is completed. (The phase running request processing is executed by primary library asynchronously) \n +/// 2. The completion notification of the event designated by next_trans_condition element is completed. \n +/// Waiting conditions for event completion notification INI_INITCOMP_[A-Z]+ stipulated at INI_API.hpp is set in cond property designated at next_trans_condition element. \n +/// AND condition can be set by being INI_INITCOMP_AAAA| INI_INITCOMP_BBBB when conditions are some. \n +/// Event completion notification can be issued by using INI_StepForkComp. +/// \~english @see INI_Main, INI_Init +//////////////////////////////////////////////////////////////////////////////////// +int32_t INI_StepForkComp(uint64_t compId); + +// Event completion notification +///////////////////////////////////////////////////////////////////////////////////// +/// \ingroup INI_AccOffComp +/// \~english @par Summary: +/// Notifies end event completion notification to TaskManager. +/// \~english @param [in] compId +/// uint64_t - The comparison ID for phase running (Designates INI_TERMCOMP_[a-zA-Z_]+ defined at INI_API.hpp) +/// \~english @par +/// The ID described at INI_API.hpp +/// \~english @code +/// - INI_TERMCOMP_NONE : None +/// - INI_TERMCOMP_ACTIVITYMGR : For ActivityManager end +/// - INI_TERMCOMP_RESIDENT : For resident service end +/// - INI_TERMCOMP_TRANSIENT : For non-resident service end +/// @endcode +/// \~english @retval INI_SUCCESS Succeeded +/// \~english @retval INI_FALSE Failed +/// \~english @par Preconditions: +/// - INI_Main or INI_Init must be called +/// \~english @par Changes of the internal state: +/// - The internal state is not changed +/// \~english @par Causes of failures: +/// - The sending of the completion notification of end event to TaskManager failed [INI_FALSE] +/// \~english @par Classification: +/// Public +/// \~english @par Type +/// Sync only +/// \~english @par Detail: +/// Sends the comparison ID for phase running as the completion notification of end event to TaskManager. If it succeeded, returns INI_SUCCESS and if it failed, return INI_FALSE. \n +/// TaskManager holds which completion notification of end event is notified and can add it to the transition conditions to next phase at phase end. \n +/// The way to add at TaskManager side depends on the definition of next_trans_condition element described in default_shutdown.xml as the definition of end order. +/// \~english @par Supplement: +/// next_trans_condition is the element to designate transition conditions to next phase. The transition to next phase is done when the following two conditions are met. \n +/// When the description of next_trans_condition element is omitted, transition is done only by condition 1. \n +/// 1. All of the phase end request processing set by request element is completed. (The phase end request processing is executed by primary library asynchronously) \n +/// 2. The completion notification of the event designated by next_trans_condition element is completed. Waiting conditions for event completion notification INI_INITCOMP_[A-Z]+ stipulated at INI_API.hpp is set in cond property designated at next_trans_condition element. \n +/// AND condition can be set by being INI_INITCOMP_AAAA| INI_INITCOMP_BBBB when conditions are some. \n +/// Event completion notification can be issued by using INI_ AccOffComp. +/// \~english @see INI_Main, INI_Init +//////////////////////////////////////////////////////////////////////////////////// +int32_t INI_AccOffComp(uint64_t compId); + +// Get boot info +///////////////////////////////////////////////////////////////////////////////////// +/// \ingroup INI_GetBootInfo +// \~english @par Summary: +/// Gets boot information. +/// \~english @param [in] info +/// T_SS_SM_START_DataStructType * - The pointer to boot information structure +/// \~english @par +/// T_SS_SM_START_DataStructType structure +/// \~english @code +/// typedef struct T_SS_SM_START_DataStruct{ +/// EPWR_WAKEUP_FACTOR_TYPE startupReason; /* Startup reason */ +/// BOOL isUserModeOn; /* User mode ON/OFF */ +/// ESMDataResetModeInfo dataResetMode; /* Data reset mode */ +/// EPWR_SC_SECURITY_STATUS securityStatus; /* Security state */ +/// EPWR_SC_WAKEUP_TYPE wakeupType; /* Battery disconnection state */ +/// ESMDramBackupStatus dramBackupStatus; /* Backup memory area state */ +/// ESMResetStatus resetStatus; /* Reset state */ +/// UI_32 resetCount; /* Abnormal reboot number */ +/// } T_SS_SM_START_DataStructType; +/// +/// Startup reason type: +/// - epswfIGN_ACC : Ignition ACC (Currently, Fixed) +/// User mode ON/OFF: +/// - TRUE : User mode ON (Currently, Fixed) +/// Data reset mode: +/// - e_SS_SM_DATA_RESET_NONE: Not-initialized +/// - e_SS_SM_DATA_RESET_USER: User data initialization +/// - e_SS_SM_DATA_RESET_FACTORY: Factory initialization +/// Security state: +/// - epsssUNLOCK : Unlock state +/// - epsssLOCK : Lock state +/// Battery disconnection state: +/// - epsstWARMSTART : Battery disconnection does not occur +/// - epsstCOLDSTART : Battery disconnection occurs +/// Backup memory area state: +/// - e_SS_SM_DRAM_BACKUP_OK: Backup OK of Backup memory area +/// - e_SS_SM_DRAM_BACKUP_NG: Backup NG of Backup memory area +/// Reset state: +/// - e_SS_SM_RESET_STATUS_UNSET: Information unsetting(Not decided yet) +/// - e_SS_SM_RESET_STATUS_NONE : Normal +/// - e_SS_SM_RESET_STATUS_NG : Abnormality occurred (Abnormal RESET or booting after service abnormal end) +/// - e_SS_SM_RESET_STATUS_IMMEDIATE : Immediate RESET occurred +/// @endcode +/// \~english @retval INI_SUCCESS Succeeded +/// \~english @retval INI_FALSE Failed +/// \~english @par Preconditions: +/// - INI_Main or INI_Init must be called. (%Process running must be completed) +/// \~english @par Changes of the internal state: +/// - The internal state is not changed +/// \~english @par Causes of failures: +/// - The pointer to boot information structure designated at parameters is NULL [INI_FALSE] +/// - Startup reason type inside the context management information of the process inside primary library is wrong (%Process running is not completed) [INI_FALSE] +/// \~english @par Classification: +/// Public +/// \~english @par Type +/// Sync only +/// \~english @par Detail: +/// Gets boot information which is managed inside the context management information of the process inside primary library. +/// If it succeeded, returns INI_SUCCESS and if it failed, does INI_FALSE. \n +/// This sets valid values as info values in FrameworkunifiedOnStart of TaskManager. In other words, this sets valid values after running ActivityManager. +/// \~english @see INI_Main, INI_Init +//////////////////////////////////////////////////////////////////////////////////// +int32_t INI_GetBootInfo(T_SS_SM_START_DataStructType *info); + +///////////////////////////////////////////////////////////////////////////////////// +/// \ingroup INI_GetExtBootInfo +/// \~english @par Summary: +/// Gets boot extended information. +/// \~english @param [in] info +/// T_SS_SM_START_ExtDataStructType * - The pointer to boot extended information structure +/// \~english @par +/// T_SS_SM_START_ExtDataStructType structure +/// \~english @code +/// #define SS_SM_START_EXT_INFO_SIZE 64 +/// #define SS_SM_START_EXT_BODY_SIZE ( sizeof(BOOL) +/// + sizeof(EMRelaunchStatus) +/// + sizeof(BOOL) +/// + sizeof(BOOL) +/// ) +/// define SS_SM_START_EXT_RSV_SIZE SS_SM_START_EXT_INFO_SIZE +/// - SS_SM_START_EXT_BODY_SIZE +/// typedef struct { +/// BOOL isProgUpdated; /* Program update information */ +/// EMRelaunchStatus relaunchStatus; /* Own-service Relaunch state */ +/// BOOL isMapUpdated; /* Map update information */ +/// BOOL isMapDiffUpdated; /* Map difference update information */ +/// uint8_t reserved[SS_SM_START_EXT_RSV_SIZE]; /* Reserve area */ +/// } T_SS_SM_START_ExtDataStructType; +/// +/// Program update information +/// - TRUE : Program update +/// - FALSE : No Program update +/// Own-service Relaunch state: +/// - e_SS_SM_RELAUNCH_STATUS_NONE : Relaunch does not occur (Initial boot) +/// - e_SS_SM_RELAUNCH_STATUS_SAFE : Normal Relaunch +/// - e_SS_SM_RELAUNCH_STATUS_ERR : Abnormal Relaunch +/// Map update information: +/// - TRUE : Map update +/// - FALSE : No Map update +/// Map difference update information +/// - TRUE : Map difference update +/// - FALSE : No Map difference update +/// @endcode +/// \~english @retval INI_SUCCESS Succeeded +/// \~english @retval INI_FALSE Failed +/// \~english @par Preconditions: +/// - INI_Main or INI_Init must be called. (%Process running must be completed.) +/// \~english @par Changes of the internal state: +/// - The internal state is not changed +/// \~english @par Causes of failures: +/// - The pointer to boot information structure designated at parameters is NULL [INI_FALSE] +/// - Startup reason type inside the context management information of the process inside primary library is wrong (%Process running is not completed) [INI_FALSE] +/// \~english @par Classification: +/// Public +/// \~english @par Type +/// Sync only +/// \~english @par Detail: +/// Gets boot extended information which is managed inside the context management information of the process inside primary library. +/// If it succeeded, returns INI_SUCCESS and if it failed, does INI_FALSE \n +/// This sets valid values as info values in FrameworkunifiedOnStart of TaskManager. In other words, this sets valid values after running ActivityManager. +/// Because TaskManager does not have Relaunch function, always sets e_SS_SM_RELAUNCH_STATUS_NONE in relaunchStatus. +/// \~english @see INI_Main, INI_Init +//////////////////////////////////////////////////////////////////////////////////// +int32_t INI_GetExtBootInfo(T_SS_SM_START_ExtDataStructType *info); + +//withoutMainLoop +///////////////////////////////////////////////////////////////////////////////////// +/// \ingroup INI_Init +/// \~english @par Summary: +/// Initializes primary library. \n +/// (This is used when implementing main thread at service side) +/// \~english @param [in] p_prm +/// T_PRIM_PRM - The pointer to parameter table of primary library +/// \~english @param [in] argc +/// int - The number of command parameters (The parameters passed to main functions must be set without processing) +/// \~english @param [in] argv +/// char* - Command parameters (The parameters passed to main functions must be set without processing) +/// \~english @param [out] fdNum +/// int * - The number of element stored in fdlist (INI_FD_MAX:3) +/// \~english @param [out] fdlist[INI_FD_MAX] +/// int - The array of FD (File Descriptor) for event reception which primary library waits +/// \~english @par +/// - Shared memory creation table \n +/// In process running, register the shared memory to create. \n +/// This creates the shared memory to be registered in process running and releases it in process end. \n +/// This must terminate by adding {"\0"} into member shmName of table termination. \n +/// It is able to access to the shared memory to have been created by shm_open. \n +/// \~english @code +/// typedef struct { +/// char shmName[32]; /* Shared memory name */ +/// uint32_t size; /* Shared memory size (BYTE) */ +/// }PRIM_SHAREDATA_TBL; +/// @endcode +/// \~english @par +/// - Running extended function table / End extended function table \n +/// Registers callback functions to be called in process start and exit. \n +/// This must terminate by adding NULL into member func of table termination. \n +/// Parameters prm of callback functions are User private information and the pointer designated by prm is passed as input parameters [in]. \n +/// Local phase numbers callback func by the designated phase numbers. \n +/// \~english @code +/// typedef struct { +/// void (* func)( void* prm); /* Callback functions for function extension */ +/// void* prm; /* The pointer to the parameters of Callback function func */ +/// uint8_t localStep; /* Local phase numbers */ +/// uint8_t rsv[3]; /* Reserve for alignment */ +/// }PRIM_EXFUNC_TBL; +/// @endcode +/// \~english @par +/// - %Parameter table of primary library \n +/// For FrameworkunifiedOnInitialization/FrameworkunifiedOnDestroy/FrameworkunifiedOnDebugDump/TaskmanagerOnTouch/FrameworkunifiedOnLowMemory, check the corresponding API specification. \n +/// It is able to get User private data by INI_GetPrivate(). \n +/// \~english @code +/// typedef struct _T_PRIM_PRM{ +/// PCSTR name; /* Application name */ +/// const PRIM_SHAREDATA_TBL* shmTbl; /* The pointer to shared memory creation table */ +/// const PRIM_EXFUNC_TBL* wakeupExFuncTbl; /* The pointer to running extended function table */ +/// const PRIM_EXFUNC_TBL* downExFuncTbl; /* The pointer to end extended function table */ +/// EFrameworkunifiedStatus (*onInit)(HANDLE hApp); /* FrameworkunifiedOnInitialization callback function setting */ +/// EFrameworkunifiedStatus (*onDestory)(HANDLE hApp); /* FrameworkunifiedOnDestroy callback function setting */ +/// EFrameworkunifiedStatus (*onDebugDump)(HANDLE hApp); /* FrameworkunifiedOnDebugDump Callback function setting */ +/// EFrameworkunifiedStatus (*onTouch)(HANDLE hApp); /* TaskmanagerOnTouch callback function setting */ +/// EFrameworkunifiedStatus (*onLowMem)(HANDLE hApp); /* FrameworkunifiedOnLowMemory callback function setting */ +/// void* priv; /* User private data */ +/// }T_PRIM_PRM; +/// @endcode +/// \~english @retval INI_SUCCESS Succeeded +/// \~english @retval INI_FALSE Failed +/// \~english @par Preconditions: +/// - None +/// \~english @par Changes of the internal state: +/// - The internal state is not changed +/// \~english @par Causes of failures: +/// - The pointer to the parameter table of primary library is NULL [INI_FALSE] +/// - The pointer to the shared memory creation table inside the parameter table of primary library is NULL [INI_FALSE] +/// - The pointer to the running extended function table inside the parameter table of primary library is NULL [INI_FALSE] +/// - The pointer to the end extended function table inside the parameter table of primary library is NULL [INI_FALSE] +/// - The setting of FrameworkunifiedOnInitialization callback function inside the parameter table of primary library is NULL [INI_FALSE] +/// - The setting of FrameworkunifiedOnDestroy callback function inside the parameter table of primary library is NULL [INI_FALSE] +/// - The setting of FrameworkunifiedOnDebugDump callback function inside the parameter table of primary library is NULL [INI_FALSE] +/// - The setting of TaskmanagerOnTouch callback function inside the parameter table of primary library is NULL [INI_FALSE] +/// \~english @par Classification: +/// Public +/// \~english @par Type +/// Sync only +/// \~english @par Detail: +/// Initializes primary thread. If it succeeded, returns INI_SUCCESS and if it failed, does INI_FALSE. \n +/// When implementing main thread at service, this function must be called in running main thread. \n +/// Waits fd of fdlist gotten by functions by select and when there is change in fd, service must execute event handler of primary by calling INI_Handler(). +/// \~english @see INI_Main +//////////////////////////////////////////////////////////////////////////////////// +int32_t INI_Init(T_PRIM_PRM* p_prm,int argc ,char* argv[],int *fdNum,int fdlist[INI_FD_MAX]); + +///////////////////////////////////////////////////////////////////////////////////// +/// \ingroup INI_Handler +/// \~english @par Summary: +/// Processes the reception event of primary library. \n +/// (This is used when implementing main thread at service side) +/// \~english @param [in] p_fds +/// fd_set* - fd set varied and detected by select() +/// \~english @retval TRUE Service running (Continuing) +/// \~english @retval FALSE The process end processing of primary library is completed +/// \~english @par Preconditions: +/// - Main thread must be run at INI_Init() +/// \~english @par Changes of the internal state: +/// - The internal state is not changed +/// \~english @par Causes of failures: +/// - Access is not from main thread context [FALSE] +/// \~english @par Classification: +/// Public +/// \~english @par Type +/// Sync only +/// \~english @par Detail: +/// When FD which primary library should process in fd set designated by p_fds is included, processes event processing of primary library. \n +/// When implementing main thread by service, it is necessary to execute the event reception processing of primary library by this function. \n +/// Returns TRUE during service running and does FALSE when the process end processing of primary library was completed. When FALSE is returned, service must call +/// INI_Term() and end itself. +/// \~english @see INI_Init +//////////////////////////////////////////////////////////////////////////////////// +BOOL INI_Handler(fd_set* p_fds); + +///////////////////////////////////////////////////////////////////////////////////// +/// \ingroup INI_Term +/// \~english @par Summary: +/// Releases the resource of primary library. \n +/// (This is used when implementing main thread at service side) +/// \~english @param None +/// \~english @retval None +/// \~english @par Preconditions: +/// - Main thread must be run at INI_Init() +/// \~english @par Changes 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: +/// Releases the resource of primary library. \n +/// When implementing main thread at service, this function must release the resource of primary library in service end. +/// \~english @see INI_Init, INI_Handler +//////////////////////////////////////////////////////////////////////////////////// +void INI_Term(void); + +///////////////////////////////////////////////////////////////////////////////////// +/// \ingroup INI_SetMonitorState +/// \~english @par Summary: +/// Sets abnormality monitoring state. \n +/// (This is used when implementing main thread at service side) +/// \~english @param [in] p_prm +/// T_PRIM_MONITOR_PRM - The pointer to the parameters structure for monitoring +/// \~english @par +/// T_PRIM_MONITOR_PRM structure +/// \~english @code +/// typedef struct { +/// BOOL bIsRun; /* Monitoring state (TRUE:RUN FALSE:SLEEP) */ +/// uint32_t timeout; /* Monitoring timeout time (sec) */ +/// }PRIM_SHAREDATA_TBL; +/// @endcode +/// \~english @retval INI_SUCCESS Succeeded +/// \~english @retval INI_FALSE Failed +/// \~english @par Preconditions: +/// - Main thread must be run at INI_ Init () +/// \~english @par Changes of the internal state: +/// - The internal state is not changed +/// \~english @par Causes of failures: +/// - The pointer(p_prm) to the parameters structure for monitoring designated by parameters is NULL [INI_FALSE] +/// \~english @par Classification: +/// Public +/// \~english @par Type +/// Sync only +/// \~english @par Detail: +/// Sets abnormality monitoring for TaskManager. If it succeeded, returns INI_SUCCESS and if it failed, does INI_FALSE \n +/// When bIsRun=FALSE is not set until time designated by timeout passes after setting bIsRun=TRUE, TaskManager decides that the service falls into abnormal state and ends forcibly. \n +/// When 0 is designated at monitoring timeout time(timeout), the service must be out of abnormality monitoring object. +/// When monitoring state (bIsRun) is FALSE, monitoring state becomes invalid. \n +/// This API can be used after running extended function CALLBACK. +/// \~english @see INI_Init +//////////////////////////////////////////////////////////////////////////////////// +int32_t INI_SetMonitorState(T_PRIM_MONITOR_PRM *p_prm); + + +void _INI_DEBUGDUMP(BOOL bIsNeedSvcName, PCSTR f_cFormat, ...); + +#define INI_DEBUGDUMP(args...) _INI_DEBUGDUMP(TRUE, ## args) +#define INI_DEBUGDUMP_RAW(args...) _INI_DEBUGDUMP(FALSE, ## args) + +// Callback functions +///////////////////////////////////////////////////////////////////////////////////// +/// \ingroup TaskmanagerOnTouch +/// \~english @par Summary: +/// Callback to notify process use +/// \~english @param [in] hApp +/// HANDLE - Application handle +/// \~english @retval eFrameworkunifiedStatusOK Succeeded +/// \~english @retval Other-than-eFrameworkunifiedStatusOK Failed (Error type depends on the implementation at user side) +/// \~english @par Preconditions: +/// - Must set inside running information structure in calling INI_Main or INI_Init +/// \~english @par Changes of the internal state: +/// - The internal state is not changed +/// \~english @par Causes of failures: +/// - Implementation specification of callback depends on the implementation (design) of an application. For this, error type on failure conditions must be considered at an application side. +/// \~english @par Detail: +/// Service is call backed just before using. \n +/// INI_ExitStart must not be issued for 30 seconds after service called this function. \n +/// Timeout must be implemented such as counting up by using interval timer so that INI_ExitStart is not issued by timeout after this API was called. \n +/// This function cannot call the API (TSKM_Xxxx) of TaskManager. (If this calls, deadlock occurs) +/// \~english @par Classification: +/// Public +/// \~english @see None +//////////////////////////////////////////////////////////////////////////////////// +EFrameworkunifiedStatus TaskmanagerOnTouch(HANDLE hApp); + +#ifdef __cplusplus +} +#endif + + +#endif //_INI_API_HPP_ + +/** @}*/ // end of TaskManager +/** @}*/ // end of SystemService +/** @}*/ // end of BaseSystem diff --git a/systemservice/task_manager/server/include/system_service/Primary_common.h b/systemservice/task_manager/server/include/system_service/Primary_common.h new file mode 100755 index 0000000..e0624bb --- /dev/null +++ b/systemservice/task_manager/server/include/system_service/Primary_common.h @@ -0,0 +1,148 @@ +/* + * @copyright Copyright (c) 2016-2020 TOYOTA MOTOR CORPORATION. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +/** + * @file Primary_common.h + * @brief \~english This file contains declaration of common enum and structures + */ +/** @addtogroup BaseSystem + * @{ + */ +/** @addtogroup system_service + * @ingroup BaseSystem + * @{ + */ +/** @addtogroup task_manager + * @ingroup system_service + * @{ + */ +#ifndef TASK_MANAGER_SERVER_INCLUDE_SYSTEM_SERVICE_PRIMARY_COMMON_H_ +#define TASK_MANAGER_SERVER_INCLUDE_SYSTEM_SERVICE_PRIMARY_COMMON_H_ + +#include +#include + +typedef unsigned int PRI_DWORD; // To eliminate the DWORD + +/* SRAM process type */ +#define SRAM_INIT (int)0 /* Initialization processing specification */ +#define SRAM_CHK (int)1 /* Range check processing specification */ +#define SRAM_MAPVER (int)2 /* Map Version change support designation */ +#define SRAM_MAPVER_CHK (int)3 /* Map Version change support + range checking specification */ +#define SRAM_SYSTEM_INIT (int)4 /* System initialization processing specification */ +#define SRAM_CONFIG_INIT (int)5 /* Reset setting */ + +/* Processing result */ +#define SRAM_CHK_OK (int)0 /* SRAM checking completed normally (no change) */ +#define SRAM_CHK_CHG (int)1 /* SRAM checking Successful completion value is changed (Including during initialization) */ +#define SRAM_CHK_NG (int)-1 /* SRAM checking error */ + +/* + Constant definition + * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ +#define PRIM_SHM_NAME_MAX 32 /* Maximum name size */ + +// Local stage number of the stage start request/end request from the TSKM +// In XML, it is set with a direct value of 1-9, but it is left because the legacy service refers to this definition +enum _PRIM_FORK_STEP { + PRIM_STEPFORK_FIRST = 1, /* First startup step */ + PRIM_STEPFORK_SECOND, /* 2nd startup step */ + PRIM_STEPFORK_THIRD, /* 3rd startup step */ + PRIM_STEPFORK_FOURTH, /* 4th startup step */ + PRIM_STEPFORK_FIFTH, /* 5th startup step */ + PRIM_STEPFORK_SIXTH, /* 6th startup step */ + PRIM_STEPFORK_SEVENTH, /* 7th startup step */ + PRIM_STEPFORK_EIGHTH, /* 8th startup step */ /* #GPF_10_018 */ + PRIM_STEPFORK_NINTH, /* 9th startup step */ /* #GPF_10_018 */ + PRIM_STEPFORK_TENTH, /* 10th startup step */ /* #GPF_10_018 */ + PRIM_STEPFORK_MAX /* Maximum number of Gradual startup steps */ /* Used for judgment when receiving gradual startup */ +}; + +enum _PRIM_ACCOFF_STEP { + PRIM_ACCOFF_FIRST = 1, /* First step */ + PRIM_ACCOFF_SECOND, /* 2nd step */ + PRIM_ACCOFF_THIRD, /* 3rd step */ + PRIM_ACCOFF_FOURTH, /* 4th step */ + PRIM_ACCOFF_FIFTH, /* 5th step */ + PRIM_ACCOFF_MAX /* Total number of ACC-OFF steps */ /* Used for judgment when receiving ACC-OFF instruction */ +}; + +/****************************************************************************** + * TAG : PRIM_SHAREDATA_TBL + * ABSTRACT : Shared data table + * NOTE : + ******************************************************************************/ +/* Structure of shared data table */ +typedef struct { + char shmName[PRIM_SHM_NAME_MAX]; /* Shared data name */ + int32_t size; /* Shared data size */ +} PRIM_SHAREDATA_TBL; + +/****************************************************************************** + * TAG : PRIM_FORK_TBL + * ABSTRACT : Startup process table + * NOTE : + ******************************************************************************/ +typedef struct { + PRI_DWORD (*threadFunc)(void* prm); /* Thread function */ + void* prm; /* Thread startup parameters */ + uint32_t priority; /* Thread priority */ + uint16_t pno; /* Thuread number */ + uint8_t rsv; /* Reserved field */ + uint8_t wakeLocalStep; /* Startup step */ + // The following is valid only when useLegacy = FALSE + char threadName[16]; /* Thread name */ + char downLocalStep; /* When the termination step is 0, termination notification is not issued */ + void* primaryLocal; /* Local area for libPrimary (cannot be changed) */ +} PRIM_FORK_TBL; + +/****************************************************************************** + * TAG : PRIM_EXFUNC_TBL + * ABSTRACT : Feature extension table + ******************************************************************************/ +typedef struct { + void (*func)(void* prm); /* Feature extension function */ + void* prm; /* parameters */ + uint8_t localStep; /* Startup step */ + uint8_t rsv[3]; /* Reserved */ +} PRIM_EXFUNC_TBL; + +/****************************************************************************** + * TAG : PRIM_BACKUPCHK_TBL + * ABSTRACT : Function table for check backup data + ******************************************************************************/ +typedef struct { + int32_t (*func)(int32_t kind); /* Feature Extension Functions */ +} PRIM_BACKUPCHK_TBL; + +/****************************************************************************** + * TAG : PRIM_ACCOFF_TBL + * ABSTRACT : ACC-OFF process table + ******************************************************************************/ +typedef struct { + uint32_t localStep; /* ACC-OFF process step */ + uint16_t pno; /* PNO of Notification destination */ + uint8_t rsv[2]; +} PRIM_ACCOFF_TBL; + +#endif // TASK_MANAGER_SERVER_INCLUDE_SYSTEM_SERVICE_PRIMARY_COMMON_H_ +/* + * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * + End of File : Primary_common.h + * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * + */ +/** @}*/ +/** @}*/ +/** @}*/ diff --git a/systemservice/task_manager/server/include/system_service/sysup.h b/systemservice/task_manager/server/include/system_service/sysup.h new file mode 100755 index 0000000..ef930a4 --- /dev/null +++ b/systemservice/task_manager/server/include/system_service/sysup.h @@ -0,0 +1,41 @@ +/* + * @copyright Copyright (c) 2016-2020 TOYOTA MOTOR CORPORATION. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +/** + * @file sysup.h + * @brief \~english This file contains declaration of system status(SYS_RESET, SYS_ONLY_RESET) + */ +/** @addtogroup BaseSystem + * @{ + */ +/** @addtogroup system_service + * @ingroup BaseSystem + * @{ + */ +/** @addtogroup task_manager + * @ingroup system_service + * @{ + */ +#ifndef TASK_MANAGER_SERVER_INCLUDE_SYSTEM_SERVICE_SYSUP_H_ +#define TASK_MANAGER_SERVER_INCLUDE_SYSTEM_SERVICE_SYSUP_H_ + +#define SYS_RESET (int32)1 /* Resetting */ +#define SYS_ONLY_RESET (int)2 /* Reset only */ + +#endif // TASK_MANAGER_SERVER_INCLUDE_SYSTEM_SERVICE_SYSUP_H_ +/** @}*/ +/** @}*/ +/** @}*/ + diff --git a/systemservice/task_manager/server/include/system_service/sysup_from.h b/systemservice/task_manager/server/include/system_service/sysup_from.h new file mode 100755 index 0000000..be7e0fe --- /dev/null +++ b/systemservice/task_manager/server/include/system_service/sysup_from.h @@ -0,0 +1,41 @@ +/* + * @copyright Copyright (c) 2016-2020 TOYOTA MOTOR CORPORATION. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef TASK_MANAGER_SERVER_INCLUDE_SYSTEM_SERVICE_SYSUP_FROM_H_ +#define TASK_MANAGER_SERVER_INCLUDE_SYSTEM_SERVICE_SYSUP_FROM_H_ + +/** + * @file sysup_from.h + * @brief \~english empty file + */ +/** @addtogroup BaseSystem + * @{ + */ +/** @addtogroup system_service + * @ingroup BaseSystem + * @{ + */ +/** @addtogroup task_manager + * @ingroup system_service + * @{ + */ +// Deleted the definitions in the file because they are not used. +// Left them for legacy sources that you include. +/** @}*/ +/** @}*/ +/** @}*/ + +#endif // TASK_MANAGER_SERVER_INCLUDE_SYSTEM_SERVICE_SYSUP_FROM_H_ diff --git a/systemservice/task_manager/server/include/system_service/task_manager.h b/systemservice/task_manager/server/include/system_service/task_manager.h new file mode 100755 index 0000000..82d23fb --- /dev/null +++ b/systemservice/task_manager/server/include/system_service/task_manager.h @@ -0,0 +1,54 @@ +/* + * @copyright Copyright (c) 2017-2020 TOYOTA MOTOR CORPORATION. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +/** + * @file task_manager.h + * @brief \~english include all task_manager_library head files + */ +/** @addtogroup BaseSystem + * @{ + */ +/** @addtogroup system_service + * @ingroup BaseSystem + * @{ + */ +/** @addtogroup task_manager + * @ingroup system_service + * @{ + */ +#ifndef TASK_MANAGER_SERVER_INCLUDE_SYSTEM_SERVICE_TASK_MANAGER_H_ +#define TASK_MANAGER_SERVER_INCLUDE_SYSTEM_SERVICE_TASK_MANAGER_H_ + +#include "system_service/INI_API.h" +#include "system_service/INI_API.hpp" +#include "system_service/Primary_common.h" +#include "system_service/sysup_from.h" +#include "system_service/sysup.h" +#include "system_service/tskm_svc.h" +#include "system_service/tskm_type.h" +#include "system_service/tskm.h" +#include "system_service/tskm_local_type.h" +#include "system_service/tskm_xml_data.h" +#include "system_service/tskm_svcid.h" +#include "system_service/task_manager_libtskmcfg.h" +#include "system_service/tskm_data_init.h" +#include "system_service/task_manager_libss_data_init.h" + + + +#endif // TASK_MANAGER_SERVER_INCLUDE_SYSTEM_SERVICE_TASK_MANAGER_H_ +/** @}*/ +/** @}*/ +/** @}*/ diff --git a/systemservice/task_manager/server/include/system_service/tskm.h b/systemservice/task_manager/server/include/system_service/tskm.h new file mode 100755 index 0000000..1a2f962 --- /dev/null +++ b/systemservice/task_manager/server/include/system_service/tskm.h @@ -0,0 +1,413 @@ +/* + * @copyright Copyright (c) 2016-2020 TOYOTA MOTOR CORPORATION. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * @file tskm.h + * @brief \~english This file contains primary API of task manager + */ + + +/** @addtogroup BaseSystem + * @{ + */ +/** @addtogroup system_service + * @ingroup BaseSystem + * @{ + */ +/** @addtogroup task_manager + * @ingroup system_service + * @{ + */ + +#ifndef TASK_MANAGER_SERVER_INCLUDE_SYSTEM_SERVICE_TSKM_H_ +#define TASK_MANAGER_SERVER_INCLUDE_SYSTEM_SERVICE_TSKM_H_ + + +#include +#include "system_service/tskm_type.h" + + +#ifdef __cplusplus +extern "C" { +#endif + +#define TSKM_ID RPC_ID +///////////////////////////////////////////////////////////////////////////////////// +/// \ingroup TSKM_Init +/// \~english @par Summary: +/// Creates the resource to communicate with Task_Manager. +/// \~english @param [out] *pID +/// UINT32 - Unique ID of the automatically allocated program +/// \~english @retval None +/// \~english @par Preconditions: +/// - None +/// \~english @par Changes 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: +/// Creates the resource to communicate with Task_Manager. \n +/// It is necessary to call this before using the APIs of TSKM_xxxx defined after this. \n +/// It is necessary to call this by the thread. \n +/// \~english @see TSKM_End +//////////////////////////////////////////////////////////////////////////////////// +#define TSKM_Init(p_tskmId) RPC_START_CLIENT(p_tskmId) +///////////////////////////////////////////////////////////////////////////////////// +/// \ingroup TSKM_End +/// \~english @par Summary: +/// Releases the resource created at TSKM_Init. +/// \~english @param [in] ID +/// UINT32 - ID gotten at TSKM_Init() +/// \~english @retval None +/// \~english @par Preconditions: +/// - TSKM_Init must be used and initialized +/// \~english @par Changes of the internal stat: +/// - The internal state is not changed +/// \~english @par Causes of failures: +/// None +/// \~english @par Classification: +/// Public +/// \~english @par Type +/// Sync only +/// \~english @par Detail: +/// Releases the resource created at TSKM_Init. +/// \~english @see TSKM_Init +//////////////////////////////////////////////////////////////////////////////////// +#define TSKM_End(tskmId) RPC_end(tskmId) + +///////////////////////////////////////////////////////////////////////////////////// +/// \ingroup TSKM_SvcCtl +// \~english @par Summary: +/// Run the control for service. +/// \~english @param [in] svcid +/// TSKM_SVCID_t - Service ID +/// \~english @param [in] ctl +/// TSKM_SVC_CTL_t* - Command +/// \~english @code +/// typedef struct{ +/// TSKM_SVC_CMD_t cmd; +/// } TSKM_SVC_CTL_t; +/// @endcode +/// \~english @retval TSKM_E_OK Succeeded +/// \~english @retval TSKM_E_PAR %Parameter error +/// \~english @retval TSKM_E_STATE State error +/// \~english @retval TSKM_E_NG Error +/// \~english @par Preconditions: +/// - TSKM_Init must be used and initialized +/// \~english @par Changes of the internal state: +/// - The internal state is not changed +/// \~english @par Causes of failures: +/// - Parameters ctl is NULL [TSKM_E_PAR] +/// - Service context is not found [TSKM_E_PAR] +/// - Before FrameworkunifiedOnStart of Task_Manager is called [TSKM_E_STATE] +/// - It is prohibited to run designated service [TSKM_E_STATE] +/// - Message sending failed [TSKM_E_RETRY] +/// - When the specified service executes the start prohibition except during +/// the stop or start prohibition status. [TSKM_E_STATE] +/// - Maximum numbers to register running reservation service are exceeded [TSKM_E_STATE] +/// - Anything except for the commands specified as parameters is designated [TSKM_E_PAR] +/// - Writing in files of running reservation information failed [TSKM_E_NG] +/// \~english @par Classification: +/// Public +/// \~english @par Type +/// Sync only +/// \~english @par Detail: +/// - TSKM_SVC_CMD_EXEC\n +/// Designated service runs. \n +/// When designated service already runs, this returns TSKM_E_OK without processing service running. \n +/// Running equal to local_step=all of request element is done. \n +/// When designated service designates the service that running is prohibited by +/// TSKM_SVC_CMD_DISABLE, this returns TSKM_E_STATE. \n +/// This guarantees that service running finished in API succeeding. \n +/// - TSKM_SVC_CMD_DISABLE\n +/// This prohibits to run the designated service. \n +/// At the prohibited service to run already, this returns TSKM_E_OK without doing anything. \n +/// When this API uses the service to be run already, this returns TSKM_E_STATE. \n +/// By this, at resident service, it is necessary to call this before running corresponding service. \n +/// About the prohibited service, this doesn't decide the wait condition of event completion notice +/// which service running, phase startup, phase end request, corresponding service control. \n +/// This command is prepared in consideration of changing the service to run in response to +/// with or without extended BOX and device configuration. \n +/// Initial values are running permission. \n +/// - TSKM_SVC_CMD_ENABLE\n +/// This permits to run the service to be set as running prohibition. \n +/// At running permission service, this returns TSKM_E_OK without doing anything. \n +/// - TSKM_SVC_RESERVE\n +/// This does the running reservation of non-resident service. \n +/// In next running, designated service runs automatically after finishing in running resident service. \n +/// Once this runs automatically, this forgets reservation information. \n +/// Maximum numbers of service able to do running reservation is the values of TSKM_SVC_RESERVE_MAX. \n +/// When this reserves over maximum numbers, this returns TSKM_E_STATE. \n +/// When backup RAM is invalid in running, this does not run automatically and +/// discards reservation information. \n +/// \~english @see None +//////////////////////////////////////////////////////////////////////////////////// +TSKM_ERR_t TSKM_SvcCtl(TSKM_SVCID_t svcId, const TSKM_SVC_CTL_t* ctl); +///////////////////////////////////////////////////////////////////////////////////// +/// \ingroup TSKM_SvcGetInfo +// \~english @par Summary: +/// Gets the information of designated service. +/// \~english @param [in] svcid +/// TSKM_SVCID_t - Service ID +/// \~english @param [out] svcInfo +/// TSKM_SVC_INFO_t* - Service information +/// \~english @code +/// typedef struct { +/// TSKM_SVCID_t svcId; +/// TSKM_BOOL_t isExecDisable; +/// } TSKM_SVC_INFO_t; +/// svcId : Service ID +/// isExecDisable : Service running prohibition state +/// TSKM_TRUE : Running prohibition +/// TSKM_FALSE : Running permission +/// @endcode +/// \~english @retval TSKM_E_OK Succeeded +/// \~english @retval TSKM_E_PAR %Parameter error +/// \~english @par Preconditions: +/// - TSKM_Init must be used and initialized +/// \~english @par Changes of the internal state: +/// - The internal state is not changed +/// \~english @par Causes of failures: +/// - Service context is not found [TSKM_E_PAR] +/// \~english @par Classification: +/// Public +/// \~english @par Type +/// Sync only +/// \~english @par Detail: +/// Gets the information of designated service. +/// \~english @see None +//////////////////////////////////////////////////////////////////////////////////// +TSKM_ERR_t TSKM_SvcGetInfo(TSKM_SVCID_t svcId, TSKM_SVC_INFO_t* svcInfo); +///////////////////////////////////////////////////////////////////////////////////// +/// \ingroup TSKM_ErrorReboot +/// \~english @par Summary: +/// Let system do abnormal reboot. +/// \~english @param [in] p_info +/// TSKM_ERROR_REBOOT_t* - REBOOT information +/// \~english @code +/// typedef struct { +/// TSKM_ERROR_REBOOT_TYPE_t type; +/// TSKM_LOGGING_ INFO_t log; +/// } TSKM_ERROR_REBOOT_t; +/// type +/// TSKM_ERROR_REBOOT_NORMAL : Abnormal detection +/// log : Log saving information +/// typedef struct { +/// char messageStr[TSKM_LOGGING_MSG_STR_SIZE]; +/// } TSKM_LOGGING_INFO_ t; +/// messageStr : Abnormal message character string +/// @endcode +/// \~english @retval TSKM_E_OK Succeeded +/// \~english @retval TSKM_E_PAR %Parameter error +/// \~english @par Preconditions: +/// - TSKM_Init must be used and initialized +/// \~english @par Changes of the internal state: +/// - The internal state is not changed +/// \~english @par Causes of failures: +/// - Parameters p_info is NULL [TSKM_E_PAR] +/// - Reboot factors are except for TSKM_ERROR_REBOOT_NORMAL [TSKM_E_PAR] +/// \~english @par Classification: +/// Public +/// \~english @par Type +/// Sync only +/// \~english @par Detail: +/// Does REBOOT. \n +/// It is assumed to issue when system is damaged if processing continues any more +/// such as device trouble and non-volatile data trouble. \n +/// Access limitation is done to this API by gid and uid. \n +/// When an application with no authorization calls this, this force-quits the application to have called API. \n +/// This stores the string designated to messageStr as factors in system information LOG. \n +/// To link with PSMShadow about trouble factors, this designates abnormal message character string defined +/// inside ss_error_message.h to messageStr. +/// \~english @see None +//////////////////////////////////////////////////////////////////////////////////// +TSKM_ERR_t TSKM_ErrorReboot(const TSKM_ERROR_REBOOT_t* p_info); +///////////////////////////////////////////////////////////////////////////////////// +/// \ingroup TSKM_Reboot +/// \~english @par Summary: +/// Let system do reboot. +/// \~english @param [in] rsv +/// TSKM_RSV_t* - Reservation ( This must designate NULL) +/// \~english @retval TSKM_E_OK Succeeded +/// \~english @retval TSKM_E_PAR %Parameter error +/// \~english @par Preconditions: +/// - TSKM_Init must be used and initialized +/// \~english @par Changes of the internal state: +/// - The internal state is not changed +/// \~english @par Causes of failures: +/// - Parameters p_rsv is except for NULL [TSKM_E_PAR] +/// \~english @par Classification: +/// Public +/// \~english @par Type +/// Sync x Method +/// \~english @par Detail: +/// Let system do normal reboot. +/// \~english @see None +//////////////////////////////////////////////////////////////////////////////////// +TSKM_ERR_t TSKM_Reboot(const TSKM_RSV_t * p_rsv); +///////////////////////////////////////////////////////////////////////////////////// +/// \ingroup TSKM_Logging +/// \~english @par Summary: +/// Stores LOG in internal non-volatile area. +/// \~english @param [in] p_info +/// TSKM_LOGGING_INFO_t * - Log storing information +/// \~english @code +/// typedef struct{ +/// TSKM_LOGGING_TYPE_NORMAL_t type; +/// char messageStr[TSKM_LOGGING_MSG_STR_SIZE]; +/// }TSKM_LOGGING_INFO_t; +/// type : Log storing type +/// TSKM_LOGGING_TYPE_MODULE_LOGS: General LOG storing request from service +/// TSKM_LOGGING_TYPE_GRP_RELAUNCH: Log collection by Group Relaunch +/// messageStr : Trouble factors +/// @endcode +/// \~english @retval TSKM_E_OK Succeeded +/// \~english @retval TSKM_E_PAR %Parameter error +/// \~english @par Preconditions: +/// - TSKM_Init must be used and initialized +/// \~english @par Changes of the internal state: +/// - The internal state is not changed +/// \~english @par Causes of failures: +/// - Parameters p_info is NULL [TSKM_E_PAR] +/// \~english @par Classification: +/// Public +/// \~english @par Type +/// Sync only +/// \~english @par Detail: +/// Collects LOG information and stores it in internal non-volatile area \n +/// This stores the string designated to messageStr as factors in system information LOG. +/// \~english @see None +//////////////////////////////////////////////////////////////////////////////////// +TSKM_ERR_t TSKM_Logging(const TSKM_LOGGING_INFO_t* p_info); +///////////////////////////////////////////////////////////////////////////////////// +/// \ingroup TSKM_DataInit +/// \~english @par Summary: +/// Does the initialization process of service data. +/// \~english @param [in] hApp +/// HANDLE - Application handle +/// \~english @param [in] p_info +/// TSKM_DATAINIT_t * - Data initialization information +/// \~english @code +/// typedef struct { +/// TSKM_DATAINIT_TYPE_t type; +/// EFrameworkunifiedStatus (*onCompInit)(HANDLE hApp); +/// } TSKM_DATAINIT_t; +/// type : Data initialization type +/// TSKM_DATAINIT_TYPE_USER : User data initialization +/// onCompInit : Initialization complete Callback +/// @endcode +/// \~english @retval TSKM_E_OK Succeeded +/// \~english @retval TSKM_E_PAR %Parameter error +/// \~english @retval TSKM_E_NG Error +/// \~english @par Preconditions: +/// - TSKM_Init must be used and initialized +/// \~english @par Changes of the internal state: +/// - The internal state is not changed +/// \~english @par Causes of failures: +/// - Parameters hAPP is NULL [TSKM_E_PAR] +/// - Parameters p_info is NULL [TSKM_E_PAR] +/// - Member type of parameters p_info is except for TSKM_DATAINIT_TYPE_USER [TSKM_E_PAR] +/// - Member onCompInit of parameters p_info is NULL [TSKM_E_PAR] +/// - The process of FrameworkunifiedAttachCallbackToDispatcher failed [TSKM_E_NG] +/// - The process of FrameworkunifiedOpenService failed [TSKM_E_STATE] +/// - The process of FrameworkunifiedSendMsg failed [TSKM_E_NG] +/// \~english @par Classification: +/// Public +/// \~english @par Type +/// Method only +/// \~english @par Detail: +/// - How to report \n +/// Reports by Callback of onCompInit. \n +/// This can get message data by calling GetMsgData inside onCompInit. \n +/// - Structure of message data \n +/// TSKM_ERR_t:Processing result \n +/// TSKM_E_OK :Normal end \n +/// TSKM_E_STATE :State error \n +/// TSKM_E_NG :Error +/// - Summary of action \n +/// Calls initialization functions which each service implemented. \n +/// When this API was called before Availability of Task_Manager becomes TRUE, this +/// does not call initialization functions and returns TSKM_E_STATE by onCompInit. \n +/// It is permitted for same application to call this API several times, at this case, +/// it is necessary to designate the pointer to same functions to onCompInit. \n +/// When this API was called by designating TSKM_DATAINIT_TYPE_USER to type, this calls +/// the initialization functions of each service by designating the following parameters. \n +/// +/// +/// +/// +/// +/// +/// +/// +/// +///
MemberValues
startupReasonepswfIGN_ACC
isUserModeOnTRUE
dataResetModee_SS_SM_DATA_RESET_MODE_USER
wakeupTypeepsstWARMSTART
dramBackupStatuse_SS_SM_DRAM_BACKUP_OK
resetStatuse_SS_SM_RESET_STATUS_NONE
resetCount0
+/// Because Task_Manager calls the initialization functions of each service and implements +/// the recovery processing according to running factors at the timing of fixing running factor, +/// this designates the above parameters not to do duplicate recover processing. +/// \~english @see TSKM_DATA_INIT_FUNC +//////////////////////////////////////////////////////////////////////////////////// +TSKM_ERR_t TSKM_DataInit(HANDLE hApp, const TSKM_DATAINIT_t *p_info); +///////////////////////////////////////////////////////////////////////////////////// +/// \ingroup TSKM_SetWakeupOrder +/// \~english @par Summary: +/// Holds running order. +/// \~english @param [in] p_order +/// TSKM_WAKEUP_ORDER_t * - Running order information +/// \~english @code +/// typedef struct { +/// char orderName[TSKM_ORDER_NAME_MAX]; +/// } TSKM_WAKEUP_ORDER_t; +/// orderName: Order name (MAX:31 characters) +/// @endcode +/// \~english @retval TSKM_E_OK Succeeded +/// \~english @retval TSKM_E_PAR %Parameter error +/// \~english @retval TSKM_E_NG Error +/// \~english @par Preconditions: +/// - TSKM_Init must be used and initialized +/// \~english @par Changes of the internal state: +/// - The internal state is not changed +/// \~english @par Causes of failures: +/// - Parameters p_order is NULL [TSKM_E_PAR] +/// - The string length of the member orderName of Parameters p_order exceeds 32 [TSKM_E_PAR] +/// - The process of SetWakeupOrderToSystemManager failed [TSKM_E_NG] +/// \~english @par Classification: +/// Public +/// \~english @par Type +/// Sync x Sync +/// \~english @par Detail: +/// This function is Wrapper function to provide SetWakeupOrderToSystemManager +/// by sessionless which SystemManger provides. +/// This designates NULL to p_order and returns TSKM_E_PAR. +/// For the detail of action, refer to SystemManager (SetWakeupOrderToSystemManager). +/// \~english @see None +//////////////////////////////////////////////////////////////////////////////////// +TSKM_ERR_t TSKM_SetWakeupOrder(const TSKM_WAKEUP_ORDER_t* p_order); +#ifdef __cplusplus +} +#endif + +#endif // TASK_MANAGER_SERVER_INCLUDE_SYSTEM_SERVICE_TSKM_H_ + +/** @}*/ // end of Task_Manager +/** @}*/ // end of SystemService +/** @}*/ // end of BaseSystem + + diff --git a/systemservice/task_manager/server/include/system_service/tskm_local_type.h b/systemservice/task_manager/server/include/system_service/tskm_local_type.h new file mode 100755 index 0000000..79831aa --- /dev/null +++ b/systemservice/task_manager/server/include/system_service/tskm_local_type.h @@ -0,0 +1,287 @@ +/* + * @copyright Copyright (c) 2016-2020 TOYOTA MOTOR CORPORATION. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +/** + * @file tskm_local_type.h + * @brief \~english localtype of tskm + */ +/** @addtogroup BaseSystem + * @{ + */ +/** @addtogroup system_service + * @ingroup BaseSystem + * @{ + */ +/** @addtogroup task_manager + * @ingroup system_service + * @{ + */ +#ifndef TASK_MANAGER_SERVER_INCLUDE_SYSTEM_SERVICE_TSKM_LOCAL_TYPE_H_ +#define TASK_MANAGER_SERVER_INCLUDE_SYSTEM_SERVICE_TSKM_LOCAL_TYPE_H_ + + +#include +#include +#include +#include "system_service/INI_API.hpp" +#include "system_service/tskm_type.h" + +//================================================== +// Configuration +//================================================== + +#if 1 +#define TSKM_CFG_WAIT_SHUTDOWN 10000 +#else +#define TSKM_CFG_WAIT_SHUTDOWN 1 // Handy for test +#warning TSKM_CFG_WAIT_SHUTDOWN is temorary +#endif + +#define TSKM_CFG_TOUCH_TIMEOUT 2 // TOUCH time-out + +//================================================== +// Task manager internal +//================================================== +// State +#define TSKM_ST_ACCOFF 0x01000000U // ACC-OFF (Default) No transition here +#define TSKM_ST_ACCON 0x02000000U // ACC-ON +#define TSKM_ST_WAKEUP 0x02010000U // Gradual startup +#define TSKM_ST_RUNNING 0x02020000U // Running (Startup completed) +#define TSKM_ST_DOWN 0x02040000U // Gradual Terminating + +typedef uint32_t TSKM_STATE_t; +#define TSKM_STATE_MASK0 0xFF000000U +#define TSKM_STATE_MASK1 0xFFFF0000U +#define TSKM_STATE_MASK2 0xFFFFFF00U +#define TSKM_STATE_MASK3 0xFFFFFFFFU + +// Global step IDs for gradual starting +typedef uint32_t TSKM_GLOBAL_STEP_t; +#define TSKM_GSTEP_NONE 0x00000000U // +#define TSKM_GSTEP_BUPCHK 0x00000001U + +// Local step +typedef uint32_t TSKM_LOCAL_STEP_t; +#define TSKM_LSTEP_LAST 0xFFFFFFF0U // Executing to end of local steps +#define TSKM_LSTEP_SHM 0xFFFFFFF1U // Creating shared memory +#define TSKM_LSTEP_BUPCHK 0xFFFFFFF2U // Checking backup memory +#define TSKM_LSTEP_ALL 0xFFFFFFF3U // Executing all user definitions + +/************************************************************ + * Structure of gradual startup/termination structure + (When this structure is modified, structure of parsexml is also changed) + *************************************************************/ +// Structure of request for services +typedef struct { + TSKM_SVCID_t svcId; // Service ID + TSKM_LOCAL_STEP_t localStep; // Local step number +} TSKM_GSTEP_REQ_INFO_t; + +// Structure of gradual startup/termination +typedef struct { + uint32_t gstepId; + + // List of executing services + uint32_t execSvcNum; + TSKM_SVCID_t* execSvcIdList; + + // List of request + uint32_t reqNum; + TSKM_GSTEP_REQ_INFO_t* reqList; + + // Event completion wait conditions + uint64_t nextTransCond; +} TSKM_GSTEP_t; + +typedef struct { + uint32_t gstepIdx; // Step index + uint32_t gstepNum; // Step number + TSKM_GSTEP_t* gstep; // Gradual startup/termination info + uint64_t compState; // Status of receiving for Event completion notification +} TSKM_GSTEP_CTX_t; + +//********* Non-volatile management information **************** + +#define TSKM_NV_STRUCT_VERSION "v000" // Compatible version of non-volatile management structure +#define TSKM_SVC_RESERVE_MAX (8) // Maximum number of reserved services to startup + +#define TSKM_NV_SIZE_ALL (512) +#define TSKM_NV_SIZE_HEADER (32) +#define TSKM_NV_SIZE_FOOTER (32) +#define TSKM_NV_SIZE_BODY (TSKM_NV_SIZE_ALL - TSKM_NV_SIZE_HEADER - TSKM_NV_SIZE_FOOTER) + +// Header +typedef struct { + char version[5]; +} TSKM_NV_HEADER_t; + +// Footer +typedef struct { + uint32_t checkSum; +} TSKM_NV_FOOTER_t; + +// Body +typedef struct { + uint8_t rsvSvcNum; // Number of reserved services + TSKM_SVCID_t rsvSvcs[TSKM_SVC_RESERVE_MAX]; // List of services +} TSKM_NV_BODY_t; + +// Non-volatile storage info +typedef struct { + TSKM_NV_HEADER_t header; + uint8_t rsvHeader[TSKM_NV_SIZE_HEADER - sizeof(TSKM_NV_HEADER_t)]; + TSKM_NV_BODY_t body; + uint8_t rsvBody[TSKM_NV_SIZE_BODY - sizeof(TSKM_NV_BODY_t)]; + uint8_t rsvFooter[TSKM_NV_SIZE_FOOTER - sizeof(TSKM_NV_FOOTER_t)]; + TSKM_NV_FOOTER_t footer; +} TSKM_NV_INFO_t; + +// Internal event +typedef enum { + TSKM_EV_NOP, // Do nothing + // TSKM->PRI + TSKM_EV_PRI_REQ_WAKEUP, // Startup request + TSKM_EV_PRI_REQ_DOWN, // Termination request + TSKM_EV_PRI_REQ_TOUCH, + TSKM_EV_PRI_REQ_DEBUGDUMP, // DebugDump request + TSKM_EV_PRI_REP_LOWMEM, // LowMemory detection request + + // PRI->TSKM(SVC) + TSKM_EV_PRI_REP_WAKEUP_COMP, // Notification of event completion at startup + TSKM_EV_PRI_REP_DOWN_COMP, // Notification of event completion at termination + TSKM_EV_PRI_REP_CONNECT, // Connecting + TSKM_EV_PRI_REP_DISCONNECT, // Disconnecting + TSKM_EV_PRI_RES_WAKEUP, // Response to startup request + TSKM_EV_PRI_RES_DOWN, // Response to termination request + TSKM_EV_PRI_RES_DEBUGDUMP, // Response to DebugDump request + TSKM_EV_PRI_REQ_EXIT, // Response to terminating request + + // SVC->TSKM + TSKM_EV_SVC_REP_TERM, // Termination of service + + // APL->TSKM + TSKM_EV_API_REQ_REBOOT, // Reboot system + TSKM_EV_API_REQ_SVC_CTL, // Startup service + TSKM_EV_API_REQ_SVC_DISABLE, // Prohibit starting service + + // Internal message + TSKM_EV_LCL_REQ_STOP, // Termination request + TSKM_EV_LCL_CHG_SVC_STATE, // State Change of service + TSKM_EV_LCL_REQ_SDUMP, // Dump of service list + TSKM_EV_LCL_REP_TIMEOUT, // Occured Timeout + TSKM_EV_LCL_REP_POLLING, // Polling request + TSKM_EV_LCL_REP_LOWMEM, // Notification of LowMemory detection + TSKM_EV_LCL_REQ_TRANS_STEP, // Gradual transitioning request +} TSKM_EVENT_t; + +#define TSKM_EV_BOOTINFO_SIZE sizeof(T_SS_SM_START_DataStructType) +#define TSKM_EV_EXTBOOTINFO_SIZE sizeof(T_SS_SM_START_ExtDataStructType) + +typedef struct { + TSKM_SVCID_t svcId; + TSKM_LOCAL_STEP_t localStep; + char bootInfo[TSKM_EV_BOOTINFO_SIZE]; + char extBootInfo[TSKM_EV_EXTBOOTINFO_SIZE]; + TSKM_BOOL_t isDynamic; // Nonresident task? +} TSKM_EV_PRI_REQ_WAKEUP_PRM_t; + +typedef struct { + TSKM_LOCAL_STEP_t localStep; +} TSKM_EV_PRI_REQ_DOWN_PRM_t; + +// PRI->TSKM +typedef struct { + uint64_t compId; +} TSKM_EV_PRI_REP_WAKEUP_COMP_PRM_t; + +typedef struct { + uint64_t compId; +} TSKM_EV_PRI_REP_DOWN_COMP_PRM_t; + +typedef struct { + int connFd; +} TSKM_EV_PRI_REP_CONNECT_PRM_t; + +typedef struct { + TSKM_BOOL_t isLast; + TSKM_BOOL_t isShmDone; + TSKM_BOOL_t isStepDone; +} TSKM_EV_PRI_RES_WAKEUP_PRM_t; + +typedef struct { + TSKM_BOOL_t isLast; +} TSKM_EV_PRI_RES_DOWN_PRM_t; + +#define TSKM_EV_DEBUGDUMP_SIZE 4096 + +typedef struct { + char dumpMsg[TSKM_EV_DEBUGDUMP_SIZE]; +} TSKM_EV_PRI_EX_RES_DEBUGDUMP_PRM_t; + +// APL->TSKM + +// Internal message +typedef struct { + TSKM_SVCID_t svcId; +} TSKM_EV_LCL_CHG_SVC_STATE_PRM_t; + +// The structure must be on a stack +typedef struct _TSKM_EVENT_INFO_t { + TSKM_EVENT_t event; + TSKM_ERR_t errCode; + pid_t fromPid; + TSKM_BOOL_t hasExtend; + uint32_t extendSize; + void *extendPrm; + union { + // TSKM->PRI + TSKM_EV_PRI_REQ_WAKEUP_PRM_t reqWakeup; + TSKM_EV_PRI_REQ_DOWN_PRM_t reqDown; + + // PRI->TSKM + TSKM_EV_PRI_REP_WAKEUP_COMP_PRM_t repWakeupComp; + TSKM_EV_PRI_REP_DOWN_COMP_PRM_t repDownComp; + TSKM_EV_PRI_REP_CONNECT_PRM_t repConnect; + TSKM_EV_PRI_RES_WAKEUP_PRM_t resWakeup; + TSKM_EV_PRI_RES_DOWN_PRM_t resDown; + + // Internal message + TSKM_EV_LCL_CHG_SVC_STATE_PRM_t chgSvc; + } prm; + _TSKM_EVENT_INFO_t() { + event = TSKM_EV_NOP; + errCode = TSKM_E_OK; + fromPid = 0; + hasExtend = TSKM_FALSE; + extendSize = 0; + extendPrm = NULL; + } + ~_TSKM_EVENT_INFO_t() { + if (hasExtend && !extendPrm) { + free(extendPrm); + } + } +} TSKM_EVENT_INFO_t; + +typedef enum { + TSKM_DATAINIT_REQ = 800, + TSKM_DATAINIT_RESP, + TSKM_TRANS_STEP_REQ +} TSKM_PROTCOL_t; + +#endif // TASK_MANAGER_SERVER_INCLUDE_SYSTEM_SERVICE_TSKM_LOCAL_TYPE_H_ +/** @}*/ +/** @}*/ +/** @}*/ diff --git a/systemservice/task_manager/server/include/system_service/tskm_svc.h b/systemservice/task_manager/server/include/system_service/tskm_svc.h new file mode 100755 index 0000000..8b25581 --- /dev/null +++ b/systemservice/task_manager/server/include/system_service/tskm_svc.h @@ -0,0 +1,904 @@ +/* + * @copyright Copyright (c) 2016-2020 TOYOTA MOTOR CORPORATION. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +/** + * @file tskm_svc.h + * @brief \~english define of tskm + */ +/** @addtogroup BaseSystem + * @{ + */ +/** @addtogroup system_service + * @ingroup BaseSystem + * @{ + */ +/** @addtogroup task_manager + * @ingroup system_service + * @{ + */ +#ifndef TASK_MANAGER_SERVER_INCLUDE_SYSTEM_SERVICE_TSKM_SVC_H_ +#define TASK_MANAGER_SERVER_INCLUDE_SYSTEM_SERVICE_TSKM_SVC_H_ + + +#include +#include +#include "system_service/tskm_local_type.h" + + +#define TSKM_SVC_WAIT_REQ_MAX (8) // Number of queued requests + +// Service type +typedef enum { + TSKM_SVC_TYPE_NATIVE, // + TSKM_SVC_TYPE_UNKNONW, // +} TSKM_SVC_TYPE_t; + +// Scheduling policy +typedef enum { + TSKM_SVC_POLICY_TSS, // + TSKM_SVC_POLICY_RR, // + TSKM_SVC_POLICY_FIFO, // +} TSKM_SVC_POLICY_t; + +// Life cycle +typedef enum { + TSKM_SVC_LC_ALWAYS, // Resident + TSKM_SVC_LC_ALWAYS_RECOVERABLE, // Resident(Recoverable) + TSKM_SVC_LC_DYNAMIC // Non-resident +} TSKM_SVC_LC_t; + +// CPU allocation: This defined value should match the specification of the second argument of CL_ProcessCreateAttrSetCpuAssign + +typedef enum { + TSKM_SVC_ASSIGN_CPU_AUTO = 0, // Automatic allocation + TSKM_SVC_ASSIGN_CPU_0 = 1, // Fixed to CPU0 + TSKM_SVC_ASSIGN_CPU_1 = 2, // Fixed to CPU1 +} TSKM_SVC_ASSIGN_CPU_t; + +// Service attributes (given by XML) +typedef struct { + TSKM_SVCID_t svcId; // + const char* name; // + const char* path; // + char** args; // + TSKM_SVC_TYPE_t type; // + uint32_t prio; // + TSKM_SVC_POLICY_t policy; // + TSKM_SVC_LC_t lifeCycle; // + uint32_t retryCnt; // + TSKM_SVC_ASSIGN_CPU_t cpuAssign; // + const char* user; // + uint32_t runtimeLimit; // + uint32_t cpuLimit; // + uint32_t memLimit; // + TSKM_BOOL_t shotdownWait; // + uint32_t subgidNum; // + gid_t *subgidList; // +} TSKM_SVC_ATTR_t; + +// Service status +typedef enum { + TSKM_SVC_DORMANT, // During dormant (Not exec) + TSKM_SVC_WAITCONNECT, // Wait for connection + TSKM_SVC_WAKEUP, // Start in progress + TSKM_SVC_RUNNING, // Running (Startup completed) + TSKM_SVC_DOWN, // Termination in progress + TSKM_SVC_FINDOWN, // Termination completed + TSKM_SVC_DISABLE, // Prohibitting startup (exec prohibited) +} TSKM_SVC_STATE_t; + +// Service +typedef struct { // Life cycle + TSKM_SVC_ATTR_t *attr; // Service Attributes ALL + TSKM_SVC_STATE_t state; // Service State ALL + int iFd; // inotifyFd for touch ALL + pid_t pid; // PID of service REQ_WAKEUP - FIN_DOWN + int connFd; // service communication socket DO_WAKEUP - FIN_DOWN + T_SS_SM_START_DataStructType bootInfo; // Boot info REQ_WAKEUP - FIN_DOWN + T_SS_SM_START_ExtDataStructType extBootInfo; // Extended boot info REQ_WAKEUP - FIN_DOWN + + TSKM_BOOL_t isShmDone; // Shared memory initialization completed + TSKM_BOOL_t isStepDone; // Gradual startup completed + TSKM_BOOL_t isAvailable; // Availability reception completed + + uint32_t watchCnt; // Service monitoring counter + uint32_t waitResCnt; // Wait for response to request DO_WAKEUP - WAIT_WAKEUP + uint32_t waitReqCnt; // Wait for request issuance REQ_WAKEUP - DO_WAKEUP + TSKM_GSTEP_REQ_INFO_t request[TSKM_SVC_WAIT_REQ_MAX]; // REQ_WAKEUP - DO_WAKEUP + + uint32_t errTermCnt; // Number of abnormal terminations ALL +} TSKM_SVC_CTX_t; + +// Service list +typedef struct { + uint32_t svcNum; + TSKM_SVC_CTX_t *svcList; +} TSKM_SVCS_CTX_t; + +// State of waiting for service termination +typedef enum { + TSKM_SVC_WAIT_NONE, // No wait + TSKM_SVC_WAIT_TRANSIENT, // Waiting for termination of nonresident service + TSKM_SVC_WAIT_BOTH, // Waiting for termination of resident/nonresident service +} TSKM_SVC_WAIT_STATE_t; + +// Service list + ///////////////////////////////////////////////////////////////////////////////////// + /// \ingroup tskm_svcsEventHandle + /// \~english @par Summary + /// + /// \~english @param + /// \~english @param [in] p_svcs + /// p_svcs - pointer of services + /// \~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] p_inEv + /// p_inEv - pointer of input event info + /// \~english @par + /// p_inEv TSKM_EVENT_INFO_t* + /// \~english @code + /// typedef struct _TSKM_EVENT_INFO_t { + /// TSKM_EVENT_t event; + /// TSKM_ERR_t errCode; + /// pid_t fromPid; + /// TSKM_BOOL_t hasExtend; + /// uint32_t extendSize; + /// void *extendPrm; + /// union { + /// // TSKM->PRI + /// TSKM_EV_PRI_REQ_WAKEUP_PRM_t reqWakeup; + /// TSKM_EV_PRI_REQ_DOWN_PRM_t reqDown; + /// // PRI->TSKM + /// TSKM_EV_PRI_REP_WAKEUP_COMP_PRM_t repWakeupComp; + /// TSKM_EV_PRI_REP_DOWN_COMP_PRM_t repDownComp; + /// TSKM_EV_PRI_REP_CONNECT_PRM_t repConnect; + /// TSKM_EV_PRI_RES_WAKEUP_PRM_t resWakeup; + /// TSKM_EV_PRI_RES_DOWN_PRM_t resDown; + /// TSKM_EV_LCL_CHG_SVC_STATE_PRM_t chgSvc; + /// } prm; + /// } TSKM_EVENT_INFO_t; + /// @endcode + /// \~english @param [out] p_outEv + /// p_outEv - pointer of output event info + /// \~english @par + /// p_outEv TSKM_EVENT_INFO_t* + /// \~english @retval + /// \~english @par Preconditions + /// - + /// \~english @par Change of the internal state + /// - The internal state is not changed. + /// \~english @par Causes of failures + /// - + /// \~english @par Classification + /// - public + /// \~english @par Type + /// - method + /// \~english @par Detail + /// + /// \~english @see None + //////////////////////////////////////////////////////////////////////////////////// +TSKM_ERR_t tskm_svcsEventHandle(TSKM_SVCS_CTX_t* p_svcs, + const TSKM_EVENT_INFO_t* p_inEv, + TSKM_EVENT_INFO_t* p_outEv); + + ///////////////////////////////////////////////////////////////////////////////////// + /// \ingroup tskm_svcsGetSvcBySvcId + /// \~english @par Summary + /// find service in inputed service list by service id. + /// \~english @param [in] p_svcs + /// p_svcs - pointer of services object + /// \~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] svcId + /// svcId - service Id + /// \~english @par + /// svcId uint32_t + /// \~english @retval TSKM_SVC_CTX_t* service pointer + /// \~english @retval TSKM_SVC_CTX_t* NULL + /// \~english @par Preconditions + /// - none + /// \~english @par Change of the internal state + /// - The internal state is not changed. + /// \~english @par Causes of failures + /// - If not find svcId in services list. [NULL] + /// \~english @par Classification + /// - public + /// \~english @par Type + /// - method only + /// \~english @par Detail + /// find service in inputed service list by service id.. If do not find then return NULL pointer. + /// \~english @see getSvcCtxBySvcId + //////////////////////////////////////////////////////////////////////////////////// +TSKM_SVC_CTX_t* tskm_svcsGetSvcBySvcId(TSKM_SVCS_CTX_t* p_svcs, + TSKM_SVCID_t svcId); + + ///////////////////////////////////////////////////////////////////////////////////// + /// \ingroup tskm_svcsGetSvcByPid + /// \~english @par Summary + /// find service in inputed service list by process id. + /// \~english @param [in] p_svcs + /// p_svcs - pointer of services + /// \~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] pid + /// pid - process id + /// \~english @par + /// pid pid_t + /// \~english @retval TSKM_SVC_CTX_t* service pointer + /// \~english @retval TSKM_SVC_CTX_t* NULL + /// \~english @par Preconditions + /// - + /// \~english @par Change of the internal state + /// - The internal state is not changed. + /// \~english @par Causes of failures + /// - If not find process id in services list. [NULL] + /// \~english @par Classification + /// - public + /// \~english @par Type + /// - method only + /// \~english @par Detail + /// find service in inputed service list by process id. If do not find then return NULL pointer. + /// \~english @see getSvcCtxByPid + //////////////////////////////////////////////////////////////////////////////////// +TSKM_SVC_CTX_t* tskm_svcsGetSvcByPid(TSKM_SVCS_CTX_t* p_svcs, pid_t pid); + + + ///////////////////////////////////////////////////////////////////////////////////// + /// \ingroup tskm_svcsIsWaiting + /// \~english @par Summary + /// Is the service state waiting. + /// \~english @param [in] p_svcs + /// p_svcs - pointer of services + /// \~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 @retval TSKM_BOOL_t + /// \~english @par Preconditions + /// - + /// \~english @par Change of the internal state + /// - The internal state is not changed. + /// \~english @par Causes of failures + /// - If service state is TSKM_SVC_WAITCONNECT and wait response num is 0. [TSKM_FALSE] + /// \~english @par Classification + /// - public + /// \~english @par Type + /// - method only + /// \~english @par Detail + /// Is the service state waiting. \n + /// There are not service's state equal TSKM_SVC_WAITCONNECT or wait respose number > 0 return TSKM_TRUE. + /// \~english @see None + //////////////////////////////////////////////////////////////////////////////////// +TSKM_BOOL_t tskm_svcsIsWaiting(TSKM_SVCS_CTX_t* p_svcs); + + ///////////////////////////////////////////////////////////////////////////////////// + /// \ingroup tskm_svcsGetSvcTermWaitState + /// \~english @par Summary + /// Get the service which state equanl not equal terminal. + /// \~english @code + /// typedef struct { + /// uint32_t svcNum; // service num + /// TSKM_SVC_CTX_t *svcList; // services list pointer + /// } TSKM_SVCS_CTX_t; + /// @endcode + /// \~english @retval TSKM_SVC_WAIT_STATE_t + /// \~english @par + /// TSKM_SVC_WAIT_STATE_t enum + /// \~english @code + /// typedef enum { + /// TSKM_SVC_WAIT_NONE, // not waiting state + /// TSKM_SVC_WAIT_TRANSIENT, // dynamic service terminal waiting state + /// TSKM_SVC_WAIT_BOTH, // no dynamic/ dyanmic service terminal waiting state + /// } TSKM_SVC_WAIT_STATE_t; + /// @endcode + /// \~english @par Preconditions + /// - none + /// \~english @par Change of the internal state + /// - The internal state is not changed. + /// \~english @par Causes of failures + /// If all services state equal TSKM_SVC_DORMANT. [TSKM_SVC_WAIT_NONE] + /// If dynamic service. [TSKM_SVC_WAIT_TRANSIENT] + /// If not dynamic service and state not TSKM_SVC_FINDOWN. [TSKM_SVC_WAIT_BOTH] + /// \~english @par Classification + /// - public + /// \~english @par Type + /// - method only + /// \~english @par Detail + /// Get the service which state equanl not equal terminal. \n + /// \~english @see None + //////////////////////////////////////////////////////////////////////////////////// +TSKM_SVC_WAIT_STATE_t tskm_svcsGetSvcTermWaitState(TSKM_SVCS_CTX_t* p_svcs); + + ///////////////////////////////////////////////////////////////////////////////////// + /// \ingroup tskm_svcsSetBootInfo + /// \~english @par Summary + /// initialize all services boot info. + /// \~english @param [in] p_svcs + /// p_svcs - pointer of services + /// \~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] p_info + /// p_info - SS_SM_START 'FrameworkunifiedOnStart'/'evStart' message pointer + /// \~english @par + /// p_info T_SS_SM_START_DataStructType* + /// \~english @code + /// Data passed as part of SS_SM_START 'FrameworkunifiedOnStart'/'evStart' message + /// 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 errResetCount; + /// T_SS_SM_START_DataStruct + /// } T_SS_SM_START_DataStructType; + /// @endcode + /// \~english @param [in] p_exInfo + /// p_exInfo - FrameworkunifiedOnStart extend info pointer + /// \~english @par + /// p_exInfo T_SS_SM_START_ExtDataStructType* + /// \~english @code + /// /// Extended Parameter for FrameworkunifiedOnStart + /// typedef struct { + /// BOOL isProgUpdated; + /// EMRelaunchStatus relaunchStatus; + /// BOOL isMapUpdated; + /// BOOL isMapDiffUpdated; + /// uint8_t reserved[SS_SM_START_EXT_RSV_SIZE]; + /// } T_SS_SM_START_ExtDataStructType; + /// @endcode + /// \~english @retval TSKM_E_OK + /// \~english @par + /// TSKM_SVC_WAIT_STATE_t enum + /// \~english @par Preconditions + /// - call tskm_dataInitAll() to get boot info + /// \~english @par Change of the internal state + /// - The internal state is not changed. + /// \~english @par Causes of failures + /// - none + /// \~english @par Classification + /// - pulbic + /// \~english @par Type + /// - method only + /// \~english @par Detail + /// - initialize all services boot info. + /// \~english @see None + //////////////////////////////////////////////////////////////////////////////////// +TSKM_ERR_t tskm_svcsSetBootInfo(TSKM_SVCS_CTX_t* p_svcs, + T_SS_SM_START_DataStructType* p_info, + T_SS_SM_START_ExtDataStructType *p_exInfo); + + ///////////////////////////////////////////////////////////////////////////////////// + /// \ingroup tskm_svcsAvtiveSvcTerm + /// \~english @par Summary + /// Terminal the dynamic services. + /// \~english @param [in] p_svcs + /// p_svcs - pointer of services + /// \~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 @retval TSKM_ERR_t + /// \~english @par + /// TSKM_E_OK + /// TSKM_E_NG + /// \~english @par Preconditions + /// - none + /// \~english @par Change of the internal state + /// - The internal state is not changed. + /// \~english @par Causes of failures + /// - tskm_svcDownRequest return failed [TSKM_E_NG] + /// \~english @par Classification + /// - pulbic + /// \~english @par Type + /// - method only + /// \~english @par Detail + /// Terminal all the dynamic services which state equal TSKM_SVC_RUNNING and response num equal 0. \n + /// \~english @see tskm_svcDownRequest + //////////////////////////////////////////////////////////////////////////////////// +TSKM_ERR_t tskm_svcsAvtiveSvcTerm(TSKM_SVCS_CTX_t* p_svcs); + + ///////////////////////////////////////////////////////////////////////////////////// + /// \ingroup tskm_svcsCallDebugDump + /// \~english @par Summary + /// Send DebugDump message to services. + /// \~english @param [in] p_svcs + /// p_svcs - pointer of services + /// \~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 @retval TSKM_ERR_t + /// \~english @par + /// TSKM_E_OK + /// TSKM_E_NG + /// \~english @par Preconditions + /// - none + /// \~english @par Change of the internal state + /// - The internal state is not changed. + /// \~english @par Causes of failures + /// - tskm_sockSend send DebugDump message failed [TSKM_E_NG] + /// \~english @par Classification + /// - public + /// \~english @par Type + /// - method only + /// \~english @par Detail + /// Send DebugDump message to services which state equal TSKM_SVC_RUNNING. \n + /// \~english @see tskm_sockSend + //////////////////////////////////////////////////////////////////////////////////// +TSKM_ERR_t tskm_svcsCallDebugDump(TSKM_SVCS_CTX_t* p_svcs); + + ///////////////////////////////////////////////////////////////////////////////////// + /// \ingroup tskm_svcsCallLowMem + /// \~english @par Summary + /// Send checking low memory message to services. + /// \~english @param [in] p_svcs + /// p_svcs - pointer of services + /// \~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 @retval TSKM_ERR_t + /// \~english @par + /// TSKM_E_OK + /// TSKM_E_NG + /// \~english @par Preconditions + /// - none + /// \~english @par Change of the internal state + /// - The internal state is not changed. + /// \~english @par Causes of failures + /// - tskm_sockSend send LowMemory message failed [TSKM_E_NG] + /// \~english @par Classification + /// - public + /// \~english @par Type + /// - method only + /// \~english @par Detail + /// Send checking LowMemory message to services which state equal TSKM_SVC_RUNNING. \n + /// \~english @see tskm_sockSend + //////////////////////////////////////////////////////////////////////////////////// +TSKM_ERR_t tskm_svcsCallLowMem(TSKM_SVCS_CTX_t* p_svcs); + +// Service + ///////////////////////////////////////////////////////////////////////////////////// + /// \ingroup tskm_svcEventHandle + /// \~english @par Summary + /// process event. + /// \~english @param [in] p_svcs + /// p_svcs - pointer of services + /// \~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][out] p_ev + /// p_ev - event info pointer + /// \~english @par + /// p_ev TSKM_EVENT_INFO_t* + /// \~english @code + /// typedef struct _TSKM_EVENT_INFO_t { + /// TSKM_EVENT_t event; + /// TSKM_ERR_t errCode; + /// pid_t fromPid; + /// TSKM_BOOL_t hasExtend; + /// uint32_t extendSize; + /// void *extendPrm; + /// union { + /// // TSKM->PRI + /// TSKM_EV_PRI_REQ_WAKEUP_PRM_t reqWakeup; + /// TSKM_EV_PRI_REQ_DOWN_PRM_t reqDown; + /// + /// // PRI->TSKM + /// TSKM_EV_PRI_REP_WAKEUP_COMP_PRM_t repWakeupComp; + /// TSKM_EV_PRI_REP_DOWN_COMP_PRM_t repDownComp; + /// TSKM_EV_PRI_REP_CONNECT_PRM_t repConnect; + /// TSKM_EV_PRI_RES_WAKEUP_PRM_t resWakeup; + /// TSKM_EV_PRI_RES_DOWN_PRM_t resDown; + /// TSKM_EV_LCL_CHG_SVC_STATE_PRM_t chgSvc; + /// } prm; + /// } TSKM_EVENT_INFO_t; + /// @endcode + /// \~english @retval TSKM_ERR_t + /// \~english @par + /// TSKM_E_OK + /// \~english @par Preconditions + /// - none + /// \~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 + /// - method + /// \~english @par Detail + /// process event.\n + /// process connect response.\n + /// process disconnect response. \n + /// process service wakeup request. \n + /// process service down request. \n + /// process service debugdump request. \n + /// process service exit request. \n + /// process service terminal response. \n + /// \~english @see isSvcEvent,connectHandle,disConnectHandle,resWakeupHandle, \n + /// resDownHandle,resDebugDumpHandle,reqExit,repTermHandle \n + //////////////////////////////////////////////////////////////////////////////////// +TSKM_ERR_t tskm_svcEventHandle(TSKM_SVC_CTX_t* p_svc, TSKM_EVENT_INFO_t* p_ev); // p_ev: [IN/OUT] + + ///////////////////////////////////////////////////////////////////////////////////// + /// \ingroup tskm_svcExec + /// \~english @par Summary + /// start service. + /// \~english @param [in][out] p_svc + /// p_svc - pointer of services + /// \~english @par + /// p_svc TSKM_SVC_CTX_t* + /// \~english @code + /// typedef struct { + /// TSKM_SVC_ATTR_t *attr; // attribute of service + /// TSKM_SVC_STATE_t state; // state of service + /// int iFd; // inotifyFd used by touch + /// pid_t pid; // PID of service + /// int connFd; // service communicate fd + /// T_SS_SM_START_DataStructType bootInfo; // BOOT info + /// T_SS_SM_START_ExtDataStructType extBootInfo; // extend BOOT info + /// TSKM_BOOL_t isShmDone; // shared memory init done + /// TSKM_BOOL_t isStepDone; // step done + /// TSKM_BOOL_t isAvailable; // Availability flag + /// uint32_t watchCnt; // service monitor count + /// uint32_t waitResCnt; // wait response num + /// uint32_t waitReqCnt; // wait request num + /// TSKM_GSTEP_REQ_INFO_t request[TSKM_SVC_WAIT_REQ_MAX]; + /// uint32_t errTermCnt; // exception terminal count + /// } TSKM_SVC_CTX_t; + /// @endcode + /// \~english @retval TSKM_ERR_t + /// \~english @par + /// TSKM_E_OK + /// TSKM_E_NG + /// TSKM_E_STATE + /// \~english @par Preconditions + /// - + /// \~english @par Change of the internal state + /// - The internal state is not changed. + /// \~english @par Causes of failures + /// - input parameter p_svc is NULL. [TSKM_E_NG] + /// - service state is TSKM_SVC_DISABLE [TSKM_E_STATE] + /// - reqTouch return failed [TSKM_E_NG] + /// - tskm_pf_createProc return failed [TSKM_E_NG] + /// \~english @par Classification + /// - public + /// \~english @par Type + /// - method + /// \~english @par Detail + /// start service which state is TSKM_SVC_DORMANT.\n + /// \~english @see svcExec, reqTouch, tskm_pf_createProc + //////////////////////////////////////////////////////////////////////////////////// +TSKM_ERR_t tskm_svcExec(TSKM_SVC_CTX_t* p_svc); + + ///////////////////////////////////////////////////////////////////////////////////// + /// \ingroup tskm_svcWakeupRequest + /// \~english @par Summary + /// Send started request to service. + /// \~english @param [in][out] p_svc + /// p_svc - pointer of service + /// \~english @par + /// p_svc TSKM_SVC_CTX_t* + /// \~english @code + /// typedef struct { + /// TSKM_SVC_ATTR_t *attr; // attribute of service + /// TSKM_SVC_STATE_t state; // state of service + /// int iFd; // inotifyFd used by touch + /// pid_t pid; // PID of service + /// int connFd; // service communicate fd + /// T_SS_SM_START_DataStructType bootInfo; // BOOT info + /// T_SS_SM_START_ExtDataStructType extBootInfo; // extend BOOT info + /// TSKM_BOOL_t isShmDone; // shared memory init done + /// TSKM_BOOL_t isStepDone; // step done + /// TSKM_BOOL_t isAvailable; // Availability flag + /// uint32_t watchCnt; // service monitor count + /// uint32_t waitResCnt; // wait response num + /// uint32_t waitReqCnt; // wait request num + /// TSKM_GSTEP_REQ_INFO_t request[TSKM_SVC_WAIT_REQ_MAX]; + /// uint32_t errTermCnt; // exception terminal count + /// } TSKM_SVC_CTX_t; + /// @endcode + /// \~english @param [in] p_req + /// p_req - pointer of request + /// \~english @par + /// p_req TSKM_GSTEP_REQ_INFO_t* + /// \~english @code + /// typedef struct { + /// TSKM_SVCID_t svcId; // service ID + /// TSKM_LOCAL_STEP_t localStep; // local step id + /// } TSKM_GSTEP_REQ_INFO_t; + /// @endcode + /// \~english @retval TSKM_ERR_t + /// \~english @par + /// TSKM_E_OK + /// TSKM_E_NG + /// TSKM_E_STATE + /// \~english @par Preconditions + /// - none + /// \~english @par Change of the internal state + /// - The internal state is not changed. + /// \~english @par Causes of failures + /// - Input parameter p_svc is NULL. [TSKM_E_STATE] + /// - Service state is TSKM_SVC_DISABLE [TSKM_E_STATE] + /// - wakeupRequest return failed [TSKM_E_NG] + /// \~english @par Classification + /// - public + /// \~english @par Type + /// - method + /// \~english @par Detail + /// Send started request to service. If service do not connect, save the request.\n + /// Send request again when service connect. \n + /// \~english @see svcWakeupRequest + //////////////////////////////////////////////////////////////////////////////////// +TSKM_ERR_t tskm_svcWakeupRequest(TSKM_SVC_CTX_t* p_svc, + TSKM_GSTEP_REQ_INFO_t* p_req); + + + ///////////////////////////////////////////////////////////////////////////////////// + /// \ingroup tskm_svcDownRequest + /// \~english @par Summary + /// Send service down request to service. + /// \~english @param [in][out] p_svc + /// p_svc - pointer service + /// \~english @par + /// p_svc TSKM_SVC_CTX_t* + /// \~english @code + /// typedef struct { + /// TSKM_SVC_ATTR_t *attr; // attribute of service + /// TSKM_SVC_STATE_t state; // state of service + /// int iFd; // inotifyFd used by touch + /// pid_t pid; // PID of service + /// int connFd; // service communicate fd + /// T_SS_SM_START_DataStructType bootInfo; // BOOT info + /// T_SS_SM_START_ExtDataStructType extBootInfo; // extend BOOT info + /// TSKM_BOOL_t isShmDone; // shared memory init done + /// TSKM_BOOL_t isStepDone; // step done + /// TSKM_BOOL_t isAvailable; // Availability flag + /// uint32_t watchCnt; // service monitor count + /// uint32_t waitResCnt; // wait response num + /// uint32_t waitReqCnt; // wait request num + /// TSKM_GSTEP_REQ_INFO_t request[TSKM_SVC_WAIT_REQ_MAX]; + /// uint32_t errTermCnt; // exception terminal count + /// } TSKM_SVC_CTX_t; + /// @endcode + /// \~english @param [in] p_req + /// p_req - request pointer + /// \~english @par + /// p_req TSKM_GSTEP_REQ_INFO_t* + /// \~english @code + /// typedef struct { + /// TSKM_SVCID_t svcId; // service ID + /// TSKM_LOCAL_STEP_t localStep; // local step id + /// } TSKM_GSTEP_REQ_INFO_t; + /// @endcode + /// \~english @retval TSKM_ERR_t + /// \~english @par + /// TSKM_E_OK + /// TSKM_E_NG + /// \~english @par Preconditions + /// - + /// \~english @par Change of the internal state + /// - The internal state is not changed. + /// \~english @par Causes of failures + /// - Send service down request failed [TSKM_E_NG] + /// \~english @par Classification + /// - public + /// \~english @par Type + /// - method + /// \~english @par Detail + /// If service state is commounicated(TSKM_SVC_WAKEUP, TSKM_SVC_RUNNING), \n + /// send service down request and set state as TSKM_SVC_DOWN.\n + /// \~english @see tskm_svcIsCommunicatable,tskm_sockSend + //////////////////////////////////////////////////////////////////////////////////// +TSKM_ERR_t tskm_svcDownRequest(TSKM_SVC_CTX_t* p_svc, + TSKM_GSTEP_REQ_INFO_t* p_req); + + ///////////////////////////////////////////////////////////////////////////////////// + /// \ingroup tskm_svcDisableRequest + /// \~english @par Summary + /// + /// \~english @param [in][out] p_svc + /// p_svc - pointer of service + /// \~english @par + /// p_svc TSKM_SVC_CTX_t* + /// \~english @code + /// typedef struct { + /// TSKM_SVC_ATTR_t *attr; // attribute of service + /// TSKM_SVC_STATE_t state; // state of service + /// int iFd; // inotifyFd used by touch + /// pid_t pid; // PID of service + /// int connFd; // service communicate fd + /// T_SS_SM_START_DataStructType bootInfo; // BOOT info + /// T_SS_SM_START_ExtDataStructType extBootInfo; // extend BOOT info + /// TSKM_BOOL_t isShmDone; // shared memory init done + /// TSKM_BOOL_t isStepDone; // step done + /// TSKM_BOOL_t isAvailable; // Availability flag + /// uint32_t watchCnt; // service monitor count + /// uint32_t waitResCnt; // wait response num + /// uint32_t waitReqCnt; // wait request num + /// TSKM_GSTEP_REQ_INFO_t request[TSKM_SVC_WAIT_REQ_MAX]; + /// uint32_t errTermCnt; // exception terminal count + /// } TSKM_SVC_CTX_t; + /// @endcode + /// \~english @retval TSKM_ERR_t + /// \~english @par + /// TSKM_E_OK + /// TSKM_E_STATE + /// \~english @par Preconditions + /// - + /// \~english @par Change of the internal state + /// - The internal state is not changed. + /// \~english @par Causes of failures + /// - If service state is not TSKM_SVC_DORMANT and TSKM_SVC_DISABLE. [TSKM_E_STATE] + /// \~english @par Classification + /// - public + /// \~english @par Type + /// - method + /// \~english @par Detail + /// Set service state as TSKM_SVC_DISABLE if state is TSKM_SVC_DORMANT. + /// \~english @see None + //////////////////////////////////////////////////////////////////////////////////// +TSKM_ERR_t tskm_svcDisableRequest(TSKM_SVC_CTX_t* p_svc); + + ///////////////////////////////////////////////////////////////////////////////////// + /// \ingroup tskm_svcDisableRequest + /// \~english @par Summary + /// Set service state as start available. + /// \~english @param [in][out] p_svc + /// p_svc - Pointer to service + /// \~english @par + /// p_svc TSKM_SVC_CTX_t* + /// \~english @code + /// typedef struct { + /// TSKM_SVC_ATTR_t *attr; // attribute of service + /// TSKM_SVC_STATE_t state; // state of service + /// int iFd; // inotifyFd used by touch + /// pid_t pid; // PID of service + /// int connFd; // service communicate fd + /// T_SS_SM_START_DataStructType bootInfo; // BOOT info + /// T_SS_SM_START_ExtDataStructType extBootInfo; // extend BOOT info + /// TSKM_BOOL_t isShmDone; // shared memory init done + /// TSKM_BOOL_t isStepDone; // step done + /// TSKM_BOOL_t isAvailable; // Availability flag + /// uint32_t watchCnt; // service monitor count + /// uint32_t waitResCnt; // wait response num + /// uint32_t waitReqCnt; // wait request num + /// TSKM_GSTEP_REQ_INFO_t request[TSKM_SVC_WAIT_REQ_MAX]; + /// uint32_t errTermCnt; // exception terminal count + /// } TSKM_SVC_CTX_t; + /// @endcode + /// \~english @retval TSKM_ERR_t + /// \~english @par + /// TSKM_E_OK + /// \~english @par Preconditions + /// - + /// \~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 + /// - method + /// \~english @par Detail + /// Set service state as start available which state is disable(TSKM_SVC_DISABLE). + /// \~english @see None + //////////////////////////////////////////////////////////////////////////////////// +TSKM_ERR_t tskm_svcEnableRequest(TSKM_SVC_CTX_t* p_svc); + + ///////////////////////////////////////////////////////////////////////////////////// + /// \ingroup tskm_svcIsCommunicatable + /// \~english @par Summary + /// Whether service is Communicatable. + /// \~english @param [in] p_svc + /// p_svc - pointer of service + /// \~english @par + /// p_svc TSKM_SVC_CTX_t* + /// \~english @code + /// typedef struct { + /// TSKM_SVC_ATTR_t *attr; // attribute of service + /// TSKM_SVC_STATE_t state; // state of service + /// int iFd; // inotifyFd used by touch + /// pid_t pid; // PID of service + /// int connFd; // service communicate fd + /// T_SS_SM_START_DataStructType bootInfo; // BOOT info + /// T_SS_SM_START_ExtDataStructType extBootInfo; // extend BOOT info + /// TSKM_BOOL_t isShmDone; // shared memory init done + /// TSKM_BOOL_t isStepDone; // step done + /// TSKM_BOOL_t isAvailable; // Availability flag + /// uint32_t watchCnt; // service monitor count + /// uint32_t waitResCnt; // wait response num + /// uint32_t waitReqCnt; // wait request num + /// TSKM_GSTEP_REQ_INFO_t request[TSKM_SVC_WAIT_REQ_MAX]; + /// uint32_t errTermCnt; // exception terminal count + /// } TSKM_SVC_CTX_t; + /// @endcode + /// \~english @retval TSKM_BOOL_t + /// \~english @par + /// TSKM_FALSE + /// TSKM_TRUE + /// \~english @par Preconditions + /// - + /// \~english @par Change of the internal state + /// - The internal state is not changed. + /// \~english @par Causes of failures + /// - If input parameter p_svc is NULL. [TSKM_FALSE] + /// - If input parameter p_svc->attr->type is TSKM_SVC_TYPE_UNKNONW. [TSKM_FALSE] + /// - If service state is TSKM_SVC_DORMANT or TSKM_SVC_WAITCONNECT or + /// TSKM_SVC_FINDOWN orTSKM_SVC_DISABLE. [TSKM_FALSE] + /// \~english @par Classification + /// - public + /// \~english @par Type + /// - method + /// \~english @par Detail + /// Whether service is Communicatable. \n + /// If service state is TSKM_SVC_WAKEUP or TSKM_SVC_RUNNING or TSKM_SVC_DOWN, return TSKM_TRUE. \n + /// \~english @see None + //////////////////////////////////////////////////////////////////////////////////// +TSKM_BOOL_t tskm_svcIsCommunicatable(TSKM_SVC_CTX_t* p_svc); + +#endif // TASK_MANAGER_SERVER_INCLUDE_SYSTEM_SERVICE_TSKM_SVC_H_ +/** @}*/ +/** @}*/ +/** @}*/ diff --git a/systemservice/task_manager/server/include/system_service/tskm_type.h b/systemservice/task_manager/server/include/system_service/tskm_type.h new file mode 100755 index 0000000..7d1f818 --- /dev/null +++ b/systemservice/task_manager/server/include/system_service/tskm_type.h @@ -0,0 +1,123 @@ +/* + * @copyright Copyright (c) 2016-2020 TOYOTA MOTOR CORPORATION. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +/** + * @file tskm_type.h + * @brief \~english type of tskm + */ +/** @addtogroup BaseSystem + * @{ + */ +/** @addtogroup system_service + * @ingroup BaseSystem + * @{ + */ +/** @addtogroup task_manager + * @ingroup system_service + * @{ + */ +#ifndef TASK_MANAGER_SERVER_INCLUDE_SYSTEM_SERVICE_TSKM_TYPE_H_ +#define TASK_MANAGER_SERVER_INCLUDE_SYSTEM_SERVICE_TSKM_TYPE_H_ + + + +#include +#include +#include +#include "system_service/tskm_svcid.h" + + +#define TSKM_ERR_t int32_t +#define TSKM_E_OK 0 +#define TSKM_E_PAR 1 +#define TSKM_E_STATE 2 +#define TSKM_E_PERMIT 3 +#define TSKM_E_ALREADY 4 +#define TSKM_E_RETRY 5 +#define TSKM_E_NG 6 + +#define TSKM_BOOL_t int32_t +#define TSKM_TRUE 1 +#define TSKM_FALSE 0 + +#define TSKM_RSV_t int + +typedef uint32_t TSKM_SVCID_t; +// Values are defined in tskm_svcid.h + +typedef enum { + TSKM_SVC_CMD_NOP, // Do nothing + TSKM_SVC_CMD_EXEC, // Startup service + TSKM_SVC_CMD_ENABLE, // Allow service startup + TSKM_SVC_CMD_DISABLE, // Prohibit service startup + TSKM_SVC_CMD_RESERVE, // Reserve service startup +} TSKM_SVC_CMD_t; + +typedef struct { + TSKM_SVC_CMD_t cmd; +} TSKM_SVC_CTL_t; + +typedef struct { + TSKM_SVCID_t svcId; + TSKM_BOOL_t isExecDisable; +} TSKM_SVC_INFO_t; + +typedef enum { + TSKM_BOOT_NORMAL, // Normal start + TSKM_BOOT_FACTRESET, // start with factory default start + TSKM_BOOT_USERRESET, // start with resetting user info + TSKM_BOOT_VERSIONUP, // start with version up +} TSKM_BOOT_t; + +typedef enum { + TSKM_LOGGING_TYPE_MODULE_LOGS, // logging request from the service + TSKM_LOGGING_TYPE_GRP_RELAUNCH, // logging by Group Relaunch +} TSKM_LOGGING_TYPE_NORMAL_t; + +typedef enum { + TSKM_ERROR_REBOOT_NORMAL, // Anomaly detection +} TSKM_ERROR_REBOOT_TYPE_t; + +#define TSKM_LOGGING_MSG_STR_SIZE 64 + +typedef struct { + TSKM_LOGGING_TYPE_NORMAL_t type; // Log type + char messageStr[TSKM_LOGGING_MSG_STR_SIZE]; // Error message +} TSKM_LOGGING_INFO_t; + +typedef struct { + TSKM_ERROR_REBOOT_TYPE_t type; // Reboot type + TSKM_LOGGING_INFO_t log; // Log info +} TSKM_ERROR_REBOOT_t; + +typedef enum { + TSKM_DATAINIT_TYPE_USER, // Reset user info +} TSKM_DATAINIT_TYPE_t; + +typedef struct { + TSKM_DATAINIT_TYPE_t type; + EFrameworkunifiedStatus (*onCompInit)(HANDLE hApp); +} TSKM_DATAINIT_t; + +#define TSKM_ORDER_NAME_MAX 32 + +typedef struct { + char orderName[TSKM_ORDER_NAME_MAX]; +} TSKM_WAKEUP_ORDER_t; + +#endif // TASK_MANAGER_SERVER_INCLUDE_SYSTEM_SERVICE_TSKM_TYPE_H_ +/** @}*/ +/** @}*/ +/** @}*/ diff --git a/systemservice/task_manager/server/include/tskm_comm.h b/systemservice/task_manager/server/include/tskm_comm.h new file mode 100755 index 0000000..c884be9 --- /dev/null +++ b/systemservice/task_manager/server/include/tskm_comm.h @@ -0,0 +1,59 @@ +/* + * @copyright Copyright (c) 2016-2020 TOYOTA MOTOR CORPORATION. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +// Communication module header file +#ifndef TASK_MANAGER_SERVER_INCLUDE_TSKM_COMM_H_ +#define TASK_MANAGER_SERVER_INCLUDE_TSKM_COMM_H_ + +#include +#include "system_service/tskm_local_type.h" + +#define TSKM_SOCKET_NAME "/tmp/tskm_sock" // Sockets for Primary Library + +#define TSKM_COMM_CONNECT_MAX (32) + +typedef struct { + pid_t pid; + int connFd; +} TSKM_SRV_CONNENT_t; + +typedef struct { + uint32_t num; + TSKM_SRV_CONNENT_t conn[TSKM_COMM_CONNECT_MAX]; +} TSKM_SRV_CONNENT_LIST_t; + +typedef struct { + int sockFd; + const char *sockName; + TSKM_SRV_CONNENT_LIST_t connList; +} TSKM_SRV_SOCK_CTX_t; + +TSKM_ERR_t tskm_srvSockCreate(const char* sockName, + TSKM_SRV_SOCK_CTX_t* p_sock); +TSKM_SRV_CONNENT_t* tskm_srvSockConnect(TSKM_SRV_SOCK_CTX_t* p_sock); +void tskm_srvSockDisconnect(TSKM_SRV_SOCK_CTX_t* p_sock, + TSKM_SRV_CONNENT_t *p_conn); +void tskm_srvSockDestory(TSKM_SRV_SOCK_CTX_t* p_sock); +int tskm_cliSockConnect(const char* sockName); +int tskm_sockRcv(int fd, TSKM_EVENT_INFO_t* p_ev); +int tskm_sockSend(int fd, TSKM_EVENT_INFO_t* p_ev); +void tskm_sockDestory(int fd); + +int tskm_comm_procInit(void); +int tskm_comm_setSvcWatchState(uint32_t id, BOOL bIsRun, uint32_t timeout); + +#endif // TASK_MANAGER_SERVER_INCLUDE_TSKM_COMM_H_ + diff --git a/systemservice/task_manager/server/include/tskm_debug.h b/systemservice/task_manager/server/include/tskm_debug.h new file mode 100755 index 0000000..ae963a8 --- /dev/null +++ b/systemservice/task_manager/server/include/tskm_debug.h @@ -0,0 +1,208 @@ +/* + * @copyright Copyright (c) 2016-2020 TOYOTA MOTOR CORPORATION. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef TASK_MANAGER_SERVER_INCLUDE_TSKM_DEBUG_H_ +#define TASK_MANAGER_SERVER_INCLUDE_TSKM_DEBUG_H_ + +#include +#include +#include +#include +#include "system_service/tskm_svc.h" + +#include "system_service/tskm_local_type.h" + +#define TSKM_STATIC static + +// for frameworkunifiedlog +#define ZONE_INIT ZONEMASK(10) // Reserved for lib +#define ZONE_FUNC ZONEMASK(11) // Reserved for lib +#define ZONE_MEM ZONEMASK(12) // Reserved for lib +#define ZONE_OUT ZONEMASK(13) +#define ZONE_STATE ZONEMASK(14) // Basic state change +#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) // Reserved for lib +#define ZONE_WARN ZONEMASK(30) // Reserved for lib +#define ZONE_ERR ZONEMASK(31) // Reserved for lib + +#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|LMSGQ) // LPRINT , LMSGQ, LSLOGGER +#endif + +#ifndef FRAMEWORKUNIFIEDLOGAPPZONES +#define FRAMEWORKUNIFIEDLOGAPPZONES ZONE_OUT, ZONE_WARN, ZONE_ERR, ZONE_STATE, ZONE_PERFORMANCE, ZONE_SYSTEMDATA +/* + ZONE_NS_FUNC,\ + ZONE_NS_DIS,\ + ZONE_NS__CWORD77_,\ + ZONE_NS_IMP_INFO,\ + ZONE_NS_SM_DEV_INFO,\ + ZONE_NS_SM_USR_INFO,\ + ZONE_NS_INFO,\ + ZONE_NS_DEBUG_DUMP,\ + ZONE_NS_WAR ,\ + ZONE_NS_ERR ,\ + ZONE_DEBUG_DUMP + */ +#endif + +#define TSKM_LOG_ERROR 0x00000001U +#define TSKM_LOG_STATE 0x00000002U +#define TSKM_LOG_DEBUG 0x00000004U +#define TSKM_LOG_API 0x00000008U +#define TSKM_LOG_PORTPF 0x00000010U +#define TSKM_LOG_FUNC 0x00000020U +#define TSKM_LOG_MSG 0x00000040U +#define TSKM_LOG_WARN 0x00000080U +#define TSKM_LOG_SVCSTATE 0x00000100U +#define TSKM_LOG_SYSTEMDATA 0x00000200U + +// For debugging +#define TSKM_LOG_CUSTUM (0 \ + ) +/* + |TSKM_LOG_MSG \ + |TSKM_LOG_DEBUG \ + |TSKM_LOG_FUNC \ + |TSKM_LOG_PORTPF \ + */ + +typedef enum { + TSKM_LOG_TYPE_TEXT, + TSKM_LOG_TYPE_PLACE, +} TSKM_LOG_TYPE_t; + +#define TSKM_DEFAULT_PRINTF(flag, fmt, ...) { \ + switch (flag) { \ + case TSKM_LOG_SYSTEMDATA: \ + FRAMEWORKUNIFIEDLOG(ZONE_SYSTEMDATA, __FUNCTION__, fmt, ##__VA_ARGS__); \ + break; \ + case TSKM_LOG_API: \ + case TSKM_LOG_STATE: \ + FRAMEWORKUNIFIEDLOG(ZONE_STATE, __FUNCTION__, fmt, ##__VA_ARGS__); \ + break; \ + case TSKM_LOG_ERROR: \ + FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, fmt, ##__VA_ARGS__); \ + break; \ + case TSKM_LOG_WARN: \ + FRAMEWORKUNIFIEDLOG(ZONE_WARN, __FUNCTION__, fmt, ##__VA_ARGS__); \ + break; \ + case TSKM_LOG_DEBUG: \ + FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__, fmt, ##__VA_ARGS__); \ + break; \ + case TSKM_LOG_MSG: \ + case TSKM_LOG_FUNC: \ + case TSKM_LOG_PORTPF: \ + default: \ + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, fmt, ##__VA_ARGS__); \ + break; \ + } \ + } + +#define TSKM_PRINTF(flag, fmt, ...) { \ + if (TSKM_LOG_SVCSTATE == flag) { \ + /* Logs at startup and termination */ \ + FRAMEWORKUNIFIEDLOG(ZONE_PERFORMANCE, __FUNCTION__, fmt, ## __VA_ARGS__); \ + } else if (TSKM_LOG_CUSTUM & flag) { \ + /* Logging by STATE when CUSTUM is specified */ \ + FRAMEWORKUNIFIEDLOG(ZONE_STATE, __FUNCTION__, fmt, ## __VA_ARGS__); \ + } else { \ + TSKM_DEFAULT_PRINTF(flag, fmt, ## __VA_ARGS__); \ + } \ + } + +#define TSKM_ASSERT(x) \ + if (!(x)) { \ + FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "TSKM_ASSERT"); \ + } + +#define TSKM_ASSERT_ERRNO(x) \ + if (!(x)) { \ + FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "TSKM_ASSERT %d:%s", errno, strerror(errno)); \ + } + +#define TSKM_ASSERT_PRINT(x, fmt, ...) \ + if (!(x)) { \ + FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "TSKM_ASSERT:" fmt, ## __VA_ARGS__); \ + } + +#define TSKM_STATIC_ASSERT(expr) \ + { \ + char STATIC_ASSERTION_FAILED[(expr) ? 1 : -1]; \ + (void)STATIC_ASSERTION_FAILED; \ + } + +#define TSKM_DUMP(addr, size) { \ + char* buf = (char*)addr; /* NOLINT (readability/casting) */ \ + int ii; \ + printf("[DUMP] %s:%d addr:%p size:%d", __FUNCTION__, __LINE__, addr, size); \ + for (ii=0 ; ii < size ; ii++) { \ + if (ii%16 == 0) printf(" "); \ + if (ii%32 == 0) printf("\n"); \ + printf("%02x", buf[ii]); \ + } \ + printf("\n"); \ + } + +#define TSKM_FUNC_IN() TSKM_PRINTF(TSKM_LOG_FUNC, "%s:IN", __FUNCTION__) + +#define TSKM_FUNC_OUT() TSKM_PRINTF(TSKM_LOG_FUNC, "%s:OUT", __FUNCTION__) + +const char* tskm_convState2Str(TSKM_STATE_t state); +const char* tskm_convLocalStep2Str(TSKM_LOCAL_STEP_t localStep); +const char* tskm_convEvent2Str(TSKM_EVENT_t event); +const char* tskm_convInitCompId2Str(uint64_t compId); +const char* tskm_convTermCompId2Str(uint64_t compId); +const char* tskm_convSvcState2Str(TSKM_SVC_STATE_t state); +void tskm_svcsDump(TSKM_SVCS_CTX_t* p_svcs); + +#endif // TASK_MANAGER_SERVER_INCLUDE_TSKM_DEBUG_H_ diff --git a/systemservice/task_manager/server/include/tskm_main.h b/systemservice/task_manager/server/include/tskm_main.h new file mode 100755 index 0000000..24ba5f1 --- /dev/null +++ b/systemservice/task_manager/server/include/tskm_main.h @@ -0,0 +1,71 @@ +/* + * @copyright Copyright (c) 2016-2020 TOYOTA MOTOR CORPORATION. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef TASK_MANAGER_SERVER_INCLUDE_TSKM_MAIN_H_ +#define TASK_MANAGER_SERVER_INCLUDE_TSKM_MAIN_H_ + +#include + +#include "system_service/tskm_svc.h" +#include "system_service/tskm_local_type.h" +#include "tskm_comm.h" +#include "tskm_type_local.h" + +typedef struct { + // State + TSKM_BOOL_t isExec; // Executing flag + TSKM_STATE_t state; // TSKM state + + // API + TSKM_BOOL_t inApi; // API running + TSKM_ERR_t apiRet; // API return + TSKM_BOOL_t isReboot; // REBOOT request + + TSKM_BOOL_t isOnStartDone; // System start process completion flag + TSKM_BOOL_t isOnStopDone; // System stop process completion flag + + // Communication + TSKM_SRV_SOCK_CTX_t sock; // priLib socket + int sigFd; // signalFd(process-termination-detection) + HANDLE hApp; // DispatcherHandle + int nsFd; // For receiving from the NSFW + int iFd; // inotify FDs + int resmFd; // EV FDs of RESM + + // Non-volatile info + TSKM_NV_INFO_t nvInfo; // Non-volatile information + + // Startup info + T_SS_SM_START_DataStructType bootInfo; // for Pri notification + T_SS_SM_START_ExtDataStructType extBootInfo; // for Pri notification + + // Analysis support + STATEMGR__CWORD69_LOG* p__CWORD69_Log; // BUGBUG: Required or not + + // Services management + TSKM_SVCS_CTX_t svcs; + + // Gradual starting state management + TSKM_GSTEP_CTX_t wakeup; + + // Gradual terminating state management + TSKM_GSTEP_CTX_t down; +} TSKM_MAIN_CTX_t; + +EFrameworkunifiedStatus OnStart(const HANDLE hApp); // System start process +TSKM_MAIN_CTX_t* tskm_getMainCtx(void); + +#endif // TASK_MANAGER_SERVER_INCLUDE_TSKM_MAIN_H_ diff --git a/systemservice/task_manager/server/include/tskm_port_pf.h b/systemservice/task_manager/server/include/tskm_port_pf.h new file mode 100755 index 0000000..31da5ab --- /dev/null +++ b/systemservice/task_manager/server/include/tskm_port_pf.h @@ -0,0 +1,46 @@ +/* + * @copyright Copyright (c) 2016-2020 TOYOTA MOTOR CORPORATION. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef TASK_MANAGER_SERVER_INCLUDE_TSKM_PORT_PF_H_ +#define TASK_MANAGER_SERVER_INCLUDE_TSKM_PORT_PF_H_ + +#include + +#include "system_service/tskm_svc.h" +#include "system_service/tskm_local_type.h" +#include "tskm_main.h" + +int tskm_pf_sysInit(); +int tskm_pf_procInit(); +pid_t tskm_pf_createProc(TSKM_SVC_ATTR_t* p_svcAttr); +int tskm_pf_cleanupProc(int sigFd, pid_t* p_pid, TSKM_ERR_t* p_err); +int tskm_pf_terminateProcGroup(uint16_t pid); +int tskm_pf_shmCreate(const char* name, int32_t size, void** p_addr); +int tskm_pf_shmDelete(const char* name); +int tskm_pf_createThread(void* (*threadFunc)(void*), void* prm, + uint32_t priority, const char* threadName, + pthread_t* p_thId); +int tskm_pf_sendStopCompResp(); +int tskm_pf_abort(); +int tskm_pf_exit(int status); +int tskm_pf_touch(char* path); +int tskm_pf_mkTouchFileName(pid_t pid, char name[32]); +int tskm_pf_nvFileInit(HANDLE hApp); +int tskm_pf_nvFileRead(HANDLE hApp, TSKM_NV_INFO_t* p_nvInfo); +int tskm_pf_nvFileWrite(const TSKM_NV_INFO_t* p_nvInfo); + +#endif // TASK_MANAGER_SERVER_INCLUDE_TSKM_PORT_PF_H_ + diff --git a/systemservice/task_manager/server/include/tskm_port_subsys.h b/systemservice/task_manager/server/include/tskm_port_subsys.h new file mode 100755 index 0000000..3dc3565 --- /dev/null +++ b/systemservice/task_manager/server/include/tskm_port_subsys.h @@ -0,0 +1,42 @@ +/* + * @copyright Copyright (c) 2016-2020 TOYOTA MOTOR CORPORATION. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef TASK_MANAGER_SERVER_INCLUDE_TSKM_PORT_SUBSYS_H_ +#define TASK_MANAGER_SERVER_INCLUDE_TSKM_PORT_SUBSYS_H_ + +#include "system_service/tskm_local_type.h" +#include "tskm_main.h" + +typedef struct { + pid_t pid; + uint8_t type; // CL_MonitorType_t +} TSKM_HUNG_INFO_t; + +int tskm_sub_init(void); +int tskm_sub_term(void); +void tskm_sub_reboot(const TSKM_ERROR_REBOOT_t* p_info); +void tskm_sub_reboot_normal(void); +void tskm_sub_logging(const TSKM_LOGGING_INFO_t* p_info); +void tskm_sub_debugDumpRes(BOOL bIsNeedSvcName, const char *p_dumpMsg); +int tskm_sub_getExtBootInfo(T_SS_SM_START_ExtDataStructType *p_info); + +TSKM_HUNG_INFO_t *tskm_sub_searchHungSvcs(); +int tskm_sub_resmInit(); +int tskm_sub_resmRcv(TSKM_EVENT_INFO_t* p_ev); +int tskm_sub_setWakeupOrder(const char* p_order); + +#endif // TASK_MANAGER_SERVER_INCLUDE_TSKM_PORT_SUBSYS_H_ + diff --git a/systemservice/task_manager/server/include/tskm_shutdown.h b/systemservice/task_manager/server/include/tskm_shutdown.h new file mode 100755 index 0000000..bb76d3c --- /dev/null +++ b/systemservice/task_manager/server/include/tskm_shutdown.h @@ -0,0 +1,27 @@ +/* + * @copyright Copyright (c) 2016-2020 TOYOTA MOTOR CORPORATION. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef TASK_MANAGER_SERVER_INCLUDE_TSKM_SHUTDOWN_H_ +#define TASK_MANAGER_SERVER_INCLUDE_TSKM_SHUTDOWN_H_ + +#include "tskm_main.h" + +TSKM_ERR_t tskm_entryDown(TSKM_MAIN_CTX_t* p_main); +TSKM_ERR_t tskm_exitDown(TSKM_MAIN_CTX_t* p_main); +TSKM_ERR_t tskm_handleDown(TSKM_MAIN_CTX_t* p_main, TSKM_EVENT_INFO_t* p_ev); + +#endif // TASK_MANAGER_SERVER_INCLUDE_TSKM_SHUTDOWN_H_ + diff --git a/systemservice/task_manager/server/include/tskm_state.h b/systemservice/task_manager/server/include/tskm_state.h new file mode 100755 index 0000000..748d25e --- /dev/null +++ b/systemservice/task_manager/server/include/tskm_state.h @@ -0,0 +1,36 @@ +/* + * @copyright Copyright (c) 2016-2020 TOYOTA MOTOR CORPORATION. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef TASK_MANAGER_SERVER_INCLUDE_TSKM_STATE_H_ +#define TASK_MANAGER_SERVER_INCLUDE_TSKM_STATE_H_ + +#include "system_service/tskm_local_type.h" +#include "system_service/tskm_type.h" +#include "tskm_main.h" + +#define TSKM_SUB_STATE_IS(p_main, subState) \ + (((p_main)->state & subState) == subState) // NOLINT (runtime/references) + +// Public functions +TSKM_ERR_t tskm_entryState(TSKM_MAIN_CTX_t* p_rec, TSKM_STATE_t state); +TSKM_ERR_t tskm_exitState(TSKM_MAIN_CTX_t* p_rec, TSKM_STATE_t state); +TSKM_ERR_t tskm_stateTransit(TSKM_MAIN_CTX_t* p_main, TSKM_STATE_t srcState, + TSKM_STATE_t dstState); +void tskm_handleEvent(TSKM_MAIN_CTX_t* p_main, TSKM_EVENT_INFO_t* p_ev); + +TSKM_ERR_t tskm_handleAccon(TSKM_MAIN_CTX_t* p_main, TSKM_EVENT_INFO_t* p_ev); + +#endif // TASK_MANAGER_SERVER_INCLUDE_TSKM_STATE_H_ diff --git a/systemservice/task_manager/server/include/tskm_wakeup.h b/systemservice/task_manager/server/include/tskm_wakeup.h new file mode 100755 index 0000000..d4a1193 --- /dev/null +++ b/systemservice/task_manager/server/include/tskm_wakeup.h @@ -0,0 +1,26 @@ +/* + * @copyright Copyright (c) 2016-2020 TOYOTA MOTOR CORPORATION. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef TASK_MANAGER_SERVER_INCLUDE_TSKM_WAKEUP_H_ +#define TASK_MANAGER_SERVER_INCLUDE_TSKM_WAKEUP_H_ + +#include "tskm_main.h" + +TSKM_ERR_t tskm_entryWakeup(TSKM_MAIN_CTX_t* p_main); +TSKM_ERR_t tskm_exitWakeup(TSKM_MAIN_CTX_t* p_main); +TSKM_ERR_t tskm_handleWakeup(TSKM_MAIN_CTX_t* p_main, TSKM_EVENT_INFO_t* p_ev); + +#endif // TASK_MANAGER_SERVER_INCLUDE_TSKM_WAKEUP_H_ diff --git a/systemservice/task_manager/server/include/tskm_watch.h b/systemservice/task_manager/server/include/tskm_watch.h new file mode 100755 index 0000000..d1aced5 --- /dev/null +++ b/systemservice/task_manager/server/include/tskm_watch.h @@ -0,0 +1,25 @@ +/* + * @copyright Copyright (c) 2016-2020 TOYOTA MOTOR CORPORATION. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef TASK_MANAGER_SERVER_INCLUDE_TSKM_WATCH_H_ +#define TASK_MANAGER_SERVER_INCLUDE_TSKM_WATCH_H_ + +#include "tskm_main.h" + +int tskm_watch_startTimer(); + +#endif // TASK_MANAGER_SERVER_INCLUDE_TSKM_WATCH_H_ + diff --git a/systemservice/task_manager/server/src/pri_main.cpp b/systemservice/task_manager/server/src/pri_main.cpp new file mode 100755 index 0000000..2c87623 --- /dev/null +++ b/systemservice/task_manager/server/src/pri_main.cpp @@ -0,0 +1,840 @@ +/* + * @copyright Copyright (c) 2016-2020 TOYOTA MOTOR CORPORATION. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "pri_main.h" +#include +#include +#include +#include +#include +#include +#include + +#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; // Executed local step + TSKM_BOOL_t shmDone; + uint32_t downStepDone; // Executed 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 socket + int nsFd; // NSFW socket + 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 in Death testing, but it is not reflected in the coverage and excluded + // LCOV_EXCL_START 5: Checked in 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 5: Checked in Death testing, but it is not reflected in the coverage and excluded + } + } + p_ctx->shmDone = TSKM_TRUE; + return; + + // LCOV_EXCL_START 5: Checked in 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 startup 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 step by step + 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) { + // Completed gradual startup + 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 handles + *********************************************/ +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 in Death testing, but it is not reflected in the coverage and excluded + // LCOV_EXCL_START 5: Checked in 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 5: Checked in Death testing, but it is not reflected in the coverage and excluded + } +} + +/********************************************* + * 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 requests + *********************************************/ +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 step by step + 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 in Death testing, but it is not reflected in the coverage and excluded + // LCOV_EXCL_START 5: Checked in 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 5: Checked in Death testing, but it is not reflected in the coverage and excluded + } + } +} + +/********************************************* + * Termination completion notification 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: Checked in Death testing, but it is not reflected in the coverage and excluded + // LCOV_EXCL_START 5: Checked in 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 5: Checked in Death testing, but it is not reflected in the coverage and excluded + } +} + +/********************************************* + * Call Touch CB + *********************************************/ +TSKM_STATIC void touchService(PRI_CTX_t* p_ctx) { + char touchName[32]; + + if (p_ctx->isExitStart) { + // If termination has already begun, the system just processes as timeout for retrying not respond Touch + 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); + } +} + +/********************************************* + * Call 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 + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + TSKM_ASSERT(0); // LCOV_EXCL_LINE 6: As NULL checked by INI_Init + } else { + p_ctx->prm.onDebugDump(p_ctx->hApp); + } +} + +/********************************************* + * Call LowMemory detection + *********************************************/ +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 before starting terminating process + p_ctx->prm.onLowMem(p_ctx->hApp); + } +} + +/********************************************* + * Event handles + *********************************************/ +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.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 in Death testing, but it is not reflected in the coverage and excluded + // LCOV_EXCL_START 5: Checked in 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 5: Checked in Death testing, but it is not reflected in the coverage and excluded + } + + 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 in Death testing, but it is not reflected in the coverage and excluded + // LCOV_EXCL_START 5: Checked in 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 5: Checked in Death testing, but it is not reflected in the coverage and excluded + } + if (pipe(p_ctx->pipeFd) != 0) { // LCOV_EXCL_BR_LINE 5: Checked in Death testing, but it is not reflected in the coverage and excluded + // LCOV_EXCL_START 5: Checked in 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 5: Checked in Death testing, but it is not reflected in the coverage and excluded + } + + return; + + // LCOV_EXCL_START 5: Checked in 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: For processing in which only return value 0 is set + 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); + } +} + +/******************************************************************* + * Initialize PRI context + *******************************************************************/ +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 6: Return value of 0 only + } + + ret = tskm_comm_procInit(); + if (ret != 0) { // LCOV_EXCL_BR_LINE 5: Checked in 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 5: Checked in Death testing, but it is not reflected in the coverage and excluded + } + + 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 in 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: True 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 in Death testing, but it is not reflected in the coverage and excluded + // LCOV_EXCL_START 5: Checked in 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 completes termination processing with a termination notice (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 in 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) { + if (errno != EINTR) { + TSKM_ASSERT(0); + } + continue; + } + + 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 6: The caller's external API does not execute the second or subsequent processing and cannot be checked + TSKM_ASSERT(0); + goto ERROR; + } + 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; + + // LCOV_EXCL_BR_START 6: The caller's external API does not execute the second or subsequent processing and cannot be checked + if (p_ctx->pipeFd[1] > 0) { + // LCOV_EXCL_BR_STOP + // LCOV_EXCL_START 6: 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_ERRNO( + write(p_ctx->pipeFd[1], &l_status, sizeof(l_status)) + == sizeof(l_status)); + // LCOV_EXCL_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; +} + +/******************************************************************* + * Get private info + *******************************************************************/ +void* +pri_getPrivate() { + PRI_CTX_t* p_ctx = &g_pri; + return p_ctx->prm.priv; +} + +/******************************************************************* + * Get app-handle + *******************************************************************/ +HANDLE pri_getHandle() { + PRI_CTX_t* p_ctx = &g_pri; + return p_ctx->hApp; +} + +/******************************************************************* + * Service monitoring status setting timeout setting + *******************************************************************/ +int32_t pri_setMonitorTimeout(uint32_t timeout) { + PRI_CTX_t* p_ctx = &g_pri; + p_ctx->timeout = timeout; + return INI_SUCCESS; +} + +/******************************************************************* + * Get boot info + *******************************************************************/ +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; +} + +/******************************************************************* + * Get extended boot info + *******************************************************************/ +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 response + *******************************************************************/ +void pri_sendDebugDumpRes(const char *buf) { // LCOV_EXCL_START 7: Debugging code + 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 (readability/casting) + 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) { + EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK; + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+"); + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-"); + return l_eStatus; +} +EFrameworkunifiedStatus FrameworkunifiedOnStop(HANDLE hApp) { + EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK; + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+"); + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-"); + return l_eStatus; +} + +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/systemservice/task_manager/server/src/tskm_api.cpp b/systemservice/task_manager/server/src/tskm_api.cpp new file mode 100755 index 0000000..94c8226 --- /dev/null +++ b/systemservice/task_manager/server/src/tskm_api.cpp @@ -0,0 +1,268 @@ +/* + * @copyright Copyright (c) 2016-2020 TOYOTA MOTOR CORPORATION. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "tskm_debug.h" +#include "tskm_main.h" +#include "tskm_state.h" +#include "tskm_util.h" + +#include "tskm_srvr.h" +#include "tskm_port_pf.h" +#include "tskm_port_subsys.h" + +/** + * _TSKM_SvcCtl Sub-func Task-startup-process + * @param svcId service id + * @param p_main TSKM_MAIN_CTX_t* + * @param p_svc TSKM_SVC_CTX_t* + * @return TSKM_E_OK Succeeded + * @return other Failed + */ + +TSKM_ERR_t tskm_svcExecRequest(TSKM_SVCID_t svcId, TSKM_MAIN_CTX_t* p_main, TSKM_SVC_CTX_t* p_svc) { + TSKM_ERR_t tskmRet = TSKM_E_OK; + + // Startup tasks + TSKM_GSTEP_REQ_INFO_t req = { 0 }; + + if (p_main->isOnStartDone == TSKM_FALSE) { + TSKM_PRINTF(TSKM_LOG_WARN, "Transient SVC cannot exec before get BootInfo"); + return TSKM_E_STATE; + } else if (p_main->isOnStopDone == TSKM_TRUE) { + TSKM_PRINTF(TSKM_LOG_WARN, "Transient SVC cannot exec after FrameworkunifiedOnStop"); + return TSKM_E_STATE; + } + + tskmRet = tskm_svcExec(p_svc); + TSKM_ERR_CHK_DFT; + if (p_svc->state == TSKM_SVC_WAITCONNECT) { + // In the state of waiting to execute + req.svcId = svcId; + req.localStep = TSKM_LSTEP_ALL; + tskmRet = tskm_svcWakeupRequest(p_svc, &req); + TSKM_ERR_CHK_DFT; // LCOV_EXCL_BR_LINE 6: Because TSKM_ERR_CHK_DFT does not specify a condition for goto to ERROR + } + ERROR: return tskmRet; +} + +/** + * _TSKM_SvcCtl Sub-func Task-startup-process + * @param p_main TSKM_MAIN_CTX_t* + * @param svcId TSKM_SVCID_t + * @return TSKM_E_OK Succeeded + * @return other Failed + */ + +TSKM_ERR_t tskm_svcReserveRequest(TSKM_MAIN_CTX_t* p_main, TSKM_SVCID_t svcId) { + uint8_t rsvSvcNum = p_main->nvInfo.body.rsvSvcNum; + TSKM_SVCID_t* p_rsvSvcs = p_main->nvInfo.body.rsvSvcs; + TSKM_ERR_t tskmRet = TSKM_E_OK; + + if (rsvSvcNum >= TSKM_SVC_RESERVE_MAX) { + tskmRet = TSKM_E_STATE; + } else { + int ii; + int ret; + + for (ii = 0; ii < rsvSvcNum; ii++) { + if (p_rsvSvcs[ii] == svcId) { + TSKM_ASSERT_PRINT(0, "Rsv Req already registered(%d)", svcId); + // Return OK as continuable + return tskmRet; + } + } + + p_rsvSvcs[rsvSvcNum] = svcId; + p_main->nvInfo.body.rsvSvcNum++; + + TSKM_PRINTF(TSKM_LOG_STATE, "Rsv Svc registered(%#x)", svcId); + + ret = tskm_pf_nvFileWrite(&p_main->nvInfo); // LCOV_EXCL_BR_LINE 6: Return value of 0 only + if (ret == -1) { + TSKM_ASSERT(0); + tskmRet = TSKM_E_NG; + return tskmRet; + } + } + return tskmRet; +} + +/** + * Service control + * @param svcId service id + * @param ctl control command + * @return TSKM_E_OK Succeeded + * @return other Failed + */ +TSKM_ERR_t _TSKM_SvcCtl(TSKM_SVCID_t svcId, const TSKM_SVC_CTL_t* ctl) { + TSKM_ERR_t tskmRet = TSKM_E_OK; + TSKM_MAIN_CTX_t* p_main = tskm_getMainCtx(); + + TSKM_SVC_CTX_t* p_svc; + + if (ctl == NULL) { + TSKM_ASSERT(0); + return TSKM_E_PAR; + } + + p_svc = tskm_svcsGetSvcBySvcId(&p_main->svcs, svcId); + if (p_svc == NULL) { + TSKM_ASSERT(0); + TSKM_PRINTF(TSKM_LOG_ERROR, "unknown svcId:%#x", svcId); + return TSKM_E_PAR; + } + + TSKM_PRINTF(TSKM_LOG_API, "%s(%#x,%d)", __FUNCTION__, svcId, ctl->cmd); + + if (ctl->cmd == TSKM_SVC_CMD_EXEC) { + tskmRet = tskm_svcExecRequest(svcId, p_main, p_svc); + } else if (ctl->cmd == TSKM_SVC_CMD_ENABLE) { + tskmRet = tskm_svcEnableRequest(p_svc); + TSKM_ERR_CHK_DFT; // LCOV_EXCL_BR_LINE 8: Because TSKM_ERR_CHK_DFT does not specify a condition for goto to ERROR + + } else if (ctl->cmd == TSKM_SVC_CMD_DISABLE) { + tskmRet = tskm_svcDisableRequest(p_svc); + TSKM_ERR_CHK_DFT; + + } else if (ctl->cmd == TSKM_SVC_CMD_RESERVE) { + tskmRet = tskm_svcReserveRequest(p_main, svcId); + + } else { + return TSKM_E_PAR; + } + + ERROR: return tskmRet; +} + +/** + * Get service info + * @param svcId service id + * @param svcInfo[O] service info + * @return TSKM_E_OK Succeeded + * @return other Failed + */ +TSKM_ERR_t TSKM_SvcGetInfo(TSKM_SVCID_t svcId, TSKM_SVC_INFO_t* svcInfo) { +// Do not LOG acquisition APIs TSKM_PRINTF(TSKM_LOG_API,"%s()",__FUNCTION__) + + TSKM_MAIN_CTX_t* p_main = tskm_getMainCtx(); + TSKM_SVC_CTX_t* p_svc = tskm_svcsGetSvcBySvcId(&p_main->svcs, svcId); + + if (p_svc == NULL || svcInfo == NULL) { + return TSKM_E_PAR; + } + + svcInfo->svcId = p_svc->attr->svcId; + svcInfo->isExecDisable = + (p_svc->state == TSKM_SVC_DISABLE) ? TSKM_TRUE : TSKM_FALSE; + + return TSKM_E_OK; +} + +RPC_Result _TSKM_ErrorReboot(const TSKM_ERROR_REBOOT_t* p_info) { + RPC_Result rpcRet = RPC_OK; + TSKM_ERROR_REBOOT_t rebootInfo; + + if (!p_info || (p_info->type != TSKM_ERROR_REBOOT_NORMAL)) { + TSKM_ASSERT(0); + return RPC_ERR_Fatal; + } + + memset(&rebootInfo, 0, sizeof(TSKM_ERROR_REBOOT_t)); + rebootInfo.type = p_info->type; + snprintf(rebootInfo.log.messageStr, TSKM_LOGGING_MSG_STR_SIZE, "%s", + p_info->log.messageStr); + + TSKM_PRINTF(TSKM_LOG_API, "%s(%d)", __FUNCTION__, p_info->type); + + tskm_sub_reboot(&rebootInfo); + + return rpcRet; +} + +/** + * Reboot service + * @param p_rsv Reserved + * @return TSKM_E_OK Succeeded + * @return other Failed + */ +TSKM_ERR_t TSKM_Reboot(const TSKM_RSV_t * p_rsv) { + TSKM_ERR_t tskmRet = TSKM_E_OK; + + TSKM_PRINTF(TSKM_LOG_API, "%s()", __FUNCTION__) + if (p_rsv != NULL) { + TSKM_ASSERT(0); + return TSKM_E_PAR; + } + + tskm_sub_reboot_normal(); + + return tskmRet; +} + +/** + * Save LOGs + * @param p_info LOG storage info + * @return TSKM_E_OK Succeeded + * @return other Failed + */ +TSKM_ERR_t TSKM_Logging(const TSKM_LOGGING_INFO_t* p_info) { + TSKM_LOGGING_INFO_t logInfo; + TSKM_PRINTF(TSKM_LOG_API, "%s()", __FUNCTION__) + + if (!p_info) { + TSKM_ASSERT(0); + return TSKM_E_PAR; + } else { + switch (p_info->type) { + case TSKM_LOGGING_TYPE_MODULE_LOGS: + case TSKM_LOGGING_TYPE_GRP_RELAUNCH: + break; + default: + TSKM_ASSERT(0); + return TSKM_E_PAR; + } + } + + logInfo.type = p_info->type; + snprintf(logInfo.messageStr, TSKM_LOGGING_MSG_STR_SIZE, "%s", + p_info->messageStr); + + tskm_sub_logging(&logInfo); + + return TSKM_E_OK; +} + +TSKM_ERR_t TSKM_SetWakeupOrder(const TSKM_WAKEUP_ORDER_t* p_order) { + TSKM_ERR_t tskmRet = TSKM_E_OK; + + TSKM_PRINTF(TSKM_LOG_API, "%s()", __FUNCTION__) + + if (p_order == NULL) { + return TSKM_E_PAR; + } + + if (strnlen(p_order->orderName, TSKM_ORDER_NAME_MAX) >= TSKM_ORDER_NAME_MAX) { + return TSKM_E_PAR; + } + + if (tskm_sub_setWakeupOrder(p_order->orderName) != 0) { + TSKM_ASSERT(0); + tskmRet = TSKM_E_NG; + } + + return tskmRet; +} // LCOV_EXCL_BR_LINE 10: Final line + diff --git a/systemservice/task_manager/server/src/tskm_comm.cpp b/systemservice/task_manager/server/src/tskm_comm.cpp new file mode 100755 index 0000000..b177b9b --- /dev/null +++ b/systemservice/task_manager/server/src/tskm_comm.cpp @@ -0,0 +1,402 @@ +/* + * @copyright Copyright (c) 2016-2020 TOYOTA MOTOR CORPORATION. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef _GNU_SOURCE +#warning "_GNU_SOURCE not defined, so define here" +#define _GNU_SOURCE +#endif +#include "tskm_comm.h" +#include +#include +#include +#include +#include +#include + +#include + +#include "tskm_debug.h" +#include "tskm_util.h" + + +/********************************************************** + * Internal functions + **********************************************************/ +TSKM_STATIC TSKM_SRV_CONNENT_t* +addConnFd(TSKM_SRV_CONNENT_LIST_t* list, TSKM_SRV_CONNENT_t* conn) { + TSKM_SRV_CONNENT_t* retConn; + if (list->num >= TSKM_COMM_CONNECT_MAX) { + TSKM_ASSERT(0) + return NULL; + } + + retConn = &list->conn[list->num]; + list->conn[list->num] = *conn; + list->num++; + return retConn; +} + +TSKM_STATIC void delConnFd(TSKM_SRV_CONNENT_LIST_t* list, + TSKM_SRV_CONNENT_t* conn) { + uint32_t ii; + TSKM_BOOL_t isFind = TSKM_FALSE; + for (ii = 0; ii < list->num; ii++) { + if (!isFind && list->conn[ii].connFd == conn->connFd) { + isFind = TSKM_TRUE; + list->num--; + } + + if (isFind && (ii < list->num)) { + list->conn[ii] = list->conn[ii + 1]; + } + } + TSKM_ASSERT(isFind); +} + +/********************************************************** + * Public functions + **********************************************************/ +TSKM_ERR_t tskm_srvSockCreate(const char *sockName, + TSKM_SRV_SOCK_CTX_t* p_sock) { + int fd = -1; + int ret; + int sockRet; + int enable = 1; + int listenNum = TSKM_COMM_CONNECT_MAX; + + struct sockaddr_un unix_addr = { }; + + fd = socket(AF_UNIX, SOCK_SEQPACKET, 0); + if (fd < 0) { // LCOV_EXCL_BR_LINE 5: For processing initializing process + // LCOV_EXCL_START 5: For processing initializing process + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + TSKM_ASSERT_ERRNO(0); + goto ERROR; + // LCOV_EXCL_STOP + } + + if (0 == access(sockName, F_OK)) { // LCOV_EXCL_BR_LINE 5: For processing initializing process + TSKM_ASSERT(0); + unlink(sockName); + } + + unix_addr.sun_family = AF_UNIX; + strncpy(unix_addr.sun_path, sockName, sizeof(unix_addr.sun_path) - 1); + + sockRet = bind(fd, (struct sockaddr *) &unix_addr, sizeof(unix_addr)); + if (sockRet != 0) { // LCOV_EXCL_BR_LINE 5: For processing initializing process + // LCOV_EXCL_START 5: For processing initializing process + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + TSKM_ASSERT_ERRNO(0); + goto ERROR; + // LCOV_EXCL_STOP + } + + ret = chmod(sockName, S_IRUSR | S_IWUSR | S_IROTH | S_IWOTH); + if (ret != 0) { // LCOV_EXCL_BR_LINE 5: For processing initializing process + // LCOV_EXCL_START 5: For processing initializing process + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + TSKM_ASSERT_ERRNO(0); + goto ERROR; + // LCOV_EXCL_STOP + } + + sockRet = setsockopt(fd, SOL_SOCKET, SO_PASSCRED, &enable, sizeof(enable)); + if (sockRet != 0) { // LCOV_EXCL_BR_LINE 5:For processing initializing process + // LCOV_EXCL_START 5: For processing initializing process + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + TSKM_ASSERT_ERRNO(0); + goto ERROR; + // LCOV_EXCL_STOP + } + + sockRet = listen(fd, listenNum); + if (sockRet != 0) { // LCOV_EXCL_BR_LINE 5: For process initialization processing + // LCOV_EXCL_START 5: For process initialization processing + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + TSKM_ASSERT_ERRNO(0); + goto ERROR; + // LCOV_EXCL_STOP + } + + memset(p_sock, 0, sizeof(*p_sock)); + p_sock->sockFd = fd; + p_sock->sockName = sockName; + + return TSKM_E_OK; + // LCOV_EXCL_START 5: For process initialization processing + ERROR: + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + if (fd != -1) { + close(fd); + } + return TSKM_E_NG; + // LCOV_EXCL_STOP +} + +TSKM_SRV_CONNENT_t* +tskm_srvSockConnect(TSKM_SRV_SOCK_CTX_t* p_sock) { + int fd = -1; + socklen_t len; + int sockRet; + TSKM_SRV_CONNENT_t conn; + TSKM_SRV_CONNENT_t *retConn; + struct ucred credent; + struct sockaddr_un unix_addr; + + memset(&conn, 0, sizeof(conn)); + conn.connFd = -1; + + len = sizeof(unix_addr); + fd = accept(p_sock->sockFd, (struct sockaddr*) &unix_addr, + (socklen_t *) &len); // NOLINT (readability/casting) + if (fd < 0) { // LCOV_EXCL_BR_LINE 5: Accept's Error-Handling Process + // LCOV_EXCL_START 5: Accept's Error-Handling Process + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + TSKM_ASSERT_ERRNO(0); + goto ERROR; + // LCOV_EXCL_STOP + } + conn.connFd = fd; + + len = sizeof(credent); + sockRet = getsockopt(fd, SOL_SOCKET, SO_PEERCRED, &credent, &len); + if (sockRet != 0) { // LCOV_EXCL_BR_LINE 5: Getsockopt's Error-Handling Process + // LCOV_EXCL_START 5: Getsockopt's Error-Handling Process + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + TSKM_ASSERT_ERRNO(0); + goto ERROR; + // LCOV_EXCL_STOP + } + conn.pid = credent.pid; + + retConn = addConnFd(&p_sock->connList, &conn); + if (retConn == NULL) { // LCOV_EXCL_BR_LINE 5: Connect's Error-Handling Process + // LCOV_EXCL_START 5: Connect's Error-Handling Process + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + TSKM_ASSERT(0); + goto ERROR; + // LCOV_EXCL_STOP + } + return retConn; + // LCOV_EXCL_START 5: Error-Handling Process + ERROR: + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + if (conn.connFd != -1) { + tskm_sockDestory(conn.connFd); + } + return NULL; + // LCOV_EXCL_STOP +} + +void tskm_srvSockDisconnect(TSKM_SRV_SOCK_CTX_t* p_sock, + TSKM_SRV_CONNENT_t *p_conn) { + int fd = p_conn->connFd; + delConnFd(&p_sock->connList, p_conn); + tskm_sockDestory(fd); +} + +void tskm_srvSockDestory(TSKM_SRV_SOCK_CTX_t* p_sock) { // LCOV_EXCL_START 6: Because the condition cannot be set + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + if (p_sock->sockFd) { + tskm_sockDestory(p_sock->sockFd); + p_sock->sockFd = 0; + + TSKM_ASSERT_ERRNO(0 == unlink(p_sock->sockName)); + } +} +// LCOV_EXCL_STOP +int tskm_cliSockConnect(const char* sockName) { + int fd = -1; + int sockRet; + struct sockaddr_un unix_addr = { }; + + /* Create socket */ + fd = socket(AF_UNIX, SOCK_SEQPACKET, 0); + if (fd < 0) { // LCOV_EXCL_BR_LINE 5: Checked in Death testing, but it is not reflected in the coverage and excluded + // LCOV_EXCL_START 5: Checked in 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 + } + + unix_addr.sun_family = AF_UNIX; + strncpy(unix_addr.sun_path, sockName, sizeof(unix_addr.sun_path) - 1); + sockRet = connect(fd, (struct sockaddr*) &unix_addr, sizeof(unix_addr)); + if (sockRet < 0) { // LCOV_EXCL_BR_LINE 5: Checked in Death testing, but it is not reflected in the coverage and excluded + // LCOV_EXCL_START 5: Checked in 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 fd; + // LCOV_EXCL_START 5: Checked in Death testing, but it is not reflected in the coverage and excluded + ERROR: + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + if (fd != -1) { + TSKM_ASSERT_ERRNO(0 == close(fd)); + } + return -1; + // LCOV_EXCL_STOP +} + +int tskm_sockRcv(int fd, TSKM_EVENT_INFO_t* p_ev) { + int ret; + TSKM_EVENT_INFO_t ev; + ret = static_cast(recv(fd, &ev, sizeof(ev), 0)); + + // LCOV_EXCL_BR_START 5: Checked in Death testing, but it is not reflected in the coverage and excluded + if (ret > (int) sizeof(ev)) { // NOLINT (readability/casting) + // LCOV_EXCL_BR_STOP + // LCOV_EXCL_START 5: Checked in 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 + } + + if (ret < 0) { // LCOV_EXCL_BR_LINE 5: Checked in Death testing, but it is not reflected in the coverage and excluded + // LCOV_EXCL_START 5: Checked in 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 + } + if (ret > 0) { // LCOV_EXCL_BR_LINE 5: Checked in Death testing, but it is not reflected in the coverage and excluded + TSKM_PRINTF(TSKM_LOG_MSG, "recv:%s from:%d ret:%d", + tskm_convEvent2Str(ev.event), ev.fromPid, ret); + } + + *p_ev = ev; + + if (p_ev->hasExtend && (0 != p_ev->extendSize)) { + TSKM_PRINTF(TSKM_LOG_MSG, "rcv:ex(%d) ", p_ev->extendSize); + + p_ev->extendPrm = malloc(p_ev->extendSize); + if (!p_ev->extendPrm) { // LCOV_EXCL_BR_LINE 5: Checked in Death testing, but it is not reflected in the coverage and excluded + // LCOV_EXCL_START 5: Checked in 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 + } + + ret = static_cast(recv(fd, p_ev->extendPrm, p_ev->extendSize, 0)); + + // LCOV_EXCL_BR_START 5: Checked in Death testing, but it is not reflected in the coverage and excluded + if (ret > (int) p_ev->extendSize) { // NOLINT (readability/casting) + // LCOV_EXCL_BR_STOP + // LCOV_EXCL_START 5: Checked in 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 + } + + if (ret < 0) { // LCOV_EXCL_BR_LINE 5: Checked in Death testing, but it is not reflected in the coverage and excluded + // LCOV_EXCL_START 5: Checked in 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 ret; + + // LCOV_EXCL_START 5: Checked in Death testing, but it is not reflected in the coverage and excluded + ERROR: + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + return -1; + // LCOV_EXCL_STOP +} + +int tskm_sockSend(int fd, TSKM_EVENT_INFO_t* p_ev) { + int ret; + p_ev->fromPid = getpid(); + TSKM_PRINTF(TSKM_LOG_MSG, "send:%s ", tskm_convEvent2Str(p_ev->event)); + ret = static_cast(send(fd, p_ev, sizeof(*p_ev), MSG_NOSIGNAL)); + if (ret != sizeof(*p_ev)) { + TSKM_ASSERT_ERRNO(0); + goto ERROR; + } + // Because it is entered only when called from a debugging function (pri_sendDebugDumpRes) + if (p_ev->hasExtend && p_ev->extendPrm && (0 != p_ev->extendSize)) { + TSKM_PRINTF(TSKM_LOG_MSG, "send:ex(%d) ", p_ev->extendSize); + + ret = static_cast(send(fd, p_ev->extendPrm, p_ev->extendSize, MSG_NOSIGNAL)); + if (ret != (int)p_ev->extendSize) { // NOLINT (readability/casting) + TSKM_ASSERT_ERRNO(0); + goto ERROR; + } + } + + return ret; + + ERROR: return -1; +} + +void tskm_sockDestory(int fd) { + TSKM_ASSERT_ERRNO(0 == shutdown(fd, SHUT_RDWR)); + TSKM_ASSERT_ERRNO(0 == close(fd)); +} + +/****************************************************************** + * Initializing (Process) + ******************************************************************/ +int tskm_comm_procInit(void) { + int ret; + + ret = CL_MonitorInit(CL_MONITOR_INIT_USER); + + if (ret != 0) { + TSKM_ASSERT_ERRNO(0); + goto ERROR; + } + + return 0; + + // LCOV_EXCL_START 5: Checked in Death testing, but it is not reflected in the coverage and excluded + ERROR: + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + return -1; + // LCOV_EXCL_STOP +} + +/********************************************************* + * Service Error Monitoring Status Setting + *********************************************************/ +int tskm_comm_setSvcWatchState(uint32_t id, BOOL bIsRun, uint32_t timeout) { + int ret = 0; + + CL_MonitorState_t state = CL_MONITOR_STATE_SLEEP; + + if (bIsRun) { + state = CL_MONITOR_STATE_RUN; + } + + ret = CL_MonitorSetEntry(CL_MONITOR_TYPE_GENERIC, id, state, timeout, 0); + if (0 != ret) { + TSKM_ASSERT_ERRNO(0); + goto ERROR; + } + + return 0; + ERROR: return -1; +} // LCOV_EXCL_BR_LINE 10: Final line + diff --git a/systemservice/task_manager/server/src/tskm_debug.cpp b/systemservice/task_manager/server/src/tskm_debug.cpp new file mode 100755 index 0000000..5881f9a --- /dev/null +++ b/systemservice/task_manager/server/src/tskm_debug.cpp @@ -0,0 +1,286 @@ +/* + * @copyright Copyright (c) 2016-2020 TOYOTA MOTOR CORPORATION. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "tskm_debug.h" + +const char* +tskm_convState2Str(TSKM_STATE_t state) { + const char* ret = "UNKNONW"; + switch (state) { // LCOV_EXCL_BR_LINE 7:debug code + case TSKM_ST_ACCOFF: + ret = "ACCOFF"; + break; + case TSKM_ST_ACCON: + ret = "ACCON"; + break; + case TSKM_ST_WAKEUP: + ret = "WAKEUP"; + break; + case TSKM_ST_RUNNING: + ret = "RUNNING"; + break; + case TSKM_ST_DOWN: + ret = "DOWN"; + break; + } + return ret; +} + +const char* +tskm_convEvent2Str(TSKM_EVENT_t event) { + switch (event) { // LCOV_EXCL_BR_LINE 7:debug code + case TSKM_EV_NOP: + return "NOP"; + case TSKM_EV_PRI_REQ_WAKEUP: + // LCOV_EXCL_START 7:debug code + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + return "PRI_REQ_WAKEUP"; + // LCOV_EXCL_STOP + case TSKM_EV_PRI_REQ_DOWN: + // LCOV_EXCL_START 7:debug code + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + return "PRI_REQ_DOWN"; + // LCOV_EXCL_STOP + case TSKM_EV_PRI_REQ_TOUCH: + // LCOV_EXCL_START 7:debug code + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + return "PRI_REQ_TOUCH"; + // LCOV_EXCL_STOP + case TSKM_EV_PRI_REQ_DEBUGDUMP: + // LCOV_EXCL_START 7:debug code + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + return "PRI_REQ_DEBUGDUMP"; + // LCOV_EXCL_STOP + case TSKM_EV_PRI_REP_LOWMEM: + // LCOV_EXCL_START 7:debug code + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + return "PRI_REP_LOWMEM"; + // LCOV_EXCL_STOP + case TSKM_EV_PRI_REP_WAKEUP_COMP: + return "PRI_REP_WAKEUP_COMP"; + case TSKM_EV_PRI_REP_DOWN_COMP: + // LCOV_EXCL_START 7:debug code + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + return "PRI_REP_DOWN_COMP"; + // LCOV_EXCL_STOP + case TSKM_EV_PRI_REP_CONNECT: + // LCOV_EXCL_START 7:debug code + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + return "PRI_REP_CONNECT"; + // LCOV_EXCL_STOP + case TSKM_EV_PRI_REP_DISCONNECT: + return "PRI_REP_DISCONNECT"; + case TSKM_EV_PRI_RES_WAKEUP: + // LCOV_EXCL_START 7:debug code + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + return "PRI_RES_WAKEUP"; + // LCOV_EXCL_STOP + case TSKM_EV_PRI_RES_DOWN: + return "PRI_RES_DOWN"; + case TSKM_EV_PRI_RES_DEBUGDUMP: + // LCOV_EXCL_START 7:debug code + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + return "PRI_RES_DEBUGDUMP"; + // LCOV_EXCL_STOP + case TSKM_EV_PRI_REQ_EXIT: + // LCOV_EXCL_START 7:debug code + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + return "PRI_REQ_EXIT"; + // LCOV_EXCL_STOP + case TSKM_EV_SVC_REP_TERM: + return "SVC_REP_TERM"; + case TSKM_EV_API_REQ_REBOOT: + // LCOV_EXCL_START 7:debug code + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + return "API_REQ_REBOOT"; + // LCOV_EXCL_STOP + case TSKM_EV_API_REQ_SVC_CTL: + // LCOV_EXCL_START 7:debug code + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + return "API_REQ_SVC_CTL"; + // LCOV_EXCL_STOP + case TSKM_EV_API_REQ_SVC_DISABLE: + // LCOV_EXCL_START 7:debug code + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + return "API_REQ_SVC_DISABLE"; + // LCOV_EXCL_STOP + case TSKM_EV_LCL_REQ_STOP: + return "API_REQ_STOP"; + case TSKM_EV_LCL_CHG_SVC_STATE: + return "LCL_CHG_SVC_STATE"; + case TSKM_EV_LCL_REQ_SDUMP: + // LCOV_EXCL_START 7:debug code + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + return "LCL_REQ_SDUMP"; + // LCOV_EXCL_STOP + case TSKM_EV_LCL_REP_TIMEOUT: + // LCOV_EXCL_START 7:debug code + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + return "LCL_REP_TIMEOUT"; + // LCOV_EXCL_STOP + case TSKM_EV_LCL_REP_POLLING: + // LCOV_EXCL_START 7:debug code + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + return "LCL_REP_POLLING"; + // LCOV_EXCL_STOP + case TSKM_EV_LCL_REP_LOWMEM: + // LCOV_EXCL_START 7:debug code + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + return "LCL_REP_LOWMEM"; + // LCOV_EXCL_STOP + case TSKM_EV_LCL_REQ_TRANS_STEP: + // LCOV_EXCL_START 7:debug code + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + return "LCL_REQ_TRANS_STEP"; + // LCOV_EXCL_STOP + default: + break; + } + // LCOV_EXCL_START 7:debug code + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + return "UNKNOWN"; + // LCOV_EXCL_STOP +} + +const char* +tskm_convInitCompId2Str(uint64_t compId) { + switch (compId) { // LCOV_EXCL_BR_LINE 7:debug code + case INI_INITCOMP_NONE: + return "NONE"; + case INI_INITCOMP_ON_START: + return "ONSTART"; + case INI_INITCOMP_NVM_ACCESS: + return "NVM_ACCESS"; + case INI_INITCOMP_TEST0: + // LCOV_EXCL_START 7:debug code + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + return "TEST0"; + // LCOV_EXCL_STOP + case INI_INITCOMP_TEST1: + // LCOV_EXCL_START 7:debug code + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + return "TEST1"; + // LCOV_EXCL_STOP + case INI_INITCOMP_TEST2: + // LCOV_EXCL_START 7:debug code + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + return "TEST2"; + // LCOV_EXCL_STOP + case INI_INITCOMP_TEST3: + // LCOV_EXCL_START 7:debug code + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + return "TEST3"; + // LCOV_EXCL_STOP + } + // LCOV_EXCL_START 7:debug code + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + return "UNKNONW"; + // LCOV_EXCL_STOP +} + +const char* +tskm_convTermCompId2Str(uint64_t compId) { + switch (compId) { // LCOV_EXCL_BR_LINE 7:debug code + case INI_TERMCOMP_NONE: + return "NONE"; + case INI_TERMCOMP_ACTIVITYMGR: + return "ACTIVITYMGR"; + case INI_TERMCOMP_RESIDENT: + return "RESIDENT"; + case INI_TERMCOMP_TRANSIENT: + // LCOV_EXCL_START 7:debug code + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + return "TRANSIENT"; + // LCOV_EXCL_STOP + case INI_TERMCOMP_TEST0: + // LCOV_EXCL_START 7:debug code + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + return "TEST0"; + // LCOV_EXCL_STOP + case INI_TERMCOMP_TEST1: + // LCOV_EXCL_START 7:debug code + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + return "TEST1"; + // LCOV_EXCL_STOP + case INI_TERMCOMP_TEST2: + // LCOV_EXCL_START 7:debug code + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + return "TEST2"; + // LCOV_EXCL_STOP + case INI_TERMCOMP_TEST3: + // LCOV_EXCL_START 7:debug code + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + return "TEST3"; + // LCOV_EXCL_STOP + } + return "UNKNONW"; +} + +const char* +tskm_convSvcState2Str(TSKM_SVC_STATE_t state) { + switch (state) { // LCOV_EXCL_BR_LINE 7:debug code + case TSKM_SVC_DORMANT: + // LCOV_EXCL_START 7:debug code + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + return "DORMANT"; + // LCOV_EXCL_STOP + case TSKM_SVC_WAITCONNECT: + // LCOV_EXCL_START 7:debug code + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + return "WAITCONNECT"; + // LCOV_EXCL_STOP + case TSKM_SVC_WAKEUP: + return "WAKEUP"; + case TSKM_SVC_RUNNING: + // LCOV_EXCL_START 7:debug code + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + return "RUNNING"; + // LCOV_EXCL_STOP + case TSKM_SVC_DOWN: + // LCOV_EXCL_START 7:debug code + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + return "DOWN"; + // LCOV_EXCL_STOP + case TSKM_SVC_FINDOWN: + // LCOV_EXCL_START 7:debug code + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + return "FINDOWN"; + // LCOV_EXCL_STOP + case TSKM_SVC_DISABLE: + // LCOV_EXCL_START 7:debug code + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + return "DISABLE"; + // LCOV_EXCL_STOP + default: + break; + } + return "UNKNONW"; +} + +TSKM_STATIC void svcDump(TSKM_SVC_CTX_t* p_svc) { + TSKM_PRINTF(TSKM_LOG_STATE, "<%s>", p_svc->attr->name); + TSKM_PRINTF(TSKM_LOG_STATE, " pid:%d svcId:%#x state:%s waitResCnt:%d", + p_svc->pid, p_svc->attr->svcId, + tskm_convSvcState2Str(p_svc->state), p_svc->waitResCnt); +} + +void tskm_svcsDump(TSKM_SVCS_CTX_t* p_svcs) { + uint32_t ii; + for (ii = 0; ii < p_svcs->svcNum; ii++) { + svcDump(&p_svcs->svcList[ii]); + } +} + diff --git a/systemservice/task_manager/server/src/tskm_main.cpp b/systemservice/task_manager/server/src/tskm_main.cpp new file mode 100755 index 0000000..33c10fa --- /dev/null +++ b/systemservice/task_manager/server/src/tskm_main.cpp @@ -0,0 +1,727 @@ +/* + * @copyright Copyright (c) 2016-2020 TOYOTA MOTOR CORPORATION. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "tskm_main.h" +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "tskm_data_init_local.h" +#include "tskm_port_pf.h" +#include "tskm_port_subsys.h" +#include "tskm_debug.h" +#include "tskm_util.h" +#include "tskm_srvr.h" +#include "tskm_comm.h" +#include "tskm_watch.h" +#include "system_service/tskm_local_type.h" +#include "system_service/tskm_xml_data.h" +#include "tskm_state.h" + +#define TSKM_DATA_KEY "TSKM_KEY" + +TSKM_STATIC TSKM_MAIN_CTX_t g_mainCtx; // Main context + +TSKM_STATIC BOOL s_isVupMode = FALSE; + +CFrameworkunifiedVersion g_FrameworkunifiedVersion(MAJORNO, MINORNO, REVISION); + +// For NsLog +FRAMEWORKUNIFIEDLOGPARAM g_FrameworkunifiedLogParams = { +FRAMEWORKUNIFIEDLOGOPTIONS, { +ZONE_TEXT_10, ZONE_TEXT_11, ZONE_TEXT_12, +ZONE_TEXT_13, ZONE_TEXT_14, ZONE_TEXT_15, +ZONE_TEXT_16, ZONE_TEXT_17, ZONE_TEXT_18, +ZONE_TEXT_19, ZONE_TEXT_20, ZONE_TEXT_21, +ZONE_TEXT_22, ZONE_TEXT_23, ZONE_TEXT_24, +ZONE_TEXT_25, ZONE_TEXT_26, ZONE_TEXT_27, +ZONE_TEXT_28, ZONE_TEXT_29, ZONE_TEXT_30, +ZONE_TEXT_31 }, FRAMEWORKUNIFIEDLOGZONES }; + +EFrameworkunifiedStatus OnFinishLoadFile(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; + + int ret; + TSKM_MAIN_CTX_t* p_main = &g_mainCtx; + TSKM_EVENT_INFO_t ev; + + ret = tskm_pf_nvFileRead(hApp, &p_main->nvInfo); + if (ret != 0) { + TSKM_ASSERT(0); + } + + // issure INI_INITCOMP_NVM_ACCESS + bzero(&ev, sizeof(ev)); + ev.event = TSKM_EV_PRI_REP_WAKEUP_COMP; + ev.errCode = TSKM_E_OK; + ev.prm.repWakeupComp.compId = INI_INITCOMP_NVM_ACCESS; + tskm_handleEvent(p_main, &ev); + + return l_eStatus; +} +// LCOV_EXCL_STOP + +EFrameworkunifiedStatus onDataInitRequest(HANDLE hApp) { + TSKM_ERR_t l_tskmRet = TSKM_E_OK; + EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK; + TSKM_MAIN_CTX_t* p_main = tskm_getMainCtx(); + + TSKM_PRINTF(TSKM_LOG_API, "%s()", __FUNCTION__) + + if (p_main->bootInfo.startupReason == epswfINVALID) { + // Before issuing FrameworkunifiedOnStart = Requests before TaskManager became Availabile are not accepted + TSKM_ASSERT(0); + l_tskmRet = TSKM_E_STATE; + } else { + T_SS_SM_START_DataStructType bootInfo(epswfIGN_ACC, TRUE, + e_SS_SM_DATA_RESET_MODE_USER, + epsssUNLOCK, epsstWARMSTART, + e_SS_SM_DRAM_BACKUP_OK, + e_SS_SM_RESET_STATUS_NONE, 0); + + T_SS_SM_START_ExtDataStructType extBootInfo; + + memcpy(&extBootInfo, &p_main->extBootInfo, sizeof(extBootInfo)); + + // After updating the program, + // FALSE is notified here because it is notified when data initialization I/F is called at startup + extBootInfo.isProgUpdated = FALSE; + + tskm_dataInitAll(&bootInfo, &extBootInfo); + } + + PCSTR l_senderName = FrameworkunifiedGetMsgSrc(hApp); + if (NULL != l_senderName) { + HANDLE hSession = FrameworkunifiedMcOpenSender(hApp, l_senderName); + if (hSession == NULL) { + TSKM_ASSERT(0); + } else { + TSKM_ASSERT( + eFrameworkunifiedStatusOK + == FrameworkunifiedSendMsg(hSession, TSKM_DATAINIT_RESP, sizeof(l_tskmRet), + &l_tskmRet)); + TSKM_ASSERT(eFrameworkunifiedStatusOK == FrameworkunifiedMcClose(hSession)); + } + } + + return l_eStatus; +} + +EFrameworkunifiedStatus onTransStepRequest(HANDLE hApp) { // LCOV_EXCL_START 6:Because the condition cannot be set + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + TSKM_MAIN_CTX_t* p_main = &g_mainCtx; + EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK; + + TSKM_EVENT_INFO_t ev; + bzero(&ev, sizeof(ev)); + + ev.event = TSKM_EV_LCL_REQ_TRANS_STEP; + ev.errCode = TSKM_E_OK; + tskm_handleEvent(p_main, &ev); + + return l_eStatus; +} +// LCOV_EXCL_STOP + +EFrameworkunifiedStatus OnResmAvailability(HANDLE hApp) { // LCOV_EXCL_START 6: Because the condition cannot be set + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + TSKM_MAIN_CTX_t* p_main = &g_mainCtx; + + if (0 != strcmp(NTFY_ResourceMgr_Availability, FrameworkunifiedGetLastNotification(hApp))) { + TSKM_ASSERT(0); + } else if (FrameworkunifiedIsServiceAvailable(hApp)) { + // Availability = TRUE + + p_main->resmFd = tskm_sub_resmInit(); + if (-1 == p_main->resmFd) { + TSKM_ASSERT(0); + } + } + return eFrameworkunifiedStatusOK; +} +// LCOV_EXCL_STOP + +//************ NS Framework Callback : must implemet ****************** +EFrameworkunifiedStatus FrameworkunifiedOnInitialization(HANDLE hApp) { + EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK; + TSKM_PRINTF(TSKM_LOG_STATE, "+"); + + l_eStatus = FrameworkunifiedRegisterServiceAvailabilityNotification(hApp, NTFY_SS_TaskManager_Availability); + if (eFrameworkunifiedStatusOK != l_eStatus) { + TSKM_ASSERT(0); + } + + l_eStatus = FrameworkunifiedPublishServiceAvailability(hApp, FALSE); + if (eFrameworkunifiedStatusOK != l_eStatus) { + TSKM_ASSERT(0); + } + + l_eStatus = FrameworkunifiedAttachCallbackToDispatcher(hApp, FRAMEWORKUNIFIED_NS_NPSERVICE, + NPS_GET_PERS_FILE_ACK, + OnFinishLoadFile); + if (eFrameworkunifiedStatusOK != l_eStatus) { + TSKM_ASSERT(0); + } + + l_eStatus = FrameworkunifiedAttachCallbackToDispatcher(hApp, FRAMEWORKUNIFIED_ANY_SOURCE, + TSKM_DATAINIT_REQ, + onDataInitRequest); + if (eFrameworkunifiedStatusOK != l_eStatus) { + TSKM_ASSERT(0); + } + + l_eStatus = FrameworkunifiedAttachCallbackToDispatcher(hApp, FrameworkunifiedGetAppName(hApp), + TSKM_TRANS_STEP_REQ, + onTransStepRequest); + if (eFrameworkunifiedStatusOK != l_eStatus) { + TSKM_ASSERT(0); + } + + l_eStatus = FrameworkunifiedSubscribeNotificationWithCallback(hApp, NTFY_ResourceMgr_Availability, OnResmAvailability); + if (eFrameworkunifiedStatusOK != l_eStatus) { + TSKM_ASSERT(0); + } + + TSKM_PRINTF(TSKM_LOG_STATE, "-"); + + return l_eStatus; +} + +EFrameworkunifiedStatus FrameworkunifiedOnStart(HANDLE hApp) { + EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK; + TSKM_PRINTF(TSKM_LOG_STATE, "+"); + l_eStatus = OnStart(hApp); + TSKM_PRINTF(TSKM_LOG_STATE, "-"); + return l_eStatus; +} + +EFrameworkunifiedStatus FrameworkunifiedOnPreStart(HANDLE hApp) { + EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK; + TSKM_PRINTF(TSKM_LOG_STATE, "+"); + l_eStatus = OnStart(hApp); + TSKM_PRINTF(TSKM_LOG_STATE, "-"); + return l_eStatus; +} + +EFrameworkunifiedStatus FrameworkunifiedOnBackgroundStart(HANDLE hApp) { + EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK; + TSKM_PRINTF(TSKM_LOG_STATE, "+"); + l_eStatus = OnStart(hApp); + TSKM_PRINTF(TSKM_LOG_STATE, "-"); + return l_eStatus; +} + +EFrameworkunifiedStatus FrameworkunifiedOnStop(HANDLE hApp) { + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+"); + TSKM_MAIN_CTX_t* p_main = &g_mainCtx; + // Returns Fail to send asynchronous STOP reply to SM + EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusFail; + + TSKM_EVENT_INFO_t ev; + bzero(&ev, sizeof(ev)); + + ev.event = TSKM_EV_LCL_REQ_STOP; + ev.errCode = TSKM_E_OK; + tskm_handleEvent(p_main, &ev); + + p_main->isOnStopDone = TSKM_TRUE; + + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-"); + return l_eStatus; +} + +EFrameworkunifiedStatus FrameworkunifiedOnPreStop(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 FrameworkunifiedOnDestroy(HANDLE hApp) { + EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK; + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+"); + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-"); + return l_eStatus; +} + +EFrameworkunifiedStatus FrameworkunifiedOnDebugDump(HANDLE hApp) { + EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK; + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+"); + TSKM_MAIN_CTX_t* p_main = &g_mainCtx; + TSKM_ERR_t l_tskmRet; + + // Call DebugDump of all running SVCs + l_tskmRet = tskm_svcsCallDebugDump(&p_main->svcs); + if (TSKM_E_OK != l_tskmRet) { + TSKM_ASSERT(0); + } + + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-"); + return l_eStatus; +} + +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 + +/********************************************************* + * System start process + *********************************************************/ +EFrameworkunifiedStatus OnStart(const HANDLE hApp) { + TSKM_PRINTF(TSKM_LOG_STATE, "+"); + TSKM_MAIN_CTX_t* const p_main = &g_mainCtx; + EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK; + + if (p_main->isOnStartDone == TSKM_FALSE) { + T_SS_SM_START_DataStructType startupInfo; + TSKM_EVENT_INFO_t ev; + l_eStatus = ReadMsg(hApp, startupInfo); + if (l_eStatus != eFrameworkunifiedStatusOK) { + TSKM_ASSERT(0); + } else { + memcpy(&p_main->bootInfo, &startupInfo, sizeof(T_SS_SM_START_DataStructType)); + } + + if (0 != tskm_sub_getExtBootInfo(&p_main->extBootInfo)) { + TSKM_ASSERT(0); + } + + tskm_dataInitAll(&p_main->bootInfo, &p_main->extBootInfo); + + tskm_svcsSetBootInfo(&p_main->svcs, &p_main->bootInfo, &p_main->extBootInfo); + p_main->isOnStartDone = TSKM_TRUE; + + l_eStatus = FrameworkunifiedPublishServiceAvailability(hApp, TRUE); + if (l_eStatus != eFrameworkunifiedStatusOK) { + TSKM_ASSERT(0); + } else { + TSKM_PRINTF(TSKM_LOG_STATE, "Availability TRUE"); + } + + // Issure INI_INITCOMP_ON_START + bzero(&ev, sizeof(ev)); + ev.event = TSKM_EV_PRI_REP_WAKEUP_COMP; + ev.errCode = TSKM_E_OK; + ev.prm.repWakeupComp.compId = INI_INITCOMP_ON_START; + tskm_handleEvent(p_main, &ev); + } + + TSKM_PRINTF(TSKM_LOG_STATE, "-"); + return l_eStatus; +} + +/********************************************************* + * Argument analysis process + *********************************************************/ +TSKM_STATIC EFrameworkunifiedStatus argParser(SI_32 argument, PCHAR argumentValue) { // LCOV_EXCL_START 6: for process initialization processing + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + if ('v' == argument) { + s_isVupMode = TRUE; + } + + return eFrameworkunifiedStatusOK; +} +// LCOV_EXCL_STOP +/********************************************************* + * Creating process for TSKM internal context + *********************************************************/ +TSKM_STATIC void ctxCreate(TSKM_MAIN_CTX_t* p_main, int argc, char* argv[]) { + int ret; + EFrameworkunifiedStatus taskmanagerRet; + TSKM_ERR_t tskmRet; + FrameworkunifiedDefaultCallbackHandler cbFuncs; + FRAMEWORKUNIFIED_MAKE_DEFAULT_CALLBACK(cbFuncs); + CustomCommandLineOptions cmdLineOpt = { "v", NULL, argParser }; + + p_main->state = TSKM_ST_ACCOFF; + p_main->isOnStartDone = TSKM_FALSE; + + // Create dispatcher + taskmanagerRet = FrameworkunifiedCreateDispatcherWithoutLoop(SS_TASK_MANAGER, p_main->hApp, argc, + argv, &cbFuncs, TRUE, &cmdLineOpt); + if (eFrameworkunifiedStatusOK != taskmanagerRet) { // LCOV_EXCL_BR_LINE 6: For process initialization processing + // LCOV_EXCL_START 6: For process initialization processing + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + TSKM_ASSERT_PRINT(0, "%d", taskmanagerRet); + goto ERROR; + // LCOV_EXCL_STOP + } + + TSKM_PRINTF(TSKM_LOG_STATE, "s_isVupMode :%s", s_isVupMode ? "TRUE" : "FALSE"); + + taskmanagerRet = FrameworkunifiedGetDispatcherFD(p_main->hApp, &p_main->nsFd); + if (taskmanagerRet != eFrameworkunifiedStatusOK) { // LCOV_EXCL_BR_LINE 6: For process initialization processing + // LCOV_EXCL_START 6: For process initialization processing + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + TSKM_ASSERT_PRINT(0, "%d", taskmanagerRet); + exit(EXIT_FAILURE); + // LCOV_EXCL_STOP + } + + p_main->sigFd = tskm_pf_sysInit(); // Platform initialization + if (p_main->sigFd == -1) { // LCOV_EXCL_BR_LINE 6: For process initialization processing + // LCOV_EXCL_LINE 6: For process initialization processing + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + TSKM_ASSERT(0); + goto ERROR; + // LCOV_EXCL_STOP + } + + p_main->iFd = inotify_init1(IN_CLOEXEC); + if (p_main->sigFd == -1) { // LCOV_EXCL_BR_LINE 6: For process initialization processing + // LCOV_EXCL_LINE 6: For process initialization processing + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + TSKM_ASSERT_ERRNO(0); + goto ERROR; + // LCOV_EXCL_STOP + } + + // Obtain RESM FDs after waiting for Availability + p_main->resmFd = -1; + + tskmRet = tskm_srvSockCreate(TSKM_SOCKET_NAME, &p_main->sock); + TSKM_ERR_CHK(tskmRet, TSKM_E_OK, ERROR); // LCOV_EXCL_BR_LINE 6: For process initialization processing + + ret = tskm_pf_nvFileInit(p_main->hApp); + if (ret != 0) { // LCOV_EXCL_BR_LINE 6: For process initialization processing + // LCOV_EXCL_START 6: For process initialization processing + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + TSKM_ASSERT(0); + goto ERROR; + // LCOV_EXCL_STOP + } + + ret = tskm_initServiceList(&p_main->svcs, p_main->iFd); // Service to be started + if (0 != ret) { // LCOV_EXCL_BR_LINE 6: For process initialization processing + // LCOV_EXCL_START 6: For For process initialization process + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + TSKM_ASSERT(0); + goto ERROR; + // LCOV_EXCL_STOP + } + + tskm_initWakeupCtx(&p_main->wakeup, s_isVupMode); // Gradual startup info + tskm_initDownCtx(&p_main->down, s_isVupMode); // Gradual termination info + return; + + // LCOV_EXCL_START 6: For process initialization processing + ERROR: + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + tskm_pf_exit(EXIT_FAILURE); + return; + // LCOV_EXCL_STOP +} + +/********************************************************* + * Get main context + *********************************************************/ +TSKM_MAIN_CTX_t* +tskm_getMainCtx(void) { + return &g_mainCtx; +} + +/********************************************************* + * Process initialization process (MAIN function sub) + *********************************************************/ +int Init_Process(int* rpcFd, int* sockFd, int* maxFd, fd_set* fds, TSKM_MAIN_CTX_t* p_main) { + int ret; + uint32_t ii; + + TSKM_SRV_CONNENT_LIST_t* p_connList = &p_main->sock.connList; + + FD_ZERO(fds); + + FD_SET(*rpcFd, fds); + *maxFd = TSKM_MAX(*rpcFd, *maxFd); // LCOV_EXCL_BR_LINE 6: For process initialization processing + + FD_SET(*sockFd, fds); + *maxFd = TSKM_MAX(*sockFd, *maxFd); // LCOV_EXCL_BR_LINE 6: For process initialization processing + + FD_SET(p_main->nsFd, fds); + *maxFd = TSKM_MAX(p_main->nsFd, *maxFd); // LCOV_EXCL_BR_LINE 6: For process initialization processing + + FD_SET(p_main->sigFd, fds); + *maxFd = TSKM_MAX(p_main->sigFd, *maxFd); // LCOV_EXCL_BR_LINE 6: For process initialization processing + + if (-1 != p_main->resmFd) { // LCOV_EXCL_BR_LINE 6: For process initialization processing + // LCOV_EXCL_START 6: For process initialization processing + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + FD_SET(p_main->resmFd, fds); + *maxFd = TSKM_MAX(p_main->resmFd, *maxFd); + // LCOV_EXCL_STOP + } + + for (ii = 0; ii < p_connList->num; ii++) { // LCOV_EXCL_BR_LINE 6: For process initialization processing + // LCOV_EXCL_START 6: For process initialization processing + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + TSKM_SRV_CONNENT_t* p_conn = &p_connList->conn[ii]; + FD_SET(p_conn->connFd, fds); + *maxFd = TSKM_MAX(p_conn->connFd, *maxFd); + // LCOV_EXCL_STOP + } + + TSKM_PRINTF(TSKM_LOG_FUNC, "SELECT IN"); + ret = select(*maxFd + 1, fds, NULL, NULL, NULL); + if (ret < 1) { + if (errno != EINTR) { + TSKM_ASSERT(0); + } + return ret; + } + TSKM_PRINTF(TSKM_LOG_FUNC, "SELECT OUT"); + return 0; +} + +/********************************************************* + * Receiving Messages from CONNECT Clients (MAIN Functions Sub) + *********************************************************/ +void Recv_Msg_FromConnectClient(fd_set* fds, TSKM_MAIN_CTX_t* p_main) { + uint32_t ii; + TSKM_SRV_CONNENT_LIST_t* p_connList = &p_main->sock.connList; + + // Messages from CONNECT clients + for (ii = 0; ii < p_connList->num; ii++) { + TSKM_SRV_CONNENT_t* p_conn = &p_connList->conn[ii]; + if (FD_ISSET(p_conn->connFd, fds)) { + TSKM_PRINTF(TSKM_LOG_FUNC, "connFd IN"); + TSKM_EVENT_INFO_t ev; + int ret; + ret = tskm_sockRcv(p_conn->connFd, &ev); + + if (ret < 0) { + TSKM_ASSERT(0); + } else { + TSKM_SVC_CTX_t* p_svc; + + if (ret == 0) { + // Closed Connection + TSKM_PRINTF(TSKM_LOG_STATE, "DISSCON pid:%d", p_conn->pid); + ev.event = TSKM_EV_PRI_REP_DISCONNECT; + ev.errCode = TSKM_E_OK; + ev.fromPid = p_conn->pid; + tskm_srvSockDisconnect(&p_main->sock, p_conn); + p_conn = NULL; // If the connection is lost, it cannot be referenced. + } + + p_svc = tskm_svcsGetSvcByPid(&p_main->svcs, ev.fromPid); + if (p_svc) { // Events from service + TSKM_ERR_t tskmRet; + tskmRet = tskm_svcEventHandle(p_svc, &ev); // Service handler + if (tskmRet != TSKM_E_OK) { + TSKM_ASSERT(0); + } + } + if (ev.event != TSKM_EV_NOP) { + tskm_handleEvent(p_main, &ev); // Main handler + } + } + TSKM_PRINTF(TSKM_LOG_FUNC, "connFd OUT"); + } + } +} + +/********************************************************* + * CONNECT Requests (MAIN Functions Sub) + *********************************************************/ +void Recv_Req_Connect(fd_set* fds, TSKM_MAIN_CTX_t* p_main, int sockFd) { + // CONNECT requests + if (FD_ISSET(sockFd, fds)) { + TSKM_PRINTF(TSKM_LOG_FUNC, "sockFd IN"); + + TSKM_SRV_CONNENT_t* conn; + conn = tskm_srvSockConnect(&p_main->sock); + if (conn == NULL) { + TSKM_ASSERT(0); + } else { + TSKM_SVC_CTX_t* p_svc; + TSKM_PRINTF(TSKM_LOG_STATE, "CONNECT pid:%d", conn->pid); + + p_svc = tskm_svcsGetSvcByPid(&p_main->svcs, conn->pid); + if (p_svc) { + TSKM_ERR_t tskmRet; + TSKM_EVENT_INFO_t ev; + + ev.event = TSKM_EV_PRI_REP_CONNECT; + ev.errCode = TSKM_E_OK; + ev.fromPid = conn->pid; + ev.prm.repConnect.connFd = conn->connFd; + + tskmRet = tskm_svcEventHandle(p_svc, &ev); // Service handler + if (tskmRet != TSKM_E_OK) { + TSKM_ASSERT(0); + } else if (ev.event != TSKM_EV_NOP) { + tskm_handleEvent(p_main, &ev); // Main hander + } + } + } + TSKM_PRINTF(TSKM_LOG_FUNC, "sockFd OUT"); + } +} + +/********************************************************* + * MAIN Function + *********************************************************/ +int main(int argc, char* argv[]) { + RPC_ID rpcId = TSKM_RPC_ID; + int rpcFd = 0; + int maxFd = 0; + int ret; + fd_set fds; + TSKM_MAIN_CTX_t* p_main = &g_mainCtx; + + // Logging setting + FRAMEWORKUNIFIED_SET_ZONES(); + + ctxCreate(p_main, argc, argv); // Initialize context + + tskm_sub_init(); // Initialize sub systems + + RPC_START_SECURE_SERVER(rpcId); + RPC_get_fd(rpcId, &rpcFd); + + uid_t uid[2]; + gid_t gid[2]; + + uid[0] = 0; + gid[0] = 0; + uid[1] = getuid(); + gid[1] = getgid(); + + if (RPC_OK != RPC_regist_credential(2, uid, 2, gid)) { // LCOV_EXCL_BR_LINE 6: For process initialization processing + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + TSKM_ASSERT(0); // LCOV_EXCL_LINE 6: For process initialization processing + } + + // Start periodic timer thread + ret = tskm_watch_startTimer(); + if (ret != 0) { // LCOV_EXCL_BR_LINE 6: For process initialization processing + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + TSKM_ASSERT(0); // LCOV_EXCL_LINE 6: For process initialization processing + } + + tskm_stateTransit(p_main, TSKM_ST_ACCOFF, TSKM_ST_ACCON); + + p_main->isExec = TSKM_TRUE; + while (p_main->isExec) { // LCOV_EXCL_BR_LINE 6: For process initialization processing + int sockFd = p_main->sock.sockFd; + + // Initialization processing + if (Init_Process(&rpcFd, &sockFd, &maxFd, &fds, p_main) != 0) { // LCOV_EXCL_BR_LINE 6: For process initialization processing + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + continue; // LCOV_EXCL_LINE 6: For process initialization processing + } + + // RPC API + if (FD_ISSET(rpcFd, &fds)) { + RPC_process_API_request(rpcId); + } + + // Process termination signal + if (FD_ISSET(p_main->sigFd, &fds)) { + int count = 0; + + do { + TSKM_EVENT_INFO_t ev; + ev.event = TSKM_EV_SVC_REP_TERM; + + count++; + + ret = tskm_pf_cleanupProc(p_main->sigFd, &ev.fromPid, &ev.errCode); + if (ret == -1) { + TSKM_ASSERT(0); + break; + } + + TSKM_SVC_CTX_t* p_svc; + + p_svc = tskm_svcsGetSvcByPid(&p_main->svcs, ev.fromPid); + if (p_svc) { + TSKM_ERR_t tskmRet; + + tskmRet = tskm_svcEventHandle(p_svc, &ev); // Service handler + if (tskmRet != TSKM_E_OK) { + TSKM_ASSERT(0); + } + if (ev.event != TSKM_EV_NOP) { + tskm_handleEvent(p_main, &ev); // Main handler + } + } + } while (ret == 1 && count < 50); + } + + if (FD_ISSET(p_main->nsFd, &fds)) { + FrameworkunifiedDispatchProcessWithoutLoop(p_main->hApp); + } + + // EV from RESM + if (-1 != p_main->resmFd) { + if (FD_ISSET(p_main->resmFd, &fds)) { + TSKM_EVENT_INFO_t ev; + int ret; + ret = tskm_sub_resmRcv(&ev); + + if (-1 == ret) { + TSKM_ASSERT(0); + } else { + tskm_handleEvent(p_main, &ev); + } + } + } + + // Messages from connected clients + Recv_Msg_FromConnectClient(&fds, p_main); + + // CONNECT request + Recv_Req_Connect(&fds, p_main, sockFd); + } + + tskm_srvSockDestory(&p_main->sock); + + RPC_end(rpcId); + + FrameworkunifiedDestroyDispatcherWithoutLoop(p_main->hApp); + TSKM_PRINTF(TSKM_LOG_STATE, "tskm end"); + + sleep(TSKM_CFG_WAIT_SHUTDOWN); + return 0; +} // LCOV_EXCL_BR_LINE 10: Final line + diff --git a/systemservice/task_manager/server/src/tskm_port_pf.cpp b/systemservice/task_manager/server/src/tskm_port_pf.cpp new file mode 100755 index 0000000..f427255 --- /dev/null +++ b/systemservice/task_manager/server/src/tskm_port_pf.cpp @@ -0,0 +1,884 @@ +/* + * @copyright Copyright (c) 2016-2020 TOYOTA MOTOR CORPORATION. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "tskm_port_pf.h" +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include + +#include "system_service/tskm_svc.h" +#include "tskm_debug.h" + +#define TSKM_PORTPF_IN() TSKM_PRINTF(TSKM_LOG_PORTPF, "%s:IN", __FUNCTION__) +#define TSKM_PORTPF_IN_ARG(format, ...) TSKM_PRINTF(TSKM_LOG_PORTPF, "%s:IN:" format, __FUNCTION__, __VA_ARGS__) +#define TSKM_PORTPF_OUT() TSKM_PRINTF(TSKM_LOG_PORTPF, "%s:OUT", __FUNCTION__) + +#define TSKM_PRIO_MIN 1 +#define TSKM_PRIO_MAX 99 +#define TSKM_PRIO_MIN_TSS -20 +#define TSKM_PRIO_MAX_TSS 19 + +#define TSKM_TMP_DIRECTORY "/tmp" +#define TSKM_TMP_TSKM_DIRECTORY TSKM_TMP_DIRECTORY "/tskm" +#define TSKM_TMP_NV_INFO_FILEPATH TSKM_TMP_TSKM_DIRECTORY "/nvInfo" + +#define TSKM_NPP_NV_FILE_TAG SS_TASK_MANAGER "/nvInfo" + +/********************************************************* + * user->uid/gid conversion + *********************************************************/ +TSKM_STATIC int cnvUserName2UidGid(const char *user, uid_t *uid, gid_t *gid) { + int ret = -1; + + if (0 == strcmp(user, "")) { + *uid = geteuid(); + *gid = getegid(); + } else { + static __thread size_t bufSize = 0; + static __thread char *buf = NULL; + struct passwd pwd; + struct passwd *result; + + if (0 == bufSize) { + struct stat statInfo; + + bufSize = -1; + + if (0 != stat("/etc/passwd", &statInfo) || 0 >= statInfo.st_size) { // LCOV_EXCL_START 8: Because buf is a static variable and cannot be passed test + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + TSKM_ASSERT_ERRNO(0); + goto ERROR; + } + // LCOV_EXCL_STOP + + bufSize = statInfo.st_size * 2; + + // Since TaskManager is a resident service, the area allocated here is expected to be released at process termination and is not explicitly released by free() + buf = (char *) malloc(sizeof(char) * bufSize); // NOLINT (runtime/printf) + if (NULL == buf) { // LCOV_EXCL_BR_LINE 5: Error branching of the standard-function malloc + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + TSKM_ASSERT_ERRNO(0); // LCOV_EXCL_LINE 5: Error branching of the standard-function malloc + goto ERROR; // LCOV_EXCL_LINE 5: Error branching of the standard-function malloc + } + } + + if (NULL == buf) { // LCOV_EXCL_BR_LINE 8: Because buf is a static variable and cannot be passed test + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + TSKM_ASSERT(0); // LCOV_EXCL_LINE 8: Because buf is a static variable and cannot be passed test + goto ERROR; // LCOV_EXCL_LINE 8: Because buf is a static variable and cannot be passed test + } + + ret = getpwnam_r(user, &pwd, buf, bufSize, &result); + if (ret != 0 || result == NULL) { + TSKM_ASSERT_PRINT(0, "ret = %d[%s]", ret, user); + goto ERROR; + } + + *uid = pwd.pw_uid; + *gid = pwd.pw_gid; + } + + ret = 0; + + ERROR: + + return ret; +} + +/********************************************************* + * Convert Scheduling Policy Definitions Values (TSKM -> CL) + *********************************************************/ +TSKM_STATIC CL_ProcessSchedPolicy_t cnvTskmPolicy2ClPolicy( + TSKM_SVC_POLICY_t policy) { + switch (policy) { + case TSKM_SVC_POLICY_FIFO: + return CL_PROCESS_SCHED_POLICY_FIFO; + case TSKM_SVC_POLICY_TSS: + return CL_PROCESS_SCHED_POLICY_OTHER; + case TSKM_SVC_POLICY_RR: + return CL_PROCESS_SCHED_POLICY_RR; + default: + TSKM_ASSERT(0); + break; + } + return CL_PROCESS_SCHED_POLICY_OTHER; +} + +/********************************************************* + * Process priority valid value determination + *********************************************************/ +TSKM_STATIC int chkPrioValue(TSKM_SVC_POLICY_t policy, int prio) { + switch (policy) { + case TSKM_SVC_POLICY_FIFO: + case TSKM_SVC_POLICY_RR: + if ((TSKM_PRIO_MIN > prio) || (prio > TSKM_PRIO_MAX)) { + TSKM_ASSERT(0); + } + break; + case TSKM_SVC_POLICY_TSS: + default: + if ((TSKM_PRIO_MIN_TSS > prio) || (prio > TSKM_PRIO_MAX_TSS)) { + TSKM_ASSERT(0); + } + break; + } + + return prio; +} + +/********************************************************* + * COMMONLIB initialization (at system startup) + *********************************************************/ +int tskm_pf_sysInit() { + int fd = 0; + int ret = 0; + + TSKM_PORTPF_IN(); + + fd = CL_ProcessInit(); + if (fd == -1) { // LCOV_EXCL_BR_LINE 6: Error branching during process initialization + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + TSKM_ASSERT_ERRNO(0); // LCOV_EXCL_LINE 6: Error branching during process initialization + goto ERROR; // LCOV_EXCL_LINE 6: Error branching during process initialization + } + + ret = CL_MonitorInit(CL_MONITOR_INIT_USER); + if (ret != 0) { // LCOV_EXCL_BR_LINE 4: NSFW error case. + TSKM_ASSERT_ERRNO(0); + } + + TSKM_PORTPF_OUT(); + return fd; + // LCOV_EXCL_START 6: Error branching during process initialization + ERROR: + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + return -1; + // LCOV_EXCL_STOP +} + +/********************************************************* + * COMMONLIB initialization (at process startup) + *********************************************************/ +int tskm_pf_procInit() { + TSKM_PORTPF_IN(); + // Originally called the _sys_Setup_CWORD64_API (NULL), but changed to empty function along to derete "_sys" + + TSKM_PORTPF_OUT(); + return 0; +} + +/********************************************************* + * Process startup + *********************************************************/ +pid_t tskm_pf_createProc(TSKM_SVC_ATTR_t* p_svcAttr) { + TSKM_PORTPF_IN(); + pid_t retPid = -1; + pid_t pid = -1; + + CL_ProcessAttr_t attr; + char procPath[255]; + char* procName; + uid_t setUid = 0; + gid_t setGid = 0; + + if (0 != CL_ProcessCreateAttrInit(&attr)) { // LCOV_EXCL_BR_LINE 6: Error branching during process initialization + // LCOV_EXCL_START 6: Error branching during process initialization + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + TSKM_ASSERT(0); + goto ERROR; + // LCOV_EXCL_STOP + } + + // Process name setting(from basename) + if (strlen(p_svcAttr->path) < sizeof(procPath)) { + strcpy(procPath, p_svcAttr->path); // NOLINT (runtime/printf) + } else { + TSKM_ASSERT(0); + goto ERROR; + } + + procName = basename(procPath); + if (strlen(procName) >= 16) { + TSKM_ASSERT(0); + procName[16] = '\0'; + } + + if (0 != CL_ProcessCreateAttrSetName(&attr, procName)) { // LCOV_EXCL_BR_LINE 4: NSFW error case. + // LCOV_EXCL_START 4: NSFW error case. + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + TSKM_ASSERT_ERRNO(0); + goto ERROR; + // LCOV_EXCL_STOP + } + + if (0 != cnvUserName2UidGid(p_svcAttr->user, &setUid, &setGid)) { // LCOV_EXCL_BR_LINE 4: NSFW error case. + // LCOV_EXCL_START 4: NSFW error case. + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + TSKM_ASSERT(0); + setUid = geteuid(); + setGid = getegid(); + // LCOV_EXCL_STOP + } + + if (0 != CL_ProcessCreateAttrSetUid(&attr, setUid)) { // LCOV_EXCL_BR_LINE 4: NSFW error case. + // LCOV_EXCL_START 4: NSFW error case. + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + TSKM_ASSERT_ERRNO(0); + goto ERROR; + // LCOV_EXCL_STOP + } + + if (0 != CL_ProcessCreateAttrSetGid(&attr, setGid)) { // LCOV_EXCL_BR_LINE 4: NSFW error case. + // LCOV_EXCL_START 4: NSFW error case. + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + TSKM_ASSERT_ERRNO(0); + goto ERROR; + // LCOV_EXCL_STOP + } + + // All are group leaders in order to recover to the child processes of the service + if (0 != CL_ProcessCreateAttrSetGroup(&attr, 1)) { // LCOV_EXCL_BR_LINE 4: NSFW error case. + // LCOV_EXCL_START 4: NSFW error case. + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + TSKM_ASSERT_ERRNO(0); + goto ERROR; + // LCOV_EXCL_STOP + } + if (0 != CL_ProcessCreateAttrSetCpuAssign(&attr, p_svcAttr->cpuAssign)) { + TSKM_ASSERT_ERRNO(0); + goto ERROR; + } + + if (0 + != CL_ProcessCreateAttrSetSchedule( + &attr, cnvTskmPolicy2ClPolicy(p_svcAttr->policy), + chkPrioValue(p_svcAttr->policy, p_svcAttr->prio))) { + TSKM_ASSERT_ERRNO(0); + goto ERROR; + } + + pid = CL_ProcessCreate(p_svcAttr->path, p_svcAttr->args, NULL, &attr); + if (pid == -1) { + TSKM_ASSERT_ERRNO(0); + goto ERROR; + } + + retPid = pid; + ERROR: + + TSKM_PORTPF_OUT(); + return retPid; +} + +/********************************************************* + * Recover termination processes + *********************************************************/ +int tskm_pf_cleanupProc(int sigFd, pid_t* p_pid, TSKM_ERR_t* p_err) { + int ret; + CL_ProcessCleanupInfo_t info; + + ret = CL_ProcessCleanup(sigFd, &info); + if (ret != 0 && ret != 1) { + TSKM_ASSERT_PRINT(0, "ret = %d", ret); + TSKM_ASSERT_ERRNO(0); + goto ERROR; + } + + TSKM_PRINTF(TSKM_LOG_STATE, "SVC TERM:pid:%d code:%d status:%d", info.pid, + info.code, info.status); + + switch (info.code) { + case CLD_STOPPED: + // Not comes here usually + TSKM_PRINTF(TSKM_LOG_STATE, "svc stoped\n"); + goto ERROR; + case CLD_TRAPPED: + // Comes here only during debugging + TSKM_PRINTF(TSKM_LOG_STATE, "svc traped\n"); + goto ERROR; + case CLD_CONTINUED: + // Not comes here usually + TSKM_PRINTF(TSKM_LOG_STATE, "svc continue\n"); + goto ERROR; + default: + break; + } + + *p_pid = info.pid; + *p_err = + (info.code != CLD_EXITED) ? TSKM_E_NG : + (info.code == CLD_EXITED && info.status != EXIT_SUCCESS) ? + TSKM_E_NG : TSKM_E_OK; + + if (TSKM_E_OK != *p_err) { + TSKM_PRINTF(TSKM_LOG_SYSTEMDATA, "SVC ERR TERM:pid:%d code:%d status:%d", + info.pid, info.code, info.status); + } + + return ret; + ERROR: return -1; +} + +/********************************************************* + * Force Terminating a Process Group + *********************************************************/ +int tskm_pf_terminateProcGroup(uint16_t pid) { + int ret; + pid_t pgid; + + pgid = getpgid(pid); + if (pgid < 0) { + TSKM_ASSERT(0); + goto ERROR; + } + + TSKM_PRINTF(TSKM_LOG_STATE, "TERM SVC GROUP:pid:%dpgid:%d", pid, pgid); + + ret = CL_ProcessEuthanizeGroup(pgid); + if (ret != 0) { + TSKM_ASSERT_ERRNO(0); + goto ERROR; + } + + return 0; + ERROR: return -1; +} + +/********************************************************* + * Opening shared memory and trancating + *********************************************************/ +int tskm_pf_shmCreate_Open_Ftrn(const char* name, int32_t size, void** p_addr) { + int ret = 0; + int fd = 0; + + fd = shm_open(name, O_CREAT | O_RDWR | O_TRUNC, S_IRWXU | S_IRWXG | S_IRWXO); + if (fd == -1) { // LCOV_EXCL_BR_LINE 5: Checked in 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); // LCOV_EXCL_LINE 5: Checked in Death testing, but it is not reflected in the coverage and excluded. + ret = -1; // LCOV_EXCL_LINE 5: Checked in Death testing, but it is not reflected in the coverage and excluded. + if (fd > 0) { // LCOV_EXCL_LINE 5: Checked in Death testing, but it is not reflected in the coverage and excluded. + TSKM_ASSERT_ERRNO(close(fd) == 0); // LCOV_EXCL_LINE 5: Checked in Death testing, but it is not reflected in the coverage and excluded. + } // LCOV_EXCL_LINE 5: Checked in Death testing, but it is not reflected in the coverage and excluded. + return ret; // LCOV_EXCL_LINE 5: Checked in Death testing, but it is not reflected in the coverage and excluded. + } + + ret = ftruncate(fd, size); + if (ret != 0) { // LCOV_EXCL_BR_LINE 5: Checked in 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); // LCOV_EXCL_LINE 5: Checked in Death testing, but it is not reflected in the coverage and excluded. + if (fd > 0) { // LCOV_EXCL_LINE 5: Checked in Death testing, but it is not reflected in the coverage and excluded. + TSKM_ASSERT_ERRNO(close(fd) == 0); // LCOV_EXCL_LINE 5: Checked in Death testing, but it is not reflected in the coverage and excluded. + } // LCOV_EXCL_LINE 5: Checked in Death testing, but it is not reflected in the coverage and excluded. + return ret; // LCOV_EXCL_LINE 5: Checked in Death testing, but it is not reflected in the coverage and excluded. + } + + if (p_addr) { // LCOV_EXCL_BR_LINE 8: Because p_addr is set to NULL only + // LCOV_EXCL_START 8: Because p_addr is set to NULL only + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + // Not supported + TSKM_ASSERT_ERRNO(0); + ret = -1; + if (fd > 0) { + TSKM_ASSERT_ERRNO(close(fd) == 0); + } + return ret; + // LCOV_EXCL_STOP + } + + ret = 0; + if (fd > 0) { + TSKM_ASSERT_ERRNO(close(fd) == 0); + } + return ret; +} + +/********************************************************* + * Creating shared memory + *********************************************************/ +int tskm_pf_shmCreate(const char* name, int32_t size, void** p_addr) { + TSKM_PORTPF_IN_ARG("%s,%d", name, size); + struct stat statInfo; + int ret = -1; + + if (stat(name, &statInfo) == 0) { + TSKM_ASSERT_PRINT(0, "Already Exist %s", name); + ret = 0; // To be Succeeded + TSKM_PORTPF_OUT(); + return ret; + } + + ret = tskm_pf_shmCreate_Open_Ftrn(name, size, p_addr); + + TSKM_PORTPF_OUT(); + return ret; +} + +/********************************************************* + * Deleting shared memory + *********************************************************/ +int tskm_pf_shmDelete(const char* name) { + TSKM_PORTPF_IN_ARG("%s", name); + int ret = 0; + + if (0 != shm_unlink(name)) { + TSKM_ASSERT_ERRNO(0); + } + + TSKM_PORTPF_OUT(); + return ret; +} + +/********************************************************* + * Starting thread + *********************************************************/ +int tskm_pf_createThread(void* (*threadFunc)(void*), void* prm, + uint32_t priority, const char* threadName, + pthread_t* p_thId) { + TSKM_PORTPF_IN(); + + int ret; + CL_ThreadAttr_t cl_attr; + + ret = CL_ThreadCreateAttrInit(&cl_attr); + if (ret != 0) { // LCOV_EXCL_BR_LINE 6: For processing initializing process + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + TSKM_ASSERT_ERRNO(0); // LCOV_EXCL_LINE 6: For processing initializing process + goto ERROR; // LCOV_EXCL_LINE 6: For processing initializing process + } + + if (threadName) { + ret = CL_ThreadCreateAttrSetName(&cl_attr, threadName); + TSKM_ASSERT_ERRNO(ret == 0); + } + + ret = CL_ThreadCreate(p_thId, NULL, &cl_attr, threadFunc, prm); + if (ret != 0) { // LCOV_EXCL_BR_LINE 6: For processing initializing process + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + TSKM_ASSERT_ERRNO(0); // LCOV_EXCL_LINE 6: For processing initializing process + goto ERROR; // LCOV_EXCL_LINE 6: For processing initializing process + } + int sched_policy; + struct sched_param sparam; + + pthread_getschedparam(*p_thId, &sched_policy, &sparam); + + sparam.sched_priority = priority; + if ((priority != 0) && (sched_policy == SCHED_OTHER)) { + sched_policy = SCHED_FIFO; + } else if ((priority == 0) && (sched_policy != SCHED_OTHER)) { + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + sched_policy = SCHED_OTHER; // LCOV_EXCL_LINE 6: For processing initializing process + } + + ret = pthread_setschedparam(*p_thId, sched_policy, &sparam); + TSKM_ASSERT(ret == 0); + TSKM_PORTPF_OUT(); + return 0; + ERROR: return -1; +} +/********************************************************* + * Send Stop Complete Response + *********************************************************/ +int tskm_pf_sendStopCompResp() { + EFrameworkunifiedStatus l_eStatus; + TSKM_PORTPF_IN(); + + l_eStatus = SendInterfaceunifiedOnStopResponseToSystemManager(eFrameworkunifiedStatusOK); + if (l_eStatus != eFrameworkunifiedStatusOK) { + TSKM_ASSERT(0); + } + + TSKM_PORTPF_OUT(); + return 0; +} + +/********************************************************* + * ABORT + *********************************************************/ +int tskm_pf_abort() { + TSKM_PORTPF_IN(); + + TSKM_ASSERT(0); + sleep(1); // Sleep a little so that the logging at the time of abnormality may be interrupted + + // Issure SIGSEG + printf("%d\n", *(int *) 0); // NOLINT (readability/casting) + + TSKM_PORTPF_OUT(); + return 0; +} + +/********************************************************* + * EXIT + *********************************************************/ +int tskm_pf_exit(int status) { //LCOV_EXCL_START 5: Checked in Death testing, but it is not reflected in the coverage and excluded + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + TSKM_PORTPF_IN(); + + exit(status); + + TSKM_PORTPF_OUT(); + return 0; +} +// LCOV_EXCL_STOP + +/********************************************************* + * TOUCH + *********************************************************/ +int tskm_pf_touch(char* path) { + TSKM_PORTPF_IN(); + int fd; + fd = open(path, O_WRONLY | O_CREAT | O_TRUNC, 0666); + if (fd < 0) { + TSKM_ASSERT_ERRNO(0); + goto ERROR; + } + + TSKM_ASSERT_ERRNO(close(fd) == 0); + TSKM_PORTPF_OUT(); + return 0; + ERROR: + return -1; +} + +/********************************************************* + * Touch + *********************************************************/ +int tskm_pf_mkTouchFileName(pid_t pid, char name[32]) { + TSKM_PORTPF_IN(); + + sprintf(name, "/tmp/tskm_touch%d", pid); // NOLINT (runtime/printf) + + TSKM_PORTPF_OUT(); + return 0; +} + +/********************************************************* + * Read file + *********************************************************/ +static ssize_t readFile(const char* filePath, void* l_buf, ssize_t bufSize) { + int fd = -1; + ssize_t readSize, totalReadSize = 0; + char *p_buf = (char*) l_buf; // NOLINT (readability/casting) + fd = open(filePath, O_RDONLY); + if (fd == -1) { + TSKM_ASSERT_ERRNO(0); + goto ERROR; + } + + do { + readSize = read(fd, p_buf, bufSize); + if (readSize == -1) { + if (errno == EINTR) { + continue; + } else { + TSKM_ASSERT_ERRNO(0); + goto ERROR; + } + } else if (readSize == 0) { + break; + } + + p_buf += readSize; + bufSize -= readSize; + totalReadSize += readSize; + } while (bufSize > 0); + + ERROR: if (fd != -1) { + close(fd); + } + + return totalReadSize; +} + +/********************************************************* + * Write to file + *********************************************************/ +static ssize_t writeFile(const char *filePath, const void* l_buf, + ssize_t bufSize) { + int ret = -1; + int fd = -1; + + const char *p_buf = (const char*) l_buf; + + ssize_t writeSize, totalWriteSize = 0; + + fd = open(filePath, O_RDWR | O_TRUNC | O_CREAT, S_IRWXU); + if (fd == -1) { // LCOV_EXCL_BR_LINE 5: Error branching of the standard-function open() + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + TSKM_ASSERT_ERRNO(0); // LCOV_EXCL_LINE 5: Error branching of the standard-function open() + goto ERROR; // LCOV_EXCL_LINE 5: Error branching of the standard-function open() + } + + do { + writeSize = write(fd, p_buf, bufSize); + if (writeSize == -1) { // LCOV_EXCL_BR_LINE 5: Error branching of the standard-function write() + // LCOV_EXCL_START 5: Error branching of the standard-function write() + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + if (errno == EINTR) { + continue; + } else { + TSKM_ASSERT_ERRNO(0); + goto ERROR; + } + // LCOV_EXCL_STOP + } else if (writeSize == 0) { // LCOV_EXCL_BR_LINE 5: Error branching of the standard-function write() + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + break; // LCOV_EXCL_LINE 5: Error branching of the standard-function write() + } + p_buf += writeSize; + bufSize -= writeSize; + totalWriteSize += writeSize; + } while (bufSize > 0); // LCOV_EXCL_BR_LINE 5: Error branching of the standard-function write() + + ret = fsync(fd); + if (ret == -1) { // LCOV_EXCL_BR_LINE 5: Error branching of the standard-function fsync() + // LCOV_EXCL_START 5: Error branching of the standard-function fsync() + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + TSKM_ASSERT_ERRNO(0); + goto ERROR; + // LCOV_EXCL_STOP + } + + ERROR: if (fd != -1) { // LCOV_EXCL_BR_LINE 5: Error branching of the standard-function open() + close(fd); + } + + return totalWriteSize; +} + +/********************************************************* + * Checksum calculation + *********************************************************/ +static uint32_t calcCheckSum(const void* p_buf, size_t bufSize) { + int ii; + int blockNum; + uint32_t sum = 0; + uint32_t *p_calcBuf = (uint32_t*) p_buf; // NOLINT (readability/casting) + + blockNum = static_cast(bufSize) / static_cast(sizeof(uint32_t)); + + for (ii = 0; ii < blockNum; ii++) { + sum += p_calcBuf[ii]; + } + + return sum; +} + +/********************************************************* + * Checking files + *********************************************************/ +static TSKM_BOOL_t checkFile(const char *filePath) { // LCOV_EXCL_START 6: Because the condition cannot be set + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + uint32_t checkSum; + struct stat st; + ssize_t readSize; + TSKM_NV_INFO_t nvInfo; + TSKM_BOOL_t isFileOk = TSKM_FALSE; + + if (stat(filePath, &st) != 0) { + goto ERROR; + } + + readSize = readFile(filePath, &nvInfo, sizeof(TSKM_NV_INFO_t)); + if (readSize != sizeof(TSKM_NV_INFO_t)) { + TSKM_ASSERT(0); + goto ERROR; + } + + checkSum = calcCheckSum(&nvInfo, offsetof(TSKM_NV_INFO_t, footer.checkSum)); + + if (checkSum != nvInfo.footer.checkSum) { + TSKM_ASSERT(0); + goto ERROR; + } + + if (strncmp(nvInfo.header.version, TSKM_NV_STRUCT_VERSION, + sizeof(TSKM_NV_STRUCT_VERSION)) != 0) { + TSKM_ASSERT(0); + goto ERROR; + } + + isFileOk = TSKM_TRUE; + ERROR: return isFileOk; +} +// LCOV_EXCL_STOP +/********************************************************* + * Non-volatile file initialization (Including checksum write) + *********************************************************/ +static int initNvFile() { + int ii; + ssize_t writeSize; + TSKM_NV_INFO_t nvInfo; + + TSKM_STATIC_ASSERT(sizeof(TSKM_NV_INFO_t) == TSKM_NV_SIZE_ALL); + TSKM_STATIC_ASSERT( + offsetof(TSKM_NV_INFO_t, footer.checkSum) % sizeof(uint32_t) == 0); + + memset(&nvInfo, 0, sizeof(TSKM_NV_INFO_t)); + sprintf(nvInfo.header.version, TSKM_NV_STRUCT_VERSION); // NOLINT (readability/casting) + nvInfo.body.rsvSvcNum = 0; + for (ii = 0; ii < TSKM_SVC_RESERVE_MAX; ii++) { + nvInfo.body.rsvSvcs[ii] = TSKM_SVCID_NONE; + } + nvInfo.footer.checkSum = calcCheckSum( + &nvInfo, offsetof(TSKM_NV_INFO_t, footer.checkSum)); + + writeSize = writeFile(TSKM_TMP_NV_INFO_FILEPATH, &nvInfo, + sizeof(TSKM_NV_INFO_t)); + if (writeSize != sizeof(TSKM_NV_INFO_t)) { // LCOV_EXCL_BR_LINE 6: writeSize must be the size of TSKM_NV_INFO_t + // LCOV_EXCL_START 6: writeSize must be the size of TSKM_NV_INFO_t + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + TSKM_ASSERT(0); + goto ERROR; + // LCOV_EXCL_STOP + } + + return 0; + ERROR: return -1; +} + +/********************************************************* + * Non-volatile file initialization + *********************************************************/ +int tskm_pf_nvFileInit(HANDLE hApp) { + int ret = -1; + struct stat st; + EFrameworkunifiedStatus l_eStatus; + + if (stat(TSKM_TMP_TSKM_DIRECTORY, &st) != 0) { // LCOV_EXCL_BR_LINE 5:Standard C function return value + // LCOV_EXCL_START 5:Standard C function return value + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + ret = mkdir(TSKM_TMP_TSKM_DIRECTORY, S_IRWXU); + if (ret == -1) { + TSKM_ASSERT_ERRNO(0); + goto ERROR; + } + // LCOV_EXCL_STOP + } + + l_eStatus = FrameworkunifiedNPRegisterPersistentFile(hApp, TSKM_NPP_NV_FILE_TAG); + if (eFrameworkunifiedStatusOK != l_eStatus) { // LCOV_EXCL_BR_LINE 6: For processing initializing process + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + TSKM_ASSERT(0); // LCOV_EXCL_LINE 6: For processing initializing process + goto ERROR; // LCOV_EXCL_LINE 6: For processing initializing process + } + + l_eStatus = FrameworkunifiedNPLoadPersistentFile(hApp, TSKM_TMP_NV_INFO_FILEPATH, TSKM_NPP_NV_FILE_TAG); + if (eFrameworkunifiedStatusOK != l_eStatus) { // LCOV_EXCL_BR_LINE 6: For processing initializing process + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + TSKM_ASSERT(0); // LCOV_EXCL_LINE 6: For processing initializing process + goto ERROR; // LCOV_EXCL_LINE 6: For processing initializing process + } + + return 0; + ERROR: return -1; +} + +/********************************************************* + * Non-volatile file read + *********************************************************/ +int tskm_pf_nvFileRead(HANDLE hApp, TSKM_NV_INFO_t* p_nvInfo) { + EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK; + NC_LoadPersistedAck l_tMsgAck; + ssize_t readSize; + TSKM_BOOL_t isTmpFileOk = TSKM_FALSE; + + if (sizeof(l_tMsgAck) != FrameworkunifiedGetMsgLength(hApp)) { + TSKM_ASSERT(0); + goto ERROR; + } else if (eFrameworkunifiedStatusOK != (l_eStatus = FrameworkunifiedGetMsgDataOfSize(hApp, &l_tMsgAck, sizeof(l_tMsgAck)))) { // LCOV_EXCL_BR_LINE 4: NSFW error case // NOLINT[whitespace/line_length] + // LCOV_EXCL_START 4: NSFW error case + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + TSKM_ASSERT(0); + goto ERROR; + // LCOV_EXCL_STOP + } + + if ((strncmp(l_tMsgAck.cTag, TSKM_NPP_NV_FILE_TAG, sizeof(TSKM_NPP_NV_FILE_TAG)) == 0) + && (eFrameworkunifiedStatusOK == l_tMsgAck.eStatus)) { + if (checkFile(TSKM_TMP_NV_INFO_FILEPATH) == TSKM_TRUE) { + isTmpFileOk = TSKM_TRUE; + } + } + + if (isTmpFileOk == TSKM_FALSE) { + int ret; + + ret = initNvFile(); + if (ret == -1) { // LCOV_EXCL_BR_LINE 6: must return ok + // LCOV_EXCL_START 6: must return ok + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + TSKM_ASSERT(0); + goto ERROR; + // LCOV_EXCL_STOP + } + } + + readSize = readFile(TSKM_TMP_NV_INFO_FILEPATH, p_nvInfo, + sizeof(TSKM_NV_INFO_t)); + if (readSize != sizeof(TSKM_NV_INFO_t)) { // LCOV_EXCL_BR_LINE 6: readSize must be the size of TSKM_NV_INFO_t + // LCOV_EXCL_START 6: readSize must be the size of TSKM_NV_INFO_t + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + TSKM_ASSERT(0); + goto ERROR; + // LCOV_EXCL_STOP + } + + l_eStatus = FrameworkunifiedNPReleasePersistentFile(hApp, eFrameworkunifiedPersistOnShutdown, TSKM_NPP_NV_FILE_TAG, TSKM_TMP_NV_INFO_FILEPATH); + if (eFrameworkunifiedStatusOK != l_eStatus) { + TSKM_ASSERT(0); + } + + return 0; + ERROR: return -1; +} + +/********************************************************* + * Write non-volatile file (Including checksum) + *********************************************************/ +int tskm_pf_nvFileWrite(const TSKM_NV_INFO_t* p_nvInfo) { + ssize_t writeSize; + TSKM_NV_INFO_t nvInfo; + + memcpy(&nvInfo, p_nvInfo, sizeof(TSKM_NV_INFO_t)); + + nvInfo.footer.checkSum = calcCheckSum( + &nvInfo, offsetof(TSKM_NV_INFO_t, footer.checkSum)); + + writeSize = writeFile(TSKM_TMP_NV_INFO_FILEPATH, &nvInfo, + sizeof(TSKM_NV_INFO_t)); + if (writeSize != sizeof(TSKM_NV_INFO_t)) { // LCOV_EXCL_BR_LINE 6: writeSize must be the size of TSKM_NV_INFO_t + // LCOV_EXCL_START 6: writeSize must be the size of TSKM_NV_INFO_t + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + TSKM_ASSERT(0); + return -1; + // LCOV_EXCL_STOP + } + return 0; +} // LCOV_EXCL_BR_LINE 10: Final line diff --git a/systemservice/task_manager/server/src/tskm_port_subsys.cpp b/systemservice/task_manager/server/src/tskm_port_subsys.cpp new file mode 100755 index 0000000..cfdec49 --- /dev/null +++ b/systemservice/task_manager/server/src/tskm_port_subsys.cpp @@ -0,0 +1,297 @@ +/* + * @copyright Copyright (c) 2016-2020 TOYOTA MOTOR CORPORATION. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "tskm_port_subsys.h" +#include +#include +#include +#include + +#include +#include +#include +//#include +#include + +#include "agl_thread.h" + +#include "tskm_main.h" +#include "tskm_debug.h" +#include "tskm_util.h" +#include "tskm_port_pf.h" + + +#ifndef oops_name2pid + #define oops_name2pid(processname) syscall(OOPSTRACE_SYSCALL, 17, processname) +#endif + + +typedef struct { + CL_MonitorSearch_t clMonSearch; + uint32_t resmId; // Session ID of RESM +} SUB_SYS_CTX_t; + +static SUB_SYS_CTX_t g_sub; + +/****************************************************************** + * Subsystem initialization + ******************************************************************/ +int tskm_sub_init(void) { + int clRet; + SUB_SYS_CTX_t* p_ctx = &g_sub; + + clRet = CL_MonitorSearchInit(&p_ctx->clMonSearch); + if (clRet != 0) { // LCOV_EXCL_BR_LINE 6: For processing intializing process + // LCOV_EXCL_START 6:For processing initializing process + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + TSKM_ASSERT_ERRNO(0); + goto ERROR; + // LCOV_EXCL_STOP 6: For processing initializing process + } + + return 0; + // LCOV_EXCL_START 6:For processing initializing process + ERROR: + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + return 1; + // LCOV_EXCL_STOP +} + +/****************************************************************** + * Subsystem termination + ******************************************************************/ +int tskm_sub_term(void) { + int ret; + SUB_SYS_CTX_t* p_ctx = &g_sub; + + ret = CL_MonitorSearchDestroy(&p_ctx->clMonSearch); + if (ret != 0) { + TSKM_ASSERT_ERRNO(0); + } + + return 0; +} +/********************************************************* + * REBOOT + *********************************************************/ +void tskm_sub_reboot(const TSKM_ERROR_REBOOT_t* p_info) { + EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK; + + TSKM_ASSERT(0); + + l_eStatus = SendCpuResetRequestToSystemManager( + e_SS_SM_CPU_RESET_REASON_GENERIC_ERR, p_info->log.messageStr); + if (eFrameworkunifiedStatusOK != l_eStatus) { + TSKM_ASSERT(0); + } +} + +/********************************************************* + * REBOOT NORMAL + *********************************************************/ +void tskm_sub_reboot_normal(void) { + EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK; + + l_eStatus = SendCpuResetRequestToSystemManager( + e_SS_SM_CPU_RESET_REASON_NORMAL); + if (l_eStatus != eFrameworkunifiedStatusOK) { + TSKM_ASSERT(0); + } +} + +/********************************************************* + * LOGGING + *********************************************************/ +void tskm_sub_logging(const TSKM_LOGGING_INFO_t* p_info) { + EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK; + eSMUserLogType l_eType; + + switch (p_info->type) { + case TSKM_LOGGING_TYPE_GRP_RELAUNCH: + l_eType = e_SS_SM_CAPTURE_GROUP_RELAUNCH; + break; + case TSKM_LOGGING_TYPE_MODULE_LOGS: + default: + l_eType = e_SS_SM_CAPTURE_MODULE_LOGS; + break; + } + + l_eStatus = SendUserInvokedLoggingRequestToSystemManager(l_eType, + p_info->messageStr); + if (eFrameworkunifiedStatusOK != l_eStatus) { + TSKM_ASSERT(0); + } +} + +/********************************************************* + * DEBUG DUMP + *********************************************************/ +void tskm_sub_debugDumpRes(BOOL bIsNeedSvcName, const char *p_dumpMsg) { + if (bIsNeedSvcName) { // LCOV_EXCL_BR_LINE 8: As the bIsNeedSvcName is set to FALSE only + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + SSDEBUGDUMP("%s", p_dumpMsg); // LCOV_EXCL_LINE 8: As the bIsNeedSvcName is set to FALSE only + } else { + SSDEBUGDUMP_RAW("%s", p_dumpMsg); + } +} + +/********************************************************* + * EXT BOOT INFO + *********************************************************/ +int tskm_sub_getExtBootInfo(T_SS_SM_START_ExtDataStructType *p_info) { + EFrameworkunifiedStatus l_eStatus; + T_SS_SM_START_ExtDataStructType extStartupInfo; + + l_eStatus = GetInterfaceunifiedOnStartExtInfo(extStartupInfo); + if (l_eStatus != eFrameworkunifiedStatusOK) { + TSKM_ASSERT(0); + goto ERROR; + } + + memcpy(p_info, &extStartupInfo, sizeof(extStartupInfo)); + + return 0; + ERROR: return -1; +} + +/********************************************************* + * Service Error Monitoring Check + *********************************************************/ +TSKM_HUNG_INFO_t* +tskm_sub_searchHungSvcs() { + int ret; + TSKM_HUNG_INFO_t *p_hungList = NULL; + SUB_SYS_CTX_t* p_ctx = &g_sub; + + ret = CL_MonitorSearchTimeout(&p_ctx->clMonSearch); + if (ret == -1) { + TSKM_ASSERT_ERRNO(0); + goto ERROR; + } + + if (0 < p_ctx->clMonSearch.entry_num) { + int ii; + + TSKM_PRINTF(TSKM_LOG_DEBUG, "TimeoutSvcNum = %d", + p_ctx->clMonSearch.entry_num); + + if (NULL == p_ctx->clMonSearch.entry_list) { + TSKM_ASSERT(0); + goto ERROR; + } + + p_hungList = (TSKM_HUNG_INFO_t *) malloc( // NOLINT (readability/casting) + sizeof(TSKM_HUNG_INFO_t) * (p_ctx->clMonSearch.entry_num + 1)); + if (p_hungList == NULL) { // LCOV_EXCL_BR_LINE 5: malloc's error case. + // LCOV_EXCL_START 5: Checked in 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 + } + + for (ii = 0; ii < p_ctx->clMonSearch.entry_num; ii++) { + p_hungList[ii].pid = p_ctx->clMonSearch.entry_list[ii].pid; + p_hungList[ii].type = p_ctx->clMonSearch.entry_list[ii].type; + } + // set "-1" to pid at the end of list. + p_hungList[p_ctx->clMonSearch.entry_num].pid = -1; + } + + ERROR: return p_hungList; +} + +/********************************************************* + * RESM Initialization + *********************************************************/ +int tskm_sub_resmInit(void) { // LCOV_EXCL_START 6: Because the condition cannot be set + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + int redmFd; + SUB_SYS_CTX_t* p_ctx = &g_sub; + RESM_ERR_t resmRet = RESM_E_OK; + RESM_REQ_EVENT_t ev; + + int pid; + + resmRet = RESM_Open(NULL, &(p_ctx->resmId)); + if (RESM_E_OK != resmRet) { + TSKM_ASSERT(0); + +#warning RESM backtrace disabled, because 'print_backtrace_pid' not support. +#if 0 + // Backtrace outoutput of the RESM + pid = oops_name2pid(MN_SS_RESOURCEMGR); + if(pid > 0){ + TSKM_ASSERT(-1 != print_backtrace_pid(pid)); + }else{ + TSKM_PRINTF(TSKM_LOG_ERROR, "ERR : oops_name2pid %d , err:%d, msg:%s", + pid, errno, strerror(errno)); + } +#endif + + goto ERROR; + } + + resmRet = RESM_GetEventFd(p_ctx->resmId, &redmFd); + if (RESM_E_OK != resmRet) { + TSKM_ASSERT(0); + goto ERROR; + } + + ev.reqEvent = RESM_EV_MEM; + ev.prm.restMemThresh = 512; // Threshold(BYTE) + + resmRet = RESM_ReqEvent(p_ctx->resmId, &ev); + if (RESM_E_OK != resmRet) { + TSKM_ASSERT(0); + goto ERROR; + } + + return redmFd; + ERROR: return -1; +} +// LCOV_EXCL_STOP +/********************************************************* + * Get EV of RESM + *********************************************************/ +int tskm_sub_resmRcv(TSKM_EVENT_INFO_t* p_ev) { + SUB_SYS_CTX_t* p_ctx = &g_sub; + RESM_ERR_t resmRet = RESM_E_OK; + RESM_EV_t evFlag; + + resmRet = RESM_GetEvent(p_ctx->resmId, &evFlag); + if (RESM_E_OK != resmRet) { + TSKM_ASSERT(0); + goto ERROR; + } + + if (RESM_EV_MEM != evFlag) { + TSKM_ASSERT(0); + goto ERROR; + } + + TSKM_PRINTF(TSKM_LOG_ERROR, "Detect LowMem"); + + p_ev->event = TSKM_EV_LCL_REP_LOWMEM; + + return 0; + ERROR: return -1; +} + +int tskm_sub_setWakeupOrder(const char* p_order) { + // Under consideration + return 0; +} // LCOV_EXCL_BR_LINE 10: Gcov constraints (last row) diff --git a/systemservice/task_manager/server/src/tskm_shutdown.cpp b/systemservice/task_manager/server/src/tskm_shutdown.cpp new file mode 100755 index 0000000..1699f90 --- /dev/null +++ b/systemservice/task_manager/server/src/tskm_shutdown.cpp @@ -0,0 +1,242 @@ +/* + * @copyright Copyright (c) 2016-2020 TOYOTA MOTOR CORPORATION. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "tskm_shutdown.h" +#include "tskm_util.h" +#include "tskm_debug.h" +#include "tskm_state.h" + +#include "tskm_port_pf.h" +#include "tskm_port_subsys.h" +#include "tskm_gstep.h" + + +/********************************************************* + * Get context of gradual startup + *********************************************************/ +TSKM_STATIC TSKM_GSTEP_CTX_t* +gstepGetDownCtx(TSKM_MAIN_CTX_t* p_main) { + return &p_main->down; +} + +/********************************************************* + * System shutdown completed + *********************************************************/ +TSKM_STATIC void downFinish(TSKM_MAIN_CTX_t* p_main) { + int ret; + + // Send FrameworkunifiedOnStop response + ret = tskm_pf_sendStopCompResp(); + if (ret != 0) { // LCOV_EXCL_BR_LINE 8: As ret never becomes non-zero + // LCOV_EXCL_START 8: As ret never becomes non-zero + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + TSKM_ASSERT(0); + // LCOV_EXCL_STOP + } + + // Terminate subsystems + tskm_sub_term(); +} +/********************************************************* + * Challenge for a transition to the next state + *********************************************************/ +TSKM_STATIC void tryTransNextState(TSKM_MAIN_CTX_t* p_main) { + TSKM_GSTEP_CTX_t* p_down; + TSKM_GSTEP_t* p_current; + + p_down = gstepGetDownCtx(p_main); + p_current = gstepGetCurrent(p_down); + + if (gstepIsLast(p_down)) { + TSKM_SVC_WAIT_STATE_t waitState; + + // Checking the ShutdownWaitSVC termination status + waitState = tskm_svcsGetSvcTermWaitState(&p_main->svcs); + switch (waitState) { + case TSKM_SVC_WAIT_BOTH: + break; + case TSKM_SVC_WAIT_TRANSIENT: + if ((p_down->compState & INI_TERMCOMP_RESIDENT) != INI_TERMCOMP_RESIDENT) { + // Nonresident service termination processing + if (TSKM_E_OK != tskm_svcsAvtiveSvcTerm(&p_main->svcs)) { // LCOV_EXCL_BR_LINE 5: tskm_svcsAvtiveSvcTerm is always return TSKM_E_OK + // LCOV_EXCL_START 5: tskm_svcsAvtiveSvcTerm is always return TSKM_E_OK + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + TSKM_ASSERT(0); + // LCOV_EXCL_STOP + } + // Nonresident SVC terminated and started + p_down->compState |= INI_TERMCOMP_RESIDENT; + TSKM_PRINTF(TSKM_LOG_SVCSTATE, "TERM COMP :%s(%#llx)", + tskm_convTermCompId2Str(INI_TERMCOMP_RESIDENT), + INI_TERMCOMP_RESIDENT); + } + break; + case TSKM_SVC_WAIT_NONE: + // Complete ShutdownWaitSVC + // Nonresident SVC terminated and started + p_down->compState |= INI_TERMCOMP_TRANSIENT; + TSKM_PRINTF(TSKM_LOG_SVCSTATE, "TERM COMP :%s(%#llx)", + tskm_convTermCompId2Str(INI_TERMCOMP_TRANSIENT), + INI_TERMCOMP_TRANSIENT); + break; + default: + // LCOV_EXCL_START 8: As it does not meet the default requirements + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + TSKM_ASSERT(0); + break; + // LCOV_EXCL_STOP + } + } + + if (tskm_svcsIsWaiting(&p_main->svcs) == TSKM_FALSE && // No waiting services + ((p_down->compState & p_current->nextTransCond) + == p_current->nextTransCond)) { // Event completion condition + if (gstepIsLast(p_down)) { + tskm_stateTransit(p_main, TSKM_ST_ACCON, TSKM_ST_ACCOFF); + } else { + tskm_stateTransit(p_main, TSKM_ST_DOWN, TSKM_ST_DOWN); + } + } +} + +/********************************************************* + * Check and process gradual termination request + *********************************************************/ +TSKM_ERR_t tskm_entryDown_Check_Req(TSKM_MAIN_CTX_t* p_main, + TSKM_GSTEP_t* p_current) { + uint32_t ii; + + if (0 == p_current->reqNum) { + EFrameworkunifiedStatus l_eStatus; + + // If there is no gradual termination request, check the transition to the next step. + l_eStatus = FrameworkunifiedSendSelf(p_main->hApp, TSKM_TRANS_STEP_REQ, 0, NULL); + if (eFrameworkunifiedStatusOK != l_eStatus) { // LCOV_EXCL_BR_LINE 5: Checked in death testing, but it is not reflected in the coverage and excluded + // LCOV_EXCL_START 5: Checked in 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); + return TSKM_E_NG; + // LCOV_EXCL_STOP + } + + } else { + // Gradual termination request + for (ii = 0; ii < p_current->reqNum; ii++) { + TSKM_ERR_t tskmRet; + TSKM_GSTEP_REQ_INFO_t* p_req = &p_current->reqList[ii]; + TSKM_SVC_CTX_t* p_svc = tskm_svcsGetSvcBySvcId(&p_main->svcs, + p_req->svcId); + + tskmRet = tskm_svcDownRequest(p_svc, p_req); + if (tskmRet != TSKM_E_OK) { + TSKM_ASSERT(0); + } + } + } + return TSKM_E_OK; +} + +/********************************************************* + * Gradual termination entry process + *********************************************************/ +TSKM_ERR_t tskm_entryDown(TSKM_MAIN_CTX_t* p_main) { + TSKM_FUNC_IN(); + + TSKM_GSTEP_CTX_t* p_down; + TSKM_GSTEP_t* p_current; + + p_main->state = TSKM_ST_DOWN; + p_down = gstepGetDownCtx(p_main); + p_current = gstepGetCurrent(p_down); + if (p_current == NULL) { // LCOV_EXCL_BR_LINE 200:p_current can not be null + // LCOV_EXCL_START 200:p_current can not be null + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + TSKM_ASSERT(0); + goto ERROR; + // LCOV_EXCL_STOP + } + TSKM_PRINTF(TSKM_LOG_SVCSTATE, "DOWN GSTEP:%d", p_down->gstepIdx); + + if (tskm_entryDown_Check_Req(p_main, p_current) == TSKM_E_NG) { // LCOV_EXCL_BR_LINE 200:the function of tskm_entryDown_Check_Req can not be TSKM_E_NG at this case // NOLINT(whitespace/line_length) + // LCOV_EXCL_START 200:tskm_entryDown_Check_Req can not be TSKM_E_NG at this case + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + goto ERROR; + // LCOV_EXCL_STOP + } + + if (p_current->nextTransCond) { + TSKM_PRINTF(TSKM_LOG_STATE, "WAIT COMP:%s(%llx)", + tskm_convTermCompId2Str(p_current->nextTransCond), + p_current->nextTransCond); + } + + TSKM_FUNC_OUT(); + return TSKM_E_OK; + + ERROR: tskm_pf_abort(); + return TSKM_E_NG; +} + +/********************************************************* + * Gradual termination exit process + *********************************************************/ +TSKM_ERR_t tskm_exitDown(TSKM_MAIN_CTX_t* p_main) { + TSKM_FUNC_IN(); + TSKM_GSTEP_CTX_t* p_down; + + p_down = gstepGetDownCtx(p_main); + + if (gstepIsLast(p_down)) { + TSKM_PRINTF(TSKM_LOG_STATE, "DOWN FINISH"); + downFinish(p_main); // Final process of termination + } + + changeNextStep(p_down); // Proceed to the next step + + TSKM_FUNC_OUT(); + return TSKM_E_OK; +} +/********************************************************* + * Hander during gradual termination + *********************************************************/ +TSKM_ERR_t tskm_handleDown(TSKM_MAIN_CTX_t* p_main, TSKM_EVENT_INFO_t* p_ev) { + TSKM_FUNC_IN(); + + switch (p_ev->event) { + case TSKM_EV_PRI_REP_DOWN_COMP: // Notificaton for event completion in termination + { + TSKM_PRINTF(TSKM_LOG_SVCSTATE, "TERM COMP :%s(%#llx) from:%d", + tskm_convTermCompId2Str(p_ev->prm.repDownComp.compId), + p_ev->prm.repDownComp.compId, p_ev->fromPid); + TSKM_GSTEP_CTX_t* p_down = gstepGetDownCtx(p_main); + p_down->compState |= p_ev->prm.repDownComp.compId; + tryTransNextState(p_main); + } + break; + case TSKM_EV_LCL_CHG_SVC_STATE: // Service state change + tryTransNextState(p_main); + break; + case TSKM_EV_LCL_REQ_TRANS_STEP: //Step transition request + tryTransNextState(p_main); + break; + default: + tskm_handleAccon(p_main, p_ev); + break; + } + TSKM_FUNC_OUT(); + return TSKM_E_OK; +} // LCOV_EXCL_BR_LINE 10: Final line + diff --git a/systemservice/task_manager/server/src/tskm_state.cpp b/systemservice/task_manager/server/src/tskm_state.cpp new file mode 100755 index 0000000..b777090 --- /dev/null +++ b/systemservice/task_manager/server/src/tskm_state.cpp @@ -0,0 +1,452 @@ +/* + * @copyright Copyright (c) 2016-2020 TOYOTA MOTOR CORPORATION. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "tskm_state.h" +#include +#include "tskm_util.h" +#include "tskm_debug.h" +#include "tskm_wakeup.h" +#include "tskm_shutdown.h" +#include "tskm_port_subsys.h" +#include "tskm_port_pf.h" + + + +// Prototype declarations +TSKM_ERR_t tskm_entryAccoff(TSKM_MAIN_CTX_t* p_main); +TSKM_ERR_t tskm_exitAccoff(TSKM_MAIN_CTX_t* p_main); +TSKM_ERR_t tskm_handleAccoff(TSKM_MAIN_CTX_t* p_main, TSKM_EVENT_INFO_t* p_ev); + +TSKM_ERR_t tskm_entryAccon(TSKM_MAIN_CTX_t* p_main); +TSKM_ERR_t tskm_exitAccon(TSKM_MAIN_CTX_t* p_main); + +TSKM_ERR_t tskm_entryRunning(TSKM_MAIN_CTX_t* p_main); +TSKM_ERR_t tskm_exitRunning(TSKM_MAIN_CTX_t* p_main); +TSKM_ERR_t tskm_handleRunning(TSKM_MAIN_CTX_t* p_main, TSKM_EVENT_INFO_t* p_ev); + +// Structures of state transitioning callback functions +typedef TSKM_ERR_t (*entry_state_t)(TSKM_MAIN_CTX_t* p_main); +typedef TSKM_ERR_t (*exit_state_t)(TSKM_MAIN_CTX_t* p_main); +typedef TSKM_ERR_t (*event_handler_t)(TSKM_MAIN_CTX_t* p_main, + TSKM_EVENT_INFO_t* p_ev); + +typedef struct { + TSKM_STATE_t state; + entry_state_t entry_func; + exit_state_t exit_func; + event_handler_t event_handler; +} state_func_table_t; + +// State specific function table +static const state_func_table_t state_func_table[] = { { TSKM_ST_ACCOFF, + tskm_entryAccoff, tskm_exitAccoff, tskm_handleAccoff }, { TSKM_ST_ACCON, + tskm_entryAccon, tskm_exitAccon, tskm_handleAccon }, { TSKM_ST_WAKEUP, + tskm_entryWakeup, tskm_exitWakeup, tskm_handleWakeup }, { TSKM_ST_RUNNING, + tskm_entryRunning, tskm_exitRunning, tskm_handleRunning }, { TSKM_ST_DOWN, + tskm_entryDown, tskm_exitDown, tskm_handleDown }, { 0, 0, 0, 0 } }; + +/**************************************************** + * ACC OFF ENTRY + ****************************************************/ +TSKM_ERR_t tskm_entryAccoff(TSKM_MAIN_CTX_t* p_main) { + TSKM_FUNC_IN(); + p_main->state = TSKM_ST_ACCOFF; + TSKM_FUNC_OUT(); + return TSKM_E_OK; +} + +/************************************************************************* + * ACC OFF EXIT + *************************************************************************/ +TSKM_ERR_t tskm_exitAccoff(TSKM_MAIN_CTX_t* p_main) { + // Do nothing + // Called only once at startup + return TSKM_E_OK; +} + +/************************************************************************* + * ACC OFF HANDLE + *************************************************************************/ +TSKM_ERR_t tskm_handleAccoff(TSKM_MAIN_CTX_t* p_main, TSKM_EVENT_INFO_t* p_ev) { + TSKM_ASSERT(0); // Do nothing + return TSKM_E_OK; +} + +/************************************************************************* + * ACC ON ENTRY + *************************************************************************/ +TSKM_ERR_t tskm_entryAccon(TSKM_MAIN_CTX_t* p_main) { + TSKM_FUNC_IN(); + p_main->state = TSKM_ST_ACCON; + + tskm_entryState(p_main, TSKM_ST_WAKEUP); + TSKM_FUNC_OUT(); + return TSKM_E_OK; +} + +/************************************************************************* + * ACC ON HANDLE + *************************************************************************/ +TSKM_ERR_t tskm_exitAccon(TSKM_MAIN_CTX_t* p_main) { + TSKM_FUNC_IN(); + + TSKM_ERR_t tskmRet = TSKM_E_OK; + + if (TSKM_SUB_STATE_IS(p_main, TSKM_ST_WAKEUP)) { // LCOV_EXCL_BR_LINE 8:Because the condition is never true + // LCOV_EXCL_START 8: Because the condition is never true + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + tskmRet = tskm_exitState(p_main, TSKM_ST_WAKEUP); + // LCOV_EXCL_STOP + } else if (TSKM_SUB_STATE_IS(p_main, TSKM_ST_RUNNING)) { // LCOV_EXCL_BR_LINE 8: Because the condition is never true + // LCOV_EXCL_START 8: Because the condition is never true + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + tskmRet = tskm_exitState(p_main, TSKM_ST_RUNNING); + // LCOV_EXCL_STOP + } else if (TSKM_SUB_STATE_IS(p_main, TSKM_ST_DOWN)) { // LCOV_EXCL_BR_LINE 8:Because the condition is never false + tskmRet = tskm_exitState(p_main, TSKM_ST_DOWN); + } + + TSKM_ERR_CHK(tskmRet, TSKM_E_OK, ERROR); // LCOV_EXCL_BR_LINE 8: Because the tskmRet does not change to NG + p_main->isExec = TSKM_FALSE; + ERROR: + TSKM_FUNC_OUT(); + return tskmRet; +} + +/************************************************************************* + * POLL EVENT HANDLE + *************************************************************************/ +TSKM_STATIC void checkHungSvcs(TSKM_MAIN_CTX_t* p_main) { + int ret; + TSKM_HUNG_INFO_t *p_hungSvcList = NULL; + + p_hungSvcList = tskm_sub_searchHungSvcs(); + if (p_hungSvcList != NULL) { + int hungSvcNum = 0; + + while (p_hungSvcList[hungSvcNum].pid != -1) { + pid_t pid = p_hungSvcList[hungSvcNum].pid; + + TSKM_SVC_CTX_t* p_svc = tskm_svcsGetSvcByPid(&p_main->svcs, pid); + + if (p_svc) { + TSKM_PRINTF(TSKM_LOG_SYSTEMDATA, "HUNG SVC(%s:%d), TYPE(%d)", + p_svc->attr->name, pid, p_hungSvcList[hungSvcNum].type); + + ret = tskm_pf_terminateProcGroup(static_cast(pid)); + if (ret != 0) { + TSKM_ASSERT(0); + } + + } else { + TSKM_PRINTF(TSKM_LOG_WARN, "UNKNOWN HUNG SVC(%d), TYPE(%d)", pid, + p_hungSvcList[hungSvcNum].type); + } + + hungSvcNum++; + } + + free(p_hungSvcList); + } + + return; +} + +#define AVAILABILITY_CHECK_RETRY_COUNT 24 + +/************************************************************************* + * CHECK SVC AVAILABILITY + *************************************************************************/ +TSKM_STATIC void checkSvcAvailability(TSKM_MAIN_CTX_t* p_main) { + for (uint32_t ii = 0; ii < p_main->svcs.svcNum; ii++) { + if (p_main->svcs.svcList[ii].state == TSKM_SVC_RUNNING + && !p_main->svcs.svcList[ii].isAvailable) { + p_main->svcs.svcList[ii].watchCnt++; + TSKM_ASSERT_PRINT(0, "WAIT AVAILABILITY FOR %s(%d) (%d/%d)", + p_main->svcs.svcList[ii].attr->name, + p_main->svcs.svcList[ii].pid, + p_main->svcs.svcList[ii].watchCnt, + AVAILABILITY_CHECK_RETRY_COUNT); + + if (p_main->svcs.svcList[ii].watchCnt > AVAILABILITY_CHECK_RETRY_COUNT) { + int ret; + + ret = tskm_pf_terminateProcGroup(static_cast(p_main->svcs.svcList[ii].pid)); + if (ret != 0) { + TSKM_ASSERT(0); + } + } + } + } + + return; +} + +/************************************************************************* + * POLL EVENT HANDLE + *************************************************************************/ +TSKM_STATIC void handlePolling(TSKM_MAIN_CTX_t* p_main) { + checkHungSvcs(p_main); + + checkSvcAvailability(p_main); + + return; +} + +/************************************************************************* + * LOW MEMORY EVENT HANDLE + *************************************************************************/ +TSKM_STATIC void handleLowMem(TSKM_MAIN_CTX_t* p_main) { + TSKM_ERR_t tskmRet = TSKM_E_OK; + + tskmRet = tskm_svcsCallLowMem(&p_main->svcs); + if (TSKM_E_OK != tskmRet) { + TSKM_ASSERT(0); + } + + return; +} +/************************************************************************* + * ACC ON HANDLE + *************************************************************************/ +TSKM_ERR_t tskm_handleAccon(TSKM_MAIN_CTX_t* p_main, TSKM_EVENT_INFO_t* p_ev) { + TSKM_FUNC_IN(); + + switch (p_ev->event) { + case TSKM_EV_LCL_REQ_SDUMP: + tskm_svcsDump(&p_main->svcs); + break; + // LCOV_EXCL_STOP + case TSKM_EV_LCL_REP_POLLING: + TSKM_PRINTF(TSKM_LOG_DEBUG, "watch timer polling event."); + handlePolling(p_main); + break; + default: + TSKM_PRINTF(TSKM_LOG_STATE, "IGNORE:%s(%d)", + tskm_convEvent2Str(p_ev->event), p_ev->event); + break; + } + TSKM_FUNC_OUT(); + return TSKM_E_OK; +} + +/************************************************************************* + * BOOT RESERVED SERVICES + *************************************************************************/ +static int bootRsvSvcs(TSKM_MAIN_CTX_t* p_main) { + uint32_t ii; + TSKM_ERR_t tskmRet = TSKM_E_OK; + uint8_t rsvSvcNum = p_main->nvInfo.body.rsvSvcNum; + TSKM_SVCID_t* p_rsvSvcs = p_main->nvInfo.body.rsvSvcs; + + TSKM_PRINTF(TSKM_LOG_STATE, "RSV SVC NUM = %d", rsvSvcNum); + + for (ii = 0; ii < rsvSvcNum; ii++) { + TSKM_GSTEP_REQ_INFO_t req = { 0 }; + TSKM_SVC_CTX_t* p_svc; + + p_svc = tskm_svcsGetSvcBySvcId(&p_main->svcs, p_rsvSvcs[ii]); + if (p_svc == NULL) { + TSKM_ASSERT(0); + continue; + } + + tskmRet = tskm_svcExec(p_svc); + if (TSKM_E_OK != tskmRet) { + TSKM_ASSERT(0); + continue; + } + if (p_svc->state == TSKM_SVC_WAITCONNECT) { + // In the state waiting for execution + req.svcId = p_rsvSvcs[ii]; + req.localStep = TSKM_LSTEP_ALL; + tskmRet = tskm_svcWakeupRequest(p_svc, &req); + if (TSKM_E_OK != tskmRet) { // LCOV_EXCL_BR_LINE 8: Because the condition is never true + // LCOV_EXCL_START 8: Because the condition is never true + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + TSKM_ASSERT_PRINT(0, "tskmRet = %d", tskmRet); + continue; + // LCOV_EXCL_STOP + } + } + } + + if (rsvSvcNum != 0) { + int ret; + + for (ii = 0; ii < TSKM_SVC_RESERVE_MAX; ii++) { + p_rsvSvcs[ii] = TSKM_SVCID_NONE; + } + + p_main->nvInfo.body.rsvSvcNum = 0; + + ret = tskm_pf_nvFileWrite(&p_main->nvInfo); + if (ret == -1) { // LCOV_EXCL_BR_LINE 8: Because the tskm_pf_nvFileWrite() only returns a return value of 0 + // LCOV_EXCL_START 8:Because the condition is never true + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + TSKM_ASSERT(0); + goto ERROR; + // LCOV_EXCL_STOP + } + } + + return 0; + // LCOV_EXCL_START 8: Because the tskm_pf_nvFileWrite() only returns a return value of 0 + ERROR: + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + return -1; + // LCOV_EXCL_STOP +} + +/************************************************************************* + * RUN ENTRY + *************************************************************************/ +TSKM_ERR_t tskm_entryRunning(TSKM_MAIN_CTX_t* p_main) { + int ret; + + TSKM_FUNC_IN(); + p_main->state = TSKM_ST_RUNNING; + + ret = bootRsvSvcs(p_main); + if (ret != 0) { // LCOV_EXCL_BR_LINE 8: Because bootRsvSvcs returns only a return value of 0 + // LCOV_EXCL_START 8: Because bootRsvSvcs returns only a return value of 0 + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + TSKM_ASSERT(0); + // LCOV_EXCL_STOP + } + + TSKM_FUNC_OUT(); + return TSKM_E_OK; +} + +/************************************************************************* + * RUN EXIT + *************************************************************************/ +TSKM_ERR_t tskm_exitRunning(TSKM_MAIN_CTX_t* p_main) { + TSKM_FUNC_IN(); + + TSKM_FUNC_OUT(); + return TSKM_E_OK; +} + +/************************************************************************* + * RUN HANDLE + *************************************************************************/ +TSKM_ERR_t tskm_handleRunning(TSKM_MAIN_CTX_t* p_main, + TSKM_EVENT_INFO_t* p_ev) { + TSKM_FUNC_IN(); + + switch (p_ev->event) { + case TSKM_EV_LCL_REQ_STOP: + tskm_stateTransit(p_main, TSKM_ST_RUNNING, TSKM_ST_DOWN); + break; + case TSKM_EV_LCL_REP_LOWMEM: + handleLowMem(p_main); + break; + default: + tskm_handleAccon(p_main, p_ev); + break; + } + + TSKM_FUNC_OUT(); + return TSKM_E_OK; +} + +/************************************************************************* + * Get transition table + *************************************************************************/ +static const state_func_table_t* +tskm_getFuncTable(TSKM_STATE_t state) { + int i; + for (i = 0; state_func_table[i].state != 0; i++) { + if (state == state_func_table[i].state) { + return &state_func_table[i]; + } + } + TSKM_ASSERT(0); + return &state_func_table[0]; +} + +/************************************************************************* + * State transition instructions + *************************************************************************/ +TSKM_ERR_t tskm_stateTransit(TSKM_MAIN_CTX_t* p_main, TSKM_STATE_t srcState, + TSKM_STATE_t dstState) { + TSKM_ERR_t tskmRet; + TSKM_PRINTF(TSKM_LOG_STATE, "STATE:%s(%s) -> %s", + tskm_convState2Str(srcState), tskm_convState2Str(p_main->state), + tskm_convState2Str(dstState)); + + tskmRet = tskm_exitState(p_main, srcState); + TSKM_ERR_CHK(tskmRet, TSKM_E_OK, ERROR); // LCOV_EXCL_BR_LINE 8: Because TSKM_ERR_CHK does not specify a goto ERROR condition + tskmRet = tskm_entryState(p_main, dstState); + TSKM_ERR_CHK(tskmRet, TSKM_E_OK, ERROR); // LCOV_EXCL_BR_LINE 8: Because TSKM_ERR_CHK does not specify a goto ERROR condition + return TSKM_E_OK; + + // LCOV_EXCL_START 8: Because TSKM_ERR_CHK does not specify a goto ERROR condition + ERROR: + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + return TSKM_E_NG; + // LCOV_EXCL_STOP +} + +/************************************************************************* + * Event handler + *************************************************************************/ +void tskm_handleEvent(TSKM_MAIN_CTX_t* p_main, TSKM_EVENT_INFO_t* p_ev) { + event_handler_t handlerFunc; + handlerFunc = tskm_getFuncTable(p_main->state)->event_handler; + handlerFunc(p_main, p_ev); +} + +/**************************************************** + * State transitioning entry process + ****************************************************/ +TSKM_ERR_t tskm_entryState(TSKM_MAIN_CTX_t* p_rec, TSKM_STATE_t state) { + TSKM_ERR_t ret = TSKM_E_NG; + const state_func_table_t* p_table = tskm_getFuncTable(state); + + TSKM_PRINTF(TSKM_LOG_DEBUG, "entry :%s", tskm_convState2Str(state)); + if (p_table->entry_func) { // LCOV_EXCL_BR_LINE 8: Because p_table->entry_func never becomes 0 + ret = ((*p_table->entry_func)(p_rec)); + } else { + // LCOV_EXCL_START 8: Because p_table->entry_func never becomes 0 + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + TSKM_ASSERT(0); + // LCOV_EXCL_STOP + } + return ret; +} + +/**************************************************** + * State transitioning exit process + ****************************************************/ +TSKM_ERR_t tskm_exitState(TSKM_MAIN_CTX_t* p_rec, TSKM_STATE_t state) { + TSKM_ERR_t ret = TSKM_E_NG; + const state_func_table_t* p_table = tskm_getFuncTable(state); + + if (p_table->exit_func) { // LCOV_EXCL_BR_LINE 8: Because p_table->exit_func never becomes 0 + ret = (*p_table->exit_func)(p_rec); + } else { + // LCOV_EXCL_START 8: Because p_table->exit_func never becomes 0 + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + TSKM_ASSERT(0); + // LCOV_EXCL_STOP + } + TSKM_PRINTF(TSKM_LOG_DEBUG, "exit :%s", tskm_convState2Str(state)); + return ret; +} // LCOV_EXCL_BR_LINE 10: Final line + diff --git a/systemservice/task_manager/server/src/tskm_svc.cpp b/systemservice/task_manager/server/src/tskm_svc.cpp new file mode 100755 index 0000000..2f9abc1 --- /dev/null +++ b/systemservice/task_manager/server/src/tskm_svc.cpp @@ -0,0 +1,970 @@ +/* + * @copyright Copyright (c) 2016-2020 TOYOTA MOTOR CORPORATION. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "system_service/tskm_svc.h" +#include +#include +#include +#include + +#include +#include + +#include "tskm_debug.h" +#include "tskm_util.h" +#include "tskm_port_pf.h" +#include "tskm_port_subsys.h" +#include "tskm_comm.h" + + +/********************************************************* + * Is the target event of the service handler? + + *********************************************************/ +TSKM_STATIC TSKM_BOOL_t isSvcEvent(const TSKM_EVENT_INFO_t* p_ev) { + switch (p_ev->event) { + case TSKM_EV_PRI_REP_CONNECT: + case TSKM_EV_PRI_REP_DISCONNECT: + case TSKM_EV_PRI_RES_WAKEUP: + case TSKM_EV_PRI_RES_DOWN: + case TSKM_EV_PRI_RES_DEBUGDUMP: + case TSKM_EV_PRI_REQ_EXIT: + case TSKM_EV_SVC_REP_TERM: + return TSKM_TRUE; + break; + default: + break; + } + return TSKM_FALSE; +} + +/********************************************************* + * Get service context + *********************************************************/ +TSKM_STATIC TSKM_SVC_CTX_t* +getSvcCtxBySvcId(TSKM_SVCS_CTX_t* p_svcs, TSKM_SVCID_t svcId) { + uint32_t ii; + + for (ii = 0; ii < p_svcs->svcNum; ii++) { + if (p_svcs->svcList[ii].attr->svcId == svcId) { + return &p_svcs->svcList[ii]; + } + } + TSKM_ASSERT(0); + return NULL; +} + +/********************************************************* + * Get service context + *********************************************************/ +TSKM_STATIC TSKM_SVC_CTX_t* +getSvcCtxByPid(TSKM_SVCS_CTX_t* p_svcs, pid_t pid) { + uint32_t ii; + + for (ii = 0; ii < p_svcs->svcNum; ii++) { + if (p_svcs->svcList[ii].pid == pid) { + return &p_svcs->svcList[ii]; + } + } + return NULL; +} + +/********************************************************* + * Get service context + *********************************************************/ +TSKM_STATIC TSKM_SVC_CTX_t* +getSvcCtxByName(TSKM_SVCS_CTX_t* p_svcs, const char *p_name) { // LCOV_EXCL_START 6: Because the condition cannot be set + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + uint32_t ii; + + for (ii = 0; ii < p_svcs->svcNum; ii++) { + if (0 + == strncmp(p_svcs->svcList[ii].attr->name, p_name, + strlen(p_svcs->svcList[ii].attr->name))) { + return &p_svcs->svcList[ii]; + } + } + return NULL; +} +// LCOV_EXCL_STOP +/********************************************************* + * Issuing a start request to the service + *********************************************************/ +TSKM_STATIC TSKM_ERR_t wakeupRequest(TSKM_SVC_CTX_t* p_svc, + TSKM_GSTEP_REQ_INFO_t* p_req) { + TSKM_EVENT_INFO_t ev; + int ret; + bzero(&ev, sizeof(ev)); + + ev.event = TSKM_EV_PRI_REQ_WAKEUP; + ev.errCode = TSKM_E_OK; + ev.prm.reqWakeup.svcId = p_svc->attr->svcId; + ev.prm.reqWakeup.localStep = p_req->localStep; + ev.prm.reqWakeup.isDynamic = + (p_svc->attr->lifeCycle == TSKM_SVC_LC_DYNAMIC) ? TSKM_TRUE : TSKM_FALSE; + // Since there is no startup in the P_CWORD72_ but only communication in the ALL/LAST, + // the startup information is optimized including the startup information in the communication of the WakeupRequest. + memcpy(&ev.prm.reqWakeup.bootInfo, &p_svc->bootInfo, + sizeof(ev.prm.reqWakeup.bootInfo)); + memcpy(&ev.prm.reqWakeup.extBootInfo, &p_svc->extBootInfo, + sizeof(ev.prm.reqWakeup.extBootInfo)); + + ret = tskm_sockSend(p_svc->connFd, &ev); + if (ret <= 0) { + TSKM_ASSERT(0); + goto ERROR; + } + p_svc->waitResCnt++; + p_svc->state = TSKM_SVC_WAKEUP; + + return TSKM_E_OK; + ERROR: return TSKM_E_NG; +} + +/********************************************************* + * Touch services and extend EXIT timeouts + *********************************************************/ +TSKM_STATIC TSKM_ERR_t reqTouch(TSKM_SVC_CTX_t* p_svc) { +#define TSKM_BUF_LEN ( 4 * ( sizeof(struct inotify_event) ) ) /* read size */ + TSKM_ERR_t funcRet = TSKM_E_NG; + char touchFileName[32]; + BOOL isNeedRetry = FALSE; + + int iFd = p_svc->iFd; + int wd = 0; + + TSKM_EVENT_INFO_t ev; + int ret; + bzero(&ev, sizeof(ev)); + + // Create monitoring files + tskm_pf_mkTouchFileName(p_svc->pid, touchFileName); + if (0 != tskm_pf_touch(touchFileName)) { + goto ERROR; + } + + // Synchronize by iNortify + wd = inotify_add_watch(iFd, touchFileName, IN_DELETE_SELF); + if (wd == -1) { + TSKM_ASSERT_ERRNO(0); + goto ERROR; + } + + // Send Touch request + ev.event = TSKM_EV_PRI_REQ_TOUCH; + ev.errCode = TSKM_E_OK; + ret = tskm_sockSend(p_svc->connFd, &ev); + if (ret <= 0) { + // Immediately after the nonresident service process terminates, since the TaskManager service status is other than DORMANT + // (mainly DOWN), the socket may be discarded and communication may fail, so retry + funcRet = TSKM_E_RETRY; + TSKM_PRINTF(TSKM_LOG_WARN, "ret = %d", ret); + goto ERROR; + } + + // Wait for Touch completion + while (1) { + int maxFd = 0; + int ret; + fd_set fds; + FD_ZERO(&fds); + struct timeval timeout = { 0 }; + timeout.tv_sec = TSKM_CFG_TOUCH_TIMEOUT; + + FD_SET(iFd, &fds); + maxFd = iFd; + + ret = select(maxFd + 1, &fds, NULL, NULL, &timeout); + if (ret == 0) { + TSKM_ASSERT_PRINT(0, "TIMEOUT:%s", touchFileName); // Timeout occurs + isNeedRetry = TRUE; + break; + } else if (ret < 1) { + if (errno == EINTR) { + continue; + } else { + TSKM_ASSERT(0); + goto ERROR; + } + } + + if (FD_ISSET(iFd, &fds)) { + int length; + uint8_t buf[TSKM_BUF_LEN]; + + length = static_cast(read(iFd, buf, TSKM_BUF_LEN)); + if (length < 0) { + TSKM_ASSERT_ERRNO(0); + goto ERROR; + } + struct inotify_event *event = (struct inotify_event *) buf; + if (event->mask & IN_DELETE_SELF) { + TSKM_PRINTF(TSKM_LOG_STATE, "TouchOK"); + wd = 0; + // When a file is deleted, the association with the monitoring target is automatically released and inotify_rm_watch is no longer needed. + break; + } else { + TSKM_ASSERT_PRINT(0, "%x", event->mask); + } + } + } + + if (isNeedRetry) { + funcRet = TSKM_E_RETRY; + } else { + funcRet = TSKM_E_OK; + } + + ERROR: if (wd > 0) { + TSKM_ASSERT_ERRNO(0 == inotify_rm_watch(iFd, wd)) + } + + if (access(touchFileName, F_OK) == 0) { + // Timeout care + unlink(touchFileName); + } + + return funcRet; +} + +/********************************************************* + * Availability Monitoring Callbacks for Services + *********************************************************/ +EFrameworkunifiedStatus OnSvcAvailability(HANDLE hApp) { // LCOV_EXCL_START 6: Because the condition cannot be set + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + PCSTR availabilityName; + TSKM_MAIN_CTX_t* p_main = tskm_getMainCtx(); + TSKM_SVC_CTX_t* p_svc; + + availabilityName = FrameworkunifiedGetLastNotification(hApp); + + std::string str = availabilityName; + +// unsigned int position; +// if (std::string::npos != (position = static_cast(str.find("/Availability", 0)))) { + ssize_t position; + if (0 <= (position = str.find("/Availability", 0))) { + str.erase(position, position + strlen("/Availability")); + } + + p_svc = getSvcCtxByName(&p_main->svcs, str.c_str()); + if (p_svc) { + p_svc->isAvailable = FrameworkunifiedIsServiceAvailable(hApp) ? TSKM_TRUE : TSKM_FALSE; + TSKM_PRINTF(TSKM_LOG_SVCSTATE, "%s Availability %s", p_svc->attr->name, + (p_svc->isAvailable == TSKM_TRUE) ? "TRUE" : "FALSE"); + } + + return eFrameworkunifiedStatusOK; +} +// LCOV_EXCL_STOP +/********************************************************* + * Starting Availability Monitoring of Services + *********************************************************/ +TSKM_STATIC TSKM_ERR_t startWatchAvailability(TSKM_SVC_CTX_t* p_svc) { + TSKM_ERR_t funcRet = TSKM_E_OK; + + // LCOV_EXCL_BR_START 8: Since the condition is checked by the caller, it is not true. + if (p_svc->attr->type == TSKM_SVC_TYPE_UNKNONW) { + // LCOV_EXCL_BR_STOP + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + p_svc->isAvailable = TSKM_TRUE; // LCOV_EXCL_LINE 8: Since the condition is checked by the caller, it is not true. + } else { + EFrameworkunifiedStatus taskmanagerStatus; + TSKM_MAIN_CTX_t* p_main = tskm_getMainCtx(); + SS_String availabilityName = p_svc->attr->name; + + availabilityName.append("/Availability"); + + taskmanagerStatus = FrameworkunifiedSubscribeNotificationWithCallback(p_main->hApp, + availabilityName.c_str(), + OnSvcAvailability); + if (eFrameworkunifiedStatusOK != taskmanagerStatus) { + TSKM_ASSERT(0); + funcRet = TSKM_E_NG; + } + } + + return funcRet; +} + +/********************************************************* + * Service startup sub + *********************************************************/ +void svcExec_Process(TSKM_SVC_CTX_t* p_svc) { + TSKM_ERR_t funcRet; + + if (p_svc->attr->type == TSKM_SVC_TYPE_NATIVE) { + p_svc->state = TSKM_SVC_WAITCONNECT; + TSKM_PRINTF(TSKM_LOG_DEBUG, "[ST:%d] WAIT_EXEC", p_svc->pid); + funcRet = startWatchAvailability(p_svc); + if (TSKM_E_OK != funcRet) { + TSKM_ASSERT(0); + p_svc->isAvailable = TSKM_TRUE; + } + } else { + p_svc->state = TSKM_SVC_RUNNING; + TSKM_PRINTF(TSKM_LOG_SVCSTATE, "[ST:%d] RUN", p_svc->pid); + p_svc->isAvailable = TSKM_TRUE; + } + return; +} + +/********************************************************* + * Service startup main + *********************************************************/ +TSKM_STATIC TSKM_ERR_t svcExec(TSKM_SVC_CTX_t* p_svc) { + TSKM_ERR_t funcRet = TSKM_E_NG; + pid_t pid; + + if (p_svc == NULL) { // LCOV_EXCL_BR_LINE 6:double check + // LCOV_EXCL_START 6: double check + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + TSKM_ASSERT(0); + goto ERROR; + // LCOV_EXCL_STOP + } + + if (p_svc->state == TSKM_SVC_DISABLE) { + // Prohibited startup + TSKM_ASSERT(0); + return TSKM_E_STATE; + } else if (p_svc->state == TSKM_SVC_WAITCONNECT) { + return TSKM_E_OK; + } else if (p_svc->state != TSKM_SVC_DORMANT) { + // Already started + funcRet = reqTouch(p_svc); + if (TSKM_E_OK != funcRet) { + TSKM_PRINTF(TSKM_LOG_WARN, "funcRet = %d", funcRet); + goto ERROR; + } + return TSKM_E_OK; + } + + pid = tskm_pf_createProc(p_svc->attr); + if (pid <= 0) { + TSKM_ASSERT(0); + goto ERROR; + } + TSKM_PRINTF(TSKM_LOG_STATE, "EXEC %s:%d", p_svc->attr->name, pid); + + p_svc->pid = pid; + p_svc->waitReqCnt = 0; + + // Startup service + svcExec_Process(p_svc); + + funcRet = TSKM_E_OK; + ERROR: return funcRet; +} + +/********************************************************* + * Issuing a start request to the service + *********************************************************/ +TSKM_STATIC TSKM_ERR_t svcWakeupRequest(TSKM_SVC_CTX_t* p_svc, + TSKM_GSTEP_REQ_INFO_t* p_req) { + if (p_svc == NULL || p_svc->state == TSKM_SVC_DISABLE) { // LCOV_EXCL_BR_LINE 6: Since this function has always been called after checking // NOLINT(whitespace/line_length) + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + return TSKM_E_STATE; // LCOV_EXCL_LINE 6: Since this function has always been called after checking + } else if (p_svc->state == TSKM_SVC_WAITCONNECT) { + // Remember it once and issue a request when the CONNECT completes. + p_svc->request[p_svc->waitReqCnt] = *p_req; + p_svc->waitReqCnt++; + } else { + TSKM_ERR_t tskmRet; + tskmRet = wakeupRequest(p_svc, p_req); + TSKM_ERR_CHK_DFT; + } + + return TSKM_E_OK; + ERROR: return TSKM_E_NG; +} + +/********************************************************* + * Service reboot processing + *********************************************************/ +TSKM_STATIC TSKM_ERR_t svcErrTermPost(TSKM_SVC_CTX_t* p_svc) { + TSKM_MAIN_CTX_t* p_main = tskm_getMainCtx(); + + TSKM_PRINTF(TSKM_LOG_SYSTEMDATA, "ERR TERM SVC(%s:%d)", p_svc->attr->name, + p_svc->pid); + + if (p_svc->attr->lifeCycle == TSKM_SVC_LC_ALWAYS || (p_svc->errTermCnt > p_svc->attr->retryCnt && (uint32_t) -1 != p_svc->attr->retryCnt)) { // NOLINT(whitespace/line_length) + TSKM_ERROR_REBOOT_t rebootInfo; + + TSKM_ASSERT(0); + memset(&rebootInfo, 0, sizeof(TSKM_ERROR_REBOOT_t)); + rebootInfo.type = TSKM_ERROR_REBOOT_NORMAL; + snprintf(rebootInfo.log.messageStr, TSKM_LOGGING_MSG_STR_SIZE, + "TaskManager:SVC ErrTerm"); + tskm_sub_reboot(&rebootInfo); + } else { + TSKM_LOGGING_INFO_t logInfo; + logInfo.type = TSKM_LOGGING_TYPE_MODULE_LOGS; + + snprintf(logInfo.messageStr, TSKM_LOGGING_MSG_STR_SIZE, + "TaskManager:SVC ErrTerm"); + tskm_sub_logging(&logInfo); + + if (p_svc->attr->lifeCycle == TSKM_SVC_LC_ALWAYS_RECOVERABLE) { + TSKM_ERR_t ret; + TSKM_GSTEP_REQ_INFO_t req = { 0 }; + + ret = svcExec(p_svc); + + if (TSKM_E_OK != ret) { + TSKM_ASSERT_PRINT(0, "ret = %d", ret); + goto ERROR; + } else if (p_svc->state == TSKM_SVC_WAITCONNECT) { + // In the state waiting for execution + req.svcId = p_svc->attr->svcId; + req.localStep = TSKM_LSTEP_ALL; + ret = svcWakeupRequest(p_svc, &req); + if (TSKM_E_OK != ret) { + TSKM_ASSERT_PRINT(0, "ret = %d", ret); + goto ERROR; + } + } + } + } + + return TSKM_E_OK; + ERROR: return TSKM_E_NG; +} + +/********************************************************* + * Connection handler + * ret:TRUE SVC status changed + * ret:FALSE SVC status not changed + *********************************************************/ +TSKM_STATIC TSKM_BOOL_t connectHandle(TSKM_SVC_CTX_t* p_svc, + const TSKM_EVENT_INFO_t* p_inEv) { + uint32_t ii; + + TSKM_ASSERT(p_svc->state == TSKM_SVC_WAITCONNECT); + + p_svc->connFd = p_inEv->prm.repConnect.connFd; + p_svc->state = TSKM_SVC_WAKEUP; + TSKM_PRINTF(TSKM_LOG_DEBUG, "[ST:%d] WAKEUP", p_svc->pid); + + p_svc->waitResCnt = 0; + + if (p_svc->waitReqCnt) { + for (ii = 0; ii < p_svc->waitReqCnt; ii++) { + TSKM_ASSERT(TSKM_E_OK == wakeupRequest(p_svc, &p_svc->request[ii])); + } + p_svc->waitReqCnt = 0; + } + + return TSKM_TRUE; +} + +/********************************************************* + * Disconnection handler + * ret:TRUE SVC status changed + * ret:FALSE SVC status not changed + *********************************************************/ +TSKM_STATIC TSKM_BOOL_t disConnectHandle(TSKM_SVC_CTX_t* p_svc, + const TSKM_EVENT_INFO_t* p_inEv) { + // No status change + + return TSKM_TRUE; +} + +/********************************************************* + * Response handler for the activation request + * ret:TRUE SVC status changed + * ret:FALSE SVC status not changed + *********************************************************/ +TSKM_STATIC TSKM_BOOL_t resWakeupHandle(TSKM_SVC_CTX_t* p_svc, + const TSKM_EVENT_INFO_t* p_inEv) { + TSKM_ASSERT(p_svc->state == TSKM_SVC_WAKEUP); + TSKM_ASSERT(p_svc->waitResCnt > 0); + TSKM_BOOL_t isStateChg = TSKM_FALSE; + + if (p_svc->isShmDone == TSKM_FALSE && p_inEv->prm.resWakeup.isShmDone) { + p_svc->isShmDone = TSKM_TRUE; + isStateChg = TSKM_TRUE; + TSKM_PRINTF(TSKM_LOG_SVCSTATE, "%s:SHM DONE", p_svc->attr->name); + } + if (p_svc->isStepDone == TSKM_FALSE && p_inEv->prm.resWakeup.isStepDone) { + p_svc->isStepDone = TSKM_TRUE; + isStateChg = TSKM_TRUE; + TSKM_PRINTF(TSKM_LOG_SVCSTATE, "%s:STEP DONE", p_svc->attr->name); + } + + if (p_svc->waitResCnt > 0) { + p_svc->waitResCnt--; + if (p_svc->waitResCnt == 0) { // Transition when the wait runs out + if (p_inEv->prm.resWakeup.isLast) { + p_svc->state = TSKM_SVC_RUNNING; // Startup completed + TSKM_PRINTF(TSKM_LOG_SVCSTATE, "[ST:%d] RUN", p_svc->pid); + } + isStateChg = TSKM_TRUE; + } + } + return isStateChg; +} + +/********************************************************* + * Response handler for the termination request + * ret:TRUE SVC state changed + * ret:FALSE SVC state not changed + *********************************************************/ +TSKM_STATIC TSKM_BOOL_t resDownHandle(TSKM_SVC_CTX_t* p_svc, + const TSKM_EVENT_INFO_t* p_inEv) { + TSKM_ASSERT(p_svc->state == TSKM_SVC_DOWN); + TSKM_ASSERT(p_svc->waitResCnt > 0); + TSKM_BOOL_t isStateChg = TSKM_FALSE; + + TSKM_PRINTF(TSKM_LOG_DEBUG, "pid:%d waitCnt:%d", p_svc->pid, + p_svc->waitResCnt); + if (p_svc->waitResCnt > 0) { + p_svc->waitResCnt--; + if (p_svc->waitResCnt == 0) { // Transition when the wait runs out + if (p_inEv->prm.resWakeup.isLast) { + p_svc->state = TSKM_SVC_FINDOWN; // Termination complete + TSKM_PRINTF(TSKM_LOG_SVCSTATE, "[ST:%d] FIN_DOWN", p_svc->pid); + } + isStateChg = TSKM_TRUE; + } + } + return isStateChg; +} + +/********************************************************* + * Response Handlers for DebugDump Requests + * ret:TRUE SVC state changed + * ret:FALSE SVC state not changed + *********************************************************/ +TSKM_STATIC TSKM_BOOL_t resDebugDumpHandle(TSKM_SVC_CTX_t* p_svc, + const TSKM_EVENT_INFO_t* p_inEv) { + TSKM_BOOL_t isStateChg = TSKM_FALSE; + TSKM_EV_PRI_EX_RES_DEBUGDUMP_PRM_t *p_prm; + + if (!p_inEv->hasExtend || !p_inEv->extendPrm) { + TSKM_ASSERT(0); + goto ERROR; + } + + p_prm = (TSKM_EV_PRI_EX_RES_DEBUGDUMP_PRM_t *) p_inEv->extendPrm; // NOLINT (readability/casting) + + // FALSE is specified here because the required service names have been added in the PrimaryLib. + tskm_sub_debugDumpRes(FALSE, p_prm->dumpMsg); + + ERROR: return isStateChg; +} + +/********************************************************* + * Service termination request + * ret:TRUE SVC state changed + * ret:FALSE SVC state not changed + *********************************************************/ +TSKM_STATIC TSKM_BOOL_t reqExit(TSKM_SVC_CTX_t* p_svc, + const TSKM_EVENT_INFO_t* p_inEv) { + int ret; + TSKM_ERR_t tskmRet; + TSKM_ASSERT(p_svc->state == TSKM_SVC_RUNNING); + TSKM_ASSERT(p_svc->waitResCnt == 0); + TSKM_GSTEP_REQ_INFO_t req = { 0 }; + + req.svcId = p_svc->attr->svcId; + req.localStep = TSKM_LSTEP_ALL; + tskmRet = tskm_svcDownRequest(p_svc, &req); + TSKM_ERR_CHK_DFT; + + return TSKM_TRUE; + + // LCOV_EXCL_START 8: dead code + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + ERROR: ret = tskm_pf_terminateProcGroup(static_cast(p_svc->pid)); + if (ret != 0) { // LCOV_EXCL_BR_LINE 8: dead code + TSKM_PRINTF(TSKM_LOG_WARN, "ret = %d", ret); + } + + return TSKM_TRUE; + // LCOV_EXCL_STOP +} + +/********************************************************* + * Service termination handler + * ret:TRUE SVC state changed + * ret:FALSE SVC state not changed + *********************************************************/ +TSKM_STATIC TSKM_BOOL_t repTermHandle(TSKM_SVC_CTX_t* p_svc, + const TSKM_EVENT_INFO_t* p_inEv) { + int ret; + + // Check error + if (p_svc->attr->lifeCycle == TSKM_SVC_LC_DYNAMIC) { + if (p_svc->state != TSKM_SVC_DOWN) { + // A STATE other than DOWN does not terminate. + TSKM_PRINTF(TSKM_LOG_ERROR, "ERR TERM %s(%d) waitCnt:%d", + p_svc->attr->name, p_svc->pid, p_svc->waitResCnt); + TSKM_ASSERT(0); + } + } else { + // The resident service terminated. + TSKM_PRINTF(TSKM_LOG_ERROR, "ERR TERM %s(%d) waitCnt:%d", p_svc->attr->name, + p_svc->pid, p_svc->waitResCnt); + TSKM_ASSERT(0); + } + + TSKM_PRINTF(TSKM_LOG_STATE, "[ST:%d] DORMANT", p_svc->pid); + + p_svc->state = TSKM_SVC_DORMANT; + p_svc->waitResCnt = 0; + p_svc->pid = 0; + + if (p_svc->attr->type == TSKM_SVC_TYPE_NATIVE) { + EFrameworkunifiedStatus taskmanagerStatus; + TSKM_MAIN_CTX_t* p_main = tskm_getMainCtx(); + SS_String availabilityName = p_svc->attr->name; + availabilityName.append("/Availability"); + + taskmanagerStatus = FrameworkunifiedUnsubscribeNotificationWithCallback( + p_main->hApp, availabilityName.c_str()); + if (eFrameworkunifiedStatusOK != taskmanagerStatus) { + TSKM_ASSERT(0); + } + + p_svc->isAvailable = TSKM_FALSE; + p_svc->watchCnt = 0; + + HANDLE hMq = McOpenSender(FRAMEWORKUNIFIED_NS_NPSERVICE); + if (NULL == hMq) { // LCOV_EXCL_BR_LINE 4: NSFW error case. + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + TSKM_ASSERT(0); // LCOV_EXCL_LINE 4: NSFW error case. + } else { + ServiceAvailability availInfo = { }; + + snprintf(availInfo.cServiceName, MAX_NAME_SIZE_APP, "%s", + p_svc->attr->name); + availInfo.eServiceAvailability = eFrameworkunifiedServiceNotAvailable; + + taskmanagerStatus = NPPublishNotification(hMq, p_svc->attr->name, + availabilityName.c_str(), &availInfo, + sizeof(availInfo)); + if (eFrameworkunifiedStatusOK != taskmanagerStatus) { + TSKM_ASSERT(0); + } + + taskmanagerStatus = McClose(hMq); + if (eFrameworkunifiedStatusOK != taskmanagerStatus) { // LCOV_EXCL_BR_LINE 4: NSFW error case. + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + TSKM_ASSERT(0); // LCOV_EXCL_LINE 4: NSFW error case. + } + } + } + + if (p_inEv->errCode != TSKM_E_OK) { + p_svc->errTermCnt++; + // Notify 'NG' at Relaunch after abnormal termination + p_svc->bootInfo.resetStatus = e_SS_SM_RESET_STATUS_NG; + + ret = svcErrTermPost(p_svc); + if (ret != TSKM_E_OK) { + TSKM_ASSERT(0); + } + } else { + // NONE is notified at Relaunch after normal completion. + p_svc->bootInfo.resetStatus = e_SS_SM_RESET_STATUS_NONE; + } + + return TSKM_TRUE; +} + +/********************************************************* + * Get service context + *********************************************************/ +TSKM_SVC_CTX_t* +tskm_svcsGetSvcBySvcId(TSKM_SVCS_CTX_t* p_svcs, TSKM_SVCID_t svcId) { + return getSvcCtxBySvcId(p_svcs, svcId); +} + +/********************************************************* + * Get service context + *********************************************************/ +TSKM_SVC_CTX_t* +tskm_svcsGetSvcByPid(TSKM_SVCS_CTX_t* p_svcs, pid_t pid) { + return getSvcCtxByPid(p_svcs, pid); +} + +/********************************************************* + * Check for waiting services + *********************************************************/ +TSKM_BOOL_t tskm_svcsIsWaiting(TSKM_SVCS_CTX_t* p_svcs) { + uint32_t ii; + for (ii = 0; ii < p_svcs->svcNum; ii++) { + if (p_svcs->svcList[ii].waitResCnt > 0 + || p_svcs->svcList[ii].state == TSKM_SVC_WAITCONNECT) { + return TSKM_TRUE; + } + } + return TSKM_FALSE; +} + +/********************************************************* + * Check if ShutdownWait services are terminated + *********************************************************/ +TSKM_SVC_WAIT_STATE_t tskm_svcsGetSvcTermWaitState(TSKM_SVCS_CTX_t* p_svcs) { + uint32_t ii; + TSKM_SVC_WAIT_STATE_t waitState = TSKM_SVC_WAIT_NONE; + + for (ii = 0; ii < p_svcs->svcNum; ii++) { + if (p_svcs->svcList[ii].attr->shotdownWait) { + // Check shutdownWait SVC Only + if (p_svcs->svcList[ii].state != TSKM_SVC_DORMANT) { + // DORMANT is terminated or not started, so no checking is required + if (TSKM_SVC_LC_DYNAMIC != p_svcs->svcList[ii].attr->lifeCycle + && p_svcs->svcList[ii].state != TSKM_SVC_FINDOWN) { // Check of termination of resident SVCs + waitState = TSKM_SVC_WAIT_BOTH; + break; + } else if (TSKM_SVC_LC_DYNAMIC == p_svcs->svcList[ii].attr->lifeCycle) { // Check of termination of non-resident SVCs + waitState = TSKM_SVC_WAIT_TRANSIENT; + } + } + } + } + return waitState; +} + +/********************************************************* + * Update boot info of all services + *********************************************************/ +TSKM_ERR_t tskm_svcsSetBootInfo(TSKM_SVCS_CTX_t* p_svcs, + T_SS_SM_START_DataStructType* p_info, + T_SS_SM_START_ExtDataStructType *p_exInfo) { + uint32_t ii = 0; + + for (ii = 0; ii < p_svcs->svcNum; ii++) { + p_svcs->svcList[ii].bootInfo = *p_info; + p_svcs->svcList[ii].extBootInfo = *p_exInfo; + } + return TSKM_E_OK; +} + +/********************************************************* + * Terminates a running non-resident services + *********************************************************/ +TSKM_ERR_t tskm_svcsAvtiveSvcTerm(TSKM_SVCS_CTX_t* p_svcs) { + uint32_t ii; + + for (ii = 0; ii < p_svcs->svcNum; ii++) { + TSKM_SVC_CTX_t* p_svc = &p_svcs->svcList[ii]; + + if (TSKM_SVC_LC_DYNAMIC == p_svc->attr->lifeCycle && // Non-resident SVC + TSKM_SVC_RUNNING == p_svc->state && p_svc->waitResCnt == 0) { // Running + TSKM_ERR_t tskmRet; + TSKM_GSTEP_REQ_INFO_t req = { 0 }; + + req.svcId = p_svc->attr->svcId; + req.localStep = TSKM_LSTEP_ALL; + tskmRet = tskm_svcDownRequest(p_svc, &req); + TSKM_ERR_CHK_DFT; + } + } + + return TSKM_E_OK; + + ERROR: + return TSKM_E_NG; +} + +/********************************************************* + * Calls back the DebugDump of the running services + *********************************************************/ +TSKM_ERR_t tskm_svcsCallDebugDump(TSKM_SVCS_CTX_t* p_svcs) { + for (uint32_t ii = 0; ii < p_svcs->svcNum; ii++) { + TSKM_SVC_CTX_t* p_svc = &p_svcs->svcList[ii]; + + if (TSKM_SVC_RUNNING == p_svc->state) { // Running + TSKM_EVENT_INFO_t ev; + bzero(&ev, sizeof(ev)); + + // Send DebugDump request + ev.event = TSKM_EV_PRI_REQ_DEBUGDUMP; + ev.errCode = TSKM_E_OK; + if (0 >= tskm_sockSend(p_svc->connFd, &ev)) { + TSKM_ASSERT(0); + goto ERROR; + } + } + } + + return TSKM_E_OK; + ERROR: return TSKM_E_NG; +} + +/********************************************************* + * Calls back the LowMemory of the running services + *********************************************************/ +TSKM_ERR_t tskm_svcsCallLowMem(TSKM_SVCS_CTX_t* p_svcs) { + for (uint32_t ii = 0; ii < p_svcs->svcNum; ii++) { + TSKM_SVC_CTX_t* p_svc = &p_svcs->svcList[ii]; + if (TSKM_SVC_RUNNING == p_svc->state) { // Running + TSKM_EVENT_INFO_t ev; + bzero(&ev, sizeof(ev)); + + // Send LowMemory detection notification + ev.event = TSKM_EV_PRI_REP_LOWMEM; + ev.errCode = TSKM_E_OK; + if (0 >= tskm_sockSend(p_svc->connFd, &ev)) { + TSKM_ASSERT(0); + goto ERROR; + } + } + } + + return TSKM_E_OK; + ERROR: return TSKM_E_NG; +} + +/********************************************************* + * Event handler + *********************************************************/ +TSKM_ERR_t tskm_svcEventHandle(TSKM_SVC_CTX_t* p_svc, TSKM_EVENT_INFO_t* p_ev) { + TSKM_FUNC_IN(); + TSKM_BOOL_t isStateChg = TSKM_FALSE; + + if (isSvcEvent(p_ev) == TSKM_FALSE) { + // If it is not an event for the service, it will be sent as follows. + TSKM_FUNC_OUT(); + return TSKM_E_OK; + } + + switch (p_ev->event) { + case TSKM_EV_PRI_REP_CONNECT: // Connection Registration from Service + isStateChg = connectHandle(p_svc, p_ev); + break; + case TSKM_EV_PRI_REP_DISCONNECT: // Disconnection Registration from Service + isStateChg = disConnectHandle(p_svc, p_ev); + break; + case TSKM_EV_PRI_RES_WAKEUP: // Response to a startup request from a service + isStateChg = resWakeupHandle(p_svc, p_ev); + break; + case TSKM_EV_PRI_RES_DOWN: + isStateChg = resDownHandle(p_svc, p_ev); + break; + case TSKM_EV_PRI_RES_DEBUGDUMP: + isStateChg = resDebugDumpHandle(p_svc, p_ev); + break; + case TSKM_EV_PRI_REQ_EXIT: + isStateChg = reqExit(p_svc, p_ev); + break; + case TSKM_EV_SVC_REP_TERM: // Service termination + isStateChg = repTermHandle(p_svc, p_ev); + break; + default: + break; + } + + // Overwrite service state change + if (isStateChg) { + p_ev->event = TSKM_EV_LCL_CHG_SVC_STATE; + p_ev->prm.chgSvc.svcId = p_svc->attr->svcId; + } else { + p_ev->event = TSKM_EV_NOP; + } + + TSKM_FUNC_OUT(); + return TSKM_E_OK; +} +/********************************************************* + * Startup service + *********************************************************/ +TSKM_ERR_t tskm_svcExec(TSKM_SVC_CTX_t* p_svc) { + return svcExec(p_svc); +} + +/********************************************************* + * Issue a startup request to the service + *********************************************************/ +TSKM_ERR_t tskm_svcWakeupRequest(TSKM_SVC_CTX_t* p_svc, + TSKM_GSTEP_REQ_INFO_t* p_req) { + return svcWakeupRequest(p_svc, p_req); +} + +/********************************************************* + * Issue a termination request to the service + *********************************************************/ +TSKM_ERR_t tskm_svcDownRequest(TSKM_SVC_CTX_t* p_svc, + TSKM_GSTEP_REQ_INFO_t* p_req) { + int ret; + TSKM_EVENT_INFO_t ev; + + bzero(&ev, sizeof(ev)); + + if (tskm_svcIsCommunicatable(p_svc) == TSKM_FALSE) { + return TSKM_E_OK; + } + + ev.event = TSKM_EV_PRI_REQ_DOWN; + ev.errCode = TSKM_E_OK; + ev.prm.reqDown.localStep = p_req->localStep; + + ret = tskm_sockSend(p_svc->connFd, &ev); + if (ret <= 0) { + TSKM_ASSERT(0); + goto ERROR; + } + p_svc->waitResCnt++; + p_svc->state = TSKM_SVC_DOWN; + + return TSKM_E_OK; + ERROR: return TSKM_E_NG; +} + +/********************************************************* + * Prohibit starting service + *********************************************************/ +TSKM_ERR_t tskm_svcDisableRequest(TSKM_SVC_CTX_t* p_svc) { + if (p_svc->state == TSKM_SVC_DORMANT || p_svc->state == TSKM_SVC_DISABLE) { + p_svc->state = TSKM_SVC_DISABLE; + return TSKM_E_OK; + } + return TSKM_E_STATE; +} + +/********************************************************* + * Allow starting service + *********************************************************/ +TSKM_ERR_t tskm_svcEnableRequest(TSKM_SVC_CTX_t* p_svc) { + if (p_svc->state == TSKM_SVC_DISABLE) { + p_svc->state = TSKM_SVC_DORMANT; + } + return TSKM_E_OK; +} + +/********************************************************* + * Queriy whether the service is ready for communication + *********************************************************/ +TSKM_BOOL_t tskm_svcIsCommunicatable(TSKM_SVC_CTX_t* p_svc) { + TSKM_BOOL_t ret = TSKM_FALSE; + if (p_svc == NULL || p_svc->attr->type == TSKM_SVC_TYPE_UNKNONW) { + } else { + switch (p_svc->state) { + case TSKM_SVC_WAKEUP: + case TSKM_SVC_RUNNING: + case TSKM_SVC_DOWN: + ret = TSKM_TRUE; + break; + default: + break; + } + } + return ret; +} // LCOV_EXCL_BR_LINE 10: Final line + diff --git a/systemservice/task_manager/server/src/tskm_wakeup.cpp b/systemservice/task_manager/server/src/tskm_wakeup.cpp new file mode 100755 index 0000000..b5c6e89 --- /dev/null +++ b/systemservice/task_manager/server/src/tskm_wakeup.cpp @@ -0,0 +1,201 @@ +/* + * @copyright Copyright (c) 2016-2020 TOYOTA MOTOR CORPORATION. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "tskm_wakeup.h" +#include "tskm_debug.h" +#include "tskm_util.h" +#include "tskm_state.h" +#include "tskm_port_subsys.h" +#include "tskm_port_pf.h" + +#include "tskm_gstep.h" + + +/********************************************************* + * Get gradual startup context + *********************************************************/ +TSKM_STATIC TSKM_GSTEP_CTX_t* +gstepGetWakeupCtx(TSKM_MAIN_CTX_t* p_main) { + return &p_main->wakeup; +} + +/*********************************************************************** + * Startup completion process + ***********************************************************************/ +TSKM_STATIC void wakeupFinish(TSKM_MAIN_CTX_t* p_main) { + return; +} + +/********************************************************* + * Challenge for a transition to the next state + *********************************************************/ +TSKM_STATIC void tryTransNextState(TSKM_MAIN_CTX_t* p_main) { + TSKM_GSTEP_CTX_t* p_wakeup; + TSKM_GSTEP_t* p_current; + + p_wakeup = gstepGetWakeupCtx(p_main); + p_current = gstepGetCurrent(p_wakeup); + + if (!p_current) { + return; + } + + // LCOV_EXCL_BR_START 8: Because the second condition in the if statement is never false + if (tskm_svcsIsWaiting(&p_main->svcs) == TSKM_FALSE && // No waiting services + ((p_wakeup->compState & p_current->nextTransCond) + == p_current->nextTransCond)) { // Event completion condition + // LCOV_EXCL_BR_STOP + if (gstepIsLast(p_wakeup)) { + tskm_stateTransit(p_main, TSKM_ST_WAKEUP, TSKM_ST_RUNNING); + } else { + tskm_stateTransit(p_main, TSKM_ST_WAKEUP, TSKM_ST_WAKEUP); + } + } +} + +/********************************************************* + * Gradual startup request issuance process + *********************************************************/ +TSKM_ERR_t tskm_entryWakeup_Req(TSKM_MAIN_CTX_t* p_main, + TSKM_GSTEP_t* p_current) { + uint32_t ii; + + // Refer to the stepId and perform preprocessing if needed. + if (p_current->gstepId == TSKM_GSTEP_BUPCHK) { + TSKM_PRINTF(TSKM_LOG_STATE, "BUPCHK EXE"); + // When TaskManager is used as a system Launcher, system data is initialized here. + } + + // Start process + for (ii = 0; ii < p_current->execSvcNum; ii++) { + TSKM_ERR_t tskmRet; + TSKM_SVCID_t svcId = p_current->execSvcIdList[ii]; + TSKM_SVC_CTX_t* p_svc = tskm_svcsGetSvcBySvcId(&p_main->svcs, svcId); + + tskmRet = tskm_svcExec(p_svc); + TSKM_ERR_CHK_DFT; + } + + // Issue gradual startup request + for (ii = 0; ii < p_current->reqNum; ii++) { + TSKM_ERR_t tskmRet; + TSKM_GSTEP_REQ_INFO_t* p_req = &p_current->reqList[ii]; + TSKM_SVC_CTX_t* p_svc = tskm_svcsGetSvcBySvcId(&p_main->svcs, p_req->svcId); + + // Queuing in the SVC layer even for services that are not started. + tskmRet = tskm_svcWakeupRequest(p_svc, p_req); + TSKM_ERR_CHK_DFT; // LCOV_EXCL_BR_LINE 6: Because TSKM_ERR_CHK_DFT does not specify a condition for goto to ERROR + } + + if (p_current->nextTransCond) { + TSKM_PRINTF(TSKM_LOG_STATE, "WAIT COMP:%s(%llx)", + tskm_convInitCompId2Str(p_current->nextTransCond), + p_current->nextTransCond); + } + + return TSKM_E_OK; + + // LCOV_EXCL_START 6: Checked in Death testing, but it is not reflected in the coverage and excluded + ERROR: + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + return TSKM_E_NG; + // LCOV_EXCL_STOP +} + +/********************************************************* + * Gradual startup entry process + *********************************************************/ +TSKM_ERR_t tskm_entryWakeup(TSKM_MAIN_CTX_t* p_main) { + TSKM_FUNC_IN(); + + TSKM_GSTEP_CTX_t* p_wakeup; + TSKM_GSTEP_t* p_current; + + p_main->state = TSKM_ST_WAKEUP; + p_wakeup = gstepGetWakeupCtx(p_main); + p_current = gstepGetCurrent(p_wakeup); + + if (p_current == NULL) { // LCOV_EXCL_BR_LINE 8: Because condition false setting is not possible + // LCOV_EXCL_START 8: Because condition false setting is not possible + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + TSKM_ASSERT(0); + tskm_pf_exit(EXIT_FAILURE); + // LCOV_EXCL_STOP + } + + TSKM_PRINTF(TSKM_LOG_SVCSTATE, "WAKEUP GSTEP:%d", p_wakeup->gstepIdx); + + if (tskm_entryWakeup_Req(p_main, p_current) == TSKM_E_NG) { // LCOV_EXCL_BR_LINE 200:the function of tskm_entryWakeup_Req can not be TSKM_E_NG at this case // NOLINT(whitespace/line_length) + // LCOV_EXCL_START 200:the function of tskm_entryWakeup_Req can not be TSKM_E_NG at this case // NOLINT(whitespace/line_length) + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + tskm_pf_exit(EXIT_FAILURE); + // LCOV_EXCL_STOP + } + + TSKM_FUNC_OUT(); + return TSKM_E_OK; +} + +/********************************************************* + * Gradual startup exit process + *********************************************************/ +TSKM_ERR_t tskm_exitWakeup(TSKM_MAIN_CTX_t* p_main) { + TSKM_GSTEP_CTX_t* p_wakeup; + + TSKM_FUNC_IN(); + p_wakeup = gstepGetWakeupCtx(p_main); + + // Exit process at the end of the gradual startup + if (gstepIsLast(p_wakeup)) { + TSKM_PRINTF(TSKM_LOG_STATE, "WAKEUP FIN"); + wakeupFinish(p_main); + } + + changeNextStep(p_wakeup); // Transition to next step + + TSKM_FUNC_OUT(); + return TSKM_E_OK; +} + +/********************************************************* + * Gradual startup handler + *********************************************************/ +TSKM_ERR_t tskm_handleWakeup(TSKM_MAIN_CTX_t* p_main, TSKM_EVENT_INFO_t* p_ev) { + TSKM_FUNC_IN(); + TSKM_ERR_t tskmRet = TSKM_E_OK; + + switch (p_ev->event) { + case TSKM_EV_PRI_REP_WAKEUP_COMP: // Event completion notification at startup + { + TSKM_PRINTF(TSKM_LOG_SVCSTATE, "INIT COMP :%s(%#llx) from:%d", + tskm_convInitCompId2Str(p_ev->prm.repWakeupComp.compId), + p_ev->prm.repWakeupComp.compId, p_ev->fromPid); + TSKM_GSTEP_CTX_t* p_wakeup = gstepGetWakeupCtx(p_main); + p_wakeup->compState |= p_ev->prm.repWakeupComp.compId; + tryTransNextState(p_main); + } + break; + case TSKM_EV_LCL_CHG_SVC_STATE: // Service state change + tryTransNextState(p_main); + break; + default: + tskmRet = tskm_handleAccon(p_main, p_ev); + break; + } + TSKM_FUNC_OUT(); + return tskmRet; +} // LCOV_EXCL_BR_LINE 10: Final line + diff --git a/systemservice/task_manager/server/src/tskm_watch.cpp b/systemservice/task_manager/server/src/tskm_watch.cpp new file mode 100755 index 0000000..455de0b --- /dev/null +++ b/systemservice/task_manager/server/src/tskm_watch.cpp @@ -0,0 +1,101 @@ +/* + * @copyright Copyright (c) 2016-2020 TOYOTA MOTOR CORPORATION. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "tskm_watch.h" +#include + +#include "tskm_debug.h" +#include "tskm_port_pf.h" +#include "tskm_comm.h" + + +#define WATCH_CYCLE 5 + +#define TIMER_THREAD_NAME "SS_TskmTimer" + +/******************************************************************* + * Periodic Timer-Thread MAIN Function + *******************************************************************/ +void * +watchMain(void *arg) { + int connFd = -1; + + connFd = tskm_cliSockConnect(TSKM_SOCKET_NAME); + if (connFd < 0) { // LCOV_EXCL_BR_LINE 5: system function(uinx) "socket" fail process + // LCOV_EXCL_START 5: system function(uinx) "socket" fail process + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + TSKM_ASSERT(0); + goto ERROR; + // LCOV_EXCL_STOP 5 + } + + while (1) { + int ret; + TSKM_EVENT_INFO_t ev; + + sleep(WATCH_CYCLE); + + ev.event = TSKM_EV_LCL_REP_POLLING; + ev.errCode = TSKM_E_OK; + ret = tskm_sockSend(connFd, &ev); + if (ret <= 0) { // LCOV_EXCL_BR_LINE 5: system function(uinx) "send" fail process + // LCOV_EXCL_START 5: system function(uinx) "send" fail process + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + TSKM_ASSERT(0); + goto ERROR; + // LCOV_EXCL_STOP 5 + } + } + + // LCOV_EXCL_START 6: system function(uinx) call fail process + ERROR: + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + if (connFd != -1) { + tskm_sockDestory(connFd); + } + + return 0; + // LCOV_EXCL_STOP +} + +/******************************************************************* + * Periodic Timer thread start + *******************************************************************/ +int tskm_watch_startTimer() { + int ret; + pthread_t thId = { 0 }; + + ret = tskm_pf_createThread(watchMain, NULL, PR_SS_TSKMTIMER, + TIMER_THREAD_NAME, &thId); + if (ret != 0) { // LCOV_EXCL_BR_LINE 5: system function(uinx) "pthread_*" fail process + // LCOV_EXCL_START 5: system function(uinx) "pthread_*" fail process + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + TSKM_ASSERT(0); + goto ERROR; + // LCOV_EXCL_STOP 5 + } else { + TSKM_PRINTF(TSKM_LOG_STATE, "watch thread created."); + } + + return 0; + + // LCOV_EXCL_LINE 6: system function(uinx) "pthread_*" fail process + ERROR: + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + return -1; + // LCOV_EXCL_STOP +} + -- cgit 1.2.3-korg