ZOO-Project: service_internal.h Source File
ZOO-Project
service_internal.h
Go to the documentation of this file.
1 /*
2  * Author : Gérald FENOY
3  *
4  * Copyright (c) 2009-2013 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_INTERNAL_H
26 #define ZOO_SERVICE_INTERNAL_H 1
27 
28 #pragma once
29 
33 #define DEFAULT_SERVICE_URL "http://www.zoo-project.org/"
34 
37 #define TIME_SIZE 40
38 
39 #include <libintl.h>
40 #include <locale.h>
44 #define _(String) dgettext ("zoo-kernel",String)
45 
48 #define _ss(String) dgettext ("zoo-services",String)
49 
53 #define ZOO_LOCK_CREATE_FAILED -4
54 
57 #define ZOO_LOCK_ACQUIRE_FAILED -5
58 
61 #define ZOO_LOCK_RELEASE_FAILED -6
62 
65 #define ZOO_LOCK_MAX_RETRY 180
66 
67 #include <sys/stat.h>
68 #include <sys/types.h>
69 #ifndef WIN32
70 #include <sys/ipc.h>
71 #include <sys/shm.h>
72 #include <sys/sem.h>
73 #else
74 #include <direct.h>
75 #endif
76 #include <stdio.h>
77 #include <time.h>
78 #include <ctype.h>
79 #ifndef USE_RUBY
80 #include <unistd.h>
81 #endif
82 #ifndef WIN32
83 #include <locale.h>
84 #endif
85 
86 #include <fcntl.h>
87 
88 #include "service.h"
89 
90 #if defined(macintosh) || (defined(__MACH__) && defined(__APPLE__))
91 
92 #include <CoreServices/CoreServices.h>
93 #include <SystemConfiguration/SystemConfiguration.h>
94 
95 #endif
96 
97 #ifdef WIN32
98 // fcntl flock definitions
99 #define F_SETLK 8 // Non-Blocking set or clear a lock
100 #define F_SETLKW 9 // Blocking set or clear a lock
101 #define F_GETLK 10
102 #define F_RDLCK 1 // read lock
103 #define F_WRLCK 2 // write lock
104 #define F_UNLCK 3 // remove lock
105 struct flock {
106  short l_type; // F_RDLCK, F_WRLCK, or F_UNLCK
107  short l_whence; // flag to choose starting offset, must be SEEK_SET
108  long l_start; // relative offset, in bytes, must be 0
109  long l_len; // length, in bytes; 0 means lock to EOF, must be 0
110  short l_pid; // unused (returned with the unsupported F_GETLK)
111  short l_xxx; // reserved for future use
112 };
113 #endif
114 
119 typedef struct zooLock{
120  struct flock lock;
121  FILE* lockfile;
122  char* filename;
123 } zooLock;
124 
125 static zooLock** zoo_file_locks=NULL;
126 static int zoo_file_locks_cnt=0;
127 
128 #ifdef __cplusplus
129 extern "C" {
130 #endif
131 
132 
133  ZOO_DLL_EXPORT char *readVSIFile(maps*,const char*);
134  ZOO_DLL_EXPORT int setOutputValue( maps*, const char*, char*, size_t);
135  ZOO_DLL_EXPORT char* getInputValue( maps*,const char*,size_t*);
136 
137  ZOO_DLL_EXPORT struct zooLock* lockFile(maps*,const char*,const char);
138  ZOO_DLL_EXPORT int unlockFile(maps*,struct zooLock*);
139 
142  ZOO_DLL_EXPORT char* _getStatus(maps*,char*);
143  ZOO_DLL_EXPORT char* _getStatusFile(maps*,char*);
144  ZOO_DLL_EXPORT char* getStatus(int);
145  ZOO_DLL_EXPORT char* getStatusId(maps*,char*);
146 
147  ZOO_DLL_EXPORT int updateStatus( maps*,const int,const char*);
148  ZOO_DLL_EXPORT int removeShmLock(maps*, int);
152 #ifndef WIN32
153 #define semid int
154 #else
155 #include <windows.h>
156 #define semid HANDLE
157 #endif
162 
163  ZOO_DLL_EXPORT char* file_exists(const char* dir, const char* name);
164 
165 #ifdef __cplusplus
166 }
167 #endif
168 
169 #endif
static zooLock ** zoo_file_locks
Definition: service_internal.h:125
struct flock lock
The lock.
Definition: service_internal.h:120
ZOO_DLL_EXPORT char * getStatus(int)
Get the current status of the running service.
Definition: service_internal.c:807
static int zoo_file_locks_cnt
Definition: service_internal.h:126
ZOO_DLL_EXPORT semid getShmLockId(maps *, int)
Try to create or access a semaphore set.
Definition: service_internal.c:673
ZOO_DLL_EXPORT int unlockShm(semid)
ZOO_DLL_EXPORT char * _getStatus(maps *, char *)
Get the ongoing status of a running service.
Definition: service_internal.c:367
FILE * lockfile
The pointer to the lock file.
Definition: service_internal.h:121
ZOO_DLL_EXPORT semid acquireLock(maps *)
Acquire the global lock.
Definition: service_internal.c:261
ZOO_DLL_EXPORT int lockShm(semid)
ZOO_DLL_EXPORT int unlockFile(maps *, struct zooLock *)
Remove a lock.
Definition: service_internal.c:198
#define ZOO_DLL_EXPORT
ZOO_DLL_EXPORT struct zooLock * lockFile(maps *, const char *, const char)
Lock a file for read, write and upload.
Definition: service_internal.c:96
ZOO_DLL_EXPORT void unhandleStatus(maps *)
Stop handling status repport.
Definition: service_internal.c:427
linked list of map pointer
Definition: main_conf_read.y:292
The lock structure used by the ZOO-Kernel to ensure atomicity of operations.
Definition: service_internal.h:119
ZOO_DLL_EXPORT int _updateStatus(maps *)
Update the current status of the running service.
Definition: service_internal.c:445
ZOO_DLL_EXPORT char * readVSIFile(maps *, const char *)
Read a file using the GDAL VSI API.
Definition: service_internal.c:880
ZOO_DLL_EXPORT char * _getStatusFile(maps *, char *)
Read the cache file of a running service.
Definition: service_internal.c:300
ZOO_DLL_EXPORT char * getInputValue(maps *, const char *, size_t *)
Access an input value.
Definition: service_internal.c:858
ZOO_DLL_EXPORT char * file_exists(const char *dir, const char *name)
Check if file exists in specified folder.
Definition: service_internal.c:937
ZOO_DLL_EXPORT int setOutputValue(maps *, const char *, char *, size_t)
Set an output value.
Definition: service_internal.c:909
ZOO_DLL_EXPORT int removeShmLock(maps *, int)
Try to remove a semaphore set.
Definition: service_internal.c:745
ZOO_DLL_EXPORT char * getStatusId(maps *, char *)
Read the sid file attached of a service if any.
Definition: service_internal.c:233
struct zooLock zooLock
The lock structure used by the ZOO-Kernel to ensure atomicity of operations.
ZOO_DLL_EXPORT int updateStatus(maps *, const int, const char *)
Update the status of an ongoing service.
Definition: service_internal.c:841
#define semid
Cross platform type used for Lock identifier.
Definition: service_internal.h:153
char * filename
The filename to lock.
Definition: service_internal.h:122

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