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 SupportsE164 = 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
00120 PBoolean StartListeners(
00121 const PStringArray & interfaces
00122 );
00123
00131 PBoolean StartListener(
00132 const OpalTransportAddress & iface
00133 );
00134
00140 PBoolean StartListener(
00141 OpalListener * listener
00142 );
00143
00148 virtual PStringArray GetDefaultListeners() const;
00149
00153 virtual PString GetDefaultTransport() const;
00154
00157 OpalListener * FindListener(
00158 const OpalTransportAddress & iface
00159 );
00160
00163 bool FindListenerForProtocol(
00164 const char * proto,
00165 OpalTransportAddress & addr
00166 );
00167
00171 PBoolean StopListener(
00172 const OpalTransportAddress & iface
00173 );
00174
00178 PBoolean RemoveListener(
00179 OpalListener * listener
00180 );
00181
00184 OpalTransportAddressArray GetInterfaceAddresses(
00185 PBoolean excludeLocalHost = true,
00186 const OpalTransport * associatedTransport = NULL
00188 );
00189
00194 PDECLARE_NOTIFIER(PThread, OpalEndPoint, ListenerCallback);
00195
00204 virtual PBoolean NewIncomingConnection(
00205 OpalTransport * transport
00206 );
00207
00213 virtual void OnNewConnection(
00214 OpalCall & call,
00215 OpalConnection & connection
00216 );
00218
00250 virtual PSafePtr<OpalConnection> MakeConnection(
00251 OpalCall & call,
00252 const PString & party,
00253 void * userData = NULL,
00254 unsigned int options = 0,
00255 OpalConnection::StringOptions * stringOptions = NULL
00256 ) = 0;
00257
00261 virtual PBoolean OnSetUpConnection(OpalConnection &connection);
00262
00284 virtual PBoolean OnIncomingConnection(
00285 OpalConnection & connection,
00286 unsigned options,
00287 OpalConnection::StringOptions * stringOptions
00288 );
00289
00304 virtual void OnProceeding(
00305 OpalConnection & connection
00306 );
00307
00323 virtual void OnAlerting(
00324 OpalConnection & connection
00325 );
00326
00343 virtual OpalConnection::AnswerCallResponse OnAnswerCall(
00344 OpalConnection & connection,
00345 const PString & caller
00346 );
00347
00358 virtual void OnConnected(
00359 OpalConnection & connection
00360 );
00361
00373 virtual void OnEstablished(
00374 OpalConnection & connection
00375 );
00376
00395 virtual void OnReleased(
00396 OpalConnection & connection
00397 );
00398
00405 virtual void OnHold(
00406 OpalConnection & connection,
00407 bool fromRemote,
00408 bool onHold
00409 );
00410 virtual void OnHold(OpalConnection & connection);
00411
00416 virtual PBoolean OnForwarded(
00417 OpalConnection & connection,
00418 const PString & remoteParty
00419 );
00420
00468 virtual bool OnTransferNotify(
00469 OpalConnection & connection,
00470 const PStringToString & info
00471 );
00472
00482 virtual PBoolean ClearCall(
00483 const PString & token,
00484 OpalConnection::CallEndReason reason = OpalConnection::EndedByLocalUser,
00485 PSyncPoint * sync = NULL
00486 );
00487
00492 virtual PBoolean ClearCallSynchronous(
00493 const PString & token,
00494 OpalConnection::CallEndReason reason = OpalConnection::EndedByLocalUser,
00495 PSyncPoint * sync = NULL
00496 );
00497
00504 virtual void ClearAllCalls(
00505 OpalConnection::CallEndReason reason = OpalConnection::EndedByLocalUser,
00506 PBoolean wait = true
00507 );
00508
00513 PSafePtr<OpalConnection> GetConnectionWithLock(
00514 const PString & token,
00515 PSafetyMode mode = PSafeReadWrite
00516 ) { return connectionsActive.FindWithLock(token, mode); }
00517
00524 template <class ConnClass>
00525 PSafePtr<ConnClass> GetConnectionWithLockAs(
00526 const PString & token,
00527 PSafetyMode mode = PSafeReadWrite
00528 )
00529 {
00530 PSafePtr<ConnClass> connection = PSafePtrCast<OpalConnection, ConnClass>(GetConnectionWithLock(token, mode));
00531 if (connection == NULL) {
00532 PSafePtr<OpalCall> call = manager.FindCallWithLock(token, PSafeReadOnly);
00533 if (call != NULL) {
00534 connection = PSafePtrCast<OpalConnection, ConnClass>(call->GetConnection(0, mode));
00535 if (connection == NULL)
00536 connection = PSafePtrCast<OpalConnection, ConnClass>(call->GetConnection(1, mode));
00537 }
00538 }
00539 return connection;
00540 }
00541
00544 PStringList GetAllConnections();
00545
00548 PINDEX GetConnectionCount() const { return connectionsActive.GetSize(); }
00549
00552 virtual PBoolean HasConnection(
00553 const PString & token
00554 );
00555
00558 virtual void DestroyConnection(
00559 OpalConnection * connection
00560 );
00562
00574 virtual OpalMediaFormatList GetMediaFormats() const = 0;
00575
00584 virtual void AdjustMediaFormats(
00585 bool local,
00586 const OpalConnection & connection,
00587 OpalMediaFormatList & mediaFormats
00588 ) const;
00589
00601 virtual PBoolean OnOpenMediaStream(
00602 OpalConnection & connection,
00603 OpalMediaStream & stream
00604 );
00605
00610 virtual void OnClosedMediaStream(
00611 const OpalMediaStream & stream
00612 );
00613
00614 #if OPAL_VIDEO
00615
00617 virtual PBoolean CreateVideoInputDevice(
00618 const OpalConnection & connection,
00619 const OpalMediaFormat & mediaFormat,
00620 PVideoInputDevice * & device,
00621 PBoolean & autoDelete
00622 );
00623
00627 virtual PBoolean CreateVideoOutputDevice(
00628 const OpalConnection & connection,
00629 const OpalMediaFormat & mediaFormat,
00630 PBoolean preview,
00631 PVideoOutputDevice * & device,
00632 PBoolean & autoDelete
00633 );
00634 #endif
00635
00636
00643 virtual void OnUserInputString(
00644 OpalConnection & connection,
00645 const PString & value
00646 );
00647
00654 virtual void OnUserInputTone(
00655 OpalConnection & connection,
00656 char tone,
00657 int duration
00658 );
00659
00662 virtual PString ReadUserInput(
00663 OpalConnection & connection,
00664 const char * terminators = "#\r\n",
00665 unsigned lastDigitTimeout = 4,
00666 unsigned firstDigitTimeout = 30
00667 );
00669
00674 virtual PBoolean Message(
00675 const PString & to,
00676 const PString & body
00677 );
00678 virtual PBoolean Message(
00679 const PURL & to,
00680 const PString & type,
00681 const PString & body,
00682 PURL & from,
00683 PString & conversationId
00684 );
00685 virtual PBoolean Message(
00686 OpalIM & Message
00687 );
00688
00691 virtual void OnMessageReceived(
00692 const OpalIM & message
00693 );
00695
00708 virtual void OnMWIReceived (
00709 const PString & party,
00710 OpalManager::MessageWaitingType type,
00711 const PString & extraInfo
00712 );
00713
00718 virtual PBoolean GarbageCollection();
00720
00725 OpalManager & GetManager() const { return manager; }
00726
00729 const PString & GetPrefixName() const { return prefixName; }
00730
00733 PBoolean HasAttribute(Attributes opt) const { return (attributeBits&opt) != 0; }
00734
00737 WORD GetDefaultSignalPort() const { return defaultSignalPort; }
00738
00741 const OpalProductInfo & GetProductInfo() const { return productInfo; }
00742
00745 void SetProductInfo(
00746 const OpalProductInfo & info
00747 ) { productInfo = info; }
00748
00751 const PString & GetDefaultLocalPartyName() const { return defaultLocalPartyName; }
00752
00755 virtual void SetDefaultLocalPartyName(
00756 const PString & name
00757 ) { defaultLocalPartyName = name; }
00758
00761 const PString & GetDefaultDisplayName() const { return defaultDisplayName; }
00762
00765 void SetDefaultDisplayName(const PString & name) { defaultDisplayName = name; }
00766
00769 unsigned GetInitialBandwidth() const { return initialBandwidth; }
00770
00773 void SetInitialBandwidth(unsigned bandwidth) { initialBandwidth = bandwidth; }
00774
00777 const OpalListenerList & GetListeners() const { return listeners; }
00778
00781 const OpalConnection::StringOptions & GetDefaultStringOptions() const { return m_defaultStringOptions; }
00782
00785 void SetDefaultStringOptions(const OpalConnection::StringOptions & opts) { m_defaultStringOptions = opts; }
00786
00789 void SetDefaultStringOption(const PCaselessString & key, const PString & data) { m_defaultStringOptions.SetAt(key, data); }
00790
00793 OpalConnection::SendUserInputModes GetSendUserInputMode() const { return defaultSendUserInputMode; }
00794
00797 void SetSendUserInputMode(OpalConnection::SendUserInputModes mode) { defaultSendUserInputMode = mode; }
00799
00800 #if OPAL_PTLIB_SSL
00801
00803 PString GetSSLCertificate() const;
00804 #endif
00805
00806 protected:
00807 OpalManager & manager;
00808 PCaselessString prefixName;
00809 unsigned attributeBits;
00810 WORD defaultSignalPort;
00811 PINDEX m_maxSizeUDP;
00812 OpalProductInfo productInfo;
00813 PString defaultLocalPartyName;
00814 PString defaultDisplayName;
00815
00816 unsigned initialBandwidth;
00817 OpalConnection::StringOptions m_defaultStringOptions;
00818 OpalConnection::SendUserInputModes defaultSendUserInputMode;
00819
00820 OpalListenerList listeners;
00821
00822 class ConnectionDict : public PSafeDictionary<PString, OpalConnection>
00823 {
00824 virtual void DeleteObject(PObject * object) const;
00825 } connectionsActive;
00826 OpalConnection * AddConnection(OpalConnection * connection);
00827
00828 PMutex inUseFlag;
00829
00830 friend void OpalManager::GarbageCollection();
00831 friend void OpalConnection::Release(CallEndReason,bool);
00832
00833 private:
00834 P_REMOVE_VIRTUAL(PBoolean, OnIncomingConnection(OpalConnection &, unsigned), false);
00835 P_REMOVE_VIRTUAL(PBoolean, OnIncomingConnection(OpalConnection &), false);
00836 P_REMOVE_VIRTUAL_VOID(AdjustMediaFormats(const OpalConnection &, OpalMediaFormatList &) const);
00837 P_REMOVE_VIRTUAL_VOID(OnMessageReceived(const PURL&,const PString&,const PURL&,const PString&,const PString&,const PString&));
00838 };
00839
00840
00842 bool OpalIsE164(
00843 const PString & number,
00844 bool strict = false
00845 );
00846
00847
00848 #endif // OPAL_OPAL_ENDPOINT_H
00849
00850
00851