blob: b823b7fad3f06b54139aba37cd66455d687bc3f7 [file] [log] [blame]
Andrew Geisslera90a31a2016-12-13 16:16:28 -06001#pragma once
2#include <tuple>
3#include <systemd/sd-bus.h>
4#include <sdbusplus/server.hpp>
5
6namespace sdbusplus
7{
8namespace xyz
9{
10namespace openbmc_project
11{
12namespace State
13{
14namespace server
15{
16
17class Chassis
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 Chassis() = delete;
30 Chassis(const Chassis&) = delete;
31 Chassis& operator=(const Chassis&) = delete;
32 Chassis(Chassis&&) = delete;
33 Chassis& operator=(Chassis&&) = delete;
34 virtual ~Chassis() = 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 Chassis(bus::bus& bus, const char* path);
41
42 enum class Transition
43 {
44 Off,
45 On,
46 };
47 enum class PowerState
48 {
49 Off,
50 On,
51 };
52
53
54
55 /** Get value of RequestedPowerTransition */
56 virtual Transition requestedPowerTransition() const;
57 /** Set value of RequestedPowerTransition */
58 virtual Transition requestedPowerTransition(Transition value);
59 /** Get value of CurrentPowerState */
60 virtual PowerState currentPowerState() const;
61 /** Set value of CurrentPowerState */
62 virtual PowerState currentPowerState(PowerState value);
63
64 /** @brief Convert a string to an appropriate enum value.
65 * @param[in] s - The string to convert in the form of
66 * "xyz.openbmc_project.State.Chassis.<value name>"
67 * @return - The enum value.
68 */
69 static Transition convertTransitionFromString(std::string& s);
70 /** @brief Convert a string to an appropriate enum value.
71 * @param[in] s - The string to convert in the form of
72 * "xyz.openbmc_project.State.Chassis.<value name>"
73 * @return - The enum value.
74 */
75 static PowerState convertPowerStateFromString(std::string& s);
76
77 private:
78
79 /** @brief sd-bus callback for get-property 'RequestedPowerTransition' */
80 static int _callback_get_RequestedPowerTransition(
81 sd_bus*, const char*, const char*, const char*,
82 sd_bus_message*, void*, sd_bus_error*);
83 /** @brief sd-bus callback for set-property 'RequestedPowerTransition' */
84 static int _callback_set_RequestedPowerTransition(
85 sd_bus*, const char*, const char*, const char*,
86 sd_bus_message*, void*, sd_bus_error*);
87
88 /** @brief sd-bus callback for get-property 'CurrentPowerState' */
89 static int _callback_get_CurrentPowerState(
90 sd_bus*, const char*, const char*, const char*,
91 sd_bus_message*, void*, sd_bus_error*);
92 /** @brief sd-bus callback for set-property 'CurrentPowerState' */
93 static int _callback_set_CurrentPowerState(
94 sd_bus*, const char*, const char*, const char*,
95 sd_bus_message*, void*, sd_bus_error*);
96
97
98 static constexpr auto _interface = "xyz.openbmc_project.State.Chassis";
99 static const vtable::vtable_t _vtable[];
100 sdbusplus::server::interface::interface
101 _xyz_openbmc_project_State_Chassis_interface;
102
103 Transition _requestedPowerTransition = Transition::Off;
104 PowerState _currentPowerState{};
105
106};
107
108/* Specialization of sdbusplus::server::bindings::details::convertForMessage
109 * for enum-type Chassis::Transition.
110 *
111 * This converts from the enum to a constant c-string representing the enum.
112 *
113 * @param[in] e - Enum value to convert.
114 * @return C-string representing the name for the enum value.
115 */
116std::string convertForMessage(Chassis::Transition e);
117/* Specialization of sdbusplus::server::bindings::details::convertForMessage
118 * for enum-type Chassis::PowerState.
119 *
120 * This converts from the enum to a constant c-string representing the enum.
121 *
122 * @param[in] e - Enum value to convert.
123 * @return C-string representing the name for the enum value.
124 */
125std::string convertForMessage(Chassis::PowerState e);
126
127} // namespace server
128} // namespace State
129} // namespace openbmc_project
130} // namespace xyz
131} // namespace sdbusplus
132