3 * Copyright (C) 2002 Simone Piccardi
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.
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.
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.
19 /*****************************************************************************
22 * Set of definition for service routines
26 * $Id: Gapil.h,v 1.5 2003/01/07 23:00:34 piccardi Exp $
28 *****************************************************************************/
29 #include <sys/sem.h> /* IPC semaphore declarations */
30 #include <sys/shm.h> /* IPC shared memory declarations */
31 #include <sys/types.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 */
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
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> */
46 /* according to X/OPEN we have to define it ourselves */
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 */
55 * Mutex handling Functions
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);
82 * Lock files function: to create and destroy lock files
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);
89 * Signal Handling Functions
91 typedef void SigFunc(int);
92 /* Function Signal: Initialize a signal handler. See SigHand.c */
93 SigFunc * Signal(int signo, SigFunc *func);
94 /* Function HandSigCHLD: to handle SIGCHILD. See SigHand.c */
95 void HandSigCHLD(int sig);
97 * Socket service functions
99 /* Function SockRead: to read from a socket. See SockRead.c */
100 ssize_t SockRead(int fd, void *buf, size_t count);
101 /* Function SockWrite: to read from a socket. See SockWrite.c */
102 ssize_t SockWrite(int fd, const void *buf, size_t count);
106 /* Function DirScan: simple scan for a directory */
107 int DirScan(char * dirname, int(*compute)(struct dirent *));