blob: 2febfbb6af895397a0099225cf4732ea91891402 [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 Liu54671852023-10-30 09:09:39 +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
41 * @param[in] serializePtr - Serialize object
42 * @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,
George Liu54671852023-10-30 09:09:39 +080045 std::shared_ptr<Serialize> serializePtr,
PriyangaRamasamy180090c2022-10-10 10:50:52 +053046 std::function<bool(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 Liu54671852023-10-30 09:09:39 +080049 path(objPath), manager(manager), serializePtr(serializePtr),
George Liuc777bef2020-11-23 17:04:21 +080050 customCallBack(callBack)
Patrick Venture91ac8d32018-11-01 17:03:22 -070051 {
George Liu2098aa62020-05-09 11:26:35 +080052 // Initialize Asserted property value
George Liu54671852023-10-30 09:09:39 +080053 if (serializePtr && serializePtr->getGroupSavedState(objPath))
George Liu2098aa62020-05-09 11:26:35 +080054 {
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 */
George Liu54671852023-10-30 09:09:39 +080077 std::shared_ptr<Serialize> serializePtr;
George Liuc777bef2020-11-23 17:04:21 +080078
79 /** @brief Custom callback when LED group is asserted
PriyangaRamasamy180090c2022-10-10 10:50:52 +053080 * Callback that holds LED group method which handles lamp test request.
81 *
82 * @param[in] Group object - Pointer to Group object
83 * @param[in] bool - Input value (true/false)
84 *
85 * @return bool which tells if execution succeeds(true) or fails(false).
George Liuc777bef2020-11-23 17:04:21 +080086 */
PriyangaRamasamy180090c2022-10-10 10:50:52 +053087 std::function<bool(Group*, bool)> customCallBack;
Vishwanatha Subbanna4c8c72b2016-11-29 23:02:06 +053088};
89
90} // namespace led
91} // namespace phosphor