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] serializePtr  - Serialize object
42      * @param[in] callBack      - Custom callback when LED group is asserted
43      */
Group(sdbusplus::bus_t & bus,const std::string & objPath,Manager & manager,std::shared_ptr<Serialize> serializePtr,std::function<bool (Group *,bool)> callBack=nullptr)44     Group(sdbusplus::bus_t& bus, const std::string& objPath, Manager& manager,
45           std::shared_ptr<Serialize> serializePtr,
46           std::function<bool(Group*, bool)> callBack = nullptr) :
47 
48         GroupInherit(bus, objPath.c_str(), GroupInherit::action::defer_emit),
49         path(objPath), manager(manager), serializePtr(serializePtr),
50         customCallBack(callBack)
51     {
52         // Initialize Asserted property value
53         if (serializePtr && serializePtr->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     std::shared_ptr<Serialize> serializePtr;
78 
79     /** @brief Custom callback when LED group is asserted
80      * Callback that holds LED group method which handles lamp test request.
81      *
82      * @param[in] Group object - Pointer to Group object
83      * @param[in] bool - Input value (true/false)
84      *
85      * @return bool which tells if execution succeeds(true) or fails(false).
86      */
87     std::function<bool(Group*, bool)> customCallBack;
88 };
89 
90 } // namespace led
91 } // namespace phosphor
92