~aleteoryx/muditaos

ref: d38e5eb877fa0c70c110391b1269ffd4cbf25310 muditaos/products/PurePhone/alarms/PureAlarmHandler.cpp -rw-r--r-- 1.4 KiB
d38e5eb8 — Lefucjusz [MOS-000] Update Pure changelog 2 years 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
// Copyright (c) 2017-2021, Mudita Sp. z.o.o. All rights reserved.
// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md

#include "PureAlarmHandler.hpp"
#include "src/actions/AlarmRecordAction.hpp"
#include "src/actions/PlayAudioActions.hpp"
#include "src/actions/NotifyGUIAction.hpp"

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

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

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

    PureAlarmClockHandler::PureAlarmClockHandler(sys::Service *service) : PureAlarmHandler{getActions(service)}
    {}

    auto PureAlarmClockHandler::getActions(sys::Service *service) -> Actions
    {
        Actions actions;
        actions.emplace_back(std::make_unique<AlarmRecordAction>(*service));
        actions.emplace_back(std::make_unique<PlayToneAction>(*service));
        actions.emplace_back(std::make_unique<NotifyGUIAction>(*service));
        return actions;
    }
} // namespace alarms