Changeset 790 for trunk/zoo-project/zoo-kernel/service_yaml.c
- Timestamp:
- Dec 19, 2016, 6:01:06 PM (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/zoo-project/zoo-kernel/service_yaml.c
r781 r790 84 84 yaml_parser_set_input_file(&parser, fh); 85 85 /* BEGIN new code */ 86 int nleveld=-1; 86 87 int level=0; 87 88 int plevel=level; 89 int nlevel=0; 90 int pnlevel=0; 88 91 int ilevel=-1; 89 92 int blevel=-1; 90 93 int ttype=0; 94 int outputs=-1; 95 int noutputs=-1; 91 96 int wait_metadata=-1; 92 97 char *cur_key; … … 145 150 blevel++; 146 151 break; 147 case YAML_SCALAR_TOKEN: 152 case YAML_SCALAR_TOKEN: 153 if((blevel-1)/2<nlevel){ 154 pnlevel=nlevel; 155 nlevel=(blevel-1)/2; 156 nleveld=1; 157 }else 158 nleveld=-1; 148 159 if(ttype==0){ 149 160 cur_key=zStrdup((char *)token.data.scalar.value); … … 180 191 current_content=NULL; 181 192 wait_metadata=1; 193 } 194 if(strcasecmp((char *)token.data.scalar.value,"Child")==0){ 195 elements* cursor=my_service->inputs; 196 if(outputs==1) 197 cursor=my_service->outputs; 198 for(int i=0;(blevel/2)>1 && i<(blevel/2)-1 && cursor!=NULL;i++){ 199 while(cursor->next!=NULL) 200 cursor=cursor->next; 201 if(cursor->child!=NULL){ 202 cursor=cursor->child; 203 } 204 } 205 if(current_content!=NULL){ 206 addMapToMap(¤t_element->content,current_content); 207 freeMap(¤t_content); 208 free(current_content); 209 current_content=NULL; 210 } 211 if(current_element!=NULL){ 212 if(blevel/2>1 && cursor!=NULL){ 213 if(cursor->child==NULL) 214 cursor->child=dupElements(current_element); 215 else 216 addToElements(&cursor->child,current_element); 217 } 218 else{ 219 if(outputs<0) 220 if(my_service->inputs==NULL) 221 my_service->inputs=dupElements(current_element); 222 else 223 addToElements(&my_service->inputs,current_element); 224 else 225 if(my_service->inputs==NULL) 226 my_service->outputs=dupElements(current_element); 227 else 228 addToElements(&my_service->outputs,current_element); 229 } 230 freeElements(¤t_element); 231 free(current_element); 232 current_element=NULL; 233 } 234 nlevel+=1; 182 235 } 183 236 if(ttype==0 && strcasecmp((char *)token.data.scalar.value,"inputs")==0 && blevel==0){ … … 200 253 } 201 254 if(ttype==0 && strcasecmp((char *)token.data.scalar.value,"outputs")==0 && blevel==1){ 255 outputs=1; 202 256 level++; 203 257 #ifdef DEBUG_YAML … … 303 357 } 304 358 359 if(strcasecmp(token.data.scalar.value,"default")!=0 && strcasecmp(token.data.scalar.value,"supported")!=0 && level==1 && (blevel-1)%2==0 && blevel!=1 && (blevel-1)/2==nlevel){ 360 if(current_element==NULL) 361 current_element=createElements((char *)token.data.scalar.value); 362 else{ 363 if(current_content!=NULL){ 364 if(current_element->defaults==NULL){ 365 current_element->defaults=(iotype*)malloc(IOTYPE_SIZE); 366 current_element->defaults->content=NULL; 367 current_element->defaults->next=NULL; 368 addMapToMap(¤t_element->defaults->content,current_content); 369 }else{ 370 if(current_element->supported==NULL){ 371 current_element->supported=(iotype*)malloc(IOTYPE_SIZE); 372 current_element->supported->content=NULL; 373 current_element->supported->next=NULL; 374 addMapToMap(¤t_element->supported->content,current_content); 375 }else 376 addMapToIoType(¤t_element->supported,current_content); 377 } 378 freeMap(¤t_content); 379 free(current_content); 380 current_content=NULL; 381 } 382 383 elements* cursor=my_service->inputs; 384 if(outputs==1) 385 cursor=my_service->outputs; 386 int llevel=((blevel-1)/2); 387 if(nleveld>0) 388 llevel=((blevel-1)/2)+1; 389 for(int i=0;llevel>1 && i<llevel-1 && cursor!=NULL;i++){ 390 while(cursor->next!=NULL) 391 cursor=cursor->next; 392 if(cursor->child!=NULL){ 393 cursor=cursor->child; 394 } 395 } 396 if(llevel>1) 397 if(cursor->child==NULL) 398 cursor->child=dupElements(current_element); 399 else 400 addToElements(&cursor->child,current_element); 401 else 402 if(cursor==NULL) 403 cursor=dupElements(current_element); 404 else 405 addToElements(&cursor,current_element); 406 freeElements(¤t_element); 407 free(current_element); 408 current_element=NULL; 409 current_element=createElements((char *)token.data.scalar.value); 410 } 411 } 305 412 if(blevel==1 && level==1){ 306 413 if(current_element!=NULL && current_content!=NULL){ … … 319 426 addMapToIoType(¤t_element->supported,current_content); 320 427 } 321 } 322 if(current_element!=NULL){ 323 if(my_service->inputs==NULL) 324 my_service->inputs=dupElements(current_element); 325 else 326 addToElements(&my_service->inputs,current_element); 327 freeElements(¤t_element); 328 free(current_element); 329 } 428 freeMap(¤t_content); 429 free(current_content); 430 current_content=NULL; 431 } 432 if(nleveld<0){ 433 if(current_element!=NULL){ 434 if(outputs<0) 435 if(my_service->inputs==NULL) 436 my_service->inputs=dupElements(current_element); 437 else 438 addToElements(&my_service->inputs,current_element); 439 else 440 if(my_service->outputs==NULL) 441 my_service->outputs=dupElements(current_element); 442 else 443 addToElements(&my_service->outputs,current_element); 444 freeElements(¤t_element); 445 free(current_element); 446 } 447 } 448 else{ 449 if(current_element!=NULL){ 450 elements* cursor=my_service->inputs; 451 if(outputs==1) 452 cursor=my_service->outputs; 453 while(cursor->next!=NULL) 454 cursor=cursor->next; 455 for(int i=0;pnlevel>1 && i<pnlevel-1 && cursor!=NULL;i++){ 456 while(cursor->next!=NULL) 457 cursor=cursor->next; 458 if(cursor->child!=NULL){ 459 cursor=cursor->child; 460 } 461 } 462 if(cursor->child==NULL) 463 cursor->child=dupElements(current_element); 464 else 465 addToElements(&cursor->child,current_element); 466 freeElements(¤t_element); 467 free(current_element); 468 } 469 } 330 470 plevel=level; 331 current_element=(elements*)malloc(ELEMENTS_SIZE); 332 current_element->name=zStrdup((char *)token.data.scalar.value); 333 current_element->content=NULL; 334 current_element->metadata=NULL; 335 current_element->format=NULL; 336 current_element->defaults=NULL; 337 current_element->supported=NULL; 338 current_element->next=NULL; 339 471 current_element=createElements((char *)token.data.scalar.value); 340 472 } 341 473 if(blevel==1 && level==2){ … … 355 487 addMapToIoType(¤t_element->supported,current_content); 356 488 } 489 freeMaps(¤t_content); 490 free(current_content); 491 current_content=NULL; 357 492 } 358 493 if(current_element!=NULL){ … … 372 507 } 373 508 plevel=level; 374 current_element=(elements*)malloc(ELEMENTS_SIZE); 375 current_element->name=zStrdup((char *)token.data.scalar.value); 376 current_element->content=NULL; 377 current_element->metadata=NULL; 378 current_element->format=NULL; 379 current_element->defaults=NULL; 380 current_element->supported=NULL; 381 current_element->next=NULL; 509 current_element=createElements((char *)token.data.scalar.value); 382 510 383 511 } 512 513 if(noutputs>0) 514 outputs=1; 515 if(strcasecmp((char *)token.data.scalar.value,"outputs")==0 && ttype==0 && blevel==0){ 516 noutputs=1; 517 } 518 384 519 385 520 … … 433 568 current_content=NULL; 434 569 } 570 435 571 if(current_element!=NULL){ 436 if(my_service->outputs==NULL) 437 my_service->outputs=dupElements(current_element); 438 else 439 addToElements(&my_service->outputs,current_element); 572 if(nlevel>0){ 573 elements* cursor=my_service->inputs; 574 if(outputs==1) 575 cursor=my_service->outputs; 576 for(int i=0;nlevel>1 && i<nlevel-1 && cursor!=NULL;i++){ 577 while(cursor->next!=NULL) 578 cursor=cursor->next; 579 if(cursor->child!=NULL){ 580 cursor=cursor->child; 581 } 582 } 583 if(cursor->child==NULL) 584 cursor->child=dupElements(current_element); 585 else 586 addToElements(&cursor->child,current_element); 587 }else{ 588 if(my_service->outputs==NULL) 589 my_service->outputs=dupElements(current_element); 590 else 591 addToElements(&my_service->outputs,current_element); 592 } 440 593 freeElements(¤t_element); 441 594 free(current_element);
Note: See TracChangeset
for help on using the changeset viewer.