ZOO-Project
Data Structures | Macros | Functions
service_internal.c File Reference
#include "cpl_vsi.h"
#include "service_internal.h"
#include "service_callback.h"
#include "dirent.h"

Data Structures

union  semun
 arg for semctl system calls. More...
 

Macros

#define _LARGEFILE64_SOURCE   1
 
#define ERROR_MSG_MAX_LENGTH   1024
 
#define MAX_RETRIES   10
 Number of time to try to access a semaphores set. More...
 

Functions

struct zooLocklockFile (maps *conf, const char *filename, const char mode)
 Lock a file for read, write and upload. More...
 
int unlockFile (maps *conf, struct zooLock *s)
 Remove a lock. More...
 
char * getStatusId (maps *conf, char *pid)
 Read the sid file attached of a service if any. More...
 
semid acquireLock (maps *conf)
 Acquire the global lock. More...
 
char * _getStatusFile (maps *conf, char *pid)
 Read the cache file of a running service. More...
 
char * _getStatus (maps *conf, char *lid)
 Get the ongoing status of a running service. More...
 
void unhandleStatus (maps *conf)
 Stop handling status repport. More...
 
int _updateStatus (maps *conf)
 Update the current status of the running service. More...
 
int getKeyValue (maps *conf)
 Set in the pre-allocated key the zoo_sem_[OSID] string where [OSID] is the lid (if any) or osid value from the [lenv] section. More...
 
int getShmLockId (maps *conf, int nsems)
 Try to create or access a semaphore set. More...
 
int removeShmLock (maps *conf, int nsems)
 Try to remove a semaphore set. More...
 
int lockShm (int id)
 Lock a semaphore set. More...
 
int unlockShm (int id)
 unLock a semaphore set. More...
 
char * getStatus (int pid)
 Get the current status of the running service. More...
 
int updateStatus (maps *conf, const int percentCompleted, const char *message)
 Update the status of an ongoing service. More...
 
char * getInputValue (maps *inputs, const char *parameterName, size_t *numberOfBytes)
 Access an input value. More...
 
char * readVSIFile (maps *conf, const char *dataSource)
 Read a file using the GDAL VSI API. More...
 
int setOutputValue (maps *outputs, const char *parameterName, char *data, size_t numberOfBytes)
 Set an output value. More...
 
char * file_exists (const char *dir, const char *name)
 Check if file exists in specified folder. More...
 

Data Structure Documentation

union semun

arg for semctl system calls.

Data Fields
ushort * array array for GETALL & SETALL
struct semid_ds * buf buffer for IPC_STAT & IPC_SET
int val value for SETVAL

Macro Definition Documentation

#define _LARGEFILE64_SOURCE   1
#define ERROR_MSG_MAX_LENGTH   1024
#define MAX_RETRIES   10

Number of time to try to access a semaphores set.

See also
getShmLockId

Function Documentation

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)
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)
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
semid acquireLock ( maps conf)

Acquire the global lock.

Parameters
confthe maps containing the setting of the main.cfg file
Returns
a semid
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
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.
int getKeyValue ( maps conf)

Set in the pre-allocated key the zoo_sem_[OSID] string where [OSID] is the lid (if any) or osid value from the [lenv] section.

Parameters
confthe map containing the setting of the main.cfg file
int 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
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
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)
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
int lockShm ( int  id)

Lock a semaphore set.

Parameters
idthe semaphores set indetifier
Returns
0 if the semaphore can be locked, -1 in other case.
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
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.
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
void unhandleStatus ( maps conf)

Stop handling status repport.

Parameters
confthe map containing the setting of the main.cfg file
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.
int unlockShm ( int  id)

unLock a semaphore set.

Parameters
idthe semaphores set indetifier
Returns
0 if the semaphore can be locked, -1 in other case.
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