From: Leandro Lucarella Date: Fri, 26 Jan 2007 19:02:03 +0000 (+0000) Subject: Add a test with mixed C-like and function object callbacks. X-Git-Tag: 0.1~11 X-Git-Url: https://git.llucax.com/software/eventxx.git/commitdiff_plain/17a6987e376600cc0294bd285606848e4d35b771 Add a test with mixed C-like and function object callbacks. --- diff --git a/test/Makefile b/test/Makefile index 3b45f26..4beddbf 100644 --- a/test/Makefile +++ b/test/Makefile @@ -5,7 +5,8 @@ CXXFLAGS=-I.. -g -Wall #CXXFLAGS+=-DEVENT_BASE_FREE_FIX LDFLAGS=-levent -targets=bench test-eof test-time test-weof trivial c-way functor-way prio-test +targets=bench test-eof test-time test-weof trivial c-way functor-way \ + prio-test mixed-way all: $(targets) diff --git a/test/mixed-way.cpp b/test/mixed-way.cpp new file mode 100644 index 0000000..d9517a2 --- /dev/null +++ b/test/mixed-way.cpp @@ -0,0 +1,40 @@ +#include +#include +#include + +using eventxx::dispatcher; + +struct handler +{ + dispatcher& d; + int i; + handler(dispatcher& d): d(d), i(0) {} + void operator() (int signum, short event) + { + if (i < 5) std::cout << "keep going...\n"; + else + { + std::cout << "done!\n"; + d.exit(); + } + } +}; + +void sighandler(int signum, short event, void* data) +{ + int& i = *static_cast< int* >(data); + std::cout << ++i << " interrupts, "; +} + +int main() +{ + dispatcher d; + handler h(d); + eventxx::csignal sigev(SIGINT, sighandler, &h.i); + eventxx::signal< handler > e(SIGINT, h); + d.add(sigev); + d.add(e); + d.dispatch(); + return 0; +} +