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

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

Add status_code key to the lenv section to support returning a specific HTTP error code from the service code. Fix callback invocation to support inputs arrays at step 1 and 2. Fix issue with cpu usage. Fix issue with mapserver publication when an input is optional. Fix callback invocation at step 7 in case the service has failed on the HPC side.

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