system_context.h 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. #pragma once
  2. //
  3. // Copyright (c) 2019-2020 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 "error_code.h"
  10. #include <system_error>
  11. namespace rotor {
  12. struct supervisor_t;
  13. using supervisor_ptr_t = intrusive_ptr_t<supervisor_t>;
  14. /** \struct system_context_t
  15. * \brief The system context holds root {@link supervisor_t}
  16. * (intrusive pointer) and may be loop-related details in derived classes
  17. *
  18. */
  19. struct system_context_t : arc_base_t<system_context_t> {
  20. public:
  21. /** \brief returns builder for root supervisor */
  22. template <typename Supervisor = supervisor_t> auto create_supervisor();
  23. /** \brief returns root supervisor */
  24. inline supervisor_ptr_t get_supervisor() noexcept { return supervisor; }
  25. system_context_t();
  26. system_context_t(const system_context_t &) = delete;
  27. system_context_t(system_context_t &&) = delete;
  28. virtual ~system_context_t();
  29. /** \brief fatal error handler
  30. *
  31. * The error is fatal, is further `rotor` behavior is undefined. The method should
  32. * be overriden in derived classes for error propagation/notification. The default
  33. * implementation is to output the error to `std::err` and invoke `std::abort()`.
  34. *
  35. */
  36. virtual void on_error(const std::error_code &ec) noexcept;
  37. private:
  38. friend struct supervisor_t;
  39. supervisor_ptr_t supervisor;
  40. };
  41. /** \brief intrusive pointer for system context */
  42. using system_context_ptr_t = intrusive_ptr_t<system_context_t>;
  43. } // namespace rotor