async_context.cpp 1.9 KB

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