blob: 93be9a5a1e394aa8958eff8cbfd2d2192fe79668 [file] [log] [blame]
George Liu2098aa62020-05-09 11:26:35 +08001#include "config.h"
2
Vishwanatha Subbanna4c8c72b2016-11-29 23:02:06 +05303#include "group.hpp"
Patrick Venture91ac8d32018-11-01 17:03:22 -07004
Patrick Williams158b2c12022-03-17 05:57:44 -05005#include "ledlayout.hpp"
6
Patrick Venture91ac8d32018-11-01 17:03:22 -07007#include <sdbusplus/message.hpp>
Vishwanatha Subbanna4c8c72b2016-11-29 23:02:06 +05308namespace phosphor
9{
10namespace led
11{
12
13/** @brief Overloaded Property Setter function */
14bool Group::asserted(bool value)
15{
PriyangaRamasamy180090c2022-10-10 10:50:52 +053016 if (customCallBack != nullptr)
17 {
18 // Custom callback method tells if the lamptest request is handled
19 // successfully or not.
20 if (customCallBack(this, value))
21 {
22 // If the lamp test request is handled successfully, update the
23 // asserted property.
24 return sdbusplus::xyz::openbmc_project::Led::server::Group::
25 asserted(value);
26 }
27
28 // If the lamp test request is not handled successfully, return the
29 // existing asserted value without any change.
30 return sdbusplus::xyz::openbmc_project::Led::server::Group::asserted();
31 }
32
Vishwanatha Subbanna4846e922020-10-09 03:42:57 -050033 // If the value is already what is before, return right away
34 if (value ==
35 sdbusplus::xyz::openbmc_project::Led::server::Group::asserted())
36 {
37 return value;
38 }
39
Vishwanatha Subbannaed490732016-12-20 15:59:29 +053040 // Introducing these to enable gtest.
Patrick Williams158b2c12022-03-17 05:57:44 -050041 ActionSet ledsAssert{};
42 ActionSet ledsDeAssert{};
Vishwanatha Subbannaed490732016-12-20 15:59:29 +053043
44 // Group management is handled by Manager. The populated leds* sets are not
45 // really used by production code. They are there to enable gtest for
46 // validation.
Patrick Venture91ac8d32018-11-01 17:03:22 -070047 auto result = manager.setGroupState(path, value, ledsAssert, ledsDeAssert);
Vishwanatha Subbannaed490732016-12-20 15:59:29 +053048
George Liu2098aa62020-05-09 11:26:35 +080049 // Store asserted state
George Liu54671852023-10-30 09:09:39 +080050 if (serializePtr)
51 {
52 serializePtr->storeGroups(path, result);
53 }
George Liu2098aa62020-05-09 11:26:35 +080054
Vishwanatha Subbannaed490732016-12-20 15:59:29 +053055 // If something does not go right here, then there should be an sdbusplus
56 // exception thrown.
Vishwanatha Subbanna4b000d82017-05-03 18:44:16 +053057 manager.driveLEDs(ledsAssert, ledsDeAssert);
Vishwanatha Subbanna4c8c72b2016-11-29 23:02:06 +053058
59 // Set the base class's asserted to 'true' since the getter
60 // operation is handled there.
Patrick Venture91ac8d32018-11-01 17:03:22 -070061 return sdbusplus::xyz::openbmc_project::Led::server::Group::asserted(
62 result);
Vishwanatha Subbanna4c8c72b2016-11-29 23:02:06 +053063}
64
65} // namespace led
66} // namespace phosphor