blob: 57c33d9a28606d5e94bbc7f023f90687e533611b [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
17/** @class Group
18 * @brief Manages group of LEDs and applies action on the elements of group
19 */
George Liua6c18f82020-06-22 10:50:04 +080020class Group :
21 sdbusplus::server::object::object<
22 sdbusplus::xyz::openbmc_project::Led::server::Group>
Vishwanatha Subbanna4c8c72b2016-11-29 23:02:06 +053023{
Patrick Venture91ac8d32018-11-01 17:03:22 -070024 public:
25 Group() = delete;
26 ~Group() = default;
27 Group(const Group&) = delete;
28 Group& operator=(const Group&) = delete;
29 Group(Group&&) = default;
30 Group& operator=(Group&&) = default;
Vishwanatha Subbanna4c8c72b2016-11-29 23:02:06 +053031
Patrick Venture91ac8d32018-11-01 17:03:22 -070032 /** @brief Constructs LED Group
33 *
George Liuc777bef2020-11-23 17:04:21 +080034 * @param[in] bus - Handle to system dbus
35 * @param[in] objPath - The D-Bus path that hosts LED group
36 * @param[in] manager - Reference to Manager
George Liu2098aa62020-05-09 11:26:35 +080037 * @param[in] serialize - Serialize object
George Liuc777bef2020-11-23 17:04:21 +080038 * @param[in] callBack - Custom callback when LED group is asserted
Patrick Venture91ac8d32018-11-01 17:03:22 -070039 */
40 Group(sdbusplus::bus::bus& bus, const std::string& objPath,
George Liuc777bef2020-11-23 17:04:21 +080041 Manager& manager, Serialize& serialize,
George Liu87fd11c2020-11-23 16:40:14 +080042 std::function<void(Group*, bool)> callBack = nullptr) :
Vishwanatha Subbanna4c8c72b2016-11-29 23:02:06 +053043
Patrick Venture91ac8d32018-11-01 17:03:22 -070044 sdbusplus::server::object::object<
Vishwanatha Subbanna4c8c72b2016-11-29 23:02:06 +053045 sdbusplus::xyz::openbmc_project::Led::server::Group>(
George Liu2098aa62020-05-09 11:26:35 +080046 bus, objPath.c_str(), true),
George Liuc777bef2020-11-23 17:04:21 +080047 path(objPath), manager(manager), serialize(serialize),
48 customCallBack(callBack)
Patrick Venture91ac8d32018-11-01 17:03:22 -070049 {
George Liu2098aa62020-05-09 11:26:35 +080050 // Initialize Asserted property value
51 if (serialize.getGroupSavedState(objPath))
52 {
53 asserted(true);
54 }
55
56 // Emit deferred signal.
57 emit_object_added();
Patrick Venture91ac8d32018-11-01 17:03:22 -070058 }
Vishwanatha Subbanna4c8c72b2016-11-29 23:02:06 +053059
Patrick Venture91ac8d32018-11-01 17:03:22 -070060 /** @brief Property SET Override function
61 *
62 * @param[in] value - True or False
63 * @return - Success or exception thrown
64 */
65 bool asserted(bool value) override;
Vishwanatha Subbanna4c8c72b2016-11-29 23:02:06 +053066
Patrick Venture91ac8d32018-11-01 17:03:22 -070067 private:
68 /** @brief Path of the group instance */
69 std::string path;
Vishwanatha Subbanna4c8c72b2016-11-29 23:02:06 +053070
Patrick Venture91ac8d32018-11-01 17:03:22 -070071 /** @brief Reference to Manager object */
72 Manager& manager;
George Liu2098aa62020-05-09 11:26:35 +080073
74 /** @brief The serialize class for storing and restoring groups of LEDs */
75 Serialize& serialize;
George Liuc777bef2020-11-23 17:04:21 +080076
77 /** @brief Custom callback when LED group is asserted
78 */
George Liu87fd11c2020-11-23 16:40:14 +080079 std::function<void(Group*, bool)> customCallBack;
Vishwanatha Subbanna4c8c72b2016-11-29 23:02:06 +053080};
81
82} // namespace led
83} // namespace phosphor