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 PBoolean
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   PBoolean 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   PBoolean IsStatusQueryEthernetFrame(IAX2Frame *frame);
00252   
00255   void SetSpecialPackets(PBoolean newValue) { specialPackets = newValue; }
00256   
00258   void Terminate();
00259   
00264   void Activate();
00265 
00272   virtual PBoolean IncomingMessageOutOfOrder(IAX2FullFrame *ff)= 0;
00273 
00275   void ReportLists(PString & answer);
00276 
00277  protected:
00278  
00280   IAX2EndPoint      & endpoint;
00281  
00285   PTimeInterval callStartTick;
00286   
00288   IAX2Remote remote;
00289   
00292   void StartNoResponseTimer(PINDEX msToWait = 60000);
00293    
00295   void StopNoResponseTimer() { noResponseTimer.Stop(); }
00296   
00298   PTimer noResponseTimer;
00299   
00301   void CleanPendingLists() { activate.Signal(); }
00302   
00305   IAX2WaitingForAck nextTask;
00306   
00308   PSyncPoint activate;
00309   
00311   PBoolean endThread;
00312   
00314   IAX2Encryption encryption;
00315   
00317   IAX2SequenceNumbers sequence;
00318   
00320   IAX2ActiveFrameList frameList;
00321   
00324   SafeString callToken;
00325   
00327   virtual void OnNoResponseTimeout() = 0;
00328   
00331   enum DefinedNoResponseTimePeriod {
00332     NoResponseTimePeriod = 5000 
00333   };
00334   
00338   PBoolean      IsHandlingSpecialPackets() { return specialPackets; };
00339 
00342   PBoolean       specialPackets;
00343   
00346   virtual void ProcessLists() = 0;  
00347   
00350   virtual void ProcessFullFrame(IAX2FullFrame & fullFrame) = 0;
00351   
00354   virtual void ProcessIaxCmdLagRq(IAX2FullFrameProtocol *src);
00355   
00358   virtual void ProcessIaxCmdLagRp(IAX2FullFrameProtocol *src);
00359   
00362   virtual void ProcessIaxCmdVnak(IAX2FullFrameProtocol *src);
00363   
00366   virtual void ProcessIaxCmdPing(IAX2FullFrameProtocol *src);
00367   
00370   virtual void ProcessIaxCmdPong(IAX2FullFrameProtocol *src); 
00371   
00375   PBoolean ProcessOneIncomingEthernetFrame();
00376   
00378   PAtomicInteger controlFramesSent;
00379   
00381   PAtomicInteger controlFramesRcvd;
00382   
00384   void IncControlFramesSent() { ++controlFramesSent; }
00385   
00387   void IncControlFramesRcvd() { ++controlFramesRcvd; }
00388   
00391   virtual void ProcessNetworkFrame(IAX2MiniFrame * src) = 0;  
00392 
00393   /* A frame of FullFrameProtocol type is labelled as AST_FRAME_IAX in the
00394      asterisk souces, It will contain 0, 1, 2 or more Information Elements
00395      (Ie) in the data section. This processor is used to do things that are
00396      common to registration and call handling.
00397 
00398   This method will eat/delete the supplied frame. Return PTrue on success,
00399   PFalse on failure.*/
00400   virtual PBoolean ProcessNetworkFrame(IAX2FullFrameProtocol * src);
00401   
00405   void TransmitFrameToRemoteEndpoint(IAX2Frame *src);
00406 
00412   void TransmitFrameToRemoteEndpoint(IAX2FullFrame *src,
00413              IAX2WaitingForAck::ResponseToAck response  
00414              );
00415 
00419   void TransmitFrameNow(IAX2Frame *src);
00420   
00422   void TransmitFrameToRemoteEndpoint(IAX2FullFrameProtocol *src);
00423   
00426   PBoolean Authenticate(IAX2FullFrameProtocol *reply, 
00427                     PString & password 
00428         );
00429         
00431   IAX2IeData ieData;
00432   
00435   void SendAckFrame(IAX2FullFrame *inReplyTo);
00436 
00440   void SendVnakFrame(IAX2FullFrame *inReplyTo);
00441   
00443   void SendUnsupportedFrame(IAX2FullFrame *inReplyTo);
00444   
00445  private:
00446 #ifdef DOC_PLUS_PLUS
00447 
00454   void OnNoResponseTimeoutStart(PTimer &, INT);
00455 #else
00456   PDECLARE_NOTIFIER(PTimer, IAX2Processor, OnNoResponseTimeoutStart);
00457 #endif 
00458 
00459  protected:
00466   DWORD currentSoundTimeStamp;
00467 };
00468 
00469 #endif // PROCESSOR_H

Generated on Mon Sep 15 11:49:14 2008 for OPAL by  doxygen 1.5.1