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: 24443 $
00028  * $Author: rjongbloed $
00029  * $Date: 2010-06-02 03:22:49 -0500 (Wed, 02 Jun 2010) $
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       HasLineInterface = 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 
00114     PBoolean StartListeners(
00115       const PStringArray & interfaces 
00116     );
00117 
00122     PBoolean StartListener(
00123       const OpalTransportAddress & iface 
00124     );
00125 
00131     PBoolean StartListener(
00132       OpalListener * listener 
00133     );
00134 
00139     virtual PStringArray GetDefaultListeners() const;
00140 
00143     OpalListener * FindListener(
00144         const OpalTransportAddress & iface 
00145     );
00146 
00150     PBoolean StopListener(
00151         const OpalTransportAddress & iface 
00152     );
00153 
00157     PBoolean RemoveListener(
00158       OpalListener * listener 
00159     );
00160 
00163     OpalTransportAddressArray GetInterfaceAddresses(
00164       PBoolean excludeLocalHost = true,       
00165       const OpalTransport * associatedTransport = NULL
00167     );
00168 
00173     PDECLARE_NOTIFIER(PThread, OpalEndPoint, ListenerCallback);
00174 
00183     virtual PBoolean NewIncomingConnection(
00184       OpalTransport * transport  
00185     );
00187 
00219     virtual PSafePtr<OpalConnection> MakeConnection(
00220       OpalCall & call,          
00221       const PString & party,    
00222       void * userData = NULL,          
00223       unsigned int options = 0,     
00224       OpalConnection::StringOptions * stringOptions = NULL 
00225     ) = 0;
00226 
00230     virtual PBoolean OnSetUpConnection(OpalConnection &connection);
00231     
00253     virtual PBoolean OnIncomingConnection(
00254       OpalConnection & connection,  
00255       unsigned options,             
00256       OpalConnection::StringOptions * stringOptions  
00257     );
00258 
00273     virtual void OnProceeding(
00274       OpalConnection & connection   
00275     );
00276 
00292     virtual void OnAlerting(
00293       OpalConnection & connection   
00294     );
00295 
00312     virtual OpalConnection::AnswerCallResponse OnAnswerCall(
00313       OpalConnection & connection,    
00314        const PString & caller         
00315     );
00316 
00327     virtual void OnConnected(
00328       OpalConnection & connection   
00329     );
00330 
00342     virtual void OnEstablished(
00343       OpalConnection & connection   
00344     );
00345 
00364     virtual void OnReleased(
00365       OpalConnection & connection   
00366     );
00367 
00374     virtual void OnHold(
00375       OpalConnection & connection,   
00376       bool fromRemote,               
00377       bool onHold                    
00378     );
00379     virtual void OnHold(OpalConnection & connection); // For backward compatibility
00380 
00385     virtual PBoolean OnForwarded(
00386       OpalConnection & connection,  
00387       const PString & remoteParty         
00388     );
00389 
00410     virtual bool OnTransferNotify(
00411       OpalConnection & connection,  
00412       const PStringToString & info  
00413     );
00414 
00422     virtual PBoolean ClearCall(
00423       const PString & token,    
00424       OpalConnection::CallEndReason reason = OpalConnection::EndedByLocalUser, 
00425       PSyncPoint * sync = NULL  
00426     );
00427 
00432     virtual PBoolean ClearCallSynchronous(
00433       const PString & token,    
00434       OpalConnection::CallEndReason reason = OpalConnection::EndedByLocalUser, 
00435       PSyncPoint * sync = NULL  
00436     );
00437 
00444     virtual void ClearAllCalls(
00445       OpalConnection::CallEndReason reason = OpalConnection::EndedByLocalUser, 
00446       PBoolean wait = true   
00447     );
00448 
00453     PSafePtr<OpalConnection> GetConnectionWithLock(
00454       const PString & token,     
00455       PSafetyMode mode = PSafeReadWrite 
00456     ) { return connectionsActive.FindWithLock(token, mode); }
00457 
00464     template <class ConnClass>
00465     PSafePtr<ConnClass> GetConnectionWithLockAs(
00466       const PString & token,     
00467       PSafetyMode mode = PSafeReadWrite 
00468     )
00469     {
00470       PSafePtr<ConnClass> connection = PSafePtrCast<OpalConnection, ConnClass>(GetConnectionWithLock(token, mode));
00471       if (connection == NULL) {
00472         PSafePtr<OpalCall> call = manager.FindCallWithLock(token, PSafeReadOnly);
00473         if (call != NULL) {
00474           connection = PSafePtrCast<OpalConnection, ConnClass>(call->GetConnection(0, mode));
00475           if (connection == NULL)
00476             connection = PSafePtrCast<OpalConnection, ConnClass>(call->GetConnection(1, mode));
00477         }
00478       }
00479       return connection;
00480     }
00481 
00484     PStringList GetAllConnections();
00485     
00488     PINDEX GetConnectionCount() const { return connectionsActive.GetSize(); }
00489 
00492     virtual PBoolean HasConnection(
00493       const PString & token   
00494     );
00495 
00498     virtual void DestroyConnection(
00499       OpalConnection * connection  
00500     );
00502 
00514     virtual OpalMediaFormatList GetMediaFormats() const = 0;
00515 
00524     virtual void AdjustMediaFormats(
00525       bool local,                         
00526       const OpalConnection & connection,  
00527       OpalMediaFormatList & mediaFormats  
00528     ) const;
00529 
00541     virtual PBoolean OnOpenMediaStream(
00542       OpalConnection & connection,  
00543       OpalMediaStream & stream      
00544     );
00545 
00550     virtual void OnClosedMediaStream(
00551       const OpalMediaStream & stream     
00552     );
00553 
00554 #if OPAL_VIDEO
00555 
00557     virtual PBoolean CreateVideoInputDevice(
00558       const OpalConnection & connection,    
00559       const OpalMediaFormat & mediaFormat,  
00560       PVideoInputDevice * & device,         
00561       PBoolean & autoDelete                     
00562     );
00563 
00567     virtual PBoolean CreateVideoOutputDevice(
00568       const OpalConnection & connection,    
00569       const OpalMediaFormat & mediaFormat,  
00570       PBoolean preview,                         
00571       PVideoOutputDevice * & device,        
00572       PBoolean & autoDelete                     
00573     );
00574 #endif
00575 
00576 
00583     virtual void OnUserInputString(
00584       OpalConnection & connection,  
00585       const PString & value   
00586     );
00587 
00594     virtual void OnUserInputTone(
00595       OpalConnection & connection,  
00596       char tone,                    
00597       int duration                  
00598     );
00599 
00602     virtual PString ReadUserInput(
00603       OpalConnection & connection,        
00604       const char * terminators = "#\r\n", 
00605       unsigned lastDigitTimeout = 4,      
00606       unsigned firstDigitTimeout = 30     
00607     );
00609 
00614     virtual void OnMWIReceived (
00615       const PString & party,                
00616       OpalManager::MessageWaitingType type, 
00617       const PString & extraInfo             
00618     );
00619 
00624     virtual PBoolean GarbageCollection();
00626 
00631     OpalManager & GetManager() const { return manager; }
00632 
00635     const PString & GetPrefixName() const { return prefixName; }
00636 
00639     PBoolean HasAttribute(Attributes opt) const { return (attributeBits&opt) != 0; }
00640 
00643     WORD GetDefaultSignalPort() const { return defaultSignalPort; }
00644 
00647     const OpalProductInfo & GetProductInfo() const { return productInfo; }
00648 
00651     void SetProductInfo(
00652       const OpalProductInfo & info
00653     ) { productInfo = info; }
00654 
00657     const PString & GetDefaultLocalPartyName() const { return defaultLocalPartyName; }
00658 
00661     virtual void SetDefaultLocalPartyName(
00662       const PString & name  
00663     ) { defaultLocalPartyName = name; }
00664 
00667     const PString & GetDefaultDisplayName() const { return defaultDisplayName; }
00668 
00671     void SetDefaultDisplayName(const PString & name) { defaultDisplayName = name; }
00672 
00675     unsigned GetInitialBandwidth() const { return initialBandwidth; }
00676 
00679     void SetInitialBandwidth(unsigned bandwidth) { initialBandwidth = bandwidth; }
00680 
00683     const OpalListenerList & GetListeners() const { return listeners; }
00684 
00687     const OpalConnection::StringOptions & GetDefaultStringOptions() const { return m_defaultStringOptions; }
00688 
00691     void SetDefaultStringOptions(const OpalConnection::StringOptions & opts) { m_defaultStringOptions = opts; }
00692 
00695     void SetDefaultStringOption(const PCaselessString & key, const PString & data) { m_defaultStringOptions.SetAt(key, data); }
00696 
00699     OpalConnection::SendUserInputModes GetSendUserInputMode() const { return defaultSendUserInputMode; }
00700 
00703     void SetSendUserInputMode(OpalConnection::SendUserInputModes mode) { defaultSendUserInputMode = mode; }
00705 
00706     virtual PString GetDefaultTransport() const;
00707 
00713     virtual void OnNewConnection(
00714       OpalCall & call,              
00715       OpalConnection & connection   
00716     );
00717 
00718 #if OPAL_PTLIB_SSL
00719     PString GetSSLCertificate() const;
00720 #endif
00721 
00724     bool FindListenerForProtocol(const char * protoPrefix, OpalTransportAddress & addr);
00725 
00728     virtual PBoolean Message(
00729       const PString & to, 
00730       const PString & body
00731     );
00732     virtual PBoolean Message(
00733       const PURL & to, 
00734       const PString & type,
00735       const PString & body,
00736       PURL & from, 
00737       PString & conversationId
00738     );
00739     virtual PBoolean Message(
00740       OpalIM & Message
00741     );
00742 
00745     virtual void OnMessageReceived(
00746       const OpalIM & message
00747     );
00748 
00749   protected:
00750     OpalManager   & manager;
00751     PCaselessString prefixName;
00752     unsigned        attributeBits;
00753     WORD            defaultSignalPort;
00754     PINDEX          m_maxSizeUDP;
00755     OpalProductInfo productInfo;
00756     PString         defaultLocalPartyName;
00757     PString         defaultDisplayName;
00758 
00759     unsigned initialBandwidth;  // in 100s of bits/sev
00760     OpalConnection::StringOptions      m_defaultStringOptions;
00761     OpalConnection::SendUserInputModes defaultSendUserInputMode;
00762 
00763     OpalListenerList   listeners;
00764 
00765     class ConnectionDict : public PSafeDictionary<PString, OpalConnection>
00766     {
00767         virtual void DeleteObject(PObject * object) const;
00768     } connectionsActive;
00769     OpalConnection * AddConnection(OpalConnection * connection);
00770 
00771     PMutex inUseFlag;
00772 
00773     friend void OpalManager::GarbageCollection();
00774     friend void OpalConnection::Release(CallEndReason reason);
00775 
00776   private:
00777     P_REMOVE_VIRTUAL(PBoolean, OnIncomingConnection(OpalConnection &, unsigned), false);
00778     P_REMOVE_VIRTUAL(PBoolean, OnIncomingConnection(OpalConnection &), false);
00779     P_REMOVE_VIRTUAL_VOID(AdjustMediaFormats(const OpalConnection &, OpalMediaFormatList &) const);
00780     P_REMOVE_VIRTUAL_VOID(OnMessageReceived(const PURL&,const PString&,const PURL&,const PString&,const PString&,const PString&));
00781 };
00782 
00783 
00785 bool OpalIsE164(
00786   const PString & number,   
00787   bool strict = false     
00788 );
00789 
00790 
00791 #endif // OPAL_OPAL_ENDPOINT_H
00792 
00793 
00794 // End of File ///////////////////////////////////////////////////////////////

Generated on Sun Nov 21 20:20:50 2010 for OPAL by  doxygen 1.4.7