blob: 2269f428682e2224b6afcdd50af9f531d217e8ee [file] [log] [blame]
Vishwanatha Subbannabda97eb2016-11-30 12:21:25 +05301#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 Led
13{
14namespace server
15{
16
17class Physical
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 * Allowed:
25 * - Move operations.
26 * - Destructor.
27 */
28 Physical() = delete;
29 Physical(const Physical&) = delete;
30 Physical& operator=(const Physical&) = delete;
31 Physical(Physical&&) = default;
32 Physical& operator=(Physical&&) = default;
33 virtual ~Physical() = default;
34
35 /** @brief Constructor to put object onto bus at a dbus path.
36 * @param[in] bus - Bus to attach to.
37 * @param[in] path - Path to attach at.
38 */
39 Physical(bus::bus& bus, const char* path);
40
41 enum class Action
42 {
43 Off,
44 On,
45 Blink,
46 };
47 enum class Palette
48 {
49 Unknown,
50 Red,
51 Green,
52 Blue,
53 Yellow,
54 };
55
56
57
58 /** Get value of State */
59 virtual Action state() const;
60 /** Set value of State */
61 virtual Action state(Action value);
62 /** Get value of DutyOn */
63 virtual uint8_t dutyOn() const;
64 /** Set value of DutyOn */
65 virtual uint8_t dutyOn(uint8_t value);
66 /** Get value of Color */
67 virtual Palette color() const;
68 /** Set value of Color */
69 virtual Palette color(Palette value);
70
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.Led.Physical.<value name>"
74 * @return - The enum value.
75 */
76 static Action convertActionFromString(std::string& s);
77 /** @brief Convert a string to an appropriate enum value.
78 * @param[in] s - The string to convert in the form of
79 * "xyz.openbmc_project.Led.Physical.<value name>"
80 * @return - The enum value.
81 */
82 static Palette convertPaletteFromString(std::string& s);
83
84 private:
85
86 /** @brief sd-bus callback for get-property 'State' */
87 static int _callback_get_State(
88 sd_bus*, const char*, const char*, const char*,
89 sd_bus_message*, void*, sd_bus_error*);
90 /** @brief sd-bus callback for set-property 'State' */
91 static int _callback_set_State(
92 sd_bus*, const char*, const char*, const char*,
93 sd_bus_message*, void*, sd_bus_error*);
94
95 /** @brief sd-bus callback for get-property 'DutyOn' */
96 static int _callback_get_DutyOn(
97 sd_bus*, const char*, const char*, const char*,
98 sd_bus_message*, void*, sd_bus_error*);
99 /** @brief sd-bus callback for set-property 'DutyOn' */
100 static int _callback_set_DutyOn(
101 sd_bus*, const char*, const char*, const char*,
102 sd_bus_message*, void*, sd_bus_error*);
103
104 /** @brief sd-bus callback for get-property 'Color' */
105 static int _callback_get_Color(
106 sd_bus*, const char*, const char*, const char*,
107 sd_bus_message*, void*, sd_bus_error*);
108 /** @brief sd-bus callback for set-property 'Color' */
109 static int _callback_set_Color(
110 sd_bus*, const char*, const char*, const char*,
111 sd_bus_message*, void*, sd_bus_error*);
112
113
114 static constexpr auto _interface = "xyz.openbmc_project.Led.Physical";
115 static const vtable::vtable_t _vtable[];
116 sdbusplus::server::interface::interface
117 _xyz_openbmc_project_Led_Physical_interface;
118
119 Action _state = Action::Off;
120 uint8_t _dutyOn = 50;
121 Palette _color = Palette::Unknown;
122
123};
124
125/* Specialization of sdbusplus::server::bindings::details::convertForMessage
126 * for enum-type Physical::Action.
127 *
128 * This converts from the enum to a constant c-string representing the enum.
129 *
130 * @param[in] e - Enum value to convert.
131 * @return C-string representing the name for the enum value.
132 */
133std::string convertForMessage(Physical::Action e);
134/* Specialization of sdbusplus::server::bindings::details::convertForMessage
135 * for enum-type Physical::Palette.
136 *
137 * This converts from the enum to a constant c-string representing the enum.
138 *
139 * @param[in] e - Enum value to convert.
140 * @return C-string representing the name for the enum value.
141 */
142std::string convertForMessage(Physical::Palette e);
143
144} // namespace server
145} // namespace Led
146} // namespace openbmc_project
147} // namespace xyz
148} // namespace sdbusplus
149