2019-12-22 23:49:51 +01:00
|
|
|
// Copyright 2019 yuzu emulator team
|
|
|
|
// Licensed under GPLv2 or any later version
|
|
|
|
// Refer to the license.txt file included.
|
|
|
|
|
|
|
|
#include "common/assert.h"
|
|
|
|
#include "core/core.h"
|
|
|
|
#include "core/hle/service/time/standard_local_system_clock_core.h"
|
|
|
|
#include "core/hle/service/time/standard_network_system_clock_core.h"
|
|
|
|
#include "core/hle/service/time/standard_user_system_clock_core.h"
|
|
|
|
|
|
|
|
namespace Service::Time::Clock {
|
|
|
|
|
|
|
|
StandardUserSystemClockCore::StandardUserSystemClockCore(
|
2021-05-16 07:46:30 +02:00
|
|
|
StandardLocalSystemClockCore& local_system_clock_core_,
|
|
|
|
StandardNetworkSystemClockCore& network_system_clock_core_, Core::System& system_)
|
|
|
|
: SystemClockCore(local_system_clock_core_.GetSteadyClockCore()),
|
|
|
|
local_system_clock_core{local_system_clock_core_},
|
|
|
|
network_system_clock_core{network_system_clock_core_},
|
2021-04-04 09:56:09 +02:00
|
|
|
auto_correction_time{SteadyClockTimePoint::GetRandom()}, auto_correction_event{
|
2021-05-16 07:46:30 +02:00
|
|
|
system_.Kernel()} {
|
2021-04-10 01:56:11 +02:00
|
|
|
Kernel::KAutoObject::Create(std::addressof(auto_correction_event));
|
2021-04-04 09:56:09 +02:00
|
|
|
auto_correction_event.Initialize("StandardUserSystemClockCore:AutoCorrectionEvent");
|
2021-01-31 10:38:57 +01:00
|
|
|
}
|
2019-12-22 23:49:51 +01:00
|
|
|
|
|
|
|
ResultCode StandardUserSystemClockCore::SetAutomaticCorrectionEnabled(Core::System& system,
|
|
|
|
bool value) {
|
2021-05-21 07:05:04 +02:00
|
|
|
if (const ResultCode result{ApplyAutomaticCorrection(system, value)}; result != ResultSuccess) {
|
2019-12-22 23:49:51 +01:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
auto_correction_enabled = value;
|
|
|
|
|
2021-05-21 07:05:04 +02:00
|
|
|
return ResultSuccess;
|
2019-12-22 23:49:51 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
ResultCode StandardUserSystemClockCore::GetClockContext(Core::System& system,
|
2021-05-16 07:46:30 +02:00
|
|
|
SystemClockContext& ctx) const {
|
2021-05-21 07:05:04 +02:00
|
|
|
if (const ResultCode result{ApplyAutomaticCorrection(system, false)}; result != ResultSuccess) {
|
2019-12-22 23:49:51 +01:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2021-05-16 07:46:30 +02:00
|
|
|
return local_system_clock_core.GetClockContext(system, ctx);
|
2019-12-22 23:49:51 +01:00
|
|
|
}
|
|
|
|
|
2021-04-26 15:11:33 +02:00
|
|
|
ResultCode StandardUserSystemClockCore::Flush(const SystemClockContext&) {
|
2019-12-22 23:49:51 +01:00
|
|
|
UNREACHABLE();
|
|
|
|
return ERROR_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
|
2021-04-26 15:11:33 +02:00
|
|
|
ResultCode StandardUserSystemClockCore::SetClockContext(const SystemClockContext&) {
|
2019-12-22 23:49:51 +01:00
|
|
|
UNREACHABLE();
|
|
|
|
return ERROR_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
ResultCode StandardUserSystemClockCore::ApplyAutomaticCorrection(Core::System& system,
|
|
|
|
bool value) const {
|
|
|
|
if (auto_correction_enabled == value) {
|
2021-05-21 07:05:04 +02:00
|
|
|
return ResultSuccess;
|
2019-12-22 23:49:51 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!network_system_clock_core.IsClockSetup(system)) {
|
|
|
|
return ERROR_UNINITIALIZED_CLOCK;
|
|
|
|
}
|
|
|
|
|
2021-05-16 07:46:30 +02:00
|
|
|
SystemClockContext ctx{};
|
|
|
|
if (const ResultCode result{network_system_clock_core.GetClockContext(system, ctx)};
|
2021-05-21 07:05:04 +02:00
|
|
|
result != ResultSuccess) {
|
2019-12-22 23:49:51 +01:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2021-05-16 07:46:30 +02:00
|
|
|
local_system_clock_core.SetClockContext(ctx);
|
2019-12-22 23:49:51 +01:00
|
|
|
|
2021-05-21 07:05:04 +02:00
|
|
|
return ResultSuccess;
|
2019-12-22 23:49:51 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace Service::Time::Clock
|