error.h 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  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. #include "compiler.h"
  15. #include <stdbool.h>
  16. /**
  17. * A class representing internal errors within QEMU. An error has a string
  18. * typename and optionally a set of named string parameters.
  19. */
  20. typedef struct Error Error;
  21. /**
  22. * Set an indirect pointer to an error given a printf-style format parameter.
  23. * Currently, qerror.h defines these error formats. This function is not
  24. * meant to be used outside of QEMU.
  25. */
  26. void error_set(Error **err, const char *fmt, ...) GCC_FMT_ATTR(2, 3);
  27. /**
  28. * Returns true if an indirect pointer to an error is pointing to a valid
  29. * error object.
  30. */
  31. bool error_is_set(Error **err);
  32. /**
  33. * Get a human readable representation of an error object.
  34. */
  35. const char *error_get_pretty(Error *err);
  36. /**
  37. * Get an individual named error field.
  38. */
  39. const char *error_get_field(Error *err, const char *field);
  40. /**
  41. * Get an individual named error field.
  42. */
  43. void error_set_field(Error *err, const char *field, const char *value);
  44. /**
  45. * Propagate an error to an indirect pointer to an error. This function will
  46. * always transfer ownership of the error reference and handles the case where
  47. * dst_err is NULL correctly.
  48. */
  49. void error_propagate(Error **dst_err, Error *local_err);
  50. /**
  51. * Free an error object.
  52. */
  53. void error_free(Error *err);
  54. /**
  55. * Determine if an error is of a speific type (based on the qerror format).
  56. * Non-QEMU users should get the `class' field to identify the error type.
  57. */
  58. bool error_is_type(Error *err, const char *fmt);
  59. #endif