OPAL  Version 3.12.9
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: 30003 $
28  * $Author: rjongbloed $
29  * $Date: 2013-06-20 13:38:44 +1000 (Thu, 20 Jun 2013) $
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/buildopts.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  enum Attributes {
76  };
77 
84  const PCaselessString & prefix,
85  unsigned attributes
86  );
87 
90  ~OpalEndPoint();
91 
96  virtual void ShutDown();
98 
105  void PrintOn(
106  ostream & strm
107  ) const;
109 
127  bool StartListeners(
128  const PStringArray & interfaces,
129  bool add = true
130  );
131 
139  PBoolean StartListener(
140  const OpalTransportAddress & iface
141  );
142 
148  PBoolean StartListener(
149  OpalListener * listener
150  );
151 
156  virtual PStringArray GetDefaultListeners() const;
157 
164  virtual PString GetDefaultTransport() const;
165 
168  virtual WORD GetDefaultSignalPort() const;
169 
170 #if OPAL_PTLIB_SSL
171 
173  virtual bool ApplySSLCredentials(
174  PSSLContext & context,
175  bool create
176  ) const;
177 #endif
178 
182  const OpalTransportAddress & iface
183  );
184 
188  const char * proto,
189  OpalTransportAddress & addr
190  );
191 
195  PBoolean StopListener(
196  const OpalTransportAddress & iface
197  );
198 
202  PBoolean RemoveListener(
203  OpalListener * listener
204  );
205 
209  PBoolean excludeLocalHost = true,
210  const OpalTransport * associatedTransport = NULL
212  ) const;
213 
218 #if DOXYGEN
219  virtual void NewIncomingConnection(
220  OpalListener & listener,
221  const OpalTransportPtr & transport
222  );
223 #endif
224  PDECLARE_AcceptHandlerNotifier(OpalEndPoint, NewIncomingConnection);
225 
231  virtual void OnNewConnection(
232  OpalCall & call,
233  OpalConnection & connection
234  );
236 
268  virtual PSafePtr<OpalConnection> MakeConnection(
269  OpalCall & call,
270  const PString & party,
271  void * userData = NULL,
272  unsigned int options = 0,
273  OpalConnection::StringOptions * stringOptions = NULL
274  ) = 0;
275 
279  virtual PBoolean OnSetUpConnection(OpalConnection &connection);
280 
302  virtual PBoolean OnIncomingConnection(
303  OpalConnection & connection,
304  unsigned options,
305  OpalConnection::StringOptions * stringOptions
306  );
307 
322  virtual void OnProceeding(
323  OpalConnection & connection
324  );
325 
341  virtual void OnAlerting(
342  OpalConnection & connection
343  );
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  );
490 
500  virtual PBoolean ClearCall(
501  const PString & token,
502  OpalConnection::CallEndReason reason = OpalConnection::EndedByLocalUser,
503  PSyncPoint * sync = NULL
504  );
505 
510  virtual PBoolean ClearCallSynchronous(
511  const PString & token,
512  OpalConnection::CallEndReason reason = OpalConnection::EndedByLocalUser,
513  PSyncPoint * sync = NULL
514  );
515 
522  virtual void ClearAllCalls(
523  OpalConnection::CallEndReason reason = OpalConnection::EndedByLocalUser,
524  PBoolean wait = true
525  );
526 
539  PSafePtr<OpalConnection> GetConnectionWithLock(
540  const PString & token,
541  PSafetyMode mode = PSafeReadWrite
542  ) const;
543 
550  template <class ConnClass>
551  PSafePtr<ConnClass> GetConnectionWithLockAs(
552  const PString & token,
553  PSafetyMode mode = PSafeReadWrite
554  ) const
555  {
556  PSafePtr<ConnClass> connection = PSafePtrCast<OpalConnection, ConnClass>(GetConnectionWithLock(token, mode));
557  if (connection == NULL) {
558  PSafePtr<OpalCall> call = manager.FindCallWithLock(token, PSafeReadOnly);
559  if (call != NULL) {
560  connection = PSafePtrCast<OpalConnection, ConnClass>(call->GetConnection(0, mode));
561  if (connection == NULL)
562  connection = PSafePtrCast<OpalConnection, ConnClass>(call->GetConnection(1, mode));
563  }
564  }
565  return connection;
566  }
567 
570  PStringList GetAllConnections();
571 
574  PINDEX GetConnectionCount() const { return connectionsActive.GetSize(); }
575 
578  virtual PBoolean HasConnection(
579  const PString & token
580  );
581 
584  virtual void DestroyConnection(
585  OpalConnection * connection
586  );
588 
600  virtual OpalMediaFormatList GetMediaFormats() const = 0;
601 
610  virtual void AdjustMediaFormats(
611  bool local,
612  const OpalConnection & connection,
613  OpalMediaFormatList & mediaFormats
614  ) const;
615 
627  virtual PBoolean OnOpenMediaStream(
628  OpalConnection & connection,
629  OpalMediaStream & stream
630  );
631 
636  virtual void OnClosedMediaStream(
637  const OpalMediaStream & stream
638  );
639 
649  const PStringArray & security
650  );
651 
656  PStringArray GetMediaCryptoSuites() const
658 
662  virtual PStringArray GetAllMediaCryptoSuites() const;
663 
664 #if P_NAT
665 
667  PNatStrategy & GetNatMethods() const;
668 
674  virtual PNatMethod * GetNatMethod(
675  const PIPSocket::Address & remoteAddress = PIPSocket::GetDefaultIpAny()
676  ) const;
677 #endif
678 
679 #if OPAL_VIDEO
680 
682  virtual PBoolean CreateVideoInputDevice(
683  const OpalConnection & connection,
684  const OpalMediaFormat & mediaFormat,
685  PVideoInputDevice * & device,
686  PBoolean & autoDelete
687  );
688 
692  virtual PBoolean CreateVideoOutputDevice(
693  const OpalConnection & connection,
694  const OpalMediaFormat & mediaFormat,
695  PBoolean preview,
696  PVideoOutputDevice * & device,
697  PBoolean & autoDelete
698  );
699 #endif
700 
701 
708  virtual void OnUserInputString(
709  OpalConnection & connection,
710  const PString & value
711  );
712 
719  virtual void OnUserInputTone(
720  OpalConnection & connection,
721  char tone,
722  int duration
723  );
724 
727  virtual PString ReadUserInput(
728  OpalConnection & connection,
729  const char * terminators = "#\r\n",
730  unsigned lastDigitTimeout = 4,
731  unsigned firstDigitTimeout = 30
732  );
734 
735 
736 #if OPAL_HAS_IM
737 
741  virtual PBoolean Message(
742  const PString & to,
743  const PString & body
744  );
745  virtual PBoolean Message(
746  const PURL & to,
747  const PString & type,
748  const PString & body,
749  PURL & from,
750  PString & conversationId
751  );
752  virtual PBoolean Message(
753  OpalIM & Message
754  );
755 
758  virtual void OnMessageReceived(
759  const OpalIM & message
760  );
762 #endif // OPAL_HAS_IM
763 
764 
777  virtual void OnMWIReceived (
778  const PString & party,
780  const PString & extraInfo
781  );
782 
798  virtual bool GetConferenceStates(
799  OpalConferenceStates & states,
800  const PString & name = PString::Empty()
801  ) const;
802 
812  virtual void OnConferenceStatusChanged(
813  OpalEndPoint & endpoint,
814  const PString & uri,
816  );
817 
822  virtual PStringList GetNetworkURIs(
823  const PString & name
824  ) const;
825 
830  virtual PBoolean GarbageCollection();
832 
837  OpalManager & GetManager() const { return manager; }
838 
841  const PString & GetPrefixName() const { return prefixName; }
842 
845  PBoolean HasAttribute(Attributes opt) const { return (attributeBits&opt) != 0; }
846 
849  const OpalProductInfo & GetProductInfo() const { return productInfo; }
850 
854  const OpalProductInfo & info
855  ) { productInfo = info; }
856 
859  const PString & GetDefaultLocalPartyName() const { return defaultLocalPartyName; }
860 
864  const PString & name
865  ) { defaultLocalPartyName = name; }
866 
869  const PString & GetDefaultDisplayName() const { return defaultDisplayName; }
870 
873  void SetDefaultDisplayName(const PString & name) { defaultDisplayName = name; }
874 
879  ) const;
880 
883  void SetInitialBandwidth(
885  OpalBandwidth bandwidth
886  );
887 
890  const OpalListenerList & GetListeners() const { return listeners; }
891 
895 
899 
902  void SetDefaultStringOption(const PCaselessString & key, const PString & data) { m_defaultStringOptions.SetAt(key, data); }
903 
906  OpalConnection::SendUserInputModes GetSendUserInputMode() const { return defaultSendUserInputMode; }
907 
910  void SetSendUserInputMode(OpalConnection::SendUserInputModes mode) { defaultSendUserInputMode = mode; }
912 
913  protected:
915  PCaselessString prefixName;
916  unsigned attributeBits;
917  PINDEX m_maxSizeUDP;
921  PStringArray m_mediaCryptoSuites;
922 
926  OpalConnection::SendUserInputModes defaultSendUserInputMode;
927 
928  OpalListenerList listeners;
929 
930  class ConnectionDict : public PSafeDictionary<PString, OpalConnection>
931  {
932  virtual void DeleteObject(PObject * object) const;
935 
936  friend void OpalManager::GarbageCollection();
937  friend void OpalConnection::Release(CallEndReason,bool);
938 
939  private:
940  P_REMOVE_VIRTUAL(PBoolean, OnIncomingConnection(OpalConnection &, unsigned), false);
941  P_REMOVE_VIRTUAL(PBoolean, OnIncomingConnection(OpalConnection &), false);
942  P_REMOVE_VIRTUAL_VOID(AdjustMediaFormats(const OpalConnection &, OpalMediaFormatList &) const);
943  P_REMOVE_VIRTUAL_VOID(OnMessageReceived(const PURL&,const PString&,const PURL&,const PString&,const PString&,const PString&));
944  P_REMOVE_VIRTUAL(OpalMediaSession *, CreateMediaSession(OpalConnection &, unsigned, const OpalMediaType &), NULL);
945  P_REMOVE_VIRTUAL(PBoolean, NewIncomingConnection(OpalTransport *), false);
946 };
947 
948 
950 bool OpalIsE164(
951  const PString & number,
952  bool strict = false
953 );
954 
955 
956 #endif // OPAL_OPAL_ENDPOINT_H
957 
958 
959 // End of File ///////////////////////////////////////////////////////////////