summaryrefslogtreecommitdiff
path: root/src/core/hle/service/am
diff options
context:
space:
mode:
authorGravatar Morph2021-09-28 23:42:50 -0400
committerGravatar Morph2021-10-01 23:38:59 -0400
commitfadcee14f8fca1b76b4ea48b1cfd136ccae8d182 (patch)
treea5787938bc73ff1b0b539e0945d3544d06a7d6d2 /src/core/hle/service/am
parentMerge pull request #7102 from Morph1984/remove-boxcat (diff)
downloadyuzu-fadcee14f8fca1b76b4ea48b1cfd136ccae8d182.tar.gz
yuzu-fadcee14f8fca1b76b4ea48b1cfd136ccae8d182.tar.xz
yuzu-fadcee14f8fca1b76b4ea48b1cfd136ccae8d182.zip
service: Replace service event creation with ServiceContext::CreateEvent
The service context helps to manage all created events and allows us to close them upon destruction.
Diffstat (limited to 'src/core/hle/service/am')
-rw-r--r--src/core/hle/service/am/am.cpp115
-rw-r--r--src/core/hle/service/am/am.h32
-rw-r--r--src/core/hle/service/am/applets/applets.cpp41
-rw-r--r--src/core/hle/service/am/applets/applets.h10
4 files changed, 104 insertions, 94 deletions
diff --git a/src/core/hle/service/am/am.cpp b/src/core/hle/service/am/am.cpp
index 8c2e2f920..02de585e4 100644
--- a/src/core/hle/service/am/am.cpp
+++ b/src/core/hle/service/am/am.cpp
@@ -16,9 +16,7 @@
16#include "core/hle/ipc_helpers.h" 16#include "core/hle/ipc_helpers.h"
17#include "core/hle/kernel/k_event.h" 17#include "core/hle/kernel/k_event.h"
18#include "core/hle/kernel/k_process.h" 18#include "core/hle/kernel/k_process.h"
19#include "core/hle/kernel/k_readable_event.h"
20#include "core/hle/kernel/k_transfer_memory.h" 19#include "core/hle/kernel/k_transfer_memory.h"
21#include "core/hle/kernel/k_writable_event.h"
22#include "core/hle/kernel/kernel.h" 20#include "core/hle/kernel/kernel.h"
23#include "core/hle/service/acc/profile_manager.h" 21#include "core/hle/service/acc/profile_manager.h"
24#include "core/hle/service/am/am.h" 22#include "core/hle/service/am/am.h"
@@ -254,8 +252,9 @@ IDebugFunctions::IDebugFunctions(Core::System& system_)
254IDebugFunctions::~IDebugFunctions() = default; 252IDebugFunctions::~IDebugFunctions() = default;
255 253
256ISelfController::ISelfController(Core::System& system_, NVFlinger::NVFlinger& nvflinger_) 254ISelfController::ISelfController(Core::System& system_, NVFlinger::NVFlinger& nvflinger_)
257 : ServiceFramework{system_, "ISelfController"}, nvflinger{nvflinger_}, 255 : ServiceFramework{system_, "ISelfController"}, nvflinger{nvflinger_}, service_context{
258 launchable_event{system.Kernel()}, accumulated_suspended_tick_changed_event{system.Kernel()} { 256 system,
257 "ISelfController"} {
259 // clang-format off 258 // clang-format off
260 static const FunctionInfo functions[] = { 259 static const FunctionInfo functions[] = {
261 {0, &ISelfController::Exit, "Exit"}, 260 {0, &ISelfController::Exit, "Exit"},
@@ -311,9 +310,7 @@ ISelfController::ISelfController(Core::System& system_, NVFlinger::NVFlinger& nv
311 310
312 RegisterHandlers(functions); 311 RegisterHandlers(functions);
313 312
314 Kernel::KAutoObject::Create(std::addressof(launchable_event)); 313 launchable_event = service_context.CreateEvent("ISelfController:LaunchableEvent");
315
316 launchable_event.Initialize("ISelfController:LaunchableEvent");
317 314
318 // This event is created by AM on the first time GetAccumulatedSuspendedTickChangedEvent() is 315 // This event is created by AM on the first time GetAccumulatedSuspendedTickChangedEvent() is
319 // called. Yuzu can just create it unconditionally, since it doesn't need to support multiple 316 // called. Yuzu can just create it unconditionally, since it doesn't need to support multiple
@@ -321,13 +318,15 @@ ISelfController::ISelfController(Core::System& system_, NVFlinger::NVFlinger& nv
321 // suspended if the event has previously been created by a call to 318 // suspended if the event has previously been created by a call to
322 // GetAccumulatedSuspendedTickChangedEvent. 319 // GetAccumulatedSuspendedTickChangedEvent.
323 320
324 Kernel::KAutoObject::Create(std::addressof(accumulated_suspended_tick_changed_event)); 321 accumulated_suspended_tick_changed_event =
325 accumulated_suspended_tick_changed_event.Initialize( 322 service_context.CreateEvent("ISelfController:AccumulatedSuspendedTickChangedEvent");
326 "ISelfController:AccumulatedSuspendedTickChangedEvent"); 323 accumulated_suspended_tick_changed_event->GetWritableEvent().Signal();
327 accumulated_suspended_tick_changed_event.GetWritableEvent().Signal();
328} 324}
329 325
330ISelfController::~ISelfController() = default; 326ISelfController::~ISelfController() {
327 service_context.CloseEvent(launchable_event);
328 service_context.CloseEvent(accumulated_suspended_tick_changed_event);
329}
331 330
332void ISelfController::Exit(Kernel::HLERequestContext& ctx) { 331void ISelfController::Exit(Kernel::HLERequestContext& ctx) {
333 LOG_DEBUG(Service_AM, "called"); 332 LOG_DEBUG(Service_AM, "called");
@@ -383,11 +382,11 @@ void ISelfController::LeaveFatalSection(Kernel::HLERequestContext& ctx) {
383void ISelfController::GetLibraryAppletLaunchableEvent(Kernel::HLERequestContext& ctx) { 382void ISelfController::GetLibraryAppletLaunchableEvent(Kernel::HLERequestContext& ctx) {
384 LOG_WARNING(Service_AM, "(STUBBED) called"); 383 LOG_WARNING(Service_AM, "(STUBBED) called");
385 384
386 launchable_event.GetWritableEvent().Signal(); 385 launchable_event->GetWritableEvent().Signal();
387 386
388 IPC::ResponseBuilder rb{ctx, 2, 1}; 387 IPC::ResponseBuilder rb{ctx, 2, 1};
389 rb.Push(ResultSuccess); 388 rb.Push(ResultSuccess);
390 rb.PushCopyObjects(launchable_event.GetReadableEvent()); 389 rb.PushCopyObjects(launchable_event->GetReadableEvent());
391} 390}
392 391
393void ISelfController::SetScreenShotPermission(Kernel::HLERequestContext& ctx) { 392void ISelfController::SetScreenShotPermission(Kernel::HLERequestContext& ctx) {
@@ -566,7 +565,7 @@ void ISelfController::GetAccumulatedSuspendedTickChangedEvent(Kernel::HLERequest
566 565
567 IPC::ResponseBuilder rb{ctx, 2, 1}; 566 IPC::ResponseBuilder rb{ctx, 2, 1};
568 rb.Push(ResultSuccess); 567 rb.Push(ResultSuccess);
569 rb.PushCopyObjects(accumulated_suspended_tick_changed_event.GetReadableEvent()); 568 rb.PushCopyObjects(accumulated_suspended_tick_changed_event->GetReadableEvent());
570} 569}
571 570
572void ISelfController::SetAlbumImageTakenNotificationEnabled(Kernel::HLERequestContext& ctx) { 571void ISelfController::SetAlbumImageTakenNotificationEnabled(Kernel::HLERequestContext& ctx) {
@@ -584,40 +583,39 @@ void ISelfController::SetAlbumImageTakenNotificationEnabled(Kernel::HLERequestCo
584 rb.Push(ResultSuccess); 583 rb.Push(ResultSuccess);
585} 584}
586 585
587AppletMessageQueue::AppletMessageQueue(Kernel::KernelCore& kernel) 586AppletMessageQueue::AppletMessageQueue(Core::System& system)
588 : on_new_message{kernel}, on_operation_mode_changed{kernel} { 587 : service_context{system, "AppletMessageQueue"} {
589 588 on_new_message = service_context.CreateEvent("AMMessageQueue:OnMessageReceived");
590 Kernel::KAutoObject::Create(std::addressof(on_new_message)); 589 on_operation_mode_changed = service_context.CreateEvent("AMMessageQueue:OperationModeChanged");
591 Kernel::KAutoObject::Create(std::addressof(on_operation_mode_changed));
592
593 on_new_message.Initialize("AMMessageQueue:OnMessageReceived");
594 on_operation_mode_changed.Initialize("AMMessageQueue:OperationModeChanged");
595} 590}
596 591
597AppletMessageQueue::~AppletMessageQueue() = default; 592AppletMessageQueue::~AppletMessageQueue() {
593 service_context.CloseEvent(on_new_message);
594 service_context.CloseEvent(on_operation_mode_changed);
595}
598 596
599Kernel::KReadableEvent& AppletMessageQueue::GetMessageReceiveEvent() { 597Kernel::KReadableEvent& AppletMessageQueue::GetMessageReceiveEvent() {
600 return on_new_message.GetReadableEvent(); 598 return on_new_message->GetReadableEvent();
601} 599}
602 600
603Kernel::KReadableEvent& AppletMessageQueue::GetOperationModeChangedEvent() { 601Kernel::KReadableEvent& AppletMessageQueue::GetOperationModeChangedEvent() {
604 return on_operation_mode_changed.GetReadableEvent(); 602 return on_operation_mode_changed->GetReadableEvent();
605} 603}
606 604
607void AppletMessageQueue::PushMessage(AppletMessage msg) { 605void AppletMessageQueue::PushMessage(AppletMessage msg) {
608 messages.push(msg); 606 messages.push(msg);
609 on_new_message.GetWritableEvent().Signal(); 607 on_new_message->GetWritableEvent().Signal();
610} 608}
611 609
612AppletMessageQueue::AppletMessage AppletMessageQueue::PopMessage() { 610AppletMessageQueue::AppletMessage AppletMessageQueue::PopMessage() {
613 if (messages.empty()) { 611 if (messages.empty()) {
614 on_new_message.GetWritableEvent().Clear(); 612 on_new_message->GetWritableEvent().Clear();
615 return AppletMessage::NoMessage; 613 return AppletMessage::NoMessage;
616 } 614 }
617 auto msg = messages.front(); 615 auto msg = messages.front();
618 messages.pop(); 616 messages.pop();
619 if (messages.empty()) { 617 if (messages.empty()) {
620 on_new_message.GetWritableEvent().Clear(); 618 on_new_message->GetWritableEvent().Clear();
621 } 619 }
622 return msg; 620 return msg;
623} 621}
@@ -637,7 +635,7 @@ void AppletMessageQueue::FocusStateChanged() {
637void AppletMessageQueue::OperationModeChanged() { 635void AppletMessageQueue::OperationModeChanged() {
638 PushMessage(AppletMessage::OperationModeChanged); 636 PushMessage(AppletMessage::OperationModeChanged);
639 PushMessage(AppletMessage::PerformanceModeChanged); 637 PushMessage(AppletMessage::PerformanceModeChanged);
640 on_operation_mode_changed.GetWritableEvent().Signal(); 638 on_operation_mode_changed->GetWritableEvent().Signal();
641} 639}
642 640
643ICommonStateGetter::ICommonStateGetter(Core::System& system_, 641ICommonStateGetter::ICommonStateGetter(Core::System& system_,
@@ -1272,10 +1270,8 @@ void ILibraryAppletCreator::CreateHandleStorage(Kernel::HLERequestContext& ctx)
1272} 1270}
1273 1271
1274IApplicationFunctions::IApplicationFunctions(Core::System& system_) 1272IApplicationFunctions::IApplicationFunctions(Core::System& system_)
1275 : ServiceFramework{system_, "IApplicationFunctions"}, gpu_error_detected_event{system.Kernel()}, 1273 : ServiceFramework{system_, "IApplicationFunctions"}, service_context{system,
1276 friend_invitation_storage_channel_event{system.Kernel()}, 1274 "IApplicationFunctions"} {
1277 notification_storage_channel_event{system.Kernel()}, health_warning_disappeared_system_event{
1278 system.Kernel()} {
1279 // clang-format off 1275 // clang-format off
1280 static const FunctionInfo functions[] = { 1276 static const FunctionInfo functions[] = {
1281 {1, &IApplicationFunctions::PopLaunchParameter, "PopLaunchParameter"}, 1277 {1, &IApplicationFunctions::PopLaunchParameter, "PopLaunchParameter"},
@@ -1343,21 +1339,22 @@ IApplicationFunctions::IApplicationFunctions(Core::System& system_)
1343 1339
1344 RegisterHandlers(functions); 1340 RegisterHandlers(functions);
1345 1341
1346 Kernel::KAutoObject::Create(std::addressof(gpu_error_detected_event)); 1342 gpu_error_detected_event =
1347 Kernel::KAutoObject::Create(std::addressof(friend_invitation_storage_channel_event)); 1343 service_context.CreateEvent("IApplicationFunctions:GpuErrorDetectedSystemEvent");
1348 Kernel::KAutoObject::Create(std::addressof(notification_storage_channel_event)); 1344 friend_invitation_storage_channel_event =
1349 Kernel::KAutoObject::Create(std::addressof(health_warning_disappeared_system_event)); 1345 service_context.CreateEvent("IApplicationFunctions:FriendInvitationStorageChannelEvent");
1350 1346 notification_storage_channel_event =
1351 gpu_error_detected_event.Initialize("IApplicationFunctions:GpuErrorDetectedSystemEvent"); 1347 service_context.CreateEvent("IApplicationFunctions:NotificationStorageChannelEvent");
1352 friend_invitation_storage_channel_event.Initialize( 1348 health_warning_disappeared_system_event =
1353 "IApplicationFunctions:FriendInvitationStorageChannelEvent"); 1349 service_context.CreateEvent("IApplicationFunctions:HealthWarningDisappearedSystemEvent");
1354 notification_storage_channel_event.Initialize(
1355 "IApplicationFunctions:NotificationStorageChannelEvent");
1356 health_warning_disappeared_system_event.Initialize(
1357 "IApplicationFunctions:HealthWarningDisappearedSystemEvent");
1358} 1350}
1359 1351
1360IApplicationFunctions::~IApplicationFunctions() = default; 1352IApplicationFunctions::~IApplicationFunctions() {
1353 service_context.CloseEvent(gpu_error_detected_event);
1354 service_context.CloseEvent(friend_invitation_storage_channel_event);
1355 service_context.CloseEvent(notification_storage_channel_event);
1356 service_context.CloseEvent(health_warning_disappeared_system_event);
1357}
1361 1358
1362void IApplicationFunctions::EnableApplicationCrashReport(Kernel::HLERequestContext& ctx) { 1359void IApplicationFunctions::EnableApplicationCrashReport(Kernel::HLERequestContext& ctx) {
1363 LOG_WARNING(Service_AM, "(STUBBED) called"); 1360 LOG_WARNING(Service_AM, "(STUBBED) called");
@@ -1751,7 +1748,7 @@ void IApplicationFunctions::GetGpuErrorDetectedSystemEvent(Kernel::HLERequestCon
1751 1748
1752 IPC::ResponseBuilder rb{ctx, 2, 1}; 1749 IPC::ResponseBuilder rb{ctx, 2, 1};
1753 rb.Push(ResultSuccess); 1750 rb.Push(ResultSuccess);
1754 rb.PushCopyObjects(gpu_error_detected_event.GetReadableEvent()); 1751 rb.PushCopyObjects(gpu_error_detected_event->GetReadableEvent());
1755} 1752}
1756 1753
1757void IApplicationFunctions::GetFriendInvitationStorageChannelEvent(Kernel::HLERequestContext& ctx) { 1754void IApplicationFunctions::GetFriendInvitationStorageChannelEvent(Kernel::HLERequestContext& ctx) {
@@ -1759,7 +1756,7 @@ void IApplicationFunctions::GetFriendInvitationStorageChannelEvent(Kernel::HLERe
1759 1756
1760 IPC::ResponseBuilder rb{ctx, 2, 1}; 1757 IPC::ResponseBuilder rb{ctx, 2, 1};
1761 rb.Push(ResultSuccess); 1758 rb.Push(ResultSuccess);
1762 rb.PushCopyObjects(friend_invitation_storage_channel_event.GetReadableEvent()); 1759 rb.PushCopyObjects(friend_invitation_storage_channel_event->GetReadableEvent());
1763} 1760}
1764 1761
1765void IApplicationFunctions::TryPopFromFriendInvitationStorageChannel( 1762void IApplicationFunctions::TryPopFromFriendInvitationStorageChannel(
@@ -1775,7 +1772,7 @@ void IApplicationFunctions::GetNotificationStorageChannelEvent(Kernel::HLEReques
1775 1772
1776 IPC::ResponseBuilder rb{ctx, 2, 1}; 1773 IPC::ResponseBuilder rb{ctx, 2, 1};
1777 rb.Push(ResultSuccess); 1774 rb.Push(ResultSuccess);
1778 rb.PushCopyObjects(notification_storage_channel_event.GetReadableEvent()); 1775 rb.PushCopyObjects(notification_storage_channel_event->GetReadableEvent());
1779} 1776}
1780 1777
1781void IApplicationFunctions::GetHealthWarningDisappearedSystemEvent(Kernel::HLERequestContext& ctx) { 1778void IApplicationFunctions::GetHealthWarningDisappearedSystemEvent(Kernel::HLERequestContext& ctx) {
@@ -1783,12 +1780,12 @@ void IApplicationFunctions::GetHealthWarningDisappearedSystemEvent(Kernel::HLERe
1783 1780
1784 IPC::ResponseBuilder rb{ctx, 2, 1}; 1781 IPC::ResponseBuilder rb{ctx, 2, 1};
1785 rb.Push(ResultSuccess); 1782 rb.Push(ResultSuccess);
1786 rb.PushCopyObjects(health_warning_disappeared_system_event.GetReadableEvent()); 1783 rb.PushCopyObjects(health_warning_disappeared_system_event->GetReadableEvent());
1787} 1784}
1788 1785
1789void InstallInterfaces(SM::ServiceManager& service_manager, NVFlinger::NVFlinger& nvflinger, 1786void InstallInterfaces(SM::ServiceManager& service_manager, NVFlinger::NVFlinger& nvflinger,
1790 Core::System& system) { 1787 Core::System& system) {
1791 auto message_queue = std::make_shared<AppletMessageQueue>(system.Kernel()); 1788 auto message_queue = std::make_shared<AppletMessageQueue>(system);
1792 // Needed on game boot 1789 // Needed on game boot
1793 message_queue->PushMessage(AppletMessageQueue::AppletMessage::FocusStateChanged); 1790 message_queue->PushMessage(AppletMessageQueue::AppletMessage::FocusStateChanged);
1794 1791
@@ -1801,8 +1798,8 @@ void InstallInterfaces(SM::ServiceManager& service_manager, NVFlinger::NVFlinger
1801} 1798}
1802 1799
1803IHomeMenuFunctions::IHomeMenuFunctions(Core::System& system_) 1800IHomeMenuFunctions::IHomeMenuFunctions(Core::System& system_)
1804 : ServiceFramework{system_, "IHomeMenuFunctions"}, pop_from_general_channel_event{ 1801 : ServiceFramework{system_, "IHomeMenuFunctions"}, service_context{system,
1805 system.Kernel()} { 1802 "IHomeMenuFunctions"} {
1806 // clang-format off 1803 // clang-format off
1807 static const FunctionInfo functions[] = { 1804 static const FunctionInfo functions[] = {
1808 {10, &IHomeMenuFunctions::RequestToGetForeground, "RequestToGetForeground"}, 1805 {10, &IHomeMenuFunctions::RequestToGetForeground, "RequestToGetForeground"},
@@ -1823,11 +1820,13 @@ IHomeMenuFunctions::IHomeMenuFunctions(Core::System& system_)
1823 1820
1824 RegisterHandlers(functions); 1821 RegisterHandlers(functions);
1825 1822
1826 Kernel::KAutoObject::Create(std::addressof(pop_from_general_channel_event)); 1823 pop_from_general_channel_event =
1827 pop_from_general_channel_event.Initialize("IHomeMenuFunctions:PopFromGeneralChannelEvent"); 1824 service_context.CreateEvent("IHomeMenuFunctions:PopFromGeneralChannelEvent");
1828} 1825}
1829 1826
1830IHomeMenuFunctions::~IHomeMenuFunctions() = default; 1827IHomeMenuFunctions::~IHomeMenuFunctions() {
1828 service_context.CloseEvent(pop_from_general_channel_event);
1829}
1831 1830
1832void IHomeMenuFunctions::RequestToGetForeground(Kernel::HLERequestContext& ctx) { 1831void IHomeMenuFunctions::RequestToGetForeground(Kernel::HLERequestContext& ctx) {
1833 LOG_WARNING(Service_AM, "(STUBBED) called"); 1832 LOG_WARNING(Service_AM, "(STUBBED) called");
@@ -1841,7 +1840,7 @@ void IHomeMenuFunctions::GetPopFromGeneralChannelEvent(Kernel::HLERequestContext
1841 1840
1842 IPC::ResponseBuilder rb{ctx, 2, 1}; 1841 IPC::ResponseBuilder rb{ctx, 2, 1};
1843 rb.Push(ResultSuccess); 1842 rb.Push(ResultSuccess);
1844 rb.PushCopyObjects(pop_from_general_channel_event.GetReadableEvent()); 1843 rb.PushCopyObjects(pop_from_general_channel_event->GetReadableEvent());
1845} 1844}
1846 1845
1847IGlobalStateController::IGlobalStateController(Core::System& system_) 1846IGlobalStateController::IGlobalStateController(Core::System& system_)
diff --git a/src/core/hle/service/am/am.h b/src/core/hle/service/am/am.h
index c13aa5787..202d20757 100644
--- a/src/core/hle/service/am/am.h
+++ b/src/core/hle/service/am/am.h
@@ -8,7 +8,7 @@
8#include <memory> 8#include <memory>
9#include <queue> 9#include <queue>
10 10
11#include "core/hle/kernel/k_event.h" 11#include "core/hle/service/kernel_helpers.h"
12#include "core/hle/service/service.h" 12#include "core/hle/service/service.h"
13 13
14namespace Kernel { 14namespace Kernel {
@@ -53,7 +53,7 @@ public:
53 PerformanceModeChanged = 31, 53 PerformanceModeChanged = 31,
54 }; 54 };
55 55
56 explicit AppletMessageQueue(Kernel::KernelCore& kernel); 56 explicit AppletMessageQueue(Core::System& system);
57 ~AppletMessageQueue(); 57 ~AppletMessageQueue();
58 58
59 Kernel::KReadableEvent& GetMessageReceiveEvent(); 59 Kernel::KReadableEvent& GetMessageReceiveEvent();
@@ -66,9 +66,12 @@ public:
66 void OperationModeChanged(); 66 void OperationModeChanged();
67 67
68private: 68private:
69 KernelHelpers::ServiceContext service_context;
70
71 Kernel::KEvent* on_new_message;
72 Kernel::KEvent* on_operation_mode_changed;
73
69 std::queue<AppletMessage> messages; 74 std::queue<AppletMessage> messages;
70 Kernel::KEvent on_new_message;
71 Kernel::KEvent on_operation_mode_changed;
72}; 75};
73 76
74class IWindowController final : public ServiceFramework<IWindowController> { 77class IWindowController final : public ServiceFramework<IWindowController> {
@@ -156,8 +159,11 @@ private:
156 }; 159 };
157 160
158 NVFlinger::NVFlinger& nvflinger; 161 NVFlinger::NVFlinger& nvflinger;
159 Kernel::KEvent launchable_event; 162
160 Kernel::KEvent accumulated_suspended_tick_changed_event; 163 KernelHelpers::ServiceContext service_context;
164
165 Kernel::KEvent* launchable_event;
166 Kernel::KEvent* accumulated_suspended_tick_changed_event;
161 167
162 u32 idle_time_detection_extension = 0; 168 u32 idle_time_detection_extension = 0;
163 u64 num_fatal_sections_entered = 0; 169 u64 num_fatal_sections_entered = 0;
@@ -298,13 +304,15 @@ private:
298 void GetNotificationStorageChannelEvent(Kernel::HLERequestContext& ctx); 304 void GetNotificationStorageChannelEvent(Kernel::HLERequestContext& ctx);
299 void GetHealthWarningDisappearedSystemEvent(Kernel::HLERequestContext& ctx); 305 void GetHealthWarningDisappearedSystemEvent(Kernel::HLERequestContext& ctx);
300 306
307 KernelHelpers::ServiceContext service_context;
308
301 bool launch_popped_application_specific = false; 309 bool launch_popped_application_specific = false;
302 bool launch_popped_account_preselect = false; 310 bool launch_popped_account_preselect = false;
303 s32 previous_program_index{-1}; 311 s32 previous_program_index{-1};
304 Kernel::KEvent gpu_error_detected_event; 312 Kernel::KEvent* gpu_error_detected_event;
305 Kernel::KEvent friend_invitation_storage_channel_event; 313 Kernel::KEvent* friend_invitation_storage_channel_event;
306 Kernel::KEvent notification_storage_channel_event; 314 Kernel::KEvent* notification_storage_channel_event;
307 Kernel::KEvent health_warning_disappeared_system_event; 315 Kernel::KEvent* health_warning_disappeared_system_event;
308}; 316};
309 317
310class IHomeMenuFunctions final : public ServiceFramework<IHomeMenuFunctions> { 318class IHomeMenuFunctions final : public ServiceFramework<IHomeMenuFunctions> {
@@ -316,7 +324,9 @@ private:
316 void RequestToGetForeground(Kernel::HLERequestContext& ctx); 324 void RequestToGetForeground(Kernel::HLERequestContext& ctx);
317 void GetPopFromGeneralChannelEvent(Kernel::HLERequestContext& ctx); 325 void GetPopFromGeneralChannelEvent(Kernel::HLERequestContext& ctx);
318 326
319 Kernel::KEvent pop_from_general_channel_event; 327 KernelHelpers::ServiceContext service_context;
328
329 Kernel::KEvent* pop_from_general_channel_event;
320}; 330};
321 331
322class IGlobalStateController final : public ServiceFramework<IGlobalStateController> { 332class IGlobalStateController final : public ServiceFramework<IGlobalStateController> {
diff --git a/src/core/hle/service/am/applets/applets.cpp b/src/core/hle/service/am/applets/applets.cpp
index 2b7685d42..7320b1c0f 100644
--- a/src/core/hle/service/am/applets/applets.cpp
+++ b/src/core/hle/service/am/applets/applets.cpp
@@ -12,8 +12,7 @@
12#include "core/frontend/applets/profile_select.h" 12#include "core/frontend/applets/profile_select.h"
13#include "core/frontend/applets/software_keyboard.h" 13#include "core/frontend/applets/software_keyboard.h"
14#include "core/frontend/applets/web_browser.h" 14#include "core/frontend/applets/web_browser.h"
15#include "core/hle/kernel/k_readable_event.h" 15#include "core/hle/kernel/k_event.h"
16#include "core/hle/kernel/k_writable_event.h"
17#include "core/hle/service/am/am.h" 16#include "core/hle/service/am/am.h"
18#include "core/hle/service/am/applet_ae.h" 17#include "core/hle/service/am/applet_ae.h"
19#include "core/hle/service/am/applet_oe.h" 18#include "core/hle/service/am/applet_oe.h"
@@ -29,19 +28,19 @@
29namespace Service::AM::Applets { 28namespace Service::AM::Applets {
30 29
31AppletDataBroker::AppletDataBroker(Core::System& system_, LibraryAppletMode applet_mode_) 30AppletDataBroker::AppletDataBroker(Core::System& system_, LibraryAppletMode applet_mode_)
32 : system{system_}, applet_mode{applet_mode_}, state_changed_event{system.Kernel()}, 31 : system{system_}, applet_mode{applet_mode_}, service_context{system,
33 pop_out_data_event{system.Kernel()}, pop_interactive_out_data_event{system.Kernel()} { 32 "ILibraryAppletAccessor"} {
34 33 state_changed_event = service_context.CreateEvent("ILibraryAppletAccessor:StateChangedEvent");
35 Kernel::KAutoObject::Create(std::addressof(state_changed_event)); 34 pop_out_data_event = service_context.CreateEvent("ILibraryAppletAccessor:PopDataOutEvent");
36 Kernel::KAutoObject::Create(std::addressof(pop_out_data_event)); 35 pop_interactive_out_data_event =
37 Kernel::KAutoObject::Create(std::addressof(pop_interactive_out_data_event)); 36 service_context.CreateEvent("ILibraryAppletAccessor:PopInteractiveDataOutEvent");
38
39 state_changed_event.Initialize("ILibraryAppletAccessor:StateChangedEvent");
40 pop_out_data_event.Initialize("ILibraryAppletAccessor:PopDataOutEvent");
41 pop_interactive_out_data_event.Initialize("ILibraryAppletAccessor:PopInteractiveDataOutEvent");
42} 37}
43 38
44AppletDataBroker::~AppletDataBroker() = default; 39AppletDataBroker::~AppletDataBroker() {
40 service_context.CloseEvent(state_changed_event);
41 service_context.CloseEvent(pop_out_data_event);
42 service_context.CloseEvent(pop_interactive_out_data_event);
43}
45 44
46AppletDataBroker::RawChannelData AppletDataBroker::PeekDataToAppletForDebug() const { 45AppletDataBroker::RawChannelData AppletDataBroker::PeekDataToAppletForDebug() const {
47 std::vector<std::vector<u8>> out_normal; 46 std::vector<std::vector<u8>> out_normal;
@@ -65,7 +64,7 @@ std::shared_ptr<IStorage> AppletDataBroker::PopNormalDataToGame() {
65 64
66 auto out = std::move(out_channel.front()); 65 auto out = std::move(out_channel.front());
67 out_channel.pop_front(); 66 out_channel.pop_front();
68 pop_out_data_event.GetWritableEvent().Clear(); 67 pop_out_data_event->GetWritableEvent().Clear();
69 return out; 68 return out;
70} 69}
71 70
@@ -84,7 +83,7 @@ std::shared_ptr<IStorage> AppletDataBroker::PopInteractiveDataToGame() {
84 83
85 auto out = std::move(out_interactive_channel.front()); 84 auto out = std::move(out_interactive_channel.front());
86 out_interactive_channel.pop_front(); 85 out_interactive_channel.pop_front();
87 pop_interactive_out_data_event.GetWritableEvent().Clear(); 86 pop_interactive_out_data_event->GetWritableEvent().Clear();
88 return out; 87 return out;
89} 88}
90 89
@@ -103,7 +102,7 @@ void AppletDataBroker::PushNormalDataFromGame(std::shared_ptr<IStorage>&& storag
103 102
104void AppletDataBroker::PushNormalDataFromApplet(std::shared_ptr<IStorage>&& storage) { 103void AppletDataBroker::PushNormalDataFromApplet(std::shared_ptr<IStorage>&& storage) {
105 out_channel.emplace_back(std::move(storage)); 104 out_channel.emplace_back(std::move(storage));
106 pop_out_data_event.GetWritableEvent().Signal(); 105 pop_out_data_event->GetWritableEvent().Signal();
107} 106}
108 107
109void AppletDataBroker::PushInteractiveDataFromGame(std::shared_ptr<IStorage>&& storage) { 108void AppletDataBroker::PushInteractiveDataFromGame(std::shared_ptr<IStorage>&& storage) {
@@ -112,11 +111,11 @@ void AppletDataBroker::PushInteractiveDataFromGame(std::shared_ptr<IStorage>&& s
112 111
113void AppletDataBroker::PushInteractiveDataFromApplet(std::shared_ptr<IStorage>&& storage) { 112void AppletDataBroker::PushInteractiveDataFromApplet(std::shared_ptr<IStorage>&& storage) {
114 out_interactive_channel.emplace_back(std::move(storage)); 113 out_interactive_channel.emplace_back(std::move(storage));
115 pop_interactive_out_data_event.GetWritableEvent().Signal(); 114 pop_interactive_out_data_event->GetWritableEvent().Signal();
116} 115}
117 116
118void AppletDataBroker::SignalStateChanged() { 117void AppletDataBroker::SignalStateChanged() {
119 state_changed_event.GetWritableEvent().Signal(); 118 state_changed_event->GetWritableEvent().Signal();
120 119
121 switch (applet_mode) { 120 switch (applet_mode) {
122 case LibraryAppletMode::AllForeground: 121 case LibraryAppletMode::AllForeground:
@@ -141,15 +140,15 @@ void AppletDataBroker::SignalStateChanged() {
141} 140}
142 141
143Kernel::KReadableEvent& AppletDataBroker::GetNormalDataEvent() { 142Kernel::KReadableEvent& AppletDataBroker::GetNormalDataEvent() {
144 return pop_out_data_event.GetReadableEvent(); 143 return pop_out_data_event->GetReadableEvent();
145} 144}
146 145
147Kernel::KReadableEvent& AppletDataBroker::GetInteractiveDataEvent() { 146Kernel::KReadableEvent& AppletDataBroker::GetInteractiveDataEvent() {
148 return pop_interactive_out_data_event.GetReadableEvent(); 147 return pop_interactive_out_data_event->GetReadableEvent();
149} 148}
150 149
151Kernel::KReadableEvent& AppletDataBroker::GetStateChangedEvent() { 150Kernel::KReadableEvent& AppletDataBroker::GetStateChangedEvent() {
152 return state_changed_event.GetReadableEvent(); 151 return state_changed_event->GetReadableEvent();
153} 152}
154 153
155Applet::Applet(Core::System& system_, LibraryAppletMode applet_mode_) 154Applet::Applet(Core::System& system_, LibraryAppletMode applet_mode_)
diff --git a/src/core/hle/service/am/applets/applets.h b/src/core/hle/service/am/applets/applets.h
index 5c0b4b459..15eeb4ee1 100644
--- a/src/core/hle/service/am/applets/applets.h
+++ b/src/core/hle/service/am/applets/applets.h
@@ -8,7 +8,7 @@
8#include <queue> 8#include <queue>
9 9
10#include "common/swap.h" 10#include "common/swap.h"
11#include "core/hle/kernel/k_event.h" 11#include "core/hle/service/kernel_helpers.h"
12 12
13union ResultCode; 13union ResultCode;
14 14
@@ -105,6 +105,8 @@ private:
105 Core::System& system; 105 Core::System& system;
106 LibraryAppletMode applet_mode; 106 LibraryAppletMode applet_mode;
107 107
108 KernelHelpers::ServiceContext service_context;
109
108 // Queues are named from applet's perspective 110 // Queues are named from applet's perspective
109 111
110 // PopNormalDataToApplet and PushNormalDataFromGame 112 // PopNormalDataToApplet and PushNormalDataFromGame
@@ -119,13 +121,13 @@ private:
119 // PopInteractiveDataToGame and PushInteractiveDataFromApplet 121 // PopInteractiveDataToGame and PushInteractiveDataFromApplet
120 std::deque<std::shared_ptr<IStorage>> out_interactive_channel; 122 std::deque<std::shared_ptr<IStorage>> out_interactive_channel;
121 123
122 Kernel::KEvent state_changed_event; 124 Kernel::KEvent* state_changed_event;
123 125
124 // Signaled on PushNormalDataFromApplet 126 // Signaled on PushNormalDataFromApplet
125 Kernel::KEvent pop_out_data_event; 127 Kernel::KEvent* pop_out_data_event;
126 128
127 // Signaled on PushInteractiveDataFromApplet 129 // Signaled on PushInteractiveDataFromApplet
128 Kernel::KEvent pop_interactive_out_data_event; 130 Kernel::KEvent* pop_interactive_out_data_event;
129}; 131};
130 132
131class Applet { 133class Applet {