summaryrefslogtreecommitdiffstats
path: root/src/core/hle/service/time/system_clock_core.h
blob: 82a8b79ff46ab33c18ba6804daf0f03af76c8f62 (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
// Copyright 2019 yuzu emulator team
// Licensed under GPLv2 or any later version
// Refer to the license.txt file included.

#pragma once

#include "common/common_types.h"
#include "core/hle/service/time/clock_types.h"

namespace Core {
class System;
}

namespace Service::Time::Clock {

class SteadyClockCore;
class SystemClockContextUpdateCallback;

// Parts of this implementation were based on Ryujinx (https://github.com/Ryujinx/Ryujinx/pull/783).
// This code was released under public domain.

class SystemClockCore {
public:
    explicit SystemClockCore(SteadyClockCore& steady_clock_core);
    virtual ~SystemClockCore();

    SteadyClockCore& GetSteadyClockCore() const {
        return steady_clock_core;
    }

    ResultCode GetCurrentTime(Core::System& system, s64& posix_time) const;

    ResultCode SetCurrentTime(Core::System& system, s64 posix_time);

    virtual ResultCode GetClockContext([[maybe_unused]] Core::System& system,
                                       SystemClockContext& value) const {
        value = context;
        return RESULT_SUCCESS;
    }

    virtual ResultCode SetClockContext(const SystemClockContext& value) {
        context = value;
        return RESULT_SUCCESS;
    }

    virtual ResultCode Flush(const SystemClockContext& clock_context);

    void SetUpdateCallbackInstance(std::shared_ptr<SystemClockContextUpdateCallback> callback) {
        system_clock_context_update_callback = std::move(callback);
    }

    ResultCode SetSystemClockContext(const SystemClockContext& context);

    bool IsInitialized() const {
        return is_initialized;
    }

    void MarkAsInitialized() {
        is_initialized = true;
    }

    bool IsClockSetup(Core::System& system) const;

private:
    SteadyClockCore& steady_clock_core;
    SystemClockContext context{};
    bool is_initialized{};
    std::shared_ptr<SystemClockContextUpdateCallback> system_clock_context_update_callback;
};

} // namespace Service::Time::Clock