libzypp 17.37.17
zyppng::Timer Class Reference

The Timer class provides repetitive and single-shot timers. More...

#include <zypp-core/zyppng/base/timer.h>

Inheritance diagram for zyppng::Timer:

Public Types

using Ptr = std::shared_ptr<Timer>
using WeakPtr = std::shared_ptr<Timer>
Public Types inherited from zyppng::Base
using Ptr = std::shared_ptr<Base>
using WeakPtr = std::weak_ptr<Base>

Public Member Functions

 ~Timer () override
void setSingleShot (bool singleShot=true)
 Sets the timer to trigger only once, after it has expired once.
bool singleShot () const
uint64_t started () const
uint64_t interval () const
uint64_t remaining () const
uint64_t elapsed () const
uint64_t expires () const
uint64_t expire ()
 Advances the internal clock of the timer, if the timer expires the sigExpired signal is emitted.
bool isRunning () const
void start ()
void start (uint64_t timeout)
 Starts the timer, if the timer is already running this will restart the currently running timer.
void stop ()
 Stops the timer if it is running. The.
SignalProxy< void(Timer &t)> sigExpired ()
 This signal is always emitted when the timer expires.
Public Member Functions inherited from zyppng::Base
 Base ()
virtual ~Base ()
WeakPtr parent () const
void addChild (const Base::Ptr &child)
void removeChild (const Ptr &child)
const std::unordered_set< Ptr > & children () const
std::thread::id threadId () const
template<typename T>
std::vector< std::weak_ptr< T > > findChildren () const
template<typename T>
std::shared_ptr< T > shared_this () const
template<typename T>
std::shared_ptr< T > shared_this ()
template<typename T>
std::weak_ptr< T > weak_this () const
template<typename T>
std::weak_ptr< T > weak_this ()
template<typename SenderFunc, typename ReceiverFunc>
auto connect (SenderFunc &&sFun, typename internal::MemberFunction< ReceiverFunc >::ClassType &recv, ReceiverFunc &&rFunc)
template<typename SenderFunc, typename ReceiverFunc, typename ... Tracker>
std::enable_if_t< std::is_member_function_pointer_v< SenderFunc >, connectionconnectFunc (SenderFunc &&sFun, ReceiverFunc &&rFunc, const Tracker &...trackers)

Static Public Member Functions

static std::shared_ptr< Timercreate ()
 Creates a new Timer object, the timer is not started at this point.
static uint64_t now ()
static uint64_t elapsedSince (const uint64_t start)
Static Public Member Functions inherited from zyppng::Base
template<typename Obj, typename Functor>
static decltype(auto) make_base_slot (Obj *o, Functor &&f)
template<typename SenderFunc, typename ReceiverFunc>
static auto connect (typename internal::MemberFunction< SenderFunc >::ClassType &s, SenderFunc &&sFun, typename internal::MemberFunction< ReceiverFunc >::ClassType &recv, ReceiverFunc &&rFunc)
template<typename SenderFunc, typename ReceiverFunc, typename ... Tracker>
static auto connectFunc (typename internal::MemberFunction< SenderFunc >::ClassType &s, SenderFunc &&sFun, ReceiverFunc &&rFunc, const Tracker &...trackers)

Protected Member Functions

 Timer ()
Protected Member Functions inherited from zyppng::Base
 Base (BasePrivate &dd)

Friends

class EventDispatcher

Additional Inherited Members

Protected Attributes inherited from zyppng::Base
std::unique_ptr< BasePrivated_ptr

Detailed Description

The Timer class provides repetitive and single-shot timers.

Provides a high level interface for timers. To use it, create a Timer and connect a slot to its

See also
sigExpired signal.
t1->sigExpired().connect( sigc::mem_fun(this, &HandlerClass::timeout) );
t1->start(1000);
static std::shared_ptr< Timer > create()
Creates a new Timer object, the timer is not started at this point.
Definition timer.cc:52
std::shared_ptr< Timer > Ptr
Definition timer.h:51

