libiio
1.0
Library for interfacing with IIO devices
Loading...
Searching...
No Matches
iio-debug.h
1
/* SPDX-License-Identifier: MIT */
2
/*
3
* libiio - Library for interfacing industrial I/O (IIO) devices
4
*
5
* Copyright (C) 2021-2023 Analog Devices, Inc.
6
* Author: Paul Cercueil <paul.cercueil@analog.com>
7
*/
8
9
#ifndef __IIO_DEBUG_H__
10
#define __IIO_DEBUG_H__
11
12
#include <
iio/iio.h
>
13
14
#define __api __iio_api
15
16
#if defined(__MINGW32__)
17
# define __iio_printf __attribute__((__format__(gnu_printf, 3, 4)))
18
#elif defined(__GNUC__)
19
# define __iio_printf __attribute__((__format__(printf, 3, 4)))
20
#else
21
# define __iio_printf
22
#endif
23
24
#ifdef LIBIIO_EXPORTS
25
#include "iio-config.h"
26
#define LIBIIO_MAX_LOG_LEVEL MAX_LOG_LEVEL
27
#else
28
#define LIBIIO_MAX_LOG_LEVEL LEVEL_DEBUG
29
#endif
30
31
#define __FIRST(a, ...) a
32
#define ___OTHERS(a, ...) a, __VA_ARGS__
33
#define __OTHERS(a, b, ...) ___OTHERS(a, __VA_ARGS__)
34
#define __SKIPFIRST(a, ...) __VA_ARGS__
35
36
42
__api __iio_printf
void
43
iio_prm_printf(
const
struct
iio_context_params
*params,
44
enum
iio_log_level
msg_level,
45
const
char
*fmt, ...);
46
47
#define __ctx_params_or_null(ctx) ((ctx) ? iio_context_get_params(ctx) : NULL)
48
#define __dev_ctx_or_null(dev) ((dev) ? iio_device_get_context(dev) : NULL)
49
#define __chn_dev_or_null(chn) ((chn) ? iio_channel_get_device(chn) : NULL)
50
51
#define __dev_id_or_null(dev) ((dev) ? iio_device_get_id(dev) : NULL)
52
#define __chn_id_or_null(chn) ((chn) ? iio_channel_get_id(chn) : NULL)
53
54
#define prm_err(prm, ...) \
55
do { \
56
if (LIBIIO_MAX_LOG_LEVEL >= LEVEL_ERROR) \
57
iio_prm_printf((prm), LEVEL_ERROR, "ERROR: " __VA_ARGS__); \
58
} while (0)
59
#define prm_warn(prm, ...) \
60
do { \
61
if (LIBIIO_MAX_LOG_LEVEL >= LEVEL_WARNING) \
62
iio_prm_printf((prm), LEVEL_WARNING, "WARNING: " __VA_ARGS__); \
63
} while (0)
64
#define prm_info(prm, ...) \
65
do { \
66
if (LIBIIO_MAX_LOG_LEVEL >= LEVEL_INFO) \
67
iio_prm_printf((prm), LEVEL_INFO, __VA_ARGS__); \
68
} while (0)
69
#define prm_dbg(prm, ...) \
70
do { \
71
if (LIBIIO_MAX_LOG_LEVEL >= LEVEL_DEBUG) \
72
iio_prm_printf((prm), LEVEL_DEBUG, "DEBUG: "__VA_ARGS__); \
73
} while (0)
74
75
#define ctx_err(ctx, ...) prm_err(__ctx_params_or_null(ctx), __VA_ARGS__)
76
#define ctx_warn(ctx, ...) prm_warn(__ctx_params_or_null(ctx), __VA_ARGS__)
77
#define ctx_info(ctx, ...) prm_info(__ctx_params_or_null(ctx), __VA_ARGS__)
78
#define ctx_dbg(ctx, ...) prm_dbg(__ctx_params_or_null(ctx), __VA_ARGS__)
79
80
#define dev_err(dev, ...) ctx_err(__dev_ctx_or_null(dev), \
81
"%s: " __FIRST(__VA_ARGS__, 0) "%s", \
82
__dev_id_or_null(dev), \
83
__SKIPFIRST(__VA_ARGS__, ""))
84
#define dev_warn(dev, ...) ctx_warn(__dev_ctx_or_null(dev), \
85
"%s: " __FIRST(__VA_ARGS__, 0) "%s", \
86
__dev_id_or_null(dev), \
87
__SKIPFIRST(__VA_ARGS__, ""))
88
#define dev_info(dev, ...) ctx_info(__dev_ctx_or_null(dev), \
89
"%s: " __FIRST(__VA_ARGS__, 0) "%s", \
90
__dev_id_or_null(dev), \
91
__SKIPFIRST(__VA_ARGS__, ""))
92
#define dev_dbg(dev, ...) ctx_dbg(__dev_ctx_or_null(dev), \
93
"%s: " __FIRST(__VA_ARGS__, 0) "%s", \
94
__dev_id_or_null(dev), \
95
__SKIPFIRST(__VA_ARGS__, ""))
96
97
#define chn_err(dev, ...) dev_err(__chn_dev_or_null(chn), \
98
"%s: " __FIRST(__VA_ARGS__, 0) "%s", \
99
__chn_id_or_null(chn), \
100
__SKIPFIRST(__VA_ARGS__, ""))
101
#define chn_warn(dev, ...) dev_warn(__chn_dev_or_null(chn), \
102
"%s: " __FIRST(__VA_ARGS__, 0) "%s", \
103
__chn_id_or_null(chn), \
104
__SKIPFIRST(__VA_ARGS__, ""))
105
#define chn_info(dev, ...) dev_info(__chn_dev_or_null(chn), \
106
"%s: " __FIRST(__VA_ARGS__, 0) "%s", \
107
__chn_id_or_null(chn), \
108
__SKIPFIRST(__VA_ARGS__, ""))
109
#define chn_dbg(dev, ...) dev_dbg(__chn_dev_or_null(chn), \
110
"%s: " __FIRST(__VA_ARGS__, 0) "%s", \
111
__chn_id_or_null(chn), \
112
__SKIPFIRST(__VA_ARGS__, ""))
113
114
#define prm_perror(params, err, ...) do { \
115
if (LIBIIO_MAX_LOG_LEVEL >= LEVEL_ERROR) { \
116
char _buf[1024]; \
117
int _err = -(err); \
118
iio_strerror(_err, _buf, sizeof(_buf)); \
119
prm_err(params, __FIRST(__VA_ARGS__, 0) \
120
__OTHERS(": %s\n",__VA_ARGS__, _buf)); \
121
} \
122
} while (0)
123
#define ctx_perror(ctx, err, ...) prm_perror(__ctx_params_or_null(ctx), err, __VA_ARGS__)
124
#define dev_perror(dev, err, ...) ctx_perror(__dev_ctx_or_null(dev), err, \
125
"%s: " __FIRST(__VA_ARGS__, 0) "%s", \
126
__dev_id_or_null(dev), \
127
__SKIPFIRST(__VA_ARGS__, ""))
128
#define chn_perror(dev, err, ...) dev_perror(__chn_dev_or_null(chn), err, \
129
"%s: " __FIRST(__VA_ARGS__, 0) "%s", \
130
__chn_id_or_null(chn), \
131
__SKIPFIRST(__VA_ARGS__, ""))
132
133
#undef __api
134
135
#endif
/* __IIO_DEBUG_H__ */
iio.h
Public interface.
iio_log_level
iio_log_level
Level of verbosity of libiio's log output.
Definition
iio.h:132
iio_context_params
IIO context creation information.
Definition
iio.h:167
include
iio
iio-debug.h
Copyright
libIIO Contributors
1.9.8