source: trunk/zoo-kernel/service.h @ 26

Last change on this file since 26 was 26, checked in by djay, 14 years ago

ZOO-Kernel updates and bug fixes :

  • Fixing gestion of RawDataOutput? when the Service return SERVICE_FAILED an ExceptionReport? was returned to the client.
  • Use gcc when compiling service_internal.c to avoid strange error messages about switch ....
  • Function setMapInMaps was added in service.h to let users set the value of a specific map in a maps.
  • Fixing JavaScript? issue during the context destruction process.
  • Use the GetStatus? ZOO Service when it is available on the local installation for statusLocation.
  • Add some comments for ServiceStarted?, ServiceSucceeded?, ServiceFailed? and ServiceAccepted?.
  • Dynamic creation of a lenv maps in the main configuration file maps, containing the current status and a sid (Service ID). Those informations can be used later by the GetStatus? Service to let user check the on-going status during the Service runs.
  • Function updateStatus was added to service_internal.h which let the Services developers set the current percentCompleted value.

ZOO-Service updates and bug fixes :

  • Add GetStatus? Service and its demo longProcess Service. All are in the wps_status.zo Services Provider.
  • Use the setMapInMaps in the base-vect-ops code to enhance readibility.

ZOO-API updates :

  • Add the function ZOO.UpdateStatus? to the ZOO JavaScript? API which simply point on ZOOUpdateStatus which can be called as-is from JavaScript?. Use : ZOOUpdateStatus(conf,value) where conf is the main configuration file maps and value the the value of the current status.
