Countdown_Time.cpp

Go to the documentation of this file.
00001 #include "ace/Countdown_Time.h"
00002 #include "ace/OS_NS_sys_time.h"
00003 
00004 ACE_RCSID (ace,
00005            Countdown_Time,
00006            "$Id: Countdown_Time.cpp 80826 2008-03-04 14:51:23Z wotte $")
00007 
00008 ACE_BEGIN_VERSIONED_NAMESPACE_DECL
00009 
00010 ACE_Countdown_Time::ACE_Countdown_Time (ACE_Time_Value *max_wait_time)
00011   : max_wait_time_ (max_wait_time),
00012     stopped_ (false)
00013 {
00014   this->start ();
00015 }
00016 
00017 ACE_Countdown_Time::~ACE_Countdown_Time (void)
00018 {
00019   this->stop ();
00020 }
00021 
00022 void
00023 ACE_Countdown_Time::start (void)
00024 {
00025   if (this->max_wait_time_ != 0)
00026     {
00027       this->start_time_ = ACE_OS::gettimeofday ();
00028       this->stopped_ = false;
00029     }
00030 }
00031 
00032 bool
00033 ACE_Countdown_Time::stopped (void) const
00034 {
00035   return stopped_;
00036 }
00037 
00038 void
00039 ACE_Countdown_Time::stop (void)
00040 {
00041   if (this->max_wait_time_ != 0 && this->stopped_ == false)
00042     {
00043       ACE_Time_Value elapsed_time = ACE_OS::gettimeofday () - this->start_time_;
00044 
00045       if (*this->max_wait_time_ > elapsed_time)
00046         {
00047           *this->max_wait_time_ -= elapsed_time;
00048         }
00049       else
00050         {
00051           // Used all of timeout.
00052           *this->max_wait_time_ = ACE_Time_Value::zero;
00053           // errno = ETIME;
00054         }
00055       this->stopped_ = true;
00056     }
00057 }
00058 
00059 void
00060 ACE_Countdown_Time::update (void)
00061 {
00062   this->stop ();
00063   this->start ();
00064 }
00065 
00066 ACE_END_VERSIONED_NAMESPACE_DECL

Generated on Tue Feb 2 17:18:39 2010 for ACE by  doxygen 1.4.7