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.
This commit is contained in:
parent
efd69e1315
commit
f40232adc9
@ -42,6 +42,7 @@ ResultVal<std::shared_ptr<Kernel::ServerPort>> 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<std::shared_ptr<Kernel::ClientSession>> 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
|
||||
|
@ -51,6 +51,8 @@ public:
|
||||
unsigned int max_sessions);
|
||||
ResultVal<std::shared_ptr<Kernel::ClientPort>> GetServicePort(const std::string& name);
|
||||
ResultVal<std::shared_ptr<Kernel::ClientSession>> ConnectToService(const std::string& name);
|
||||
// For IPC Recorder
|
||||
std::string GetServiceNameByPortId(u32 port) const;
|
||||
|
||||
template <typename T>
|
||||
std::shared_ptr<T> GetService(const std::string& service_name) const {
|
||||
@ -74,6 +76,10 @@ private:
|
||||
|
||||
/// Map of registered services, retrieved using GetServicePort or ConnectToService.
|
||||
std::unordered_map<std::string, std::shared_ptr<Kernel::ClientPort>> registered_services;
|
||||
|
||||
// For IPC Recorder
|
||||
/// client port Object id -> service name
|
||||
std::unordered_map<u32, std::string> registered_services_inverse;
|
||||
};
|
||||
|
||||
} // namespace Service::SM
|
||||
|
Loading…
Reference in New Issue
Block a user