diff options
| author | 2018-11-11 20:16:38 -0500 | |
|---|---|---|
| committer | 2018-11-18 10:53:47 -0500 | |
| commit | 7cfb29de23836aa1873bbb108e3d25a0e9dcfa6d (patch) | |
| tree | 6ed63f8c93a0d9b4e0cb6ac8d41e0a94aa149e99 /src | |
| parent | am: Implement ILibraryAppletAccessor IsCompleted and GetResult (diff) | |
| download | yuzu-7cfb29de23836aa1873bbb108e3d25a0e9dcfa6d.tar.gz yuzu-7cfb29de23836aa1873bbb108e3d25a0e9dcfa6d.tar.xz yuzu-7cfb29de23836aa1873bbb108e3d25a0e9dcfa6d.zip | |
am: Allow applets to push multiple and different channels of data
Diffstat (limited to 'src')
| -rw-r--r-- | src/core/frontend/applets/software_keyboard.cpp | 10 | ||||
| -rw-r--r-- | src/core/frontend/applets/software_keyboard.h | 5 | ||||
| -rw-r--r-- | src/core/hle/service/am/am.cpp | 34 | ||||
| -rw-r--r-- | src/core/hle/service/am/applets/applets.h | 6 | ||||
| -rw-r--r-- | src/core/hle/service/am/applets/software_keyboard.cpp | 27 | ||||
| -rw-r--r-- | src/core/hle/service/am/applets/software_keyboard.h | 3 | ||||
| -rw-r--r-- | src/yuzu/applets/software_keyboard.cpp | 15 | ||||
| -rw-r--r-- | src/yuzu/applets/software_keyboard.h | 8 | ||||
| -rw-r--r-- | src/yuzu/main.cpp | 14 | ||||
| -rw-r--r-- | src/yuzu/main.h | 4 |
10 files changed, 62 insertions, 64 deletions
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 @@ | |||
| 9 | namespace Core::Frontend { | 9 | namespace Core::Frontend { |
| 10 | SoftwareKeyboardApplet::~SoftwareKeyboardApplet() = default; | 10 | SoftwareKeyboardApplet::~SoftwareKeyboardApplet() = default; |
| 11 | 11 | ||
| 12 | bool DefaultSoftwareKeyboardApplet::GetText(SoftwareKeyboardParameters parameters, | 12 | std::optional<std::u16string> DefaultSoftwareKeyboardApplet::GetText( |
| 13 | std::u16string& text) const { | 13 | SoftwareKeyboardParameters parameters) const { |
| 14 | if (parameters.initial_text.empty()) | 14 | if (parameters.initial_text.empty()) |
| 15 | text = u"yuzu"; | 15 | return u"yuzu"; |
| 16 | else | ||
| 17 | text = parameters.initial_text; | ||
| 18 | 16 | ||
| 19 | return true; | 17 | return parameters.initial_text; |
| 20 | } | 18 | } |
| 21 | 19 | ||
| 22 | void DefaultSoftwareKeyboardApplet::SendTextCheckDialog(std::u16string error_message) const { | 20 | 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 @@ | |||
| 4 | 4 | ||
| 5 | #pragma once | 5 | #pragma once |
| 6 | 6 | ||
| 7 | #include <optional> | ||
| 7 | #include <string> | 8 | #include <string> |
| 8 | #include "common/bit_field.h" | 9 | #include "common/bit_field.h" |
| 9 | #include "common/common_types.h" | 10 | #include "common/common_types.h" |
| @@ -35,13 +36,13 @@ class SoftwareKeyboardApplet { | |||
| 35 | public: | 36 | public: |
| 36 | virtual ~SoftwareKeyboardApplet(); | 37 | virtual ~SoftwareKeyboardApplet(); |
| 37 | 38 | ||
| 38 | virtual bool GetText(SoftwareKeyboardParameters parameters, std::u16string& text) const = 0; | 39 | virtual std::optional<std::u16string> GetText(SoftwareKeyboardParameters parameters) const = 0; |
| 39 | virtual void SendTextCheckDialog(std::u16string error_message) const = 0; | 40 | virtual void SendTextCheckDialog(std::u16string error_message) const = 0; |
| 40 | }; | 41 | }; |
| 41 | 42 | ||
| 42 | class DefaultSoftwareKeyboardApplet final : public SoftwareKeyboardApplet { | 43 | class DefaultSoftwareKeyboardApplet final : public SoftwareKeyboardApplet { |
| 43 | public: | 44 | public: |
| 44 | bool GetText(SoftwareKeyboardParameters parameters, std::u16string& text) const override; | 45 | std::optional<std::u16string> GetText(SoftwareKeyboardParameters parameters) const override; |
| 45 | void SendTextCheckDialog(std::u16string error_message) const override; | 46 | void SendTextCheckDialog(std::u16string error_message) const override; |
| 46 | }; | 47 | }; |
| 47 | 48 | ||
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: | |||
| 566 | } | 566 | } |
| 567 | 567 | ||
| 568 | private: | 568 | private: |
| 569 | void AppletStorageProxyOutData(IStorage storage) { | ||
| 570 | storage_stack.push_back(std::make_shared<IStorage>(storage)); | ||
| 571 | pop_out_data_event->Signal(); | ||
| 572 | } | ||
| 573 | |||
| 574 | void AppletStorageProxyOutInteractiveData(IStorage storage) { | ||
| 575 | interactive_storage_stack.push_back(std::make_shared<IStorage>(storage)); | ||
| 576 | pop_interactive_out_data_event->Signal(); | ||
| 577 | } | ||
| 578 | |||
| 569 | void GetAppletStateChangedEvent(Kernel::HLERequestContext& ctx) { | 579 | void GetAppletStateChangedEvent(Kernel::HLERequestContext& ctx) { |
| 570 | state_changed_event->Signal(); | 580 | state_changed_event->Signal(); |
| 571 | 581 | ||
| @@ -591,17 +601,11 @@ private: | |||
| 591 | ASSERT(applet != nullptr); | 601 | ASSERT(applet != nullptr); |
| 592 | 602 | ||
| 593 | applet->Initialize(storage_stack); | 603 | applet->Initialize(storage_stack); |
| 594 | const auto data = std::make_shared<IStorage>(applet->Execute()); | 604 | applet->Execute( |
| 605 | [this](IStorage storage) { AppletStorageProxyOutData(storage); }, | ||
| 606 | [this](IStorage storage) { AppletStorageProxyOutInteractiveData(storage); }); | ||
| 595 | state_changed_event->Signal(); | 607 | state_changed_event->Signal(); |
| 596 | 608 | ||
| 597 | if (applet->TransactionComplete()) { | ||
| 598 | storage_stack.push_back(data); | ||
| 599 | pop_out_data_event->Signal(); | ||
| 600 | } else { | ||
| 601 | interactive_storage_stack.push_back(data); | ||
| 602 | pop_interactive_out_data_event->Signal(); | ||
| 603 | } | ||
| 604 | |||
| 605 | IPC::ResponseBuilder rb{ctx, 2}; | 609 | IPC::ResponseBuilder rb{ctx, 2}; |
| 606 | rb.Push(RESULT_SUCCESS); | 610 | rb.Push(RESULT_SUCCESS); |
| 607 | } | 611 | } |
| @@ -632,17 +636,11 @@ private: | |||
| 632 | 636 | ||
| 633 | ASSERT(applet->IsInitialized()); | 637 | ASSERT(applet->IsInitialized()); |
| 634 | applet->ReceiveInteractiveData(interactive_storage_stack.back()); | 638 | applet->ReceiveInteractiveData(interactive_storage_stack.back()); |
| 635 | const auto data = std::make_shared<IStorage>(applet->Execute()); | 639 | applet->Execute( |
| 640 | [this](IStorage storage) { AppletStorageProxyOutData(storage); }, | ||
| 641 | [this](IStorage storage) { AppletStorageProxyOutInteractiveData(storage); }); | ||
| 636 | state_changed_event->Signal(); | 642 | state_changed_event->Signal(); |
| 637 | 643 | ||
| 638 | if (applet->TransactionComplete()) { | ||
| 639 | storage_stack.push_back(data); | ||
| 640 | pop_out_data_event->Signal(); | ||
| 641 | } else { | ||
| 642 | interactive_storage_stack.push_back(data); | ||
| 643 | pop_interactive_out_data_event->Signal(); | ||
| 644 | } | ||
| 645 | |||
| 646 | IPC::ResponseBuilder rb{ctx, 2}; | 644 | IPC::ResponseBuilder rb{ctx, 2}; |
| 647 | rb.Push(RESULT_SUCCESS); | 645 | rb.Push(RESULT_SUCCESS); |
| 648 | 646 | ||
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 @@ | |||
| 4 | 4 | ||
| 5 | #pragma once | 5 | #pragma once |
| 6 | 6 | ||
| 7 | #include <functional> | ||
| 7 | #include <memory> | 8 | #include <memory> |
| 8 | #include <vector> | 9 | #include <vector> |
| 9 | #include "common/swap.h" | 10 | #include "common/swap.h" |
| @@ -20,6 +21,8 @@ class IStorage; | |||
| 20 | 21 | ||
| 21 | namespace Applets { | 22 | namespace Applets { |
| 22 | 23 | ||
| 24 | using AppletStorageProxyFunction = std::function<void(IStorage)>; | ||
| 25 | |||
| 23 | class Applet { | 26 | class Applet { |
| 24 | public: | 27 | public: |
| 25 | Applet(); | 28 | Applet(); |
| @@ -30,7 +33,8 @@ public: | |||
| 30 | virtual bool TransactionComplete() const = 0; | 33 | virtual bool TransactionComplete() const = 0; |
| 31 | virtual ResultCode GetStatus() const = 0; | 34 | virtual ResultCode GetStatus() const = 0; |
| 32 | virtual void ReceiveInteractiveData(std::shared_ptr<IStorage> storage) = 0; | 35 | virtual void ReceiveInteractiveData(std::shared_ptr<IStorage> storage) = 0; |
| 33 | virtual IStorage Execute() = 0; | 36 | virtual void Execute(AppletStorageProxyFunction out_data, |
| 37 | AppletStorageProxyFunction out_interactive_data) = 0; | ||
| 34 | 38 | ||
| 35 | bool IsInitialized() const { | 39 | bool IsInitialized() const { |
| 36 | return initialized; | 40 | 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<IStorage> storage) | |||
| 87 | } | 87 | } |
| 88 | } | 88 | } |
| 89 | 89 | ||
| 90 | IStorage SoftwareKeyboard::Execute() { | 90 | void SoftwareKeyboard::Execute(AppletStorageProxyFunction out_data, |
| 91 | AppletStorageProxyFunction out_interactive_data) { | ||
| 91 | if (complete) | 92 | if (complete) |
| 92 | return IStorage{final_data}; | 93 | return; |
| 93 | 94 | ||
| 94 | const auto& frontend{Core::System::GetInstance().GetSoftwareKeyboard()}; | 95 | const auto& frontend{Core::System::GetInstance().GetSoftwareKeyboard()}; |
| 95 | 96 | ||
| 96 | const auto parameters = ConvertToFrontendParameters(config, initial_text); | 97 | const auto parameters = ConvertToFrontendParameters(config, initial_text); |
| 97 | 98 | ||
| 98 | std::u16string text; | 99 | const auto res = frontend.GetText(parameters); |
| 99 | const auto success = frontend.GetText(parameters, text); | ||
| 100 | 100 | ||
| 101 | std::vector<u8> output(SWKBD_OUTPUT_BUFFER_SIZE); | 101 | std::vector<u8> output(SWKBD_OUTPUT_BUFFER_SIZE); |
| 102 | 102 | ||
| 103 | if (success) { | 103 | if (res.has_value()) { |
| 104 | if (config.text_check) { | 104 | if (config.text_check) { |
| 105 | const auto size = static_cast<u32>(text.size() * 2 + 4); | 105 | const auto size = static_cast<u32>(res->size() * 2 + 4); |
| 106 | std::memcpy(output.data(), &size, sizeof(u32)); | 106 | std::memcpy(output.data(), &size, sizeof(u32)); |
| 107 | } else { | 107 | } else { |
| 108 | output[0] = 1; | 108 | output[0] = 1; |
| 109 | } | 109 | } |
| 110 | 110 | ||
| 111 | std::memcpy(output.data() + 4, text.data(), | 111 | std::memcpy(output.data() + 4, res->data(), |
| 112 | std::min(text.size() * 2, SWKBD_OUTPUT_BUFFER_SIZE - 4)); | 112 | std::min(res->size() * 2, SWKBD_OUTPUT_BUFFER_SIZE - 4)); |
| 113 | } else { | 113 | } else { |
| 114 | complete = true; | 114 | complete = true; |
| 115 | final_data = std::move(output); | 115 | out_data(IStorage{output}); |
| 116 | return IStorage{final_data}; | 116 | return; |
| 117 | } | 117 | } |
| 118 | 118 | ||
| 119 | complete = !config.text_check; | 119 | complete = !config.text_check; |
| 120 | 120 | ||
| 121 | if (complete) { | 121 | (complete ? out_data : out_interactive_data)(IStorage{output}); |
| 122 | final_data = std::move(output); | ||
| 123 | return IStorage{final_data}; | ||
| 124 | } | ||
| 125 | |||
| 126 | return IStorage{output}; | ||
| 127 | } | 122 | } |
| 128 | } // namespace Service::AM::Applets | 123 | } // 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: | |||
| 54 | bool TransactionComplete() const override; | 54 | bool TransactionComplete() const override; |
| 55 | ResultCode GetStatus() const override; | 55 | ResultCode GetStatus() const override; |
| 56 | void ReceiveInteractiveData(std::shared_ptr<IStorage> storage) override; | 56 | void ReceiveInteractiveData(std::shared_ptr<IStorage> storage) override; |
| 57 | IStorage Execute() override; | 57 | void Execute(AppletStorageProxyFunction out_data, |
| 58 | AppletStorageProxyFunction out_interactive_data) override; | ||
| 58 | 59 | ||
| 59 | private: | 60 | private: |
| 60 | KeyboardConfig config; | 61 | KeyboardConfig config; |
diff --git a/src/yuzu/applets/software_keyboard.cpp b/src/yuzu/applets/software_keyboard.cpp index fad150ec1..92992ef87 100644 --- a/src/yuzu/applets/software_keyboard.cpp +++ b/src/yuzu/applets/software_keyboard.cpp | |||
| @@ -97,11 +97,11 @@ void QtSoftwareKeyboardDialog::Reject() { | |||
| 97 | accept(); | 97 | accept(); |
| 98 | } | 98 | } |
| 99 | 99 | ||
| 100 | std::u16string QtSoftwareKeyboardDialog::GetText() { | 100 | std::u16string QtSoftwareKeyboardDialog::GetText() const { |
| 101 | return text; | 101 | return text; |
| 102 | } | 102 | } |
| 103 | 103 | ||
| 104 | bool QtSoftwareKeyboardDialog::GetStatus() { | 104 | bool QtSoftwareKeyboardDialog::GetStatus() const { |
| 105 | return ok; | 105 | return ok; |
| 106 | } | 106 | } |
| 107 | 107 | ||
| @@ -109,13 +109,12 @@ QtSoftwareKeyboard::QtSoftwareKeyboard(GMainWindow& parent) : main_window(parent | |||
| 109 | 109 | ||
| 110 | QtSoftwareKeyboard::~QtSoftwareKeyboard() = default; | 110 | QtSoftwareKeyboard::~QtSoftwareKeyboard() = default; |
| 111 | 111 | ||
| 112 | bool QtSoftwareKeyboard::GetText(Core::Frontend::SoftwareKeyboardParameters parameters, | 112 | std::optional<std::u16string> QtSoftwareKeyboard::GetText( |
| 113 | std::u16string& text) const { | 113 | Core::Frontend::SoftwareKeyboardParameters parameters) const { |
| 114 | bool success; | 114 | std::optional<std::u16string> success; |
| 115 | QMetaObject::invokeMethod(&main_window, "SoftwareKeyboardGetText", Qt::BlockingQueuedConnection, | 115 | QMetaObject::invokeMethod(&main_window, "SoftwareKeyboardGetText", Qt::BlockingQueuedConnection, |
| 116 | Q_RETURN_ARG(bool, success), | 116 | Q_RETURN_ARG(std::optional<std::u16string>, success), |
| 117 | Q_ARG(Core::Frontend::SoftwareKeyboardParameters, parameters), | 117 | Q_ARG(Core::Frontend::SoftwareKeyboardParameters, parameters)); |
| 118 | Q_ARG(std::u16string&, text)); | ||
| 119 | return success; | 118 | return success; |
| 120 | } | 119 | } |
| 121 | 120 | ||
diff --git a/src/yuzu/applets/software_keyboard.h b/src/yuzu/applets/software_keyboard.h index 1069c10ec..8d95ca511 100644 --- a/src/yuzu/applets/software_keyboard.h +++ b/src/yuzu/applets/software_keyboard.h | |||
| @@ -36,8 +36,8 @@ public: | |||
| 36 | void Submit(); | 36 | void Submit(); |
| 37 | void Reject(); | 37 | void Reject(); |
| 38 | 38 | ||
| 39 | std::u16string GetText(); | 39 | std::u16string GetText() const; |
| 40 | bool GetStatus(); | 40 | bool GetStatus() const; |
| 41 | 41 | ||
| 42 | private: | 42 | private: |
| 43 | bool ok = false; | 43 | bool ok = false; |
| @@ -58,8 +58,8 @@ public: | |||
| 58 | explicit QtSoftwareKeyboard(GMainWindow& parent); | 58 | explicit QtSoftwareKeyboard(GMainWindow& parent); |
| 59 | ~QtSoftwareKeyboard() override; | 59 | ~QtSoftwareKeyboard() override; |
| 60 | 60 | ||
| 61 | bool GetText(Core::Frontend::SoftwareKeyboardParameters parameters, | 61 | std::optional<std::u16string> GetText( |
| 62 | std::u16string& text) const override; | 62 | Core::Frontend::SoftwareKeyboardParameters parameters) const override; |
| 63 | void SendTextCheckDialog(std::u16string error_message) const override; | 63 | void SendTextCheckDialog(std::u16string error_message) const override; |
| 64 | 64 | ||
| 65 | private: | 65 | private: |
diff --git a/src/yuzu/main.cpp b/src/yuzu/main.cpp index 447d9dece..a11eb7f86 100644 --- a/src/yuzu/main.cpp +++ b/src/yuzu/main.cpp | |||
| @@ -207,16 +207,18 @@ GMainWindow::~GMainWindow() { | |||
| 207 | delete render_window; | 207 | delete render_window; |
| 208 | } | 208 | } |
| 209 | 209 | ||
| 210 | bool GMainWindow::SoftwareKeyboardGetText( | 210 | std::optional<std::u16string> GMainWindow::SoftwareKeyboardGetText( |
| 211 | const Core::Frontend::SoftwareKeyboardParameters& parameters, std::u16string& text) { | 211 | const Core::Frontend::SoftwareKeyboardParameters& parameters) { |
| 212 | QtSoftwareKeyboardDialog dialog(this, parameters); | 212 | QtSoftwareKeyboardDialog dialog(this, parameters); |
| 213 | dialog.setWindowFlags(Qt::Dialog | Qt::CustomizeWindowHint | Qt::WindowTitleHint | | 213 | dialog.setWindowFlags(Qt::Dialog | Qt::CustomizeWindowHint | Qt::WindowTitleHint | |
| 214 | Qt::WindowSystemMenuHint | Qt::WindowCloseButtonHint); | 214 | Qt::WindowSystemMenuHint | Qt::WindowCloseButtonHint); |
| 215 | dialog.setWindowModality(Qt::WindowModal); | 215 | dialog.setWindowModality(Qt::WindowModal); |
| 216 | dialog.exec(); | 216 | dialog.exec(); |
| 217 | 217 | ||
| 218 | text = dialog.GetText(); | 218 | if (!dialog.GetStatus()) |
| 219 | return dialog.GetStatus(); | 219 | return std::nullopt; |
| 220 | |||
| 221 | return dialog.GetText(); | ||
| 220 | } | 222 | } |
| 221 | 223 | ||
| 222 | void GMainWindow::SoftwareKeyboardInvokeCheckDialog(std::u16string error_message) { | 224 | void GMainWindow::SoftwareKeyboardInvokeCheckDialog(std::u16string error_message) { |
| @@ -1251,10 +1253,10 @@ void GMainWindow::OnStartGame() { | |||
| 1251 | emu_thread->SetRunning(true); | 1253 | emu_thread->SetRunning(true); |
| 1252 | 1254 | ||
| 1253 | qRegisterMetaType<Core::Frontend::SoftwareKeyboardParameters>( | 1255 | qRegisterMetaType<Core::Frontend::SoftwareKeyboardParameters>( |
| 1254 | "core::Frontend::SoftwareKeyboardParameters"); | 1256 | "Core::Frontend::SoftwareKeyboardParameters"); |
| 1255 | qRegisterMetaType<Core::System::ResultStatus>("Core::System::ResultStatus"); | 1257 | qRegisterMetaType<Core::System::ResultStatus>("Core::System::ResultStatus"); |
| 1256 | qRegisterMetaType<std::string>("std::string"); | 1258 | qRegisterMetaType<std::string>("std::string"); |
| 1257 | qRegisterMetaType<std::u16string>("std::u16string"); | 1259 | qRegisterMetaType<std::optional<std::u16string>>("std::optional<std::u16string>"); |
| 1258 | 1260 | ||
| 1259 | connect(emu_thread.get(), &EmuThread::ErrorThrown, this, &GMainWindow::OnCoreError); | 1261 | connect(emu_thread.get(), &EmuThread::ErrorThrown, this, &GMainWindow::OnCoreError); |
| 1260 | 1262 | ||
diff --git a/src/yuzu/main.h b/src/yuzu/main.h index 38074e3f0..8fbe998ea 100644 --- a/src/yuzu/main.h +++ b/src/yuzu/main.h | |||
| @@ -100,8 +100,8 @@ signals: | |||
| 100 | void UpdateThemedIcons(); | 100 | void UpdateThemedIcons(); |
| 101 | 101 | ||
| 102 | public slots: | 102 | public slots: |
| 103 | bool SoftwareKeyboardGetText(const Core::Frontend::SoftwareKeyboardParameters& parameters, | 103 | std::optional<std::u16string> SoftwareKeyboardGetText( |
| 104 | std::u16string& text); | 104 | const Core::Frontend::SoftwareKeyboardParameters& parameters); |
| 105 | void SoftwareKeyboardInvokeCheckDialog(std::u16string error_message); | 105 | void SoftwareKeyboardInvokeCheckDialog(std::u16string error_message); |
| 106 | 106 | ||
| 107 | private: | 107 | private: |