File size: 13.8 KB
Line 
1/**
2 * Author : Gérald FENOY
3 *
4 * Copyright (c) 2009-2010 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 __cplusplus
31extern "C" {
32#endif
33
34#include <stdlib.h>
35#include <ctype.h>
36#include <stdio.h>
37#include <string.h>
38
39#define bool int
40#define true 1
41#define false -1
42
43#define SERVICE_ACCEPTED 0
44#define SERVICE_STARTED 1
45#define SERVICE_PAUSED 2
46#define SERVICE_SUCCEEDED 3
47#define SERVICE_FAILED 4
48
49#define ELEMENTS_SIZE (sizeof(char*)+(((2*sizeof(char*))+sizeof(maps*))*2)+sizeof(char*)+(((2*sizeof(char*))+sizeof(iotype*))*2)+sizeof(elements*))
50#define MAP_SIZE (2*sizeof(char*))+sizeof(NULL)
51#define IOTYPE_SIZE MAP_SIZE+sizeof(NULL)
52#define MAPS_SIZE (2*sizeof(char*))+sizeof(map*)+MAP_SIZE
53#define SERVICE_SIZE (ELEMENTS_SIZE*2)+(MAP_SIZE*2)+sizeof(char*)
54
55#define SHMSZ     27
56
57  /**
58   * \struct maps
59   * \brief linked list of map pointer
60   *
61   * Small object to store WPS KVP set.
62   */
63  typedef struct maps{
64    char* name;         
65    struct map* content; 
66    struct maps* next;   
67  } maps;
68
69  /**
70   * \struct map
71   * \brief KVP linked list
72   *
73   * Deal with WPS KVP (name,value).
74   */
75  typedef struct map{
76    char* name;       /* The key */
77    char* value;      /* The value */
78    struct map* next; /* Next couple */
79  } map;
80
81#ifdef WIN32
82#define NULLMAP ((map*) 0)
83#else
84#define NULLMAP NULL
85#endif
86
87  static void _dumpMap(map* t){
88    if(t!=NULL){
89      fprintf(stderr,"[%s] => [%s] \n",t->name,t->value);
90      fflush(stderr);
91    }else{
92      fprintf(stderr,"NULL\n");
93      fflush(stderr);
94    }
95  }
96
97  static void dumpMap(map* t){
98    map* tmp=t;
99    while(tmp!=NULL){
100      _dumpMap(tmp);
101      tmp=tmp->next;
102    }
103  }
104
105  static void dumpMaps(maps* m){
106    maps* tmp=m;
107    while(tmp!=NULL){
108      fprintf(stderr,"MAP => [%s] \n",tmp->name);
109      dumpMap(tmp->content);
110      tmp=tmp->next;
111    }
112  }
113
114  static map* createMap(const char* name,const char* value){
115    map* tmp=(map *)malloc(MAP_SIZE);
116    tmp->name=strdup(name);
117    tmp->value=strdup(value);
118    tmp->next=NULL;
119    return tmp;
120  }
121
122  static int count(map* m){
123    map* tmp=m;
124    int c=0;
125    while(tmp!=NULL){
126      c++;
127      tmp=tmp->next;
128    }
129    return c;
130  }
131   
132  static bool hasKey(map* m,const char *key){
133    map* tmp=m;
134    while(tmp!=NULL){
135      if(strncasecmp(tmp->name,key,strlen(key))==0)
136        return true;
137      tmp=tmp->next;
138    }
139#ifdef DEBUG_MAP
140    fprintf(stderr,"NOT FOUND \n");
141#endif
142    return false;
143  }
144
145  static maps* getMaps(maps* m,const char *key){
146    maps* tmp=m;
147    while(tmp!=NULL){
148      if(strncasecmp(tmp->name,key,strlen(key))==0){
149        return tmp;
150      }
151      tmp=tmp->next;
152    }
153    return NULL;
154  }
155
156  static map* getMap(map* m,const char *key){
157    map* tmp=m;
158    while(tmp!=NULL){
159      if(strncasecmp(tmp->name,key,strlen(key))==0){
160        return tmp;
161      }
162      tmp=tmp->next;
163    }
164    return NULL;
165  }
166
167  static map* getMapFromMaps(maps* m,char* key,char* subkey){
168    maps* _tmpm=getMaps(m,key);
169    if(_tmpm!=NULL){
170      map* _ztmpm=getMap(_tmpm->content,subkey);
171      return _ztmpm;
172    }
173    else return NULL;
174  }
175
176  static void freeMap(map** mo){
177    map* _cursor=*mo;
178    if(_cursor!=NULL){
179#ifdef DEBUG
180      fprintf(stderr,"freeMap\n");
181#endif
182      free(_cursor->name);
183      free(_cursor->value);
184      if(_cursor->next!=NULL){
185        freeMap(&_cursor->next);
186        free(_cursor->next);
187      }
188    }
189  }
190
191  static void freeMaps(maps** mo){
192    maps* _cursor=*mo;
193    fflush(stderr);
194    if(_cursor && _cursor!=NULL){
195#ifdef DEBUG
196      fprintf(stderr,"freeMaps\n");
197#endif
198      free(_cursor->name);
199      if(_cursor->content!=NULL){
200        freeMap(&_cursor->content);
201        free(_cursor->content);
202      }
203      if(_cursor->next!=NULL){
204        freeMaps(&_cursor->next);
205        free(_cursor->next);
206      }
207    }
208  }
209
210  typedef struct iotype{
211    struct map* content;
212    struct iotype* next;
213  } iotype;
214
215  typedef struct elements{
216    char* name;
217    struct map* content;
218    struct map* metadata;
219    char* format;
220    struct iotype* defaults;
221    struct iotype* supported;
222    struct elements* next;
223  } elements;
224
225  typedef struct service{
226    char* name;
227    struct map* content;
228    struct map* metadata;
229    struct elements* inputs;
230    struct elements* outputs; 
231  } service;
232
233  typedef struct services{
234    struct service* content; 
235    struct services* next; 
236  } services;
237
238  static bool hasElement(elements* e,char* key){
239    elements* tmp=e;
240    while(tmp!=NULL){
241      if(strncasecmp(key,tmp->name,strlen(key))==0)
242        return true;
243      tmp=tmp->next;
244    }
245    return false;
246  }
247
248  static elements* getElements(elements* m,char *key){
249    elements* tmp=m;
250    while(tmp!=NULL){
251      if(strncasecmp(tmp->name,key,strlen(tmp->name))==0)
252        return tmp;
253      tmp=tmp->next;
254    }
255    return NULL;
256  }
257
258
259  static void freeIOType(iotype** i){
260    iotype* _cursor=*i;
261    if(_cursor!=NULL){
262      freeMap(&_cursor->content);
263      free(_cursor->content);
264      if(_cursor->next!=NULL){
265        freeIOType(&_cursor->next);
266        free(_cursor->next);
267      }
268    }
269  }
270
271  static void freeElements(elements** e){
272    elements* tmp=*e;
273    if(tmp!=NULL){
274      free(tmp->name);
275      freeMap(&tmp->content);
276      free(tmp->content);
277      freeMap(&tmp->metadata);
278      free(tmp->metadata);
279      free(tmp->format);
280      freeIOType(&tmp->defaults);
281      if(tmp->defaults!=NULL)
282        free(tmp->defaults);
283      freeIOType(&tmp->supported);
284      if(tmp->supported!=NULL)
285        free(tmp->supported);
286      freeElements(&tmp->next);
287    }
288  }
289
290  static void freeService(service** s){
291    service* tmp=*s;
292    if(tmp!=NULL){
293      if(tmp->name!=NULL)
294        free(tmp->name);
295      freeMap(&tmp->content);
296      if(tmp->content!=NULL)
297        free(tmp->content);
298      freeMap(&tmp->metadata);
299      if(tmp->metadata!=NULL)
300        free(tmp->metadata);
301      freeElements(&tmp->inputs);
302      if(tmp->inputs!=NULL)
303        free(tmp->inputs);
304      freeElements(&tmp->outputs);
305      if(tmp->outputs!=NULL)
306        free(tmp->outputs);
307    }
308  }
309
310  static void addToMap(map* m,const char* n,const char* v){
311    if(hasKey(m,n)==false){
312      map* _cursor=m;
313      while(_cursor->next!=NULL)
314        _cursor=_cursor->next;
315      _cursor->next=createMap(n,v);
316    }
317    else{
318      map *tmp=getMap(m,n);
319      if(tmp->value!=NULL)
320        free(tmp->value);
321      tmp->value=strdup(v);
322    }
323  }
324
325  static void addMapToMap(map** mo,map* mi){
326    map* tmp=mi;
327    map* _cursor=*mo;
328    if(tmp==NULL){
329      if(_cursor!=NULL){
330        while(_cursor!=NULL)
331          _cursor=_cursor->next;
332        _cursor=NULL;
333      }else
334        *mo=NULL;
335    }
336    while(tmp!=NULL){
337      if(_cursor==NULL){
338        if(*mo==NULL)
339          *mo=createMap(tmp->name,tmp->value);
340        else
341          addToMap(*mo,tmp->name,tmp->value);
342      }
343      else{
344#ifdef DEBUG
345        fprintf(stderr,"_CURSOR\n");
346        dumpMap(_cursor);
347#endif
348        while(_cursor!=NULL)
349          _cursor=_cursor->next;
350        _cursor=createMap(tmp->name,tmp->value);
351        _cursor->next=NULL;
352      }
353      tmp=tmp->next;
354#ifdef DEBUG
355      fprintf(stderr,"MO\n");
356      dumpMap(*mo);
357#endif
358    }
359  }
360
361  static void addMapToIoType(iotype** io,map* mi){
362    iotype* tmp=*io;
363    while(tmp!=NULL){
364#ifdef DEBUG
365      fprintf(stderr,">> CURRENT MAP");
366      dumpMap(tmp->content);
367#endif
368      tmp=tmp->next;
369    }
370#ifdef DEBUG
371    fprintf(stderr,">> %s %i\n",__FILE__,__LINE__);
372    fflush(stderr);
373#endif
374    tmp=(iotype*)malloc(IOTYPE_SIZE);
375#ifdef DEBUG
376    fprintf(stderr,">> %s %i\n",__FILE__,__LINE__);
377    fflush(stderr);
378#endif
379    tmp->content=NULL;
380#ifdef DEBUG
381    fprintf(stderr,">> %s %i\n",__FILE__,__LINE__);
382    fflush(stderr);
383#endif
384    addMapToMap(&tmp->content,mi);
385#ifdef DEBUG
386    fprintf(stderr,">> %s %i\n",__FILE__,__LINE__);
387    fflush(stderr);
388#endif
389    dumpMap(tmp->content);
390    tmp->next=NULL;
391  }
392
393
394  static maps* dupMaps(maps** mo){
395    maps* _cursor=*mo;
396    maps* res=NULL;
397    if(_cursor!=NULL){
398      res=(maps*)malloc(MAPS_SIZE);
399      res->name=strdup(_cursor->name);
400      res->content=NULL;
401      res->next=NULL;
402      map* mc=_cursor->content;
403      if(mc!=NULL){
404        addMapToMap(&res->content,mc);
405      }
406      res->next=dupMaps(&_cursor->next);
407    }
408    return res;
409  }
410
411  static void addMapsToMaps(maps** mo,maps* mi){
412    maps* tmp=mi;
413    maps* _cursor=*mo;
414    while(tmp!=NULL){
415      if(_cursor==NULL){
416        *mo=dupMaps(&mi);
417        (*mo)->next=NULL;
418      }
419      else{
420        while(_cursor->next!=NULL)
421          _cursor=_cursor->next;
422        _cursor->next=dupMaps(&tmp);
423      }
424      tmp=tmp->next;
425    }
426  }
427
428
429  static void* setMapInMaps(maps* m,char* key,char* subkey,char *value){
430    maps* _tmpm=getMaps(m,key);
431    if(_tmpm!=NULL){
432      map* _ztmpm=getMap(_tmpm->content,subkey);
433      if(_ztmpm!=NULL){
434        free(_ztmpm->value);
435        _ztmpm->value=strdup(value);
436        dumpMap(_ztmpm);
437      }else{
438        addToMap(_tmpm->content,subkey,value);
439      }
440    }
441  }
442
443
444  static void dumpElements(elements* e){
445    elements* tmp=e;
446    while(tmp!=NULL){
447      fprintf(stderr,"ELEMENT [%s]\n",tmp->name);
448      fprintf(stderr," > CONTENT [%s]\n",tmp->name);
449      dumpMap(tmp->content);
450      fprintf(stderr," > METADATA [%s]\n",tmp->name);
451      dumpMap(tmp->metadata);
452      fprintf(stderr," > FORMAT [%s]\n",tmp->format);
453      iotype* tmpio=tmp->defaults;
454      int ioc=0;
455      while(tmpio!=NULL){
456        fprintf(stderr," > DEFAULTS [%s] (%i)\n",tmp->name,ioc);
457        dumpMap(tmpio->content);
458        tmpio=tmpio->next;
459        ioc++;
460      }
461      tmpio=tmp->supported;
462      ioc=0;
463      while(tmpio!=NULL){
464        fprintf(stderr," > SUPPORTED [%s] (%i)\n",tmp->name,ioc);
465        dumpMap(tmpio->content);
466        tmpio=tmpio->next;
467        ioc++;
468      }
469      fprintf(stderr,"------------------\n");
470      tmp=tmp->next;
471    }
472  }
473
474  static elements* dupElements(elements* e){
475    elements* cursor=e;
476    elements* tmp=NULL;
477    if(cursor!=NULL){
478#ifdef DEBUG
479      fprintf(stderr,">> %s %i\n",__FILE__,__LINE__);
480      dumpElements(e);
481      fprintf(stderr,">> %s %i\n",__FILE__,__LINE__);
482#endif
483      tmp=(elements*)malloc(ELEMENTS_SIZE);
484      tmp->name=strdup(e->name);
485      tmp->content=NULL;
486      addMapToMap(&tmp->content,e->content);
487      tmp->metadata=NULL;
488      addMapToMap(&tmp->metadata,e->metadata);
489      tmp->format=strdup(e->format);
490      if(e->defaults!=NULL){
491        tmp->defaults=(iotype*)malloc(IOTYPE_SIZE);
492        tmp->defaults->content=NULL;
493        addMapToMap(&tmp->defaults->content,e->defaults->content);
494        tmp->defaults->next=NULL;
495#ifdef DEBUG
496        fprintf(stderr,">> %s %i\n",__FILE__,__LINE__);
497        dumpMap(tmp->defaults->content);
498#endif
499      }else
500        tmp->defaults=NULL;
501      if(e->supported!=NULL){
502        tmp->supported=(iotype*)malloc(IOTYPE_SIZE);
503        tmp->supported->content=NULL;
504        tmp->supported->next=NULL;
505        addMapToMap(&tmp->supported->content,e->supported->content);
506        iotype *etmp=*(&tmp->supported->next) ;
507        iotype *tmp2=e->supported->next;
508        while(tmp2!=NULL){
509          etmp=(iotype*)malloc(IOTYPE_SIZE);
510          etmp->content=NULL;
511          addMapToMap(&etmp->content,tmp2->content);
512          etmp->next=NULL;
513#ifdef DEBUG
514          fprintf(stderr,">> %s %i\n",__FILE__,__LINE__);
515          dumpMap(tmp->defaults->content);
516#endif
517          tmp2=tmp2->next;
518          etmp=etmp->next;
519        }
520      }
521      else
522        tmp->supported=NULL;
523      tmp->next=dupElements(cursor->next);
524    }
525    return tmp;
526  }
527
528  static void addToElements(elements** m,elements* e){
529    elements* _cursor=*m;
530    elements* tmp=e;
531    if(_cursor==NULL){
532      *m=dupElements(tmp);
533    }else{
534      while(_cursor->next!=NULL)
535        _cursor=_cursor->next;
536      _cursor->next=dupElements(tmp);
537    }
538  }
539
540  static void dumpService(service* s){
541    fprintf(stderr,"++++++++++++++++++\nSERVICE [%s]\n++++++++++++++++++\n",s->name);
542    if(s->content!=NULL){
543      fprintf(stderr,"CONTENT MAP\n");
544      dumpMap(s->content);
545      fprintf(stderr,"CONTENT METADATA\n");
546      dumpMap(s->metadata);
547    }
548    if(s->inputs!=NULL){
549      fprintf(stderr,"INPUT ELEMENTS [%s]\n------------------\n",s->name);
550      dumpElements(s->inputs);
551    }
552    if(s->outputs!=NULL){
553      fprintf(stderr,"OUTPUT ELEMENTS [%s]\n------------------\n",s->name);
554      dumpElements(s->outputs);
555    }
556    fprintf(stderr,"++++++++++++++++++\n");
557  }
558
559  static void mapsToCharXXX(maps* m,char*** c){
560    maps* tm=m;
561    int i=0;
562    int j=0;
563    char tmp[10][30][1024];
564    memset(tmp,0,1024*10*10);
565    while(tm!=NULL){
566      if(i>=10)
567        break;
568      strcpy(tmp[i][j],"name");
569      j++;
570      strcpy(tmp[i][j],tm->name);
571      j++;
572      map* tc=tm->content;
573      while(tc!=NULL){
574        if(j>=30)
575          break;
576        strcpy(tmp[i][j],tc->name);
577        j++;
578        strcpy(tmp[i][j],tc->value);
579        j++;
580        tc=tc->next;
581      }
582      tm=tm->next;
583      j=0;
584      i++;
585    }
586    memcpy(c,tmp,10*10*1024);
587  }
588
589  static void charxxxToMaps(char*** c,maps**m){
590    maps* trorf=*m;
591    int i,j;
592    char tmp[10][30][1024];
593    memcpy(tmp,c,10*30*1024);
594    for(i=0;i<10;i++){
595      if(strlen(tmp[i][1])==0)
596        break;
597      trorf->name=tmp[i][1];
598      trorf->content=NULL;
599      trorf->next=NULL;
600      for(j=2;j<29;j+=2){
601        if(strlen(tmp[i][j+1])==0)
602          break;
603        if(trorf->content==NULL)
604          trorf->content=createMap(tmp[i][j],tmp[i][j+1]);
605        else
606          addToMap(trorf->content,tmp[i][j],tmp[i][j+1]);
607      }
608      trorf=trorf->next;
609    }
610    m=&trorf;
611  }
612
613#ifdef __cplusplus
614}
615#endif
616
617#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