diff --git a/spa/include/spa/debug/buffer.h b/spa/include/spa/debug/buffer.h index 7ccdd8fa8..df6beaad4 100644 --- a/spa/include/spa/debug/buffer.h +++ b/spa/include/spa/debug/buffer.h @@ -38,14 +38,11 @@ extern "C" { * \{ */ +#include #include #include #include -#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; diff --git a/spa/include/spa/debug/dict.h b/spa/include/spa/debug/dict.h index 3e74dd72b..10498f27c 100644 --- a/spa/include/spa/debug/dict.h +++ b/spa/include/spa/debug/dict.h @@ -34,12 +34,9 @@ extern "C" { * \{ */ +#include #include -#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; diff --git a/spa/include/spa/debug/format.h b/spa/include/spa/debug/format.h index 559dd3d2b..2f2f1ffa4 100644 --- a/spa/include/spa/debug/format.h +++ b/spa/include/spa/debug/format.h @@ -35,6 +35,7 @@ extern "C" { */ #include +#include #include #include #include @@ -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; } diff --git a/spa/include/spa/debug/log.h b/spa/include/spa/debug/log.h new file mode 100644 index 000000000..8311e9546 --- /dev/null +++ b/spa/include/spa/debug/log.h @@ -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 +/** + * \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 */ diff --git a/spa/include/spa/debug/mem.h b/spa/include/spa/debug/mem.h index bd248aa15..4999c00bd 100644 --- a/spa/include/spa/debug/mem.h +++ b/spa/include/spa/debug/mem.h @@ -29,16 +29,14 @@ extern "C" { #endif +#include + /** * \addtogroup spa_debug * \{ */ -#include - -#ifndef spa_debug -#define spa_debug(...) ({ fprintf(stderr, __VA_ARGS__);fputc('\n', stderr); }) -#endif +#include static inline int spa_debug_mem(int indent, const void *data, size_t size) { diff --git a/spa/include/spa/debug/node.h b/spa/include/spa/debug/node.h index e8648e435..6ec14b4fa 100644 --- a/spa/include/spa/debug/node.h +++ b/spa/include/spa/debug/node.h @@ -35,12 +35,9 @@ extern "C" { */ #include +#include #include -#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); diff --git a/spa/include/spa/debug/pod.h b/spa/include/spa/debug/pod.h index 1de32c6a6..1468aab04 100644 --- a/spa/include/spa/debug/pod.h +++ b/spa/include/spa/debug/pod.h @@ -34,15 +34,12 @@ extern "C" { * \{ */ +#include #include #include #include #include -#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)