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 | using GroupInherit = sdbusplus::server::object_t< |
| 18 | sdbusplus::xyz::openbmc_project::Led::server::Group>; |
Patrick Williams | 6d08cce | 2022-04-01 19:05:07 -0500 | [diff] [blame] | 19 | |
Vishwanatha Subbanna | 4c8c72b | 2016-11-29 23:02:06 +0530 | [diff] [blame] | 20 | /** @class Group |
| 21 | * @brief Manages group of LEDs and applies action on the elements of group |
| 22 | */ |
Patrick Williams | 6d08cce | 2022-04-01 19:05:07 -0500 | [diff] [blame] | 23 | class Group : public GroupInherit |
Vishwanatha Subbanna | 4c8c72b | 2016-11-29 23:02:06 +0530 | [diff] [blame] | 24 | { |
Patrick Venture | 91ac8d3 | 2018-11-01 17:03:22 -0700 | [diff] [blame] | 25 | public: |
| 26 | Group() = delete; |
| 27 | ~Group() = default; |
| 28 | Group(const Group&) = delete; |
| 29 | Group& operator=(const Group&) = delete; |
George Liu | 8f538d9 | 2024-08-22 15:41:22 +0800 | [diff] [blame] | 30 | Group(Group&&) = delete; |
| 31 | Group& operator=(Group&&) = delete; |
Vishwanatha Subbanna | 4c8c72b | 2016-11-29 23:02:06 +0530 | [diff] [blame] | 32 | |
Patrick Venture | 91ac8d3 | 2018-11-01 17:03:22 -0700 | [diff] [blame] | 33 | /** @brief Constructs LED Group |
| 34 | * |
George Liu | 5467185 | 2023-10-30 09:09:39 +0800 | [diff] [blame] | 35 | * @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 Venture | 91ac8d3 | 2018-11-01 17:03:22 -0700 | [diff] [blame] | 40 | */ |
Patrick Williams | 3e073ba | 2022-07-22 19:26:52 -0500 | [diff] [blame] | 41 | Group(sdbusplus::bus_t& bus, const std::string& objPath, Manager& manager, |
George Liu | 5467185 | 2023-10-30 09:09:39 +0800 | [diff] [blame] | 42 | std::shared_ptr<Serialize> serializePtr, |
PriyangaRamasamy | 180090c | 2022-10-10 10:50:52 +0530 | [diff] [blame] | 43 | std::function<bool(Group*, bool)> callBack = nullptr) : |
Vishwanatha Subbanna | 4c8c72b | 2016-11-29 23:02:06 +0530 | [diff] [blame] | 44 | |
Patrick Williams | 6d08cce | 2022-04-01 19:05:07 -0500 | [diff] [blame] | 45 | GroupInherit(bus, objPath.c_str(), GroupInherit::action::defer_emit), |
George Liu | 5467185 | 2023-10-30 09:09:39 +0800 | [diff] [blame] | 46 | path(objPath), manager(manager), serializePtr(serializePtr), |
George Liu | c777bef | 2020-11-23 17:04:21 +0800 | [diff] [blame] | 47 | customCallBack(callBack) |
Patrick Venture | 91ac8d3 | 2018-11-01 17:03:22 -0700 | [diff] [blame] | 48 | { |
George Liu | 2098aa6 | 2020-05-09 11:26:35 +0800 | [diff] [blame] | 49 | // Initialize Asserted property value |
George Liu | 5467185 | 2023-10-30 09:09:39 +0800 | [diff] [blame] | 50 | if (serializePtr && serializePtr->getGroupSavedState(objPath)) |
George Liu | 2098aa6 | 2020-05-09 11:26:35 +0800 | [diff] [blame] | 51 | { |
| 52 | asserted(true); |
| 53 | } |
| 54 | |
| 55 | // Emit deferred signal. |
| 56 | emit_object_added(); |
Patrick Venture | 91ac8d3 | 2018-11-01 17:03:22 -0700 | [diff] [blame] | 57 | } |
Vishwanatha Subbanna | 4c8c72b | 2016-11-29 23:02:06 +0530 | [diff] [blame] | 58 | |
Patrick Venture | 91ac8d3 | 2018-11-01 17:03:22 -0700 | [diff] [blame] | 59 | /** @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 Subbanna | 4c8c72b | 2016-11-29 23:02:06 +0530 | [diff] [blame] | 65 | |
Patrick Venture | 91ac8d3 | 2018-11-01 17:03:22 -0700 | [diff] [blame] | 66 | private: |
| 67 | /** @brief Path of the group instance */ |
| 68 | std::string path; |
Vishwanatha Subbanna | 4c8c72b | 2016-11-29 23:02:06 +0530 | [diff] [blame] | 69 | |
Patrick Venture | 91ac8d3 | 2018-11-01 17:03:22 -0700 | [diff] [blame] | 70 | /** @brief Reference to Manager object */ |
| 71 | Manager& manager; |
George Liu | 2098aa6 | 2020-05-09 11:26:35 +0800 | [diff] [blame] | 72 | |
| 73 | /** @brief The serialize class for storing and restoring groups of LEDs */ |
George Liu | 5467185 | 2023-10-30 09:09:39 +0800 | [diff] [blame] | 74 | std::shared_ptr<Serialize> serializePtr; |
George Liu | c777bef | 2020-11-23 17:04:21 +0800 | [diff] [blame] | 75 | |
| 76 | /** @brief Custom callback when LED group is asserted |
PriyangaRamasamy | 180090c | 2022-10-10 10:50:52 +0530 | [diff] [blame] | 77 | * 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 Liu | c777bef | 2020-11-23 17:04:21 +0800 | [diff] [blame] | 83 | */ |
PriyangaRamasamy | 180090c | 2022-10-10 10:50:52 +0530 | [diff] [blame] | 84 | std::function<bool(Group*, bool)> customCallBack; |
Vishwanatha Subbanna | 4c8c72b | 2016-11-29 23:02:06 +0530 | [diff] [blame] | 85 | }; |
| 86 | |
| 87 | } // namespace led |
| 88 | } // namespace phosphor |