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
|
// 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/system_clock.h"
namespace Service::PSC::Time {
SystemClock::SystemClock(Core::System& system_, SystemClockCore& clock_core, bool can_write_clock,
bool can_write_uninitialized_clock)
: ServiceFramework{system_, "ISystemClock"}, m_system{system}, m_clock_core{clock_core},
m_can_write_clock{can_write_clock}, m_can_write_uninitialized_clock{
can_write_uninitialized_clock} {
// clang-format off
static const FunctionInfo functions[] = {
{0, &SystemClock::Handle_GetCurrentTime, "GetCurrentTime"},
{1, &SystemClock::Handle_SetCurrentTime, "SetCurrentTime"},
{2, &SystemClock::Handle_GetSystemClockContext, "GetSystemClockContext"},
{3, &SystemClock::Handle_SetSystemClockContext, "SetSystemClockContext"},
{4, &SystemClock::Handle_GetOperationEventReadableHandle, "GetOperationEventReadableHandle"},
};
// clang-format on
RegisterHandlers(functions);
}
void SystemClock::Handle_GetCurrentTime(HLERequestContext& ctx) {
LOG_DEBUG(Service_Time, "called.");
s64 time{};
auto res = GetCurrentTime(time);
IPC::ResponseBuilder rb{ctx, 4};
rb.Push(res);
rb.Push<s64>(time);
}
void SystemClock::Handle_SetCurrentTime(HLERequestContext& ctx) {
LOG_DEBUG(Service_Time, "called.");
IPC::RequestParser rp{ctx};
auto time{rp.Pop<s64>()};
auto res = SetCurrentTime(time);
IPC::ResponseBuilder rb{ctx, 2};
rb.Push(res);
}
void SystemClock::Handle_GetSystemClockContext(HLERequestContext& ctx) {
LOG_DEBUG(Service_Time, "called.");
SystemClockContext context{};
auto res = GetSystemClockContext(context);
IPC::ResponseBuilder rb{ctx, 2 + sizeof(SystemClockContext) / sizeof(u32)};
rb.Push(res);
rb.PushRaw<SystemClockContext>(context);
}
void SystemClock::Handle_SetSystemClockContext(HLERequestContext& ctx) {
LOG_DEBUG(Service_Time, "called.");
IPC::RequestParser rp{ctx};
auto context{rp.PopRaw<SystemClockContext>()};
auto res = SetSystemClockContext(context);
IPC::ResponseBuilder rb{ctx, 2};
rb.Push(res);
}
void SystemClock::Handle_GetOperationEventReadableHandle(HLERequestContext& ctx) {
LOG_DEBUG(Service_Time, "called.");
Kernel::KEvent* event{};
auto res = GetOperationEventReadableHandle(&event);
IPC::ResponseBuilder rb{ctx, 2, 1};
rb.Push(res);
rb.PushCopyObjects(event->GetReadableEvent());
}
// =============================== Implementations ===========================
Result SystemClock::GetCurrentTime(s64& out_time) {
R_UNLESS(m_can_write_uninitialized_clock || m_clock_core.IsInitialized(),
ResultClockUninitialized);
R_RETURN(m_clock_core.GetCurrentTime(&out_time));
}
Result SystemClock::SetCurrentTime(s64 time) {
R_UNLESS(m_can_write_clock, ResultPermissionDenied);
R_UNLESS(m_can_write_uninitialized_clock || m_clock_core.IsInitialized(),
ResultClockUninitialized);
R_RETURN(m_clock_core.SetCurrentTime(time));
}
Result SystemClock::GetSystemClockContext(SystemClockContext& out_context) {
R_UNLESS(m_can_write_uninitialized_clock || m_clock_core.IsInitialized(),
ResultClockUninitialized);
R_RETURN(m_clock_core.GetContext(out_context));
}
Result SystemClock::SetSystemClockContext(SystemClockContext& context) {
R_UNLESS(m_can_write_clock, ResultPermissionDenied);
R_UNLESS(m_can_write_uninitialized_clock || m_clock_core.IsInitialized(),
ResultClockUninitialized);
R_RETURN(m_clock_core.SetContextAndWrite(context));
}
Result SystemClock::GetOperationEventReadableHandle(Kernel::KEvent** out_event) {
if (!m_operation_event) {
m_operation_event = std::make_unique<OperationEvent>(m_system);
R_UNLESS(m_operation_event != nullptr, ResultFailed);
m_clock_core.LinkOperationEvent(*m_operation_event);
}
*out_event = m_operation_event->m_event;
R_SUCCEED();
}
} // namespace Service::PSC::Time
|