35 if( m_this ==
nullptr )
48 m_list.push_back( Value(&t,&eh) ) ;
53 const List::iterator end = m_list.end() ;
54 for( List::iterator p = m_list.begin() ; p != end ; ++p )
56 if( (*p).first == &timer )
57 (*p).first = nullptr ;
60 if( m_soonest == &timer )
62 m_soonest = findSoonest() ;
69 const List::iterator end = m_list.end() ;
70 for( List::iterator p = m_list.begin() ; p != end ; ++p )
72 if( (*p).second == eh )
73 (*p).second = nullptr ;
79 if( !timer.
active() && m_soonest != &timer )
83 else if( timer.
active() && m_soonest !=
nullptr && timer.
t() > m_soonest->t() )
90 m_soonest = (timer.
active() && timer.
immediate()) ? &timer : findSoonest() ;
91 if( soonestTime() != old_soonest )
98 return m_soonest ==
nullptr ?
G::EpochTime(0) : m_soonest->t() ;
104 TimerBase * result = nullptr ;
105 const List::const_iterator end = m_list.end() ;
106 for( List::const_iterator p = m_list.begin() ; p != end ; ++p )
108 if( (*p).first !=
nullptr && (*p).first->active() && ( result ==
nullptr || (*p).first->t() < result->t() ) )
109 result = (*p).first ;
116 if( m_soonest ==
nullptr )
121 else if( m_soonest->immediate() )
142 return m_this != nullptr ;
147 if( m_this ==
nullptr )
155 for( List::iterator p = m_list.begin() ; p != m_list.end() ; ++p )
157 if( (*p).first !=
nullptr && (*p).first->active() && (*p).first->expired(now) )
161 (*p).first->doTimeout() ;
163 catch( std::exception & e )
166 (*p).second->onException( e ) ;
173 m_soonest = findSoonest() ;
177 void GNet::TimerList::setTimeout()
183 void GNet::TimerList::collectGarbage()
185 for( List::iterator p = m_list.begin() ; p != m_list.end() ; )
187 if( (*p).first ==
nullptr )
188 p = m_list.erase( p ) ;
196 std::ostringstream ss ;
197 ss << m_list.size() ;
A subsecond-resolution timestamp based on a time_t.
virtual void setTimeout(G::EpochTime t)=0
Used by GNet::TimerList.
G::EpochTime t() const
Used by TimerList to get the expiry epoch time.
bool active() const
Returns true if the timer is started and not cancelled.
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...
void add(TimerBase &, ExceptionHandler &)
Adds a timer.
static EpochTime now()
Returns the current epoch time.
An abstract interface for handling exceptions thrown out of event-loop callbacks (socket events...
static TimerList & instance()
Singleton access. Throws an exception if none.
G::EpochTime interval(bool &infinite) const
Returns the interval to the first timer expiry.
void doTimeouts()
Triggers the timeout callbacks of any expired timers.
static bool exists()
Returns true if instance() exists.
~TimerList()
Destructor. Any expired timers have their timeouts called.
void update(TimerBase &)
Called when a timer changes its value.
An interface used by GNet::TimerList to keep track of pending timeouts and to deliver timeout events...
bool immediate() const
Used by TimerList.
static bool exists()
Returns true if an instance exists.
void disarm(ExceptionHandler *)
Resets any matching ExceptionHandler pointers.
void remove(TimerBase &)
Removes a timer from the list.
std::string report() const
Returns a line of text reporting the status of the timer list.
static EventLoop & instance()
Returns a reference to an instance of the class, if any.