diff options
author | Johannes Demel <demel@ant.uni-bremen.de> | 2020-05-09 14:25:32 +0200 |
---|---|---|
committer | Josh Morman <mormjb@gmail.com> | 2020-06-04 10:05:48 -0400 |
commit | d584e7e9be13b500a8bc9a85f37d1cd51b0e0be5 (patch) | |
tree | 9e30cecfdeed04cb32263f7b9509291e0d6fbf40 | |
parent | a6a1954f83478aff0c4fc53d0e8f51b49d51cc1e (diff) |
msg_handler: Use lambdas to set msg handlers
With this commit, all calls to `set_msg_handler` in `gr-blocks` use
lambdas. This helps to use `std::function` instead of `boost::function`.
-rw-r--r-- | gnuradio-runtime/lib/block.cc | 3 | ||||
-rw-r--r-- | gr-blocks/lib/copy_impl.cc | 3 | ||||
-rw-r--r-- | gr-blocks/lib/message_debug_impl.cc | 11 | ||||
-rw-r--r-- | gr-blocks/lib/message_strobe_impl.cc | 4 | ||||
-rw-r--r-- | gr-blocks/lib/message_strobe_random_impl.cc | 4 | ||||
-rw-r--r-- | gr-blocks/lib/multiply_matrix_impl.cc | 10 | ||||
-rw-r--r-- | gr-blocks/lib/mute_impl.cc | 3 | ||||
-rw-r--r-- | gr-blocks/lib/nop_impl.cc | 5 | ||||
-rw-r--r-- | gr-blocks/lib/pdu_filter_impl.cc | 2 | ||||
-rw-r--r-- | gr-blocks/lib/pdu_remove_impl.cc | 2 | ||||
-rw-r--r-- | gr-blocks/lib/pdu_set_impl.cc | 3 | ||||
-rw-r--r-- | gr-blocks/lib/random_pdu_impl.cc | 6 | ||||
-rw-r--r-- | gr-blocks/lib/repeat_impl.cc | 4 | ||||
-rw-r--r-- | gr-blocks/lib/socket_pdu_impl.cc | 20 | ||||
-rw-r--r-- | gr-blocks/lib/tagged_stream_multiply_length_impl.cc | 4 | ||||
-rw-r--r-- | gr-blocks/lib/tuntap_pdu_impl.cc | 3 |
16 files changed, 28 insertions, 59 deletions
diff --git a/gnuradio-runtime/lib/block.cc b/gnuradio-runtime/lib/block.cc index b10ae97072..b6137f7a51 100644 --- a/gnuradio-runtime/lib/block.cc +++ b/gnuradio-runtime/lib/block.cc @@ -49,8 +49,7 @@ block::block(const std::string& name, { global_block_registry.register_primitive(alias(), this); message_port_register_in(d_system_port); - set_msg_handler(d_system_port, - std::bind(&block::system_handler, this, std::placeholders::_1)); + set_msg_handler(d_system_port, [this](pmt::pmt_t msg) { this->system_handler(msg); }); } block::~block() { global_block_registry.unregister_primitive(symbol_name()); } diff --git a/gr-blocks/lib/copy_impl.cc b/gr-blocks/lib/copy_impl.cc index 3d1229b89a..c963f0d635 100644 --- a/gr-blocks/lib/copy_impl.cc +++ b/gr-blocks/lib/copy_impl.cc @@ -32,8 +32,7 @@ copy_impl::copy_impl(size_t itemsize) d_enabled(true) { message_port_register_in(pmt::mp("en")); - set_msg_handler(pmt::mp("en"), - std::bind(©_impl::handle_enable, this, std::placeholders::_1)); + set_msg_handler(pmt::mp("en"), [this](pmt::pmt_t msg) { this->handle_enable(msg); }); } copy_impl::~copy_impl() {} diff --git a/gr-blocks/lib/message_debug_impl.cc b/gr-blocks/lib/message_debug_impl.cc index 55352f6e62..eb47fee299 100644 --- a/gr-blocks/lib/message_debug_impl.cc +++ b/gr-blocks/lib/message_debug_impl.cc @@ -78,17 +78,14 @@ message_debug_impl::message_debug_impl() : block("message_debug", io_signature::make(0, 0, 0), io_signature::make(0, 0, 0)) { message_port_register_in(pmt::mp("print")); - set_msg_handler(pmt::mp("print"), - std::bind(&message_debug_impl::print, this, std::placeholders::_1)); + set_msg_handler(pmt::mp("print"), [this](pmt::pmt_t msg) { this->print(msg); }); message_port_register_in(pmt::mp("store")); - set_msg_handler(pmt::mp("store"), - std::bind(&message_debug_impl::store, this, std::placeholders::_1)); + set_msg_handler(pmt::mp("store"), [this](pmt::pmt_t msg) { this->store(msg); }); message_port_register_in(pmt::mp("print_pdu")); - set_msg_handler( - pmt::mp("print_pdu"), - std::bind(&message_debug_impl::print_pdu, this, std::placeholders::_1)); + set_msg_handler(pmt::mp("print_pdu"), + [this](pmt::pmt_t msg) { this->print_pdu(msg); }); } message_debug_impl::~message_debug_impl() {} diff --git a/gr-blocks/lib/message_strobe_impl.cc b/gr-blocks/lib/message_strobe_impl.cc index 4f1f7b5ff9..33215a5a81 100644 --- a/gr-blocks/lib/message_strobe_impl.cc +++ b/gr-blocks/lib/message_strobe_impl.cc @@ -41,9 +41,7 @@ message_strobe_impl::message_strobe_impl(pmt::pmt_t msg, long period_ms) message_port_register_out(d_port); message_port_register_in(pmt::mp("set_msg")); - set_msg_handler( - pmt::mp("set_msg"), - std::bind(&message_strobe_impl::set_msg, this, std::placeholders::_1)); + set_msg_handler(pmt::mp("set_msg"), [this](pmt::pmt_t msg) { this->set_msg(msg); }); } message_strobe_impl::~message_strobe_impl() {} diff --git a/gr-blocks/lib/message_strobe_random_impl.cc b/gr-blocks/lib/message_strobe_random_impl.cc index 1241d1c382..1c2b4ec2a1 100644 --- a/gr-blocks/lib/message_strobe_random_impl.cc +++ b/gr-blocks/lib/message_strobe_random_impl.cc @@ -54,9 +54,7 @@ message_strobe_random_impl::message_strobe_random_impl( new gr::thread::thread(std::bind(&message_strobe_random_impl::run, this))); message_port_register_in(pmt::mp("set_msg")); - set_msg_handler( - pmt::mp("set_msg"), - std::bind(&message_strobe_random_impl::set_msg, this, std::placeholders::_1)); + set_msg_handler(pmt::mp("set_msg"), [this](pmt::pmt_t msg) { this->set_msg(msg); }); } void message_strobe_random_impl::set_mean(float mean_ms) diff --git a/gr-blocks/lib/multiply_matrix_impl.cc b/gr-blocks/lib/multiply_matrix_impl.cc index 358843abff..539432eac8 100644 --- a/gr-blocks/lib/multiply_matrix_impl.cc +++ b/gr-blocks/lib/multiply_matrix_impl.cc @@ -223,10 +223,7 @@ multiply_matrix_impl<gr_complex>::multiply_matrix_impl( pmt::pmt_t port_name = pmt::string_to_symbol("set_A"); message_port_register_in(port_name); - set_msg_handler(port_name, - std::bind(&multiply_matrix_impl<gr_complex>::msg_handler_A, - this, - std::placeholders::_1)); + set_msg_handler(port_name, [this](pmt::pmt_t msg) { this->msg_handler_A(msg); }); } template <> @@ -245,10 +242,7 @@ multiply_matrix_impl<float>::multiply_matrix_impl( pmt::pmt_t port_name = pmt::string_to_symbol("set_A"); message_port_register_in(port_name); - set_msg_handler(port_name, - std::bind(&multiply_matrix_impl<float>::msg_handler_A, - this, - std::placeholders::_1)); + set_msg_handler(port_name, [this](pmt::pmt_t msg) { this->msg_handler_A(msg); }); } diff --git a/gr-blocks/lib/mute_impl.cc b/gr-blocks/lib/mute_impl.cc index e77d3199b4..c17573b0c2 100644 --- a/gr-blocks/lib/mute_impl.cc +++ b/gr-blocks/lib/mute_impl.cc @@ -36,8 +36,7 @@ mute_impl<T>::mute_impl(bool mute) { this->message_port_register_in(pmt::intern("set_mute")); this->set_msg_handler( - pmt::intern("set_mute"), - std::bind(&mute_impl<T>::set_mute_pmt, this, std::placeholders::_1)); + pmt::intern("set_mute"), [this](pmt::pmt_t msg) { this->set_mute_pmt(msg); }); } template <class T> diff --git a/gr-blocks/lib/nop_impl.cc b/gr-blocks/lib/nop_impl.cc index 042db40da9..5ed25f5d1a 100644 --- a/gr-blocks/lib/nop_impl.cc +++ b/gr-blocks/lib/nop_impl.cc @@ -32,9 +32,8 @@ nop_impl::nop_impl(size_t sizeof_stream_item) { // Arrange to have count_received_msgs called when messages are received. message_port_register_in(pmt::mp("port")); - set_msg_handler( - pmt::mp("port"), - std::bind(&nop_impl::count_received_msgs, this, std::placeholders::_1)); + set_msg_handler(pmt::mp("port"), + [this](pmt::pmt_t msg) { this->count_received_msgs(msg); }); } nop_impl::~nop_impl() {} diff --git a/gr-blocks/lib/pdu_filter_impl.cc b/gr-blocks/lib/pdu_filter_impl.cc index eca057144e..dcf83a8d2e 100644 --- a/gr-blocks/lib/pdu_filter_impl.cc +++ b/gr-blocks/lib/pdu_filter_impl.cc @@ -33,7 +33,7 @@ pdu_filter_impl::pdu_filter_impl(pmt::pmt_t k, pmt::pmt_t v, bool invert) message_port_register_out(pdu::pdu_port_id()); message_port_register_in(pdu::pdu_port_id()); set_msg_handler(pdu::pdu_port_id(), - std::bind(&pdu_filter_impl::handle_msg, this, std::placeholders::_1)); + [this](pmt::pmt_t msg) { this->handle_msg(msg); }); } void pdu_filter_impl::handle_msg(pmt::pmt_t pdu) diff --git a/gr-blocks/lib/pdu_remove_impl.cc b/gr-blocks/lib/pdu_remove_impl.cc index ddcf5f995e..55a3b7237e 100644 --- a/gr-blocks/lib/pdu_remove_impl.cc +++ b/gr-blocks/lib/pdu_remove_impl.cc @@ -31,7 +31,7 @@ pdu_remove_impl::pdu_remove_impl(pmt::pmt_t k) message_port_register_out(pdu::pdu_port_id()); message_port_register_in(pdu::pdu_port_id()); set_msg_handler(pdu::pdu_port_id(), - std::bind(&pdu_remove_impl::handle_msg, this, std::placeholders::_1)); + [this](pmt::pmt_t msg) { this->handle_msg(msg); }); } void pdu_remove_impl::handle_msg(pmt::pmt_t pdu) diff --git a/gr-blocks/lib/pdu_set_impl.cc b/gr-blocks/lib/pdu_set_impl.cc index ade302e31e..337da584de 100644 --- a/gr-blocks/lib/pdu_set_impl.cc +++ b/gr-blocks/lib/pdu_set_impl.cc @@ -31,8 +31,7 @@ pdu_set_impl::pdu_set_impl(pmt::pmt_t k, pmt::pmt_t v) { message_port_register_out(pdu::pdu_port_id()); message_port_register_in(pdu::pdu_port_id()); - set_msg_handler(pdu::pdu_port_id(), - std::bind(&pdu_set_impl::handle_msg, this, std::placeholders::_1)); + set_msg_handler(pdu::pdu_port_id(), [this](pmt::pmt_t msg) { this->handle_msg(msg); }); } void pdu_set_impl::handle_msg(pmt::pmt_t pdu) diff --git a/gr-blocks/lib/random_pdu_impl.cc b/gr-blocks/lib/random_pdu_impl.cc index 3714e37085..b0d4f8d7e0 100644 --- a/gr-blocks/lib/random_pdu_impl.cc +++ b/gr-blocks/lib/random_pdu_impl.cc @@ -38,11 +38,7 @@ random_pdu_impl::random_pdu_impl(int min_items, { message_port_register_out(pdu::pdu_port_id()); message_port_register_in(pmt::mp("generate")); - set_msg_handler(pmt::mp("generate"), - std::bind(static_cast<void (random_pdu_impl::*)(pmt::pmt_t)>( - &random_pdu_impl::generate_pdu), - this, - std::placeholders::_1)); + set_msg_handler(pmt::mp("generate"), [this](pmt::pmt_t msg) { this->generate_pdu(msg); }); if (length_modulo < 1) throw std::runtime_error("length_module must be >= 1"); if (max_items < length_modulo) diff --git a/gr-blocks/lib/repeat_impl.cc b/gr-blocks/lib/repeat_impl.cc index 96e2a25eb2..539b9d4b58 100644 --- a/gr-blocks/lib/repeat_impl.cc +++ b/gr-blocks/lib/repeat_impl.cc @@ -32,9 +32,7 @@ repeat_impl::repeat_impl(size_t itemsize, int interp) d_interp(interp) { message_port_register_in(pmt::mp("interpolation")); - set_msg_handler( - pmt::mp("interpolation"), - std::bind(&repeat_impl::msg_set_interpolation, this, std::placeholders::_1)); + set_msg_handler(pmt::mp("interpolation"), [this](pmt::pmt_t msg) { this->msg_set_interpolation(msg); }); } void repeat_impl::msg_set_interpolation(pmt::pmt_t msg) diff --git a/gr-blocks/lib/socket_pdu_impl.cc b/gr-blocks/lib/socket_pdu_impl.cc index 14dc124e63..bdbe1eb2d2 100644 --- a/gr-blocks/lib/socket_pdu_impl.cc +++ b/gr-blocks/lib/socket_pdu_impl.cc @@ -88,9 +88,8 @@ socket_pdu_impl::socket_pdu_impl(std::string type, start_tcp_accept(); - set_msg_handler( - pdu::pdu_port_id(), - std::bind(&socket_pdu_impl::tcp_server_send, this, std::placeholders::_1)); + set_msg_handler(pdu::pdu_port_id(), + [this](pmt::pmt_t msg) { this->tcp_server_send(msg); }); } else if (type == "TCP_CLIENT") { boost::system::error_code error = boost::asio::error::host_not_found; d_tcp_socket.reset(new boost::asio::ip::tcp::socket(d_io_service)); @@ -99,9 +98,8 @@ socket_pdu_impl::socket_pdu_impl(std::string type, throw boost::system::system_error(error); d_tcp_socket->set_option(boost::asio::ip::tcp::no_delay(d_tcp_no_delay)); - set_msg_handler( - pdu::pdu_port_id(), - std::bind(&socket_pdu_impl::tcp_client_send, this, std::placeholders::_1)); + set_msg_handler(pdu::pdu_port_id(), + [this](pmt::pmt_t msg) { this->tcp_client_send(msg); }); d_tcp_socket->async_read_some( boost::asio::buffer(d_rxbuf), @@ -120,9 +118,8 @@ socket_pdu_impl::socket_pdu_impl(std::string type, boost::asio::placeholders::error, boost::asio::placeholders::bytes_transferred)); - set_msg_handler( - pdu::pdu_port_id(), - std::bind(&socket_pdu_impl::udp_send, this, std::placeholders::_1)); + set_msg_handler(pdu::pdu_port_id(), + [this](pmt::pmt_t msg) { this->udp_send(msg); }); } else if (type == "UDP_CLIENT") { d_udp_socket.reset( new boost::asio::ip::udp::socket(d_io_service, d_udp_endpoint)); @@ -134,9 +131,8 @@ socket_pdu_impl::socket_pdu_impl(std::string type, boost::asio::placeholders::error, boost::asio::placeholders::bytes_transferred)); - set_msg_handler( - pdu::pdu_port_id(), - std::bind(&socket_pdu_impl::udp_send, this, std::placeholders::_1)); + set_msg_handler(pdu::pdu_port_id(), + [this](pmt::pmt_t msg) { this->udp_send(msg); }); } else throw std::runtime_error("gr::blocks:socket_pdu: unknown socket type"); diff --git a/gr-blocks/lib/tagged_stream_multiply_length_impl.cc b/gr-blocks/lib/tagged_stream_multiply_length_impl.cc index 95877ec728..948c189444 100644 --- a/gr-blocks/lib/tagged_stream_multiply_length_impl.cc +++ b/gr-blocks/lib/tagged_stream_multiply_length_impl.cc @@ -38,9 +38,7 @@ tagged_stream_multiply_length_impl::tagged_stream_multiply_length_impl( set_relative_rate(1, 1); message_port_register_in(pmt::intern("set_scalar")); set_msg_handler(pmt::intern("set_scalar"), - std::bind(&tagged_stream_multiply_length_impl::set_scalar_pmt, - this, - std::placeholders::_1)); + [this](pmt::pmt_t msg) { this->set_scalar_pmt(msg); }); } tagged_stream_multiply_length_impl::~tagged_stream_multiply_length_impl() {} diff --git a/gr-blocks/lib/tuntap_pdu_impl.cc b/gr-blocks/lib/tuntap_pdu_impl.cc index 17a78cc322..c2e352c559 100644 --- a/gr-blocks/lib/tuntap_pdu_impl.cc +++ b/gr-blocks/lib/tuntap_pdu_impl.cc @@ -86,8 +86,7 @@ tuntap_pdu_impl::tuntap_pdu_impl(std::string dev, int MTU, bool istunflag) // set up input message port message_port_register_in(pdu::pdu_port_id()); - set_msg_handler(pdu::pdu_port_id(), - std::bind(&tuntap_pdu_impl::send, this, std::placeholders::_1)); + set_msg_handler(pdu::pdu_port_id(), [this](pmt::pmt_t msg) { this->send(msg); }); } int tuntap_pdu_impl::tun_alloc(char* dev, int flags) |