OPAL Version 3.10.2
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  * $Revision: 26231 $
00028  * $Author: rjongbloed $
00029  * $Date: 2011-07-19 21:23:34 -0500 (Tue, 19 Jul 2011) $
00030  */
00031 
00032 #ifndef OPAL_OPAL_ENDPOINT_H
00033 #define OPAL_OPAL_ENDPOINT_H
00034 
00035 #ifdef P_USE_PRAGMA
00036 #pragma interface
00037 #endif
00038 
00039 #include <opal/buildopts.h>
00040 
00041 #include <opal/manager.h>
00042 #include <opal/mediafmt.h>
00043 #include <opal/transports.h>
00044 
00045 class OpalCall;
00046 class OpalMediaStream;
00047 
00067 class OpalEndPoint : public PObject
00068 {
00069     PCLASSINFO(OpalEndPoint, PObject);
00070   public:
00071     enum Attributes {
00072       CanTerminateCall = 1,
00073       SupportsE164 = 2
00074     };
00075 
00080     OpalEndPoint(
00081       OpalManager & manager,          
00082       const PCaselessString & prefix, 
00083       unsigned attributes             
00084     );
00085 
00088     ~OpalEndPoint();
00089 
00094     virtual void ShutDown();
00096 
00103     void PrintOn(
00104       ostream & strm    
00105     ) const;
00107 
00120     PBoolean StartListeners(
00121       const PStringArray & interfaces 
00122     );
00123 
00131     PBoolean StartListener(
00132       const OpalTransportAddress & iface 
00133     );
00134 
00140     PBoolean StartListener(
00141       OpalListener * listener 
00142     );
00143 
00148     virtual PStringArray GetDefaultListeners() const;
00149 
00153     virtual PString GetDefaultTransport() const;
00154 
00157     OpalListener * FindListener(
00158         const OpalTransportAddress & iface 
00159     );
00160 
00163     bool FindListenerForProtocol(
00164       const char * proto,         
00165       OpalTransportAddress & addr 
00166     );
00167 
00171     PBoolean StopListener(
00172         const OpalTransportAddress & iface 
00173     );
00174 
00178     PBoolean RemoveListener(
00179       OpalListener * listener 
00180     );
00181 
00184     OpalTransportAddressArray GetInterfaceAddresses(
00185       PBoolean excludeLocalHost = true,       
00186       const OpalTransport * associatedTransport = NULL
00188     );
00189 
00194     PDECLARE_NOTIFIER(PThread, OpalEndPoint, ListenerCallback);
00195 
00204     virtual PBoolean NewIncomingConnection(
00205       OpalTransport * transport  
00206     );
00207 
00213     virtual void OnNewConnection(
00214       OpalCall & call,              
00215       OpalConnection & connection   
00216     );
00218 
00250     virtual PSafePtr<OpalConnection> MakeConnection(
00251       OpalCall & call,          
00252       const PString & party,    
00253       void * userData = NULL,          
00254       unsigned int options = 0,     
00255       OpalConnection::StringOptions * stringOptions = NULL 
00256     ) = 0;
00257 
00261     virtual PBoolean OnSetUpConnection(OpalConnection &connection);
00262     
00284     virtual PBoolean OnIncomingConnection(
00285       OpalConnection & connection,  
00286       unsigned options,             
00287       OpalConnection::StringOptions * stringOptions  
00288     );
00289 
00304     virtual void OnProceeding(
00305       OpalConnection & connection   
00306     );
00307 
00323     virtual void OnAlerting(
00324       OpalConnection & connection   
00325     );
00326 
00343     virtual OpalConnection::AnswerCallResponse OnAnswerCall(
00344       OpalConnection & connection,    
00345        const PString & caller         
00346     );
00347 
00358     virtual void OnConnected(
00359       OpalConnection & connection   
00360     );
00361 
00373     virtual void OnEstablished(
00374       OpalConnection & connection   
00375     );
00376 
00395     virtual void OnReleased(
00396       OpalConnection & connection   
00397     );
00398 
00405     virtual void OnHold(
00406       OpalConnection & connection,   
00407       bool fromRemote,               
00408       bool onHold                    
00409     );
00410     virtual void OnHold(OpalConnection & connection); // For backward compatibility
00411 
00416     virtual PBoolean OnForwarded(
00417       OpalConnection & connection,  
00418       const PString & remoteParty         
00419     );
00420 
00441     virtual bool OnTransferNotify(
00442       OpalConnection & connection,  
00443       const PStringToString & info  
00444     );
00445 
00453     virtual PBoolean ClearCall(
00454       const PString & token,    
00455       OpalConnection::CallEndReason reason = OpalConnection::EndedByLocalUser, 
00456       PSyncPoint * sync = NULL  
00457     );
00458 
00463     virtual PBoolean ClearCallSynchronous(
00464       const PString & token,    
00465       OpalConnection::CallEndReason reason = OpalConnection::EndedByLocalUser, 
00466       PSyncPoint * sync = NULL  
00467     );
00468 
00475     virtual void ClearAllCalls(
00476       OpalConnection::CallEndReason reason = OpalConnection::EndedByLocalUser, 
00477       PBoolean wait = true   
00478     );
00479 
00484     PSafePtr<OpalConnection> GetConnectionWithLock(
00485       const PString & token,     
00486       PSafetyMode mode = PSafeReadWrite 
00487     ) { return connectionsActive.FindWithLock(token, mode); }
00488 
00495     template <class ConnClass>
00496     PSafePtr<ConnClass> GetConnectionWithLockAs(
00497       const PString & token,     
00498       PSafetyMode mode = PSafeReadWrite 
00499     )
00500     {
00501       PSafePtr<ConnClass> connection = PSafePtrCast<OpalConnection, ConnClass>(GetConnectionWithLock(token, mode));
00502       if (connection == NULL) {
00503         PSafePtr<OpalCall> call = manager.FindCallWithLock(token, PSafeReadOnly);
00504         if (call != NULL) {
00505           connection = PSafePtrCast<OpalConnection, ConnClass>(call->GetConnection(0, mode));
00506           if (connection == NULL)
00507             connection = PSafePtrCast<OpalConnection, ConnClass>(call->GetConnection(1, mode));
00508         }
00509       }
00510       return connection;
00511     }
00512 
00515     PStringList GetAllConnections();
00516     
00519     PINDEX GetConnectionCount() const { return connectionsActive.GetSize(); }
00520 
00523     virtual PBoolean HasConnection(
00524       const PString & token   
00525     );
00526 
00529     virtual void DestroyConnection(
00530       OpalConnection * connection  
00531     );
00533 
00545     virtual OpalMediaFormatList GetMediaFormats() const = 0;
00546 
00555     virtual void AdjustMediaFormats(
00556       bool local,                         
00557       const OpalConnection & connection,  
00558       OpalMediaFormatList & mediaFormats  
00559     ) const;
00560 
00572     virtual PBoolean OnOpenMediaStream(
00573       OpalConnection & connection,  
00574       OpalMediaStream & stream      
00575     );
00576 
00581     virtual void OnClosedMediaStream(
00582       const OpalMediaStream & stream     
00583     );
00584 
00585 #if OPAL_VIDEO
00586 
00588     virtual PBoolean CreateVideoInputDevice(
00589       const OpalConnection & connection,    
00590       const OpalMediaFormat & mediaFormat,  
00591       PVideoInputDevice * & device,         
00592       PBoolean & autoDelete                     
00593     );
00594 
00598     virtual PBoolean CreateVideoOutputDevice(
00599       const OpalConnection & connection,    
00600       const OpalMediaFormat & mediaFormat,  
00601       PBoolean preview,                         
00602       PVideoOutputDevice * & device,        
00603       PBoolean & autoDelete                     
00604     );
00605 #endif
00606 
00607 
00614     virtual void OnUserInputString(
00615       OpalConnection & connection,  
00616       const PString & value   
00617     );
00618 
00625     virtual void OnUserInputTone(
00626       OpalConnection & connection,  
00627       char tone,                    
00628       int duration                  
00629     );
00630 
00633     virtual PString ReadUserInput(
00634       OpalConnection & connection,        
00635       const char * terminators = "#\r\n", 
00636       unsigned lastDigitTimeout = 4,      
00637       unsigned firstDigitTimeout = 30     
00638     );
00640 
00645     virtual PBoolean Message(
00646       const PString & to, 
00647       const PString & body
00648     );
00649     virtual PBoolean Message(
00650       const PURL & to, 
00651       const PString & type,
00652       const PString & body,
00653       PURL & from, 
00654       PString & conversationId
00655     );
00656     virtual PBoolean Message(
00657       OpalIM & Message
00658     );
00659 
00662     virtual void OnMessageReceived(
00663       const OpalIM & message
00664     );
00666 
00671     virtual void OnMWIReceived (
00672       const PString & party,                
00673       OpalManager::MessageWaitingType type, 
00674       const PString & extraInfo             
00675     );
00676 
00681     virtual PBoolean GarbageCollection();
00683 
00688     OpalManager & GetManager() const { return manager; }
00689 
00692     const PString & GetPrefixName() const { return prefixName; }
00693 
00696     PBoolean HasAttribute(Attributes opt) const { return (attributeBits&opt) != 0; }
00697 
00700     WORD GetDefaultSignalPort() const { return defaultSignalPort; }
00701 
00704     const OpalProductInfo & GetProductInfo() const { return productInfo; }
00705 
00708     void SetProductInfo(
00709       const OpalProductInfo & info
00710     ) { productInfo = info; }
00711 
00714     const PString & GetDefaultLocalPartyName() const { return defaultLocalPartyName; }
00715 
00718     virtual void SetDefaultLocalPartyName(
00719       const PString & name  
00720     ) { defaultLocalPartyName = name; }
00721 
00724     const PString & GetDefaultDisplayName() const { return defaultDisplayName; }
00725 
00728     void SetDefaultDisplayName(const PString & name) { defaultDisplayName = name; }
00729 
00732     unsigned GetInitialBandwidth() const { return initialBandwidth; }
00733 
00736     void SetInitialBandwidth(unsigned bandwidth) { initialBandwidth = bandwidth; }
00737 
00740     const OpalListenerList & GetListeners() const { return listeners; }
00741 
00744     const OpalConnection::StringOptions & GetDefaultStringOptions() const { return m_defaultStringOptions; }
00745 
00748     void SetDefaultStringOptions(const OpalConnection::StringOptions & opts) { m_defaultStringOptions = opts; }
00749 
00752     void SetDefaultStringOption(const PCaselessString & key, const PString & data) { m_defaultStringOptions.SetAt(key, data); }
00753 
00756     OpalConnection::SendUserInputModes GetSendUserInputMode() const { return defaultSendUserInputMode; }
00757 
00760     void SetSendUserInputMode(OpalConnection::SendUserInputModes mode) { defaultSendUserInputMode = mode; }
00762 
00763 #if OPAL_PTLIB_SSL
00764 
00766     PString GetSSLCertificate() const;
00767 #endif
00768 
00769   protected:
00770     OpalManager   & manager;
00771     PCaselessString prefixName;
00772     unsigned        attributeBits;
00773     WORD            defaultSignalPort;
00774     PINDEX          m_maxSizeUDP;
00775     OpalProductInfo productInfo;
00776     PString         defaultLocalPartyName;
00777     PString         defaultDisplayName;
00778 
00779     unsigned initialBandwidth;  // in 100s of bits/sev
00780     OpalConnection::StringOptions      m_defaultStringOptions;
00781     OpalConnection::SendUserInputModes defaultSendUserInputMode;
00782 
00783     OpalListenerList   listeners;
00784 
00785     class ConnectionDict : public PSafeDictionary<PString, OpalConnection>
00786     {
00787         virtual void DeleteObject(PObject * object) const;
00788     } connectionsActive;
00789     OpalConnection * AddConnection(OpalConnection * connection);
00790 
00791     PMutex inUseFlag;
00792 
00793     friend void OpalManager::GarbageCollection();
00794     friend void OpalConnection::Release(CallEndReason reason);
00795 
00796   private:
00797     P_REMOVE_VIRTUAL(PBoolean, OnIncomingConnection(OpalConnection &, unsigned), false);
00798     P_REMOVE_VIRTUAL(PBoolean, OnIncomingConnection(OpalConnection &), false);
00799     P_REMOVE_VIRTUAL_VOID(AdjustMediaFormats(const OpalConnection &, OpalMediaFormatList &) const);
00800     P_REMOVE_VIRTUAL_VOID(OnMessageReceived(const PURL&,const PString&,const PURL&,const PString&,const PString&,const PString&));
00801 };
00802 
00803 
00805 bool OpalIsE164(
00806   const PString & number,   
00807   bool strict = false     
00808 );
00809 
00810 
00811 #endif // OPAL_OPAL_ENDPOINT_H
00812 
00813 
00814 // End of File ///////////////////////////////////////////////////////////////