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

Last change on this file since 756 was 738, checked in by knut, 9 years ago

Redefined the API function addToMapWithSize to fix problem with Python/PHP support. Added some variable initializations and NULL pointer checks.

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