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: 21283 $
00028  * $Author: rjongbloed $
00029  * $Date: 2008-10-11 07:10:58 +0000 (Sat, 11 Oct 2008) $
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();
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:
00112   IAX2EndPoint(
00113     OpalManager & manager
00114   );
00115   
00117   ~IAX2EndPoint();
00119   
00126   virtual PBoolean NewIncomingConnection(
00127     OpalTransport * transport  
00128   );
00129   
00159   virtual PBoolean MakeConnection(
00160                               OpalCall & call,          
00161                               const PString & party,    
00162                               void * userData = NULL,   
00163                               unsigned int options = 0, 
00164                               OpalConnection::StringOptions * stringOptions = NULL
00165                               );
00166   
00170   virtual IAX2Connection * CreateConnection(
00171                                            OpalCall & call,            
00172                                            const PString & token,      
00173                                            void * userData,             
00174                                            const PString & remoteParty, 
00175              const PString & remotePartyName = PString::Empty() 
00176                                            );
00178   
00183   PBoolean Initialise();
00184 
00186   virtual void IncomingEthernetFrame (IAX2Frame *frame);
00187   
00193   PBoolean ConectionForFrameIsAlive(IAX2Frame *f);
00194   
00201   PINDEX NextSrcCallNumber(IAX2Processor * processor);
00202       
00205   void ReportStoredConnections();
00206   
00208   WORD ListenPortNumber()  { return 4569; }
00209       
00211   IAX2Transmit *transmitter;
00212   
00214   IAX2Receiver    *receiver;
00215   
00217   PString GetLocalUserName() { return localUserName; }
00218   
00220   PString GetLocalNumber() { return localNumber; }
00221   
00223   void SetLocalUserName(PString newValue); 
00224   
00226   void SetLocalNumber(PString newValue);
00227   
00229   PString & GetPassword() { return password; }
00230   
00232   void SetPassword(PString newValue);
00233 
00240   PBoolean ConnectionForFrameIsAlive(IAX2Frame *f);
00241  
00243   PINDEX GetOutSequenceNumberForStatusQuery();
00244   
00246   void StartRinging(PString remoteCaller);
00247   
00259     void NewIncomingConnection(
00260       IAX2Frame *f  
00261                 );
00262 
00268     void OnEstablished(
00269        OpalConnection & con
00270     );
00271 
00277     virtual void OnReleased(
00278       OpalConnection & connection   
00279     );
00280 
00290   virtual OpalMediaFormatList GetMediaFormats() const;
00291 
00292   virtual PBoolean OnIncomingCall(IAX2Connection & conn);
00293 
00295   PINDEX GetSupportedCodecs(OpalMediaFormatList & list);
00296   
00298   PINDEX GetPreferredCodec(OpalMediaFormatList & list);
00299 
00302   void GetCodecLengths(PINDEX src, PINDEX &compressedBytes, PINDEX &duration);
00303   
00309   enum IAX2RemoteAddressFields {
00310     protoIndex     = 0,     
00311     userIndex      = 1,     
00312     transportIndex = 2,     
00313     addressIndex   = 3,     
00314     extensionIndex = 4,     
00315     contextIndex   = 5,     
00316     maximumIndex   = 6      
00317   };
00318 
00325   static PStringArray DissectRemoteParty(const PString & other);
00326 
00330   void ProcessReceivedEthernetFrames();
00331 
00334   void ReportTransmitterLists(PString & answer, bool getFullReport = false);
00335 
00337   void CopyLocalMediaFormats(OpalMediaFormatList & list);
00338   
00344   void Register(
00345       const PString & host,
00346       const PString & username,
00347       const PString & password = PString::Empty(),
00348       PINDEX requestedRefreshTime = 60
00349     );
00350   
00351   enum RegisteredError {
00352     RegisteredFailureUnknown
00353   };
00354   
00357   virtual void OnRegistered(
00358       const PString & host,
00359       const PString & userName,
00360       PBoolean isFailure,
00361       RegisteredError reason = RegisteredFailureUnknown);
00362    
00365   void Unregister(
00366       const PString & host,
00367       const PString & username);
00368       
00369   enum UnregisteredError {
00370     UnregisteredFailureUnknown
00371   };
00372       
00377   virtual void OnUnregistered(
00378       const PString & host,
00379       const PString & userName,
00380       PBoolean isFailure,
00381       UnregisteredError reason = UnregisteredFailureUnknown);
00382       
00383   
00385   PBoolean IsRegistered(const PString & host, const PString & username);
00386   
00388   PINDEX GetRegistrationsCount();
00389   
00391   PString BuildUrl(
00392     const PString & host,
00393     const PString & userName = PString::Empty(),
00394     const PString & extension = PString::Empty(),
00395     const PString & context = PString::Empty(),
00396     const PString & transport = PString::Empty()
00397   );
00398   
00400   
00401  protected:
00408   IAX2IncomingEthernetFrames incomingFrameHandler;
00409 
00412   IAX2FrameList   packetsReadFromEthernet;
00413   
00415   PUDPSocket  *sock;
00416   
00418   int callnumbs;
00419   
00421   PMutex callNumbLock;
00422   
00424   PTime callStartTime;
00425   
00427   PString localUserName;
00428   
00430   PString localNumber;
00431   
00433   PString password;
00434   
00436   PINDEX statusQueryCounter;
00437   
00439   PMutex statusQueryMutex;
00440   
00443   IAX2SpecialProcessor * specialPacketHandler;
00444     
00452   PBoolean ProcessInMatchingConnection(IAX2Frame *f);  
00453     
00461   PBoolean AddNewTranslationEntry(IAX2Frame *f);
00462   
00475   PStringToString    tokenTable;
00476   
00480   PReadWriteMutex    mutexTokenTable;
00481 
00484   PAtomicInteger callsEstablished;
00485 
00487   OpalMediaFormatList localMediaFormats;
00488   
00490   PMutex regProcessorsMutex;
00491   
00496   PArrayObjects regProcessors;
00497   
00498 };
00499 
00500 
00501 #endif // OPAL_IAX2
00502 
00503 #endif // OPAL_IAX2_IAX2EP_H
00504 
00505 /* The comment below is magic for those who use emacs to edit this file. */
00506 /* With the comment below, the tab key does auto indent to 2 spaces.     */
00507 
00508 /*
00509  * Local Variables:
00510  * mode:c
00511  * c-basic-offset:2
00512  * End:
00513  */
00514 

Generated on Mon Feb 23 02:01:36 2009 for OPAL by  doxygen 1.5.1