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>
diff --git a/src/Makefile.am b/src/Makefile.am
index c20b9dd..cf91619 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -32,7 +32,8 @@
 	templates/elog.mako.cpp \
 	templates/errors.mako.hpp \
 	templates/method.mako.cpp \
-	templates/resolve_errors.mako.cpp
+	templates/resolve_errors.mako.cpp \
+	templates/event.mako.cpp
 
 generated.hpp: $(PDMGEN) $(YAML_PATH) $(TEMPLATES)
 	$(AM_V_GEN)$(PYTHON) ${PDMGEN} \
diff --git a/src/data_types.hpp b/src/data_types.hpp
index 21f2ecf..1ba0b8a 100644
--- a/src/data_types.hpp
+++ b/src/data_types.hpp
@@ -16,6 +16,10 @@
 constexpr auto MAPPER_BUSNAME = "xyz.openbmc_project.ObjectMapper";
 constexpr auto MAPPER_PATH = "/xyz/openbmc_project/object_mapper";
 constexpr auto MAPPER_INTERFACE = "xyz.openbmc_project.ObjectMapper";
+constexpr auto pathIndex = 0;
+constexpr auto propertyIndex = 2;
+constexpr auto valueIndex = 2;
+constexpr auto metaIndex = 1;
 
 /** @brief A map with references as keys. */
 template <typename Key, typename Value>
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
diff --git a/src/pdmgen.py b/src/pdmgen.py
index efff03d..fe3f826 100755
--- a/src/pdmgen.py
+++ b/src/pdmgen.py
@@ -700,6 +700,20 @@
             c=self,
             indent=indent)
 
+class Event(Callback, Renderer):
+    '''Handle the event callback config file directive.'''
+
+    def __init__(self, *a, **kw):
+        self.eventName = kw.pop('eventName')
+        self.eventMessage = kw.pop('eventMessage')
+        super(Event, self).__init__(**kw)
+
+    def construct(self, loader, indent):
+        return self.render(
+            loader,
+            'event.mako.cpp',
+            c=self,
+            indent=indent)
 
 class ResolveCallout(Callback, Renderer):
     '''Handle the 'resolve callout' callback config file directive.'''
@@ -884,6 +898,7 @@
             'callback': {
                 'journal': Journal,
                 'elog': Elog,
+                'event': Event,
                 'group': GroupOfCallbacks,
                 'method': Method,
                 'resolve callout': ResolveCallout,
diff --git a/src/templates/event.mako.cpp b/src/templates/event.mako.cpp
new file mode 100644
index 0000000..e5ac850
--- /dev/null
+++ b/src/templates/event.mako.cpp
@@ -0,0 +1,2 @@
+std::make_unique<Event<${c.datatype}>>("${c.eventName}"s, "${c.eventMessage}"s,
+${indent(1)}ConfigPropertyIndicies::get()[${c.instances}])\
diff --git a/src/templates/generated.mako.hpp b/src/templates/generated.mako.hpp
index 740acfa..4a5b87c 100644
--- a/src/templates/generated.mako.hpp
+++ b/src/templates/generated.mako.hpp
@@ -14,6 +14,7 @@
 #include "propertywatchimpl.hpp"
 #include "resolve_errors.hpp"
 #include "sdbusplus.hpp"
+#include "event.hpp"
 #include "sdevent.hpp"
 
 using namespace std::string_literals;