mirror of
https://github.com/Thealexbarney/LibHac.git
synced 2024-11-14 10:49:41 +01:00
Implement the rest of TimeServiceImpl
This commit is contained in:
parent
d0e608775e
commit
3463c977dd
1 changed files with 43 additions and 11 deletions
|
@ -1,6 +1,7 @@
|
||||||
using System;
|
using System.Runtime.CompilerServices;
|
||||||
using LibHac.Fs;
|
using LibHac.Fs;
|
||||||
using LibHac.FsSrv.Impl;
|
using LibHac.FsSrv.Impl;
|
||||||
|
using LibHac.Os;
|
||||||
|
|
||||||
namespace LibHac.FsSrv
|
namespace LibHac.FsSrv
|
||||||
{
|
{
|
||||||
|
@ -23,7 +24,8 @@ namespace LibHac.FsSrv
|
||||||
if (!programInfo.AccessControl.CanCall(OperationType.SetCurrentPosixTime))
|
if (!programInfo.AccessControl.CanCall(OperationType.SetCurrentPosixTime))
|
||||||
return ResultFs.PermissionDenied.Log();
|
return ResultFs.PermissionDenied.Log();
|
||||||
|
|
||||||
return _serviceImpl.SetCurrentPosixTimeWithTimeDifference(currentTime, timeDifference);
|
_serviceImpl.SetCurrentPosixTimeWithTimeDifference(currentTime, timeDifference);
|
||||||
|
return Result.Success;
|
||||||
}
|
}
|
||||||
|
|
||||||
private Result GetProgramInfo(out ProgramInfo programInfo)
|
private Result GetProgramInfo(out ProgramInfo programInfo)
|
||||||
|
@ -35,16 +37,16 @@ namespace LibHac.FsSrv
|
||||||
public class TimeServiceImpl
|
public class TimeServiceImpl
|
||||||
{
|
{
|
||||||
private Configuration _config;
|
private Configuration _config;
|
||||||
private long _baseTime;
|
private long _basePosixTime;
|
||||||
private int _timeDifference;
|
private int _timeDifference;
|
||||||
private object _lockObject;
|
private SdkMutexType _mutex;
|
||||||
|
|
||||||
public TimeServiceImpl(in Configuration configuration)
|
public TimeServiceImpl(in Configuration configuration)
|
||||||
{
|
{
|
||||||
_config = configuration;
|
_config = configuration;
|
||||||
_baseTime = 0;
|
_basePosixTime = 0;
|
||||||
_timeDifference = 0;
|
_timeDifference = 0;
|
||||||
_lockObject = new object();
|
_mutex.Initialize();
|
||||||
}
|
}
|
||||||
|
|
||||||
// The entire Configuration struct is a LibHac addition to avoid using global state
|
// The entire Configuration struct is a LibHac addition to avoid using global state
|
||||||
|
@ -54,19 +56,49 @@ namespace LibHac.FsSrv
|
||||||
public ProgramRegistryImpl ProgramRegistry;
|
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)
|
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();
|
||||||
}
|
}
|
||||||
|
|
||||||
public Result SetCurrentPosixTimeWithTimeDifference(long currentTime, int timeDifference)
|
if (!Unsafe.IsNullRef(ref timeDifference))
|
||||||
{
|
{
|
||||||
throw new NotImplementedException();
|
timeDifference = _timeDifference;
|
||||||
|
}
|
||||||
|
|
||||||
|
return Result.Success;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void SetCurrentPosixTimeWithTimeDifference(long currentTime, int timeDifference)
|
||||||
|
{
|
||||||
|
using ScopedLock<SdkMutexType> lk = ScopedLock.Lock(ref _mutex);
|
||||||
|
|
||||||
|
_basePosixTime = currentTime - GetSystemSeconds();
|
||||||
|
_timeDifference = timeDifference;
|
||||||
}
|
}
|
||||||
|
|
||||||
internal Result GetProgramInfo(out ProgramInfo programInfo, ulong processId)
|
internal Result GetProgramInfo(out ProgramInfo programInfo, ulong processId)
|
||||||
|
|
Loading…
Reference in a new issue