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: 24719 $
00028  * $Author: rjongbloed $
00029  * $Date: 2010-09-23 18:55:55 -0500 (Thu, 23 Sep 2010) $
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:
00112   IAX2EndPoint(
00113     OpalManager & manager,
00114     unsigned short port = 4569
00115   );
00116   
00118   ~IAX2EndPoint();
00120   
00127   virtual PBoolean NewIncomingConnection(
00128     OpalTransport * transport  
00129   );
00130   
00160   virtual PSafePtr<OpalConnection> MakeConnection(
00161                               OpalCall & call,          
00162                               const PString & party,    
00163                               void * userData = NULL,   
00164                               unsigned int options = 0, 
00165                               OpalConnection::StringOptions * stringOptions = NULL
00166                               );
00167   
00171   virtual IAX2Connection * CreateConnection(
00172                                            OpalCall & call,            
00173                                            const PString & token,      
00174                                            void * userData,             
00175                                            const PString & remoteParty, 
00176              const PString & remotePartyName = PString::Empty() 
00177                                            );
00179   
00184   PBoolean Initialise();
00185 
00187   virtual void IncomingEthernetFrame (IAX2Frame *frame);
00188   
00194   PBoolean ConectionForFrameIsAlive(IAX2Frame *f);
00195   
00202   PINDEX NextSrcCallNumber(IAX2Processor * processor);
00203       
00206   void ReportStoredConnections();
00207   
00209   WORD ListenPortNumber()  { return 4569; }
00210       
00212   IAX2Transmit *transmitter;
00213   
00215   IAX2Receiver    *receiver;
00216   
00218   PString GetLocalUserName() { return localUserName; }
00219   
00221   PString GetLocalNumber() { return localNumber; }
00222   
00224   void SetLocalUserName(PString newValue); 
00225   
00227   void SetLocalNumber(PString newValue);
00228   
00230   PString & GetPassword() { return password; }
00231   
00233   void SetPassword(PString newValue);
00234 
00241   PBoolean ConnectionForFrameIsAlive(IAX2Frame *f);
00242  
00244   PINDEX GetOutSequenceNumberForStatusQuery();
00245   
00247   void StartRinging(PString remoteCaller);
00248   
00260     void NewIncomingConnection(
00261       IAX2Frame *f  
00262                 );
00263 
00269     void OnEstablished(
00270        OpalConnection & con
00271     );
00272 
00278     virtual void OnReleased(
00279       OpalConnection & connection   
00280     );
00281 
00291   virtual OpalMediaFormatList GetMediaFormats() const;
00292 
00294   PINDEX GetSupportedCodecs(OpalMediaFormatList & list);
00295   
00297   PINDEX GetPreferredCodec(OpalMediaFormatList & list);
00298 
00301   void GetCodecLengths(PINDEX src, PINDEX &compressedBytes, PINDEX &duration);
00302   
00308   enum IAX2RemoteAddressFields {
00309     protoIndex     = 0,     
00310     userIndex      = 1,     
00311     transportIndex = 2,     
00312     addressIndex   = 3,     
00313     portIndex      = 4,     
00314     extensionIndex = 5,     
00315     contextIndex   = 6,     
00316     maximumIndex   = 7      
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   PBoolean InitialisedOK() { return (transmitter != NULL) && (receiver != NULL); }
00401 
00404   PBoolean EthernetFramesToBeProcessed() 
00405   { return packetsReadFromEthernet.GetSize() > 0; }
00407   
00408  protected:
00415   IAX2IncomingEthernetFrames incomingFrameHandler;
00416 
00419   IAX2FrameList   packetsReadFromEthernet;
00420   
00422   PUDPSocket  *sock;
00423 
00425   unsigned short localPort;
00426 
00428   int callnumbs;
00429   
00431   PMutex callNumbLock;
00432   
00434   PTime callStartTime;
00435   
00437   PString localUserName;
00438   
00440   PString localNumber;
00441   
00443   PString password;
00444   
00446   PINDEX statusQueryCounter;
00447   
00449   PMutex statusQueryMutex;
00450   
00453   IAX2SpecialProcessor * specialPacketHandler;
00454     
00462   PBoolean ProcessInMatchingConnection(IAX2Frame *f);  
00463 
00472     PBoolean ProcessFrameInConnection(IAX2Frame *f, const PString & token);  
00473     
00480   PBoolean ProcessInConnectionTestAll(IAX2Frame *f);
00481   
00494   PStringToString    tokenTable;
00495   
00499   PReadWriteMutex    mutexTokenTable;
00500 
00503   PAtomicInteger callsEstablished;
00504 
00506   OpalMediaFormatList localMediaFormats;
00507   
00509   PMutex regProcessorsMutex;
00510   
00515   PArrayObjects regProcessors;
00516   
00517 };
00518 
00519 
00520 #endif // OPAL_IAX2
00521 
00522 #endif // OPAL_IAX2_IAX2EP_H
00523 
00524 /* The comment below is magic for those who use emacs to edit this file.
00525  * With the comment below, the tab key does auto indent to 2 spaces.    
00526  *
00527  * Local Variables:
00528  * mode:c
00529  * c-basic-offset:2
00530  * End:
00531  */
00532 

Generated on Sun Nov 21 20:20:50 2010 for OPAL by  doxygen 1.4.7