ICommonStateGetter.cs 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. using Ryujinx.Core.Logging;
  2. using Ryujinx.Core.OsHle.Handles;
  3. using Ryujinx.Core.OsHle.Ipc;
  4. using System.Collections.Generic;
  5. using static Ryujinx.Core.OsHle.ErrorCode;
  6. namespace Ryujinx.Core.OsHle.Services.Am
  7. {
  8. class ICommonStateGetter : IpcService
  9. {
  10. private Dictionary<int, ServiceProcessRequest> m_Commands;
  11. public override IReadOnlyDictionary<int, ServiceProcessRequest> Commands => m_Commands;
  12. public ICommonStateGetter()
  13. {
  14. m_Commands = new Dictionary<int, ServiceProcessRequest>()
  15. {
  16. { 0, GetEventHandle },
  17. { 1, ReceiveMessage },
  18. { 5, GetOperationMode },
  19. { 6, GetPerformanceMode },
  20. { 8, GetBootMode },
  21. { 9, GetCurrentFocusState }
  22. };
  23. }
  24. public long GetEventHandle(ServiceCtx Context)
  25. {
  26. KEvent Event = Context.Process.AppletState.MessageEvent;
  27. int Handle = Context.Process.HandleTable.OpenHandle(Event);
  28. Context.Response.HandleDesc = IpcHandleDesc.MakeCopy(Handle);
  29. return 0;
  30. }
  31. public long ReceiveMessage(ServiceCtx Context)
  32. {
  33. if (!Context.Process.AppletState.TryDequeueMessage(out MessageInfo Message))
  34. {
  35. return MakeError(ErrorModule.Am, AmErr.NoMessages);
  36. }
  37. Context.ResponseData.Write((int)Message);
  38. return 0;
  39. }
  40. public long GetOperationMode(ServiceCtx Context)
  41. {
  42. Context.ResponseData.Write((byte)OperationMode.Handheld);
  43. return 0;
  44. }
  45. public long GetPerformanceMode(ServiceCtx Context)
  46. {
  47. Context.ResponseData.Write((byte)Apm.PerformanceMode.Handheld);
  48. return 0;
  49. }
  50. public long GetBootMode(ServiceCtx Context)
  51. {
  52. Context.ResponseData.Write((byte)0); //Unknown value.
  53. Context.Ns.Log.PrintStub(LogClass.ServiceAm, "Stubbed.");
  54. return 0;
  55. }
  56. public long GetCurrentFocusState(ServiceCtx Context)
  57. {
  58. Context.ResponseData.Write((byte)Context.Process.AppletState.FocusState);
  59. return 0;
  60. }
  61. }
  62. }