endpoint.h

Go to the documentation of this file.
00001 /*
00002  * endpoint.h
00003  *
00004  * Telephony endpoint abstraction
00005  *
00006  * Open Phone Abstraction Library (OPAL)
00007  * Formally known as the Open H323 project.
00008  *
00009  * Copyright (c) 2001 Equivalence Pty. Ltd.
00010  *
00011  * The contents of this file are subject to the Mozilla Public License
00012  * Version 1.0 (the "License"); you may not use this file except in
00013  * compliance with the License. You may obtain a copy of the License at
00014  * http://www.mozilla.org/MPL/
00015  *
00016  * Software distributed under the License is distributed on an "AS IS"
00017  * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
00018  * the License for the specific language governing rights and limitations
00019  * under the License.
00020  *
00021  * The Original Code is Open Phone Abstraction Library.
00022  *
00023  * The Initial Developer of the Original Code is Equivalence Pty. Ltd.
00024  *
00025  * Contributor(s): ______________________________________.
00026  *
00027  * $Log: endpoint.h,v $
00028  * Revision 2.50  2007/09/21 01:34:09  rjongbloed
00029  * Rewrite of SIP transaction handling to:
00030  *   a) use PSafeObject and safe collections
00031  *   b) only one database of transactions, remove connection copy
00032  *   c) fix timers not always firing due to bogus deadlock avoidance
00033  *   d) cleaning up only occurs in the existing garbage collection thread
00034  *   e) use of read/write mutex on endpoint list to avoid possible deadlock
00035  *
00036  * Revision 2.49  2007/06/29 06:59:56  rjongbloed
00037  * Major improvement to the "product info", normalising H.221 and User-Agent mechanisms.
00038  *
00039  * Revision 2.48  2007/05/15 07:26:38  csoutheren
00040  * Remove deprecated  interface to STUN server in H323Endpoint
00041  * Change UseNATForIncomingCall to IsRTPNATEnabled
00042  * Various cleanups of messy and unused code
00043  *
00044  * Revision 2.47  2007/05/15 05:24:50  csoutheren
00045  * Add UseNATForIncomingCall override so applications can optionally implement their own NAT activation strategy
00046  *
00047  * Revision 2.46  2007/03/29 23:55:46  rjongbloed
00048  * Tidied some code when a new connection is created by an endpoint. Now
00049  *   if someone needs to derive a connection class they can create it without
00050  *   needing to remember to do any more than the new.
00051  *
00052  * Revision 2.45  2007/03/21 06:15:57  rjongbloed
00053  * Added functions to find an active comms listener for an interface,
00054  *    and remove/stop it.
00055  *
00056  * Revision 2.44  2007/03/13 00:32:16  csoutheren
00057  * Simple but messy changes to allow compile time removal of protocol
00058  * options such as H.450 and H.460
00059  * Fix MakeConnection overrides
00060  *
00061  * Revision 2.43  2007/03/01 05:51:04  rjongbloed
00062  * Fixed backward compatibility of OnIncomingConnection() virtual
00063  *   functions on various classes. If an old override returned FALSE
00064  *   then it will now abort the call as it used to.
00065  *
00066  * Revision 2.42  2007/01/24 04:00:56  csoutheren
00067  * Arrrghh. Changing OnIncomingConnection turned out to have a lot of side-effects
00068  * Added some pure viritual functions to prevent old code from breaking silently
00069  * New OpalEndpoint and OpalConnection descendants will need to re-implement
00070  * OnIncomingConnection. Sorry :)
00071  *
00072  * Revision 2.41  2007/01/23 00:59:40  csoutheren
00073  * Fix problem with providing backwards compatible overrides for OpalEndpoint::MakeConnection
00074  *
00075  * Revision 2.40  2007/01/18 04:45:16  csoutheren
00076  * Messy, but simple change to add additional options argument to OpalConnection constructor
00077  * This allows the provision of non-trivial arguments for connections
00078  *
00079  * Revision 2.39  2006/12/18 03:18:41  csoutheren
00080  * Messy but simple fixes
00081  *   - Add access to SIP REGISTER timeout
00082  *   - Ensure OpalConnection options are correctly progagated
00083  *
00084  * Revision 2.38  2006/12/08 05:10:43  csoutheren
00085  * Applied 1608002 - Callback for OpalTransportUDP multiple interface handling
00086  * Thanks to Hannes Friederich
00087  *
00088  * Revision 2.37  2006/11/20 03:37:12  csoutheren
00089  * Allow optional inclusion of RTP aggregation
00090  *
00091  * Revision 2.36  2006/11/19 06:02:57  rjongbloed
00092  * Moved function that reads User Input into a destination address to
00093  *   OpalManager so can be easily overidden in applications.
00094  *
00095  * Revision 2.35  2006/10/10 07:18:18  csoutheren
00096  * Allow compilation with and without various options
00097  *
00098  * Revision 2.34  2006/09/28 07:42:17  csoutheren
00099  * Merge of useful SRTP implementation
00100  *
00101  * Revision 2.33  2006/08/21 05:29:25  csoutheren
00102  * Messy but relatively simple change to add support for secure (SSL/TLS) TCP transport
00103  * and secure H.323 signalling via the sh323 URL scheme
00104  *
00105  * Revision 2.32  2006/05/30 04:58:06  csoutheren
00106  * Added suport for SIP INFO message (untested as yet)
00107  * Fixed some issues with SIP state machine on answering calls
00108  * Fixed some formatting issues
00109  *
00110  * Revision 2.31  2006/04/20 16:52:22  hfriederich
00111  * Adding support for H.224/H.281
00112  *
00113  * Revision 2.30  2006/02/22 10:40:09  csoutheren
00114  * Added patch #1374583 from Frederic Heem
00115  * Added additional H.323 virtual function
00116  *
00117  * Revision 2.29  2005/11/30 13:35:26  csoutheren
00118  * Changed tags for Doxygen
00119  *
00120  * Revision 2.28  2005/10/08 19:26:37  dsandras
00121  * Added OnForwarded callback in case of call forwarding.
00122  *
00123  * Revision 2.27  2005/08/24 10:43:51  rjongbloed
00124  * Changed create video functions yet again so can return pointers that are not to be deleted.
00125  *
00126  * Revision 2.26  2005/08/23 12:45:09  rjongbloed
00127  * Fixed creation of video preview window and setting video grab/display initial frame size.
00128  *
00129  * Revision 2.25  2005/07/14 08:51:18  csoutheren
00130  * Removed CreateExternalRTPAddress - it's not needed because you can override GetMediaAddress
00131  * to do the same thing
00132  * Fixed problems with logic associated with media bypass
00133  *
00134  * Revision 2.24  2005/07/11 06:52:16  csoutheren
00135  * Added support for outgoing calls using external RTP
00136  *
00137  * Revision 2.23  2005/07/11 01:52:23  csoutheren
00138  * Extended AnsweringCall to work for SIP as well as H.323
00139  * Fixed problems with external RTP connection in H.323
00140  * Added call to OnClosedMediaStream
00141  *
00142  * Revision 2.22  2005/04/10 20:45:22  dsandras
00143  * Added callback that is called when a connection is put on hold (locally or remotely).
00144  *
00145  * Revision 2.21  2004/08/14 07:56:29  rjongbloed
00146  * Major revision to utilise the PSafeCollection classes for the connections and calls.
00147  *
00148  * Revision 2.20  2004/07/11 12:42:10  rjongbloed
00149  * Added function on endpoints to get the list of all media formats any
00150  *   connection the endpoint may create can support.
00151  *
00152  * Revision 2.19  2004/04/26 06:30:32  rjongbloed
00153  * Added ability to specify more than one defualt listener for an endpoint,
00154  *   required by SIP which listens on both UDP and TCP.
00155  *
00156  * Revision 2.18  2004/03/13 06:25:52  rjongbloed
00157  * Slight rearrangement of local party name and alias list to beter match common
00158  *   behaviour in ancestor.
00159  * Abstracted local party name for endpoint into ancestor from H.,323.
00160  *
00161  * Revision 2.17  2004/03/11 06:54:27  csoutheren
00162  * Added ability to disable SIP or H.323 stacks
00163  *
00164  * Revision 2.16  2004/02/19 10:46:44  rjongbloed
00165  * Merged OpenH323 version 1.13.1 changes.
00166  *
00167  * Revision 2.15  2003/03/17 10:26:59  robertj
00168  * Added video support.
00169  *
00170  * Revision 2.14  2003/03/06 03:57:47  robertj
00171  * IVR support (work in progress) requiring large changes everywhere.
00172  *
00173  * Revision 2.13  2002/11/10 11:33:17  robertj
00174  * Updated to OpenH323 v1.10.3
00175  *
00176  * Revision 2.12  2002/09/16 02:52:35  robertj
00177  * Added #define so can select if #pragma interface/implementation is used on
00178  *   platform basis (eg MacOS) rather than compiler, thanks Robert Monaghan.
00179  *
00180  * Revision 2.11  2002/07/04 07:41:47  robertj
00181  * Fixed memory/thread leak of transports.
00182  *
00183  * Revision 2.10  2002/07/01 04:56:30  robertj
00184  * Updated to OpenH323 v1.9.1
00185  *
00186  * Revision 2.9  2002/04/05 10:36:53  robertj
00187  * Rearranged OnRelease to remove the connection from endpoints connection
00188  *   list at the end of the release phase rather than the beginning.
00189  *
00190  * Revision 2.8  2002/01/22 05:04:40  robertj
00191  * Revamp of user input API triggered by RFC2833 support
00192  *
00193  * Revision 2.7  2001/11/14 01:31:55  robertj
00194  * Corrected placement of adjusting media format list.
00195  *
00196  * Revision 2.6  2001/11/13 06:25:56  robertj
00197  * Changed SetUpConnection() so returns BOOL as returning
00198  *   pointer to connection is not useful.
00199  *
00200  * Revision 2.5  2001/08/23 05:51:17  robertj
00201  * Completed implementation of codec reordering.
00202  *
00203  * Revision 2.4  2001/08/22 10:20:09  robertj
00204  * Changed connection locking to use double mutex to guarantee that
00205  *   no threads can ever deadlock or access deleted connection.
00206  *
00207  * Revision 2.3  2001/08/17 08:22:23  robertj
00208  * Moved call end reasons enum from OpalConnection to global.
00209  *
00210  * Revision 2.2  2001/08/01 05:26:35  robertj
00211  * Moved media formats list from endpoint to connection.
00212  *
00213  * Revision 2.1  2001/07/30 07:22:25  robertj
00214  * Abstracted listener management from H.323 to OpalEndPoint class.
00215  *
00216  * Revision 2.0  2001/07/27 15:48:24  robertj
00217  * Conversion of OpenH323 to Open Phone Abstraction Library (OPAL)
00218  *
00219  */
00220 
00221 #ifndef __OPAL_ENDPOINT_H
00222 #define __OPAL_ENDPOINT_H
00223 
00224 #ifdef P_USE_PRAGMA
00225 #pragma interface
00226 #endif
00227 
00228 #include <opal/buildopts.h>
00229 
00230 #include <opal/manager.h>
00231 #include <opal/mediafmt.h>
00232 #include <opal/transports.h>
00233 
00234 class OpalCall;
00235 class OpalMediaStream;
00236 class OpalH224Handler;
00237 class OpalH281Handler;
00238 
00239 
00259 class OpalEndPoint : public PObject
00260 {
00261     PCLASSINFO(OpalEndPoint, PObject);
00262   public:
00263     enum Attributes {
00264       CanTerminateCall = 1,
00265       HasLineInterface = 2
00266     };
00267 
00272     OpalEndPoint(
00273       OpalManager & manager,          
00274       const PCaselessString & prefix, 
00275       unsigned attributes             
00276     );
00277 
00280     ~OpalEndPoint();
00282 
00289     void PrintOn(
00290       ostream & strm    
00291     ) const;
00293 
00303     BOOL StartListeners(
00304       const PStringArray & interfaces 
00305     );
00306 
00314     BOOL StartListener(
00315       const OpalTransportAddress & iface 
00316     );
00317 
00323     BOOL StartListener(
00324       OpalListener * listener 
00325     );
00326 
00331     virtual PStringArray GetDefaultListeners() const;
00332 
00335     OpalListener * FindListener(
00336         const OpalTransportAddress & iface 
00337     );
00338 
00342     BOOL StopListener(
00343         const OpalTransportAddress & iface 
00344     );
00345 
00349     BOOL RemoveListener(
00350       OpalListener * listener 
00351     );
00352 
00355     OpalTransportAddressArray GetInterfaceAddresses(
00356       BOOL excludeLocalHost = TRUE,       
00357       OpalTransport * associatedTransport = NULL
00359     );
00360 
00365     PDECLARE_NOTIFIER(PThread, OpalEndPoint, ListenerCallback);
00366 
00375     virtual BOOL NewIncomingConnection(
00376       OpalTransport * transport  
00377     );
00379 
00411     virtual BOOL MakeConnection(
00412       OpalCall & call,          
00413       const PString & party,    
00414       void * userData = NULL,          
00415       unsigned int options = 0,     
00416       OpalConnection::StringOptions * stringOptions = NULL
00417     ) = 0;
00418 
00422     virtual BOOL OnSetUpConnection(OpalConnection &connection);
00423     
00445     virtual BOOL OnIncomingConnection(
00446       OpalConnection & connection,  
00447       unsigned options,             
00448       OpalConnection::StringOptions * stringOptions
00449     );
00450     virtual BOOL OnIncomingConnection(
00451       OpalConnection & connection,  
00452       unsigned options              
00453     );
00454     virtual BOOL OnIncomingConnection(
00455       OpalConnection & connection   
00456     );
00457 
00473     virtual void OnAlerting(
00474       OpalConnection & connection   
00475     );
00476 
00493     virtual OpalConnection::AnswerCallResponse OnAnswerCall(
00494       OpalConnection & connection,    
00495        const PString & caller         
00496     );
00497 
00508     virtual void OnConnected(
00509       OpalConnection & connection   
00510     );
00511 
00523     virtual void OnEstablished(
00524       OpalConnection & connection   
00525     );
00526 
00545     virtual void OnReleased(
00546       OpalConnection & connection   
00547     );
00548 
00555     void OnHold(
00556       OpalConnection & connection   
00557     );
00558 
00563     virtual BOOL OnForwarded(
00564       OpalConnection & connection,  
00565       const PString & remoteParty         
00566     );
00567 
00575     virtual BOOL ClearCall(
00576       const PString & token,    
00577       OpalConnection::CallEndReason reason = OpalConnection::EndedByLocalUser, 
00578       PSyncPoint * sync = NULL  
00579     );
00580 
00585     virtual BOOL ClearCallSynchronous(
00586       const PString & token,    
00587       OpalConnection::CallEndReason reason = OpalConnection::EndedByLocalUser, 
00588       PSyncPoint * sync = NULL  
00589     );
00590 
00597     virtual void ClearAllCalls(
00598       OpalConnection::CallEndReason reason = OpalConnection::EndedByLocalUser, 
00599       BOOL wait = TRUE   
00600     );
00601 
00606     PSafePtr<OpalConnection> GetConnectionWithLock(
00607       const PString & token,     
00608       PSafetyMode mode = PSafeReadWrite
00609     ) { return connectionsActive.FindWithLock(token, mode); }
00610 
00613     PStringList GetAllConnections();
00614 
00617     virtual BOOL HasConnection(
00618       const PString & token   
00619     );
00620 
00623     virtual void DestroyConnection(
00624       OpalConnection * connection  
00625     );
00627 
00639     virtual OpalMediaFormatList GetMediaFormats() const = 0;
00640 
00649     virtual void AdjustMediaFormats(
00650       const OpalConnection & connection,  
00651       OpalMediaFormatList & mediaFormats  
00652     ) const;
00653 
00665     virtual BOOL OnOpenMediaStream(
00666       OpalConnection & connection,  
00667       OpalMediaStream & stream      
00668     );
00669 
00674     virtual void OnClosedMediaStream(
00675       const OpalMediaStream & stream     
00676     );
00677 
00678 #if OPAL_VIDEO
00679 
00683     virtual void AddVideoMediaFormats(
00684       OpalMediaFormatList & mediaFormats, 
00685       const OpalConnection * connection = NULL  
00686     ) const;
00687 
00690     virtual BOOL CreateVideoInputDevice(
00691       const OpalConnection & connection,    
00692       const OpalMediaFormat & mediaFormat,  
00693       PVideoInputDevice * & device,         
00694       BOOL & autoDelete                     
00695     );
00696 
00700     virtual BOOL CreateVideoOutputDevice(
00701       const OpalConnection & connection,    
00702       const OpalMediaFormat & mediaFormat,  
00703       BOOL preview,                         
00704       PVideoOutputDevice * & device,        
00705       BOOL & autoDelete                     
00706     );
00707 #endif
00708 
00709 
00716     virtual void OnUserInputString(
00717       OpalConnection & connection,  
00718       const PString & value   
00719     );
00720 
00727     virtual void OnUserInputTone(
00728       OpalConnection & connection,  
00729       char tone,                    
00730       int duration                  
00731     );
00732 
00735     virtual PString ReadUserInput(
00736       OpalConnection & connection,        
00737       const char * terminators = "#\r\n", 
00738       unsigned lastDigitTimeout = 4,      
00739       unsigned firstDigitTimeout = 30     
00740     );
00742 
00745 #if OPAL_T120DATA
00746 
00756     virtual OpalT120Protocol * CreateT120ProtocolHandler(
00757       const OpalConnection & connection  
00758     ) const;
00759 #endif
00760 
00761 #if OPAL_T38FAX
00762 
00773     virtual OpalT38Protocol * CreateT38ProtocolHandler(
00774       const OpalConnection & connection  
00775     ) const;
00776         
00777 #endif
00778 
00779 #if OPAL_H224
00780 
00790     virtual OpalH224Handler * CreateH224ProtocolHandler(
00791       OpalConnection & connection, 
00792       unsigned sessionID
00793     ) const;
00794         
00804     virtual OpalH281Handler * CreateH281ProtocolHandler(
00805       OpalH224Handler & h224Handler
00806     ) const;
00807 #endif
00808 
00813     virtual BOOL GarbageCollection();
00815 
00820     OpalManager & GetManager() const { return manager; }
00821 
00824     const PString & GetPrefixName() const { return prefixName; }
00825 
00828     BOOL HasAttribute(Attributes opt) const { return (attributeBits&opt) != 0; }
00829 
00832     WORD GetDefaultSignalPort() const { return defaultSignalPort; }
00833 
00836     const OpalProductInfo & GetProductInfo() const { return productInfo; }
00837 
00840     void SetProductInfo(
00841       const OpalProductInfo & info
00842     ) { productInfo = info; }
00843 
00846     const PString & GetDefaultLocalPartyName() const { return defaultLocalPartyName; }
00847 
00850     void SetDefaultLocalPartyName(const PString & name) { defaultLocalPartyName = name; }
00851 
00854     const PString & GetDefaultDisplayName() const { return defaultDisplayName; }
00855 
00858     void SetDefaultDisplayName(const PString & name) { defaultDisplayName = name; }
00859 
00862     unsigned GetInitialBandwidth() const { return initialBandwidth; }
00863 
00866     void SetInitialBandwidth(unsigned bandwidth) { initialBandwidth = bandwidth; }
00867 
00870     const OpalListenerList & GetListeners() const { return listeners; }
00871 
00874     OpalConnection::SendUserInputModes GetSendUserInputMode() const { return defaultSendUserInputMode; }
00875 
00878     void SetSendUserInputMode(OpalConnection::SendUserInputModes mode) { defaultSendUserInputMode = mode; }
00880 
00881     virtual PString GetDefaultTransport() const;
00882 
00883     virtual void OnNewConnection(OpalCall & call, OpalConnection & conn);
00884 
00885 #if P_SSL
00886     PString GetSSLCertificate() const;
00887 #endif
00888 
00889     virtual void SetDefaultSecurityMode(const PString & v)
00890     { defaultSecurityMode = v; }
00891 
00892     virtual PString GetDefaultSecurityMode() const 
00893     { return defaultSecurityMode; }
00894 
00895     virtual BOOL UseRTPAggregation() const;
00896 
00899     void SetRTPAggregationSize(
00900       PINDEX size            
00901     );
00902 
00905     PINDEX GetRTPAggregationSize() const;
00906 
00909     PHandleAggregator * GetRTPAggregator();
00910         
00914     virtual BOOL AdjustInterfaceTable(PIPSocket::Address & remoteAddress,
00915                                       PIPSocket::InterfaceTable & interfaceTable);
00916 
00917     virtual BOOL IsRTPNATEnabled(OpalConnection & conn, 
00918                        const PIPSocket::Address & localAddr, 
00919                        const PIPSocket::Address & peerAddr,
00920                        const PIPSocket::Address & sigAddr,
00921                                              BOOL incoming);
00922 
00923   protected:
00924     OpalManager   & manager;
00925     PCaselessString prefixName;
00926     unsigned        attributeBits;
00927     WORD            defaultSignalPort;
00928     OpalProductInfo productInfo;
00929     PString         defaultLocalPartyName;
00930     PString         defaultDisplayName;
00931 
00932     unsigned initialBandwidth;  // in 100s of bits/sev
00933     OpalConnection::SendUserInputModes defaultSendUserInputMode;
00934 
00935     OpalListenerList   listeners;
00936 
00937     class ConnectionDict : public PSafeDictionary<PString, OpalConnection>
00938     {
00939         virtual void DeleteObject(PObject * object) const;
00940     } connectionsActive;
00941     BOOL AddConnection(OpalConnection * connection);
00942 
00943     PMutex inUseFlag;
00944 
00945     PString defaultSecurityMode; 
00946 
00947 #if OPAL_RTP_AGGREGATE
00948     PMutex rtpAggregationMutex;
00949     BOOL useRTPAggregation; 
00950     PINDEX rtpAggregationSize;
00951     PHandleAggregator * rtpAggregator;
00952 #endif
00953 
00954     friend void OpalManager::GarbageCollection();
00955     friend void OpalConnection::Release(CallEndReason reason);
00956 };
00957 
00958 
00959 #endif // __OPAL_ENDPOINT_H
00960 
00961 
00962 // End of File ///////////////////////////////////////////////////////////////

Generated on Fri Mar 7 06:33:09 2008 for OPAL by  doxygen 1.5.1