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
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
[877]37#define strtok_r strtok_s
[375]38#define strncasecmp _strnicmp
39#define strcasecmp _stricmp
[757]40#if defined(_MSC_VER) && _MSC_VER < 1900
41#define snprintf _snprintf
[453]42#endif
43#define zStrdup _strdup
44#define zMkdir _mkdir
[890]45#define zGetpid _getpid
[453]46#define zOpen _open
[890]47#define zClose _close
48#define zUnlink _unlink
49#define zDup _dup
50#define zDup2 _dup2
[453]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{
[554]60  if (tp == 0) {
61    return -1;
62  }
63 
[514]64  struct _timeb theTime;
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
[890]72#define zStatStruct struct _stati64
73#define zStat _stati64
74
[379]75#else
[579]76/**
77 * The crossplatform strdup alias
78 */
[453]79#define zStrdup strdup
[579]80/**
81 * The crossplatform mkdir alias
82 */
[453]83#define zMkdir mkdir
[579]84/**
85 * The crossplatform open alias
86 */
[454]87#define zOpen open
[579]88/**
[890]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/**
[579]105 * The crossplatform write alias
106 */
[454]107#define zWrite write
[860]108#include "unistd.h"
[579]109/**
110 * The crossplatform sleep alias
111 */
[860]112static int zSleep(const long millisecond){
113  return usleep(millisecond*1000);
114}
[579]115/**
116 * The crossplatform gettimeofday alias
117 */
[514]118#define zGettimeofday gettimeofday
[579]119/**
120 * The crossplatform timeval alias
121 */
[514]122#define ztimeval timeval
[890]123/**
124 * The crossplatform getpid alias
125 */
126#define zGetpid getpid
127
128#define zStatStruct struct stat64
129#define zStat stat64
130
[216]131#endif
132
[1]133#ifdef __cplusplus
134extern "C" {
135#endif
136
[444]137#ifdef WIN32
138#ifdef USE_MS
139#include <mapserver.h>
140#endif
141#endif
[1]142#include <stdlib.h>
143#include <ctype.h>
[712]144
[1]145#include <stdio.h>
[712]146
[1]147#include <string.h>
[364]148#ifndef WIN32
[618]149#include <ctype.h>
[767]150#include <stdbool.h>
[490]151#endif
[9]152
[579]153/**
154 * The global accepted status for a service
155 */
[1]156#define SERVICE_ACCEPTED 0
[579]157/**
158 * The global started status for a service
159 */
[1]160#define SERVICE_STARTED 1
[579]161/**
162 * The global paused status for a service
163 */
[1]164#define SERVICE_PAUSED 2
[579]165/**
166 * The global succeeded status for a service
167 */
[1]168#define SERVICE_SUCCEEDED 3
[579]169/**
170 * The global failed status for a service
171 */
[1]172#define SERVICE_FAILED 4
[9]173
[579]174/**
175 * The memory size to create an elements
176 */
[850]177#define ELEMENTS_SIZE (sizeof(char*)+(((2*sizeof(char*))+sizeof(maps*))*3)+sizeof(char*)+((sizeof(map*) + sizeof(iotype*))*2)+(2*sizeof(elements*)))
[579]178/**
179 * The memory size to create a map
180 */
[788]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*)
[579]183/**
184 * The memory size to create an iotype
185 */
[788]186//#define IOTYPE_SIZE MAP_SIZE+sizeof(NULL)
187#define IOTYPE_SIZE sizeof(map*) + sizeof(iotype*)
[579]188/**
189 * The memory size to create a maps
190 */
[788]191//#define MAPS_SIZE (2*sizeof(char*))+sizeof(map*)+MAP_SIZE
[790]192#define MAPS_SIZE sizeof(char*)+sizeof(map*)+(2*sizeof(maps*))
[579]193/**
194 * The memory size to create a service
195 */
[788]196//#define SERVICE_SIZE (ELEMENTS_SIZE*2)+(MAP_SIZE*2)+sizeof(char*)
[839]197#define SERVICE_SIZE sizeof(char*) + 3*sizeof(map*) + 2*sizeof(elements*)
[607]198/**
199 * The memory size to create a services
200 */
[788]201//#define SERVICES_SIZE SERVICE_SIZE+sizeof(services*)
202#define SERVICES_SIZE sizeof(service*)+sizeof(services*)
[607]203/**
204 * The memory size to create a registry
205 */
[788]206//#define REGISTRY_SIZE SERVICES_SIZE+sizeof(char*)
207#define REGISTRY_SIZE sizeof(char*)+sizeof(services*)+sizeof(registry*)
[1]208
[26]209#define SHMSZ     27
[1]210
[465]211#include "version.h"
[1]212
[375]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
[9]220  /**
[579]221   * KVP linked list
[9]222   */
[1]223  typedef struct map{
[607]224    char* name; //!< the key
225    char* value; //!< the value
226    struct map* next; //!< the pointer to the next map if any or NULL
[1]227  } map;
228
229#ifdef WIN32
230#define NULLMAP ((map*) 0)
[877]231#define bool int
232#define true 1
233#define false 0
[1]234#else
235#define NULLMAP NULL
236#endif
237
[114]238  /**
[579]239   * linked list of map pointer
[114]240   *
241   * Small object to store WPS KVP set.
242   */
243  typedef struct maps{
[607]244    char* name; //!< the maps name
245    struct map* content; //!< the content map
[790]246    struct maps* child; //!< the child maps
[607]247    struct maps* next; //!< the pointer to the next maps if any or NULL
[114]248  } maps;
[601]249 
[579]250  /**
251   * Not named linked list
[114]252   *
[781]253   * Used to store information about formats, such as mimeType, encoding ...
[114]254   */
[1]255  typedef struct iotype{
[607]256    struct map* content; //!< the content map
257    struct iotype* next; //!< the pointer to the next iotype if any or NULL
[1]258  } iotype;
259
[114]260  /**
[579]261   * Metadata information about input or output.
[114]262   *
[781]263   * The elements are used to store metadata information defined in the ZCFG.
[114]264   */
[1]265  typedef struct elements{
[607]266    char* name; //!< the name
267    struct map* content; //!< the content map
268    struct map* metadata; //!< the metadata map
[839]269    struct map* additional_parameters; //!< the additional parameters map
[607]270    char* format; //!< the format: LiteralData or ComplexData or BoundingBoxData
271    struct iotype* defaults; //!< the default iotype
272    struct iotype* supported; //!< the supported iotype
[640]273    struct elements* child; //!< the pointer to the children element if any (or NULL)
[607]274    struct elements* next; //!< the pointer to the next element if any (or NULL)
[1]275  } elements;
276
[579]277  /**
[781]278   * Metadata information about a full Service.
[579]279   */
[1]280  typedef struct service{
[607]281    char* name; //!< the name
282    struct map* content; //!< the content map
283    struct map* metadata; //!< the metadata map
[839]284    struct map* additional_parameters; //!< the additional parameters map
[607]285    struct elements* inputs; //!< the inputs elements
286    struct elements* outputs; //!< the outputs elements
[1]287  } service;
288
[579]289  /**
[607]290   * Services chained list.
[579]291   */
[1]292  typedef struct services{
[607]293    struct service* content; //!< the content service pointer
294    struct services* next; //!< the pointer to the next services*
[1]295  } services;
296
[579]297  /**
[607]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
[680]306  ZOO_DLL_EXPORT void _dumpMap(map*);
307  ZOO_DLL_EXPORT void dumpMap(map*);
308  ZOO_DLL_EXPORT void dumpMaps(maps* m);
[682]309  ZOO_DLL_EXPORT void dumpMapToFile(map*,FILE*); // (used only internally)
310  ZOO_DLL_EXPORT void dumpMapsToFile(maps*,char*,int);
[680]311  ZOO_DLL_EXPORT map* createMap(const char*,const char*);
[790]312  ZOO_DLL_EXPORT maps* createMaps(const char*);
[680]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);
[839]321  ZOO_DLL_EXPORT iotype* createIoType();
[790]322  ZOO_DLL_EXPORT elements* createEmptyElements();
[822]323  ZOO_DLL_EXPORT elements* createElements(const char*);
[790]324  ZOO_DLL_EXPORT void setElementsName(elements**,char*);
[680]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**);
[790]329  ZOO_DLL_EXPORT void setServiceName(service**,char*);
[881]330  ZOO_DLL_EXPORT service* createService();
[680]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);
[877]334  ZOO_DLL_EXPORT void addIntToMapArray(map*,const char*,int,const int);
[738]335  ZOO_DLL_EXPORT map* addToMapWithSize(map*,const char*,const char*,int);
[680]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*);
[790]351  ZOO_DLL_EXPORT void dumpElementsAsYAML(elements*,int);
[680]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**);
[757]367#if defined(_MSC_VER) && _MSC_VER < 1800
[712]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, ...);
[757]371#endif
[1]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