From 83393a6c6bedc9c00378c73721ec17c7a4fb2b71 Mon Sep 17 00:00:00 2001 From: Zephyron Date: Mon, 6 Jan 2025 16:57:45 +1000 Subject: [PATCH] service/am: Implement friend invitation storage channel Implements TryPopFromFriendInvitationStorageChannel to properly handle friend invitation data storage and retrieval. This includes: - Add ResultNoData error code to am_results.h - Add friend_invitation_storage_channel storage queue to Applet struct - Implement proper data handling in TryPopFromFriendInvitationStorageChannel The implementation now properly manages a queue of friend invitation data and returns appropriate results based on data availability. --- src/core/hle/service/am/am_results.h | 1 + src/core/hle/service/am/applet.h | 3 +++ .../am/service/application_functions.cpp | 18 ++++++++++++++++-- 3 files changed, 20 insertions(+), 2 deletions(-) diff --git a/src/core/hle/service/am/am_results.h b/src/core/hle/service/am/am_results.h index 020896a2e..17bed2b12 100644 --- a/src/core/hle/service/am/am_results.h +++ b/src/core/hle/service/am/am_results.h @@ -13,5 +13,6 @@ constexpr Result ResultLibraryAppletTerminated{ErrorModule::AM, 22}; constexpr Result ResultInvalidOffset{ErrorModule::AM, 503}; constexpr Result ResultInvalidStorageType{ErrorModule::AM, 511}; constexpr Result ResultFatalSectionCountImbalance{ErrorModule::AM, 512}; +constexpr Result ResultNoData{ErrorModule::AM, 2}; } // namespace Service::AM diff --git a/src/core/hle/service/am/applet.h b/src/core/hle/service/am/applet.h index 0e286b8d7..a9b558618 100644 --- a/src/core/hle/service/am/applet.h +++ b/src/core/hle/service/am/applet.h @@ -133,6 +133,9 @@ struct Applet { void UpdateSuspensionStateLocked(bool force_message); void SetInteractibleLocked(bool interactible); void OnProcessTerminatedLocked(); + + // Storage channels + std::deque> friend_invitation_storage_channel; }; } // namespace Service::AM diff --git a/src/core/hle/service/am/service/application_functions.cpp b/src/core/hle/service/am/service/application_functions.cpp index 5e5b9e771..19635d0c7 100644 --- a/src/core/hle/service/am/service/application_functions.cpp +++ b/src/core/hle/service/am/service/application_functions.cpp @@ -456,8 +456,22 @@ Result IApplicationFunctions::GetFriendInvitationStorageChannelEvent( Result IApplicationFunctions::TryPopFromFriendInvitationStorageChannel( Out> out_storage) { - LOG_INFO(Service_AM, "(STUBBED) called"); - R_THROW(AM::ResultNoDataInChannel); + LOG_DEBUG(Service_AM, "called"); + + std::scoped_lock lock{m_applet->lock}; + + // Check if there's any data in the friend invitation storage channel + if (m_applet->friend_invitation_storage_channel.empty()) { + R_THROW(AM::ResultNoData); + } + + // Pop the most recent data + std::vector data = std::move(m_applet->friend_invitation_storage_channel.front()); + m_applet->friend_invitation_storage_channel.pop_front(); + + // Create IStorage containing the data + *out_storage = std::make_shared(system, std::move(data)); + R_SUCCEED(); } Result IApplicationFunctions::GetNotificationStorageChannelEvent(