blob: 5923e8ef67f1a83e9c0e56b01f258bd38c6329e3 [file] [log] [blame]
Lei YU96232822017-01-20 14:05:46 +08001#include "bmc_epoch.hpp"
2
3#include <phosphor-logging/log.hpp>
4
5namespace phosphor
6{
7namespace time
8{
9namespace server = sdbusplus::xyz::openbmc_project::Time::server;
10using namespace phosphor::logging;
11
12BmcEpoch::BmcEpoch(sdbusplus::bus::bus& bus,
13 const char* objPath)
14 : EpochBase(bus, objPath)
15{
16 // Empty
17}
18
19uint64_t BmcEpoch::elapsed() const
20{
21 // It does not needs to check owner when getting time
22 return getTime().count();
23}
24
25uint64_t BmcEpoch::elapsed(uint64_t value)
26{
Lei YUe7abcdc2017-01-16 15:05:24 +080027 if (timeMode == Mode::NTP)
Lei YU96232822017-01-20 14:05:46 +080028 {
Lei YUe7abcdc2017-01-16 15:05:24 +080029 log<level::ERR>("Setting BmcTime with NTP mode is not allowed");
30 // TODO: throw NotAllowed exception
31 return 0;
Lei YU96232822017-01-20 14:05:46 +080032 }
Lei YUe7abcdc2017-01-16 15:05:24 +080033 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 YU96232822017-01-20 14:05:46 +080043 server::EpochTime::elapsed(value);
44 return value;
45}
46
47}
48}
49