Tamer
C++ language extensions for event-driven programming
Loading...
Searching...
No Matches
driver.hh
Go to the documentation of this file.
1#ifndef TAMER_DRIVER_HH
2#define TAMER_DRIVER_HH 1
3/* Copyright (c) 2007-2015, Eddie Kohler
4 * Copyright (c) 2007, Regents of the University of California
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the "Software"),
8 * to deal in the Software without restriction, subject to the conditions
9 * listed in the Tamer LICENSE file. These conditions include: you must
10 * preserve this copyright notice, and you cannot mention the copyright
11 * holders in advertising related to the Software without their permission.
12 * The Software is provided WITHOUT ANY WARRANTY, EXPRESS OR IMPLIED. This
13 * notice is a summary of the Tamer LICENSE file; the license in that file is
14 * legally binding.
15 */
16#include <tamer/xdriver.hh>
17namespace tamer {
18
23
24enum init_flags {
25 init_tamer = 1,
26 init_libevent = 2,
27 init_libev = 4,
28 init_sigpipe = 0x1000,
29 init_strict = 0x2000,
30 init_no_epoll = 0x4000
31};
32
45bool initialize(int flags = 0);
46
52void cleanup();
53
54enum time_type_t {
55 time_normal,
56 time_virtual
57};
58
59void set_time_type(time_type_t tt);
60
62inline const timeval& recent() {
63 if (tamerpriv::need_recent) {
64 tamerpriv::recent = now();
65 tamerpriv::need_recent = false;
66 }
67 return tamerpriv::recent;
68}
69
72inline void set_recent() {
73 tamerpriv::need_recent = true;
74}
75
77inline double dtime(const timeval tv) {
78 return tv.tv_sec + tv.tv_usec / 1000000.;
79}
80
82inline double dnow() {
83 return dtime(now());
84}
85
87inline double drecent() {
88 return dtime(recent());
89}
90
92inline void loop(loop_flags flags) {
93 driver::main->loop(flags);
94}
95
97inline void loop() {
98 driver::main->loop(loop_forever);
99}
100
102inline void once() {
103 driver::main->loop(loop_once);
104}
105
107inline void break_loop() {
108 driver::main->break_loop();
109}
110
118inline void at_fd_read(int fd, event<> e) {
119 driver::main->at_fd(fd, fd_read, e);
120}
121
122inline void at_fd_read(int fd, event<int> e) {
123 driver::main->at_fd(fd, fd_read, e);
124}
125
133inline void at_fd_write(int fd, event<> e) {
134 driver::main->at_fd(fd, fd_write, e);
135}
136
137inline void at_fd_write(int fd, event<int> e) {
138 driver::main->at_fd(fd, fd_write, e);
139}
140
147inline void at_fd_shutdown(int fd, event<> e) {
148 driver::main->at_fd(fd, fd_hangup, e);
149}
150
163inline void at_time(const timeval &expiry, event<> e, bool bg = false) {
164 driver::main->at_time(expiry, e, bg);
165}
166
168inline void at_time(double expiry, event<> e, bool bg = false) {
169 driver::main->at_time(expiry, e, bg);
170}
171
180inline void at_delay(const timeval &delay, event<> e, bool bg = false) {
181 driver::main->at_delay(delay, e, bg);
182}
183
192inline void at_delay(double delay, event<> e, bool bg = false) {
193 driver::main->at_delay(delay, e, bg);
194}
195
204inline void at_delay_sec(int delay, event<> e, bool bg = false) {
205 driver::main->at_delay_sec(delay, e, bg);
206}
207
216inline void at_delay_msec(int delay, event<> e, bool bg = false) {
217 driver::main->at_delay_msec(delay, e, bg);
218}
219
228inline void at_delay_usec(int delay, event<> e, bool bg = false) {
229 driver::main->at_delay_usec(delay, e, bg);
230}
231
239inline void at_signal(int signo, event<> e) {
240 driver::at_signal(signo, e);
241}
242
248inline void at_asap(event<> e) {
249 driver::main->at_asap(e);
250}
251
257inline void at_preblock(event<> e) {
258 driver::main->at_preblock(e);
259}
260
261namespace tamerpriv { extern time_type_t time_type; }
262} // namespace tamer
263#endif /* TAMER_DRIVER_HH */
Namespace containing public Tamer classes and functions for the Tamer core.
Definition adapter.hh:17
void at_time(const timeval &expiry, event<> e, bool bg=false)
Register event for a given time.
Definition driver.hh:163
const timeval & recent()
Return a recent snapshot of the current time.
Definition driver.hh:62
void at_signal(int signo, event<> e)
Register event for signal occurrence.
Definition driver.hh:239
void at_fd_shutdown(int fd, event<> e)
Register event for file descriptor shutdown.
Definition driver.hh:147
void cleanup()
Clean up the Tamer event loop.
void once()
Run driver loop once.
Definition driver.hh:102
void at_fd_write(int fd, event<> e)
Register event for file descriptor writability.
Definition driver.hh:133
void at_delay_sec(int delay, event<> e, bool bg=false)
Register event for a given delay.
Definition driver.hh:204
void at_delay_msec(int delay, event<> e, bool bg=false)
Register event for a given delay.
Definition driver.hh:216
void break_loop()
Exit the current driver loop.
Definition driver.hh:107
double dtime(const timeval tv)
Translate a time to a double.
Definition driver.hh:77
void loop()
Run driver loop indefinitely.
Definition driver.hh:97
void at_fd_read(int fd, event<> e)
Register event for file descriptor readability.
Definition driver.hh:118
void at_delay(const timeval &delay, event<> e, bool bg=false)
Register event for a given delay.
Definition driver.hh:180
double drecent()
Return a recent snapshot of the current time as a double.
Definition driver.hh:87
bool initialize(int flags=0)
Initialize the Tamer event loop.
void at_delay_usec(int delay, event<> e, bool bg=false)
Register event for a given delay.
Definition driver.hh:228
void at_preblock(event<> e)
Register event to trigger before Tamer blocks.
Definition driver.hh:257
void at_asap(event<> e)
Register event to trigger soon.
Definition driver.hh:248
void set_recent()
Sets Tamer's current time to the current timestamp.
Definition driver.hh:72
double dnow()
Return the current time as a double.
Definition driver.hh:82