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.
20 #include <sys/types.h>
30 #define OUTFILE "tskm_auto_build.h"
31 #define TMPFILE "parsexml.tmp"
33 typedef uint32_t ELE_STATE_t;
34 #define ELE_NONE 0x00000000U
35 #define ELE_TSKM_CFG 0x10000000U
36 #define ELE_SERVICE_LIST 0x11000000U
37 #define ELE_SERVICE 0x11100000U
38 #define ELE_SUBGID_LIST 0x11110000U
40 #define ELE_COMMON_GSTEP 0x00100000U
41 #define ELE_COMMON_EXEC 0x00010000U
42 #define ELE_COMMON_REQ 0x00020000U
44 #define ELE_NORMAL_WAKEUP 0x12000000U
45 #define ELE_NORMAL_W_GSTEP (ELE_NORMAL_WAKEUP|ELE_COMMON_GSTEP)
46 #define ELE_NORMAL_W_EXEC (ELE_NORMAL_WAKEUP|ELE_COMMON_GSTEP|ELE_COMMON_EXEC)
47 #define ELE_NORMAL_W_REQ (ELE_NORMAL_WAKEUP|ELE_COMMON_GSTEP|ELE_COMMON_REQ)
49 #define ELE_NORMAL_SHUTDOWN 0x13000000U
50 #define ELE_NORMAL_D_GSTEP (ELE_NORMAL_SHUTDOWN|ELE_COMMON_GSTEP)
51 #define ELE_NORMAL_D_REQ (ELE_NORMAL_SHUTDOWN|ELE_COMMON_GSTEP|ELE_COMMON_REQ)
53 #define ELE_VUP_WAKEUP 0x14000000U
54 #define ELE_VUP_W_GSTEP (ELE_VUP_WAKEUP|ELE_COMMON_GSTEP)
55 #define ELE_VUP_W_EXEC (ELE_VUP_WAKEUP|ELE_COMMON_GSTEP|ELE_COMMON_EXEC)
56 #define ELE_VUP_W_REQ (ELE_VUP_WAKEUP|ELE_COMMON_GSTEP|ELE_COMMON_REQ)
58 #define ELE_VUP_SHUTDOWN 0x15000000U
59 #define ELE_VUP_D_GSTEP (ELE_VUP_SHUTDOWN|ELE_COMMON_GSTEP)
60 #define ELE_VUP_D_REQ (ELE_VUP_SHUTDOWN|ELE_COMMON_GSTEP|ELE_COMMON_REQ)
63 #define ELE_MASK0 0xF0000000U
64 #define ELE_MASK1 0x0F000000U
65 #define ELE_MASK2 0x00F00000U
66 #define ELE_MASK3 0x000F0000U
68 #define PARSE_ASSERT_EXIT(x) \
70 printf("ASSERT %s:%s:%d\n",__FILE__,__FUNCTION__,__LINE__); \
74 #define VALUE_NAME_MAX 255
77 char gstepIdStr[VALUE_NAME_MAX];
80 char nextStepCondStr[VALUE_NAME_MAX];
81 char execSvcName[VALUE_NAME_MAX];
82 char reqTableName[VALUE_NAME_MAX];
87 char svcid[VALUE_NAME_MAX];
88 char name[VALUE_NAME_MAX];
89 char path[VALUE_NAME_MAX];
90 char type[VALUE_NAME_MAX];
91 char life_cycle[VALUE_NAME_MAX];
92 char retry_cnt[VALUE_NAME_MAX];
93 char cpu_assign[VALUE_NAME_MAX];
94 char prio[VALUE_NAME_MAX];
95 char policy[VALUE_NAME_MAX];
96 char user[VALUE_NAME_MAX];
97 char runtime_limit[VALUE_NAME_MAX];
98 char cpu_limit[VALUE_NAME_MAX];
99 char mem_limit[VALUE_NAME_MAX];
101 char args[VALUE_NAME_MAX];
102 char shutdown_wait[VALUE_NAME_MAX];
105 /***************************************
107 **************************************/
109 FILE* fp; // Output file pointer
110 FILE* tmpFp; // Temporary file
115 int svcNum; // Number of services
120 /***************************************
122 **************************************/
124 entryTskmCfg(PARSE_CTX_t* p_ctx,const XML_Char* atts[]) {
125 p_ctx->state = ELE_TSKM_CFG;
128 /***************************************
130 **************************************/
132 exitTskmCfg(PARSE_CTX_t* p_ctx) {
133 p_ctx->state = ELE_NONE;
137 /***************************************
139 **************************************/
141 entryServiceList(PARSE_CTX_t* p_ctx,const XML_Char* atts[]) {
142 p_ctx->state = ELE_SERVICE_LIST;
144 p_ctx->tmpFp = fopen(TMPFILE,"w");
146 fprintf(p_ctx->tmpFp,
147 "static TSKM_SVC_ATTR_t serviceAttr[]={"
151 /***************************************
153 **************************************/
155 exitServiceList(PARSE_CTX_t* p_ctx) {
156 fprintf(p_ctx->tmpFp,
160 fprintf(p_ctx->tmpFp, "#define TSKM_SVC_NUM (%d) \n\n",p_ctx->svcNum);
162 fprintf(p_ctx->tmpFp, "static TSKM_SVC_CTX_t serviceList[TSKM_SVC_NUM]; \n\n");
164 fclose(p_ctx->tmpFp);
166 fprintf(p_ctx->fp,"\n\n");
168 p_ctx->state = ELE_TSKM_CFG;
171 /***************************************
173 **************************************/
175 entryService(PARSE_CTX_t* p_ctx,const XML_Char *name,const XML_Char* atts[]) {
176 PARSE_ASSERT_EXIT(strcmp(name,"service") == 0);
179 p_ctx->state = ELE_SERVICE;
181 memset(&p_ctx->svc,0,sizeof(p_ctx->svc));
183 for(ii=0; atts[ii]; ii+=2) {
184 const char* attr = atts[ii];
185 const char* value = atts[ii+1];
186 if(strcmp(attr,"svcid")==0) {
187 strcpy(p_ctx->svc.svcid,value);
188 } else if(strcmp(attr,"name")==0) {
189 strcpy(p_ctx->svc.name,value);
190 } else if(strcmp(attr,"path")==0) {
191 strcpy(p_ctx->svc.path,value);
192 } else if(strcmp(attr,"type")==0) {
193 const char* typeName = (strcmp(value,"native")==0) ? "TSKM_SVC_TYPE_NATIVE" : "TSKM_SVC_TYPE_UNKNONW";
194 strcpy(p_ctx->svc.type,typeName);
195 } else if(strcmp(attr,"prio")==0) {
196 strcpy(p_ctx->svc.prio,value);
197 } else if(strcmp(attr,"policy")==0) {
198 const char* polName = (strcmp(value,"fifo")==0) ? "TSKM_SVC_POLICY_FIFO" :
199 (strcmp(value,"tss")==0) ? "TSKM_SVC_POLICY_TSS" :
200 (strcmp(value,"rr")==0) ? "TSKM_SVC_POLICY_RR" : "ERROR";
201 strcpy(p_ctx->svc.policy,polName);
202 } else if(strcmp(attr,"life_cycle")==0) {
203 const char* lcName = (strcmp(value,"always")==0) ? "TSKM_SVC_LC_ALWAYS" :
204 (strcmp(value,"always_recoverable")==0) ? "TSKM_SVC_LC_ALWAYS_RECOVERABLE" :
205 (strcmp(value,"dynamic")==0) ? "TSKM_SVC_LC_DYNAMIC" : "ERROR";
206 strcpy(p_ctx->svc.life_cycle,lcName);
207 } else if(strcmp(attr,"retry_cnt")==0) {
208 strcpy(p_ctx->svc.retry_cnt,value);
209 } else if(strcmp(attr,"cpu_assign")==0) {
210 const char* caName = (strcmp(value,"cpu0")==0) ? "TSKM_SVC_ASSIGN_CPU_0" :
211 (strcmp(value,"cpu1")==0) ? "TSKM_SVC_ASSIGN_CPU_1" :
212 (strcmp(value,"auto")==0) ? "TSKM_SVC_ASSIGN_CPU_AUTO" : "ERROR";
213 strcpy(p_ctx->svc.cpu_assign,caName);
214 } else if(strcmp(attr,"user")==0) {
215 strcpy(p_ctx->svc.user,value);
216 } else if(strcmp(attr,"runtime_limit")==0) {
217 strcpy(p_ctx->svc.runtime_limit,value);
218 } else if(strcmp(attr,"cpu_limit")==0) {
219 strcpy(p_ctx->svc.cpu_limit,value);
220 } else if(strcmp(attr,"mem_limit")==0) {
221 strcpy(p_ctx->svc.mem_limit,value);
222 } else if(strcmp(attr,"args")==0) {
223 strcpy(p_ctx->svc.args,value);
224 } else if(strcmp(attr,"shutdown_wait")==0) {
225 const char* swStr = (strcmp(value,"yes")==0) ? "TSKM_TRUE" :
226 (strcmp(value,"no")==0) ? "TSKM_FALSE" : "ERROR";
227 strcpy(p_ctx->svc.shutdown_wait,swStr);
231 fprintf(p_ctx->fp,"char const *svcArgs%d[] = {",p_ctx->svcNum);
232 fprintf(p_ctx->fp,"\"%s\",",p_ctx->svc.path);
235 tp = strtok(p_ctx->svc.args," ");
237 fprintf(p_ctx->fp,"\"%s\",",tp);
238 tp = strtok(NULL," ");
241 fprintf(p_ctx->fp,"NULL");
242 fprintf(p_ctx->fp,"};\n");
245 /***************************************
247 **************************************/
249 exitService(PARSE_CTX_t* p_ctx) {
251 fprintf(p_ctx->tmpFp,"{" );
253 fprintf(p_ctx->tmpFp,"%s",p_ctx->svc.svcid);
254 fprintf(p_ctx->tmpFp,", (const char *)\"%s\"",p_ctx->svc.name);
255 fprintf(p_ctx->tmpFp,", (const char *)\"%s\"",p_ctx->svc.path);
256 fprintf(p_ctx->tmpFp,", (char**)svcArgs%d",p_ctx->svcNum);
257 fprintf(p_ctx->tmpFp,", %s",p_ctx->svc.type);
258 fprintf(p_ctx->tmpFp,", %s",p_ctx->svc.prio);
259 fprintf(p_ctx->tmpFp,", %s",p_ctx->svc.policy);
260 fprintf(p_ctx->tmpFp,", %s",p_ctx->svc.life_cycle);
261 fprintf(p_ctx->tmpFp,", (uint32_t)%s",p_ctx->svc.retry_cnt);
262 fprintf(p_ctx->tmpFp,", %s",p_ctx->svc.cpu_assign);
263 fprintf(p_ctx->tmpFp,", (const char *)\"%s\"",p_ctx->svc.user);
264 fprintf(p_ctx->tmpFp,", %s",(p_ctx->svc.runtime_limit[0] != '\0') ? p_ctx->svc.runtime_limit : "0");
265 fprintf(p_ctx->tmpFp,", %s",(p_ctx->svc.cpu_limit[0] != '\0') ? p_ctx->svc.cpu_limit : "0");
266 fprintf(p_ctx->tmpFp,", %s",(p_ctx->svc.mem_limit[0] != '\0') ? p_ctx->svc.mem_limit : "0");
267 fprintf(p_ctx->tmpFp,", %s",p_ctx->svc.shutdown_wait);
268 fprintf(p_ctx->tmpFp,", %d",p_ctx->svc.subgidNum);
269 if(p_ctx->svc.subgidNum) {
270 fprintf(p_ctx->tmpFp,", subgidList%d",p_ctx->svcNum);
272 fprintf(p_ctx->tmpFp,", NULL");
275 fprintf(p_ctx->tmpFp,"},\n");
279 p_ctx->state = ELE_SERVICE_LIST;
282 /***************************************
284 **************************************/
286 entrySubgidList(PARSE_CTX_t* p_ctx,const XML_Char* atts[]) {
287 p_ctx->state = ELE_SUBGID_LIST;
289 fprintf(p_ctx->fp,"static gid_t subgidList%d[] = {",p_ctx->svcNum);
294 /***************************************
296 **************************************/
298 handleSubgidList(PARSE_CTX_t* p_ctx,const XML_Char *name,const XML_Char* atts[]) {
299 PARSE_ASSERT_EXIT(strcmp(name,"subgid") == 0);
302 if(p_ctx->svc.subgidNum > 0) {
303 fprintf(p_ctx->fp,",");
305 for(ii=0; atts[ii]; ii+=2) {
306 const char* attr = atts[ii];
307 const char* value = atts[ii+1];
308 if(strcmp(attr,"gid")==0) {
309 fprintf(p_ctx->fp,"%s",value);
311 PARSE_ASSERT_EXIT(0);
314 p_ctx->svc.subgidNum++;
317 /***************************************
319 **************************************/
321 exitSubgidList(PARSE_CTX_t* p_ctx) {
323 fprintf(p_ctx->fp,"};\n");
325 p_ctx->state = ELE_SERVICE;
329 /***************************************
331 **************************************/
333 entryNormalWakeup(PARSE_CTX_t* p_ctx,const XML_Char* atts[]) {
334 p_ctx->state = ELE_NORMAL_WAKEUP;
335 memset(&p_ctx->gstep,0,sizeof(p_ctx->gstep));
337 sprintf(p_ctx->gstep.reqTableName,"wakeupReqList");
338 sprintf(p_ctx->gstep.execSvcName,"wakeupExecSvcId");
339 p_ctx->tmpFp = fopen(TMPFILE,"a");
340 PARSE_ASSERT_EXIT(p_ctx->tmpFp);
342 fprintf(p_ctx->tmpFp,"TSKM_GSTEP_t wakeupGstep[]={\n");
345 /***************************************
347 **************************************/
349 exitNormalWakeup(PARSE_CTX_t* p_ctx) {
350 fprintf(p_ctx->tmpFp,"};\n\n");
351 fclose(p_ctx->tmpFp);
353 p_ctx->state = ELE_TSKM_CFG;
356 /***************************************
358 **************************************/
360 entryVupWakeup(PARSE_CTX_t* p_ctx,const XML_Char* atts[]) {
361 p_ctx->state = ELE_VUP_WAKEUP;
362 memset(&p_ctx->gstep,0,sizeof(p_ctx->gstep));
364 sprintf(p_ctx->gstep.reqTableName,"wakeupReqListVup");
365 sprintf(p_ctx->gstep.execSvcName,"wakeupExecSvcIdVup");
366 p_ctx->tmpFp = fopen(TMPFILE,"a");
367 PARSE_ASSERT_EXIT(p_ctx->tmpFp);
369 fprintf(p_ctx->tmpFp,"TSKM_GSTEP_t wakeupGstepVup[]={\n");
372 /***************************************
374 **************************************/
376 exitVupWakeup(PARSE_CTX_t* p_ctx) {
377 fprintf(p_ctx->tmpFp,"};\n\n");
378 fclose(p_ctx->tmpFp);
380 p_ctx->state = ELE_TSKM_CFG;
384 entryGstep(PARSE_CTX_t* p_ctx,const XML_Char* atts[]) {
386 p_ctx->state &= ~ELE_MASK2;
387 p_ctx->state |= ELE_COMMON_GSTEP;
389 PARSE_GSTEP_t *p_gstep = &p_ctx->gstep;
391 if(atts[0] && strcmp(atts[0],"stepid") == 0) {
392 sprintf(p_gstep->gstepIdStr,"%s",atts[1]);
394 sprintf(p_gstep->gstepIdStr,"TSKM_GSTEP_NONE");
396 p_gstep->execSvcNum = 0;
398 sprintf(p_gstep->nextStepCondStr,"INI_INITCOMP_NONE");
402 handleGstep(PARSE_CTX_t* p_ctx,const XML_Char *name,const XML_Char* atts[]) {
403 PARSE_ASSERT_EXIT(strcmp(name,"next_trans_condition") == 0);
404 PARSE_GSTEP_t *p_gstep = &p_ctx->gstep;
406 if(atts[0] && strcmp(atts[0],"cond") == 0) {
407 sprintf(p_gstep->nextStepCondStr,"%s",atts[1]);
409 PARSE_ASSERT_EXIT(0);
414 exitGstep(PARSE_CTX_t* p_ctx) {
415 PARSE_GSTEP_t *p_gstep = &p_ctx->gstep;
417 fprintf(p_ctx->tmpFp,"{");
418 fprintf(p_ctx->tmpFp,"%s,",p_gstep->gstepIdStr);
419 fprintf(p_ctx->tmpFp,"%d,",p_gstep->execSvcNum);
420 if(p_gstep->execSvcNum) {
421 fprintf(p_ctx->tmpFp,"%s%d,",p_gstep->execSvcName,p_gstep->step);
423 fprintf(p_ctx->tmpFp,"NULL,");
425 fprintf(p_ctx->tmpFp,"%d,",p_gstep->reqNum);
426 if(p_gstep->reqNum) {
427 fprintf(p_ctx->tmpFp,"%s%d,",p_gstep->reqTableName,p_gstep->step);
429 fprintf(p_ctx->tmpFp,"NULL,");
431 fprintf(p_ctx->tmpFp,"%s",p_gstep->nextStepCondStr);
432 fprintf(p_ctx->tmpFp,"},\n");
436 p_ctx->state &= ~ELE_MASK2;
440 entryExec(PARSE_CTX_t* p_ctx,const XML_Char* atts[]) {
441 p_ctx->state &= ~ELE_MASK3;
442 p_ctx->state |= ELE_COMMON_EXEC;
444 PARSE_GSTEP_t *p_gstep = &p_ctx->gstep;
446 "static TSKM_SVCID_t %s%d[] = {",p_gstep->execSvcName,p_gstep->step);
449 handleExec(PARSE_CTX_t* p_ctx,const XML_Char *name,const XML_Char* atts[]) {
450 PARSE_ASSERT_EXIT(strcmp(name,"exec_svc") == 0);
451 PARSE_GSTEP_t *p_gstep = &p_ctx->gstep;
454 if(p_gstep->execSvcNum > 0) {
455 fprintf(p_ctx->fp,",");
458 for(ii=0; atts[ii]; ii+=2) {
459 const char* attr = atts[ii];
460 const char* value = atts[ii+1];
461 PARSE_ASSERT_EXIT(strcmp(attr,"svcid") == 0);
462 fprintf(p_ctx->fp,"%s",value);
464 p_gstep->execSvcNum++;
467 exitExec(PARSE_CTX_t* p_ctx) {
468 fprintf(p_ctx->fp,"};\n\n");
469 p_ctx->state &= ~ELE_MASK3;
473 entryReq(PARSE_CTX_t* p_ctx,const XML_Char* atts[]) {
474 p_ctx->state &= ~ELE_MASK3;
475 p_ctx->state |= ELE_COMMON_REQ;
476 PARSE_GSTEP_t *p_gstep = &p_ctx->gstep;
478 fprintf(p_ctx->fp,"static TSKM_GSTEP_REQ_INFO_t %s%d[] ={",p_gstep->reqTableName,p_gstep->step);
481 handleReq(PARSE_CTX_t* p_ctx,const XML_Char *name,const XML_Char* atts[]) {
482 PARSE_GSTEP_t *p_gstep = &p_ctx->gstep;
483 PARSE_ASSERT_EXIT(strcmp(name,"request") == 0);
486 fprintf(p_ctx->fp," {");
488 for(ii=0; atts[ii]; ii+=2) {
489 const char* attr = atts[ii];
490 const char* value = atts[ii+1];
491 if(strcmp(attr,"local_step") == 0) {
492 if(strcmp(value,"shm") == 0) {
493 fprintf(p_ctx->fp,"TSKM_LSTEP_SHM");
494 } else if(strcmp(value,"bupchk") == 0) {
495 fprintf(p_ctx->fp,"TSKM_LSTEP_BUPCHK");
496 } else if(strcmp(value,"last") == 0) {
497 fprintf(p_ctx->fp,"TSKM_LSTEP_LAST");
498 } else if(strcmp(value,"all") == 0) {
499 fprintf(p_ctx->fp,"TSKM_LSTEP_ALL");
501 fprintf(p_ctx->fp,"%s",value);
504 fprintf(p_ctx->fp,"%s",value); // Output of ","
506 fprintf(p_ctx->fp,"%s",(atts[ii+2])?",":""); // Outoput of ","
508 fprintf(p_ctx->fp,"},");
512 exitReq(PARSE_CTX_t* p_ctx) {
513 fprintf(p_ctx->fp,"};\n\n");
514 p_ctx->state &= ~ELE_MASK3;
517 /***************************************
518 * entryNormalShutdown
519 **************************************/
521 entryNormalShutdown(PARSE_CTX_t* p_ctx,const XML_Char* atts[]) {
522 p_ctx->state = ELE_NORMAL_SHUTDOWN;
524 memset(&p_ctx->gstep,0,sizeof(p_ctx->gstep));
525 sprintf(p_ctx->gstep.reqTableName,"downReqList");
526 p_ctx->tmpFp = fopen(TMPFILE,"a");
527 PARSE_ASSERT_EXIT(p_ctx->tmpFp);
529 fprintf(p_ctx->tmpFp,"static TSKM_GSTEP_t downGstep[]={\n");
532 /***************************************
534 **************************************/
536 exitNormalShutdown(PARSE_CTX_t* p_ctx) {
538 fprintf(p_ctx->tmpFp,"};\n\n");
539 fclose(p_ctx->tmpFp);
541 p_ctx->state = ELE_TSKM_CFG;
544 /***************************************
546 **************************************/
548 entryVupShutdown(PARSE_CTX_t* p_ctx,const XML_Char* atts[]) {
549 p_ctx->state = ELE_VUP_SHUTDOWN;
550 memset(&p_ctx->gstep,0,sizeof(p_ctx->gstep));
552 sprintf(p_ctx->gstep.reqTableName,"downReqListVup");
553 p_ctx->tmpFp = fopen(TMPFILE,"a");
554 PARSE_ASSERT_EXIT(p_ctx->tmpFp);
556 fprintf(p_ctx->tmpFp,"static TSKM_GSTEP_t downGstepVup[]={\n");
559 /***************************************
561 **************************************/
563 exitVupShutdown(PARSE_CTX_t* p_ctx) {
564 fprintf(p_ctx->tmpFp,"};\n\n");
565 fclose(p_ctx->tmpFp);
567 p_ctx->state = ELE_TSKM_CFG;
570 /***************************************
572 **************************************/
574 elementStart(void *userData, const XML_Char *name, const XML_Char *atts[]) {
575 PARSE_CTX_t *p_ctx = (PARSE_CTX_t*)userData;
578 printf("[ELEMENT] %s Start!\n", name);
579 for(ii=0; atts[ii]; ii+=2) {
580 printf(" %s:%s \n", atts[ii],atts[ii+1]);
583 switch(p_ctx->state) {
585 if(strcmp(name,"tskm_cfg") == 0) {
586 entryTskmCfg(p_ctx,atts);
588 PARSE_ASSERT_EXIT(0);
592 if(strcmp(name,"service_list") == 0) {
593 entryServiceList(p_ctx,atts);
594 } else if(strcmp(name,"normal_wakeup") == 0) {
595 entryNormalWakeup(p_ctx,atts);
596 } else if(strcmp(name,"normal_shutdown") == 0) {
597 entryNormalShutdown(p_ctx,atts);
598 } else if(strcmp(name,"vup_wakeup") == 0) {
599 entryVupWakeup(p_ctx,atts);
600 } else if(strcmp(name,"vup_shutdown") == 0) {
601 entryVupShutdown(p_ctx,atts);
603 PARSE_ASSERT_EXIT(0);
606 case ELE_SERVICE_LIST:
607 if(strcmp(name,"service") == 0) {
608 entryService(p_ctx,name,atts);
612 if(strcmp(name,"subgid_list") == 0) {
613 entrySubgidList(p_ctx,atts);
616 case ELE_SUBGID_LIST:
617 handleSubgidList(p_ctx,name,atts);
619 case ELE_NORMAL_WAKEUP:
620 case ELE_NORMAL_SHUTDOWN:
622 case ELE_VUP_SHUTDOWN:
623 if(strcmp(name,"global_step") == 0) {
624 entryGstep(p_ctx,atts);
626 PARSE_ASSERT_EXIT(0);
629 case ELE_NORMAL_W_GSTEP:
630 case ELE_NORMAL_D_GSTEP:
631 case ELE_VUP_W_GSTEP:
632 case ELE_VUP_D_GSTEP:
633 if(strcmp(name,"exec_list") == 0) {
634 entryExec(p_ctx,atts);
635 } else if(strcmp(name,"request_list") == 0) {
636 entryReq(p_ctx,atts);
638 handleGstep(p_ctx,name,atts);
641 case ELE_NORMAL_W_EXEC:
643 handleExec(p_ctx,name,atts);
645 case ELE_NORMAL_W_REQ:
646 case ELE_NORMAL_D_REQ:
649 handleReq(p_ctx,name,atts);
655 /***************************************
657 **************************************/
659 elementEnd(void *userData, const XML_Char *name) {
660 PARSE_CTX_t *p_ctx = (PARSE_CTX_t*)userData;
661 switch(p_ctx->state) {
663 PARSE_ASSERT_EXIT(0);
666 if(strcmp(name,"tskm_cfg") == 0) {
669 PARSE_ASSERT_EXIT(0);
672 case ELE_SERVICE_LIST:
673 if(strcmp(name,"service_list") == 0) {
674 exitServiceList(p_ctx);
678 if(strcmp(name,"service") == 0) {
682 case ELE_SUBGID_LIST:
683 if(strcmp(name,"subgid_list") == 0) {
684 exitSubgidList(p_ctx);
687 case ELE_NORMAL_WAKEUP:
688 if(strcmp(name,"normal_wakeup") == 0) {
689 exitNormalWakeup(p_ctx);
692 case ELE_NORMAL_SHUTDOWN:
693 if(strcmp(name,"normal_shutdown") == 0) {
694 exitNormalShutdown(p_ctx);
698 if(strcmp(name,"vup_wakeup") == 0) {
699 exitVupWakeup(p_ctx);
702 case ELE_VUP_SHUTDOWN:
703 if(strcmp(name,"vup_shutdown") == 0) {
704 exitVupShutdown(p_ctx);
707 case ELE_NORMAL_D_GSTEP:
708 case ELE_NORMAL_W_GSTEP:
709 case ELE_VUP_D_GSTEP:
710 case ELE_VUP_W_GSTEP:
711 if(strcmp(name,"global_step") == 0) {
715 case ELE_NORMAL_W_EXEC:
717 if(strcmp(name,"exec_list") == 0) {
721 case ELE_NORMAL_D_REQ:
722 case ELE_NORMAL_W_REQ:
725 if(strcmp(name,"request_list") == 0) {
731 /***************************************
733 **************************************/
735 parseXmlFile(const char* file,XML_Parser parser) {
737 FILE* fp = fopen(file, "r");
743 char *buf = (char*) XML_GetBuffer(parser, BUFSIZE);
748 size_t nread = fread(buf, sizeof(char), BUFSIZE, fp);
753 if (!XML_ParseBuffer(parser, nread, feof(fp))) {
769 /***************************************
771 **************************************/
773 externalHandler(XML_Parser parser,
774 const XML_Char* content, const XML_Char* base,
775 const XML_Char* systemId, const XML_Char* publicId) {
776 printf("parse %s \n",systemId);
778 int ret = XML_ERROR_EXTERNAL_ENTITY_HANDLING;
779 XML_Parser extparser = NULL;
781 extparser = XML_ExternalEntityParserCreate(parser, content, NULL);
782 if(extparser ==NULL) {
786 if(parseXmlFile(systemId,extparser) != 0) {
792 XML_ParserFree(extparser);
797 /***************************************
799 **************************************/
801 usage(const char* cmd) {
802 printf("usage:%s xmlfile\n",cmd);
805 /***************************************
807 **************************************/
809 main (int argc, char *argv[]) {
810 struct stat statinfo;
827 if(0 != stat(inpath,&statinfo)) {
828 fprintf(stderr, "%s:%s",strerror(errno),inpath);
831 memset(&ctx,0,sizeof(ctx));
833 strcpy(tmpstr1,inpath);
834 strcpy(tmpstr2,inpath);
835 workdir=dirname(tmpstr1);
836 infile=basename(tmpstr2);
838 if(0 != chdir(workdir)) {
839 fprintf(stderr, "%s:%s",strerror(errno),workdir);
843 ctx.fp = fopen(OUTFILE, "w");
844 if (ctx.fp == NULL) {
847 fprintf(ctx.fp,"//This file is created automatically from %s.\n",inpath);
848 fprintf(ctx.fp,"//So you shall not modify this file immediately.\n");
850 /* create XML parser */
851 if ((parser = XML_ParserCreate(NULL)) == NULL) {
852 fprintf(stderr, "parser creation error\n");
855 XML_SetUserData(parser,&ctx);
856 XML_SetParamEntityParsing(parser,XML_PARAM_ENTITY_PARSING_ALWAYS); // Allow External Entities
857 XML_SetExternalEntityRefHandler(parser,externalHandler);
858 XML_SetElementHandler(parser, elementStart, elementEnd);
860 if(parseXmlFile(infile,parser) != 0) {
867 XML_ParserFree(parser);
873 sprintf(buf,"cat %s >> %s",TMPFILE,OUTFILE);