]> git.llucax.com Git - software/eventxx.git/commitdiff
Add a test with mixed C-like and function object callbacks.
authorLeandro Lucarella <llucarella@integratech.com.ar>
Fri, 26 Jan 2007 19:02:03 +0000 (19:02 +0000)
committerLeandro Lucarella <llucarella@integratech.com.ar>
Fri, 26 Jan 2007 19:02:03 +0000 (19:02 +0000)
test/Makefile
test/mixed-way.cpp [new file with mode: 0644]

index 3b45f263e062b3c0283cbaf6bd9eedbc9cebea14..4beddbfbb4112e004a7b51aa552ce050eac60a9b 100644 (file)
@@ -5,7 +5,8 @@ CXXFLAGS=-I.. -g -Wall
 #CXXFLAGS+=-DEVENT_BASE_FREE_FIX
 LDFLAGS=-levent
 
 #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)
 
 
 all: $(targets)
 
diff --git a/test/mixed-way.cpp b/test/mixed-way.cpp
new file mode 100644 (file)
index 0000000..d9517a2
--- /dev/null
@@ -0,0 +1,40 @@
+#include <eventxx>
+#include <iostream>
+#include <csignal>
+
+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;
+}
+