diff --git a/retinify/include/retinify/logging.hpp b/retinify/include/retinify/logging.hpp index 75adc77..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,5 +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 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 7986a41..ba9aa69 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 @@ -13,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; @@ -29,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; @@ -47,9 +48,6 @@ void SetLogLocation(LogLocation location) noexcept namespace { -constexpr const char kDefaultLabel[] = "NONE "; -constexpr const char kDefaultMessage[] = " "; - struct LogMetadata { const char *label; @@ -73,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}; } } @@ -86,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); @@ -105,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)) { @@ -150,29 +147,50 @@ 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); } + +auto LogSoftwareInfo(const std::source_location location) noexcept -> void +{ + 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, 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 609d901..9cdcc38 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" @@ -55,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; @@ -395,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); } @@ -528,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); } @@ -566,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); } @@ -604,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); } @@ -654,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); } @@ -692,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); } @@ -736,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); } 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