blob: 07b3113a0ae2eb9f673acf5161983c6d604675f1 [file] [log] [blame]
Lei YU2f9c0cc2017-01-20 14:02:03 +08001#include "epoch_base.hpp"
2
3#include <phosphor-logging/log.hpp>
4
5#include <iomanip>
6#include <sstream>
7
Lei YU2f9c0cc2017-01-20 14:02:03 +08008namespace phosphor
9{
10namespace time
11{
12
13using namespace phosphor::logging;
14
Lei YU2f9c0cc2017-01-20 14:02:03 +080015EpochBase::EpochBase(sdbusplus::bus::bus& bus,
16 const char* objPath)
Lei YU415b9642017-02-09 11:37:26 +080017 : sdbusplus::server::object::object<EpochTime>(bus, objPath),
Lei YU2f9c0cc2017-01-20 14:02:03 +080018 bus(bus)
19{
Lei YU2f9c0cc2017-01-20 14:02:03 +080020}
21
Lei YU415b9642017-02-09 11:37:26 +080022void EpochBase::onModeChanged(Mode mode)
Lei YU2f9c0cc2017-01-20 14:02:03 +080023{
Lei YU415b9642017-02-09 11:37:26 +080024 timeMode = mode;
Lei YU2f9c0cc2017-01-20 14:02:03 +080025}
26
Lei YU415b9642017-02-09 11:37:26 +080027void EpochBase::onOwnerChanged(Owner owner)
Lei YU2f9c0cc2017-01-20 14:02:03 +080028{
Lei YU415b9642017-02-09 11:37:26 +080029 timeOwner = owner;
Lei YU2f9c0cc2017-01-20 14:02:03 +080030}
31
32using namespace std::chrono;
33void 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
45microseconds 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