D:/Storage/CVS_Head/h323plus/include/h323neg.h

00001 /*
00002  * h323neg.h
00003  *
00004  * H.323 protocol handler
00005  *
00006  * Open H323 Library
00007  *
00008  * Copyright (c) 1998-2000 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  * $Log: h323neg.h,v $
00030  * Revision 1.1  2007/08/06 20:50:49  shorne
00031  * First commit of h323plus
00032  *
00033  * Revision 1.34.14.1  2007/03/24 23:39:42  shorne
00034  * More H.239 work
00035  *
00036  * Revision 1.34  2002/09/16 01:14:15  robertj
00037  * Added #define so can select if #pragma interface/implementation is used on
00038  *   platform basis (eg MacOS) rather than compiler, thanks Robert Monaghan.
00039  *
00040  * Revision 1.33  2002/09/03 06:19:36  robertj
00041  * Normalised the multi-include header prevention ifdef/define symbol.
00042  *
00043  * Revision 1.32  2002/08/05 10:03:47  robertj
00044  * Cosmetic changes to normalise the usage of pragma interface/implementation.
00045  *
00046  * Revision 1.31  2002/06/26 08:51:16  robertj
00047  * Fixed deadlock if logical channel is closed via H.245 at exactly same
00048  *   time as being closed locally due to a channel I/O error.
00049  *
00050  * Revision 1.30  2002/05/03 03:08:35  robertj
00051  * Added replacementFor field in OLC when resolving conflicting channels.
00052  *
00053  * Revision 1.29  2002/01/09 00:21:36  robertj
00054  * Changes to support outgoing H.245 RequstModeChange.
00055  *
00056  * Revision 1.28  2002/01/01 23:32:30  craigs
00057  * Added HandleAck and StartRequest implementations for T.38
00058  * thanks to Vyacheslav Frolov
00059  *
00060  * Revision 1.27  2002/01/01 23:21:30  craigs
00061  * Added virtual keyword to many functions
00062  *
00063  * Revision 1.26  2001/09/12 01:54:45  robertj
00064  * Added virtual keyword to function in logical channel management.
00065  *
00066  * Revision 1.25  2001/08/06 03:08:11  robertj
00067  * Fission of h323.h to h323ep.h & h323con.h, h323.h now just includes files.
00068  *
00069  * Revision 1.24  2001/05/30 23:34:54  robertj
00070  * Added functions to send TCS=0 for transmitter side pause.
00071  *
00072  * Revision 1.23  2001/03/16 07:11:38  robertj
00073  * Added logical channel open function version without locking.
00074  *
00075  * Revision 1.22  2001/03/14 22:05:24  robertj
00076  * Changed H245NegLogicalChannel::Release() to be virtual protected rather than private.
00077  *
00078  * Revision 1.21  2001/03/14 03:20:25  robertj
00079  * Fixed possible nested mutex deadlock in logical channel negotiator.
00080  *
00081  * Revision 1.20  2001/03/06 04:44:46  robertj
00082  * Fixed problem where could send capability set twice. This should not be
00083  *   a problem except when talking to another broken stack, eg Cisco routers.
00084  *
00085  * Revision 1.19  2001/02/09 05:16:24  robertj
00086  * Added #pragma interface for GNU C++.
00087  *
00088  * Revision 1.18  2000/08/21 12:37:14  robertj
00089  * Fixed race condition if close call just as slow start media channels are opening, part 2.
00090  *
00091  * Revision 1.17  2000/07/14 08:59:56  robertj
00092  * Fixed race condition in closing connection and explicit close logical channel.
00093  *
00094  * Revision 1.16  2000/07/10 16:00:14  robertj
00095  * Added TCS=0 support.
00096  * Fixed bug where negotiations hang if not fast start and tunnelled but remot does not tunnel.
00097  *
00098  * Revision 1.15  2000/05/22 07:32:51  craigs
00099  * Fixed problem with ohphone silence detection hanging
00100  *
00101  * Revision 1.14  2000/05/16 08:13:32  robertj
00102  * Added function to find channel by session ID, supporting H323Connection::FindChannel() with mutex.
00103  *
00104  * Revision 1.13  2000/05/11 04:16:35  robertj
00105  * Fixed missing timeout (and typo!) in bidirectional open logical channel.
00106  *
00107  * Revision 1.12  2000/05/02 04:32:24  robertj
00108  * Fixed copyright notice comment.
00109  *
00110  * Revision 1.11  2000/04/10 17:50:53  robertj
00111  * Fixed yet another race condition needing mutex in logical channels management class.
00112  *
00113  * Revision 1.10  2000/04/05 03:17:30  robertj
00114  * Added more RTP statistics gathering and H.245 round trip delay calculation.
00115  *
00116  * Revision 1.9  2000/03/25 02:19:50  robertj
00117  * Fixed missing mutex call in some logical channels structure access.
00118  *
00119  * Revision 1.8  1999/11/06 11:58:38  robertj
00120  * Changed clean up to delete logical channels before channel destructor is called.
00121  *
00122  * Revision 1.7  1999/11/06 11:00:08  robertj
00123  * Fixed race condition in explicit channel close and connection close.
00124  *
00125  * Revision 1.6  1999/11/06 05:37:44  robertj
00126  * Complete rewrite of termination of connection to avoid numerous race conditions.
00127  *
00128  * Revision 1.5  1999/10/14 12:05:03  robertj
00129  * Fixed deadlock possibilities in clearing calls.
00130  *
00131  * Revision 1.4  1999/09/21 14:03:03  robertj
00132  * Fixed incorrect PTRACING test
00133  *
00134  * Revision 1.3  1999/09/08 04:05:48  robertj
00135  * Added support for video capabilities & codec, still needs the actual codec itself!
00136  *
00137  * Revision 1.2  1999/08/31 12:34:18  robertj
00138  * Added gatekeeper support.
00139  *
00140  * Revision 1.1  1999/08/25 05:07:49  robertj
00141  * File fission (critical mass reached).
00142  *
00143  */
00144 
00145 #ifndef __OPAL_H323NEG_H
00146 #define __OPAL_H323NEG_H
00147 
00148 #ifdef P_USE_PRAGMA
00149 #pragma interface
00150 #endif
00151 
00152 
00153 #include "h323pdu.h"
00154 #include "channels.h"
00155 
00156 
00157 
00159 
00162 class H245Negotiator : public PObject
00163 {
00164   PCLASSINFO(H245Negotiator, PObject);
00165 
00166   public:
00167     H245Negotiator(H323EndPoint & endpoint, H323Connection & connection);
00168 
00169   protected:
00170     PDECLARE_NOTIFIER(PTimer, H245Negotiator, HandleTimeout);
00171 
00172     H323EndPoint   & endpoint;
00173     H323Connection & connection;
00174     PTimer           replyTimer;
00175     PMutex           mutex;
00176 };
00177 
00178 
00181 class H245NegMasterSlaveDetermination : public H245Negotiator
00182 {
00183   PCLASSINFO(H245NegMasterSlaveDetermination, H245Negotiator);
00184 
00185   public:
00186     H245NegMasterSlaveDetermination(H323EndPoint & endpoint, H323Connection & connection);
00187 
00188     BOOL Start(BOOL renegotiate);
00189     void Stop();
00190     BOOL HandleIncoming(const H245_MasterSlaveDetermination & pdu);
00191     BOOL HandleAck(const H245_MasterSlaveDeterminationAck & pdu);
00192     BOOL HandleReject(const H245_MasterSlaveDeterminationReject & pdu);
00193     BOOL HandleRelease(const H245_MasterSlaveDeterminationRelease & pdu);
00194     void HandleTimeout(PTimer &, INT);
00195 
00196     BOOL IsMaster() const     { return status == e_DeterminedMaster; }
00197     BOOL IsDetermined() const { return state == e_Idle && status != e_Indeterminate; }
00198 
00199   protected:
00200     BOOL Restart();
00201 
00202     enum States {
00203       e_Idle, e_Outgoing, e_Incoming,
00204       e_NumStates
00205     } state;
00206 #if PTRACING
00207     static const char * const StateNames[e_NumStates];
00208     friend ostream & operator<<(ostream & o, States s) { return o << StateNames[s]; }
00209 #endif
00210 
00211     DWORD    determinationNumber;
00212     unsigned retryCount;
00213 
00214     enum MasterSlaveStatus {
00215       e_Indeterminate, e_DeterminedMaster, e_DeterminedSlave,
00216       e_NumStatuses
00217     } status;
00218 #if PTRACING
00219     static const char * const StatusNames[e_NumStatuses];
00220     friend ostream & operator<<(ostream & o , MasterSlaveStatus s) { return o << StatusNames[s]; }
00221 #endif
00222 };
00223 
00224 
00227 class H245NegTerminalCapabilitySet : public H245Negotiator
00228 {
00229   PCLASSINFO(H245NegTerminalCapabilitySet, H245Negotiator);
00230 
00231   public:
00232     H245NegTerminalCapabilitySet(H323EndPoint & endpoint, H323Connection & connection);
00233 
00234     BOOL Start(BOOL renegotiate, BOOL empty = FALSE);
00235     void Stop();
00236     BOOL HandleIncoming(const H245_TerminalCapabilitySet & pdu);
00237     BOOL HandleAck(const H245_TerminalCapabilitySetAck & pdu);
00238     BOOL HandleReject(const H245_TerminalCapabilitySetReject & pdu);
00239     BOOL HandleRelease(const H245_TerminalCapabilitySetRelease & pdu);
00240     void HandleTimeout(PTimer &, INT);
00241 
00242     BOOL HasSentCapabilities() const { return state == e_Sent; }
00243     BOOL HasReceivedCapabilities() const { return receivedCapabilites; }
00244 
00245   protected:
00246     enum States {
00247       e_Idle, e_InProgress, e_Sent,
00248       e_NumStates
00249     } state;
00250 #if PTRACING
00251     static const char * const StateNames[e_NumStates];
00252     friend ostream & operator<<(ostream & o, States s) { return o << StateNames[s]; }
00253 #endif
00254 
00255     unsigned inSequenceNumber;
00256     unsigned outSequenceNumber;
00257 
00258     BOOL receivedCapabilites;
00259 };
00260 
00261 
00264 class H245NegLogicalChannel : public H245Negotiator
00265 {
00266   PCLASSINFO(H245NegLogicalChannel, H245Negotiator);
00267 
00268   public:
00269     H245NegLogicalChannel(H323EndPoint & endpoint,
00270                           H323Connection & connection,
00271                           const H323ChannelNumber & channelNumber);
00272     H245NegLogicalChannel(H323EndPoint & endpoint,
00273                           H323Connection & connection,
00274                           H323Channel & channel);
00275     ~H245NegLogicalChannel();
00276 
00277     virtual BOOL Open(
00278       const H323Capability & capability,
00279       unsigned sessionID,
00280       unsigned replacementFor = 0,
00281           unsigned roleLabel = 0
00282     );
00283     virtual BOOL Close();
00284     virtual BOOL HandleOpen(const H245_OpenLogicalChannel & pdu);
00285     virtual BOOL HandleOpenAck(const H245_OpenLogicalChannelAck & pdu);
00286     virtual BOOL HandleOpenConfirm(const H245_OpenLogicalChannelConfirm & pdu);
00287     virtual BOOL HandleReject(const H245_OpenLogicalChannelReject & pdu);
00288     virtual BOOL HandleClose(const H245_CloseLogicalChannel & pdu);
00289     virtual BOOL HandleCloseAck(const H245_CloseLogicalChannelAck & pdu);
00290     virtual BOOL HandleRequestClose(const H245_RequestChannelClose & pdu);
00291     virtual BOOL HandleRequestCloseAck(const H245_RequestChannelCloseAck & pdu);
00292     virtual BOOL HandleRequestCloseReject(const H245_RequestChannelCloseReject & pdu);
00293     virtual BOOL HandleRequestCloseRelease(const H245_RequestChannelCloseRelease & pdu);
00294     virtual void HandleTimeout(PTimer &, INT);
00295 
00296     H323Channel * GetChannel();
00297 
00298 
00299   protected:
00300     virtual BOOL OpenWhileLocked(
00301       const H323Capability & capability,
00302       unsigned sessionID,
00303       unsigned replacementFor = 0,
00304           unsigned roleLabel = 0
00305     );
00306     virtual BOOL CloseWhileLocked();
00307     virtual void Release();
00308 
00309 
00310     H323Channel * channel;
00311 
00312     H323ChannelNumber channelNumber;
00313 
00314     enum States {
00315       e_Released,
00316       e_AwaitingEstablishment,
00317       e_Established,
00318       e_AwaitingRelease,
00319       e_AwaitingConfirmation,
00320       e_AwaitingResponse,
00321       e_NumStates
00322     } state;
00323 #if PTRACING
00324     static const char * const StateNames[e_NumStates];
00325     friend ostream & operator<<(ostream & o, States s) { return o << StateNames[s]; }
00326 #endif
00327 
00328 
00329   friend class H245NegLogicalChannels;
00330 };
00331 
00332 
00333 PDICTIONARY(H245LogicalChannelDict, H323ChannelNumber, H245NegLogicalChannel);
00334 
00337 class H245NegLogicalChannels : public H245Negotiator
00338 {
00339   PCLASSINFO(H245NegLogicalChannels, H245Negotiator);
00340 
00341   public:
00342     H245NegLogicalChannels(H323EndPoint & endpoint, H323Connection & connection);
00343 
00344     virtual void Add(H323Channel & channel);
00345 
00346     virtual BOOL Open(
00347       const H323Capability & capability,
00348       unsigned sessionID,
00349       unsigned replacementFor = 0
00350     );
00351 
00352     virtual BOOL Open(
00353       const H323Capability & capability,
00354       unsigned sessionID,
00355           H323ChannelNumber & channelnumber,
00356       unsigned replacementFor = 0,
00357           unsigned roleLabel = 0
00358     );
00359 
00360     virtual BOOL Close(unsigned channelNumber, BOOL fromRemote);
00361     virtual BOOL HandleOpen(const H245_OpenLogicalChannel & pdu);
00362     virtual BOOL HandleOpenAck(const H245_OpenLogicalChannelAck & pdu);
00363     virtual BOOL HandleOpenConfirm(const H245_OpenLogicalChannelConfirm & pdu);
00364     virtual BOOL HandleReject(const H245_OpenLogicalChannelReject & pdu);
00365     virtual BOOL HandleClose(const H245_CloseLogicalChannel & pdu);
00366     virtual BOOL HandleCloseAck(const H245_CloseLogicalChannelAck & pdu);
00367     virtual BOOL HandleRequestClose(const H245_RequestChannelClose & pdu);
00368     virtual BOOL HandleRequestCloseAck(const H245_RequestChannelCloseAck & pdu);
00369     virtual BOOL HandleRequestCloseReject(const H245_RequestChannelCloseReject & pdu);
00370     virtual BOOL HandleRequestCloseRelease(const H245_RequestChannelCloseRelease & pdu);
00371 
00372     H323ChannelNumber GetNextChannelNumber();
00373     PINDEX GetSize() const { return channels.GetSize(); }
00374     H323Channel * GetChannelAt(PINDEX i);
00375     H323Channel * FindChannel(unsigned channelNumber, BOOL fromRemote);
00376     H245NegLogicalChannel & GetNegLogicalChannelAt(PINDEX i);
00377     H245NegLogicalChannel * FindNegLogicalChannel(unsigned channelNumber, BOOL fromRemote);
00378     H323Channel * FindChannelBySession(unsigned rtpSessionId, BOOL fromRemote);
00379     void RemoveAll();
00380 
00381   protected:
00382     H323ChannelNumber      lastChannelNumber;
00383     H245LogicalChannelDict channels;
00384 };
00385 
00386 
00389 class H245NegRequestMode : public H245Negotiator
00390 {
00391   PCLASSINFO(H245NegRequestMode, H245Negotiator);
00392 
00393   public:
00394     H245NegRequestMode(H323EndPoint & endpoint, H323Connection & connection);
00395 
00396     virtual BOOL StartRequest(const PString & newModes);
00397     virtual BOOL StartRequest(const H245_ArrayOf_ModeDescription & newModes);
00398     virtual BOOL HandleRequest(const H245_RequestMode & pdu);
00399     virtual BOOL HandleAck(const H245_RequestModeAck & pdu);
00400     virtual BOOL HandleReject(const H245_RequestModeReject & pdu);
00401     virtual BOOL HandleRelease(const H245_RequestModeRelease & pdu);
00402     virtual void HandleTimeout(PTimer &, INT);
00403 
00404   protected:
00405     BOOL awaitingResponse;
00406     unsigned inSequenceNumber;
00407     unsigned outSequenceNumber;
00408 };
00409 
00410 
00413 class H245NegRoundTripDelay : public H245Negotiator
00414 {
00415   PCLASSINFO(H245NegRoundTripDelay, H245Negotiator);
00416 
00417   public:
00418     H245NegRoundTripDelay(H323EndPoint & endpoint, H323Connection & connection);
00419 
00420     BOOL StartRequest();
00421     BOOL HandleRequest(const H245_RoundTripDelayRequest & pdu);
00422     BOOL HandleResponse(const H245_RoundTripDelayResponse & pdu);
00423     void HandleTimeout(PTimer &, INT);
00424 
00425     PTimeInterval GetRoundTripDelay() const { return roundTripTime; }
00426     BOOL IsRemoteOffline() const { return retryCount == 0; }
00427 
00428   protected:
00429     BOOL          awaitingResponse;
00430     unsigned      sequenceNumber;
00431     PTimeInterval tripStartTime;
00432     PTimeInterval roundTripTime;
00433     unsigned      retryCount;
00434 };
00435 
00436 
00437 #endif // __OPAL_H323NEG_H
00438 
00439 

Generated on Thu Oct 25 13:42:27 2007 for h323plus by  doxygen 1.5.2