Carol Wang | 71230ef | 2020-02-18 17:39:49 +0800 | [diff] [blame] | 1 | #include "scheduled_host_transition.hpp" |
| 2 | |
Carol Wang | 4ca6f3f | 2020-02-19 16:28:59 +0800 | [diff] [blame^] | 3 | #include <phosphor-logging/elog-errors.hpp> |
| 4 | #include <phosphor-logging/elog.hpp> |
| 5 | #include <phosphor-logging/log.hpp> |
| 6 | #include <xyz/openbmc_project/ScheduledTime/error.hpp> |
| 7 | #include <chrono> |
| 8 | |
Carol Wang | 71230ef | 2020-02-18 17:39:49 +0800 | [diff] [blame] | 9 | namespace phosphor |
| 10 | { |
| 11 | namespace state |
| 12 | { |
| 13 | namespace manager |
| 14 | { |
| 15 | |
Carol Wang | 4ca6f3f | 2020-02-19 16:28:59 +0800 | [diff] [blame^] | 16 | using namespace std::chrono; |
| 17 | using namespace phosphor::logging; |
| 18 | using namespace xyz::openbmc_project::ScheduledTime; |
| 19 | using InvalidTimeError = |
| 20 | sdbusplus::xyz::openbmc_project::ScheduledTime::Error::InvalidTime; |
Carol Wang | 71230ef | 2020-02-18 17:39:49 +0800 | [diff] [blame] | 21 | using HostTransition = |
| 22 | sdbusplus::xyz::openbmc_project::State::server::ScheduledHostTransition; |
| 23 | |
| 24 | uint64_t ScheduledHostTransition::scheduledTime(uint64_t value) |
| 25 | { |
Carol Wang | 4ca6f3f | 2020-02-19 16:28:59 +0800 | [diff] [blame^] | 26 | if (value == 0) |
| 27 | { |
| 28 | // 0 means the function Scheduled Host Transition is disabled |
| 29 | // to do: check timer, stop timer |
| 30 | log<level::INFO>("The function Scheduled Host Transition is disabled."); |
| 31 | return HostTransition::scheduledTime(value); |
| 32 | } |
| 33 | |
| 34 | auto deltaTime = seconds(value) - getTime(); |
| 35 | if (deltaTime < seconds(0)) |
| 36 | { |
| 37 | log<level::ERR>("Scheduled time is earlier than current time. Fail to " |
| 38 | "do host transition."); |
| 39 | elog<InvalidTimeError>( |
| 40 | InvalidTime::REASON("Scheduled time is in the past")); |
| 41 | } |
| 42 | else |
| 43 | { |
| 44 | // start timer |
| 45 | } |
Carol Wang | 71230ef | 2020-02-18 17:39:49 +0800 | [diff] [blame] | 46 | return HostTransition::scheduledTime(value); |
| 47 | } |
| 48 | |
Carol Wang | 4ca6f3f | 2020-02-19 16:28:59 +0800 | [diff] [blame^] | 49 | seconds ScheduledHostTransition::getTime() |
| 50 | { |
| 51 | auto now = system_clock::now(); |
| 52 | return duration_cast<seconds>(now.time_since_epoch()); |
| 53 | } |
| 54 | |
Carol Wang | 71230ef | 2020-02-18 17:39:49 +0800 | [diff] [blame] | 55 | } // namespace manager |
| 56 | } // namespace state |
| 57 | } // namespace phosphor |