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 using GroupInherit = sdbusplus::server::object_t<
18     sdbusplus::xyz::openbmc_project::Led::server::Group>;
19 
20 /** @class Group
21  *  @brief Manages group of LEDs and applies action on the elements of group
22  */
23 class Group : public GroupInherit
24 {
25   public:
26     Group() = delete;
27     ~Group() override = default;
28     Group(const Group&) = delete;
29     Group& operator=(const Group&) = delete;
30     Group(Group&&) = delete;
31     Group& operator=(Group&&) = delete;
32 
33     /** @brief Constructs LED Group
34      *
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
40      */
Group(sdbusplus::bus_t & bus,const std::string & objPath,Manager & manager,std::shared_ptr<Serialize> serializePtr,std::function<bool (Group *,bool)> callBack=nullptr)41     Group(sdbusplus::bus_t& bus, const std::string& objPath, Manager& manager,
42           std::shared_ptr<Serialize> serializePtr,
43           std::function<bool(Group*, bool)> callBack = nullptr) :
44 
45         GroupInherit(bus, objPath.c_str(), GroupInherit::action::defer_emit),
46         path(objPath), manager(manager), serializePtr(serializePtr),
47         customCallBack(callBack)
48     {
49         // Initialize Asserted property value
50         if (serializePtr && serializePtr->getGroupSavedState(objPath))
51         {
52             asserted(true);
53         }
54 
55         // Emit deferred signal.
56         emit_object_added();
57     }
58 
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;
65 
66   private:
67     /** @brief Path of the group instance */
68     std::string path;
69 
70     /** @brief Reference to Manager object */
71     Manager& manager;
72 
73     /** @brief The serialize class for storing and restoring groups of LEDs */
74     std::shared_ptr<Serialize> serializePtr;
75 
76     /** @brief Custom callback when LED group is asserted
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).
83      */
84     std::function<bool(Group*, bool)> customCallBack;
85 };
86 
87 } // namespace led
88 } // namespace phosphor
89