blob: 3b4c00eb4fc30cb69d275ec39c74f71f8f7c86ed [file] [log] [blame]
Lei YUaf5abc52017-03-07 17:49:17 +08001#include "host_epoch.hpp"
Lei YU7f4fca52017-02-23 15:15:51 +08002#include "utils.hpp"
Lei YUaf5abc52017-03-07 17:49:17 +08003
4#include <phosphor-logging/log.hpp>
5
Lei YUaf5abc52017-03-07 17:49:17 +08006namespace phosphor
7{
8namespace time
9{
10using namespace sdbusplus::xyz::openbmc_project::Time;
11using namespace phosphor::logging;
12
13HostEpoch::HostEpoch(sdbusplus::bus::bus& bus,
14 const char* objPath)
15 : EpochBase(bus, objPath),
Lei YU7f4fca52017-02-23 15:15:51 +080016 offset(utils::readData<decltype(offset)::rep>(offsetFile))
Lei YUaf5abc52017-03-07 17:49:17 +080017{
18 // Empty
19}
20
21uint64_t HostEpoch::elapsed() const
22{
23 // It does not needs to check owner when getting time
24 return (getTime() + offset).count();
25}
26
27uint64_t HostEpoch::elapsed(uint64_t value)
28{
29 if (timeOwner == Owner::BMC)
30 {
31 log<level::ERR>("Setting HostTime in BMC owner is not allowed");
32 // TODO: throw NotAllowed exception
33 return 0;
34 }
35
36 // TODO: implement the logic of setting host time
37 // based on timeOwner and timeMode
38
39 auto time = std::chrono::microseconds(value);
40 offset = time - getTime();
41
42 // Store the offset to file
Lei YU7f4fca52017-02-23 15:15:51 +080043 utils::writeData(offsetFile, offset.count());
Lei YUaf5abc52017-03-07 17:49:17 +080044
45 server::EpochTime::elapsed(value);
46 return value;
47}
48
Lei YUaf5abc52017-03-07 17:49:17 +080049} // namespace time
50} // namespace phosphor
51