Vishwanatha Subbanna | 4c8c72b | 2016-11-29 23:02:06 +0530 | [diff] [blame] | 1 | #pragma once |
| 2 | |
Patrick Venture | 91ac8d3 | 2018-11-01 17:03:22 -0700 | [diff] [blame] | 3 | #include "manager.hpp" |
George Liu | 2098aa6 | 2020-05-09 11:26:35 +0800 | [diff] [blame] | 4 | #include "serialize.hpp" |
Patrick Venture | 91ac8d3 | 2018-11-01 17:03:22 -0700 | [diff] [blame] | 5 | |
Vishwanatha Subbanna | 4c8c72b | 2016-11-29 23:02:06 +0530 | [diff] [blame] | 6 | #include <sdbusplus/bus.hpp> |
| 7 | #include <sdbusplus/server/object.hpp> |
Vishwanatha Subbanna | 55ef5b0 | 2017-03-10 13:32:08 +0530 | [diff] [blame] | 8 | #include <xyz/openbmc_project/Led/Group/server.hpp> |
Andrew Geissler | d02c3cb | 2020-05-16 10:28:02 -0500 | [diff] [blame] | 9 | |
George Liu | a6c18f8 | 2020-06-22 10:50:04 +0800 | [diff] [blame] | 10 | #include <string> |
| 11 | |
Vishwanatha Subbanna | 4c8c72b | 2016-11-29 23:02:06 +0530 | [diff] [blame] | 12 | namespace phosphor |
| 13 | { |
| 14 | namespace led |
| 15 | { |
| 16 | |
Patrick Williams | 6d08cce | 2022-04-01 19:05:07 -0500 | [diff] [blame] | 17 | namespace |
| 18 | { |
| 19 | using GroupInherit = sdbusplus::server::object_t< |
| 20 | sdbusplus::xyz::openbmc_project::Led::server::Group>; |
| 21 | } |
| 22 | |
Vishwanatha Subbanna | 4c8c72b | 2016-11-29 23:02:06 +0530 | [diff] [blame] | 23 | /** @class Group |
| 24 | * @brief Manages group of LEDs and applies action on the elements of group |
| 25 | */ |
Patrick Williams | 6d08cce | 2022-04-01 19:05:07 -0500 | [diff] [blame] | 26 | class Group : public GroupInherit |
Vishwanatha Subbanna | 4c8c72b | 2016-11-29 23:02:06 +0530 | [diff] [blame] | 27 | { |
Patrick Venture | 91ac8d3 | 2018-11-01 17:03:22 -0700 | [diff] [blame] | 28 | 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 Subbanna | 4c8c72b | 2016-11-29 23:02:06 +0530 | [diff] [blame] | 35 | |
Patrick Venture | 91ac8d3 | 2018-11-01 17:03:22 -0700 | [diff] [blame] | 36 | /** @brief Constructs LED Group |
| 37 | * |
George Liu | 5467185 | 2023-10-30 09:09:39 +0800 | [diff] [blame^] | 38 | * @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 Venture | 91ac8d3 | 2018-11-01 17:03:22 -0700 | [diff] [blame] | 43 | */ |
Patrick Williams | 3e073ba | 2022-07-22 19:26:52 -0500 | [diff] [blame] | 44 | Group(sdbusplus::bus_t& bus, const std::string& objPath, Manager& manager, |
George Liu | 5467185 | 2023-10-30 09:09:39 +0800 | [diff] [blame^] | 45 | std::shared_ptr<Serialize> serializePtr, |
George Liu | 87fd11c | 2020-11-23 16:40:14 +0800 | [diff] [blame] | 46 | std::function<void(Group*, bool)> callBack = nullptr) : |
Vishwanatha Subbanna | 4c8c72b | 2016-11-29 23:02:06 +0530 | [diff] [blame] | 47 | |
Patrick Williams | 6d08cce | 2022-04-01 19:05:07 -0500 | [diff] [blame] | 48 | GroupInherit(bus, objPath.c_str(), GroupInherit::action::defer_emit), |
George Liu | 5467185 | 2023-10-30 09:09:39 +0800 | [diff] [blame^] | 49 | path(objPath), manager(manager), serializePtr(serializePtr), |
George Liu | c777bef | 2020-11-23 17:04:21 +0800 | [diff] [blame] | 50 | customCallBack(callBack) |
Patrick Venture | 91ac8d3 | 2018-11-01 17:03:22 -0700 | [diff] [blame] | 51 | { |
George Liu | 2098aa6 | 2020-05-09 11:26:35 +0800 | [diff] [blame] | 52 | // Initialize Asserted property value |
George Liu | 5467185 | 2023-10-30 09:09:39 +0800 | [diff] [blame^] | 53 | if (serializePtr && serializePtr->getGroupSavedState(objPath)) |
George Liu | 2098aa6 | 2020-05-09 11:26:35 +0800 | [diff] [blame] | 54 | { |
| 55 | asserted(true); |
| 56 | } |
| 57 | |
| 58 | // Emit deferred signal. |
| 59 | emit_object_added(); |
Patrick Venture | 91ac8d3 | 2018-11-01 17:03:22 -0700 | [diff] [blame] | 60 | } |
Vishwanatha Subbanna | 4c8c72b | 2016-11-29 23:02:06 +0530 | [diff] [blame] | 61 | |
Patrick Venture | 91ac8d3 | 2018-11-01 17:03:22 -0700 | [diff] [blame] | 62 | /** @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 Subbanna | 4c8c72b | 2016-11-29 23:02:06 +0530 | [diff] [blame] | 68 | |
Patrick Venture | 91ac8d3 | 2018-11-01 17:03:22 -0700 | [diff] [blame] | 69 | private: |
| 70 | /** @brief Path of the group instance */ |
| 71 | std::string path; |
Vishwanatha Subbanna | 4c8c72b | 2016-11-29 23:02:06 +0530 | [diff] [blame] | 72 | |
Patrick Venture | 91ac8d3 | 2018-11-01 17:03:22 -0700 | [diff] [blame] | 73 | /** @brief Reference to Manager object */ |
| 74 | Manager& manager; |
George Liu | 2098aa6 | 2020-05-09 11:26:35 +0800 | [diff] [blame] | 75 | |
| 76 | /** @brief The serialize class for storing and restoring groups of LEDs */ |
George Liu | 5467185 | 2023-10-30 09:09:39 +0800 | [diff] [blame^] | 77 | std::shared_ptr<Serialize> serializePtr; |
George Liu | c777bef | 2020-11-23 17:04:21 +0800 | [diff] [blame] | 78 | |
| 79 | /** @brief Custom callback when LED group is asserted |
| 80 | */ |
George Liu | 87fd11c | 2020-11-23 16:40:14 +0800 | [diff] [blame] | 81 | std::function<void(Group*, bool)> customCallBack; |
Vishwanatha Subbanna | 4c8c72b | 2016-11-29 23:02:06 +0530 | [diff] [blame] | 82 | }; |
| 83 | |
| 84 | } // namespace led |
| 85 | } // namespace phosphor |