rjx-mirror/Ryujinx.HLE/HOS/Services/Time/IStaticService.cs
Ac_K 4ad3936afd Refactoring result codes (#731)
* refactoring result codes

- Add a main enum who can handle some orphalin result codes and the default `ResultCode.Success` one.
- Add sub-enum by services when it's needed.
- Remove some empty line.
- Recast all service calls to ResultCode.
- Remove some unneeded static declaration.
- Delete unused `NvHelper` class.

* NvResult is back

* Fix
2019-07-14 16:04:38 -03:00

92 lines
No EOL
3.1 KiB
C#

using Ryujinx.HLE.HOS.Ipc;
using Ryujinx.HLE.HOS.Kernel.Common;
using System;
namespace Ryujinx.HLE.HOS.Services.Time
{
[Service("time:a")]
[Service("time:s")]
[Service("time:u")]
class IStaticService : IpcService
{
private int _timeSharedMemoryNativeHandle = 0;
private static readonly DateTime StartupDate = DateTime.UtcNow;
public IStaticService(ServiceCtx context) { }
[Command(0)]
// GetStandardUserSystemClock() -> object<nn::timesrv::detail::service::ISystemClock>
public ResultCode GetStandardUserSystemClock(ServiceCtx context)
{
MakeObject(context, new ISystemClock(SystemClockType.User));
return ResultCode.Success;
}
[Command(1)]
// GetStandardNetworkSystemClock() -> object<nn::timesrv::detail::service::ISystemClock>
public ResultCode GetStandardNetworkSystemClock(ServiceCtx context)
{
MakeObject(context, new ISystemClock(SystemClockType.Network));
return ResultCode.Success;
}
[Command(2)]
// GetStandardSteadyClock() -> object<nn::timesrv::detail::service::ISteadyClock>
public ResultCode GetStandardSteadyClock(ServiceCtx context)
{
MakeObject(context, new ISteadyClock());
return ResultCode.Success;
}
[Command(3)]
// GetTimeZoneService() -> object<nn::timesrv::detail::service::ITimeZoneService>
public ResultCode GetTimeZoneService(ServiceCtx context)
{
MakeObject(context, new ITimeZoneService());
return ResultCode.Success;
}
[Command(4)]
// GetStandardLocalSystemClock() -> object<nn::timesrv::detail::service::ISystemClock>
public ResultCode GetStandardLocalSystemClock(ServiceCtx context)
{
MakeObject(context, new ISystemClock(SystemClockType.Local));
return ResultCode.Success;
}
[Command(20)] // 6.0.0+
// GetSharedMemoryNativeHandle() -> handle<copy>
public ResultCode GetSharedMemoryNativeHandle(ServiceCtx context)
{
if (_timeSharedMemoryNativeHandle == 0)
{
if (context.Process.HandleTable.GenerateHandle(context.Device.System.TimeSharedMem, out _timeSharedMemoryNativeHandle) != KernelResult.Success)
{
throw new InvalidOperationException("Out of handles!");
}
}
context.Response.HandleDesc = IpcHandleDesc.MakeCopy(_timeSharedMemoryNativeHandle);
return ResultCode.Success;
}
[Command(300)] // 4.0.0+
// CalculateMonotonicSystemClockBaseTimePoint(nn::time::SystemClockContext) -> u64
public ResultCode CalculateMonotonicSystemClockBaseTimePoint(ServiceCtx context)
{
long timeOffset = (long)(DateTime.UtcNow - StartupDate).TotalSeconds;
long systemClockContextEpoch = context.RequestData.ReadInt64();
context.ResponseData.Write(timeOffset + systemClockContextEpoch);
return ResultCode.Success;
}
}
}