30 std::weak_ptr<EventDispatcher>
_ev;
54 return std::shared_ptr<Timer>(
new Timer() );
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;
104 if ( elapsed >= d->_requestedTimeout )
106 return ( d->_requestedTimeout -
elapsed );
117 return d_func()->_beginMs + d_func()->_requestedTimeout;
122 return d_func()->_expired;
131 auto lock = shared_from_this();
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;
Base class for Exception.
static std::shared_ptr< EventDispatcher > instance()
TimerPrivate & operator=(const TimerPrivate &)=delete
TimerPrivate(const TimerPrivate &)=delete
uint64_t _requestedTimeout
Signal< void(Timer &t)> _expired
std::weak_ptr< EventDispatcher > _ev
TimerPrivate(TimerPrivate &&)=delete
TimerPrivate & operator=(TimerPrivate &&)=delete
The Timer class provides repetitive and single-shot timers.
static uint64_t elapsedSince(const uint64_t start)
static std::shared_ptr< Timer > create()
Creates a new Timer object, the timer is not started at this point.
SignalProxy< void(Timer &t)> sigExpired()
This signal is always emitted when the timer expires.
void setSingleShot(bool singleShot=true)
Sets the timer to trigger only once, after it has expired once.
uint64_t remaining() const
uint64_t interval() const
uint64_t expire()
Advances the internal clock of the timer, if the timer expires the sigExpired signal is emitted.
void stop()
Stops the timer if it is running. The.
#define ZYPP_THROW(EXCPT)
Drops a logline and throws the Exception.
#define ZYPP_IMPL_PRIVATE(Class)
#define ZYPP_DECLARE_PUBLIC(Class)