StandardUserSystemClockCore.cs 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  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)
  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 SteadyClockCore GetSteadyClockCore()
  32. {
  33. return _localSystemClockCore.GetSteadyClockCore();
  34. }
  35. public override ResultCode GetSystemClockContext(KThread thread, out SystemClockContext context)
  36. {
  37. ResultCode result = ApplyAutomaticCorrection(thread, false);
  38. context = new SystemClockContext();
  39. if (result == ResultCode.Success)
  40. {
  41. return _localSystemClockCore.GetSystemClockContext(thread, out context);
  42. }
  43. return result;
  44. }
  45. public override ResultCode SetSystemClockContext(SystemClockContext context)
  46. {
  47. return ResultCode.NotImplemented;
  48. }
  49. private ResultCode ApplyAutomaticCorrection(KThread thread, bool autoCorrectionEnabled)
  50. {
  51. ResultCode result = ResultCode.Success;
  52. if (_autoCorrectionEnabled != autoCorrectionEnabled && _networkSystemClockCore.IsClockSetup(thread))
  53. {
  54. result = _networkSystemClockCore.GetSystemClockContext(thread, out SystemClockContext context);
  55. if (result == ResultCode.Success)
  56. {
  57. _localSystemClockCore.SetSystemClockContext(context);
  58. }
  59. }
  60. return result;
  61. }
  62. public ResultCode SetAutomaticCorrectionEnabled(KThread thread, bool autoCorrectionEnabled)
  63. {
  64. ResultCode result = ApplyAutomaticCorrection(thread, autoCorrectionEnabled);
  65. if (result == ResultCode.Success)
  66. {
  67. _autoCorrectionEnabled = autoCorrectionEnabled;
  68. }
  69. return result;
  70. }
  71. public bool IsAutomaticCorrectionEnabled()
  72. {
  73. return _autoCorrectionEnabled;
  74. }
  75. }
  76. }