aboutsummaryrefslogtreecommitdiff
blob: b82b905cf4d4265dae7f185e8ad47b6e85f0d623 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
/*
 * virterror.h: internal error handling
 *
 * Copyright (C) 2006-2009, 2011 Red Hat, Inc.
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library;  If not, see
 * <http://www.gnu.org/licenses/>.
 *
 */

#ifndef __VIRT_ERROR_H_
# define __VIRT_ERROR_H_

# include "internal.h"

extern virErrorFunc virErrorHandler;
extern void *virUserData;

/************************************************************************
 *									*
 *		API for error handling					*
 *									*
 ************************************************************************/
int virErrorInitialize(void);
void virRaiseErrorFull(const char *filename,
                       const char *funcname,
                       size_t linenr,
                       int domain,
                       int code,
                       virErrorLevel level,
                       const char *str1,
                       const char *str2,
                       const char *str3,
                       int int1,
                       int int2,
                       const char *fmt, ...)
    ATTRIBUTE_FMT_PRINTF(12, 13);

void virReportErrorHelper(int domcode, int errcode,
                          const char *filename,
                          const char *funcname,
                          size_t linenr,
                          const char *fmt, ...)
  ATTRIBUTE_FMT_PRINTF(6, 7);

void virReportSystemErrorFull(int domcode,
                              int theerrno,
                              const char *filename,
                              const char *funcname,
                              size_t linenr,
                              const char *fmt, ...)
    ATTRIBUTE_FMT_PRINTF(6, 7);

# define virReportSystemError(theerrno, fmt,...)                   \
    virReportSystemErrorFull(VIR_FROM_THIS,                       \
                             (theerrno),                          \
                             __FILE__, __FUNCTION__, __LINE__,    \
                             (fmt), __VA_ARGS__)

# define virReportInvalidNullArg(argname)                            \
    virRaiseErrorFull(__FILE__, __FUNCTION__, __LINE__,              \
                      VIR_FROM_THIS,                                 \
                      VIR_ERR_INVALID_ARG,                           \
                      VIR_ERR_ERROR,                                 \
                      __FUNCTION__,                                  \
                      #argname,                                      \
                      NULL,                                          \
                      0, 0,                                          \
                      _("%s in %s must be NULL"),                    \
                      #argname, __FUNCTION__)
# define virReportInvalidNonNullArg(argname)                         \
    virRaiseErrorFull(__FILE__, __FUNCTION__, __LINE__,              \
                      VIR_FROM_THIS,                                 \
                      VIR_ERR_INVALID_ARG,                           \
                      VIR_ERR_ERROR,                                 \
                      __FUNCTION__,                                  \
                      #argname,                                      \
                      NULL,                                          \
                      0, 0,                                          \
                      _("%s in %s must not be NULL"),                \
                      #argname, __FUNCTION__)
# define virReportInvalidPositiveArg(argname)                        \
    virRaiseErrorFull(__FILE__, __FUNCTION__, __LINE__,              \
                      VIR_FROM_THIS,                                 \
                      VIR_ERR_INVALID_ARG,                           \
                      VIR_ERR_ERROR,                                 \
                      __FUNCTION__,                                  \
                      #argname,                                      \
                      NULL,                                          \
                      0, 0,                                          \
                      _("%s in %s must greater than zero"),          \
                      #argname, __FUNCTION__)
# define virReportInvalidNonZeroArg(argname)                         \
    virRaiseErrorFull(__FILE__, __FUNCTION__, __LINE__,              \
                      VIR_FROM_THIS,                                 \
                      VIR_ERR_INVALID_ARG,                           \
                      VIR_ERR_ERROR,                                 \
                      __FUNCTION__,                                  \
                      #argname,                                      \
                      NULL,                                          \
                      0, 0,                                          \
                      _("%s in %s must not be zero"),                \
                      #argname, __FUNCTION__)
# define virReportInvalidZeroArg(argname)                            \
    virRaiseErrorFull(__FILE__, __FUNCTION__, __LINE__,              \
                      VIR_FROM_THIS,                                 \
                      VIR_ERR_INVALID_ARG,                           \
                      VIR_ERR_ERROR,                                 \
                      __FUNCTION__,                                  \
                      #argname,                                      \
                      NULL,                                          \
                      0, 0,                                          \
                      _("%s in %s must  be zero"),                   \
                      #argname, __FUNCTION__)
# define virReportInvalidNonNegativeArg(argname)                     \
    virRaiseErrorFull(__FILE__, __FUNCTION__, __LINE__,              \
                      VIR_FROM_THIS,                                 \
                      VIR_ERR_INVALID_ARG,                           \
                      VIR_ERR_ERROR,                                 \
                      __FUNCTION__,                                  \
                      #argname,                                      \
                      NULL,                                          \
                      0, 0,                                          \
                      _("%s in %s must be zero or greater"),         \
                      #argname, __FUNCTION__)
# define virReportInvalidArg(argname, fmt, ...)                      \
    virRaiseErrorFull(__FILE__, __FUNCTION__, __LINE__,              \
                      VIR_FROM_THIS,                                 \
                      VIR_ERR_INVALID_ARG,                           \
                      VIR_ERR_ERROR,                                 \
                      __FUNCTION__,                                  \
                      #argname,                                      \
                      NULL,                                          \
                      0, 0,                                          \
                      (fmt), __VA_ARGS__)

void virReportOOMErrorFull(int domcode,
                           const char *filename,
                           const char *funcname,
                           size_t linenr);

# define virReportOOMError() \
    virReportOOMErrorFull(VIR_FROM_THIS, __FILE__, __FUNCTION__, __LINE__)

# define virReportError(code, ...)                                   \
    virReportErrorHelper(VIR_FROM_THIS, code, __FILE__,              \
                         __FUNCTION__, __LINE__, __VA_ARGS__)

int virSetError(virErrorPtr newerr);
void virDispatchError(virConnectPtr conn);
const char *virStrerror(int theerrno, char *errBuf, size_t errBufLen);

typedef int (*virErrorLogPriorityFunc)(virErrorPtr, int);
void virSetErrorLogPriorityFunc(virErrorLogPriorityFunc func);

#endif