Fix hardcoded string in propertyChangedTo
Prior to this change this template will not build with types
other than strings.
Add an example that tests this.
Change-Id: I71e5c4136e7e4fd52fea3e8e027e42634011d630
Signed-off-by: Brad Bishop <bradleyb@fuzziesquirrel.com>
diff --git a/events.hpp b/events.hpp
index 0c789bd..65eb06a 100644
--- a/events.hpp
+++ b/events.hpp
@@ -140,7 +140,8 @@
return false;
}
- return _condition(it->second.template get<T>());
+ return _condition(
+ std::forward<T>(it->second.template get<T>()));
}
private:
@@ -157,9 +158,9 @@
auto propertyChangedTo(
const char* iface,
const char* property,
- T val)
+ T&& val)
{
- auto condition = [val = std::move(val)](const std::string & arg)
+ auto condition = [val = std::move(val)](T && arg)
{
return arg == val;
};
diff --git a/example/events.d/match2.yaml b/example/events.d/match2.yaml
index 22f7c80..047462d 100644
--- a/example/events.d/match2.yaml
+++ b/example/events.d/match2.yaml
@@ -2,7 +2,7 @@
An example inventory match rule.
events:
- - name: Example Match(2)
+ - name: Example Match
description: >
Destroys the /deleteme1 and /deleteme2 objects
When the value of ExampleProperty2 on
@@ -26,5 +26,27 @@
- /deleteme1
- /deleteme2
+ - name: Example Match
+ description: >
+ Destroys the /deleteme3 object when the value of
+ ExampleProperty3 on /testing/trigger3
+ changes to 10.
+ type: match
+ signatures:
+ - type: signal
+ path: /testing/trigger3
+ interface: org.freedesktop.DBus.Properties
+ member: PropertiesChanged
+ filters:
+ - name: propertyChangedTo
+ interface: xyz.openbmc_project.Example.Iface2
+ property: ExampleProperty3
+ value:
+ value: 10
+ type: int64
+ actions:
+ - name: destroyObjects
+ paths:
+ - /deleteme3
# vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4
diff --git a/example/extra_interfaces.d/xyz/openbmc_project/Example/Iface2.interface.yaml b/example/extra_interfaces.d/xyz/openbmc_project/Example/Iface2.interface.yaml
index c4bcce0..cb81630 100644
--- a/example/extra_interfaces.d/xyz/openbmc_project/Example/Iface2.interface.yaml
+++ b/example/extra_interfaces.d/xyz/openbmc_project/Example/Iface2.interface.yaml
@@ -4,6 +4,11 @@
- name: ExampleProperty2
type: string
description: >
- An example property.
+ An example string property.
+ - name: ExampleProperty3
+ type: int64
+ description: >
+ An example int64 property.
+
# vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4
diff --git a/test/test.cpp b/test/test.cpp
index 621860a..bd75dbb 100644
--- a/test/test.cpp
+++ b/test/test.cpp
@@ -36,6 +36,17 @@
"/trigger1"s);
const auto trigger2 = sdbusplus::message::object_path(EXAMPLE_ROOT +
"/trigger2"s);
+const auto trigger3 = sdbusplus::message::object_path(EXAMPLE_ROOT +
+ "/trigger3"s);
+
+const sdbusplus::message::object_path relDeleteMeOne{"/deleteme1"};
+const sdbusplus::message::object_path relDeleteMeTwo{"/deleteme2"};
+const sdbusplus::message::object_path relDeleteMeThree{"/deleteme3"};
+
+const std::string root{MGR_ROOT};
+const std::string deleteMeOne{root + relDeleteMeOne.str};
+const std::string deleteMeTwo{root + relDeleteMeTwo.str};
+const std::string deleteMeThree{root + relDeleteMeThree.str};
using ExampleIface1 = sdbusplus::xyz::openbmc_project::Example::server::Iface1;
using ExampleIface2 = sdbusplus::xyz::openbmc_project::Example::server::Iface2;
@@ -60,6 +71,8 @@
ExampleIface1, ExampleIface2 > t1(bus, trigger1.str.c_str());
sdbusplus::server::object::object <
ExampleIface1, ExampleIface2 > t2(bus, trigger2.str.c_str());
+ sdbusplus::server::object::object <
+ ExampleIface1, ExampleIface2 > t3(bus, trigger3.str.c_str());
while (!shutdown)
{
@@ -163,7 +176,6 @@
void runTests()
{
- const std::string root{MGR_ROOT};
const std::string exampleRoot{EXAMPLE_ROOT};
auto b = sdbusplus::bus::new_default();
@@ -223,11 +235,6 @@
// Make sure DBus signals are handled.
{
- sdbusplus::message::object_path relDeleteMeOne{"/deleteme1"};
- sdbusplus::message::object_path relDeleteMeTwo{"/deleteme2"};
- std::string deleteMeOne{root + relDeleteMeOne.str};
- std::string deleteMeTwo{root + relDeleteMeTwo.str};
-
// Create some objects to be deleted by an action.
{
auto m = notify();
@@ -241,8 +248,14 @@
m.append(obj);
b.call(m);
}
+ {
+ auto m = notify();
+ m.append(relDeleteMeThree);
+ m.append(obj);
+ b.call(m);
+ }
- // Set a property that should not trigger due to a filter.
+ // Set some properties that should not trigger due to a filter.
{
SignalQueue queue(
"path='" + root + "',member='InterfacesRemoved'");
@@ -254,8 +267,19 @@
auto sig{queue.pop()};
assert(!sig);
}
+ {
+ SignalQueue queue(
+ "path='" + root + "',member='InterfacesRemoved'");
+ auto m = set(trigger3.str);
+ m.append("xyz.openbmc_project.Example.Iface2");
+ m.append("ExampleProperty3");
+ m.append(sdbusplus::message::variant<int64_t>(11));
+ b.call(m);
+ auto sig{queue.pop()};
+ assert(!sig);
+ }
- // Set a property that should trigger.
+ // Set some properties that should trigger.
{
SignalQueue queue(
"path='" + root + "',member='InterfacesRemoved'");
@@ -294,6 +318,34 @@
assert(!sig);
}
}
+ {
+ SignalQueue queue(
+ "path='" + root + "',member='InterfacesRemoved'");
+
+ auto m = set(trigger3.str);
+ m.append("xyz.openbmc_project.Example.Iface2");
+ m.append("ExampleProperty3");
+ m.append(sdbusplus::message::variant<int64_t>(10));
+ b.call(m);
+
+ sdbusplus::message::object_path sigpath;
+ std::vector<std::string> interfaces;
+ {
+ std::vector<std::string> interfaces;
+ auto sig{queue.pop()};
+ assert(sig);
+ sig.read(sigpath);
+ assert(sigpath == deleteMeThree);
+ sig.read(interfaces);
+ std::sort(interfaces.begin(), interfaces.end());
+ assert(hasInterfaces(interfaces, obj));
+ }
+ {
+ // Make sure there was only one signal.
+ auto sig{queue.pop()};
+ assert(!sig);
+ }
+ }
}
// Validate the set property action.