1 // Copyright 2019 yuzu emulator team
2 // Licensed under GPLv2 or any later version
3 // Refer to the license.txt file included.
4 
5 #pragma once
6 
7 #include "core/hle/kernel/writable_event.h"
8 #include "core/hle/service/time/clock_types.h"
9 #include "core/hle/service/time/system_clock_core.h"
10 
11 namespace Core {
12 class System;
13 }
14 
15 namespace Service::Time::Clock {
16 
17 class StandardLocalSystemClockCore;
18 class StandardNetworkSystemClockCore;
19 
20 class StandardUserSystemClockCore final : public SystemClockCore {
21 public:
22     StandardUserSystemClockCore(StandardLocalSystemClockCore& local_system_clock_core,
23                                 StandardNetworkSystemClockCore& network_system_clock_core,
24                                 Core::System& system);
25 
26     ResultCode SetAutomaticCorrectionEnabled(Core::System& system, bool value);
27 
28     ResultCode GetClockContext(Core::System& system, SystemClockContext& context) const override;
29 
IsAutomaticCorrectionEnabled()30     bool IsAutomaticCorrectionEnabled() const {
31         return auto_correction_enabled;
32     }
33 
SetAutomaticCorrectionUpdatedTime(SteadyClockTimePoint steady_clock_time_point)34     void SetAutomaticCorrectionUpdatedTime(SteadyClockTimePoint steady_clock_time_point) {
35         auto_correction_time = steady_clock_time_point;
36     }
37 
38 protected:
39     ResultCode Flush(const SystemClockContext& context) override;
40 
41     ResultCode SetClockContext(const SystemClockContext&) override;
42 
43     ResultCode ApplyAutomaticCorrection(Core::System& system, bool value) const;
44 
GetAutomaticCorrectionUpdatedTime()45     const SteadyClockTimePoint& GetAutomaticCorrectionUpdatedTime() const {
46         return auto_correction_time;
47     }
48 
49 private:
50     StandardLocalSystemClockCore& local_system_clock_core;
51     StandardNetworkSystemClockCore& network_system_clock_core;
52     bool auto_correction_enabled{};
53     SteadyClockTimePoint auto_correction_time;
54     Kernel::EventPair auto_correction_event;
55 };
56 
57 } // namespace Service::Time::Clock
58