summaryrefslogtreecommitdiffstats
path: root/src/monitor.hpp
blob: 63afebea55938f830064b3c63249ee5e54b501b6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
#pragma once

#include <sdbusplus/bus.hpp>
#include <sdbusplus/server.hpp>
#include "events.hpp"

namespace phosphor
{
namespace dbus
{
namespace monitoring
{

/**
 * @class Monitor
 * @brief OpenBMC DBus Monitoring application
 * @details A configurable application to perform a set of actions based on one
 * or more conditions for items within a group
 */
class Monitor
{
    public:
        Monitor() = delete;
        Monitor(const Monitor&) = delete;
        Monitor(Monitor&&) = default;
        Monitor& operator=(const Monitor&) = delete;
        Monitor& operator=(Monitor&&) = default;
        ~Monitor() = default;

        /**
         * @brief Constructs monitor object
         *
         * @param[in] bus - Dbus bus object
         */
        explicit Monitor(sdbusplus::bus::bus& bus);

        /**
         * @brief Process events triggered by the application starting
         */
        void processStart() noexcept;

        /**
         * @brief Handle an event being processed
         *
         * @param[in] msg - Dbus msg
         * @param[in] event - Event to be handled
         * @param[in] eventDef - The event's full definition
         */
        void handleEvent(sdbusplus::message::message& msg,
                         const Event& event,
                         const std::tuple<std::vector<std::shared_ptr<Event>>,
                                    std::vector<Action>>& eventDef);

        /**
         * @brief An event's set of arguments
         */
        using eventArg = std::tuple<Monitor*,
                                    const SignalEvent*,
                                    const std::tuple<
                                        std::vector<std::shared_ptr<Event>>,
                                        std::vector<Action>>*>;

    private:
        /** @brief Connection for sdbusplus bus */
        sdbusplus::bus::bus& bus;
        /** @brief List of events to process */
        static const std::vector<
            std::tuple<std::vector<std::shared_ptr<Event>>,
                       std::vector<Action>>> events;
        /** @brief List of event arguments */
        std::vector<std::unique_ptr<eventArg>> eventArgs;
        /** @brief list of Dbus matches for callbacks */
        std::vector<sdbusplus::server::match::match> matches;

        /**
         * @brief Handle an event signal
         *
         * @param[in] msg - Data associated with the subscribed signal
         * @param[in] data - Pointer to the event items's data
         * @param[in] err - Contains any sdbus error reference if occurred
         *
         * @return 0
         */
        static int handleSignal(sd_bus_message* msg,
                                void* data,
                                sd_bus_error* err);

};

} // namespace monitoring
} // namespace dbus
} // namespace phosphor
OpenPOWER on IntegriCloud