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