00001 // -*- c++ -*- 00002 //------------------------------------------------------------------------------ 00003 // TimerCountdown.h 00004 //------------------------------------------------------------------------------ 00005 // Copyright (c) 1999 by Vladislav Grinchenko 00006 // 00007 // This library is free software; you can redistribute it and/or 00008 // modify it under the terms of the GNU Library General Public 00009 // License as published by the Free Software Foundation; either 00010 // version 2 of the License, or (at your option) any later version. 00011 //------------------------------------------------------------------------------ 00012 // Created: 08/25/1999 00013 //------------------------------------------------------------------------------ 00014 #ifndef TIMER_COUNTDOWN_H 00015 #define TIMER_COUNTDOWN_H 00016 00017 #include "assa/TimeVal.h" 00018 00019 namespace ASSA { 00020 00028 class TimerCountdown 00029 { 00030 public: 00033 TimerCountdown (TimeVal* wait_time_); 00034 00037 ~TimerCountdown (); 00038 00039 private: 00041 TimeVal* m_maxWaitTime; 00042 00044 TimeVal m_start; 00045 }; 00046 00047 //------------------------------------------------------------------------------ 00048 // inlines 00049 //------------------------------------------------------------------------------ 00050 00051 inline 00052 TimerCountdown:: 00053 TimerCountdown (TimeVal* wt_) 00054 : m_maxWaitTime (wt_), m_start (TimeVal::gettimeofday ()) 00055 { 00056 } 00057 00058 inline 00059 TimerCountdown:: 00060 ~TimerCountdown () 00061 { 00062 if (m_maxWaitTime == NULL) 00063 return; 00064 00065 TimeVal elapsed (TimeVal::gettimeofday ()); 00066 elapsed -= m_start; 00067 00068 if ( *m_maxWaitTime > elapsed ) 00069 *m_maxWaitTime -= elapsed; 00070 else 00071 *m_maxWaitTime = TimeVal::zeroTime (); 00072 } 00073 00074 } // end namespace ASSA 00075 00076 #endif /* TIMER_COUNTDOWN_H */