blob: 63afebea55938f830064b3c63249ee5e54b501b6 [file] [log] [blame]
Matthew Barth1febc282017-04-12 11:33:39 -05001#pragma once
2
3#include <sdbusplus/bus.hpp>
4#include <sdbusplus/server.hpp>
5#include "events.hpp"
6
7namespace phosphor
8{
9namespace dbus
10{
11namespace monitoring
12{
13
Matthew Barthc5736432017-04-17 12:22:50 -050014/**
15 * @class Monitor
16 * @brief OpenBMC DBus Monitoring application
17 * @details A configurable application to perform a set of actions based on one
18 * or more conditions for items within a group
19 */
Matthew Barth1febc282017-04-12 11:33:39 -050020class Monitor
21{
22 public:
23 Monitor() = delete;
24 Monitor(const Monitor&) = delete;
25 Monitor(Monitor&&) = default;
26 Monitor& operator=(const Monitor&) = delete;
27 Monitor& operator=(Monitor&&) = default;
28 ~Monitor() = default;
29
Matthew Barthc5736432017-04-17 12:22:50 -050030 /**
31 * @brief Constructs monitor object
32 *
33 * @param[in] bus - Dbus bus object
34 */
Matthew Barth1febc282017-04-12 11:33:39 -050035 explicit Monitor(sdbusplus::bus::bus& bus);
36
Matthew Barthc5736432017-04-17 12:22:50 -050037 /**
38 * @brief Process events triggered by the application starting
39 */
Matthew Barthe6af2332017-04-12 13:37:29 -050040 void processStart() noexcept;
41
Matthew Barthc5736432017-04-17 12:22:50 -050042 /**
43 * @brief Handle an event being processed
44 *
45 * @param[in] msg - Dbus msg
46 * @param[in] event - Event to be handled
47 * @param[in] eventDef - The event's full definition
48 */
Matthew Barthe6af2332017-04-12 13:37:29 -050049 void handleEvent(sdbusplus::message::message& msg,
50 const Event& event,
51 const std::tuple<std::vector<std::shared_ptr<Event>>,
52 std::vector<Action>>& eventDef);
53
Matthew Barthc5736432017-04-17 12:22:50 -050054 /**
55 * @brief An event's set of arguments
56 */
Matthew Barth240bf332017-04-12 13:48:29 -050057 using eventArg = std::tuple<Monitor*,
58 const SignalEvent*,
59 const std::tuple<
60 std::vector<std::shared_ptr<Event>>,
61 std::vector<Action>>*>;
62
Matthew Barth1febc282017-04-12 11:33:39 -050063 private:
Matthew Barthc5736432017-04-17 12:22:50 -050064 /** @brief Connection for sdbusplus bus */
Matthew Barth1febc282017-04-12 11:33:39 -050065 sdbusplus::bus::bus& bus;
Matthew Barthc5736432017-04-17 12:22:50 -050066 /** @brief List of events to process */
Matthew Barthe6af2332017-04-12 13:37:29 -050067 static const std::vector<
68 std::tuple<std::vector<std::shared_ptr<Event>>,
69 std::vector<Action>>> events;
Matthew Barthc5736432017-04-17 12:22:50 -050070 /** @brief List of event arguments */
Matthew Barth240bf332017-04-12 13:48:29 -050071 std::vector<std::unique_ptr<eventArg>> eventArgs;
Matthew Barthc5736432017-04-17 12:22:50 -050072 /** @brief list of Dbus matches for callbacks */
Matthew Barth240bf332017-04-12 13:48:29 -050073 std::vector<sdbusplus::server::match::match> matches;
74
Matthew Barthc5736432017-04-17 12:22:50 -050075 /**
76 * @brief Handle an event signal
77 *
78 * @param[in] msg - Data associated with the subscribed signal
79 * @param[in] data - Pointer to the event items's data
80 * @param[in] err - Contains any sdbus error reference if occurred
81 *
82 * @return 0
83 */
Matthew Barth240bf332017-04-12 13:48:29 -050084 static int handleSignal(sd_bus_message* msg,
85 void* data,
86 sd_bus_error* err);
87
Matthew Barth1febc282017-04-12 11:33:39 -050088};
89
90} // namespace monitoring
91} // namespace dbus
92} // namespace phosphor