Debian Codegraph @

third_party/rust/cubeb-sys/libcubeb/src/cubeb_log.h

raw
1 /*
2 * Copyright © 2016 Mozilla Foundation
3 *
4 * This program is made available under an ISC-style license. See the
5 * accompanying file LICENSE for details.
6 */
7
8 #ifndef CUBEB_LOG
9 #define CUBEB_LOG
10
11 #include "cubeb/cubeb.h"
12
13 #ifdef __cplusplus
14 extern "C" {
15 #endif
16
17 #if defined(__GNUC__) || defined(__clang__)
18 #define PRINTF_FORMAT(fmt, args) __attribute__((format(printf, fmt, args)))
19 #if defined(__FILE_NAME__)
20 #define __FILENAME__ __FILE_NAME__
21 #else
22 #define __FILENAME__ \
23 (__builtin_strrchr(__FILE__, '/') ? __builtin_strrchr(__FILE__, '/') + 1 \
24 : __FILE__)
25 #endif
26 #else
27 #define PRINTF_FORMAT(fmt, args)
28 #include <string.h>
29 #define __FILENAME__ \
30 (strrchr(__FILE__, '/') ? strrchr(__FILE__, '/') + 1 : __FILE__)
31 #endif
32
33 void
34 cubeb_log_set(cubeb_log_level log_level, cubeb_log_callback log_callback);
35 cubeb_log_level
36 cubeb_log_get_level(void);
37 cubeb_log_callback
38 cubeb_log_get_callback(void);
39 void
40 cubeb_log_internal_no_format(const char * msg);
41 void
42 cubeb_log_internal(const char * filename, uint32_t line, const char * fmt, ...);
43 void
44 cubeb_async_log(const char * fmt, ...);
45 void
46 cubeb_async_log_reset_threads(void);
47
48 #ifdef __cplusplus
49 }
50 #endif
51
52 #define LOGV(msg, ...) LOG_INTERNAL(CUBEB_LOG_VERBOSE, msg, ##__VA_ARGS__)
53 #define LOG(msg, ...) LOG_INTERNAL(CUBEB_LOG_NORMAL, msg, ##__VA_ARGS__)
54
55 #define LOG_INTERNAL(level, fmt, ...) \
56 do { \
57 if (cubeb_log_get_level() >= level && cubeb_log_get_callback()) { \
58 cubeb_log_internal(__FILENAME__, __LINE__, fmt, ##__VA_ARGS__); \
59 } \
60 } while (0)
61
62 #define ALOG_INTERNAL(level, fmt, ...) \
63 do { \
64 if (cubeb_log_get_level() >= level && cubeb_log_get_callback()) { \
65 cubeb_async_log(fmt, ##__VA_ARGS__); \
66 } \
67 } while (0)
68
69 /* Asynchronous logging macros to log in real-time callbacks. */
70 /* Should not be used on android due to the use of global/static variables. */
71 #define ALOGV(msg, ...) ALOG_INTERNAL(CUBEB_LOG_VERBOSE, msg, ##__VA_ARGS__)
72 #define ALOG(msg, ...) ALOG_INTERNAL(CUBEB_LOG_NORMAL, msg, ##__VA_ARGS__)
73
74 #endif // CUBEB_LOG