Add support for application startup events.

Allow clients to specify filters and actions that trigger
on application startup.

Signed-off-by: Brad Bishop <bradleyb@fuzziesquirrel.com>
Change-Id: Ib36c5bab778d7c87906dd3f61a3a6e033c7ccde1
diff --git a/events.hpp b/events.hpp
index e197719..6737861 100644
--- a/events.hpp
+++ b/events.hpp
@@ -33,6 +33,7 @@
     enum class Type
     {
         DBUS_SIGNAL,
+        STARTUP,
     };
 
     virtual ~Event() = default;
@@ -47,7 +48,7 @@
      *  @param[in] t - The event type.
      */
     explicit Event(
-        const std::vector<FilterBasePtr>& filters, Type t) :
+        const std::vector<FilterBasePtr>& filters, Type t = Type::STARTUP) :
         std::vector<FilterBasePtr>(filters),
         type(t) {}
 
@@ -55,6 +56,8 @@
     Type type;
 };
 
+using StartupEvent = Event;
+
 using EventBasePtr = std::shared_ptr<Event>;
 
 /** @struct DbusSignal
diff --git a/example/events.d/match1.yaml b/example/events.d/match1.yaml
index 0d53657..9dca187 100644
--- a/example/events.d/match1.yaml
+++ b/example/events.d/match1.yaml
@@ -74,4 +74,17 @@
                     value: 888
                     type: int64
 
+    - name: startup event example
+      description: >
+          Create /createme3 at startup.
+      type: startup
+      actions:
+          - name: createObjects
+            objs:
+              /createme3:
+                xyz.openbmc_project.Example.Iface1:
+                  ExampleProperty1:
+                    value: foo
+                    type: string
+
 # vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4
diff --git a/manager.cpp b/manager.cpp
index 1ebcb7f..8026bf0 100644
--- a/manager.cpp
+++ b/manager.cpp
@@ -114,6 +114,22 @@
 
 void Manager::run() noexcept
 {
+    sdbusplus::message::message unusedMsg{nullptr};
+
+    // Run startup events.
+    for (auto& group : _events)
+    {
+        for (auto pEvent : std::get<std::vector<details::EventBasePtr>>(
+                 group))
+        {
+            if (pEvent->type ==
+                details::Event::Type::STARTUP)
+            {
+                handleEvent(unusedMsg, *pEvent, group);
+            }
+        }
+    }
+
     while (!_shutdown)
     {
         try
diff --git a/test/test.cpp b/test/test.cpp
index 816d471..3f39fa9 100644
--- a/test/test.cpp
+++ b/test/test.cpp
@@ -209,6 +209,24 @@
         },
     };
 
+    // Validate startup events occurred.
+    {
+        sdbusplus::message::object_path relCreateMe3{"/createme3"};
+        std::string createMe3{root + relCreateMe3.str};
+
+        auto get = b.new_method_call(
+                       MGR_SERVICE,
+                       createMe3.c_str(),
+                       "org.freedesktop.DBus.Properties",
+                       "GetAll");
+        get.append("xyz.openbmc_project.Example.Iface1");
+        auto resp = b.call(get);
+
+        Object::mapped_type properties;
+        assert(!resp.is_method_error());
+        resp.read(properties);
+    }
+
     // Make sure the notify method works.
     {
         sdbusplus::message::object_path relPath{"/foo"};