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

Last change on this file since 889 was 889, checked in by knut, 3 years ago

Added some new logging functionality (function logMessage(), macros zooLog, zooLogMsg). Added utility functions setErrorMessage(), hasvalue(), and nonempty() in service.c. Added enum WPSException and arrays WPSExceptionText and WPSExceptionCode (see also function setErrorMessage). New conditional definition of type bool in service.c (to fix issue with bool). Null pointer check in function addToMap. Added missing return values and explicit type casts in some functions. Removed Windows-specific code in function dumpBackFinalFile (zoo_service_loader.c) that may cause error for async raw data output in formats other than XML.

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