diff --git a/src/core/hle/kernel/client_port.cpp b/src/core/hle/kernel/client_port.cpp index 873d6c5163..d4c91d529c 100644 --- a/src/core/hle/kernel/client_port.cpp +++ b/src/core/hle/kernel/client_port.cpp @@ -17,6 +17,10 @@ namespace Kernel { ClientPort::ClientPort(KernelCore& kernel) : Object{kernel} {} ClientPort::~ClientPort() = default; +SharedPtr ClientPort::GetServerPort() const { + return server_port; +} + ResultVal> ClientPort::Connect() { // Note: Threads do not wait for the server endpoint to call // AcceptSession before returning from this call. diff --git a/src/core/hle/kernel/client_port.h b/src/core/hle/kernel/client_port.h index f3dfebbb18..6cd607206d 100644 --- a/src/core/hle/kernel/client_port.h +++ b/src/core/hle/kernel/client_port.h @@ -30,6 +30,8 @@ public: return HANDLE_TYPE; } + SharedPtr GetServerPort() const; + /** * Creates a new Session pair, adds the created ServerSession to the associated ServerPort's * list of pending sessions, and signals the ServerPort, causing any threads diff --git a/src/core/hle/kernel/server_port.h b/src/core/hle/kernel/server_port.h index 62fb513490..e52f8245f1 100644 --- a/src/core/hle/kernel/server_port.h +++ b/src/core/hle/kernel/server_port.h @@ -11,6 +11,7 @@ #include "common/common_types.h" #include "core/hle/kernel/object.h" #include "core/hle/kernel/wait_object.h" +#include "core/hle/result.h" namespace Kernel { diff --git a/src/core/hle/service/sm/sm.h b/src/core/hle/service/sm/sm.h index da2c51082c..4f8145dda7 100644 --- a/src/core/hle/service/sm/sm.h +++ b/src/core/hle/service/sm/sm.h @@ -6,9 +6,12 @@ #include #include +#include #include +#include "core/hle/kernel/client_port.h" #include "core/hle/kernel/object.h" +#include "core/hle/kernel/server_port.h" #include "core/hle/result.h" #include "core/hle/service/service.h" @@ -48,6 +51,22 @@ public: ResultVal> GetServicePort(const std::string& name); ResultVal> ConnectToService(const std::string& name); + template + std::shared_ptr GetService(const std::string& service_name) const { + static_assert(std::is_base_of_v, + "Not a base of ServiceFrameworkBase"); + auto service = registered_services.find(service_name); + if (service == registered_services.end()) { + LOG_DEBUG(Service, "Can't find service: {}", service_name); + return nullptr; + } + auto port = service->second->GetServerPort(); + if (port == nullptr) { + return nullptr; + } + return std::static_pointer_cast(port->hle_handler); + } + void InvokeControlRequest(Kernel::HLERequestContext& context); private: