blob: 286492463af34acca2dc02be2a17c1364e51a932 [file] [log] [blame]
Matthew Barth1febc282017-04-12 11:33:39 -05001#include "monitor.hpp"
2
3namespace phosphor
4{
5namespace dbus
6{
7namespace monitoring
8{
9
Matthew Barthe6af2332017-04-12 13:37:29 -050010// TODO Remove when generated.cpp included
11const std::vector<std::tuple<std::vector<std::shared_ptr<Event>>,
12 std::vector<Action>>>
13 Monitor::events
14{};
15
Matthew Barth1febc282017-04-12 11:33:39 -050016Monitor::Monitor(sdbusplus::bus::bus& bus) :
17 bus(bus)
18{
19
20}
21
Matthew Barthe6af2332017-04-12 13:37:29 -050022void 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
39void 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 Barth1febc282017-04-12 11:33:39 -050060} // namespace monitoring
61} // namespace dbus
62} // namespace phosphor