diff options
author | Liam <byteslice@airmail.cc> | 2024-01-03 07:16:27 +0100 |
---|---|---|
committer | Liam <byteslice@airmail.cc> | 2024-01-30 02:17:33 +0100 |
commit | 8a146469c0639ff402e77da8843072ce1f2bce0c (patch) | |
tree | c5dbc016c8ff1affaa06d9bfe7b580b468fed1ba /src/core/hle/service/am/applet_data_broker.cpp | |
parent | am: rework IStorage for transfer storage (diff) | |
download | yuzu-8a146469c0639ff402e77da8843072ce1f2bce0c.tar yuzu-8a146469c0639ff402e77da8843072ce1f2bce0c.tar.gz yuzu-8a146469c0639ff402e77da8843072ce1f2bce0c.tar.bz2 yuzu-8a146469c0639ff402e77da8843072ce1f2bce0c.tar.lz yuzu-8a146469c0639ff402e77da8843072ce1f2bce0c.tar.xz yuzu-8a146469c0639ff402e77da8843072ce1f2bce0c.tar.zst yuzu-8a146469c0639ff402e77da8843072ce1f2bce0c.zip |
Diffstat (limited to '')
-rw-r--r-- | src/core/hle/service/am/applet_data_broker.cpp | 67 |
1 files changed, 67 insertions, 0 deletions
diff --git a/src/core/hle/service/am/applet_data_broker.cpp b/src/core/hle/service/am/applet_data_broker.cpp new file mode 100644 index 000000000..4d58c4db5 --- /dev/null +++ b/src/core/hle/service/am/applet_data_broker.cpp @@ -0,0 +1,67 @@ +// SPDX-FileCopyrightText: Copyright 2024 yuzu Emulator Project +// SPDX-License-Identifier: GPL-2.0-or-later + +#include "common/scope_exit.h" + +#include "core/core.h" +#include "core/hle/service/am/am_results.h" +#include "core/hle/service/am/applet_data_broker.h" +#include "core/hle/service/am/applet_manager.h" + +namespace Service::AM { + +AppletStorageChannel::AppletStorageChannel(KernelHelpers::ServiceContext& context) + : m_event(context) {} +AppletStorageChannel::~AppletStorageChannel() = default; + +void AppletStorageChannel::Push(std::shared_ptr<IStorage> storage) { + std::scoped_lock lk{m_lock}; + + m_data.emplace_back(std::move(storage)); + m_event.Signal(); +} + +Result AppletStorageChannel::Pop(std::shared_ptr<IStorage>* out_storage) { + std::scoped_lock lk{m_lock}; + + SCOPE_EXIT({ + if (m_data.empty()) { + m_event.Clear(); + } + }); + + R_UNLESS(!m_data.empty(), AM::ResultNoDataInChannel); + + *out_storage = std::move(m_data.front()); + m_data.pop_front(); + + R_SUCCEED(); +} + +Kernel::KReadableEvent* AppletStorageChannel::GetEvent() { + return m_event.GetHandle(); +} + +AppletDataBroker::AppletDataBroker(Core::System& system_) + : system(system_), context(system_, "AppletDataBroker"), in_data(context), + interactive_in_data(context), out_data(context), interactive_out_data(context), + state_changed_event(context), is_completed(false) {} + +AppletDataBroker::~AppletDataBroker() = default; + +void AppletDataBroker::SignalCompletion() { + { + std::scoped_lock lk{lock}; + + if (is_completed) { + return; + } + + is_completed = true; + state_changed_event.Signal(); + } + + system.GetAppletManager().FocusStateChanged(); +} + +} // namespace Service::AM |