forked from T38Modem/t38modem
-
Notifications
You must be signed in to change notification settings - Fork 0
/
enginebase.h
251 lines (215 loc) · 6.64 KB
/
enginebase.h
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
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
/*
* enginebase.h
*
* T38FAX Pseudo Modem
*
* Copyright (c) 2007-2010 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):
*
* $Log: enginebase.h,v $
* Revision 1.14 2010-10-12 16:46:25 vfrolov
* Implemented fake streams
*
* Revision 1.14 2010/10/12 16:46:25 vfrolov
* Implemented fake streams
*
* Revision 1.13 2010/10/08 06:04:59 vfrolov
* Added diagErrorMask
*
* Revision 1.12 2010/10/06 16:54:19 vfrolov
* Redesigned engine opening/closing
*
* Revision 1.11 2010/09/29 11:52:59 vfrolov
* Redesigned engine attaching/detaching
*
* Revision 1.10 2010/09/22 15:07:45 vfrolov
* Added ResetModemState() and OnResetModemState()
*
* Revision 1.9 2010/09/08 17:22:23 vfrolov
* Redesigned modem engine (continue)
*
* Revision 1.8 2010/07/07 08:09:47 vfrolov
* Added IsAttached()
*
* Revision 1.7 2010/03/18 08:42:17 vfrolov
* Added named tracing of data types
*
* Revision 1.6 2009/11/19 14:48:28 vfrolov
* Moved common code to class EngineBase
*
* Revision 1.5 2009/11/19 11:14:04 vfrolov
* Added OnUserInput
*
* Revision 1.4 2009/11/18 19:08:47 vfrolov
* Moved common code to class EngineBase
*
* Revision 1.3 2008/09/10 11:15:00 frolov
* Ported to OPAL SVN trunk
*
* Revision 1.2 2007/04/09 08:07:12 vfrolov
* Added symbolic logging ModemCallbackParam
*
* Revision 1.1 2007/03/23 09:54:45 vfrolov
* Initial revision
*
*/
#ifndef _ENGINEBASE_H
#define _ENGINEBASE_H
///////////////////////////////////////////////////////////////
class DataStream;
///////////////////////////////////////////////////////////////
class ReferenceObject : public PObject
{
PCLASSINFO(ReferenceObject, PObject);
public:
ReferenceObject() : referenceCount(1) {}
void AddReference() {
PWaitAndSignal mutex(referenceCountMutex);
++referenceCount;
}
static void DelPointer(ReferenceObject * object) {
PBoolean doDelele;
object->referenceCountMutex.Wait();
doDelele = (--object->referenceCount == 0);
object->referenceCountMutex.Signal();
if (doDelele)
delete object;
}
private:
PMutex referenceCountMutex;
unsigned referenceCount;
};
///////////////////////////////////////////////////////////////
class EngineBase : public ReferenceObject
{
PCLASSINFO(EngineBase, ReferenceObject);
private:
class OWNERIN { int unused; };
class OWNEROUT { int unused; };
public:
typedef const OWNERIN *HOWNERIN;
typedef const OWNEROUT *HOWNEROUT;
public:
/**@name Construction */
//@{
EngineBase(const PString &_name = "");
virtual ~EngineBase();
//@}
enum {
diagNoCarrier = 0x0001,
diagOutOfOrder = 0x0100,
diagDiffSig = 0x0400, // a different signal is detected
diagBadFcs = 0x0800,
diagError = 0x8000, // bad usage
diagErrorMask = 0xFF00,
};
enum DataType {
dtNone,
dtRing,
dtBusy,
dtCed,
dtCng,
dtSilence,
dtHdlc,
dtRaw,
};
enum ModemCallbackParam {
cbpUserDataMask = 0xFF,
cbpOutBufNoFull = 256,
cbpUpdateState = 257,
cbpReset = -1,
cbpOutBufEmpty = -2,
cbpUserInput = -3,
};
enum ModemClass {
mcUndefined,
mcFax,
};
/**@name Modem API */
//@{
const PString &Name() const { return name; }
PBoolean Attach(const PNotifier &callback);
void Detach(const PNotifier &callback);
void ResetModemState();
void OpenIn(HOWNERIN hOwner, PBoolean fake = FALSE);
void OpenOut(HOWNEROUT hOwner, PBoolean fake = FALSE);
void CloseIn(HOWNERIN hOwner);
void CloseOut(HOWNEROUT hOwner);
void EnableFakeIn(PBoolean enable = TRUE);
void EnableFakeOut(PBoolean enable = TRUE);
PBoolean IsOpenIn() const { return hOwnerIn != NULL; }
PBoolean IsOpenOut() const { return hOwnerOut != NULL; }
PBoolean TryLockModemCallback();
void UnlockModemCallback();
void ChangeModemClass(ModemClass newModemClass);
void WriteUserInput(const PString & value);
int RecvUserInput(void * pBuf, PINDEX count);
virtual void SendOnIdle(DataType /*_dataType*/) {}
virtual PBoolean SendStart(DataType _dataType, int param) = 0;
virtual int Send(const void *pBuf, PINDEX count) = 0;
virtual PBoolean SendStop(PBoolean moreFrames, int _callbackParam) = 0;
virtual PBoolean isOutBufFull() const = 0;
virtual PBoolean SendingNotCompleted() const { return FALSE; }
virtual void RecvOnIdle(DataType /*_dataType*/) {}
virtual PBoolean RecvWait(DataType _dataType, int param, int _callbackParam, PBoolean &done) = 0;
virtual PBoolean RecvStart(int _callbackParam) = 0;
virtual int Recv(void *pBuf, PINDEX count) = 0;
virtual void RecvStop() = 0;
virtual int RecvDiag() const { return 0; };
//@}
protected:
PBoolean IsModemOpen() const { return !modemCallback.IsNULL(); }
virtual void OnAttach();
virtual void OnDetach();
virtual void OnResetModemState();
virtual void OnChangeModemClass();
virtual void OnUserInput(const PString & value);
virtual void OnOpenIn();
virtual void OnOpenOut();
virtual void OnCloseIn();
virtual void OnCloseOut();
virtual void OnChangeEnableFakeIn();
virtual void OnChangeEnableFakeOut();
const PString name;
DataStream *volatile recvUserInput;
ModemClass modemClass;
volatile HOWNERIN hOwnerIn;
volatile HOWNEROUT hOwnerOut;
PBoolean firstIn;
PBoolean firstOut;
PBoolean isFakeOwnerIn;
PBoolean isFakeOwnerOut;
PBoolean isEnableFakeIn;
PBoolean isEnableFakeOut;
void ModemCallbackWithUnlock(INT extra);
PNotifier modemCallback;
PTimedMutex MutexModemCallback;
PMutex MutexModem;
PMutex MutexIn;
PMutex MutexOut;
PMutex Mutex;
};
#if PTRACING
ostream & operator<<(ostream & out, EngineBase::DataType dataType);
ostream & operator<<(ostream & out, EngineBase::ModemCallbackParam param);
ostream & operator<<(ostream & out, EngineBase::ModemClass modemClass);
#endif
///////////////////////////////////////////////////////////////
#endif // _ENGINEBASE_H