aboutsummaryrefslogtreecommitdiff
path: root/src/core/hle/kernel/k_port.h
blob: 698f794538b1be8bf04fb23b5e78af9f615f94f6 (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
63
64
65
66
67
68
69
70
71
72
73
74
75
// SPDX-FileCopyrightText: Copyright 2026 Eden Emulator Project
// SPDX-License-Identifier: GPL-3.0-or-later

// SPDX-FileCopyrightText: Copyright 2021 yuzu Emulator Project
// SPDX-License-Identifier: GPL-2.0-or-later

#pragma once

#include <string>

#include "common/common_types.h"
#include "core/hle/kernel/k_client_port.h"
#include "core/hle/kernel/k_server_port.h"
#include "core/hle/kernel/slab_helpers.h"
#include "core/hle/result.h"

namespace Kernel {

class KLightServerSession;
class KServerSession;

class KPort final : public KAutoObjectWithSlabHeapAndContainer<KPort, KAutoObjectWithList> {
    KERNEL_AUTOOBJECT_TRAITS(KPort, KAutoObject);

public:
    explicit KPort(KernelCore& kernel);
    ~KPort() override;

    static void PostDestroy(KernelCore& kernel, uintptr_t arg) {}

    void Initialize(KernelCore& kernel, s32 max_sessions, bool is_light, uintptr_t name);
    void OnClientClosed(KernelCore& kernel);
    void OnServerClosed(KernelCore& kernel);

    uintptr_t GetName() const {
        return m_name;
    }
    bool IsLight() const {
        return m_is_light;
    }

    bool IsServerClosed(KernelCore& kernel) const;

    Result EnqueueSession(KernelCore& kernel, KServerSession* session);
    Result EnqueueSession(KernelCore& kernel, KLightServerSession* session);

    KClientPort& GetClientPort() {
        return m_client;
    }
    KServerPort& GetServerPort() {
        return m_server;
    }
    const KClientPort& GetClientPort() const {
        return m_client;
    }
    const KServerPort& GetServerPort() const {
        return m_server;
    }

private:
    enum class State : u8 {
        Invalid = 0,
        Normal = 1,
        ClientClosed = 2,
        ServerClosed = 3,
    };

    KServerPort m_server;
    KClientPort m_client;
    uintptr_t m_name;
    State m_state{State::Invalid};
    bool m_is_light{};
};

} // namespace Kernel