24 uint64_t _beginMs = 0;
25 uint64_t _requestedTimeout = 0;
26 std::weak_ptr<EventDispatcher>
_ev;
27 bool _isRunning =
false;
31 bool _singleShot =
false;
48 return std::shared_ptr<Timer>(
new Timer() );
56 d_func()->_singleShot = singleShot;
61 return d_func()->_singleShot;
66 return static_cast<uint64_t
>( g_get_monotonic_time () / 1000 );
69 if ( clock_gettime( CLOCK_MONOTONIC_RAW, &now ) ) {
70 WAR <<
"Unable to get current monotonic time, timers will not work" << std::endl;
73 return ( uint(now.tv_sec) * 1000 ) + uint( now.tv_nsec * 1e-6 );
79 return d_func()->_beginMs;
84 return d_func()->_requestedTimeout;
91 uint64_t elapsed = this->elapsed();
92 if ( elapsed >= d->_requestedTimeout )
94 return ( d->_requestedTimeout - elapsed );
100 uint64_t nowMs = now();
101 return ( nowMs - d->_beginMs );
106 return d_func()->_beginMs + d_func()->_requestedTimeout;
111 return d_func()->_expired;
120 auto lock = shared_from_this();
122 auto exp = remaining();
124 if ( d->_singleShot )
128 d->_expired.emit( *
this );
135 return d_func()->_isRunning;
140 start ( d_func()->_requestedTimeout );
147 d->_requestedTimeout =
timeout;
150 if ( !d->_isRunning ) {
151 auto ev = d->_ev.lock();
155 ev->registerTimer(
this );
157 d->_isRunning =
true;
166 if ( !d->_isRunning )
169 auto ev = d->_ev.lock();
173 ev->removeTimer(
this );
175 d->_isRunning =
false;
uint64_t interval() const
#define ZYPP_THROW(EXCPT)
Drops a logline and throws the Exception.
std::weak_ptr< EventDispatcher > _ev
SignalProxy< void(Timer &t)> sigExpired()
This signal is always emitted when the timer expires.
void stop()
Stops the timer if its running. The.
void setSingleShot(bool singleShot=true)
Sets the timer to trigger only once, after it has expired once.
The Timer class provides repetitive and single-shot timers.
static std::shared_ptr< EventDispatcher > instance()
uint64_t remaining() const
static std::shared_ptr< Timer > create()
Creates a new Timer object, the timer is not started at this point.
uint64_t expire()
Advances the internal clock of the timer, if the timer expires the sigExpired signal is emitted...
Base class for Exception.
signal< void(Timer &t)> _expired
#define ZYPP_DECLARE_PUBLIC(Class)
Easy-to use interface to the ZYPP dependency resolver.