28 uint64_t _beginMs = 0;
29 uint64_t _requestedTimeout = 0;
30 std::weak_ptr<EventDispatcher>
_ev;
31 bool _isRunning =
false;
35 bool _singleShot =
false;
54 return std::shared_ptr<Timer>(
new Timer() );
62 d_func()->_singleShot = singleShot;
67 return d_func()->_singleShot;
72 return static_cast<uint64_t
>( g_get_monotonic_time () / 1000 );
75 if ( clock_gettime( CLOCK_MONOTONIC_RAW, &now ) ) {
76 WAR <<
"Unable to get current monotonic time, timers will not work" << std::endl;
79 return ( uint(now.tv_sec) * 1000 ) + uint( now.tv_nsec * 1e-6 );
85 uint64_t nowMs = now();
86 return ( nowMs - start );
91 return d_func()->_beginMs;
96 return d_func()->_requestedTimeout;
103 uint64_t elapsed = this->elapsed();
104 if ( elapsed >= d->_requestedTimeout )
106 return ( d->_requestedTimeout - elapsed );
112 return elapsedSince( d->_beginMs );
117 return d_func()->_beginMs + d_func()->_requestedTimeout;
122 return d_func()->_expired;
131 auto lock = shared_from_this();
133 auto exp = remaining();
135 if ( d->_singleShot )
139 d->_expired.emit( *
this );
146 return d_func()->_isRunning;
151 start ( d_func()->_requestedTimeout );
158 d->_requestedTimeout = timeout;
161 if ( !d->_isRunning ) {
162 auto ev = d->_ev.lock();
166 ev->registerTimer( *
this );
168 d->_isRunning =
true;
177 if ( !d->_isRunning )
180 auto ev = d->_ev.lock();
184 ev->removeTimer( *
this );
186 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 it is 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
ZYPP_IMPL_PRIVATE(UnixSignalSource)
#define ZYPP_DECLARE_PUBLIC(Class)
Easy-to use interface to the ZYPP dependency resolver.
static uint64_t elapsedSince(const uint64_t start)