2018-11-10 02:09:37 +01:00
|
|
|
// Copyright 2018 yuzu emulator team
|
|
|
|
// Licensed under GPLv2 or any later version
|
|
|
|
// Refer to the license.txt file included.
|
|
|
|
|
2018-11-17 18:19:06 +01:00
|
|
|
#include <cstring>
|
|
|
|
#include "common/assert.h"
|
2018-11-19 20:24:36 +01:00
|
|
|
#include "core/core.h"
|
2018-11-27 00:34:07 +01:00
|
|
|
#include "core/hle/kernel/readable_event.h"
|
2018-11-19 20:24:36 +01:00
|
|
|
#include "core/hle/kernel/server_port.h"
|
2018-11-27 00:34:07 +01:00
|
|
|
#include "core/hle/kernel/writable_event.h"
|
2018-11-17 18:19:06 +01:00
|
|
|
#include "core/hle/service/am/am.h"
|
2018-11-10 02:09:37 +01:00
|
|
|
#include "core/hle/service/am/applets/applets.h"
|
|
|
|
|
|
|
|
namespace Service::AM::Applets {
|
|
|
|
|
2018-11-19 20:24:36 +01:00
|
|
|
AppletDataBroker::AppletDataBroker() {
|
|
|
|
auto& kernel = Core::System::GetInstance().Kernel();
|
2018-11-27 15:18:29 +01:00
|
|
|
state_changed_event = Kernel::WritableEvent::CreateEventPair(
|
2018-12-10 01:46:15 +01:00
|
|
|
kernel, Kernel::ResetType::Sticky, "ILibraryAppletAccessor:StateChangedEvent");
|
2018-11-27 15:18:29 +01:00
|
|
|
pop_out_data_event = Kernel::WritableEvent::CreateEventPair(
|
2018-12-10 01:46:15 +01:00
|
|
|
kernel, Kernel::ResetType::Sticky, "ILibraryAppletAccessor:PopDataOutEvent");
|
2018-11-27 15:18:29 +01:00
|
|
|
pop_interactive_out_data_event = Kernel::WritableEvent::CreateEventPair(
|
2018-12-10 01:46:15 +01:00
|
|
|
kernel, Kernel::ResetType::Sticky, "ILibraryAppletAccessor:PopInteractiveDataOutEvent");
|
2018-11-19 20:24:36 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
AppletDataBroker::~AppletDataBroker() = default;
|
|
|
|
|
|
|
|
std::unique_ptr<IStorage> AppletDataBroker::PopNormalDataToGame() {
|
|
|
|
if (out_channel.empty())
|
|
|
|
return nullptr;
|
|
|
|
|
|
|
|
auto out = std::move(out_channel.front());
|
|
|
|
out_channel.pop();
|
|
|
|
return out;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::unique_ptr<IStorage> AppletDataBroker::PopNormalDataToApplet() {
|
|
|
|
if (in_channel.empty())
|
|
|
|
return nullptr;
|
|
|
|
|
|
|
|
auto out = std::move(in_channel.front());
|
|
|
|
in_channel.pop();
|
|
|
|
return out;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::unique_ptr<IStorage> AppletDataBroker::PopInteractiveDataToGame() {
|
|
|
|
if (out_interactive_channel.empty())
|
|
|
|
return nullptr;
|
|
|
|
|
|
|
|
auto out = std::move(out_interactive_channel.front());
|
|
|
|
out_interactive_channel.pop();
|
|
|
|
return out;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::unique_ptr<IStorage> AppletDataBroker::PopInteractiveDataToApplet() {
|
|
|
|
if (in_interactive_channel.empty())
|
|
|
|
return nullptr;
|
|
|
|
|
|
|
|
auto out = std::move(in_interactive_channel.front());
|
|
|
|
in_interactive_channel.pop();
|
|
|
|
return out;
|
|
|
|
}
|
|
|
|
|
|
|
|
void AppletDataBroker::PushNormalDataFromGame(IStorage storage) {
|
|
|
|
in_channel.push(std::make_unique<IStorage>(storage));
|
|
|
|
}
|
|
|
|
|
|
|
|
void AppletDataBroker::PushNormalDataFromApplet(IStorage storage) {
|
|
|
|
out_channel.push(std::make_unique<IStorage>(storage));
|
2018-11-27 15:18:29 +01:00
|
|
|
pop_out_data_event.writable->Signal();
|
2018-11-19 20:24:36 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void AppletDataBroker::PushInteractiveDataFromGame(IStorage storage) {
|
|
|
|
in_interactive_channel.push(std::make_unique<IStorage>(storage));
|
|
|
|
}
|
|
|
|
|
|
|
|
void AppletDataBroker::PushInteractiveDataFromApplet(IStorage storage) {
|
|
|
|
out_interactive_channel.push(std::make_unique<IStorage>(storage));
|
2018-11-27 15:18:29 +01:00
|
|
|
pop_interactive_out_data_event.writable->Signal();
|
2018-11-19 20:24:36 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void AppletDataBroker::SignalStateChanged() const {
|
2018-11-27 15:18:29 +01:00
|
|
|
state_changed_event.writable->Signal();
|
2018-11-19 20:24:36 +01:00
|
|
|
}
|
|
|
|
|
2018-11-27 00:34:07 +01:00
|
|
|
Kernel::SharedPtr<Kernel::ReadableEvent> AppletDataBroker::GetNormalDataEvent() const {
|
2018-11-27 15:18:29 +01:00
|
|
|
return pop_out_data_event.readable;
|
2018-11-19 20:24:36 +01:00
|
|
|
}
|
|
|
|
|
2018-11-27 00:34:07 +01:00
|
|
|
Kernel::SharedPtr<Kernel::ReadableEvent> AppletDataBroker::GetInteractiveDataEvent() const {
|
2018-11-27 15:18:29 +01:00
|
|
|
return pop_interactive_out_data_event.readable;
|
2018-11-19 20:24:36 +01:00
|
|
|
}
|
|
|
|
|
2018-11-27 00:34:07 +01:00
|
|
|
Kernel::SharedPtr<Kernel::ReadableEvent> AppletDataBroker::GetStateChangedEvent() const {
|
2018-11-27 15:18:29 +01:00
|
|
|
return state_changed_event.readable;
|
2018-11-19 20:24:36 +01:00
|
|
|
}
|
|
|
|
|
2018-11-11 22:39:25 +01:00
|
|
|
Applet::Applet() = default;
|
|
|
|
|
|
|
|
Applet::~Applet() = default;
|
2018-11-10 02:09:37 +01:00
|
|
|
|
2018-11-20 18:02:16 +01:00
|
|
|
void Applet::Initialize() {
|
|
|
|
const auto common = broker.PopNormalDataToApplet();
|
2018-11-19 20:24:36 +01:00
|
|
|
ASSERT(common != nullptr);
|
2018-11-17 18:19:06 +01:00
|
|
|
|
2018-11-19 20:24:36 +01:00
|
|
|
const auto common_data = common->GetData();
|
2018-11-17 18:19:06 +01:00
|
|
|
|
|
|
|
ASSERT(common_data.size() >= sizeof(CommonArguments));
|
|
|
|
std::memcpy(&common_args, common_data.data(), sizeof(CommonArguments));
|
|
|
|
|
2018-11-10 02:09:37 +01:00
|
|
|
initialized = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace Service::AM::Applets
|