blob: 15bf0d4fc270fe7fd33661ae6e37095ddd1fb06e (
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
|
// Copyright 2016 Citra Emulator Project
// Licensed under GPLv2 or any later version
// Refer to the license.txt file included.
#include "core/hle/kernel/hle_ipc.h"
#include "core/hle/kernel/k_client_port.h"
#include "core/hle/kernel/k_session.h"
#include "core/hle/kernel/object.h"
#include "core/hle/kernel/server_port.h"
#include "core/hle/kernel/svc_results.h"
namespace Kernel {
KClientPort::KClientPort(KernelCore& kernel) : KSynchronizationObject{kernel} {}
KClientPort::~KClientPort() = default;
void KClientPort::Initialize(s32 max_sessions_, std::string&& name_) {
max_sessions = max_sessions_;
name = std::move(name_);
}
std::shared_ptr<ServerPort> KClientPort::GetServerPort() const {
return server_port;
}
ResultVal<KClientSession*> KClientPort::Connect() {
if (num_sessions >= max_sessions) {
return ResultOutOfSessions;
}
num_sessions++;
auto* session = Kernel::KSession::Create(kernel);
session->Initialize(name + ":ClientPort");
if (server_port->HasHLEHandler()) {
server_port->GetHLEHandler()->ClientConnected(session);
} else {
server_port->AppendPendingSession(std::addressof(session->GetServerSession()));
}
return MakeResult(std::addressof(session->GetClientSession()));
}
void KClientPort::ConnectionClosed() {
if (num_sessions == 0) {
return;
}
--num_sessions;
}
void KClientPort::Destroy() {}
bool KClientPort::IsSignaled() const {
return num_sessions < max_sessions;
}
} // namespace Kernel
|