herr.h 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. #ifndef H_ERR_H
  2. #define H_ERR_H
  3. // F(macro, errcode, errmsg)
  4. #define FOREACH_ERR_COMMON(F) \
  5. F(ERR_OK, 0, "ok") \
  6. F(ERR_UNKNOWN, 1000, "unknown error") \
  7. F(ERR_NULL_PARAM, 1001, "null param") \
  8. F(ERR_NULL_POINTER, 1002, "null pointer") \
  9. F(ERR_NULL_DATA, 1003, "null data") \
  10. \
  11. F(ERR_INVALID_PARAM, 1010, "invalid param") \
  12. F(ERR_INVALID_HANDLE, 1011, "invalid handle") \
  13. F(ERR_INVALID_JSON, 1012, "invalid json") \
  14. F(ERR_INVALID_XML, 1013, "invalid xml") \
  15. F(ERR_INVALID_FMT, 1014, "invalid format") \
  16. \
  17. F(ERR_MISMATCH, 1020, "mismatch") \
  18. F(ERR_REQUEST, 1021, "error request") \
  19. F(ERR_RESPONSE, 1022, "error response") \
  20. \
  21. F(ERR_MALLOC, 1030, "malloc failed") \
  22. F(ERR_FREE, 1031, "free failed") \
  23. \
  24. F(ERR_TASK_TIMEOUT, 1100, "task timeout") \
  25. F(ERR_TASK_DEQUE_FULL, 1101, "task deque full") \
  26. F(ERR_TASK_NOT_CREATE, 1102, "task not create") \
  27. \
  28. F(ERR_OPEN_FILE, 1200, "open file failed") \
  29. F(ERR_SAVE_FILE, 1201, "save file failed")
  30. #define FOREACH_ERR_NETWORK(F) \
  31. F(ERR_ADAPTER_NOT_FOUND, 2001, "adapter not found") \
  32. F(ERR_SERVER_NOT_FOUND, 2002, "server not found") \
  33. F(ERR_SERVER_UNREACHEABLE, 2003, "server unreacheable") \
  34. F(ERR_SERVER_DISCONNECT, 2004, "server disconnect") \
  35. F(ERR_CONNECT_TIMEOUT, 2005, "connect timeout") \
  36. F(ERR_INVALID_PACKAGE, 2006, "invalid package") \
  37. F(ERR_SERVER_NOT_STARTUP, 2007, "server not startup") \
  38. F(ERR_CLIENT_DISCONNECT, 2008, "client disconnect")
  39. #define FOREACH_ERR_SERVICE(F) \
  40. F(ERR_GROUP_NOT_FOUND, 3000, "group not found")
  41. #define FOREACH_ERR(F) \
  42. FOREACH_ERR_COMMON(F) \
  43. FOREACH_ERR_NETWORK(F) \
  44. FOREACH_ERR_SERVICE(F)
  45. #define ENUM_ERR(macro, errcode, _) macro = errcode,
  46. enum E_ERR{
  47. FOREACH_ERR(ENUM_ERR)
  48. ERR_LAST
  49. };
  50. #undef ENUM_ERR
  51. // id => errcode
  52. void set_id_errcode(int id, int errcode);
  53. int get_id_errcode(int id);
  54. // id = gettid()
  55. void set_last_errcode(int errcode);
  56. int get_last_errcode();
  57. // errcode => errmsg
  58. const char* get_errmsg(int errcode);
  59. #endif // H_ERR_H