error_code.h 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  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. #include "rotor/export.h"
  10. #if defined(_MSC_VER)
  11. #pragma warning(push)
  12. #pragma warning(disable : 4251)
  13. #pragma warning(disable : 4275)
  14. #endif
  15. namespace rotor {
  16. /** \brief fatal error codes in rotor */
  17. enum class error_code_t {
  18. success = 0,
  19. cancelled,
  20. request_timeout,
  21. supervisor_defined,
  22. already_registered,
  23. actor_misconfigured,
  24. actor_not_linkable,
  25. already_linked,
  26. failure_escalation,
  27. registration_failed,
  28. discovery_failed,
  29. unknown_service,
  30. };
  31. /** \brief actor shutdown reasons as error code */
  32. enum class shutdown_code_t {
  33. normal = 0,
  34. supervisor_shutdown,
  35. child_down,
  36. child_init_failed,
  37. init_failed,
  38. unlink_requested,
  39. };
  40. namespace details {
  41. /** \brief category support for `rotor` error codes */
  42. class ROTOR_API error_code_category : public std::error_category {
  43. public:
  44. /** error category name */
  45. virtual const char *name() const noexcept override;
  46. /** message for error code */
  47. virtual std::string message(int c) const override;
  48. };
  49. /** \brief category support for `rotor` shutdown codes */
  50. class ROTOR_API shutdown_code_category : public std::error_category {
  51. public:
  52. /** error category name */
  53. virtual const char *name() const noexcept override;
  54. /** message for error code */
  55. virtual std::string message(int c) const override;
  56. };
  57. } // namespace details
  58. /** \brief returns error code category for `rotor` error codes */
  59. ROTOR_API const details::error_code_category &error_code_category();
  60. /** \brief returns error code category for `rotor` shutdown codes */
  61. ROTOR_API const details::shutdown_code_category &shutdown_code_category();
  62. /** \brief makes `std::error_code` from rotor error code enumerations */
  63. ROTOR_API inline std::error_code make_error_code(const error_code_t e) {
  64. return {static_cast<int>(e), error_code_category()};
  65. }
  66. /** \brief makes `std::error_code` from rotor shutdown code enumerations */
  67. ROTOR_API inline std::error_code make_error_code(const shutdown_code_t e) {
  68. return {static_cast<int>(e), shutdown_code_category()};
  69. }
  70. } // namespace rotor
  71. namespace std {
  72. template <> struct is_error_code_enum<rotor::error_code_t> : std::true_type {};
  73. template <> struct is_error_code_enum<rotor::shutdown_code_t> : std::true_type {};
  74. } // namespace std
  75. #if defined(_MSC_VER)
  76. #pragma warning(pop)
  77. #endif