~aleteoryx/muditaos

ref: 34ee674f371c0588f1c47bb0ce6fdda517e2ace0 muditaos/module-services/service-appmgr/model/ApplicationHandle.cpp -rw-r--r-- 2.6 KiB
34ee674f — Mateusz Piesta [MOS-939] Apply target update scripts 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
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
93
// Copyright (c) 2017-2021, Mudita Sp. z.o.o. All rights reserved.
// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md

#include "ApplicationHandle.hpp"

#include <apps-common/ApplicationLauncher.hpp>

namespace app::manager
{
    ApplicationHandle::ApplicationHandle(std::unique_ptr<app::ApplicationLauncher> &&_launcher)
        : launcher{std::move(_launcher)}
    {
        if (!launcher) {
            throw std::invalid_argument{"The application launcher must not be null."};
        }
    }

    auto ApplicationHandle::valid() const noexcept -> bool
    {
        return launcher && launcher->handle;
    }

    auto ApplicationHandle::name() const -> ApplicationName
    {
        return launcher->getName();
    }

    auto ApplicationHandle::state() const noexcept -> State
    {
        return valid() ? launcher->handle->getState() : State::NONE;
    }

    void ApplicationHandle::setState(State state) noexcept
    {
        if (valid()) {
            launcher->handle->setState(state);
        }
    }

    auto ApplicationHandle::preventsAutoLocking() const noexcept -> bool
    {
        return launcher->preventsAutoLocking();
    }

    auto ApplicationHandle::checkBlockClosing() const noexcept -> bool
    {
        return launcher->handle->getState() == ApplicationCommon::State::FINALIZING_CLOSE;
    }

    auto ApplicationHandle::closeable() const noexcept -> bool
    {
        return launcher->isCloseable() && !checkBlockClosing();
    }

    auto ApplicationHandle::started() const noexcept -> bool
    {
        const auto appState = state();
        return appState == State::ACTIVE_FORGROUND || appState == State::ACTIVE_BACKGROUND ||
               appState == State::ACTIVATING;
    }

    auto ApplicationHandle::handles(actions::ActionId action) const noexcept -> bool
    {
        const auto manifest = getManifest();
        return manifest.contains(action);
    }

    auto ApplicationHandle::actionFlag(actions::ActionId action) const noexcept -> actions::ActionFlag
    {
        const auto manifest = getManifest();
        return manifest.getActionFlag(action);
    }

    void ApplicationHandle::run(StatusIndicators statusIndicators, sys::Service *caller)
    {
        launcher->run(statusIndicators, caller);
    }

    void ApplicationHandle::runInBackground(StatusIndicators statusIndicators, sys::Service *caller)
    {
        launcher->runBackground(statusIndicators, caller);
    }

    void ApplicationHandle::close() noexcept
    {
        launcher->handle = nullptr;
    }

    auto ApplicationHandle::getManifest() const -> const ApplicationManifest &
    {
        return launcher->getManifest();
    }
} // namespace app::manager