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 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);
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 bool local,
00501 const OpalConnection & connection,
00502 OpalMediaFormatList & mediaFormats
00503 ) const;
00504
00516 virtual PBoolean OnOpenMediaStream(
00517 OpalConnection & connection,
00518 OpalMediaStream & stream
00519 );
00520
00525 virtual void OnClosedMediaStream(
00526 const OpalMediaStream & stream
00527 );
00528
00529 #if OPAL_VIDEO
00530
00532 virtual PBoolean CreateVideoInputDevice(
00533 const OpalConnection & connection,
00534 const OpalMediaFormat & mediaFormat,
00535 PVideoInputDevice * & device,
00536 PBoolean & autoDelete
00537 );
00538
00542 virtual PBoolean CreateVideoOutputDevice(
00543 const OpalConnection & connection,
00544 const OpalMediaFormat & mediaFormat,
00545 PBoolean preview,
00546 PVideoOutputDevice * & device,
00547 PBoolean & autoDelete
00548 );
00549 #endif
00550
00551
00558 virtual void OnUserInputString(
00559 OpalConnection & connection,
00560 const PString & value
00561 );
00562
00569 virtual void OnUserInputTone(
00570 OpalConnection & connection,
00571 char tone,
00572 int duration
00573 );
00574
00577 virtual PString ReadUserInput(
00578 OpalConnection & connection,
00579 const char * terminators = "#\r\n",
00580 unsigned lastDigitTimeout = 4,
00581 unsigned firstDigitTimeout = 30
00582 );
00584
00589 virtual void OnMWIReceived (
00590 const PString & party,
00591 OpalManager::MessageWaitingType type,
00592 const PString & extraInfo
00593 );
00594
00599 virtual PBoolean GarbageCollection();
00601
00606 OpalManager & GetManager() const { return manager; }
00607
00610 const PString & GetPrefixName() const { return prefixName; }
00611
00614 PBoolean HasAttribute(Attributes opt) const { return (attributeBits&opt) != 0; }
00615
00618 WORD GetDefaultSignalPort() const { return defaultSignalPort; }
00619
00622 const OpalProductInfo & GetProductInfo() const { return productInfo; }
00623
00626 void SetProductInfo(
00627 const OpalProductInfo & info
00628 ) { productInfo = info; }
00629
00632 const PString & GetDefaultLocalPartyName() const { return defaultLocalPartyName; }
00633
00636 virtual void SetDefaultLocalPartyName(
00637 const PString & name
00638 ) { defaultLocalPartyName = name; }
00639
00642 const PString & GetDefaultDisplayName() const { return defaultDisplayName; }
00643
00646 void SetDefaultDisplayName(const PString & name) { defaultDisplayName = name; }
00647
00650 unsigned GetInitialBandwidth() const { return initialBandwidth; }
00651
00654 void SetInitialBandwidth(unsigned bandwidth) { initialBandwidth = bandwidth; }
00655
00658 const OpalListenerList & GetListeners() const { return listeners; }
00659
00662 const OpalConnection::StringOptions & GetDefaultStringOptions() const { return m_defaultStringOptions; }
00663
00666 void SetDefaultStringOptions(const OpalConnection::StringOptions & opts) { m_defaultStringOptions = opts; }
00667
00670 void SetDefaultStringOption(const PCaselessString & key, const PString & data) { m_defaultStringOptions.SetAt(key, data); }
00671
00674 OpalConnection::SendUserInputModes GetSendUserInputMode() const { return defaultSendUserInputMode; }
00675
00678 void SetSendUserInputMode(OpalConnection::SendUserInputModes mode) { defaultSendUserInputMode = mode; }
00680
00681 virtual PString GetDefaultTransport() const;
00682
00688 virtual void OnNewConnection(
00689 OpalCall & call,
00690 OpalConnection & connection
00691 );
00692
00693 #if OPAL_PTLIB_SSL
00694 PString GetSSLCertificate() const;
00695 #endif
00696
00699 bool FindListenerForProtocol(const char * protoPrefix, OpalTransportAddress & addr);
00700
00703 virtual PBoolean Message(
00704 const PString & to,
00705 const PString & body
00706 );
00707 virtual PBoolean Message(
00708 const PURL & to,
00709 const PString & type,
00710 const PString & body,
00711 PURL & from,
00712 PString & conversationId
00713 );
00714
00717 virtual void OnMessageReceived(
00718 const PURL & from,
00719 const PString & fromName,
00720 const PURL & to,
00721 const PString & type,
00722 const PString & body,
00723 const PString & conversationId
00724 );
00725
00726 #if OPAL_HAS_IM
00727
00729 virtual bool TransmitExternalIM(
00730 OpalConnection & conn,
00731 const OpalMediaFormat & format,
00732 RTP_IMFrame & frame
00733 );
00734 #endif
00735
00736 protected:
00737 OpalManager & manager;
00738 PCaselessString prefixName;
00739 unsigned attributeBits;
00740 WORD defaultSignalPort;
00741 OpalProductInfo productInfo;
00742 PString defaultLocalPartyName;
00743 PString defaultDisplayName;
00744
00745 unsigned initialBandwidth;
00746 OpalConnection::StringOptions m_defaultStringOptions;
00747 OpalConnection::SendUserInputModes defaultSendUserInputMode;
00748
00749 OpalListenerList listeners;
00750
00751 class ConnectionDict : public PSafeDictionary<PString, OpalConnection>
00752 {
00753 virtual void DeleteObject(PObject * object) const;
00754 } connectionsActive;
00755 OpalConnection * AddConnection(OpalConnection * connection);
00756
00757 PMutex inUseFlag;
00758
00759 friend void OpalManager::GarbageCollection();
00760 friend void OpalConnection::Release(CallEndReason reason);
00761
00762 private:
00763 P_REMOVE_VIRTUAL(PBoolean, OnIncomingConnection(OpalConnection &, unsigned), false);
00764 P_REMOVE_VIRTUAL(PBoolean, OnIncomingConnection(OpalConnection &), false);
00765 P_REMOVE_VIRTUAL_VOID(AdjustMediaFormats(const OpalConnection &, OpalMediaFormatList &) const);
00766 };
00767
00768
00770 bool OpalIsE164(
00771 const PString & number,
00772 bool strict = false
00773 );
00774
00775
00776 #endif // OPAL_OPAL_ENDPOINT_H
00777
00778
00779