Add interface exposing utility functions
Add utility functions enabling easy method calls on sdbusplus interface
binding objects.
Change-Id: Ie1d01f82604406705869fea0ec19d84c95d90474
Signed-off-by: Brad Bishop <bradleyb@fuzziesquirrel.com>
diff --git a/manager.hpp b/manager.hpp
index 92afd9f..6326336 100644
--- a/manager.hpp
+++ b/manager.hpp
@@ -116,6 +116,48 @@
sdbusplus::bus::bus &, const char *);
using Makers = std::map<std::string, MakerType>;
+ /** @brief Provides weak references to interface holders.
+ *
+ * Common code for all types for the templated getInterface
+ * methods.
+ *
+ * @param[in] path - The DBus path for which the interface
+ * holder instance should be provided.
+ * @param[in] interface - The DBus interface for which the
+ * holder instance should be provided.
+ *
+ * @returns A weak reference to the holder instance.
+ */
+ details::holder::Base& getInterfaceHolder(
+ const char *, const char *) const;
+ details::holder::Base& getInterfaceHolder(
+ const char *, const char *);
+
+ /** @brief Provides weak references to interface holders.
+ *
+ * @tparam T - The sdbusplus server binding interface type.
+ *
+ * @param[in] path - The DBus path for which the interface
+ * should be provided.
+ * @param[in] interface - The DBus interface to obtain.
+ *
+ * @returns A weak reference to the interface holder.
+ */
+ template<typename T>
+ auto& getInterface(const char *path, const char *interface)
+ {
+ auto &holder = getInterfaceHolder(path, interface);
+ return static_cast<
+ details::holder::Holder<T> &>(holder);
+ }
+ template<typename T>
+ auto& getInterface(const char *path, const char *interface) const
+ {
+ auto &holder = getInterfaceHolder(path, interface);
+ return static_cast<
+ const details::holder::Holder<T> &>(holder);
+ }
+
/** @brief Provided for testing only. */
bool _shutdown;