+ +
2da5fe7 OpenAVX v0.2.0 - High-performance open-standard IP audio and video transport suite
saifmukhtar · 2026-11-24
main
| 1 | /* Simple Plugin API */ |
| 2 | /* SPDX-FileCopyrightText: Copyright © 2018 Wim Taymans */ |
| 3 | /* SPDX-License-Identifier: MIT */ |
| 4 | |
| 5 | #ifndef SPA_LOG_IMPL_H |
| 6 | #define SPA_LOG_IMPL_H |
| 7 | |
| 8 | #include <stdio.h> |
| 9 | |
| 10 | #include <spa/utils/type.h> |
| 11 | #include <spa/support/log.h> |
| 12 | |
| 13 | #ifdef __cplusplus |
| 14 | extern "C" { |
| 15 | #endif |
| 16 | |
| 17 | /** |
| 18 | * \addtogroup spa_log |
| 19 | * \{ |
| 20 | */ |
| 21 | |
| 22 | static inline SPA_PRINTF_FUNC(7, 0) void spa_log_impl_logtv(void *object SPA_UNUSED, |
| 23 | enum spa_log_level level, |
| 24 | const struct spa_log_topic *topic, |
| 25 | const char *file, |
| 26 | int line, |
| 27 | const char *func, |
| 28 | const char *fmt, |
| 29 | va_list args) |
| 30 | { |
| 31 | static const char * const levels[] = { "-", "E", "W", "I", "D", "T" }; |
| 32 | |
| 33 | const char *basename = strrchr(file, '/'); |
| 34 | char text[512], location[1024]; |
| 35 | char topicstr[32] = {0}; |
| 36 | |
| 37 | if (basename) |
| 38 | basename += 1; /* skip '/' */ |
| 39 | else |
| 40 | basename = file; /* use whole string if no '/' is found */ |
| 41 | |
| 42 | if (topic && topic->topic) |
| 43 | snprintf(topicstr, sizeof(topicstr), " %s ", topic->topic); |
| 44 | vsnprintf(text, sizeof(text), fmt, args); |
| 45 | snprintf(location, sizeof(location), "[%s]%s[%s:%i %s()] %s\n", |
| 46 | levels[level], |
| 47 | topicstr, |
| 48 | basename, line, func, text); |
| 49 | fputs(location, stderr); |
| 50 | } |
| 51 | |
| 52 | static inline SPA_PRINTF_FUNC(7,8) void spa_log_impl_logt(void *object, |
| 53 | enum spa_log_level level, |
| 54 | const struct spa_log_topic *topic, |
| 55 | const char *file, |
| 56 | int line, |
| 57 | const char *func, |
| 58 | const char *fmt, ...) |
| 59 | { |
| 60 | va_list args; |
| 61 | va_start(args, fmt); |
| 62 | spa_log_impl_logtv(object, level, topic, file, line, func, fmt, args); |
| 63 | va_end(args); |
| 64 | } |
| 65 | |
| 66 | static inline SPA_PRINTF_FUNC(6, 0) void spa_log_impl_logv(void *object, |
| 67 | enum spa_log_level level, |
| 68 | const char *file, |
| 69 | int line, |
| 70 | const char *func, |
| 71 | const char *fmt, |
| 72 | va_list args) |
| 73 | { |
| 74 | |
| 75 | spa_log_impl_logtv(object, level, NULL, file, line, func, fmt, args); |
| 76 | } |
| 77 | |
| 78 | static inline SPA_PRINTF_FUNC(6,7) void spa_log_impl_log(void *object, |
| 79 | enum spa_log_level level, |
| 80 | const char *file, |
| 81 | int line, |
| 82 | const char *func, |
| 83 | const char *fmt, ...) |
| 84 | { |
| 85 | va_list args; |
| 86 | va_start(args, fmt); |
| 87 | spa_log_impl_logv(object, level, file, line, func, fmt, args); |
| 88 | va_end(args); |
| 89 | } |
| 90 | |
| 91 | static inline void spa_log_impl_topic_init(void *object SPA_UNUSED, struct spa_log_topic *topic SPA_UNUSED) |
| 92 | { |
| 93 | /* noop */ |
| 94 | } |
| 95 | |
| 96 | #define SPA_LOG_IMPL_DEFINE(name) \ |
| 97 | struct { \ |
| 98 | struct spa_log log; \ |
| 99 | struct spa_log_methods methods; \ |
| 100 | } name |
| 101 | |
| 102 | #define SPA_LOG_IMPL_INIT(name) \ |
| 103 | { { { SPA_TYPE_INTERFACE_Log, SPA_VERSION_LOG, \ |
| 104 | SPA_CALLBACKS_INIT(&(name).methods, &(name)) }, \ |
| 105 | SPA_LOG_LEVEL_INFO, }, \ |
| 106 | { SPA_VERSION_LOG_METHODS, \ |
| 107 | spa_log_impl_log, \ |
| 108 | spa_log_impl_logv, \ |
| 109 | spa_log_impl_logt, \ |
| 110 | spa_log_impl_logtv, \ |
| 111 | spa_log_impl_topic_init, \ |
| 112 | } } |
| 113 | |
| 114 | #define SPA_LOG_IMPL(name) \ |
| 115 | SPA_LOG_IMPL_DEFINE(name) = SPA_LOG_IMPL_INIT(name) |
| 116 | |
| 117 | /** |
| 118 | * \} |
| 119 | */ |
| 120 | |
| 121 | #ifdef __cplusplus |
| 122 | } /* extern "C" */ |
| 123 | #endif |
| 124 | #endif /* SPA_LOG_IMPL_H */ |