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

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

Merge prototype-v0 branch in trunk

  • Property svn:eol-style set to native
  • Property svn:mime-type set to text/x-chdr
File size: 14.9 KB
Line 
1/*
2 * Author : Gérald FENOY
3 *
4 * Copyright (c) 2009-2019 GeoLabs SARL
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
30#ifdef WIN32
31#define ZOO_DLL_EXPORT __declspec( dllexport )
32#else
33#define ZOO_DLL_EXPORT
34#endif
35
36 // knut: add bool if necessary
37#ifndef __cplusplus
38#ifndef WIN32
39#include <stdbool.h>
40#else
41typedef int bool;
42#define false 0
43#define true 1 
44#endif
45#endif
46#ifndef __bool_true_false_are_defined
47#define __bool_true_false_are_defined 1
48#endif
49
50#ifdef WIN32
51#define strtok_r strtok_s
52#define strncasecmp _strnicmp
53#define strcasecmp _stricmp
54#if defined(_MSC_VER) && _MSC_VER < 1900
55#define snprintf _snprintf
56#endif
57#define zStrdup _strdup
58#define zMkdir _mkdir
59#define zGetpid _getpid
60#define zOpen _open
61#define zClose _close
62#define zUnlink _unlink
63#define zDup _dup
64#define zDup2 _dup2
65#define zWrite _write
66#define zSleep Sleep
67#include <sys/timeb.h>
68struct ztimeval {
69  long tv_sec; /* seconds */
70  long tv_usec; /* and microseconds */
71};
72static int zGettimeofday(struct ztimeval* tp, void* tzp)
73{
74  if (tp == 0) {
75    return -1;
76  }
77 
78  struct _timeb theTime;
79  _ftime(&theTime);
80  tp->tv_sec = theTime.time;
81  tp->tv_usec = theTime.millitm * 1000;
82 
83  return 0; // The gettimeofday() function shall return 0 on success
84}
85
86#define zStatStruct struct _stati64
87#define zStat _stati64
88
89#else
90/**
91 * The crossplatform strdup alias
92 */
93#define zStrdup strdup
94/**
95 * The crossplatform mkdir alias
96 */
97#define zMkdir mkdir
98/**
99 * The crossplatform open alias
100 */
101#define zOpen open
102/**
103 * The crossplatform close alias
104 */
105#define zClose close
106/**
107 * The crossplatform unlink alias
108 */
109#define zUnlink unlink
110/**
111 * The crossplatform dup alias
112 */
113#define zDup dup
114/**
115 * The crossplatform dup2 alias
116 */
117#define zDup2 dup2
118/**
119 * The crossplatform write alias
120 */
121#define zWrite write
122#include "unistd.h"
123/**
124 * The crossplatform sleep alias
125 */
126static int zSleep(const long millisecond){
127  return usleep(millisecond*1000);
128}
129/**
130 * The crossplatform gettimeofday alias
131 */
132#define zGettimeofday gettimeofday
133/**
134 * The crossplatform timeval alias
135 */
136#define ztimeval timeval
137/**
138 * The crossplatform getpid alias
139 */
140#define zGetpid getpid
141
142#define zStatStruct struct stat64
143#define zStat stat64
144
145#endif
146
147#ifdef __cplusplus
148extern "C" {
149#endif
150
151#ifdef WIN32
152#ifdef USE_MS
153#include <mapserver.h>
154#endif
155#endif
156#include <stdlib.h>
157#include <ctype.h>
158
159#include <stdio.h>
160
161#include <string.h>
162#ifndef WIN32
163#include <ctype.h>
164#include <stdbool.h>
165#endif
166
167/**
168 * The global accepted status for a service
169 */
170#define SERVICE_ACCEPTED 0
171/**
172 * The global started status for a service
173 */
174#define SERVICE_STARTED 1
175/**
176 * The global paused status for a service
177 */
178#define SERVICE_PAUSED 2
179/**
180 * The global succeeded status for a service
181 */
182#define SERVICE_SUCCEEDED 3
183/**
184 * The global failed status for a service
185 */
186#define SERVICE_FAILED 4
187
188/**
189 * The memory size to create an elements
190 */
191#define ELEMENTS_SIZE (sizeof(char*)+(((2*sizeof(char*))+sizeof(maps*))*3)+sizeof(char*)+((sizeof(map*) + sizeof(iotype*))*2)+(2*sizeof(elements*)))
192/**
193 * The memory size to create a map
194 */
195//#define MAP_SIZE (2*sizeof(char*))+sizeof(NULL) // knut: size of NULL pointer may be different from regular pointer (platform dependent)
196#define MAP_SIZE (2*sizeof(char*))+sizeof(map*)
197/**
198 * The memory size to create an iotype
199 */
200//#define IOTYPE_SIZE MAP_SIZE+sizeof(NULL)
201#define IOTYPE_SIZE sizeof(map*) + sizeof(iotype*)
202/**
203 * The memory size to create a maps
204 */
205//#define MAPS_SIZE (2*sizeof(char*))+sizeof(map*)+MAP_SIZE
206#define MAPS_SIZE sizeof(char*)+sizeof(map*)+(2*sizeof(maps*))
207/**
208 * The memory size to create a service
209 */
210//#define SERVICE_SIZE (ELEMENTS_SIZE*2)+(MAP_SIZE*2)+sizeof(char*)
211#define SERVICE_SIZE sizeof(char*) + 3*sizeof(map*) + 2*sizeof(elements*)
212/**
213 * The memory size to create a services
214 */
215//#define SERVICES_SIZE SERVICE_SIZE+sizeof(services*)
216#define SERVICES_SIZE sizeof(service*)+sizeof(services*)
217/**
218 * The memory size to create a registry
219 */
220//#define REGISTRY_SIZE SERVICES_SIZE+sizeof(char*)
221#define REGISTRY_SIZE sizeof(char*)+sizeof(services*)+sizeof(registry*)
222
223#define SHMSZ     27
224
225#include "version.h"
226
227#ifdef DEBUG_STACK
228  void debugStack(const char* file,const int line){
229    int stack;
230    fprintf(stderr,"stack %p (%s: %d) \n",&stack,file,line);
231  }
232#endif
233
234  /**
235   * KVP linked list
236   */
237  typedef struct map{
238    char* name; //!< the key
239    char* value; //!< the value
240    struct map* next; //!< the pointer to the next map if any or NULL
241  } map;
242
243#ifdef WIN32
244#define NULLMAP ((map*) 0)
245// knut: see new definition above
246//#define bool int
247//#define true 1
248//#define false 0
249#else
250#define NULLMAP NULL
251#endif
252
253  /**
254   * linked list of map pointer
255   *
256   * Small object to store WPS KVP set.
257   */
258  typedef struct maps{
259    char* name; //!< the maps name
260    struct map* content; //!< the content map
261    struct maps* child; //!< the child maps
262    struct maps* next; //!< the pointer to the next maps if any or NULL
263  } maps;
264 
265  /**
266   * Not named linked list
267   *
268   * Used to store information about formats, such as mimeType, encoding ...
269   */
270  typedef struct iotype{
271    struct map* content; //!< the content map
272    struct iotype* next; //!< the pointer to the next iotype if any or NULL
273  } iotype;
274
275  /**
276   * Metadata information about input or output.
277   *
278   * The elements are used to store metadata information defined in the ZCFG.
279   */
280  typedef struct elements{
281    char* name; //!< the name
282    struct map* content; //!< the content map
283    struct map* metadata; //!< the metadata map
284    struct map* additional_parameters; //!< the additional parameters map
285    char* format; //!< the format: LiteralData or ComplexData or BoundingBoxData
286    struct iotype* defaults; //!< the default iotype
287    struct iotype* supported; //!< the supported iotype
288    struct elements* child; //!< the pointer to the children element if any (or NULL)
289    struct elements* next; //!< the pointer to the next element if any (or NULL)
290  } elements;
291
292  /**
293   * Metadata information about a full Service.
294   */
295  typedef struct service{
296    char* name; //!< the name
297    struct map* content; //!< the content map
298    struct map* metadata; //!< the metadata map
299    struct map* additional_parameters; //!< the additional parameters map
300    struct elements* inputs; //!< the inputs elements
301    struct elements* outputs; //!< the outputs elements
302  } service;
303
304  /**
305   * Services chained list.
306   */
307  typedef struct services{
308    struct service* content; //!< the content service pointer
309    struct services* next; //!< the pointer to the next services*
310  } services;
311
312  /**
313   * Profile registry.
314   */
315  typedef struct registry{
316    char *name; //!< the name
317    struct services* content; //!< the content services pointer
318    struct registry* next; //!< the next registry pointer
319  } registry;
320
321  // knut
322  enum WPSException {
323          /*
324          * StatusOK is not a WPS exception, it is added
325          * here for convenience.
326          */
327          StatusOK,
328          /*
329          * See WPS 1.0 specification, Table 38 and Table 62.
330          */
331          MissingParameterValue,
332          InvalidParameterValue,
333          NoApplicableCode,
334          NotEnoughStorage,
335          ServerBusy,
336          FileSizeExceeded,
337          StorageNotSupported,
338          VersionNegotiationFailed,
339          /*
340          * See WPS 2.0 specification, Tables 41, 46, 48, and 50.
341          */
342          NoSuchProcess,
343          NoSuchMode,
344          NoSuchInput,
345          NoSuchOutput,
346          DataNotAccessible,
347          SizeExceeded,
348          TooManyInputs,
349          TooManyOutputs,
350          NoSuchFormat,
351          WrongInputData,
352          InternalServerError,
353          NoSuchJob,
354          ResultNotReady
355  };
356
357  static const char* const WPSExceptionCode[] = {
358        "StatusOK",
359        "MissingParameterValue",
360        "InvalidParameterValue",
361        "NoApplicableCode",
362        "NotEnoughStorage",
363        "ServerBusy",
364        "FileSizeExceeded",
365        "StorageNotSupported",
366        "VersionNegotiationFailed",
367        "NoSuchProcess",
368        "NoSuchMode",
369        "NoSuchInput",
370        "NoSuchOutput",
371        "DataNotAccessible",
372        "SizeExceeded",
373        "TooManyInputs",
374        "TooManyOutputs",
375        "NoSuchFormat",
376        "WrongInputData",
377        "InternalServerError",
378        "NoSuchJob",
379        "ResultNotReady"
380  };
381
382  static const char* const WPSExceptionText[] = {
383        "No problem detected",
384        "Operation request does not include a parameter value, and this server did not declare a default value for that parameter.",
385        "Operation request contains an invalid parameter value.",
386        "No other exceptionCode specified by this service and server applies to this exception.",
387        "The server does not have enough space available to store the inputs and outputs associated with the request.",
388        "The server is too busy to accept and queue the request at this time.",
389        "The file size of one of the input parameters was too large for this process to handle.",
390        "Execute operation request included transmission=”reference” for one of the outputs, but storage is not offered by this server.",
391        "Service version for a ComplexData xlink:href input was not supported by the referenced server, and version negotiation failed.",
392        "One of the identifiers passed does not match with any of the processes offered by this server.",
393        "The process does not permit the desired execution mode.",
394        "One or more of the input identifiers passed does not match with any of the input identifiers of this process.",
395        "One or more of the output identifiers passed does not match with any of the input identifiers of this process.",
396        "One of the referenced input data sets was inaccessible.",
397        "The size of one of the input parameters was too large for this process to handle.",
398        "Too many input items have been specified.",
399        "Too many output items have been specified.",
400        "One or more of the input or output formats specified in the request did not match with any of the formats defined for that particular input or output.",
401        "One or more of inputs for which the service was able to retrieve the data but could not read it.",
402        "",
403        "The JobID from the request does not match any of the Jobs running on this server.",
404        "The result for the requested JobID has not yet been generated."
405  };
406
407  ZOO_DLL_EXPORT void _dumpMap(map*);
408  ZOO_DLL_EXPORT void dumpMap(map*);
409  ZOO_DLL_EXPORT void dumpMaps(maps* m);
410  ZOO_DLL_EXPORT void dumpMapToFile(map*,FILE*); // (used only internally)
411  ZOO_DLL_EXPORT void dumpMapsToFile(maps*,char*,int);
412  ZOO_DLL_EXPORT map* createMap(const char*,const char*);
413  ZOO_DLL_EXPORT maps* createMaps(const char*);
414  ZOO_DLL_EXPORT int count(map*);
415  ZOO_DLL_EXPORT bool hasKey(map*,const char*);
416  ZOO_DLL_EXPORT maps* getMaps(maps*,const char*);
417  ZOO_DLL_EXPORT map* getMap(map*,const char*);
418  ZOO_DLL_EXPORT map* getLastMap(map*);
419  ZOO_DLL_EXPORT map* getMapFromMaps(maps*,const char*,const char*);
420  ZOO_DLL_EXPORT void freeMap(map**);
421  ZOO_DLL_EXPORT void freeMaps(maps** mo);
422  ZOO_DLL_EXPORT iotype* createIoType();
423  ZOO_DLL_EXPORT elements* createEmptyElements();
424  ZOO_DLL_EXPORT elements* createElements(const char*);
425  ZOO_DLL_EXPORT void setElementsName(elements**,char*);
426  ZOO_DLL_EXPORT bool hasElement(elements*,const char*);
427  ZOO_DLL_EXPORT elements* getElements(elements*,char*);
428  ZOO_DLL_EXPORT void freeIOType(iotype**);
429  ZOO_DLL_EXPORT void freeElements(elements**);
430  ZOO_DLL_EXPORT void setServiceName(service**,char*);
431  ZOO_DLL_EXPORT service* createService();
432  ZOO_DLL_EXPORT void freeService(service**);
433  ZOO_DLL_EXPORT void addToMap(map*,const char*,const char*);
434  ZOO_DLL_EXPORT void addIntToMap(map*,const char*,const int);
435  ZOO_DLL_EXPORT void addIntToMapArray(map*,const char*,int,const int);
436  ZOO_DLL_EXPORT map* addToMapWithSize(map*,const char*,const char*,int);
437  ZOO_DLL_EXPORT void addMapToMap(map**,map*);
438  ZOO_DLL_EXPORT void addMapToIoType(iotype**,map*);
439  ZOO_DLL_EXPORT map* getMapOrFill(map**,const char*,const char*);
440  ZOO_DLL_EXPORT bool contains(map*,map*);
441  ZOO_DLL_EXPORT iotype* getIoTypeFromElement(elements*,char*, map*);
442  ZOO_DLL_EXPORT void loadMapBinary(map**,map*,int);
443  ZOO_DLL_EXPORT void loadMapBinaries(map**,map*);
444  ZOO_DLL_EXPORT maps* dupMaps(maps**);
445  ZOO_DLL_EXPORT void addMapsToMaps(maps**,maps*);
446  ZOO_DLL_EXPORT map* getMapArray(map*,const char*,int);
447  ZOO_DLL_EXPORT void setMapArray(map*,const char*,int,const char*);
448  ZOO_DLL_EXPORT map* getMapType(map*);
449  ZOO_DLL_EXPORT int addMapsArrayToMaps(maps**,maps*,char*);
450  ZOO_DLL_EXPORT void setMapInMaps(maps*,const char*,const char*,const char*);
451  ZOO_DLL_EXPORT void dumpElements(elements*);
452  ZOO_DLL_EXPORT void dumpElementsAsYAML(elements*,int);
453  ZOO_DLL_EXPORT elements* dupElements(elements*);
454  ZOO_DLL_EXPORT void addToElements(elements**,elements*);
455  ZOO_DLL_EXPORT void dumpService(service*);
456  ZOO_DLL_EXPORT void dumpServiceAsYAML(service*);
457  ZOO_DLL_EXPORT service* dupService(service*);
458  ZOO_DLL_EXPORT void dumpRegistry(registry*);
459  ZOO_DLL_EXPORT bool addServiceToRegistry(registry**,char*,service*);
460  ZOO_DLL_EXPORT void freeRegistry(registry**);
461  ZOO_DLL_EXPORT service* getServiceFromRegistry(registry*,char*,char*);
462  ZOO_DLL_EXPORT void inheritMap(map**,map*);
463  ZOO_DLL_EXPORT void inheritIOType(iotype**,iotype*);
464  ZOO_DLL_EXPORT void inheritElements(elements**,elements*);
465  ZOO_DLL_EXPORT void inheritance(registry*,service**);
466  ZOO_DLL_EXPORT void mapsToCharXXX(maps*,char***);
467  ZOO_DLL_EXPORT void charxxxToMaps(char***,maps**);
468#if defined(_MSC_VER) && _MSC_VER < 1800
469  // snprintf for Visual Studio compiler;
470  // it is also used by services (e.g., GetStatus), therefore exported to shared library
471  ZOO_DLL_EXPORT int snprintf(char *buffer, size_t n, const char *format, ...);
472#endif
473
474  // knut: some new utility functions; logMessage is primarily intended for debugging   
475  ZOO_DLL_EXPORT bool nonempty(map* map);
476  ZOO_DLL_EXPORT bool hasvalue(maps* source, const char* node, const char* key, map** kvp);
477#ifdef __cplusplus
478  ZOO_DLL_EXPORT void setErrorMessage(maps*& conf, const char* service, WPSException exc, const char* message = NULL);
479  ZOO_DLL_EXPORT void logMessage(const char* source, const char* function, int line, const char* file = NULL, const char* message = NULL);
480#endif
481  #define zooLogMsg(file,message) logMessage(__FILE__, __func__, __LINE__, (file), (message))
482  #define zooLog logMessage(__FILE__, __func__, __LINE__) 
483
484#ifdef __cplusplus
485}
486#endif
487
488#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