From c6e3632952bd3e86e4d8437d7619e7fececb524e Mon Sep 17 00:00:00 2001
From: Johannes Demel <demel@ant.uni-bremen.de>
Date: Sat, 9 May 2020 15:14:37 +0200
Subject: [PATCH] msg_handler: Use lambdas in most components

With this commit, all components except gr-qtgui use lambdas instead of
`boost::bind` to register msg handlers.
---
 gr-digital/lib/chunks_to_symbols_impl.cc         |  6 ++----
 gr-digital/lib/constellation_receiver_cb_impl.cc | 10 ++++------
 gr-digital/lib/costas_loop_cc_impl.cc            |  2 +-
 gr-digital/lib/crc32_async_bb_impl.cc            |  4 ++--
 gr-digital/lib/header_payload_demux_impl.cc      |  5 ++---
 gr-digital/lib/protocol_formatter_async_impl.cc  |  3 +--
 gr-fec/lib/async_decoder_impl.cc                 |  5 ++---
 gr-fec/lib/async_encoder_impl.cc                 |  5 ++---
 gr-fec/lib/depuncture_bb_impl.cc                 |  2 +-
 gr-fec/lib/puncture_bb_impl.cc                   |  2 +-
 gr-fec/lib/puncture_ff_impl.cc                   |  2 +-
 gr-filter/lib/freq_xlating_fir_filter_impl.cc    |  8 ++------
 gr-filter/lib/mmse_resampler_cc_impl.cc          |  2 +-
 gr-filter/lib/mmse_resampler_ff_impl.cc          |  2 +-
 gr-uhd/lib/usrp_block_impl.cc                    |  2 +-
 gr-zeromq/lib/pub_msg_sink_impl.cc               |  2 +-
 gr-zeromq/lib/push_msg_sink_impl.cc              |  2 +-
 17 files changed, 26 insertions(+), 38 deletions(-)

diff --git a/gr-digital/lib/chunks_to_symbols_impl.cc b/gr-digital/lib/chunks_to_symbols_impl.cc
index 26d590a66e..c2cc99b0c8 100644
--- a/gr-digital/lib/chunks_to_symbols_impl.cc
+++ b/gr-digital/lib/chunks_to_symbols_impl.cc
@@ -51,10 +51,8 @@ chunks_to_symbols_impl<IN_T, OUT_T>::chunks_to_symbols_impl(
       d_symbol_table(symbol_table)
 {
     this->message_port_register_in(pmt::mp("set_symbol_table"));
-    this->set_msg_handler(
-        pmt::mp("set_symbol_table"),
-        boost::bind(
-            &chunks_to_symbols_impl<IN_T, OUT_T>::handle_set_symbol_table, this, _1));
+    this->set_msg_handler(pmt::mp("set_symbol_table"),
+                          [this](pmt::pmt_t msg) { this->handle_set_symbol_table(msg); });
 }
 
 template <class IN_T, class OUT_T>
diff --git a/gr-digital/lib/constellation_receiver_cb_impl.cc b/gr-digital/lib/constellation_receiver_cb_impl.cc
index 7fb7559d5e..1c160ff1bb 100644
--- a/gr-digital/lib/constellation_receiver_cb_impl.cc
+++ b/gr-digital/lib/constellation_receiver_cb_impl.cc
@@ -61,14 +61,12 @@ constellation_receiver_cb_impl::constellation_receiver_cb_impl(
             "This receiver only works with constellations of dimension 1.");
 
     message_port_register_in(pmt::mp("set_constellation"));
-    set_msg_handler(
-        pmt::mp("set_constellation"),
-        boost::bind(&constellation_receiver_cb_impl::handle_set_constellation, this, _1));
+    set_msg_handler(pmt::mp("set_constellation"),
+                    [this](pmt::pmt_t msg) { this->handle_set_constellation(msg); });
 
     message_port_register_in(pmt::mp("rotate_phase"));
-    set_msg_handler(
-        pmt::mp("rotate_phase"),
-        boost::bind(&constellation_receiver_cb_impl::handle_rotate_phase, this, _1));
+    set_msg_handler(pmt::mp("rotate_phase"),
+                    [this](pmt::pmt_t msg) { this->handle_rotate_phase(msg); });
 }
 
 constellation_receiver_cb_impl::~constellation_receiver_cb_impl() {}
