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: 21788 $
00027  * $Author: rjongbloed $
00028  * $Date: 2008-12-12 05:42:13 +0000 (Fri, 12 Dec 2008) $
00029  */
00030 
00031 #ifndef PTLIB_DELAYCHAN_H
00032 #define PTLIB_DELAYCHAN_H
00033 
00034 
00035 #ifdef P_USE_PRAGMA
00036 #pragma interface
00037 #endif
00038 
00039 
00048 class PAdaptiveDelay : public PObject
00049 { 
00050   PCLASSINFO(PAdaptiveDelay, PObject);
00051   
00052   public:
00053 
00060     PAdaptiveDelay(
00061       unsigned maximumSlip = 0,   
00062       unsigned minimumDelay = 0   
00063     );
00065 
00074     void SetMaximumSlip(PTimeInterval maximumSlip)
00075     { jitterLimit = maximumSlip; }
00076 
00078     PTimeInterval GetMaximumSlip() const
00079     { return jitterLimit; }
00081 
00098     PBoolean Delay(int time);
00099 
00103     void Restart();
00105  
00106   protected:
00107     PBoolean   firstTime;
00108     PTime  targetTime;
00109 
00110     PTimeInterval  jitterLimit;
00111     PTimeInterval  minimumDelay;
00112 };
00113 
00114 
00130 class PDelayChannel : public PIndirectChannel
00131 {
00132     PCLASSINFO(PDelayChannel, PIndirectChannel);
00133   public:
00136     enum Mode {
00137       DelayReadsOnly,
00138       DelayWritesOnly,
00139       DelayReadsAndWrites
00140     };
00141 
00149     PDelayChannel(
00150       Mode mode,                  
00151       unsigned frameDelay,        
00152       PINDEX frameSize = 0,       
00153       unsigned maximumSlip = 250, 
00154       unsigned minimumDelay = 10  
00155     );
00156     
00164     PDelayChannel(
00165         PChannel &channel,          
00166         Mode mode,                  
00167         unsigned frameDelay,        
00168         PINDEX frameSize = 0,       
00169         unsigned maximumSlip = 250, 
00170         unsigned minimumDelay = 10  
00171                  );    
00173 
00174 
00188     virtual PBoolean Read(
00189       void * buf,   
00190       PINDEX len    
00191     );
00192 
00202     virtual PBoolean Write(
00203       const void * buf, 
00204       PINDEX len        
00205     );
00207 
00208 
00209   protected:
00210     virtual void Wait(PINDEX count, PTimeInterval & nextTick);
00211 
00212     Mode          mode;
00213     unsigned      frameDelay;
00214     PINDEX        frameSize;
00215     PTimeInterval maximumSlip;
00216     PTimeInterval minimumDelay;
00217 
00218     PTimeInterval nextReadTick;
00219     PTimeInterval nextWriteTick;
00220 };
00221 
00222 
00223 #endif // PTLIB_DELAYCHAN_H
00224 
00225 
00226 // End Of File ///////////////////////////////////////////////////////////////

Generated on Fri Apr 10 22:33:48 2009 for PTLib by  doxygen 1.5.8