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