ZOO-Project
Data Structures | Macros | Typedefs | Functions | Variables
service_internal.h File Reference
#include <libintl.h>
#include <locale.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <sys/ipc.h>
#include <sys/shm.h>
#include <sys/sem.h>
#include <stdio.h>
#include <time.h>
#include <ctype.h>
#include <unistd.h>
#include <fcntl.h>
#include "service.h"

Go to the source code of this file.

Data Structures

struct  zooLock
 The lock structure used by the ZOO-Kernel to ensure atomicity of operations. More...
 

Macros

#define DEFAULT_SERVICE_URL   "http://www.zoo-project.org/"
 The default service url (overriden by serverAddress) More...
 
#define _(String)   dgettext ("zoo-kernel",String)
 ZOO-Kernel internal messages translation function. More...
 
#define _ss(String)   dgettext ("zoo-services",String)
 ZOO-Services messages translation function. More...
 
#define ZOO_LOCK_CREATE_FAILED   -4
 ZOO-Kernel was unable to create a lock. More...
 
#define ZOO_LOCK_ACQUIRE_FAILED   -5
 ZOO-Kernel was unable to acquire a lock. More...
 
#define ZOO_LOCK_RELEASE_FAILED   -6
 ZOO-Kernel was unable to release a lock. More...
 
#define ZOO_LOCK_MAX_RETRY   180
 Number of time the ZOO-Kernel will try to acquire lock. More...
 
#define semid   int
 Cross platform type used for Lock identifier. More...
 

Typedefs

typedef struct zooLock zooLock
 The lock structure used by the ZOO-Kernel to ensure atomicity of operations. More...
 

Functions

ZOO_DLL_EXPORT char * readVSIFile (maps *, const char *)
 Read a file using the GDAL VSI API. More...
 
ZOO_DLL_EXPORT bool validateVRT (maps *, const char *)
 Validate that the VRT contains only allowed path. More...
 
ZOO_DLL_EXPORT int setOutputValue (maps *, const char *, char *, size_t)
 Set an output value. More...
 
ZOO_DLL_EXPORT char * getInputValue (maps *, const char *, size_t *)
 Access an input value. More...
 
ZOO_DLL_EXPORT struct zooLocklockFile (maps *, const char *, const char)
 Lock a file for read, write and upload. More...
 
ZOO_DLL_EXPORT int unlockFile (maps *, struct zooLock *)
 Remove a lock. More...
 
ZOO_DLL_EXPORT void unhandleStatus (maps *)
 Stop handling status repport. More...
 
ZOO_DLL_EXPORT int _updateStatus (maps *)
 Update the current status of the running service. More...
 
ZOO_DLL_EXPORT char * _getStatus (maps *, char *)
 Get the ongoing status of a running service. More...
 
ZOO_DLL_EXPORT char * _getStatusField (maps *, char *, const char *)
 
ZOO_DLL_EXPORT char * _getStatusFile (maps *, char *)
 Read the cache file of a running service. More...
 
ZOO_DLL_EXPORT char * getStatus (int)
 Get the current status of the running service. More...
 
ZOO_DLL_EXPORT char * getStatusId (maps *, char *)
 Read the sid file attached of a service if any. More...
 
ZOO_DLL_EXPORT int updateStatus (maps *, const int, const char *)
 Update the status of an ongoing service. More...
 
ZOO_DLL_EXPORT int removeShmLock (maps *, int)
 Try to remove a semaphore set. More...
 
ZOO_DLL_EXPORT semid acquireLock (maps *)
 Acquire the global lock. More...
 
ZOO_DLL_EXPORT semid getShmLockId (maps *, int)
 Try to create or access a semaphore set. More...
 
ZOO_DLL_EXPORT int lockShm (semid)
 
ZOO_DLL_EXPORT int unlockShm (semid)
 
ZOO_DLL_EXPORT char * file_exists (const char *dir, const char *name)
 Check if file exists in specified folder. More...
 
ZOO_DLL_EXPORT bool isAsyncCall (maps *)
 Verify if an Execute request has been invoked asynchronously. More...
 
ZOO_DLL_EXPORT bool hasDbs (maps *)
 Verify if the server rely on database backend. More...
 

