From 83a57b493a992ea202faf2ce223b660d211c00d4 Mon Sep 17 00:00:00 2001 From: "Matthias P. Braendli" Date: Sat, 10 Mar 2018 22:28:08 +0100 Subject: Support UHD 3.11 logging subsystem --- src/output/UHD.cpp | 38 +++++++++++++++++++++++++++++++++++++- src/output/UHD.h | 1 - 2 files changed, 37 insertions(+), 2 deletions(-) (limited to 'src/output') diff --git a/src/output/UHD.cpp b/src/output/UHD.cpp index 6838338..04137cc 100644 --- a/src/output/UHD.cpp +++ b/src/output/UHD.cpp @@ -38,7 +38,19 @@ #include -#include +#include +// 3.11.0.0 introduces the API breaking change, where +// uhd::msg is replaced by the new log API +#if UHD_VERSION >= 3110000 +# define UHD_HAS_LOG_API 1 +# include +# include +#else +# define UHD_HAS_LOG_API 0 +# include +# include +#endif + #include #include @@ -67,6 +79,19 @@ static std::string stringtrim(const std::string &s) [](int c){ return std::isspace(c);} ).base()); } +#if UHD_HAS_LOG_API == 1 +static void uhd_log_handler(const uhd::log::logging_info& info) +{ + // do not print very short U messages, nor those of + // verbosity trace or debug + if (info.verbosity >= uhd::log::info and + stringtrim(info.message).size() != 1) { + etiLog.level(debug) << "UHD Message (" << + (int)info.verbosity << ") " << + info.component << ": " << info.message; + } +} +#else static void uhd_msg_handler(uhd::msg::type_t type, const std::string &msg) { if (type == uhd::msg::warning) { @@ -82,6 +107,7 @@ static void uhd_msg_handler(uhd::msg::type_t type, const std::string &msg) } } } +#endif // UHD_HAS_LOG_API @@ -103,7 +129,17 @@ UHD::UHD(SDRDeviceConfig& config) : MDEBUG("OutputUHD::OutputUHD(device: %s) @ %p\n", device.str().c_str(), this); +#if UHD_HAS_LOG_API == 1 + uhd::log::add_logger("dabmod", uhd_log_handler); + try { + uhd::log::set_console_level(uhd::log::fatal); + } + catch (const uhd::key_error&) { + etiLog.level(warn) << "OutputUHD: Could not set UHD console loglevel"; + } +#else uhd::msg::register_handler(uhd_msg_handler); +#endif uhd::set_thread_priority_safe(); diff --git a/src/output/UHD.h b/src/output/UHD.h index b34455c..0e9911c 100644 --- a/src/output/UHD.h +++ b/src/output/UHD.h @@ -37,7 +37,6 @@ DESCRIPTION: #ifdef HAVE_OUTPUT_UHD -#include #include #include #include -- cgit v1.2.3