2
0

error.h 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  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 "qapi-types.h"
  16. #include <stdbool.h>
  17. /**
  18. * A class representing internal errors within QEMU. An error has a ErrorClass
  19. * code and a human message.
  20. */
  21. typedef struct Error Error;
  22. /**
  23. * Set an indirect pointer to an error given a ErrorClass value and a
  24. * printf-style human message. This function is not meant to be used outside
  25. * of QEMU.
  26. */
  27. void error_set(Error **err, ErrorClass err_class, const char *fmt, ...) GCC_FMT_ATTR(3, 4);
  28. /**
  29. * Returns true if an indirect pointer to an error is pointing to a valid
  30. * error object.
  31. */
  32. bool error_is_set(Error **err);
  33. /*
  34. * Get the error class of an error object.
  35. */
  36. ErrorClass error_get_class(const Error *err);
  37. /**
  38. * Returns an exact copy of the error passed as an argument.
  39. */
  40. Error *error_copy(const Error *err);
  41. /**
  42. * Get a human readable representation of an error object.
  43. */
  44. const char *error_get_pretty(Error *err);
  45. /**
  46. * Propagate an error to an indirect pointer to an error. This function will
  47. * always transfer ownership of the error reference and handles the case where
  48. * dst_err is NULL correctly. Errors after the first are discarded.
  49. */
  50. void error_propagate(Error **dst_err, Error *local_err);
  51. /**
  52. * Free an error object.
  53. */
  54. void error_free(Error *err);
  55. #endif