summaryrefslogtreecommitdiffstats
path: root/src/core/hle/service/time/system_clock_core.cpp
diff options
context:
space:
mode:
authorbunnei <bunneidev@gmail.com>2019-12-22 23:49:51 +0100
committerbunnei <bunneidev@gmail.com>2020-01-04 19:48:29 +0100
commit78f977c980e125e92b86261335447d0a254f18ee (patch)
treeeca0bcfdcabe32dd737fc545b1ce42395cdad2fc /src/core/hle/service/time/system_clock_core.cpp
parentcore: Initialize several structs that make use of Common::UUID. (diff)
downloadyuzu-78f977c980e125e92b86261335447d0a254f18ee.tar
yuzu-78f977c980e125e92b86261335447d0a254f18ee.tar.gz
yuzu-78f977c980e125e92b86261335447d0a254f18ee.tar.bz2
yuzu-78f977c980e125e92b86261335447d0a254f18ee.tar.lz
yuzu-78f977c980e125e92b86261335447d0a254f18ee.tar.xz
yuzu-78f977c980e125e92b86261335447d0a254f18ee.tar.zst
yuzu-78f977c980e125e92b86261335447d0a254f18ee.zip
Diffstat (limited to 'src/core/hle/service/time/system_clock_core.cpp')
-rw-r--r--src/core/hle/service/time/system_clock_core.cpp72
1 files changed, 72 insertions, 0 deletions
diff --git a/src/core/hle/service/time/system_clock_core.cpp b/src/core/hle/service/time/system_clock_core.cpp
new file mode 100644
index 000000000..1a3ab8cfa
--- /dev/null
+++ b/src/core/hle/service/time/system_clock_core.cpp
@@ -0,0 +1,72 @@
+// Copyright 2019 yuzu emulator team
+// Licensed under GPLv2 or any later version
+// Refer to the license.txt file included.
+
+#include "core/hle/service/time/steady_clock_core.h"
+#include "core/hle/service/time/system_clock_context_update_callback.h"
+#include "core/hle/service/time/system_clock_core.h"
+
+namespace Service::Time::Clock {
+
+SystemClockCore::SystemClockCore(SteadyClockCore& steady_clock_core)
+ : steady_clock_core{steady_clock_core}, is_initialized{} {
+ context.steady_time_point.clock_source_id = steady_clock_core.GetClockSourceId();
+}
+
+SystemClockCore ::~SystemClockCore() = default;
+
+ResultCode SystemClockCore::GetCurrentTime(Core::System& system, s64& posix_time) const {
+ posix_time = 0;
+
+ const SteadyClockTimePoint current_time_point{steady_clock_core.GetCurrentTimePoint(system)};
+
+ SystemClockContext clock_context{};
+ if (const ResultCode result{GetClockContext(system, clock_context)}; result != RESULT_SUCCESS) {
+ return result;
+ }
+
+ if (current_time_point.clock_source_id != clock_context.steady_time_point.clock_source_id) {
+ return ERROR_TIME_MISMATCH;
+ }
+
+ posix_time = clock_context.offset + current_time_point.time_point;
+
+ return RESULT_SUCCESS;
+}
+
+ResultCode SystemClockCore::SetCurrentTime(Core::System& system, s64 posix_time) {
+ const SteadyClockTimePoint current_time_point{steady_clock_core.GetCurrentTimePoint(system)};
+ const SystemClockContext clock_context{posix_time - current_time_point.time_point,
+ current_time_point};
+
+ if (const ResultCode result{SetClockContext(clock_context)}; result != RESULT_SUCCESS) {
+ return result;
+ }
+ return Flush(clock_context);
+}
+
+ResultCode SystemClockCore::Flush(const SystemClockContext& context) {
+ if (!system_clock_context_update_callback) {
+ return RESULT_SUCCESS;
+ }
+ return system_clock_context_update_callback->Update(context);
+}
+
+ResultCode SystemClockCore::SetSystemClockContext(const SystemClockContext& context) {
+ if (const ResultCode result{SetClockContext(context)}; result != RESULT_SUCCESS) {
+ return result;
+ }
+ return Flush(context);
+}
+
+bool SystemClockCore::IsClockSetup(Core::System& system) const {
+ SystemClockContext value{};
+ if (GetClockContext(system, value) == RESULT_SUCCESS) {
+ const SteadyClockTimePoint steady_clock_time_point{
+ steady_clock_core.GetCurrentTimePoint(system)};
+ return steady_clock_time_point.clock_source_id == value.steady_time_point.clock_source_id;
+ }
+ return {};
+}
+
+} // namespace Service::Time::Clock