bolar_2 backup
This commit is contained in:
42
main/schedule/reminder_service.h
Normal file
42
main/schedule/reminder_service.h
Normal file
@@ -0,0 +1,42 @@
|
||||
#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
|
||||
Reference in New Issue
Block a user