From 2e614ce08f56f4c49d8070e69ecdb44e2cb9f1c1 Mon Sep 17 00:00:00 2001 From: Liam Date: Sun, 11 Feb 2024 20:28:51 -0500 Subject: am: rewrite IStorageAccessor, ITransferStorageAccessor --- src/core/CMakeLists.txt | 4 +- .../hle/service/am/service/storage_accessor.cpp | 68 ++++++++++++++++ src/core/hle/service/am/service/storage_accessor.h | 38 +++++++++ src/core/hle/service/am/storage.cpp | 2 +- src/core/hle/service/am/storage_accessor.cpp | 90 ---------------------- src/core/hle/service/am/storage_accessor.h | 37 --------- 6 files changed, 109 insertions(+), 130 deletions(-) create mode 100644 src/core/hle/service/am/service/storage_accessor.cpp create mode 100644 src/core/hle/service/am/service/storage_accessor.h delete mode 100644 src/core/hle/service/am/storage_accessor.cpp delete mode 100644 src/core/hle/service/am/storage_accessor.h (limited to 'src/core') diff --git a/src/core/CMakeLists.txt b/src/core/CMakeLists.txt index 956207fcf..c2c08c2e9 100644 --- a/src/core/CMakeLists.txt +++ b/src/core/CMakeLists.txt @@ -475,14 +475,14 @@ add_library(core STATIC hle/service/am/service/process_winding_controller.h hle/service/am/service/self_controller.cpp hle/service/am/service/self_controller.h + hle/service/am/service/storage_accessor.cpp + hle/service/am/service/storage_accessor.h hle/service/am/service/system_applet_proxy.cpp hle/service/am/service/system_applet_proxy.h hle/service/am/system_buffer_manager.cpp hle/service/am/system_buffer_manager.h hle/service/am/spsm.cpp hle/service/am/spsm.h - hle/service/am/storage_accessor.cpp - hle/service/am/storage_accessor.h hle/service/am/storage.cpp hle/service/am/storage.h hle/service/am/window_controller.cpp diff --git a/src/core/hle/service/am/service/storage_accessor.cpp b/src/core/hle/service/am/service/storage_accessor.cpp new file mode 100644 index 000000000..84577fee4 --- /dev/null +++ b/src/core/hle/service/am/service/storage_accessor.cpp @@ -0,0 +1,68 @@ +// SPDX-FileCopyrightText: Copyright 2024 yuzu Emulator Project +// SPDX-License-Identifier: GPL-2.0-or-later + +#include "core/hle/kernel/k_transfer_memory.h" +#include "core/hle/service/am/library_applet_storage.h" +#include "core/hle/service/am/service/storage_accessor.h" +#include "core/hle/service/cmif_serialization.h" + +namespace Service::AM { + +IStorageAccessor::IStorageAccessor(Core::System& system_, + std::shared_ptr impl) + : ServiceFramework{system_, "IStorageAccessor"}, m_impl{std::move(impl)} { + static const FunctionInfo functions[] = { + {0, D<&IStorageAccessor::GetSize>, "GetSize"}, + {10, D<&IStorageAccessor::Write>, "Write"}, + {11, D<&IStorageAccessor::Read>, "Read"}, + }; + + RegisterHandlers(functions); +} + +IStorageAccessor::~IStorageAccessor() = default; + +Result IStorageAccessor::GetSize(Out out_size) { + LOG_DEBUG(Service_AM, "called"); + *out_size = m_impl->GetSize(); + R_SUCCEED(); +} + +Result IStorageAccessor::Write(InBuffer buffer, s64 offset) { + LOG_DEBUG(Service_AM, "called, offset={} size={}", offset, buffer.size()); + R_RETURN(m_impl->Write(offset, buffer.data(), buffer.size())); +} + +Result IStorageAccessor::Read(OutBuffer out_buffer, s64 offset) { + LOG_DEBUG(Service_AM, "called, offset={} size={}", offset, out_buffer.size()); + R_RETURN(m_impl->Read(offset, out_buffer.data(), out_buffer.size())); +} + +ITransferStorageAccessor::ITransferStorageAccessor(Core::System& system_, + std::shared_ptr impl) + : ServiceFramework{system_, "ITransferStorageAccessor"}, m_impl{std::move(impl)} { + static const FunctionInfo functions[] = { + {0, D<&ITransferStorageAccessor::GetSize>, "GetSize"}, + {1, D<&ITransferStorageAccessor::GetHandle>, "GetHandle"}, + }; + + RegisterHandlers(functions); +} + +ITransferStorageAccessor::~ITransferStorageAccessor() = default; + +Result ITransferStorageAccessor::GetSize(Out out_size) { + LOG_DEBUG(Service_AM, "called"); + *out_size = m_impl->GetSize(); + R_SUCCEED(); +} + +Result ITransferStorageAccessor::GetHandle(Out out_size, + OutCopyHandle out_handle) { + LOG_INFO(Service_AM, "called"); + *out_size = m_impl->GetSize(); + *out_handle = m_impl->GetHandle(); + R_SUCCEED(); +} + +} // namespace Service::AM diff --git a/src/core/hle/service/am/service/storage_accessor.h b/src/core/hle/service/am/service/storage_accessor.h new file mode 100644 index 000000000..1a01730e0 --- /dev/null +++ b/src/core/hle/service/am/service/storage_accessor.h @@ -0,0 +1,38 @@ +// SPDX-FileCopyrightText: Copyright 2024 yuzu Emulator Project +// SPDX-License-Identifier: GPL-2.0-or-later + +#pragma once + +#include "core/hle/service/am/library_applet_storage.h" +#include "core/hle/service/cmif_types.h" +#include "core/hle/service/service.h" + +namespace Service::AM { + +class IStorageAccessor final : public ServiceFramework { +public: + explicit IStorageAccessor(Core::System& system_, std::shared_ptr impl); + ~IStorageAccessor() override; + +private: + Result GetSize(Out out_size); + Result Write(InBuffer buffer, s64 offset); + Result Read(OutBuffer out_buffer, s64 offset); + + const std::shared_ptr m_impl; +}; + +class ITransferStorageAccessor final : public ServiceFramework { +public: + explicit ITransferStorageAccessor(Core::System& system_, + std::shared_ptr impl); + ~ITransferStorageAccessor() override; + +private: + Result GetSize(Out out_size); + Result GetHandle(Out out_size, OutCopyHandle out_handle); + + const std::shared_ptr m_impl; +}; + +} // namespace Service::AM diff --git a/src/core/hle/service/am/storage.cpp b/src/core/hle/service/am/storage.cpp index 4e82afd1c..12d95eebd 100644 --- a/src/core/hle/service/am/storage.cpp +++ b/src/core/hle/service/am/storage.cpp @@ -3,8 +3,8 @@ #include "core/hle/service/am/am_results.h" #include "core/hle/service/am/library_applet_storage.h" +#include "core/hle/service/am/service/storage_accessor.h" #include "core/hle/service/am/storage.h" -#include "core/hle/service/am/storage_accessor.h" #include "core/hle/service/ipc_helpers.h" namespace Service::AM { diff --git a/src/core/hle/service/am/storage_accessor.cpp b/src/core/hle/service/am/storage_accessor.cpp deleted file mode 100644 index a1184b065..000000000 --- a/src/core/hle/service/am/storage_accessor.cpp +++ /dev/null @@ -1,90 +0,0 @@ -// SPDX-FileCopyrightText: Copyright 2024 yuzu Emulator Project -// SPDX-License-Identifier: GPL-2.0-or-later - -#include "core/hle/kernel/k_transfer_memory.h" -#include "core/hle/service/am/am_results.h" -#include "core/hle/service/am/library_applet_storage.h" -#include "core/hle/service/am/storage_accessor.h" -#include "core/hle/service/ipc_helpers.h" - -namespace Service::AM { - -IStorageAccessor::IStorageAccessor(Core::System& system_, - std::shared_ptr impl_) - : ServiceFramework{system_, "IStorageAccessor"}, impl{std::move(impl_)} { - static const FunctionInfo functions[] = { - {0, &IStorageAccessor::GetSize, "GetSize"}, - {10, &IStorageAccessor::Write, "Write"}, - {11, &IStorageAccessor::Read, "Read"}, - }; - - RegisterHandlers(functions); -} - -IStorageAccessor::~IStorageAccessor() = default; - -void IStorageAccessor::GetSize(HLERequestContext& ctx) { - LOG_DEBUG(Service_AM, "called"); - - IPC::ResponseBuilder rb{ctx, 4}; - - rb.Push(ResultSuccess); - rb.Push(impl->GetSize()); -} - -void IStorageAccessor::Write(HLERequestContext& ctx) { - IPC::RequestParser rp{ctx}; - - const s64 offset{rp.Pop()}; - const auto data{ctx.ReadBuffer()}; - LOG_DEBUG(Service_AM, "called, offset={}, size={}", offset, data.size()); - - const auto res{impl->Write(offset, data.data(), data.size())}; - - IPC::ResponseBuilder rb{ctx, 2}; - rb.Push(res); -} - -void IStorageAccessor::Read(HLERequestContext& ctx) { - IPC::RequestParser rp{ctx}; - - const s64 offset{rp.Pop()}; - std::vector data(ctx.GetWriteBufferSize()); - - LOG_DEBUG(Service_AM, "called, offset={}, size={}", offset, data.size()); - - const auto res{impl->Read(offset, data.data(), data.size())}; - - ctx.WriteBuffer(data); - - IPC::ResponseBuilder rb{ctx, 2}; - rb.Push(res); -} - -ITransferStorageAccessor::ITransferStorageAccessor(Core::System& system_, - std::shared_ptr impl_) - : ServiceFramework{system_, "ITransferStorageAccessor"}, impl{std::move(impl_)} { - static const FunctionInfo functions[] = { - {0, &ITransferStorageAccessor::GetSize, "GetSize"}, - {1, &ITransferStorageAccessor::GetHandle, "GetHandle"}, - }; - - RegisterHandlers(functions); -} - -ITransferStorageAccessor::~ITransferStorageAccessor() = default; - -void ITransferStorageAccessor::GetSize(HLERequestContext& ctx) { - IPC::ResponseBuilder rb{ctx, 4}; - rb.Push(ResultSuccess); - rb.Push(impl->GetSize()); -} - -void ITransferStorageAccessor::GetHandle(HLERequestContext& ctx) { - IPC::ResponseBuilder rb{ctx, 4, 1}; - rb.Push(ResultSuccess); - rb.Push(impl->GetSize()); - rb.PushCopyObjects(impl->GetHandle()); -} - -} // namespace Service::AM diff --git a/src/core/hle/service/am/storage_accessor.h b/src/core/hle/service/am/storage_accessor.h deleted file mode 100644 index b9aa85a66..000000000 --- a/src/core/hle/service/am/storage_accessor.h +++ /dev/null @@ -1,37 +0,0 @@ -// SPDX-FileCopyrightText: Copyright 2024 yuzu Emulator Project -// SPDX-License-Identifier: GPL-2.0-or-later - -#pragma once - -#include "core/hle/service/am/storage.h" -#include "core/hle/service/service.h" - -namespace Service::AM { - -class IStorageAccessor final : public ServiceFramework { -public: - explicit IStorageAccessor(Core::System& system_, std::shared_ptr impl_); - ~IStorageAccessor() override; - -private: - void GetSize(HLERequestContext& ctx); - void Write(HLERequestContext& ctx); - void Read(HLERequestContext& ctx); - - const std::shared_ptr impl; -}; - -class ITransferStorageAccessor final : public ServiceFramework { -public: - explicit ITransferStorageAccessor(Core::System& system_, - std::shared_ptr impl_); - ~ITransferStorageAccessor() override; - -private: - void GetSize(HLERequestContext& ctx); - void GetHandle(HLERequestContext& ctx); - - const std::shared_ptr impl; -}; - -} // namespace Service::AM -- cgit v1.2.3