Add debounce timer to intrusion sensor rescan
GPIO based intrusion sensors were failing with rapid fire configuration
changes. Added a debounce timer to ensure multiple rescans can coalesce
into a single call to createSensorsFromConfig.
Tested: Ran change on Akamai Crow server and observed the GPIO Intrusion
Sensor being created properly at boot.
Change-Id: I789838a31575b80d839bdb9812d23ad0d71505a9
Signed-off-by: Ian Woloschin <ian.woloschin@akamai.com>
diff --git a/src/IntrusionSensorMain.cpp b/src/IntrusionSensorMain.cpp
index 4566b08..d59b2e6 100644
--- a/src/IntrusionSensorMain.cpp
+++ b/src/IntrusionSensorMain.cpp
@@ -485,6 +485,7 @@
createSensorsFromConfig(io, objServer, systemBus, intrusionSensor);
// callback to handle configuration change
+ boost::asio::steady_timer filterTimer(io);
std::function<void(sdbusplus::message_t&)> eventHandler =
[&](sdbusplus::message_t& message) {
if (message.is_method_error())
@@ -492,9 +493,17 @@
std::cerr << "callback method error\n";
return;
}
-
- std::cout << "rescan due to configuration change \n";
- createSensorsFromConfig(io, objServer, systemBus, intrusionSensor);
+ // this implicitly cancels the timer
+ filterTimer.expires_after(std::chrono::seconds(1));
+ filterTimer.async_wait([&](const boost::system::error_code& ec) {
+ if (ec == boost::asio::error::operation_aborted)
+ {
+ // timer was cancelled
+ return;
+ }
+ std::cout << "rescan due to configuration change \n";
+ createSensorsFromConfig(io, objServer, systemBus, intrusionSensor);
+ });
};
std::vector<std::unique_ptr<sdbusplus::bus::match_t>> matches =