IStaticServiceForGlue.cs 7.4 KB

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