Add I2C interface to Device class
Add an I2C interface to the phosphor-regulators C++ Device class.
Use the I2CInterface class from the tools/i2c directory of this
repository.
Also add the other required properties of the JSON "device" object to
the C++ Device class.
The JSON "device" object is in the phosphor-regulators config file. For
more information, see phosphor-regulators/docs/config_file/device.md.
Signed-off-by: Shawn McCarney <shawnmm@us.ibm.com>
Change-Id: Idc780b1a11372d6597762cfb6540fa44f1cfb64e
diff --git a/phosphor-regulators/src/device.hpp b/phosphor-regulators/src/device.hpp
index ba4c067..b4c2af6 100644
--- a/phosphor-regulators/src/device.hpp
+++ b/phosphor-regulators/src/device.hpp
@@ -15,7 +15,11 @@
*/
#pragma once
+#include "i2c_interface.hpp"
+
+#include <memory>
#include <string>
+#include <utility>
namespace phosphor::power::regulators
{
@@ -40,8 +44,16 @@
* Constructor.
*
* @param id unique device ID
+ * @param isRegulator indicates whether this device is a voltage regulator
+ * @param fru Field-Replaceable Unit (FRU) for this device
+ * @param i2cInterface I2C interface to this device
*/
- explicit Device(const std::string& id) : id{id}
+ explicit Device(const std::string& id, bool isRegulator,
+ const std::string& fru,
+ std::unique_ptr<i2c::I2CInterface> i2cInterface) :
+ id{id},
+ isRegulatorDevice{isRegulator}, fru{fru}, i2cInterface{
+ std::move(i2cInterface)}
{
}
@@ -55,11 +67,62 @@
return id;
}
+ /**
+ * Returns whether this device is a voltage regulator.
+ *
+ * @return true if device is a voltage regulator, false otherwise
+ */
+ bool isRegulator() const
+ {
+ return isRegulatorDevice;
+ }
+
+ /**
+ * Returns the Field-Replaceable Unit (FRU) for this device.
+ *
+ * Returns the D-Bus inventory path of the FRU. If the device itself is not
+ * a FRU, returns the FRU that contains the device.
+ *
+ * @return FRU for this device
+ */
+ const std::string& getFRU() const
+ {
+ return fru;
+ }
+
+ /**
+ * Gets the I2C interface to this device.
+ *
+ * @return I2C interface to device
+ */
+ i2c::I2CInterface& getI2CInterface()
+ {
+ return *i2cInterface;
+ }
+
private:
/**
* Unique ID of this device.
*/
const std::string id{};
+
+ /**
+ * Indicates whether this device is a voltage regulator.
+ */
+ const bool isRegulatorDevice{false};
+
+ /**
+ * Field-Replaceable Unit (FRU) for this device.
+ *
+ * Set to the D-Bus inventory path of the FRU. If the device itself is not
+ * a FRU, set to the FRU that contains the device.
+ */
+ const std::string fru{};
+
+ /**
+ * I2C interface to this device.
+ */
+ std::unique_ptr<i2c::I2CInterface> i2cInterface{};
};
} // namespace phosphor::power::regulators
diff --git a/phosphor-regulators/src/meson.build b/phosphor-regulators/src/meson.build
index 4337095..121bf45 100644
--- a/phosphor-regulators/src/meson.build
+++ b/phosphor-regulators/src/meson.build
@@ -13,7 +13,10 @@
'phosphor-regulators',
phosphor_regulators_library_source_files,
implicit_include_directories: false,
- include_directories: phosphor_regulators_include_directories
+ include_directories: [
+ phosphor_regulators_include_directories,
+ libi2c_inc
+ ]
)
phosphor_regulators = executable(