]> git.llucax.com Git - software/eventxx.git/blob - test/wrapped-functor-way.cpp
tagged 0.6
[software/eventxx.git] / test / wrapped-functor-way.cpp
1 #include <eventxx>
2 #include <iostream>
3 #include <csignal>
4
5 using eventxx::dispatcher;
6
7 struct handler
8 {
9         dispatcher& d;
10         int i;
11         handler(dispatcher& d): d(d), i(0) {}
12         void handle_event(int signum, eventxx::type event)
13         {
14                 std::cout << ++i << " interrupts, ";
15                 if (i < 5) std::cout << "keep going...\n";
16                 else
17                 {
18                         std::cout << "done!\n";
19                         d.exit();
20                 }
21         }
22 };
23
24 typedef eventxx::mem_cb< handler, void (handler::*)(int, eventxx::type) > cb_type;
25
26 int main()
27 {
28         dispatcher d;
29         handler h(d);
30         cb_type cb(h, &handler::handle_event);
31         eventxx::signal< cb_type > e(SIGINT, cb);
32         d.add(e);
33         d.dispatch();
34         return 0;
35 }
36