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

Last change on this file since 653 was 640, checked in by djay, 9 years ago

First version including zoo_service shared library

  • Property svn:eol-style set to native
  • Property svn:mime-type set to text/x-chdr
File size: 8.3 KB
Line 
1/*
2 * Author : Gérald FENOY
3 *
4 * Copyright (c) 2009-2015 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#ifndef USE_MS
32#define strncasecmp _strnicmp
33#define strcasecmp _stricmp
34#endif
35#ifndef snprintf
36#define snprintf sprintf_s
37#endif
38#define zStrdup _strdup
39#define zMkdir _mkdir
40#define zOpen _open
41#define zWrite _write
42#define zSleep Sleep
43#include <sys/timeb.h>
44struct ztimeval {
45  long tv_sec; /* seconds */
46  long tv_usec; /* and microseconds */
47};
48static int zGettimeofday(struct ztimeval* tp, void* tzp)
49{
50  if (tp == 0) {
51    return -1;
52  }
53 
54  struct _timeb theTime;
55  _ftime(&theTime);
56  tp->tv_sec = theTime.time;
57  tp->tv_usec = theTime.millitm * 1000;
58 
59  return 0; // The gettimeofday() function shall return 0 on success
60}
61#else
62/**
63 * The crossplatform strdup alias
64 */
65#define zStrdup strdup
66/**
67 * The crossplatform mkdir alias
68 */
69#define zMkdir mkdir
70/**
71 * The crossplatform open alias
72 */
73#define zOpen open
74/**
75 * The crossplatform write alias
76 */
77#define zWrite write
78/**
79 * The crossplatform sleep alias
80 */
81#define zSleep sleep
82/**
83 * The crossplatform gettimeofday alias
84 */
85#define zGettimeofday gettimeofday
86/**
87 * The crossplatform timeval alias
88 */
89#define ztimeval timeval
90#endif
91
92#ifdef __cplusplus
93extern "C" {
94#endif
95
96#ifdef WIN32
97#ifdef USE_MS
98#include <mapserver.h>
99#endif
100#endif
101#include <stdlib.h>
102#include <ctype.h>
103#include <stdio.h>
104#include <string.h>
105#ifndef WIN32
106#include <ctype.h>
107#ifndef bool
108#define bool int
109#endif
110#ifndef true
111  /**
112   * Local true definition
113   */
114#define true 1
115  /**
116   * Local false definition
117   */
118#define false 0
119#endif
120#endif
121
122/**
123 * The global accepted status for a service
124 */
125#define SERVICE_ACCEPTED 0
126/**
127 * The global started status for a service
128 */
129#define SERVICE_STARTED 1
130/**
131 * The global paused status for a service
132 */
133#define SERVICE_PAUSED 2
134/**
135 * The global succeeded status for a service
136 */
137#define SERVICE_SUCCEEDED 3
138/**
139 * The global failed status for a service
140 */
141#define SERVICE_FAILED 4
142
143/**
144 * The memory size to create an elements
145 */
146#define ELEMENTS_SIZE (sizeof(char*)+(((2*sizeof(char*))+sizeof(maps*))*2)+sizeof(char*)+(((2*sizeof(char*))+sizeof(iotype*))*2)+(2*sizeof(elements*)))
147/**
148 * The memory size to create a map
149 */
150#define MAP_SIZE (2*sizeof(char*))+sizeof(NULL)
151/**
152 * The memory size to create an iotype
153 */
154#define IOTYPE_SIZE MAP_SIZE+sizeof(NULL)
155/**
156 * The memory size to create a maps
157 */
158#define MAPS_SIZE (2*sizeof(char*))+sizeof(map*)+MAP_SIZE
159/**
160 * The memory size to create a service
161 */
162#define SERVICE_SIZE (ELEMENTS_SIZE*2)+(MAP_SIZE*2)+sizeof(char*)
163/**
164 * The memory size to create a services
165 */
166#define SERVICES_SIZE SERVICE_SIZE+sizeof(services*)
167/**
168 * The memory size to create a registry
169 */
170#define REGISTRY_SIZE SERVICES_SIZE+sizeof(char*)
171
172#define SHMSZ     27
173
174#include "version.h"
175
176#ifdef DEBUG_STACK
177  void debugStack(const char* file,const int line){
178    int stack;
179    fprintf(stderr,"stack %p (%s: %d) \n",&stack,file,line);
180  }
181#endif
182
183  /**
184   * KVP linked list
185   */
186  typedef struct map{
187    char* name; //!< the key
188    char* value; //!< the value
189    struct map* next; //!< the pointer to the next map if any or NULL
190  } map;
191
192#ifdef WIN32
193#define NULLMAP ((map*) 0)
194#else
195#define NULLMAP NULL
196#endif
197
198  /**
199   * linked list of map pointer
200   *
201   * Small object to store WPS KVP set.
202   */
203  typedef struct maps{
204    char* name; //!< the maps name
205    struct map* content; //!< the content map
206    struct maps* next; //!< the pointer to the next maps if any or NULL
207  } maps;
208 
209  /**
210   * Not named linked list
211   *
212   * Used to store informations about formats, such as mimeType, encoding ...
213   */
214  typedef struct iotype{
215    struct map* content; //!< the content map
216    struct iotype* next; //!< the pointer to the next iotype if any or NULL
217  } iotype;
218
219  /**
220   * Metadata information about input or output.
221   *
222   * The elements are used to store metadata informations defined in the ZCFG.
223   */
224  typedef struct elements{
225    char* name; //!< the name
226    struct map* content; //!< the content map
227    struct map* metadata; //!< the metadata map
228    char* format; //!< the format: LiteralData or ComplexData or BoundingBoxData
229    struct iotype* defaults; //!< the default iotype
230    struct iotype* supported; //!< the supported iotype
231    struct elements* child; //!< the pointer to the children element if any (or NULL)
232    struct elements* next; //!< the pointer to the next element if any (or NULL)
233  } elements;
234
235  /**
236   * Metadata informations about a full Service.
237   */
238  typedef struct service{
239    char* name; //!< the name
240    struct map* content; //!< the content map
241    struct map* metadata; //!< the metadata map
242    struct elements* inputs; //!< the inputs elements
243    struct elements* outputs; //!< the outputs elements
244  } service;
245
246  /**
247   * Services chained list.
248   */
249  typedef struct services{
250    struct service* content; //!< the content service pointer
251    struct services* next; //!< the pointer to the next services*
252  } services;
253
254  /**
255   * Profile registry.
256   */
257  typedef struct registry{
258    char *name; //!< the name
259    struct services* content; //!< the content services pointer
260    struct registry* next; //!< the next registry pointer
261  } registry;
262
263
264  void _dumpMap(map*);
265  void dumpMap(map*);
266  void dumpMapToFile(map*,FILE*);
267  void dumpMaps(maps* m);
268  void dumpMapsToFile(maps*,char*);
269  map* createMap(const char*,const char*);
270  int count(map*);
271  bool hasKey(map*,const char*);
272  maps* getMaps(maps*,const char*);
273  map* getMap(map*,const char*);
274  map* getLastMap(map*);
275  map* getMapFromMaps(maps*,const char*,const char*);
276  void freeMap(map**);
277  void freeMaps(maps** mo);
278 
279
280  bool hasElement(elements*,const char*);
281  elements* getElements(elements*,char*);
282  void freeIOType(iotype**);
283  void freeElements(elements**);
284  void freeService(service**);
285  void addToMap(map*,const char*,const char*);
286  void addIntToMap(map*,const char*,const int);
287  void addToMapWithSize(map*,const char*,const char*,int);
288  void addMapToMap(map**,map*);
289  void addMapToIoType(iotype**,map*);
290  map* getMapOrFill(map**,const char*,const char*);
291  bool contains(map*,map*);
292  iotype* getIoTypeFromElement(elements*,char*, map*);
293  void loadMapBinary(map**,map*,int);
294  void loadMapBinaries(map**,map*);
295  maps* dupMaps(maps**);
296  void addMapsToMaps(maps**,maps*);
297  map* getMapArray(map*,const char*,int);
298  void setMapArray(map*,const char*,int,const char*);
299  map* getMapType(map*);
300  int addMapsArrayToMaps(maps**,maps*,char*);
301  void setMapInMaps(maps*,const char*,const char*,const char*);
302  void dumpElements(elements*);
303  void dumpElementsAsYAML(elements*);
304  elements* dupElements(elements*);
305  void addToElements(elements**,elements*);
306  void dumpService(service*);
307  void dumpServiceAsYAML(service*);
308  service* dupService(service*);
309  void dumpRegistry(registry*);
310  bool addServiceToRegistry(registry**,char*,service*);
311  void freeRegistry(registry**);
312  service* getServiceFromRegistry(registry*,char*,char*);
313  void inheritMap(map**,map*);
314  void inheritIOType(iotype**,iotype*);
315  void inheritElements(elements**,elements*);
316  void inheritance(registry*,service**);
317  void mapsToCharXXX(maps*,char***);
318  void charxxxToMaps(char***,maps**);
319#ifdef WIN32
320  extern char *url_encode(char *);
321  char* getMapsAsKVP(maps*,int,int);
322#endif
323
324#ifdef __cplusplus
325}
326#endif
327
328#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