Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 23 additions & 7 deletions retinify/include/retinify/logging.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -69,45 +69,61 @@ 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
/// @param message
/// 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
/// @param message
/// 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
/// @param message
/// 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
/// @param message
/// 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
/// @param message
/// 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
48 changes: 33 additions & 15 deletions retinify/src/logging.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// SPDX-License-Identifier: Apache-2.0

#include "retinify/logging.hpp"
#include "retinify/version.hpp"

#include <atomic>
#include <chrono>
Expand All @@ -13,7 +14,7 @@

namespace retinify
{
static inline auto GetLogLevelStorage() noexcept -> std::atomic<LogLevel> &
static auto GetLogLevelStorage() noexcept -> std::atomic<LogLevel> &
{
static std::atomic<LogLevel> storage{LogLevel::INFO};
return storage;
Expand All @@ -29,7 +30,7 @@ void SetLogLevel(LogLevel level) noexcept
GetLogLevelStorage().store(level, std::memory_order_relaxed);
}

static inline auto GetLogLocationStorage() noexcept -> std::atomic<LogLocation> &
static auto GetLogLocationStorage() noexcept -> std::atomic<LogLocation> &
{
static std::atomic<LogLocation> storage{LogLocation::NONE};
return storage;
Expand All @@ -47,9 +48,6 @@ void SetLogLocation(LogLocation location) noexcept

namespace
{
constexpr const char kDefaultLabel[] = "NONE ";
constexpr const char kDefaultMessage[] = " ";

struct LogMetadata
{
const char *label;
Expand All @@ -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};
}
}

Expand All @@ -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);
Expand All @@ -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))
{
Expand Down Expand Up @@ -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
2 changes: 2 additions & 0 deletions retinify/src/mat.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down Expand Up @@ -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);
}

Expand Down
18 changes: 14 additions & 4 deletions retinify/src/pipeline.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
#include "mat.hpp"
#include "session.hpp"
#include "stream.hpp"
#include "summary.hpp"

#include "retinify/retinifyModels.hpp"

Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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);
}

Expand Down Expand Up @@ -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);
}

Expand Down Expand Up @@ -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);
}

Expand Down Expand Up @@ -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);
}

Expand Down Expand Up @@ -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);
}

Expand Down Expand Up @@ -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);
}

Expand Down Expand Up @@ -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);
}

Expand Down
26 changes: 0 additions & 26 deletions retinify/src/summary.cpp

This file was deleted.

11 changes: 0 additions & 11 deletions retinify/src/summary.hpp

This file was deleted.