OPAL  Version 3.10.10
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: 27984 $
28  * $Author: rjongbloed $
29  * $Date: 2012-07-10 03:24:24 -0500 (Tue, 10 Jul 2012) $
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 class OpalCall;
46 class OpalMediaStream;
47 
67 class OpalEndPoint : public PObject
68 {
69  PCLASSINFO(OpalEndPoint, PObject);
70  public:
71  enum Attributes {
74  };
75 
82  const PCaselessString & prefix,
83  unsigned attributes
84  );
85 
88  ~OpalEndPoint();
89 
94  virtual void ShutDown();
96 
103  void PrintOn(
104  ostream & strm
105  ) const;
107 
120  PBoolean StartListeners(
121  const PStringArray & interfaces
122  );
123 
131  PBoolean StartListener(
132  const OpalTransportAddress & iface
133  );
134 
140  PBoolean StartListener(
141  OpalListener * listener
142  );
143 
148  virtual PStringArray GetDefaultListeners() const;
149 
153  virtual PString GetDefaultTransport() const;
154 
158  const OpalTransportAddress & iface
159  );
160 
164  const char * proto,
165  OpalTransportAddress & addr
166  );
167 
171  PBoolean StopListener(
172  const OpalTransportAddress & iface
173  );
174 
178  PBoolean RemoveListener(
179  OpalListener * listener
180  );
181 
185  PBoolean excludeLocalHost = true,
186  const OpalTransport * associatedTransport = NULL
188  );
189 
194  PDECLARE_NOTIFIER(PThread, OpalEndPoint, ListenerCallback);
195 
204  virtual PBoolean NewIncomingConnection(
205  OpalTransport * transport
206  );
207 
213  virtual void OnNewConnection(
214  OpalCall & call,
215  OpalConnection & connection
216  );
218 
250  virtual PSafePtr<OpalConnection> MakeConnection(
251  OpalCall & call,
252  const PString & party,
253  void * userData = NULL,
254  unsigned int options = 0,
255  OpalConnection::StringOptions * stringOptions = NULL
256  ) = 0;
257 
261  virtual PBoolean OnSetUpConnection(OpalConnection &connection);
262 
284  virtual PBoolean OnIncomingConnection(
285  OpalConnection & connection,
286  unsigned options,
287  OpalConnection::StringOptions * stringOptions
288  );
289 
304  virtual void OnProceeding(
305  OpalConnection & connection
306  );
307 
323  virtual void OnAlerting(
324  OpalConnection & connection
325  );
326 
344  OpalConnection & connection,
345  const PString & caller
346  );
347 
358  virtual void OnConnected(
359  OpalConnection & connection
360  );
361 
373  virtual void OnEstablished(
374  OpalConnection & connection
375  );
376 
395  virtual void OnReleased(
396  OpalConnection & connection
397  );
398 
405  virtual void OnHold(
406  OpalConnection & connection,
407  bool fromRemote,
408  bool onHold
409  );
410  virtual void OnHold(OpalConnection & connection); // For backward compatibility
411 
416  virtual PBoolean OnForwarded(
417  OpalConnection & connection,
418  const PString & remoteParty
419  );
420 
468  virtual bool OnTransferNotify(
469  OpalConnection & connection,
470  const PStringToString & info
471  );
472 
482  virtual PBoolean ClearCall(
483  const PString & token,
485  PSyncPoint * sync = NULL
486  );
487 
492  virtual PBoolean ClearCallSynchronous(
493  const PString & token,
495  PSyncPoint * sync = NULL
496  );
497 
504  virtual void ClearAllCalls(
506  PBoolean wait = true
507  );
508 
513  PSafePtr<OpalConnection> GetConnectionWithLock(
514  const PString & token,
515  PSafetyMode mode = PSafeReadWrite
516  ) { return connectionsActive.FindWithLock(token, mode); }
517 
524  template <class ConnClass>
525  PSafePtr<ConnClass> GetConnectionWithLockAs(
526  const PString & token,
527  PSafetyMode mode = PSafeReadWrite
528  )
529  {
530  PSafePtr<ConnClass> connection = PSafePtrCast<OpalConnection, ConnClass>(GetConnectionWithLock(token, mode));
531  if (connection == NULL) {
532  PSafePtr<OpalCall> call = manager.FindCallWithLock(token, PSafeReadOnly);
533  if (call != NULL) {
534  connection = PSafePtrCast<OpalConnection, ConnClass>(call->GetConnection(0, mode));
535  if (connection == NULL)
536  connection = PSafePtrCast<OpalConnection, ConnClass>(call->GetConnection(1, mode));
537  }
538  }
539  return connection;
540  }
541 
544  PStringList GetAllConnections();
545 
548  PINDEX GetConnectionCount() const { return connectionsActive.GetSize(); }
549 
552  virtual PBoolean HasConnection(
553  const PString & token
554  );
555 
558  virtual void DestroyConnection(
559  OpalConnection * connection
560  );
562 
574  virtual OpalMediaFormatList GetMediaFormats() const = 0;
575 
584  virtual void AdjustMediaFormats(
585  bool local,
586  const OpalConnection & connection,
587  OpalMediaFormatList & mediaFormats
588  ) const;
589 
601  virtual PBoolean OnOpenMediaStream(
602  OpalConnection & connection,
603  OpalMediaStream & stream
604  );
605 
610  virtual void OnClosedMediaStream(
611  const OpalMediaStream & stream
612  );
613 
614 #if OPAL_VIDEO
615 
617  virtual PBoolean CreateVideoInputDevice(
618  const OpalConnection & connection,
619  const OpalMediaFormat & mediaFormat,
620  PVideoInputDevice * & device,
621  PBoolean & autoDelete
622  );
623 
627  virtual PBoolean CreateVideoOutputDevice(
628  const OpalConnection & connection,
629  const OpalMediaFormat & mediaFormat,
630  PBoolean preview,
631  PVideoOutputDevice * & device,
632  PBoolean & autoDelete
633  );
634 #endif
635 
636 
643  virtual void OnUserInputString(
644  OpalConnection & connection,
645  const PString & value
646  );
647 
654  virtual void OnUserInputTone(
655  OpalConnection & connection,
656  char tone,
657  int duration
658  );
659 
662  virtual PString ReadUserInput(
663  OpalConnection & connection,
664  const char * terminators = "#\r\n",
665  unsigned lastDigitTimeout = 4,
666  unsigned firstDigitTimeout = 30
667  );
669 
674  virtual PBoolean Message(
675  const PString & to,
676  const PString & body
677  );
678  virtual PBoolean Message(
679  const PURL & to,
680  const PString & type,
681  const PString & body,
682  PURL & from,
683  PString & conversationId
684  );
685  virtual PBoolean Message(
686  OpalIM & Message
687  );
688 
691  virtual void OnMessageReceived(
692  const OpalIM & message
693  );
695 
708  virtual void OnMWIReceived (
709  const PString & party,
711  const PString & extraInfo
712  );
713 
718  virtual PBoolean GarbageCollection();
720 
725  OpalManager & GetManager() const { return manager; }
726 
729  const PString & GetPrefixName() const { return prefixName; }
730 
733  PBoolean HasAttribute(Attributes opt) const { return (attributeBits&opt) != 0; }
734 
737  WORD GetDefaultSignalPort() const { return defaultSignalPort; }
738 
741  const OpalProductInfo & GetProductInfo() const { return productInfo; }
742 
746  const OpalProductInfo & info
747  ) { productInfo = info; }
748 
751  const PString & GetDefaultLocalPartyName() const { return defaultLocalPartyName; }
752 
756  const PString & name
757  ) { defaultLocalPartyName = name; }
758 
761  const PString & GetDefaultDisplayName() const { return defaultDisplayName; }
762 
765  void SetDefaultDisplayName(const PString & name) { defaultDisplayName = name; }
766 
769  unsigned GetInitialBandwidth() const { return initialBandwidth; }
770 
773  void SetInitialBandwidth(unsigned bandwidth) { initialBandwidth = bandwidth; }
774 
777  const OpalListenerList & GetListeners() const { return listeners; }
778 
782 
786 
789  void SetDefaultStringOption(const PCaselessString & key, const PString & data) { m_defaultStringOptions.SetAt(key, data); }
790 
794 
799 
800 #if OPAL_PTLIB_SSL
801 
803  PString GetSSLCertificate() const;
804 #endif
805 
806  protected:
808  PCaselessString prefixName;
809  unsigned attributeBits;
811  PINDEX m_maxSizeUDP;
815 
816  unsigned initialBandwidth; // in 100s of bits/sev
819 
820  OpalListenerList listeners;
821 
822  class ConnectionDict : public PSafeDictionary<PString, OpalConnection>
823  {
824  virtual void DeleteObject(PObject * object) const;
827 
828  PMutex inUseFlag;
829 
830  friend void OpalManager::GarbageCollection();
831  friend void OpalConnection::Release(CallEndReason,bool);
832 
833  private:
834  P_REMOVE_VIRTUAL(PBoolean, OnIncomingConnection(OpalConnection &, unsigned), false);
835  P_REMOVE_VIRTUAL(PBoolean, OnIncomingConnection(OpalConnection &), false);
836  P_REMOVE_VIRTUAL_VOID(AdjustMediaFormats(const OpalConnection &, OpalMediaFormatList &) const);
837  P_REMOVE_VIRTUAL_VOID(OnMessageReceived(const PURL&,const PString&,const PURL&,const PString&,const PString&,const PString&));
838 };
839 
840 
842 bool OpalIsE164(
843  const PString & number,
844  bool strict = false
845 );
846 
847 
848 #endif // OPAL_OPAL_ENDPOINT_H
849 
850 
851 // End of File ///////////////////////////////////////////////////////////////