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.c

    r757 r790  
    7474
    7575/**
    76  * Dump a map to a file
     76 * Dump a map to a file 
    7777 *
    7878 * @param t the map to dump to file
    79  * @param file the file to store the map
     79 * @param file the file pointer to store the map
    8080 */
    8181void dumpMapToFile(map* t,FILE* file){
     
    9696  while(tmp!=NULL){
    9797    fprintf(stderr,"MAP => [%s] \n",tmp->name);
     98    fprintf(stderr," * CONTENT [%s] \n",tmp->name);
    9899    dumpMap(tmp->content);
     100    fprintf(stderr," * CHILD [%s] \n",tmp->name);
     101    dumpMaps(tmp->child);
    99102    tmp=tmp->next;
    100103  }
     
    105108 *
    106109 * @param m the map to dump
    107  * @param file_path the full path to the file name to store the map
    108  */
    109 void dumpMapsToFile(maps* m,char* file_path,int limit){
    110   FILE* file=fopen(file_path,"w+");
     110 * @param file the the file pointer to store the map
     111 */
     112void _dumpMapsToFile(maps* m,FILE* file,int limit){
    111113  maps* tmp=m;
    112114  int cnt=0;
    113115  while(tmp!=NULL){
    114116    fprintf(file,"[%s]\n",tmp->name);
    115     dumpMapToFile(tmp->content,file);
     117    if(tmp->child!=NULL){
     118      _dumpMapsToFile(tmp->child,file,limit);
     119    }else
     120      dumpMapToFile(tmp->content,file);
    116121    fflush(file);
    117122    tmp=tmp->next;
     
    121126  }
    122127  fflush(file);
     128}
     129
     130/**
     131 * Dump a maps to a file, see _dumpMapsToFile().
     132 *
     133 * @param m the map to dump
     134 * @param file_path the full path to the file name to store the map
     135 * @param limit the number limiting the maps to be dumped
     136 */
     137void dumpMapsToFile(maps* m,char* file_path,int limit){
     138  FILE* file=fopen(file_path,"w+");
     139  _dumpMapsToFile(m,file,limit);
     140  fflush(file);
    123141  fclose(file);
    124142}
     
    129147 * @param name the key to add to the map
    130148 * @param value the corresponding value to add to the map
    131  * @return the allocated map
     149 * @return a pointer to the allocated map
    132150 */
    133151map* createMap(const char* name,const char* value){
     
    136154  tmp->value=zStrdup(value);
    137155  tmp->next=NULL;
     156  return tmp;
     157}
     158
     159/**
     160 * Create a new maps with the given name
     161 *
     162 * @param name of the maps
     163 * @return the allocated map
     164 */
     165maps* createMaps(const char* name){
     166  maps* tmp = (maps *) malloc (MAPS_SIZE);
     167  tmp->name = zStrdup (name);
     168  tmp->content = NULL;
     169  tmp->child = NULL;
     170  tmp->next = NULL;
    138171  return tmp;
    139172}
     
    283316      freeMap(&_cursor->content);
    284317      free(_cursor->content);
     318    }
     319    if(_cursor->child!=NULL){
     320      freeMaps(&_cursor->child);
     321      free(_cursor->child);
    285322    }
    286323    if(_cursor->next!=NULL){
     
    362399    if(tmp->format!=NULL)
    363400      free(tmp->format);
     401    if(tmp->child!=NULL){
     402      freeElements(&tmp->child);
     403      free(tmp->child);
     404    }
    364405    freeIOType(&tmp->defaults);
    365406    if(tmp->defaults!=NULL)
     
    593634iotype* getIoTypeFromElement(elements* e,char *name, map* values){
    594635  elements* cursor=e;
    595   while(cursor!=NULL){
    596     if(strcasecmp(cursor->name,name)==0){
    597       if(contains(cursor->defaults->content,values)==true)
    598         return cursor->defaults;
    599       else{
    600         iotype* tmp=cursor->supported;
    601         while(tmp!=NULL){
    602           if(contains(tmp->content,values)==true)
    603             return tmp;     
    604           tmp=tmp->next;
     636  if(values!=NULL)
     637    while(cursor!=NULL){
     638      if(strcasecmp(cursor->name,name)==0 && (cursor->defaults!=NULL || cursor->supported!=NULL)){
     639        if(contains(cursor->defaults->content,values)==true)
     640          return cursor->defaults;
     641        else{
     642          iotype* tmp=cursor->supported;
     643          while(tmp!=NULL){
     644            if(contains(tmp->content,values)==true)
     645              return tmp;           
     646            tmp=tmp->next;
     647          }
    605648        }
    606649      }
    607     }
    608     cursor=cursor->next;
    609   }
     650      cursor=cursor->next;
     651    }
    610652  return NULL;
    611653}
     
    677719  maps* res=NULL;
    678720  if(_cursor!=NULL){
    679     res=(maps*)malloc(MAPS_SIZE);
    680     res->name=zStrdup(_cursor->name);
    681     res->content=NULL;
    682     res->next=NULL;
     721    res=createMaps(_cursor->name);
    683722    map* mc=_cursor->content;
    684723    if(mc!=NULL){
    685724      addMapToMap(&res->content,mc);
    686725      loadMapBinaries(&res->content,mc);
     726    }
     727    maps* mcs=_cursor->child;
     728    if(mcs!=NULL){
     729      res->child=dupMaps(&mcs);
    687730    }
    688731    res->next=dupMaps(&_cursor->next);
     
    709752        _cursor=_cursor->next;
    710753      maps* tmp1=getMaps(*mo,tmp->name);
    711       if(tmp1==NULL)
     754      if(tmp1==NULL){
    712755        _cursor->next=dupMaps(&tmp);
    713       else
     756        if(tmp->child!=NULL)
     757          _cursor->next->child=dupMaps(&tmp->child);
     758        else
     759          _cursor->next->child=NULL;
     760      }
     761      else{
    714762        addMapToMap(&tmp1->content,tmp->content);
     763        if(tmp->child!=NULL)
     764          tmp1->child=dupMaps(&tmp->child);
     765        else
     766          tmp1->child=NULL;
     767      }
    715768      _cursor=*mo;
    716769    }
     
    872925      _ztmpm->value=zStrdup(value);
    873926    }else{
    874       maps *tmp=(maps*)malloc(MAPS_SIZE);
    875       tmp->name=zStrdup(key);
     927      maps *tmp=createMaps(key);
    876928      tmp->content=createMap(subkey,value);
    877       tmp->next=NULL;
    878929      addMapsToMaps(&_tmpm,tmp);
    879930      freeMaps(&tmp);
     
    881932    }
    882933  }else{
    883     maps *tmp=(maps*)malloc(MAPS_SIZE);
    884     tmp->name=zStrdup(key);
     934    maps *tmp=createMaps(key);
    885935    tmp->content=createMap(subkey,value);
    886     tmp->next=NULL;
    887936    addMapsToMaps(&m,tmp);
    888937    freeMaps(&tmp);
    889938    free(tmp);
    890939  }
     940}
     941
     942/**
     943 * Create an empty elements
     944 *
     945 * @return a pointer to the allocated elements
     946 */
     947elements* createEmptyElements(){
     948  elements* res=(elements*)malloc(ELEMENTS_SIZE);
     949  res->name=NULL;
     950  res->content=NULL;
     951  res->metadata=NULL;
     952  res->format=NULL;
     953  res->defaults=NULL;
     954  res->supported=NULL;
     955  res->child=NULL;
     956  res->next=NULL;
     957  return res;
     958}
     959
     960/**
     961 * Create a named elements
     962 *
     963 * @param name the elements name
     964 * @return a pointer to the allocated elements
     965 */
     966elements* createElements(char* name){
     967  elements* res=(elements*)malloc(ELEMENTS_SIZE);
     968  res->name=zStrdup(name);
     969  res->content=NULL;
     970  res->metadata=NULL;
     971  res->format=NULL;
     972  res->defaults=NULL;
     973  res->supported=NULL;
     974  res->child=NULL;
     975  res->next=NULL;
     976  return res;
     977}
     978
     979/**
     980 * Set the name of an elements
     981 *
     982 * @param name the elements name
     983 * @return a pointer to the allocated elements
     984 */
     985void setElementsName(elements** elem,char* name){
     986  elements* res=*elem;
     987  res->name=zStrdup(name);
     988  res->content=NULL;
     989  res->metadata=NULL;
     990  res->format=NULL;
     991  res->defaults=NULL;
     992  res->supported=NULL;
     993  res->child=NULL;
     994  res->next=NULL;
    891995}
    892996
     
    9211025      ioc++;
    9221026    }
     1027    if(tmp->child!=NULL){
     1028      fprintf(stderr," > CHILD \n");
     1029      dumpElements(tmp->child);
     1030    }
    9231031    fprintf(stderr,"------------------\n");
    9241032    tmp=tmp->next;
     
    9311039 * @param e the elements to dump
    9321040 */
    933 void dumpElementsAsYAML(elements* e){
     1041void dumpElementsAsYAML(elements* e,int level){
    9341042  elements* tmp=e;
    9351043  int i;
    9361044  while(tmp!=NULL){
    937     for(i=0;i<2;i++)
     1045    for(i=0;i<2+(4*level);i++)
    9381046      fprintf(stderr," ");
    9391047    fprintf(stderr,"%s:\n",tmp->name);
    9401048    map* mcurs=tmp->content;
    9411049    while(mcurs!=NULL){
    942       for(i=0;i<4;i++)
     1050      for(i=0;i<4+(4*level);i++)
    9431051        fprintf(stderr," ");
    9441052      _dumpMap(mcurs);
     
    9471055    mcurs=tmp->metadata;
    9481056    if(mcurs!=NULL){
    949       for(i=0;i<4;i++)
     1057      for(i=0;i<4+(4*level);i++)
    9501058        fprintf(stderr," ");
    9511059      fprintf(stderr,"MetaData:\n");
    9521060      while(mcurs!=NULL){
    953         for(i=0;i<6;i++)
     1061        for(i=0;i<6+(4*level);i++)
    9541062          fprintf(stderr," ");
    9551063        _dumpMap(mcurs);
     
    9571065      }
    9581066    }
    959     for(i=0;i<4;i++)
     1067    for(i=0;i<4+(4*level);i++)
    9601068      fprintf(stderr," ");
    961     fprintf(stderr,"%s:\n",tmp->format);
     1069    if(tmp->format!=NULL)
     1070      fprintf(stderr,"%s:\n",tmp->format);
     1071    else{
     1072      fprintf(stderr,"Child:\n");
     1073      if(tmp->child!=NULL)
     1074        dumpElementsAsYAML(tmp->child,level+1);
     1075    }
    9621076    iotype* tmpio=tmp->defaults;
    9631077    int ioc=0;
    9641078    while(tmpio!=NULL){
    965       for(i=0;i<6;i++)
     1079      for(i=0;i<6+(4*level);i++)
    9661080        fprintf(stderr," ");
    9671081      fprintf(stderr,"default:\n");
    9681082      mcurs=tmpio->content;
    9691083      while(mcurs!=NULL){
    970         for(i=0;i<8;i++)
     1084        for(i=0;i<8+(4*level);i++)
    9711085          fprintf(stderr," ");
    9721086        if(strcasecmp(mcurs->name,"range")==0){
     
    9821096    ioc=0;
    9831097    while(tmpio!=NULL){
    984       for(i=0;i<6;i++)
     1098      for(i=0;i<6+(4*level);i++)
    9851099        fprintf(stderr," ");
    9861100      fprintf(stderr,"supported:\n");
    9871101      mcurs=tmpio->content;
    9881102      while(mcurs!=NULL){
    989         for(i=0;i<8;i++)
     1103        for(i=0;i<8+(4*level);i++)
    9901104          fprintf(stderr," ");
    9911105        if(strcasecmp(mcurs->name,"range")==0){
     
    10551169    else
    10561170      tmp->supported=NULL;
     1171    if(cursor->child!=NULL)
     1172      tmp->child=dupElements(cursor->child);
     1173    else
     1174      tmp->child=NULL;
    10571175    tmp->next=dupElements(cursor->next);
    10581176  }
     
    10751193  }
    10761194}
    1077  
     1195
     1196/**
     1197 * Set the name of a service
     1198 *
     1199 * @param name the service name
     1200 */
     1201void setServiceName(service** serv,char* name){
     1202  service* res=*serv;
     1203  res->name=zStrdup(name);
     1204  res->content=NULL;
     1205  res->metadata=NULL;
     1206  res->inputs=NULL;
     1207  res->outputs=NULL;
     1208}
     1209
    10781210/**
    10791211 * Dump a service on stderr
     
    11261258  if(s->inputs!=NULL){
    11271259    fprintf(stderr,"\ninputs:\n");
    1128     dumpElementsAsYAML(s->inputs);
     1260    dumpElementsAsYAML(s->inputs,0);
    11291261  }
    11301262  if(s->outputs!=NULL){
    11311263    fprintf(stderr,"\noutputs:\n");
    1132     dumpElementsAsYAML(s->outputs);
     1264    dumpElementsAsYAML(s->outputs,0);
    11331265  }
    11341266}
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