diff --git a/src/core/hle/kernel/client_port.cpp b/src/core/hle/kernel/client_port.cpp index e18d0d4e8..0c9628911 100644 --- a/src/core/hle/kernel/client_port.cpp +++ b/src/core/hle/kernel/client_port.cpp @@ -15,7 +15,7 @@ namespace Kernel { ClientPort::ClientPort() {} ClientPort::~ClientPort() {} -Kernel::SharedPtr ClientPort::CreateForHLE(u32 max_sessions, std::unique_ptr hle_interface) { +Kernel::SharedPtr ClientPort::CreateForHLE(u32 max_sessions, std::shared_ptr hle_interface) { SharedPtr client_port(new ClientPort); client_port->max_sessions = max_sessions; client_port->active_sessions = 0; @@ -35,12 +35,4 @@ void ClientPort::AddWaitingSession(SharedPtr server_session) { server_port->WakeupAllWaitingThreads(); } -ResultCode ClientPort::HandleSyncRequest() { - // Forward the request to the associated HLE interface if it exists - if (hle_interface != nullptr) - return hle_interface->HandleSyncRequest(); - - return RESULT_SUCCESS; -} - } // namespace diff --git a/src/core/hle/kernel/client_port.h b/src/core/hle/kernel/client_port.h index 1c7c7513d..269012194 100644 --- a/src/core/hle/kernel/client_port.h +++ b/src/core/hle/kernel/client_port.h @@ -30,19 +30,13 @@ public: * @param hle_interface Interface object that implements the commands of the service. * @returns ClientPort for the given HLE interface. */ - static Kernel::SharedPtr CreateForHLE(u32 max_sessions, std::unique_ptr hle_interface); + static Kernel::SharedPtr CreateForHLE(u32 max_sessions, std::shared_ptr hle_interface); /** * Adds the specified server session to the queue of pending sessions of the associated ServerPort * @param server_session Server session to add to the queue */ - virtual void AddWaitingSession(SharedPtr server_session); - - /** - * Handle a sync request from the emulated application. - * @returns ResultCode from the operation. - */ - ResultCode HandleSyncRequest(); + void AddWaitingSession(SharedPtr server_session); std::string GetTypeName() const override { return "ClientPort"; } std::string GetName() const override { return name; } @@ -54,7 +48,7 @@ public: u32 max_sessions; ///< Maximum number of simultaneous sessions the port can have u32 active_sessions; ///< Number of currently open sessions to this port std::string name; ///< Name of client port (optional) - std::unique_ptr hle_interface = nullptr; ///< HLE implementation of this port's request handler + std::shared_ptr hle_interface = nullptr; ///< HLE implementation of this port's request handler private: ClientPort(); diff --git a/src/core/hle/kernel/client_session.cpp b/src/core/hle/kernel/client_session.cpp index f1ad9b65b..22fa2ff03 100644 --- a/src/core/hle/kernel/client_session.cpp +++ b/src/core/hle/kernel/client_session.cpp @@ -8,6 +8,7 @@ #include "core/hle/kernel/client_session.h" #include "core/hle/kernel/server_session.h" #include "core/hle/kernel/kernel.h" +#include "core/hle/service/service.h" namespace Kernel { @@ -20,6 +21,7 @@ ResultVal> ClientSession::Create(SharedPtrname = std::move(name); client_session->server_session = server_session; client_session->client_port = client_port; + client_session->hle_helper = client_port->hle_interface; return MakeResult>(std::move(client_session)); } @@ -31,10 +33,9 @@ ResultCode ClientSession::HandleSyncRequest() { if (result.IsError()) return result; - // Tell the client port to handle the request in case it's an HLE service. - // The client port can be nullptr for port-less sessions (Like for example File and Directory sessions). - if (client_port != nullptr) - result = client_port->HandleSyncRequest(); + // If this ClientSession has an associated HLE helper, forward the request to it. + if (hle_helper != nullptr) + result = hle_helper->HandleSyncRequest(server_session); return result; } diff --git a/src/core/hle/kernel/client_session.h b/src/core/hle/kernel/client_session.h index 4fe9b4517..c2fc0d7dd 100644 --- a/src/core/hle/kernel/client_session.h +++ b/src/core/hle/kernel/client_session.h @@ -5,11 +5,16 @@ #pragma once #include +#include #include "common/common_types.h" #include "core/hle/kernel/kernel.h" +namespace Service { +class Interface; +} + namespace Kernel { class ClientPort; @@ -41,6 +46,7 @@ public: std::string name; ///< Name of client port (optional) SharedPtr server_session; ///< The server session associated with this client session. SharedPtr client_port; ///< The client port which this session is connected to. + std::shared_ptr hle_helper = nullptr; ///< HLE implementation of this port's request handler private: ClientSession(); diff --git a/src/core/hle/service/service.cpp b/src/core/hle/service/service.cpp index 93b33f021..7b1acfc8c 100644 --- a/src/core/hle/service/service.cpp +++ b/src/core/hle/service/service.cpp @@ -61,7 +61,9 @@ static std::string MakeFunctionString(const char* name, const char* port_name, c return function_string; } -ResultCode Interface::HandleSyncRequest() { +ResultCode Interface::HandleSyncRequest(Kernel::SharedPtr server_session) { + // TODO(Subv): Make use of the server_session in the HLE service handlers to distinguish which session triggered each command. + u32* cmd_buff = Kernel::GetCommandBuffer(); auto itr = m_functions.find(cmd_buff[0]); @@ -92,12 +94,12 @@ void Interface::Register(const FunctionInfo* functions, size_t n) { // Module interface static void AddNamedPort(Interface* interface_) { - auto client_port = Kernel::ClientPort::CreateForHLE(interface_->GetMaxSessions(), std::unique_ptr(interface_)); + auto client_port = Kernel::ClientPort::CreateForHLE(interface_->GetMaxSessions(), std::shared_ptr(interface_)); g_kernel_named_ports.emplace(interface_->GetPortName(), client_port); } void AddService(Interface* interface_) { - auto client_port = Kernel::ClientPort::CreateForHLE(interface_->GetMaxSessions(), std::unique_ptr(interface_)); + auto client_port = Kernel::ClientPort::CreateForHLE(interface_->GetMaxSessions(), std::shared_ptr(interface_)); g_srv_services.emplace(interface_->GetPortName(), client_port); } diff --git a/src/core/hle/service/service.h b/src/core/hle/service/service.h index 4d6356e2a..f92b42058 100644 --- a/src/core/hle/service/service.h +++ b/src/core/hle/service/service.h @@ -52,7 +52,7 @@ public: return "[UNKNOWN SERVICE PORT]"; } - ResultCode HandleSyncRequest(); + ResultCode HandleSyncRequest(Kernel::SharedPtr server_session); protected: /**