OPAL  Version 3.14.3
processor.h
Go to the documentation of this file.
1 /*
2  *
3  * Inter Asterisk Exchange 2
4  *
5  * The core routine which determines the processing of packets for one call.
6  *
7  * Open Phone Abstraction Library (OPAL)
8  *
9  * Copyright (c) 2005 Indranet Technologies Ltd.
10  *
11  * The contents of this file are subject to the Mozilla Public License
12  * Version 1.0 (the "License"); you may not use this file except in
13  * compliance with the License. You may obtain a copy of the License at
14  * http://www.mozilla.org/MPL/
15  *
16  * Software distributed under the License is distributed on an "AS IS"
17  * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
18  * the License for the specific language governing rights and limitations
19  * under the License.
20  *
21  * The Original Code is Open Phone Abstraction Library.
22  *
23  * The Initial Developer of the Original Code is Indranet Technologies Ltd.
24  *
25  * The author of this code is Derek J Smithies
26  *
27  * $Revision: 29536 $
28  * $Author: rjongbloed $
29  * $Date: 2013-04-19 18:55:15 +1000 (Fri, 19 Apr 2013) $
30  */
31 
32 #ifndef OPAL_IAX2_PROCESSOR_H
33 #define OPAL_IAX2_PROCESSOR_H
34 
35 #ifndef _PTLIB_H
36 #include <ptlib.h>
37 #endif
38 
39 #include <opal_config.h>
40 
41 #if OPAL_IAX2
42 
43 #include <opal/connection.h>
44 
45 #include <iax2/frame.h>
46 #include <iax2/iedata.h>
47 #include <iax2/remote.h>
48 #include <iax2/safestrings.h>
49 #include <iax2/sound.h>
50 
51 class IAX2EndPoint;
52 class IAX2Connection;
53 class IAX2ThreadHelper;
54 
56 
77 class IAX2WaitingForAck : public PObject
78 {
79  PCLASSINFO(IAX2WaitingForAck, PObject);
80 
81  public:
88  };
89 
92 
94  void Assign(IAX2FullFrame *f, ResponseToAck _response);
95 
97  PBoolean MatchingAckPacket(IAX2FullFrame *f);
98 
100  ResponseToAck GetResponse() { return response; }
101 
103  PString GetResponseAsString() const;
104 
106  virtual void PrintOn(ostream & strm) const;
107 
109  void ZeroValues();
110 
111  private:
113  DWORD timeStamp;
114 
116  PINDEX seqNo;
117 
119  ResponseToAck response;
120 };
121 
123 
136 class IAX2Processor : public PThread
137 {
138  PCLASSINFO(IAX2Processor, PObject);
139 
140  public:
143 
145  virtual ~IAX2Processor();
146 
149 
152 
154  void IncomingEthernetFrame (IAX2Frame *frame);
155 
158  virtual void PrintOn(ostream & strm) const = 0;
159 
162 
172  void SetCallToken(const PString & newToken);
173 
175  PString GetCallToken();
176 
179 
181  const PTimeInterval & GetCallStartTick() { return callStartTick; }
182 
186  void Main();
187 
190  PBoolean IsStatusQueryEthernetFrame(IAX2Frame *frame);
191 
194  void SetSpecialPackets(PBoolean newValue) { specialPackets = newValue; }
195 
197  void Terminate();
198 
203  void Activate();
204 
211  virtual PBoolean IncomingMessageOutOfOrder(IAX2FullFrame *ff)= 0;
212 
214  void ReportLists(PString & answer);
215 
216  protected:
217 
220 
224  PTimeInterval callStartTick;
225 
228 
231  void StartNoResponseTimer(PINDEX msToWait = 60000);
232 
235 
238 
240  void CleanPendingLists() { activate.Signal(); }
241 
245 
247  PSyncPoint activate;
248 
250  PBoolean endThread;
251 
254 
257 
260 
264 
266  virtual void OnNoResponseTimeout() = 0;
267 
272  };
273 
277  PBoolean IsHandlingSpecialPackets() { return specialPackets; };
278 
281  PBoolean specialPackets;
282 
285  virtual void ProcessLists() = 0;
286 
289  virtual void ProcessFullFrame(IAX2FullFrame & fullFrame) = 0;
290 
293  virtual void ProcessIaxCmdLagRq(IAX2FullFrameProtocol *src);
294 
297  virtual void ProcessIaxCmdLagRp(IAX2FullFrameProtocol *src);
298 
301  virtual void ProcessIaxCmdVnak(IAX2FullFrameProtocol *src);
302 
305  virtual void ProcessIaxCmdPing(IAX2FullFrameProtocol *src);
306 
309  virtual void ProcessIaxCmdPong(IAX2FullFrameProtocol *src);
310 
315 
317  PAtomicInteger controlFramesSent;
318 
320  PAtomicInteger controlFramesRcvd;
321 
324 
327 
330  virtual void ProcessNetworkFrame(IAX2MiniFrame * src) = 0;
331 
332  /* A frame of FullFrameProtocol type is labelled as AST_FRAME_IAX in the
333  asterisk souces, It will contain 0, 1, 2 or more Information Elements
334  (Ie) in the data section. This processor is used to do things that are
335  common to registration and call handling.
336 
337  This method will eat/delete the supplied frame. Return true on success,
338  false on failure.*/
339  virtual PBoolean ProcessNetworkFrame(IAX2FullFrameProtocol * src);
340 
345 
353  );
354 
358  void TransmitFrameNow(IAX2Frame *src);
359 
362 
365  PBoolean Authenticate(IAX2FullFrameProtocol *reply,
366  PString & password
367  );
368 
371 
374  void SendAckFrame(IAX2FullFrame *inReplyTo);
375 
379  void SendVnakFrame(IAX2FullFrame *inReplyTo);
380 
382  void SendUnsupportedFrame(IAX2FullFrame *inReplyTo);
383 
384  private:
385 #ifdef DOC_PLUS_PLUS
386 
393  void OnNoResponseTimeoutStart(PTimer &, INT);
394 #else
395  PDECLARE_NOTIFIER(PTimer, IAX2Processor, OnNoResponseTimeoutStart);
396 #endif
397 
398  protected:
406 };
407 
408 
409 #endif // OPAL_IAX2
410 
411 #endif // OPAL_IAX2_PROCESSOR_H