IStaticServiceForGlue.cs 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  1. using Ryujinx.Common;
  2. using Ryujinx.HLE.HOS.Services.Pcv.Bpc;
  3. using Ryujinx.HLE.HOS.Services.Settings;
  4. using Ryujinx.HLE.HOS.Services.Time.Clock;
  5. using Ryujinx.HLE.HOS.Services.Time.StaticService;
  6. using System;
  7. namespace Ryujinx.HLE.HOS.Services.Time
  8. {
  9. [Service("time:a", TimePermissions.Admin)]
  10. [Service("time:r", TimePermissions.Repair)]
  11. [Service("time:u", TimePermissions.User)]
  12. class IStaticServiceForGlue : IpcService
  13. {
  14. private IStaticServiceForPsc _inner;
  15. private TimePermissions _permissions;
  16. public IStaticServiceForGlue(ServiceCtx context, TimePermissions permissions)
  17. {
  18. _permissions = permissions;
  19. _inner = new IStaticServiceForPsc(context, permissions);
  20. }
  21. [Command(0)]
  22. // GetStandardUserSystemClock() -> object<nn::timesrv::detail::service::ISystemClock>
  23. public ResultCode GetStandardUserSystemClock(ServiceCtx context)
  24. {
  25. return _inner.GetStandardUserSystemClock(context);
  26. }
  27. [Command(1)]
  28. // GetStandardNetworkSystemClock() -> object<nn::timesrv::detail::service::ISystemClock>
  29. public ResultCode GetStandardNetworkSystemClock(ServiceCtx context)
  30. {
  31. return _inner.GetStandardNetworkSystemClock(context);
  32. }
  33. [Command(2)]
  34. // GetStandardSteadyClock() -> object<nn::timesrv::detail::service::ISteadyClock>
  35. public ResultCode GetStandardSteadyClock(ServiceCtx context)
  36. {
  37. return _inner.GetStandardSteadyClock(context);
  38. }
  39. [Command(3)]
  40. // GetTimeZoneService() -> object<nn::timesrv::detail::service::ITimeZoneService>
  41. public ResultCode GetTimeZoneService(ServiceCtx context)
  42. {
  43. MakeObject(context, new ITimeZoneServiceForGlue(TimeManager.Instance.TimeZone, (_permissions & TimePermissions.TimeZoneWritableMask) != 0));
  44. return ResultCode.Success;
  45. }
  46. [Command(4)]
  47. // GetStandardLocalSystemClock() -> object<nn::timesrv::detail::service::ISystemClock>
  48. public ResultCode GetStandardLocalSystemClock(ServiceCtx context)
  49. {
  50. return _inner.GetStandardLocalSystemClock(context);
  51. }
  52. [Command(5)] // 4.0.0+
  53. // GetEphemeralNetworkSystemClock() -> object<nn::timesrv::detail::service::ISystemClock>
  54. public ResultCode GetEphemeralNetworkSystemClock(ServiceCtx context)
  55. {
  56. return _inner.GetEphemeralNetworkSystemClock(context);
  57. }
  58. [Command(20)] // 6.0.0+
  59. // GetSharedMemoryNativeHandle() -> handle<copy>
  60. public ResultCode GetSharedMemoryNativeHandle(ServiceCtx context)
  61. {
  62. return _inner.GetSharedMemoryNativeHandle(context);
  63. }
  64. [Command(50)] // 4.0.0+
  65. // SetStandardSteadyClockInternalOffset(nn::TimeSpanType internal_offset)
  66. public ResultCode SetStandardSteadyClockInternalOffset(ServiceCtx context)
  67. {
  68. if ((_permissions & TimePermissions.BypassUninitialized) == 0)
  69. {
  70. return ResultCode.PermissionDenied;
  71. }
  72. TimeSpanType internalOffset = context.RequestData.ReadStruct<TimeSpanType>();
  73. // TODO: set:sys SetExternalSteadyClockInternalOffset(internalOffset.ToSeconds())
  74. return ResultCode.Success;
  75. }
  76. [Command(51)] // 9.0.0+
  77. // GetStandardSteadyClockRtcValue() -> u64
  78. public ResultCode GetStandardSteadyClockRtcValue(ServiceCtx context)
  79. {
  80. ResultCode result = (ResultCode)IRtcManager.GetExternalRtcValue(out ulong rtcValue);
  81. if (result == ResultCode.Success)
  82. {
  83. context.ResponseData.Write(rtcValue);
  84. }
  85. return result;
  86. }
  87. [Command(100)]
  88. // IsStandardUserSystemClockAutomaticCorrectionEnabled() -> bool
  89. public ResultCode IsStandardUserSystemClockAutomaticCorrectionEnabled(ServiceCtx context)
  90. {
  91. return _inner.IsStandardUserSystemClockAutomaticCorrectionEnabled(context);
  92. }
  93. [Command(101)]
  94. // SetStandardUserSystemClockAutomaticCorrectionEnabled(b8)
  95. public ResultCode SetStandardUserSystemClockAutomaticCorrectionEnabled(ServiceCtx context)
  96. {
  97. return _inner.SetStandardUserSystemClockAutomaticCorrectionEnabled(context);
  98. }
  99. [Command(102)] // 5.0.0+
  100. // GetStandardUserSystemClockInitialYear() -> u32
  101. public ResultCode GetStandardUserSystemClockInitialYear(ServiceCtx context)
  102. {
  103. if (!NxSettings.Settings.TryGetValue("time!standard_user_clock_initial_year", out object standardUserSystemClockInitialYear))
  104. {
  105. throw new InvalidOperationException("standard_user_clock_initial_year isn't defined in system settings!");
  106. }
  107. context.ResponseData.Write((int)standardUserSystemClockInitialYear);
  108. return ResultCode.Success;
  109. }
  110. [Command(200)] // 3.0.0+
  111. // IsStandardNetworkSystemClockAccuracySufficient() -> bool
  112. public ResultCode IsStandardNetworkSystemClockAccuracySufficient(ServiceCtx context)
  113. {
  114. return _inner.IsStandardNetworkSystemClockAccuracySufficient(context);
  115. }
  116. [Command(201)] // 6.0.0+
  117. // GetStandardUserSystemClockAutomaticCorrectionUpdatedTime() -> nn::time::SteadyClockTimePoint
  118. public ResultCode GetStandardUserSystemClockAutomaticCorrectionUpdatedTime(ServiceCtx context)
  119. {
  120. return _inner.GetStandardUserSystemClockAutomaticCorrectionUpdatedTime(context);
  121. }
  122. [Command(300)] // 4.0.0+
  123. // CalculateMonotonicSystemClockBaseTimePoint(nn::time::SystemClockContext) -> s64
  124. public ResultCode CalculateMonotonicSystemClockBaseTimePoint(ServiceCtx context)
  125. {
  126. return _inner.CalculateMonotonicSystemClockBaseTimePoint(context);
  127. }
  128. [Command(400)] // 4.0.0+
  129. // GetClockSnapshot(u8) -> buffer<nn::time::sf::ClockSnapshot, 0x1a>
  130. public ResultCode GetClockSnapshot(ServiceCtx context)
  131. {
  132. return _inner.GetClockSnapshot(context);
  133. }
  134. [Command(401)] // 4.0.0+
  135. // GetClockSnapshotFromSystemClockContext(u8, nn::time::SystemClockContext, nn::time::SystemClockContext) -> buffer<nn::time::sf::ClockSnapshot, 0x1a>
  136. public ResultCode GetClockSnapshotFromSystemClockContext(ServiceCtx context)
  137. {
  138. return _inner.GetClockSnapshotFromSystemClockContext(context);
  139. }
  140. [Command(500)] // 4.0.0+
  141. // CalculateStandardUserSystemClockDifferenceByUser(buffer<nn::time::sf::ClockSnapshot, 0x19>, buffer<nn::time::sf::ClockSnapshot, 0x19>) -> nn::TimeSpanType
  142. public ResultCode CalculateStandardUserSystemClockDifferenceByUser(ServiceCtx context)
  143. {
  144. return _inner.CalculateStandardUserSystemClockDifferenceByUser(context);
  145. }
  146. [Command(501)] // 4.0.0+
  147. // CalculateSpanBetween(buffer<nn::time::sf::ClockSnapshot, 0x19>, buffer<nn::time::sf::ClockSnapshot, 0x19>) -> nn::TimeSpanType
  148. public ResultCode CalculateSpanBetween(ServiceCtx context)
  149. {
  150. return _inner.CalculateSpanBetween(context);
  151. }
  152. }
  153. }