blob: ca256a742d17385f64e0e512d5f923b4a9a1c533 [file] [log] [blame]
Ratan Gupta90bfaea2017-10-06 20:56:31 +05301#pragma once
2
3#include <phosphor-logging/log.hpp>
4#include "callback.hpp"
5
6namespace phosphor
7{
8namespace dbus
9{
10namespace monitoring
11{
12
13/** @class EventBase
14 * @brief Event callback implementation.
15 *
16 * The event callback creates the event dbus object
17 * which has event message and metadata as key value pairs
18 * as specified by the client supplied property index.
19 */
20class EventBase : public IndexedCallback
21{
22 public:
23 EventBase() = delete;
24 EventBase(const EventBase&) = delete;
25 EventBase(EventBase&&) = default;
26 EventBase& operator=(const EventBase&) = delete;
27 EventBase& operator=(EventBase&&) = default;
28 virtual ~EventBase() = default;
29 EventBase(const PropertyIndex& index) :
30 IndexedCallback(index) {}
31
32 /** @brief Callback interface implementation. */
Ratan Guptaa45e0862018-02-21 19:03:13 +053033 void operator()(Context ctx) override
Ratan Gupta90bfaea2017-10-06 20:56:31 +053034 {
Ratan Guptaef69ac02018-02-21 19:23:16 +053035 if (ctx == Context::START)
36 {
37 // No action should be taken
38 // as this call back is being called from
39 // daemon Startup.
40 return;
41 }
42
Ratan Gupta90bfaea2017-10-06 20:56:31 +053043 for (const auto& n : index)
44 {
45 const auto& path = std::get<pathIndex>(n.first);
Ratan Guptaef69ac02018-02-21 19:23:16 +053046 const auto& propertyMeta = std::get<propertyIndex>(n.first);
Ratan Gupta90bfaea2017-10-06 20:56:31 +053047 const auto& value = std::get<valueIndex>(n.second);
48
49 if (!value.get().empty())
50 {
51 createEvent(
52 path,
53 propertyMeta,
54 value);
55 }
56 }
57
58 }
59
60 private:
61
62 /** @brief Create the event Dbus Object.
63 * @param[in] path - Dbus Object Path for which the
64 * property has changed.
65 * @param[in] property - Name of the property whose value
66 * has been changed.
67 * @param[in] value - Changed property value.
68 */
69 virtual void createEvent(
70 const std::string& path,
71 const std::string& property,
72 const any_ns::any& value) const = 0;
73
74
75};
76
77/** @class Event
78 * @brief C++ type specific logic for the event callback.
79 *
80 * @tparam T - The C++ type of the property values being traced.
81 */
82template <typename T>
83class Event : public EventBase
84{
85 public:
86 Event() = delete;
87 Event(const Event&) = delete;
88 Event(Event&&) = default;
89 Event& operator=(const Event&) = delete;
90 Event& operator=(Event&&) = default;
91 ~Event() = default;
92
93 /** @brief Constructor.
94 * @param[in] eventName - Name of the event.
95 * @param[in] eventMessage- Event Message.
96 * @param[in] index - look up index for the properties.
97 */
98 Event(std::string eventName,
99 std::string eventMessage,
100 const PropertyIndex& index) :
101 EventBase(index),
102 name(eventName),
103 message(eventMessage) {}
104
105 private:
106 /** @brief Create the event Dbus Object.
107 * @param[in] path - Dbus Object Path for which the
108 * property has changed.
109 * @param[in] property - Name of the property whose value
110 * has been changed.
111 * @param[in] value - Changed property value.
112 */
113 void createEvent(
114 const std::string& path,
115 const std::string& property,
116 const any_ns::any& value) const override {}
117
118 /** @brief Event Name */
119 std::string name;
120
121 /** @brief Event Message */
122 std::string message;
123};
124
125} // namespace monitoring
126} // namespace dbus
127} // namespace phosphor