processor.h

Go to the documentation of this file.
00001 /*
00002  *
00003  * Inter Asterisk Exchange 2
00004  * 
00005  * The core routine which determines the processing of packets for one call.
00006  * 
00007  * Open Phone Abstraction Library (OPAL)
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  * 
00028  *  $Log: processor.h,v $
00029  *  Revision 1.16  2007/04/19 06:17:21  csoutheren
00030  *  Fixes for precompiled headers with gcc
00031  *
00032  *  Revision 1.15  2007/01/23 02:08:25  dereksmithies
00033  *  Handle Vnak frames correctly. handle iseqno and oseqno correctly.
00034  *
00035  *  Revision 1.14  2007/01/17 03:48:13  dereksmithies
00036  *  Tidy up comments, remove leaks, improve reporting of packet types.
00037  *
00038  *  Revision 1.13  2007/01/16 03:17:42  dereksmithies
00039  *  tidyup of comments. Remove unused variables.
00040  *  Guarantee that media frames are sent with a monotonically increasing timestamp
00041  *
00042  *  Revision 1.12  2007/01/11 03:02:15  dereksmithies
00043  *  Remove the previous audio buffering code, and switch to using the jitter
00044  *  buffer provided in Opal. Reduce the verbosity of the log mesasges.
00045  *
00046  *  Revision 1.11  2006/09/22 00:33:19  csoutheren
00047  *  Changed PAtomicInteger to BOOL
00048  *
00049  *  Revision 1.10  2006/09/11 03:08:51  dereksmithies
00050  *  Add fixes from Stephen Cook (sitiveni@gmail.com) for new patches to
00051  *  improve call handling. Notably, IAX2 call transfer. Many thanks.
00052  *  Thanks also to the Google summer of code for sponsoring this work.
00053  *
00054  *  Revision 1.9  2006/08/09 03:46:39  dereksmithies
00055  *  Add ability to register to a remote Asterisk box. The iaxProcessor class is split
00056  *  into a callProcessor and a regProcessor class.
00057  *  Big thanks to Stephen Cook, (sitiveni@gmail.com) for this work.
00058  * 
00059  *  Revision 1.8  2006/06/16 01:47:08  dereksmithies
00060  *  Get the OnHold features of IAX2 to work correctly.
00061  *  Thanks to Stephen Cook, (sitiveni@gmail.com) for this work.
00062  *
00063  *  Revision 1.7  2005/09/05 01:19:43  dereksmithies
00064  *  add patches from Adrian Sietsma to avoid multiple hangup packets at call end,
00065  *  and stop the sending of ping/lagrq packets at call end. Many thanks.
00066  *
00067  *  Revision 1.6  2005/08/26 03:07:38  dereksmithies
00068  *  Change naming convention, so all class names contain the string "IAX2"
00069  *
00070  *  Revision 1.5  2005/08/25 03:26:06  dereksmithies
00071  *  Add patch from Adrian Sietsma to correctly set the packet timestamps under windows.
00072  *  Many thanks.
00073  *
00074  *  Revision 1.4  2005/08/24 04:56:25  dereksmithies
00075  *  Add code from Adrian Sietsma to send FullFrameTexts and FullFrameDtmfs to
00076  *  the remote end.  Many Thanks.
00077  *
00078  *  Revision 1.3  2005/08/24 01:38:38  dereksmithies
00079  *  Add encryption, iax2 style. Numerous tidy ups. Use the label iax2, not iax
00080  *
00081  *  Revision 1.2  2005/08/04 08:14:17  rjongbloed
00082  *  Fixed Windows build under DevStudio 2003 of IAX2 code
00083  *
00084  *  Revision 1.1  2005/07/30 07:01:32  csoutheren
00085  *  Added implementation of IAX2 (Inter Asterisk Exchange 2) protocol
00086  *  Thanks to Derek Smithies of Indranet Technologies Ltd. for
00087  *  writing and contributing this code
00088  *
00089  *
00090  *
00091  *
00092  *
00093  *
00094  *
00095  */
00096 
00097 #ifndef PROCESSOR_H
00098 #define PROCESSOR_H
00099 
00100 #ifndef _PTLIB_H
00101 #include <ptlib.h>
00102 #endif
00103 
00104 #include <opal/connection.h>
00105 
00106 #include <iax2/frame.h>
00107 #include <iax2/iedata.h>
00108 #include <iax2/remote.h>
00109 #include <iax2/safestrings.h>
00110 #include <iax2/sound.h>
00111 
00112 class IAX2EndPoint;
00113 class IAX2Connection;
00114 class IAX2ThreadHelper;
00115 
00117 
00138 class IAX2WaitingForAck : public PObject
00139 {
00140   PCLASSINFO(IAX2WaitingForAck, PObject);
00141 
00142  public:
00144   enum ResponseToAck {
00145     RingingAcked   = 0,  
00146     AcceptAcked    = 1,  
00147     AuthRepAcked   = 2,  
00148     AnswerAcked    = 3   
00149   };
00150   
00152   IAX2WaitingForAck();
00153   
00155   void Assign(IAX2FullFrame *f, ResponseToAck _response);
00156   
00158   BOOL MatchingAckPacket(IAX2FullFrame *f);
00159   
00161   ResponseToAck GetResponse() { return response; }
00162   
00164   PString GetResponseAsString() const;
00165   
00167   virtual void PrintOn(ostream & strm) const;
00168   
00170   void ZeroValues();
00171   
00172  private:
00174   DWORD timeStamp;
00175   
00177   PINDEX seqNo;
00178   
00180   ResponseToAck response;
00181 };
00182 
00184 
00197 class IAX2Processor : public PThread
00198 {
00199   PCLASSINFO(IAX2Processor, PObject);
00200   
00201  public:
00203   IAX2Processor(IAX2EndPoint & ep);
00204 
00206   virtual ~IAX2Processor();
00207   
00209   IAX2SequenceNumbers & GetSequenceInfo() { return sequence; }
00210   
00212   IAX2Encryption & GetEncryptionInfo() { return encryption; }
00213   
00215   void IncomingEthernetFrame (IAX2Frame *frame);
00216   
00219   virtual void PrintOn(ostream & strm) const = 0;
00220   
00222   IAX2EndPoint & GetEndPoint() { return endpoint; };
00223   
00233   void SetCallToken(const PString & newToken);
00234   
00236   PString GetCallToken();
00237   
00239   IAX2Remote & GetRemoteInfo() { return remote; }
00240   
00242   const PTimeInterval & GetCallStartTick() { return callStartTick; }
00243   
00247   void Main();
00248   
00251   BOOL IsStatusQueryEthernetFrame(IAX2Frame *frame);
00252   
00255   void SetSpecialPackets(BOOL newValue) { specialPackets = newValue; }
00256   
00258   void Terminate();
00259   
00262   void Activate();
00263 
00264  protected:
00265  
00267   IAX2EndPoint      & endpoint;
00268  
00272   PTimeInterval callStartTick;
00273   
00275   IAX2Remote remote;
00276   
00279   void StartNoResponseTimer(PINDEX msToWait = 60000);
00280    
00282   void StopNoResponseTimer() { noResponseTimer.Stop(); }
00283   
00285   PTimer noResponseTimer;
00286   
00288   void CleanPendingLists() { activate.Signal(); }
00289   
00292   IAX2WaitingForAck nextTask;
00293   
00295   PSyncPoint activate;
00296   
00298   BOOL endThread;
00299   
00301   IAX2Encryption encryption;
00302   
00304   IAX2SequenceNumbers sequence;
00305   
00307   IAX2FrameList frameList;
00308   
00311   SafeString callToken;
00312   
00314   virtual void OnNoResponseTimeout() = 0;
00315   
00318   enum DefinedNoResponseTimePeriod {
00319     NoResponseTimePeriod = 5000 
00320   };
00321   
00325   BOOL      IsHandlingSpecialPackets() { return specialPackets; };
00326 
00329   BOOL       specialPackets;
00330   
00333   virtual void ProcessLists() = 0;  
00334   
00337   virtual void ProcessFullFrame(IAX2FullFrame & fullFrame) = 0;
00338   
00341   virtual void ProcessIaxCmdLagRq(IAX2FullFrameProtocol *src);
00342   
00345   virtual void ProcessIaxCmdLagRp(IAX2FullFrameProtocol *src);
00346   
00349   virtual void ProcessIaxCmdVnak(IAX2FullFrameProtocol *src);
00350   
00353   virtual void ProcessIaxCmdPing(IAX2FullFrameProtocol *src);
00354   
00357   virtual void ProcessIaxCmdPong(IAX2FullFrameProtocol *src); 
00358   
00362   BOOL ProcessOneIncomingEthernetFrame();
00363   
00365   PAtomicInteger controlFramesSent;
00366   
00368   PAtomicInteger controlFramesRcvd;
00369   
00371   void IncControlFramesSent() { ++controlFramesSent; }
00372   
00374   void IncControlFramesRcvd() { ++controlFramesRcvd; }
00375   
00378   virtual void ProcessNetworkFrame(IAX2MiniFrame * src) = 0;  
00379 
00380   /* A frame of FullFrameProtocol type is labelled as AST_FRAME_IAX in the
00381      asterisk souces, It will contain 0, 1, 2 or more Information Elements
00382      (Ie) in the data section. This processor is used to do things that are
00383      common to registration and call handling.
00384 
00385   This method will eat/delete the supplied frame. Return TRUE on success,
00386   FALSE on failure.*/
00387   virtual BOOL ProcessNetworkFrame(IAX2FullFrameProtocol * src);
00388   
00392   void TransmitFrameToRemoteEndpoint(IAX2Frame *src);
00393 
00399   void TransmitFrameToRemoteEndpoint(IAX2FullFrame *src,
00400              IAX2WaitingForAck::ResponseToAck response  
00401              );
00402 
00406   void TransmitFrameNow(IAX2Frame *src);
00407   
00409   void TransmitFrameToRemoteEndpoint(IAX2FullFrameProtocol *src);
00410   
00413   BOOL Authenticate(IAX2FullFrameProtocol *reply, 
00414                     PString & password 
00415         );
00416         
00418   IAX2IeData ieData;
00419   
00422   void SendAckFrame(IAX2FullFrame *inReplyTo);
00423 
00427   void SendVnakFrame(IAX2FullFrame *inReplyTo);
00428   
00430   void SendUnsupportedFrame(IAX2FullFrame *inReplyTo);
00431   
00432  private:
00433 #ifdef DOC_PLUS_PLUS
00434 
00441   void OnNoResponseTimeoutStart(PTimer &, INT);
00442 #else
00443   PDECLARE_NOTIFIER(PTimer, IAX2Processor, OnNoResponseTimeoutStart);
00444 #endif 
00445 
00446  protected:
00453   DWORD currentSoundTimeStamp;
00454 };
00455 
00456 #endif // PROCESSOR_H

Generated on Fri Mar 7 06:33:40 2008 for OPAL by  doxygen 1.5.1