2 * @copyright Copyright (c) 2016-2020 TOYOTA MOTOR CORPORATION.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 #include "system_service/tskm_xml_data.h"
19 #include <boost/algorithm/string.hpp>
25 #include "system_service/tskm_svc.h"
27 #include "system_service/tskm_svcid.h"
28 #include "tskm_debug.h"
29 #include "tskm_comm.h"
30 #include "tskm_auto_build.h" // Generated data from XML
32 // This size depends on the size of the TM area of CL_Monitor
33 #define TSKM_SVC_ID_MAX_SIZE 1024
35 /***********************************************************************
36 * tskm_initServiceList
37 ***********************************************************************/
38 int tskm_initServiceList(TSKM_SVCS_CTX_t* p_svcs, int iFd) {
41 p_svcs->svcNum = sizeof(serviceList) / sizeof(TSKM_SVC_CTX_t);
42 p_svcs->svcList = serviceList;
44 // It is initialized with the Inotify floppy disk.
45 for (ii = 0; ii < p_svcs->svcNum; ii++) {
46 serviceList[ii].attr = &serviceAttr[ii];
47 serviceList[ii].iFd = iFd;
48 if (serviceList[ii].attr->svcId >= TSKM_SVC_ID_MAX_SIZE) {
54 const char* nfsenv = getenv("AGL_NFS");
55 bool isNfs = (nfsenv && strcmp(nfsenv, "y") == 0) ? true : false;
57 // For NFS environments, replace the PATH with CAP with /tmp
59 std::list<std::string> capFiles;
60 const std::string capPath("/usr/debug/share/target/cap.lst");
61 std::ifstream fin(capPath.c_str());
63 while (fin && std::getline(fin, line)) {
64 std::list<std::string> strList;
65 try { // throw exception by boost::split
66 boost::split(strList, line, boost::is_any_of("|"));
67 if (!strList.empty()) {
68 if (strList.front()[0] == '/') { // Only character strings beginning with '/' are considered PATH
69 capFiles.push_back(strList.front().c_str());
77 for (ii = 0; ii < p_svcs->svcNum; ii++) {
78 std::string binPath(serviceList[ii].attr->path);
80 for (std::list<std::string>::iterator ite = capFiles.begin();
81 ite != capFiles.end(); ite++) {
82 if (binPath == *ite) {
83 std::list<std::string> nodes;
84 try { // throw exception by boost::split
85 boost::split(nodes, binPath, boost::is_any_of("/"));
86 std::string *p_newPath = new std::string("/tmp/"); // Intent not to free up memory
87 *p_newPath += nodes.back();
88 TSKM_PRINTF(TSKM_LOG_STATE, "EXCHG %s", p_newPath->c_str());
89 serviceList[ii].attr->path = p_newPath->c_str();
99 // If there is no socket resource equal to the number of services + 1 (internal control connection), a compilation error occurs
100 TSKM_STATIC_ASSERT(TSKM_COMM_CONNECT_MAX >= (TSKM_SVC_NUM+1));
105 /***********************************************************************
107 ***********************************************************************/
108 void tskm_initWakeupCtx(TSKM_GSTEP_CTX_t* p_wakeup, BOOL isVupMode) {
109 memset(p_wakeup, 0, sizeof(*p_wakeup));
112 p_wakeup->gstepNum = sizeof(wakeupGstepVup) / sizeof(TSKM_GSTEP_t);
113 p_wakeup->gstep = wakeupGstepVup;
115 p_wakeup->gstepNum = sizeof(wakeupGstep) / sizeof(TSKM_GSTEP_t);
116 p_wakeup->gstep = wakeupGstep;
119 TSKM_PRINTF(TSKM_LOG_STATE, "gstep(wakeup):%d", p_wakeup->gstepNum);
122 /***********************************************************************
124 ***********************************************************************/
125 void tskm_initDownCtx(TSKM_GSTEP_CTX_t* p_down, BOOL isVupMode) {
126 memset(p_down, 0, sizeof(*p_down));
129 p_down->gstepNum = sizeof(downGstepVup) / sizeof(TSKM_GSTEP_t);
130 p_down->gstep = downGstepVup;
132 p_down->gstepNum = sizeof(downGstep) / sizeof(TSKM_GSTEP_t);
133 p_down->gstep = downGstep;
136 TSKM_PRINTF(TSKM_LOG_STATE, "gstep(down):%d", p_down->gstepNum);