#pragma once #include "ports/alert_ringer.h" #include "ports/audio_engine.h" #include "ports/event_publisher.h" #include "schedule/alarm_service.h" #include #include #include #include #include #include namespace borla { class AlertRinger final : public IAlertRinger { public: AlertRinger( IAudioEngine& audio, AlarmService& alarms) : audio_(audio), alarms_(alarms) { } void SetEventPublisher(IEventPublisher& publisher) { publisher_ = &publisher; } void Start(AlertKind kind) override; void Stop() override; private: static constexpr uint32_t kTaskStackDepth = 3072; static void TaskEntry(void* context); // The worker is created once and then parks on request_. A static task // control block and stack must not be recycled while the previous task is // still being torn down, so this worker is never deleted. bool EnsureWorker(); [[noreturn]] void Run(); void RunOneAlert(uint32_t generation); IAudioEngine& audio_; AlarmService& alarms_; IEventPublisher* publisher_ = nullptr; std::atomic running_{false}; std::atomic generation_{0}; std::atomic kind_{AlertKind::kReminder}; SemaphoreHandle_t request_ = nullptr; StaticSemaphore_t request_storage_{}; TaskHandle_t task_ = nullptr; StaticTask_t task_control_{}; std::array task_stack_{}; }; } // namespace borla