]> git.llucax.com Git - software/eventxx.git/blob - test/mixed-way.cpp
Add a Download section to the documentation
[software/eventxx.git] / test / mixed-way.cpp
1 #include <eventxx>
2 #include <iostream>
3 #include <csignal>
4
5 struct handler
6 {
7         eventxx::dispatcher& d;
8         int i;
9         handler(eventxx::dispatcher& d): d(d), i(0) {}
10         void operator() (int signum, eventxx::type event)
11         {
12                 std::cout << ++i << " interrupts, ";
13                 if (i < 5) std::cout << "keep going...\n";
14                 else
15                 {
16                         std::cout << "done!\n";
17                         d.exit();
18                 }
19         }
20 };
21
22 void timer_handler(int, short, void*)
23 {
24         std::cout << "Press Ctrl-C 5 times to quit.\n";
25 }
26
27 int main()
28 {
29         eventxx::dispatcher d;
30         handler h(d);
31         eventxx::ctimer t(timer_handler);
32         eventxx::signal< handler > e(SIGINT, h);
33         d.add(t, eventxx::time(1)); // 1 second
34         d.add(e);
35         d.dispatch();
36         return 0;
37 }
38