summaryrefslogtreecommitdiffstats
path: root/src/core/hle/service/psc/time/clocks/standard_user_system_clock_core.cpp
blob: 9e9be05d6318f35c2d952f698e0bba919a0a45e6 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
// SPDX-FileCopyrightText: Copyright 2023 yuzu Emulator Project
// SPDX-License-Identifier: GPL-2.0-or-later

#include "core/core.h"
#include "core/hle/service/psc/time/clocks/standard_user_system_clock_core.h"

namespace Service::PSC::Time {

StandardUserSystemClockCore::StandardUserSystemClockCore(
    Core::System& system, StandardLocalSystemClockCore& local_clock,
    StandardNetworkSystemClockCore& network_clock)
    : SystemClockCore{local_clock.GetSteadyClock()}, m_system{system},
      m_ctx{m_system, "Psc:StandardUserSystemClockCore"}, m_local_system_clock{local_clock},
      m_network_system_clock{network_clock}, m_event{m_ctx.CreateEvent(
                                                 "Psc:StandardUserSystemClockCore:Event")} {}

StandardUserSystemClockCore::~StandardUserSystemClockCore() {
    m_ctx.CloseEvent(m_event);
}

Result StandardUserSystemClockCore::SetAutomaticCorrection(bool automatic_correction) {
    R_SUCCEED_IF(m_automatic_correction == automatic_correction);
    R_SUCCEED_IF(!m_network_system_clock.CheckClockSourceMatches());

    SystemClockContext context{};
    R_TRY(m_network_system_clock.GetContext(context));
    R_TRY(m_local_system_clock.SetContextAndWrite(context));

    m_automatic_correction = automatic_correction;
    R_SUCCEED();
}

Result StandardUserSystemClockCore::GetContext(SystemClockContext& out_context) const {
    if (!m_automatic_correction) {
        R_RETURN(m_local_system_clock.GetContext(out_context));
    }

    if (!m_network_system_clock.CheckClockSourceMatches()) {
        R_RETURN(m_local_system_clock.GetContext(out_context));
    }

    SystemClockContext context{};
    R_TRY(m_network_system_clock.GetContext(context));
    R_TRY(m_local_system_clock.SetContextAndWrite(context));

    R_RETURN(m_local_system_clock.GetContext(out_context));
}

Result StandardUserSystemClockCore::SetContext(SystemClockContext& context) {
    R_RETURN(ResultNotImplemented);
}

Result StandardUserSystemClockCore::GetTimePoint(SteadyClockTimePoint& out_time_point) {
    out_time_point = m_time_point;
    R_SUCCEED();
}

void StandardUserSystemClockCore::SetTimePointAndSignal(SteadyClockTimePoint& time_point) {
    m_time_point = time_point;
    m_event->Signal();
}

} // namespace Service::PSC::Time