Lei YU | 2f9c0cc | 2017-01-20 14:02:03 +0800 | [diff] [blame] | 1 | #include "epoch_base.hpp" |
| 2 | |
| 3 | #include <phosphor-logging/log.hpp> |
| 4 | |
| 5 | #include <iomanip> |
| 6 | #include <sstream> |
| 7 | |
Lei YU | 2f9c0cc | 2017-01-20 14:02:03 +0800 | [diff] [blame] | 8 | namespace phosphor |
| 9 | { |
| 10 | namespace time |
| 11 | { |
| 12 | |
| 13 | using namespace phosphor::logging; |
| 14 | |
Lei YU | 2f9c0cc | 2017-01-20 14:02:03 +0800 | [diff] [blame] | 15 | EpochBase::EpochBase(sdbusplus::bus::bus& bus, |
| 16 | const char* objPath) |
Lei YU | 415b964 | 2017-02-09 11:37:26 +0800 | [diff] [blame] | 17 | : sdbusplus::server::object::object<EpochTime>(bus, objPath), |
Lei YU | 2f9c0cc | 2017-01-20 14:02:03 +0800 | [diff] [blame] | 18 | bus(bus) |
| 19 | { |
Lei YU | 2f9c0cc | 2017-01-20 14:02:03 +0800 | [diff] [blame] | 20 | } |
| 21 | |
Lei YU | 415b964 | 2017-02-09 11:37:26 +0800 | [diff] [blame] | 22 | void EpochBase::onModeChanged(Mode mode) |
Lei YU | 2f9c0cc | 2017-01-20 14:02:03 +0800 | [diff] [blame] | 23 | { |
Lei YU | 415b964 | 2017-02-09 11:37:26 +0800 | [diff] [blame] | 24 | timeMode = mode; |
Lei YU | 2f9c0cc | 2017-01-20 14:02:03 +0800 | [diff] [blame] | 25 | } |
| 26 | |
Lei YU | 415b964 | 2017-02-09 11:37:26 +0800 | [diff] [blame] | 27 | void EpochBase::onOwnerChanged(Owner owner) |
Lei YU | 2f9c0cc | 2017-01-20 14:02:03 +0800 | [diff] [blame] | 28 | { |
Lei YU | 415b964 | 2017-02-09 11:37:26 +0800 | [diff] [blame] | 29 | timeOwner = owner; |
Lei YU | 2f9c0cc | 2017-01-20 14:02:03 +0800 | [diff] [blame] | 30 | } |
| 31 | |
| 32 | using namespace std::chrono; |
| 33 | void EpochBase::setTime(const microseconds& usec) |
| 34 | { |
| 35 | auto method = bus.new_method_call("org.freedesktop.timedate1", |
| 36 | "/org/freedesktop/timedate1", |
| 37 | "org.freedesktop.timedate1", |
| 38 | "SetTime"); |
| 39 | method.append(static_cast<int64_t>(usec.count()), |
| 40 | false, // relative |
| 41 | false); // user_interaction |
| 42 | bus.call_noreply(method); |
| 43 | } |
| 44 | |
| 45 | microseconds EpochBase::getTime() const |
| 46 | { |
| 47 | auto now = system_clock::now(); |
| 48 | return duration_cast<microseconds> |
| 49 | (now.time_since_epoch()); |
| 50 | } |
| 51 | |
| 52 | } // namespace time |
| 53 | } // namespace phosphor |