IStaticService.cs 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. using Ryujinx.HLE.HOS.Ipc;
  2. using System;
  3. using System.Collections.Generic;
  4. namespace Ryujinx.HLE.HOS.Services.Time
  5. {
  6. class IStaticService : IpcService
  7. {
  8. private Dictionary<int, ServiceProcessRequest> _commands;
  9. public override IReadOnlyDictionary<int, ServiceProcessRequest> Commands => _commands;
  10. private static readonly DateTime StartupDate = DateTime.UtcNow;
  11. public IStaticService()
  12. {
  13. _commands = new Dictionary<int, ServiceProcessRequest>
  14. {
  15. { 0, GetStandardUserSystemClock },
  16. { 1, GetStandardNetworkSystemClock },
  17. { 2, GetStandardSteadyClock },
  18. { 3, GetTimeZoneService },
  19. { 4, GetStandardLocalSystemClock },
  20. { 300, CalculateMonotonicSystemClockBaseTimePoint }
  21. };
  22. }
  23. public long GetStandardUserSystemClock(ServiceCtx context)
  24. {
  25. MakeObject(context, new ISystemClock(SystemClockType.User));
  26. return 0;
  27. }
  28. public long GetStandardNetworkSystemClock(ServiceCtx context)
  29. {
  30. MakeObject(context, new ISystemClock(SystemClockType.Network));
  31. return 0;
  32. }
  33. public long GetStandardSteadyClock(ServiceCtx context)
  34. {
  35. MakeObject(context, new ISteadyClock());
  36. return 0;
  37. }
  38. public long GetTimeZoneService(ServiceCtx context)
  39. {
  40. MakeObject(context, new ITimeZoneService());
  41. return 0;
  42. }
  43. public long GetStandardLocalSystemClock(ServiceCtx context)
  44. {
  45. MakeObject(context, new ISystemClock(SystemClockType.Local));
  46. return 0;
  47. }
  48. public long CalculateMonotonicSystemClockBaseTimePoint(ServiceCtx context)
  49. {
  50. long timeOffset = (long)(DateTime.UtcNow - StartupDate).TotalSeconds;
  51. long systemClockContextEpoch = context.RequestData.ReadInt64();
  52. context.ResponseData.Write(timeOffset + systemClockContextEpoch);
  53. return 0;
  54. }
  55. }
  56. }