~aleteoryx/muditaos

muditaos/products/BellHybrid/alarms/BellAlarmHandler.cpp -rw-r--r-- 3.2 KiB
a405cad6Aleteoryx trim readme 7 days ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
// Copyright (c) 2017-2024, Mudita Sp. z.o.o. All rights reserved.
// For licensing, see https://github.com/mudita/MuditaOS/blob/master/LICENSE.md

#include "BellAlarmHandler.hpp"
#include "src/actions/PlayAudioActions.hpp"
#include "src/actions/NotifyGUIAction.hpp"
#include "src/actions/FrontlightAction.hpp"
#include "src/actions/IgnoreKeysAction.hpp"
#include "src/actions/NotifyGUIBedtimeReminderAction.hpp"

namespace alarms
{
    BellAlarmHandler::BellAlarmHandler(Actions &&actions) : actions{std::move(actions)}
    {}

    bool BellAlarmHandler::handle(const AlarmEventRecord &record)
    {
        auto result{true};
        if (record.enabled) {
            for (const auto &action : actions) {
                result &= action->execute();
            }
        }
        return result;
    }

    bool BellAlarmHandler::handleOff([[maybe_unused]] const AlarmEventRecord &record)
    {
        auto result{true};
        for (const auto &action : actions) {
            result &= action->turnOff();
        }
        return result;
    }

    BellAlarmClockHandler::BellAlarmClockHandler(sys::Service *service) : BellAlarmHandler{getActions(service)}
    {}

    auto BellAlarmClockHandler::getActions(sys::Service *service) -> Actions
    {
        Actions actions;
        actions.emplace_back(factory::createAlarmToneAction(*service));
        actions.emplace_back(std::make_unique<NotifyGUIAction>(*service));
        actions.emplace_back(std::make_unique<FrontlightAction>(
            *service, FrontlightAction::Mode::LinearProgress, FrontlightAction::SettingsDependency::AlarmClock));
        return actions;
    }

    PreWakeUpChimeHandler::PreWakeUpChimeHandler(sys::Service *service) : BellAlarmHandler{getActions(service)}
    {}

    auto PreWakeUpChimeHandler::getActions(sys::Service *service) -> Actions
    {
        Actions actions;
        actions.emplace_back(factory::createPreWakeUpChimeAction(*service));
        actions.emplace_back(std::make_unique<IgnoreKeysAction>(*service));
        return actions;
    }

    PreWakeUpFrontlightHandler::PreWakeUpFrontlightHandler(sys::Service *service)
        : BellAlarmHandler(getActions(service))
    {}

    auto PreWakeUpFrontlightHandler::getActions(sys::Service *service) -> Actions
    {
        Actions actions;
        actions.emplace_back(std::make_unique<FrontlightAction>(
            *service, FrontlightAction::Mode::LinearProgress, FrontlightAction::SettingsDependency::Prewakeup));
        return actions;
    }

    SnoozeChimeHandler::SnoozeChimeHandler(sys::Service *service) : BellAlarmHandler{getActions(service)}
    {}

    auto SnoozeChimeHandler::getActions(sys::Service *service) -> Actions
    {
        Actions actions;
        actions.emplace_back(factory::createSnoozeChimeAction(*service));
        return actions;
    }

    BedtimeReminderHandler::BedtimeReminderHandler(sys::Service *service) : BellAlarmHandler{getActions(service)}
    {}

    auto BedtimeReminderHandler::getActions(sys::Service *service) -> Actions
    {
        Actions actions;
        actions.emplace_back(factory::createBedtimeChimeAction(*service));
        actions.emplace_back(std::make_unique<NotifyGUIBedtimeReminderAction>(*service));
        return actions;
    }
} // namespace alarms