File: Modem.h

package info (click to toggle)
hylafax 2%3A6.0.5-4.1
  • links: PTS, VCS
  • area: main
  • in suites: squeeze
  • size: 8,776 kB
  • ctags: 7,663
  • sloc: sh: 15,158; ansic: 13,231; makefile: 1,543; cpp: 781; awk: 529
file content (179 lines) | stat: -rw-r--r-- 6,421 bytes parent folder | download | duplicates (8)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
/*	$Id$ */
/*
 * Copyright (c) 1994-1996 Sam Leffler
 * Copyright (c) 1994-1996 Silicon Graphics, Inc.
 * HylaFAX is a trademark of Silicon Graphics
 *
 * Permission to use, copy, modify, distribute, and sell this software and 
 * its documentation for any purpose is hereby granted without fee, provided
 * that (i) the above copyright notices and this permission notice appear in
 * all copies of the software and related documentation, and (ii) the names of
 * Sam Leffler and Silicon Graphics may not be used in any advertising or
 * publicity relating to the software without the specific, prior written
 * permission of Sam Leffler and Silicon Graphics.
 * 
 * THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND, 
 * EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY 
 * WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.  
 * 
 * IN NO EVENT SHALL SAM LEFFLER OR SILICON GRAPHICS BE LIABLE FOR
 * ANY SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND,
 * OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
 * WHETHER OR NOT ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF 
 * LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE 
 * OF THIS SOFTWARE.
 */
#ifndef _Modem_
#define	_Modem_
/*
 * HylaFAX Queue Manager Abstract Modem.
 */
#include "Class2Params.h"
#include "Str.h"
#include "faxQueueApp.h"

typedef	unsigned int ModemState;

class UUCPLock;
class RE;
class REDict;
class fxStackBuffer;
class Modem;

class ModemGroup {
private:
    static REDict* classes;	// registered modem classes
public:
    static void reset();
    static void set(const fxStr& name, RE* re);
    static RE* find(const char* name);
};

/*
 * NB: This should be a private nested class but various
 *     C++ compilers cannot grok it.
 */
class ModemLockWaitHandler : public IOHandler {
private:
    Modem& modem;
public:
    ModemLockWaitHandler(Modem&);
    ~ModemLockWaitHandler();
    void timerExpired(long, long);
};

/*
 * Each modem server process that has identified itself has
 * an instance of this class.  It contains all the information
 * needed by the queuer to select and prepare outbound jobs.
 * Modem processes communicate with the queuer through FIFO
 * files to exchange server and job state changes and to export
 * modem/server capabilities to the queuer.
 */
class Modem : public QLink {
public:
    enum {
	DOWN  = 0,		// modem identified, but offline
	READY = 1,		// modem ready for use
	BUSY  = 2		// modem in use
    };
private:
    int		fd;		// cached open FIFO file
    fxStr	fifoName;	// modem FIFO filename
    fxStr	devID;		// modem device identifier
    fxStr	number;		// modem phone number
    fxStr	commid;		// communication identifier
    ModemState	state;		// modem state
    bool	canpoll;	// modem is capable of polling
    u_short	priority;	// modem priority
    Class2Params caps;		// modem capabilities
    UUCPLock*	lock;		// UUCP lockfile support
    QLink	triggers;	// waiting specifically on this modem
				// Dispatcher handler for lock wait thread
    ModemLockWaitHandler lockHandler;

    static QLink list;		// list of all modems
    static int modemsReady;	// count of ready modems

    void setCapabilities(const char*);	// specify modem capabilities
    void setNumber(const char*);	// specify modem phone number
    void setCommID(const char*);	// specify modem commid
    void setState(ModemState);		// specify modem state

    friend class faxQueueApp;
    friend class Trigger;		// for triggers
public:
    Modem(const fxStr& devid);
    virtual ~Modem();

    static void CLEANUP (void);

    static bool anyReady (void);
    static Modem& getModemByID(const fxStr& id);
    static Modem* modemExists(const fxStr& id);
    static Modem* findModem(const Job& job);
    bool isInGroup(const fxStr& mgroup);

    bool assign();			// assign modem
    void release();			// release modem

    void startLockPolling(long sec);	// initiate polling thread
    void stopLockPolling();		// terminate any active thread

    const fxStr& getDeviceID() const;	// return modem device ID
    const fxStr& getNumber() const;	// return modem phone number
    ModemState getState() const;	// return modem state
    const Class2Params& getCapabilities() const;
    u_int getPriority() const;		// return modem scheduling priority
    const fxStr& getCommID() const;	// return communication ID

    bool isCapable(const Job& job) const;
    bool supports2D() const;		// modem supports 2D-encoded fax
    bool supportsMMR() const;		// modem supports 2D-MMR encoding
    bool supportsJBIG() const;		// modem supports JBIG encoding
    bool supportsVRes(float) const;	// modem supports vertical resolution
    bool supportsVR(u_int) const;	// modem supports VR setting
    // modem support fax page width
    bool supportsPageWidthInMM(u_int) const;
    bool supportsPageWidthInPixels(u_int) const;
    // modem supports fax page length
    bool supportsPageLengthInMM(u_int) const;
    bool supportsPolling() const;	// modem supports fax polling

    // send message to modem FIFO
    bool send(const char* msg, u_int len, bool cacheFd = true);
    static void broadcast(const fxStr&);	// broadcast msg to all FIFOs

    void encode(fxStackBuffer&) const;	// encode for ModemExt
};
inline bool Modem::supportsPolling() const	{ return canpoll; }
inline const fxStr& Modem::getDeviceID() const	{ return devID; }
inline const fxStr& Modem::getNumber() const	{ return number; }
inline ModemState Modem::getState() const	{ return state; }
inline const Class2Params& Modem::getCapabilities() const { return caps; }
inline u_int Modem::getPriority() const		{ return priority; }
inline const fxStr& Modem::getCommID() const	{ return commid; }

inline bool Modem::anyReady()			{ return modemsReady > 0; }

/*
 * Modem iterator class; for iterating
 * over the set of known modems.
 */
class ModemIter {
private:
    const QLink* head;
    QLink*	ql;
public:
    ModemIter(QLink& q)		{ head = &q; ql = q.next; }
    ~ModemIter() {}

    void operator=(QLink& q)	{ head = &q; ql = q.next; }
    void operator++()		{ ql = ql->next; }
    void operator++(int)	{ ql = ql->next; }
    operator Modem&() const	{ return *(Modem*)ql; }
    operator Modem*() const	{ return (Modem*) ql; }
    Modem& modem() const	{ return *(Modem*)ql; }
    bool notDone()		{ return ql != head; }
};
#endif /* _Modem_ */