Merge commit '5a4d701acde890a5ca134236424ece45545f70c7' into upstream-merge
[qemu-kvm.git] / error.h
blob96fc20328f97f80b4d38b2f9c05f37c7dcb6a70c
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 * Returns true if an indirect pointer to an error is pointing to a valid
34 * error object.
36 bool error_is_set(Error **err);
39 * Get the error class of an error object.
41 ErrorClass error_get_class(const Error *err);
43 /**
44 * Returns an exact copy of the error passed as an argument.
46 Error *error_copy(const Error *err);
48 /**
49 * Get a human readable representation of an error object.
51 const char *error_get_pretty(Error *err);
53 /**
54 * Propagate an error to an indirect pointer to an error. This function will
55 * always transfer ownership of the error reference and handles the case where
56 * dst_err is NULL correctly. Errors after the first are discarded.
58 void error_propagate(Error **dst_err, Error *local_err);
60 /**
61 * Free an error object.
63 void error_free(Error *err);
65 #endif