43 lines
1.0 KiB
C++
43 lines
1.0 KiB
C++
#pragma once
|
|
|
|
#include "ports/event_publisher.h"
|
|
#include "schedule/reminder_schedule.h"
|
|
#include "schedule/schedule_types.h"
|
|
|
|
#include <array>
|
|
#include <atomic>
|
|
#include <cstdint>
|
|
|
|
#include <freertos/FreeRTOS.h>
|
|
#include <freertos/semphr.h>
|
|
#include <freertos/task.h>
|
|
|
|
namespace borla {
|
|
|
|
class ReminderService final {
|
|
public:
|
|
bool Initialize(IEventPublisher& publisher);
|
|
void Stop();
|
|
bool Add(uint32_t duration_seconds);
|
|
void Cancel(TimerCancelScope scope);
|
|
size_t count() const;
|
|
uint64_t NextWakeupDelayUs() const;
|
|
|
|
private:
|
|
static constexpr uint32_t kTaskStackDepth = 2048;
|
|
static void TaskEntry(void* context);
|
|
void Run();
|
|
static uint64_t NowMs();
|
|
|
|
IEventPublisher* publisher_ = nullptr;
|
|
mutable SemaphoreHandle_t mutex_ = nullptr;
|
|
mutable StaticSemaphore_t mutex_control_{};
|
|
ReminderSchedule schedule_;
|
|
std::atomic<bool> running_{false};
|
|
TaskHandle_t task_ = nullptr;
|
|
StaticTask_t task_control_{};
|
|
std::array<StackType_t, kTaskStackDepth> task_stack_{};
|
|
};
|
|
|
|
} // namespace borla
|