From 1499a5c3635f22a3607c19c836bc00deb671ad10 Mon Sep 17 00:00:00 2001 From: Matthew Barth Date: Tue, 20 Mar 2018 15:52:33 -0500 Subject: Add InterfacesRemoved signal handling When an InterfacesRemoved signal is received for a subscribed object path, each interface returned is checked against the interface which was defined for each object on the event. When these are equal, the interface (and all associated properties) are removed from the shared cache of event properties. Tested: Manually added an InterfacesRemoved signal Verified interface was removed from object path in cache Change-Id: I348d82f14e0cfba2b18a81a9f54c6cb06b586797 Signed-off-by: Matthew Barth --- control/functor.hpp | 80 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 80 insertions(+) (limited to 'control/functor.hpp') diff --git a/control/functor.hpp b/control/functor.hpp index 8e85fcb..0a2b955 100644 --- a/control/functor.hpp +++ b/control/functor.hpp @@ -254,6 +254,86 @@ auto objectSignal(const char* path, std::forward(handler)); } +/** + * @struct Interface Removed + * @brief A match filter functor for Dbus interface removed signals + * + * @tparam U - The type of the handler + */ +template +struct InterfaceRemoved +{ + InterfaceRemoved() = delete; + ~InterfaceRemoved() = default; + InterfaceRemoved(const InterfaceRemoved&) = default; + InterfaceRemoved& operator=(const InterfaceRemoved&) = default; + InterfaceRemoved(InterfaceRemoved&&) = default; + InterfaceRemoved& operator=(InterfaceRemoved&&) = default; + InterfaceRemoved(const char* path, + const char* iface, + U&& handler) : + _path(path), + _iface(iface), + _handler(std::forward(handler)) { } + + /** @brief Run signal handler function + * + * Extract the property from the InterfacesRemoved + * message and run the handler function. + */ + void operator()(sdbusplus::bus::bus&, + sdbusplus::message::message& msg, + Zone& zone) const + { + if (msg) + { + std::vector intfs; + sdbusplus::message::object_path op; + + msg.read(op); + if (static_cast(op) != _path) + { + // Object path does not match this handler's path + return; + } + + msg.read(intfs); + auto itIntf = std::find(intfs.begin(), intfs.end(), _iface); + if (itIntf == intfs.cend()) + { + // Interface not found on this handler's path + return; + } + + _handler(zone); + } + } + +private: + const char* _path; + const char* _iface; + U _handler; +}; + +/** + * @brief Used to process a Dbus interface removed signal event + * + * @param[in] path - Object path + * @param[in] iface - Object interface + * @param[in] handler - Handler function to perform + * + * @tparam U - The type of the handler + */ +template +auto objectSignal(const char* path, + const char* iface, + U&& handler) +{ + return InterfaceRemoved(path, + iface, + std::forward(handler)); +} + /** * @struct Name Owner Changed * @brief A match filter functor for Dbus name owner changed signals -- cgit v1.2.1