]> git.llucax.com Git - software/eventxx.git/blob - test/mixed-way.cpp
tagged 0.3
[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                 if (i < 5) std::cout << "keep going...\n";
13                 else
14                 {
15                         std::cout << "done!\n";
16                         d.exit();
17                 }
18         }
19 };
20
21 void sighandler(int signum, short event, void* data)
22 {
23         int& i = *static_cast< int* >(data);
24         std::cout << ++i << " interrupts, ";
25 }
26
27 int main()
28 {
29         eventxx::dispatcher d;
30         handler h(d);
31         eventxx::csignal sigev(SIGINT, sighandler, &h.i);
32         eventxx::signal< handler > e(SIGINT, h);
33         d.add(sigev);
34         d.add(e);
35         d.dispatch();
36         return 0;
37 }
38