source: branches/prototype-v0/zoo-project/zoo-kernel/service.h @ 890

Last change on this file since 890 was 890, checked in by djay, 5 years ago

Make this ZOO-Kernel working properly on windows platform again.

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