blob: a6be9f540287120887bc746b08fccb620c720593 [file] [log] [blame]
Brandon Wymanaed1f752019-11-25 18:10:52 -06001#include "power_supply.hpp"
2
3#include "types.hpp"
4#include "utility.hpp"
5
6namespace phosphor
7{
8namespace power
9{
10namespace psu
11{
12
13using namespace phosphor::logging;
14
15void 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
31void 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