2019-07-14 20:50:11 +00:00
|
|
|
using Ryujinx.Common;
|
|
|
|
using Ryujinx.HLE.HOS.Services.Time.Clock;
|
2018-02-10 00:14:55 +00:00
|
|
|
|
2018-08-16 23:47:36 +00:00
|
|
|
namespace Ryujinx.HLE.HOS.Services.Time
|
2018-02-10 00:14:55 +00:00
|
|
|
{
|
2018-03-19 18:58:46 +00:00
|
|
|
class ISystemClock : IpcService
|
2018-02-10 00:14:55 +00:00
|
|
|
{
|
2019-07-14 20:50:11 +00:00
|
|
|
private SystemClockCore _clockCore;
|
|
|
|
private bool _writePermission;
|
2018-02-10 00:14:55 +00:00
|
|
|
|
2019-07-14 20:50:11 +00:00
|
|
|
public ISystemClock(SystemClockCore clockCore, bool writePermission)
|
2018-02-10 00:14:55 +00:00
|
|
|
{
|
2019-07-14 20:50:11 +00:00
|
|
|
_clockCore = clockCore;
|
|
|
|
_writePermission = writePermission;
|
2018-02-10 00:14:55 +00:00
|
|
|
}
|
|
|
|
|
2019-07-12 01:13:43 +00:00
|
|
|
[Command(0)]
|
|
|
|
// GetCurrentTime() -> nn::time::PosixTime
|
2019-07-14 19:04:38 +00:00
|
|
|
public ResultCode GetCurrentTime(ServiceCtx context)
|
2018-02-10 00:14:55 +00:00
|
|
|
{
|
2019-07-14 20:50:11 +00:00
|
|
|
SteadyClockCore steadyClockCore = _clockCore.GetSteadyClockCore();
|
|
|
|
SteadyClockTimePoint currentTimePoint = steadyClockCore.GetCurrentTimePoint(context.Thread);
|
|
|
|
|
|
|
|
ResultCode result = _clockCore.GetSystemClockContext(context.Thread, out SystemClockContext clockContext);
|
2018-02-14 05:43:21 +00:00
|
|
|
|
2019-07-14 20:50:11 +00:00
|
|
|
if (result == ResultCode.Success)
|
2018-02-14 05:43:21 +00:00
|
|
|
{
|
2019-07-14 20:50:11 +00:00
|
|
|
result = ResultCode.TimeMismatch;
|
|
|
|
|
|
|
|
if (currentTimePoint.ClockSourceId == clockContext.SteadyTimePoint.ClockSourceId)
|
|
|
|
{
|
|
|
|
ulong posixTime = clockContext.Offset + currentTimePoint.TimePoint;
|
|
|
|
|
|
|
|
context.ResponseData.Write(posixTime);
|
2018-02-14 05:43:21 +00:00
|
|
|
|
2019-07-14 20:50:11 +00:00
|
|
|
result = 0;
|
|
|
|
}
|
|
|
|
}
|
2018-07-02 00:03:05 +00:00
|
|
|
|
2019-07-14 20:50:11 +00:00
|
|
|
return result;
|
2018-07-02 00:03:05 +00:00
|
|
|
}
|
|
|
|
|
2019-07-12 01:13:43 +00:00
|
|
|
[Command(1)]
|
|
|
|
// SetCurrentTime(nn::time::PosixTime)
|
2019-07-14 19:04:38 +00:00
|
|
|
public ResultCode SetCurrentTime(ServiceCtx context)
|
2018-07-02 00:03:05 +00:00
|
|
|
{
|
2019-07-14 20:50:11 +00:00
|
|
|
if (!_writePermission)
|
2018-07-02 00:03:05 +00:00
|
|
|
{
|
2019-07-14 20:50:11 +00:00
|
|
|
return ResultCode.PermissionDenied;
|
2018-07-02 00:03:05 +00:00
|
|
|
}
|
|
|
|
|
2019-07-14 20:50:11 +00:00
|
|
|
ulong posixTime = context.RequestData.ReadUInt64();
|
|
|
|
SteadyClockCore steadyClockCore = _clockCore.GetSteadyClockCore();
|
|
|
|
SteadyClockTimePoint currentTimePoint = steadyClockCore.GetCurrentTimePoint(context.Thread);
|
|
|
|
|
|
|
|
SystemClockContext clockContext = new SystemClockContext()
|
|
|
|
{
|
|
|
|
Offset = posixTime - currentTimePoint.TimePoint,
|
|
|
|
SteadyTimePoint = currentTimePoint
|
|
|
|
};
|
|
|
|
|
|
|
|
ResultCode result = _clockCore.SetSystemClockContext(clockContext);
|
|
|
|
|
|
|
|
if (result == ResultCode.Success)
|
|
|
|
{
|
|
|
|
result = _clockCore.Flush(clockContext);
|
|
|
|
}
|
2018-07-02 00:03:05 +00:00
|
|
|
|
2019-07-14 20:50:11 +00:00
|
|
|
return result;
|
2018-07-02 00:03:05 +00:00
|
|
|
}
|
|
|
|
|
2019-07-12 01:13:43 +00:00
|
|
|
[Command(2)]
|
|
|
|
// GetSystemClockContext() -> nn::time::SystemClockContext
|
2019-07-14 19:04:38 +00:00
|
|
|
public ResultCode GetSystemClockContext(ServiceCtx context)
|
2018-07-02 00:03:05 +00:00
|
|
|
{
|
2019-07-14 20:50:11 +00:00
|
|
|
ResultCode result = _clockCore.GetSystemClockContext(context.Thread, out SystemClockContext clockContext);
|
2018-07-02 00:03:05 +00:00
|
|
|
|
2019-07-14 20:50:11 +00:00
|
|
|
if (result == ResultCode.Success)
|
2018-07-02 00:03:05 +00:00
|
|
|
{
|
2019-07-14 20:50:11 +00:00
|
|
|
context.ResponseData.WriteStruct(clockContext);
|
2018-07-02 00:03:05 +00:00
|
|
|
}
|
|
|
|
|
2019-07-14 20:50:11 +00:00
|
|
|
return result;
|
2018-07-02 00:03:05 +00:00
|
|
|
}
|
|
|
|
|
2019-07-12 01:13:43 +00:00
|
|
|
[Command(3)]
|
|
|
|
// SetSystemClockContext(nn::time::SystemClockContext)
|
2019-07-14 19:04:38 +00:00
|
|
|
public ResultCode SetSystemClockContext(ServiceCtx context)
|
2018-07-02 00:03:05 +00:00
|
|
|
{
|
2019-07-14 20:50:11 +00:00
|
|
|
if (!_writePermission)
|
|
|
|
{
|
|
|
|
return ResultCode.PermissionDenied;
|
|
|
|
}
|
|
|
|
|
|
|
|
SystemClockContext clockContext = context.RequestData.ReadStruct<SystemClockContext>();
|
2018-07-02 00:03:05 +00:00
|
|
|
|
2019-07-14 20:50:11 +00:00
|
|
|
ResultCode result = _clockCore.SetSystemClockContext(clockContext);
|
|
|
|
|
|
|
|
if (result == ResultCode.Success)
|
|
|
|
{
|
|
|
|
result = _clockCore.Flush(clockContext);
|
|
|
|
}
|
2018-02-10 00:14:55 +00:00
|
|
|
|
2019-07-14 20:50:11 +00:00
|
|
|
return result;
|
2018-02-10 00:14:55 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|