1#ifndef _EFAXOS_H
2#define _EFAXOS_H
3
4#include <time.h>
5
6#include "efaxlib.h"
7
8#if defined(__APPLE__)
9#include <CoreFoundation/CoreFoundation.h>
10#include <IOKit/pwr_mgt/IOPMLib.h>
11#endif
12
13/* signals to be caught */
14
15#define ANSISIGS  SIGABRT, SIGFPE, SIGILL, SIGINT, SIGSEGV, SIGTERM
16#define UNIXSIGS  SIGHUP, SIGQUIT, SIGIOT, SIGALRM
17#define CATCHSIGS ANSISIGS, UNIXSIGS
18
19/* Bit order reversal table. */
20
21extern unsigned char normalbits [ ] ;
22
23typedef enum ttymodes		/* serial port modes:  */
24{
25    COMMAND,			/*   19200 8N1, no f/c, DTR high */
26    SEND,			/*   19200 send-only XON/XOFF f/c */
27    VOICECOMMAND,		/*   38400 8N1, no f/c, DTR high */
28    VOICESEND,			/*   38400 send-only XON/XOFF f/c*/
29    DROPDTR,			/*   ", DTR low */
30    ORIGINAL			/*   restore original settings */
31} ttymodes ;
32
33/* OS-specific i/o & delay functions */
34
35/* We define new stream i/o macros because it's not possible to
36   do non-blocking reads/writes with C stream i/o [UNIX select()
37   gives the status of the file, not the stream buffer].*/
38
39#define IBUFSIZE 1024	    /* read up to this many bytes at a time from fax */
40#define OBUFSIZE 1024	    /* maximum bytes to write at a time to fax */
41
42typedef struct tfilestruct {
43  int fd ;
44  void (*onsig)(int sig);
45  unsigned char *ip, *iq ;
46  unsigned char ibuf [ IBUFSIZE ] ;
47  unsigned char *ibitorder, *obitorder ;
48  int bytes, pad, lines ;
49  int hwfc ;
50  time_t start ;
51  long mstart ;
52  int rd_state ;
53  int modem_wait ;
54  int signal;
55} TFILE ;
56
57/* tgetc() is a macro like getc().  It evaluates to the next
58   character from the fax device or EOF after idle time t. */
59
60#define tgetc(f,t) ( (f)->ip >= (f)->iq && tundrflw(f,t) == EOF ? EOF : \
61		    *(unsigned char*)(f)->ip++ )
62
63int tundrflw ( TFILE *f, int t ) ;
64int tgetd ( TFILE *f, int t ) ;
65int tput ( TFILE *f, const char *p, int n ) ;
66int tdata ( TFILE *f, int t ) ;
67int ttyopen ( TFILE *f, char *fname, int reverse, int hwfc ) ;
68int ttyclose ( TFILE *f ) ;
69int ttymode ( TFILE *f, ttymodes mode ) ;
70void msleep ( int t ) ;
71long proc_ms ( void ) ;
72int time_ms ( void ) ;
73
74/* POSIX execl */
75
76extern int execl ( const char *path, const char *arg , ... ) ;
77
78/* UUCP-style device locks */
79
80#define BINLKFLAG '#'		/* prefix to force binary lock files */
81
82				/* [un]lock serial port using named files */
83int lockall ( TFILE *f, char **lkfiles, int log ) ;
84int unlockall ( TFILE *f, char **lkfiles ) ;
85
86/* extract program name to be used in messages from argv0 */
87
88char *efaxbasename ( char *p ) ;
89
90/* default fax modem device */
91
92#define FAXFILE "/dev/modem"
93
94#ifdef __APPLE__
95
96/* tdata() return values */
97#define TDATA_READY		1
98#define TDATA_TIMEOUT		0
99#define TDATA_SELECTERR		-2
100#define TDATA_SLEEP		-6
101#define TDATA_WAKE		-7
102#define TDATA_MANANSWER		-8
103#define TDATA_CANCEL		-9
104#define TDATA_MODEMADDED	-10
105#define TDATA_MODEMREMOVED	-11
106
107typedef struct syseventstruct		/*** System event data ****/
108{
109  unsigned char	event;			/* Event bit field */
110  io_connect_t	powerKernelPort;	/* Power context data */
111  long		powerNotificationID;	/* Power event data */
112} sysevent_t;
113
114extern sysevent_t sysevent;		/* system event data */
115extern int waiting;			/* blocked waiting for activity (okay to exit on SIGHUP) */
116extern int manual_answer;		/* Manual answer flag (set by client connection) */
117extern int answer_wait;			/* blocked waiting for the first fax frame (inclusive of RING messages) */
118extern char *faxfile;			/* device to use ("/dev/<*>.modem") */
119extern int modem_found;			/* modem found */
120
121extern int  cleanup ( int err );
122extern void notify(CFStringRef status, CFTypeRef value);
123extern void sysEventMonitorStart(void);
124extern void sysEventMonitorStop(void);
125#endif	/* __APPLE__ */
126
127#endif
128