1 #pragma once
2 
3 #include "manager.hpp"
4 #include "serialize.hpp"
5 
6 #include <sdbusplus/bus.hpp>
7 #include <sdbusplus/server/object.hpp>
8 #include <xyz/openbmc_project/Led/Group/server.hpp>
9 
10 #include <string>
11 
12 namespace phosphor
13 {
14 namespace led
15 {
16 
17 namespace
18 {
19 using GroupInherit = sdbusplus::server::object_t<
20     sdbusplus::xyz::openbmc_project::Led::server::Group>;
21 }
22 
23 /** @class Group
24  *  @brief Manages group of LEDs and applies action on the elements of group
25  */
26 class Group : public GroupInherit
27 {
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;
35 
36     /** @brief Constructs LED Group
37      *
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] serialize - Serialize object
42      * @param[in] callBack  - Custom callback when LED group is asserted
43      */
44     Group(sdbusplus::bus_t& bus, const std::string& objPath, Manager& manager,
45           Serialize& serialize,
46           std::function<void(Group*, bool)> callBack = nullptr) :
47 
48         GroupInherit(bus, objPath.c_str(), GroupInherit::action::defer_emit),
49         path(objPath), manager(manager), serialize(serialize),
50         customCallBack(callBack)
51     {
52         // Initialize Asserted property value
53         if (serialize.getGroupSavedState(objPath))
54         {
55             asserted(true);
56         }
57 
58         // Emit deferred signal.
59         emit_object_added();
60     }
61 
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;
68 
69   private:
70     /** @brief Path of the group instance */
71     std::string path;
72 
73     /** @brief Reference to Manager object */
74     Manager& manager;
75 
76     /** @brief The serialize class for storing and restoring groups of LEDs */
77     Serialize& serialize;
78 
79     /** @brief Custom callback when LED group is asserted
80      */
81     std::function<void(Group*, bool)> customCallBack;
82 };
83 
84 } // namespace led
85 } // namespace phosphor
86