84e7211535ee7cb7d785af8b96195f5c48ebc653
[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.4 2003/01/04 17:24:30 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 LockMutex: acquire a mutex (using file locking). See Mutex.c */
70 inline int LockFile(const char* path_name);
71 /* Function UnlockMutex: release a mutex (using file locking). See Mutex.c */
72 inline int UnlockFile(const char* path_name);
73
74
75 /* Function LockFile: create a lock file. See FileLock.c */
76 inline int LockFile(const char* path_name);
77 /* Function UnlockFile: remove a lock file. See FileLock.c */
78 inline int UnlockFile(const char* path_name);
79 /*
80  * Signal Handling Functions
81  */
82 typedef void SigFunc(int);
83 /* Function Signal: Initialize a signal handler. See SigHand.c */
84 SigFunc * Signal(int signo, SigFunc *func);
85 /* Function HandSigCHLD: to handle SIGCHILD. See SigHand.c */
86 void HandSigCHLD(int sig);
87 /* 
88  * Socket service functions
89  */
90 /* Function SockRead: to read from a socket. See SockRead.c */
91 ssize_t SockRead(int fd, void *buf, size_t count);
92 /* Function SockWrite: to read from a socket. See SockWrite.c */
93 ssize_t SockWrite(int fd, const void *buf, size_t count);
94 /*
95  * File miscellaneous
96  */
97 /* Function DirScan: simple scan for a directory */
98 int DirScan(char * dirname, int(*compute)(struct dirent *));