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

Last change on this file since 840 was 840, checked in by jmckenna, 7 years ago

handle missing bool on Windows

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