Implement the rest of TimeServiceImpl

This commit is contained in:
Alex Barney 2021-01-30 02:14:12 -07:00
parent d0e608775e
commit 3463c977dd

View file

@ -1,6 +1,7 @@
using System;
using System.Runtime.CompilerServices;
using LibHac.Fs;
using LibHac.FsSrv.Impl;
using LibHac.Os;
namespace LibHac.FsSrv
{
@ -23,7 +24,8 @@ namespace LibHac.FsSrv
if (!programInfo.AccessControl.CanCall(OperationType.SetCurrentPosixTime))
return ResultFs.PermissionDenied.Log();
return _serviceImpl.SetCurrentPosixTimeWithTimeDifference(currentTime, timeDifference);
_serviceImpl.SetCurrentPosixTimeWithTimeDifference(currentTime, timeDifference);
return Result.Success;
}
private Result GetProgramInfo(out ProgramInfo programInfo)
@ -35,16 +37,16 @@ namespace LibHac.FsSrv
public class TimeServiceImpl
{
private Configuration _config;
private long _baseTime;
private long _basePosixTime;
private int _timeDifference;
private object _lockObject;
private SdkMutexType _mutex;
public TimeServiceImpl(in Configuration configuration)
{
_config = configuration;
_baseTime = 0;
_basePosixTime = 0;
_timeDifference = 0;
_lockObject = new object();
_mutex.Initialize();
}
// The entire Configuration struct is a LibHac addition to avoid using global state
@ -54,19 +56,49 @@ namespace LibHac.FsSrv
public ProgramRegistryImpl ProgramRegistry;
}
public Result GetCurrentPosixTime(out long time)
private long GetSystemSeconds()
{
throw new NotImplementedException();
OsState os = _config.HorizonClient.Os;
Tick tick = os.GetSystemTick();
TimeSpan timeSpan = os.ConvertToTimeSpan(tick);
return timeSpan.GetSeconds();
}
public Result GetCurrentPosixTime(out long currentTime)
{
return GetCurrentPosixTimeWithTimeDifference(out currentTime, out int _);
}
public Result GetCurrentPosixTimeWithTimeDifference(out long currentTime, out int timeDifference)
{
throw new NotImplementedException();
Unsafe.SkipInit(out currentTime);
Unsafe.SkipInit(out timeDifference);
using ScopedLock<SdkMutexType> lk = ScopedLock.Lock(ref _mutex);
if (_basePosixTime == 0)
return ResultFs.NotInitialized.Log();
if (!Unsafe.IsNullRef(ref currentTime))
{
currentTime = _basePosixTime + GetSystemSeconds();
}
if (!Unsafe.IsNullRef(ref timeDifference))
{
timeDifference = _timeDifference;
}
return Result.Success;
}
public Result SetCurrentPosixTimeWithTimeDifference(long currentTime, int timeDifference)
public void SetCurrentPosixTimeWithTimeDifference(long currentTime, int timeDifference)
{
throw new NotImplementedException();
using ScopedLock<SdkMutexType> lk = ScopedLock.Lock(ref _mutex);
_basePosixTime = currentTime - GetSystemSeconds();
_timeDifference = timeDifference;
}
internal Result GetProgramInfo(out ProgramInfo programInfo, ulong processId)