summaryrefslogtreecommitdiffstats
path: root/host_epoch.hpp
blob: bbf9d22a583c37b1f8ad48b9944785e412988c33 (plain)
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
#pragma once

#include "config.h"

#include "bmc_time_change_listener.hpp"
#include "epoch_base.hpp"

#include <chrono>

namespace phosphor
{
namespace time
{

/** @class HostEpoch
 *  @brief OpenBMC HOST EpochTime implementation.
 *  @details A concrete implementation for xyz.openbmc_project.Time.EpochTime
 *  DBus API for HOST's epoch time.
 */
class HostEpoch : public EpochBase, public BmcTimeChangeListener
{
  public:
    friend class TestHostEpoch;
    HostEpoch(sdbusplus::bus::bus& bus, const char* objPath);

    /**
     * @brief Get value of Elapsed property
     *
     * @return The elapsed microseconds since UTC
     **/
    uint64_t elapsed() const override;

    /**
     * @brief Set value of Elapsed property
     *
     * @param[in] value - The microseconds since UTC to set
     *
     * @return The updated elapsed microseconds since UTC
     **/
    uint64_t elapsed(uint64_t value) override;

    /** @brief Notified on time owner changed */
    void onOwnerChanged(Owner owner) override;

    /** @brief Notified on bmc time is changed
     *
     * @param[in] bmcTime - The epoch time in microseconds
     */
    void onBmcTimeChanged(const std::chrono::microseconds& bmcTime) override;

  private:
    /** @brief The diff between BMC and Host time */
    std::chrono::microseconds offset;

    /**
     * @brief The diff between host time and steady clock
     * @details This diff is used to calculate the host time if BMC time
     * is changed and the owner is SPLIT.
     * Without this the host time is lost if BMC time is changed.
     */
    std::chrono::microseconds diffToSteadyClock;

    /** @brief Save the offset value into offsetFile */
    void saveOffset();

    /** @brief The file to store the offset in File System.
     *  Read back when starts
     **/
    static constexpr auto offsetFile = HOST_OFFSET_FILE;
};

} // namespace time
} // namespace phosphor
OpenPOWER on IntegriCloud