supervisor_config_wx.h 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  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_config.h"
  8. #include <wx/event.h>
  9. namespace rotor {
  10. namespace wx {
  11. /** \struct supervisor_config_wx_t
  12. * \brief wx supervisor config, which holds a pointer to the "context window".
  13. */
  14. struct supervisor_config_wx_t : public supervisor_config_t {
  15. /** \brief the wx context, responsible for messages delivery
  16. *
  17. * Actual rotor-message delivery for actors running on the
  18. * top of wx-loop is performed via wx-events, i.e. rotor-messages
  19. * are **wrapped** into wx-events.
  20. *
  21. * The wx-supervisor subscribes to the `wx-events` and unswraps
  22. * the rotor-messages from the events.
  23. *
  24. * The wx event handler is used as a transport medium.
  25. *
  26. */
  27. wxEvtHandler *handler;
  28. using supervisor_config_t::supervisor_config_t;
  29. };
  30. /** \brief config builder for wx supervisor */
  31. template <typename Supervisor> struct supervisor_config_wx_builder_t : supervisor_config_builder_t<Supervisor> {
  32. /** \brief final builder class */
  33. using builder_t = typename Supervisor::template config_builder_t<Supervisor>;
  34. /** \brief parent config builder */
  35. using parent_t = supervisor_config_builder_t<Supervisor>;
  36. using parent_t::parent_t;
  37. /** \brief bit mask for event handler validation */
  38. constexpr static const std::uint32_t EVT_LOOP = 1 << 2;
  39. /** \brief bit mask for all required fields */
  40. constexpr static const std::uint32_t requirements_mask = parent_t::requirements_mask | EVT_LOOP;
  41. /** \brief sets event handler */
  42. builder_t &&handler(wxEvtHandler *handler_) && {
  43. parent_t::config.handler = handler_;
  44. parent_t::mask = (parent_t::mask & ~EVT_LOOP);
  45. return std::move(*static_cast<builder_t *>(this));
  46. }
  47. };
  48. } // namespace wx
  49. } // namespace rotor