IUser.cs 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. using Ryujinx.Common.Logging;
  2. using Ryujinx.HLE.HOS.Ipc;
  3. using Ryujinx.HLE.HOS.Kernel.Common;
  4. using Ryujinx.HLE.HOS.Kernel.Threading;
  5. using Ryujinx.HLE.Input;
  6. using System;
  7. using System.Collections.Generic;
  8. namespace Ryujinx.HLE.HOS.Services.Nfp
  9. {
  10. class IUser : IpcService
  11. {
  12. private Dictionary<int, ServiceProcessRequest> _commands;
  13. public override IReadOnlyDictionary<int, ServiceProcessRequest> Commands => _commands;
  14. private const HidControllerId NpadId = HidControllerId.ControllerPlayer1;
  15. private State _state = State.NonInitialized;
  16. private DeviceState _deviceState = DeviceState.Initialized;
  17. private KEvent _activateEvent;
  18. private KEvent _deactivateEvent;
  19. private KEvent _availabilityChangeEvent;
  20. public IUser(Horizon system)
  21. {
  22. _commands = new Dictionary<int, ServiceProcessRequest>
  23. {
  24. { 0, Initialize },
  25. { 17, AttachActivateEvent },
  26. { 18, AttachDeactivateEvent },
  27. { 19, GetState },
  28. { 20, GetDeviceState },
  29. { 21, GetNpadId },
  30. { 23, AttachAvailabilityChangeEvent }
  31. };
  32. _activateEvent = new KEvent(system);
  33. _deactivateEvent = new KEvent(system);
  34. _availabilityChangeEvent = new KEvent(system);
  35. }
  36. public long Initialize(ServiceCtx context)
  37. {
  38. Logger.PrintStub(LogClass.ServiceNfp);
  39. _state = State.Initialized;
  40. return 0;
  41. }
  42. public long AttachActivateEvent(ServiceCtx context)
  43. {
  44. Logger.PrintStub(LogClass.ServiceNfp);
  45. if (context.Process.HandleTable.GenerateHandle(_activateEvent.ReadableEvent, out int handle) != KernelResult.Success)
  46. {
  47. throw new InvalidOperationException("Out of handles!");
  48. }
  49. context.Response.HandleDesc = IpcHandleDesc.MakeCopy(handle);
  50. return 0;
  51. }
  52. public long AttachDeactivateEvent(ServiceCtx context)
  53. {
  54. Logger.PrintStub(LogClass.ServiceNfp);
  55. if (context.Process.HandleTable.GenerateHandle(_deactivateEvent.ReadableEvent, out int handle) != KernelResult.Success)
  56. {
  57. throw new InvalidOperationException("Out of handles!");
  58. }
  59. context.Response.HandleDesc = IpcHandleDesc.MakeCopy(handle);
  60. return 0;
  61. }
  62. public long GetState(ServiceCtx context)
  63. {
  64. context.ResponseData.Write((int)_state);
  65. Logger.PrintStub(LogClass.ServiceNfp);
  66. return 0;
  67. }
  68. public long GetDeviceState(ServiceCtx context)
  69. {
  70. context.ResponseData.Write((int)_deviceState);
  71. Logger.PrintStub(LogClass.ServiceNfp);
  72. return 0;
  73. }
  74. public long GetNpadId(ServiceCtx context)
  75. {
  76. context.ResponseData.Write((int)NpadId);
  77. Logger.PrintStub(LogClass.ServiceNfp);
  78. return 0;
  79. }
  80. public long AttachAvailabilityChangeEvent(ServiceCtx context)
  81. {
  82. Logger.PrintStub(LogClass.ServiceNfp);
  83. if (context.Process.HandleTable.GenerateHandle(_availabilityChangeEvent.ReadableEvent, out int handle) != KernelResult.Success)
  84. {
  85. throw new InvalidOperationException("Out of handles!");
  86. }
  87. context.Response.HandleDesc = IpcHandleDesc.MakeCopy(handle);
  88. return 0;
  89. }
  90. }
  91. }