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> m_Commands;
  12. public override IReadOnlyDictionary<int, ServiceProcessRequest> Commands => m_Commands;
  13. private const HidControllerId NpadId = HidControllerId.CONTROLLER_PLAYER_1;
  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. m_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. }