ZOO-Project: service_internal.h File Reference
ZOO-Project
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 TIME_SIZE   40
 The time size. 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 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 * _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...
 

Variables

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

Data Structure Documentation

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.

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

ZOO-Services messages translation function.

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

The default service url (overriden by serverAddress)

#define semid   int

Cross platform type used for Lock identifier.

#define TIME_SIZE   40

The time size.

#define ZOO_LOCK_ACQUIRE_FAILED   -5

ZOO-Kernel was unable to acquire a lock.

#define ZOO_LOCK_CREATE_FAILED   -4

ZOO-Kernel was unable to create a lock.

#define ZOO_LOCK_MAX_RETRY   180

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

#define ZOO_LOCK_RELEASE_FAILED   -6

ZOO-Kernel was unable to release a lock.

Typedef Documentation

typedef struct zooLock zooLock

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

Function Documentation

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)
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)
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
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
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
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.
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
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
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)
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
ZOO_DLL_EXPORT int lockShm ( semid  )
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
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.
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
ZOO_DLL_EXPORT void unhandleStatus ( maps conf)

Stop handling status repport.

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

Variable Documentation

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

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