2022-03-14 23:07:07 -04:00
|
|
|
|
using Ryujinx.Common.Logging;
|
|
|
|
|
using Ryujinx.HLE.HOS.Ipc;
|
|
|
|
|
using Ryujinx.HLE.HOS.Kernel.Threading;
|
2023-01-04 17:15:45 -05:00
|
|
|
|
using Ryujinx.Horizon.Common;
|
2022-03-14 23:07:07 -04:00
|
|
|
|
using System;
|
|
|
|
|
|
|
|
|
|
namespace Ryujinx.HLE.HOS.Services.Nim.Ntc.StaticService
|
|
|
|
|
{
|
2023-01-04 17:15:45 -05:00
|
|
|
|
class IEnsureNetworkClockAvailabilityService : IpcService
|
2022-03-14 23:07:07 -04:00
|
|
|
|
{
|
|
|
|
|
private KEvent _finishNotificationEvent;
|
|
|
|
|
private ResultCode _taskResultCode;
|
|
|
|
|
|
|
|
|
|
public IEnsureNetworkClockAvailabilityService(ServiceCtx context)
|
|
|
|
|
{
|
|
|
|
|
_finishNotificationEvent = new KEvent(context.Device.System.KernelContext);
|
|
|
|
|
_taskResultCode = ResultCode.Success;
|
|
|
|
|
|
|
|
|
|
// NOTE: The service starts a thread that polls Nintendo NTP server and syncs the time with it.
|
|
|
|
|
// Additionnally it gets and uses some settings too:
|
|
|
|
|
// autonomic_correction_interval_seconds, autonomic_correction_failed_retry_interval_seconds,
|
|
|
|
|
// autonomic_correction_immediate_try_count_max, autonomic_correction_immediate_try_interval_milliseconds
|
|
|
|
|
}
|
|
|
|
|
|
2023-04-14 19:00:34 -04:00
|
|
|
|
[CommandCmif(0)]
|
2022-03-14 23:07:07 -04:00
|
|
|
|
// StartTask()
|
|
|
|
|
public ResultCode StartTask(ServiceCtx context)
|
|
|
|
|
{
|
|
|
|
|
if (!context.Device.Configuration.EnableInternetAccess)
|
|
|
|
|
{
|
|
|
|
|
return (ResultCode)Time.ResultCode.NetworkTimeNotAvailable;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// NOTE: Since we don't support the Nintendo NTP server, we can signal the event now to confirm the update task is done.
|
|
|
|
|
_finishNotificationEvent.ReadableEvent.Signal();
|
|
|
|
|
|
|
|
|
|
Logger.Stub?.PrintStub(LogClass.ServiceNtc);
|
|
|
|
|
|
|
|
|
|
return ResultCode.Success;
|
|
|
|
|
}
|
|
|
|
|
|
2023-04-14 19:00:34 -04:00
|
|
|
|
[CommandCmif(1)]
|
2022-03-14 23:07:07 -04:00
|
|
|
|
// GetFinishNotificationEvent() -> handle<copy>
|
|
|
|
|
public ResultCode GetFinishNotificationEvent(ServiceCtx context)
|
|
|
|
|
{
|
2023-01-04 17:15:45 -05:00
|
|
|
|
if (context.Process.HandleTable.GenerateHandle(_finishNotificationEvent.ReadableEvent, out int finishNotificationEventHandle) != Result.Success)
|
2022-03-14 23:07:07 -04:00
|
|
|
|
{
|
|
|
|
|
throw new InvalidOperationException("Out of handles!");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
context.Response.HandleDesc = IpcHandleDesc.MakeCopy(finishNotificationEventHandle);
|
|
|
|
|
|
|
|
|
|
return ResultCode.Success;
|
|
|
|
|
}
|
|
|
|
|
|
2023-04-14 19:00:34 -04:00
|
|
|
|
[CommandCmif(2)]
|
2022-03-14 23:07:07 -04:00
|
|
|
|
// GetResult()
|
|
|
|
|
public ResultCode GetResult(ServiceCtx context)
|
|
|
|
|
{
|
|
|
|
|
return _taskResultCode;
|
|
|
|
|
}
|
|
|
|
|
|
2023-04-14 19:00:34 -04:00
|
|
|
|
[CommandCmif(3)]
|
2022-03-14 23:07:07 -04:00
|
|
|
|
// Cancel()
|
|
|
|
|
public ResultCode Cancel(ServiceCtx context)
|
|
|
|
|
{
|
|
|
|
|
// NOTE: The update task should be canceled here.
|
|
|
|
|
_finishNotificationEvent.ReadableEvent.Signal();
|
|
|
|
|
|
|
|
|
|
_taskResultCode = (ResultCode)Time.ResultCode.NetworkTimeTaskCanceled;
|
|
|
|
|
|
|
|
|
|
Logger.Stub?.PrintStub(LogClass.ServiceNtc);
|
|
|
|
|
|
|
|
|
|
return ResultCode.Success;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|