From 179664d6b6430300b07d16ff37b4a8937c65b8bb Mon Sep 17 00:00:00 2001 From: Jakob Bornecrantz Date: Sun, 10 Apr 2022 10:16:59 +0100 Subject: [PATCH] st/oxr: Add pretty print integration in oxr_sink_logger --- src/xrt/state_trackers/oxr/oxr_logger.c | 17 ++++++++++++++++- src/xrt/state_trackers/oxr/oxr_logger.h | 19 +++++++++++++++++++ 2 files changed, 35 insertions(+), 1 deletion(-) diff --git a/src/xrt/state_trackers/oxr/oxr_logger.c b/src/xrt/state_trackers/oxr/oxr_logger.c index a6514a6ea..f62968eec 100644 --- a/src/xrt/state_trackers/oxr/oxr_logger.c +++ b/src/xrt/state_trackers/oxr/oxr_logger.c @@ -1,4 +1,4 @@ -// Copyright 2018-2020, Collabora, Ltd. +// Copyright 2018-2022, Collabora, Ltd. // SPDX-License-Identifier: BSL-1.0 /*! * @file @@ -224,6 +224,21 @@ oxr_slog(struct oxr_sink_logger *slog, const char *fmt, ...) slog->length += ret; } +void +oxr_slog_add_array(struct oxr_sink_logger *slog, const char *str, size_t size) +{ + if (size == 0) { + return; + } + + size_t size_with_null = size + 1; + oxr_slog_ensure(slog, size_with_null); + + memcpy(slog->store + slog->length, str, size); + + slog->length += size; +} + void oxr_slog_abort(struct oxr_sink_logger *slog) { diff --git a/src/xrt/state_trackers/oxr/oxr_logger.h b/src/xrt/state_trackers/oxr/oxr_logger.h index aebdb4deb..9ded6f8d9 100644 --- a/src/xrt/state_trackers/oxr/oxr_logger.h +++ b/src/xrt/state_trackers/oxr/oxr_logger.h @@ -9,6 +9,9 @@ #pragma once +#include "util/u_pretty_print.h" + + #ifdef __cplusplus extern "C" { #endif @@ -94,6 +97,22 @@ struct oxr_sink_logger void oxr_slog(struct oxr_sink_logger *slog, const char *fmt, ...) XRT_PRINTF_FORMAT(2, 3); +/*! + * Add the string to the slog struct. + */ +void +oxr_slog_add_array(struct oxr_sink_logger *slog, const char *str, size_t size); + +/*! + * Get a pretty print delegate from a @ref oxr_sink_logger. + */ +static inline u_pp_delegate_t +oxr_slog_dg(struct oxr_sink_logger *slog) +{ + u_pp_delegate_t dg = {(void *)slog, (u_pp_delegate_func_t)oxr_slog_add_array}; + return dg; +} + /*! * Abort logging, frees all internal data. */