system_context.h 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  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 "address.hpp"
  8. #include "supervisor_config.h"
  9. #include "extended_error.h"
  10. #include <system_error>
  11. #if defined(_MSC_VER)
  12. #pragma warning(push)
  13. #pragma warning(disable : 4251)
  14. #endif
  15. namespace rotor {
  16. struct supervisor_t;
  17. struct actor_base_t;
  18. using supervisor_ptr_t = intrusive_ptr_t<supervisor_t>;
  19. /** \struct system_context_t
  20. * \brief The system context holds root {@link supervisor_t}
  21. * (intrusive pointer) and may be loop-related details in derived classes
  22. *
  23. */
  24. struct ROTOR_API system_context_t : arc_base_t<system_context_t> {
  25. public:
  26. /** \brief returns builder for root supervisor */
  27. template <typename Supervisor = supervisor_t> auto create_supervisor();
  28. /** \brief returns root supervisor */
  29. inline supervisor_ptr_t get_supervisor() noexcept { return supervisor; }
  30. system_context_t() = default;
  31. system_context_t(const system_context_t &) = delete;
  32. system_context_t(system_context_t &&) = delete;
  33. virtual ~system_context_t();
  34. /** \brief fatal error handler
  35. *
  36. * The error is fatal, is further `rotor` behavior is undefined. The method should
  37. * be overriden in derived classes for error propagation/notification. The default
  38. * implementation is to output the error to `std::err` and invoke `std::abort()`.
  39. *
  40. */
  41. virtual void on_error(actor_base_t *actor, const extended_error_ptr_t &ec) noexcept;
  42. /** \brief identifies the context.
  43. *
  44. * By default, is is just human-readable address of the system context
  45. *
  46. */
  47. virtual std::string identity() noexcept;
  48. /** \brief generic non-public fields accessor */
  49. template <typename T> auto &access() noexcept;
  50. private:
  51. friend struct supervisor_t;
  52. supervisor_ptr_t supervisor;
  53. };
  54. /** \brief intrusive pointer for system context */
  55. using system_context_ptr_t = intrusive_ptr_t<system_context_t>;
  56. } // namespace rotor
  57. #if defined(_MSC_VER)
  58. #pragma warning(pop)
  59. #endif