Refine BridgeGpio object creation logic
This commit refines BridgeGpio object creation logic by using explicit
std::move to prevent object copy. Also, for cases of rescanning of
ADCSensors, it adjusts timing of destroying for the previous ADCSensor
to avoid double request of a gpio line.
Tested: adcsensor service was started without making a below error
even in case of a recreation sensors caused by rescanning:
Error requesting gpio: P3VBAT_BRIDGE_EN
terminate called after throwing an instance of 'std::system_error'
what(): error setting GPIO line values: Operation not permitted
Change-Id: I26ca059f8fe6eea2c60605f19ec49a3e365dc66f
Signed-off-by: Jae Hyun Yoo <jae.hyun.yoo@linux.intel.com>
diff --git a/src/ADCSensor.cpp b/src/ADCSensor.cpp
index ab1481b..ec3efdb 100644
--- a/src/ADCSensor.cpp
+++ b/src/ADCSensor.cpp
@@ -45,13 +45,14 @@
std::vector<thresholds::Threshold>&& _thresholds,
const double scaleFactor, PowerState readState,
const std::string& sensorConfiguration,
- std::optional<BridgeGpio> bridgeGpio) :
+ std::optional<BridgeGpio>&& bridgeGpio) :
Sensor(boost::replace_all_copy(sensorName, " ", "_"),
std::move(_thresholds), sensorConfiguration,
"xyz.openbmc_project.Configuration.ADC", maxReading, minReading),
objServer(objectServer), scaleFactor(scaleFactor), path(path),
readState(std::move(readState)), inputDev(io, open(path.c_str(), O_RDONLY)),
- waitTimer(io), errCount(0), thresholdTimer(io, this), bridgeGpio(bridgeGpio)
+ waitTimer(io), errCount(0), thresholdTimer(io, this),
+ bridgeGpio(std::move(bridgeGpio))
{
sensorInterface = objectServer.add_interface(
"/xyz/openbmc_project/sensors/voltage/" + name,