diff options
author | Patrick Venture <venture@google.com> | 2018-12-19 08:13:41 -0800 |
---|---|---|
committer | Patrick Venture <venture@google.com> | 2018-12-19 08:43:56 -0800 |
commit | 2864b0637f6a826dd2919e533100f9c18afda1cd (patch) | |
tree | 60f0b5362cfeb53d8cecc5085637c4ed6416bd8a | |
parent | 5a842c3e3931993bcb184300b289c8a82ecd6322 (diff) | |
download | phosphor-hwmon-2864b0637f6a826dd2919e533100f9c18afda1cd.tar.gz phosphor-hwmon-2864b0637f6a826dd2919e533100f9c18afda1cd.zip |
sensor: to enable testing receive hwmonio interface pointer
The sensor objects all share a reference to the mainloop's ioAccess
object. To enable testing, the sensor object needs to expect the base
pointer to this object.
Change-Id: I1d7f2841528776c8d4f1166e20874ddeb4b8554a
Signed-off-by: Patrick Venture <venture@google.com>
-rw-r--r-- | mainloop.cpp | 3 | ||||
-rw-r--r-- | sensor.cpp | 15 | ||||
-rw-r--r-- | sensor.hpp | 5 |
3 files changed, 13 insertions, 10 deletions
diff --git a/mainloop.cpp b/mainloop.cpp index 29bd378..b6d44b7 100644 --- a/mainloop.cpp +++ b/mainloop.cpp @@ -148,8 +148,9 @@ std::optional<ObjectStateData> return {}; } + /* Note: The sensor objects all share the same ioAccess object. */ auto sensorObj = - std::make_unique<sensor::Sensor>(sensor.first, ioAccess, _devPath); + std::make_unique<sensor::Sensor>(sensor.first, &ioAccess, _devPath); // Get list of return codes for removing sensors on device auto devRmRCs = env::getEnv("REMOVERCS"); @@ -36,7 +36,8 @@ void setScale(T& iface, int64_t value, int64_t) // todo: this can be simplified once we move to the double interface Sensor::Sensor(const SensorSet::key_type& sensor, - const hwmonio::HwmonIO& ioAccess, const std::string& devPath) : + const hwmonio::HwmonIOInterface* ioAccess, + const std::string& devPath) : sensor(sensor), ioAccess(ioAccess), devPath(devPath) { @@ -148,9 +149,9 @@ std::shared_ptr<ValueObject> Sensor::addValue(const RetryIO& retryIO, // Retry for up to a second if device is busy // or has a transient error. - val = ioAccess.read(sensor.first, sensor.second, hwmon::entry::cinput, - std::get<size_t>(retryIO), - std::get<std::chrono::milliseconds>(retryIO)); + val = ioAccess->read(sensor.first, sensor.second, hwmon::entry::cinput, + std::get<size_t>(retryIO), + std::get<std::chrono::milliseconds>(retryIO)); lockGpio(); val = adjustValue(val); @@ -199,14 +200,14 @@ std::shared_ptr<StatusObject> Sensor::addStatus(ObjectInfo& info) std::string entry = hwmon::entry::fault; auto sysfsFullPath = - sysfs::make_sysfs_path(ioAccess.path(), faultName, faultID, entry); + sysfs::make_sysfs_path(ioAccess->path(), faultName, faultID, entry); if (fs::exists(sysfsFullPath)) { bool functional = true; try { - uint32_t fault = ioAccess.read(faultName, faultID, entry, - hwmonio::retries, hwmonio::delay); + uint32_t fault = ioAccess->read(faultName, faultID, entry, + hwmonio::retries, hwmonio::delay); if (fault != 0) { functional = false; @@ -6,6 +6,7 @@ #include <chrono> #include <gpioplus/handle.hpp> +#include <memory> #include <unordered_set> namespace sensor @@ -42,7 +43,7 @@ class Sensor * @param[in] devPath - Device sysfs path */ explicit Sensor(const SensorSet::key_type& sensor, - const hwmonio::HwmonIO& ioAccess, + const hwmonio::HwmonIOInterface* ioAccess, const std::string& devPath); /** @@ -128,7 +129,7 @@ class Sensor SensorSet::key_type sensor; /** @brief Hwmon sysfs access. */ - const hwmonio::HwmonIO& ioAccess; + const hwmonio::HwmonIOInterface* ioAccess; /** @brief Physical device sysfs path. */ const std::string& devPath; |