Ignore:
Timestamp:
Dec 19, 2016, 6:01:06 PM (7 years ago)
Author:
djay
Message:

Add support for nested inputs and outputs.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/zoo-project/zoo-kernel/service_yaml.c

    r781 r790  
    8484  yaml_parser_set_input_file(&parser, fh);
    8585  /* BEGIN new code */
     86  int nleveld=-1;
    8687  int level=0;
    8788  int plevel=level;
     89  int nlevel=0;
     90  int pnlevel=0;
    8891  int ilevel=-1;
    8992  int blevel=-1;
    9093  int ttype=0;
     94  int outputs=-1;
     95  int noutputs=-1;
    9196  int wait_metadata=-1;
    9297  char *cur_key;
     
    145150      blevel++;
    146151      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;
    148159      if(ttype==0){
    149160        cur_key=zStrdup((char *)token.data.scalar.value);
     
    180191        current_content=NULL;
    181192        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(&current_element->content,current_content);
     207          freeMap(&current_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(&current_element);
     231          free(current_element);
     232          current_element=NULL;
     233        }
     234        nlevel+=1;
    182235      }
    183236      if(ttype==0 && strcasecmp((char *)token.data.scalar.value,"inputs")==0 && blevel==0){
     
    200253      }
    201254      if(ttype==0 && strcasecmp((char *)token.data.scalar.value,"outputs")==0 && blevel==1){
     255        outputs=1;
    202256        level++;
    203257#ifdef DEBUG_YAML
     
    303357      }
    304358
     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(&current_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(&current_element->supported->content,current_content);
     375              }else
     376                addMapToIoType(&current_element->supported,current_content);
     377            }
     378            freeMap(&current_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(&current_element);
     407          free(current_element);
     408          current_element=NULL;
     409          current_element=createElements((char *)token.data.scalar.value);
     410        }
     411      }
    305412      if(blevel==1 && level==1){
    306413        if(current_element!=NULL && current_content!=NULL){
     
    319426              addMapToIoType(&current_element->supported,current_content);
    320427          }
    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(&current_element);
    328           free(current_element);
    329         }
     428          freeMap(&current_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(&current_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(&current_element);
     467            free(current_element);
     468          }
     469        }   
    330470        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);       
    340472      }
    341473      if(blevel==1 && level==2){
     
    355487              addMapToIoType(&current_element->supported,current_content);
    356488          }
     489          freeMaps(&current_content);
     490          free(current_content);
     491          current_content=NULL;
    357492        }
    358493        if(current_element!=NULL){
     
    372507        }
    373508        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);       
    382510       
    383511      }
     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     
    384519
    385520
     
    433568    current_content=NULL;
    434569  }
     570
    435571  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    }
    440593    freeElements(&current_element);
    441594    free(current_element);
Note: See TracChangeset for help on using the changeset viewer.

Search

Context Navigation

ZOO Sponsors

http://www.zoo-project.org/trac/chrome/site/img/geolabs-logo.pnghttp://www.zoo-project.org/trac/chrome/site/img/neogeo-logo.png http://www.zoo-project.org/trac/chrome/site/img/apptech-logo.png http://www.zoo-project.org/trac/chrome/site/img/3liz-logo.png http://www.zoo-project.org/trac/chrome/site/img/gateway-logo.png

Become a sponsor !

Knowledge partners

http://www.zoo-project.org/trac/chrome/site/img/ocu-logo.png http://www.zoo-project.org/trac/chrome/site/img/gucas-logo.png http://www.zoo-project.org/trac/chrome/site/img/polimi-logo.png http://www.zoo-project.org/trac/chrome/site/img/fem-logo.png http://www.zoo-project.org/trac/chrome/site/img/supsi-logo.png http://www.zoo-project.org/trac/chrome/site/img/cumtb-logo.png

Become a knowledge partner

Related links

http://zoo-project.org/img/ogclogo.png http://zoo-project.org/img/osgeologo.png