error.h 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. #ifndef _PCILIB_ERROR_H
  2. #define _PCILIB_ERROR_H
  3. #include <errno.h>
  4. #include <pcilib.h>
  5. typedef enum {
  6. PCILIB_LOG_DEFAULT = 0,
  7. PCILIB_LOG_ONCE = 1
  8. } pcilib_log_flags_t;
  9. typedef enum {
  10. PCILIB_ERROR_SUCCESS = 0,
  11. PCILIB_ERROR_MEMORY = ENOMEM,
  12. PCILIB_ERROR_INVALID_REQUEST = EBADR,
  13. PCILIB_ERROR_INVALID_ADDRESS = EFAULT,
  14. PCILIB_ERROR_INVALID_BANK = ENOENT,
  15. PCILIB_ERROR_INVALID_DATA = EILSEQ,
  16. PCILIB_ERROR_INVALID_STATE = EBADFD,
  17. PCILIB_ERROR_INVALID_ARGUMENT = EINVAL,
  18. PCILIB_ERROR_TIMEOUT = ETIME,
  19. PCILIB_ERROR_FAILED = EBADE,
  20. PCILIB_ERROR_VERIFY = EREMOTEIO,
  21. PCILIB_ERROR_NOTSUPPORTED = ENOTSUP,
  22. PCILIB_ERROR_NOTFOUND = ESRCH,
  23. PCILIB_ERROR_OUTOFRANGE = ERANGE,
  24. PCILIB_ERROR_NOTAVAILABLE = ENAVAIL,
  25. PCILIB_ERROR_NOTINITIALIZED = EBADFD,
  26. PCILIB_ERROR_NOTPERMITED = EPERM,
  27. PCILIB_ERROR_TOOBIG = EFBIG,
  28. PCILIB_ERROR_OVERWRITTEN = ESTALE,
  29. PCILIB_ERROR_BUSY = EBUSY,
  30. PCILIB_ERROR_EXIST = EEXIST
  31. } pcilib_errot_t;
  32. #ifdef __cplusplus
  33. extern "C" {
  34. #endif
  35. void pcilib_log_message(const char *file, int line, pcilib_log_flags_t flags, pcilib_log_priority_t prio, const char *msg, ...);
  36. void pcilib_log_vmessage(const char *file, int line, pcilib_log_flags_t flags, pcilib_log_priority_t prio, const char *msg, va_list va);
  37. /**
  38. * Gets current logger function.
  39. */
  40. pcilib_logger_t pcilib_get_logger();
  41. /**
  42. * Gets current logger min priority.
  43. */
  44. pcilib_log_priority_t pcilib_get_log_level();
  45. /**
  46. * Gets current logger argument.
  47. */
  48. void* pcilib_get_logger_context();
  49. #ifdef __cplusplus
  50. }
  51. #endif
  52. #define pcilib_log(prio, ...) \
  53. pcilib_log_message(__FILE__, __LINE__, PCILIB_LOG_DEFAULT, prio, __VA_ARGS__)
  54. #define pcilib_log_once(prio, ...) \
  55. pcilib_log_message(__FILE__, __LINE__, PCILIB_LOG_ONCE, prio, __VA_ARGS__)
  56. #define pcilib_error(...) pcilib_log(PCILIB_LOG_ERROR, __VA_ARGS__)
  57. #define pcilib_warning(...) pcilib_log(PCILIB_LOG_WARNING, __VA_ARGS__)
  58. #define pcilib_info(...) pcilib_log(PCILIB_LOG_INFO, __VA_ARGS__)
  59. #define pcilib_warning_once(...) pcilib_log_once(PCILIB_LOG_WARNING, __VA_ARGS__)
  60. #define pcilib_info_once(...) pcilib_log_once(PCILIB_LOG_INFO, __VA_ARGS__)
  61. #endif /* _PCILIB_ERROR_H */