blob: 93463910288807bb7c7102267fb05e171a6b708a (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
|
#include "epoch_base.hpp"
#include <iomanip>
#include <phosphor-logging/elog-errors.hpp>
#include <phosphor-logging/elog.hpp>
#include <phosphor-logging/log.hpp>
#include <sstream>
#include <xyz/openbmc_project/Time/error.hpp>
namespace // anonymous
{
constexpr auto SYSTEMD_TIME_SERVICE = "org.freedesktop.timedate1";
constexpr auto SYSTEMD_TIME_PATH = "/org/freedesktop/timedate1";
constexpr auto SYSTEMD_TIME_INTERFACE = "org.freedesktop.timedate1";
constexpr auto METHOD_SET_TIME = "SetTime";
} // namespace
namespace phosphor
{
namespace time
{
using namespace phosphor::logging;
using FailedError = sdbusplus::xyz::openbmc_project::Time::Error::Failed;
EpochBase::EpochBase(sdbusplus::bus::bus& bus, const char* objPath) :
sdbusplus::server::object::object<EpochTime>(bus, objPath), bus(bus)
{
}
void EpochBase::onModeChanged(Mode mode)
{
timeMode = mode;
}
void EpochBase::onOwnerChanged(Owner owner)
{
timeOwner = owner;
}
using namespace std::chrono;
bool EpochBase::setTime(const microseconds& usec)
{
auto method = bus.new_method_call(SYSTEMD_TIME_SERVICE, SYSTEMD_TIME_PATH,
SYSTEMD_TIME_INTERFACE, METHOD_SET_TIME);
method.append(static_cast<int64_t>(usec.count()),
false, // relative
false); // user_interaction
try
{
bus.call_noreply(method);
}
catch (const sdbusplus::exception::SdBusError& ex)
{
log<level::ERR>("Error in setting system time");
using namespace xyz::openbmc_project::Time;
elog<FailedError>(Failed::REASON(ex.what()));
}
return true;
}
microseconds EpochBase::getTime() const
{
auto now = system_clock::now();
return duration_cast<microseconds>(now.time_since_epoch());
}
} // namespace time
} // namespace phosphor
|