Lei YU | 9623282 | 2017-01-20 14:05:46 +0800 | [diff] [blame] | 1 | #include "bmc_epoch.hpp" |
| 2 | |
| 3 | #include <phosphor-logging/log.hpp> |
| 4 | |
| 5 | namespace phosphor |
| 6 | { |
| 7 | namespace time |
| 8 | { |
| 9 | namespace server = sdbusplus::xyz::openbmc_project::Time::server; |
| 10 | using namespace phosphor::logging; |
| 11 | |
| 12 | BmcEpoch::BmcEpoch(sdbusplus::bus::bus& bus, |
| 13 | const char* objPath) |
| 14 | : EpochBase(bus, objPath) |
| 15 | { |
| 16 | // Empty |
| 17 | } |
| 18 | |
| 19 | uint64_t BmcEpoch::elapsed() const |
| 20 | { |
| 21 | // It does not needs to check owner when getting time |
| 22 | return getTime().count(); |
| 23 | } |
| 24 | |
| 25 | uint64_t BmcEpoch::elapsed(uint64_t value) |
| 26 | { |
Lei YU | e7abcdc | 2017-01-16 15:05:24 +0800 | [diff] [blame] | 27 | if (timeMode == Mode::NTP) |
Lei YU | 9623282 | 2017-01-20 14:05:46 +0800 | [diff] [blame] | 28 | { |
Lei YU | e7abcdc | 2017-01-16 15:05:24 +0800 | [diff] [blame] | 29 | log<level::ERR>("Setting BmcTime with NTP mode is not allowed"); |
| 30 | // TODO: throw NotAllowed exception |
| 31 | return 0; |
Lei YU | 9623282 | 2017-01-20 14:05:46 +0800 | [diff] [blame] | 32 | } |
Lei YU | e7abcdc | 2017-01-16 15:05:24 +0800 | [diff] [blame] | 33 | if (timeOwner == Owner::HOST) |
| 34 | { |
| 35 | log<level::ERR>("Setting BmcTime with HOST owner is not allowed"); |
| 36 | // TODO: throw NotAllowed exception |
| 37 | return 0; |
| 38 | } |
| 39 | |
| 40 | auto time = std::chrono::microseconds(value); |
| 41 | setTime(time); |
| 42 | |
Lei YU | 9623282 | 2017-01-20 14:05:46 +0800 | [diff] [blame] | 43 | server::EpochTime::elapsed(value); |
| 44 | return value; |
| 45 | } |
| 46 | |
Lei YU | af5abc5 | 2017-03-07 17:49:17 +0800 | [diff] [blame] | 47 | } // namespace time |
| 48 | } // namespace phosphor |
Lei YU | 9623282 | 2017-01-20 14:05:46 +0800 | [diff] [blame] | 49 | |