OPAL  Version 3.14.3
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  * $Revision: 32530 $
28  * $Author: rjongbloed $
29  * $Date: 2014-08-15 13:41:56 +1000 (Fri, 15 Aug 2014) $
30  */
31 
32 #ifndef OPAL_OPAL_ENDPOINT_H
33 #define OPAL_OPAL_ENDPOINT_H
34 
35 #ifdef P_USE_PRAGMA
36 #pragma interface
37 #endif
38 
39 #include <opal_config.h>
40 
41 #include <opal/manager.h>
42 #include <opal/mediafmt.h>
43 #include <opal/transports.h>
44 
45 
46 class OpalCall;
47 class OpalMediaStream;
48 
49 
69 class OpalEndPoint : public PObject
70 {
71  PCLASSINFO(OpalEndPoint, PObject);
72  public:
73  P_DECLARE_BITWISE_ENUM(Attributes, 2, (
74  NoAttributes,
75  IsNetworkEndPoint,
76  SupportsE164
77  ));
78 
85  const PCaselessString & prefix,
86  Attributes attributes
87  );
88 
91  ~OpalEndPoint();
92 
97  virtual void ShutDown();
99 
106  void PrintOn(
107  ostream & strm
108  ) const;
110 
128  bool StartListeners(
129  const PStringArray & interfaces,
130  bool add = true
131  );
132 
140  PBoolean StartListener(
141  const OpalTransportAddress & iface
142  );
143 
149  PBoolean StartListener(
150  OpalListener * listener
151  );
152 
157  virtual PStringArray GetDefaultListeners() const;
158 
165  virtual PString GetDefaultTransport() const;
166 
169  virtual WORD GetDefaultSignalPort() const;
170 
171 #if OPAL_PTLIB_SSL
172 
174  virtual bool ApplySSLCredentials(
175  PSSLContext & context,
176  bool create
177  ) const;
178 #endif
179 
183  const OpalTransportAddress & iface
184  );
185 
189  const char * proto,
190  OpalTransportAddress & addr
191  );
192 
196  PBoolean StopListener(
197  const OpalTransportAddress & iface
198  );
199 
203  PBoolean RemoveListener(
204  OpalListener * listener
205  );
206 
212  const OpalTransport * associatedTransport = NULL
214  ) const;
215 
220 #if DOXYGEN
221  virtual void NewIncomingConnection(
222  OpalListener & listener,
223  const OpalTransportPtr & transport
224  );
225 #endif
226  PDECLARE_AcceptHandlerNotifier(OpalEndPoint, NewIncomingConnection);
227 
233  virtual void OnNewConnection(
234  OpalCall & call,
235  OpalConnection & connection
236  );
238 
270  virtual PSafePtr<OpalConnection> MakeConnection(
271  OpalCall & call,
272  const PString & party,
273  void * userData = NULL,
274  unsigned int options = 0,
275  OpalConnection::StringOptions * stringOptions = NULL
276  ) = 0;
277 
281  virtual PBoolean OnSetUpConnection(OpalConnection &connection);
282 
304  virtual PBoolean OnIncomingConnection(
305  OpalConnection & connection,
306  unsigned options,
307  OpalConnection::StringOptions * stringOptions
308  );
309 
324  virtual void OnProceeding(
325  OpalConnection & connection
326  );
327 
343  virtual void OnAlerting(
344  OpalConnection & connection
345  );
346 
363  virtual OpalConnection::AnswerCallResponse OnAnswerCall(
364  OpalConnection & connection,
365  const PString & caller
366  );
367 
378  virtual void OnConnected(
379  OpalConnection & connection
380  );
381 
393  virtual void OnEstablished(
394  OpalConnection & connection
395  );
396 
415  virtual void OnReleased(
416  OpalConnection & connection
417  );
418 
425  virtual void OnHold(
426  OpalConnection & connection,
427  bool fromRemote,
428  bool onHold
429  );
430  virtual void OnHold(OpalConnection & connection); // For backward compatibility
431 
436  virtual PBoolean OnForwarded(
437  OpalConnection & connection,
438  const PString & remoteParty
439  );
440 
488  virtual bool OnTransferNotify(
489  OpalConnection & connection,
490  const PStringToString & info
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 = 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 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 & source,
629  const OpalConnection & destination,
630  const OpalMediaType & mediaType,
631  OpalTransportAddressArray & transports
632  ) const;
633 
645  virtual PBoolean OnOpenMediaStream(
646  OpalConnection & connection,
647  OpalMediaStream & stream
648  );
649 
654  virtual void OnClosedMediaStream(
655  const OpalMediaStream & stream
656  );
657 
662  virtual void OnFailedMediaStream(
663  OpalConnection & connection,
664  bool fromRemote,
665  const PString & reason
666  );
667 
677  const PStringArray & security
678  );
679 
684  PStringArray GetMediaCryptoSuites() const
686 
690  virtual PStringArray GetAllMediaCryptoSuites() const;
692 
699  virtual void OnUserInputString(
700  OpalConnection & connection,
701  const PString & value
702  );
703 
718  virtual void OnUserInputTone(
719  OpalConnection & connection,
720  char tone,
721  int duration
722  );
723 
726  virtual PString ReadUserInput(
727  OpalConnection & connection,
728  const char * terminators = "#\r\n",
729  unsigned lastDigitTimeout = 4,
730  unsigned firstDigitTimeout = 30
731  );
733 
734 
735 #if OPAL_HAS_IM
736 
740  virtual PBoolean Message(
741  const PString & to,
742  const PString & body
743  );
744  virtual PBoolean Message(
745  const PURL & to,
746  const PString & type,
747  const PString & body,
748  PURL & from,
749  PString & conversationId
750  );
751  virtual PBoolean Message(
752  OpalIM & Message
753  );
754 
757  virtual void OnMessageReceived(
758  const OpalIM & message
759  );
761 #endif // OPAL_HAS_IM
762 
763 
776  virtual void OnMWIReceived (
777  const PString & party,
779  const PString & extraInfo
780  );
781 
797  virtual bool GetConferenceStates(
798  OpalConferenceStates & states,
799  const PString & name = PString::Empty()
800  ) const;
801 
811  virtual void OnConferenceStatusChanged(
812  OpalEndPoint & endpoint,
813  const PString & uri,
815  );
816 
821  virtual PStringList GetNetworkURIs(
822  const PString & name
823  ) const;
824 
829  virtual PBoolean GarbageCollection();
831 
836  OpalManager & GetManager() const { return manager; }
837 
840  const PString & GetPrefixName() const { return prefixName; }
841 
844  bool HasAttribute(Attributes opt) const { return m_attributes & opt; }
845 
848  const OpalProductInfo & GetProductInfo() const { return productInfo; }
849 
853  const OpalProductInfo & info
854  ) { productInfo = info; }
855 
858  const PString & GetDefaultLocalPartyName() const { return defaultLocalPartyName; }
859 
863  const PString & name
864  ) { defaultLocalPartyName = name; }
865 
868  const PString & GetDefaultDisplayName() const { return defaultDisplayName; }
869 
872  void SetDefaultDisplayName(const PString & name) { defaultDisplayName = name; }
873 
878  ) const;
879 
882  void SetInitialBandwidth(
884  OpalBandwidth bandwidth
885  );
886 
889  const OpalListenerList & GetListeners() const { return listeners; }
890 
894 
898 
901  void SetDefaultStringOption(const PCaselessString & key, const PString & data) { m_defaultStringOptions.SetAt(key, data); }
902 
905  void RemoveDefaultStringOption(const PCaselessString & key) { m_defaultStringOptions.RemoveAt(key); }
906 
909  virtual PStringList GetAvailableStringOptions() const;
910 
913  OpalConnection::SendUserInputModes GetSendUserInputMode() const { return defaultSendUserInputMode; }
914 
917  void SetSendUserInputMode(OpalConnection::SendUserInputModes mode) { defaultSendUserInputMode = mode; }
919 
920  protected:
922  PCaselessString prefixName;
923  Attributes m_attributes;
924  PINDEX m_maxSizeUDP;
928  PStringArray m_mediaCryptoSuites;
929 
933  OpalConnection::SendUserInputModes defaultSendUserInputMode;
934 
935  OpalListenerList listeners;
936 
937  class ConnectionDict : public PSafeDictionary<PString, OpalConnection>
938  {
939  virtual void DeleteObject(PObject * object) const;
942 
943  friend void OpalManager::GarbageCollection();
944 
945  private:
946  P_REMOVE_VIRTUAL(PBoolean, OnIncomingConnection(OpalConnection &, unsigned), false);
947  P_REMOVE_VIRTUAL(PBoolean, OnIncomingConnection(OpalConnection &), false);
948  P_REMOVE_VIRTUAL_VOID(AdjustMediaFormats(const OpalConnection &, OpalMediaFormatList &) const);
949  P_REMOVE_VIRTUAL_VOID(OnMessageReceived(const PURL&,const PString&,const PURL&,const PString&,const PString&,const PString&));
950  P_REMOVE_VIRTUAL(OpalMediaSession *, CreateMediaSession(OpalConnection &, unsigned, const OpalMediaType &), NULL);
951  P_REMOVE_VIRTUAL(PBoolean, NewIncomingConnection(OpalTransport *), false);
952 #if OPAL_PTLIB_NAT
953  P_REMOVE_VIRTUAL(PNatMethod *, GetNatMethod(const PIPSocket::Address &) const, NULL);
954 #endif
955 };
956 
957 
959 bool OpalIsE164(
960  const PString & number,
961  bool strict = false
962 );
963 
964 
965 #endif // OPAL_OPAL_ENDPOINT_H
966 
967 
968 // End of File ///////////////////////////////////////////////////////////////