Make the dbushelper own its own bus handle.

The dbushelper implements an interface that should not be sdbusplus
specific. By making the implementation own the sdbusplus aspects, an
alternate implementation can be swapped in.

Signed-off-by: Patrick Venture <venture@google.com>
Change-Id: I4109772499421e2e6497a0fcad663ebbd1210a7c
diff --git a/dbus/dbuswrite.cpp b/dbus/dbuswrite.cpp
index 83e5cd1..a6b2835 100644
--- a/dbus/dbuswrite.cpp
+++ b/dbus/dbuswrite.cpp
@@ -21,6 +21,7 @@
 #include <phosphor-logging/log.hpp>
 #include <sdbusplus/bus.hpp>
 
+#include <exception>
 #include <iostream>
 #include <memory>
 #include <string>
@@ -33,16 +34,16 @@
 
 using namespace phosphor::logging;
 
-std::unique_ptr<WriteInterface>
-    DbusWritePercent::createDbusWrite(const std::string& path, int64_t min,
-                                      int64_t max, DbusHelperInterface& helper)
+std::unique_ptr<WriteInterface> DbusWritePercent::createDbusWrite(
+    const std::string& path, int64_t min, int64_t max,
+    std::unique_ptr<DbusHelperInterface> helper)
 {
     auto tempBus = sdbusplus::bus::new_system();
     std::string connectionName;
 
     try
     {
-        connectionName = helper.getService(tempBus, pwmInterface, path);
+        connectionName = helper->getService(tempBus, pwmInterface, path);
     }
     catch (const std::exception& e)
     {
@@ -89,14 +90,15 @@
 
 std::unique_ptr<WriteInterface>
     DbusWrite::createDbusWrite(const std::string& path, int64_t min,
-                               int64_t max, DbusHelperInterface& helper)
+                               int64_t max,
+                               std::unique_ptr<DbusHelperInterface> helper)
 {
     auto tempBus = sdbusplus::bus::new_system();
     std::string connectionName;
 
     try
     {
-        connectionName = helper.getService(tempBus, pwmInterface, path);
+        connectionName = helper->getService(tempBus, pwmInterface, path);
     }
     catch (const std::exception& e)
     {