diff --git a/gr-digital/lib/costas_loop_cc_impl.cc b/gr-digital/lib/costas_loop_cc_impl.cc
index c3b30834eb..b1a0e67caa 100644
--- a/gr-digital/lib/costas_loop_cc_impl.cc
+++ b/gr-digital/lib/costas_loop_cc_impl.cc
@@ -82,7 +82,7 @@ costas_loop_cc_impl::costas_loop_cc_impl(float loop_bw, int order, bool use_snr)
 
     message_port_register_in(pmt::mp("noise"));
     set_msg_handler(pmt::mp("noise"),
-                    boost::bind(&costas_loop_cc_impl::handle_set_noise, this, _1));
+                    [this](pmt::pmt_t msg) { this->handle_set_noise(msg); });
 }
 
 costas_loop_cc_impl::~costas_loop_cc_impl() {}
diff --git a/gr-digital/lib/crc32_async_bb_impl.cc b/gr-digital/lib/crc32_async_bb_impl.cc
index bffbb2a737..230decc2ae 100644
--- a/gr-digital/lib/crc32_async_bb_impl.cc
+++ b/gr-digital/lib/crc32_async_bb_impl.cc
@@ -48,9 +48,9 @@ crc32_async_bb_impl::crc32_async_bb_impl(bool check)
     message_port_register_out(d_out_port);
 
     if (check)
-        set_msg_handler(d_in_port, boost::bind(&crc32_async_bb_impl::check, this, _1));
+        set_msg_handler(d_in_port, [this](pmt::pmt_t msg) { this->check(msg); });
     else
-        set_msg_handler(d_in_port, boost::bind(&crc32_async_bb_impl::calc, this, _1));
+        set_msg_handler(d_in_port, [this](pmt::pmt_t msg) { this->calc(msg); });
 }
 
 crc32_async_bb_impl::~crc32_async_bb_impl() {}
diff --git a/gr-digital/lib/header_payload_demux_impl.cc b/gr-digital/lib/header_payload_demux_impl.cc
index 98c805fb20..5dc65f422b 100644
--- a/gr-digital/lib/header_payload_demux_impl.cc
+++ b/gr-digital/lib/header_payload_demux_impl.cc
@@ -150,9 +150,8 @@ header_payload_demux_impl::header_payload_demux_impl(
     }
     set_tag_propagation_policy(TPP_DONT);
     message_port_register_in(msg_port_id());