Variables

static zooLock ** zoo_file_locks =NULL
 
static int zoo_file_locks_cnt =0
 

Data Structure Documentation

◆ zooLock

struct zooLock

The lock structure used by the ZOO-Kernel to ensure atomicity of operations.

Data Fields
char * filename The filename to lock.
struct flock lock The lock.
FILE * lockfile The pointer to the lock file.

Macro Definition Documentation

◆ _

#define _ (   String)    dgettext ("zoo-kernel",String)

ZOO-Kernel internal messages translation function.

◆ _ss

#define _ss (   String)    dgettext ("zoo-services",String)

ZOO-Services messages translation function.

◆ DEFAULT_SERVICE_URL

#define DEFAULT_SERVICE_URL   "http://www.zoo-project.org/"

The default service url (overriden by serverAddress)

◆ semid

#define semid   int

Cross platform type used for Lock identifier.

◆ ZOO_LOCK_ACQUIRE_FAILED

#define ZOO_LOCK_ACQUIRE_FAILED   -5

ZOO-Kernel was unable to acquire a lock.

◆ ZOO_LOCK_CREATE_FAILED

#define ZOO_LOCK_CREATE_FAILED   -4

ZOO-Kernel was unable to create a lock.

◆ ZOO_LOCK_MAX_RETRY

#define ZOO_LOCK_MAX_RETRY   180

Number of time the ZOO-Kernel will try to acquire lock.

◆ ZOO_LOCK_RELEASE_FAILED

#define ZOO_LOCK_RELEASE_FAILED   -6

ZOO-Kernel was unable to release a lock.

Typedef Documentation

◆ zooLock

typedef struct zooLock zooLock

The lock structure used by the ZOO-Kernel to ensure atomicity of operations.

Function Documentation

◆ _getStatus()

ZOO_DLL_EXPORT char* _getStatus ( maps conf,
char *  lid 
)

Get the ongoing status of a running service.

Parameters
confthe maps containing the setting of the main.cfg file
pidthe service identifier (usid key from the [lenv] section)
Returns
the reported status char* (MESSAGE|POURCENTAGE)
Warning
make sure to free resources returned by this function

◆ _getStatusField()

ZOO_DLL_EXPORT char* _getStatusField ( maps ,
char *  ,
const char *   
)

◆ _getStatusFile()

ZOO_DLL_EXPORT char* _getStatusFile ( maps conf,
char *  pid 
)

Read the cache file of a running service.

Parameters
confthe maps containing the setting of the main.cfg file
pidthe service identifier (usid key from the [lenv] section)
Returns
the reported status char* (temporary/final result)

◆ _updateStatus()

ZOO_DLL_EXPORT int _updateStatus ( maps conf)

Update the current status of the running service.

See also
acquireLock, lockShm
Parameters
confthe map containing the setting of the main.cfg file
Returns
0 on success, -2 if shmget failed, -1 if shmat failed

◆ acquireLock()

ZOO_DLL_EXPORT semid acquireLock ( maps conf)

Acquire the global lock.

Parameters
confthe maps containing the setting of the main.cfg file
Returns
a semid

◆ file_exists()

ZOO_DLL_EXPORT char* file_exists ( const char *  dir,
const char *  name 
)

Check if file exists in specified folder.

Parameters
dirthe folder in which to search for file
namethe name of the file (not full path)
Returns
a character string with the full path [dir/name], or NULL if the file does not exist
Attention
Caller is responsible for applying free() to the returned pointer

◆ getInputValue()

ZOO_DLL_EXPORT char* getInputValue ( maps inputs,
const char *  parameterName,
size_t *  numberOfBytes 
)

Access an input value.

Parameters
inputsthe maps to search for the input value
parameterNamethe input name to fetch the value
numberOfBytesthe resulting size of the value to add (for binary values), -1 for basic char* data
Returns
a pointer to the input value if found, NULL in other case.

◆ getShmLockId()

ZOO_DLL_EXPORT semid getShmLockId ( maps conf,
int  nsems 
)

Try to create or access a semaphore set.

See also
getKeyValue
Parameters
confthe map containing the setting of the main.cfg file
nsemsnumber of semaphores
Returns
a semaphores set indentifier on success, -1 in other case

