blob: 1cb2591d4ee91953987ac7d30382e4ee5afffda8 [file] [log] [blame]
Carol Wang71230ef2020-02-18 17:39:49 +08001#pragma once
2
3#include <sdbusplus/bus.hpp>
4#include <phosphor-logging/log.hpp>
Carol Wang6a5db3d2020-02-21 10:12:01 +08005#include <sdeventplus/event.hpp>
6#include <sdeventplus/utility/timer.hpp>
Carol Wang71230ef2020-02-18 17:39:49 +08007#include <xyz/openbmc_project/State/ScheduledHostTransition/server.hpp>
Carol Wang6a5db3d2020-02-21 10:12:01 +08008#include "config.h"
Carol Wang71230ef2020-02-18 17:39:49 +08009
Carol Wang4ca6f3f2020-02-19 16:28:59 +080010class TestScheduledHostTransition;
11
Carol Wang71230ef2020-02-18 17:39:49 +080012namespace phosphor
13{
14namespace state
15{
16namespace manager
17{
18
Carol Wang6a5db3d2020-02-21 10:12:01 +080019using Transition =
20 sdbusplus::xyz::openbmc_project::State::server::Host::Transition;
Carol Wang71230ef2020-02-18 17:39:49 +080021using 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 */
29class ScheduledHostTransition : public ScheduledHostTransitionInherit
30{
31 public:
Carol Wang6a5db3d2020-02-21 10:12:01 +080032 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 Wang71230ef2020-02-18 17:39:49 +080037 {
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 Wang4ca6f3f2020-02-19 16:28:59 +080051
52 private:
53 friend class TestScheduledHostTransition;
Carol Wang6a5db3d2020-02-21 10:12:01 +080054
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 Wang4ca6f3f2020-02-19 16:28:59 +080061 /** @brief Get current time
62 *
63 * @return - return current epoch time
64 */
65 std::chrono::seconds getTime();
Carol Wang6a5db3d2020-02-21 10:12:01 +080066
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 Wang71230ef2020-02-18 17:39:49 +080076};
77} // namespace manager
78} // namespace state
Carol Wang4ca6f3f2020-02-19 16:28:59 +080079} // namespace phosphor