From 3b8a450a54059727a04c4f19d50077791338f71c Mon Sep 17 00:00:00 2001 From: yagi Date: Thu, 5 Feb 2026 20:09:43 +0900 Subject: [PATCH 1/2] feat: add logging utility for software summary and remove redundant summary files --- retinify/include/retinify/logging.hpp | 4 ++++ retinify/src/logging.cpp | 14 ++++++++++++++ retinify/src/pipeline.cpp | 1 - retinify/src/summary.cpp | 26 -------------------------- retinify/src/summary.hpp | 11 ----------- 5 files changed, 18 insertions(+), 38 deletions(-) delete mode 100644 retinify/src/summary.cpp delete mode 100644 retinify/src/summary.hpp diff --git a/retinify/include/retinify/logging.hpp b/retinify/include/retinify/logging.hpp index 75adc77..06b89bc 100644 --- a/retinify/include/retinify/logging.hpp +++ b/retinify/include/retinify/logging.hpp @@ -110,4 +110,8 @@ RETINIFY_API void LogError(const char *message, std::source_location location = /// @param location /// The source location of the log call (defaults to the call site) RETINIFY_API void LogFatal(const char *message, std::source_location location = std::source_location::current()) noexcept; + +/// @brief +/// Logs a brief summary of the retinify software, including version and copyright information. +RETINIFY_API void LogSoftwareSummary() noexcept; } // namespace retinify diff --git a/retinify/src/logging.cpp b/retinify/src/logging.cpp index 7986a41..1be8f32 100644 --- a/retinify/src/logging.cpp +++ b/retinify/src/logging.cpp @@ -2,6 +2,7 @@ // SPDX-License-Identifier: Apache-2.0 #include "retinify/logging.hpp" +#include "retinify/version.hpp" #include #include @@ -175,4 +176,17 @@ void LogFatal(const char *message, const std::source_location location) noexcept { Log(LogLevel::FATAL, message, location); } + +void LogSoftwareSummary() noexcept +{ + static std::atomic_flag printed = ATOMIC_FLAG_INIT; + if (printed.test_and_set()) + { + return; + } + + char summaryBuffer[128]; + std::snprintf(summaryBuffer, sizeof(summaryBuffer), "retinify v%s | Real-Time AI Stereo Vision Library | Copyright (c) 2025 Sensui Yagi", Version()); + LogInfo(summaryBuffer); +} } // namespace retinify diff --git a/retinify/src/pipeline.cpp b/retinify/src/pipeline.cpp index 609d901..85a7afa 100644 --- a/retinify/src/pipeline.cpp +++ b/retinify/src/pipeline.cpp @@ -5,7 +5,6 @@ #include "mat.hpp" #include "session.hpp" #include "stream.hpp" -#include "summary.hpp" #include "retinify/retinifyModels.hpp" diff --git a/retinify/src/summary.cpp b/retinify/src/summary.cpp deleted file mode 100644 index d1d68c5..0000000 --- a/retinify/src/summary.cpp +++ /dev/null @@ -1,26 +0,0 @@ -// SPDX-FileCopyrightText: Copyright (c) 2025 Sensui Yagi. All rights reserved. -// SPDX-License-Identifier: Apache-2.0 - -#include "summary.hpp" - -#include "retinify/logging.hpp" -#include "retinify/version.hpp" - -#include -#include - -namespace retinify -{ -void LogSoftwareSummary() noexcept -{ - static std::atomic_flag printed = ATOMIC_FLAG_INIT; - if (printed.test_and_set()) - { - return; - } - - char summaryBuffer[128]; - std::snprintf(summaryBuffer, sizeof(summaryBuffer), "retinify v%s | Real-Time AI Stereo Vision Library | Copyright (c) 2025 Sensui Yagi", Version()); - LogInfo(summaryBuffer); -} -} // namespace retinify diff --git a/retinify/src/summary.hpp b/retinify/src/summary.hpp deleted file mode 100644 index 33b6e82..0000000 --- a/retinify/src/summary.hpp +++ /dev/null @@ -1,11 +0,0 @@ -// SPDX-FileCopyrightText: Copyright (c) 2025 Sensui Yagi. All rights reserved. -// SPDX-License-Identifier: Apache-2.0 - -#pragma once - -namespace retinify -{ -/// @brief -/// Logs a brief summary of the retinify software, including version and copyright information. -void LogSoftwareSummary() noexcept; -} // namespace retinify From a388b801360a743941a2d6307c4296313ba543a2 Mon Sep 17 00:00:00 2001 From: yagi Date: Fri, 6 Feb 2026 11:24:38 +0900 Subject: [PATCH 2/2] feat: update logging functions to use new signature and add stride error logging --- retinify/include/retinify/logging.hpp | 30 ++++++++++++++------- retinify/src/logging.cpp | 38 +++++++++++++++------------ retinify/src/mat.cpp | 2 ++ retinify/src/pipeline.cpp | 17 +++++++++--- 4 files changed, 58 insertions(+), 29 deletions(-) diff --git a/retinify/include/retinify/logging.hpp b/retinify/include/retinify/logging.hpp index 06b89bc..e0dbced 100644 --- a/retinify/include/retinify/logging.hpp +++ b/retinify/include/retinify/logging.hpp @@ -45,7 +45,7 @@ RETINIFY_API auto GetLogLevel() noexcept -> LogLevel; /// Sets the log level /// @param level /// The new log level to apply -RETINIFY_API void SetLogLevel(LogLevel level) noexcept; +RETINIFY_API auto SetLogLevel(LogLevel level) noexcept -> void; /// @brief /// Logging source location options @@ -69,7 +69,7 @@ RETINIFY_API auto GetLogLocation() noexcept -> LogLocation; /// Sets the log location setting /// @param location /// The new log location setting to apply -RETINIFY_API void SetLogLocation(LogLocation location) noexcept; +RETINIFY_API auto SetLogLocation(LogLocation location) noexcept -> void; /// @brief /// Logs a debug message @@ -77,7 +77,7 @@ RETINIFY_API void SetLogLocation(LogLocation location) noexcept; /// The message to log /// @param location /// The source location of the log call (defaults to the call site) -RETINIFY_API void LogDebug(const char *message, std::source_location location = std::source_location::current()) noexcept; +RETINIFY_API auto LogDebug(const char *message, std::source_location location = std::source_location::current()) noexcept -> void; /// @brief /// Logs an informational message @@ -85,7 +85,7 @@ RETINIFY_API void LogDebug(const char *message, std::source_location location = /// The message to log /// @param location /// The source location of the log call (defaults to the call site) -RETINIFY_API void LogInfo(const char *message, std::source_location location = std::source_location::current()) noexcept; +RETINIFY_API auto LogInfo(const char *message, std::source_location location = std::source_location::current()) noexcept -> void; /// @brief /// Logs a warning message @@ -93,7 +93,7 @@ RETINIFY_API void LogInfo(const char *message, std::source_location location = s /// The message to log /// @param location /// The source location of the log call (defaults to the call site) -RETINIFY_API void LogWarn(const char *message, std::source_location location = std::source_location::current()) noexcept; +RETINIFY_API auto LogWarn(const char *message, std::source_location location = std::source_location::current()) noexcept -> void; /// @brief /// Logs an error message @@ -101,7 +101,7 @@ RETINIFY_API void LogWarn(const char *message, std::source_location location = s /// The message to log /// @param location /// The source location of the log call (defaults to the call site) -RETINIFY_API void LogError(const char *message, std::source_location location = std::source_location::current()) noexcept; +RETINIFY_API auto LogError(const char *message, std::source_location location = std::source_location::current()) noexcept -> void; /// @brief /// Logs a fatal error message @@ -109,9 +109,21 @@ RETINIFY_API void LogError(const char *message, std::source_location location = /// The message to log /// @param location /// The source location of the log call (defaults to the call site) -RETINIFY_API void LogFatal(const char *message, std::source_location location = std::source_location::current()) noexcept; +RETINIFY_API auto LogFatal(const char *message, std::source_location location = std::source_location::current()) noexcept -> void; /// @brief -/// Logs a brief summary of the retinify software, including version and copyright information. -RETINIFY_API void LogSoftwareSummary() noexcept; +/// Logs basic information about the retinify library +/// @param location +/// The source location of the log call (defaults to the call site) +RETINIFY_API auto LogSoftwareInfo(std::source_location location = std::source_location::current()) noexcept -> void; + +/// @brief +/// Logs an error indicating that the provided stride is smaller than the required stride +/// @param providedStride +/// The provided stride value (in bytes) +/// @param requiredStride +/// The required stride value (in bytes) +/// @param location +/// The source location of the log call (defaults to the call site) +RETINIFY_API auto LogStrideError(std::size_t providedStride, std::size_t requiredStride, std::source_location location = std::source_location::current()) noexcept -> void; } // namespace retinify diff --git a/retinify/src/logging.cpp b/retinify/src/logging.cpp index 1be8f32..ba9aa69 100644 --- a/retinify/src/logging.cpp +++ b/retinify/src/logging.cpp @@ -14,7 +14,7 @@ namespace retinify { -static inline auto GetLogLevelStorage() noexcept -> std::atomic & +static auto GetLogLevelStorage() noexcept -> std::atomic & { static std::atomic storage{LogLevel::INFO}; return storage; @@ -30,7 +30,7 @@ void SetLogLevel(LogLevel level) noexcept GetLogLevelStorage().store(level, std::memory_order_relaxed); } -static inline auto GetLogLocationStorage() noexcept -> std::atomic & +static auto GetLogLocationStorage() noexcept -> std::atomic & { static std::atomic storage{LogLocation::NONE}; return storage; @@ -48,9 +48,6 @@ void SetLogLocation(LogLocation location) noexcept namespace { -constexpr const char kDefaultLabel[] = "NONE "; -constexpr const char kDefaultMessage[] = " "; - struct LogMetadata { const char *label; @@ -74,7 +71,7 @@ struct LogMetadata return {"FATAL", "\033[31;1m", &std::cerr}; case LogLevel::OFF: default: - return {kDefaultLabel, "\033[0m", &std::cerr}; + return {"NONE ", "\033[0m", &std::cerr}; } } @@ -87,13 +84,13 @@ struct LogMetadata { if (message == nullptr || std::strlen(message) == 0) { - return kDefaultMessage; + return " "; } return message; } -static inline auto GetCurrentTime() -> std::string +[[nodiscard]] auto GetCurrentTime() -> std::string { const std::chrono::system_clock::time_point currentTimePoint = std::chrono::system_clock::now(); const std::time_t currentTimeT = std::chrono::system_clock::to_time_t(currentTimePoint); @@ -106,9 +103,8 @@ static inline auto GetCurrentTime() -> std::string timeStream << std::put_time(&localTimeStruct, "%F %T"); return timeStream.str(); } -} // namespace -static inline void Log(LogLevel level, const char *message, std::source_location location) noexcept +inline auto Log(LogLevel level, const char *message, std::source_location location) noexcept -> void { if (!ShouldLog(level)) { @@ -151,33 +147,34 @@ static inline void Log(LogLevel level, const char *message, std::source_location // do nothing } } +} // namespace -void LogDebug(const char *message, const std::source_location location) noexcept +auto LogDebug(const char *message, const std::source_location location) noexcept -> void { Log(LogLevel::DEBUG, message, location); } -void LogInfo(const char *message, const std::source_location location) noexcept +auto LogInfo(const char *message, const std::source_location location) noexcept -> void { Log(LogLevel::INFO, message, location); } -void LogWarn(const char *message, const std::source_location location) noexcept +auto LogWarn(const char *message, const std::source_location location) noexcept -> void { Log(LogLevel::WARN, message, location); } -void LogError(const char *message, const std::source_location location) noexcept +auto LogError(const char *message, const std::source_location location) noexcept -> void { Log(LogLevel::ERROR, message, location); } -void LogFatal(const char *message, const std::source_location location) noexcept +auto LogFatal(const char *message, const std::source_location location) noexcept -> void { Log(LogLevel::FATAL, message, location); } -void LogSoftwareSummary() noexcept +auto LogSoftwareInfo(const std::source_location location) noexcept -> void { static std::atomic_flag printed = ATOMIC_FLAG_INIT; if (printed.test_and_set()) @@ -187,6 +184,13 @@ void LogSoftwareSummary() noexcept char summaryBuffer[128]; std::snprintf(summaryBuffer, sizeof(summaryBuffer), "retinify v%s | Real-Time AI Stereo Vision Library | Copyright (c) 2025 Sensui Yagi", Version()); - LogInfo(summaryBuffer); + LogInfo(summaryBuffer, location); +} + +auto LogStrideError(std::size_t providedStride, std::size_t requiredStride, const std::source_location location) noexcept -> void +{ + char messageBuffer[256]; + std::snprintf(messageBuffer, sizeof(messageBuffer), "Provided stride (%zu bytes) is smaller than the required stride (%zu bytes).", providedStride, requiredStride); + LogError(messageBuffer, location); } } // namespace retinify diff --git a/retinify/src/mat.cpp b/retinify/src/mat.cpp index b8c4ab8..16dff5e 100644 --- a/retinify/src/mat.cpp +++ b/retinify/src/mat.cpp @@ -207,6 +207,7 @@ auto Mat::Upload(const void *hostData, std::size_t hostStride, Stream &stream) c if (hostStride < deviceColumnsInBytes_) { LogError("Host stride is less than device columns in bytes."); + LogStrideError(hostStride, deviceColumnsInBytes_); return Status(StatusCategory::USER, StatusCode::INVALID_ARGUMENT); } @@ -264,6 +265,7 @@ auto Mat::Download(void *hostData, std::size_t hostStride, Stream &stream) const if (hostStride < deviceColumnsInBytes_) { LogError("Host stride is less than device columns in bytes."); + LogStrideError(hostStride, deviceColumnsInBytes_); return Status(StatusCategory::USER, StatusCode::INVALID_ARGUMENT); } diff --git a/retinify/src/pipeline.cpp b/retinify/src/pipeline.cpp index 85a7afa..9cdcc38 100644 --- a/retinify/src/pipeline.cpp +++ b/retinify/src/pipeline.cpp @@ -54,7 +54,7 @@ class Pipeline::Impl auto Initialize(std::uint32_t imageWidth, std::uint32_t imageHeight, PixelFormat pixelFormat, DepthMode depthMode, const CalibrationParameters &calibrationParameters) noexcept -> Status { - LogSoftwareSummary(); + LogSoftwareInfo(); Status status; @@ -394,15 +394,19 @@ class Pipeline::Impl return Status(StatusCategory::USER, StatusCode::INVALID_ARGUMENT); } - if (leftImageStride < imageWidth_ * imageChannels_ * sizeof(std::uint8_t)) + const std::size_t requiredStride = imageWidth_ * imageChannels_ * sizeof(std::uint8_t); + + if (leftImageStride < requiredStride) { LogError("Left image stride is too small."); + LogStrideError(leftImageStride, requiredStride); return Status(StatusCategory::USER, StatusCode::INVALID_ARGUMENT); } - if (rightImageStride < imageWidth_ * imageChannels_ * sizeof(std::uint8_t)) + if (rightImageStride < requiredStride) { LogError("Right image stride is too small."); + LogStrideError(rightImageStride, requiredStride); return Status(StatusCategory::USER, StatusCode::INVALID_ARGUMENT); } @@ -527,6 +531,7 @@ class Pipeline::Impl if (leftImageStride < requiredStride) { LogError("Rectified left image stride is too small."); + LogStrideError(leftImageStride, requiredStride); return Status(StatusCategory::USER, StatusCode::INVALID_ARGUMENT); } @@ -565,6 +570,7 @@ class Pipeline::Impl if (rightImageStride < requiredStride) { LogError("Rectified right image stride is too small."); + LogStrideError(rightImageStride, requiredStride); return Status(StatusCategory::USER, StatusCode::INVALID_ARGUMENT); } @@ -603,12 +609,14 @@ class Pipeline::Impl if (leftImageStride < requiredStride) { LogError("Rectified left image stride is too small."); + LogStrideError(leftImageStride, requiredStride); return Status(StatusCategory::USER, StatusCode::INVALID_ARGUMENT); } if (rightImageStride < requiredStride) { LogError("Rectified right image stride is too small."); + LogStrideError(rightImageStride, requiredStride); return Status(StatusCategory::USER, StatusCode::INVALID_ARGUMENT); } @@ -653,6 +661,7 @@ class Pipeline::Impl if (disparityStride < requiredStride) { LogError("Disparity stride is too small."); + LogStrideError(disparityStride, requiredStride); return Status(StatusCategory::USER, StatusCode::INVALID_ARGUMENT); } @@ -691,6 +700,7 @@ class Pipeline::Impl if (depthStride < requiredStride) { LogError("Depth stride is too small."); + LogStrideError(depthStride, requiredStride); return Status(StatusCategory::USER, StatusCode::INVALID_ARGUMENT); } @@ -735,6 +745,7 @@ class Pipeline::Impl if (pointCloudStride < requiredStride) { LogError("Point cloud stride is too small."); + LogStrideError(pointCloudStride, requiredStride); return Status(StatusCategory::USER, StatusCode::INVALID_ARGUMENT); }