30 m_run_on_destruction(true) ,
31 m_list_changed(false) ,
32 m_empty_set_timeout_hint(false) ,
33 m_soonest_changed(true) ,
42 if( m_run_on_destruction )
59 m_list_changed = true ;
60 m_list.push_back( &t ) ;
65 for( List::iterator p = m_list.begin() ; p != m_list.end() ; ++p )
82 m_soonest_changed = true ;
85 G_DEBUG(
"GNet::TimerList::update: " << t_old <<
" -> " << t_new ) ;
91 void GNet::TimerList::update()
95 m_soonest_changed = true ;
99 G_DEBUG(
"GNet::TimerList::update: ? -> " << t_new ) ;
107 const List::const_iterator end = m_list.end() ;
108 for( List::const_iterator p = m_list.begin() ; p != end ; ++p )
110 if( *p != NULL && (*p)->t() != 0UL && ( result == 0U || (*p)->t() < result ) )
121 if( m_soonest_changed )
124 This->m_soonest = soonest() ;
125 This->m_soonest_changed = false ;
131 bool GNet::TimerList::valid()
const
133 if( soonest() != m_soonest )
135 G_ERROR(
"GNet::TimerList::valid: soonest()=" << soonest() <<
", m_soonest=" << m_soonest ) ;
144 infinite = then == 0U ;
152 return now >= then ? 0U :
static_cast<unsigned int>(then-now) ;
171 G_DEBUG(
"GNet::TimerList::doTimeouts" ) ;
174 for( List::iterator p = m_list.begin() ; p != m_list.end() ; ++p )
179 if( t != 0U && now >= t )
190 void GNet::TimerList::collectGarbage()
192 for( List::iterator p = m_list.begin() ; p != m_list.end() ; )
195 p = m_list.erase( p ) ;
static EpochTime now()
Returns the current epoch time.
void remove(AbstractTimer &)
Removes a timer from the list.
void add(AbstractTimer &)
Adds a timer. Used by Timer::Timer().
void update(G::DateTime::EpochTime previous_soonest)
Called when one of the list's timers has changed.
G::DateTime::EpochTime soonest() const
Returns the time of the first timer to expire, or zero if none.
TimerList()
Default constructor.
Overload discriminator class for TimerList.
A singleton which maintains a list of all Timer objects, and interfaces to the event loop on their be...
unsigned int interval(bool &infinite) const
Returns the interval to the next timer expiry.
static TimerList & instance()
Singleton access. Throws an exception if none.
virtual void setTimeout(G::DateTime::EpochTime t, bool &empty_implementation_hint)=0
Used by GNet::TimerList.
void doTimeouts()
Triggers the timeout callbacks of any expired timers.
static bool exists()
Returns true if an instance exists.
static EventLoop & instance()
Returns a reference to an instance of the class, if any.
A timer base class that calls a pure virtual method on expiry.