541cd49126711950f28363517fa33b4377335c84
[gapil.git] / sources / Gapil.h
1 /* Gapil.h
2  * 
3  * Copyright (C) 2002 Simone Piccardi
4  * 
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; either version 2 of the License, or (at
8  * your option) any later version.
9  * 
10  * This program is distributed in the hope that it will be useful, but
11  * WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13  * General Public License for more details.
14  * 
15  * You should have received a copy of the GNU General Public License
16  * along with this program; if not, write to the Free Software
17  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18  */
19 /*****************************************************************************
20  *
21  * File Gapil.h: 
22  * Set of definition for service routines
23  *
24  * Author: S. Piccardi
25  *
26  * $Id: Gapil.h,v 1.2 2002/12/03 22:30:11 piccardi Exp $
27  *
28  *****************************************************************************/
29 #include <sys/sem.h>                           /* IPC semaphore declarations */
30 #include <sys/shm.h>                       /* IPC shared memory declarations */
31 #include <sys/types.h>
32 #include <sys/stat.h>
33 #include <unistd.h>                               /* unix standard functions */
34 #include <fcntl.h>                          /* file control (lock) functions */
35 #include <signal.h>                          /* signal handling declarations */
36 /*
37  * Definition of semun struct; used to implement a MutexXXXX API To
38  * create a Mutex use an underlaying semaphore and init it; we put
39  * here all the needed data structures
40  */
41 /* use this definition, get from the man pages */
42 #if defined(__GNU_LIBRARY__) && !defined(_SEM_SEMUN_UNDEFINED)
43 /* union semun is defined by including <sys/sem.h> */
44 #else
45 /* according to X/OPEN we have to define it ourselves */
46 union semun {
47   int val;                    /* value for SETVAL */
48   struct semid_ds *buf;       /* buffer for IPC_STAT, IPC_SET */
49   unsigned short int *array;  /* array for GETALL, SETALL */
50   struct seminfo *__buf;      /* buffer for IPC_INFO */
51 };
52 #endif
53 /*
54  * Mutex handling Functions
55  */
56 /* Function MutexCreate: create a mutex. See Mutex.c */
57 inline int MutexCreate(key_t ipc_key);
58 /* Function MutexFind: get the mutex ID given fomr IPC key. See Mutex.c */
59 inline int MutexFind(key_t ipc_key);
60 /* Function MutexRead: read the current value of the mutex. See Mutex.c */
61 inline int MutexRead(int sem_id);
62 /* Function MutexLock: to lock a mutex/semaphore. See Mutex.c */
63 inline int MutexLock(int sem_id);
64 /* Function MutexUnlock: to unlock a mutex/semaphore. See Mutex.c */
65 inline int MutexUnlock(int sem_id);
66
67 /* Function LockFile: create a lock file. See FileLock.c*/
68 inline int LockFile(const char* path_name);
69 /* Function UnLockFile: remove a lock file. See FileLock.c*/
70 inline int UnlockFile(const char* path_name);
71 /*
72  * Signal Handling Functions
73  */
74 typedef void SigFunc(int);
75 /* Function Signal: Initialize a signal handler. See SigHand.c */
76 SigFunc * Signal(int signo, SigFunc *func);
77 /* Function HandSigCHLD: to handle SIGCHILD. See SigHand.c */
78 void HandSigCHLD(int sig);
79 /* 
80  * Socket service functions
81  */
82 /* Function SockRead: to read from a socket. See SockRead.c */
83 ssize_t SockRead(int fd, void *buf, size_t count);
84 /* Function SockWrite: to read from a socket. See SockWrite.c */
85 ssize_t SockWrite(int fd, const void *buf, size_t count);