[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 |
---|
[843] | 37 | ZOO_DLL_EXPORT char *strcasestr (char const *,char const *); |
---|
| 38 | #endif |
---|
| 39 | |
---|
| 40 | #ifdef WIN32 |
---|
[375] | 41 | #define strncasecmp _strnicmp |
---|
| 42 | #define strcasecmp _stricmp |
---|
[842] | 43 | #define strtok_r strtok_s |
---|
[757] | 44 | #if defined(_MSC_VER) && _MSC_VER < 1900 |
---|
| 45 | #define snprintf _snprintf |
---|
[453] | 46 | #endif |
---|
[840] | 47 | #if defined(_MSC_VER) && _MSC_VER < 1800 |
---|
| 48 | #define false 0 |
---|
| 49 | #define true 1 |
---|
| 50 | #define bool int |
---|
| 51 | #endif |
---|
[453] | 52 | #define zStrdup _strdup |
---|
| 53 | #define zMkdir _mkdir |
---|
| 54 | #define zOpen _open |
---|
| 55 | #define zWrite _write |
---|
[507] | 56 | #define zSleep Sleep |
---|
[514] | 57 | #include <sys/timeb.h> |
---|
| 58 | struct ztimeval { |
---|
| 59 | long tv_sec; /* seconds */ |
---|
| 60 | long tv_usec; /* and microseconds */ |
---|
| 61 | }; |
---|
[554] | 62 | static int zGettimeofday(struct ztimeval* tp, void* tzp) |
---|
[514] | 63 | { |
---|
[838] | 64 | struct _timeb theTime; |
---|
[554] | 65 | if (tp == 0) { |
---|
| 66 | return -1; |
---|
| 67 | } |
---|
| 68 | |
---|
[514] | 69 | _ftime(&theTime); |
---|
| 70 | tp->tv_sec = theTime.time; |
---|
| 71 | tp->tv_usec = theTime.millitm * 1000; |
---|
[554] | 72 | |
---|
| 73 | return 0; // The gettimeofday() function shall return 0 on success |
---|
[514] | 74 | } |
---|
[712] | 75 | |
---|
[379] | 76 | #else |
---|
[579] | 77 | /** |
---|
| 78 | * The crossplatform strdup alias |
---|
| 79 | */ |
---|
[453] | 80 | #define zStrdup strdup |
---|
[579] | 81 | /** |
---|
| 82 | * The crossplatform mkdir alias |
---|
| 83 | */ |
---|
[453] | 84 | #define zMkdir mkdir |
---|
[579] | 85 | /** |
---|
| 86 | * The crossplatform open alias |
---|
| 87 | */ |
---|
[454] | 88 | #define zOpen open |
---|
[579] | 89 | /** |
---|
| 90 | * The crossplatform write alias |
---|
| 91 | */ |
---|
[454] | 92 | #define zWrite write |
---|
[579] | 93 | /** |
---|
| 94 | * The crossplatform sleep alias |
---|
| 95 | */ |
---|
[507] | 96 | #define zSleep sleep |
---|
[579] | 97 | /** |
---|
| 98 | * The crossplatform gettimeofday alias |
---|
| 99 | */ |
---|
[514] | 100 | #define zGettimeofday gettimeofday |
---|
[579] | 101 | /** |
---|
| 102 | * The crossplatform timeval alias |
---|
| 103 | */ |
---|
[514] | 104 | #define ztimeval timeval |
---|
[216] | 105 | #endif |
---|
| 106 | |
---|
[1] | 107 | #ifdef __cplusplus |
---|
| 108 | extern "C" { |
---|
| 109 | #endif |
---|
| 110 | |
---|
[444] | 111 | #ifdef WIN32 |
---|
| 112 | #ifdef USE_MS |
---|
| 113 | #include <mapserver.h> |
---|
| 114 | #endif |
---|
| 115 | #endif |
---|
[1] | 116 | #include <stdlib.h> |
---|
| 117 | #include <ctype.h> |
---|
[712] | 118 | |
---|
[1] | 119 | #include <stdio.h> |
---|
[712] | 120 | |
---|
[1] | 121 | #include <string.h> |
---|
[364] | 122 | #ifndef WIN32 |
---|
[618] | 123 | #include <ctype.h> |
---|
[767] | 124 | #include <stdbool.h> |
---|
[490] | 125 | #endif |
---|
[9] | 126 | |
---|
[579] | 127 | /** |
---|
| 128 | * The global accepted status for a service |
---|
| 129 | */ |
---|
[1] | 130 | #define SERVICE_ACCEPTED 0 |
---|
[579] | 131 | /** |
---|
| 132 | * The global started status for a service |
---|
| 133 | */ |
---|
[1] | 134 | #define SERVICE_STARTED 1 |
---|
[579] | 135 | /** |
---|
| 136 | * The global paused status for a service |
---|
| 137 | */ |
---|
[1] | 138 | #define SERVICE_PAUSED 2 |
---|
[579] | 139 | /** |
---|
| 140 | * The global succeeded status for a service |
---|
| 141 | */ |
---|
[1] | 142 | #define SERVICE_SUCCEEDED 3 |
---|
[579] | 143 | /** |
---|
| 144 | * The global failed status for a service |
---|
| 145 | */ |
---|
[1] | 146 | #define SERVICE_FAILED 4 |
---|
[9] | 147 | |
---|
[579] | 148 | /** |
---|
| 149 | * The memory size to create an elements |
---|
| 150 | */ |
---|
[640] | 151 | #define ELEMENTS_SIZE (sizeof(char*)+(((2*sizeof(char*))+sizeof(maps*))*2)+sizeof(char*)+(((2*sizeof(char*))+sizeof(iotype*))*2)+(2*sizeof(elements*))) |
---|
[579] | 152 | /** |
---|
| 153 | * The memory size to create a map |
---|
| 154 | */ |
---|
[788] | 155 | //#define MAP_SIZE (2*sizeof(char*))+sizeof(NULL) // knut: size of NULL pointer may be different from regular pointer (platform dependent) |
---|
| 156 | #define MAP_SIZE (2*sizeof(char*))+sizeof(map*) |
---|
[579] | 157 | /** |
---|
| 158 | * The memory size to create an iotype |
---|
| 159 | */ |
---|
[788] | 160 | //#define IOTYPE_SIZE MAP_SIZE+sizeof(NULL) |
---|
| 161 | #define IOTYPE_SIZE sizeof(map*) + sizeof(iotype*) |
---|
[579] | 162 | /** |
---|
| 163 | * The memory size to create a maps |
---|
| 164 | */ |
---|
[788] | 165 | //#define MAPS_SIZE (2*sizeof(char*))+sizeof(map*)+MAP_SIZE |
---|
[790] | 166 | #define MAPS_SIZE sizeof(char*)+sizeof(map*)+(2*sizeof(maps*)) |
---|
[579] | 167 | /** |
---|
| 168 | * The memory size to create a service |
---|
| 169 | */ |
---|
[788] | 170 | //#define SERVICE_SIZE (ELEMENTS_SIZE*2)+(MAP_SIZE*2)+sizeof(char*) |
---|
| 171 | #define SERVICE_SIZE sizeof(char*) + 2*sizeof(map*) + 2*sizeof(elements*) |
---|
[607] | 172 | /** |
---|
| 173 | * The memory size to create a services |
---|
| 174 | */ |
---|
[788] | 175 | //#define SERVICES_SIZE SERVICE_SIZE+sizeof(services*) |
---|
| 176 | #define SERVICES_SIZE sizeof(service*)+sizeof(services*) |
---|
[607] | 177 | /** |
---|
| 178 | * The memory size to create a registry |
---|
| 179 | */ |
---|
[788] | 180 | //#define REGISTRY_SIZE SERVICES_SIZE+sizeof(char*) |
---|
| 181 | #define REGISTRY_SIZE sizeof(char*)+sizeof(services*)+sizeof(registry*) |
---|
[1] | 182 | |
---|
[26] | 183 | #define SHMSZ 27 |
---|
[1] | 184 | |
---|
[465] | 185 | #include "version.h" |
---|
[1] | 186 | |
---|
[375] | 187 | #ifdef DEBUG_STACK |
---|
| 188 | void debugStack(const char* file,const int line){ |
---|
| 189 | int stack; |
---|
| 190 | fprintf(stderr,"stack %p (%s: %d) \n",&stack,file,line); |
---|
| 191 | } |
---|
| 192 | #endif |
---|
| 193 | |
---|
[9] | 194 | /** |
---|
[579] | 195 | * KVP linked list |
---|
[9] | 196 | */ |
---|
[1] | 197 | typedef struct map{ |
---|
[607] | 198 | char* name; //!< the key |
---|
| 199 | char* value; //!< the value |
---|
| 200 | struct map* next; //!< the pointer to the next map if any or NULL |
---|
[1] | 201 | } map; |
---|
| 202 | |
---|
| 203 | #ifdef WIN32 |
---|
| 204 | #define NULLMAP ((map*) 0) |
---|
| 205 | #else |
---|
| 206 | #define NULLMAP NULL |
---|
| 207 | #endif |
---|
| 208 | |
---|
[114] | 209 | /** |
---|
[579] | 210 | * linked list of map pointer |
---|
[114] | 211 | * |
---|
| 212 | * Small object to store WPS KVP set. |
---|
| 213 | */ |
---|
| 214 | typedef struct maps{ |
---|
[607] | 215 | char* name; //!< the maps name |
---|
| 216 | struct map* content; //!< the content map |
---|
[790] | 217 | struct maps* child; //!< the child maps |
---|
[607] | 218 | struct maps* next; //!< the pointer to the next maps if any or NULL |
---|
[114] | 219 | } maps; |
---|
[601] | 220 | |
---|
[579] | 221 | /** |
---|
| 222 | * Not named linked list |
---|
[114] | 223 | * |
---|
[781] | 224 | * Used to store information about formats, such as mimeType, encoding ... |
---|
[114] | 225 | */ |
---|
[1] | 226 | typedef struct iotype{ |
---|
[607] | 227 | struct map* content; //!< the content map |
---|
| 228 | struct iotype* next; //!< the pointer to the next iotype if any or NULL |
---|
[1] | 229 | } iotype; |
---|
| 230 | |
---|
[114] | 231 | /** |
---|
[579] | 232 | * Metadata information about input or output. |
---|
[114] | 233 | * |
---|
[781] | 234 | * The elements are used to store metadata information defined in the ZCFG. |
---|
[114] | 235 | */ |
---|
[1] | 236 | typedef struct elements{ |
---|
[607] | 237 | char* name; //!< the name |
---|
| 238 | struct map* content; //!< the content map |
---|
| 239 | struct map* metadata; //!< the metadata map |
---|
| 240 | char* format; //!< the format: LiteralData or ComplexData or BoundingBoxData |
---|
| 241 | struct iotype* defaults; //!< the default iotype |
---|
| 242 | struct iotype* supported; //!< the supported iotype |
---|
[640] | 243 | struct elements* child; //!< the pointer to the children element if any (or NULL) |
---|
[607] | 244 | struct elements* next; //!< the pointer to the next element if any (or NULL) |
---|
[1] | 245 | } elements; |
---|
| 246 | |
---|
[579] | 247 | /** |
---|
[781] | 248 | * Metadata information about a full Service. |
---|
[579] | 249 | */ |
---|
[1] | 250 | typedef struct service{ |
---|
[607] | 251 | char* name; //!< the name |
---|
| 252 | struct map* content; //!< the content map |
---|
| 253 | struct map* metadata; //!< the metadata map |
---|
| 254 | struct elements* inputs; //!< the inputs elements |
---|
| 255 | struct elements* outputs; //!< the outputs elements |
---|
[1] | 256 | } service; |
---|
| 257 | |
---|
[579] | 258 | /** |
---|
[607] | 259 | * Services chained list. |
---|
[579] | 260 | */ |
---|
[1] | 261 | typedef struct services{ |
---|
[607] | 262 | struct service* content; //!< the content service pointer |
---|
| 263 | struct services* next; //!< the pointer to the next services* |
---|
[1] | 264 | } services; |
---|
| 265 | |
---|
[579] | 266 | /** |
---|
[607] | 267 | * Profile registry. |
---|
| 268 | */ |
---|
| 269 | typedef struct registry{ |
---|
| 270 | char *name; //!< the name |
---|
| 271 | struct services* content; //!< the content services pointer |
---|
| 272 | struct registry* next; //!< the next registry pointer |
---|
| 273 | } registry; |
---|
| 274 | |
---|
[680] | 275 | ZOO_DLL_EXPORT void _dumpMap(map*); |
---|
| 276 | ZOO_DLL_EXPORT void dumpMap(map*); |
---|
| 277 | ZOO_DLL_EXPORT void dumpMaps(maps* m); |
---|
[682] | 278 | ZOO_DLL_EXPORT void dumpMapToFile(map*,FILE*); // (used only internally) |
---|
| 279 | ZOO_DLL_EXPORT void dumpMapsToFile(maps*,char*,int); |
---|
[680] | 280 | ZOO_DLL_EXPORT map* createMap(const char*,const char*); |
---|
[790] | 281 | ZOO_DLL_EXPORT maps* createMaps(const char*); |
---|
[680] | 282 | ZOO_DLL_EXPORT int count(map*); |
---|
| 283 | ZOO_DLL_EXPORT bool hasKey(map*,const char*); |
---|
| 284 | ZOO_DLL_EXPORT maps* getMaps(maps*,const char*); |
---|
| 285 | ZOO_DLL_EXPORT map* getMap(map*,const char*); |
---|
| 286 | ZOO_DLL_EXPORT map* getLastMap(map*); |
---|
| 287 | ZOO_DLL_EXPORT map* getMapFromMaps(maps*,const char*,const char*); |
---|
| 288 | ZOO_DLL_EXPORT void freeMap(map**); |
---|
| 289 | ZOO_DLL_EXPORT void freeMaps(maps** mo); |
---|
[550] | 290 | |
---|
| 291 | |
---|
[790] | 292 | ZOO_DLL_EXPORT elements* createEmptyElements(); |
---|
| 293 | ZOO_DLL_EXPORT elements* createElements(char*); |
---|
| 294 | ZOO_DLL_EXPORT void setElementsName(elements**,char*); |
---|
[680] | 295 | ZOO_DLL_EXPORT bool hasElement(elements*,const char*); |
---|
| 296 | ZOO_DLL_EXPORT elements* getElements(elements*,char*); |
---|
| 297 | ZOO_DLL_EXPORT void freeIOType(iotype**); |
---|
| 298 | ZOO_DLL_EXPORT void freeElements(elements**); |
---|
[790] | 299 | ZOO_DLL_EXPORT void setServiceName(service**,char*); |
---|
[680] | 300 | ZOO_DLL_EXPORT void freeService(service**); |
---|
| 301 | ZOO_DLL_EXPORT void addToMap(map*,const char*,const char*); |
---|
| 302 | ZOO_DLL_EXPORT void addIntToMap(map*,const char*,const int); |
---|
[738] | 303 | ZOO_DLL_EXPORT map* addToMapWithSize(map*,const char*,const char*,int); |
---|
[680] | 304 | ZOO_DLL_EXPORT void addMapToMap(map**,map*); |
---|
| 305 | ZOO_DLL_EXPORT void addMapToIoType(iotype**,map*); |
---|
| 306 | ZOO_DLL_EXPORT map* getMapOrFill(map**,const char*,const char*); |
---|
| 307 | ZOO_DLL_EXPORT bool contains(map*,map*); |
---|
| 308 | ZOO_DLL_EXPORT iotype* getIoTypeFromElement(elements*,char*, map*); |
---|
| 309 | ZOO_DLL_EXPORT void loadMapBinary(map**,map*,int); |
---|
| 310 | ZOO_DLL_EXPORT void loadMapBinaries(map**,map*); |
---|
| 311 | ZOO_DLL_EXPORT maps* dupMaps(maps**); |
---|
| 312 | ZOO_DLL_EXPORT void addMapsToMaps(maps**,maps*); |
---|
| 313 | ZOO_DLL_EXPORT map* getMapArray(map*,const char*,int); |
---|
| 314 | ZOO_DLL_EXPORT void setMapArray(map*,const char*,int,const char*); |
---|
| 315 | ZOO_DLL_EXPORT map* getMapType(map*); |
---|
| 316 | ZOO_DLL_EXPORT int addMapsArrayToMaps(maps**,maps*,char*); |
---|
| 317 | ZOO_DLL_EXPORT void setMapInMaps(maps*,const char*,const char*,const char*); |
---|
| 318 | ZOO_DLL_EXPORT void dumpElements(elements*); |
---|
[790] | 319 | ZOO_DLL_EXPORT void dumpElementsAsYAML(elements*,int); |
---|
[680] | 320 | ZOO_DLL_EXPORT elements* dupElements(elements*); |
---|
| 321 | ZOO_DLL_EXPORT void addToElements(elements**,elements*); |
---|
| 322 | ZOO_DLL_EXPORT void dumpService(service*); |
---|
| 323 | ZOO_DLL_EXPORT void dumpServiceAsYAML(service*); |
---|
| 324 | ZOO_DLL_EXPORT service* dupService(service*); |
---|
| 325 | ZOO_DLL_EXPORT void dumpRegistry(registry*); |
---|
| 326 | ZOO_DLL_EXPORT bool addServiceToRegistry(registry**,char*,service*); |
---|
| 327 | ZOO_DLL_EXPORT void freeRegistry(registry**); |
---|
| 328 | ZOO_DLL_EXPORT service* getServiceFromRegistry(registry*,char*,char*); |
---|
| 329 | ZOO_DLL_EXPORT void inheritMap(map**,map*); |
---|
| 330 | ZOO_DLL_EXPORT void inheritIOType(iotype**,iotype*); |
---|
| 331 | ZOO_DLL_EXPORT void inheritElements(elements**,elements*); |
---|
| 332 | ZOO_DLL_EXPORT void inheritance(registry*,service**); |
---|
| 333 | ZOO_DLL_EXPORT void mapsToCharXXX(maps*,char***); |
---|
| 334 | ZOO_DLL_EXPORT void charxxxToMaps(char***,maps**); |
---|
[757] | 335 | #if defined(_MSC_VER) && _MSC_VER < 1800 |
---|
[712] | 336 | // snprintf for Visual Studio compiler; |
---|
| 337 | // it is also used by services (e.g., GetStatus), therefore exported to shared library |
---|
| 338 | ZOO_DLL_EXPORT int snprintf(char *buffer, size_t n, const char *format, ...); |
---|
[757] | 339 | #endif |
---|
[1] | 340 | #ifdef __cplusplus |
---|
| 341 | } |
---|
| 342 | #endif |
---|
| 343 | |
---|
| 344 | #endif |
---|