StandardUserSystemClockCore.cs 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. using Ryujinx.HLE.HOS.Kernel.Threading;
  2. namespace Ryujinx.HLE.HOS.Services.Time.Clock
  3. {
  4. class StandardUserSystemClockCore : SystemClockCore
  5. {
  6. private StandardLocalSystemClockCore _localSystemClockCore;
  7. private StandardNetworkSystemClockCore _networkSystemClockCore;
  8. private bool _autoCorrectionEnabled;
  9. private static StandardUserSystemClockCore _instance;
  10. public static StandardUserSystemClockCore Instance
  11. {
  12. get
  13. {
  14. if (_instance == null)
  15. {
  16. _instance = new StandardUserSystemClockCore(StandardLocalSystemClockCore.Instance, StandardNetworkSystemClockCore.Instance);
  17. }
  18. return _instance;
  19. }
  20. }
  21. public StandardUserSystemClockCore(StandardLocalSystemClockCore localSystemClockCore, StandardNetworkSystemClockCore networkSystemClockCore) : base(localSystemClockCore.GetSteadyClockCore())
  22. {
  23. _localSystemClockCore = localSystemClockCore;
  24. _networkSystemClockCore = networkSystemClockCore;
  25. _autoCorrectionEnabled = false;
  26. }
  27. public override ResultCode Flush(SystemClockContext context)
  28. {
  29. return ResultCode.NotImplemented;
  30. }
  31. public override ResultCode GetSystemClockContext(KThread thread, out SystemClockContext context)
  32. {
  33. ResultCode result = ApplyAutomaticCorrection(thread, false);
  34. context = new SystemClockContext();
  35. if (result == ResultCode.Success)
  36. {
  37. return _localSystemClockCore.GetSystemClockContext(thread, out context);
  38. }
  39. return result;
  40. }
  41. public override ResultCode SetSystemClockContext(SystemClockContext context)
  42. {
  43. return ResultCode.NotImplemented;
  44. }
  45. private ResultCode ApplyAutomaticCorrection(KThread thread, bool autoCorrectionEnabled)
  46. {
  47. ResultCode result = ResultCode.Success;
  48. if (_autoCorrectionEnabled != autoCorrectionEnabled && _networkSystemClockCore.IsClockSetup(thread))
  49. {
  50. result = _networkSystemClockCore.GetSystemClockContext(thread, out SystemClockContext context);
  51. if (result == ResultCode.Success)
  52. {
  53. _localSystemClockCore.SetSystemClockContext(context);
  54. }
  55. }
  56. return result;
  57. }
  58. public ResultCode SetAutomaticCorrectionEnabled(KThread thread, bool autoCorrectionEnabled)
  59. {
  60. ResultCode result = ApplyAutomaticCorrection(thread, autoCorrectionEnabled);
  61. if (result == ResultCode.Success)
  62. {
  63. _autoCorrectionEnabled = autoCorrectionEnabled;
  64. }
  65. return result;
  66. }
  67. public bool IsAutomaticCorrectionEnabled()
  68. {
  69. return _autoCorrectionEnabled;
  70. }
  71. }
  72. }