Refactor PropertiesChanged handler setup
Most sensor daemons had pretty much the same duplicated open-coded
pattern for setting up PropertiesChanged signal matches; introduce a
helper function to reduce the duplication and make things more readable.
Signed-off-by: Zev Weiss <zev@bewilderbeest.net>
Change-Id: I803a21eea2f6d7fc71b50d54bb8fd57a104f3349
diff --git a/src/Utils.cpp b/src/Utils.cpp
index 60c05d6..66464e8 100644
--- a/src/Utils.cpp
+++ b/src/Utils.cpp
@@ -707,3 +707,21 @@
{
return manufacturingMode;
}
+
+std::vector<std::unique_ptr<sdbusplus::bus::match_t>>
+ setupPropertiesChangedMatches(
+ sdbusplus::asio::connection& bus, std::span<const char* const> types,
+ const std::function<void(sdbusplus::message_t&)>& handler)
+{
+ std::vector<std::unique_ptr<sdbusplus::bus::match_t>> matches;
+ for (const char* type : types)
+ {
+ auto match = std::make_unique<sdbusplus::bus::match_t>(
+ static_cast<sdbusplus::bus_t&>(bus),
+ "type='signal',member='PropertiesChanged',path_namespace='" +
+ std::string(inventoryPath) + "',arg0namespace='" + type + "'",
+ handler);
+ matches.emplace_back(std::move(match));
+ }
+ return matches;
+}