From 7b07e521cab33c54e68def947dff36f8536921a6 Mon Sep 17 00:00:00 2001 From: bunnei Date: Sun, 2 Feb 2020 00:38:22 -0500 Subject: [PATCH] hle: services: Use std::shared_ptr instead of copy by value. --- src/core/hle/service/am/am.cpp | 8 +++---- src/core/hle/service/am/applets/applets.cpp | 24 +++++++++---------- src/core/hle/service/am/applets/applets.h | 24 +++++++++---------- src/core/hle/service/am/applets/error.cpp | 2 +- .../service/am/applets/general_backend.cpp | 14 +++++------ .../hle/service/am/applets/profile_select.cpp | 4 ++-- .../service/am/applets/software_keyboard.cpp | 8 +++---- .../hle/service/am/applets/web_browser.cpp | 2 +- src/core/hle/service/filesystem/fsp_srv.cpp | 16 +++++++------ 9 files changed, 52 insertions(+), 50 deletions(-) diff --git a/src/core/hle/service/am/am.cpp b/src/core/hle/service/am/am.cpp index c1550013a..cc978713b 100644 --- a/src/core/hle/service/am/am.cpp +++ b/src/core/hle/service/am/am.cpp @@ -847,7 +847,7 @@ private: LOG_DEBUG(Service_AM, "called"); IPC::RequestParser rp{ctx}; - applet->GetBroker().PushNormalDataFromGame(*rp.PopIpcInterface()); + applet->GetBroker().PushNormalDataFromGame(rp.PopIpcInterface()); IPC::ResponseBuilder rb{ctx, 2}; rb.Push(RESULT_SUCCESS); @@ -867,14 +867,14 @@ private: IPC::ResponseBuilder rb{ctx, 2, 0, 1}; rb.Push(RESULT_SUCCESS); - rb.PushIpcInterface(std::move(*storage)); + rb.PushIpcInterface(std::move(storage)); } void PushInteractiveInData(Kernel::HLERequestContext& ctx) { LOG_DEBUG(Service_AM, "called"); IPC::RequestParser rp{ctx}; - applet->GetBroker().PushInteractiveDataFromGame(*rp.PopIpcInterface()); + applet->GetBroker().PushInteractiveDataFromGame(rp.PopIpcInterface()); ASSERT(applet->IsInitialized()); applet->ExecuteInteractive(); @@ -898,7 +898,7 @@ private: IPC::ResponseBuilder rb{ctx, 2, 0, 1}; rb.Push(RESULT_SUCCESS); - rb.PushIpcInterface(std::move(*storage)); + rb.PushIpcInterface(std::move(storage)); } void GetPopOutDataEvent(Kernel::HLERequestContext& ctx) { diff --git a/src/core/hle/service/am/applets/applets.cpp b/src/core/hle/service/am/applets/applets.cpp index 3e97ba218..c3261f3e6 100644 --- a/src/core/hle/service/am/applets/applets.cpp +++ b/src/core/hle/service/am/applets/applets.cpp @@ -50,7 +50,7 @@ AppletDataBroker::RawChannelData AppletDataBroker::PeekDataToAppletForDebug() co return {std::move(out_normal), std::move(out_interactive)}; } -std::unique_ptr AppletDataBroker::PopNormalDataToGame() { +std::shared_ptr AppletDataBroker::PopNormalDataToGame() { if (out_channel.empty()) return nullptr; @@ -60,7 +60,7 @@ std::unique_ptr AppletDataBroker::PopNormalDataToGame() { return out; } -std::unique_ptr AppletDataBroker::PopNormalDataToApplet() { +std::shared_ptr AppletDataBroker::PopNormalDataToApplet() { if (in_channel.empty()) return nullptr; @@ -69,7 +69,7 @@ std::unique_ptr AppletDataBroker::PopNormalDataToApplet() { return out; } -std::unique_ptr AppletDataBroker::PopInteractiveDataToGame() { +std::shared_ptr AppletDataBroker::PopInteractiveDataToGame() { if (out_interactive_channel.empty()) return nullptr; @@ -79,7 +79,7 @@ std::unique_ptr AppletDataBroker::PopInteractiveDataToGame() { return out; } -std::unique_ptr AppletDataBroker::PopInteractiveDataToApplet() { +std::shared_ptr AppletDataBroker::PopInteractiveDataToApplet() { if (in_interactive_channel.empty()) return nullptr; @@ -88,21 +88,21 @@ std::unique_ptr AppletDataBroker::PopInteractiveDataToApplet() { return out; } -void AppletDataBroker::PushNormalDataFromGame(IStorage storage) { - in_channel.push_back(std::make_unique(storage)); +void AppletDataBroker::PushNormalDataFromGame(std::shared_ptr&& storage) { + in_channel.emplace_back(std::move(storage)); } -void AppletDataBroker::PushNormalDataFromApplet(IStorage storage) { - out_channel.push_back(std::make_unique(storage)); +void AppletDataBroker::PushNormalDataFromApplet(std::shared_ptr&& storage) { + out_channel.emplace_back(std::move(storage)); pop_out_data_event.writable->Signal(); } -void AppletDataBroker::PushInteractiveDataFromGame(IStorage storage) { - in_interactive_channel.push_back(std::make_unique(storage)); +void AppletDataBroker::PushInteractiveDataFromGame(std::shared_ptr&& storage) { + in_interactive_channel.emplace_back(std::move(storage)); } -void AppletDataBroker::PushInteractiveDataFromApplet(IStorage storage) { - out_interactive_channel.push_back(std::make_unique(storage)); +void AppletDataBroker::PushInteractiveDataFromApplet(std::shared_ptr&& storage) { + out_interactive_channel.emplace_back(std::move(storage)); pop_interactive_out_data_event.writable->Signal(); } diff --git a/src/core/hle/service/am/applets/applets.h b/src/core/hle/service/am/applets/applets.h index 16e61fc6f..e75be86a2 100644 --- a/src/core/hle/service/am/applets/applets.h +++ b/src/core/hle/service/am/applets/applets.h @@ -72,17 +72,17 @@ public: // Retrieves but does not pop the data sent to applet. RawChannelData PeekDataToAppletForDebug() const; - std::unique_ptr PopNormalDataToGame(); - std::unique_ptr PopNormalDataToApplet(); + std::shared_ptr PopNormalDataToGame(); + std::shared_ptr PopNormalDataToApplet(); - std::unique_ptr PopInteractiveDataToGame(); - std::unique_ptr PopInteractiveDataToApplet(); + std::shared_ptr PopInteractiveDataToGame(); + std::shared_ptr PopInteractiveDataToApplet(); - void PushNormalDataFromGame(IStorage storage); - void PushNormalDataFromApplet(IStorage storage); + void PushNormalDataFromGame(std::shared_ptr&& storage); + void PushNormalDataFromApplet(std::shared_ptr&& storage); - void PushInteractiveDataFromGame(IStorage storage); - void PushInteractiveDataFromApplet(IStorage storage); + void PushInteractiveDataFromGame(std::shared_ptr&& storage); + void PushInteractiveDataFromApplet(std::shared_ptr&& storage); void SignalStateChanged() const; @@ -94,16 +94,16 @@ private: // Queues are named from applet's perspective // PopNormalDataToApplet and PushNormalDataFromGame - std::deque> in_channel; + std::deque> in_channel; // PopNormalDataToGame and PushNormalDataFromApplet - std::deque> out_channel; + std::deque> out_channel; // PopInteractiveDataToApplet and PushInteractiveDataFromGame - std::deque> in_interactive_channel; + std::deque> in_interactive_channel; // PopInteractiveDataToGame and PushInteractiveDataFromApplet - std::deque> out_interactive_channel; + std::deque> out_interactive_channel; Kernel::EventPair state_changed_event; diff --git a/src/core/hle/service/am/applets/error.cpp b/src/core/hle/service/am/applets/error.cpp index e6c4e8b87..f12fd7f89 100644 --- a/src/core/hle/service/am/applets/error.cpp +++ b/src/core/hle/service/am/applets/error.cpp @@ -186,7 +186,7 @@ void Error::Execute() { void Error::DisplayCompleted() { complete = true; - broker.PushNormalDataFromApplet(IStorage{std::vector{}}); + broker.PushNormalDataFromApplet(std::make_shared(std::vector{})); broker.SignalStateChanged(); } diff --git a/src/core/hle/service/am/applets/general_backend.cpp b/src/core/hle/service/am/applets/general_backend.cpp index fe8400a15..104501ac5 100644 --- a/src/core/hle/service/am/applets/general_backend.cpp +++ b/src/core/hle/service/am/applets/general_backend.cpp @@ -20,7 +20,7 @@ namespace Service::AM::Applets { constexpr ResultCode ERROR_INVALID_PIN{ErrorModule::PCTL, 221}; static void LogCurrentStorage(AppletDataBroker& broker, std::string_view prefix) { - std::unique_ptr storage = broker.PopNormalDataToApplet(); + std::shared_ptr storage = broker.PopNormalDataToApplet(); for (; storage != nullptr; storage = broker.PopNormalDataToApplet()) { const auto data = storage->GetData(); LOG_INFO(Service_AM, @@ -148,7 +148,7 @@ void Auth::AuthFinished(bool successful) { std::vector out(sizeof(Return)); std::memcpy(out.data(), &return_, sizeof(Return)); - broker.PushNormalDataFromApplet(IStorage{std::move(out)}); + broker.PushNormalDataFromApplet(std::make_shared(std::move(out))); broker.SignalStateChanged(); } @@ -198,7 +198,7 @@ void PhotoViewer::Execute() { } void PhotoViewer::ViewFinished() { - broker.PushNormalDataFromApplet(IStorage{std::vector{}}); + broker.PushNormalDataFromApplet(std::make_shared(std::vector{})); broker.SignalStateChanged(); } @@ -234,8 +234,8 @@ void StubApplet::ExecuteInteractive() { LOG_WARNING(Service_AM, "called (STUBBED)"); LogCurrentStorage(broker, "ExecuteInteractive"); - broker.PushNormalDataFromApplet(IStorage{std::vector(0x1000)}); - broker.PushInteractiveDataFromApplet(IStorage{std::vector(0x1000)}); + broker.PushNormalDataFromApplet(std::make_shared(std::vector(0x1000))); + broker.PushInteractiveDataFromApplet(std::make_shared(std::vector(0x1000))); broker.SignalStateChanged(); } @@ -243,8 +243,8 @@ void StubApplet::Execute() { LOG_WARNING(Service_AM, "called (STUBBED)"); LogCurrentStorage(broker, "Execute"); - broker.PushNormalDataFromApplet(IStorage{std::vector(0x1000)}); - broker.PushInteractiveDataFromApplet(IStorage{std::vector(0x1000)}); + broker.PushNormalDataFromApplet(std::make_shared(std::vector(0x1000))); + broker.PushInteractiveDataFromApplet(std::make_shared(std::vector(0x1000))); broker.SignalStateChanged(); } diff --git a/src/core/hle/service/am/applets/profile_select.cpp b/src/core/hle/service/am/applets/profile_select.cpp index 91d00f72a..70cc23552 100644 --- a/src/core/hle/service/am/applets/profile_select.cpp +++ b/src/core/hle/service/am/applets/profile_select.cpp @@ -50,7 +50,7 @@ void ProfileSelect::ExecuteInteractive() { void ProfileSelect::Execute() { if (complete) { - broker.PushNormalDataFromApplet(IStorage{std::move(final_data)}); + broker.PushNormalDataFromApplet(std::make_shared(std::move(final_data))); return; } @@ -71,7 +71,7 @@ void ProfileSelect::SelectionComplete(std::optional uuid) { final_data = std::vector(sizeof(UserSelectionOutput)); std::memcpy(final_data.data(), &output, final_data.size()); - broker.PushNormalDataFromApplet(IStorage{std::move(final_data)}); + broker.PushNormalDataFromApplet(std::make_shared(std::move(final_data))); broker.SignalStateChanged(); } diff --git a/src/core/hle/service/am/applets/software_keyboard.cpp b/src/core/hle/service/am/applets/software_keyboard.cpp index 964c67202..54e63c138 100644 --- a/src/core/hle/service/am/applets/software_keyboard.cpp +++ b/src/core/hle/service/am/applets/software_keyboard.cpp @@ -102,7 +102,7 @@ void SoftwareKeyboard::ExecuteInteractive() { void SoftwareKeyboard::Execute() { if (complete) { - broker.PushNormalDataFromApplet(IStorage{std::move(final_data)}); + broker.PushNormalDataFromApplet(std::make_shared(std::move(final_data))); broker.SignalStateChanged(); return; } @@ -145,15 +145,15 @@ void SoftwareKeyboard::WriteText(std::optional text) { final_data = output_main; if (complete) { - broker.PushNormalDataFromApplet(IStorage{std::move(output_main)}); + broker.PushNormalDataFromApplet(std::make_shared(std::move(output_main))); broker.SignalStateChanged(); } else { - broker.PushInteractiveDataFromApplet(IStorage{std::move(output_sub)}); + broker.PushInteractiveDataFromApplet(std::make_shared(std::move(output_sub))); } } else { output_main[0] = 1; complete = true; - broker.PushNormalDataFromApplet(IStorage{std::move(output_main)}); + broker.PushNormalDataFromApplet(std::make_shared(std::move(output_main))); broker.SignalStateChanged(); } } diff --git a/src/core/hle/service/am/applets/web_browser.cpp b/src/core/hle/service/am/applets/web_browser.cpp index 05d6b3a19..12443c910 100644 --- a/src/core/hle/service/am/applets/web_browser.cpp +++ b/src/core/hle/service/am/applets/web_browser.cpp @@ -284,7 +284,7 @@ void WebBrowser::Finalize() { std::vector data(sizeof(WebCommonReturnValue)); std::memcpy(data.data(), &out, sizeof(WebCommonReturnValue)); - broker.PushNormalDataFromApplet(IStorage{std::move(data)}); + broker.PushNormalDataFromApplet(std::make_shared(std::move(data))); broker.SignalStateChanged(); if (!temporary_dir.empty() && FileUtil::IsDirectory(temporary_dir)) { diff --git a/src/core/hle/service/filesystem/fsp_srv.cpp b/src/core/hle/service/filesystem/fsp_srv.cpp index 55d62fc5e..e6811d5b5 100644 --- a/src/core/hle/service/filesystem/fsp_srv.cpp +++ b/src/core/hle/service/filesystem/fsp_srv.cpp @@ -420,7 +420,7 @@ public: return; } - IFile file(result.Unwrap()); + auto file = std::make_shared(result.Unwrap()); IPC::ResponseBuilder rb{ctx, 2, 0, 1}; rb.Push(RESULT_SUCCESS); @@ -445,7 +445,7 @@ public: return; } - IDirectory directory(result.Unwrap()); + auto directory = std::make_shared(result.Unwrap()); IPC::ResponseBuilder rb{ctx, 2, 0, 1}; rb.Push(RESULT_SUCCESS); @@ -794,8 +794,8 @@ void FSP_SRV::OpenFileSystemWithPatch(Kernel::HLERequestContext& ctx) { void FSP_SRV::OpenSdCardFileSystem(Kernel::HLERequestContext& ctx) { LOG_DEBUG(Service_FS, "called"); - IFileSystem filesystem(fsc.OpenSDMC().Unwrap(), - SizeGetter::FromStorageId(fsc, FileSys::StorageId::SdCard)); + auto filesystem = std::make_shared( + fsc.OpenSDMC().Unwrap(), SizeGetter::FromStorageId(fsc, FileSys::StorageId::SdCard)); IPC::ResponseBuilder rb{ctx, 2, 0, 1}; rb.Push(RESULT_SUCCESS); @@ -846,7 +846,8 @@ void FSP_SRV::OpenSaveDataFileSystem(Kernel::HLERequestContext& ctx) { id = FileSys::StorageId::NandSystem; } - IFileSystem filesystem(std::move(dir.Unwrap()), SizeGetter::FromStorageId(fsc, id)); + auto filesystem = + std::make_shared(std::move(dir.Unwrap()), SizeGetter::FromStorageId(fsc, id)); IPC::ResponseBuilder rb{ctx, 2, 0, 1}; rb.Push(RESULT_SUCCESS); @@ -898,7 +899,7 @@ void FSP_SRV::OpenDataStorageByCurrentProcess(Kernel::HLERequestContext& ctx) { return; } - IStorage storage(std::move(romfs.Unwrap())); + auto storage = std::make_shared(std::move(romfs.Unwrap())); IPC::ResponseBuilder rb{ctx, 2, 0, 1}; rb.Push(RESULT_SUCCESS); @@ -937,7 +938,8 @@ void FSP_SRV::OpenDataStorageByDataId(Kernel::HLERequestContext& ctx) { FileSys::PatchManager pm{title_id}; - IStorage storage(pm.PatchRomFS(std::move(data.Unwrap()), 0, FileSys::ContentRecordType::Data)); + auto storage = std::make_shared( + pm.PatchRomFS(std::move(data.Unwrap()), 0, FileSys::ContentRecordType::Data)); IPC::ResponseBuilder rb{ctx, 2, 0, 1}; rb.Push(RESULT_SUCCESS);