bolar_2 backup
This commit is contained in:
64
main/schedule/alarm_service.h
Normal file
64
main/schedule/alarm_service.h
Normal file
@@ -0,0 +1,64 @@
|
||||
#pragma once
|
||||
|
||||
#include "core/task_stack_budget.h"
|
||||
#include "ports/event_publisher.h"
|
||||
#include "schedule/alarm_schedule.h"
|
||||
#include "schedule/alarm_store.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 AlarmService final {
|
||||
public:
|
||||
explicit AlarmService(IAlarmStore& store) : store_(store) {}
|
||||
|
||||
bool Initialize(
|
||||
IEventPublisher& publisher,
|
||||
IScheduleEventSink& event_sink);
|
||||
void Stop();
|
||||
|
||||
bool Set(const AlarmEntry& alarm);
|
||||
void Delete(int32_t id);
|
||||
bool Sync(const AlarmList& alarms);
|
||||
void SetToneIndices(
|
||||
int8_t set_tone_index,
|
||||
int8_t wake_tone_index);
|
||||
int8_t wake_tone_index() const
|
||||
{
|
||||
return wake_tone_index_.load();
|
||||
}
|
||||
uint64_t NextWakeupDelayUs() const;
|
||||
|
||||
private:
|
||||
static void TaskEntry(void* context);
|
||||
void Run();
|
||||
bool SaveLocked();
|
||||
static bool MakeCalendar(
|
||||
int64_t epoch_seconds,
|
||||
CalendarMinute* calendar);
|
||||
|
||||
IAlarmStore& store_;
|
||||
IEventPublisher* publisher_ = nullptr;
|
||||
IScheduleEventSink* event_sink_ = nullptr;
|
||||
mutable SemaphoreHandle_t mutex_ = nullptr;
|
||||
mutable StaticSemaphore_t mutex_control_{};
|
||||
AlarmSchedule schedule_;
|
||||
std::atomic<int8_t> set_tone_index_{-1};
|
||||
std::atomic<int8_t> wake_tone_index_{-1};
|
||||
std::atomic<bool> running_{false};
|
||||
TaskHandle_t task_ = nullptr;
|
||||
StaticTask_t task_control_{};
|
||||
std::array<
|
||||
StackType_t,
|
||||
task_stack_budget::kAlarmServiceBytes> task_stack_{};
|
||||
};
|
||||
|
||||
} // namespace borla
|
||||
Reference in New Issue
Block a user