Ryujinx/Ryujinx.HLE/HOS/Services/Time/IStaticService.cs

74 lines
2.2 KiB
C#
Raw Normal View History

using Ryujinx.HLE.HOS.Ipc;
using System;
using System.Collections.Generic;
namespace Ryujinx.HLE.HOS.Services.Time
{
class IStaticService : IpcService
{
2018-12-01 21:01:59 +01:00
private Dictionary<int, ServiceProcessRequest> _commands;
2018-12-01 21:01:59 +01:00
public override IReadOnlyDictionary<int, ServiceProcessRequest> Commands => _commands;
private static readonly DateTime StartupDate = DateTime.UtcNow;
public IStaticService()
{
2018-12-01 21:01:59 +01:00
_commands = new Dictionary<int, ServiceProcessRequest>()
{
{ 0, GetStandardUserSystemClock },
{ 1, GetStandardNetworkSystemClock },
{ 2, GetStandardSteadyClock },
{ 3, GetTimeZoneService },
{ 4, GetStandardLocalSystemClock },
{ 300, CalculateMonotonicSystemClockBaseTimePoint }
};
}
2018-12-01 21:01:59 +01:00
public long GetStandardUserSystemClock(ServiceCtx context)
{
2018-12-01 21:01:59 +01:00
MakeObject(context, new ISystemClock(SystemClockType.User));
return 0;
}
2018-12-01 21:01:59 +01:00
public long GetStandardNetworkSystemClock(ServiceCtx context)
{
2018-12-01 21:01:59 +01:00
MakeObject(context, new ISystemClock(SystemClockType.Network));
return 0;
}
2018-12-01 21:01:59 +01:00
public long GetStandardSteadyClock(ServiceCtx context)
{
2018-12-01 21:01:59 +01:00
MakeObject(context, new ISteadyClock());
return 0;
}
2018-12-01 21:01:59 +01:00
public long GetTimeZoneService(ServiceCtx context)
{
2018-12-01 21:01:59 +01:00
MakeObject(context, new ITimeZoneService());
return 0;
}
2018-12-01 21:01:59 +01:00
public long GetStandardLocalSystemClock(ServiceCtx context)
{
2018-12-01 21:01:59 +01:00
MakeObject(context, new ISystemClock(SystemClockType.Local));
return 0;
}
2018-12-01 21:01:59 +01:00
public long CalculateMonotonicSystemClockBaseTimePoint(ServiceCtx context)
{
2018-12-01 21:01:59 +01:00
long timeOffset = (long)(DateTime.UtcNow - StartupDate).TotalSeconds;
long systemClockContextEpoch = context.RequestData.ReadInt64();
2018-12-01 21:01:59 +01:00
context.ResponseData.Write(timeOffset + systemClockContextEpoch);
return 0;
}
}
}