diff options
author | Matthew Barth <msbarth@us.ibm.com> | 2017-04-12 13:37:29 -0500 |
---|---|---|
committer | Brad Bishop <bradleyb@fuzziesquirrel.com> | 2017-05-15 16:57:10 -0400 |
commit | e6af23313890b82c4fca4d61ec1d2d9ff4817870 (patch) | |
tree | 09cb9f2930386c79bdea64aaeb92b3277cbf5b72 /src/monitor.cpp | |
parent | 1febc28a1b9b72c805b74c28c8b505e292591fc5 (diff) | |
download | phosphor-dbus-monitor-e6af23313890b82c4fca4d61ec1d2d9ff4817870.tar.gz phosphor-dbus-monitor-e6af23313890b82c4fca4d61ec1d2d9ff4817870.zip |
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>
Diffstat (limited to 'src/monitor.cpp')
-rw-r--r-- | src/monitor.cpp | 44 |
1 files changed, 44 insertions, 0 deletions
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 dbus 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 |