From 69f16ba50e3c52a17405670b976ac4ba63f58021 Mon Sep 17 00:00:00 2001 From: Lioncash Date: Sun, 6 Oct 2019 13:02:23 -0400 Subject: hle/service: Replace global system instance calls with instance-based ones Migrates the HLE service code off the use of directly accessing the global system instance where trivially able to do so. This removes all usages of Core::CurrentProcess from the service code, only 8 occurrences of this function exist elsewhere. There's still quite a bit of "System::GetInstance()" being used, however this was able to replace a few instances. --- src/core/hle/service/bcat/module.cpp | 34 +++++++++++++++++++--------------- 1 file changed, 19 insertions(+), 15 deletions(-) (limited to 'src/core/hle/service/bcat/module.cpp') diff --git a/src/core/hle/service/bcat/module.cpp b/src/core/hle/service/bcat/module.cpp index 4c01bcd99..8931fb385 100644 --- a/src/core/hle/service/bcat/module.cpp +++ b/src/core/hle/service/bcat/module.cpp @@ -35,8 +35,7 @@ using BCATDigest = std::array; namespace { -u64 GetCurrentBuildID() { - const auto& id = Core::System::GetInstance().GetCurrentProcessBuildID(); +u64 GetCurrentBuildID(const Core::System::CurrentBuildProcessID& id) { u64 out{}; std::memcpy(&out, id.data(), sizeof(u64)); return out; @@ -125,7 +124,8 @@ private: class IBcatService final : public ServiceFramework { public: - IBcatService(Backend& backend) : ServiceFramework("IBcatService"), backend(backend) { + explicit IBcatService(Core::System& system_, Backend& backend_) + : ServiceFramework("IBcatService"), system{system_}, backend{backend_} { // clang-format off static const FunctionInfo functions[] = { {10100, &IBcatService::RequestSyncDeliveryCache, "RequestSyncDeliveryCache"}, @@ -163,7 +163,8 @@ private: void RequestSyncDeliveryCache(Kernel::HLERequestContext& ctx) { LOG_DEBUG(Service_BCAT, "called"); - backend.Synchronize({Core::CurrentProcess()->GetTitleID(), GetCurrentBuildID()}, + backend.Synchronize({system.CurrentProcess()->GetTitleID(), + GetCurrentBuildID(system.GetCurrentProcessBuildID())}, progress.at(static_cast(SyncType::Normal))); IPC::ResponseBuilder rb{ctx, 2, 0, 1}; @@ -179,7 +180,8 @@ private: LOG_DEBUG(Service_BCAT, "called, name={}", name); - backend.SynchronizeDirectory({Core::CurrentProcess()->GetTitleID(), GetCurrentBuildID()}, + backend.SynchronizeDirectory({system.CurrentProcess()->GetTitleID(), + GetCurrentBuildID(system.GetCurrentProcessBuildID())}, name, progress.at(static_cast(SyncType::Directory))); @@ -244,6 +246,7 @@ private: rb.Push(RESULT_SUCCESS); } + Core::System& system; Backend& backend; std::array(SyncType::Count)> progress{ @@ -257,7 +260,7 @@ void Module::Interface::CreateBcatService(Kernel::HLERequestContext& ctx) { IPC::ResponseBuilder rb{ctx, 2, 0, 1}; rb.Push(RESULT_SUCCESS); - rb.PushIpcInterface(*backend); + rb.PushIpcInterface(system, *backend); } class IDeliveryCacheFileService final : public ServiceFramework { @@ -539,7 +542,7 @@ void Module::Interface::CreateDeliveryCacheStorageService(Kernel::HLERequestCont IPC::ResponseBuilder rb{ctx, 2, 0, 1}; rb.Push(RESULT_SUCCESS); rb.PushIpcInterface( - fsc.GetBCATDirectory(Core::CurrentProcess()->GetTitleID())); + fsc.GetBCATDirectory(system.CurrentProcess()->GetTitleID())); } void Module::Interface::CreateDeliveryCacheStorageServiceWithApplicationId( @@ -565,22 +568,23 @@ std::unique_ptr CreateBackendFromSettings(DirectoryGetter getter) { return std::make_unique(std::move(getter)); } -Module::Interface::Interface(std::shared_ptr module, FileSystem::FileSystemController& fsc, - const char* name) - : ServiceFramework(name), fsc(fsc), module(std::move(module)), - backend(CreateBackendFromSettings([&fsc](u64 tid) { return fsc.GetBCATDirectory(tid); })) {} +Module::Interface::Interface(Core::System& system_, std::shared_ptr module_, + FileSystem::FileSystemController& fsc_, const char* name) + : ServiceFramework(name), fsc{fsc_}, module{std::move(module_)}, + backend{CreateBackendFromSettings([&fsc_](u64 tid) { return fsc_.GetBCATDirectory(tid); })}, + system{system_} {} Module::Interface::~Interface() = default; void InstallInterfaces(Core::System& system) { auto module = std::make_shared(); - std::make_shared(module, system.GetFileSystemController(), "bcat:a") + std::make_shared(system, module, system.GetFileSystemController(), "bcat:a") ->InstallAsService(system.ServiceManager()); - std::make_shared(module, system.GetFileSystemController(), "bcat:m") + std::make_shared(system, module, system.GetFileSystemController(), "bcat:m") ->InstallAsService(system.ServiceManager()); - std::make_shared(module, system.GetFileSystemController(), "bcat:u") + std::make_shared(system, module, system.GetFileSystemController(), "bcat:u") ->InstallAsService(system.ServiceManager()); - std::make_shared(module, system.GetFileSystemController(), "bcat:s") + std::make_shared(system, module, system.GetFileSystemController(), "bcat:s") ->InstallAsService(system.ServiceManager()); } -- cgit v1.2.3