IAsyncContext.cs 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. using Ryujinx.HLE.HOS.Ipc;
  2. using Ryujinx.HLE.HOS.Kernel.Common;
  3. using Ryujinx.HLE.HOS.Services.Account.Acc.AsyncContext;
  4. using System;
  5. namespace Ryujinx.HLE.HOS.Services.Account.Acc
  6. {
  7. class IAsyncContext : IpcService
  8. {
  9. AsyncExecution _asyncExecution;
  10. public IAsyncContext(AsyncExecution asyncExecution)
  11. {
  12. _asyncExecution = asyncExecution;
  13. }
  14. [CommandHipc(0)]
  15. // GetSystemEvent() -> handle<copy>
  16. public ResultCode GetSystemEvent(ServiceCtx context)
  17. {
  18. if (context.Process.HandleTable.GenerateHandle(_asyncExecution.SystemEvent.ReadableEvent, out int _systemEventHandle) != KernelResult.Success)
  19. {
  20. throw new InvalidOperationException("Out of handles!");
  21. }
  22. context.Response.HandleDesc = IpcHandleDesc.MakeCopy(_systemEventHandle);
  23. return ResultCode.Success;
  24. }
  25. [CommandHipc(1)]
  26. // Cancel()
  27. public ResultCode Cancel(ServiceCtx context)
  28. {
  29. if (!_asyncExecution.IsInitialized)
  30. {
  31. return ResultCode.AsyncExecutionNotInitialized;
  32. }
  33. if (_asyncExecution.IsRunning)
  34. {
  35. _asyncExecution.Cancel();
  36. }
  37. return ResultCode.Success;
  38. }
  39. [CommandHipc(2)]
  40. // HasDone() -> b8
  41. public ResultCode HasDone(ServiceCtx context)
  42. {
  43. if (!_asyncExecution.IsInitialized)
  44. {
  45. return ResultCode.AsyncExecutionNotInitialized;
  46. }
  47. context.ResponseData.Write(_asyncExecution.SystemEvent.ReadableEvent.IsSignaled());
  48. return ResultCode.Success;
  49. }
  50. [CommandHipc(3)]
  51. // GetResult()
  52. public ResultCode GetResult(ServiceCtx context)
  53. {
  54. if (!_asyncExecution.IsInitialized)
  55. {
  56. return ResultCode.AsyncExecutionNotInitialized;
  57. }
  58. if (!_asyncExecution.SystemEvent.ReadableEvent.IsSignaled())
  59. {
  60. return ResultCode.Unknown41;
  61. }
  62. return ResultCode.Success;
  63. }
  64. }
  65. }