summaryrefslogtreecommitdiffstats
path: root/src/core/hle/kernel/session.h
blob: 7cd9c0d770ae32351ad011e2a4157dca0ba0f977 (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
// Copyright 2019 yuzu emulator team
// Licensed under GPLv2 or any later version
// Refer to the license.txt file included.

#pragma once

#include <memory>
#include <string>
#include <utility>

#include "core/hle/kernel/synchronization_object.h"

namespace Kernel {

class ClientSession;
class ServerSession;

/**
 * Parent structure to link the client and server endpoints of a session with their associated
 * client port.
 */
class Session final : public SynchronizationObject {
public:
    explicit Session(KernelCore& kernel);
    ~Session() override;

    using SessionPair = std::pair<std::shared_ptr<ClientSession>, std::shared_ptr<ServerSession>>;

    static SessionPair Create(KernelCore& kernel, std::string name = "Unknown");

    std::string GetName() const override {
        return name;
    }

    static constexpr HandleType HANDLE_TYPE = HandleType::Session;
    HandleType GetHandleType() const override {
        return HANDLE_TYPE;
    }

    bool ShouldWait(const Thread* thread) const override;

    bool IsSignaled() const override;

    void Acquire(Thread* thread) override;

    std::shared_ptr<ClientSession> Client() {
        if (auto result{client.lock()}) {
            return result;
        }
        return {};
    }

    std::shared_ptr<ServerSession> Server() {
        if (auto result{server.lock()}) {
            return result;
        }
        return {};
    }

private:
    std::string name;
    std::weak_ptr<ClientSession> client;
    std::weak_ptr<ServerSession> server;
};

} // namespace Kernel