Carol Wang | 71230ef | 2020-02-18 17:39:49 +0800 | [diff] [blame] | 1 | #pragma once |
| 2 | |
| 3 | #include <sdbusplus/bus.hpp> |
| 4 | #include <phosphor-logging/log.hpp> |
Carol Wang | 6a5db3d | 2020-02-21 10:12:01 +0800 | [diff] [blame^] | 5 | #include <sdeventplus/event.hpp> |
| 6 | #include <sdeventplus/utility/timer.hpp> |
Carol Wang | 71230ef | 2020-02-18 17:39:49 +0800 | [diff] [blame] | 7 | #include <xyz/openbmc_project/State/ScheduledHostTransition/server.hpp> |
Carol Wang | 6a5db3d | 2020-02-21 10:12:01 +0800 | [diff] [blame^] | 8 | #include "config.h" |
Carol Wang | 71230ef | 2020-02-18 17:39:49 +0800 | [diff] [blame] | 9 | |
Carol Wang | 4ca6f3f | 2020-02-19 16:28:59 +0800 | [diff] [blame] | 10 | class TestScheduledHostTransition; |
| 11 | |
Carol Wang | 71230ef | 2020-02-18 17:39:49 +0800 | [diff] [blame] | 12 | namespace phosphor |
| 13 | { |
| 14 | namespace state |
| 15 | { |
| 16 | namespace manager |
| 17 | { |
| 18 | |
Carol Wang | 6a5db3d | 2020-02-21 10:12:01 +0800 | [diff] [blame^] | 19 | using Transition = |
| 20 | sdbusplus::xyz::openbmc_project::State::server::Host::Transition; |
Carol Wang | 71230ef | 2020-02-18 17:39:49 +0800 | [diff] [blame] | 21 | using ScheduledHostTransitionInherit = sdbusplus::server::object::object< |
| 22 | sdbusplus::xyz::openbmc_project::State::server::ScheduledHostTransition>; |
| 23 | |
| 24 | /** @class ScheduledHostTransition |
| 25 | * @brief Scheduled host transition implementation. |
| 26 | * @details A concrete implementation for |
| 27 | * xyz.openbmc_project.State.ScheduledHostTransition |
| 28 | */ |
| 29 | class ScheduledHostTransition : public ScheduledHostTransitionInherit |
| 30 | { |
| 31 | public: |
Carol Wang | 6a5db3d | 2020-02-21 10:12:01 +0800 | [diff] [blame^] | 32 | ScheduledHostTransition(sdbusplus::bus::bus& bus, const char* objPath, |
| 33 | const sdeventplus::Event& event) : |
| 34 | ScheduledHostTransitionInherit(bus, objPath), |
| 35 | bus(bus), |
| 36 | timer(event, std::bind(&ScheduledHostTransition::callback, this)) |
Carol Wang | 71230ef | 2020-02-18 17:39:49 +0800 | [diff] [blame] | 37 | { |
| 38 | } |
| 39 | |
| 40 | ~ScheduledHostTransition() = default; |
| 41 | |
| 42 | /** |
| 43 | * @brief Handle with scheduled time |
| 44 | * |
| 45 | * @param[in] value - The seconds since epoch |
| 46 | * @return The time for the transition. It is the same as the input value if |
| 47 | * it is set successfully. Otherwise, it won't return value, but throw an |
| 48 | * error. |
| 49 | **/ |
| 50 | uint64_t scheduledTime(uint64_t value) override; |
Carol Wang | 4ca6f3f | 2020-02-19 16:28:59 +0800 | [diff] [blame] | 51 | |
| 52 | private: |
| 53 | friend class TestScheduledHostTransition; |
Carol Wang | 6a5db3d | 2020-02-21 10:12:01 +0800 | [diff] [blame^] | 54 | |
| 55 | /** @brief sdbusplus bus client connection */ |
| 56 | sdbusplus::bus::bus& bus; |
| 57 | |
| 58 | /** @brief Timer used for host transition with seconds */ |
| 59 | sdeventplus::utility::Timer<sdeventplus::ClockId::RealTime> timer; |
| 60 | |
Carol Wang | 4ca6f3f | 2020-02-19 16:28:59 +0800 | [diff] [blame] | 61 | /** @brief Get current time |
| 62 | * |
| 63 | * @return - return current epoch time |
| 64 | */ |
| 65 | std::chrono::seconds getTime(); |
Carol Wang | 6a5db3d | 2020-02-21 10:12:01 +0800 | [diff] [blame^] | 66 | |
| 67 | /** @brief Implement host transition |
| 68 | * |
| 69 | * @return - Does not return anything. Error will result in exception |
| 70 | * being thrown |
| 71 | */ |
| 72 | void hostTransition(); |
| 73 | |
| 74 | /** @brief Used by the timer to do host transition */ |
| 75 | void callback(); |
Carol Wang | 71230ef | 2020-02-18 17:39:49 +0800 | [diff] [blame] | 76 | }; |
| 77 | } // namespace manager |
| 78 | } // namespace state |
Carol Wang | 4ca6f3f | 2020-02-19 16:28:59 +0800 | [diff] [blame] | 79 | } // namespace phosphor |