spa: move debug log defines to one place

Use spa_debug to debug formats.
Make debug go to stdout by default.
This commit is contained in:
Wim Taymans 2022-02-07 17:00:38 +01:00
parent 136989eaa6
commit a16cd95593
7 changed files with 82 additions and 42 deletions

View file

@ -38,14 +38,11 @@ extern "C" {
* \{
*/
#include <spa/debug/log.h>
#include <spa/debug/mem.h>
#include <spa/debug/types.h>
#include <spa/buffer/type-info.h>
#ifndef spa_debug
#define spa_debug(...) ({ fprintf(stderr, __VA_ARGS__);fputc('\n', stderr); })
#endif
static inline int spa_debug_buffer(int indent, const struct spa_buffer *buffer)
{
uint32_t i;

View file

@ -34,12 +34,9 @@ extern "C" {
* \{
*/
#include <spa/debug/log.h>
#include <spa/utils/dict.h>
#ifndef spa_debug
#define spa_debug(...) ({ fprintf(stderr, __VA_ARGS__);fputc('\n', stderr); })
#endif
static inline int spa_debug_dict(int indent, const struct spa_dict *dict)
{
const struct spa_dict_item *item;

View file

@ -35,6 +35,7 @@ extern "C" {
*/
#include <spa/pod/parser.h>
#include <spa/debug/log.h>
#include <spa/debug/types.h>
#include <spa/param/type-info.h>
#include <spa/param/format-utils.h>
@ -45,7 +46,7 @@ spa_debug_format_value(const struct spa_type_info *info,
{
switch (type) {
case SPA_TYPE_Bool:
fprintf(stderr, "%s", *(int32_t *) body ? "true" : "false");
spa_debugn("%s", *(int32_t *) body ? "true" : "false");
break;
case SPA_TYPE_Id:
{
@ -55,41 +56,41 @@ spa_debug_format_value(const struct spa_type_info *info,
snprintf(tmp, sizeof(tmp), "%d", *(int32_t*)body);
str = tmp;
}
fprintf(stderr, "%s", str);
spa_debugn("%s", str);
break;
}
case SPA_TYPE_Int:
fprintf(stderr, "%d", *(int32_t *) body);
spa_debugn("%d", *(int32_t *) body);
break;
case SPA_TYPE_Long:
fprintf(stderr, "%" PRIi64, *(int64_t *) body);
spa_debugn("%" PRIi64, *(int64_t *) body);
break;
case SPA_TYPE_Float:
fprintf(stderr, "%f", *(float *) body);
spa_debugn("%f", *(float *) body);
break;
case SPA_TYPE_Double:
fprintf(stderr, "%g", *(double *) body);
spa_debugn("%g", *(double *) body);
break;
case SPA_TYPE_String:
fprintf(stderr, "%s", (char *) body);
spa_debugn("%s", (char *) body);
break;
case SPA_TYPE_Rectangle:
{
struct spa_rectangle *r = (struct spa_rectangle *)body;
fprintf(stderr, "%" PRIu32 "x%" PRIu32, r->width, r->height);
spa_debugn("%" PRIu32 "x%" PRIu32, r->width, r->height);
break;
}
case SPA_TYPE_Fraction:
{
struct spa_fraction *f = (struct spa_fraction *)body;
fprintf(stderr, "%" PRIu32 "/%" PRIu32, f->num, f->denom);
spa_debugn("%" PRIu32 "/%" PRIu32, f->num, f->denom);
break;
}
case SPA_TYPE_Bitmap:
fprintf(stderr, "Bitmap");
spa_debugn("Bitmap");
break;
case SPA_TYPE_Bytes:
fprintf(stderr, "Bytes");
spa_debugn("Bytes");
break;
case SPA_TYPE_Array:
{
@ -97,17 +98,17 @@ spa_debug_format_value(const struct spa_type_info *info,
struct spa_pod_array_body *b = (struct spa_pod_array_body *)body;
int i = 0;
info = info && info->values ? info->values : info;
fprintf(stderr, "< ");
spa_debugn("< ");
SPA_POD_ARRAY_BODY_FOREACH(b, size, p) {
if (i++ > 0)
fprintf(stderr, ", ");
spa_debugn(", ");
spa_debug_format_value(info, b->child.type, p, b->child.size);
}
fprintf(stderr, " >");
spa_debugn(" >");
break;
}
default:
fprintf(stderr, "INVALID type %d", type);
spa_debugn("INVALID type %d", type);
break;
}
return 0;
@ -133,7 +134,7 @@ static inline int spa_debug_format(int indent,
media_type = spa_debug_type_find_name(spa_type_media_type, mtype);
media_subtype = spa_debug_type_find_name(spa_type_media_subtype, mstype);
fprintf(stderr, "%*s %s/%s\n", indent, "",
spa_debug("%*s %s/%s", indent, "",
media_type ? spa_debug_type_short_name(media_type) : "unknown",
media_subtype ? spa_debug_type_short_name(media_subtype) : "unknown");
@ -160,7 +161,7 @@ static inline int spa_debug_format(int indent,
ti = spa_debug_type_find(info, prop->key);
key = ti ? ti->name : NULL;
fprintf(stderr, "%*s %16s : (%s) ", indent, "",
spa_debugn("%*s %16s : (%s) ", indent, "",
key ? spa_debug_type_short_name(key) : "unknown",
spa_debug_type_short_name(spa_types[type].name));
@ -185,17 +186,17 @@ static inline int spa_debug_format(int indent,
break;
}
fprintf(stderr, "%s", ssep);
spa_debugn("%s", ssep);
for (i = 1; i < n_vals; i++) {
vals = SPA_PTROFF(vals, size, void);
if (i > 1)
fprintf(stderr, "%s", sep);
spa_debugn("%s", sep);
spa_debug_format_value(ti ? ti->values : NULL, type, vals, size);
}
fprintf(stderr, "%s", esep);
spa_debugn("%s", esep);
}
fprintf(stderr, "\n");
spa_debugn("\n");
}
return 0;
}

View file

@ -0,0 +1,53 @@
/* Simple Plugin API
*
* Copyright © 2022 Wim Taymans
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice (including the next
* paragraph) shall be included in all copies or substantial portions of the
* Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
*/
#ifndef SPA_DEBUG_LOG_H
#define SPA_DEBUG_LOG_H
#ifdef __cplusplus
extern "C" {
#endif
#include <stdio.h>
/**
* \addtogroup spa_debug
* \{
*/
#ifndef spa_debug
#define spa_debug(fmt,...) ({ printf(fmt"\n", ## __VA_ARGS__); })
#endif
#ifndef spa_debugn
#define spa_debugn(fmt,...) ({ printf(fmt, ## __VA_ARGS__); })
#endif
/**
* \}
*/
#ifdef __cplusplus
} /* extern "C" */
#endif
#endif /* SPA_DEBUG_LOGH */

View file

@ -29,16 +29,14 @@
extern "C" {
#endif
#include <inttypes.h>
/**
* \addtogroup spa_debug
* \{
*/
#include <spa/utils/dict.h>
#ifndef spa_debug
#define spa_debug(...) ({ fprintf(stderr, __VA_ARGS__);fputc('\n', stderr); })
#endif
#include <spa/debug/log.h>
static inline int spa_debug_mem(int indent, const void *data, size_t size)
{

View file

@ -35,12 +35,9 @@ extern "C" {
*/
#include <spa/node/node.h>
#include <spa/debug/log.h>
#include <spa/debug/dict.h>
#ifndef spa_debug
#define spa_debug(...) ({ fprintf(stderr, __VA_ARGS__);fputc('\n', stderr); })
#endif
static inline int spa_debug_port_info(int indent, const struct spa_port_info *info)
{
spa_debug("%*s" "struct spa_port_info %p:", indent, "", info);

View file

@ -34,15 +34,12 @@ extern "C" {
* \{
*/
#include <spa/debug/log.h>
#include <spa/debug/mem.h>
#include <spa/debug/types.h>
#include <spa/pod/pod.h>
#include <spa/pod/iter.h>
#ifndef spa_debug
#define spa_debug(...) ({ fprintf(stderr, __VA_ARGS__);fputc('\n', stderr); })
#endif
static inline int
spa_debug_pod_value(int indent, const struct spa_type_info *info,
uint32_t type, void *body, uint32_t size)