summaryrefslogtreecommitdiffstats
path: root/src/core/hle/service/psc/time/steady_clock.cpp
blob: 1ed5c76799e4d6819001021f01ddff20db3ce209 (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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
// 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/steady_clock.h"

namespace Service::PSC::Time {

SteadyClock::SteadyClock(Core::System& system_, std::shared_ptr<TimeManager> manager,
                         bool can_write_steady_clock, bool can_write_uninitialized_clock)
    : ServiceFramework{system_, "ISteadyClock"}, m_system{system},
      m_clock_core{manager->m_standard_steady_clock},
      m_can_write_steady_clock{can_write_steady_clock}, m_can_write_uninitialized_clock{
                                                            can_write_uninitialized_clock} {
    // clang-format off
         static const FunctionInfo functions[] = {
        {0, &SteadyClock::Handle_GetCurrentTimePoint, "GetCurrentTimePoint"},
        {2, &SteadyClock::Handle_GetTestOffset, "GetTestOffset"},
        {3, &SteadyClock::Handle_SetTestOffset, "SetTestOffset"},
        {100, &SteadyClock::Handle_GetRtcValue, "GetRtcValue"},
        {101, &SteadyClock::Handle_IsRtcResetDetected, "IsRtcResetDetected"},
        {102, &SteadyClock::Handle_GetSetupResultValue, "GetSetupResultValue"},
        {200, &SteadyClock::Handle_GetInternalOffset, "GetInternalOffset"},
    };
    // clang-format on
    RegisterHandlers(functions);
}

void SteadyClock::Handle_GetCurrentTimePoint(HLERequestContext& ctx) {
    LOG_DEBUG(Service_Time, "called.");

    SteadyClockTimePoint time_point{};
    auto res = GetCurrentTimePoint(time_point);

    IPC::ResponseBuilder rb{ctx, 2 + sizeof(SteadyClockTimePoint) / sizeof(u32)};
    rb.Push(res);
    rb.PushRaw<SteadyClockTimePoint>(time_point);
}

void SteadyClock::Handle_GetTestOffset(HLERequestContext& ctx) {
    LOG_DEBUG(Service_Time, "called.");

    s64 test_offset{};
    auto res = GetTestOffset(test_offset);

    IPC::ResponseBuilder rb{ctx, 4};
    rb.Push(res);
    rb.Push(test_offset);
}

void SteadyClock::Handle_SetTestOffset(HLERequestContext& ctx) {
    LOG_DEBUG(Service_Time, "called.");

    IPC::RequestParser rp{ctx};
    auto test_offset{rp.Pop<s64>()};

    auto res = SetTestOffset(test_offset);

    IPC::ResponseBuilder rb{ctx, 2};
    rb.Push(res);
}

void SteadyClock::Handle_GetRtcValue(HLERequestContext& ctx) {
    LOG_DEBUG(Service_Time, "called.");

    s64 rtc_value{};
    auto res = GetRtcValue(rtc_value);

    IPC::ResponseBuilder rb{ctx, 4};
    rb.Push(res);
    rb.Push(rtc_value);
}

void SteadyClock::Handle_IsRtcResetDetected(HLERequestContext& ctx) {
    LOG_DEBUG(Service_Time, "called.");

    bool reset_detected{false};
    auto res = IsRtcResetDetected(reset_detected);

    IPC::ResponseBuilder rb{ctx, 3};
    rb.Push(res);
    rb.Push(reset_detected);
}

void SteadyClock::Handle_GetSetupResultValue(HLERequestContext& ctx) {
    LOG_DEBUG(Service_Time, "called.");

    Result result_value{ResultSuccess};
    auto res = GetSetupResultValue(result_value);

    IPC::ResponseBuilder rb{ctx, 3};
    rb.Push(res);
    rb.Push(result_value);
}

void SteadyClock::Handle_GetInternalOffset(HLERequestContext& ctx) {
    LOG_DEBUG(Service_Time, "called.");

    s64 internal_offset{};
    auto res = GetInternalOffset(internal_offset);

    IPC::ResponseBuilder rb{ctx, 4};
    rb.Push(res);
    rb.Push(internal_offset);
}

// =============================== Implementations ===========================

Result SteadyClock::GetCurrentTimePoint(SteadyClockTimePoint& out_time_point) {
    R_UNLESS(m_can_write_uninitialized_clock || m_clock_core.IsInitialized(),
             ResultClockUninitialized);

    R_RETURN(m_clock_core.GetCurrentTimePoint(out_time_point));
}

Result SteadyClock::GetTestOffset(s64& out_test_offset) {
    R_UNLESS(m_can_write_uninitialized_clock || m_clock_core.IsInitialized(),
             ResultClockUninitialized);

    out_test_offset = m_clock_core.GetTestOffset();
    R_SUCCEED();
}

Result SteadyClock::SetTestOffset(s64 test_offset) {
    R_UNLESS(m_can_write_steady_clock, ResultPermissionDenied);
    R_UNLESS(m_can_write_uninitialized_clock || m_clock_core.IsInitialized(),
             ResultClockUninitialized);

    m_clock_core.SetTestOffset(test_offset);
    R_SUCCEED();
}

Result SteadyClock::GetRtcValue(s64& out_rtc_value) {
    R_UNLESS(m_can_write_uninitialized_clock || m_clock_core.IsInitialized(),
             ResultClockUninitialized);

    R_RETURN(m_clock_core.GetRtcValue(out_rtc_value));
}

Result SteadyClock::IsRtcResetDetected(bool& out_is_detected) {
    R_UNLESS(m_can_write_uninitialized_clock || m_clock_core.IsInitialized(),
             ResultClockUninitialized);

    out_is_detected = m_clock_core.IsResetDetected();
    R_SUCCEED();
}

Result SteadyClock::GetSetupResultValue(Result& out_result) {
    R_UNLESS(m_can_write_uninitialized_clock || m_clock_core.IsInitialized(),
             ResultClockUninitialized);

    out_result = m_clock_core.GetSetupResultValue();
    R_SUCCEED();
}

Result SteadyClock::GetInternalOffset(s64& out_internal_offset) {
    R_UNLESS(m_can_write_uninitialized_clock || m_clock_core.IsInitialized(),
             ResultClockUninitialized);

    out_internal_offset = m_clock_core.GetInternalOffset();
    R_SUCCEED();
}

} // namespace Service::PSC::Time