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

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

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