From f40232adc97da95456b63c051e9cb75a9e001322 Mon Sep 17 00:00:00 2001 From: zhupengfei Date: Mon, 22 Jul 2019 20:27:35 +0800 Subject: [PATCH] service/sm: Add service name retrival based on client port ID This is for displaying the service names. This function is only used in the frontend, because Recorder which is in the Kernel cannot and should not have access to SM in the System. --- src/core/hle/service/sm/sm.cpp | 9 +++++++++ src/core/hle/service/sm/sm.h | 6 ++++++ 2 files changed, 15 insertions(+) diff --git a/src/core/hle/service/sm/sm.cpp b/src/core/hle/service/sm/sm.cpp index e37c72cc15..3caca2f93e 100644 --- a/src/core/hle/service/sm/sm.cpp +++ b/src/core/hle/service/sm/sm.cpp @@ -42,6 +42,7 @@ ResultVal> ServiceManager::RegisterService( auto [server_port, client_port] = system.Kernel().CreatePortPair(max_sessions, name); + registered_services_inverse.emplace(client_port->GetObjectId(), name); registered_services.emplace(std::move(name), std::move(client_port)); return MakeResult(std::move(server_port)); } @@ -65,4 +66,12 @@ ResultVal> ServiceManager::ConnectToServi return client_port->Connect(); } +std::string ServiceManager::GetServiceNameByPortId(u32 port) const { + if (registered_services_inverse.count(port)) { + return registered_services_inverse.at(port); + } + + return ""; +} + } // namespace Service::SM diff --git a/src/core/hle/service/sm/sm.h b/src/core/hle/service/sm/sm.h index dc26d88148..6e47fd1525 100644 --- a/src/core/hle/service/sm/sm.h +++ b/src/core/hle/service/sm/sm.h @@ -51,6 +51,8 @@ public: unsigned int max_sessions); ResultVal> GetServicePort(const std::string& name); ResultVal> ConnectToService(const std::string& name); + // For IPC Recorder + std::string GetServiceNameByPortId(u32 port) const; template std::shared_ptr GetService(const std::string& service_name) const { @@ -74,6 +76,10 @@ private: /// Map of registered services, retrieved using GetServicePort or ConnectToService. std::unordered_map> registered_services; + + // For IPC Recorder + /// client port Object id -> service name + std::unordered_map registered_services_inverse; }; } // namespace Service::SM