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

Last change on this file since 881 was 881, checked in by djay, 6 years ago

Make sure to initialize properly every field of a service.

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