| Andrew Geissler | 3652902 | 2016-11-29 15:23:54 -0600 | [diff] [blame] | 1 | #pragma once |
| 2 | #include <tuple> |
| 3 | #include <systemd/sd-bus.h> |
| 4 | #include <sdbusplus/server.hpp> |
| 5 | |
| 6 | namespace sdbusplus |
| 7 | { |
| 8 | namespace xyz |
| 9 | { |
| 10 | namespace openbmc_project |
| 11 | { |
| 12 | namespace State |
| 13 | { |
| 14 | namespace server |
| 15 | { |
| 16 | |
| 17 | class Host |
| 18 | { |
| 19 | public: |
| 20 | /* Define all of the basic class operations: |
| 21 | * Not allowed: |
| 22 | * - Default constructor to avoid nullptrs. |
| 23 | * - Copy operations due to internal unique_ptr. |
| 24 | * - Move operations due to 'this' being registered as the |
| 25 | * 'context' with sdbus. |
| 26 | * Allowed: |
| 27 | * - Destructor. |
| 28 | */ |
| 29 | Host() = delete; |
| 30 | Host(const Host&) = delete; |
| 31 | Host& operator=(const Host&) = delete; |
| 32 | Host(Host&&) = delete; |
| 33 | Host& operator=(Host&&) = delete; |
| 34 | virtual ~Host() = default; |
| 35 | |
| 36 | /** @brief Constructor to put object onto bus at a dbus path. |
| 37 | * @param[in] bus - Bus to attach to. |
| 38 | * @param[in] path - Path to attach at. |
| 39 | */ |
| 40 | Host(bus::bus& bus, const char* path); |
| 41 | |
| 42 | enum class Transition |
| 43 | { |
| 44 | Off, |
| 45 | On, |
| 46 | Reboot, |
| 47 | }; |
| 48 | enum class HostState |
| 49 | { |
| 50 | Off, |
| 51 | Running, |
| 52 | }; |
| 53 | |
| 54 | |
| 55 | |
| 56 | /** Get value of RequestedHostTransition */ |
| 57 | virtual Transition requestedHostTransition() const; |
| 58 | /** Set value of RequestedHostTransition */ |
| 59 | virtual Transition requestedHostTransition(Transition value); |
| 60 | /** Get value of CurrentHostState */ |
| 61 | virtual HostState currentHostState() const; |
| 62 | /** Set value of CurrentHostState */ |
| 63 | virtual HostState currentHostState(HostState value); |
| 64 | |
| 65 | /** @brief Convert a string to an appropriate enum value. |
| 66 | * @param[in] s - The string to convert in the form of |
| 67 | * "xyz.openbmc_project.State.Host.<value name>" |
| 68 | * @return - The enum value. |
| 69 | */ |
| 70 | static Transition convertTransitionFromString(std::string& s); |
| 71 | /** @brief Convert a string to an appropriate enum value. |
| 72 | * @param[in] s - The string to convert in the form of |
| 73 | * "xyz.openbmc_project.State.Host.<value name>" |
| 74 | * @return - The enum value. |
| 75 | */ |
| 76 | static HostState convertHostStateFromString(std::string& s); |
| 77 | |
| 78 | private: |
| 79 | |
| 80 | /** @brief sd-bus callback for get-property 'RequestedHostTransition' */ |
| 81 | static int _callback_get_RequestedHostTransition( |
| 82 | sd_bus*, const char*, const char*, const char*, |
| 83 | sd_bus_message*, void*, sd_bus_error*); |
| 84 | /** @brief sd-bus callback for set-property 'RequestedHostTransition' */ |
| 85 | static int _callback_set_RequestedHostTransition( |
| 86 | sd_bus*, const char*, const char*, const char*, |
| 87 | sd_bus_message*, void*, sd_bus_error*); |
| 88 | |
| 89 | /** @brief sd-bus callback for get-property 'CurrentHostState' */ |
| 90 | static int _callback_get_CurrentHostState( |
| 91 | sd_bus*, const char*, const char*, const char*, |
| 92 | sd_bus_message*, void*, sd_bus_error*); |
| 93 | /** @brief sd-bus callback for set-property 'CurrentHostState' */ |
| 94 | static int _callback_set_CurrentHostState( |
| 95 | sd_bus*, const char*, const char*, const char*, |
| 96 | sd_bus_message*, void*, sd_bus_error*); |
| 97 | |
| 98 | |
| 99 | static constexpr auto _interface = "xyz.openbmc_project.State.Host"; |
| 100 | static const vtable::vtable_t _vtable[]; |
| 101 | sdbusplus::server::interface::interface |
| 102 | _xyz_openbmc_project_State_Host_interface; |
| 103 | |
| 104 | Transition _requestedHostTransition = Transition::Off; |
| 105 | HostState _currentHostState{}; |
| 106 | |
| 107 | }; |
| 108 | |
| 109 | /* Specialization of sdbusplus::server::bindings::details::convertForMessage |
| 110 | * for enum-type Host::Transition. |
| 111 | * |
| 112 | * This converts from the enum to a constant c-string representing the enum. |
| 113 | * |
| 114 | * @param[in] e - Enum value to convert. |
| 115 | * @return C-string representing the name for the enum value. |
| 116 | */ |
| 117 | std::string convertForMessage(Host::Transition e); |
| 118 | /* Specialization of sdbusplus::server::bindings::details::convertForMessage |
| 119 | * for enum-type Host::HostState. |
| 120 | * |
| 121 | * This converts from the enum to a constant c-string representing the enum. |
| 122 | * |
| 123 | * @param[in] e - Enum value to convert. |
| 124 | * @return C-string representing the name for the enum value. |
| 125 | */ |
| 126 | std::string convertForMessage(Host::HostState e); |
| 127 | |
| 128 | } // namespace server |
| 129 | } // namespace State |
| 130 | } // namespace openbmc_project |
| 131 | } // namespace xyz |
| 132 | } // namespace sdbusplus |
| 133 | |