OPAL  Version 3.10.4
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: 26937 $
28  * $Author: rjongbloed $
29  * $Date: 2012-02-06 19:54:19 -0600 (Mon, 06 Feb 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 
480  virtual PBoolean ClearCall(
481  const PString & token,
483  PSyncPoint * sync = NULL
484  );
485 
490  virtual PBoolean ClearCallSynchronous(
491  const PString & token,
493  PSyncPoint * sync = NULL
494  );
495 
502  virtual void ClearAllCalls(
504  PBoolean wait = true
505  );
506 
511  PSafePtr<OpalConnection> GetConnectionWithLock(
512  const PString & token,
513  PSafetyMode mode = PSafeReadWrite
514  ) { return connectionsActive.FindWithLock(token, mode); }
515 
522  template <class ConnClass>
523  PSafePtr<ConnClass> GetConnectionWithLockAs(
524  const PString & token,
525  PSafetyMode mode = PSafeReadWrite
526  )
527  {
528  PSafePtr<ConnClass> connection = PSafePtrCast<OpalConnection, ConnClass>(GetConnectionWithLock(token, mode));
529  if (connection == NULL) {
530  PSafePtr<OpalCall> call = manager.FindCallWithLock(token, PSafeReadOnly);
531  if (call != NULL) {
532  connection = PSafePtrCast<OpalConnection, ConnClass>(call->GetConnection(0, mode));
533  if (connection == NULL)
534  connection = PSafePtrCast<OpalConnection, ConnClass>(call->GetConnection(1, mode));
535  }
536  }
537  return connection;
538  }
539 
542  PStringList GetAllConnections();
543 
546  PINDEX GetConnectionCount() const { return connectionsActive.GetSize(); }
547 
550  virtual PBoolean HasConnection(
551  const PString & token
552  );
553 
556  virtual void DestroyConnection(
557  OpalConnection * connection
558  );
560 
572  virtual OpalMediaFormatList GetMediaFormats() const = 0;
573 
582  virtual void AdjustMediaFormats(
583  bool local,
584  const OpalConnection & connection,
585  OpalMediaFormatList & mediaFormats
586  ) const;
587 
599  virtual PBoolean OnOpenMediaStream(
600  OpalConnection & connection,
601  OpalMediaStream & stream
602  );
603 
608  virtual void OnClosedMediaStream(
609  const OpalMediaStream & stream
610  );
611 
612 #if OPAL_VIDEO
613 
615  virtual PBoolean CreateVideoInputDevice(
616  const OpalConnection & connection,
617  const OpalMediaFormat & mediaFormat,
618  PVideoInputDevice * & device,
619  PBoolean & autoDelete
620  );
621 
625  virtual PBoolean CreateVideoOutputDevice(
626  const OpalConnection & connection,
627  const OpalMediaFormat & mediaFormat,
628  PBoolean preview,
629  PVideoOutputDevice * & device,
630  PBoolean & autoDelete
631  );
632 #endif
633 
634 
641  virtual void OnUserInputString(
642  OpalConnection & connection,
643  const PString & value
644  );
645 
652  virtual void OnUserInputTone(
653  OpalConnection & connection,
654  char tone,
655  int duration
656  );
657 
660  virtual PString ReadUserInput(
661  OpalConnection & connection,
662  const char * terminators = "#\r\n",
663  unsigned lastDigitTimeout = 4,
664  unsigned firstDigitTimeout = 30
665  );
667 
672  virtual PBoolean Message(
673  const PString & to,
674  const PString & body
675  );
676  virtual PBoolean Message(
677  const PURL & to,
678  const PString & type,
679  const PString & body,
680  PURL & from,
681  PString & conversationId
682  );
683  virtual PBoolean Message(
684  OpalIM & Message
685  );
686 
689  virtual void OnMessageReceived(
690  const OpalIM & message
691  );
693 
706  virtual void OnMWIReceived (
707  const PString & party,
709  const PString & extraInfo
710  );
711 
716  virtual PBoolean GarbageCollection();
718 
723  OpalManager & GetManager() const { return manager; }
724 
727  const PString & GetPrefixName() const { return prefixName; }
728 
731  PBoolean HasAttribute(Attributes opt) const { return (attributeBits&opt) != 0; }
732 
735  WORD GetDefaultSignalPort() const { return defaultSignalPort; }
736 
739  const OpalProductInfo & GetProductInfo() const { return productInfo; }
740 
744  const OpalProductInfo & info
745  ) { productInfo = info; }
746 
749  const PString & GetDefaultLocalPartyName() const { return defaultLocalPartyName; }
750 
754  const PString & name
755  ) { defaultLocalPartyName = name; }
756 
759  const PString & GetDefaultDisplayName() const { return defaultDisplayName; }
760 
763  void SetDefaultDisplayName(const PString & name) { defaultDisplayName = name; }
764 
767  unsigned GetInitialBandwidth() const { return initialBandwidth; }
768 
771  void SetInitialBandwidth(unsigned bandwidth) { initialBandwidth = bandwidth; }
772 
775  const OpalListenerList & GetListeners() const { return listeners; }
776 
780 
784 
787  void SetDefaultStringOption(const PCaselessString & key, const PString & data) { m_defaultStringOptions.SetAt(key, data); }
788 
792 
797 
798 #if OPAL_PTLIB_SSL
799 
801  PString GetSSLCertificate() const;
802 #endif
803 
804  protected:
806  PCaselessString prefixName;
807  unsigned attributeBits;
809  PINDEX m_maxSizeUDP;
813 
814  unsigned initialBandwidth; // in 100s of bits/sev
817 
818  OpalListenerList listeners;
819 
820  class ConnectionDict : public PSafeDictionary<PString, OpalConnection>
821  {
822  virtual void DeleteObject(PObject * object) const;
825 
826  PMutex inUseFlag;
827 
828  friend void OpalManager::GarbageCollection();
829  friend void OpalConnection::Release(CallEndReason reason);
830 
831  private:
832  P_REMOVE_VIRTUAL(PBoolean, OnIncomingConnection(OpalConnection &, unsigned), false);
833  P_REMOVE_VIRTUAL(PBoolean, OnIncomingConnection(OpalConnection &), false);
834  P_REMOVE_VIRTUAL_VOID(AdjustMediaFormats(const OpalConnection &, OpalMediaFormatList &) const);
835  P_REMOVE_VIRTUAL_VOID(OnMessageReceived(const PURL&,const PString&,const PURL&,const PString&,const PString&,const PString&));
836 };
837 
838 
840 bool OpalIsE164(
841  const PString & number,
842  bool strict = false
843 );
844 
845 
846 #endif // OPAL_OPAL_ENDPOINT_H
847 
848 
849 // End of File ///////////////////////////////////////////////////////////////