IEnsureNetworkClockAvailabilityService.cs 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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 System;
  6. namespace Ryujinx.HLE.HOS.Services.Nim.Ntc.StaticService
  7. {
  8. class IEnsureNetworkClockAvailabilityService : IpcService
  9. {
  10. private KEvent _finishNotificationEvent;
  11. private ResultCode _taskResultCode;
  12. public IEnsureNetworkClockAvailabilityService(ServiceCtx context)
  13. {
  14. _finishNotificationEvent = new KEvent(context.Device.System.KernelContext);
  15. _taskResultCode = ResultCode.Success;
  16. // NOTE: The service starts a thread that polls Nintendo NTP server and syncs the time with it.
  17. // Additionnally it gets and uses some settings too:
  18. // autonomic_correction_interval_seconds, autonomic_correction_failed_retry_interval_seconds,
  19. // autonomic_correction_immediate_try_count_max, autonomic_correction_immediate_try_interval_milliseconds
  20. }
  21. [CommandHipc(0)]
  22. // StartTask()
  23. public ResultCode StartTask(ServiceCtx context)
  24. {
  25. if (!context.Device.Configuration.EnableInternetAccess)
  26. {
  27. return (ResultCode)Time.ResultCode.NetworkTimeNotAvailable;
  28. }
  29. // NOTE: Since we don't support the Nintendo NTP server, we can signal the event now to confirm the update task is done.
  30. _finishNotificationEvent.ReadableEvent.Signal();
  31. Logger.Stub?.PrintStub(LogClass.ServiceNtc);
  32. return ResultCode.Success;
  33. }
  34. [CommandHipc(1)]
  35. // GetFinishNotificationEvent() -> handle<copy>
  36. public ResultCode GetFinishNotificationEvent(ServiceCtx context)
  37. {
  38. if (context.Process.HandleTable.GenerateHandle(_finishNotificationEvent.ReadableEvent, out int finishNotificationEventHandle) != KernelResult.Success)
  39. {
  40. throw new InvalidOperationException("Out of handles!");
  41. }
  42. context.Response.HandleDesc = IpcHandleDesc.MakeCopy(finishNotificationEventHandle);
  43. return ResultCode.Success;
  44. }
  45. [CommandHipc(2)]
  46. // GetResult()
  47. public ResultCode GetResult(ServiceCtx context)
  48. {
  49. return _taskResultCode;
  50. }
  51. [CommandHipc(3)]
  52. // Cancel()
  53. public ResultCode Cancel(ServiceCtx context)
  54. {
  55. // NOTE: The update task should be canceled here.
  56. _finishNotificationEvent.ReadableEvent.Signal();
  57. _taskResultCode = (ResultCode)Time.ResultCode.NetworkTimeTaskCanceled;
  58. Logger.Stub?.PrintStub(LogClass.ServiceNtc);
  59. return ResultCode.Success;
  60. }
  61. }
  62. }