summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar bunnei2018-11-21 11:43:43 -0800
committerGravatar GitHub2018-11-21 11:43:43 -0800
commitd4012a454052bc6dd40a93831231255227a6017e (patch)
tree5de77feba013f6acf4a93df460d6618e4cc08d61
parentMerge pull request #1754 from ReinUsesLisp/zero-register (diff)
parentam/applets: Make the applet data broker part of the applet itself. (diff)
downloadyuzu-d4012a454052bc6dd40a93831231255227a6017e.tar.gz
yuzu-d4012a454052bc6dd40a93831231255227a6017e.tar.xz
yuzu-d4012a454052bc6dd40a93831231255227a6017e.zip
Merge pull request #1742 from lioncash/hle-swkbd
am/applets: Minor cleanup
-rw-r--r--src/core/hle/service/am/am.cpp20
-rw-r--r--src/core/hle/service/am/applets/applets.cpp6
-rw-r--r--src/core/hle/service/am/applets/applets.h50
-rw-r--r--src/core/hle/service/am/applets/software_keyboard.cpp24
-rw-r--r--src/core/hle/service/am/applets/software_keyboard.h7
5 files changed, 63 insertions, 44 deletions
diff --git a/src/core/hle/service/am/am.cpp b/src/core/hle/service/am/am.cpp
index 7b4af9eb7..11181a0af 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) {
532class ILibraryAppletAccessor final : public ServiceFramework<ILibraryAppletAccessor> { 532class ILibraryAppletAccessor final : public ServiceFramework<ILibraryAppletAccessor> {
533public: 533public:
534 explicit ILibraryAppletAccessor(std::shared_ptr<Applets::Applet> applet) 534 explicit ILibraryAppletAccessor(std::shared_ptr<Applets::Applet> applet)
535 : ServiceFramework("ILibraryAppletAccessor"), applet(std::move(applet)), 535 : ServiceFramework("ILibraryAppletAccessor"), applet(std::move(applet)) {
536 broker(std::make_shared<Applets::AppletDataBroker>()) {
537 // clang-format off 536 // clang-format off
538 static const FunctionInfo functions[] = { 537 static const FunctionInfo functions[] = {
539 {0, &ILibraryAppletAccessor::GetAppletStateChangedEvent, "GetAppletStateChangedEvent"}, 538 {0, &ILibraryAppletAccessor::GetAppletStateChangedEvent, "GetAppletStateChangedEvent"},
@@ -562,7 +561,7 @@ public:
562 561
563private: 562private:
564 void GetAppletStateChangedEvent(Kernel::HLERequestContext& ctx) { 563 void GetAppletStateChangedEvent(Kernel::HLERequestContext& ctx) {
565 const auto event = broker->GetStateChangedEvent(); 564 const auto event = applet->GetBroker().GetStateChangedEvent();
566 event->Signal(); 565 event->Signal();
567 566
568 IPC::ResponseBuilder rb{ctx, 2, 1}; 567 IPC::ResponseBuilder rb{ctx, 2, 1};
@@ -590,7 +589,7 @@ private:
590 void Start(Kernel::HLERequestContext& ctx) { 589 void Start(Kernel::HLERequestContext& ctx) {
591 ASSERT(applet != nullptr); 590 ASSERT(applet != nullptr);
592 591
593 applet->Initialize(broker); 592 applet->Initialize();
594 applet->Execute(); 593 applet->Execute();
595 594
596 IPC::ResponseBuilder rb{ctx, 2}; 595 IPC::ResponseBuilder rb{ctx, 2};
@@ -601,7 +600,7 @@ private:
601 600
602 void PushInData(Kernel::HLERequestContext& ctx) { 601 void PushInData(Kernel::HLERequestContext& ctx) {
603 IPC::RequestParser rp{ctx}; 602 IPC::RequestParser rp{ctx};
604 broker->PushNormalDataFromGame(*rp.PopIpcInterface<IStorage>()); 603 applet->GetBroker().PushNormalDataFromGame(*rp.PopIpcInterface<IStorage>());
605 604
606 IPC::ResponseBuilder rb{ctx, 2}; 605 IPC::ResponseBuilder rb{ctx, 2};
607 rb.Push(RESULT_SUCCESS); 606 rb.Push(RESULT_SUCCESS);
@@ -612,7 +611,7 @@ private:
612 void PopOutData(Kernel::HLERequestContext& ctx) { 611 void PopOutData(Kernel::HLERequestContext& ctx) {
613 IPC::ResponseBuilder rb{ctx, 2, 0, 1}; 612 IPC::ResponseBuilder rb{ctx, 2, 0, 1};
614 613
615 const auto storage = broker->PopNormalDataToGame(); 614 const auto storage = applet->GetBroker().PopNormalDataToGame();
616 if (storage == nullptr) { 615 if (storage == nullptr) {
617 rb.Push(ERR_NO_DATA_IN_CHANNEL); 616 rb.Push(ERR_NO_DATA_IN_CHANNEL);
618 return; 617 return;
@@ -626,7 +625,7 @@ private:
626 625
627 void PushInteractiveInData(Kernel::HLERequestContext& ctx) { 626 void PushInteractiveInData(Kernel::HLERequestContext& ctx) {
628 IPC::RequestParser rp{ctx}; 627 IPC::RequestParser rp{ctx};
629 broker->PushInteractiveDataFromGame(*rp.PopIpcInterface<IStorage>()); 628 applet->GetBroker().PushInteractiveDataFromGame(*rp.PopIpcInterface<IStorage>());
630 629
631 ASSERT(applet->IsInitialized()); 630 ASSERT(applet->IsInitialized());
632 applet->ExecuteInteractive(); 631 applet->ExecuteInteractive();
@@ -641,7 +640,7 @@ private:
641 void PopInteractiveOutData(Kernel::HLERequestContext& ctx) { 640 void PopInteractiveOutData(Kernel::HLERequestContext& ctx) {
642 IPC::ResponseBuilder rb{ctx, 2, 0, 1}; 641 IPC::ResponseBuilder rb{ctx, 2, 0, 1};
643 642
644 const auto storage = broker->PopInteractiveDataToGame(); 643 const auto storage = applet->GetBroker().PopInteractiveDataToGame();
645 if (storage == nullptr) { 644 if (storage == nullptr) {
646 rb.Push(ERR_NO_DATA_IN_CHANNEL); 645 rb.Push(ERR_NO_DATA_IN_CHANNEL);
647 return; 646 return;
@@ -656,7 +655,7 @@ private:
656 void GetPopOutDataEvent(Kernel::HLERequestContext& ctx) { 655 void GetPopOutDataEvent(Kernel::HLERequestContext& ctx) {
657 IPC::ResponseBuilder rb{ctx, 2, 1}; 656 IPC::ResponseBuilder rb{ctx, 2, 1};
658 rb.Push(RESULT_SUCCESS); 657 rb.Push(RESULT_SUCCESS);
659 rb.PushCopyObjects(broker->GetNormalDataEvent()); 658 rb.PushCopyObjects(applet->GetBroker().GetNormalDataEvent());
660 659
661 LOG_DEBUG(Service_AM, "called"); 660 LOG_DEBUG(Service_AM, "called");
662 } 661 }
@@ -664,13 +663,12 @@ private:
664 void GetPopInteractiveOutDataEvent(Kernel::HLERequestContext& ctx) { 663 void GetPopInteractiveOutDataEvent(Kernel::HLERequestContext& ctx) {
665 IPC::ResponseBuilder rb{ctx, 2, 1}; 664 IPC::ResponseBuilder rb{ctx, 2, 1};
666 rb.Push(RESULT_SUCCESS); 665 rb.Push(RESULT_SUCCESS);
667 rb.PushCopyObjects(broker->GetInteractiveDataEvent()); 666 rb.PushCopyObjects(applet->GetBroker().GetInteractiveDataEvent());
668 667
669 LOG_DEBUG(Service_AM, "called"); 668 LOG_DEBUG(Service_AM, "called");
670 } 669 }
671 670
672 std::shared_ptr<Applets::Applet> applet; 671 std::shared_ptr<Applets::Applet> applet;
673 std::shared_ptr<Applets::AppletDataBroker> broker;
674}; 672};
675 673
676void IStorage::Open(Kernel::HLERequestContext& ctx) { 674void 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;
98 98
99Applet::~Applet() = default; 99Applet::~Applet() = default;
100 100
101void Applet::Initialize(std::shared_ptr<AppletDataBroker> broker_) { 101void Applet::Initialize() {
102 broker = std::move(broker_); 102 const auto common = broker.PopNormalDataToApplet();
103
104 const auto common = broker->PopNormalDataToApplet();
105 ASSERT(common != nullptr); 103 ASSERT(common != nullptr);
106 104
107 const auto common_data = common->GetData(); 105 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 136445649..f65ea119c 100644
--- a/src/core/hle/service/am/applets/applets.h
+++ b/src/core/hle/service/am/applets/applets.h
@@ -4,14 +4,17 @@
4 4
5#pragma once 5#pragma once
6 6
7#include <functional>
8#include <memory> 7#include <memory>
9#include <queue> 8#include <queue>
10#include "common/swap.h" 9#include "common/swap.h"
11#include "core/hle/kernel/event.h" 10#include "core/hle/kernel/kernel.h"
12 11
13union ResultCode; 12union ResultCode;
14 13
14namespace Kernel {
15class Event;
16}
17
15namespace Service::AM { 18namespace Service::AM {
16 19
17class IStorage; 20class IStorage;
@@ -43,19 +46,26 @@ public:
43 46
44private: 47private:
45 // Queues are named from applet's perspective 48 // Queues are named from applet's perspective
46 std::queue<std::unique_ptr<IStorage>> 49
47 in_channel; // PopNormalDataToApplet and PushNormalDataFromGame 50 // PopNormalDataToApplet and PushNormalDataFromGame
48 std::queue<std::unique_ptr<IStorage>> 51 std::queue<std::unique_ptr<IStorage>> in_channel;
49 out_channel; // PopNormalDataToGame and PushNormalDataFromApplet 52
50 std::queue<std::unique_ptr<IStorage>> 53 // PopNormalDataToGame and PushNormalDataFromApplet
51 in_interactive_channel; // PopInteractiveDataToApplet and PushInteractiveDataFromGame 54 std::queue<std::unique_ptr<IStorage>> out_channel;
52 std::queue<std::unique_ptr<IStorage>> 55
53 out_interactive_channel; // PopInteractiveDataToGame and PushInteractiveDataFromApplet 56 // PopInteractiveDataToApplet and PushInteractiveDataFromGame
57 std::queue<std::unique_ptr<IStorage>> in_interactive_channel;
58
59 // PopInteractiveDataToGame and PushInteractiveDataFromApplet
60 std::queue<std::unique_ptr<IStorage>> out_interactive_channel;
54 61
55 Kernel::SharedPtr<Kernel::Event> state_changed_event; 62 Kernel::SharedPtr<Kernel::Event> state_changed_event;
56 Kernel::SharedPtr<Kernel::Event> pop_out_data_event; // Signaled on PushNormalDataFromApplet 63
57 Kernel::SharedPtr<Kernel::Event> 64 // Signaled on PushNormalDataFromApplet
58 pop_interactive_out_data_event; // Signaled on PushInteractiveDataFromApplet 65 Kernel::SharedPtr<Kernel::Event> pop_out_data_event;
66
67 // Signaled on PushInteractiveDataFromApplet
68 Kernel::SharedPtr<Kernel::Event> pop_interactive_out_data_event;
59}; 69};
60 70
61class Applet { 71class Applet {
@@ -63,7 +73,7 @@ public:
63 Applet(); 73 Applet();
64 virtual ~Applet(); 74 virtual ~Applet();
65 75
66 virtual void Initialize(std::shared_ptr<AppletDataBroker> broker); 76 virtual void Initialize();
67 77
68 virtual bool TransactionComplete() const = 0; 78 virtual bool TransactionComplete() const = 0;
69 virtual ResultCode GetStatus() const = 0; 79 virtual ResultCode GetStatus() const = 0;
@@ -74,6 +84,14 @@ public:
74 return initialized; 84 return initialized;
75 } 85 }
76 86
87 AppletDataBroker& GetBroker() {
88 return broker;
89 }
90
91 const AppletDataBroker& GetBroker() const {
92 return broker;
93 }
94
77protected: 95protected:
78 struct CommonArguments { 96 struct CommonArguments {
79 u32_le arguments_version; 97 u32_le arguments_version;
@@ -85,8 +103,8 @@ protected:
85 }; 103 };
86 static_assert(sizeof(CommonArguments) == 0x20, "CommonArguments has incorrect size."); 104 static_assert(sizeof(CommonArguments) == 0x20, "CommonArguments has incorrect size.");
87 105
88 CommonArguments common_args; 106 CommonArguments common_args{};
89 std::shared_ptr<AppletDataBroker> broker; 107 AppletDataBroker broker;
90 bool initialized = false; 108 bool initialized = false;
91}; 109};
92 110
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;
42 42
43SoftwareKeyboard::~SoftwareKeyboard() = default; 43SoftwareKeyboard::~SoftwareKeyboard() = default;
44 44
45void SoftwareKeyboard::Initialize(std::shared_ptr<AppletDataBroker> broker_) { 45void SoftwareKeyboard::Initialize() {
46 complete = false; 46 complete = false;
47 initial_text.clear(); 47 initial_text.clear();
48 final_data.clear(); 48 final_data.clear();
49 49
50 Applet::Initialize(std::move(broker_)); 50 Applet::Initialize();
51 51
52 const auto keyboard_config_storage = broker->PopNormalDataToApplet(); 52 const auto keyboard_config_storage = broker.PopNormalDataToApplet();
53 ASSERT(keyboard_config_storage != nullptr); 53 ASSERT(keyboard_config_storage != nullptr);
54 const auto& keyboard_config = keyboard_config_storage->GetData(); 54 const auto& keyboard_config = keyboard_config_storage->GetData();
55 55
56 ASSERT(keyboard_config.size() >= sizeof(KeyboardConfig)); 56 ASSERT(keyboard_config.size() >= sizeof(KeyboardConfig));
57 std::memcpy(&config, keyboard_config.data(), sizeof(KeyboardConfig)); 57 std::memcpy(&config, keyboard_config.data(), sizeof(KeyboardConfig));
58 58
59 const auto work_buffer_storage = broker->PopNormalDataToApplet(); 59 const auto work_buffer_storage = broker.PopNormalDataToApplet();
60 ASSERT(work_buffer_storage != nullptr); 60 ASSERT(work_buffer_storage != nullptr);
61 const auto& work_buffer = work_buffer_storage->GetData(); 61 const auto& work_buffer = work_buffer_storage->GetData();
62 62
@@ -81,7 +81,7 @@ void SoftwareKeyboard::ExecuteInteractive() {
81 if (complete) 81 if (complete)
82 return; 82 return;
83 83
84 const auto storage = broker->PopInteractiveDataToApplet(); 84 const auto storage = broker.PopInteractiveDataToApplet();
85 ASSERT(storage != nullptr); 85 ASSERT(storage != nullptr);
86 const auto data = storage->GetData(); 86 const auto data = storage->GetData();
87 const auto status = static_cast<bool>(data[0]); 87 const auto status = static_cast<bool>(data[0]);
@@ -95,13 +95,13 @@ void SoftwareKeyboard::ExecuteInteractive() {
95 std::memcpy(string.data(), data.data() + 4, string.size() * 2); 95 std::memcpy(string.data(), data.data() + 4, string.size() * 2);
96 frontend.SendTextCheckDialog( 96 frontend.SendTextCheckDialog(
97 Common::UTF16StringFromFixedZeroTerminatedBuffer(string.data(), string.size()), 97 Common::UTF16StringFromFixedZeroTerminatedBuffer(string.data(), string.size()),
98 [this] { broker->SignalStateChanged(); }); 98 [this] { broker.SignalStateChanged(); });
99 } 99 }
100} 100}
101 101
102void SoftwareKeyboard::Execute() { 102void SoftwareKeyboard::Execute() {
103 if (complete) { 103 if (complete) {
104 broker->PushNormalDataFromApplet(IStorage{final_data}); 104 broker.PushNormalDataFromApplet(IStorage{final_data});
105 return; 105 return;
106 } 106 }
107 107
@@ -145,17 +145,17 @@ void SoftwareKeyboard::WriteText(std::optional<std::u16string> text) {
145 final_data = output_main; 145 final_data = output_main;
146 146
147 if (complete) { 147 if (complete) {
148 broker->PushNormalDataFromApplet(IStorage{output_main}); 148 broker.PushNormalDataFromApplet(IStorage{output_main});
149 } else { 149 } else {
150 broker->PushInteractiveDataFromApplet(IStorage{output_sub}); 150 broker.PushInteractiveDataFromApplet(IStorage{output_sub});
151 } 151 }
152 152
153 broker->SignalStateChanged(); 153 broker.SignalStateChanged();
154 } else { 154 } else {
155 output_main[0] = 1; 155 output_main[0] = 1;
156 complete = true; 156 complete = true;
157 broker->PushNormalDataFromApplet(IStorage{output_main}); 157 broker.PushNormalDataFromApplet(IStorage{output_main});
158 broker->SignalStateChanged(); 158 broker.SignalStateChanged();
159 } 159 }
160} 160}
161} // namespace Service::AM::Applets 161} // 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 16e1fff66..efd5753a1 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 @@
4 4
5#pragma once 5#pragma once
6 6
7#include <array>
8#include <string>
9#include <vector>
10
7#include "common/common_funcs.h" 11#include "common/common_funcs.h"
12#include "common/swap.h"
8#include "core/hle/service/am/am.h" 13#include "core/hle/service/am/am.h"
9#include "core/hle/service/am/applets/applets.h" 14#include "core/hle/service/am/applets/applets.h"
10 15
@@ -50,7 +55,7 @@ public:
50 SoftwareKeyboard(); 55 SoftwareKeyboard();
51 ~SoftwareKeyboard() override; 56 ~SoftwareKeyboard() override;
52 57
53 void Initialize(std::shared_ptr<AppletDataBroker> broker) override; 58 void Initialize() override;
54 59
55 bool TransactionComplete() const override; 60 bool TransactionComplete() const override;
56 ResultCode GetStatus() const override; 61 ResultCode GetStatus() const override;