Lei YU | af5abc5 | 2017-03-07 17:49:17 +0800 | [diff] [blame] | 1 | #include "host_epoch.hpp" |
Lei YU | 7f4fca5 | 2017-02-23 15:15:51 +0800 | [diff] [blame^] | 2 | #include "utils.hpp" |
Lei YU | af5abc5 | 2017-03-07 17:49:17 +0800 | [diff] [blame] | 3 | |
| 4 | #include <phosphor-logging/log.hpp> |
| 5 | |
Lei YU | af5abc5 | 2017-03-07 17:49:17 +0800 | [diff] [blame] | 6 | namespace phosphor |
| 7 | { |
| 8 | namespace time |
| 9 | { |
| 10 | using namespace sdbusplus::xyz::openbmc_project::Time; |
| 11 | using namespace phosphor::logging; |
| 12 | |
| 13 | HostEpoch::HostEpoch(sdbusplus::bus::bus& bus, |
| 14 | const char* objPath) |
| 15 | : EpochBase(bus, objPath), |
Lei YU | 7f4fca5 | 2017-02-23 15:15:51 +0800 | [diff] [blame^] | 16 | offset(utils::readData<decltype(offset)::rep>(offsetFile)) |
Lei YU | af5abc5 | 2017-03-07 17:49:17 +0800 | [diff] [blame] | 17 | { |
| 18 | // Empty |
| 19 | } |
| 20 | |
| 21 | uint64_t HostEpoch::elapsed() const |
| 22 | { |
| 23 | // It does not needs to check owner when getting time |
| 24 | return (getTime() + offset).count(); |
| 25 | } |
| 26 | |
| 27 | uint64_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 YU | 7f4fca5 | 2017-02-23 15:15:51 +0800 | [diff] [blame^] | 43 | utils::writeData(offsetFile, offset.count()); |
Lei YU | af5abc5 | 2017-03-07 17:49:17 +0800 | [diff] [blame] | 44 | |
| 45 | server::EpochTime::elapsed(value); |
| 46 | return value; |
| 47 | } |
| 48 | |
Lei YU | af5abc5 | 2017-03-07 17:49:17 +0800 | [diff] [blame] | 49 | } // namespace time |
| 50 | } // namespace phosphor |
| 51 | |