delaychan.h

Go to the documentation of this file.
00001 /*
00002  * delaychan.h
00003  *
00004  * Class for implementing a serial queue channel in memory.
00005  *
00006  * Portable Windows Library
00007  *
00008  * Copyright (c) 2001 Equivalence Pty. Ltd.
00009  *
00010  * The contents of this file are subject to the Mozilla Public License
00011  * Version 1.0 (the "License"); you may not use this file except in
00012  * compliance with the License. You may obtain a copy of the License at
00013  * http://www.mozilla.org/MPL/
00014  *
00015  * Software distributed under the License is distributed on an "AS IS"
00016  * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
00017  * the License for the specific language governing rights and limitations
00018  * under the License.
00019  *
00020  * The Original Code is Portable Windows Library.
00021  *
00022  * The Initial Developer of the Original Code is Equivalence Pty. Ltd.
00023  *
00024  * Contributor(s): ______________________________________.
00025  *
00026  * $Revision: 20385 $
00027  * $Author: rjongbloed $
00028  * $Date: 2008-06-04 10:40:38 +0000 (Wed, 04 Jun 2008) $
00029  */
00030 
00031 #ifndef _DELAYCHAN_H
00032 #define _DELAYCHAN_H
00033 
00034 
00035 #ifdef P_USE_PRAGMA
00036 #pragma interface
00037 #endif
00038 
00039 #ifndef _PTLIB_H
00040 #include <ptlib.h>
00041 #endif
00042 
00051 class PAdaptiveDelay : public PObject
00052 { 
00053   PCLASSINFO(PAdaptiveDelay, PObject);
00054   
00055   public:
00056 
00063     PAdaptiveDelay(
00064       unsigned maximumSlip = 0,   
00065       unsigned minimumDelay = 0   
00066     );
00068 
00077     void SetMaximumSlip(PTimeInterval maximumSlip)
00078     { jitterLimit = maximumSlip; }
00079 
00081     PTimeInterval GetMaximumSlip() const
00082     { return jitterLimit; }
00084 
00101     PBoolean Delay(int time);
00102 
00106     void Restart();
00108  
00109   protected:
00110     PBoolean   firstTime;
00111     PTime  targetTime;
00112 
00113     PTimeInterval  jitterLimit;
00114     PTimeInterval  minimumDelay;
00115 };
00116 
00117 
00133 class PDelayChannel : public PIndirectChannel
00134 {
00135     PCLASSINFO(PDelayChannel, PIndirectChannel);
00136   public:
00139     enum Mode {
00140       DelayReadsOnly,
00141       DelayWritesOnly,
00142       DelayReadsAndWrites
00143     };
00144 
00152     PDelayChannel(
00153       Mode mode,                  
00154       unsigned frameDelay,        
00155       PINDEX frameSize = 0,       
00156       unsigned maximumSlip = 250, 
00157       unsigned minimumDelay = 10  
00158     );
00159     
00167     PDelayChannel(
00168         PChannel &channel,          
00169         Mode mode,                  
00170         unsigned frameDelay,        
00171         PINDEX frameSize = 0,       
00172         unsigned maximumSlip = 250, 
00173         unsigned minimumDelay = 10  
00174                  );    
00176 
00177 
00191     virtual PBoolean Read(
00192       void * buf,   
00193       PINDEX len    
00194     );
00195 
00205     virtual PBoolean Write(
00206       const void * buf, 
00207       PINDEX len        
00208     );
00210 
00211 
00212   protected:
00213     virtual void Wait(PINDEX count, PTimeInterval & nextTick);
00214 
00215     Mode          mode;
00216     unsigned      frameDelay;
00217     PINDEX        frameSize;
00218     PTimeInterval maximumSlip;
00219     PTimeInterval minimumDelay;
00220 
00221     PTimeInterval nextReadTick;
00222     PTimeInterval nextWriteTick;
00223 };
00224 
00225 
00226 #endif // _DELAYCHAN_H
00227 
00228 
00229 // End Of File ///////////////////////////////////////////////////////////////

Generated on Mon Feb 23 01:57:54 2009 for PTLib by  doxygen 1.5.1