async_context.cpp 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. // SPDX-FileCopyrightText: Copyright 2021 yuzu Emulator Project
  2. // SPDX-License-Identifier: GPL-2.0-or-later
  3. #include "core/core.h"
  4. #include "core/hle/kernel/k_event.h"
  5. #include "core/hle/service/acc/async_context.h"
  6. #include "core/hle/service/ipc_helpers.h"
  7. namespace Service::Account {
  8. IAsyncContext::IAsyncContext(Core::System& system_)
  9. : ServiceFramework{system_, "IAsyncContext"}, service_context{system_, "IAsyncContext"} {
  10. // clang-format off
  11. static const FunctionInfo functions[] = {
  12. {0, &IAsyncContext::GetSystemEvent, "GetSystemEvent"},
  13. {1, &IAsyncContext::Cancel, "Cancel"},
  14. {2, &IAsyncContext::HasDone, "HasDone"},
  15. {3, &IAsyncContext::GetResult, "GetResult"},
  16. };
  17. // clang-format on
  18. RegisterHandlers(functions);
  19. completion_event = service_context.CreateEvent("IAsyncContext:CompletionEvent");
  20. }
  21. IAsyncContext::~IAsyncContext() {
  22. service_context.CloseEvent(completion_event);
  23. }
  24. void IAsyncContext::GetSystemEvent(HLERequestContext& ctx) {
  25. LOG_DEBUG(Service_ACC, "called");
  26. IPC::ResponseBuilder rb{ctx, 2, 1};
  27. rb.Push(ResultSuccess);
  28. rb.PushCopyObjects(completion_event->GetReadableEvent());
  29. }
  30. void IAsyncContext::Cancel(HLERequestContext& ctx) {
  31. LOG_DEBUG(Service_ACC, "called");
  32. Cancel();
  33. MarkComplete();
  34. IPC::ResponseBuilder rb{ctx, 2};
  35. rb.Push(ResultSuccess);
  36. }
  37. void IAsyncContext::HasDone(HLERequestContext& ctx) {
  38. LOG_DEBUG(Service_ACC, "called");
  39. is_complete.store(IsComplete());
  40. IPC::ResponseBuilder rb{ctx, 3};
  41. rb.Push(ResultSuccess);
  42. rb.Push(is_complete.load());
  43. }
  44. void IAsyncContext::GetResult(HLERequestContext& ctx) {
  45. LOG_DEBUG(Service_ACC, "called");
  46. IPC::ResponseBuilder rb{ctx, 3};
  47. rb.Push(GetResult());
  48. }
  49. void IAsyncContext::MarkComplete() {
  50. is_complete.store(true);
  51. completion_event->Signal();
  52. }
  53. } // namespace Service::Account