iax2ep.h

Go to the documentation of this file.
00001 /*
00002  *
00003  * Inter Asterisk Exchange 2
00004  * 
00005  * Open Phone Abstraction Library (OPAL)
00006  *
00007  * Describes the IAX2 extension of the OpalEndpoint class.
00008  *
00009  * Copyright (c) 2005 Indranet Technologies Ltd.
00010  *
00011  * The contents of this file are subject to the Mozilla Public License
00012  * Version 1.0 (the "License"); you may not use this file except in
00013  * compliance with the License. You may obtain a copy of the License at
00014  * http://www.mozilla.org/MPL/
00015  *
00016  * Software distributed under the License is distributed on an "AS IS"
00017  * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
00018  * the License for the specific language governing rights and limitations
00019  * under the License.
00020  *
00021  * The Original Code is Open Phone Abstraction Library.
00022  *
00023  * The Initial Developer of the Original Code is Indranet Technologies Ltd.
00024  *
00025  * The author of this code is Derek J Smithies
00026  *
00027  * $Revision: 29658 $
00028  * $Author: rjongbloed $
00029  * $Date: 2013-05-07 21:16:26 -0500 (Tue, 07 May 2013) $
00030  */
00031 
00032 #ifndef OPAL_IAX2_IAX2EP_H
00033 #define OPAL_IAX2_IAX2EP_H
00034 
00035 #ifndef _PTLIB_H
00036 #include <ptlib.h>
00037 #endif
00038 
00039 #ifdef P_USE_PRAGMA
00040 #pragma interface
00041 #endif
00042 
00043 #include <opal/buildopts.h>
00044 
00045 #if OPAL_IAX2
00046 
00047 #include <opal/endpoint.h>
00048 #include <iax2/iax2con.h>
00049 #include <iax2/processor.h>
00050 #include <iax2/regprocessor.h>
00051 #include <iax2/specialprocessor.h>
00052 
00053 class IAX2Receiver;
00054 class IAX2Transmit;
00055 class IAX2Processor;
00056 
00060 class IAX2IncomingEthernetFrames : public PThread
00061 {
00062   PCLASSINFO(IAX2IncomingEthernetFrames, PThread);
00063 public:
00064 
00068   IAX2IncomingEthernetFrames();
00069    
00071   ~IAX2IncomingEthernetFrames() { }
00072 
00075   /*The method which gets everythig to happen */
00076   virtual void Main();
00077    
00079   void Assign(IAX2EndPoint *ep);
00080 
00083   void ProcessList() { activate.Signal(); }
00084 
00086   void Terminate();
00087 
00089  protected:
00091   IAX2EndPoint *endpoint;
00092    
00094   PSyncPoint activate;
00095 
00097   PBoolean           keepGoing;
00098 };
00099 
00100 
00101 
00102 
00104 class IAX2EndPoint : public OpalEndPoint
00105 {
00106   PCLASSINFO(IAX2EndPoint, OpalEndPoint);
00107  public:
00108    enum { DefaultUdpPort = 4569 };
00109 
00113   IAX2EndPoint(
00114     OpalManager & manager
00115   );
00116   
00118   ~IAX2EndPoint();
00120   
00126     virtual PString GetDefaultTransport() const;
00127 
00130     virtual WORD GetDefaultSignalPort() const;
00131 
00132 
00162   virtual PSafePtr<OpalConnection> MakeConnection(
00163                               OpalCall & call,          
00164                               const PString & party,    
00165                               void * userData = NULL,   
00166                               unsigned int options = 0, 
00167                               OpalConnection::StringOptions * stringOptions = NULL
00168                               );
00169   
00173   virtual IAX2Connection * CreateConnection(
00174                                            OpalCall & call,            
00175                                            const PString & token,      
00176                                            void * userData,             
00177                                            const PString & remoteParty, 
00178              const PString & remotePartyName = PString::Empty() 
00179                                            );
00181   
00186   PBoolean Initialise();
00187 
00189   virtual void IncomingEthernetFrame (IAX2Frame *frame);
00190   
00196   PBoolean ConectionForFrameIsAlive(IAX2Frame *f);
00197   
00204   PINDEX NextSrcCallNumber(IAX2Processor * processor);
00205       
00208   void ReportStoredConnections();
00209   
00211   WORD ListenPortNumber()  { return 4569; }
00212       
00214   IAX2Transmit *transmitter;
00215   
00217   IAX2Receiver    *receiver;
00218   
00220   PString GetLocalUserName() { return localUserName; }
00221   
00223   PString GetLocalNumber() { return localNumber; }
00224   
00226   void SetLocalUserName(PString newValue); 
00227   
00229   void SetLocalNumber(PString newValue);
00230   
00232   PString & GetPassword() { return password; }
00233   
00235   void SetPassword(PString newValue);
00236 
00243   PBoolean ConnectionForFrameIsAlive(IAX2Frame *f);
00244  
00246   PINDEX GetOutSequenceNumberForStatusQuery();
00247   
00249   void StartRinging(PString remoteCaller);
00250   
00262     void NewIncomingConnection(
00263       IAX2Frame *f  
00264                 );
00265 
00271     void OnEstablished(
00272        OpalConnection & con
00273     );
00274 
00280     virtual void OnReleased(
00281       OpalConnection & connection   
00282     );
00283 
00293   virtual OpalMediaFormatList GetMediaFormats() const;
00294 
00296   PINDEX GetSupportedCodecs(OpalMediaFormatList & list);
00297   
00299   PINDEX GetPreferredCodec(OpalMediaFormatList & list);
00300 
00303   void GetCodecLengths(PINDEX src, PINDEX &compressedBytes, PINDEX &duration);
00304   
00310   enum IAX2RemoteAddressFields {
00311     protoIndex     = 0,     
00312     userIndex      = 1,     
00313     transportIndex = 2,     
00314     addressIndex   = 3,     
00315     portIndex      = 4,     
00316     extensionIndex = 5,     
00317     contextIndex   = 6,     
00318     maximumIndex   = 7      
00319   };
00320 
00327   static PStringArray DissectRemoteParty(const PString & other);
00328 
00332   void ProcessReceivedEthernetFrames();
00333 
00336   void ReportTransmitterLists(PString & answer, bool getFullReport = false);
00337 
00339   void CopyLocalMediaFormats(OpalMediaFormatList & list);
00340   
00346   void Register(
00347       const PString & host,
00348       const PString & username,
00349       const PString & password = PString::Empty(),
00350       PINDEX requestedRefreshTime = 60
00351     );
00352   
00353   enum RegisteredError {
00354     RegisteredFailureUnknown
00355   };
00356   
00359   virtual void OnRegistered(
00360       const PString & host,
00361       const PString & userName,
00362       PBoolean isFailure,
00363       RegisteredError reason = RegisteredFailureUnknown);
00364    
00367   void Unregister(
00368       const PString & host,
00369       const PString & username);
00370       
00371   enum UnregisteredError {
00372     UnregisteredFailureUnknown
00373   };
00374       
00379   virtual void OnUnregistered(
00380       const PString & host,
00381       const PString & userName,
00382       PBoolean isFailure,
00383       UnregisteredError reason = UnregisteredFailureUnknown);
00384       
00385   
00387   PBoolean IsRegistered(const PString & host, const PString & username);
00388   
00390   PINDEX GetRegistrationsCount();
00391   
00393   PString BuildUrl(
00394     const PString & host,
00395     const PString & userName = PString::Empty(),
00396     const PString & extension = PString::Empty(),
00397     const PString & context = PString::Empty(),
00398     const PString & transport = PString::Empty()
00399   );
00400   
00402   PBoolean InitialisedOK() { return (transmitter != NULL) && (receiver != NULL); }
00403 
00406   PBoolean EthernetFramesToBeProcessed() 
00407   { return packetsReadFromEthernet.GetSize() > 0; }
00409   
00410  protected:
00417   IAX2IncomingEthernetFrames incomingFrameHandler;
00418 
00421   IAX2FrameList   packetsReadFromEthernet;
00422   
00424   PUDPSocket  *sock;
00425 
00427   int callnumbs;
00428   
00430   PMutex callNumbLock;
00431   
00433   PTime callStartTime;
00434   
00436   PString localUserName;
00437   
00439   PString localNumber;
00440   
00442   PString password;
00443   
00445   PINDEX statusQueryCounter;
00446   
00448   PMutex statusQueryMutex;
00449   
00452   IAX2SpecialProcessor * specialPacketHandler;
00453     
00461   PBoolean ProcessInMatchingConnection(IAX2Frame *f);  
00462 
00471     PBoolean ProcessFrameInConnection(IAX2Frame *f, const PString & token);  
00472     
00479   PBoolean ProcessInConnectionTestAll(IAX2Frame *f);
00480   
00493   PStringToString    tokenTable;
00494   
00498   PReadWriteMutex    mutexTokenTable;
00499 
00502   PAtomicInteger callsEstablished;
00503 
00505   OpalMediaFormatList localMediaFormats;
00506   
00508   PMutex regProcessorsMutex;
00509   
00514   PArrayObjects regProcessors;
00515   
00516 };
00517 
00518 
00519 #endif // OPAL_IAX2
00520 
00521 #endif // OPAL_IAX2_IAX2EP_H
00522 
00523 /* The comment below is magic for those who use emacs to edit this file.
00524  * With the comment below, the tab key does auto indent to 2 spaces.    
00525  *
00526  * Local Variables:
00527  * mode:c
00528  * c-basic-offset:2
00529  * End:
00530  */
00531 

Generated on 21 Jun 2013 for OPAL by  doxygen 1.4.7