blob: 8006c233d1fde1bdaa0b334524179381e6c0bcdb [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. */
33 void operator()() override
34 {
35 for (const auto& n : index)
36 {
37 const auto& path = std::get<pathIndex>(n.first);
38 const auto& propertyMeta = std::get<metaIndex>(n.first);
39 const auto& value = std::get<valueIndex>(n.second);
40
41 if (!value.get().empty())
42 {
43 createEvent(
44 path,
45 propertyMeta,
46 value);
47 }
48 }
49
50 }
51
52 private:
53
54 /** @brief Create the event Dbus Object.
55 * @param[in] path - Dbus Object Path for which the
56 * property has changed.
57 * @param[in] property - Name of the property whose value
58 * has been changed.
59 * @param[in] value - Changed property value.
60 */
61 virtual void createEvent(
62 const std::string& path,
63 const std::string& property,
64 const any_ns::any& value) const = 0;
65
66
67};
68
69/** @class Event
70 * @brief C++ type specific logic for the event callback.
71 *
72 * @tparam T - The C++ type of the property values being traced.
73 */
74template <typename T>
75class Event : public EventBase
76{
77 public:
78 Event() = delete;
79 Event(const Event&) = delete;
80 Event(Event&&) = default;
81 Event& operator=(const Event&) = delete;
82 Event& operator=(Event&&) = default;
83 ~Event() = default;
84
85 /** @brief Constructor.
86 * @param[in] eventName - Name of the event.
87 * @param[in] eventMessage- Event Message.
88 * @param[in] index - look up index for the properties.
89 */
90 Event(std::string eventName,
91 std::string eventMessage,
92 const PropertyIndex& index) :
93 EventBase(index),
94 name(eventName),
95 message(eventMessage) {}
96
97 private:
98 /** @brief Create the event Dbus Object.
99 * @param[in] path - Dbus Object Path for which the
100 * property has changed.
101 * @param[in] property - Name of the property whose value
102 * has been changed.
103 * @param[in] value - Changed property value.
104 */
105 void createEvent(
106 const std::string& path,
107 const std::string& property,
108 const any_ns::any& value) const override {}
109
110 /** @brief Event Name */
111 std::string name;
112
113 /** @brief Event Message */
114 std::string message;
115};
116
117} // namespace monitoring
118} // namespace dbus
119} // namespace phosphor