Matthew Barth | 1febc28 | 2017-04-12 11:33:39 -0500 | [diff] [blame] | 1 | #include "monitor.hpp" |
| 2 | |
| 3 | namespace phosphor |
| 4 | { |
| 5 | namespace dbus |
| 6 | { |
| 7 | namespace monitoring |
| 8 | { |
| 9 | |
Matthew Barth | e6af233 | 2017-04-12 13:37:29 -0500 | [diff] [blame^] | 10 | // TODO Remove when generated.cpp included |
| 11 | const std::vector<std::tuple<std::vector<std::shared_ptr<Event>>, |
| 12 | std::vector<Action>>> |
| 13 | Monitor::events |
| 14 | {}; |
| 15 | |
Matthew Barth | 1febc28 | 2017-04-12 11:33:39 -0500 | [diff] [blame] | 16 | Monitor::Monitor(sdbusplus::bus::bus& bus) : |
| 17 | bus(bus) |
| 18 | { |
| 19 | |
| 20 | } |
| 21 | |
Matthew Barth | e6af233 | 2017-04-12 13:37:29 -0500 | [diff] [blame^] | 22 | void Monitor::processStart() noexcept |
| 23 | { |
| 24 | sdbusplus::message::message nullMsg{nullptr}; |
| 25 | |
| 26 | // Process thru given events that are type 'start' |
| 27 | for (auto& event : events) |
| 28 | { |
| 29 | for (auto& pEvent : std::get<std::vector<std::shared_ptr<Event>>>(event)) |
| 30 | { |
| 31 | if (pEvent->trigger == Event::Trigger::START) |
| 32 | { |
| 33 | handleEvent(nullMsg, *pEvent, event); |
| 34 | } |
| 35 | } |
| 36 | } |
| 37 | } |
| 38 | |
| 39 | void Monitor::handleEvent(sdbusplus::message::message& msg, |
| 40 | const Event& event, |
| 41 | const std::tuple<std::vector<std::shared_ptr<Event>>, |
| 42 | std::vector<Action>>& eventDef) |
| 43 | { |
| 44 | // Iterate over conditions |
| 45 | for (auto& cond : event) |
| 46 | { |
| 47 | if (!cond(bus, msg, *this)) |
| 48 | { |
| 49 | continue; |
| 50 | } |
| 51 | // Perform defined actions |
| 52 | for (auto& act : std::get<1>(eventDef)) |
| 53 | { |
| 54 | act(bus, *this); |
| 55 | } |
| 56 | return; |
| 57 | } |
| 58 | } |
| 59 | |
Matthew Barth | 1febc28 | 2017-04-12 11:33:39 -0500 | [diff] [blame] | 60 | } // namespace monitoring |
| 61 | } // namespace dbus |
| 62 | } // namespace phosphor |