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

Last change on this file was 962, checked in by djay, 6 weeks ago

Update OGC API - Processes documentation and implementation, providing a browsable User Interface to Processes.

  • Property svn:eol-style set to native
  • Property svn:mime-type set to text/x-chdr
File size: 15.3 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 * The global dismissed status for a service
189 */
190#define SERVICE_DISMISSED 5
191
192/**
193 * The memory size to create an elements
194 */
195#define ELEMENTS_SIZE (sizeof(char*)+(((2*sizeof(char*))+sizeof(maps*))*3)+sizeof(char*)+((sizeof(map*) + sizeof(iotype*))*2)+(2*sizeof(elements*)))
196/**
197 * The memory size to create a map
198 */
199//#define MAP_SIZE (2*sizeof(char*))+sizeof(NULL) // knut: size of NULL pointer may be different from regular pointer (platform dependent)
200#define MAP_SIZE (2*sizeof(char*))+sizeof(map*)
201/**
202 * The memory size to create an iotype
203 */
204//#define IOTYPE_SIZE MAP_SIZE+sizeof(NULL)
205#define IOTYPE_SIZE sizeof(map*) + sizeof(iotype*)
206/**
207 * The memory size to create a maps
208 */
209//#define MAPS_SIZE (2*sizeof(char*))+sizeof(map*)+MAP_SIZE
210#define MAPS_SIZE sizeof(char*)+sizeof(map*)+(2*sizeof(maps*))
211/**
212 * The memory size to create a service
213 */
214//#define SERVICE_SIZE (ELEMENTS_SIZE*2)+(MAP_SIZE*2)+sizeof(char*)
215#define SERVICE_SIZE sizeof(char*) + 3*sizeof(map*) + 2*sizeof(elements*)
216/**
217 * The memory size to create a services
218 */
219//#define SERVICES_SIZE SERVICE_SIZE+sizeof(services*)
220#define SERVICES_SIZE sizeof(service*)+sizeof(services*)
221/**
222 * The memory size to create a registry
223 */
224//#define REGISTRY_SIZE SERVICES_SIZE+sizeof(char*)
225#define REGISTRY_SIZE sizeof(char*)+sizeof(services*)+sizeof(registry*)
226
227#define SHMSZ     27
228
229#include "version.h"
230
231#ifdef DEBUG_STACK
232  void debugStack(const char* file,const int line){
233    int stack;
234    fprintf(stderr,"stack %p (%s: %d) \n",&stack,file,line);
235  }
236#endif
237
238  /**
239   * KVP linked list
240   */
241  typedef struct map{
242    char* name; //!< the key
243    char* value; //!< the value
244    struct map* next; //!< the pointer to the next map if any or NULL
245  } map;
246
247#ifdef WIN32
248#define NULLMAP ((map*) 0)
249// knut: see new definition above
250//#define bool int
251//#define true 1
252//#define false 0
253#else
254#define NULLMAP NULL
255#endif
256
257  /**
258   * linked list of map pointer
259   *
260   * Small object to store WPS KVP set.
261   */
262  typedef struct maps{
263    char* name; //!< the maps name
264    struct map* content; //!< the content map
265    struct maps* child; //!< the child maps
266    struct maps* next; //!< the pointer to the next maps if any or NULL
267  } maps;
268 
269  /**
270   * Not named linked list
271   *
272   * Used to store information about formats, such as mimeType, encoding ...
273   */
274  typedef struct iotype{
275    struct map* content; //!< the content map
276    struct iotype* next; //!< the pointer to the next iotype if any or NULL
277  } iotype;
278
279  /**
280   * Metadata information about input or output.
281   *
282   * The elements are used to store metadata information defined in the ZCFG.
283   */
284  typedef struct elements{
285    char* name; //!< the name
286    struct map* content; //!< the content map
287    struct map* metadata; //!< the metadata map
288    struct map* additional_parameters; //!< the additional parameters map
289    char* format; //!< the format: LiteralData or ComplexData or BoundingBoxData
290    struct iotype* defaults; //!< the default iotype
291    struct iotype* supported; //!< the supported iotype
292    struct elements* child; //!< the pointer to the children element if any (or NULL)
293    struct elements* next; //!< the pointer to the next element if any (or NULL)
294  } elements;
295
296  /**
297   * Metadata information about a full Service.
298   */
299  typedef struct service{
300    char* name; //!< the name
301    struct map* content; //!< the content map
302    struct map* metadata; //!< the metadata map
303    struct map* additional_parameters; //!< the additional parameters map
304    struct elements* inputs; //!< the inputs elements
305    struct elements* outputs; //!< the outputs elements
306  } service;
307
308  /**
309   * Services chained list.
310   */
311  typedef struct services{
312    struct service* content; //!< the content service pointer
313    struct services* next; //!< the pointer to the next services*
314  } services;
315
316  /**
317   * Profile registry.
318   */
319  typedef struct registry{
320    char *name; //!< the name
321    struct services* content; //!< the content services pointer
322    struct registry* next; //!< the next registry pointer
323  } registry;
324
325  // knut
326  enum WPSException {
327          /*
328          * StatusOK is not a WPS exception, it is added
329          * here for convenience.
330          */
331          StatusOK,
332          /*
333          * See WPS 1.0 specification, Table 38 and Table 62.
334          */
335          MissingParameterValue,
336          InvalidParameterValue,
337          NoApplicableCode,
338          NotEnoughStorage,
339          ServerBusy,
340          FileSizeExceeded,
341          StorageNotSupported,
342          VersionNegotiationFailed,
343          /*
344          * See WPS 2.0 specification, Tables 41, 46, 48, and 50.
345          */
346          NoSuchProcess,
347          NoSuchMode,
348          NoSuchInput,
349          NoSuchOutput,
350          DataNotAccessible,
351          SizeExceeded,
352          TooManyInputs,
353          TooManyOutputs,
354          NoSuchFormat,
355          WrongInputData,
356          InternalServerError,
357          NoSuchJob,
358          ResultNotReady
359  };
360
361  static const char* const WPSExceptionCode[] = {
362        "StatusOK",
363        "MissingParameterValue",
364        "InvalidParameterValue",
365        "NoApplicableCode",
366        "NotEnoughStorage",
367        "ServerBusy",
368        "FileSizeExceeded",
369        "StorageNotSupported",
370        "VersionNegotiationFailed",
371        "NoSuchProcess",
372        "NoSuchMode",
373        "NoSuchInput",
374        "NoSuchOutput",
375        "DataNotAccessible",
376        "SizeExceeded",
377        "TooManyInputs",
378        "TooManyOutputs",
379        "NoSuchFormat",
380        "WrongInputData",
381        "InternalServerError",
382        "NoSuchJob",
383        "ResultNotReady"
384  };
385
386  static const char* const WPSExceptionText[] = {
387        "No problem detected",
388        "Operation request does not include a parameter value, and this server did not declare a default value for that parameter.",
389        "Operation request contains an invalid parameter value.",
390        "No other exceptionCode specified by this service and server applies to this exception.",
391        "The server does not have enough space available to store the inputs and outputs associated with the request.",
392        "The server is too busy to accept and queue the request at this time.",
393        "The file size of one of the input parameters was too large for this process to handle.",
394        "Execute operation request included transmission=”reference” for one of the outputs, but storage is not offered by this server.",
395        "Service version for a ComplexData xlink:href input was not supported by the referenced server, and version negotiation failed.",
396        "One of the identifiers passed does not match with any of the processes offered by this server.",
397        "The process does not permit the desired execution mode.",
398        "One or more of the input identifiers passed does not match with any of the input identifiers of this process.",
399        "One or more of the output identifiers passed does not match with any of the input identifiers of this process.",
400        "One of the referenced input data sets was inaccessible.",
401        "The size of one of the input parameters was too large for this process to handle.",
402        "Too many input items have been specified.",
403        "Too many output items have been specified.",
404        "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.",
405        "One or more of inputs for which the service was able to retrieve the data but could not read it.",
406        "",
407        "The JobID from the request does not match any of the Jobs running on this server.",
408        "The result for the requested JobID has not yet been generated."
409  };
410
411  ZOO_DLL_EXPORT void _dumpMap(map*);
412  ZOO_DLL_EXPORT void dumpMap(map*);
413  ZOO_DLL_EXPORT void dumpMaps(maps* m);
414  ZOO_DLL_EXPORT void dumpMapToFile(map*,FILE*); // (used only internally)
415  ZOO_DLL_EXPORT void dumpMapsToFile(maps*,char*,int);
416  ZOO_DLL_EXPORT map* createMap(const char*,const char*);
417  ZOO_DLL_EXPORT maps* createMaps(const char*);
418  ZOO_DLL_EXPORT int count(map*);
419  ZOO_DLL_EXPORT bool hasKey(map*,const char*);
420  ZOO_DLL_EXPORT maps* getMaps(maps*,const char*);
421  ZOO_DLL_EXPORT map* getMap(map*,const char*);
422  ZOO_DLL_EXPORT map* getLastMap(map*);
423  ZOO_DLL_EXPORT map* getMapFromMaps(maps*,const char*,const char*);
424  ZOO_DLL_EXPORT void freeMap(map**);
425  ZOO_DLL_EXPORT void freeMaps(maps** mo);
426  ZOO_DLL_EXPORT iotype* createIoType();
427  ZOO_DLL_EXPORT elements* createEmptyElements();
428  ZOO_DLL_EXPORT elements* createElements(const char*);
429  ZOO_DLL_EXPORT void setElementsName(elements**,char*);
430  ZOO_DLL_EXPORT bool hasElement(elements*,const char*);
431  ZOO_DLL_EXPORT elements* getElements(elements*,const char*);
432  ZOO_DLL_EXPORT void freeIOType(iotype**);
433  ZOO_DLL_EXPORT void freeElements(elements**);
434  ZOO_DLL_EXPORT void setServiceName(service**,char*);
435  ZOO_DLL_EXPORT service* createService();
436  ZOO_DLL_EXPORT void freeService(service**);
437  ZOO_DLL_EXPORT void addToMap(map*,const char*,const char*);
438  ZOO_DLL_EXPORT void addIntToMap(map*,const char*,const int);
439  ZOO_DLL_EXPORT void addIntToMapArray(map*,const char*,int,const int);
440  ZOO_DLL_EXPORT map* addToMapWithSize(map*,const char*,const char*,int);
441  ZOO_DLL_EXPORT void addMapToMap(map**,map*);
442  ZOO_DLL_EXPORT void addMapToIoType(iotype**,map*);
443  ZOO_DLL_EXPORT map* getMapOrFill(map**,const char*,const char*);
444  ZOO_DLL_EXPORT bool contains(map*,map*);
445  ZOO_DLL_EXPORT iotype* getIoTypeFromElement(elements*,char*, map*);
446  ZOO_DLL_EXPORT void loadMapBinary(map**,map*,int);
447  ZOO_DLL_EXPORT void loadMapBinaries(map**,map*);
448  ZOO_DLL_EXPORT maps* dupMaps(maps**);
449  ZOO_DLL_EXPORT void addMapsToMaps(maps**,maps*);
450  ZOO_DLL_EXPORT map* getMapArray(map*,const char*,int);
451  ZOO_DLL_EXPORT void setMapArray(map*,const char*,int,const char*);
452  ZOO_DLL_EXPORT map* getMapType(map*);
453  ZOO_DLL_EXPORT int addMapsArrayToMaps(maps**,maps*,char*);
454  ZOO_DLL_EXPORT void setMapInMaps(maps*,const char*,const char*,const char*);
455  ZOO_DLL_EXPORT void dumpElements(elements*);
456  ZOO_DLL_EXPORT void dumpElementsAsYAML(elements*,int);
457  ZOO_DLL_EXPORT elements* dupElements(elements*);
458  ZOO_DLL_EXPORT void addToElements(elements**,elements*);
459  ZOO_DLL_EXPORT void dumpService(service*);
460  ZOO_DLL_EXPORT void dumpServiceAsYAML(service*);
461  ZOO_DLL_EXPORT service* dupService(service*);
462  ZOO_DLL_EXPORT void dumpRegistry(registry*);
463  ZOO_DLL_EXPORT bool addServiceToRegistry(registry**,char*,service*);
464  ZOO_DLL_EXPORT void freeRegistry(registry**);
465  ZOO_DLL_EXPORT service* getServiceFromRegistry(registry*,char*,char*);
466  ZOO_DLL_EXPORT void inheritMap(map**,map*);
467  ZOO_DLL_EXPORT void inheritIOType(iotype**,iotype*);
468  ZOO_DLL_EXPORT void inheritElements(elements**,elements*);
469  ZOO_DLL_EXPORT void inheritance(registry*,service**);
470  ZOO_DLL_EXPORT void mapsToCharXXX(maps*,char***);
471  ZOO_DLL_EXPORT void charxxxToMaps(char***,maps**);
472#if defined(_MSC_VER) && _MSC_VER < 1800
473  // snprintf for Visual Studio compiler;
474  // it is also used by services (e.g., GetStatus), therefore exported to shared library
475  ZOO_DLL_EXPORT int snprintf(char *buffer, size_t n, const char *format, ...);
476#endif
477
478  // knut: some new utility functions; logMessage is primarily intended for debugging   
479  ZOO_DLL_EXPORT bool nonempty(map* map);
480  ZOO_DLL_EXPORT bool hasvalue(maps* source, const char* node, const char* key, map** kvp);
481#ifdef __cplusplus
482  ZOO_DLL_EXPORT void setErrorMessage(maps*& conf, const char* service, WPSException exc, const char* message = NULL);
483  ZOO_DLL_EXPORT void logMessage(const char* source, const char* function, int line, const char* file = NULL, const char* message = NULL);
484#endif
485  #define zooLogMsg(file,message) logMessage(__FILE__, __func__, __LINE__, (file), (message))
486  #define zooLog logMessage(__FILE__, __func__, __LINE__) 
487 
488  // knut : function for pre-allocated memory for a map value;
489  // processing algorithms may be able to write directly to this space, thereby avoiding unneccesary copying of data
490  ZOO_DLL_EXPORT char* allocateMapValue(map* node, size_t num_bytes); 
491 
492#ifdef __cplusplus
493}
494#endif
495
496#endif
Note: See TracBrowser for help on using the repository browser.

Search

Context Navigation

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