blob: e5c1e764a3b71edf6abfc46f01e52feb081dba51 [file] [log] [blame]
Brandon Wymana0f33ce2019-10-17 18:32:29 -05001#pragma once
2
Brandon Wymanaed1f752019-11-25 18:10:52 -06003#include "types.hpp"
4
5#include <sdbusplus/bus/match.hpp>
6
Brandon Wymana0f33ce2019-10-17 18:32:29 -05007namespace phosphor::power::psu
8{
9/**
10 * @class PowerSupply
11 * Represents a PMBus power supply device.
12 */
13class PowerSupply
14{
15 public:
Brandon Wymanaed1f752019-11-25 18:10:52 -060016 PowerSupply() = delete;
Brandon Wymana0f33ce2019-10-17 18:32:29 -050017 PowerSupply(const PowerSupply&) = delete;
18 PowerSupply(PowerSupply&&) = delete;
19 PowerSupply& operator=(const PowerSupply&) = delete;
20 PowerSupply& operator=(PowerSupply&&) = delete;
21 ~PowerSupply() = default;
22
23 /**
Brandon Wymanaed1f752019-11-25 18:10:52 -060024 * @param[in] invpath - string for inventory path to use
25 */
26 PowerSupply(sdbusplus::bus::bus& bus, const std::string& invpath) :
27 bus(bus), inventoryPath(invpath)
28 {
29 // Setup the functions to call when the D-Bus inventory path for the
30 // Present property changes.
31 presentMatch = std::make_unique<sdbusplus::bus::match_t>(
32 bus,
33 sdbusplus::bus::match::rules::propertiesChanged(inventoryPath,
34 INVENTORY_IFACE),
35 [this](auto& msg) { this->inventoryChanged(msg); });
36 presentAddedMatch = std::make_unique<sdbusplus::bus::match_t>(
37 bus,
38 sdbusplus::bus::match::rules::interfacesAdded() +
39 sdbusplus::bus::match::rules::path_namespace(inventoryPath),
40 [this](auto& msg) { this->inventoryChanged(msg); });
41 // Get the current state of the Present property.
42 updatePresence();
43 }
44
45 /**
Brandon Wymana0f33ce2019-10-17 18:32:29 -050046 * Power supply specific function to analyze for faults/errors.
47 *
48 * Various PMBus status bits will be checked for fault conditions.
49 * If a certain fault bits are on, the appropriate error will be
50 * committed.
51 */
52 void analyze()
53 {
54 }
55
56 /**
57 * Write PMBus CLEAR_FAULTS
58 *
59 * This function will be called in various situations in order to clear
60 * any fault status bits that may have been set, in order to start over
61 * with a clean state. Presence changes and power state changes will
62 * want to clear any faults logged.
63 */
64 void clearFaults()
65 {
66 }
67
68 /**
69 * @brief Adds properties to the inventory.
70 *
71 * Reads the values from the device and writes them to the
72 * associated power supply D-Bus inventory object.
73 *
74 * This needs to be done on startup, and each time the presence
75 * state changes.
76 *
77 * Properties added:
78 * - Serial Number
79 * - Part Number
80 * - CCIN (Customer Card Identification Number) - added as the Model
81 * - Firmware version
82 */
83 void updateInventory()
84 {
85 }
86
Brandon Wymanaed1f752019-11-25 18:10:52 -060087 /**
88 * @brief Accessor function to indicate present status
89 */
90 bool isPresent() const
91 {
92 return present;
93 }
94
Brandon Wymana0f33ce2019-10-17 18:32:29 -050095 private:
Brandon Wymanaed1f752019-11-25 18:10:52 -060096 /** @brief systemd bus member */
97 sdbusplus::bus::bus& bus;
98
Brandon Wymana0f33ce2019-10-17 18:32:29 -050099 /** @brief True if a fault has already been found and not cleared */
100 bool faultFound = false;
Brandon Wymanaed1f752019-11-25 18:10:52 -0600101
102 /**
103 * @brief D-Bus path to use for this power supply's inventory status.
104 **/
105 std::string inventoryPath;
106
107 /** @brief True if the power supply is present. */
108 bool present = false;
109
110 /** @brief D-Bus match variable used to subscribe to Present property
111 * changes.
112 **/
113 std::unique_ptr<sdbusplus::bus::match_t> presentMatch;
114
115 /** @brief D-Bus match variable used to subscribe for Present property
116 * interface added.
117 */
118 std::unique_ptr<sdbusplus::bus::match_t> presentAddedMatch;
119
120 /**
121 * @brief Updates the presence status by querying D-Bus
122 *
123 * The D-Bus inventory properties for this power supply will be read to
124 * determine if the power supply is present or not and update this
125 * object's present member variable to reflect current status.
126 **/
127 void updatePresence();
128
129 /**
130 * @brief Callback for inventory property changes
131 *
132 * Process change of Present property for power supply.
133 *
134 * @param[in] msg - Data associated with Present change signal
135 **/
136 void inventoryChanged(sdbusplus::message::message& msg);
Brandon Wymana0f33ce2019-10-17 18:32:29 -0500137};
138
139} // namespace phosphor::power::psu