00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
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
00280 virtual void OnProceeding(
00281 OpalConnection & connection
00282 );
00283
00299 virtual void OnAlerting(
00300 OpalConnection & connection
00301 );
00302
00319 virtual OpalConnection::AnswerCallResponse OnAnswerCall(
00320 OpalConnection & connection,
00321 const PString & caller
00322 );
00323
00334 virtual void OnConnected(
00335 OpalConnection & connection
00336 );
00337
00349 virtual void OnEstablished(
00350 OpalConnection & connection
00351 );
00352
00371 virtual void OnReleased(
00372 OpalConnection & connection
00373 );
00374
00381 virtual void OnHold(
00382 OpalConnection & connection,
00383 bool fromRemote,
00384 bool onHold
00385 );
00386 virtual void OnHold(OpalConnection & connection);
00387
00392 virtual PBoolean OnForwarded(
00393 OpalConnection & connection,
00394 const PString & remoteParty
00395 );
00396
00404 virtual PBoolean ClearCall(
00405 const PString & token,
00406 OpalConnection::CallEndReason reason = OpalConnection::EndedByLocalUser,
00407 PSyncPoint * sync = NULL
00408 );
00409
00414 virtual PBoolean ClearCallSynchronous(
00415 const PString & token,
00416 OpalConnection::CallEndReason reason = OpalConnection::EndedByLocalUser,
00417 PSyncPoint * sync = NULL
00418 );
00419
00426 virtual void ClearAllCalls(
00427 OpalConnection::CallEndReason reason = OpalConnection::EndedByLocalUser,
00428 PBoolean wait = PTrue
00429 );
00430
00435 PSafePtr<OpalConnection> GetConnectionWithLock(
00436 const PString & token,
00437 PSafetyMode mode = PSafeReadWrite
00438 ) { return connectionsActive.FindWithLock(token, mode); }
00439
00446 template <class ConnClass>
00447 PSafePtr<ConnClass> GetConnectionWithLockAs(
00448 const PString & token,
00449 PSafetyMode mode = PSafeReadWrite
00450 )
00451 {
00452 PSafePtr<ConnClass> connection = PSafePtrCast<OpalConnection, ConnClass>(GetConnectionWithLock(token, mode));
00453 if (connection == NULL) {
00454 PSafePtr<OpalCall> call = manager.FindCallWithLock(token, PSafeReadOnly);
00455 if (call != NULL) {
00456 connection = PSafePtrCast<OpalConnection, ConnClass>(call->GetConnection(0, mode));
00457 if (connection == NULL)
00458 connection = PSafePtrCast<OpalConnection, ConnClass>(call->GetConnection(1, mode));
00459 }
00460 }
00461 return connection;
00462 }
00463
00466 PStringList GetAllConnections();
00467
00470 PINDEX GetConnectionCount() const { return connectionsActive.GetSize(); }
00471
00474 virtual PBoolean HasConnection(
00475 const PString & token
00476 );
00477
00480 virtual void DestroyConnection(
00481 OpalConnection * connection
00482 );
00484
00497 virtual OpalMediaFormatList GetMediaFormats() const;
00498
00507 virtual void AdjustMediaFormats(
00508 const OpalConnection & connection,
00509 OpalMediaFormatList & mediaFormats
00510 ) const;
00511
00523 virtual PBoolean OnOpenMediaStream(
00524 OpalConnection & connection,
00525 OpalMediaStream & stream
00526 );
00527
00532 virtual void OnClosedMediaStream(
00533 const OpalMediaStream & stream
00534 );
00535
00536 #if OPAL_VIDEO
00537
00541 virtual void AddVideoMediaFormats(
00542 OpalMediaFormatList & mediaFormats,
00543 const OpalConnection * connection = NULL
00544 ) const;
00545
00548 virtual PBoolean CreateVideoInputDevice(
00549 const OpalConnection & connection,
00550 const OpalMediaFormat & mediaFormat,
00551 PVideoInputDevice * & device,
00552 PBoolean & autoDelete
00553 );
00554
00558 virtual PBoolean CreateVideoOutputDevice(
00559 const OpalConnection & connection,
00560 const OpalMediaFormat & mediaFormat,
00561 PBoolean preview,
00562 PVideoOutputDevice * & device,
00563 PBoolean & autoDelete
00564 );
00565 #endif
00566
00567
00574 virtual void OnUserInputString(
00575 OpalConnection & connection,
00576 const PString & value
00577 );
00578
00585 virtual void OnUserInputTone(
00586 OpalConnection & connection,
00587 char tone,
00588 int duration
00589 );
00590
00593 virtual PString ReadUserInput(
00594 OpalConnection & connection,
00595 const char * terminators = "#\r\n",
00596 unsigned lastDigitTimeout = 4,
00597 unsigned firstDigitTimeout = 30
00598 );
00600
00605 virtual void OnMWIReceived (
00606 const PString & party,
00607 OpalManager::MessageWaitingType type,
00608 const PString & extraInfo
00609 );
00610
00615 virtual PBoolean GarbageCollection();
00617
00622 OpalManager & GetManager() const { return manager; }
00623
00626 const PString & GetPrefixName() const { return prefixName; }
00627
00630 PBoolean HasAttribute(Attributes opt) const { return (attributeBits&opt) != 0; }
00631
00634 WORD GetDefaultSignalPort() const { return defaultSignalPort; }
00635
00638 const OpalProductInfo & GetProductInfo() const { return productInfo; }
00639
00642 void SetProductInfo(
00643 const OpalProductInfo & info
00644 ) { productInfo = info; }
00645
00648 const PString & GetDefaultLocalPartyName() const { return defaultLocalPartyName; }
00649
00652 virtual void SetDefaultLocalPartyName(
00653 const PString & name
00654 ) { defaultLocalPartyName = name; }
00655
00658 const PString & GetDefaultDisplayName() const { return defaultDisplayName; }
00659
00662 void SetDefaultDisplayName(const PString & name) { defaultDisplayName = name; }
00663
00666 unsigned GetInitialBandwidth() const { return initialBandwidth; }
00667
00670 void SetInitialBandwidth(unsigned bandwidth) { initialBandwidth = bandwidth; }
00671
00674 const OpalListenerList & GetListeners() const { return listeners; }
00675
00678 const OpalConnection::StringOptions & GetDefaultStringOptions() const { return m_defaultStringOptions; }
00679
00682 void SetDefaultStringOptions(const OpalConnection::StringOptions & opts) { m_defaultStringOptions = opts; }
00683
00686 void SetDefaultStringOption(const PCaselessString & key, const PString & data) { m_defaultStringOptions.SetAt(key, data); }
00687
00690 OpalConnection::SendUserInputModes GetSendUserInputMode() const { return defaultSendUserInputMode; }
00691
00694 void SetSendUserInputMode(OpalConnection::SendUserInputModes mode) { defaultSendUserInputMode = mode; }
00696
00697 virtual PString GetDefaultTransport() const;
00698
00704 virtual void OnNewConnection(
00705 OpalCall & call,
00706 OpalConnection & connection
00707 );
00708
00709 #if OPAL_PTLIB_SSL
00710 PString GetSSLCertificate() const;
00711 #endif
00712
00715 bool FindListenerForProtocol(const char * protoPrefix, OpalTransportAddress & addr);
00716
00720 virtual void AddIMMediaFormats(
00721 OpalMediaFormatList & mediaFormats,
00722 const OpalConnection * connection = NULL
00723 ) const;
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;
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 PBoolean AddConnection(OpalConnection * connection);
00745
00746 PMutex inUseFlag;
00747
00748 friend void OpalManager::GarbageCollection();
00749 friend void OpalConnection::Release(CallEndReason reason);
00750 };
00751
00752
00753 #endif // OPAL_OPAL_ENDPOINT_H
00754
00755
00756