-    set_msg_handler(
-        msg_port_id(),
-        boost::bind(&header_payload_demux_impl::parse_header_data_msg, this, _1));
+    set_msg_handler(msg_port_id(),
+                    [this](pmt::pmt_t msg) { this->parse_header_data_msg(msg); });
     for (size_t i = 0; i < special_tags.size(); i++) {
         d_special_tags.push_back(pmt::string_to_symbol(special_tags[i]));
         d_special_tags_last_value.push_back(pmt::PMT_NIL);
diff --git a/gr-digital/lib/protocol_formatter_async_impl.cc b/gr-digital/lib/protocol_formatter_async_impl.cc
index 84b693745d..08e324ecfb 100644
--- a/gr-digital/lib/protocol_formatter_async_impl.cc
+++ b/gr-digital/lib/protocol_formatter_async_impl.cc
@@ -54,8 +54,7 @@ protocol_formatter_async_impl::protocol_formatter_async_impl(
     message_port_register_out(d_hdr_port);
     message_port_register_out(d_pld_port);
 
-    set_msg_handler(d_in_port,
-                    boost::bind(&protocol_formatter_async_impl::append, this, _1));
+    set_msg_handler(d_in_port, [this](pmt::pmt_t msg) { this->append(msg); });
 }
 
 protocol_formatter_async_impl::~protocol_formatter_async_impl() {}
diff --git a/gr-fec/lib/async_decoder_impl.cc b/gr-fec/lib/async_decoder_impl.cc
index e7a668c832..c907b297a5 100644
--- a/gr-fec/lib/async_decoder_impl.cc
+++ b/gr-fec/lib/async_decoder_impl.cc
@@ -64,11 +64,10 @@ async_decoder_impl::async_decoder_impl(generic_decoder::sptr my_decoder,
 
     if (d_packed) {
         d_pack = new blocks::kernel::pack_k_bits(8);
-        set_msg_handler(d_in_port,
-                        boost::bind(&async_decoder_impl::decode_packed, this, _1));
+        set_msg_handler(d_in_port, [this](pmt::pmt_t msg) { this->decode_packed(msg); });
     } else {
         set_msg_handler(d_in_port,
-                        boost::bind(&async_decoder_impl::decode_unpacked, this, _1));
+                        [this](pmt::pmt_t msg) { this->decode_unpacked(msg); });
     }
 
     // The maximum frame size is set by the initial frame size of the decoder.
diff --git a/gr-fec/lib/async_encoder_impl.cc b/gr-fec/lib/async_encoder_impl.cc
index 811d55601f..2e8fd62d12 100644
--- a/gr-fec/lib/async_encoder_impl.cc
+++ b/gr-fec/lib/async_encoder_impl.cc
@@ -63,8 +63,7 @@ async_encoder_impl::async_encoder_impl(generic_encoder::sptr my_encoder,
     message_port_register_out(d_out_port);
 
     if (d_packed) {
-        set_msg_handler(d_in_port,
-                        boost::bind(&async_encoder_impl::encode_packed, this, _1));
+        set_msg_handler(d_in_port, [this](pmt::pmt_t msg) { this->encode_packed(msg); });
 
         d_unpack = new blocks::kernel::unpack_k_bits(8);
 
@@ -74,7 +73,7 @@ async_encoder_impl::async_encoder_impl(generic_encoder::sptr my_encoder,
 
     } else {
         set_msg_handler(d_in_port,
-                        boost::bind(&async_encoder_impl::encode_unpacked, this, _1));
+                        [this](pmt::pmt_t msg) { this->encode_unpacked(msg); });
     }
 
     if (d_packed || (strncmp(d_encoder->get_input_conversion(), "pack", 4) == 0)) {
diff --git a/gr-fec/lib/depuncture_bb_impl.cc b/gr-fec/lib/depuncture_bb_impl.cc
index 27d00bb5bb..59ed44dd8a 100644
--- a/gr-fec/lib/depuncture_bb_impl.cc
+++ b/gr-fec/lib/depuncture_bb_impl.cc
@@ -74,7 +74,7 @@ depuncture_bb_impl::depuncture_bb_impl(int puncsize, int puncpat, int delay, cha
     set_fixed_rate(true);
     set_relative_rate((uint64_t)d_puncsize, (uint64_t)(d_puncsize - d_puncholes));
     set_output_multiple(d_puncsize);
-    // set_msg_handler(boost::bind(&depuncture_bb_impl::catch_msg, this, _1));
+    // set_msg_handler(<portname>, [this](pmt::pmt_t msg) { this->catch_msg(msg); });
 }
 
 depuncture_bb_impl::~depuncture_bb_impl() {}
diff --git a/gr-fec/lib/puncture_bb_impl.cc b/gr-fec/lib/puncture_bb_impl.cc
index a365d6a69f..1f328c2214 100644
--- a/gr-fec/lib/puncture_bb_impl.cc
+++ b/gr-fec/lib/puncture_bb_impl.cc
@@ -72,7 +72,7 @@ puncture_bb_impl::puncture_bb_impl(int puncsize, int puncpat, int delay)
     set_fixed_rate(true);
     set_relative_rate((uint64_t)(d_puncsize - d_puncholes), (uint64_t)d_puncsize);
     set_output_multiple(d_puncsize - d_puncholes);
-    // set_msg_handler(boost::bind(&puncture_bb_impl::catch_msg, this, _1));
+    // set_msg_handler(<portname>, [this](pmt::pmt_t msg) { this->catch_msg(msg); });
 }
 
 puncture_bb_impl::~puncture_bb_impl() {}
diff --git a/gr-fec/lib/puncture_ff_impl.cc b/gr-fec/lib/puncture_ff_impl.cc
index c95288d691..31c686ea4c 100644
--- a/gr-fec/lib/puncture_ff_impl.cc
+++ b/gr-fec/lib/puncture_ff_impl.cc
@@ -72,7 +72,7 @@ puncture_ff_impl::puncture_ff_impl(int puncsize, int puncpat, int delay)
     set_fixed_rate(true);
     set_relative_rate((uint64_t)(d_puncsize - d_puncholes), (uint64_t)d_puncsize);
     set_output_multiple(d_puncsize - d_puncholes);
-    // set_msg_handler(boost::bind(&puncture_ff_impl::catch_msg, this, _1));
+    // set_msg_handler(<portname>, [this](pmt::pmt_t msg) { this->catch_msg(msg); });
 }
 
 puncture_ff_impl::~puncture_ff_impl() {}
diff --git a/gr-filter/lib/freq_xlating_fir_filter_impl.cc b/gr-filter/lib/freq_xlating_fir_filter_impl.cc
index 8ddc967ba1..1050fb82a5 100644
--- a/gr-filter/lib/freq_xlating_fir_filter_impl.cc
+++ b/gr-filter/lib/freq_xlating_fir_filter_impl.cc
@@ -67,12 +67,8 @@ freq_xlating_fir_filter_impl<IN_T, OUT_T, TAP_T>::freq_xlating_fir_filter_impl(
     this->build_composite_fir();
 
     this->message_port_register_in(pmt::mp("freq"));
-    this->set_msg_handler(
-        pmt::mp("freq"),
-        boost::bind(
-            &freq_xlating_fir_filter_impl<IN_T, OUT_T, TAP_T>::handle_set_center_freq,
-            this,
-            _1));
+    this->set_msg_handler(pmt::mp("freq"),
+                          [this](pmt::pmt_t msg) { this->handle_set_center_freq(msg); });
 }
 
 template <class IN_T, class OUT_T, class TAP_T>
diff --git a/gr-filter/lib/mmse_resampler_cc_impl.cc b/gr-filter/lib/mmse_resampler_cc_impl.cc
index 59f9eacfab..9ca62082ce 100644
--- a/gr-filter/lib/mmse_resampler_cc_impl.cc
+++ b/gr-filter/lib/mmse_resampler_cc_impl.cc
@@ -53,7 +53,7 @@ mmse_resampler_cc_impl::mmse_resampler_cc_impl(float phase_shift, float resamp_r
     set_inverse_relative_rate(d_mu_inc);
     message_port_register_in(pmt::intern("msg_in"));
     set_msg_handler(pmt::intern("msg_in"),
-                    boost::bind(&mmse_resampler_cc_impl::handle_msg, this, _1));
+                    [this](pmt::pmt_t msg) { this->handle_msg(msg); });
 }
 
 mmse_resampler_cc_impl::~mmse_resampler_cc_impl() { delete d_resamp; }
