Add logging for Fan Presence / Redundancy
Add logging and fix bug with shared_ptr usage. We
now use a std::optional * to the shared redundancy
object, so that it can 1. point to object / null and 2.
exist in config or not.
Tested: cat /var/log/redfish to see logs made by removing
and adding fans, and using sensor override to change
redundancy.
Change-Id: Ic4b319cf7484cbbd7ce7dbdf7556f48bebe11cb0
Signed-off-by: James Feist <james.feist@linux.intel.com>
diff --git a/src/FanMain.cpp b/src/FanMain.cpp
index 962a115..eeface8 100644
--- a/src/FanMain.cpp
+++ b/src/FanMain.cpp
@@ -46,7 +46,7 @@
};
// todo: power supply fan redundancy
-std::shared_ptr<RedundancySensor> systemRedundancy = nullptr;
+std::optional<RedundancySensor> systemRedundancy;
FanTypes getFanType(const fs::path& parentPath)
{
@@ -251,14 +251,14 @@
size_t index = std::get<uint64_t>(findIndex->second);
bool inverted =
std::get<std::string>(findPolarity->second) == "Low";
- presenceSensor =
- std::make_unique<PresenceSensor>(index, inverted, io);
+ presenceSensor = std::make_unique<PresenceSensor>(
+ index, inverted, io, sensorName);
}
}
- std::shared_ptr<RedundancySensor> redundancy;
+ std::optional<RedundancySensor>* redundancy = nullptr;
if (fanType == FanTypes::aspeed)
{
- redundancy = systemRedundancy;
+ redundancy = &systemRedundancy;
}
constexpr double defaultMaxReading = 25000;
@@ -360,10 +360,10 @@
"/xyz/openbmc_project/sensors/fan_tach/" +
sensor.second->name);
}
- systemRedundancy = nullptr;
- systemRedundancy = std::make_shared<RedundancySensor>(
+ systemRedundancy.reset();
+ systemRedundancy.emplace(RedundancySensor(
std::get<uint64_t>(findCount->second), sensorList,
- objectServer, pathPair.first);
+ objectServer, pathPair.first));
return;
}