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: 23008 $
00028  * $Author: rjongbloed $
00029  * $Date: 2009-06-29 04:24:23 +0000 (Mon, 29 Jun 2009) $
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 = PTrue,       
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 
00397     virtual PBoolean ClearCall(
00398       const PString & token,    
00399       OpalConnection::CallEndReason reason = OpalConnection::EndedByLocalUser, 
00400       PSyncPoint * sync = NULL  
00401     );
00402 
00407     virtual PBoolean ClearCallSynchronous(
00408       const PString & token,    
00409       OpalConnection::CallEndReason reason = OpalConnection::EndedByLocalUser, 
00410       PSyncPoint * sync = NULL  
00411     );
00412 
00419     virtual void ClearAllCalls(
00420       OpalConnection::CallEndReason reason = OpalConnection::EndedByLocalUser, 
00421       PBoolean wait = PTrue   
00422     );
00423 
00428     PSafePtr<OpalConnection> GetConnectionWithLock(
00429       const PString & token,     
00430       PSafetyMode mode = PSafeReadWrite
00431     ) { return connectionsActive.FindWithLock(token, mode); }
00432 
00439     template <class ConnClass>
00440     PSafePtr<ConnClass> GetConnectionWithLockAs(
00441       const PString & token,     
00442       PSafetyMode mode = PSafeReadWrite
00443     )
00444     {
00445       PSafePtr<ConnClass> connection = PSafePtrCast<OpalConnection, ConnClass>(GetConnectionWithLock(token, mode));
00446       if (connection == NULL) {
00447         PSafePtr<OpalCall> call = manager.FindCallWithLock(token, PSafeReadOnly);
00448         if (call != NULL) {
00449           connection = PSafePtrCast<OpalConnection, ConnClass>(call->GetConnection(0, mode));
00450           if (connection == NULL)
00451             connection = PSafePtrCast<OpalConnection, ConnClass>(call->GetConnection(1, mode));
00452         }
00453       }
00454       return connection;
00455     }
00456 
00459     PStringList GetAllConnections();
00460     
00463     PINDEX GetConnectionCount() const { return connectionsActive.GetSize(); }
00464 
00467     virtual PBoolean HasConnection(
00468       const PString & token   
00469     );
00470 
00473     virtual void DestroyConnection(
00474       OpalConnection * connection  
00475     );
00477 
00489     virtual OpalMediaFormatList GetMediaFormats() const = 0;
00490 
00499     virtual void AdjustMediaFormats(
00500       const OpalConnection & connection,  
00501       OpalMediaFormatList & mediaFormats  
00502     ) const;
00503 
00515     virtual PBoolean OnOpenMediaStream(
00516       OpalConnection & connection,  
00517       OpalMediaStream & stream      
00518     );
00519 
00524     virtual void OnClosedMediaStream(
00525       const OpalMediaStream & stream     
00526     );
00527 
00528 #if OPAL_VIDEO
00529 
00531     virtual PBoolean CreateVideoInputDevice(
00532       const OpalConnection & connection,    
00533       const OpalMediaFormat & mediaFormat,  
00534       PVideoInputDevice * & device,         
00535       PBoolean & autoDelete                     
00536     );
00537 
00541     virtual PBoolean CreateVideoOutputDevice(
00542       const OpalConnection & connection,    
00543       const OpalMediaFormat & mediaFormat,  
00544       PBoolean preview,                         
00545       PVideoOutputDevice * & device,        
00546       PBoolean & autoDelete                     
00547     );
00548 #endif
00549 
00550 
00557     virtual void OnUserInputString(
00558       OpalConnection & connection,  
00559       const PString & value   
00560     );
00561 
00568     virtual void OnUserInputTone(
00569       OpalConnection & connection,  
00570       char tone,                    
00571       int duration                  
00572     );
00573 
00576     virtual PString ReadUserInput(
00577       OpalConnection & connection,        
00578       const char * terminators = "#\r\n", 
00579       unsigned lastDigitTimeout = 4,      
00580       unsigned firstDigitTimeout = 30     
00581     );
00583 
00588     virtual void OnMWIReceived (
00589       const PString & party,                
00590       OpalManager::MessageWaitingType type, 
00591       const PString & extraInfo             
00592     );
00593 
00598     virtual PBoolean GarbageCollection();
00600 
00605     OpalManager & GetManager() const { return manager; }
00606 
00609     const PString & GetPrefixName() const { return prefixName; }
00610 
00613     PBoolean HasAttribute(Attributes opt) const { return (attributeBits&opt) != 0; }
00614 
00617     WORD GetDefaultSignalPort() const { return defaultSignalPort; }
00618 
00621     const OpalProductInfo & GetProductInfo() const { return productInfo; }
00622 
00625     void SetProductInfo(
00626       const OpalProductInfo & info
00627     ) { productInfo = info; }
00628 
00631     const PString & GetDefaultLocalPartyName() const { return defaultLocalPartyName; }
00632 
00635     virtual void SetDefaultLocalPartyName(
00636       const PString & name  
00637     ) { defaultLocalPartyName = name; }
00638 
00641     const PString & GetDefaultDisplayName() const { return defaultDisplayName; }
00642 
00645     void SetDefaultDisplayName(const PString & name) { defaultDisplayName = name; }
00646 
00649     unsigned GetInitialBandwidth() const { return initialBandwidth; }
00650 
00653     void SetInitialBandwidth(unsigned bandwidth) { initialBandwidth = bandwidth; }
00654 
00657     const OpalListenerList & GetListeners() const { return listeners; }
00658 
00661     const OpalConnection::StringOptions & GetDefaultStringOptions() const { return m_defaultStringOptions; }
00662 
00665     void SetDefaultStringOptions(const OpalConnection::StringOptions & opts) { m_defaultStringOptions = opts; }
00666 
00669     void SetDefaultStringOption(const PCaselessString & key, const PString & data) { m_defaultStringOptions.SetAt(key, data); }
00670 
00673     OpalConnection::SendUserInputModes GetSendUserInputMode() const { return defaultSendUserInputMode; }
00674 
00677     void SetSendUserInputMode(OpalConnection::SendUserInputModes mode) { defaultSendUserInputMode = mode; }
00679 
00680     virtual PString GetDefaultTransport() const;
00681 
00687     virtual void OnNewConnection(
00688       OpalCall & call,              
00689       OpalConnection & connection   
00690     );
00691 
00692 #if OPAL_PTLIB_SSL
00693     PString GetSSLCertificate() const;
00694 #endif
00695 
00698     bool FindListenerForProtocol(const char * protoPrefix, OpalTransportAddress & addr);
00699 
00702     virtual PBoolean Message(
00703       const PString & to, 
00704       const PString & body
00705     );
00706     virtual PBoolean Message(
00707       const PURL & to, 
00708       const PString & type,
00709       const PString & body,
00710       PURL & from, 
00711       PString & conversationId
00712     );
00713 
00716     virtual void OnMessageReceived(
00717       const PURL & from, 
00718       const PString & fromName,
00719       const PURL & to, 
00720       const PString & type,
00721       const PString & body,
00722       const PString & conversationId
00723     );
00724 
00725   protected:
00726     OpalManager   & manager;
00727     PCaselessString prefixName;
00728     unsigned        attributeBits;
00729     WORD            defaultSignalPort;
00730     OpalProductInfo productInfo;
00731     PString         defaultLocalPartyName;
00732     PString         defaultDisplayName;
00733 
00734     unsigned initialBandwidth;  // in 100s of bits/sev
00735     OpalConnection::StringOptions      m_defaultStringOptions;
00736     OpalConnection::SendUserInputModes defaultSendUserInputMode;
00737 
00738     OpalListenerList   listeners;
00739 
00740     class ConnectionDict : public PSafeDictionary<PString, OpalConnection>
00741     {
00742         virtual void DeleteObject(PObject * object) const;
00743     } connectionsActive;
00744     OpalConnection * AddConnection(OpalConnection * connection);
00745 
00746     PMutex inUseFlag;
00747 
00748     friend void OpalManager::GarbageCollection();
00749     friend void OpalConnection::Release(CallEndReason reason);
00750 
00751   private:
00752     P_REMOVE_VIRTUAL(PBoolean, OnIncomingConnection(OpalConnection &, unsigned), false);
00753     P_REMOVE_VIRTUAL(PBoolean, OnIncomingConnection(OpalConnection &), false);
00754 };
00755 
00756 
00757 #endif // OPAL_OPAL_ENDPOINT_H
00758 
00759 
00760 // End of File ///////////////////////////////////////////////////////////////

Generated on Mon Aug 3 20:49:45 2009 for OPAL by  doxygen 1.5.1