2016-05-22 18:22:49 +02:00
|
|
|
// Copyright 2016 Citra Emulator Project
|
|
|
|
// Licensed under GPLv2 or any later version
|
|
|
|
// Refer to the license.txt file included.
|
|
|
|
|
2016-05-22 19:30:13 +02:00
|
|
|
#include <tuple>
|
2016-05-22 18:22:49 +02:00
|
|
|
#include "common/assert.h"
|
2016-05-22 19:30:13 +02:00
|
|
|
#include "core/hle/kernel/client_port.h"
|
2017-06-23 08:57:05 +02:00
|
|
|
#include "core/hle/kernel/errors.h"
|
2018-08-02 04:40:00 +02:00
|
|
|
#include "core/hle/kernel/object.h"
|
2016-09-21 08:52:38 +02:00
|
|
|
#include "core/hle/kernel/server_port.h"
|
2017-06-23 08:57:05 +02:00
|
|
|
#include "core/hle/kernel/server_session.h"
|
2016-05-22 18:22:49 +02:00
|
|
|
#include "core/hle/kernel/thread.h"
|
|
|
|
|
|
|
|
namespace Kernel {
|
|
|
|
|
2020-12-22 07:36:53 +01:00
|
|
|
ServerPort::ServerPort(KernelCore& kernel) : KSynchronizationObject{kernel} {}
|
2018-08-28 18:30:33 +02:00
|
|
|
ServerPort::~ServerPort() = default;
|
2016-05-22 18:22:49 +02:00
|
|
|
|
2019-11-25 02:15:51 +01:00
|
|
|
ResultVal<std::shared_ptr<ServerSession>> ServerPort::Accept() {
|
2017-06-23 08:57:05 +02:00
|
|
|
if (pending_sessions.empty()) {
|
2018-10-24 20:23:36 +02:00
|
|
|
return ERR_NOT_FOUND;
|
2017-06-23 08:57:05 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
auto session = std::move(pending_sessions.back());
|
|
|
|
pending_sessions.pop_back();
|
|
|
|
return MakeResult(std::move(session));
|
|
|
|
}
|
|
|
|
|
2019-11-25 02:15:51 +01:00
|
|
|
void ServerPort::AppendPendingSession(std::shared_ptr<ServerSession> pending_session) {
|
2019-03-11 15:28:16 +01:00
|
|
|
pending_sessions.push_back(std::move(pending_session));
|
2020-12-22 07:36:53 +01:00
|
|
|
if (pending_sessions.size() == 1) {
|
|
|
|
NotifyAvailable();
|
|
|
|
}
|
2016-05-22 18:22:49 +02:00
|
|
|
}
|
|
|
|
|
2020-02-11 22:36:39 +01:00
|
|
|
bool ServerPort::IsSignaled() const {
|
|
|
|
return !pending_sessions.empty();
|
|
|
|
}
|
|
|
|
|
2019-04-06 07:36:50 +02:00
|
|
|
ServerPort::PortPair ServerPort::CreatePortPair(KernelCore& kernel, u32 max_sessions,
|
|
|
|
std::string name) {
|
2019-11-25 02:15:51 +01:00
|
|
|
std::shared_ptr<ServerPort> server_port = std::make_shared<ServerPort>(kernel);
|
|
|
|
std::shared_ptr<ClientPort> client_port = std::make_shared<ClientPort>(kernel);
|
2016-05-22 18:22:49 +02:00
|
|
|
|
|
|
|
server_port->name = name + "_Server";
|
|
|
|
client_port->name = name + "_Client";
|
|
|
|
client_port->server_port = server_port;
|
|
|
|
client_port->max_sessions = max_sessions;
|
|
|
|
client_port->active_sessions = 0;
|
|
|
|
|
2019-04-06 07:36:50 +02:00
|
|
|
return std::make_pair(std::move(server_port), std::move(client_port));
|
2016-05-22 18:22:49 +02:00
|
|
|
}
|
|
|
|
|
2018-01-20 08:48:02 +01:00
|
|
|
} // namespace Kernel
|