Add item group monitoring data type framework
Include supported data types for item groups:
--Start event trigger
--Signal event trigger
--A countAtOrAbove condition
--A log_error action
Change-Id: I1ae5ba60e4d9c06155885d52d98a44b31fd73207
Signed-off-by: Matthew Barth <msbarth@us.ibm.com>
diff --git a/src/conditions.hpp b/src/conditions.hpp
new file mode 100644
index 0000000..54a6dc6
--- /dev/null
+++ b/src/conditions.hpp
@@ -0,0 +1,48 @@
+#pragma once
+
+#include <algorithm>
+#include "data_types.hpp"
+
+namespace phosphor
+{
+namespace dbus
+{
+namespace monitoring
+{
+namespace condition
+{
+
+template <typename T>
+auto countAtOrAbove(Group& items, const char* path, size_t count, T&& value)
+{
+ return [&items,
+ path,
+ count,
+ value = std::forward<T>(value)](T&& arg)
+ {
+ Group::iterator it =
+ std::find_if(items.begin(),
+ items.end(),
+ [&path](auto const& item)
+ {
+ return std::get<0>(item) == path;
+ });
+ if (it != std::end(items))
+ {
+ std::get<1>(*it) = arg;
+ }
+ size_t condCount =
+ std::count_if(items.begin(),
+ items.end(),
+ [&value](auto const& item)
+ {
+ return std::get<1>(item) >= value;
+ });
+ return condCount >= count;
+ };
+}
+
+} // namespace condition
+} // namespace monitoring
+} // namespace dbus
+} // namespace phosphor