forked from hehol/t38modem
-
Notifications
You must be signed in to change notification settings - Fork 4
/
pmodem.cxx
230 lines (200 loc) · 6.12 KB
/
pmodem.cxx
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
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
/*
* pmodem.cxx
*
* T38FAX Pseudo Modem
*
* Copyright (c) 2001-2008 Vyacheslav Frolov
*
* Open H323 Project
*
* The contents of this file are subject to the Mozilla Public License
* Version 1.0 (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS"
* basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
* the License for the specific language governing rights and limitations
* under the License.
*
* The Original Code is Open H323 Library.
*
* The Initial Developer of the Original Code is Vyacheslav Frolov
*
* Contributor(s): Equivalence Pty ltd
*
* $Log: pmodem.cxx,v $
* Revision 1.11 2008-09-10 11:15:00 frolov
* Ported to OPAL SVN trunk
*
* Revision 1.11 2008/09/10 11:15:00 frolov
* Ported to OPAL SVN trunk
*
* Revision 1.10 2007/03/22 16:26:04 vfrolov
* Fixed compiler warnings
*
* Revision 1.9 2007/01/29 12:44:41 vfrolov
* Added ability to put args to drivers
*
* Revision 1.8 2006/05/23 14:48:54 vfrolov
* Fixed race condition (reported by Tamas)
*
* Revision 1.7 2004/07/07 12:38:32 vfrolov
* The code for pseudo-tty (pty) devices that communicates with fax application formed to PTY driver.
*
* Revision 1.6 2004/05/09 07:46:11 csoutheren
* Updated to compile with new PIsDescendant function
*
* Revision 1.5 2002/05/15 16:17:44 vfrolov
* Implemented per modem routing for I/C calls
*
* Revision 1.4 2002/03/05 12:35:52 vfrolov
* Added Copyright header
* Changed class hierarchy
* PseudoModem is abstract
* PseudoModemBody is child of PseudoModem
* Added PseudoModemQ::CreateModem() to create instances
* Some OS specific code moved from pmodem.cxx to pty.cxx
*
* Revision 1.3 2002/02/08 12:58:22 vfrolov
* Defined Linux and FreeBSD patterns in ttyPattern().
*
* Revision 1.2 2002/01/10 06:10:02 craigs
* Added MPL header
*
* Revision 1.1 2002/01/01 23:06:54 craigs
* Initial version
*
*/
#include <ptlib.h>
#include "pmodem.h"
#include "drivers.h"
#define new PNEW
///////////////////////////////////////////////////////////////
PLIST(_PseudoModemList, PseudoModem);
class PseudoModemList : protected _PseudoModemList
{
PCLASSINFO(PseudoModemList, _PseudoModemList);
public:
PINDEX Append(PseudoModem *modem);
PseudoModem *Find(const PString &modemToken) const;
protected:
PseudoModem *_Find(const PString &modemToken) const;
PMutex Mutex;
};
PINDEX PseudoModemList::Append(PseudoModem *modem)
{
PWaitAndSignal mutexWait(Mutex);
if (_Find(modem->modemToken())) {
myPTRACE(1, "T38Modem\tPseudoModemList::Append can't add " << modem->ptyName() << " to modem list");
delete modem;
return P_MAX_INDEX;
}
PINDEX i = _PseudoModemList::Append(modem);
myPTRACE(3, "T38Modem\tPseudoModemList::Append " << modem->ptyName() << " (" << i << ") OK");
return i;
}
PseudoModem *PseudoModemList::Find(const PString &modemToken) const
{
PWaitAndSignal mutexWait(Mutex);
return _Find(modemToken);
}
PseudoModem *PseudoModemList::_Find(const PString &modemToken) const
{
PObject *object;
for (PINDEX i = 0 ; (object = ((PCollection*)this)->GetAt(i)) != NULL ; i++) {
PAssert(PIsDescendant(object, PseudoModem), PInvalidCast);
PseudoModem *modem = (PseudoModem *)object;
if (modem->modemToken() == modemToken)
return modem;
}
return NULL;
}
///////////////////////////////////////////////////////////////
PObject::Comparison PseudoModem::Compare(const PObject & obj) const
{
PAssert(PIsDescendant(&obj, PseudoModem), PInvalidCast);
const PseudoModem & other = (const PseudoModem &)obj;
return modemToken().Compare(other.modemToken());
}
///////////////////////////////////////////////////////////////
PseudoModemQ::PseudoModemQ()
{
pmodem_list = new PseudoModemList();
}
PseudoModemQ::~PseudoModemQ()
{
delete pmodem_list;
}
PBoolean PseudoModemQ::CreateModem(
const PString &tty,
const PString &route,
const PConfigArgs &args,
const PNotifier &callbackEndPoint
)
{
PseudoModem *modem = PseudoModemDrivers::CreateModem(tty, route, args, callbackEndPoint);
if (!modem)
return FALSE;
if (pmodem_list->Append(modem) == P_MAX_INDEX)
return FALSE;
modem->Resume();
return TRUE;
}
void PseudoModemQ::Enqueue(PseudoModem *modem)
{
myPTRACE((modem != NULL) ? 3 : 1, "T38Modem\tPseudoModemQ::Enqueue "
<< ((modem != NULL) ? modem->ptyName() : "BAD"));
PWaitAndSignal mutexWait(Mutex);
_PseudoModemQ::Enqueue(modem);
}
PBoolean PseudoModemQ::Enqueue(const PString &modemToken)
{
PseudoModem *modem = pmodem_list->Find(modemToken);
if (!modem) {
myPTRACE(1, "T38Modem\tPseudoModemQ::Enqueue BAD token " << modemToken);
return FALSE;
}
Enqueue(modem);
return TRUE;
}
PseudoModem *PseudoModemQ::DequeueWithRoute(const PString &number)
{
PWaitAndSignal mutexWait(Mutex);
PObject *object;
for( PINDEX i = 0 ; (object = ((PCollection*)this)->GetAt(i)) != NULL ; i++ ) {
PAssert(PIsDescendant(object, PseudoModem), PInvalidCast);
PseudoModem *modem = (PseudoModem *)object;
if (modem->CheckRoute(number) && modem->IsReady()) {
if (!Remove(modem))
modem = NULL;
myPTRACE(3, "T38Modem\tPseudoModemQ::DequeueWithRoute "
<< ((modem != NULL) ? modem->ptyName() : "BAD"));
return modem;
}
}
return NULL;
}
PseudoModem *PseudoModemQ::Find(const PString &modemToken) const
{
PObject *object;
for( PINDEX i = 0 ; (object = ((PCollection*)this)->GetAt(i)) != NULL ; i++ ) {
PAssert(PIsDescendant(object, PseudoModem), PInvalidCast);
PseudoModem *modem = (PseudoModem *)object;
if( modem->modemToken() == modemToken ) {
return modem;
}
}
return NULL;
}
PseudoModem *PseudoModemQ::Dequeue(const PString &modemToken)
{
PWaitAndSignal mutexWait(Mutex);
PseudoModem *modem = Find(modemToken);
if (modem != NULL && !Remove(modem))
modem = NULL;
myPTRACE(1, "T38Modem\tPseudoModemQ::Dequeue "
<< ((modem != NULL) ? modem->ptyName() : "BAD"));
return modem;
}
///////////////////////////////////////////////////////////////