Add support for processing start event triggers
Process application start event triggers' list of conditions on a group
and perform the defined actions.
This re-uses the following structs(and their necessary functions)
directly from phosphor-inventory-manager:
--struct PropertyConditionBase
--struct PropertyCondition
Change-Id: If4090299fe887ef940320091d4d4be9f6aa7dd29
Signed-off-by: Matthew Barth <msbarth@us.ibm.com>
diff --git a/src/monitor.cpp b/src/monitor.cpp
index f734b00..2864924 100644
--- a/src/monitor.cpp
+++ b/src/monitor.cpp
@@ -7,12 +7,56 @@
namespace monitoring
{
+// TODO Remove when generated.cpp included
+const std::vector<std::tuple<std::vector<std::shared_ptr<Event>>,
+ std::vector<Action>>>
+ Monitor::events
+{};
+
Monitor::Monitor(sdbusplus::bus::bus& bus) :
bus(bus)
{
}
+void Monitor::processStart() noexcept
+{
+ sdbusplus::message::message nullMsg{nullptr};
+
+ // Process thru given events that are type 'start'
+ for (auto& event : events)
+ {
+ for (auto& pEvent : std::get<std::vector<std::shared_ptr<Event>>>(event))
+ {
+ if (pEvent->trigger == Event::Trigger::START)
+ {
+ handleEvent(nullMsg, *pEvent, event);
+ }
+ }
+ }
+}
+
+void Monitor::handleEvent(sdbusplus::message::message& msg,
+ const Event& event,
+ const std::tuple<std::vector<std::shared_ptr<Event>>,
+ std::vector<Action>>& eventDef)
+{
+ // Iterate over conditions
+ for (auto& cond : event)
+ {
+ if (!cond(bus, msg, *this))
+ {
+ continue;
+ }
+ // Perform defined actions
+ for (auto& act : std::get<1>(eventDef))
+ {
+ act(bus, *this);
+ }
+ return;
+ }
+}
+
} // namespace monitoring
} // namespace dbus
} // namespace phosphor