ALcune correzioni sparse, risistemati i commenti interni delle varie
[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.12 2003/08/16 18:30:21 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 #include <dirent.h>                              /* directory scan functions */
37 /*
38  * Definition of semun struct; used to implement a MutexXXXX API To
39  * create a Mutex use an underlaying semaphore and init it; we put
40  * here all the needed data structures
41  */
42 /* use this definition, get from the man pages */
43 #if defined(__GNU_LIBRARY__) && !defined(_SEM_SEMUN_UNDEFINED)
44 /* union semun is defined by including <sys/sem.h> */
45 #else
46 /* according to X/OPEN we have to define it ourselves */
47 union semun {
48   int val;                    /* value for SETVAL */
49   struct semid_ds *buf;       /* buffer for IPC_STAT, IPC_SET */
50   unsigned short int *array;  /* array for GETALL, SETALL */
51   struct seminfo *__buf;      /* buffer for IPC_INFO */
52 };
53 #endif
54 /*
55  * Mutex handling Functions
56  */
57 /* Function MutexCreate: create a mutex. See Mutex.c */
58 inline int MutexCreate(key_t ipc_key);
59 /* Function MutexFind: get the mutex ID given fomr IPC key. See Mutex.c */
60 inline int MutexFind(key_t ipc_key);
61 /* Function MutexRead: read the current value of the mutex. See Mutex.c */
62 inline int MutexRead(int sem_id);
63 /* Function MutexLock: to lock a mutex/semaphore. See Mutex.c */
64 inline int MutexLock(int sem_id);
65 /* Function MutexUnlock: to unlock a mutex/semaphore. See Mutex.c */
66 inline int MutexUnlock(int sem_id);
67 /* Function MutexRemove: remove the mutex/semphore. See Mutex.c */
68 inline int MutexRemove(int sem_id);
69 /* Function CreateMutex: create a mutex (using file locking). See Mutex.c */
70 inline int CreateMutex(const char *path_name);
71 /* Function UnlockMutex: find a mutex (using file locking). See Mutex.c */
72 inline int FindMutex(const char *path_name);
73 /* Function LockMutex: acquire a mutex (using file locking). See Mutex.c */
74 inline int LockMutex(int fd);
75 /* Function UnlockMutex: release a mutex (using file locking). See Mutex.c */
76 inline int UnlockMutex(int fd);
77 /* Function ReadMutex: read a mutex (using file locking). See Mutex.c */
78 inline int ReadMutex(int fd);
79 /* Function RemoveMutex: remove a mutex (using file locking). See Mutex.c */
80 inline int RemoveMutex(const char *path_name);
81 /* 
82  * Lock files function: to create and destroy lock files
83  */
84 /* Function LockFile: create a lock file. See FileLock.c */
85 inline int LockFile(const char* path_name);
86 /* Function UnlockFile: remove a lock file. See FileLock.c */
87 inline int UnlockFile(const char* path_name);
88 /*
89  * Signal Handling Functions
90  */
91 typedef void SigFunc(int);
92 /* Function Signal: Initialize a signal handler. See SigHand.c */
93 SigFunc * Signal(int signo, SigFunc *func);
94 /* Function SignalRestart: restart system calls. See SigHand.c */
95 SigFunc * SignalRestart(int signo, SigFunc *func);
96 /* Function HandSigCHLD: to handle SIGCHILD. See SigHand.c */
97 void HandSigCHLD(int sig);
98 /* 
99  * Socket service functions
100  */
101 /* Function FullRead: to read from a socket. See FullRead.c */
102 ssize_t FullRead(int fd, void *buf, size_t count);
103 /* Function FullWrite: to read from a socket. See FullWrite.c */
104 ssize_t FullWrite(int fd, const void *buf, size_t count);
105 /*
106  * File miscellaneous
107  */
108 /* Function DirScan: simple scan for a directory. See DirScan.c */
109 int DirScan(char * dirname, int(*compute)(struct dirent *));
110 /*
111  * Shared memory handling functions. See SharedMem.c
112  */
113 /* Function ShmCreate: create a SysV shared memory */
114 void * ShmCreate(key_t ipc_key, int shm_size, int perm, int fill);
115 /* Function ShmFind: find an existing SysV shared memory */
116 void * ShmFind(key_t ipc_key, int shm_size);
117 /* Function ShmRemove: remove a SysV shared memory */
118 int ShmRemove(key_t ipc_key, void * shm_ptr);
119 /* Function CreateShm: create a POSIX shared memory */
120 void * CreateShm(char * shm_name, off_t shm_size, int perm, int fill);
121 /* Function FindShm: find an existing POSIX shared memory */
122 void * FindShm(char * shm_name, off_t shm_size);
123 /* Function RemoveShm: remove a POSIX shared memory */
124 int RemoveShm(char * shm_name);
125 /*
126  * General purpose functions. See corresponding .c
127  */
128 int endian(void);