From 116144085c5fc68009ac90d77efd61507aa7585c Mon Sep 17 00:00:00 2001 From: Nicolas Schodet Date: Thu, 21 Feb 2013 22:40:30 +0100 Subject: digital/ucoolib/ucoolib/arch/host/mex: simplify handlers thanks to TR1 TR1 (and C++11, but this must compile on debian squeeze) defines function objects which can contain any callable which respects the prototype. This greatly simplify handler code. Also, get rid of get_instance and give Node as handler parameter instead. --- digital/ucoolib/ucoolib/arch/host/mex/test/test_mex.cc | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) (limited to 'digital/ucoolib/ucoolib/arch/host/mex/test/test_mex.cc') diff --git a/digital/ucoolib/ucoolib/arch/host/mex/test/test_mex.cc b/digital/ucoolib/ucoolib/arch/host/mex/test/test_mex.cc index f260203b..9628ca16 100644 --- a/digital/ucoolib/ucoolib/arch/host/mex/test/test_mex.cc +++ b/digital/ucoolib/ucoolib/arch/host/mex/test/test_mex.cc @@ -183,7 +183,7 @@ test_node_1 () } void -test_node_2_handle_hello (Msg &msg) +test_node_2_handle_hello (Node &, Msg &msg) { int pass; msg.pop ("l") >> pass; @@ -192,14 +192,14 @@ test_node_2_handle_hello (Msg &msg) } void -test_node_2_handle_world (Msg &msg) +test_node_2_handle_world (Node &node, Msg &msg) { int a, b; msg.pop ("bh") >> a >> b; printf ("world\n"); Msg resp (msg.mtype ()); resp.push ("l") << a + b; - Node::instance ()->response (resp); + node.response (resp); } void @@ -209,10 +209,8 @@ test_node_2 () mtype_t hello_mtype, world_mtype; hello_mtype = node.reserve ("hello"); world_mtype = node.reserve ("world"); - HandlerPtrfun hello_handler (test_node_2_handle_hello); - HandlerPtrfun world_handler (test_node_2_handle_world); - node.handler_register (hello_mtype, hello_handler); - node.handler_register (world_mtype, world_handler); + node.handler_register (hello_mtype, test_node_2_handle_hello); + node.handler_register (world_mtype, test_node_2_handle_world); node.wait (); } -- cgit v1.2.3