mirror of
https://github.com/PabloMK7/citra.git
synced 2024-11-29 02:40:15 +00:00
kernel/server_session: Return a std::pair from CreateSessionPair()
Keeps the return type consistent with the function name. While we're at it, we can also reduce the amount of boilerplate involved with handling these by using structured bindings.
This commit is contained in:
parent
1afc2c72d6
commit
42535468c3
7 changed files with 25 additions and 30 deletions
|
@ -26,18 +26,17 @@ ResultVal<std::shared_ptr<ClientSession>> ClientPort::Connect() {
|
||||||
active_sessions++;
|
active_sessions++;
|
||||||
|
|
||||||
// Create a new session pair, let the created sessions inherit the parent port's HLE handler.
|
// Create a new session pair, let the created sessions inherit the parent port's HLE handler.
|
||||||
auto sessions = kernel.CreateSessionPair(server_port->GetName(), SharedFrom(this));
|
auto [server, client] = kernel.CreateSessionPair(server_port->GetName(), SharedFrom(this));
|
||||||
|
|
||||||
if (server_port->hle_handler)
|
if (server_port->hle_handler)
|
||||||
server_port->hle_handler->ClientConnected(
|
server_port->hle_handler->ClientConnected(server);
|
||||||
std::get<std::shared_ptr<ServerSession>>(sessions));
|
|
||||||
else
|
else
|
||||||
server_port->pending_sessions.push_back(std::get<std::shared_ptr<ServerSession>>(sessions));
|
server_port->pending_sessions.push_back(server);
|
||||||
|
|
||||||
// Wake the threads waiting on the ServerPort
|
// Wake the threads waiting on the ServerPort
|
||||||
server_port->WakeupAllWaitingThreads();
|
server_port->WakeupAllWaitingThreads();
|
||||||
|
|
||||||
return MakeResult(std::get<std::shared_ptr<ClientSession>>(sessions));
|
return MakeResult(client);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ClientPort::ConnectionClosed() {
|
void ClientPort::ConnectionClosed() {
|
||||||
|
|
|
@ -83,7 +83,8 @@ public:
|
||||||
std::function<void()> prepare_reschedule_callback, u32 system_mode);
|
std::function<void()> prepare_reschedule_callback, u32 system_mode);
|
||||||
~KernelSystem();
|
~KernelSystem();
|
||||||
|
|
||||||
using PortPair = std::tuple<std::shared_ptr<ServerPort>, std::shared_ptr<ClientPort>>;
|
using PortPair = std::pair<std::shared_ptr<ServerPort>, std::shared_ptr<ClientPort>>;
|
||||||
|
using SessionPair = std::pair<std::shared_ptr<ServerSession>, std::shared_ptr<ClientSession>>;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates an address arbiter.
|
* Creates an address arbiter.
|
||||||
|
@ -160,8 +161,8 @@ public:
|
||||||
* @param client_port Optional The ClientPort that spawned this session.
|
* @param client_port Optional The ClientPort that spawned this session.
|
||||||
* @return The created session tuple
|
* @return The created session tuple
|
||||||
*/
|
*/
|
||||||
std::tuple<std::shared_ptr<ServerSession>, std::shared_ptr<ClientSession>> CreateSessionPair(
|
SessionPair CreateSessionPair(const std::string& name = "Unknown",
|
||||||
const std::string& name = "Unknown", std::shared_ptr<ClientPort> client_port = nullptr);
|
std::shared_ptr<ClientPort> client_port = nullptr);
|
||||||
|
|
||||||
ResourceLimitList& ResourceLimit();
|
ResourceLimitList& ResourceLimit();
|
||||||
const ResourceLimitList& ResourceLimit() const;
|
const ResourceLimitList& ResourceLimit() const;
|
||||||
|
|
|
@ -120,8 +120,8 @@ ResultCode ServerSession::HandleSyncRequest(std::shared_ptr<Thread> thread) {
|
||||||
return RESULT_SUCCESS;
|
return RESULT_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::tuple<std::shared_ptr<ServerSession>, std::shared_ptr<ClientSession>>
|
KernelSystem::SessionPair KernelSystem::CreateSessionPair(const std::string& name,
|
||||||
KernelSystem::CreateSessionPair(const std::string& name, std::shared_ptr<ClientPort> port) {
|
std::shared_ptr<ClientPort> port) {
|
||||||
auto server_session = ServerSession::Create(*this, name + "_Server").Unwrap();
|
auto server_session = ServerSession::Create(*this, name + "_Server").Unwrap();
|
||||||
auto client_session{std::make_shared<ClientSession>(*this)};
|
auto client_session{std::make_shared<ClientSession>(*this)};
|
||||||
client_session->name = name + "_Client";
|
client_session->name = name + "_Client";
|
||||||
|
@ -134,7 +134,7 @@ KernelSystem::CreateSessionPair(const std::string& name, std::shared_ptr<ClientP
|
||||||
client_session->parent = parent;
|
client_session->parent = parent;
|
||||||
server_session->parent = parent;
|
server_session->parent = parent;
|
||||||
|
|
||||||
return std::make_tuple(std::move(server_session), std::move(client_session));
|
return std::make_pair(std::move(server_session), std::move(client_session));
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace Kernel
|
} // namespace Kernel
|
||||||
|
|
|
@ -1315,14 +1315,12 @@ ResultCode SVC::CreateSessionToPort(Handle* out_client_session, Handle client_po
|
||||||
}
|
}
|
||||||
|
|
||||||
ResultCode SVC::CreateSession(Handle* server_session, Handle* client_session) {
|
ResultCode SVC::CreateSession(Handle* server_session, Handle* client_session) {
|
||||||
auto sessions = kernel.CreateSessionPair();
|
auto [server, client] = kernel.CreateSessionPair();
|
||||||
|
|
||||||
std::shared_ptr<Process> current_process = kernel.GetCurrentProcess();
|
std::shared_ptr<Process> current_process = kernel.GetCurrentProcess();
|
||||||
|
|
||||||
auto& server = std::get<std::shared_ptr<ServerSession>>(sessions);
|
|
||||||
CASCADE_RESULT(*server_session, current_process->handle_table.Create(std::move(server)));
|
CASCADE_RESULT(*server_session, current_process->handle_table.Create(std::move(server)));
|
||||||
|
|
||||||
auto& client = std::get<std::shared_ptr<ClientSession>>(sessions);
|
|
||||||
CASCADE_RESULT(*client_session, current_process->handle_table.Create(std::move(client)));
|
CASCADE_RESULT(*client_session, current_process->handle_table.Create(std::move(client)));
|
||||||
|
|
||||||
LOG_TRACE(Kernel_SVC, "called");
|
LOG_TRACE(Kernel_SVC, "called");
|
||||||
|
|
|
@ -197,8 +197,7 @@ void File::OpenLinkFile(Kernel::HLERequestContext& ctx) {
|
||||||
using Kernel::ServerSession;
|
using Kernel::ServerSession;
|
||||||
IPC::RequestParser rp(ctx, 0x080C, 0, 0);
|
IPC::RequestParser rp(ctx, 0x080C, 0, 0);
|
||||||
IPC::RequestBuilder rb = rp.MakeBuilder(1, 2);
|
IPC::RequestBuilder rb = rp.MakeBuilder(1, 2);
|
||||||
auto sessions = system.Kernel().CreateSessionPair(GetName());
|
auto [server, client] = system.Kernel().CreateSessionPair(GetName());
|
||||||
auto server = std::get<std::shared_ptr<ServerSession>>(sessions);
|
|
||||||
ClientConnected(server);
|
ClientConnected(server);
|
||||||
|
|
||||||
FileSessionSlot* slot = GetSessionData(server);
|
FileSessionSlot* slot = GetSessionData(server);
|
||||||
|
@ -210,7 +209,7 @@ void File::OpenLinkFile(Kernel::HLERequestContext& ctx) {
|
||||||
slot->subfile = false;
|
slot->subfile = false;
|
||||||
|
|
||||||
rb.Push(RESULT_SUCCESS);
|
rb.Push(RESULT_SUCCESS);
|
||||||
rb.PushMoveObjects(std::get<std::shared_ptr<ClientSession>>(sessions));
|
rb.PushMoveObjects(client);
|
||||||
}
|
}
|
||||||
|
|
||||||
void File::OpenSubFile(Kernel::HLERequestContext& ctx) {
|
void File::OpenSubFile(Kernel::HLERequestContext& ctx) {
|
||||||
|
@ -244,8 +243,7 @@ void File::OpenSubFile(Kernel::HLERequestContext& ctx) {
|
||||||
|
|
||||||
using Kernel::ClientSession;
|
using Kernel::ClientSession;
|
||||||
using Kernel::ServerSession;
|
using Kernel::ServerSession;
|
||||||
auto sessions = system.Kernel().CreateSessionPair(GetName());
|
auto [server, client] = system.Kernel().CreateSessionPair(GetName());
|
||||||
auto server = std::get<std::shared_ptr<ServerSession>>(sessions);
|
|
||||||
ClientConnected(server);
|
ClientConnected(server);
|
||||||
|
|
||||||
FileSessionSlot* slot = GetSessionData(server);
|
FileSessionSlot* slot = GetSessionData(server);
|
||||||
|
@ -255,12 +253,11 @@ void File::OpenSubFile(Kernel::HLERequestContext& ctx) {
|
||||||
slot->subfile = true;
|
slot->subfile = true;
|
||||||
|
|
||||||
rb.Push(RESULT_SUCCESS);
|
rb.Push(RESULT_SUCCESS);
|
||||||
rb.PushMoveObjects(std::get<std::shared_ptr<ClientSession>>(sessions));
|
rb.PushMoveObjects(client);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::shared_ptr<Kernel::ClientSession> File::Connect() {
|
std::shared_ptr<Kernel::ClientSession> File::Connect() {
|
||||||
auto sessions = system.Kernel().CreateSessionPair(GetName());
|
auto [server, client] = system.Kernel().CreateSessionPair(GetName());
|
||||||
auto server = std::get<std::shared_ptr<Kernel::ServerSession>>(sessions);
|
|
||||||
ClientConnected(server);
|
ClientConnected(server);
|
||||||
|
|
||||||
FileSessionSlot* slot = GetSessionData(server);
|
FileSessionSlot* slot = GetSessionData(server);
|
||||||
|
@ -269,7 +266,7 @@ std::shared_ptr<Kernel::ClientSession> File::Connect() {
|
||||||
slot->size = backend->GetSize();
|
slot->size = backend->GetSize();
|
||||||
slot->subfile = false;
|
slot->subfile = false;
|
||||||
|
|
||||||
return std::get<std::shared_ptr<Kernel::ClientSession>>(sessions);
|
return client;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::size_t File::GetSessionFileOffset(std::shared_ptr<Kernel::ServerSession> session) {
|
std::size_t File::GetSessionFileOffset(std::shared_ptr<Kernel::ServerSession> session) {
|
||||||
|
|
|
@ -306,9 +306,9 @@ void FS_USER::OpenDirectory(Kernel::HLERequestContext& ctx) {
|
||||||
rb.Push(dir_res.Code());
|
rb.Push(dir_res.Code());
|
||||||
if (dir_res.Succeeded()) {
|
if (dir_res.Succeeded()) {
|
||||||
std::shared_ptr<Directory> directory = *dir_res;
|
std::shared_ptr<Directory> directory = *dir_res;
|
||||||
auto sessions = system.Kernel().CreateSessionPair(directory->GetName());
|
auto [server, client] = system.Kernel().CreateSessionPair(directory->GetName());
|
||||||
directory->ClientConnected(std::get<std::shared_ptr<ServerSession>>(sessions));
|
directory->ClientConnected(server);
|
||||||
rb.PushMoveObjects(std::get<std::shared_ptr<ClientSession>>(sessions));
|
rb.PushMoveObjects(client);
|
||||||
} else {
|
} else {
|
||||||
LOG_ERROR(Service_FS, "failed to get a handle for directory type={} size={} data={}",
|
LOG_ERROR(Service_FS, "failed to get a handle for directory type={} size={} data={}",
|
||||||
static_cast<u32>(dirname_type), dirname_size, dir_path.DebugStr());
|
static_cast<u32>(dirname_type), dirname_size, dir_path.DebugStr());
|
||||||
|
|
|
@ -24,8 +24,8 @@ TEST_CASE("HLERequestContext::PopulateFromIncomingCommandBuffer", "[core][kernel
|
||||||
Core::Timing timing;
|
Core::Timing timing;
|
||||||
Memory::MemorySystem memory;
|
Memory::MemorySystem memory;
|
||||||
Kernel::KernelSystem kernel(memory, timing, [] {}, 0);
|
Kernel::KernelSystem kernel(memory, timing, [] {}, 0);
|
||||||
auto session = std::get<std::shared_ptr<ServerSession>>(kernel.CreateSessionPair());
|
auto [server, client] = kernel.CreateSessionPair();
|
||||||
HLERequestContext context(kernel, std::move(session), nullptr);
|
HLERequestContext context(kernel, std::move(server), nullptr);
|
||||||
|
|
||||||
auto process = kernel.CreateProcess(kernel.CreateCodeSet("", 0));
|
auto process = kernel.CreateProcess(kernel.CreateCodeSet("", 0));
|
||||||
|
|
||||||
|
@ -236,8 +236,8 @@ TEST_CASE("HLERequestContext::WriteToOutgoingCommandBuffer", "[core][kernel]") {
|
||||||
Core::Timing timing;
|
Core::Timing timing;
|
||||||
Memory::MemorySystem memory;
|
Memory::MemorySystem memory;
|
||||||
Kernel::KernelSystem kernel(memory, timing, [] {}, 0);
|
Kernel::KernelSystem kernel(memory, timing, [] {}, 0);
|
||||||
auto session = std::get<std::shared_ptr<ServerSession>>(kernel.CreateSessionPair());
|
auto [server, client] = kernel.CreateSessionPair();
|
||||||
HLERequestContext context(kernel, std::move(session), nullptr);
|
HLERequestContext context(kernel, std::move(server), nullptr);
|
||||||
|
|
||||||
auto process = kernel.CreateProcess(kernel.CreateCodeSet("", 0));
|
auto process = kernel.CreateProcess(kernel.CreateCodeSet("", 0));
|
||||||
auto* input = context.CommandBuffer();
|
auto* input = context.CommandBuffer();
|
||||||
|
|
Loading…
Reference in a new issue