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

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

handle strcasestr for MapServer? support

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