summaryrefslogtreecommitdiffstats
path: root/src/core/hle/kernel/k_port.h
blob: 68c8ed8df4a25b4665b9134796d1ad0599304afa (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
76
77
78
79
80
81
82
83
84
85
86
87
// Copyright 2021 yuzu Emulator Project
// Licensed under GPLv2 or any later version
// Refer to the license.txt file included.

#pragma once

#include <memory>
#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 KServerSession;

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

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

    static void PostDestroy([[maybe_unused]] uintptr_t arg) {}

    void Initialize(s32 max_sessions_, bool is_light_, const std::string& name_);
    void OnClientClosed();
    void OnServerClosed();

    bool IsLight() const {
        return is_light;
    }

    bool IsServerClosed() const;

    ResultCode EnqueueSession(KServerSession* session);

    KClientPort& GetClientPort() {
        return client;
    }
    KServerPort& GetServerPort() {
        return server;
    }
    const KClientPort& GetClientPort() const {
        return client;
    }
    const KServerPort& GetServerPort() const {
        return server;
    }

    // DEPRECATED

    friend class ServerPort;
    std::string GetTypeName() const override {
        return "Port";
    }
    std::string GetName() const override {
        return name;
    }

    HandleType GetHandleType() const override {
        return {};
    }

    void Finalize() override {}

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

private:
    KServerPort server;
    KClientPort client;
    State state{State::Invalid};
    bool is_light{};

    std::string name; ///< Name of client port (optional)
};

} // namespace Kernel