OPAL Version 3.10.4

- Main Page
- Related Pages
- Namespaces
- Data Structures
- Files

- File List
- Globals

iax2ep.h
Go to the documentation of this file.
1 /*
2 *
3 * Inter Asterisk Exchange 2
4 *
5 * Open Phone Abstraction Library (OPAL)
6 *
7 * Describes the IAX2 extension of the OpalEndpoint class.
8 *
9 * Copyright (c) 2005 Indranet Technologies Ltd.
10 *
11 * The contents of this file are subject to the Mozilla Public License
12 * Version 1.0 (the "License"); you may not use this file except in
13 * compliance with the License. You may obtain a copy of the License at
14 * http://www.mozilla.org/MPL/
15 *
16 * Software distributed under the License is distributed on an "AS IS"
17 * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
18 * the License for the specific language governing rights and limitations
19 * under the License.
20 *
21 * The Original Code is Open Phone Abstraction Library.
22 *
23 * The Initial Developer of the Original Code is Indranet Technologies Ltd.
24 *
25 * The author of this code is Derek J Smithies
26 *
27 * $Revision: 24719 $
28 * $Author: rjongbloed $
29 * $Date: 2010-09-23 18:55:55 -0500 (Thu, 23 Sep 2010) $
30 */
31
32 #ifndef OPAL_IAX2_IAX2EP_H
33 #define OPAL_IAX2_IAX2EP_H
34
35 #ifndef _PTLIB_H
36 #include <ptlib.h>
37 #endif
38
39 #ifdef P_USE_PRAGMA
40 #pragma interface
41 #endif
42
43 #include <opal/buildopts.h>
44
45 #if OPAL_IAX2
46
47 #include <opal/endpoint.h>
48 #include <iax2/iax2con.h>
49 #include <iax2/processor.h>
50 #include <iax2/regprocessor.h>
51 #include <iax2/specialprocessor.h>
52
53 class IAX2Receiver;
54 class IAX2Transmit;
55 class IAX2Processor;
56
60 class IAX2IncomingEthernetFrames : public PThread
61 {
62 PCLASSINFO(IAX2IncomingEthernetFrames, PThread);
63 public:
64
68 IAX2IncomingEthernetFrames();
69
71 ~IAX2IncomingEthernetFrames() { }
72
75 /*The method which gets everythig to happen */
76 virtual void Main();
77
79 void Assign(IAX2EndPoint *ep);
80
83 void ProcessList() { activate.Signal(); }
84
86 void Terminate();
87
89 protected:
91 IAX2EndPoint *endpoint;
92
94 PSyncPoint activate;
95
97 PBoolean keepGoing;
98 };
99
100
101
102
104 class IAX2EndPoint : public OpalEndPoint
105 {
106 PCLASSINFO(IAX2EndPoint, OpalEndPoint);
107 public:
112 IAX2EndPoint(
113 OpalManager & manager,
114 unsigned short port = 4569
115 );
116
118 ~IAX2EndPoint();
120
127 virtual PBoolean NewIncomingConnection(
128 OpalTransport * transport
129 );
130
160 virtual PSafePtr<OpalConnection> MakeConnection(
161 OpalCall & call,
162 const PString & party,
163 void * userData = NULL,
164 unsigned int options = 0,
165 OpalConnection::StringOptions * stringOptions = NULL
166 );
167
171 virtual IAX2Connection * CreateConnection(
172 OpalCall & call,
173 const PString & token,
174 void * userData,
175 const PString & remoteParty,
176 const PString & remotePartyName = PString::Empty()
177 );
179
184 PBoolean Initialise();
185
187 virtual void IncomingEthernetFrame (IAX2Frame *frame);
188
194 PBoolean ConectionForFrameIsAlive(IAX2Frame *f);
195
202 PINDEX NextSrcCallNumber(IAX2Processor * processor);
203
206 void ReportStoredConnections();
207
209 WORD ListenPortNumber() { return 4569; }
210
212 IAX2Transmit *transmitter;
213
215 IAX2Receiver *receiver;
216
218 PString GetLocalUserName() { return localUserName; }
219
221 PString GetLocalNumber() { return localNumber; }
222
224 void SetLocalUserName(PString newValue);
225
227 void SetLocalNumber(PString newValue);
228
230 PString & GetPassword() { return password; }
231
233 void SetPassword(PString newValue);
234
241 PBoolean ConnectionForFrameIsAlive(IAX2Frame *f);
242
244 PINDEX GetOutSequenceNumberForStatusQuery();
245
247 void StartRinging(PString remoteCaller);
248
260 void NewIncomingConnection(
261 IAX2Frame *f
262 );
263
269 void OnEstablished(
270 OpalConnection & con
271 );
272
278 virtual void OnReleased(
279 OpalConnection & connection
280 );
281
291 virtual OpalMediaFormatList GetMediaFormats() const;
292
294 PINDEX GetSupportedCodecs(OpalMediaFormatList & list);
295
297 PINDEX GetPreferredCodec(OpalMediaFormatList & list);
298
301 void GetCodecLengths(PINDEX src, PINDEX &compressedBytes, PINDEX &duration);
302
308 enum IAX2RemoteAddressFields {
309 protoIndex = 0,
310 userIndex = 1,
311 transportIndex = 2,
312 addressIndex = 3,
313 portIndex = 4,
314 extensionIndex = 5,
315 contextIndex = 6,
316 maximumIndex = 7
317 };
318
325 static PStringArray DissectRemoteParty(const PString & other);
326
330 void ProcessReceivedEthernetFrames();
331
334 void ReportTransmitterLists(PString & answer, bool getFullReport = false);
335
337 void CopyLocalMediaFormats(OpalMediaFormatList & list);
338
344 void Register(
345 const PString & host,
346 const PString & username,
347 const PString & password = PString::Empty(),
348 PINDEX requestedRefreshTime = 60
349 );
350
351 enum RegisteredError {
352 RegisteredFailureUnknown
353 };
354
357 virtual void OnRegistered(
358 const PString & host,
359 const PString & userName,
360 PBoolean isFailure,
361 RegisteredError reason = RegisteredFailureUnknown);
362
365 void Unregister(
366 const PString & host,
367 const PString & username);
368
369 enum UnregisteredError {
370 UnregisteredFailureUnknown
371 };
372
377 virtual void OnUnregistered(
378 const PString & host,
379 const PString & userName,
380 PBoolean isFailure,
381 UnregisteredError reason = UnregisteredFailureUnknown);
382
383
385 PBoolean IsRegistered(const PString & host, const PString & username);
386
388 PINDEX GetRegistrationsCount();
389
391 PString BuildUrl(
392 const PString & host,
393 const PString & userName = PString::Empty(),
394 const PString & extension = PString::Empty(),
395 const PString & context = PString::Empty(),
396 const PString & transport = PString::Empty()
397 );
398
400 PBoolean InitialisedOK() { return (transmitter != NULL) && (receiver != NULL); }
401
404 PBoolean EthernetFramesToBeProcessed()
405 { return packetsReadFromEthernet.GetSize() > 0; }
407
408 protected:
415 IAX2IncomingEthernetFrames incomingFrameHandler;
416
419 IAX2FrameList packetsReadFromEthernet;
420
422 PUDPSocket *sock;
423
425 unsigned short localPort;
426
428 int callnumbs;
429
431 PMutex callNumbLock;
432
434 PTime callStartTime;
435
437 PString localUserName;
438
440 PString localNumber;
441
443 PString password;
444
446 PINDEX statusQueryCounter;
447
449 PMutex statusQueryMutex;
450
453 IAX2SpecialProcessor * specialPacketHandler;
454
462 PBoolean ProcessInMatchingConnection(IAX2Frame *f);
463
472 PBoolean ProcessFrameInConnection(IAX2Frame *f, const PString & token);
473
480 PBoolean ProcessInConnectionTestAll(IAX2Frame *f);
481
494 PStringToString tokenTable;
495
499 PReadWriteMutex mutexTokenTable;
500
503 PAtomicInteger callsEstablished;
504
506 OpalMediaFormatList localMediaFormats;
507
509 PMutex regProcessorsMutex;
510
515 PArrayObjects regProcessors;
516
517 };
518
519
520 #endif // OPAL_IAX2
521
522 #endif // OPAL_IAX2_IAX2EP_H
523
524 /* The comment below is magic for those who use emacs to edit this file.
525 * With the comment below, the tab key does auto indent to 2 spaces.
526 *
527 * Local Variables:
528 * mode:c
529 * c-basic-offset:2
530 * End:
531 */
532