lifetime.h 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  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 "plugin_base.h"
  8. namespace rotor::plugin {
  9. /** \struct lifetime_plugin_t
  10. *
  11. * \brief manages all actor subscriptions (i.e. from plugins or actor itself).
  12. *
  13. * The plugin main focus to properly cancel subscriptions, i.e. every address
  14. * where an actor plugin or the actor itslef was subscribscribed to.
  15. *
  16. */
  17. struct lifetime_plugin_t : public plugin_base_t {
  18. using plugin_base_t::plugin_base_t;
  19. /** The plugin unique identity to allow further static_cast'ing*/
  20. static const void *class_identity;
  21. const void *identity() const noexcept override;
  22. void activate(actor_base_t *actor) noexcept override;
  23. void deactivate() noexcept override;
  24. /** \brief records initial subscription information */
  25. void initate_subscription(const subscription_info_ptr_t &info) noexcept;
  26. /** \brief alias for unsubscription trigger (see below) */
  27. void unsubscribe(const handler_ptr_t &h, const address_ptr_t &addr) noexcept;
  28. /** \brief triggers unsubscription
  29. *
  30. * For internal subscriptions it answers with unsubscription
  31. * confirimation; for foreign subscription it sends external unsubscription
  32. * request
  33. */
  34. void unsubscribe(const subscription_info_ptr_t &info) noexcept;
  35. /** \brief reaction on subscription
  36. *
  37. * It just forwards it to the actor to poll related plugins
  38. */
  39. virtual void on_subscription(message::subscription_t &) noexcept;
  40. /** \brief reaction on unsubscription
  41. *
  42. * It just forwards it to the actor to poll related plugins
  43. */
  44. virtual void on_unsubscription(message::unsubscription_t &) noexcept;
  45. /** \brief reaction on external unsubscription
  46. *
  47. * It just forwards it to the actor to poll related plugins
  48. */
  49. virtual void on_unsubscription_external(message::unsubscription_external_t &) noexcept;
  50. bool handle_unsubscription(const subscription_point_t &point, bool external) noexcept override;
  51. bool handle_shutdown(message::shutdown_request_t *message) noexcept override;
  52. /** \brief generic non-public fields accessor */
  53. template <typename T> auto &access() noexcept;
  54. private:
  55. void unsubscribe() noexcept;
  56. /** \brief recorded subscription points (i.e. handler/address pairs) */
  57. subscription_container_t points;
  58. bool ready_to_shutdown() noexcept;
  59. };
  60. } // namespace rotor::plugin