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

Last change on this file since 894 was 889, checked in by knut, 6 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
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
[847]37#ifndef USE_MS
[843]38ZOO_DLL_EXPORT char *strcasestr (char const *,char const *);
39#endif
[847]40#endif
[843]41
[889]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
[843]56#ifdef WIN32
[375]57#define strncasecmp _strnicmp
58#define strcasecmp _stricmp
[842]59#define strtok_r strtok_s
[757]60#if defined(_MSC_VER) && _MSC_VER < 1900
61#define snprintf _snprintf
[453]62#endif
[889]63/* knut: see new definition of bool above
[840]64#if defined(_MSC_VER) && _MSC_VER < 1800
65#define false 0
66#define true 1
67#define bool int
68#endif
[889]69*/
[453]70#define zStrdup _strdup
71#define zMkdir _mkdir
72#define zOpen _open
73#define zWrite _write
[507]74#define zSleep Sleep
[514]75#include <sys/timeb.h>
76struct ztimeval {
77  long tv_sec; /* seconds */
78  long tv_usec; /* and microseconds */
79};
[554]80static int zGettimeofday(struct ztimeval* tp, void* tzp)
[514]81{
[838]82  struct _timeb theTime;       
[554]83  if (tp == 0) {
84    return -1;
85  }
86 
[514]87  _ftime(&theTime);
88  tp->tv_sec = theTime.time;
89  tp->tv_usec = theTime.millitm * 1000;
[554]90 
91  return 0; // The gettimeofday() function shall return 0 on success
[514]92}
[712]93
[379]94#else
[579]95/**
96 * The crossplatform strdup alias
97 */
[453]98#define zStrdup strdup
[579]99/**
100 * The crossplatform mkdir alias
101 */
[453]102#define zMkdir mkdir
[579]103/**
104 * The crossplatform open alias
105 */
[454]106#define zOpen open
[579]107/**
108 * The crossplatform write alias
109 */
[454]110#define zWrite write
[579]111/**
112 * The crossplatform sleep alias
113 */
[507]114#define zSleep sleep
[579]115/**
116 * The crossplatform gettimeofday alias
117 */
[514]118#define zGettimeofday gettimeofday
[579]119/**
120 * The crossplatform timeval alias
121 */
[514]122#define ztimeval timeval
[216]123#endif
124
[1]125#ifdef __cplusplus
126extern "C" {
127#endif
128
[444]129#ifdef WIN32
130#ifdef USE_MS
131#include <mapserver.h>
132#endif
133#endif
[1]134#include <stdlib.h>
135#include <ctype.h>
[712]136
[1]137#include <stdio.h>
[712]138
[1]139#include <string.h>
[364]140#ifndef WIN32
[618]141#include <ctype.h>
[889]142//#include <stdbool.h> // knut: see new definition of bool above
[490]143#endif
[9]144
[579]145/**
146 * The global accepted status for a service
147 */
[1]148#define SERVICE_ACCEPTED 0
[579]149/**
150 * The global started status for a service
151 */
[1]152#define SERVICE_STARTED 1
[579]153/**
154 * The global paused status for a service
155 */
[1]156#define SERVICE_PAUSED 2
[579]157/**
158 * The global succeeded status for a service
159 */
[1]160#define SERVICE_SUCCEEDED 3
[579]161/**
162 * The global failed status for a service
163 */
[1]164#define SERVICE_FAILED 4
[9]165
[579]166/**
167 * The memory size to create an elements
168 */
[640]169#define ELEMENTS_SIZE (sizeof(char*)+(((2*sizeof(char*))+sizeof(maps*))*2)+sizeof(char*)+(((2*sizeof(char*))+sizeof(iotype*))*2)+(2*sizeof(elements*)))
[579]170/**
171 * The memory size to create a map
172 */
[788]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*)
[579]175/**
176 * The memory size to create an iotype
177 */
[788]178//#define IOTYPE_SIZE MAP_SIZE+sizeof(NULL)
179#define IOTYPE_SIZE sizeof(map*) + sizeof(iotype*)
[579]180/**
181 * The memory size to create a maps
182 */
[788]183//#define MAPS_SIZE (2*sizeof(char*))+sizeof(map*)+MAP_SIZE
[790]184#define MAPS_SIZE sizeof(char*)+sizeof(map*)+(2*sizeof(maps*))
[579]185/**
186 * The memory size to create a service
187 */
[788]188//#define SERVICE_SIZE (ELEMENTS_SIZE*2)+(MAP_SIZE*2)+sizeof(char*)
189#define SERVICE_SIZE sizeof(char*) + 2*sizeof(map*) + 2*sizeof(elements*)
[607]190/**
191 * The memory size to create a services
192 */
[788]193//#define SERVICES_SIZE SERVICE_SIZE+sizeof(services*)
194#define SERVICES_SIZE sizeof(service*)+sizeof(services*)
[607]195/**
196 * The memory size to create a registry
197 */
[788]198//#define REGISTRY_SIZE SERVICES_SIZE+sizeof(char*)
199#define REGISTRY_SIZE sizeof(char*)+sizeof(services*)+sizeof(registry*)
[1]200
[26]201#define SHMSZ     27
[1]202
[465]203#include "version.h"
[1]204
[375]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
[9]212  /**
[579]213   * KVP linked list
[9]214   */
[1]215  typedef struct map{
[607]216    char* name; //!< the key
217    char* value; //!< the value
218    struct map* next; //!< the pointer to the next map if any or NULL
[1]219  } map;
220
221#ifdef WIN32
222#define NULLMAP ((map*) 0)
223#else
224#define NULLMAP NULL
225#endif
226
[114]227  /**
[579]228   * linked list of map pointer
[114]229   *
230   * Small object to store WPS KVP set.
231   */
232  typedef struct maps{
[607]233    char* name; //!< the maps name
234    struct map* content; //!< the content map
[790]235    struct maps* child; //!< the child maps
[607]236    struct maps* next; //!< the pointer to the next maps if any or NULL
[114]237  } maps;
[601]238 
[579]239  /**
240   * Not named linked list
[114]241   *
[781]242   * Used to store information about formats, such as mimeType, encoding ...
[114]243   */
[1]244  typedef struct iotype{
[607]245    struct map* content; //!< the content map
246    struct iotype* next; //!< the pointer to the next iotype if any or NULL
[1]247  } iotype;
248
[114]249  /**
[579]250   * Metadata information about input or output.
[114]251   *
[781]252   * The elements are used to store metadata information defined in the ZCFG.
[114]253   */
[1]254  typedef struct elements{
[607]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
[640]261    struct elements* child; //!< the pointer to the children element if any (or NULL)
[607]262    struct elements* next; //!< the pointer to the next element if any (or NULL)
[1]263  } elements;
264
[579]265  /**
[781]266   * Metadata information about a full Service.
[579]267   */
[1]268  typedef struct service{
[607]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
[1]274  } service;
275
[579]276  /**
[607]277   * Services chained list.
[579]278   */
[1]279  typedef struct services{
[607]280    struct service* content; //!< the content service pointer
281    struct services* next; //!< the pointer to the next services*
[1]282  } services;
283
[579]284  /**
[607]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;
[889]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  };     
[607]353
[889]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
[680]379  ZOO_DLL_EXPORT void _dumpMap(map*);
380  ZOO_DLL_EXPORT void dumpMap(map*);
381  ZOO_DLL_EXPORT void dumpMaps(maps* m);
[682]382  ZOO_DLL_EXPORT void dumpMapToFile(map*,FILE*); // (used only internally)
383  ZOO_DLL_EXPORT void dumpMapsToFile(maps*,char*,int);
[680]384  ZOO_DLL_EXPORT map* createMap(const char*,const char*);
[790]385  ZOO_DLL_EXPORT maps* createMaps(const char*);
[680]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);
[550]394 
395
[790]396  ZOO_DLL_EXPORT elements* createEmptyElements();
397  ZOO_DLL_EXPORT elements* createElements(char*);
398  ZOO_DLL_EXPORT void setElementsName(elements**,char*);
[680]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**);
[790]403  ZOO_DLL_EXPORT void setServiceName(service**,char*);
[680]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);
[738]407  ZOO_DLL_EXPORT map* addToMapWithSize(map*,const char*,const char*,int);
[680]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*);
[790]423  ZOO_DLL_EXPORT void dumpElementsAsYAML(elements*,int);
[680]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**);
[757]439#if defined(_MSC_VER) && _MSC_VER < 1800
[712]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, ...);
[757]443#endif
[889]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 
[1]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