From 044b4a3b49b67adfe53e0e88f9adf847a25fad61 Mon Sep 17 00:00:00 2001
From: Jacob Gilbert <jacob.gilbert@protonmail.com>
Date: Mon, 15 Feb 2021 15:07:45 -0800
Subject: gr-blocks: deprecate print_pdu port of message_debug block

Having two print ports on this block has confused a number of people,
most recently issue #4191, and combining them is straightforward and
should make this block easier to use. The print_pdu formatting is now
be applied on the print port if the message is a PDU.

Signed-off-by: Jacob Gilbert <jacob.gilbert@protonmail.com>
---
 gr-blocks/lib/message_debug_impl.cc | 55 +++++++++++++++++++------------------
 1 file changed, 28 insertions(+), 27 deletions(-)

(limited to 'gr-blocks/lib/message_debug_impl.cc')

diff --git a/gr-blocks/lib/message_debug_impl.cc b/gr-blocks/lib/message_debug_impl.cc
index 557bbfd106..0dd2c834de 100644
--- a/gr-blocks/lib/message_debug_impl.cc
+++ b/gr-blocks/lib/message_debug_impl.cc
@@ -46,34 +46,13 @@ void message_debug_impl::print(pmt::pmt_t msg)
 {
     std::stringstream sout;
 
-    sout << "******* MESSAGE DEBUG PRINT ********" << std::endl
-         << pmt::write_string(msg) << std::endl
-         << "************************************" << std::endl;
-    std::cout << sout.str();
-}
-
-void message_debug_impl::store(pmt::pmt_t msg)
-{
-    gr::thread::scoped_lock guard(d_mutex);
-    d_messages.push_back(msg);
-}
-
-void message_debug_impl::print_pdu(pmt::pmt_t pdu)
-{
-    if (!pmt::is_pdu(pdu)) {
-        GR_LOG_WARN(d_logger, "Non PDU type message received. Dropping.");
-        return;
-    }
-
-    std::stringstream sout;
+    if (pmt::is_pdu(msg)) {
+        pmt::pmt_t meta = pmt::car(msg);
+        pmt::pmt_t vector = pmt::cdr(msg);
 
-    pmt::pmt_t meta = pmt::car(pdu);
-    pmt::pmt_t vector = pmt::cdr(pdu);
+        sout << "***** VERBOSE PDU DEBUG PRINT ******" << std::endl
+             << pmt::write_string(meta) << std::endl;
 
-    sout << "***** VERBOSE PDU DEBUG PRINT ******" << std::endl
-         << pmt::write_string(meta) << std::endl;
-
-    if (pmt::is_uniform_vector(vector)) {
         size_t len = pmt::blob_length(vector);
         if (d_en_uvec) {
             sout << "pdu length = " << len << " bytes" << std::endl
@@ -93,14 +72,36 @@ void message_debug_impl::print_pdu(pmt::pmt_t pdu)
         } else {
             sout << "pdu length = " << len << " bytes (printing disabled)" << std::endl;
         }
+
     } else {
-        sout << "Message CDR is not a uniform vector..." << std::endl;
+        sout << "******* MESSAGE DEBUG PRINT ********" << std::endl
+             << pmt::write_string(msg) << std::endl;
     }
 
     sout << "************************************" << std::endl;
     std::cout << sout.str();
 }
 
+void message_debug_impl::store(pmt::pmt_t msg)
+{
+    gr::thread::scoped_lock guard(d_mutex);
+    d_messages.push_back(msg);
+}
+
+// ! DEPRECATED as of 3.10 use print() for all printing!
+void message_debug_impl::print_pdu(pmt::pmt_t pdu)
+{
+    if (pmt::is_pdu(pdu)) {
+        GR_LOG_INFO(d_logger,
+                    "The `print_pdu` port is deprecated and will be removed; forwarding "
+                    "to `print`.");
+        this->print(pdu);
+    } else {
+        GR_LOG_INFO(d_logger, "The `print_pdu` port is deprecated and will be removed.");
+        GR_LOG_WARN(d_logger, "Non PDU type message received. Dropping.");
+    }
+}
+
 int message_debug_impl::num_messages() { return (int)d_messages.size(); }
 
 pmt::pmt_t message_debug_impl::get_message(int i)
-- 
cgit v1.2.3