Major rework of how SIP utilises sockets, using new "socket bundling" subsystem.
[opal/cbnco.git] / include / iax2 / transmit.h
blobc04e799846dfc43b32fc0ab83f03ca6bca86a35a
1 /*
4 * Inter Asterisk Exchange 2
5 *
6 * Class definition for describing the entity that sends all packets
7 * for all calls
8 *
9 * Open Phone Abstraction Library (OPAL)
11 * Copyright (c) 2005 Indranet Technologies Ltd.
13 * The contents of this file are subject to the Mozilla Public License
14 * Version 1.0 (the "License"); you may not use this file except in
15 * compliance with the License. You may obtain a copy of the License at
16 * http://www.mozilla.org/MPL/
18 * Software distributed under the License is distributed on an "AS IS"
19 * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
20 * the License for the specific language governing rights and limitations
21 * under the License.
23 * The Original Code is Open Phone Abstraction Library.
25 * The Initial Developer of the Original Code is Indranet Technologies Ltd.
27 * The author of this code is Derek J Smithies
29 * $Log$
30 * Revision 1.6 2007/04/19 06:17:21 csoutheren
31 * Fixes for precompiled headers with gcc
33 * Revision 1.5 2007/01/23 02:08:25 dereksmithies
34 * Handle Vnak frames correctly. handle iseqno and oseqno correctly.
36 * Revision 1.4 2007/01/09 03:32:23 dereksmithies
37 * Tidy up and improve the close down process - make it more robust.
38 * Alter level of several PTRACE statements. Add Terminate() method to transmitter and receiver.
40 * Revision 1.3 2006/06/16 01:47:08 dereksmithies
41 * Get the OnHold features of IAX2 to work correctly.
42 * Thanks to Stephen Cook, (sitiveni@gmail.com) for this work.
44 * Revision 1.2 2005/08/26 03:07:38 dereksmithies
45 * Change naming convention, so all class names contain the string "IAX2"
47 * Revision 1.1 2005/07/30 07:01:32 csoutheren
48 * Added implementation of IAX2 (Inter Asterisk Exchange 2) protocol
49 * Thanks to Derek Smithies of Indranet Technologies Ltd. for
50 * writing and contributing this code
57 #ifndef TRANSMIT_H
58 #define TRANSMIT_H
60 #ifndef _PTLIB_H
61 #include <ptlib.h>
62 #endif
64 #include <ptlib/sockets.h>
66 #include <iax2/frame.h>
67 #include <iax2/iax2ep.h>
69 #ifdef P_USE_PRAGMA
70 #pragma interface
71 #endif
73 /**Manage the transmission of ethernet packets on the specified
74 port. All transmitted packets are received from any of the current
75 connections. A separate thread is used to wait on the request to
76 send packets. Full frame packets, which have been resent the
77 requisite number of times are deleted. This class will
78 (eventually) delete all the frames it is given.
80 Note that this class is a thread, and runs when activated by outside
81 events.*/
82 class IAX2Transmit : public PThread
84 PCLASSINFO(IAX2Transmit, PThread);
85 public:
86 /**@name Construction/destruction*/
87 //@{
89 /**
90 Constructor, which creates a thread to send all packets on the
91 designated socket. */
92 IAX2Transmit(IAX2EndPoint & _newEndpoint, PUDPSocket & _newSocket);
94 /**
95 Destructor. Deletes all pending packets.
97 ~IAX2Transmit();
98 //@}
100 /**@name Worker methods*/
101 //@{
103 /**Cause this thread to end now */
104 virtual void Terminate();
106 /**Queue a frame for delivery. This is called by a connection, and then
107 the transmit thread is woken up.
109 void SendFrame(IAX2Frame *newFrame);
111 /**Activate the transmit thread to process all frames in the lists
113 void ProcessLists() { activate.Signal(); }
115 /**An Ack has been received..
116 Delete the matching frame from the queue waiting for an ack
118 void AckReceived();
120 /**Do the work of the thread here. Read all lists and check for
121 frames to send/delete.*/
122 virtual void Main();
124 /** A full frame was transmitted a while ago, and the receiver has replied
125 with a suitable acknowledgement. The acknowledgment (the newFrame) means
126 that matching frames in the ack list should be removed.
128 void PurgeMatchingFullFrames(IAX2Frame *frame);
130 /** A Vnak frame has been received (voice not acknowledged) which actually
131 means, retransmit all those frames you have on this particular call
132 number from the oseqno specified in the supplied frame */
133 void SendVnakRequestedFrames(IAX2FullFrameProtocol &src);
135 /** Report on the contents of the lists waiting for transmission */
136 void ReportLists();
137 //@}
139 protected:
141 /**Go through the acking list:: delete those who have too many
142 retries, and transmit those who need retransmitting */
143 void ProcessAckingList();
145 /**Go through the send list:: send all frames on this list */
146 void ProcessSendList();
148 /**Global variable specifying application specific variables */
149 IAX2EndPoint &ep;
151 /**Network socket used to transmit packets*/
152 PUDPSocket & sock;
154 /**Flag to activate this thread*/
155 PSyncPoint activate;
157 /**Frames in the acking list - These frames are waiting on an ack*/
158 IAX2FrameList ackingFrames;
160 /**Send Now list of frames - These frames are to be sent now */
161 IAX2FrameList sendNowFrames;
163 /**Flag to indicate that this thread should keep working */
164 BOOL keepGoing;
167 #endif // IAX2_TRANSMIT_H
168 /* The comment below is magic for those who use emacs to edit this file. */
169 /* With the comment below, the tab key does auto indent to 4 spaces. */
172 * Local Variables:
173 * mode:c
174 * c-file-style:linux
175 * c-basic-offset:2
176 * End: