IUser.cs 3.7 KB

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