st/oxr: Add pretty print integration in oxr_sink_logger

This commit is contained in:
Jakob Bornecrantz 2022-04-10 10:16:59 +01:00
parent 03df012e90
commit 179664d6b6
2 changed files with 35 additions and 1 deletions

View file

@ -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)
{

View file

@ -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.
*/