target-i386: Add Haswell CPU model
[qemu.git] / error.h
blob4d52e7369e9af5096b86984d84fac7b5b8b640db
1 /*
2 * QEMU Error Objects
4 * Copyright IBM, Corp. 2011
6 * Authors:
7 * Anthony Liguori <aliguori@us.ibm.com>
9 * This work is licensed under the terms of the GNU LGPL, version 2. See
10 * the COPYING.LIB file in the top-level directory.
12 #ifndef ERROR_H
13 #define ERROR_H
15 #include "compiler.h"
16 #include "qapi-types.h"
17 #include <stdbool.h>
19 /**
20 * A class representing internal errors within QEMU. An error has a ErrorClass
21 * code and a human message.
23 typedef struct Error Error;
25 /**
26 * Set an indirect pointer to an error given a ErrorClass value and a
27 * printf-style human message. This function is not meant to be used outside
28 * of QEMU.
30 void error_set(Error **err, ErrorClass err_class, const char *fmt, ...) GCC_FMT_ATTR(3, 4);
32 /**
33 * Set an indirect pointer to an error given a ErrorClass value and a
34 * printf-style human message, followed by a strerror() string if
35 * @os_error is not zero.
37 void error_set_errno(Error **err, int os_error, ErrorClass err_class, const char *fmt, ...) GCC_FMT_ATTR(4, 5);
39 /**
40 * Same as error_set(), but sets a generic error
42 #define error_setg(err, fmt, ...) \
43 error_set(err, ERROR_CLASS_GENERIC_ERROR, fmt, ## __VA_ARGS__)
44 #define error_setg_errno(err, os_error, fmt, ...) \
45 error_set_errno(err, os_error, ERROR_CLASS_GENERIC_ERROR, fmt, ## __VA_ARGS__)
47 /**
48 * Returns true if an indirect pointer to an error is pointing to a valid
49 * error object.
51 bool error_is_set(Error **err);
54 * Get the error class of an error object.
56 ErrorClass error_get_class(const Error *err);
58 /**
59 * Returns an exact copy of the error passed as an argument.
61 Error *error_copy(const Error *err);
63 /**
64 * Get a human readable representation of an error object.
66 const char *error_get_pretty(Error *err);
68 /**
69 * Propagate an error to an indirect pointer to an error. This function will
70 * always transfer ownership of the error reference and handles the case where
71 * dst_err is NULL correctly. Errors after the first are discarded.
73 void error_propagate(Error **dst_err, Error *local_err);
75 /**
76 * Free an error object.
78 void error_free(Error *err);
80 #endif