supervisor_test.h 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  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 "rotor/supervisor.h"
  8. #include "actor_test.h"
  9. #include <list>
  10. namespace rotor {
  11. namespace test {
  12. extern pt::time_duration default_timeout;
  13. struct supervisor_config_test_t : public supervisor_config_t {
  14. const void *locality = nullptr;
  15. plugin_configurer_t configurer = plugin_configurer_t{};
  16. };
  17. template <typename Supervisor> struct supervisor_test_config_builder_t;
  18. struct supervisor_test_t : public supervisor_t {
  19. using timers_t = std::list<timer_handler_base_t*>;
  20. using config_t = supervisor_config_test_t;
  21. template <typename Supervisor> using config_builder_t = supervisor_test_config_builder_t<Supervisor>;
  22. supervisor_test_t(supervisor_config_test_t &config_);
  23. ~supervisor_test_t();
  24. void configure(plugin::plugin_base_t &plugin) noexcept override;
  25. virtual void do_start_timer(const pt::time_duration &interval, timer_handler_base_t& handler) noexcept override;
  26. virtual void do_cancel_timer(request_id_t timer_id) noexcept override;
  27. void do_invoke_timer(request_id_t timer_id) noexcept;
  28. request_id_t get_timer(std::size_t index) noexcept;
  29. virtual void start() noexcept override {}
  30. virtual void shutdown() noexcept override {}
  31. virtual void enqueue(rotor::message_ptr_t message) noexcept override;
  32. virtual address_ptr_t make_address() noexcept override;
  33. state_t &get_state() noexcept { return state; }
  34. messages_queue_t &get_leader_queue() { return get_leader().queue; }
  35. supervisor_test_t &get_leader();
  36. subscription_container_t &get_points() noexcept;
  37. subscription_t &get_subscription() noexcept { return subscription_map; }
  38. size_t get_children_count() noexcept;
  39. request_map_t &get_requests() noexcept { return request_map; }
  40. auto get_activating_plugins() noexcept { return this->activating_plugins; }
  41. auto get_deactivating_plugins() noexcept { return this->deactivating_plugins; }
  42. const void *locality;
  43. timers_t active_timers;
  44. plugin_configurer_t configurer;
  45. };
  46. using supervisor_test_ptr_t = rotor::intrusive_ptr_t<supervisor_test_t>;
  47. template <typename Supervisor> struct supervisor_test_config_builder_t : supervisor_config_builder_t<Supervisor> {
  48. using builder_t = typename Supervisor::template config_builder_t<Supervisor>;
  49. using parent_t = supervisor_config_builder_t<Supervisor>;
  50. using parent_t::parent_t;
  51. builder_t &&locality(const void *locality_) && {
  52. parent_t::config.locality = locality_;
  53. return std::move(*this);
  54. }
  55. builder_t &&configurer(plugin_configurer_t&& value) && {
  56. parent_t::config.configurer = std::move(value);
  57. return std::move(*this);
  58. }
  59. };
  60. } // namespace test
  61. } // namespace rotor