diff options
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 |