From 4e2aa50cefd56f4bb119c9c6e6ab89afbb31351e Mon Sep 17 00:00:00 2001 From: Chloe Marcec Date: Mon, 6 Sep 2021 21:16:21 +1000 Subject: account: EnsureTokenIdCacheAsync Closes #2547, #6946 --- src/core/CMakeLists.txt | 2 + src/core/hle/service/acc/acc.cpp | 67 ++++++++++++++++++++--------- src/core/hle/service/acc/async_context.cpp | 68 ++++++++++++++++++++++++++++++ src/core/hle/service/acc/async_context.h | 36 ++++++++++++++++ 4 files changed, 154 insertions(+), 19 deletions(-) create mode 100644 src/core/hle/service/acc/async_context.cpp create mode 100644 src/core/hle/service/acc/async_context.h (limited to 'src') diff --git a/src/core/CMakeLists.txt b/src/core/CMakeLists.txt index 87d47e2e5..7140d0db8 100644 --- a/src/core/CMakeLists.txt +++ b/src/core/CMakeLists.txt @@ -263,6 +263,8 @@ add_library(core STATIC hle/service/acc/acc_u0.h hle/service/acc/acc_u1.cpp hle/service/acc/acc_u1.h + hle/service/acc/async_context.cpp + hle/service/acc/async_context.h hle/service/acc/errors.h hle/service/acc/profile_manager.cpp hle/service/acc/profile_manager.h diff --git a/src/core/hle/service/acc/acc.cpp b/src/core/hle/service/acc/acc.cpp index 882fc1492..1db054257 100644 --- a/src/core/hle/service/acc/acc.cpp +++ b/src/core/hle/service/acc/acc.cpp @@ -23,6 +23,7 @@ #include "core/hle/service/acc/acc_su.h" #include "core/hle/service/acc/acc_u0.h" #include "core/hle/service/acc/acc_u1.h" +#include "core/hle/service/acc/async_context.h" #include "core/hle/service/acc/errors.h" #include "core/hle/service/acc/profile_manager.h" #include "core/hle/service/glue/arp.h" @@ -454,22 +455,6 @@ public: : IProfileCommon{system_, "IProfileEditor", true, user_id_, profile_manager_} {} }; -class IAsyncContext final : public ServiceFramework { -public: - explicit IAsyncContext(Core::System& system_) : ServiceFramework{system_, "IAsyncContext"} { - // clang-format off - static const FunctionInfo functions[] = { - {0, nullptr, "GetSystemEvent"}, - {1, nullptr, "Cancel"}, - {2, nullptr, "HasDone"}, - {3, nullptr, "GetResult"}, - }; - // clang-format on - - RegisterHandlers(functions); - } -}; - class ISessionObject final : public ServiceFramework { public: explicit ISessionObject(Core::System& system_, Common::UUID) @@ -504,16 +489,42 @@ public: } }; +class EnsureTokenIdCacheAsyncInterface final : public IAsyncContext { +public: + explicit EnsureTokenIdCacheAsyncInterface(Core::System& system_) : IAsyncContext(system_) { + MarkComplete(); + } + ~EnsureTokenIdCacheAsyncInterface() = default; + + void LoadIdTokenCache(Kernel::HLERequestContext& ctx) { + LOG_WARNING(Service_ACC, "(STUBBED) called"); + + IPC::ResponseBuilder rb{ctx, 2}; + rb.Push(ResultSuccess); + } + +protected: + bool IsComplete() override { + return true; + } + + void Cancel() override {} + + ResultCode GetResult() override { + return ResultSuccess; + } +}; + class IManagerForApplication final : public ServiceFramework { public: explicit IManagerForApplication(Core::System& system_, Common::UUID user_id_) - : ServiceFramework{system_, "IManagerForApplication"}, user_id{user_id_} { + : ServiceFramework{system_, "IManagerForApplication"}, user_id{user_id_}, system(system_) { // clang-format off static const FunctionInfo functions[] = { {0, &IManagerForApplication::CheckAvailability, "CheckAvailability"}, {1, &IManagerForApplication::GetAccountId, "GetAccountId"}, - {2, nullptr, "EnsureIdTokenCacheAsync"}, - {3, nullptr, "LoadIdTokenCache"}, + {2, &IManagerForApplication::EnsureIdTokenCacheAsync, "EnsureIdTokenCacheAsync"}, + {3, &IManagerForApplication::LoadIdTokenCache, "LoadIdTokenCache"}, {130, &IManagerForApplication::GetNintendoAccountUserResourceCacheForApplication, "GetNintendoAccountUserResourceCacheForApplication"}, {150, nullptr, "CreateAuthorizationRequest"}, {160, &IManagerForApplication::StoreOpenContext, "StoreOpenContext"}, @@ -522,6 +533,8 @@ public: // clang-format on RegisterHandlers(functions); + + ensure_token_id = std::make_shared(system); } private: @@ -540,6 +553,20 @@ private: rb.PushRaw(user_id.GetNintendoID()); } + void EnsureIdTokenCacheAsync(Kernel::HLERequestContext& ctx) { + LOG_WARNING(Service_ACC, "(STUBBED) called"); + + IPC::ResponseBuilder rb{ctx, 2, 0, 1}; + rb.Push(ResultSuccess); + rb.PushIpcInterface(ensure_token_id); + } + + void LoadIdTokenCache(Kernel::HLERequestContext& ctx) { + LOG_WARNING(Service_ACC, "(STUBBED) called"); + + ensure_token_id->LoadIdTokenCache(ctx); + } + void GetNintendoAccountUserResourceCacheForApplication(Kernel::HLERequestContext& ctx) { LOG_WARNING(Service_ACC, "(STUBBED) called"); @@ -562,7 +589,9 @@ private: rb.Push(ResultSuccess); } + std::shared_ptr ensure_token_id{}; Common::UUID user_id{Common::INVALID_UUID}; + Core::System& system; }; // 6.0.0+ diff --git a/src/core/hle/service/acc/async_context.cpp b/src/core/hle/service/acc/async_context.cpp new file mode 100644 index 000000000..a58429090 --- /dev/null +++ b/src/core/hle/service/acc/async_context.cpp @@ -0,0 +1,68 @@ +// Copyright 2021 yuzu emulator team +// Licensed under GPLv2 or any later version +// Refer to the license.txt file included. + +#include "core/core.h" +#include "core/hle/ipc_helpers.h" +#include "core/hle/service/acc/async_context.h" + +namespace Service::Account { +IAsyncContext::IAsyncContext(Core::System& system) + : ServiceFramework{system, "IAsyncContext"}, compeletion_event{system.Kernel()} { + + Kernel::KAutoObject::Create(std::addressof(compeletion_event)); + compeletion_event.Initialize("IAsyncContext:CompletionEvent"); + + // clang-format off + static const FunctionInfo functions[] = { + {0, &IAsyncContext::GetSystemEvent, "GetSystemEvent"}, + {1, &IAsyncContext::Cancel, "Cancel"}, + {2, &IAsyncContext::HasDone, "HasDone"}, + {3, &IAsyncContext::GetResult, "GetResult"}, + }; + // clang-format on + + RegisterHandlers(functions); +} + +void IAsyncContext::GetSystemEvent(Kernel::HLERequestContext& ctx) { + LOG_DEBUG(Service_ACC, "called"); + + IPC::ResponseBuilder rb{ctx, 2, 1}; + rb.Push(ResultSuccess); + rb.PushCopyObjects(compeletion_event.GetReadableEvent()); +} + +void IAsyncContext::Cancel(Kernel::HLERequestContext& ctx) { + LOG_DEBUG(Service_ACC, "called"); + + Cancel(); + MarkComplete(); + + IPC::ResponseBuilder rb{ctx, 2}; + rb.Push(ResultSuccess); +} + +void IAsyncContext::HasDone(Kernel::HLERequestContext& ctx) { + LOG_DEBUG(Service_ACC, "called"); + + is_complete = IsComplete(); + + IPC::ResponseBuilder rb{ctx, 3}; + rb.Push(ResultSuccess); + rb.Push(is_complete); +} + +void IAsyncContext::GetResult(Kernel::HLERequestContext& ctx) { + LOG_DEBUG(Service_ACC, "called"); + + IPC::ResponseBuilder rb{ctx, 3}; + rb.Push(GetResult()); +} + +void IAsyncContext::MarkComplete() { + is_complete = true; + compeletion_event.GetWritableEvent().Signal(); +} + +} // namespace Service::Account diff --git a/src/core/hle/service/acc/async_context.h b/src/core/hle/service/acc/async_context.h new file mode 100644 index 000000000..2453a79f5 --- /dev/null +++ b/src/core/hle/service/acc/async_context.h @@ -0,0 +1,36 @@ +// Copyright 2021 yuzu emulator team +// Licensed under GPLv2 or any later version +// Refer to the license.txt file included. + +#pragma once + +#include "core/hle/kernel/k_event.h" +#include "core/hle/service/service.h" + +namespace Core { +class System; +} + +namespace Service::Account { + +class IAsyncContext : public ServiceFramework { +public: + explicit IAsyncContext(Core::System& system_); + + void GetSystemEvent(Kernel::HLERequestContext& ctx); + void Cancel(Kernel::HLERequestContext& ctx); + void HasDone(Kernel::HLERequestContext& ctx); + void GetResult(Kernel::HLERequestContext& ctx); + +protected: + virtual bool IsComplete() = 0; + virtual void Cancel() = 0; + virtual ResultCode GetResult() = 0; + + void MarkComplete(); + + bool is_complete{false}; + Kernel::KEvent compeletion_event; +}; + +} // namespace Service::Account -- cgit v1.2.3 From 9141816b101cf12635f3a64cbe796c93b6108cdd Mon Sep 17 00:00:00 2001 From: Chloe Marcec Date: Mon, 6 Sep 2021 22:13:51 +1000 Subject: address name shadowing with system --- src/core/hle/service/acc/async_context.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/core/hle/service/acc/async_context.cpp b/src/core/hle/service/acc/async_context.cpp index a58429090..a9a8888ed 100644 --- a/src/core/hle/service/acc/async_context.cpp +++ b/src/core/hle/service/acc/async_context.cpp @@ -7,8 +7,8 @@ #include "core/hle/service/acc/async_context.h" namespace Service::Account { -IAsyncContext::IAsyncContext(Core::System& system) - : ServiceFramework{system, "IAsyncContext"}, compeletion_event{system.Kernel()} { +IAsyncContext::IAsyncContext(Core::System& system_) + : ServiceFramework{system_, "IAsyncContext"}, compeletion_event{system_.Kernel()} { Kernel::KAutoObject::Create(std::addressof(compeletion_event)); compeletion_event.Initialize("IAsyncContext:CompletionEvent"); -- cgit v1.2.3 From 89958e27aa81fb376005f262d725692698321607 Mon Sep 17 00:00:00 2001 From: Chloe Marcec Date: Thu, 9 Sep 2021 00:09:04 +1000 Subject: Addressed issues --- src/core/hle/service/acc/acc.cpp | 13 ++++++------- src/core/hle/service/acc/async_context.cpp | 12 ++++++------ src/core/hle/service/acc/async_context.h | 4 ++-- 3 files changed, 14 insertions(+), 15 deletions(-) (limited to 'src') diff --git a/src/core/hle/service/acc/acc.cpp b/src/core/hle/service/acc/acc.cpp index 1db054257..6d9ec0a8a 100644 --- a/src/core/hle/service/acc/acc.cpp +++ b/src/core/hle/service/acc/acc.cpp @@ -491,7 +491,7 @@ public: class EnsureTokenIdCacheAsyncInterface final : public IAsyncContext { public: - explicit EnsureTokenIdCacheAsyncInterface(Core::System& system_) : IAsyncContext(system_) { + explicit EnsureTokenIdCacheAsyncInterface(Core::System& system_) : IAsyncContext{system_} { MarkComplete(); } ~EnsureTokenIdCacheAsyncInterface() = default; @@ -504,13 +504,13 @@ public: } protected: - bool IsComplete() override { + bool IsComplete() const override { return true; } void Cancel() override {} - ResultCode GetResult() override { + ResultCode GetResult() const override { return ResultSuccess; } }; @@ -518,7 +518,9 @@ protected: class IManagerForApplication final : public ServiceFramework { public: explicit IManagerForApplication(Core::System& system_, Common::UUID user_id_) - : ServiceFramework{system_, "IManagerForApplication"}, user_id{user_id_}, system(system_) { + : ServiceFramework{system_, "IManagerForApplication"}, + ensure_token_id{std::make_shared(system)}, + user_id{user_id_} { // clang-format off static const FunctionInfo functions[] = { {0, &IManagerForApplication::CheckAvailability, "CheckAvailability"}, @@ -533,8 +535,6 @@ public: // clang-format on RegisterHandlers(functions); - - ensure_token_id = std::make_shared(system); } private: @@ -591,7 +591,6 @@ private: std::shared_ptr ensure_token_id{}; Common::UUID user_id{Common::INVALID_UUID}; - Core::System& system; }; // 6.0.0+ diff --git a/src/core/hle/service/acc/async_context.cpp b/src/core/hle/service/acc/async_context.cpp index a9a8888ed..f7a7e34ea 100644 --- a/src/core/hle/service/acc/async_context.cpp +++ b/src/core/hle/service/acc/async_context.cpp @@ -14,12 +14,12 @@ IAsyncContext::IAsyncContext(Core::System& system_) compeletion_event.Initialize("IAsyncContext:CompletionEvent"); // clang-format off - static const FunctionInfo functions[] = { - {0, &IAsyncContext::GetSystemEvent, "GetSystemEvent"}, - {1, &IAsyncContext::Cancel, "Cancel"}, - {2, &IAsyncContext::HasDone, "HasDone"}, - {3, &IAsyncContext::GetResult, "GetResult"}, - }; + static const FunctionInfo functions[] = { + {0, &IAsyncContext::GetSystemEvent, "GetSystemEvent"}, + {1, &IAsyncContext::Cancel, "Cancel"}, + {2, &IAsyncContext::HasDone, "HasDone"}, + {3, &IAsyncContext::GetResult, "GetResult"}, + }; // clang-format on RegisterHandlers(functions); diff --git a/src/core/hle/service/acc/async_context.h b/src/core/hle/service/acc/async_context.h index 2453a79f5..6592326d0 100644 --- a/src/core/hle/service/acc/async_context.h +++ b/src/core/hle/service/acc/async_context.h @@ -23,9 +23,9 @@ public: void GetResult(Kernel::HLERequestContext& ctx); protected: - virtual bool IsComplete() = 0; + virtual bool IsComplete() const = 0; virtual void Cancel() = 0; - virtual ResultCode GetResult() = 0; + virtual ResultCode GetResult() const = 0; void MarkComplete(); -- cgit v1.2.3 From 543081e4a198386a7208d0fe63411c149c4e36f5 Mon Sep 17 00:00:00 2001 From: Chloe Marcec Date: Thu, 9 Sep 2021 00:10:52 +1000 Subject: Mark is_complete as atomic --- src/core/hle/service/acc/async_context.cpp | 6 +++--- src/core/hle/service/acc/async_context.h | 3 ++- 2 files changed, 5 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/core/hle/service/acc/async_context.cpp b/src/core/hle/service/acc/async_context.cpp index f7a7e34ea..459323132 100644 --- a/src/core/hle/service/acc/async_context.cpp +++ b/src/core/hle/service/acc/async_context.cpp @@ -46,11 +46,11 @@ void IAsyncContext::Cancel(Kernel::HLERequestContext& ctx) { void IAsyncContext::HasDone(Kernel::HLERequestContext& ctx) { LOG_DEBUG(Service_ACC, "called"); - is_complete = IsComplete(); + is_complete.store(IsComplete()); IPC::ResponseBuilder rb{ctx, 3}; rb.Push(ResultSuccess); - rb.Push(is_complete); + rb.Push(is_complete.load()); } void IAsyncContext::GetResult(Kernel::HLERequestContext& ctx) { @@ -61,7 +61,7 @@ void IAsyncContext::GetResult(Kernel::HLERequestContext& ctx) { } void IAsyncContext::MarkComplete() { - is_complete = true; + is_complete.store(true); compeletion_event.GetWritableEvent().Signal(); } diff --git a/src/core/hle/service/acc/async_context.h b/src/core/hle/service/acc/async_context.h index 6592326d0..c694b4946 100644 --- a/src/core/hle/service/acc/async_context.h +++ b/src/core/hle/service/acc/async_context.h @@ -4,6 +4,7 @@ #pragma once +#include #include "core/hle/kernel/k_event.h" #include "core/hle/service/service.h" @@ -29,7 +30,7 @@ protected: void MarkComplete(); - bool is_complete{false}; + std::atomic is_complete{false}; Kernel::KEvent compeletion_event; }; -- cgit v1.2.3