am: Refactor IStorage interface.
This commit is contained in:
parent
3557fa25d0
commit
84e895cdd6
|
@ -709,8 +709,34 @@ void ICommonStateGetter::SetCpuBoostMode(Kernel::HLERequestContext& ctx) {
|
||||||
apm_sys->SetCpuBoostMode(ctx);
|
apm_sys->SetCpuBoostMode(ctx);
|
||||||
}
|
}
|
||||||
|
|
||||||
IStorage::IStorage(std::vector<u8> buffer)
|
IStorageImpl::~IStorageImpl() = default;
|
||||||
: ServiceFramework("IStorage"), buffer(std::move(buffer)) {
|
|
||||||
|
class StorageDataImpl final : public IStorageImpl {
|
||||||
|
public:
|
||||||
|
explicit StorageDataImpl(std::vector<u8>&& buffer) : buffer{std::move(buffer)} {}
|
||||||
|
|
||||||
|
std::vector<u8>& GetData() override {
|
||||||
|
return buffer;
|
||||||
|
}
|
||||||
|
|
||||||
|
const std::vector<u8>& GetData() const override {
|
||||||
|
return buffer;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::size_t GetSize() const override {
|
||||||
|
return buffer.size();
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
std::vector<u8> buffer;
|
||||||
|
};
|
||||||
|
|
||||||
|
IStorage::IStorage(std::vector<u8>&& buffer)
|
||||||
|
: ServiceFramework("IStorage"), impl{std::make_shared<StorageDataImpl>(std::move(buffer))} {
|
||||||
|
Register();
|
||||||
|
}
|
||||||
|
|
||||||
|
void IStorage::Register() {
|
||||||
// clang-format off
|
// clang-format off
|
||||||
static const FunctionInfo functions[] = {
|
static const FunctionInfo functions[] = {
|
||||||
{0, &IStorage::Open, "Open"},
|
{0, &IStorage::Open, "Open"},
|
||||||
|
@ -723,8 +749,13 @@ IStorage::IStorage(std::vector<u8> buffer)
|
||||||
|
|
||||||
IStorage::~IStorage() = default;
|
IStorage::~IStorage() = default;
|
||||||
|
|
||||||
const std::vector<u8>& IStorage::GetData() const {
|
void IStorage::Open(Kernel::HLERequestContext& ctx) {
|
||||||
return buffer;
|
LOG_DEBUG(Service_AM, "called");
|
||||||
|
|
||||||
|
IPC::ResponseBuilder rb{ctx, 2, 0, 1};
|
||||||
|
|
||||||
|
rb.Push(RESULT_SUCCESS);
|
||||||
|
rb.PushIpcInterface<IStorageAccessor>(*this);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ICommonStateGetter::GetOperationMode(Kernel::HLERequestContext& ctx) {
|
void ICommonStateGetter::GetOperationMode(Kernel::HLERequestContext& ctx) {
|
||||||
|
@ -891,15 +922,6 @@ private:
|
||||||
std::shared_ptr<Applets::Applet> applet;
|
std::shared_ptr<Applets::Applet> applet;
|
||||||
};
|
};
|
||||||
|
|
||||||
void IStorage::Open(Kernel::HLERequestContext& ctx) {
|
|
||||||
LOG_DEBUG(Service_AM, "called");
|
|
||||||
|
|
||||||
IPC::ResponseBuilder rb{ctx, 2, 0, 1};
|
|
||||||
|
|
||||||
rb.Push(RESULT_SUCCESS);
|
|
||||||
rb.PushIpcInterface<IStorageAccessor>(*this);
|
|
||||||
}
|
|
||||||
|
|
||||||
IStorageAccessor::IStorageAccessor(IStorage& storage)
|
IStorageAccessor::IStorageAccessor(IStorage& storage)
|
||||||
: ServiceFramework("IStorageAccessor"), backing(storage) {
|
: ServiceFramework("IStorageAccessor"), backing(storage) {
|
||||||
// clang-format off
|
// clang-format off
|
||||||
|
@ -921,7 +943,7 @@ void IStorageAccessor::GetSize(Kernel::HLERequestContext& ctx) {
|
||||||
IPC::ResponseBuilder rb{ctx, 4};
|
IPC::ResponseBuilder rb{ctx, 4};
|
||||||
|
|
||||||
rb.Push(RESULT_SUCCESS);
|
rb.Push(RESULT_SUCCESS);
|
||||||
rb.Push(static_cast<u64>(backing.buffer.size()));
|
rb.Push(static_cast<u64>(backing.GetSize()));
|
||||||
}
|
}
|
||||||
|
|
||||||
void IStorageAccessor::Write(Kernel::HLERequestContext& ctx) {
|
void IStorageAccessor::Write(Kernel::HLERequestContext& ctx) {
|
||||||
|
@ -932,17 +954,17 @@ void IStorageAccessor::Write(Kernel::HLERequestContext& ctx) {
|
||||||
|
|
||||||
LOG_DEBUG(Service_AM, "called, offset={}, size={}", offset, data.size());
|
LOG_DEBUG(Service_AM, "called, offset={}, size={}", offset, data.size());
|
||||||
|
|
||||||
if (data.size() > backing.buffer.size() - offset) {
|
if (data.size() > backing.GetSize() - offset) {
|
||||||
LOG_ERROR(Service_AM,
|
LOG_ERROR(Service_AM,
|
||||||
"offset is out of bounds, backing_buffer_sz={}, data_size={}, offset={}",
|
"offset is out of bounds, backing_buffer_sz={}, data_size={}, offset={}",
|
||||||
backing.buffer.size(), data.size(), offset);
|
backing.GetSize(), data.size(), offset);
|
||||||
|
|
||||||
IPC::ResponseBuilder rb{ctx, 2};
|
IPC::ResponseBuilder rb{ctx, 2};
|
||||||
rb.Push(ERR_SIZE_OUT_OF_BOUNDS);
|
rb.Push(ERR_SIZE_OUT_OF_BOUNDS);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::memcpy(backing.buffer.data() + offset, data.data(), data.size());
|
std::memcpy(backing.GetData().data() + offset, data.data(), data.size());
|
||||||
|
|
||||||
IPC::ResponseBuilder rb{ctx, 2};
|
IPC::ResponseBuilder rb{ctx, 2};
|
||||||
rb.Push(RESULT_SUCCESS);
|
rb.Push(RESULT_SUCCESS);
|
||||||
|
@ -956,16 +978,16 @@ void IStorageAccessor::Read(Kernel::HLERequestContext& ctx) {
|
||||||
|
|
||||||
LOG_DEBUG(Service_AM, "called, offset={}, size={}", offset, size);
|
LOG_DEBUG(Service_AM, "called, offset={}, size={}", offset, size);
|
||||||
|
|
||||||
if (size > backing.buffer.size() - offset) {
|
if (size > backing.GetSize() - offset) {
|
||||||
LOG_ERROR(Service_AM, "offset is out of bounds, backing_buffer_sz={}, size={}, offset={}",
|
LOG_ERROR(Service_AM, "offset is out of bounds, backing_buffer_sz={}, size={}, offset={}",
|
||||||
backing.buffer.size(), size, offset);
|
backing.GetSize(), size, offset);
|
||||||
|
|
||||||
IPC::ResponseBuilder rb{ctx, 2};
|
IPC::ResponseBuilder rb{ctx, 2};
|
||||||
rb.Push(ERR_SIZE_OUT_OF_BOUNDS);
|
rb.Push(ERR_SIZE_OUT_OF_BOUNDS);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
ctx.WriteBuffer(backing.buffer.data() + offset, size);
|
ctx.WriteBuffer(backing.GetData().data() + offset, size);
|
||||||
|
|
||||||
IPC::ResponseBuilder rb{ctx, 2};
|
IPC::ResponseBuilder rb{ctx, 2};
|
||||||
rb.Push(RESULT_SUCCESS);
|
rb.Push(RESULT_SUCCESS);
|
||||||
|
@ -1031,7 +1053,7 @@ void ILibraryAppletCreator::CreateTransferMemoryStorage(Kernel::HLERequestContex
|
||||||
rp.SetCurrentOffset(3);
|
rp.SetCurrentOffset(3);
|
||||||
const auto handle{rp.Pop<Kernel::Handle>()};
|
const auto handle{rp.Pop<Kernel::Handle>()};
|
||||||
|
|
||||||
const auto transfer_mem =
|
auto transfer_mem =
|
||||||
system.CurrentProcess()->GetHandleTable().Get<Kernel::TransferMemory>(handle);
|
system.CurrentProcess()->GetHandleTable().Get<Kernel::TransferMemory>(handle);
|
||||||
|
|
||||||
if (transfer_mem == nullptr) {
|
if (transfer_mem == nullptr) {
|
||||||
|
@ -1047,7 +1069,7 @@ void ILibraryAppletCreator::CreateTransferMemoryStorage(Kernel::HLERequestContex
|
||||||
|
|
||||||
IPC::ResponseBuilder rb{ctx, 2, 0, 1};
|
IPC::ResponseBuilder rb{ctx, 2, 0, 1};
|
||||||
rb.Push(RESULT_SUCCESS);
|
rb.Push(RESULT_SUCCESS);
|
||||||
rb.PushIpcInterface(std::make_shared<IStorage>(std::move(memory)));
|
rb.PushIpcInterface<IStorage>(std::move(memory));
|
||||||
}
|
}
|
||||||
|
|
||||||
IApplicationFunctions::IApplicationFunctions(Core::System& system_)
|
IApplicationFunctions::IApplicationFunctions(Core::System& system_)
|
||||||
|
@ -1189,13 +1211,11 @@ void IApplicationFunctions::PopLaunchParameter(Kernel::HLERequestContext& ctx) {
|
||||||
u64 build_id{};
|
u64 build_id{};
|
||||||
std::memcpy(&build_id, build_id_full.data(), sizeof(u64));
|
std::memcpy(&build_id, build_id_full.data(), sizeof(u64));
|
||||||
|
|
||||||
const auto data =
|
auto data = backend->GetLaunchParameter({system.CurrentProcess()->GetTitleID(), build_id});
|
||||||
backend->GetLaunchParameter({system.CurrentProcess()->GetTitleID(), build_id});
|
|
||||||
|
|
||||||
if (data.has_value()) {
|
if (data.has_value()) {
|
||||||
IPC::ResponseBuilder rb{ctx, 2, 0, 1};
|
IPC::ResponseBuilder rb{ctx, 2, 0, 1};
|
||||||
rb.Push(RESULT_SUCCESS);
|
rb.Push(RESULT_SUCCESS);
|
||||||
rb.PushIpcInterface<AM::IStorage>(*data);
|
rb.PushIpcInterface<IStorage>(std::move(*data));
|
||||||
launch_popped_application_specific = true;
|
launch_popped_application_specific = true;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -1218,7 +1238,7 @@ void IApplicationFunctions::PopLaunchParameter(Kernel::HLERequestContext& ctx) {
|
||||||
std::vector<u8> buffer(sizeof(LaunchParameterAccountPreselectedUser));
|
std::vector<u8> buffer(sizeof(LaunchParameterAccountPreselectedUser));
|
||||||
std::memcpy(buffer.data(), ¶ms, buffer.size());
|
std::memcpy(buffer.data(), ¶ms, buffer.size());
|
||||||
|
|
||||||
rb.PushIpcInterface<AM::IStorage>(buffer);
|
rb.PushIpcInterface<IStorage>(std::move(buffer));
|
||||||
launch_popped_account_preselect = true;
|
launch_popped_account_preselect = true;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,7 +12,8 @@
|
||||||
|
|
||||||
namespace Kernel {
|
namespace Kernel {
|
||||||
class KernelCore;
|
class KernelCore;
|
||||||
}
|
class TransferMemory;
|
||||||
|
} // namespace Kernel
|
||||||
|
|
||||||
namespace Service::NVFlinger {
|
namespace Service::NVFlinger {
|
||||||
class NVFlinger;
|
class NVFlinger;
|
||||||
|
@ -188,19 +189,36 @@ private:
|
||||||
std::shared_ptr<AppletMessageQueue> msg_queue;
|
std::shared_ptr<AppletMessageQueue> msg_queue;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
class IStorageImpl {
|
||||||
|
public:
|
||||||
|
virtual ~IStorageImpl();
|
||||||
|
virtual std::vector<u8>& GetData() = 0;
|
||||||
|
virtual const std::vector<u8>& GetData() const = 0;
|
||||||
|
virtual std::size_t GetSize() const = 0;
|
||||||
|
};
|
||||||
|
|
||||||
class IStorage final : public ServiceFramework<IStorage> {
|
class IStorage final : public ServiceFramework<IStorage> {
|
||||||
public:
|
public:
|
||||||
explicit IStorage(std::vector<u8> buffer);
|
explicit IStorage(std::vector<u8>&& buffer);
|
||||||
~IStorage() override;
|
~IStorage() override;
|
||||||
|
|
||||||
const std::vector<u8>& GetData() const;
|
std::vector<u8>& GetData() {
|
||||||
|
return impl->GetData();
|
||||||
|
}
|
||||||
|
|
||||||
|
const std::vector<u8>& GetData() const {
|
||||||
|
return impl->GetData();
|
||||||
|
}
|
||||||
|
|
||||||
|
std::size_t GetSize() const {
|
||||||
|
return impl->GetSize();
|
||||||
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
void Register();
|
||||||
void Open(Kernel::HLERequestContext& ctx);
|
void Open(Kernel::HLERequestContext& ctx);
|
||||||
|
|
||||||
std::vector<u8> buffer;
|
std::shared_ptr<IStorageImpl> impl;
|
||||||
|
|
||||||
friend class IStorageAccessor;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
class IStorageAccessor final : public ServiceFramework<IStorageAccessor> {
|
class IStorageAccessor final : public ServiceFramework<IStorageAccessor> {
|
||||||
|
|
|
@ -186,7 +186,7 @@ void Error::Execute() {
|
||||||
|
|
||||||
void Error::DisplayCompleted() {
|
void Error::DisplayCompleted() {
|
||||||
complete = true;
|
complete = true;
|
||||||
broker.PushNormalDataFromApplet(IStorage{{}});
|
broker.PushNormalDataFromApplet(IStorage{std::vector<u8>{}});
|
||||||
broker.SignalStateChanged();
|
broker.SignalStateChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -148,7 +148,7 @@ void Auth::AuthFinished(bool successful) {
|
||||||
std::vector<u8> out(sizeof(Return));
|
std::vector<u8> out(sizeof(Return));
|
||||||
std::memcpy(out.data(), &return_, sizeof(Return));
|
std::memcpy(out.data(), &return_, sizeof(Return));
|
||||||
|
|
||||||
broker.PushNormalDataFromApplet(IStorage{out});
|
broker.PushNormalDataFromApplet(IStorage{std::move(out)});
|
||||||
broker.SignalStateChanged();
|
broker.SignalStateChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -198,7 +198,7 @@ void PhotoViewer::Execute() {
|
||||||
}
|
}
|
||||||
|
|
||||||
void PhotoViewer::ViewFinished() {
|
void PhotoViewer::ViewFinished() {
|
||||||
broker.PushNormalDataFromApplet(IStorage{{}});
|
broker.PushNormalDataFromApplet(IStorage{std::vector<u8>{}});
|
||||||
broker.SignalStateChanged();
|
broker.SignalStateChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -50,7 +50,7 @@ void ProfileSelect::ExecuteInteractive() {
|
||||||
|
|
||||||
void ProfileSelect::Execute() {
|
void ProfileSelect::Execute() {
|
||||||
if (complete) {
|
if (complete) {
|
||||||
broker.PushNormalDataFromApplet(IStorage{final_data});
|
broker.PushNormalDataFromApplet(IStorage{std::move(final_data)});
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -71,7 +71,7 @@ void ProfileSelect::SelectionComplete(std::optional<Common::UUID> uuid) {
|
||||||
|
|
||||||
final_data = std::vector<u8>(sizeof(UserSelectionOutput));
|
final_data = std::vector<u8>(sizeof(UserSelectionOutput));
|
||||||
std::memcpy(final_data.data(), &output, final_data.size());
|
std::memcpy(final_data.data(), &output, final_data.size());
|
||||||
broker.PushNormalDataFromApplet(IStorage{final_data});
|
broker.PushNormalDataFromApplet(IStorage{std::move(final_data)});
|
||||||
broker.SignalStateChanged();
|
broker.SignalStateChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -102,7 +102,7 @@ void SoftwareKeyboard::ExecuteInteractive() {
|
||||||
|
|
||||||
void SoftwareKeyboard::Execute() {
|
void SoftwareKeyboard::Execute() {
|
||||||
if (complete) {
|
if (complete) {
|
||||||
broker.PushNormalDataFromApplet(IStorage{final_data});
|
broker.PushNormalDataFromApplet(IStorage{std::move(final_data)});
|
||||||
broker.SignalStateChanged();
|
broker.SignalStateChanged();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -145,15 +145,15 @@ void SoftwareKeyboard::WriteText(std::optional<std::u16string> text) {
|
||||||
final_data = output_main;
|
final_data = output_main;
|
||||||
|
|
||||||
if (complete) {
|
if (complete) {
|
||||||
broker.PushNormalDataFromApplet(IStorage{output_main});
|
broker.PushNormalDataFromApplet(IStorage{std::move(output_main)});
|
||||||
broker.SignalStateChanged();
|
broker.SignalStateChanged();
|
||||||
} else {
|
} else {
|
||||||
broker.PushInteractiveDataFromApplet(IStorage{output_sub});
|
broker.PushInteractiveDataFromApplet(IStorage{std::move(output_sub)});
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
output_main[0] = 1;
|
output_main[0] = 1;
|
||||||
complete = true;
|
complete = true;
|
||||||
broker.PushNormalDataFromApplet(IStorage{output_main});
|
broker.PushNormalDataFromApplet(IStorage{std::move(output_main)});
|
||||||
broker.SignalStateChanged();
|
broker.SignalStateChanged();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -284,7 +284,7 @@ void WebBrowser::Finalize() {
|
||||||
std::vector<u8> data(sizeof(WebCommonReturnValue));
|
std::vector<u8> data(sizeof(WebCommonReturnValue));
|
||||||
std::memcpy(data.data(), &out, sizeof(WebCommonReturnValue));
|
std::memcpy(data.data(), &out, sizeof(WebCommonReturnValue));
|
||||||
|
|
||||||
broker.PushNormalDataFromApplet(IStorage{data});
|
broker.PushNormalDataFromApplet(IStorage{std::move(data)});
|
||||||
broker.SignalStateChanged();
|
broker.SignalStateChanged();
|
||||||
|
|
||||||
if (!temporary_dir.empty() && FileUtil::IsDirectory(temporary_dir)) {
|
if (!temporary_dir.empty() && FileUtil::IsDirectory(temporary_dir)) {
|
||||||
|
|
Loading…
Reference in a new issue