Introduce interval configuration for sensor reads.
This introduces the ability to specify in the sensor label configuration
file, a specific sleep interval. The interval is in this file to allow
straightforward interval control over the sensors listed in that file.
Sensors grouped in the same file are treated as a group and run within
the same instance.
Tested: I tested setting the interval in one of four running
configurations and the change was picked up in that configuration while
the others ran at the default interval.
Resolves openbmc/phosphor-hwmon#5
Change-Id: Ia9e474bc446090c8ac95dc2e6bf23a4fd6ccf7b7
Signed-off-by: Patrick Venture <venture@google.com>
diff --git a/mainloop.cpp b/mainloop.cpp
index 8eb418f..1da6b69 100644
--- a/mainloop.cpp
+++ b/mainloop.cpp
@@ -16,7 +16,6 @@
#include <iostream>
#include <memory>
#include <cstdlib>
-#include <chrono>
#include <algorithm>
#include "sensorset.hpp"
#include "hwmon.hpp"
@@ -56,7 +55,6 @@
&CriticalObject::criticalAlarmHigh;
-using namespace std::literals::chrono_literals;
static constexpr auto typeAttrMap =
{
@@ -275,6 +273,14 @@
_bus.request_name(busname.c_str());
}
+ {
+ auto interval = getenv("INTERVAL");
+ if (interval)
+ {
+ _interval = strtoull(interval, NULL, 10);
+ }
+ }
+
// TODO: Issue#3 - Need to make calls to the dbus sensor cache here to
// ensure the objects all exist?
@@ -326,9 +332,8 @@
_bus.process_discard();
// Sleep until next interval.
- // TODO: Issue#5 - Make this configurable.
// TODO: Issue#6 - Optionally look at polling interval sysfs entry.
- _bus.wait((1000000us).count());
+ _bus.wait(_interval);
// TODO: Issue#7 - Should probably periodically check the SensorSet
// for new entries.
diff --git a/mainloop.hpp b/mainloop.hpp
index f48e590..d4ef2c4 100644
--- a/mainloop.hpp
+++ b/mainloop.hpp
@@ -7,6 +7,8 @@
#include "sensorset.hpp"
#include "interface.hpp"
+static constexpr auto default_interval = 1000000;
+
using Object = std::map<InterfaceType, std::experimental::any>;
using ObjectInfo = std::tuple<sdbusplus::bus::bus*, std::string, Object>;
@@ -71,4 +73,6 @@
const char* _root;
/** @brief DBus object state. */
SensorState state;
+ /** @brief Sleep interval in microseconds. */
+ uint64_t _interval = default_interval;
};