PTLib  Version 2.18.8
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
delaychan.h
Go to the documentation of this file.
1 /*
2  * delaychan.h
3  *
4  * Class for implementing a serial queue channel in memory.
5  *
6  * Portable Windows Library
7  *
8  * Copyright (c) 2001 Equivalence Pty. Ltd.
9  *
10  * The contents of this file are subject to the Mozilla Public License
11  * Version 1.0 (the "License"); you may not use this file except in
12  * compliance with the License. You may obtain a copy of the License at
13  * http://www.mozilla.org/MPL/
14  *
15  * Software distributed under the License is distributed on an "AS IS"
16  * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
17  * the License for the specific language governing rights and limitations
18  * under the License.
19  *
20  * The Original Code is Portable Windows Library.
21  *
22  * The Initial Developer of the Original Code is Equivalence Pty. Ltd.
23  *
24  * Contributor(s): ______________________________________.
25  */
26 
27 #ifndef PTLIB_DELAYCHAN_H
28 #define PTLIB_DELAYCHAN_H
29 #include <ptlib/contain.h>
30 #include <ptlib/object.h>
31 #include <ptlib/timeint.h>
32 #include <ptlib/ptime.h>
33 #include <ptlib/indchan.h>
34 
35 #ifdef P_USE_PRAGMA
36 #pragma interface
37 #endif
38 
39 
48 class PAdaptiveDelay : public PObject
49 {
50  PCLASSINFO(PAdaptiveDelay, PObject);
51 
52  public:
53 
61  const PTimeInterval & maximumSlip = 0,
62  const PTimeInterval & minimumDelay = 0
63  );
65 
74  void SetMaximumSlip(const PTimeInterval & maximumSlip)
75  { m_maximumSlip = -maximumSlip; }
76 
79  { return -m_maximumSlip; }
80 
82  const PTimeInterval & GetActualDelay() const { return m_actualDelay; }
84 
87  enum DelayResult
89  {
103  };
104 
119  DelayResult Delay(int deltaMS) { return DelayInterval(deltaMS); }
120 
122  DelayResult DelayInterval(const PTimeInterval & delta);
123 
127  void Restart();
129 
130  protected:
136 #if PTRACING
137  unsigned m_traceLevel;
138 #endif
139 };
140 
141 
158 {
159  PCLASSINFO(PDelayChannel, PIndirectChannel);
160  public:
163  enum Mode {
167  };
168 
177  Mode mode,
178  unsigned frameDelay,
179  PINDEX frameSize = 0,
180  unsigned maximumSlip = 250,
181  unsigned minimumDelay = 10
182  );
183 
192  PChannel &channel,
193  Mode mode,
194  unsigned frameDelay,
195  PINDEX frameSize = 0,
196  unsigned maximumSlip = 250,
197  unsigned minimumDelay = 10
198  );
200 
201 
215  virtual PBoolean Read(
216  void * buf,
217  PINDEX len
218  );
219 
229  virtual PBoolean Write(
230  const void * buf,
231  PINDEX len
232  );
234 
235 
236  protected:
237  virtual void Wait(PINDEX count, PTimeInterval & nextTick);
238 
240  unsigned frameDelay;
241  PINDEX frameSize;
244 
247 };
248 
249 
250 #endif // PTLIB_DELAYCHAN_H
251 
252 
253 // End Of File ///////////////////////////////////////////////////////////////
virtual PBoolean Write(const void *buf, PINDEX len)
Low level write to the file channel.
PTimeInterval m_maximumSlip
Definition: delaychan.h:131
This class defines an arbitrary time interval to millisecond accuracy.
Definition: timeint.h:51
PINDEX frameSize
Definition: delaychan.h:241
virtual void Wait(PINDEX count, PTimeInterval &nextTick)
This class defines an absolute time and date.
Definition: ptime.h:49
Mode
Definition: delaychan.h:163
This is a channel that operates indirectly through another channel(s).
Definition: indchan.h:45
PDelayChannel(Mode mode, unsigned frameDelay, PINDEX frameSize=0, unsigned maximumSlip=250, unsigned minimumDelay=10)
Create a new delay channel with the specified delays.
void SetMaximumSlip(const PTimeInterval &maximumSlip)
Set the number of milliseconds that the delay may &quot;catch up&quot; by using zero delays.
Definition: delaychan.h:74
PTime m_targetTime
Definition: delaychan.h:134
Definition: delaychan.h:165
The delta time interval was zero or negative.
Definition: delaychan.h:102
PTimeInterval GetMaximumSlip() const
Get the current slip time.
Definition: delaychan.h:78
PAdaptiveDelay(const PTimeInterval &maximumSlip=0, const PTimeInterval &minimumDelay=0)
Create a new adaptive delay with the specified parameters.
PTimeInterval m_minimumDelay
Definition: delaychan.h:132
Class for implementing a &quot;delay line&quot; channel.
Definition: delaychan.h:157
Definition: delaychan.h:166
The function was called within the delta time of the expected time and a possible sleep was performed...
Definition: delaychan.h:90
Abstract class defining I/O channel semantics.
Definition: channel.h:103
DelayResult Delay(int deltaMS)
Wait until the specified number of milliseconds have elapsed from the previous call (on average)...
Definition: delaychan.h:119
bool PBoolean
Definition: object.h:174
DelayResult
&lt; Result of call to Delay() or DelayInterval() function call
Definition: delaychan.h:88
Definition: delaychan.h:164
Class for implementing an &quot;adaptive&quot; delay.
Definition: delaychan.h:48
PTimeInterval maximumSlip
Definition: delaychan.h:242
virtual PBoolean Read(void *buf, PINDEX len)
Low level read from the file channel.
The function was called greater than delta time intervals late, no sleep was made.
Definition: delaychan.h:98
const PTimeInterval & GetActualDelay() const
Get the actual sleep time of the last call to the delay function.
Definition: delaychan.h:82
PTimeInterval nextWriteTick
Definition: delaychan.h:246
PTimeInterval m_actualDelay
Definition: delaychan.h:133
void Restart()
Invalidate the timer.
bool m_firstTime
Definition: delaychan.h:135
unsigned frameDelay
Definition: delaychan.h:240
DelayResult DelayInterval(const PTimeInterval &delta)
As for Delay() but for more accurate timing.
The function was called in time, and a sleep was performed, but the operating system did not return c...
Definition: delaychan.h:94
PTimeInterval minimumDelay
Definition: delaychan.h:243
PTimeInterval nextReadTick
Definition: delaychan.h:245
Ultimate parent class for all objects in the class library.
Definition: object.h:2204
The function was called more than the m_maximumSlip time late, the adaptation is reset, no sleep is performed.
Definition: delaychan.h:100
Mode mode
Definition: delaychan.h:239