OPAL  Version 3.18.8
endpoint.h
Go to the documentation of this file.
1 /*
2  * endpoint.h
3  *
4  * Telephony endpoint abstraction
5  *
6  * Open Phone Abstraction Library (OPAL)
7  * Formally known as the Open H323 project.
8  *
9  * Copyright (c) 2001 Equivalence Pty. Ltd.
10  *
11  * The contents of this file are subject to the Mozilla Public License
12  * Version 1.0 (the "License"); you may not use this file except in
13  * compliance with the License. You may obtain a copy of the License at
14  * http://www.mozilla.org/MPL/
15  *
16  * Software distributed under the License is distributed on an "AS IS"
17  * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
18  * the License for the specific language governing rights and limitations
19  * under the License.
20  *
21  * The Original Code is Open Phone Abstraction Library.
22  *
23  * The Initial Developer of the Original Code is Equivalence Pty. Ltd.
24  *
25  * Contributor(s): ______________________________________.
26  */
27 
28 #ifndef OPAL_OPAL_ENDPOINT_H
29 #define OPAL_OPAL_ENDPOINT_H
30 
31 #ifdef P_USE_PRAGMA
32 #pragma interface
33 #endif
34 
35 #include <opal_config.h>
36 
37 #include <opal/manager.h>
38 #include <opal/mediafmt.h>
39 #include <opal/transports.h>
40 
41 
42 class OpalCall;
43 class OpalMediaStream;
44 
45 
65 class OpalEndPoint : public PObject
66 {
67  PCLASSINFO(OpalEndPoint, PObject);
68  public:
69  P_DECLARE_BITWISE_ENUM(Attributes, 2, (
70  NoAttributes,
71  IsNetworkEndPoint,
72  SupportsE164
73  ));
74 
80  OpalManager & manager,
81  const PCaselessString & prefix,
82  Attributes attributes
83  );
84 
87  ~OpalEndPoint();
88 
93  virtual void ShutDown();
95 
102  void PrintOn(
103  ostream & strm
104  ) const;
106 
124  bool StartListeners(
125  const PStringArray & interfaces,
126  bool add = true
127  );
128 
136  virtual bool StartListener(
137  const PString & address
138  );
139 
145  virtual bool StartListener(
146  OpalListener * listener
147  );
148 
153  virtual PStringArray GetDefaultListeners() const;
154 
161  virtual PString GetDefaultTransport() const;
162 
165  virtual WORD GetDefaultSignalPort() const;
166 
167 #if OPAL_PTLIB_SSL
168 
170  virtual bool ApplySSLCredentials(
171  PSSLContext & context,
172  bool create
173  ) const;
174 #endif
175 
179  const OpalTransportAddress & iface
180  );
181 
185  const char * proto,
186  OpalTransportAddress & addr
187  );
188 
192  PBoolean StopListener(
193  const OpalTransportAddress & iface
194  );
195 
199  PBoolean RemoveListener(
200  OpalListener * listener
201  );
202 
208  const OpalTransport * associatedTransport = NULL
210  ) const;
211 
216 #if DOXYGEN
217  virtual void NewIncomingConnection(
218  OpalListener & listener,
219  const OpalTransportPtr & transport
220  );
221 #endif
222  PDECLARE_AcceptHandlerNotifier(OpalEndPoint, NewIncomingConnection);
223 
229  virtual void OnNewConnection(
230  OpalCall & call,
231  OpalConnection & connection
232  );
234 
266  virtual PSafePtr<OpalConnection> MakeConnection(
267  OpalCall & call,
268  const PString & party,
269  void * userData = NULL,
270  unsigned int options = 0,
271  OpalConnection::StringOptions * stringOptions = NULL
272  ) = 0;
273 
277  virtual PBoolean OnSetUpConnection(OpalConnection &connection);
278 
300  virtual PBoolean OnIncomingConnection(
301  OpalConnection & connection,
302  unsigned options,
303  OpalConnection::StringOptions * stringOptions
304  );
305 
320  virtual void OnProceeding(
321  OpalConnection & connection
322  );
323 
339  virtual void OnAlerting(
340  OpalConnection & connection,
341  bool withMedia
342  );
343  virtual void OnAlerting(OpalConnection & connection); // For backward compatibility
344 
361  virtual OpalConnection::AnswerCallResponse OnAnswerCall(
362  OpalConnection & connection,
363  const PString & caller
364  );
365 
376  virtual void OnConnected(
377  OpalConnection & connection
378  );
379 
391  virtual void OnEstablished(
392  OpalConnection & connection
393  );
394 
413  virtual void OnReleased(
414  OpalConnection & connection
415  );
416 
423  virtual void OnHold(
424  OpalConnection & connection,
425  bool fromRemote,
426  bool onHold
427  );
428  virtual void OnHold(OpalConnection & connection); // For backward compatibility
429 
434  virtual PBoolean OnForwarded(
435  OpalConnection & connection,
436  const PString & remoteParty
437  );
438 
486  virtual bool OnTransferNotify(
487  OpalConnection & connection,
488  const PStringToString & info,
489  const OpalConnection * transferringConnection
491  );
492 
502  virtual PBoolean ClearCall(
503  const PString & token,
504  OpalConnection::CallEndReason reason = OpalConnection::EndedByLocalUser,
505  PSyncPoint * sync = NULL
506  );
507 
512  virtual PBoolean ClearCallSynchronous(
513  const PString & token,
514  OpalConnection::CallEndReason reason = OpalConnection::EndedByLocalUser,
515  PSyncPoint * sync = NULL
516  );
517 
524  virtual void ClearAllCalls(
525  OpalConnection::CallEndReason reason = OpalConnection::EndedByLocalUser,
526  PBoolean wait = true
527  );
528 
541  PSafePtr<OpalConnection> GetConnectionWithLock(
542  const PString & token,
543  PSafetyMode mode = PSafeReadWrite
544  ) const;
545 
552  template <class ConnClass>
553  PSafePtr<ConnClass> GetConnectionWithLockAs(
554  const PString & token,
555  PSafetyMode mode = PSafeReadWrite
556  ) const
557  {
558  PSafePtr<ConnClass> connection = PSafePtrCast<OpalConnection, ConnClass>(GetConnectionWithLock(token, mode));
559  if (connection == NULL) {
560  PSafePtr<OpalCall> call = m_manager.FindCallWithLock(token, PSafeReadOnly);
561  if (call != NULL) {
562  connection = PSafePtrCast<OpalConnection, ConnClass>(call->GetConnection(0, mode));
563  if (connection == NULL)
564  connection = PSafePtrCast<OpalConnection, ConnClass>(call->GetConnection(1, mode));
565  }
566  }
567  return connection;
568  }
569 
572  PStringList GetAllConnections();
573 
576  PINDEX GetConnectionCount() const { return m_connectionsActive.GetSize(); }
577 
580  virtual PBoolean HasConnection(
581  const PString & token
582  );
583 
586  virtual void DestroyConnection(
587  OpalConnection * connection
588  );
590 
602  virtual OpalMediaFormatList GetMediaFormats() const = 0;
603 
612  virtual void AdjustMediaFormats(
613  bool local,
614  const OpalConnection & connection,
615  OpalMediaFormatList & mediaFormats
616  ) const;
617 
627  virtual bool GetMediaTransportAddresses(
628  const OpalConnection & provider,
629  const OpalConnection & consumer,
630  unsigned sessionId,
631  const OpalMediaType & mediaType,
632  OpalTransportAddressArray & transports
633  ) const;
634 
646  virtual PBoolean OnOpenMediaStream(
647  OpalConnection & connection,
648  OpalMediaStream & stream
649  );
650 
655  virtual void OnClosedMediaStream(
656  const OpalMediaStream & stream
657  );
658 
663  virtual void OnFailedMediaStream(
664  OpalConnection & connection,
665  bool fromRemote,
666  const PString & reason
667  );
668 
680  const PStringArray & security
681  );
682 
687  PStringArray GetMediaCryptoSuites() const
689 
693  virtual PStringArray GetAllMediaCryptoSuites() const;
695 
702  virtual void OnUserInputString(
703  OpalConnection & connection,
704  const PString & value
705  );
706 
721  virtual void OnUserInputTone(
722  OpalConnection & connection,
723  char tone,
724  int duration
725  );
726 
729  virtual PString ReadUserInput(
730  OpalConnection & connection,
731  const char * terminators = "#\r\n",
732  unsigned lastDigitTimeout = 4,
733  unsigned firstDigitTimeout = 30
734  );
736 
737 
738 #if OPAL_HAS_IM
739 
743  virtual PBoolean Message(
744  const PString & to,
745  const PString & body
746  );
747  virtual PBoolean Message(
748  const PURL & to,
749  const PString & type,
750  const PString & body,
751  PURL & from,
752  PString & conversationId
753  );
754  virtual PBoolean Message(
755  OpalIM & Message
756  );
757 
760  virtual void OnMessageReceived(
761  const OpalIM & message
762  );
764 #endif // OPAL_HAS_IM
765 
766 
779  virtual void OnMWIReceived (
780  const PString & party,
782  const PString & extraInfo
783  );
784 
800  virtual bool GetConferenceStates(
801  OpalConferenceStates & states,
802  const PString & name = PString::Empty()
803  ) const;
804 
814  virtual void OnConferenceStatusChanged(
815  OpalEndPoint & endpoint,
816  const PString & uri,
818  );
819 
824  virtual PStringList GetNetworkURIs(
825  const PString & name
826  ) const;
827 
832  virtual PBoolean GarbageCollection();
834 
839  OpalManager & GetManager() const { return m_manager; }
840 
843  const PString & GetPrefixName() const { return m_prefixName; }
844 
847  bool HasAttribute(Attributes opt) const { return m_attributes & opt; }
848 
851  const OpalProductInfo & GetProductInfo() const { return m_productInfo; }
852 
856  const OpalProductInfo & info
857  ) { m_productInfo = info; }
858 
861  const PString & GetDefaultLocalPartyName() const { return m_defaultLocalPartyName; }
862 
866  const PString & name
867  ) { m_defaultLocalPartyName = name; }
868 
871  const PString & GetDefaultDisplayName() const { return m_defaultDisplayName; }
872 
875  void SetDefaultDisplayName(const PString & name) { m_defaultDisplayName = name; }
876 
881  ) const;
882 
885  bool SetInitialBandwidth(
887  OpalBandwidth bandwidth
888  );
889 
892  const OpalListenerList & GetListeners() const { return m_listeners; }
893 
897 
901  const OpalConnection::StringOptions & opts,
902  bool overwrite = false
903  );
904 
907  void SetDefaultStringOption(const PCaselessString & key, const PString & data) { m_defaultStringOptions.SetAt(key, data); }
908 
911  void RemoveDefaultStringOption(const PCaselessString & key) { m_defaultStringOptions.RemoveAt(key); }
912 
915  virtual PStringList GetAvailableStringOptions() const;
916 
919  OpalConnection::SendUserInputModes GetSendUserInputMode() const { return m_defaultSendUserInputMode; }
920 
923  void SetSendUserInputMode(OpalConnection::SendUserInputModes mode) { m_defaultSendUserInputMode = mode; }
924 
927  const PIPSocket::QoS & GetSignalQoS() const { return m_signalQoS; }
928 
931  void SetSignalQoS(const PIPSocket::QoS & qos) { m_signalQoS = qos; }
932 
937  const PIPSocket::QoS & GetMediaQoS(const OpalMediaType & type) const;
938 
941  void SetMediaQoS(const OpalMediaType & type, const PIPSocket::QoS & qos);
942 
945  PINDEX GetMaxSizeUDP() const { return m_maxSizeUDP; }
946 
949  void SetMaxSizeUDP(PINDEX size) { m_maxSizeUDP = size; }
951 
952  protected:
954  PCaselessString m_prefixName;
955  Attributes m_attributes;
956  PINDEX m_maxSizeUDP;
960  PStringArray m_mediaCryptoSuites;
961  PIPSocket::QoS m_signalQoS;
963 
967  OpalConnection::SendUserInputModes m_defaultSendUserInputMode;
968 
969  OpalListenerList m_listeners;
970 
971  class ConnectionDict : public PSafeDictionary<PString, OpalConnection>
972  {
973  virtual void DeleteObject(PObject * object) const;
976 
977  friend void OpalManager::GarbageCollection();
978  friend void OpalConnection::SetToken(const PString & newToken);
979 
980  private:
981  P_REMOVE_VIRTUAL(PBoolean, OnIncomingConnection(OpalConnection &, unsigned), false);
982  P_REMOVE_VIRTUAL(PBoolean, OnIncomingConnection(OpalConnection &), false);
983  P_REMOVE_VIRTUAL_VOID(AdjustMediaFormats(const OpalConnection &, OpalMediaFormatList &) const);
984  P_REMOVE_VIRTUAL_VOID(OnMessageReceived(const PURL&,const PString&,const PURL&,const PString&,const PString&,const PString&));
985  P_REMOVE_VIRTUAL(OpalMediaSession *, CreateMediaSession(OpalConnection &, unsigned, const OpalMediaType &), NULL);
986  P_REMOVE_VIRTUAL(PBoolean, NewIncomingConnection(OpalTransport *), false);
987  P_REMOVE_VIRTUAL(bool, OnTransferNotify(OpalConnection &, const PStringToString &), false);
988 #if OPAL_PTLIB_NAT
989  P_REMOVE_VIRTUAL(PNatMethod *, GetNatMethod(const PIPSocket::Address &) const, NULL);
990 #endif
991 };
992 
993 
995 bool OpalIsE164(
996  const PString & number,
997  bool strict = false
998 );
999 
1000 
1001 #endif // OPAL_OPAL_ENDPOINT_H
1002 
1003 
1004 // End of File ///////////////////////////////////////////////////////////////
void GarbageCollection()
virtual PStringList GetAvailableStringOptions() const
PCaselessString m_prefixName
Definition: endpoint.h:954
void PrintOn(ostream &strm) const
virtual OpalMediaFormatList GetMediaFormats() const =0
Attributes m_attributes
Definition: endpoint.h:955
Definition: manager.h:150
Definition: endpoint.h:65
virtual void OnClosedMediaStream(const OpalMediaStream &stream)
virtual void OnProceeding(OpalConnection &connection)
bool OpalIsE164(const PString &number, bool strict=false)
Test for if string is a valid E.164 number.
virtual void SetToken(const PString &newToken)
virtual void OnNewConnection(OpalCall &call, OpalConnection &connection)
void SetMediaCryptoSuites(const PStringArray &security)
virtual PStringList GetNetworkURIs(const PString &name) const
virtual void OnUserInputString(OpalConnection &connection, const PString &value)
void SetDefaultDisplayName(const PString &name)
Definition: endpoint.h:875
virtual void OnConferenceStatusChanged(OpalEndPoint &endpoint, const PString &uri, OpalConferenceState::ChangeType change)
PStringList GetAllConnections()
PBoolean RemoveListener(OpalListener *listener)
virtual PString ReadUserInput(OpalConnection &connection, const char *terminators="#\r\n", unsigned lastDigitTimeout=4, unsigned firstDigitTimeout=30)
Definition: mediasession.h:647
const OpalConnection::StringOptions & GetDefaultStringOptions() const
Definition: endpoint.h:896
OpalBandwidth m_initialRxBandwidth
Definition: endpoint.h:964
std::map< OpalMediaType, PIPSocket::QoS > MediaQoSMap
Definition: manager.h:2076
virtual void OnUserInputTone(OpalConnection &connection, char tone, int duration)
Definition: transports.h:788
PSafePtr< OpalCall > FindCallWithLock(const PString &token, PSafetyMode mode=PSafeReadWrite) const
Definition: manager.h:344
virtual PBoolean OnForwarded(OpalConnection &connection, const PString &remoteParty)
void SetProductInfo(const OpalProductInfo &info)
Definition: endpoint.h:855
OpalBandwidth GetInitialBandwidth(OpalBandwidth::Direction dir) const
Definition: mediatype.h:66
void SetDefaultStringOption(const PCaselessString &key, const PString &data)
Definition: endpoint.h:907
void SetSendUserInputMode(OpalConnection::SendUserInputModes mode)
Definition: endpoint.h:923
OpalTransportAddressArray GetInterfaceAddresses(const OpalTransport *associatedTransport=NULL) const
void SetSignalQoS(const PIPSocket::QoS &qos)
Definition: endpoint.h:931
virtual PBoolean HasConnection(const PString &token)
virtual void OnFailedMediaStream(OpalConnection &connection, bool fromRemote, const PString &reason)
virtual void OnEstablished(OpalConnection &connection)
const PIPSocket::QoS & GetSignalQoS() const
Definition: endpoint.h:927
Definition: im.h:75
virtual OpalConnection::AnswerCallResponse OnAnswerCall(OpalConnection &connection, const PString &caller)
OpalConnection::SendUserInputModes m_defaultSendUserInputMode
Definition: endpoint.h:967
P_DECLARE_BITWISE_ENUM(Attributes, 2,(NoAttributes, IsNetworkEndPoint, SupportsE164))
Definition: transports.h:411
void SetDefaultStringOptions(const OpalConnection::StringOptions &opts, bool overwrite=false)
PSafePtr< OpalConnection > GetConnectionWithLock(const PString &token, PSafetyMode mode=PSafeReadWrite) const
PStringArray GetMediaCryptoSuites() const
Definition: endpoint.h:687
Definition: endpoint.h:971
OpalConnection::StringOptions m_defaultStringOptions
Definition: endpoint.h:966
virtual PSafePtr< OpalConnection > MakeConnection(OpalCall &call, const PString &party, void *userData=NULL, unsigned int options=0, OpalConnection::StringOptions *stringOptions=NULL)=0
virtual PBoolean ClearCallSynchronous(const PString &token, OpalConnection::CallEndReason reason=OpalConnection::EndedByLocalUser, PSyncPoint *sync=NULL)
OpalConnection * AddConnection(OpalConnection *connection)
Definition: mediafmt.h:112
void RemoveDefaultStringOption(const PCaselessString &key)
Definition: endpoint.h:911
virtual bool GetMediaTransportAddresses(const OpalConnection &provider, const OpalConnection &consumer, unsigned sessionId, const OpalMediaType &mediaType, OpalTransportAddressArray &transports) const
virtual void OnMessageReceived(const OpalIM &message)
Definition: mediafmt.h:60
PBoolean StopListener(const OpalTransportAddress &iface)
Definition: connection.h:530
virtual void OnHold(OpalConnection &connection, bool fromRemote, bool onHold)
OpalBandwidth m_initialTxBandwidth
Definition: endpoint.h:965
virtual WORD GetDefaultSignalPort() const
MessageWaitingType
Message waiting sub-types.
Definition: manager.h:1394
virtual PStringArray GetAllMediaCryptoSuites() const
virtual PBoolean OnIncomingConnection(OpalConnection &connection, unsigned options, OpalConnection::StringOptions *stringOptions)
PINDEX m_maxSizeUDP
Definition: endpoint.h:956
Direction
Definition: mediafmt.h:64
Definition: call.h:62
OpalListenerList m_listeners
Definition: endpoint.h:969
OpalProductInfo m_productInfo
Definition: endpoint.h:957
bool FindListenerForProtocol(const char *proto, OpalTransportAddress &addr)
void SetMediaQoS(const OpalMediaType &type, const PIPSocket::QoS &qos)
const PString & GetDefaultLocalPartyName() const
Definition: endpoint.h:861
PStringArray m_mediaCryptoSuites
Definition: endpoint.h:960
virtual bool StartListener(const PString &address)
void SetMaxSizeUDP(PINDEX size)
Definition: endpoint.h:949
PINDEX GetConnectionCount() const
Definition: endpoint.h:576
virtual PBoolean ClearCall(const PString &token, OpalConnection::CallEndReason reason=OpalConnection::EndedByLocalUser, PSyncPoint *sync=NULL)
virtual void ShutDown()
virtual void OnReleased(OpalConnection &connection)
virtual void OnAlerting(OpalConnection &connection, bool withMedia)
OpalManager & GetManager() const
Definition: endpoint.h:839
ChangeType
Definition: manager.h:76
virtual void DestroyConnection(OpalConnection *connection)
OpalListener * FindListener(const OpalTransportAddress &iface)
OpalEndPoint(OpalManager &manager, const PCaselessString &prefix, Attributes attributes)
PString m_defaultDisplayName
Definition: endpoint.h:959
OpalManager & m_manager
Definition: endpoint.h:953
Definition: connection.h:462
PSafePtr< OpalTransport > OpalTransportPtr
Definition: transports.h:50
virtual void OnConnected(OpalConnection &connection)
OpalManager::MediaQoSMap m_mediaQoS
Definition: endpoint.h:962
Definition: mediastrm.h:110
virtual void AdjustMediaFormats(bool local, const OpalConnection &connection, OpalMediaFormatList &mediaFormats) const
PDECLARE_AcceptHandlerNotifier(OpalEndPoint, NewIncomingConnection)
PINDEX GetMaxSizeUDP() const
Definition: endpoint.h:945
PIPSocket::QoS m_signalQoS
Definition: endpoint.h:961
virtual void ClearAllCalls(OpalConnection::CallEndReason reason=OpalConnection::EndedByLocalUser, PBoolean wait=true)
virtual PBoolean Message(const PString &to, const PString &body)
virtual PBoolean OnOpenMediaStream(OpalConnection &connection, OpalMediaStream &stream)
Definition: connection.h:415
PSafePtr< ConnClass > GetConnectionWithLockAs(const PString &token, PSafetyMode mode=PSafeReadWrite) const
Definition: endpoint.h:553
std::list< OpalConferenceState > OpalConferenceStates
Definition: manager.h:131
bool HasAttribute(Attributes opt) const
Definition: endpoint.h:847
virtual PBoolean GarbageCollection()
virtual PBoolean OnSetUpConnection(OpalConnection &connection)
const OpalProductInfo & GetProductInfo() const
Definition: endpoint.h:851
OpalEndPoint::ConnectionDict m_connectionsActive
bool SetInitialBandwidth(OpalBandwidth::Direction dir, OpalBandwidth bandwidth)
bool StartListeners(const PStringArray &interfaces, bool add=true)
Definition: transports.h:151
Definition: transports.h:326
OpalConnection::SendUserInputModes GetSendUserInputMode() const
Definition: endpoint.h:919
virtual bool OnTransferNotify(OpalConnection &connection, const PStringToString &info, const OpalConnection *transferringConnection)
virtual void OnMWIReceived(const PString &party, OpalManager::MessageWaitingType type, const PString &extraInfo)
virtual void SetDefaultLocalPartyName(const PString &name)
Definition: endpoint.h:865
virtual PString GetDefaultTransport() const
const PString & GetDefaultDisplayName() const
Definition: endpoint.h:871
virtual PStringArray GetDefaultListeners() const
const PString & GetPrefixName() const
Definition: endpoint.h:843
PString m_defaultLocalPartyName
Definition: endpoint.h:958
virtual bool GetConferenceStates(OpalConferenceStates &states, const PString &name=PString::Empty()) const
const PIPSocket::QoS & GetMediaQoS(const OpalMediaType &type) const
Definition: connection.h:358
const OpalListenerList & GetListeners() const
Definition: endpoint.h:892