From ba5296e203ea906484977633afd41bbd0c8d22c4 Mon Sep 17 00:00:00 2001 From: Nicholas Corgan Date: Mon, 26 Dec 2022 06:18:41 -0600 Subject: [PATCH] Logger: added getLogLevel() for symmetry * Bumped ABI to 0.8.3 --- include/SoapySDR/Logger.h | 6 ++++++ include/SoapySDR/Logger.hpp | 6 ++++++ include/SoapySDR/Version.h | 11 ++++++++--- lib/Logger.cpp | 6 ++++++ lib/LoggerC.cpp | 6 ++++++ luajit/Lib.lua | 2 ++ luajit/Logger.lua | 8 +++++++- luajit/tests/TestLogger.lua | 10 ++++++---- swig/csharp/assembly/Logger.cs | 3 +-- swig/csharp/swig/Logger.i | 5 +++++ swig/csharp/tests/TestLogger.cs | 4 ++-- swig/soapy_common.i | 4 ++++ 12 files changed, 59 insertions(+), 12 deletions(-) diff --git a/include/SoapySDR/Logger.h b/include/SoapySDR/Logger.h index 47ff7bd0..202760d0 100644 --- a/include/SoapySDR/Logger.h +++ b/include/SoapySDR/Logger.h @@ -7,6 +7,7 @@ /// /// \copyright /// Copyright (c) 2014-2015 Josh Blum +/// 2022 Nicholas Corgan /// SPDX-License-Identifier: BSL-1.0 /// @@ -92,6 +93,11 @@ SOAPY_SDR_API void SoapySDR_registerLogHandler(const SoapySDRLogHandler handler) */ SOAPY_SDR_API void SoapySDR_setLogLevel(const SoapySDRLogLevel logLevel); +/*! + * Get the log level threshold. + */ +SOAPY_SDR_API SoapySDRLogLevel SoapySDR_getLogLevel(void); + #ifdef __cplusplus } #endif diff --git a/include/SoapySDR/Logger.hpp b/include/SoapySDR/Logger.hpp index d52b4a66..8811e057 100644 --- a/include/SoapySDR/Logger.hpp +++ b/include/SoapySDR/Logger.hpp @@ -7,6 +7,7 @@ /// /// \copyright /// Copyright (c) 2014-2015 Josh Blum +/// 2022 Nicholas Corgan /// SPDX-License-Identifier: BSL-1.0 /// @@ -66,4 +67,9 @@ SOAPY_SDR_API void registerLogHandler(const LogHandler &handler); */ SOAPY_SDR_API void setLogLevel(const LogLevel logLevel); +/*! + * Get the log level threshold. + */ +SOAPY_SDR_API LogLevel getLogLevel(void); + } diff --git a/include/SoapySDR/Version.h b/include/SoapySDR/Version.h index 9cc65691..675519ac 100644 --- a/include/SoapySDR/Version.h +++ b/include/SoapySDR/Version.h @@ -6,7 +6,7 @@ /// \copyright /// Copyright (c) 2014-2021 Josh Blum /// Copyright (c) 2016-2016 Bastille Networks -/// 2021 Nicholas Corgan +/// 2021-2022 Nicholas Corgan /// SPDX-License-Identifier: BSL-1.0 /// @@ -36,7 +36,7 @@ * And extra is empty for releases but set on development branches. * The ABI should remain constant across patch releases of the library. */ -#define SOAPY_SDR_ABI_VERSION "0.8-2" +#define SOAPY_SDR_ABI_VERSION "0.8-3" /*! * Compatibility define for GPIO access API with masks @@ -164,10 +164,15 @@ #define SOAPY_SDR_API_HAS_PARALLEL_STRING_MAKE /*! - * Compatiblity define for querying information for specific settings + * Compatibility define for querying information for specific settings */ #define SOAPY_SDR_API_HAS_GET_SPECIFIC_SETTING_INFO +/*! + * Compatibility define for getting log level + */ +#define SOAPY_SDR_API_HAS_GET_LOG_LEVEL + #ifdef __cplusplus extern "C" { #endif diff --git a/lib/Logger.cpp b/lib/Logger.cpp index 0350a20b..e794d100 100644 --- a/lib/Logger.cpp +++ b/lib/Logger.cpp @@ -1,4 +1,5 @@ // Copyright (c) 2014-2015 Josh Blum +// 2022 Nicholas Corgan // SPDX-License-Identifier: BSL-1.0 #include @@ -22,3 +23,8 @@ void SoapySDR::setLogLevel(const LogLevel logLevel) { SoapySDR_setLogLevel(logLevel); } + +SoapySDR::LogLevel SoapySDR::getLogLevel(void) +{ + return SoapySDR_getLogLevel(); +} diff --git a/lib/LoggerC.cpp b/lib/LoggerC.cpp index d256b2a5..67a6cf40 100644 --- a/lib/LoggerC.cpp +++ b/lib/LoggerC.cpp @@ -1,4 +1,5 @@ // Copyright (c) 2014-2021 Josh Blum +// 2022 Nicholas Corgan // SPDX-License-Identifier: BSL-1.0 #include @@ -106,4 +107,9 @@ void SoapySDR_setLogLevel(const SoapySDRLogLevel logLevel) registeredLogLevel = logLevel; } +SoapySDRLogLevel SoapySDR_getLogLevel(void) +{ + return registeredLogLevel; +} + } diff --git a/luajit/Lib.lua b/luajit/Lib.lua index 2dd8e65a..e9939799 100644 --- a/luajit/Lib.lua +++ b/luajit/Lib.lua @@ -105,6 +105,8 @@ if not __internal.SoapySDR then void SoapySDR_setLogLevel(const SoapySDRLogLevel logLevel); + SoapySDRLogLevel SoapySDR_getLogLevel(); + /* SoapySDR/Version.h */ const char *SoapySDR_getAPIVersion(void); diff --git a/luajit/Logger.lua b/luajit/Logger.lua index 07130b3a..3a0e63ad 100644 --- a/luajit/Logger.lua +++ b/luajit/Logger.lua @@ -1,4 +1,4 @@ --- Copyright (c) 2021 Nicholas Corgan +-- Copyright (c) 2021-2022 Nicholas Corgan -- SPDX-License-Identifier: BSL-1.0 --- @@ -81,6 +81,12 @@ local Logger = -- @tparam Level logLevel a possible logging level setLevel = function(logLevel) lib.SoapySDR_setLogLevel(logLevel) + end, + + --- + -- Get the log level threshold + getLevel = function() + return tonumber(lib.SoapySDR_getLogLevel()) end } diff --git a/luajit/tests/TestLogger.lua b/luajit/tests/TestLogger.lua index bb1b337d..ba846296 100644 --- a/luajit/tests/TestLogger.lua +++ b/luajit/tests/TestLogger.lua @@ -1,4 +1,4 @@ --- Copyright (c) 2021 Nicholas Corgan +-- Copyright (c) 2021-2022 Nicholas Corgan -- SPDX-License-Identifier: BSL-1.0 SoapySDR = require("SoapySDR") @@ -16,6 +16,7 @@ function testLogger() SoapySDR.Logger.registerHandler(logFunction) SoapySDR.Logger.setLevel(SoapySDR.Logger.Level.INFO) + luaunit.assertEquals(SoapySDR.Logger.getLevel(), SoapySDR.Logger.Level.INFO) SoapySDR.Logger.log(SoapySDR.Logger.Level.WARNING, "Warning") SoapySDR.Logger.log(SoapySDR.Logger.Level.ERROR, "Error") @@ -45,14 +46,15 @@ function testErrorDuringLog() end SoapySDR.Logger.registerHandler(errorLogFunction) - SoapySDR.Logger.setLevel(SoapySDR.Logger.Level.INFO) + SoapySDR.Logger.setLevel(SoapySDR.Logger.Level.NOTICE) + luaunit.assertEquals(SoapySDR.Logger.getLevel(), SoapySDR.Logger.Level.NOTICE) - luaunit.assertFalse(pcall(SoapySDR.Logger.log, SoapySDR.Logger.Level.INFO, "Info")) + luaunit.assertFalse(pcall(SoapySDR.Logger.log, SoapySDR.Logger.Level.NOTICE, "Notice")) tmpFile:seek("set") local logContents = tmpFile:read("*a") - luaunit.assertEquals(logContents, "Info\n") + luaunit.assertEquals(logContents, "Notice\n") end local runner = luaunit.LuaUnit.new() diff --git a/swig/csharp/assembly/Logger.cs b/swig/csharp/assembly/Logger.cs index 960dda61..dbe5a901 100644 --- a/swig/csharp/assembly/Logger.cs +++ b/swig/csharp/assembly/Logger.cs @@ -31,13 +31,12 @@ public CSharpLogHandler() : base() public override void Handle(LogLevel logLevel, string message) => Delegate?.Invoke(logLevel, message); } - // TODO: add read after getter implemented - /// /// The log level threshold. Messages with lower priorities are dropped. /// public static LogLevel LogLevel { + get => LogHandlerBase.GetLogLevel(); set => LogHandlerBase.SetLogLevel(value); } diff --git a/swig/csharp/swig/Logger.i b/swig/csharp/swig/Logger.i index e99e3dc2..e0f77516 100644 --- a/swig/csharp/swig/Logger.i +++ b/swig/csharp/swig/Logger.i @@ -42,6 +42,11 @@ SoapySDR::log((SoapySDR::LogLevel)logLevel, message); } + static SoapySDR::CSharp::LogLevel GetLogLevel() + { + return SoapySDR::CSharp::LogLevel(SoapySDR::getLogLevel()); + } + static void SetLogLevel(const SoapySDR::CSharp::LogLevel logLevel) { SoapySDR::setLogLevel((SoapySDR::LogLevel)logLevel); diff --git a/swig/csharp/tests/TestLogger.cs b/swig/csharp/tests/TestLogger.cs index 3652e6c6..a26d05ca 100644 --- a/swig/csharp/tests/TestLogger.cs +++ b/swig/csharp/tests/TestLogger.cs @@ -63,8 +63,8 @@ private static string GetExpectedLoggerOutput() [Test] public void Test_Logger() { - // TODO: test value after getter implemented Pothosware.SoapySDR.Logger.LogLevel = Pothosware.SoapySDR.LogLevel.Notice; + Assert.AreEqual(Pothosware.SoapySDR.LogLevel.Notice, Pothosware.SoapySDR.Logger.LogLevel); // Before doing anything, the standard stdio logger should be used. Unfortunately, // we can't intercept and programmatically check the output. @@ -96,8 +96,8 @@ public void Test_Logger() [Test] public void Test_LoggerException() { - // TODO: test value after getter implemented Pothosware.SoapySDR.Logger.LogLevel = Pothosware.SoapySDR.LogLevel.Notice; + Assert.AreEqual(Pothosware.SoapySDR.LogLevel.Notice, Pothosware.SoapySDR.Logger.LogLevel); // Make sure exceptions from the C# callback given to C++ propagate up // to C# properly. diff --git a/swig/soapy_common.i b/swig/soapy_common.i index e58b1111..9250d32a 100644 --- a/swig/soapy_common.i +++ b/swig/soapy_common.i @@ -21,12 +21,16 @@ // SoapySDR/Errors.h %ignore SoapySDR_errToStr; +// SoapySDR/Formats.h +%ignore SoapySDR_formatToSize; + // SoapySDR/Logger.h %ignore SoapySDR_log; %ignore SoapySDR_vlogf; %ignore SoapySDR_logf; %ignore SoapySDRLogHandler; %ignore SoapySDR_registerLogHandler; +%ignore SoapySDR_getLogLevel; %ignore SoapySDR_setLogLevel; // SoapySDR/Logger.hpp