OPAL  Version 3.14.3
h323neg.h
Go to the documentation of this file.
1 /*
2  * h323neg.h
3  *
4  * H.323 protocol handler
5  *
6  * Open H323 Library
7  *
8  * Copyright (c) 1998-2001 Equivalence Pty. Ltd.
9  *
10  * The contents of this file are subject to the Mozilla Public License
11  * Version 1.0 (the "License"); you may not use this file except in
12  * compliance with the License. You may obtain a copy of the License at
13  * http://www.mozilla.org/MPL/
14  *
15  * Software distributed under the License is distributed on an "AS IS"
16  * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
17  * the License for the specific language governing rights and limitations
18  * under the License.
19  *
20  * The Original Code is Open H323 Library.
21  *
22  * The Initial Developer of the Original Code is Equivalence Pty. Ltd.
23  *
24  * Portions of this code were written with the assisance of funding from
25  * Vovida Networks, Inc. http://www.vovida.com.
26  *
27  * Contributor(s): ______________________________________.
28  *
29  * $Revision: 31462 $
30  * $Author: rjongbloed $
31  * $Date: 2014-02-14 15:47:20 +1100 (Fri, 14 Feb 2014) $
32  */
33 
34 #ifndef OPAL_H323_H323NEG_H
35 #define OPAL_H323_H323NEG_H
36 
37 #ifdef P_USE_PRAGMA
38 #pragma interface
39 #endif
40 
41 #include <opal_config.h>
42 
43 #if OPAL_H323
44 
45 #include <h323/h323pdu.h>
46 #include <h323/channels.h>
47 
48 
49 class H323EndPoint;
50 class H323Connection;
51 
52 
54 
57 class H245Negotiator : public PObject
58 {
59  PCLASSINFO(H245Negotiator, PObject);
60 
61  public:
63 
64  protected:
65  PDECLARE_NOTIFIER(PTimer, H245Negotiator, HandleTimeoutUnlocked);
66  virtual void HandleTimeout();
67 
70  PTimer replyTimer;
71 };
72 
73 
77 {
79 
80  public:
82 
83  PBoolean Start(PBoolean renegotiate);
84  void Stop();
85  PBoolean HandleIncoming(const H245_MasterSlaveDetermination & pdu);
86  PBoolean HandleAck(const H245_MasterSlaveDeterminationAck & pdu);
87  PBoolean HandleReject(const H245_MasterSlaveDeterminationReject & pdu);
88  PBoolean HandleRelease(const H245_MasterSlaveDeterminationRelease & pdu);
89  void HandleTimeout();
90 
91  PBoolean IsMaster() const { return m_status == e_DeterminedMaster; }
92  PBoolean IsDetermined() const { return m_status != e_Indeterminate; }
93 
94  protected:
95  PBoolean Restart();
96 
97  P_DECLARE_TRACED_ENUM(States, e_Idle, e_Outgoing, e_Incoming);
98  States m_state;
99 
101  unsigned m_retryCount;
102 
103  P_DECLARE_TRACED_ENUM(MasterSlaveStatus, e_Indeterminate, e_DeterminedMaster, e_DeterminedSlave);
104  MasterSlaveStatus m_status;
105 };
106 
107 
111 {
113 
114  public:
116 
117  PBoolean Start(PBoolean renegotiate, PBoolean empty = false);
118  void Stop(PBoolean dec = false);
119  PBoolean HandleIncoming(const H245_TerminalCapabilitySet & pdu);
120  PBoolean HandleAck(const H245_TerminalCapabilitySetAck & pdu);
121  PBoolean HandleReject(const H245_TerminalCapabilitySetReject & pdu);
122  PBoolean HandleRelease(const H245_TerminalCapabilitySetRelease & pdu);
123  void HandleTimeout();
124 
125  bool HasSentCapabilities() const { return state >= e_InProgress; }
126  bool IsSendingCapabilities() const { return state == e_InProgress; }
127  bool ConfrimedCapabilitiesSent() const { return state == e_Confirmed; }
129 
130  protected:
131  P_DECLARE_TRACED_ENUM(States, e_Idle, e_InProgress, e_Confirmed);
132  States state;
133 
136 
138 };
139 
140 
144 {
146 
147  public:
152  H323Connection & connection,
153  H323Channel & channel);
155 
156  virtual PBoolean Open(
157  const H323Capability & capability,
158  unsigned sessionID,
159  unsigned replacementFor = 0,
160  OpalMediaStreamPtr mediaStream = NULL
161  );
162  virtual PBoolean Close();
163  virtual PBoolean HandleOpen(const H245_OpenLogicalChannel & pdu);
164  virtual PBoolean HandleOpenAck(const H245_OpenLogicalChannelAck & pdu);
165  virtual PBoolean HandleOpenConfirm(const H245_OpenLogicalChannelConfirm & pdu);
166  virtual PBoolean HandleReject(const H245_OpenLogicalChannelReject & pdu);
167  virtual PBoolean HandleClose(const H245_CloseLogicalChannel & pdu);
168  virtual PBoolean HandleCloseAck(const H245_CloseLogicalChannelAck & pdu);
169  virtual PBoolean HandleRequestClose(const H245_RequestChannelClose & pdu);
170  virtual PBoolean HandleRequestCloseAck(const H245_RequestChannelCloseAck & pdu);
171  virtual PBoolean HandleRequestCloseReject(const H245_RequestChannelCloseReject & pdu);
172  virtual PBoolean HandleRequestCloseRelease(const H245_RequestChannelCloseRelease & pdu);
173  virtual void HandleTimeout();
174 
175  H323Channel * GetChannel() const;
176 
177  bool IsAwaitingEstablishment() const { return state == e_AwaitingEstablishment || state == e_Establishing; }
178  bool IsEstablished() const { return state == e_Established; }
179 
180  protected:
181  virtual void Release();
182 
183 
185 
187 
188  P_DECLARE_TRACED_ENUM(States,
189  e_Released,
190  e_AwaitingEstablishment,
191  e_Establishing,
192  e_Established,
193  e_AwaitingRelease,
194  e_AwaitingConfirmation,
195  e_AwaitingResponse,
196  e_NumStates
197  );
198  States state;
199 
201 };
202 
203 
204 PDICTIONARY(H245LogicalChannelDict, H323ChannelNumber, H245NegLogicalChannel);
205 
209 {
211 
212  public:
214 
215  virtual void Add(H323Channel & channel);
216 
217  virtual PBoolean Open(
218  const H323Capability & capability,
219  unsigned sessionID,
220  unsigned replacementFor = 0,
221  OpalMediaStreamPtr mediaStream = NULL
222  );
223  virtual PBoolean Close(unsigned channelNumber, PBoolean fromRemote);
224  virtual PBoolean HandleOpen(const H245_OpenLogicalChannel & pdu);
225  virtual PBoolean HandleOpenAck(const H245_OpenLogicalChannelAck & pdu);
226  virtual PBoolean HandleOpenConfirm(const H245_OpenLogicalChannelConfirm & pdu);
227  virtual PBoolean HandleReject(const H245_OpenLogicalChannelReject & pdu);
228  virtual PBoolean HandleClose(const H245_CloseLogicalChannel & pdu);
229  virtual PBoolean HandleCloseAck(const H245_CloseLogicalChannelAck & pdu);
230  virtual PBoolean HandleRequestClose(const H245_RequestChannelClose & pdu);
231  virtual PBoolean HandleRequestCloseAck(const H245_RequestChannelCloseAck & pdu);
232  virtual PBoolean HandleRequestCloseReject(const H245_RequestChannelCloseReject & pdu);
233  virtual PBoolean HandleRequestCloseRelease(const H245_RequestChannelCloseRelease & pdu);
234 
236  H245LogicalChannelDict & GetChannels() { return channels; }
237  const H245LogicalChannelDict & GetChannels() const { return channels; }
238  H323Channel * FindChannel(unsigned channelNumber, PBoolean fromRemote);
239  H245NegLogicalChannel * FindNegLogicalChannel(unsigned channelNumber, PBoolean fromRemote);
240  H323Channel * FindChannelBySession(unsigned rtpSessionId, PBoolean fromRemote);
241  void RemoveAll();
242 
243  protected:
245  H245LogicalChannelDict channels;
246 };
247 
248 
252 {
253  PCLASSINFO(H245NegRequestMode, H245Negotiator);
254 
255  public:
257 
258  virtual PBoolean StartRequest(const PString & newModes);
259  virtual PBoolean StartRequest(const H245_ArrayOf_ModeDescription & newModes);
260  virtual PBoolean HandleRequest(const H245_RequestMode & pdu);
261  virtual PBoolean HandleAck(const H245_RequestModeAck & pdu);
262  virtual PBoolean HandleReject(const H245_RequestModeReject & pdu);
263  virtual PBoolean HandleRelease(const H245_RequestModeRelease & pdu);
264  virtual void HandleTimeout();
265 
266  protected:
270 };
271 
272 
276 {
278 
279  public:
281 
282  PBoolean StartRequest();
283  PBoolean HandleRequest(const H245_RoundTripDelayRequest & pdu);
284  PBoolean HandleResponse(const H245_RoundTripDelayResponse & pdu);
285  void HandleTimeout();
286 
287  PTimeInterval GetRoundTripDelay() const { return roundTripTime; }
288  PBoolean IsRemoteOffline() const { return retryCount == 0; }
289 
290  protected:
292  unsigned sequenceNumber;
293  PTimeInterval tripStartTime;
294  PTimeInterval roundTripTime;
295  unsigned retryCount;
296 };
297 
298 
299 #endif // OPAL_H323
300 
301 #endif // OPAL_H323_H323NEG_H
302 
303