From 17a6987e376600cc0294bd285606848e4d35b771 Mon Sep 17 00:00:00 2001 From: Leandro Lucarella Date: Fri, 26 Jan 2007 19:02:03 +0000 Subject: [PATCH] Add a test with mixed C-like and function object callbacks. --- test/Makefile | 3 ++- test/mixed-way.cpp | 40 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 42 insertions(+), 1 deletion(-) create mode 100644 test/mixed-way.cpp 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; +} + -- 2.43.0