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