presence: Make error time be per fan
Previously there was a global value for the amount of time a fan needed
to be missing before an event log was created. This commit changes it
so that instead the value is specified per fan in the JSON.
This way, the times can be different or left off completely on a fan to
fan basis. The ErrorReporter object will only be created if there is at
least one fan with a time value.
Signed-off-by: Matt Spinler <spinler@us.ibm.com>
Change-Id: I53bb91c88ec1b0352df11b2e988064c2ec02af45
diff --git a/presence/error_reporter.cpp b/presence/error_reporter.cpp
index 1f7e5bc..4644535 100644
--- a/presence/error_reporter.cpp
+++ b/presence/error_reporter.cpp
@@ -33,6 +33,7 @@
using namespace phosphor::logging;
using namespace sdbusplus::bus::match;
using namespace std::literals::string_literals;
+using namespace std::chrono;
namespace fs = std::filesystem;
const auto itemIface = "xyz.openbmc_project.Inventory.Item"s;
@@ -41,14 +42,12 @@
const auto loggingCreateIface = "xyz.openbmc_project.Logging.Create";
ErrorReporter::ErrorReporter(
- sdbusplus::bus::bus& bus, const json& jsonConf,
+ sdbusplus::bus::bus& bus,
const std::vector<
std::tuple<Fan, std::vector<std::unique_ptr<PresenceSensor>>>>& fans) :
_bus(bus),
_event(sdeventplus::Event::get_default())
{
- loadConfig(jsonConf);
-
// If different methods to check the power state are needed across the
// various platforms, the method/class to use could be read out of JSON
// or set with a compilation flag.
@@ -58,25 +57,34 @@
for (const auto& fan : fans)
{
- auto path = invPrefix + std::get<1>(std::get<0>(fan));
+ const auto& fanData = std::get<0>(fan);
- // Register for fan presence changes, get their initial states,
- // and create the fan missing timers for each fan.
+ // Only deal with fans that have an error time defined.
+ if (std::get<std::optional<size_t>>(fanData))
+ {
+ auto path = invPrefix + std::get<1>(fanData);
- _matches.emplace_back(
- _bus, rules::propertiesChanged(path, itemIface),
- std::bind(std::mem_fn(&ErrorReporter::presenceChanged), this,
- std::placeholders::_1));
+ // Register for fan presence changes, get their initial states,
+ // and create the fan missing timers.
- _fanStates.emplace(path, getPresence(std::get<0>(fan)));
+ _matches.emplace_back(
+ _bus, rules::propertiesChanged(path, itemIface),
+ std::bind(std::mem_fn(&ErrorReporter::presenceChanged), this,
+ std::placeholders::_1));
- auto timer = std::make_unique<
- sdeventplus::utility::Timer<sdeventplus::ClockId::Monotonic>>(
- _event,
- std::bind(std::mem_fn(&ErrorReporter::fanMissingTimerExpired), this,
- path));
+ _fanStates.emplace(path, getPresence(fanData));
- _fanMissingTimers.emplace(path, std::move(timer));
+ auto timer = std::make_unique<
+ sdeventplus::utility::Timer<sdeventplus::ClockId::Monotonic>>(
+ _event,
+ std::bind(std::mem_fn(&ErrorReporter::fanMissingTimerExpired),
+ this, path));
+
+ seconds errorTime{std::get<std::optional<size_t>>(fanData).value()};
+
+ _fanMissingTimers.emplace(
+ path, std::make_tuple(std::move(timer), std::move(errorTime)));
+ }
}
// If power is already on, check for currently missing fans.
@@ -86,20 +94,6 @@
}
}
-void ErrorReporter::loadConfig(const json& jsonConf)
-{
- if (!jsonConf.contains("fan_missing_error_time"))
- {
- log<level::ERR>("Missing 'fan_missing_error_time' entry in JSON "
- "'reporting' section");
-
- throw std::runtime_error("Missing fan missing time entry in JSON");
- }
-
- _fanMissingErrorTime = std::chrono::seconds{
- jsonConf.at("fan_missing_error_time").get<std::size_t>()};
-}
-
void ErrorReporter::presenceChanged(sdbusplus::message::message& msg)
{
bool present;
@@ -126,25 +120,27 @@
void ErrorReporter::checkFan(const std::string& fanPath)
{
+ auto& timer = std::get<0>(_fanMissingTimers[fanPath]);
+
if (!_fanStates[fanPath])
{
// Fan is missing. If power is on, start the timer.
// If power is off, stop a running timer.
if (_powerState->isPowerOn())
{
- _fanMissingTimers[fanPath]->restartOnce(_fanMissingErrorTime);
+ timer->restartOnce(std::get<seconds>(_fanMissingTimers[fanPath]));
}
- else if (_fanMissingTimers[fanPath]->isEnabled())
+ else if (timer->isEnabled())
{
- _fanMissingTimers[fanPath]->setEnabled(false);
+ timer->setEnabled(false);
}
}
else
{
// Fan is present. Stop a running timer.
- if (_fanMissingTimers[fanPath]->isEnabled())
+ if (timer->isEnabled())
{
- _fanMissingTimers[fanPath]->setEnabled(false);
+ timer->setEnabled(false);
}
}
}