Remove some unused includes in C++ files
[babeltrace.git] / src / cpp-common / cfg-error-reporting.hpp
CommitLineData
b4953462
SM
1/*
2 * SPDX-License-Identifier: MIT
3 *
4 * Copyright (c) 2022 Simon Marchi <simon.marchi@efficios.com>
5 * Copyright (c) 2022 Philippe Proulx <eeppeliteloop@gmail.com>
6 */
7
8#ifndef BABELTRACE_CPP_COMMON_CFG_ERROR_REPORTING_HPP
9#define BABELTRACE_CPP_COMMON_CFG_ERROR_REPORTING_HPP
10
11#include <babeltrace2/babeltrace.h>
c802cacb 12
b4953462
SM
13/*
14 * Appends a cause to the error of the current thread using the logging
15 * configuration `_log_cfg`.
16 */
17#define BT_APPEND_CAUSE_EX(_log_cfg, _fmt, ...) \
18 do { \
19 if ((_log_cfg).selfMsgIter()) { \
20 BT_CURRENT_THREAD_ERROR_APPEND_CAUSE_FROM_MESSAGE_ITERATOR((_log_cfg).selfMsgIter(), \
21 _fmt, ##__VA_ARGS__); \
22 } else if ((_log_cfg).selfComp()) { \
23 BT_CURRENT_THREAD_ERROR_APPEND_CAUSE_FROM_COMPONENT((_log_cfg).selfComp(), _fmt, \
24 ##__VA_ARGS__); \
25 } else if ((_log_cfg).selfCompCls()) { \
26 BT_CURRENT_THREAD_ERROR_APPEND_CAUSE_FROM_COMPONENT_CLASS((_log_cfg).selfCompCls(), \
27 _fmt, ##__VA_ARGS__); \
28 } else { \
29 BT_CURRENT_THREAD_ERROR_APPEND_CAUSE_FROM_UNKNOWN((_log_cfg).moduleName(), _fmt, \
30 ##__VA_ARGS__); \
31 } \
32 } while (false)
33
34#define BT_APPEND_CAUSE(_fmt, ...) BT_APPEND_CAUSE_EX((BT_CLOG_CFG), _fmt, ##__VA_ARGS__)
35
36/*
37 * Appends a cause to the error of the current thread using the logging
38 * configuration `_log_cfg`.
39 */
40#define BT_APPEND_CAUSE_STR_EX(_log_cfg, _str) BT_APPEND_CAUSE_EX((_log_cfg), "%s", _str)
41
42#define BT_APPEND_CAUSE_STR(_str) BT_APPEND_CAUSE_STR_EX((BT_CLOG_CFG), _str)
43
44/*
45 * Appends a cause with an errno message to the error of the current
46 * thread using the logging configuration `_log_cfg`.
47 */
48#define BT_APPEND_CAUSE_ERRNO_EX(_log_cfg, _init_msg, _fmt, ...) \
49 do { \
50 const auto errStr = g_strerror(errno); \
51 BT_APPEND_CAUSE_EX((_log_cfg), "%s: %s" _fmt, _init_msg, errStr, ##__VA_ARGS__); \
52 } while (false)
53
54#define BT_APPEND_CAUSE_ERRNO(_init_msg, _fmt, ...) \
55 BT_APPEND_CAUSE_EX((BT_CLOG_CFG), _init_msg, _fmt, ##__VA_ARGS__)
56
57#endif /* BABELTRACE_CPP_COMMON_CFG_ERROR_REPORTING_HPP */
This page took 0.026224 seconds and 4 git commands to generate.