diff options
Diffstat (limited to 'task_manager/client/libtskmcfg')
13 files changed, 1628 insertions, 0 deletions
diff --git a/task_manager/client/libtskmcfg/Makefile b/task_manager/client/libtskmcfg/Makefile new file mode 100644 index 00000000..40a1ca65 --- /dev/null +++ b/task_manager/client/libtskmcfg/Makefile @@ -0,0 +1,97 @@ +# +# @copyright Copyright (c) 2016-2019 TOYOTA MOTOR CORPORATION. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +SVCONF_DIR=$(DESTDIR)/usr/agl/conf/tm_launch +THREADCONF_DIR=$(DESTDIR)/usr/agl/conf/thread +WAKESHUTCONF_DIR=./conf + +VPATH = ./src ./include/$(COMPONENT_NAME) + +INST_SHLIBS = libtskmcfg +INST_HEADERS = tskm_xml_data.h tskm_svcid.h task_manager_libtskmcfg.h +libtskmcfg_SRCS = tskm_xml_data.cpp + + +CPPFLAGS = -I./ -I./include -I./../../include-share -I./../../server/include +LDFLAGS += -Wl,--no-as-needed +LDLIBS += -Wl,-Bdynamic -lNS_FrameworkUnified + + +#============ XML PARSE ============ +XMLOUTFILE= tskm_auto_build.h + +CLEAN_FILES+=$(XMLOUTFILE) $(PARSEXMLCMD) $(CONFIG_FILES) top.xml + +#TOOLS +HOST_CPP=cpp +XMLCHECKER=xmllint +XMLCHECKEROPT=--noout --valid +PARSEXMLCMD=parsexml +HOSTCC=gcc +XMLFILETOP=tskm_cfg.xml + +install:install-pre install-pre-header +build-lib:install-pre install-pre-header +install-lib:install-pre install-pre-header +install-pre: + install -d -m 775 $(DESTDIR)/usr/agl/conf/tm_launch;\ + install -d -m 775 $(DESTDIR)/usr/agl/conf/thread;\ + install -m 644 -t $(DESTDIR)/usr/agl/conf/tm_launch $(WAKESHUTCONF_DIR)/tskm_launch.xml;\ + install -m 644 -t $(DESTDIR)/usr/agl/conf/thread $(SDKTARGETSYSROOT)/usr/agl/include/agl_thread.h + +CONFIG_FILES:=tskm_wakeup.xml tskm_shutdown.xml tskm_wakeup_vup.xml tskm_shutdown_vup.xml tskm_launch.xml tskm_svcid.h agl_thread.h + +#install-header:$(XMLOUTFILE) +install-pre-header:$(XMLOUTFILE) + +#TOPFILE +top.xml:$(XMLFILETOP) + ln -fs $< $@ + +#CONFIG RULES +tskm_wakeup.xml:$(WAKESHUTCONF_DIR)/tskm_wakeup.xml + ln -fs $< $@ + +tskm_shutdown.xml:$(WAKESHUTCONF_DIR)/tskm_shutdown.xml + ln -fs $< $@ + +tskm_wakeup_vup.xml:$(WAKESHUTCONF_DIR)/tskm_wakeup_vup.xml + ln -fs $< $@ + +tskm_shutdown_vup.xml:$(WAKESHUTCONF_DIR)/tskm_shutdown_vup.xml + ln -fs $< $@ + +#tskm_svcid.h:$(SVCONF_DIR)/tskm_svcid.h +# ln -fs $< $@ + +agl_thread.h:$(THREADCONF_DIR)/agl_thread.h + ln -fs $< $@ + + +tskm_launch.xml:$(SVCONF_DIR)/tskm_launch.xml agl_thread.h + $(HOST_CPP) -P -include agl_thread.h $< > $@ +#tskm_launch.xml:$(SVCONF_DIR)/tskm_launch.xml $(SDKTARGETSYSROOT)/usr/agl/include/agl_thread.h +# $(HOST_CPP) -P -include agl_thread.h $< > $@ + +$(XMLOUTFILE):top.xml $(PARSEXMLCMD) $(CONFIG_FILES) + $(XMLCHECKER) $(XMLCHECKEROPT) $< + ./$(PARSEXMLCMD) $< + +$(PARSEXMLCMD):$(PARSEXMLCMD).c + $(HOSTCC) -o $@ $< -lexpat + +include ../../../system_service.mk + diff --git a/task_manager/client/libtskmcfg/conf/tskm_launch.xml b/task_manager/client/libtskmcfg/conf/tskm_launch.xml new file mode 100644 index 00000000..d4ab06ce --- /dev/null +++ b/task_manager/client/libtskmcfg/conf/tskm_launch.xml @@ -0,0 +1,106 @@ +<service_list> + <service + svcid="TSKM_SVCID_ACTIVITYMGR" + name=MN_ACTIVITYMANAGER + path="/usr/agl/bin/acmsrv" + prio=PR_ACTIVITYMANAGER_S + policy="tss" + life_cycle="always" + user="" + shutdown_wait="yes" /> + + <service + svcid="TSKM_SVCID_TE_RESIDENT" + name=MN_RESIDENT_SVC + path="/usr/agl/bin/resident" + prio=PR_RESIDENT_SVC_S + policy="tss" + life_cycle="always" + user="" + shutdown_wait="no" /> + + <service + svcid="TSKM_SVCID_TE_TRANSIENT" + name =MN_TRANSIENT_SVC + path="/usr/agl/bin/transient" + prio=PR_TRANSIENT_SVC_S + policy="tss" + user="" + shutdown_wait="no" /> + + + <service + svcid="TSKM_SVCID__CWORD58_" + name =MN__CWORD58_SERVICE + path="/usr/agl/bin/_CWORD58_Service" + prio=PR__CWORD58_SERVICE_S + policy="tss" + retry_cnt="-1" + user="" + shutdown_wait="yes" /> + + <service + svcid="TSKM_SVCID_SYSUPDATE" + name =MN_PS_SYSUPDATE + path="/usr/bin/sysupdate" + prio=PR_PS_SYSUPDATE_S + policy="tss" + user="" + shutdown_wait="no" /> + + <service + svcid="TSKM_SVCID_NANDUPDATE" + name =MN_SS_NANDUPDATE + path="/usr/bin/nandupdate" + prio=PR_SS_NANDUPDATE_S + policy="tss" + user="" + shutdown_wait="no" /> + + <service + svcid="TSKM_SVCID_XMVUPSRV" + name =MN_XMVUPSERVICE + path="/usr/agl/bin/radio_xm_update" + prio=PR_XMVUPSERVICE_S + policy="tss" + user="" + shutdown_wait="no" /> + + <service + svcid="TSKM_SVCID_BTPHONESRV" + name =MN_BTPHONESRV + path="/usr/agl/bin/BT_PhoneSrv" + prio=PR_BTPHONESRV_S + policy="tss" + user="" + shutdown_wait="no" /> + + <service + svcid="TSKM_SVCID_BTPBKSRV" + name =MN_BTPBKSRV + path="/usr/agl/bin/BT_PbkSrv" + prio=PR_BTPBKSRV_S + policy="tss" + user="" + shutdown_wait="no" /> + + <service + svcid="TSKM_SVCID_BTMSGSRV" + name =MN_BTMSGSRV + path="/usr/agl/bin/BT_MsgSrv" + prio=PR_BTMSGSRV_S + policy="tss" + user="" + shutdown_wait="no" /> + + <service + svcid="TSKM_SVCID_DTVVUPSRV" + name =MN_DTVVUPSERVICE + path="/usr/agl/bin/DtvVupService" + prio=PR_DTVVUPSERVICE_S + policy="tss" + user="" + shutdown_wait="no" /> + +</service_list> + diff --git a/task_manager/client/libtskmcfg/conf/tskm_shutdown.xml b/task_manager/client/libtskmcfg/conf/tskm_shutdown.xml new file mode 100644 index 00000000..4f724f75 --- /dev/null +++ b/task_manager/client/libtskmcfg/conf/tskm_shutdown.xml @@ -0,0 +1,11 @@ +<normal_shutdown> + <global_step> + <request_list> + <request svcid="TSKM_SVCID_TE_RESIDENT" local_step="last" /> + <!-- <request svcid="TSKM_SVCID_ACTIVITYMGR" local_step="last" /> --> + </request_list> + + <next_trans_condition cond="INI_TERMCOMP_TRANSIENT" /> + </global_step> +</normal_shutdown> + diff --git a/task_manager/client/libtskmcfg/conf/tskm_shutdown_vup.xml b/task_manager/client/libtskmcfg/conf/tskm_shutdown_vup.xml new file mode 100644 index 00000000..71a30c82 --- /dev/null +++ b/task_manager/client/libtskmcfg/conf/tskm_shutdown_vup.xml @@ -0,0 +1,6 @@ +<vup_shutdown> + <global_step> + <next_trans_condition cond="INI_TERMCOMP_TRANSIENT" /> + </global_step> +</vup_shutdown> + diff --git a/task_manager/client/libtskmcfg/conf/tskm_wakeup.xml b/task_manager/client/libtskmcfg/conf/tskm_wakeup.xml new file mode 100644 index 00000000..aeb35485 --- /dev/null +++ b/task_manager/client/libtskmcfg/conf/tskm_wakeup.xml @@ -0,0 +1,8 @@ +<normal_wakeup> + <global_step> + <next_trans_condition cond="INI_INITCOMP_ON_START" /> + </global_step> + <global_step> + <next_trans_condition cond="INI_INITCOMP_NVM_ACCESS" /> + </global_step> +</normal_wakeup> diff --git a/task_manager/client/libtskmcfg/conf/tskm_wakeup_vup.xml b/task_manager/client/libtskmcfg/conf/tskm_wakeup_vup.xml new file mode 100644 index 00000000..7162fdf3 --- /dev/null +++ b/task_manager/client/libtskmcfg/conf/tskm_wakeup_vup.xml @@ -0,0 +1,5 @@ +<vup_wakeup> + <global_step> + <next_trans_condition cond="INI_INITCOMP_NVM_ACCESS" /> + </global_step> +</vup_wakeup> diff --git a/task_manager/client/libtskmcfg/include/system_service/task_manager_libtskmcfg.h b/task_manager/client/libtskmcfg/include/system_service/task_manager_libtskmcfg.h new file mode 100644 index 00000000..2b765bca --- /dev/null +++ b/task_manager/client/libtskmcfg/include/system_service/task_manager_libtskmcfg.h @@ -0,0 +1,40 @@ +/* + * @copyright Copyright (c) 2017-2019 TOYOTA MOTOR CORPORATION. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +/** + * @file task_manager_libtskmcfg.h + * @brief \~english This file include tskm_svcid.h file and tskm_xml_data.h file + */ +/** @addtogroup BaseSystem + * @{ + */ +/** @addtogroup system_service + * @ingroup BaseSystem + * @{ + */ +/** @addtogroup task_manager + * @ingroup system_service + * @{ + */ +#ifndef SYSTEMSERVICE_TASKMNAGERLIBTASKMCFG_H_ // NOLINT(build/header_guard) +#define SYSTEMSERVICE_TASKMNAGERLIBTASKMCFG_H_ + +#include "system_service/tskm_svcid.h" +#include "system_service/tskm_xml_data.h" + +#endif // SYSTEMSERVICE_TASKMNAGERLIBTASKMCFG_H_ +/** @}*/ +/** @}*/ +/** @}*/ diff --git a/task_manager/client/libtskmcfg/include/system_service/tskm_svcid.h b/task_manager/client/libtskmcfg/include/system_service/tskm_svcid.h new file mode 100644 index 00000000..633d2b4d --- /dev/null +++ b/task_manager/client/libtskmcfg/include/system_service/tskm_svcid.h @@ -0,0 +1,59 @@ +/* + * @copyright Copyright (c) 2016-2019 TOYOTA MOTOR CORPORATION. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +/** + * @file tskm_svcid.h + * @brief \~english This file contains declaration of TSKM_SVC ID + */ +/** @addtogroup BaseSystem + * @{ + */ +/** @addtogroup system_service + * @ingroup BaseSystem + * @{ + */ +/** @addtogroup task_manager + * @ingroup system_service + * @{ + */ +/* + * Service ID + */ +#ifndef TASK_MANAGER_CLIENT_LIBTSKMCFG_INCLUDE_SYSTEM_SERVICE_TSKM_SVCID_H_ +#define TASK_MANAGER_CLIENT_LIBTSKMCFG_INCLUDE_SYSTEM_SERVICE_TSKM_SVCID_H_ + + +#define TSKM_SVCID_NONE 0x00000000U +#define TSKM_SVCID_TE_RESIDENT 0x00000001U // for test +#define TSKM_SVCID_TE_TRANSIENT 0x00000002U // for test +#define TSKM_SVCID_ACTIVITYMGR 0x00000003U +#define TSKM_SVCID_SYSVUP 0x00000004U // for vup +#define TSKM_SVCID__CWORD52_VUP 0x00000005U // for vup +#define TSKM_SVCID_ROOTFSVUP 0x00000006U // for vup +#define TSKM_SVCID_VUPPROGUI 0x00000007U // for vup +#define TSKM_SVCID_NORVUP 0x00000008U // for vup +#define TSKM_SVCID__CWORD58_ 0x00000009U // for _CWORD76_ +#define TSKM_SVCID_SYSUPDATE 0x0000000AU // for repro vup +#define TSKM_SVCID_NANDUPDATE 0x0000000BU // for repro vup +#define TSKM_SVCID_BTPHONESRV 0x0000000CU +#define TSKM_SVCID_BTPBKSRV 0x0000000DU +#define TSKM_SVCID_BTMSGSRV 0x0000000EU +#define TSKM_SVCID_DTVVUPSRV 0x0000000FU // fot peaks vup +#define TSKM_SVCID_XMVUPSRV 0x00000020U // fot XM_outer_update vup + +#endif // TASK_MANAGER_CLIENT_LIBTSKMCFG_INCLUDE_SYSTEM_SERVICE_TSKM_SVCID_H_ +/** @}*/ +/** @}*/ +/** @}*/ diff --git a/task_manager/client/libtskmcfg/include/system_service/tskm_xml_data.h b/task_manager/client/libtskmcfg/include/system_service/tskm_xml_data.h new file mode 100644 index 00000000..d1d3407e --- /dev/null +++ b/task_manager/client/libtskmcfg/include/system_service/tskm_xml_data.h @@ -0,0 +1,173 @@ +/* + * @copyright Copyright (c) 2016-2019 TOYOTA MOTOR CORPORATION. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +/** + * @file tskm_xml_data.h + * @brief \~english This file provide api to operating task manager with XML data + */ +/** @addtogroup BaseSystem + * @{ + */ +/** @addtogroup system_service + * @ingroup BaseSystem + * @{ + */ +/** @addtogroup task_manager + * @ingroup system_service + * @{ + */ +#ifndef TASK_MANAGER_CLIENT_LIBTSKMCFG_INCLUDE_SYSTEM_SERVICE_TSKM_XML_DATA_H_ +#define TASK_MANAGER_CLIENT_LIBTSKMCFG_INCLUDE_SYSTEM_SERVICE_TSKM_XML_DATA_H_ + +#include "system_service/tskm_type.h" +#include "system_service/tskm_svc.h" + + +#ifdef __cplusplus +extern "C" { +#endif + + ///////////////////////////////////////////////////////////////////////////////////// + /// \ingroup tskm_initServiceList + /// \~english @par Summary + /// init started services list + /// \~english @param [out] p_svcs + /// p_svcs - pointer of service list + /// \~english @par + /// p_svcs TSKM_SVCS_CTX_t* + /// \~english @code + /// typedef struct { + /// uint32_t svcNum; // service num + /// TSKM_SVC_CTX_t *svcList; // services list pointer + /// } TSKM_SVCS_CTX_t; + /// @endcode + /// \~english @param [in] iFd + /// iFd - the file descriptor return by inotify_init1(). + /// \~english @par + /// p_svcs int + /// \~english @retval 0 Success + /// \~english @retval -1 Failed + /// \~english @par Preconditions + /// - called in the ctxCreate() + /// \~english @par Change of the internal state + /// - The internal state is not changed. + /// \~english @par Causes of failures + /// - if srvId in serviceList greater than TSKM_SVC_ID_MAX_SIZE. [-1] + /// \~english @par Classification + /// - public + /// \~english @par Type + /// - sync only + /// \~english @par Detail + /// Init started services list\n + /// Get the started services list from static variable serviceList and init by input parameter iFd\n + /// If envirment is NFS, change the path after /tmp to CAP path.\n + /// + /// \~english @see None + //////////////////////////////////////////////////////////////////////////////////// +int tskm_initServiceList(TSKM_SVCS_CTX_t* p_svcs, int iFd); + + ///////////////////////////////////////////////////////////////////////////////////// + /// \ingroup tskm_initWakeupCtx + /// \~english @par Summary + /// Get state of started step. + /// \~english @param [out] p_wakeup + /// p_wakeup - pointer of TSKM_GSTEP_CTX_t + /// \~english @par + /// p_wakeup TSKM_GSTEP_CTX_t* + /// \~english @code + /// typedef struct { + /// uint32_t gstepIdx; // step Index + /// uint32_t gstepNum; // number of step + /// TSKM_GSTEP_t* gstep; // step start/stop info + /// uint64_t compState; + /// } TSKM_GSTEP_CTX_t; + /// @endcode + /// \~english @param [in] isVupMode + /// isVupMode - version up flag + /// \~english @par + /// isVupMode BOOL + /// TRUE version up mode + /// FALSE not versoin up mode + /// \~english @retval void + /// + /// \~english @par Preconditions + /// - called in ctxCreate() + /// \~english @par Change of the internal state + /// - The internal state is not changed. + /// \~english @par Causes of failures + /// - none + /// \~english @par Classification + /// - public + /// \~english @par Type + /// - sync only + /// \~english @par Detail + /// Get state of started step.\n + /// if version up mode is TRUE, retrun the wakeupGstepVup.\n + /// if version up mode is FALSE, return the wakeupGstep.\n + /// + /// \~english @see None + //////////////////////////////////////////////////////////////////////////////////// +void tskm_initWakeupCtx(TSKM_GSTEP_CTX_t* p_wakeup, BOOL isVupMode); + + + ///////////////////////////////////////////////////////////////////////////////////// + /// \ingroup tskm_initDownCtx + /// \~english @par Summary + /// Get state of down step. + /// \~english @param [out] p_down + /// p_down - pointer of TSKM_GSTEP_CTX_t + /// \~english @par + /// p_wakeup TSKM_GSTEP_CTX_t* + /// \~english @code + /// typedef struct { + /// uint32_t gstepIdx; // step Index + /// uint32_t gstepNum; // number of step + /// TSKM_GSTEP_t* gstep; // step start/stop info + /// uint64_t compState; + /// } TSKM_GSTEP_CTX_t; + /// @endcode + /// \~english @param [in] isVupMode + /// isVupMode - version up mode flag + /// \~english @par + /// isVupMode BOOL + /// TRUE version up mode + /// FALSE not versoin up mode + /// \~english @retval + /// \~english @par Preconditions + /// - called in ctxCreate(). + /// \~english @par Change of the internal state + /// - The internal state is not changed. + /// \~english @par Causes of failures + /// - none + /// \~english @par Classification + /// - public + /// \~english @par Type + /// - sync only + /// \~english @par Detail + /// Get state of down step.\n + /// if version up mode is TRUE, retrun the downGstepVup.\n + /// if version up mode is FALSE, return the downGstep.\n + /// \~english @see None + //////////////////////////////////////////////////////////////////////////////////// +void tskm_initDownCtx(TSKM_GSTEP_CTX_t* p_down, BOOL isVupMode); + +#ifdef __cplusplus +} +#endif + +#endif // TASK_MANAGER_CLIENT_LIBTSKMCFG_INCLUDE_SYSTEM_SERVICE_TSKM_XML_DATA_H_ +/** @}*/ +/** @}*/ +/** @}*/ diff --git a/task_manager/client/libtskmcfg/libtskmcfg.ver b/task_manager/client/libtskmcfg/libtskmcfg.ver new file mode 100644 index 00000000..696d5078 --- /dev/null +++ b/task_manager/client/libtskmcfg/libtskmcfg.ver @@ -0,0 +1,21 @@ +/* + * @copyright Copyright (c) 2016-2019 TOYOTA MOTOR CORPORATION. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +{ + global: + tskm_init*; + local: *; +}; diff --git a/task_manager/client/libtskmcfg/src/parsexml.c b/task_manager/client/libtskmcfg/src/parsexml.c new file mode 100644 index 00000000..e67cd5c2 --- /dev/null +++ b/task_manager/client/libtskmcfg/src/parsexml.c @@ -0,0 +1,879 @@ +/* + * @copyright Copyright (c) 2016-2019 TOYOTA MOTOR CORPORATION. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include <stdio.h> +#include <stdlib.h> +#include <stdint.h> +#include <sys/types.h> +#include <sys/stat.h> +#include <string.h> +#include <unistd.h> +#include <errno.h> +#include <libgen.h> + +#include <expat.h> + +#define BUFSIZE 4096 +#define OUTFILE "tskm_auto_build.h" +#define TMPFILE "parsexml.tmp" + +typedef uint32_t ELE_STATE_t; +#define ELE_NONE 0x00000000U +#define ELE_TSKM_CFG 0x10000000U +#define ELE_SERVICE_LIST 0x11000000U +#define ELE_SERVICE 0x11100000U +#define ELE_SUBGID_LIST 0x11110000U + +#define ELE_COMMON_GSTEP 0x00100000U +#define ELE_COMMON_EXEC 0x00010000U +#define ELE_COMMON_REQ 0x00020000U + +#define ELE_NORMAL_WAKEUP 0x12000000U +#define ELE_NORMAL_W_GSTEP (ELE_NORMAL_WAKEUP|ELE_COMMON_GSTEP) +#define ELE_NORMAL_W_EXEC (ELE_NORMAL_WAKEUP|ELE_COMMON_GSTEP|ELE_COMMON_EXEC) +#define ELE_NORMAL_W_REQ (ELE_NORMAL_WAKEUP|ELE_COMMON_GSTEP|ELE_COMMON_REQ) + +#define ELE_NORMAL_SHUTDOWN 0x13000000U +#define ELE_NORMAL_D_GSTEP (ELE_NORMAL_SHUTDOWN|ELE_COMMON_GSTEP) +#define ELE_NORMAL_D_REQ (ELE_NORMAL_SHUTDOWN|ELE_COMMON_GSTEP|ELE_COMMON_REQ) + +#define ELE_VUP_WAKEUP 0x14000000U +#define ELE_VUP_W_GSTEP (ELE_VUP_WAKEUP|ELE_COMMON_GSTEP) +#define ELE_VUP_W_EXEC (ELE_VUP_WAKEUP|ELE_COMMON_GSTEP|ELE_COMMON_EXEC) +#define ELE_VUP_W_REQ (ELE_VUP_WAKEUP|ELE_COMMON_GSTEP|ELE_COMMON_REQ) + +#define ELE_VUP_SHUTDOWN 0x15000000U +#define ELE_VUP_D_GSTEP (ELE_VUP_SHUTDOWN|ELE_COMMON_GSTEP) +#define ELE_VUP_D_REQ (ELE_VUP_SHUTDOWN|ELE_COMMON_GSTEP|ELE_COMMON_REQ) + + +#define ELE_MASK0 0xF0000000U +#define ELE_MASK1 0x0F000000U +#define ELE_MASK2 0x00F00000U +#define ELE_MASK3 0x000F0000U + +#define PARSE_ASSERT_EXIT(x) \ + if(!(x)){ \ + printf("ASSERT %s:%s:%d\n",__FILE__,__FUNCTION__,__LINE__); \ + exit(-1); \ + } + +#define VALUE_NAME_MAX 255 +typedef struct { + int step; + char gstepIdStr[VALUE_NAME_MAX]; + int execSvcNum; + int reqNum; + char nextStepCondStr[VALUE_NAME_MAX]; + char execSvcName[VALUE_NAME_MAX]; + char reqTableName[VALUE_NAME_MAX]; +} PARSE_GSTEP_t; + + +typedef struct { + char svcid[VALUE_NAME_MAX]; + char name[VALUE_NAME_MAX]; + char path[VALUE_NAME_MAX]; + char type[VALUE_NAME_MAX]; + char life_cycle[VALUE_NAME_MAX]; + char retry_cnt[VALUE_NAME_MAX]; + char cpu_assign[VALUE_NAME_MAX]; + char prio[VALUE_NAME_MAX]; + char policy[VALUE_NAME_MAX]; + char user[VALUE_NAME_MAX]; + char runtime_limit[VALUE_NAME_MAX]; + char cpu_limit[VALUE_NAME_MAX]; + char mem_limit[VALUE_NAME_MAX]; + int subgidNum; + char args[VALUE_NAME_MAX]; + char shutdown_wait[VALUE_NAME_MAX]; +} PARSE_SVC_t; + +/*************************************** + * Context + **************************************/ +typedef struct { + FILE* fp; // Output file pointer + FILE* tmpFp; // Temporary file + ELE_STATE_t state; + + PARSE_SVC_t svc; + + int svcNum; // Number of services + PARSE_GSTEP_t gstep; +} PARSE_CTX_t; + + +/*************************************** + * entryTskmCfg + **************************************/ +void +entryTskmCfg(PARSE_CTX_t* p_ctx,const XML_Char* atts[]) { + p_ctx->state = ELE_TSKM_CFG; +} + +/*************************************** + * exitTskmCfg + **************************************/ +void +exitTskmCfg(PARSE_CTX_t* p_ctx) { + p_ctx->state = ELE_NONE; +} + + +/*************************************** + * entryServiceList + **************************************/ +void +entryServiceList(PARSE_CTX_t* p_ctx,const XML_Char* atts[]) { + p_ctx->state = ELE_SERVICE_LIST; + + p_ctx->tmpFp = fopen(TMPFILE,"w"); + + fprintf(p_ctx->tmpFp, + "static TSKM_SVC_ATTR_t serviceAttr[]={" + "\n"); +} + +/*************************************** + * exitServiceList + **************************************/ +void +exitServiceList(PARSE_CTX_t* p_ctx) { + fprintf(p_ctx->tmpFp, + "};" + "\n\n"); + + fprintf(p_ctx->tmpFp, "#define TSKM_SVC_NUM (%d) \n\n",p_ctx->svcNum); + + fprintf(p_ctx->tmpFp, "static TSKM_SVC_CTX_t serviceList[TSKM_SVC_NUM]; \n\n"); + + fclose(p_ctx->tmpFp); + + fprintf(p_ctx->fp,"\n\n"); + + p_ctx->state = ELE_TSKM_CFG; +} + +/*************************************** + * handleServiceList + **************************************/ +void +entryService(PARSE_CTX_t* p_ctx,const XML_Char *name,const XML_Char* atts[]) { + PARSE_ASSERT_EXIT(strcmp(name,"service") == 0); + int ii; + char* tp; + p_ctx->state = ELE_SERVICE; + + memset(&p_ctx->svc,0,sizeof(p_ctx->svc)); + + for(ii=0; atts[ii]; ii+=2) { + const char* attr = atts[ii]; + const char* value = atts[ii+1]; + if(strcmp(attr,"svcid")==0) { + strcpy(p_ctx->svc.svcid,value); + } else if(strcmp(attr,"name")==0) { + strcpy(p_ctx->svc.name,value); + } else if(strcmp(attr,"path")==0) { + strcpy(p_ctx->svc.path,value); + } else if(strcmp(attr,"type")==0) { + const char* typeName = (strcmp(value,"native")==0) ? "TSKM_SVC_TYPE_NATIVE" : "TSKM_SVC_TYPE_UNKNONW"; + strcpy(p_ctx->svc.type,typeName); + } else if(strcmp(attr,"prio")==0) { + strcpy(p_ctx->svc.prio,value); + } else if(strcmp(attr,"policy")==0) { + const char* polName = (strcmp(value,"fifo")==0) ? "TSKM_SVC_POLICY_FIFO" : + (strcmp(value,"tss")==0) ? "TSKM_SVC_POLICY_TSS" : + (strcmp(value,"rr")==0) ? "TSKM_SVC_POLICY_RR" : "ERROR"; + strcpy(p_ctx->svc.policy,polName); + } else if(strcmp(attr,"life_cycle")==0) { + const char* lcName = (strcmp(value,"always")==0) ? "TSKM_SVC_LC_ALWAYS" : + (strcmp(value,"always_recoverable")==0) ? "TSKM_SVC_LC_ALWAYS_RECOVERABLE" : + (strcmp(value,"dynamic")==0) ? "TSKM_SVC_LC_DYNAMIC" : "ERROR"; + strcpy(p_ctx->svc.life_cycle,lcName); + } else if(strcmp(attr,"retry_cnt")==0) { + strcpy(p_ctx->svc.retry_cnt,value); + } else if(strcmp(attr,"cpu_assign")==0) { + const char* caName = (strcmp(value,"cpu0")==0) ? "TSKM_SVC_ASSIGN_CPU_0" : + (strcmp(value,"cpu1")==0) ? "TSKM_SVC_ASSIGN_CPU_1" : + (strcmp(value,"auto")==0) ? "TSKM_SVC_ASSIGN_CPU_AUTO" : "ERROR"; + strcpy(p_ctx->svc.cpu_assign,caName); + } else if(strcmp(attr,"user")==0) { + strcpy(p_ctx->svc.user,value); + } else if(strcmp(attr,"runtime_limit")==0) { + strcpy(p_ctx->svc.runtime_limit,value); + } else if(strcmp(attr,"cpu_limit")==0) { + strcpy(p_ctx->svc.cpu_limit,value); + } else if(strcmp(attr,"mem_limit")==0) { + strcpy(p_ctx->svc.mem_limit,value); + } else if(strcmp(attr,"args")==0) { + strcpy(p_ctx->svc.args,value); + } else if(strcmp(attr,"shutdown_wait")==0) { + const char* swStr = (strcmp(value,"yes")==0) ? "TSKM_TRUE" : + (strcmp(value,"no")==0) ? "TSKM_FALSE" : "ERROR"; + strcpy(p_ctx->svc.shutdown_wait,swStr); + } + } + + fprintf(p_ctx->fp,"char const *svcArgs%d[] = {",p_ctx->svcNum); + fprintf(p_ctx->fp,"\"%s\",",p_ctx->svc.path); + + // Output arguments + tp = strtok(p_ctx->svc.args," "); + while(tp != NULL) { + fprintf(p_ctx->fp,"\"%s\",",tp); + tp = strtok(NULL," "); + } + + fprintf(p_ctx->fp,"NULL"); + fprintf(p_ctx->fp,"};\n"); +} + +/*************************************** + * exitService + **************************************/ +void +exitService(PARSE_CTX_t* p_ctx) { + uint32_t ii; + fprintf(p_ctx->tmpFp,"{" ); + + fprintf(p_ctx->tmpFp,"%s",p_ctx->svc.svcid); + fprintf(p_ctx->tmpFp,", (const char *)\"%s\"",p_ctx->svc.name); + fprintf(p_ctx->tmpFp,", (const char *)\"%s\"",p_ctx->svc.path); + fprintf(p_ctx->tmpFp,", (char**)svcArgs%d",p_ctx->svcNum); + fprintf(p_ctx->tmpFp,", %s",p_ctx->svc.type); + fprintf(p_ctx->tmpFp,", %s",p_ctx->svc.prio); + fprintf(p_ctx->tmpFp,", %s",p_ctx->svc.policy); + fprintf(p_ctx->tmpFp,", %s",p_ctx->svc.life_cycle); + fprintf(p_ctx->tmpFp,", (uint32_t)%s",p_ctx->svc.retry_cnt); + fprintf(p_ctx->tmpFp,", %s",p_ctx->svc.cpu_assign); + fprintf(p_ctx->tmpFp,", (const char *)\"%s\"",p_ctx->svc.user); + fprintf(p_ctx->tmpFp,", %s",(p_ctx->svc.runtime_limit[0] != '\0') ? p_ctx->svc.runtime_limit : "0"); + fprintf(p_ctx->tmpFp,", %s",(p_ctx->svc.cpu_limit[0] != '\0') ? p_ctx->svc.cpu_limit : "0"); + fprintf(p_ctx->tmpFp,", %s",(p_ctx->svc.mem_limit[0] != '\0') ? p_ctx->svc.mem_limit : "0"); + fprintf(p_ctx->tmpFp,", %s",p_ctx->svc.shutdown_wait); + fprintf(p_ctx->tmpFp,", %d",p_ctx->svc.subgidNum); + if(p_ctx->svc.subgidNum) { + fprintf(p_ctx->tmpFp,", subgidList%d",p_ctx->svcNum); + } else { + fprintf(p_ctx->tmpFp,", NULL"); + } + + fprintf(p_ctx->tmpFp,"},\n"); + + p_ctx->svcNum++; + + p_ctx->state = ELE_SERVICE_LIST; +} + +/*************************************** + * entrySubgidList + **************************************/ +void +entrySubgidList(PARSE_CTX_t* p_ctx,const XML_Char* atts[]) { + p_ctx->state = ELE_SUBGID_LIST; + + fprintf(p_ctx->fp,"static gid_t subgidList%d[] = {",p_ctx->svcNum); + + +} + +/*************************************** + * handleSubgidList + **************************************/ +void +handleSubgidList(PARSE_CTX_t* p_ctx,const XML_Char *name,const XML_Char* atts[]) { + PARSE_ASSERT_EXIT(strcmp(name,"subgid") == 0); + int32_t ii; + + if(p_ctx->svc.subgidNum > 0) { + fprintf(p_ctx->fp,","); + } + for(ii=0; atts[ii]; ii+=2) { + const char* attr = atts[ii]; + const char* value = atts[ii+1]; + if(strcmp(attr,"gid")==0) { + fprintf(p_ctx->fp,"%s",value); + } else { + PARSE_ASSERT_EXIT(0); + } + } + p_ctx->svc.subgidNum++; +} + +/*************************************** + * exitSubgidList + **************************************/ +void +exitSubgidList(PARSE_CTX_t* p_ctx) { + + fprintf(p_ctx->fp,"};\n"); + + p_ctx->state = ELE_SERVICE; +} + + +/*************************************** + * entryNormalWakeup + **************************************/ +void +entryNormalWakeup(PARSE_CTX_t* p_ctx,const XML_Char* atts[]) { + p_ctx->state = ELE_NORMAL_WAKEUP; + memset(&p_ctx->gstep,0,sizeof(p_ctx->gstep)); + + sprintf(p_ctx->gstep.reqTableName,"wakeupReqList"); + sprintf(p_ctx->gstep.execSvcName,"wakeupExecSvcId"); + p_ctx->tmpFp = fopen(TMPFILE,"a"); + PARSE_ASSERT_EXIT(p_ctx->tmpFp); + + fprintf(p_ctx->tmpFp,"TSKM_GSTEP_t wakeupGstep[]={\n"); +} + +/*************************************** + * exitNormalWakeup + **************************************/ +void +exitNormalWakeup(PARSE_CTX_t* p_ctx) { + fprintf(p_ctx->tmpFp,"};\n\n"); + fclose(p_ctx->tmpFp); + + p_ctx->state = ELE_TSKM_CFG; +} + +/*************************************** + * entryVupWakeup + **************************************/ +void +entryVupWakeup(PARSE_CTX_t* p_ctx,const XML_Char* atts[]) { + p_ctx->state = ELE_VUP_WAKEUP; + memset(&p_ctx->gstep,0,sizeof(p_ctx->gstep)); + + sprintf(p_ctx->gstep.reqTableName,"wakeupReqListVup"); + sprintf(p_ctx->gstep.execSvcName,"wakeupExecSvcIdVup"); + p_ctx->tmpFp = fopen(TMPFILE,"a"); + PARSE_ASSERT_EXIT(p_ctx->tmpFp); + + fprintf(p_ctx->tmpFp,"TSKM_GSTEP_t wakeupGstepVup[]={\n"); +} + +/*************************************** + * exitVupWakeup + **************************************/ +void +exitVupWakeup(PARSE_CTX_t* p_ctx) { + fprintf(p_ctx->tmpFp,"};\n\n"); + fclose(p_ctx->tmpFp); + + p_ctx->state = ELE_TSKM_CFG; +} + +void +entryGstep(PARSE_CTX_t* p_ctx,const XML_Char* atts[]) { + + p_ctx->state &= ~ELE_MASK2; + p_ctx->state |= ELE_COMMON_GSTEP; + + PARSE_GSTEP_t *p_gstep = &p_ctx->gstep; + + if(atts[0] && strcmp(atts[0],"stepid") == 0) { + sprintf(p_gstep->gstepIdStr,"%s",atts[1]); + } else { + sprintf(p_gstep->gstepIdStr,"TSKM_GSTEP_NONE"); + } + p_gstep->execSvcNum = 0; + p_gstep->reqNum = 0; + sprintf(p_gstep->nextStepCondStr,"INI_INITCOMP_NONE"); +} + +void +handleGstep(PARSE_CTX_t* p_ctx,const XML_Char *name,const XML_Char* atts[]) { + PARSE_ASSERT_EXIT(strcmp(name,"next_trans_condition") == 0); + PARSE_GSTEP_t *p_gstep = &p_ctx->gstep; + + if(atts[0] && strcmp(atts[0],"cond") == 0) { + sprintf(p_gstep->nextStepCondStr,"%s",atts[1]); + } else { + PARSE_ASSERT_EXIT(0); + } +} + +void +exitGstep(PARSE_CTX_t* p_ctx) { + PARSE_GSTEP_t *p_gstep = &p_ctx->gstep; + + fprintf(p_ctx->tmpFp,"{"); + fprintf(p_ctx->tmpFp,"%s,",p_gstep->gstepIdStr); + fprintf(p_ctx->tmpFp,"%d,",p_gstep->execSvcNum); + if(p_gstep->execSvcNum) { + fprintf(p_ctx->tmpFp,"%s%d,",p_gstep->execSvcName,p_gstep->step); + } else { + fprintf(p_ctx->tmpFp,"NULL,"); + } + fprintf(p_ctx->tmpFp,"%d,",p_gstep->reqNum); + if(p_gstep->reqNum) { + fprintf(p_ctx->tmpFp,"%s%d,",p_gstep->reqTableName,p_gstep->step); + } else { + fprintf(p_ctx->tmpFp,"NULL,"); + } + fprintf(p_ctx->tmpFp,"%s",p_gstep->nextStepCondStr); + fprintf(p_ctx->tmpFp,"},\n"); + + p_gstep->step++; + + p_ctx->state &= ~ELE_MASK2; +} + +void +entryExec(PARSE_CTX_t* p_ctx,const XML_Char* atts[]) { + p_ctx->state &= ~ELE_MASK3; + p_ctx->state |= ELE_COMMON_EXEC; + + PARSE_GSTEP_t *p_gstep = &p_ctx->gstep; + fprintf(p_ctx->fp, + "static TSKM_SVCID_t %s%d[] = {",p_gstep->execSvcName,p_gstep->step); +} +void +handleExec(PARSE_CTX_t* p_ctx,const XML_Char *name,const XML_Char* atts[]) { + PARSE_ASSERT_EXIT(strcmp(name,"exec_svc") == 0); + PARSE_GSTEP_t *p_gstep = &p_ctx->gstep; + int ii; + + if(p_gstep->execSvcNum > 0) { + fprintf(p_ctx->fp,","); + } + + for(ii=0; atts[ii]; ii+=2) { + const char* attr = atts[ii]; + const char* value = atts[ii+1]; + PARSE_ASSERT_EXIT(strcmp(attr,"svcid") == 0); + fprintf(p_ctx->fp,"%s",value); + } + p_gstep->execSvcNum++; +} +void +exitExec(PARSE_CTX_t* p_ctx) { + fprintf(p_ctx->fp,"};\n\n"); + p_ctx->state &= ~ELE_MASK3; +} + +void +entryReq(PARSE_CTX_t* p_ctx,const XML_Char* atts[]) { + p_ctx->state &= ~ELE_MASK3; + p_ctx->state |= ELE_COMMON_REQ; + PARSE_GSTEP_t *p_gstep = &p_ctx->gstep; + + fprintf(p_ctx->fp,"static TSKM_GSTEP_REQ_INFO_t %s%d[] ={",p_gstep->reqTableName,p_gstep->step); +} +void +handleReq(PARSE_CTX_t* p_ctx,const XML_Char *name,const XML_Char* atts[]) { + PARSE_GSTEP_t *p_gstep = &p_ctx->gstep; + PARSE_ASSERT_EXIT(strcmp(name,"request") == 0); + int ii; + + fprintf(p_ctx->fp," {"); + + for(ii=0; atts[ii]; ii+=2) { + const char* attr = atts[ii]; + const char* value = atts[ii+1]; + if(strcmp(attr,"local_step") == 0) { + if(strcmp(value,"shm") == 0) { + fprintf(p_ctx->fp,"TSKM_LSTEP_SHM"); + } else if(strcmp(value,"bupchk") == 0) { + fprintf(p_ctx->fp,"TSKM_LSTEP_BUPCHK"); + } else if(strcmp(value,"last") == 0) { + fprintf(p_ctx->fp,"TSKM_LSTEP_LAST"); + } else if(strcmp(value,"all") == 0) { + fprintf(p_ctx->fp,"TSKM_LSTEP_ALL"); + } else { + fprintf(p_ctx->fp,"%s",value); + } + } else { + fprintf(p_ctx->fp,"%s",value); // Output of "," + } + fprintf(p_ctx->fp,"%s",(atts[ii+2])?",":""); // Outoput of "," + } + fprintf(p_ctx->fp,"},"); + p_gstep->reqNum++; +} +void +exitReq(PARSE_CTX_t* p_ctx) { + fprintf(p_ctx->fp,"};\n\n"); + p_ctx->state &= ~ELE_MASK3; +} + +/*************************************** + * entryNormalShutdown + **************************************/ +void +entryNormalShutdown(PARSE_CTX_t* p_ctx,const XML_Char* atts[]) { + p_ctx->state = ELE_NORMAL_SHUTDOWN; + + memset(&p_ctx->gstep,0,sizeof(p_ctx->gstep)); + sprintf(p_ctx->gstep.reqTableName,"downReqList"); + p_ctx->tmpFp = fopen(TMPFILE,"a"); + PARSE_ASSERT_EXIT(p_ctx->tmpFp); + + fprintf(p_ctx->tmpFp,"static TSKM_GSTEP_t downGstep[]={\n"); +} + +/*************************************** + * exitNormalShutdown + **************************************/ +void +exitNormalShutdown(PARSE_CTX_t* p_ctx) { + + fprintf(p_ctx->tmpFp,"};\n\n"); + fclose(p_ctx->tmpFp); + + p_ctx->state = ELE_TSKM_CFG; +} + +/*************************************** + * entryVupShutdown + **************************************/ +void +entryVupShutdown(PARSE_CTX_t* p_ctx,const XML_Char* atts[]) { + p_ctx->state = ELE_VUP_SHUTDOWN; + memset(&p_ctx->gstep,0,sizeof(p_ctx->gstep)); + + sprintf(p_ctx->gstep.reqTableName,"downReqListVup"); + p_ctx->tmpFp = fopen(TMPFILE,"a"); + PARSE_ASSERT_EXIT(p_ctx->tmpFp); + + fprintf(p_ctx->tmpFp,"static TSKM_GSTEP_t downGstepVup[]={\n"); +} + +/*************************************** + * exitVupShutdown + **************************************/ +void +exitVupShutdown(PARSE_CTX_t* p_ctx) { + fprintf(p_ctx->tmpFp,"};\n\n"); + fclose(p_ctx->tmpFp); + + p_ctx->state = ELE_TSKM_CFG; +} + +/*************************************** + * elementStart + **************************************/ +void +elementStart(void *userData, const XML_Char *name, const XML_Char *atts[]) { + PARSE_CTX_t *p_ctx = (PARSE_CTX_t*)userData; +#if 0 + int ii; + printf("[ELEMENT] %s Start!\n", name); + for(ii=0; atts[ii]; ii+=2) { + printf(" %s:%s \n", atts[ii],atts[ii+1]); + } +#endif + switch(p_ctx->state) { + case ELE_NONE: + if(strcmp(name,"tskm_cfg") == 0) { + entryTskmCfg(p_ctx,atts); + } else { + PARSE_ASSERT_EXIT(0); + } + break; + case ELE_TSKM_CFG: + if(strcmp(name,"service_list") == 0) { + entryServiceList(p_ctx,atts); + } else if(strcmp(name,"normal_wakeup") == 0) { + entryNormalWakeup(p_ctx,atts); + } else if(strcmp(name,"normal_shutdown") == 0) { + entryNormalShutdown(p_ctx,atts); + } else if(strcmp(name,"vup_wakeup") == 0) { + entryVupWakeup(p_ctx,atts); + } else if(strcmp(name,"vup_shutdown") == 0) { + entryVupShutdown(p_ctx,atts); + } else { + PARSE_ASSERT_EXIT(0); + } + break; + case ELE_SERVICE_LIST: + if(strcmp(name,"service") == 0) { + entryService(p_ctx,name,atts); + } + break; + case ELE_SERVICE: + if(strcmp(name,"subgid_list") == 0) { + entrySubgidList(p_ctx,atts); + } + break; + case ELE_SUBGID_LIST: + handleSubgidList(p_ctx,name,atts); + break; + case ELE_NORMAL_WAKEUP: + case ELE_NORMAL_SHUTDOWN: + case ELE_VUP_WAKEUP: + case ELE_VUP_SHUTDOWN: + if(strcmp(name,"global_step") == 0) { + entryGstep(p_ctx,atts); + } else { + PARSE_ASSERT_EXIT(0); + } + break; + case ELE_NORMAL_W_GSTEP: + case ELE_NORMAL_D_GSTEP: + case ELE_VUP_W_GSTEP: + case ELE_VUP_D_GSTEP: + if(strcmp(name,"exec_list") == 0) { + entryExec(p_ctx,atts); + } else if(strcmp(name,"request_list") == 0) { + entryReq(p_ctx,atts); + } else { + handleGstep(p_ctx,name,atts); + } + break; + case ELE_NORMAL_W_EXEC: + case ELE_VUP_W_EXEC: + handleExec(p_ctx,name,atts); + break; + case ELE_NORMAL_W_REQ: + case ELE_NORMAL_D_REQ: + case ELE_VUP_W_REQ: + case ELE_VUP_D_REQ: + handleReq(p_ctx,name,atts); + break; + } +} + + +/*************************************** + * elementEnd + **************************************/ +void +elementEnd(void *userData, const XML_Char *name) { + PARSE_CTX_t *p_ctx = (PARSE_CTX_t*)userData; + switch(p_ctx->state) { + case ELE_NONE: + PARSE_ASSERT_EXIT(0); + break; + case ELE_TSKM_CFG: + if(strcmp(name,"tskm_cfg") == 0) { + exitTskmCfg(p_ctx); + } else { + PARSE_ASSERT_EXIT(0); + } + break; + case ELE_SERVICE_LIST: + if(strcmp(name,"service_list") == 0) { + exitServiceList(p_ctx); + } + break; + case ELE_SERVICE: + if(strcmp(name,"service") == 0) { + exitService(p_ctx); + } + break; + case ELE_SUBGID_LIST: + if(strcmp(name,"subgid_list") == 0) { + exitSubgidList(p_ctx); + } + break; + case ELE_NORMAL_WAKEUP: + if(strcmp(name,"normal_wakeup") == 0) { + exitNormalWakeup(p_ctx); + } + break; + case ELE_NORMAL_SHUTDOWN: + if(strcmp(name,"normal_shutdown") == 0) { + exitNormalShutdown(p_ctx); + } + break; + case ELE_VUP_WAKEUP: + if(strcmp(name,"vup_wakeup") == 0) { + exitVupWakeup(p_ctx); + } + break; + case ELE_VUP_SHUTDOWN: + if(strcmp(name,"vup_shutdown") == 0) { + exitVupShutdown(p_ctx); + } + break; + case ELE_NORMAL_D_GSTEP: + case ELE_NORMAL_W_GSTEP: + case ELE_VUP_D_GSTEP: + case ELE_VUP_W_GSTEP: + if(strcmp(name,"global_step") == 0) { + exitGstep(p_ctx); + } + break; + case ELE_NORMAL_W_EXEC: + case ELE_VUP_W_EXEC: + if(strcmp(name,"exec_list") == 0) { + exitExec(p_ctx); + } + break; + case ELE_NORMAL_D_REQ: + case ELE_NORMAL_W_REQ: + case ELE_VUP_D_REQ: + case ELE_VUP_W_REQ: + if(strcmp(name,"request_list") == 0) { + exitReq(p_ctx); + } + break; + } +} +/*************************************** + * parseXmlFile + **************************************/ +int +parseXmlFile(const char* file,XML_Parser parser) { + int ret = -1; + FILE* fp = fopen(file, "r"); + if (fp == NULL) { + goto ERROR; + } + + while(1) { + char *buf = (char*) XML_GetBuffer(parser, BUFSIZE); + if (!buf) { + goto ERROR; + } + + size_t nread = fread(buf, sizeof(char), BUFSIZE, fp); + if (ferror(fp)) { + goto ERROR; + } + + if (!XML_ParseBuffer(parser, nread, feof(fp))) { + goto ERROR; + } + + if (feof(fp)) { + break; + } + } + ret = 0; +ERROR: + if(fp) { + fclose(fp); + } + return ret; +} + +/*************************************** + * externalHandler + **************************************/ +int +externalHandler(XML_Parser parser, + const XML_Char* content, const XML_Char* base, + const XML_Char* systemId, const XML_Char* publicId) { + printf("parse %s \n",systemId); + + int ret = XML_ERROR_EXTERNAL_ENTITY_HANDLING; + XML_Parser extparser = NULL; + + extparser = XML_ExternalEntityParserCreate(parser, content, NULL); + if(extparser ==NULL) { + goto ERROR; + } + + if(parseXmlFile(systemId,extparser) != 0) { + goto ERROR; + } + ret = XML_STATUS_OK; +ERROR: + if(extparser) { + XML_ParserFree(extparser); + } + return ret; +} + +/*************************************** + * usage + **************************************/ +void +usage(const char* cmd) { + printf("usage:%s xmlfile\n",cmd); +} + +/*************************************** + * main + **************************************/ +int +main (int argc, char *argv[]) { + struct stat statinfo; + int ret=-1; + int xmlRet; + const char* inpath; + char tmpstr1[255]; + char tmpstr2[255]; + const char* workdir; + const char* infile; + XML_Parser parser; + PARSE_CTX_t ctx; + + if(argc < 2) { + usage(argv[0]); + goto ERROR; + } + + inpath = argv[1]; + if(0 != stat(inpath,&statinfo)) { + fprintf(stderr, "%s:%s",strerror(errno),inpath); + goto ERROR; + } + memset(&ctx,0,sizeof(ctx)); + + strcpy(tmpstr1,inpath); + strcpy(tmpstr2,inpath); + workdir=dirname(tmpstr1); + infile=basename(tmpstr2); + + if(0 != chdir(workdir)) { + fprintf(stderr, "%s:%s",strerror(errno),workdir); + goto ERROR; + } + + ctx.fp = fopen(OUTFILE, "w"); + if (ctx.fp == NULL) { + goto ERROR; + } + fprintf(ctx.fp,"//This file is created automatically from %s.\n",inpath); + fprintf(ctx.fp,"//So you shall not modify this file immediately.\n"); + + /* create XML parser */ + if ((parser = XML_ParserCreate(NULL)) == NULL) { + fprintf(stderr, "parser creation error\n"); + goto ERROR; + } + XML_SetUserData(parser,&ctx); + XML_SetParamEntityParsing(parser,XML_PARAM_ENTITY_PARSING_ALWAYS); // Allow External Entities + XML_SetExternalEntityRefHandler(parser,externalHandler); + XML_SetElementHandler(parser, elementStart, elementEnd); + + if(parseXmlFile(infile,parser) != 0) { + goto ERROR; + } + ret = 0; + +ERROR: + if(parser) { + XML_ParserFree(parser); + } + if(ctx.fp) { + fclose(ctx.fp); + } + char buf[255]; + sprintf(buf,"cat %s >> %s",TMPFILE,OUTFILE); + printf("%s\n",buf); + system(buf); + unlink(TMPFILE); + return ret; +} + diff --git a/task_manager/client/libtskmcfg/src/tskm_xml_data.cpp b/task_manager/client/libtskmcfg/src/tskm_xml_data.cpp new file mode 100644 index 00000000..dbdfde84 --- /dev/null +++ b/task_manager/client/libtskmcfg/src/tskm_xml_data.cpp @@ -0,0 +1,140 @@ +/* + * @copyright Copyright (c) 2016-2019 TOYOTA MOTOR CORPORATION. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "system_service/tskm_xml_data.h" + +#include <boost/algorithm/string.hpp> +#include <fstream> +#include <iostream> +#include <string> +#include <list> + +#include "system_service/tskm_svc.h" + +#include "system_service/tskm_svcid.h" +#include "tskm_debug.h" +#include "tskm_comm.h" +#include "tskm_auto_build.h" // Generated data from XML + +// This size depends on the size of the TM area of CL_Monitor +#define TSKM_SVC_ID_MAX_SIZE 1024 + +/*********************************************************************** + * tskm_initServiceList + ***********************************************************************/ +int tskm_initServiceList(TSKM_SVCS_CTX_t* p_svcs, int iFd) { + uint32_t ii; + + p_svcs->svcNum = sizeof(serviceList) / sizeof(TSKM_SVC_CTX_t); + p_svcs->svcList = serviceList; + + // It is initialized with the Inotify floppy disk. + for (ii = 0; ii < p_svcs->svcNum; ii++) { + serviceList[ii].attr = &serviceAttr[ii]; + serviceList[ii].iFd = iFd; + if (serviceList[ii].attr->svcId >= TSKM_SVC_ID_MAX_SIZE) { + TSKM_ASSERT(0); + return -1; + } + } + + const char* nfsenv = getenv("AGL_NFS"); + bool isNfs = (nfsenv && strcmp(nfsenv, "y") == 0) ? true : false; + + // For NFS environments, replace the PATH with CAP with /tmp + if (isNfs) { + std::list<std::string> capFiles; + const std::string capPath("/usr/debug/share/target/cap.lst"); + std::ifstream fin(capPath.c_str()); + std::string line; + while (fin && std::getline(fin, line)) { + std::list<std::string> strList; + try { // throw exception by boost::split + boost::split(strList, line, boost::is_any_of("|")); + if (!strList.empty()) { + if (strList.front()[0] == '/') { // Only character strings beginning with '/' are considered PATH + capFiles.push_back(strList.front().c_str()); + } + } + } catch (...) { + TSKM_ASSERT(0); + } + } + + for (ii = 0; ii < p_svcs->svcNum; ii++) { + std::string binPath(serviceList[ii].attr->path); + + for (std::list<std::string>::iterator ite = capFiles.begin(); + ite != capFiles.end(); ite++) { + if (binPath == *ite) { + std::list<std::string> nodes; + try { // throw exception by boost::split + boost::split(nodes, binPath, boost::is_any_of("/")); + std::string *p_newPath = new std::string("/tmp/"); // Intent not to free up memory + *p_newPath += nodes.back(); + TSKM_PRINTF(TSKM_LOG_STATE, "EXCHG %s", p_newPath->c_str()); + serviceList[ii].attr->path = p_newPath->c_str(); + delete p_newPath; + p_newPath = NULL; + break; + } catch (...) { + TSKM_ASSERT(0); + } + } + } + } + } + + // If there is no socket resource equal to the number of services + 1 (internal control connection), a compilation error occurs + TSKM_STATIC_ASSERT(TSKM_COMM_CONNECT_MAX >= (TSKM_SVC_NUM+1)); + + return 0; +} + +/*********************************************************************** + * tskm_initWakeupCtx + ***********************************************************************/ +void tskm_initWakeupCtx(TSKM_GSTEP_CTX_t* p_wakeup, BOOL isVupMode) { + memset(p_wakeup, 0, sizeof(*p_wakeup)); + + if (isVupMode) { + p_wakeup->gstepNum = sizeof(wakeupGstepVup) / sizeof(TSKM_GSTEP_t); + p_wakeup->gstep = wakeupGstepVup; + } else { + p_wakeup->gstepNum = sizeof(wakeupGstep) / sizeof(TSKM_GSTEP_t); + p_wakeup->gstep = wakeupGstep; + } + + TSKM_PRINTF(TSKM_LOG_STATE, "gstep(wakeup):%d", p_wakeup->gstepNum); +} + +/*********************************************************************** + * tskm_initDownCtx + ***********************************************************************/ +void tskm_initDownCtx(TSKM_GSTEP_CTX_t* p_down, BOOL isVupMode) { + memset(p_down, 0, sizeof(*p_down)); + + if (isVupMode) { + p_down->gstepNum = sizeof(downGstepVup) / sizeof(TSKM_GSTEP_t); + p_down->gstep = downGstepVup; + } else { + p_down->gstepNum = sizeof(downGstep) / sizeof(TSKM_GSTEP_t); + p_down->gstep = downGstep; + } + + TSKM_PRINTF(TSKM_LOG_STATE, "gstep(down):%d", p_down->gstepNum); +} + diff --git a/task_manager/client/libtskmcfg/tskm_cfg.xml b/task_manager/client/libtskmcfg/tskm_cfg.xml new file mode 100644 index 00000000..2898f442 --- /dev/null +++ b/task_manager/client/libtskmcfg/tskm_cfg.xml @@ -0,0 +1,83 @@ +<?xml version="1.0" ?> + +<!DOCTYPE tskm_cfg [ + <!ELEMENT tskm_cfg (service_list,normal_wakeup,normal_shutdown,vup_wakeup,vup_shutdown) > + + <!-- service list --> + <!ELEMENT service_list (service+) > + <!ELEMENT service (subgid_list*) > + <!ATTLIST service + svcid ID #REQUIRED + name CDATA #REQUIRED + path CDATA #REQUIRED + type (native|unknown) "native" + prio CDATA #REQUIRED + policy (fifo|tss|rr) #REQUIRED + life_cycle (always|always_recoverable|dynamic) "dynamic" + retry_cnt CDATA "1" + cpu_assign (cpu0|cpu1|auto) "auto" + user CDATA #REQUIRED + runtime_limit CDATA #IMPLIED + cpu_limit CDATA #IMPLIED + mem_limit CDATA #IMPLIED + args CDATA #IMPLIED + shutdown_wait (yes|no) #REQUIRED + > + + <!ELEMENT subgid_list (subgid+) > + <!ELEMENT subgid EMPTY > + <!ATTLIST subgid + gid CDATA #REQUIRED + > + + + <!-- Starting/terminating of services --> + <!ELEMENT normal_wakeup (global_step+) > + <!ELEMENT normal_shutdown (global_step+) > + <!ELEMENT vup_wakeup (global_step+) > + <!ELEMENT vup_shutdown (global_step+) > + + <!ELEMENT global_step (exec_list?,request_list?,next_trans_condition?) > + <!ATTLIST global_step + stepid ID #IMPLIED + > + + <!ELEMENT exec_list (exec_svc+) > + <!ELEMENT exec_svc EMPTY > + + <!ATTLIST exec_svc + svcid IDREF #REQUIRED + > + + <!ELEMENT request_list (request+) > + <!ELEMENT request EMPTY > + <!ATTLIST request + svcid IDREF #REQUIRED + local_step (shm|bupchk|1|2|3|4|5|6|7|8|9|last|all) #REQUIRED + > + + <!ELEMENT next_trans_condition EMPTY> + <!ATTLIST next_trans_condition + cond CDATA #REQUIRED + > + + <!ENTITY service_list_xml SYSTEM "tskm_launch.xml"> + <!ENTITY normal_wakeup_xml SYSTEM "tskm_wakeup.xml"> + <!ENTITY normal_shutdown_xml SYSTEM "tskm_shutdown.xml"> + <!ENTITY vup_wakeup_xml SYSTEM "tskm_wakeup_vup.xml"> + <!ENTITY vup_shutdown_xml SYSTEM "tskm_shutdown_vup.xml"> +]> + + +<tskm_cfg> + &service_list_xml; + + &normal_wakeup_xml; + + &normal_shutdown_xml; + + &vup_wakeup_xml; + + &vup_shutdown_xml; + +</tskm_cfg> |