OPAL Version 3.10.2
h323neg.h
Go to the documentation of this file.
00001 /*
00002  * h323neg.h
00003  *
00004  * H.323 protocol handler
00005  *
00006  * Open H323 Library
00007  *
00008  * Copyright (c) 1998-2001 Equivalence Pty. Ltd.
00009  *
00010  * The contents of this file are subject to the Mozilla Public License
00011  * Version 1.0 (the "License"); you may not use this file except in
00012  * compliance with the License. You may obtain a copy of the License at
00013  * http://www.mozilla.org/MPL/
00014  *
00015  * Software distributed under the License is distributed on an "AS IS"
00016  * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
00017  * the License for the specific language governing rights and limitations
00018  * under the License.
00019  *
00020  * The Original Code is Open H323 Library.
00021  *
00022  * The Initial Developer of the Original Code is Equivalence Pty. Ltd.
00023  *
00024  * Portions of this code were written with the assisance of funding from
00025  * Vovida Networks, Inc. http://www.vovida.com.
00026  *
00027  * Contributor(s): ______________________________________.
00028  *
00029  * $Revision: 25091 $
00030  * $Author: rjongbloed $
00031  * $Date: 2011-01-22 12:19:24 -0600 (Sat, 22 Jan 2011) $
00032  */
00033 
00034 #ifndef OPAL_H323_H323NEG_H
00035 #define OPAL_H323_H323NEG_H
00036 
00037 #ifdef P_USE_PRAGMA
00038 #pragma interface
00039 #endif
00040 
00041 #include <opal/buildopts.h>
00042 
00043 #if OPAL_H323
00044 
00045 #include <h323/h323pdu.h>
00046 #include <h323/channels.h>
00047 
00048 
00049 class H323EndPoint;
00050 class H323Connection;
00051 
00052 
00054 
00057 class H245Negotiator : public PObject
00058 {
00059   PCLASSINFO(H245Negotiator, PObject);
00060 
00061   public:
00062     H245Negotiator(H323EndPoint & endpoint, H323Connection & connection);
00063 
00064   protected:
00065     PDECLARE_NOTIFIER(PTimer, H245Negotiator, HandleTimeout);
00066 
00067     H323EndPoint   & endpoint;
00068     H323Connection & connection;
00069     PTimer           replyTimer;
00070 };
00071 
00072 
00075 class H245NegMasterSlaveDetermination : public H245Negotiator
00076 {
00077   PCLASSINFO(H245NegMasterSlaveDetermination, H245Negotiator);
00078 
00079   public:
00080     H245NegMasterSlaveDetermination(H323EndPoint & endpoint, H323Connection & connection);
00081 
00082     PBoolean Start(PBoolean renegotiate);
00083     void Stop();
00084     PBoolean HandleIncoming(const H245_MasterSlaveDetermination & pdu);
00085     PBoolean HandleAck(const H245_MasterSlaveDeterminationAck & pdu);
00086     PBoolean HandleReject(const H245_MasterSlaveDeterminationReject & pdu);
00087     PBoolean HandleRelease(const H245_MasterSlaveDeterminationRelease & pdu);
00088     void HandleTimeout(PTimer &, INT);
00089 
00090     PBoolean IsMaster() const     { return status == e_DeterminedMaster; }
00091     PBoolean IsDetermined() const { return state == e_Idle && status != e_Indeterminate; }
00092 
00093   protected:
00094     PBoolean Restart();
00095 
00096     enum States {
00097       e_Idle, e_Outgoing, e_Incoming,
00098       e_NumStates
00099     } state;
00100 #if PTRACING
00101     static const char * GetStateName(States s);
00102     friend ostream & operator<<(ostream & o, States s) { return o << GetStateName(s); }
00103 #endif
00104 
00105     DWORD    determinationNumber;
00106     unsigned retryCount;
00107 
00108     enum MasterSlaveStatus {
00109       e_Indeterminate, e_DeterminedMaster, e_DeterminedSlave,
00110       e_NumStatuses
00111     } status;
00112 #if PTRACING
00113     static const char * GetStatusName(MasterSlaveStatus s);
00114     friend ostream & operator<<(ostream & o , MasterSlaveStatus s) { return o << GetStatusName(s); }
00115 #endif
00116 };
00117 
00118 
00121 class H245NegTerminalCapabilitySet : public H245Negotiator
00122 {
00123   PCLASSINFO(H245NegTerminalCapabilitySet, H245Negotiator);
00124 
00125   public:
00126     H245NegTerminalCapabilitySet(H323EndPoint & endpoint, H323Connection & connection);
00127 
00128     PBoolean Start(PBoolean renegotiate, PBoolean empty = false);
00129     void Stop(PBoolean dec = false);
00130     PBoolean HandleIncoming(const H245_TerminalCapabilitySet & pdu);
00131     PBoolean HandleAck(const H245_TerminalCapabilitySetAck & pdu);
00132     PBoolean HandleReject(const H245_TerminalCapabilitySetReject & pdu);
00133     PBoolean HandleRelease(const H245_TerminalCapabilitySetRelease & pdu);
00134     void HandleTimeout(PTimer &, INT);
00135 
00136     bool HasSentCapabilities() const { return state >= e_InProgress; }
00137     bool IsSendingCapabilities() const { return state == e_InProgress; }
00138     bool ConfrimedCapabilitiesSent() const { return state == e_Confirmed; }
00139     bool HasReceivedCapabilities() const { return receivedCapabilites; }
00140 
00141   protected:
00142     enum States {
00143       e_Idle, e_InProgress, e_Confirmed,
00144       e_NumStates
00145     } state;
00146 #if PTRACING
00147     static const char * GetStateName(States s);
00148     friend ostream & operator<<(ostream & o, States s) { return o << GetStateName(s); }
00149 #endif
00150 
00151     unsigned inSequenceNumber;
00152     unsigned outSequenceNumber;
00153 
00154     PBoolean receivedCapabilites;
00155 };
00156 
00157 
00160 class H245NegLogicalChannel : public H245Negotiator
00161 {
00162   PCLASSINFO(H245NegLogicalChannel, H245Negotiator);
00163 
00164   public:
00165     H245NegLogicalChannel(H323EndPoint & endpoint,
00166                           H323Connection & connection,
00167                           const H323ChannelNumber & channelNumber);
00168     H245NegLogicalChannel(H323EndPoint & endpoint,
00169                           H323Connection & connection,
00170                           H323Channel & channel);
00171     ~H245NegLogicalChannel();
00172 
00173     virtual PBoolean Open(
00174       const H323Capability & capability,
00175       unsigned sessionID,
00176       unsigned replacementFor = 0
00177     );
00178     virtual PBoolean Close();
00179     virtual PBoolean HandleOpen(const H245_OpenLogicalChannel & pdu);
00180     virtual PBoolean HandleOpenAck(const H245_OpenLogicalChannelAck & pdu);
00181     virtual PBoolean HandleOpenConfirm(const H245_OpenLogicalChannelConfirm & pdu);
00182     virtual PBoolean HandleReject(const H245_OpenLogicalChannelReject & pdu);
00183     virtual PBoolean HandleClose(const H245_CloseLogicalChannel & pdu);
00184     virtual PBoolean HandleCloseAck(const H245_CloseLogicalChannelAck & pdu);
00185     virtual PBoolean HandleRequestClose(const H245_RequestChannelClose & pdu);
00186     virtual PBoolean HandleRequestCloseAck(const H245_RequestChannelCloseAck & pdu);
00187     virtual PBoolean HandleRequestCloseReject(const H245_RequestChannelCloseReject & pdu);
00188     virtual PBoolean HandleRequestCloseRelease(const H245_RequestChannelCloseRelease & pdu);
00189     virtual void HandleTimeout(PTimer &, INT);
00190 
00191     H323Channel * GetChannel();
00192 
00193     bool IsAwaitingEstablishment() const { return state == e_AwaitingEstablishment; }
00194     bool IsEstablished() const { return state == e_Established; }
00195 
00196   protected:
00197     virtual void Release();
00198 
00199 
00200     H323Channel * channel;
00201 
00202     H323ChannelNumber channelNumber;
00203 
00204     enum States {
00205       e_Released,
00206       e_AwaitingEstablishment,
00207       e_Established,
00208       e_AwaitingRelease,
00209       e_AwaitingConfirmation,
00210       e_AwaitingResponse,
00211       e_NumStates
00212     } state;
00213 #if PTRACING
00214     static const char * GetStateName(States s);
00215     friend ostream & operator<<(ostream & o, States s) { return o << GetStateName(s); }
00216 #endif
00217 
00218 
00219   friend class H245NegLogicalChannels;
00220 };
00221 
00222 
00223 PDICTIONARY(H245LogicalChannelDict, H323ChannelNumber, H245NegLogicalChannel);
00224 
00227 class H245NegLogicalChannels : public H245Negotiator
00228 {
00229   PCLASSINFO(H245NegLogicalChannels, H245Negotiator);
00230 
00231   public:
00232     H245NegLogicalChannels(H323EndPoint & endpoint, H323Connection & connection);
00233 
00234     virtual void Add(H323Channel & channel);
00235 
00236     virtual PBoolean Open(
00237       const H323Capability & capability,
00238       unsigned sessionID,
00239       unsigned replacementFor = 0
00240     );
00241     virtual PBoolean Close(unsigned channelNumber, PBoolean fromRemote);
00242     virtual PBoolean HandleOpen(const H245_OpenLogicalChannel & pdu);
00243     virtual PBoolean HandleOpenAck(const H245_OpenLogicalChannelAck & pdu);
00244     virtual PBoolean HandleOpenConfirm(const H245_OpenLogicalChannelConfirm & pdu);
00245     virtual PBoolean HandleReject(const H245_OpenLogicalChannelReject & pdu);
00246     virtual PBoolean HandleClose(const H245_CloseLogicalChannel & pdu);
00247     virtual PBoolean HandleCloseAck(const H245_CloseLogicalChannelAck & pdu);
00248     virtual PBoolean HandleRequestClose(const H245_RequestChannelClose & pdu);
00249     virtual PBoolean HandleRequestCloseAck(const H245_RequestChannelCloseAck & pdu);
00250     virtual PBoolean HandleRequestCloseReject(const H245_RequestChannelCloseReject & pdu);
00251     virtual PBoolean HandleRequestCloseRelease(const H245_RequestChannelCloseRelease & pdu);
00252 
00253     H323ChannelNumber GetNextChannelNumber();
00254     PINDEX GetSize() const { return channels.GetSize(); }
00255     H323Channel * GetChannelAt(PINDEX i);
00256     H323Channel * FindChannel(unsigned channelNumber, PBoolean fromRemote);
00257     H245NegLogicalChannel & GetNegLogicalChannelAt(PINDEX i);
00258     H245NegLogicalChannel * FindNegLogicalChannel(unsigned channelNumber, PBoolean fromRemote);
00259     H323Channel * FindChannelBySession(unsigned rtpSessionId, PBoolean fromRemote);
00260     void RemoveAll();
00261 
00262   protected:
00263     H323ChannelNumber      lastChannelNumber;
00264     H245LogicalChannelDict channels;
00265 };
00266 
00267 
00270 class H245NegRequestMode : public H245Negotiator
00271 {
00272   PCLASSINFO(H245NegRequestMode, H245Negotiator);
00273 
00274   public:
00275     H245NegRequestMode(H323EndPoint & endpoint, H323Connection & connection);
00276 
00277     virtual PBoolean StartRequest(const PString & newModes);
00278     virtual PBoolean StartRequest(const H245_ArrayOf_ModeDescription & newModes);
00279     virtual PBoolean HandleRequest(const H245_RequestMode & pdu);
00280     virtual PBoolean HandleAck(const H245_RequestModeAck & pdu);
00281     virtual PBoolean HandleReject(const H245_RequestModeReject & pdu);
00282     virtual PBoolean HandleRelease(const H245_RequestModeRelease & pdu);
00283     virtual void HandleTimeout(PTimer &, INT);
00284 
00285   protected:
00286     PBoolean awaitingResponse;
00287     unsigned inSequenceNumber;
00288     unsigned outSequenceNumber;
00289 };
00290 
00291 
00294 class H245NegRoundTripDelay : public H245Negotiator
00295 {
00296   PCLASSINFO(H245NegRoundTripDelay, H245Negotiator);
00297 
00298   public:
00299     H245NegRoundTripDelay(H323EndPoint & endpoint, H323Connection & connection);
00300 
00301     PBoolean StartRequest();
00302     PBoolean HandleRequest(const H245_RoundTripDelayRequest & pdu);
00303     PBoolean HandleResponse(const H245_RoundTripDelayResponse & pdu);
00304     void HandleTimeout(PTimer &, INT);
00305 
00306     PTimeInterval GetRoundTripDelay() const { return roundTripTime; }
00307     PBoolean IsRemoteOffline() const { return retryCount == 0; }
00308 
00309   protected:
00310     PBoolean          awaitingResponse;
00311     unsigned      sequenceNumber;
00312     PTimeInterval tripStartTime;
00313     PTimeInterval roundTripTime;
00314     unsigned      retryCount;
00315 };
00316 
00317 
00318 #endif // OPAL_H323
00319 
00320 #endif // OPAL_H323_H323NEG_H
00321 
00322