From 7cfb29de23836aa1873bbb108e3d25a0e9dcfa6d Mon Sep 17 00:00:00 2001 From: Zach Hilman Date: Sun, 11 Nov 2018 20:16:38 -0500 Subject: am: Allow applets to push multiple and different channels of data --- src/core/frontend/applets/software_keyboard.cpp | 10 +++---- src/core/frontend/applets/software_keyboard.h | 5 ++-- src/core/hle/service/am/am.cpp | 34 ++++++++++------------ src/core/hle/service/am/applets/applets.h | 6 +++- .../hle/service/am/applets/software_keyboard.cpp | 27 +++++++---------- .../hle/service/am/applets/software_keyboard.h | 3 +- 6 files changed, 41 insertions(+), 44 deletions(-) (limited to 'src/core') diff --git a/src/core/frontend/applets/software_keyboard.cpp b/src/core/frontend/applets/software_keyboard.cpp index cf5e2ea31..2445a980d 100644 --- a/src/core/frontend/applets/software_keyboard.cpp +++ b/src/core/frontend/applets/software_keyboard.cpp @@ -9,14 +9,12 @@ namespace Core::Frontend { SoftwareKeyboardApplet::~SoftwareKeyboardApplet() = default; -bool DefaultSoftwareKeyboardApplet::GetText(SoftwareKeyboardParameters parameters, - std::u16string& text) const { +std::optional DefaultSoftwareKeyboardApplet::GetText( + SoftwareKeyboardParameters parameters) const { if (parameters.initial_text.empty()) - text = u"yuzu"; - else - text = parameters.initial_text; + return u"yuzu"; - return true; + return parameters.initial_text; } void DefaultSoftwareKeyboardApplet::SendTextCheckDialog(std::u16string error_message) const { diff --git a/src/core/frontend/applets/software_keyboard.h b/src/core/frontend/applets/software_keyboard.h index 0a82aac0d..7387ee8d7 100644 --- a/src/core/frontend/applets/software_keyboard.h +++ b/src/core/frontend/applets/software_keyboard.h @@ -4,6 +4,7 @@ #pragma once +#include #include #include "common/bit_field.h" #include "common/common_types.h" @@ -35,13 +36,13 @@ class SoftwareKeyboardApplet { public: virtual ~SoftwareKeyboardApplet(); - virtual bool GetText(SoftwareKeyboardParameters parameters, std::u16string& text) const = 0; + virtual std::optional GetText(SoftwareKeyboardParameters parameters) const = 0; virtual void SendTextCheckDialog(std::u16string error_message) const = 0; }; class DefaultSoftwareKeyboardApplet final : public SoftwareKeyboardApplet { public: - bool GetText(SoftwareKeyboardParameters parameters, std::u16string& text) const override; + std::optional GetText(SoftwareKeyboardParameters parameters) const override; void SendTextCheckDialog(std::u16string error_message) const override; }; diff --git a/src/core/hle/service/am/am.cpp b/src/core/hle/service/am/am.cpp index 3201e2d4b..3f8d97d31 100644 --- a/src/core/hle/service/am/am.cpp +++ b/src/core/hle/service/am/am.cpp @@ -566,6 +566,16 @@ public: } private: + void AppletStorageProxyOutData(IStorage storage) { + storage_stack.push_back(std::make_shared(storage)); + pop_out_data_event->Signal(); + } + + void AppletStorageProxyOutInteractiveData(IStorage storage) { + interactive_storage_stack.push_back(std::make_shared(storage)); + pop_interactive_out_data_event->Signal(); + } + void GetAppletStateChangedEvent(Kernel::HLERequestContext& ctx) { state_changed_event->Signal(); @@ -591,17 +601,11 @@ private: ASSERT(applet != nullptr); applet->Initialize(storage_stack); - const auto data = std::make_shared(applet->Execute()); + applet->Execute( + [this](IStorage storage) { AppletStorageProxyOutData(storage); }, + [this](IStorage storage) { AppletStorageProxyOutInteractiveData(storage); }); state_changed_event->Signal(); - if (applet->TransactionComplete()) { - storage_stack.push_back(data); - pop_out_data_event->Signal(); - } else { - interactive_storage_stack.push_back(data); - pop_interactive_out_data_event->Signal(); - } - IPC::ResponseBuilder rb{ctx, 2}; rb.Push(RESULT_SUCCESS); } @@ -632,17 +636,11 @@ private: ASSERT(applet->IsInitialized()); applet->ReceiveInteractiveData(interactive_storage_stack.back()); - const auto data = std::make_shared(applet->Execute()); + applet->Execute( + [this](IStorage storage) { AppletStorageProxyOutData(storage); }, + [this](IStorage storage) { AppletStorageProxyOutInteractiveData(storage); }); state_changed_event->Signal(); - if (applet->TransactionComplete()) { - storage_stack.push_back(data); - pop_out_data_event->Signal(); - } else { - interactive_storage_stack.push_back(data); - pop_interactive_out_data_event->Signal(); - } - IPC::ResponseBuilder rb{ctx, 2}; rb.Push(RESULT_SUCCESS); diff --git a/src/core/hle/service/am/applets/applets.h b/src/core/hle/service/am/applets/applets.h index 6d90eb608..7fbaaf2f3 100644 --- a/src/core/hle/service/am/applets/applets.h +++ b/src/core/hle/service/am/applets/applets.h @@ -4,6 +4,7 @@ #pragma once +#include #include #include #include "common/swap.h" @@ -20,6 +21,8 @@ class IStorage; namespace Applets { +using AppletStorageProxyFunction = std::function; + class Applet { public: Applet(); @@ -30,7 +33,8 @@ public: virtual bool TransactionComplete() const = 0; virtual ResultCode GetStatus() const = 0; virtual void ReceiveInteractiveData(std::shared_ptr storage) = 0; - virtual IStorage Execute() = 0; + virtual void Execute(AppletStorageProxyFunction out_data, + AppletStorageProxyFunction out_interactive_data) = 0; bool IsInitialized() const { return initialized; diff --git a/src/core/hle/service/am/applets/software_keyboard.cpp b/src/core/hle/service/am/applets/software_keyboard.cpp index 044a16264..7352f3bdf 100644 --- a/src/core/hle/service/am/applets/software_keyboard.cpp +++ b/src/core/hle/service/am/applets/software_keyboard.cpp @@ -87,42 +87,37 @@ void SoftwareKeyboard::ReceiveInteractiveData(std::shared_ptr storage) } } -IStorage SoftwareKeyboard::Execute() { +void SoftwareKeyboard::Execute(AppletStorageProxyFunction out_data, + AppletStorageProxyFunction out_interactive_data) { if (complete) - return IStorage{final_data}; + return; const auto& frontend{Core::System::GetInstance().GetSoftwareKeyboard()}; const auto parameters = ConvertToFrontendParameters(config, initial_text); - std::u16string text; - const auto success = frontend.GetText(parameters, text); + const auto res = frontend.GetText(parameters); std::vector output(SWKBD_OUTPUT_BUFFER_SIZE); - if (success) { + if (res.has_value()) { if (config.text_check) { - const auto size = static_cast(text.size() * 2 + 4); + const auto size = static_cast(res->size() * 2 + 4); std::memcpy(output.data(), &size, sizeof(u32)); } else { output[0] = 1; } - std::memcpy(output.data() + 4, text.data(), - std::min(text.size() * 2, SWKBD_OUTPUT_BUFFER_SIZE - 4)); + std::memcpy(output.data() + 4, res->data(), + std::min(res->size() * 2, SWKBD_OUTPUT_BUFFER_SIZE - 4)); } else { complete = true; - final_data = std::move(output); - return IStorage{final_data}; + out_data(IStorage{output}); + return; } complete = !config.text_check; - if (complete) { - final_data = std::move(output); - return IStorage{final_data}; - } - - return IStorage{output}; + (complete ? out_data : out_interactive_data)(IStorage{output}); } } // 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 9d77f5802..66de4bc59 100644 --- a/src/core/hle/service/am/applets/software_keyboard.h +++ b/src/core/hle/service/am/applets/software_keyboard.h @@ -54,7 +54,8 @@ public: bool TransactionComplete() const override; ResultCode GetStatus() const override; void ReceiveInteractiveData(std::shared_ptr storage) override; - IStorage Execute() override; + void Execute(AppletStorageProxyFunction out_data, + AppletStorageProxyFunction out_interactive_data) override; private: KeyboardConfig config; -- cgit v1.2.3