aboutsummaryrefslogtreecommitdiff
path: root/src/core/hle/applets/applet.cpp
blob: f237898e6cc697ad78a85a7962d915f6fa45e161 (plain) (blame)
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
// Copyright 2015 Citra Emulator Project
// Licensed under GPLv2 or any later version
// Refer to the license.txt file included.

#include <cstddef>
#include <memory>
#include <type_traits>
#include <utility>
#include "common/assert.h"
#include "common/common_types.h"
#include "core/core.h"
#include "core/core_timing.h"
#include "core/hle/applets/applet.h"
#include "core/hle/result.h"

namespace HLE::Applets {

bool Applet::IsRunning() const {
    return is_running;
}

bool Applet::IsActive() const {
    return is_active;
}

Result Applet::ReceiveParameter(const Service::APT::MessageParameter& parameter) {
    switch (parameter.signal) {
    case Service::APT::SignalType::Wakeup: {
        Result result = Start(parameter);
        if (!result.IsError()) {
            is_active = true;
        }
        return result;
    }
    case Service::APT::SignalType::WakeupByCancel:
        return Finalize();
    default:
        return ReceiveParameterImpl(parameter);
    }
}

void Applet::SendParameter(const Service::APT::MessageParameter& parameter) {
    if (auto locked = manager.lock()) {
        locked->CancelAndSendParameter(parameter);
    } else {
        LOG_ERROR(Service_APT, "called after destructing applet manager");
    }
}

void Applet::CloseApplet(std::shared_ptr<Kernel::Object> object, const std::vector<u8>& buffer) {
    if (auto locked = manager.lock()) {
        locked->PrepareToCloseLibraryApplet(true, false, false);
        locked->CloseLibraryApplet(std::move(object), buffer);
    } else {
        LOG_ERROR(Service_APT, "called after destructing applet manager");
    }

    is_active = false;
    is_running = false;
}

} // namespace HLE::Applets