Add support for re-finding interfaces/system types
The DBusInterfacesFinder class simplifies the task of finding interface
instances on D-Bus. Similarly, the CompatibleSystemTypesFinder class
simplifies the task of finding the list of compatible system types for
the current system.
Both classes initially find the D-Bus objects that already exist at the
time the classes are constructed. They use InterfacesAdded listeners to
find new D-Bus objects that are created later.
This behavior handles most use cases. However, sometimes a caller may
not be receiving D-Bus signals, but they still need to find new D-Bus
objects that have been created. For example, the caller may be looping
within a timeout period waiting for a D-Bus object to be created.
To handle this use case, add `refind()` methods to both classes that
will re-find all matching D-Bus objects that now exist, including those
created since the classes were constructed.
Tested:
* DBusInterfacesFinder
* Verify finds all interface instances that exist at time class is
constructed
* None found
* Instances found
* Verify finds new interface instances via InterfacesAdded listener
* Verify refind() finds all interface instances, including those that
were created after the class was constructed.
* None found
* Instances found
* CompatibleSystemTypesFinder
* Verify finds all compatible system type lists that exist at time
class is constructed
* None found
* Lists found
* Verify finds new compatible system type lists via InterfacesAdded
listener
* Verify refind() finds all compatible system type lists, including
those that were created after the class was constructed.
* None found
* Lists found
Change-Id: I975b37524f687e6d2f3d4ff48abb5e4486a84bfe
Signed-off-by: Shawn McCarney <shawnmm@us.ibm.com>
diff --git a/compatible_system_types_finder.hpp b/compatible_system_types_finder.hpp
index f24617d..26093d9 100644
--- a/compatible_system_types_finder.hpp
+++ b/compatible_system_types_finder.hpp
@@ -85,6 +85,22 @@
Callback callback);
/**
+ * Refind all compatible system types for the current system.
+ *
+ * The callback specified in the constructor will be called for each list of
+ * compatible system types found.
+ *
+ * This method normally does not need to be called. New lists of compatible
+ * system types are automatically detected using an InterfacesAdded
+ * listener. However, this method may be useful if the caller is not
+ * currently receiving D-Bus signals (such as within a loop).
+ */
+ void refind()
+ {
+ interfaceFinder->refind();
+ }
+
+ /**
* Callback function that is called when a Compatible interface is found.
*
* @param path D-Bus object path that implements the interface
diff --git a/dbus_interfaces_finder.hpp b/dbus_interfaces_finder.hpp
index db89e26..b74e88d 100644
--- a/dbus_interfaces_finder.hpp
+++ b/dbus_interfaces_finder.hpp
@@ -92,6 +92,22 @@
Callback callback);
/**
+ * Refind all instances of the interfaces specified in the constructor.
+ *
+ * The callback specified in the constructor will be called for each
+ * instance found.
+ *
+ * This method normally does not need to be called. New instances are
+ * automatically detected using an InterfacesAdded listener. However, this
+ * method may be useful if the caller is not currently receiving D-Bus
+ * signals (such as within a loop).
+ */
+ void refind()
+ {
+ findInterfaces();
+ }
+
+ /**
* Callback function to handle InterfacesAdded D-Bus signals
*
* @param message Expanded sdbusplus message data