source: trunk/zoo-project/zoo-kernel/service.h @ 360

Last change on this file since 360 was 360, checked in by djay, 12 years ago

Add support for multiple inputs values for the same identifier.

  • Property svn:eol-style set to native
  • Property svn:mime-type set to text/x-chdr
File size: 19.9 KB
Line 
1/**
2 * Author : Gérald FENOY
3 *
4 * Copyright (c) 2009-2012 GeoLabs SARL
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a copy
7 * of this software and associated documentation files (the "Software"), to deal
8 * in the Software without restriction, including without limitation the rights
9 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 * copies of the Software, and to permit persons to whom the Software is
11 * furnished to do so, subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be included in
14 * all copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22 * THE SOFTWARE.
23 */
24
25#ifndef ZOO_SERVICE_H
26#define ZOO_SERVICE_H 1
27
28#pragma once
29
30#ifdef WIN32
31#define strncasecmp strnicmp
32#define strcasecmp stricmp
33#define snprintf sprintf_s
34#endif
35
36#ifdef __cplusplus
37extern "C" {
38#endif
39
40#include <stdlib.h>
41#include <ctype.h>
42#include <stdio.h>
43#include <string.h>
44
45#define bool int
46#define true 1
47#define false -1
48
49#define SERVICE_ACCEPTED 0
50#define SERVICE_STARTED 1
51#define SERVICE_PAUSED 2
52#define SERVICE_SUCCEEDED 3
53#define SERVICE_FAILED 4
54
55#define ELEMENTS_SIZE (sizeof(char*)+(((2*sizeof(char*))+sizeof(maps*))*2)+sizeof(char*)+(((2*sizeof(char*))+sizeof(iotype*))*2)+sizeof(elements*))
56#define MAP_SIZE (2*sizeof(char*))+sizeof(NULL)
57#define IOTYPE_SIZE MAP_SIZE+sizeof(NULL)
58#define MAPS_SIZE (2*sizeof(char*))+sizeof(map*)+MAP_SIZE
59#define SERVICE_SIZE (ELEMENTS_SIZE*2)+(MAP_SIZE*2)+sizeof(char*)
60
61#define SHMSZ     27
62
63
64  /**
65   * \struct map
66   * \brief KVP linked list
67   *
68   * Deal with WPS KVP (name,value).
69   * A map is defined as:
70   *  - name : a key,
71   *  - value: a value,
72   *  - next : a pointer to the next map if any.
73   */
74  typedef struct map{
75    char* name;
76    char* value;
77    struct map* next;
78  } map;
79
80#ifdef WIN32
81#define NULLMAP ((map*) 0)
82#else
83#define NULLMAP NULL
84#endif
85
86  /**
87   * \struct maps
88   * \brief linked list of map pointer
89   *
90   * Small object to store WPS KVP set.
91   * Maps is defined as:
92   *  - a name,
93   *  - a content map,
94   *  - a pointer to the next maps if any.
95   */
96  typedef struct maps{
97    char* name;         
98    struct map* content; 
99    struct maps* next;   
100  } maps;
101
102  /**
103   * \brief Dump a map on stderr
104   */
105  static void _dumpMap(map* t){
106    if(t!=NULL){
107      fprintf(stderr,"[%s] => [%s] \n",t->name,t->value);
108      fflush(stderr);
109    }else{
110      fprintf(stderr,"NULL\n");
111      fflush(stderr);
112    }
113  }
114
115  static void dumpMap(map* t){
116    map* tmp=t;
117    while(tmp!=NULL){
118      _dumpMap(tmp);
119      tmp=tmp->next;
120    }
121  }
122
123  static void dumpMapToFile(map* t,FILE* file){
124    map* tmp=t;
125    while(tmp!=NULL){
126      fprintf(stderr,"%s = %s\n",tmp->name,tmp->value);
127      fprintf(file,"%s = %s\n",tmp->name,tmp->value);
128      tmp=tmp->next;
129    }
130  }
131
132  static void dumpMaps(maps* m){
133    maps* tmp=m;
134    while(tmp!=NULL){
135      fprintf(stderr,"MAP => [%s] \n",tmp->name);
136      dumpMap(tmp->content);
137      tmp=tmp->next;
138    }
139  }
140
141  static void dumpMapsToFile(maps* m,char* file_path){
142    FILE* file=fopen(file_path,"w");
143    maps* tmp=m;
144    if(tmp!=NULL){
145      fprintf(file,"[%s]\n",tmp->name);
146      dumpMapToFile(tmp->content,file);
147      fflush(file);
148    }
149    fclose(file);
150  }
151
152  static map* createMap(const char* name,const char* value){
153    map* tmp=(map *)malloc(MAP_SIZE);
154    tmp->name=strdup(name);
155    tmp->value=strdup(value);
156    tmp->next=NULL;
157    return tmp;
158  }
159
160  static int count(map* m){
161    map* tmp=m;
162    int c=0;
163    while(tmp!=NULL){
164      c++;
165      tmp=tmp->next;
166    }
167    return c;
168  }
169   
170  static bool hasKey(map* m,const char *key){
171    map* tmp=m;
172    while(tmp!=NULL){
173      if(strcasecmp(tmp->name,key)==0)
174        return true;
175      tmp=tmp->next;
176    }
177#ifdef DEBUG_MAP
178    fprintf(stderr,"NOT FOUND \n");
179#endif
180    return false;
181  }
182
183  static maps* getMaps(maps* m,const char *key){
184    maps* tmp=m;
185    while(tmp!=NULL){
186      if(strcasecmp(tmp->name,key)==0){
187        return tmp;
188      }
189      tmp=tmp->next;
190    }
191    return NULL;
192  }
193
194  static map* getMap(map* m,const char *key){
195    map* tmp=m;
196    while(tmp!=NULL){
197      if(strcasecmp(tmp->name,key)==0){
198        return tmp;
199      }
200      tmp=tmp->next;
201    }
202    return NULL;
203  }
204
205
206  static map* getLastMap(map* m){
207    map* tmp=m;
208    while(tmp!=NULL){
209      if(tmp->next==NULL){
210        return tmp;
211      }
212      tmp=tmp->next;
213    }
214    return NULL;
215  }
216
217  static map* getMapFromMaps(maps* m,const char* key,const char* subkey){
218    maps* _tmpm=getMaps(m,key);
219    if(_tmpm!=NULL){
220      map* _ztmpm=getMap(_tmpm->content,subkey);
221      return _ztmpm;
222    }
223    else return NULL;
224  }
225
226  static char* getMapsAsKVP(maps* m,int length,int type){
227    char *dataInputsKVP=(char*) malloc(length*sizeof(char));
228    maps* curs=m;
229    int i=0;
230    while(curs!=NULL){
231      if(i==0)
232        if(type==0)
233          sprintf(dataInputsKVP,"%s=",curs->name);
234        else
235          sprintf(dataInputsKVP,"%s",curs->name);
236      else{
237        char *temp=strdup(dataInputsKVP);
238        if(type==0)
239          sprintf(dataInputsKVP,"%s;%s=",temp,curs->name);
240        else
241          sprintf(dataInputsKVP,"%s;%s",temp,curs->name);
242        free(temp);
243      }
244      map* icurs=curs->content;
245      if(type==0){
246        map* tmp=getMap(curs->content,"value");
247        char *temp=strdup(dataInputsKVP);
248        if(getMap(m->content,"xlink:href")!=NULL)
249          sprintf(dataInputsKVP,"%sReference",temp);
250        else
251          sprintf(dataInputsKVP,"%s%s",temp,icurs->value);
252        free(temp);
253      }
254      int j=0;
255      while(icurs!=NULL){
256        if(strcasecmp(icurs->name,"value")!=0 &&
257           strcasecmp(icurs->name,"Reference")!=0 &&
258           strcasecmp(icurs->name,"minOccurs")!=0 &&
259           strcasecmp(icurs->name,"maxOccurs")!=0 &&
260           strcasecmp(icurs->name,"inRequest")!=0){
261          char *itemp=strdup(dataInputsKVP);
262          sprintf(dataInputsKVP,"%s@%s=%s",itemp,icurs->name,icurs->value);
263          free(itemp);
264        }
265        icurs=icurs->next;
266      }
267      curs=curs->next;
268      i++;
269    }
270    return dataInputsKVP;
271  }
272
273
274  static void freeMap(map** mo){
275    map* _cursor=*mo;
276    if(_cursor!=NULL){
277#ifdef DEBUG
278      fprintf(stderr,"freeMap\n");
279#endif
280      free(_cursor->name);
281      free(_cursor->value);
282      if(_cursor->next!=NULL){
283        freeMap(&_cursor->next);
284        free(_cursor->next);
285      }
286    }
287  }
288
289  static void freeMaps(maps** mo){
290    maps* _cursor=*mo;
291    fflush(stderr);
292    if(_cursor && _cursor!=NULL){
293#ifdef DEBUG
294      fprintf(stderr,"freeMaps\n");
295#endif
296      free(_cursor->name);
297      if(_cursor->content!=NULL){
298        freeMap(&_cursor->content);
299        free(_cursor->content);
300      }
301      if(_cursor->next!=NULL){
302        freeMaps(&_cursor->next);
303        free(_cursor->next);
304      }
305    }
306  }
307
308  /**
309   * \brief Not named linked list
310   *
311   * Used to store informations about formats, such as mimeType, encoding ...
312   *
313   * An iotype is defined as :
314   *  - a content map,
315   *  - a pointer to the next iotype if any.
316   */
317  typedef struct iotype{
318    struct map* content;
319    struct iotype* next;
320  } iotype;
321
322  /**
323   * \brief Metadata information about input or output.
324   *
325   * The elements are used to store metadata informations defined in the ZCFG.
326   *
327   * An elements is defined as :
328   *  - a name,
329   *  - a content map,
330   *  - a metadata map,
331   *  - a format (possible values are LiteralData, ComplexData or
332   * BoundingBoxData),
333   *  - a default iotype,
334   *  - a pointer to the next elements id any.
335   */
336  typedef struct elements{
337    char* name;
338    struct map* content;
339    struct map* metadata;
340    char* format;
341    struct iotype* defaults;
342    struct iotype* supported;
343    struct elements* next;
344  } elements;
345
346  typedef struct service{
347    char* name;
348    struct map* content;
349    struct map* metadata;
350    struct elements* inputs;
351    struct elements* outputs; 
352  } service;
353
354  typedef struct services{
355    struct service* content; 
356    struct services* next; 
357  } services;
358
359  static bool hasElement(elements* e,const char* key){
360    elements* tmp=e;
361    while(tmp!=NULL){
362      if(strcasecmp(key,tmp->name)==0)
363        return true;
364      tmp=tmp->next;
365    }
366    return false;
367  }
368
369  static elements* getElements(elements* m,char *key){
370    elements* tmp=m;
371    while(tmp!=NULL){
372      if(strcasecmp(tmp->name,key)==0)
373        return tmp;
374      tmp=tmp->next;
375    }
376    return NULL;
377  }
378
379
380  static void freeIOType(iotype** i){
381    iotype* _cursor=*i;
382    if(_cursor!=NULL){
383      if(_cursor->next!=NULL){
384        freeIOType(&_cursor->next);
385        free(_cursor->next);
386      }
387      freeMap(&_cursor->content);
388      free(_cursor->content);
389    }
390  }
391
392  static void freeElements(elements** e){
393    elements* tmp=*e;
394    if(tmp!=NULL){
395      if(tmp->name!=NULL)
396        free(tmp->name);
397      freeMap(&tmp->content);
398      if(tmp->content!=NULL)
399        free(tmp->content);
400      freeMap(&tmp->metadata);
401      if(tmp->metadata!=NULL)
402        free(tmp->metadata);
403      if(tmp->format!=NULL)
404        free(tmp->format);
405      freeIOType(&tmp->defaults);
406      if(tmp->defaults!=NULL)
407        free(tmp->defaults);
408      freeIOType(&tmp->supported);
409      if(tmp->supported!=NULL){
410        free(tmp->supported);
411      }
412      freeElements(&tmp->next);
413      if(tmp->next!=NULL)
414        free(tmp->next);
415    }
416  }
417
418  static void freeService(service** s){
419    service* tmp=*s;
420    if(tmp!=NULL){
421      if(tmp->name!=NULL)
422        free(tmp->name);
423      freeMap(&tmp->content);
424      if(tmp->content!=NULL)
425        free(tmp->content);
426      freeMap(&tmp->metadata);
427      if(tmp->metadata!=NULL)
428        free(tmp->metadata);
429      freeElements(&tmp->inputs);
430      if(tmp->inputs!=NULL)
431        free(tmp->inputs);
432      freeElements(&tmp->outputs);
433      if(tmp->outputs!=NULL)
434        free(tmp->outputs);
435    }
436  }
437
438  static void addToMap(map* m,const char* n,const char* v){
439    if(hasKey(m,n)==false){
440      map* _cursor=m;
441      while(_cursor->next!=NULL)
442        _cursor=_cursor->next;
443      _cursor->next=createMap(n,v);
444    }
445    else{
446      map *tmp=getMap(m,n);
447      if(tmp->value!=NULL)
448        free(tmp->value);
449      tmp->value=strdup(v);
450    }
451  }
452
453  static void addMapToMap(map** mo,map* mi){
454    map* tmp=mi;
455    map* _cursor=*mo;
456    if(tmp==NULL){
457      if(_cursor!=NULL){
458        while(_cursor!=NULL)
459          _cursor=_cursor->next;
460        _cursor=NULL;
461      }else
462        *mo=NULL;
463    }
464    while(tmp!=NULL){
465      if(_cursor==NULL){
466        if(*mo==NULL)
467          *mo=createMap(tmp->name,tmp->value);
468        else
469          addToMap(*mo,tmp->name,tmp->value);
470      }
471      else{
472#ifdef DEBUG
473        fprintf(stderr,"_CURSOR\n");
474        dumpMap(_cursor);
475#endif
476        while(_cursor!=NULL)
477          _cursor=_cursor->next;
478        _cursor=createMap(tmp->name,tmp->value);
479        _cursor->next=NULL;
480      }
481      tmp=tmp->next;
482#ifdef DEBUG
483      fprintf(stderr,"MO\n");
484      dumpMap(*mo);
485#endif
486    }
487  }
488
489  static void addMapToIoType(iotype** io,map* mi){
490    iotype* tmp=*io;
491    while(tmp->next!=NULL){
492      tmp=tmp->next;
493    }
494    tmp->next=(iotype*)malloc(IOTYPE_SIZE);
495    tmp->next->content=NULL;
496    addMapToMap(&tmp->next->content,mi);
497    tmp->next->next=NULL;
498  }
499
500  static map* getMapOrFill(map* m,const char *key,char* value){
501    map* tmp=m;
502    map* tmpMap=getMap(tmp,key);
503    if(tmpMap==NULL){
504      if(tmp!=NULL)
505        addToMap(tmp,key,value);
506      else
507        tmp=createMap(key,value);
508      tmpMap=getMap(tmp,key);
509    }
510    return tmpMap;
511  }
512
513  static bool contains(map* m,map* i){
514    while(i!=NULL){     
515      if(strcasecmp(i->name,"value")!=0 &&
516         strcasecmp(i->name,"xlink:href")!=0 &&
517         strcasecmp(i->name,"useMapServer")!=0 &&
518         strcasecmp(i->name,"asReference")!=0){
519        map *tmp;
520        if(hasKey(m,i->name) && (tmp=getMap(m,i->name))!=NULL && 
521           strcasecmp(i->value,tmp->value)!=0)
522          return false;
523      }
524      i=i->next;
525    }
526    return true;
527  }
528
529  static iotype* getIoTypeFromElement(elements* e,char *name, map* values){
530    elements* cursor=e;
531    while(cursor!=NULL){
532      if(strcasecmp(cursor->name,name)==0){
533        if(contains(cursor->defaults->content,values)==true)
534          return cursor->defaults;
535        else{
536          iotype* tmp=cursor->supported;
537          while(tmp!=NULL){
538            if(contains(tmp->content,values)==true)
539              return tmp;           
540            tmp=tmp->next;
541          }
542        }
543      }
544      cursor=cursor->next;
545    }
546    return NULL;
547  }
548
549  static maps* dupMaps(maps** mo){
550    maps* _cursor=*mo;
551    maps* res=NULL;
552    if(_cursor!=NULL){
553      res=(maps*)malloc(MAPS_SIZE);
554      res->name=strdup(_cursor->name);
555      res->content=NULL;
556      res->next=NULL;
557      map* mc=_cursor->content;
558      map* tmp=getMap(mc,"size");
559      char* tmpSized=NULL;
560      if(tmp!=NULL){
561        map* tmpV=getMap(mc,"value");
562        tmpSized=(char*)malloc((atoi(tmp->value)+1)*sizeof(char));
563        memmove(tmpSized,tmpV->value,atoi(tmp->value)*sizeof(char));
564      }
565      if(mc!=NULL){
566        addMapToMap(&res->content,mc);
567      }
568      if(tmp!=NULL){
569        map* tmpV=getMap(res->content,"value");
570        free(tmpV->value);
571        tmpV->value=(char*)malloc((atoi(tmp->value)+1)*sizeof(char));
572        memmove(tmpV->value,tmpSized,atoi(tmp->value)*sizeof(char));
573        tmpV->value[atoi(tmp->value)]=0;
574        free(tmpSized);
575      }
576      res->next=dupMaps(&_cursor->next);
577    }
578    return res;
579  }
580
581  static void addMapsToMaps(maps** mo,maps* mi){
582    maps* tmp=mi;
583    maps* _cursor=*mo;
584    while(tmp!=NULL){
585      if(_cursor==NULL){
586        *mo=dupMaps(&mi);
587        (*mo)->next=NULL;
588      }
589      else{
590        while(_cursor->next!=NULL)
591          _cursor=_cursor->next;
592        _cursor->next=dupMaps(&tmp);
593      }
594      tmp=tmp->next;
595    }
596  }
597
598  static map* getMapArray(map* m,char* key,int index){
599    char tmp[1024];
600    if(index>0)
601      sprintf(tmp,"%s_%d",key,index);
602    else
603      sprintf(tmp,key);
604#ifdef DEBUG
605    fprintf(stderr,"** KEY %s\n",tmp);
606#endif
607    map* tmpMap=getMap(m,tmp);
608#ifdef DEBUG
609    if(tmpMap!=NULL)
610      dumpMap(tmpMap);
611#endif
612    return tmpMap;
613  }
614
615
616  static void setMapArray(map* m,char* key,int index,char* value){
617    char tmp[1024];
618    if(index>0)
619      sprintf(tmp,"%s_%d",key,index);
620    else
621      sprintf(tmp,key);
622    map* tmpSize=getMapArray(m,"size",index);
623    if(tmpSize!=NULL && strncasecmp(key,"value",5)==0){
624      fprintf(stderr,"%s\n",tmpSize->value);
625      map* ptr=getMapOrFill(m,tmp,"");
626      free(ptr->value);
627      ptr->value=(char*)malloc((atoi(tmpSize->value)+1)*sizeof(char));
628      memcpy(ptr->value,value,atoi(tmpSize->value)); 
629    }
630    else
631      addToMap(m,tmp,value);
632  }
633
634  static map* getMapType(map* mt){
635    map* tmap=getMap(mt,"mimeType");
636    if(tmap==NULL){
637      tmap=getMap(mt,"dataType");
638      if(tmap==NULL){
639        tmap=getMap(mt,"CRS");
640      }
641    }
642    dumpMap(tmap);
643    return tmap;
644  }
645
646  static int addMapsArrayToMaps(maps** mo,maps* mi,char* typ){
647    maps* tmp=mi;
648    maps* _cursor=*mo;
649    maps* tmpMaps=getMaps(_cursor,tmp->name);
650
651    if(tmpMaps==NULL)
652      return -1;
653
654    map* tmpLength=getMap(tmpMaps->content,"length");
655    char tmpLen[10];
656    int len=1;
657    if(tmpLength!=NULL){
658      len=atoi(tmpLength->value);
659    }
660
661    map* tmpValI=getMap(tmp->content,"value");
662    char *tmpV[8]={
663      "size",
664      "value",
665      "uom",
666      "Reference",
667      "xlink:href",
668      typ,
669      "schema",
670      "encoding"
671    };
672    sprintf(tmpLen,"%d",len+1);
673    addToMap(_cursor->content,"length",tmpLen);
674    int i=0;
675    map* tmpSizeI=getMap(tmp->content,tmpV[i]);
676    for(0;i<8;i++){
677      map* tmpVI=getMap(tmp->content,tmpV[i]);
678      if(tmpVI!=NULL){
679        fprintf(stderr,"%s = %s\n",tmpV[i],tmpVI->value);
680        if(i<5)
681          setMapArray(_cursor->content,tmpV[i],len,tmpVI->value);
682        else
683          if(strncasecmp(tmpV[5],"mimeType",8)==0)
684            setMapArray(_cursor->content,tmpV[i],len,tmpVI->value);
685      }
686    }
687   
688    addToMap(_cursor->content,"isArray","true");
689    return 0;
690  }
691
692  static void setMapInMaps(maps* m,const char* key,const char* subkey,const char *value){
693    maps* _tmpm=getMaps(m,key);
694    if(_tmpm!=NULL){
695      map* _ztmpm=getMap(_tmpm->content,subkey);
696      if(_ztmpm!=NULL){
697        if(_ztmpm->value!=NULL)
698          free(_ztmpm->value);
699        _ztmpm->value=strdup(value);
700      }else{
701        addToMap(_tmpm->content,subkey,value);
702      }
703    }
704  }
705
706
707  static void dumpElements(elements* e){
708    elements* tmp=e;
709    while(tmp!=NULL){
710      fprintf(stderr,"ELEMENT [%s]\n",tmp->name);
711      fprintf(stderr," > CONTENT [%s]\n",tmp->name);
712      dumpMap(tmp->content);
713      fprintf(stderr," > METADATA [%s]\n",tmp->name);
714      dumpMap(tmp->metadata);
715      fprintf(stderr," > FORMAT [%s]\n",tmp->format);
716      iotype* tmpio=tmp->defaults;
717      int ioc=0;
718      while(tmpio!=NULL){
719        fprintf(stderr," > DEFAULTS [%s] (%i)\n",tmp->name,ioc);
720        dumpMap(tmpio->content);
721        tmpio=tmpio->next;
722        ioc++;
723      }
724      tmpio=tmp->supported;
725      ioc=0;
726      while(tmpio!=NULL){
727        fprintf(stderr," > SUPPORTED [%s] (%i)\n",tmp->name,ioc);
728        dumpMap(tmpio->content);
729        tmpio=tmpio->next;
730        ioc++;
731      }
732      fprintf(stderr,"------------------\n");
733      tmp=tmp->next;
734    }
735  }
736
737  static elements* dupElements(elements* e){
738    elements* cursor=e;
739    elements* tmp=NULL;
740    if(cursor!=NULL){
741#ifdef DEBUG
742      fprintf(stderr,">> %s %i\n",__FILE__,__LINE__);
743      dumpElements(e);
744      fprintf(stderr,">> %s %i\n",__FILE__,__LINE__);
745#endif
746      tmp=(elements*)malloc(ELEMENTS_SIZE);
747      tmp->name=strdup(e->name);
748      tmp->content=NULL;
749      addMapToMap(&tmp->content,e->content);
750      tmp->metadata=NULL;
751      addMapToMap(&tmp->metadata,e->metadata);
752      tmp->format=strdup(e->format);
753      if(e->defaults!=NULL){
754        tmp->defaults=(iotype*)malloc(IOTYPE_SIZE);
755        tmp->defaults->content=NULL;
756        addMapToMap(&tmp->defaults->content,e->defaults->content);
757        tmp->defaults->next=NULL;
758#ifdef DEBUG
759        fprintf(stderr,">> %s %i\n",__FILE__,__LINE__);
760        dumpMap(tmp->defaults->content);
761#endif
762      }else
763        tmp->defaults=NULL;
764      if(e->supported!=NULL){
765        tmp->supported=(iotype*)malloc(IOTYPE_SIZE);
766        tmp->supported->content=NULL;
767        addMapToMap(&tmp->supported->content,e->supported->content);
768        tmp->supported->next=NULL;
769        iotype *tmp2=e->supported->next;
770        while(tmp2!=NULL){
771          addMapToIoType(&tmp->supported,tmp2->content);
772#ifdef DEBUG
773          fprintf(stderr,">> %s %i\n",__FILE__,__LINE__);
774          dumpMap(tmp->defaults->content);
775#endif
776          tmp2=tmp2->next;
777        }
778      }
779      else
780        tmp->supported=NULL;
781      tmp->next=dupElements(cursor->next);
782    }
783    return tmp;
784  }
785
786  static void addToElements(elements** m,elements* e){
787    elements* tmp=e;
788    if(*m==NULL){
789      *m=dupElements(tmp);
790    }else{
791      addToElements(&(*m)->next,tmp);
792    }
793  }
794
795  static void dumpService(service* s){
796    fprintf(stderr,"++++++++++++++++++\nSERVICE [%s]\n++++++++++++++++++\n",s->name);
797    if(s->content!=NULL){
798      fprintf(stderr,"CONTENT MAP\n");
799      dumpMap(s->content);
800      fprintf(stderr,"CONTENT METADATA\n");
801      dumpMap(s->metadata);
802    }
803    if(s->inputs!=NULL){
804      fprintf(stderr,"INPUT ELEMENTS [%s]\n------------------\n",s->name);
805      dumpElements(s->inputs);
806    }
807    if(s->outputs!=NULL){
808      fprintf(stderr,"OUTPUT ELEMENTS [%s]\n------------------\n",s->name);
809      dumpElements(s->outputs);
810    }
811    fprintf(stderr,"++++++++++++++++++\n");
812  }
813
814  static void mapsToCharXXX(maps* m,char*** c){
815    maps* tm=m;
816    int i=0;
817    int j=0;
818    char tmp[10][30][1024];
819    memset(tmp,0,1024*10*10);
820    while(tm!=NULL){
821      if(i>=10)
822        break;
823      strcpy(tmp[i][j],"name");
824      j++;
825      strcpy(tmp[i][j],tm->name);
826      j++;
827      map* tc=tm->content;
828      while(tc!=NULL){
829        if(j>=30)
830          break;
831        strcpy(tmp[i][j],tc->name);
832        j++;
833        strcpy(tmp[i][j],tc->value);
834        j++;
835        tc=tc->next;
836      }
837      tm=tm->next;
838      j=0;
839      i++;
840    }
841    memcpy(c,tmp,10*10*1024);
842  }
843
844  static void charxxxToMaps(char*** c,maps**m){
845    maps* trorf=*m;
846    int i,j;
847    char tmp[10][30][1024];
848    memcpy(tmp,c,10*30*1024);
849    for(i=0;i<10;i++){
850      if(strlen(tmp[i][1])==0)
851        break;
852      trorf->name=tmp[i][1];
853      trorf->content=NULL;
854      trorf->next=NULL;
855      for(j=2;j<29;j+=2){
856        if(strlen(tmp[i][j+1])==0)
857          break;
858        if(trorf->content==NULL)
859          trorf->content=createMap(tmp[i][j],tmp[i][j+1]);
860        else
861          addToMap(trorf->content,tmp[i][j],tmp[i][j+1]);
862      }
863      trorf=trorf->next;
864    }
865    m=&trorf;
866  }
867
868#ifdef __cplusplus
869}
870#endif
871
872#endif
Note: See TracBrowser for help on using the repository browser.

Search

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