diff --git a/gr-filter/lib/mmse_resampler_ff_impl.cc b/gr-filter/lib/mmse_resampler_ff_impl.cc
index 342d9f7678..312a6a8755 100644
--- a/gr-filter/lib/mmse_resampler_ff_impl.cc
+++ b/gr-filter/lib/mmse_resampler_ff_impl.cc
@@ -54,7 +54,7 @@ mmse_resampler_ff_impl::mmse_resampler_ff_impl(float phase_shift, float resamp_r
 
     message_port_register_in(pmt::intern("msg_in"));
     set_msg_handler(pmt::intern("msg_in"),
-                    boost::bind(&mmse_resampler_ff_impl::handle_msg, this, _1));
+                    [this](pmt::pmt_t msg) { this->handle_msg(msg); });
 }
 
 mmse_resampler_ff_impl::~mmse_resampler_ff_impl() { delete d_resamp; }
diff --git a/gr-uhd/lib/usrp_block_impl.cc b/gr-uhd/lib/usrp_block_impl.cc
index 4f030159ff..e5e1dd9161 100644
--- a/gr-uhd/lib/usrp_block_impl.cc
+++ b/gr-uhd/lib/usrp_block_impl.cc
@@ -137,7 +137,7 @@ usrp_block_impl::usrp_block_impl(const ::uhd::device_addr_t& device_addr,
     // Set up message ports:
     message_port_register_in(pmt::mp("command"));
     set_msg_handler(pmt::mp("command"),
-                    boost::bind(&usrp_block_impl::msg_handler_command, this, _1));
+                    [this](pmt::pmt_t msg) { this->msg_handler_command(msg); });
 
 // cuz we lazy:
 #define REGISTER_CMD_HANDLER(key, _handler) \
diff --git a/gr-zeromq/lib/pub_msg_sink_impl.cc b/gr-zeromq/lib/pub_msg_sink_impl.cc
index b5da7421ef..3973b8f835 100644
--- a/gr-zeromq/lib/pub_msg_sink_impl.cc
+++ b/gr-zeromq/lib/pub_msg_sink_impl.cc
@@ -62,7 +62,7 @@ pub_msg_sink_impl::pub_msg_sink_impl(char* address, int timeout, bool bind)
     }
 
     message_port_register_in(pmt::mp("in"));
-    set_msg_handler(pmt::mp("in"), boost::bind(&pub_msg_sink_impl::handler, this, _1));
+    set_msg_handler(pmt::mp("in"), [this](pmt::pmt_t msg) { this->handler(msg); });
 }
 
 pub_msg_sink_impl::~pub_msg_sink_impl()
diff --git a/gr-zeromq/lib/push_msg_sink_impl.cc b/gr-zeromq/lib/push_msg_sink_impl.cc
index 4140781ab9..fee734753b 100644
--- a/gr-zeromq/lib/push_msg_sink_impl.cc
+++ b/gr-zeromq/lib/push_msg_sink_impl.cc
@@ -62,7 +62,7 @@ push_msg_sink_impl::push_msg_sink_impl(char* address, int timeout, bool bind)
     }
 
     message_port_register_in(pmt::mp("in"));
-    set_msg_handler(pmt::mp("in"), boost::bind(&push_msg_sink_impl::handler, this, _1));
+    set_msg_handler(pmt::mp("in"), [this](pmt::pmt_t msg) { this->handler(msg); });
 }
 
 push_msg_sink_impl::~push_msg_sink_impl()
