blob: aec0e85cb18fdcbb57265fa59e970c28c55ecfac [file] [log] [blame]
Vishwanatha Subbanna4c8c72b2016-11-29 23:02:06 +05301#pragma once
2
Patrick Venture91ac8d32018-11-01 17:03:22 -07003#include "manager.hpp"
George Liu2098aa62020-05-09 11:26:35 +08004#include "serialize.hpp"
Patrick Venture91ac8d32018-11-01 17:03:22 -07005
Vishwanatha Subbanna4c8c72b2016-11-29 23:02:06 +05306#include <sdbusplus/bus.hpp>
7#include <sdbusplus/server/object.hpp>
Vishwanatha Subbanna55ef5b02017-03-10 13:32:08 +05308#include <xyz/openbmc_project/Led/Group/server.hpp>
Andrew Geisslerd02c3cb2020-05-16 10:28:02 -05009
George Liua6c18f82020-06-22 10:50:04 +080010#include <string>
11
Vishwanatha Subbanna4c8c72b2016-11-29 23:02:06 +053012namespace phosphor
13{
14namespace led
15{
16
Patrick Williams6d08cce2022-04-01 19:05:07 -050017namespace
18{
19using GroupInherit = sdbusplus::server::object_t<
20 sdbusplus::xyz::openbmc_project::Led::server::Group>;
21}
22
Vishwanatha Subbanna4c8c72b2016-11-29 23:02:06 +053023/** @class Group
24 * @brief Manages group of LEDs and applies action on the elements of group
25 */
Patrick Williams6d08cce2022-04-01 19:05:07 -050026class Group : public GroupInherit
Vishwanatha Subbanna4c8c72b2016-11-29 23:02:06 +053027{
Patrick Venture91ac8d32018-11-01 17:03:22 -070028 public:
29 Group() = delete;
30 ~Group() = default;
31 Group(const Group&) = delete;
32 Group& operator=(const Group&) = delete;
33 Group(Group&&) = default;
34 Group& operator=(Group&&) = default;
Vishwanatha Subbanna4c8c72b2016-11-29 23:02:06 +053035
Patrick Venture91ac8d32018-11-01 17:03:22 -070036 /** @brief Constructs LED Group
37 *
George Liuc777bef2020-11-23 17:04:21 +080038 * @param[in] bus - Handle to system dbus
39 * @param[in] objPath - The D-Bus path that hosts LED group
40 * @param[in] manager - Reference to Manager
George Liu2098aa62020-05-09 11:26:35 +080041 * @param[in] serialize - Serialize object
George Liuc777bef2020-11-23 17:04:21 +080042 * @param[in] callBack - Custom callback when LED group is asserted
Patrick Venture91ac8d32018-11-01 17:03:22 -070043 */
Patrick Williams3e073ba2022-07-22 19:26:52 -050044 Group(sdbusplus::bus_t& bus, const std::string& objPath, Manager& manager,
45 Serialize& serialize,
George Liu87fd11c2020-11-23 16:40:14 +080046 std::function<void(Group*, bool)> callBack = nullptr) :
Vishwanatha Subbanna4c8c72b2016-11-29 23:02:06 +053047
Patrick Williams6d08cce2022-04-01 19:05:07 -050048 GroupInherit(bus, objPath.c_str(), GroupInherit::action::defer_emit),
George Liuc777bef2020-11-23 17:04:21 +080049 path(objPath), manager(manager), serialize(serialize),
50 customCallBack(callBack)
Patrick Venture91ac8d32018-11-01 17:03:22 -070051 {
George Liu2098aa62020-05-09 11:26:35 +080052 // Initialize Asserted property value
53 if (serialize.getGroupSavedState(objPath))
54 {
55 asserted(true);
56 }
57
58 // Emit deferred signal.
59 emit_object_added();
Patrick Venture91ac8d32018-11-01 17:03:22 -070060 }
Vishwanatha Subbanna4c8c72b2016-11-29 23:02:06 +053061
Patrick Venture91ac8d32018-11-01 17:03:22 -070062 /** @brief Property SET Override function
63 *
64 * @param[in] value - True or False
65 * @return - Success or exception thrown
66 */
67 bool asserted(bool value) override;
Vishwanatha Subbanna4c8c72b2016-11-29 23:02:06 +053068
Patrick Venture91ac8d32018-11-01 17:03:22 -070069 private:
70 /** @brief Path of the group instance */
71 std::string path;
Vishwanatha Subbanna4c8c72b2016-11-29 23:02:06 +053072
Patrick Venture91ac8d32018-11-01 17:03:22 -070073 /** @brief Reference to Manager object */
74 Manager& manager;
George Liu2098aa62020-05-09 11:26:35 +080075
76 /** @brief The serialize class for storing and restoring groups of LEDs */
77 Serialize& serialize;
George Liuc777bef2020-11-23 17:04:21 +080078
79 /** @brief Custom callback when LED group is asserted
80 */
George Liu87fd11c2020-11-23 16:40:14 +080081 std::function<void(Group*, bool)> customCallBack;
Vishwanatha Subbanna4c8c72b2016-11-29 23:02:06 +053082};
83
84} // namespace led
85} // namespace phosphor