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: 21568 $
00028  * $Author: rjongbloed $
00029  * $Date: 2008-11-20 03:24:56 +0000 (Thu, 20 Nov 2008) $
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 PBoolean 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     virtual PBoolean OnIncomingConnection(
00259       OpalConnection & connection,  
00260       unsigned options              
00261     );
00262     virtual PBoolean OnIncomingConnection(
00263       OpalConnection & connection   
00264     );
00265 
00281     virtual void OnAlerting(
00282       OpalConnection & connection   
00283     );
00284 
00301     virtual OpalConnection::AnswerCallResponse OnAnswerCall(
00302       OpalConnection & connection,    
00303        const PString & caller         
00304     );
00305 
00316     virtual void OnConnected(
00317       OpalConnection & connection   
00318     );
00319 
00331     virtual void OnEstablished(
00332       OpalConnection & connection   
00333     );
00334 
00353     virtual void OnReleased(
00354       OpalConnection & connection   
00355     );
00356 
00363     virtual void OnHold(
00364       OpalConnection & connection,   
00365       bool fromRemote,               
00366       bool onHold                    
00367     );
00368     virtual void OnHold(OpalConnection & connection); // For backward compatibility
00369 
00374     virtual PBoolean OnForwarded(
00375       OpalConnection & connection,  
00376       const PString & remoteParty         
00377     );
00378 
00386     virtual PBoolean ClearCall(
00387       const PString & token,    
00388       OpalConnection::CallEndReason reason = OpalConnection::EndedByLocalUser, 
00389       PSyncPoint * sync = NULL  
00390     );
00391 
00396     virtual PBoolean ClearCallSynchronous(
00397       const PString & token,    
00398       OpalConnection::CallEndReason reason = OpalConnection::EndedByLocalUser, 
00399       PSyncPoint * sync = NULL  
00400     );
00401 
00408     virtual void ClearAllCalls(
00409       OpalConnection::CallEndReason reason = OpalConnection::EndedByLocalUser, 
00410       PBoolean wait = PTrue   
00411     );
00412 
00417     PSafePtr<OpalConnection> GetConnectionWithLock(
00418       const PString & token,     
00419       PSafetyMode mode = PSafeReadWrite
00420     ) { return connectionsActive.FindWithLock(token, mode); }
00421 
00428     template <class ConnClass>
00429     PSafePtr<ConnClass> GetConnectionWithLockAs(
00430       const PString & token,     
00431       PSafetyMode mode = PSafeReadWrite
00432     )
00433     {
00434       PSafePtr<ConnClass> connection = PSafePtrCast<OpalConnection, ConnClass>(GetConnectionWithLock(token, mode));
00435       if (connection == NULL) {
00436         PSafePtr<OpalCall> call = manager.FindCallWithLock(token, PSafeReadOnly);
00437         if (call != NULL) {
00438           connection = PSafePtrCast<OpalConnection, ConnClass>(call->GetConnection(0, mode));
00439           if (connection == NULL)
00440             connection = PSafePtrCast<OpalConnection, ConnClass>(call->GetConnection(1, mode));
00441         }
00442       }
00443       return connection;
00444     }
00445 
00448     PStringList GetAllConnections();
00449     
00452     PINDEX GetConnectionCount() const { return connectionsActive.GetSize(); }
00453 
00456     virtual PBoolean HasConnection(
00457       const PString & token   
00458     );
00459 
00462     virtual void DestroyConnection(
00463       OpalConnection * connection  
00464     );
00466 
00479     virtual OpalMediaFormatList GetMediaFormats() const;
00480 
00489     virtual void AdjustMediaFormats(
00490       const OpalConnection & connection,  
00491       OpalMediaFormatList & mediaFormats  
00492     ) const;
00493 
00505     virtual PBoolean OnOpenMediaStream(
00506       OpalConnection & connection,  
00507       OpalMediaStream & stream      
00508     );
00509 
00514     virtual void OnClosedMediaStream(
00515       const OpalMediaStream & stream     
00516     );
00517 
00518 #if OPAL_VIDEO
00519 
00523     virtual void AddVideoMediaFormats(
00524       OpalMediaFormatList & mediaFormats, 
00525       const OpalConnection * connection = NULL  
00526     ) const;
00527 
00530     virtual PBoolean CreateVideoInputDevice(
00531       const OpalConnection & connection,    
00532       const OpalMediaFormat & mediaFormat,  
00533       PVideoInputDevice * & device,         
00534       PBoolean & autoDelete                     
00535     );
00536 
00540     virtual PBoolean CreateVideoOutputDevice(
00541       const OpalConnection & connection,    
00542       const OpalMediaFormat & mediaFormat,  
00543       PBoolean preview,                         
00544       PVideoOutputDevice * & device,        
00545       PBoolean & autoDelete                     
00546     );
00547 #endif
00548 
00549 
00556     virtual void OnUserInputString(
00557       OpalConnection & connection,  
00558       const PString & value   
00559     );
00560 
00567     virtual void OnUserInputTone(
00568       OpalConnection & connection,  
00569       char tone,                    
00570       int duration                  
00571     );
00572 
00575     virtual PString ReadUserInput(
00576       OpalConnection & connection,        
00577       const char * terminators = "#\r\n", 
00578       unsigned lastDigitTimeout = 4,      
00579       unsigned firstDigitTimeout = 30     
00580     );
00582 
00587     virtual void OnMWIReceived (
00588       const PString & party,                
00589       OpalManager::MessageWaitingType type, 
00590       const PString & extraInfo             
00591     );
00592 
00597     virtual PBoolean GarbageCollection();
00599 
00604     OpalManager & GetManager() const { return manager; }
00605 
00608     const PString & GetPrefixName() const { return prefixName; }
00609 
00612     PBoolean HasAttribute(Attributes opt) const { return (attributeBits&opt) != 0; }
00613 
00616     WORD GetDefaultSignalPort() const { return defaultSignalPort; }
00617 
00620     const OpalProductInfo & GetProductInfo() const { return productInfo; }
00621 
00624     void SetProductInfo(
00625       const OpalProductInfo & info
00626     ) { productInfo = info; }
00627 
00630     const PString & GetDefaultLocalPartyName() const { return defaultLocalPartyName; }
00631 
00634     virtual void SetDefaultLocalPartyName(
00635       const PString & name  
00636     ) { defaultLocalPartyName = name; }
00637 
00640     const PString & GetDefaultDisplayName() const { return defaultDisplayName; }
00641 
00644     void SetDefaultDisplayName(const PString & name) { defaultDisplayName = name; }
00645 
00648     unsigned GetInitialBandwidth() const { return initialBandwidth; }
00649 
00652     void SetInitialBandwidth(unsigned bandwidth) { initialBandwidth = bandwidth; }
00653 
00656     const OpalListenerList & GetListeners() const { return listeners; }
00657 
00660     OpalConnection::SendUserInputModes GetSendUserInputMode() const { return defaultSendUserInputMode; }
00661 
00664     void SetSendUserInputMode(OpalConnection::SendUserInputModes mode) { defaultSendUserInputMode = mode; }
00666 
00667     virtual PString GetDefaultTransport() const;
00668 
00674     virtual void OnNewConnection(
00675       OpalCall & call,              
00676       OpalConnection & connection   
00677     );
00678 
00679 #if OPAL_PTLIB_SSL
00680     PString GetSSLCertificate() const;
00681 #endif
00682 
00683   protected:
00684     OpalManager   & manager;
00685     PCaselessString prefixName;
00686     unsigned        attributeBits;
00687     WORD            defaultSignalPort;
00688     OpalProductInfo productInfo;
00689     PString         defaultLocalPartyName;
00690     PString         defaultDisplayName;
00691 
00692     unsigned initialBandwidth;  // in 100s of bits/sev
00693     OpalConnection::SendUserInputModes defaultSendUserInputMode;
00694 
00695     OpalListenerList   listeners;
00696 
00697     class ConnectionDict : public PSafeDictionary<PString, OpalConnection>
00698     {
00699         virtual void DeleteObject(PObject * object) const;
00700     } connectionsActive;
00701     PBoolean AddConnection(OpalConnection * connection);
00702 
00703     PMutex inUseFlag;
00704 
00705     friend void OpalManager::GarbageCollection();
00706     friend void OpalConnection::Release(CallEndReason reason);
00707 };
00708 
00709 
00710 #endif // OPAL_OPAL_ENDPOINT_H
00711 
00712 
00713 // End of File ///////////////////////////////////////////////////////////////

Generated on Mon Feb 23 02:01:06 2009 for OPAL by  doxygen 1.5.1