blob: 2c334456382d17be66852734463b21cbdb4dc0fd [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 -050017using GroupInherit = sdbusplus::server::object_t<
18 sdbusplus::xyz::openbmc_project::Led::server::Group>;
Patrick Williams6d08cce2022-04-01 19:05:07 -050019
Vishwanatha Subbanna4c8c72b2016-11-29 23:02:06 +053020/** @class Group
21 * @brief Manages group of LEDs and applies action on the elements of group
22 */
Patrick Williams6d08cce2022-04-01 19:05:07 -050023class Group : public GroupInherit
Vishwanatha Subbanna4c8c72b2016-11-29 23:02:06 +053024{
Patrick Venture91ac8d32018-11-01 17:03:22 -070025 public:
26 Group() = delete;
George Liuc8ddde62024-08-22 17:29:16 +080027 ~Group() override = default;
Patrick Venture91ac8d32018-11-01 17:03:22 -070028 Group(const Group&) = delete;
29 Group& operator=(const Group&) = delete;
George Liu8f538d92024-08-22 15:41:22 +080030 Group(Group&&) = delete;
31 Group& operator=(Group&&) = delete;
Vishwanatha Subbanna4c8c72b2016-11-29 23:02:06 +053032
Patrick Venture91ac8d32018-11-01 17:03:22 -070033 /** @brief Constructs LED Group
34 *
George Liu54671852023-10-30 09:09:39 +080035 * @param[in] bus - Handle to system dbus
36 * @param[in] objPath - The D-Bus path that hosts LED group
37 * @param[in] manager - Reference to Manager
38 * @param[in] serializePtr - Serialize object
39 * @param[in] callBack - Custom callback when LED group is asserted
Patrick Venture91ac8d32018-11-01 17:03:22 -070040 */
Patrick Williams3e073ba2022-07-22 19:26:52 -050041 Group(sdbusplus::bus_t& bus, const std::string& objPath, Manager& manager,
George Liu54671852023-10-30 09:09:39 +080042 std::shared_ptr<Serialize> serializePtr,
PriyangaRamasamy180090c2022-10-10 10:50:52 +053043 std::function<bool(Group*, bool)> callBack = nullptr) :
Vishwanatha Subbanna4c8c72b2016-11-29 23:02:06 +053044
Patrick Williams6d08cce2022-04-01 19:05:07 -050045 GroupInherit(bus, objPath.c_str(), GroupInherit::action::defer_emit),
George Liu54671852023-10-30 09:09:39 +080046 path(objPath), manager(manager), serializePtr(serializePtr),
George Liuc777bef2020-11-23 17:04:21 +080047 customCallBack(callBack)
Patrick Venture91ac8d32018-11-01 17:03:22 -070048 {
George Liu2098aa62020-05-09 11:26:35 +080049 // Initialize Asserted property value
George Liu54671852023-10-30 09:09:39 +080050 if (serializePtr && serializePtr->getGroupSavedState(objPath))
George Liu2098aa62020-05-09 11:26:35 +080051 {
52 asserted(true);
53 }
54
55 // Emit deferred signal.
56 emit_object_added();
Patrick Venture91ac8d32018-11-01 17:03:22 -070057 }
Vishwanatha Subbanna4c8c72b2016-11-29 23:02:06 +053058
Patrick Venture91ac8d32018-11-01 17:03:22 -070059 /** @brief Property SET Override function
60 *
61 * @param[in] value - True or False
62 * @return - Success or exception thrown
63 */
64 bool asserted(bool value) override;
Vishwanatha Subbanna4c8c72b2016-11-29 23:02:06 +053065
Patrick Venture91ac8d32018-11-01 17:03:22 -070066 private:
67 /** @brief Path of the group instance */
68 std::string path;
Vishwanatha Subbanna4c8c72b2016-11-29 23:02:06 +053069
Patrick Venture91ac8d32018-11-01 17:03:22 -070070 /** @brief Reference to Manager object */
71 Manager& manager;
George Liu2098aa62020-05-09 11:26:35 +080072
73 /** @brief The serialize class for storing and restoring groups of LEDs */
George Liu54671852023-10-30 09:09:39 +080074 std::shared_ptr<Serialize> serializePtr;
George Liuc777bef2020-11-23 17:04:21 +080075
76 /** @brief Custom callback when LED group is asserted
PriyangaRamasamy180090c2022-10-10 10:50:52 +053077 * Callback that holds LED group method which handles lamp test request.
78 *
79 * @param[in] Group object - Pointer to Group object
80 * @param[in] bool - Input value (true/false)
81 *
82 * @return bool which tells if execution succeeds(true) or fails(false).
George Liuc777bef2020-11-23 17:04:21 +080083 */
PriyangaRamasamy180090c2022-10-10 10:50:52 +053084 std::function<bool(Group*, bool)> customCallBack;
Vishwanatha Subbanna4c8c72b2016-11-29 23:02:06 +053085};
86
87} // namespace led
88} // namespace phosphor