summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBrad Bishop <bradleyb@fuzziesquirrel.com>2017-01-21 22:17:09 -0500
committerPatrick Williams <patrick@stwcx.xyz>2017-02-02 03:30:04 +0000
commit3e4a19a3983b48c6d558d30711ec979e37e17f2b (patch)
treee01e5d0c9865fde3c8d549230993084ec5f7a39f
parent828df832d282b65eb22f0806885b8a961ecb7fa1 (diff)
downloadphosphor-inventory-manager-3e4a19a3983b48c6d558d30711ec979e37e17f2b.tar.gz
phosphor-inventory-manager-3e4a19a3983b48c6d558d30711ec979e37e17f2b.zip
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
-rw-r--r--events.hpp5
-rw-r--r--example/events.d/match1.yaml13
-rw-r--r--manager.cpp16
-rw-r--r--test/test.cpp18
4 files changed, 51 insertions, 1 deletions
diff --git a/events.hpp b/events.hpp
index e197719..6737861 100644
--- a/events.hpp
+++ b/events.hpp
@@ -33,6 +33,7 @@ struct Event : public std::vector<FilterBasePtr>
enum class Type
{
DBUS_SIGNAL,
+ STARTUP,
};
virtual ~Event() = default;
@@ -47,7 +48,7 @@ struct Event : public std::vector<FilterBasePtr>
* @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 @@ struct Event : public std::vector<FilterBasePtr>
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 @@ events:
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::shutdown() noexcept
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 @@ void runTests()
},
};
+ // 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"};
OpenPOWER on IntegriCloud