error_code.h 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. #pragma once
  2. //
  3. // Copyright (c) 2019-2021 Ivan Baidakou (basiliscos) (the dot dmol at gmail dot com)
  4. //
  5. // Distributed under the MIT Software License
  6. //
  7. #include <string>
  8. #include <system_error>
  9. namespace rotor {
  10. /** \brief fatal error codes in rotor */
  11. enum class error_code_t {
  12. success = 0,
  13. cancelled,
  14. request_timeout,
  15. supervisor_defined,
  16. already_registered,
  17. actor_misconfigured,
  18. actor_not_linkable,
  19. already_linked,
  20. failure_escalation,
  21. registration_failed,
  22. discovery_failed,
  23. unknown_service,
  24. };
  25. /** \brief actor shutdown reasons as error code */
  26. enum class shutdown_code_t {
  27. normal = 0,
  28. supervisor_shutdown,
  29. child_down,
  30. child_init_failed,
  31. init_failed,
  32. unlink_requested,
  33. };
  34. namespace details {
  35. /** \brief category support for `rotor` error codes */
  36. class error_code_category : public std::error_category {
  37. public:
  38. /** error category name */
  39. virtual const char *name() const noexcept override;
  40. /** message for error code */
  41. virtual std::string message(int c) const override;
  42. };
  43. /** \brief category support for `rotor` shutdown codes */
  44. class shutdown_code_category : public std::error_category {
  45. public:
  46. /** error category name */
  47. virtual const char *name() const noexcept override;
  48. /** message for error code */
  49. virtual std::string message(int c) const override;
  50. };
  51. } // namespace details
  52. /** \brief returns error code category for `rotor` error codes */
  53. const details::error_code_category &error_code_category();
  54. /** \brief returns error code category for `rotor` shutdown codes */
  55. const details::shutdown_code_category &shutdown_code_category();
  56. /** \brief makes `std::error_code` from rotor error code enumerations */
  57. inline std::error_code make_error_code(const error_code_t e) { return {static_cast<int>(e), error_code_category()}; }
  58. /** \brief makes `std::error_code` from rotor shutdown code enumerations */
  59. inline std::error_code make_error_code(const shutdown_code_t e) {
  60. return {static_cast<int>(e), shutdown_code_category()};
  61. }
  62. } // namespace rotor
  63. namespace std {
  64. template <> struct is_error_code_enum<rotor::error_code_t> : std::true_type {};
  65. template <> struct is_error_code_enum<rotor::shutdown_code_t> : std::true_type {};
  66. } // namespace std