blob: 96787521526a3d3d8ac8215e23d908ca9b5b8e0e [file] [log] [blame]
Luiz Capitulinod5ec4f22011-06-01 12:14:49 -05001/*
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 Capitulinod3608b72011-07-11 15:01:57 -030015#include "compiler.h"
Luiz Capitulino13f59ae2012-07-27 14:09:29 -030016#include "qapi-types.h"
Luiz Capitulinod5ec4f22011-06-01 12:14:49 -050017#include <stdbool.h>
18
19/**
20 * A class representing internal errors within QEMU. An error has a string
21 * typename and optionally a set of named string parameters.
22 */
23typedef struct Error Error;
24
25/**
26 * Set an indirect pointer to an error given a printf-style format parameter.
27 * Currently, qerror.h defines these error formats. This function is not
28 * meant to be used outside of QEMU.
29 */
Luiz Capitulino13f59ae2012-07-27 14:09:29 -030030void error_set(Error **err, ErrorClass err_class, const char *fmt, ...) GCC_FMT_ATTR(3, 4);
Luiz Capitulinod5ec4f22011-06-01 12:14:49 -050031
32/**
33 * Returns true if an indirect pointer to an error is pointing to a valid
34 * error object.
35 */
36bool error_is_set(Error **err);
37
38/**
Luiz Capitulino79020cf2011-12-05 16:04:05 -020039 * Returns an exact copy of the error passed as an argument.
40 */
41Error *error_copy(const Error *err);
42
43/**
Luiz Capitulinod5ec4f22011-06-01 12:14:49 -050044 * Get a human readable representation of an error object.
45 */
46const char *error_get_pretty(Error *err);
47
48/**
49 * Get an individual named error field.
50 */
51const char *error_get_field(Error *err, const char *field);
52
53/**
54 * Get an individual named error field.
55 */
56void error_set_field(Error *err, const char *field, const char *value);
57
58/**
59 * Propagate an error to an indirect pointer to an error. This function will
60 * always transfer ownership of the error reference and handles the case where
Paolo Bonzinid1953252012-07-17 16:17:04 +020061 * dst_err is NULL correctly. Errors after the first are discarded.
Luiz Capitulinod5ec4f22011-06-01 12:14:49 -050062 */
63void error_propagate(Error **dst_err, Error *local_err);
64
65/**
66 * Free an error object.
67 */
68void error_free(Error *err);
69
70/**
71 * Determine if an error is of a speific type (based on the qerror format).
72 * Non-QEMU users should get the `class' field to identify the error type.
73 */
Luiz Capitulino13f59ae2012-07-27 14:09:29 -030074bool error_is_type(Error *err, ErrorClass err_class, const char *fmt);
Luiz Capitulinod5ec4f22011-06-01 12:14:49 -050075
76#endif