/********************************/
/*   sem_gen.h by IoDream       */
/* sem_server general functions */
/*   Not released yet           */
/*       PUBLIC DOMAIN          */
/********************************/

/* IoDream (IoDream@ifrance.com) */

#ifndef sem_gen_h
#define sem_gen_h

/* C++ compilers friendly */
#ifdef __cplusplus
extern "C" {
#endif /*__cplusplus*/

/* Maximum length of pid number in chars */
#define SEM_LEN_PID 6
/* TRUE and FALSE */
#ifndef FALSE
#define FALSE 0
#define TRUE  1
#endif /* FALSE */

enum sem_request {SEM_REQ_CREATE, SEM_REQ_DESTROY, SEM_REQ_WAIT, SEM_REQ_RELEASE, SEM_REQ_RESET, SEM_REQ_LAST};
extern char *sem_req_txt[SEM_REQ_LAST];

/* Interface for j_net_read_max (look in j_net.h). */
extern ssize_t read_max(int fd, const void *dest, size_t len);
/* Interface for j_net_read_all (look in j_net.h). */
extern ssize_t read_all(int fd, const void *dest, size_t len);
/* Interface for j_net_write_all (look in j_net.h). */
extern ssize_t write_all(int fd, const void *source, size_t len);

/* Lock the mutex fd (created by pipe). */
extern void lock_mutex(int fd[2]);
/* Unlock the mutex fd (created by pipe). */
extern void unlock_mutex(int fd[2]);

/* Find the first item in the string *p_str_item, items are delimited by one or more chars.
   Return a pointer to it (in p_str) and its length (function return), a pointer to the next item (in *p_str_next). */
extern int next_item(char **p_str_item, char **p_str_next, char delim);
/* Parse the request string req and fill in id and pid.
   Return the order of the request (see enum sem_request), or -1 in case of failure.
   Note: if pid is NULL, no pid will be seeked. */
extern int parse_request(char *req, int *id, pid_t *pid);

/* C++ compilers friendly */
#ifdef __cplusplus
}
#endif /*__cplusplus*/

#endif /*sem_gen_h*/
