mirror of
https://git.suyu.dev/suyu/suyu
synced 2024-10-31 04:17:52 +00:00
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.
This commit is contained in:
parent
8b4b560df5
commit
73b7748984
5 changed files with 36 additions and 31 deletions
|
@ -532,8 +532,7 @@ void ICommonStateGetter::GetPerformanceMode(Kernel::HLERequestContext& ctx) {
|
||||||
class ILibraryAppletAccessor final : public ServiceFramework<ILibraryAppletAccessor> {
|
class ILibraryAppletAccessor final : public ServiceFramework<ILibraryAppletAccessor> {
|
||||||
public:
|
public:
|
||||||
explicit ILibraryAppletAccessor(std::shared_ptr<Applets::Applet> applet)
|
explicit ILibraryAppletAccessor(std::shared_ptr<Applets::Applet> applet)
|
||||||
: ServiceFramework("ILibraryAppletAccessor"), applet(std::move(applet)),
|
: ServiceFramework("ILibraryAppletAccessor"), applet(std::move(applet)) {
|
||||||
broker(std::make_shared<Applets::AppletDataBroker>()) {
|
|
||||||
// clang-format off
|
// clang-format off
|
||||||
static const FunctionInfo functions[] = {
|
static const FunctionInfo functions[] = {
|
||||||
{0, &ILibraryAppletAccessor::GetAppletStateChangedEvent, "GetAppletStateChangedEvent"},
|
{0, &ILibraryAppletAccessor::GetAppletStateChangedEvent, "GetAppletStateChangedEvent"},
|
||||||
|
@ -562,7 +561,7 @@ public:
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void GetAppletStateChangedEvent(Kernel::HLERequestContext& ctx) {
|
void GetAppletStateChangedEvent(Kernel::HLERequestContext& ctx) {
|
||||||
const auto event = broker->GetStateChangedEvent();
|
const auto event = applet->GetBroker().GetStateChangedEvent();
|
||||||
event->Signal();
|
event->Signal();
|
||||||
|
|
||||||
IPC::ResponseBuilder rb{ctx, 2, 1};
|
IPC::ResponseBuilder rb{ctx, 2, 1};
|
||||||
|
@ -590,7 +589,7 @@ private:
|
||||||
void Start(Kernel::HLERequestContext& ctx) {
|
void Start(Kernel::HLERequestContext& ctx) {
|
||||||
ASSERT(applet != nullptr);
|
ASSERT(applet != nullptr);
|
||||||
|
|
||||||
applet->Initialize(broker);
|
applet->Initialize();
|
||||||
applet->Execute();
|
applet->Execute();
|
||||||
|
|
||||||
IPC::ResponseBuilder rb{ctx, 2};
|
IPC::ResponseBuilder rb{ctx, 2};
|
||||||
|
@ -601,7 +600,7 @@ private:
|
||||||
|
|
||||||
void PushInData(Kernel::HLERequestContext& ctx) {
|
void PushInData(Kernel::HLERequestContext& ctx) {
|
||||||
IPC::RequestParser rp{ctx};
|
IPC::RequestParser rp{ctx};
|
||||||
broker->PushNormalDataFromGame(*rp.PopIpcInterface<IStorage>());
|
applet->GetBroker().PushNormalDataFromGame(*rp.PopIpcInterface<IStorage>());
|
||||||
|
|
||||||
IPC::ResponseBuilder rb{ctx, 2};
|
IPC::ResponseBuilder rb{ctx, 2};
|
||||||
rb.Push(RESULT_SUCCESS);
|
rb.Push(RESULT_SUCCESS);
|
||||||
|
@ -612,7 +611,7 @@ private:
|
||||||
void PopOutData(Kernel::HLERequestContext& ctx) {
|
void PopOutData(Kernel::HLERequestContext& ctx) {
|
||||||
IPC::ResponseBuilder rb{ctx, 2, 0, 1};
|
IPC::ResponseBuilder rb{ctx, 2, 0, 1};
|
||||||
|
|
||||||
const auto storage = broker->PopNormalDataToGame();
|
const auto storage = applet->GetBroker().PopNormalDataToGame();
|
||||||
if (storage == nullptr) {
|
if (storage == nullptr) {
|
||||||
rb.Push(ERR_NO_DATA_IN_CHANNEL);
|
rb.Push(ERR_NO_DATA_IN_CHANNEL);
|
||||||
return;
|
return;
|
||||||
|
@ -626,7 +625,7 @@ private:
|
||||||
|
|
||||||
void PushInteractiveInData(Kernel::HLERequestContext& ctx) {
|
void PushInteractiveInData(Kernel::HLERequestContext& ctx) {
|
||||||
IPC::RequestParser rp{ctx};
|
IPC::RequestParser rp{ctx};
|
||||||
broker->PushInteractiveDataFromGame(*rp.PopIpcInterface<IStorage>());
|
applet->GetBroker().PushInteractiveDataFromGame(*rp.PopIpcInterface<IStorage>());
|
||||||
|
|
||||||
ASSERT(applet->IsInitialized());
|
ASSERT(applet->IsInitialized());
|
||||||
applet->ExecuteInteractive();
|
applet->ExecuteInteractive();
|
||||||
|
@ -641,7 +640,7 @@ private:
|
||||||
void PopInteractiveOutData(Kernel::HLERequestContext& ctx) {
|
void PopInteractiveOutData(Kernel::HLERequestContext& ctx) {
|
||||||
IPC::ResponseBuilder rb{ctx, 2, 0, 1};
|
IPC::ResponseBuilder rb{ctx, 2, 0, 1};
|
||||||
|
|
||||||
const auto storage = broker->PopInteractiveDataToGame();
|
const auto storage = applet->GetBroker().PopInteractiveDataToGame();
|
||||||
if (storage == nullptr) {
|
if (storage == nullptr) {
|
||||||
rb.Push(ERR_NO_DATA_IN_CHANNEL);
|
rb.Push(ERR_NO_DATA_IN_CHANNEL);
|
||||||
return;
|
return;
|
||||||
|
@ -656,7 +655,7 @@ private:
|
||||||
void GetPopOutDataEvent(Kernel::HLERequestContext& ctx) {
|
void GetPopOutDataEvent(Kernel::HLERequestContext& ctx) {
|
||||||
IPC::ResponseBuilder rb{ctx, 2, 1};
|
IPC::ResponseBuilder rb{ctx, 2, 1};
|
||||||
rb.Push(RESULT_SUCCESS);
|
rb.Push(RESULT_SUCCESS);
|
||||||
rb.PushCopyObjects(broker->GetNormalDataEvent());
|
rb.PushCopyObjects(applet->GetBroker().GetNormalDataEvent());
|
||||||
|
|
||||||
LOG_DEBUG(Service_AM, "called");
|
LOG_DEBUG(Service_AM, "called");
|
||||||
}
|
}
|
||||||
|
@ -664,13 +663,12 @@ private:
|
||||||
void GetPopInteractiveOutDataEvent(Kernel::HLERequestContext& ctx) {
|
void GetPopInteractiveOutDataEvent(Kernel::HLERequestContext& ctx) {
|
||||||
IPC::ResponseBuilder rb{ctx, 2, 1};
|
IPC::ResponseBuilder rb{ctx, 2, 1};
|
||||||
rb.Push(RESULT_SUCCESS);
|
rb.Push(RESULT_SUCCESS);
|
||||||
rb.PushCopyObjects(broker->GetInteractiveDataEvent());
|
rb.PushCopyObjects(applet->GetBroker().GetInteractiveDataEvent());
|
||||||
|
|
||||||
LOG_DEBUG(Service_AM, "called");
|
LOG_DEBUG(Service_AM, "called");
|
||||||
}
|
}
|
||||||
|
|
||||||
std::shared_ptr<Applets::Applet> applet;
|
std::shared_ptr<Applets::Applet> applet;
|
||||||
std::shared_ptr<Applets::AppletDataBroker> broker;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
void IStorage::Open(Kernel::HLERequestContext& ctx) {
|
void IStorage::Open(Kernel::HLERequestContext& ctx) {
|
||||||
|
|
|
@ -98,10 +98,8 @@ Applet::Applet() = default;
|
||||||
|
|
||||||
Applet::~Applet() = default;
|
Applet::~Applet() = default;
|
||||||
|
|
||||||
void Applet::Initialize(std::shared_ptr<AppletDataBroker> broker_) {
|
void Applet::Initialize() {
|
||||||
broker = std::move(broker_);
|
const auto common = broker.PopNormalDataToApplet();
|
||||||
|
|
||||||
const auto common = broker->PopNormalDataToApplet();
|
|
||||||
ASSERT(common != nullptr);
|
ASSERT(common != nullptr);
|
||||||
|
|
||||||
const auto common_data = common->GetData();
|
const auto common_data = common->GetData();
|
||||||
|
|
|
@ -7,6 +7,7 @@
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include <queue>
|
#include <queue>
|
||||||
#include "common/swap.h"
|
#include "common/swap.h"
|
||||||
|
#include "core/hle/kernel/kernel.h"
|
||||||
|
|
||||||
union ResultCode;
|
union ResultCode;
|
||||||
|
|
||||||
|
@ -72,7 +73,7 @@ public:
|
||||||
Applet();
|
Applet();
|
||||||
virtual ~Applet();
|
virtual ~Applet();
|
||||||
|
|
||||||
virtual void Initialize(std::shared_ptr<AppletDataBroker> broker);
|
virtual void Initialize();
|
||||||
|
|
||||||
virtual bool TransactionComplete() const = 0;
|
virtual bool TransactionComplete() const = 0;
|
||||||
virtual ResultCode GetStatus() const = 0;
|
virtual ResultCode GetStatus() const = 0;
|
||||||
|
@ -83,6 +84,14 @@ public:
|
||||||
return initialized;
|
return initialized;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
AppletDataBroker& GetBroker() {
|
||||||
|
return broker;
|
||||||
|
}
|
||||||
|
|
||||||
|
const AppletDataBroker& GetBroker() const {
|
||||||
|
return broker;
|
||||||
|
}
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
struct CommonArguments {
|
struct CommonArguments {
|
||||||
u32_le arguments_version;
|
u32_le arguments_version;
|
||||||
|
@ -94,8 +103,8 @@ protected:
|
||||||
};
|
};
|
||||||
static_assert(sizeof(CommonArguments) == 0x20, "CommonArguments has incorrect size.");
|
static_assert(sizeof(CommonArguments) == 0x20, "CommonArguments has incorrect size.");
|
||||||
|
|
||||||
CommonArguments common_args;
|
CommonArguments common_args{};
|
||||||
std::shared_ptr<AppletDataBroker> broker;
|
AppletDataBroker broker;
|
||||||
bool initialized = false;
|
bool initialized = false;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -42,21 +42,21 @@ SoftwareKeyboard::SoftwareKeyboard() = default;
|
||||||
|
|
||||||
SoftwareKeyboard::~SoftwareKeyboard() = default;
|
SoftwareKeyboard::~SoftwareKeyboard() = default;
|
||||||
|
|
||||||
void SoftwareKeyboard::Initialize(std::shared_ptr<AppletDataBroker> broker_) {
|
void SoftwareKeyboard::Initialize() {
|
||||||
complete = false;
|
complete = false;
|
||||||
initial_text.clear();
|
initial_text.clear();
|
||||||
final_data.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);
|
ASSERT(keyboard_config_storage != nullptr);
|
||||||
const auto& keyboard_config = keyboard_config_storage->GetData();
|
const auto& keyboard_config = keyboard_config_storage->GetData();
|
||||||
|
|
||||||
ASSERT(keyboard_config.size() >= sizeof(KeyboardConfig));
|
ASSERT(keyboard_config.size() >= sizeof(KeyboardConfig));
|
||||||
std::memcpy(&config, keyboard_config.data(), 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);
|
ASSERT(work_buffer_storage != nullptr);
|
||||||
const auto& work_buffer = work_buffer_storage->GetData();
|
const auto& work_buffer = work_buffer_storage->GetData();
|
||||||
|
|
||||||
|
@ -81,7 +81,7 @@ void SoftwareKeyboard::ExecuteInteractive() {
|
||||||
if (complete)
|
if (complete)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
const auto storage = broker->PopInteractiveDataToApplet();
|
const auto storage = broker.PopInteractiveDataToApplet();
|
||||||
ASSERT(storage != nullptr);
|
ASSERT(storage != nullptr);
|
||||||
const auto data = storage->GetData();
|
const auto data = storage->GetData();
|
||||||
const auto status = static_cast<bool>(data[0]);
|
const auto status = static_cast<bool>(data[0]);
|
||||||
|
@ -95,13 +95,13 @@ void SoftwareKeyboard::ExecuteInteractive() {
|
||||||
std::memcpy(string.data(), data.data() + 4, string.size() * 2);
|
std::memcpy(string.data(), data.data() + 4, string.size() * 2);
|
||||||
frontend.SendTextCheckDialog(
|
frontend.SendTextCheckDialog(
|
||||||
Common::UTF16StringFromFixedZeroTerminatedBuffer(string.data(), string.size()),
|
Common::UTF16StringFromFixedZeroTerminatedBuffer(string.data(), string.size()),
|
||||||
[this] { broker->SignalStateChanged(); });
|
[this] { broker.SignalStateChanged(); });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void SoftwareKeyboard::Execute() {
|
void SoftwareKeyboard::Execute() {
|
||||||
if (complete) {
|
if (complete) {
|
||||||
broker->PushNormalDataFromApplet(IStorage{final_data});
|
broker.PushNormalDataFromApplet(IStorage{final_data});
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -145,17 +145,17 @@ 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{output_main});
|
||||||
} else {
|
} else {
|
||||||
broker->PushInteractiveDataFromApplet(IStorage{output_sub});
|
broker.PushInteractiveDataFromApplet(IStorage{output_sub});
|
||||||
}
|
}
|
||||||
|
|
||||||
broker->SignalStateChanged();
|
broker.SignalStateChanged();
|
||||||
} else {
|
} else {
|
||||||
output_main[0] = 1;
|
output_main[0] = 1;
|
||||||
complete = true;
|
complete = true;
|
||||||
broker->PushNormalDataFromApplet(IStorage{output_main});
|
broker.PushNormalDataFromApplet(IStorage{output_main});
|
||||||
broker->SignalStateChanged();
|
broker.SignalStateChanged();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} // namespace Service::AM::Applets
|
} // namespace Service::AM::Applets
|
||||||
|
|
|
@ -55,7 +55,7 @@ public:
|
||||||
SoftwareKeyboard();
|
SoftwareKeyboard();
|
||||||
~SoftwareKeyboard() override;
|
~SoftwareKeyboard() override;
|
||||||
|
|
||||||
void Initialize(std::shared_ptr<AppletDataBroker> broker) override;
|
void Initialize() override;
|
||||||
|
|
||||||
bool TransactionComplete() const override;
|
bool TransactionComplete() const override;
|
||||||
ResultCode GetStatus() const override;
|
ResultCode GetStatus() const override;
|
||||||
|
|
Loading…
Reference in a new issue