xref: /openbmc/phosphor-power/phosphor-power-supply/power_supply.cpp (revision 43082e70b20692017c279c4448c8f05066ce3805)
1 #include "power_supply.hpp"
2 
3 #include "types.hpp"
4 #include "utility.hpp"
5 
6 namespace phosphor
7 {
8 namespace power
9 {
10 namespace psu
11 {
12 
13 using namespace phosphor::logging;
14 
15 void PowerSupply::updatePresence()
16 {
17     try
18     {
19         // Use getProperty utility function to get presence status.
20         util::getProperty(INVENTORY_IFACE, PRESENT_PROP, inventoryPath,
21                           INVENTORY_MGR_IFACE, bus, this->present);
22     }
23     catch (const sdbusplus::exception::SdBusError& e)
24     {
25         // Relying on property change or interface added to retry.
26         // Log an informational trace to the journal.
27         log<level::INFO>("D-Bus property access failure exception");
28     }
29 }
30 
31 void PowerSupply::inventoryChanged(sdbusplus::message::message& msg)
32 {
33     std::string msgSensor;
34     std::map<std::string, sdbusplus::message::variant<uint32_t, bool>> msgData;
35     msg.read(msgSensor, msgData);
36 
37     // Check if it was the Present property that changed.
38     auto valPropMap = msgData.find(PRESENT_PROP);
39     if (valPropMap != msgData.end())
40     {
41         if (std::get<bool>(valPropMap->second))
42         {
43             present = true;
44             clearFaults();
45         }
46         else
47         {
48             present = false;
49 
50             // Clear out the now outdated inventory properties
51             updateInventory();
52         }
53     }
54 }
55 
56 } // namespace psu
57 } // namespace power
58 } // namespace phosphor
59