psu-sensor: Add devmgmt and powercallback to PSU
Some PSU sensors are dependent on system power state.
Without change the device initialization would fail and
dbus-sensors and entity-manager wouldn't come back to
properly instantiate.
Same intention as this hwmontempsensor change: https://github.com/openbmc/dbus-sensors/commit/a1456c4abafc697e7caa6b8e95ac9ddb35c4e7d1
Tested: Same sensors are getting created. Sensors are
getting created/destroyed on host power events based
on their PowerState.
Signed-off-by: Matt Simmering <matthew.simmering@intel.com>
Change-Id: I3ee719cf65df225f964148d3994eec4d758d72a1
diff --git a/src/PSUSensor.hpp b/src/PSUSensor.hpp
index 49e181e..69f365b 100644
--- a/src/PSUSensor.hpp
+++ b/src/PSUSensor.hpp
@@ -1,5 +1,6 @@
#pragma once
+#include "DeviceMgmt.hpp"
#include "PwmSensor.hpp"
#include "Thresholds.hpp"
#include "sensor.hpp"
@@ -23,15 +24,26 @@
const std::string& sensorConfiguration,
const PowerState& powerState, const std::string& sensorUnits,
unsigned int factor, double max, double min, double offset,
- const std::string& label, size_t tSize, double pollRate);
+ const std::string& label, size_t tSize, double pollRate,
+ const std::shared_ptr<I2CDevice>& i2cDevice);
~PSUSensor() override;
void setupRead(void);
+ void activate(const std::string& newPath,
+ const std::shared_ptr<I2CDevice>& newI2CDevice);
+ void deactivate(void);
+ bool isActive(void);
+
+ std::shared_ptr<I2CDevice> getI2CDevice() const
+ {
+ return i2cDevice;
+ }
private:
// Note, this buffer is a shared_ptr because during a read, its lifetime
// might have to outlive the PSUSensor class if the object gets destroyed
// while in the middle of a read operation
std::shared_ptr<std::array<char, 128>> buffer;
+ std::shared_ptr<I2CDevice> i2cDevice;
sdbusplus::asio::object_server& objServer;
boost::asio::random_access_file inputDev;
boost::asio::steady_timer waitTimer;