system_context.h 1.9 KB

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