The timeout slot will now be called every second.

Note
The accuracy of the timer should be around 1ms , but also depends on the underlying hardware.

Definition at line 44 of file timer.h.

Member Typedef Documentation

◆ Ptr

using zyppng::Timer::Ptr = std::shared_ptr<Timer>

Definition at line 51 of file timer.h.

◆ WeakPtr

using zyppng::Timer::WeakPtr = std::shared_ptr<Timer>

Definition at line 52 of file timer.h.

Constructor & Destructor Documentation

◆ ~Timer()

zyppng::Timer::~Timer ( )
override

Definition at line 57 of file timer.cc.

◆ Timer()

zyppng::Timer::Timer ( )
protected

Definition at line 189 of file timer.cc.

Member Function Documentation

◆ create()

std::shared_ptr< Timer > zyppng::Timer::create ( )
static

Creates a new Timer object, the timer is not started at this point.

Definition at line 52 of file timer.cc.

◆ setSingleShot()

void zyppng::Timer::setSingleShot ( bool singleShot = true)

Sets the timer to trigger only once, after it has expired once.

See also
start needs to be called again

Definition at line 60 of file timer.cc.

◆ singleShot()

bool zyppng::Timer::singleShot ( ) const
Returns
true if the timer is a single shot timer

Definition at line 65 of file timer.cc.

◆ now()

uint64_t zyppng::Timer::now ( )
static
Returns
The current monotonic system time in milliseconds

Definition at line 70 of file timer.cc.

◆ elapsedSince()

uint64_t zyppng::Timer::elapsedSince ( const uint64_t start)
static
Returns
the time that has elapsed since the timepoint given in start

Definition at line 83 of file timer.cc.

◆ started()

uint64_t zyppng::Timer::started ( ) const
Returns
the monotonic system time when the timer started

Definition at line 89 of file timer.cc.

◆ interval()

uint64_t zyppng::Timer::interval ( ) const
Returns
the requested interval in milliseconds

Definition at line 94 of file timer.cc.

◆ remaining()

uint64_t zyppng::Timer::remaining ( ) const
Returns
the remaining time until the timer expires in milliseconds

Definition at line 99 of file timer.cc.

◆ elapsed()

uint64_t zyppng::Timer::elapsed ( ) const
Returns
the time that has elapsed since the last call to start in milliseconds

Definition at line 109 of file timer.cc.

◆ expires()

uint64_t zyppng::Timer::expires ( ) const
Returns
the monotonic system time in ms when the timer is about to expire

Definition at line 115 of file timer.cc.

◆ expire()

uint64_t zyppng::Timer::expire ( )

Advances the internal clock of the timer, if the timer expires the sigExpired signal is emitted.

Returns
the monotonic system time in ms when the timer is about to expire
Note
There should not be any reason to call this manually, the
See also
EventDispatcher is taking care of that

Definition at line 125 of file timer.cc.

◆ isRunning()

bool zyppng::Timer::isRunning ( ) const
Returns
if the timer is currently active

Definition at line 144 of file timer.cc.

◆ start() [1/2]

void zyppng::Timer::start ( )

Starts the timer, if the timer is already running this will restart the currently running timer

Definition at line 149 of file timer.cc.

◆ start() [2/2]

void zyppng::Timer::start ( uint64_t timeout)

Starts the timer, if the timer is already running this will restart the currently running timer.

Parameters
timeoutthe new timeout in ms

Definition at line 154 of file timer.cc.

◆ stop()

void zyppng::Timer::stop ( )

Stops the timer if it is running. The.

See also
sigExpired signal will not emit until
start was called again.

Definition at line 173 of file timer.cc.

◆ sigExpired()

SignalProxy< void(Timer &t)> zyppng::Timer::sigExpired ( )

This signal is always emitted when the timer expires.

Definition at line 120 of file timer.cc.

◆ EventDispatcher

friend class EventDispatcher
friend

Definition at line 47 of file timer.h.


The documentation for this class was generated from the following files: