libzypp  17.35.14
timer.h
Go to the documentation of this file.
1 /*---------------------------------------------------------------------\
2 | ____ _ __ __ ___ |
3 | |__ / \ / / . \ . \ |
4 | / / \ V /| _/ _/ |
5 | / /__ | | | | | | |
6 | /_____||_| |_| |_| |
7 | |
8 \----------------------------------------------------------------------/
9 *
10 * This file contains private API, this might break at any time between releases.
11 * You have been warned!
12 *
13 */
14 #ifndef ZYPP_NG_BASE_TIMER_H_INCLUDED
15 #define ZYPP_NG_BASE_TIMER_H_INCLUDED
16 
18 #include <zypp-core/zyppng/base/Base>
19 #include <zypp-core/zyppng/base/Signals>
20 #include <functional>
21 
22 namespace zyppng {
23 
24 class TimerPrivate;
25 class EventDispatcher;
27 
44 class Timer : public Base
45 {
47  friend class EventDispatcher;
48 
49 public:
50 
51  using Ptr = std::shared_ptr<Timer>;
52  using WeakPtr = std::shared_ptr<Timer>;
53 
57  static std::shared_ptr<Timer> create ();
58  ~Timer () override;
59 
64  void setSingleShot ( bool singleShot = true );
65 
69  bool singleShot () const;
70 
74  static uint64_t now ();
75 
79  static uint64_t elapsedSince ( const uint64_t start );
80 
84  uint64_t started () const;
85 
89  uint64_t interval () const;
90 
94  uint64_t remaining () const;
95 
99  uint64_t elapsed () const;
100 
104  uint64_t expires () const;
105 
112  uint64_t expire ();
113 
117  bool isRunning ( ) const;
118 
122  void start ( );
123 
128  void start ( uint64_t timeout );
129 
133  void stop ();
134 
138  SignalProxy<void (Timer &t)> sigExpired ();
139 
140 protected:
141  Timer ();
142 };
143 
144 }
145 
146 #endif
uint64_t interval() const
Definition: timer.cc:94
std::weak_ptr< Base > WeakPtr
Definition: base.h:66
Definition: Arch.h:363
SignalProxy< void(Timer &t)> sigExpired()
This signal is always emitted when the timer expires.
Definition: timer.cc:120
ZYPP_FWD_DECL_TYPE_WITH_REFS(Context)
void stop()
Stops the timer if it is running. The.
Definition: timer.cc:173
uint64_t expires() const
Definition: timer.cc:115
void setSingleShot(bool singleShot=true)
Sets the timer to trigger only once, after it has expired once.
Definition: timer.cc:60
void start()
Definition: timer.cc:149
The Timer class provides repetitive and single-shot timers.
Definition: timer.h:44
uint64_t elapsed() const
Definition: timer.cc:109
uint64_t remaining() const
Definition: timer.cc:99
static std::shared_ptr< Timer > create()
Creates a new Timer object, the timer is not started at this point.
Definition: timer.cc:52
uint64_t expire()
Advances the internal clock of the timer, if the timer expires the sigExpired signal is emitted...
Definition: timer.cc:125
#define ZYPP_DECLARE_PRIVATE(Class)
Definition: zyppglobal.h:87
static uint64_t now()
Definition: timer.cc:70
bool singleShot() const
Definition: timer.cc:65
bool isRunning() const
Definition: timer.cc:144
uint64_t started() const
Definition: timer.cc:89
std::shared_ptr< Base > Ptr
Definition: base.h:65
static uint64_t elapsedSince(const uint64_t start)
Definition: timer.cc:83