Add filters option to property watch class
Each property changed signal calls a defined callback, an optional set
of filters can be defined to filter out property values not intended to
be used within the callback. These filters can be setup to eliminate
property value(s) that should be ignored per property group and its
configured callback.
ex.) Handle errant sensor values that could occur from a faulty device
so these values do not cause unwanted results from a callback function.
Example config entry to throw out an ambient temperature less than 0C or
greater than 100C:
- name: watch ambient temps
description: >
'Filter the ambient temps, discarding any value that
does not pass, then trigger the callback logic.'
class: watch
watch: property
paths: ambient sensors
properties: ambient temp
callback: median temps
filters:
- op: '>='
bound: 0
- op: '<='
bound: 100000
Tested:
Generate a single filter function against a group of properties
Generate multiple filter functions against a group of properties
Property values are cleared when it fails to pass a filter
Property values that pass all filters are updated
Change-Id: Id5126263096b4787a40befdb14cf3514038df3ed
Signed-off-by: Matthew Barth <msbarth@us.ibm.com>
diff --git a/src/propertywatch.hpp b/src/propertywatch.hpp
index a94b99e..3168abe 100644
--- a/src/propertywatch.hpp
+++ b/src/propertywatch.hpp
@@ -116,12 +116,16 @@
PropertyWatchOfType& operator=(const PropertyWatchOfType&) = delete;
PropertyWatchOfType& operator=(PropertyWatchOfType&&) = default;
~PropertyWatchOfType() = default;
- PropertyWatchOfType(const PropertyIndex& watchIndex, Callback& callback) :
- PropertyWatch<DBusInterfaceType>(watchIndex, &callback)
+ PropertyWatchOfType(const std::vector<std::function<bool(T)>>& filterOps,
+ const PropertyIndex& watchIndex, Callback& callback) :
+ PropertyWatch<DBusInterfaceType>(watchIndex, &callback),
+ filterOps(filterOps)
{
}
- PropertyWatchOfType(const PropertyIndex& watchIndex) :
- PropertyWatch<DBusInterfaceType>(watchIndex, nullptr)
+ PropertyWatchOfType(const std::vector<std::function<bool(T)>>& filterOps,
+ const PropertyIndex& watchIndex) :
+ PropertyWatch<DBusInterfaceType>(watchIndex, nullptr),
+ filterOps(filterOps)
{
}
@@ -170,6 +174,10 @@
*/
void interfacesAdded(const std::string& path,
const InterfacesAdded<T>& interfaces);
+
+ private:
+ /** @brief List of filter operations to perform on property changes. */
+ const std::vector<std::function<bool(T)>> filterOps;
};
} // namespace monitoring