herr.h 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  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. F(ERR_PARSE, 1023, "parse failed") \
  21. \
  22. F(ERR_MALLOC, 1030, "malloc failed") \
  23. F(ERR_FREE, 1031, "free failed") \
  24. \
  25. F(ERR_TASK_TIMEOUT, 1100, "task timeout") \
  26. F(ERR_TASK_DEQUE_FULL, 1101, "task deque full") \
  27. F(ERR_TASK_NOT_CREATE, 1102, "task not create") \
  28. \
  29. F(ERR_OPEN_FILE, 1200, "open file failed") \
  30. F(ERR_SAVE_FILE, 1201, "save file failed")
  31. #define FOREACH_ERR_NETWORK(F) \
  32. F(ERR_ADAPTER_NOT_FOUND, 2001, "adapter not found") \
  33. F(ERR_SERVER_NOT_FOUND, 2002, "server not found") \
  34. F(ERR_SERVER_UNREACHEABLE, 2003, "server unreacheable") \
  35. F(ERR_SERVER_DISCONNECT, 2004, "server disconnect") \
  36. F(ERR_CONNECT_TIMEOUT, 2005, "connect timeout") \
  37. F(ERR_INVALID_PACKAGE, 2006, "invalid package") \
  38. F(ERR_SERVER_NOT_STARTUP, 2007, "server not startup") \
  39. F(ERR_CLIENT_DISCONNECT, 2008, "client disconnect")
  40. #define FOREACH_ERR_SERVICE(F) \
  41. F(ERR_RESOURCE_NOT_FOUND, 3000, "resource not found") \
  42. F(ERR_GROUP_NOT_FOUND, 3001, "group not found") \
  43. F(ERR_PERSON_NOT_FOUND, 3002, "person not found") \
  44. F(ERR_FACE_NOT_FOUND, 3003, "face not found") \
  45. F(ERR_DEVICE_NOT_FOUND, 3004, "device not found")
  46. #define FOREACH_ERR(F) \
  47. FOREACH_ERR_COMMON(F) \
  48. FOREACH_ERR_NETWORK(F) \
  49. FOREACH_ERR_SERVICE(F)
  50. #define ENUM_ERR(macro, errcode, _) macro = errcode,
  51. enum E_ERR{
  52. FOREACH_ERR(ENUM_ERR)
  53. ERR_LAST
  54. };
  55. #undef ENUM_ERR
  56. // id => errcode
  57. void set_id_errcode(int id, int errcode);
  58. int get_id_errcode(int id);
  59. // id = gettid()
  60. void set_last_errcode(int errcode);
  61. int get_last_errcode();
  62. // errcode => errmsg
  63. const char* get_errmsg(int errcode);
  64. #endif // H_ERR_H