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

Last change on this file was 975, checked in by djay, 10 months ago

Use zMkdir for building on windows

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