2019-07-14 13:50:11 -07:00
|
|
|
|
using Ryujinx.HLE.HOS.Kernel.Threading;
|
2019-10-07 20:48:49 -07:00
|
|
|
|
using System;
|
2019-07-14 13:50:11 -07:00
|
|
|
|
|
|
|
|
|
namespace Ryujinx.HLE.HOS.Services.Time.Clock
|
|
|
|
|
{
|
|
|
|
|
class StandardUserSystemClockCore : SystemClockCore
|
|
|
|
|
{
|
|
|
|
|
private StandardLocalSystemClockCore _localSystemClockCore;
|
|
|
|
|
private StandardNetworkSystemClockCore _networkSystemClockCore;
|
|
|
|
|
private bool _autoCorrectionEnabled;
|
2019-10-07 20:48:49 -07:00
|
|
|
|
private SteadyClockTimePoint _autoCorrectionTime;
|
|
|
|
|
private KEvent _autoCorrectionEvent;
|
2019-07-14 13:50:11 -07:00
|
|
|
|
|
2019-07-25 07:44:51 -07:00
|
|
|
|
public StandardUserSystemClockCore(StandardLocalSystemClockCore localSystemClockCore, StandardNetworkSystemClockCore networkSystemClockCore) : base(localSystemClockCore.GetSteadyClockCore())
|
2019-07-14 13:50:11 -07:00
|
|
|
|
{
|
|
|
|
|
_localSystemClockCore = localSystemClockCore;
|
|
|
|
|
_networkSystemClockCore = networkSystemClockCore;
|
|
|
|
|
_autoCorrectionEnabled = false;
|
2019-10-07 20:48:49 -07:00
|
|
|
|
_autoCorrectionTime = SteadyClockTimePoint.GetRandom();
|
|
|
|
|
_autoCorrectionEvent = null;
|
2019-07-14 13:50:11 -07:00
|
|
|
|
}
|
|
|
|
|
|
2019-10-07 20:48:49 -07:00
|
|
|
|
protected override ResultCode Flush(SystemClockContext context)
|
2019-07-14 13:50:11 -07:00
|
|
|
|
{
|
2019-10-07 20:48:49 -07:00
|
|
|
|
// As UserSystemClock isn't a real system clock, this shouldn't happens.
|
|
|
|
|
throw new NotImplementedException();
|
2019-07-14 13:50:11 -07:00
|
|
|
|
}
|
|
|
|
|
|
2019-10-07 20:48:49 -07:00
|
|
|
|
public override ResultCode GetClockContext(KThread thread, out SystemClockContext context)
|
2019-07-14 13:50:11 -07:00
|
|
|
|
{
|
|
|
|
|
ResultCode result = ApplyAutomaticCorrection(thread, false);
|
|
|
|
|
|
|
|
|
|
context = new SystemClockContext();
|
|
|
|
|
|
|
|
|
|
if (result == ResultCode.Success)
|
|
|
|
|
{
|
2019-10-07 20:48:49 -07:00
|
|
|
|
return _localSystemClockCore.GetClockContext(thread, out context);
|
2019-07-14 13:50:11 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
2019-10-07 20:48:49 -07:00
|
|
|
|
public override ResultCode SetClockContext(SystemClockContext context)
|
2019-07-14 13:50:11 -07:00
|
|
|
|
{
|
|
|
|
|
return ResultCode.NotImplemented;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private ResultCode ApplyAutomaticCorrection(KThread thread, bool autoCorrectionEnabled)
|
|
|
|
|
{
|
|
|
|
|
ResultCode result = ResultCode.Success;
|
|
|
|
|
|
|
|
|
|
if (_autoCorrectionEnabled != autoCorrectionEnabled && _networkSystemClockCore.IsClockSetup(thread))
|
|
|
|
|
{
|
2019-10-07 20:48:49 -07:00
|
|
|
|
result = _networkSystemClockCore.GetClockContext(thread, out SystemClockContext context);
|
2019-07-14 13:50:11 -07:00
|
|
|
|
|
|
|
|
|
if (result == ResultCode.Success)
|
|
|
|
|
{
|
2019-10-07 20:48:49 -07:00
|
|
|
|
_localSystemClockCore.SetClockContext(context);
|
2019-07-14 13:50:11 -07:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
2019-10-07 20:48:49 -07:00
|
|
|
|
internal void CreateAutomaticCorrectionEvent(Horizon system)
|
|
|
|
|
{
|
|
|
|
|
_autoCorrectionEvent = new KEvent(system);
|
|
|
|
|
}
|
|
|
|
|
|
2019-07-14 13:50:11 -07:00
|
|
|
|
public ResultCode SetAutomaticCorrectionEnabled(KThread thread, bool autoCorrectionEnabled)
|
|
|
|
|
{
|
|
|
|
|
ResultCode result = ApplyAutomaticCorrection(thread, autoCorrectionEnabled);
|
|
|
|
|
|
|
|
|
|
if (result == ResultCode.Success)
|
|
|
|
|
{
|
|
|
|
|
_autoCorrectionEnabled = autoCorrectionEnabled;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public bool IsAutomaticCorrectionEnabled()
|
|
|
|
|
{
|
|
|
|
|
return _autoCorrectionEnabled;
|
|
|
|
|
}
|
2019-10-07 20:48:49 -07:00
|
|
|
|
|
|
|
|
|
public KReadableEvent GetAutomaticCorrectionReadableEvent()
|
|
|
|
|
{
|
|
|
|
|
return _autoCorrectionEvent.ReadableEvent;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void SetAutomaticCorrectionUpdatedTime(SteadyClockTimePoint steadyClockTimePoint)
|
|
|
|
|
{
|
|
|
|
|
_autoCorrectionTime = steadyClockTimePoint;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public SteadyClockTimePoint GetAutomaticCorrectionUpdatedTime()
|
|
|
|
|
{
|
|
|
|
|
return _autoCorrectionTime;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void SignalAutomaticCorrectionEvent()
|
|
|
|
|
{
|
|
|
|
|
_autoCorrectionEvent.WritableEvent.Signal();
|
|
|
|
|
}
|
2019-07-14 13:50:11 -07:00
|
|
|
|
}
|
|
|
|
|
}
|