timers.hpp
Go to the documentation of this file.
1 /* SPDX-License-Identifier: MPL-2.0 */
2 
3 #ifndef __ZMQ_TIMERS_HPP_INCLUDED__
4 #define __ZMQ_TIMERS_HPP_INCLUDED__
5 
6 #include <stddef.h>
7 #include <map>
8 #include <set>
9 
10 #include "clock.hpp"
11 
12 namespace zmq
13 {
14 typedef void (timers_timer_fn) (int timer_id_, void *arg_);
15 
16 class timers_t
17 {
18  public:
19  timers_t ();
20  ~timers_t ();
21 
22  // Add timer to the set, timer repeats forever, or until cancel is called.
23  // Returns a timer_id that is used to cancel the timer.
24  // Returns -1 if there was an error.
25  int add (size_t interval_, timers_timer_fn handler_, void *arg_);
26 
27  // Set the interval of the timer.
28  // This method is slow, cancelling exsting and adding a new timer yield better performance.
29  // Returns 0 on success and -1 on error.
30  int set_interval (int timer_id_, size_t interval_);
31 
32  // Reset the timer.
33  // This method is slow, cancelling exsting and adding a new timer yield better performance.
34  // Returns 0 on success and -1 on error.
35  int reset (int timer_id_);
36 
37  // Cancel a timer.
38  // Returns 0 on success and -1 on error.
39  int cancel (int timer_id_);
40 
41  // Returns the time in millisecond until the next timer.
42  // Returns -1 if no timer is due.
43  long timeout ();
44 
45  // Execute timers.
46  // Return 0 if all succeed and -1 if error.
47  int execute ();
48 
49  // Return false if object is not a timers class.
50  bool check_tag () const;
51 
52  private:
53  // Used to check whether the object is a timers class.
54  uint32_t _tag;
55 
57 
58  // Clock instance.
60 
61  typedef struct timer_t
62  {
63  int timer_id;
64  size_t interval;
66  void *arg;
67  } timer_t;
68 
69  typedef std::multimap<uint64_t, timer_t> timersmap_t;
71 
72  typedef std::set<int> cancelled_timers_t;
74 
75  struct match_by_id;
76 
78 };
79 }
80 
81 #endif
zmq::timers_t::cancel
int cancel(int timer_id_)
Definition: timers.cpp:51
zmq::timers_t::timer_t::arg
void * arg
Definition: timers.hpp:66
zmq::timers_timer_fn
void() timers_timer_fn(int timer_id_, void *arg_)
Definition: timers.hpp:14
zmq::timers_t::timer_t
struct zmq::timers_t::timer_t timer_t
zmq::timers_t::set_interval
int set_interval(int timer_id_, size_t interval_)
Definition: timers.cpp:72
zmq::timers_t::timer_t::interval
size_t interval
Definition: timers.hpp:64
clock.hpp
zmq::timers_t::cancelled_timers_t
std::set< int > cancelled_timers_t
Definition: timers.hpp:72
zmq::timers_t::timersmap_t
std::multimap< uint64_t, timer_t > timersmap_t
Definition: timers.hpp:69
zmq::timers_t::reset
int reset(int timer_id_)
Definition: timers.cpp:91
zmq::timers_t::timers_t
timers_t()
Definition: timers.cpp:9
zmq::timers_t::match_by_id
Definition: timers.cpp:38
zmq::timers_t::_tag
uint32_t _tag
Definition: timers.hpp:54
zmq
Definition: zmq.hpp:229
zmq::timers_t::~timers_t
~timers_t()
Definition: timers.cpp:13
zmq::timers_t::add
int add(size_t interval_, timers_timer_fn handler_, void *arg_)
Definition: timers.cpp:24
ZMQ_NON_COPYABLE_NOR_MOVABLE
#define ZMQ_NON_COPYABLE_NOR_MOVABLE(classname)
Definition: macros.hpp:58
zmq::timers_t::execute
int execute()
Definition: timers.cpp:131
void
typedef void(APIENTRY *GLDEBUGPROCARB)(GLenum source
zmq::timers_t::timer_t::timer_id
int timer_id
Definition: timers.hpp:63
zmq::timers_t::timer_t
Definition: timers.hpp:61
zmq::clock_t
Definition: clock.hpp:27
zmq::timers_t::timeout
long timeout()
Definition: timers.cpp:109
zmq::timers_t
Definition: timers.hpp:16
zmq::timers_t::_timers
timersmap_t _timers
Definition: timers.hpp:70
zmq::timers_t::_next_timer_id
int _next_timer_id
Definition: timers.hpp:56
zmq::timers_t::_cancelled_timers
cancelled_timers_t _cancelled_timers
Definition: timers.hpp:73
zmq::timers_t::check_tag
bool check_tag() const
Definition: timers.cpp:19
zmq::timers_t::_clock
clock_t _clock
Definition: timers.hpp:59
zmq::timers_t::timer_t::handler
timers_timer_fn * handler
Definition: timers.hpp:65


libaditof
Author(s):
autogenerated on Wed May 21 2025 02:07:00