mirror of
https://git.h3cjp.net/H3cJP/yuzu.git
synced 2024-11-15 14:22:59 +00:00
Merge pull request #4665 from lioncash/sm-kernel
service/sm: Eliminate dependency on the global system instance
This commit is contained in:
commit
9bdca01c27
|
@ -178,7 +178,7 @@ struct System::Impl {
|
||||||
arp_manager.ResetAll();
|
arp_manager.ResetAll();
|
||||||
|
|
||||||
telemetry_session = std::make_unique<Core::TelemetrySession>();
|
telemetry_session = std::make_unique<Core::TelemetrySession>();
|
||||||
service_manager = std::make_shared<Service::SM::ServiceManager>();
|
service_manager = std::make_shared<Service::SM::ServiceManager>(kernel);
|
||||||
|
|
||||||
Service::Init(service_manager, system);
|
Service::Init(service_manager, system);
|
||||||
GDBStub::DeferStart();
|
GDBStub::DeferStart();
|
||||||
|
|
|
@ -19,7 +19,7 @@ constexpr ResultCode ERR_ALREADY_REGISTERED(ErrorModule::SM, 4);
|
||||||
constexpr ResultCode ERR_INVALID_NAME(ErrorModule::SM, 6);
|
constexpr ResultCode ERR_INVALID_NAME(ErrorModule::SM, 6);
|
||||||
constexpr ResultCode ERR_SERVICE_NOT_REGISTERED(ErrorModule::SM, 7);
|
constexpr ResultCode ERR_SERVICE_NOT_REGISTERED(ErrorModule::SM, 7);
|
||||||
|
|
||||||
ServiceManager::ServiceManager() = default;
|
ServiceManager::ServiceManager(Kernel::KernelCore& kernel_) : kernel{kernel_} {}
|
||||||
ServiceManager::~ServiceManager() = default;
|
ServiceManager::~ServiceManager() = default;
|
||||||
|
|
||||||
void ServiceManager::InvokeControlRequest(Kernel::HLERequestContext& context) {
|
void ServiceManager::InvokeControlRequest(Kernel::HLERequestContext& context) {
|
||||||
|
@ -27,11 +27,11 @@ void ServiceManager::InvokeControlRequest(Kernel::HLERequestContext& context) {
|
||||||
}
|
}
|
||||||
|
|
||||||
static ResultCode ValidateServiceName(const std::string& name) {
|
static ResultCode ValidateServiceName(const std::string& name) {
|
||||||
if (name.size() <= 0 || name.size() > 8) {
|
if (name.empty() || name.size() > 8) {
|
||||||
LOG_ERROR(Service_SM, "Invalid service name! service={}", name);
|
LOG_ERROR(Service_SM, "Invalid service name! service={}", name);
|
||||||
return ERR_INVALID_NAME;
|
return ERR_INVALID_NAME;
|
||||||
}
|
}
|
||||||
if (name.find('\0') != std::string::npos) {
|
if (name.rfind('\0') != std::string::npos) {
|
||||||
LOG_ERROR(Service_SM, "A non null terminated service was passed");
|
LOG_ERROR(Service_SM, "A non null terminated service was passed");
|
||||||
return ERR_INVALID_NAME;
|
return ERR_INVALID_NAME;
|
||||||
}
|
}
|
||||||
|
@ -48,8 +48,8 @@ void ServiceManager::InstallInterfaces(std::shared_ptr<ServiceManager> self,
|
||||||
self->controller_interface = std::make_unique<Controller>();
|
self->controller_interface = std::make_unique<Controller>();
|
||||||
}
|
}
|
||||||
|
|
||||||
ResultVal<std::shared_ptr<Kernel::ServerPort>> ServiceManager::RegisterService(
|
ResultVal<std::shared_ptr<Kernel::ServerPort>> ServiceManager::RegisterService(std::string name,
|
||||||
std::string name, unsigned int max_sessions) {
|
u32 max_sessions) {
|
||||||
|
|
||||||
CASCADE_CODE(ValidateServiceName(name));
|
CASCADE_CODE(ValidateServiceName(name));
|
||||||
|
|
||||||
|
@ -58,7 +58,6 @@ ResultVal<std::shared_ptr<Kernel::ServerPort>> ServiceManager::RegisterService(
|
||||||
return ERR_ALREADY_REGISTERED;
|
return ERR_ALREADY_REGISTERED;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto& kernel = Core::System::GetInstance().Kernel();
|
|
||||||
auto [server_port, client_port] =
|
auto [server_port, client_port] =
|
||||||
Kernel::ServerPort::CreatePortPair(kernel, max_sessions, name);
|
Kernel::ServerPort::CreatePortPair(kernel, max_sessions, name);
|
||||||
|
|
||||||
|
|
|
@ -48,11 +48,11 @@ class ServiceManager {
|
||||||
public:
|
public:
|
||||||
static void InstallInterfaces(std::shared_ptr<ServiceManager> self, Kernel::KernelCore& kernel);
|
static void InstallInterfaces(std::shared_ptr<ServiceManager> self, Kernel::KernelCore& kernel);
|
||||||
|
|
||||||
ServiceManager();
|
explicit ServiceManager(Kernel::KernelCore& kernel_);
|
||||||
~ServiceManager();
|
~ServiceManager();
|
||||||
|
|
||||||
ResultVal<std::shared_ptr<Kernel::ServerPort>> RegisterService(std::string name,
|
ResultVal<std::shared_ptr<Kernel::ServerPort>> RegisterService(std::string name,
|
||||||
unsigned int max_sessions);
|
u32 max_sessions);
|
||||||
ResultCode UnregisterService(const std::string& name);
|
ResultCode UnregisterService(const std::string& name);
|
||||||
ResultVal<std::shared_ptr<Kernel::ClientPort>> GetServicePort(const std::string& name);
|
ResultVal<std::shared_ptr<Kernel::ClientPort>> GetServicePort(const std::string& name);
|
||||||
ResultVal<std::shared_ptr<Kernel::ClientSession>> ConnectToService(const std::string& name);
|
ResultVal<std::shared_ptr<Kernel::ClientSession>> ConnectToService(const std::string& name);
|
||||||
|
@ -79,6 +79,9 @@ private:
|
||||||
|
|
||||||
/// Map of registered services, retrieved using GetServicePort or ConnectToService.
|
/// Map of registered services, retrieved using GetServicePort or ConnectToService.
|
||||||
std::unordered_map<std::string, std::shared_ptr<Kernel::ClientPort>> registered_services;
|
std::unordered_map<std::string, std::shared_ptr<Kernel::ClientPort>> registered_services;
|
||||||
|
|
||||||
|
/// Kernel context
|
||||||
|
Kernel::KernelCore& kernel;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace Service::SM
|
} // namespace Service::SM
|
||||||
|
|
Loading…
Reference in a new issue