diff options
author | Ratan Gupta <ratagupt@in.ibm.com> | 2017-10-06 20:56:31 +0530 |
---|---|---|
committer | Ratan Gupta <ratagupt@in.ibm.com> | 2018-02-20 09:30:04 +0530 |
commit | 90bfaea4c69773f4f252d06fad1147a718e8b863 (patch) | |
tree | 5d1ad14ac9e61ea0fbf9111bf48ec0ace714a9a9 /src/event.hpp | |
parent | 80e9b65fdf9b1172e02de606cc193a6723791828 (diff) | |
download | phosphor-dbus-monitor-90bfaea4c69773f4f252d06fad1147a718e8b863.tar.gz phosphor-dbus-monitor-90bfaea4c69773f4f252d06fad1147a718e8b863.zip |
Initial support for event callbacks
Add parser support for template rendering of events.
Also defines the EventBase and Event classes.
EventBase is parent of Event.
Change-Id: I6b07b415acf510a8437529095bd489c0af73ddf5
Signed-off-by: Ratan Gupta <ratagupt@in.ibm.com>
Diffstat (limited to 'src/event.hpp')
-rw-r--r-- | src/event.hpp | 119 |
1 files changed, 119 insertions, 0 deletions
diff --git a/src/event.hpp b/src/event.hpp new file mode 100644 index 0000000..8006c23 --- /dev/null +++ b/src/event.hpp @@ -0,0 +1,119 @@ +#pragma once + +#include <phosphor-logging/log.hpp> +#include "callback.hpp" + +namespace phosphor +{ +namespace dbus +{ +namespace monitoring +{ + +/** @class EventBase + * @brief Event callback implementation. + * + * The event callback creates the event dbus object + * which has event message and metadata as key value pairs + * as specified by the client supplied property index. + */ +class EventBase : public IndexedCallback +{ + public: + EventBase() = delete; + EventBase(const EventBase&) = delete; + EventBase(EventBase&&) = default; + EventBase& operator=(const EventBase&) = delete; + EventBase& operator=(EventBase&&) = default; + virtual ~EventBase() = default; + EventBase(const PropertyIndex& index) : + IndexedCallback(index) {} + + /** @brief Callback interface implementation. */ + void operator()() override + { + for (const auto& n : index) + { + const auto& path = std::get<pathIndex>(n.first); + const auto& propertyMeta = std::get<metaIndex>(n.first); + const auto& value = std::get<valueIndex>(n.second); + + if (!value.get().empty()) + { + createEvent( + path, + propertyMeta, + value); + } + } + + } + + private: + + /** @brief Create the event Dbus Object. + * @param[in] path - Dbus Object Path for which the + * property has changed. + * @param[in] property - Name of the property whose value + * has been changed. + * @param[in] value - Changed property value. + */ + virtual void createEvent( + const std::string& path, + const std::string& property, + const any_ns::any& value) const = 0; + + +}; + +/** @class Event + * @brief C++ type specific logic for the event callback. + * + * @tparam T - The C++ type of the property values being traced. + */ +template <typename T> +class Event : public EventBase +{ + public: + Event() = delete; + Event(const Event&) = delete; + Event(Event&&) = default; + Event& operator=(const Event&) = delete; + Event& operator=(Event&&) = default; + ~Event() = default; + + /** @brief Constructor. + * @param[in] eventName - Name of the event. + * @param[in] eventMessage- Event Message. + * @param[in] index - look up index for the properties. + */ + Event(std::string eventName, + std::string eventMessage, + const PropertyIndex& index) : + EventBase(index), + name(eventName), + message(eventMessage) {} + + private: + /** @brief Create the event Dbus Object. + * @param[in] path - Dbus Object Path for which the + * property has changed. + * @param[in] property - Name of the property whose value + * has been changed. + * @param[in] value - Changed property value. + */ + void createEvent( + const std::string& path, + const std::string& property, + const any_ns::any& value) const override {} + + /** @brief Event Name */ + std::string name; + + /** @brief Event Message */ + std::string message; +}; + +} // namespace monitoring +} // namespace dbus +} // namespace phosphor |