laforge has submitted this change. ( 
https://gerrit.osmocom.org/c/osmo-trx/+/16665 )

Change subject: uhd: Use DEVDRV log category and support UHD >=3.11 logging 
framework
......................................................................

uhd: Use DEVDRV log category and support UHD >=3.11 logging framework

Change-Id: I36f1ff7d425a2144fb512ff393af02741eb4a3d4
---
M CommonLibs/Logger.h
M Transceiver52M/device/uhd/UHDDevice.cpp
2 files changed, 51 insertions(+), 12 deletions(-)

Approvals:
  Jenkins Builder: Verified
  laforge: Looks good to me, approved



diff --git a/CommonLibs/Logger.h b/CommonLibs/Logger.h
index ab72303..b752e51 100644
--- a/CommonLibs/Logger.h
+++ b/CommonLibs/Logger.h
@@ -58,6 +58,9 @@
 #define LOGLV(category, level) \
        Log(category, level, __BASE_FILE__, __LINE__).get() <<  "[tid=" << 
pthread_self() << "] "

+#define LOGSRC(category, level, file, line) \
+       Log(category, level, file, line).get() <<  "[tid=" << pthread_self() << 
"] "
+
 #define LOGCHAN(chan, category, level) \
        Log(category, LOGL_##level, __BASE_FILE__, __LINE__).get() <<  "[tid=" 
<< pthread_self() << "][chan=" << chan << "] "

diff --git a/Transceiver52M/device/uhd/UHDDevice.cpp 
b/Transceiver52M/device/uhd/UHDDevice.cpp
index 59eb8a7..4a6c233 100644
--- a/Transceiver52M/device/uhd/UHDDevice.cpp
+++ b/Transceiver52M/device/uhd/UHDDevice.cpp
@@ -33,11 +33,12 @@
 #include "config.h"
 #endif

-#ifndef USE_UHD_3_11
+#ifdef USE_UHD_3_11
+#include <uhd/utils/log_add.hpp>
+#include <uhd/utils/thread.hpp>
+#else
 #include <uhd/utils/msg.hpp>
 #include <uhd/utils/thread_priority.hpp>
-#else
-#include <uhd/utils/thread.hpp>
 #endif

 #define USRP_TX_AMPL     0.3
@@ -134,23 +135,52 @@
        return NULL;
 }

-#ifndef USE_UHD_3_11
+#ifdef USE_UHD_3_11
+static void uhd_log_handler(const uhd::log::logging_info &info)
+{
+       int level;
+
+       switch (info.verbosity)
+       {
+       case uhd::log::trace:
+       case uhd::log::debug:
+               level = LOGL_DEBUG;
+               break;
+       case uhd::log::info:
+               level = LOGL_INFO;
+               break;
+       case uhd::log::warning:
+               level = LOGL_NOTICE;
+               break;
+       case uhd::log::error:
+               level = LOGL_ERROR;
+               break;
+       case uhd::log::fatal:
+               level = LOGL_FATAL;
+               break;
+       default:
+               level = LOGL_NOTICE;
+       }
+
+       LOGSRC(DDEVDRV, level, info.file.c_str(), info.line) << "[" << 
info.component << "] " << info.message;
+}
+#else
 /*
     Catch and drop underrun 'U' and overrun 'O' messages from stdout
     since we already report using the logging facility. Direct
     everything else appropriately.
  */
-void uhd_msg_handler(uhd::msg::type_t type, const std::string &msg)
+static void uhd_msg_handler(uhd::msg::type_t type, const std::string &msg)
 {
        switch (type) {
        case uhd::msg::status:
-               LOGC(DDEV, INFO) << msg;
+               LOGC(DDEVDRV, INFO) << msg;
                break;
        case uhd::msg::warning:
-               LOGC(DDEV, WARNING) << msg;
+               LOGC(DDEVDRV, NOTICE) << msg;
                break;
        case uhd::msg::error:
-               LOGC(DDEV, ERROR) << msg;
+               LOGC(DDEVDRV, ERROR) << msg;
                break;
        case uhd::msg::fastpath:
                break;
@@ -418,6 +448,16 @@
 {
        const char *refstr;

+       /* Register msg handler. Different APIs depending on UHD version */
+#ifdef USE_UHD_3_11
+       uhd::log::add_logger("OsmoTRX", &uhd_log_handler);
+       uhd::log::set_log_level(uhd::log::debug);
+       uhd::log::set_console_level(uhd::log::off);
+       uhd::log::set_logger_level("OsmoTRX", uhd::log::debug);
+#else
+       uhd::msg::register_handler(&uhd_msg_handler);
+#endif
+
        // Find UHD devices
        uhd::device_addr_t addr(args);
        uhd::device_addrs_t dev_addrs = uhd::device::find(addr);
@@ -604,10 +644,6 @@
                return false;
        }

-#ifndef USE_UHD_3_11
-       // Register msg handler
-       uhd::msg::register_handler(&uhd_msg_handler);
-#endif
        // Start asynchronous event (underrun check) loop
        async_event_thrd = new Thread();
        async_event_thrd->start((void * (*)(void*))async_event_loop, 
(void*)this);

--
To view, visit https://gerrit.osmocom.org/c/osmo-trx/+/16665
To unsubscribe, or for help writing mail filters, visit 
https://gerrit.osmocom.org/settings

Gerrit-Project: osmo-trx
Gerrit-Branch: master
Gerrit-Change-Id: I36f1ff7d425a2144fb512ff393af02741eb4a3d4
Gerrit-Change-Number: 16665
Gerrit-PatchSet: 5
Gerrit-Owner: pespin <pes...@sysmocom.de>
Gerrit-Reviewer: Jenkins Builder
Gerrit-Reviewer: fixeria <axilira...@gmail.com>
Gerrit-Reviewer: laforge <lafo...@osmocom.org>
Gerrit-Reviewer: pespin <pes...@sysmocom.de>
Gerrit-MessageType: merged

Reply via email to