~aleteoryx/muditaos

ref: c77a104f3d781b7fb93773be5a2b5af6b97b2a8c muditaos/products/PurePhone/alarms/PureAlarmHandler.cpp -rw-r--r-- 1.4 KiB
c77a104f — Maciej Gibowicz [BH-1991] Creating a new application "What`s new" 1 year, 8 months 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