From 181646679c414ce4dd4bfb1e7d9c1a335c8073d9 Mon Sep 17 00:00:00 2001 From: Weiyi Wang Date: Fri, 12 Oct 2018 16:11:51 -0400 Subject: [PATCH] ServiceManager: pass down core reference --- src/core/core.cpp | 2 +- src/core/hle/service/service.cpp | 4 ++-- src/core/hle/service/service.h | 2 +- src/core/hle/service/sm/sm.cpp | 9 +++++---- src/core/hle/service/sm/sm.h | 6 +++++- src/core/hle/service/sm/srv.cpp | 10 +++++----- src/core/hle/service/sm/srv.h | 8 ++++++-- 7 files changed, 25 insertions(+), 16 deletions(-) diff --git a/src/core/core.cpp b/src/core/core.cpp index d5445b438..6ae8345d4 100644 --- a/src/core/core.cpp +++ b/src/core/core.cpp @@ -197,7 +197,7 @@ System::ResultStatus System::Init(EmuWindow& emu_window, u32 system_mode) { HW::Init(); kernel = std::make_unique(system_mode); - Service::Init(*this, service_manager); + Service::Init(*this); GDBStub::Init(); ResultStatus result = VideoCore::Init(emu_window); diff --git a/src/core/hle/service/service.cpp b/src/core/hle/service/service.cpp index 5755d0335..459629975 100644 --- a/src/core/hle/service/service.cpp +++ b/src/core/hle/service/service.cpp @@ -235,8 +235,8 @@ static bool AttemptLLE(const ServiceModuleInfo& service_module) { } /// Initialize ServiceManager -void Init(Core::System& core, std::shared_ptr& sm) { - SM::ServiceManager::InstallInterfaces(sm); +void Init(Core::System& core) { + SM::ServiceManager::InstallInterfaces(core); for (const auto& service_module : service_module_map) { if (!AttemptLLE(service_module) && service_module.init_function != nullptr) diff --git a/src/core/hle/service/service.h b/src/core/hle/service/service.h index 3a8634251..dbe6e207c 100644 --- a/src/core/hle/service/service.h +++ b/src/core/hle/service/service.h @@ -184,7 +184,7 @@ private: }; /// Initialize ServiceManager -void Init(Core::System& system, std::shared_ptr& sm); +void Init(Core::System& system); /// Shutdown ServiceManager void Shutdown(); diff --git a/src/core/hle/service/sm/sm.cpp b/src/core/hle/service/sm/sm.cpp index 588de7daa..cd3b4ee30 100644 --- a/src/core/hle/service/sm/sm.cpp +++ b/src/core/hle/service/sm/sm.cpp @@ -4,6 +4,7 @@ #include #include "common/assert.h" +#include "core/core.h" #include "core/hle/kernel/client_session.h" #include "core/hle/result.h" #include "core/hle/service/sm/sm.h" @@ -21,12 +22,12 @@ static ResultCode ValidateServiceName(const std::string& name) { return RESULT_SUCCESS; } -void ServiceManager::InstallInterfaces(std::shared_ptr self) { - ASSERT(self->srv_interface.expired()); +void ServiceManager::InstallInterfaces(Core::System& system) { + ASSERT(system.ServiceManager().srv_interface.expired()); - auto srv = std::make_shared(self); + auto srv = std::make_shared(system); srv->InstallAsNamedPort(); - self->srv_interface = srv; + system.ServiceManager().srv_interface = srv; } ResultVal> ServiceManager::RegisterService( diff --git a/src/core/hle/service/sm/sm.h b/src/core/hle/service/sm/sm.h index 9e9164a66..c0666aeec 100644 --- a/src/core/hle/service/sm/sm.h +++ b/src/core/hle/service/sm/sm.h @@ -14,6 +14,10 @@ #include "core/hle/result.h" #include "core/hle/service/service.h" +namespace Core { +class System; +} + namespace Kernel { class ClientSession; class SessionRequestHandler; @@ -39,7 +43,7 @@ constexpr ResultCode ERR_ALREADY_REGISTERED(ErrorDescription::AlreadyExists, Err class ServiceManager { public: - static void InstallInterfaces(std::shared_ptr self); + static void InstallInterfaces(Core::System& system); ResultVal> RegisterService(std::string name, unsigned int max_sessions); diff --git a/src/core/hle/service/sm/srv.cpp b/src/core/hle/service/sm/srv.cpp index ca723745f..83fb94418 100644 --- a/src/core/hle/service/sm/srv.cpp +++ b/src/core/hle/service/sm/srv.cpp @@ -5,6 +5,7 @@ #include #include "common/common_types.h" #include "common/logging/log.h" +#include "core/core.h" #include "core/hle/ipc.h" #include "core/hle/ipc_helpers.h" #include "core/hle/kernel/client_port.h" @@ -103,7 +104,7 @@ void SRV::GetServiceHandle(Kernel::HLERequestContext& ctx) { Kernel::HLERequestContext& ctx, Kernel::ThreadWakeupReason reason) { LOG_ERROR(Service_SRV, "called service={} wakeup", name); - auto client_port = service_manager->GetServicePort(name); + auto client_port = system.ServiceManager().GetServicePort(name); auto session = client_port.Unwrap()->Connect(); if (session.Succeeded()) { @@ -122,7 +123,7 @@ void SRV::GetServiceHandle(Kernel::HLERequestContext& ctx) { } }; - auto client_port = service_manager->GetServicePort(name); + auto client_port = system.ServiceManager().GetServicePort(name); if (client_port.Failed()) { if (wait_until_available && client_port.Code() == ERR_SERVICE_NOT_REGISTERED) { LOG_INFO(Service_SRV, "called service={} delayed", name); @@ -223,7 +224,7 @@ void SRV::RegisterService(Kernel::HLERequestContext& ctx) { std::string name(name_buf.data(), std::min(name_len, name_buf.size())); - auto port = service_manager->RegisterService(name, max_sessions); + auto port = system.ServiceManager().RegisterService(name, max_sessions); if (port.Failed()) { IPC::RequestBuilder rb = rp.MakeBuilder(1, 0); @@ -243,8 +244,7 @@ void SRV::RegisterService(Kernel::HLERequestContext& ctx) { rb.PushMoveObjects(port.Unwrap()); } -SRV::SRV(std::shared_ptr service_manager) - : ServiceFramework("srv:", 4), service_manager(std::move(service_manager)) { +SRV::SRV(Core::System& system) : ServiceFramework("srv:", 4), system(system) { static const FunctionInfo functions[] = { {0x00010002, &SRV::RegisterClient, "RegisterClient"}, {0x00020000, &SRV::EnableNotification, "EnableNotification"}, diff --git a/src/core/hle/service/sm/srv.h b/src/core/hle/service/sm/srv.h index 066d00eac..02d72ec49 100644 --- a/src/core/hle/service/sm/srv.h +++ b/src/core/hle/service/sm/srv.h @@ -8,6 +8,10 @@ #include "core/hle/kernel/kernel.h" #include "core/hle/service/service.h" +namespace Core { +class System; +} + namespace Kernel { class HLERequestContext; class Semaphore; @@ -18,7 +22,7 @@ namespace Service::SM { /// Interface to "srv:" service class SRV final : public ServiceFramework { public: - explicit SRV(std::shared_ptr service_manager); + explicit SRV(Core::System& system); ~SRV(); private: @@ -30,7 +34,7 @@ private: void PublishToSubscriber(Kernel::HLERequestContext& ctx); void RegisterService(Kernel::HLERequestContext& ctx); - std::shared_ptr service_manager; + Core::System& system; Kernel::SharedPtr notification_semaphore; std::unordered_map> get_service_handle_delayed_map;