◆ getStatus()

ZOO_DLL_EXPORT char* getStatus ( int  pid)

Get the current status of the running service.

See also
getKeyValue, getShmLockId, lockShm
Parameters
pidthe semaphores
Returns
0 on success, -2 if shmget failed, -1 if shmat failed

◆ getStatusId()

ZOO_DLL_EXPORT char* getStatusId ( maps conf,
char *  pid 
)

Read the sid file attached of a service if any.

Parameters
confthe maps containing the setting of the main.cfg file
pidthe service identifier (usid key from the [lenv] section)
Returns
the reported status char* (temporary/final result)
Warning
make sure to free resources returned by this function

◆ hasDbs()

ZOO_DLL_EXPORT bool hasDbs ( maps pmsConf)

Verify if the server rely on database backend.

Parameters
pmsConfthe maps pointing to the main configuration
Returns
true if the server rely no database, false otherwise

◆ isAsyncCall()

ZOO_DLL_EXPORT bool isAsyncCall ( maps pmsConf)

Verify if an Execute request has been invoked asynchronously.

Parameters
pmsConfthe maps pointing to the main configuration
Returns
true if the service should be invoked asynchronously, false otherwise

◆ lockFile()

ZOO_DLL_EXPORT struct zooLock* lockFile ( maps conf,
const char *  filename,
const char  mode 
)

Lock a file for read, write and upload.

Parameters
confthe main configuration maps
filenamethe file to lock
modedefine access: 'r' for read, 'w' for write
Returns
a new zooLock structure on sucess, NULL on failure

◆ lockShm()

ZOO_DLL_EXPORT int lockShm ( semid  )

◆ readVSIFile()

ZOO_DLL_EXPORT char* readVSIFile ( maps conf,
const char *  dataSource 
)

Read a file using the GDAL VSI API.

Parameters
confthe maps containing the settings of the main.cfg file
dataSourcethe datasource name to read
Warning
make sure to free resources returned by this function

◆ removeShmLock()

ZOO_DLL_EXPORT int removeShmLock ( maps conf,
int  nsems 
)

Try to remove a semaphore set.

Parameters
confthe map containing the setting of the main.cfg file
nsemsnumber of semaphores
Returns
0 if the semaphore can be removed, -1 in other case.

◆ setOutputValue()

ZOO_DLL_EXPORT int setOutputValue ( maps outputs,
const char *  parameterName,
char *  data,
size_t  numberOfBytes 
)

Set an output value.

Parameters
outputsthe maps to define the output value
parameterNamethe output name to set the value
datathe value to set
numberOfBytessize of the value to add (for binary values), -1 for basic char* data
Returns
0

◆ unhandleStatus()

ZOO_DLL_EXPORT void unhandleStatus ( maps conf)

Stop handling status repport.

Parameters
confthe map containing the setting of the main.cfg file

◆ unlockFile()

ZOO_DLL_EXPORT int unlockFile ( maps conf,
struct zooLock s 
)

Remove a lock.

Parameters
confthe main configuration maps
sthe zooLock structure
Returns
0 on success, -1 on failure.

◆ unlockShm()

ZOO_DLL_EXPORT int unlockShm ( semid  )

◆ updateStatus()

ZOO_DLL_EXPORT int updateStatus ( maps conf,
const int  percentCompleted,
const char *  message 
)

Update the status of an ongoing service.

Parameters
confthe maps containing the settings of the main.cfg file
percentCompletedpercentage of completude of execution of the service
messageinformation about the current step executed
Returns
the value of _updateStatus
See also
_updateStatus

◆ validateVRT()

ZOO_DLL_EXPORT bool validateVRT ( maps pmsConf,
const char *  pccVRTName 
)

Validate that the VRT contains only allowed path.

Parameters
pmsConfthe maps pointing to the main configuration
pccVRTNamethe name of the VRT file to validate
Returns
true if the VRT is valid, false otherwise

Variable Documentation

◆ zoo_file_locks

zooLock** zoo_file_locks =NULL
static

◆ zoo_file_locks_cnt

int zoo_file_locks_cnt =0
static