25 if (!pending_.exchange(
true, std::memory_order_acq_rel)) {
27 post_to_event_thread();
33 pending_.store(
false, std::memory_order_release);
38 return pending_.load(std::memory_order_acquire);
46 if (pending_.exchange(
false, std::memory_order_acq_rel)) {
52 std::atomic<bool> pending_{
false};
55 void post_to_event_thread() {}
62 : callback_(
std::move(callback)) {}
65 if (callback_) callback_();
69 std::function<void()> callback_;
99 std::vector<TimerEntry> timers_;
109 std::vector<std::pair<int, ActionCallback>> callbacks;
110 callbacks.reserve(listeners_.size());
111 for (
const auto& [
id, fn] : listeners_) {
112 callbacks.push_back({id, fn});
114 for (
auto& [
id, fn] : callbacks) {
115 if (fn && has_listener(
id)) fn(action);
122 listeners_.push_back({id, std::move(fn)});
129 std::remove_if(listeners_.begin(), listeners_.end(),
130 [
id](
auto& p) { return p.first == id; }),
135 std::vector<std::pair<int, ActionCallback>> listeners_;
138 bool has_listener(
int id)
const {
139 return std::any_of(listeners_.begin(), listeners_.end(),
140 [
id](
const auto& p) { return p.first == id; });
155 bool active_ =
false;
ActionBroadcaster — string-based action dispatch (for menu commands, etc.).
Definition coalesced_updater.hpp:103
int add_listener(ActionCallback fn)
Add a listener. Returns an ID for removal.
Definition coalesced_updater.hpp:120
std::function< void(std::string_view action)> ActionCallback
Definition coalesced_updater.hpp:105
void remove_listener(int id)
Remove a listener by ID.
Definition coalesced_updater.hpp:127
void send_action(std::string_view action)
Send an action to all listeners.
Definition coalesced_updater.hpp:108
void cancel_update()
Cancel a pending update.
Definition coalesced_updater.hpp:32
virtual ~CoalescedUpdater()=default
virtual void on_update()=0
Override this to handle the async update (runs on event thread).
void request_update()
Trigger an async update.
Definition coalesced_updater.hpp:24
CoalescedUpdater()=default
void process_pending()
Called by the event loop to process pending updates.
Definition coalesced_updater.hpp:45
bool update_pending() const
Whether an update is pending.
Definition coalesced_updater.hpp:37
void on_update() override
Override this to handle the async update (runs on event thread).
Definition coalesced_updater.hpp:64
LambdaCoalescedUpdater(std::function< void()> callback)
Definition coalesced_updater.hpp:61
void start_timer(int timer_id, int interval_ms)
Start a timer with the given ID and interval in milliseconds.
bool is_timer_running(int timer_id) const
Whether a timer is running.
virtual ~MultiTimer()=default
virtual void timer_callback(int timer_id)=0
Override to handle timer callbacks.
void stop_all_timers()
Stop all timers.
void stop_timer(int timer_id)
Stop a specific timer.
ScopedLowPowerModeDisabler(const ScopedLowPowerModeDisabler &)=delete
ScopedLowPowerModeDisabler()
ScopedLowPowerModeDisabler & operator=(const ScopedLowPowerModeDisabler &)=delete
~ScopedLowPowerModeDisabler()
Definition child_process_manager.hpp:18