From dd254c603d0ab6091203c9d29b62db8294b64fad Mon Sep 17 00:00:00 2001 From: Lioncash Date: Tue, 20 Nov 2018 11:49:47 -0500 Subject: [PATCH 1/3] am/applets: Relocate comments above the relevant data member in AppletDataBroker Avoids wonky wrapping and makes it nicer to read. --- src/core/hle/service/am/applets/applets.h | 29 ++++++++++++++--------- 1 file changed, 18 insertions(+), 11 deletions(-) diff --git a/src/core/hle/service/am/applets/applets.h b/src/core/hle/service/am/applets/applets.h index 136445649..eb54cd5ae 100644 --- a/src/core/hle/service/am/applets/applets.h +++ b/src/core/hle/service/am/applets/applets.h @@ -43,19 +43,26 @@ public: private: // Queues are named from applet's perspective - std::queue> - in_channel; // PopNormalDataToApplet and PushNormalDataFromGame - std::queue> - out_channel; // PopNormalDataToGame and PushNormalDataFromApplet - std::queue> - in_interactive_channel; // PopInteractiveDataToApplet and PushInteractiveDataFromGame - std::queue> - out_interactive_channel; // PopInteractiveDataToGame and PushInteractiveDataFromApplet + + // PopNormalDataToApplet and PushNormalDataFromGame + std::queue> in_channel; + + // PopNormalDataToGame and PushNormalDataFromApplet + std::queue> out_channel; + + // PopInteractiveDataToApplet and PushInteractiveDataFromGame + std::queue> in_interactive_channel; + + // PopInteractiveDataToGame and PushInteractiveDataFromApplet + std::queue> out_interactive_channel; Kernel::SharedPtr state_changed_event; - Kernel::SharedPtr pop_out_data_event; // Signaled on PushNormalDataFromApplet - Kernel::SharedPtr - pop_interactive_out_data_event; // Signaled on PushInteractiveDataFromApplet + + // Signaled on PushNormalDataFromApplet + Kernel::SharedPtr pop_out_data_event; + + // Signaled on PushInteractiveDataFromApplet + Kernel::SharedPtr pop_interactive_out_data_event; }; class Applet { From 8b4b560df55ba0db01539cc088149adc5b1ad564 Mon Sep 17 00:00:00 2001 From: Lioncash Date: Tue, 20 Nov 2018 11:51:54 -0500 Subject: [PATCH 2/3] am/applets: Replace includes with forward declarations where applicable Also resolve places where includes should have been provided, but weren't. --- src/core/hle/service/am/applets/applets.h | 6 ++++-- src/core/hle/service/am/applets/software_keyboard.h | 5 +++++ 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/src/core/hle/service/am/applets/applets.h b/src/core/hle/service/am/applets/applets.h index eb54cd5ae..9c1f068d4 100644 --- a/src/core/hle/service/am/applets/applets.h +++ b/src/core/hle/service/am/applets/applets.h @@ -4,14 +4,16 @@ #pragma once -#include #include #include #include "common/swap.h" -#include "core/hle/kernel/event.h" union ResultCode; +namespace Kernel { +class Event; +} + namespace Service::AM { class IStorage; diff --git a/src/core/hle/service/am/applets/software_keyboard.h b/src/core/hle/service/am/applets/software_keyboard.h index 16e1fff66..38cabcaec 100644 --- a/src/core/hle/service/am/applets/software_keyboard.h +++ b/src/core/hle/service/am/applets/software_keyboard.h @@ -4,7 +4,12 @@ #pragma once +#include +#include +#include + #include "common/common_funcs.h" +#include "common/swap.h" #include "core/hle/service/am/am.h" #include "core/hle/service/am/applets/applets.h" From 73b77489846989c8bccf9615ae75658d1ebc6f1d Mon Sep 17 00:00:00 2001 From: Lioncash Date: Tue, 20 Nov 2018 12:02:16 -0500 Subject: [PATCH 3/3] am/applets: Make the applet data broker part of the applet itself. The accessor should be doing just that, accessing, rather than retaining the lifetime of the data broker as well. --- src/core/hle/service/am/am.cpp | 20 +++++++--------- src/core/hle/service/am/applets/applets.cpp | 6 ++--- src/core/hle/service/am/applets/applets.h | 15 +++++++++--- .../service/am/applets/software_keyboard.cpp | 24 +++++++++---------- .../service/am/applets/software_keyboard.h | 2 +- 5 files changed, 36 insertions(+), 31 deletions(-) diff --git a/src/core/hle/service/am/am.cpp b/src/core/hle/service/am/am.cpp index fd14af1e7..9696db42b 100644 --- a/src/core/hle/service/am/am.cpp +++ b/src/core/hle/service/am/am.cpp @@ -532,8 +532,7 @@ void ICommonStateGetter::GetPerformanceMode(Kernel::HLERequestContext& ctx) { class ILibraryAppletAccessor final : public ServiceFramework { public: explicit ILibraryAppletAccessor(std::shared_ptr applet) - : ServiceFramework("ILibraryAppletAccessor"), applet(std::move(applet)), - broker(std::make_shared()) { + : ServiceFramework("ILibraryAppletAccessor"), applet(std::move(applet)) { // clang-format off static const FunctionInfo functions[] = { {0, &ILibraryAppletAccessor::GetAppletStateChangedEvent, "GetAppletStateChangedEvent"}, @@ -562,7 +561,7 @@ public: private: void GetAppletStateChangedEvent(Kernel::HLERequestContext& ctx) { - const auto event = broker->GetStateChangedEvent(); + const auto event = applet->GetBroker().GetStateChangedEvent(); event->Signal(); IPC::ResponseBuilder rb{ctx, 2, 1}; @@ -590,7 +589,7 @@ private: void Start(Kernel::HLERequestContext& ctx) { ASSERT(applet != nullptr); - applet->Initialize(broker); + applet->Initialize(); applet->Execute(); IPC::ResponseBuilder rb{ctx, 2}; @@ -601,7 +600,7 @@ private: void PushInData(Kernel::HLERequestContext& ctx) { IPC::RequestParser rp{ctx}; - broker->PushNormalDataFromGame(*rp.PopIpcInterface()); + applet->GetBroker().PushNormalDataFromGame(*rp.PopIpcInterface()); IPC::ResponseBuilder rb{ctx, 2}; rb.Push(RESULT_SUCCESS); @@ -612,7 +611,7 @@ private: void PopOutData(Kernel::HLERequestContext& ctx) { IPC::ResponseBuilder rb{ctx, 2, 0, 1}; - const auto storage = broker->PopNormalDataToGame(); + const auto storage = applet->GetBroker().PopNormalDataToGame(); if (storage == nullptr) { rb.Push(ERR_NO_DATA_IN_CHANNEL); return; @@ -626,7 +625,7 @@ private: void PushInteractiveInData(Kernel::HLERequestContext& ctx) { IPC::RequestParser rp{ctx}; - broker->PushInteractiveDataFromGame(*rp.PopIpcInterface()); + applet->GetBroker().PushInteractiveDataFromGame(*rp.PopIpcInterface()); ASSERT(applet->IsInitialized()); applet->ExecuteInteractive(); @@ -641,7 +640,7 @@ private: void PopInteractiveOutData(Kernel::HLERequestContext& ctx) { IPC::ResponseBuilder rb{ctx, 2, 0, 1}; - const auto storage = broker->PopInteractiveDataToGame(); + const auto storage = applet->GetBroker().PopInteractiveDataToGame(); if (storage == nullptr) { rb.Push(ERR_NO_DATA_IN_CHANNEL); return; @@ -656,7 +655,7 @@ private: void GetPopOutDataEvent(Kernel::HLERequestContext& ctx) { IPC::ResponseBuilder rb{ctx, 2, 1}; rb.Push(RESULT_SUCCESS); - rb.PushCopyObjects(broker->GetNormalDataEvent()); + rb.PushCopyObjects(applet->GetBroker().GetNormalDataEvent()); LOG_DEBUG(Service_AM, "called"); } @@ -664,13 +663,12 @@ private: void GetPopInteractiveOutDataEvent(Kernel::HLERequestContext& ctx) { IPC::ResponseBuilder rb{ctx, 2, 1}; rb.Push(RESULT_SUCCESS); - rb.PushCopyObjects(broker->GetInteractiveDataEvent()); + rb.PushCopyObjects(applet->GetBroker().GetInteractiveDataEvent()); LOG_DEBUG(Service_AM, "called"); } std::shared_ptr applet; - std::shared_ptr broker; }; void IStorage::Open(Kernel::HLERequestContext& ctx) { diff --git a/src/core/hle/service/am/applets/applets.cpp b/src/core/hle/service/am/applets/applets.cpp index 8adb81823..becbadd06 100644 --- a/src/core/hle/service/am/applets/applets.cpp +++ b/src/core/hle/service/am/applets/applets.cpp @@ -98,10 +98,8 @@ Applet::Applet() = default; Applet::~Applet() = default; -void Applet::Initialize(std::shared_ptr broker_) { - broker = std::move(broker_); - - const auto common = broker->PopNormalDataToApplet(); +void Applet::Initialize() { + const auto common = broker.PopNormalDataToApplet(); ASSERT(common != nullptr); const auto common_data = common->GetData(); diff --git a/src/core/hle/service/am/applets/applets.h b/src/core/hle/service/am/applets/applets.h index 9c1f068d4..f65ea119c 100644 --- a/src/core/hle/service/am/applets/applets.h +++ b/src/core/hle/service/am/applets/applets.h @@ -7,6 +7,7 @@ #include #include #include "common/swap.h" +#include "core/hle/kernel/kernel.h" union ResultCode; @@ -72,7 +73,7 @@ public: Applet(); virtual ~Applet(); - virtual void Initialize(std::shared_ptr broker); + virtual void Initialize(); virtual bool TransactionComplete() const = 0; virtual ResultCode GetStatus() const = 0; @@ -83,6 +84,14 @@ public: return initialized; } + AppletDataBroker& GetBroker() { + return broker; + } + + const AppletDataBroker& GetBroker() const { + return broker; + } + protected: struct CommonArguments { u32_le arguments_version; @@ -94,8 +103,8 @@ protected: }; static_assert(sizeof(CommonArguments) == 0x20, "CommonArguments has incorrect size."); - CommonArguments common_args; - std::shared_ptr broker; + CommonArguments common_args{}; + AppletDataBroker broker; bool initialized = false; }; diff --git a/src/core/hle/service/am/applets/software_keyboard.cpp b/src/core/hle/service/am/applets/software_keyboard.cpp index c4b76a515..981bdec51 100644 --- a/src/core/hle/service/am/applets/software_keyboard.cpp +++ b/src/core/hle/service/am/applets/software_keyboard.cpp @@ -42,21 +42,21 @@ SoftwareKeyboard::SoftwareKeyboard() = default; SoftwareKeyboard::~SoftwareKeyboard() = default; -void SoftwareKeyboard::Initialize(std::shared_ptr broker_) { +void SoftwareKeyboard::Initialize() { complete = false; initial_text.clear(); final_data.clear(); - Applet::Initialize(std::move(broker_)); + Applet::Initialize(); - const auto keyboard_config_storage = broker->PopNormalDataToApplet(); + const auto keyboard_config_storage = broker.PopNormalDataToApplet(); ASSERT(keyboard_config_storage != nullptr); const auto& keyboard_config = keyboard_config_storage->GetData(); ASSERT(keyboard_config.size() >= sizeof(KeyboardConfig)); std::memcpy(&config, keyboard_config.data(), sizeof(KeyboardConfig)); - const auto work_buffer_storage = broker->PopNormalDataToApplet(); + const auto work_buffer_storage = broker.PopNormalDataToApplet(); ASSERT(work_buffer_storage != nullptr); const auto& work_buffer = work_buffer_storage->GetData(); @@ -81,7 +81,7 @@ void SoftwareKeyboard::ExecuteInteractive() { if (complete) return; - const auto storage = broker->PopInteractiveDataToApplet(); + const auto storage = broker.PopInteractiveDataToApplet(); ASSERT(storage != nullptr); const auto data = storage->GetData(); const auto status = static_cast(data[0]); @@ -95,13 +95,13 @@ void SoftwareKeyboard::ExecuteInteractive() { std::memcpy(string.data(), data.data() + 4, string.size() * 2); frontend.SendTextCheckDialog( Common::UTF16StringFromFixedZeroTerminatedBuffer(string.data(), string.size()), - [this] { broker->SignalStateChanged(); }); + [this] { broker.SignalStateChanged(); }); } } void SoftwareKeyboard::Execute() { if (complete) { - broker->PushNormalDataFromApplet(IStorage{final_data}); + broker.PushNormalDataFromApplet(IStorage{final_data}); return; } @@ -145,17 +145,17 @@ void SoftwareKeyboard::WriteText(std::optional text) { final_data = output_main; if (complete) { - broker->PushNormalDataFromApplet(IStorage{output_main}); + broker.PushNormalDataFromApplet(IStorage{output_main}); } else { - broker->PushInteractiveDataFromApplet(IStorage{output_sub}); + broker.PushInteractiveDataFromApplet(IStorage{output_sub}); } - broker->SignalStateChanged(); + broker.SignalStateChanged(); } else { output_main[0] = 1; complete = true; - broker->PushNormalDataFromApplet(IStorage{output_main}); - broker->SignalStateChanged(); + broker.PushNormalDataFromApplet(IStorage{output_main}); + broker.SignalStateChanged(); } } } // namespace Service::AM::Applets diff --git a/src/core/hle/service/am/applets/software_keyboard.h b/src/core/hle/service/am/applets/software_keyboard.h index 38cabcaec..efd5753a1 100644 --- a/src/core/hle/service/am/applets/software_keyboard.h +++ b/src/core/hle/service/am/applets/software_keyboard.h @@ -55,7 +55,7 @@ public: SoftwareKeyboard(); ~SoftwareKeyboard() override; - void Initialize(std::shared_ptr broker) override; + void Initialize() override; bool TransactionComplete() const override; ResultCode GetStatus() const override;