Luiz Capitulino | d5ec4f2 | 2011-06-01 12:14:49 -0500 | [diff] [blame] | 1 | /* |
| 2 | * QEMU Error Objects |
| 3 | * |
| 4 | * Copyright IBM, Corp. 2011 |
| 5 | * |
| 6 | * Authors: |
| 7 | * Anthony Liguori <aliguori@us.ibm.com> |
| 8 | * |
| 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. |
| 11 | */ |
| 12 | #ifndef ERROR_H |
| 13 | #define ERROR_H |
| 14 | |
Luiz Capitulino | d3608b7 | 2011-07-11 15:01:57 -0300 | [diff] [blame] | 15 | #include "compiler.h" |
Luiz Capitulino | 13f59ae | 2012-07-27 14:09:29 -0300 | [diff] [blame] | 16 | #include "qapi-types.h" |
Luiz Capitulino | d5ec4f2 | 2011-06-01 12:14:49 -0500 | [diff] [blame] | 17 | #include <stdbool.h> |
| 18 | |
| 19 | /** |
Luiz Capitulino | df1e608 | 2012-07-27 17:51:03 -0300 | [diff] [blame] | 20 | * A class representing internal errors within QEMU. An error has a ErrorClass |
| 21 | * code and a human message. |
Luiz Capitulino | d5ec4f2 | 2011-06-01 12:14:49 -0500 | [diff] [blame] | 22 | */ |
| 23 | typedef struct Error Error; |
| 24 | |
| 25 | /** |
Luiz Capitulino | df1e608 | 2012-07-27 17:51:03 -0300 | [diff] [blame] | 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. |
Luiz Capitulino | d5ec4f2 | 2011-06-01 12:14:49 -0500 | [diff] [blame] | 29 | */ |
Luiz Capitulino | 13f59ae | 2012-07-27 14:09:29 -0300 | [diff] [blame] | 30 | void error_set(Error **err, ErrorClass err_class, const char *fmt, ...) GCC_FMT_ATTR(3, 4); |
Luiz Capitulino | d5ec4f2 | 2011-06-01 12:14:49 -0500 | [diff] [blame] | 31 | |
| 32 | /** |
| 33 | * Returns true if an indirect pointer to an error is pointing to a valid |
| 34 | * error object. |
| 35 | */ |
| 36 | bool error_is_set(Error **err); |
| 37 | |
Luiz Capitulino | ea25fbc | 2012-08-01 16:29:38 -0300 | [diff] [blame] | 38 | /* |
| 39 | * Get the error class of an error object. |
| 40 | */ |
| 41 | ErrorClass error_get_class(const Error *err); |
| 42 | |
Luiz Capitulino | d5ec4f2 | 2011-06-01 12:14:49 -0500 | [diff] [blame] | 43 | /** |
Luiz Capitulino | 79020cf | 2011-12-05 16:04:05 -0200 | [diff] [blame] | 44 | * Returns an exact copy of the error passed as an argument. |
| 45 | */ |
| 46 | Error *error_copy(const Error *err); |
| 47 | |
| 48 | /** |
Luiz Capitulino | d5ec4f2 | 2011-06-01 12:14:49 -0500 | [diff] [blame] | 49 | * Get a human readable representation of an error object. |
| 50 | */ |
| 51 | const char *error_get_pretty(Error *err); |
| 52 | |
| 53 | /** |
Luiz Capitulino | d5ec4f2 | 2011-06-01 12:14:49 -0500 | [diff] [blame] | 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 |
Paolo Bonzini | d195325 | 2012-07-17 16:17:04 +0200 | [diff] [blame] | 56 | * dst_err is NULL correctly. Errors after the first are discarded. |
Luiz Capitulino | d5ec4f2 | 2011-06-01 12:14:49 -0500 | [diff] [blame] | 57 | */ |
| 58 | void error_propagate(Error **dst_err, Error *local_err); |
| 59 | |
| 60 | /** |
| 61 | * Free an error object. |
| 62 | */ |
| 63 | void error_free(Error *err); |
| 64 | |
Luiz Capitulino | d5ec4f2 | 2011-06-01 12:14:49 -0500 | [diff] [blame] | 65 | #endif |