Matthew Barth | 1febc28 | 2017-04-12 11:33:39 -0500 | [diff] [blame] | 1 | #pragma once |
| 2 | |
| 3 | #include <sdbusplus/bus.hpp> |
| 4 | #include <sdbusplus/server.hpp> |
| 5 | #include "events.hpp" |
| 6 | |
| 7 | namespace phosphor |
| 8 | { |
| 9 | namespace dbus |
| 10 | { |
| 11 | namespace monitoring |
| 12 | { |
| 13 | |
Matthew Barth | c573643 | 2017-04-17 12:22:50 -0500 | [diff] [blame] | 14 | /** |
| 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 Barth | 1febc28 | 2017-04-12 11:33:39 -0500 | [diff] [blame] | 20 | class 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 Barth | c573643 | 2017-04-17 12:22:50 -0500 | [diff] [blame] | 30 | /** |
| 31 | * @brief Constructs monitor object |
| 32 | * |
| 33 | * @param[in] bus - Dbus bus object |
| 34 | */ |
Matthew Barth | 1febc28 | 2017-04-12 11:33:39 -0500 | [diff] [blame] | 35 | explicit Monitor(sdbusplus::bus::bus& bus); |
| 36 | |
Matthew Barth | c573643 | 2017-04-17 12:22:50 -0500 | [diff] [blame] | 37 | /** |
| 38 | * @brief Process events triggered by the application starting |
| 39 | */ |
Matthew Barth | e6af233 | 2017-04-12 13:37:29 -0500 | [diff] [blame] | 40 | void processStart() noexcept; |
| 41 | |
Matthew Barth | c573643 | 2017-04-17 12:22:50 -0500 | [diff] [blame] | 42 | /** |
| 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 Barth | e6af233 | 2017-04-12 13:37:29 -0500 | [diff] [blame] | 49 | 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 Barth | c573643 | 2017-04-17 12:22:50 -0500 | [diff] [blame] | 54 | /** |
| 55 | * @brief An event's set of arguments |
| 56 | */ |
Matthew Barth | 240bf33 | 2017-04-12 13:48:29 -0500 | [diff] [blame] | 57 | 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 Barth | 1febc28 | 2017-04-12 11:33:39 -0500 | [diff] [blame] | 63 | private: |
Matthew Barth | c573643 | 2017-04-17 12:22:50 -0500 | [diff] [blame] | 64 | /** @brief Connection for sdbusplus bus */ |
Matthew Barth | 1febc28 | 2017-04-12 11:33:39 -0500 | [diff] [blame] | 65 | sdbusplus::bus::bus& bus; |
Matthew Barth | c573643 | 2017-04-17 12:22:50 -0500 | [diff] [blame] | 66 | /** @brief List of events to process */ |
Matthew Barth | e6af233 | 2017-04-12 13:37:29 -0500 | [diff] [blame] | 67 | static const std::vector< |
| 68 | std::tuple<std::vector<std::shared_ptr<Event>>, |
| 69 | std::vector<Action>>> events; |
Matthew Barth | c573643 | 2017-04-17 12:22:50 -0500 | [diff] [blame] | 70 | /** @brief List of event arguments */ |
Matthew Barth | 240bf33 | 2017-04-12 13:48:29 -0500 | [diff] [blame] | 71 | std::vector<std::unique_ptr<eventArg>> eventArgs; |
Matthew Barth | c573643 | 2017-04-17 12:22:50 -0500 | [diff] [blame] | 72 | /** @brief list of Dbus matches for callbacks */ |
Matthew Barth | 240bf33 | 2017-04-12 13:48:29 -0500 | [diff] [blame] | 73 | std::vector<sdbusplus::server::match::match> matches; |
| 74 | |
Matthew Barth | c573643 | 2017-04-17 12:22:50 -0500 | [diff] [blame] | 75 | /** |
| 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 Barth | 240bf33 | 2017-04-12 13:48:29 -0500 | [diff] [blame] | 84 | static int handleSignal(sd_bus_message* msg, |
| 85 | void* data, |
| 86 | sd_bus_error* err); |
| 87 | |
Matthew Barth | 1febc28 | 2017-04-12 11:33:39 -0500 | [diff] [blame] | 88 | }; |
| 89 | |
| 90 | } // namespace monitoring |
| 91 | } // namespace dbus |
| 92 | } // namespace phosphor |