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