rotor
Event loop friendly C++ actor micro-framework
 
Loading...
Searching...
No Matches
supervisor_wx.h
1#pragma once
2
3//
4// Copyright (c) 2019-2022 Ivan Baidakou (basiliscos) (the dot dmol at gmail dot com)
5//
6// Distributed under the MIT Software License
7//
8
9#include "rotor/wx/export.h"
10#include "rotor/supervisor.h"
11#include "rotor/wx/supervisor_config_wx.h"
12#include "rotor/wx/system_context_wx.h"
13#include <wx/event.h>
14#include <wx/timer.h>
15#include <memory>
16#include <unordered_map>
17
18namespace rotor {
19namespace wx {
20
42struct ROTOR_WX_API supervisor_wx_t : public supervisor_t {
43
46
48 template <typename Supervisor> using config_builder_t = supervisor_config_wx_builder_t<Supervisor>;
49
52
53 void start() noexcept override;
54 void shutdown() noexcept override;
55 void enqueue(message_ptr_t message) noexcept override;
56 // void on_timer_trigger(request_id_t timer_id) noexcept override;
57
59 inline system_context_wx_t *get_context() noexcept { return static_cast<system_context_wx_t *>(context); }
60
61 protected:
65 struct ROTOR_WX_API timer_t : public wxTimer {
68
71
74
77
79 virtual void Notify() noexcept override;
80 };
81
82 friend struct timer_t;
83
84 void do_start_timer(const pt::time_duration &interval, timer_handler_base_t &handler) noexcept override;
85 void do_cancel_timer(request_id_t timer_id) noexcept override;
86
88 using timer_ptr_t = std::unique_ptr<timer_t>;
89
91 using timers_map_t = std::unordered_map<request_id_t, timer_ptr_t>;
92
94 wxEvtHandler *handler;
95
97 timers_map_t timers_map;
98};
99
100} // namespace wx
101} // namespace rotor
Basic namespace for all rotor functionalities.
Definition rotor.hpp:21
intrusive_ptr_t< message_base_t > message_ptr_t
intrusive pointer for message
Definition message.h:118
std::size_t request_id_t
timer identifier type in the scope of the actor
Definition forward.hpp:34
boost::intrusive_ptr< T > intrusive_ptr_t
alias for intrusive pointer
Definition arc.hpp:27
supervisor is responsible for managing actors (workers) lifetime
Definition supervisor.h:69
Base class for timer handler.
Definition timer_handler.hpp:17
config builder for wx supervisor
Definition supervisor_config_wx.h:37
wx supervisor config, which holds a pointer to the "context window".
Definition supervisor_config_wx.h:18
timer structure, adoped for wx-supervisor needs.
Definition supervisor_wx.h:65
virtual void Notify() noexcept override
invokes shutdown_timer_trigger method if shutdown timer triggers
timer_handler_base_t * handler
non-owning pointer to timer handler
Definition supervisor_wx.h:70
intrusive_ptr_t< supervisor_wx_t > supervisor_ptr_t
alias for intrusive pointer for the supervisor
Definition supervisor_wx.h:67
timer_t(timer_handler_base_t *handler, supervisor_ptr_t &&sup_)
constructs timer from wx supervisor
supervisor_ptr_t sup
intrusive pointer to the supervisor
Definition supervisor_wx.h:73
delivers rotor-messages on top of wx event
Definition supervisor_wx.h:42
std::unique_ptr< timer_t > timer_ptr_t
unique pointer to timer
Definition supervisor_wx.h:88
std::unordered_map< request_id_t, timer_ptr_t > timers_map_t
timer id to timer pointer mapping type
Definition supervisor_wx.h:91
void start() noexcept override
thread-safe version of do_process
supervisor_wx_t(supervisor_config_wx_t &config)
constructs new supervisor from supervisor config
The wxWidgets system context, which holds a pointer to wxApp and root wx-supervisor.
Definition system_context_wx.h:28