libzypp  17.22.0
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/zyppng/base/Base>
19 #include <zypp/zyppng/base/Signals>
20 #include <functional>
21 
22 namespace zyppng {
23 class TimerPrivate;
24 class EventDispatcher;
25 
42 class Timer : public Base
43 {
45  friend class EventDispatcher;
46 
47 public:
48 
49  using Ptr = std::shared_ptr<Timer>;
50  using WeakPtr = std::shared_ptr<Timer>;
51 
55  static std::shared_ptr<Timer> create ();
56  virtual ~Timer ();
57 
62  void setSingleShot ( bool singleShot = true );
63 
67  bool singleShot () const;
68 
72  static uint64_t now ();
73 
77  uint64_t started () const;
78 
82  uint64_t interval () const;
83 
87  uint64_t remaining () const;
88 
92  uint64_t elapsed () const;
93 
97  uint64_t expires () const;
98 
105  uint64_t expire ();
106 
110  bool isRunning ( ) const;
111 
115  void start ( );
116 
121  void start ( uint64_t timeout );
122 
126  void stop ();
127 
131  SignalProxy<void (Timer &t)> sigExpired ();
132 
133 protected:
134  Timer ();
135 };
136 
137 }
138 
139 #endif
uint64_t interval() const
Definition: timer.cc:82
std::weak_ptr< Base > WeakPtr
Definition: base.h:39
Definition: Arch.h:347
SignalProxy< void(Timer &t)> sigExpired()
This signal is always emitted when the timer expires.
Definition: timer.cc:109
time_t timeout
Definition: MediaCurl.cc:66
void stop()
Stops the timer if its running. The.
Definition: timer.cc:162
uint64_t expires() const
Definition: timer.cc:104
void setSingleShot(bool singleShot=true)
Sets the timer to trigger only once, after it has expired once.
Definition: timer.cc:54
void start()
Definition: timer.cc:138
The Timer class provides repetitive and single-shot timers.
Definition: timer.h:42
uint64_t elapsed() const
Definition: timer.cc:97
uint64_t remaining() const
Definition: timer.cc:87
static std::shared_ptr< Timer > create()
Creates a new Timer object, the timer is not started at this point.
Definition: timer.cc:46
uint64_t expire()
Advances the internal clock of the timer, if the timer expires the sigExpired signal is emitted...
Definition: timer.cc:114
#define ZYPP_DECLARE_PRIVATE(Class)
Definition: zyppglobal.h:21
static uint64_t now()
Definition: timer.cc:64
bool singleShot() const
Definition: timer.cc:59
bool isRunning() const
Definition: timer.cc:133
uint64_t started() const
Definition: timer.cc:77
std::shared_ptr< Base > Ptr
Definition: base.h:38