timer.h

Go to the documentation of this file.
00001 /*
00002  * timer.h
00003  *
00004  * Real time down counting time interval class.
00005  *
00006  * Portable Windows Library
00007  *
00008  * Copyright (c) 1993-1998 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  * Portions are Copyright (C) 1993 Free Software Foundation, Inc.
00025  * All Rights Reserved.
00026  *
00027  * Contributor(s): ______________________________________.
00028  *
00029  * $Revision: 19008 $
00030  * $Author: rjongbloed $
00031  * $Date: 2007-11-29 09:17:41 +0000 (Thu, 29 Nov 2007) $
00032  */
00033 
00034 #ifndef _PTIMER
00035 #define _PTIMER
00036 
00037 #ifdef P_USE_PRAGMA
00038 #pragma interface
00039 #endif
00040 
00041 class PThread;
00042 
00043 #include <ptlib/notifier.h>
00044 
00073 class PTimer : public PTimeInterval
00074 {
00075   PCLASSINFO(PTimer, PTimeInterval);
00076 
00077   public:
00085     PTimer(
00086       long milliseconds = 0,  
00087       int seconds = 0,        
00088       int minutes = 0,        
00089       int hours = 0,          
00090       int days = 0            
00091     );
00092     PTimer(
00093       const PTimeInterval & time    
00094     );
00095 
00102     PTimer & operator=(
00103       DWORD milliseconds            
00104     );
00105     PTimer & operator=(
00106       const PTimeInterval & time    
00107     );
00108 
00112     virtual ~PTimer();
00114 
00128     virtual void SetInterval(
00129       PInt64 milliseconds = 0,  
00130       long seconds = 0,         
00131       long minutes = 0,         
00132       long hours = 0,           
00133       int days = 0              
00134     );
00135 
00140     void RunContinuous(
00141       const PTimeInterval & time    // New time interval for timer.
00142     );
00143 
00148     void Stop();
00149 
00156     PBoolean IsRunning() const;
00157 
00162     void Pause();
00163 
00168     void Resume();
00169 
00175     PBoolean IsPaused() const;
00176 
00179     void Reset();
00180 
00183     const PTimeInterval & GetResetTime() const;
00185 
00200     virtual void OnTimeout();
00201 
00208     const PNotifier & GetNotifier() const;
00209 
00213     void SetNotifier(
00214       const PNotifier & func  // New notifier function for the timer.
00215     );
00217 
00232     static PTimeInterval Tick();
00233 
00242     static unsigned Resolution();
00244 
00245   private:
00246     void Construct();
00247 
00248     /* Start or restart the timer from the #resetTime# variable.
00249        This is an internal function.
00250      */
00251     void StartRunning(
00252       PBoolean once   // Flag for one shot or continuous.
00253     );
00254 
00255     /* Process the timer decrementing it by the delta amount and calling the
00256        #OnTimeout()# when zero. This is used internally by the
00257        #PTimerList::Process()# function.
00258      */
00259     void Process(
00260       const PTimeInterval & delta,    // Time interval since last call.
00261       PTimeInterval & minTimeLeft     // Minimum time left till next timeout.
00262     );
00263 
00264   // Member variables
00265     PNotifier callback;
00266     // Callback function for expired timers.
00267 
00268     PTimeInterval resetTime;
00269     // The time to reset a timer to when RunContinuous() is called.
00270 
00271     PBoolean oneshot;
00272     // Timer operates once then stops.
00273 
00274     enum { Stopped, Starting, Running, Paused } state;
00275     // Timer state.
00276 
00277 
00278   friend class PTimerList;
00279     class PTimerList * timerList;
00280 
00281 
00282 // Include platform dependent part of class
00283 #ifdef _WIN32
00284 #include "msos/ptlib/timer.h"
00285 #else
00286 #include "unix/ptlib/timer.h"
00287 #endif
00288 };
00289 
00290 #endif
00291 
00292 
00293 // End Of File ///////////////////////////////////////////////////////////////

Generated on Mon Dec 10 11:18:57 2007 for PTLib by  doxygen 1.5.1