presence: Use new sdbusplus wrapper

Use the sdbusplus wrapper methods introduced previously.

Change-Id: Ifd431753e9513436a9b5ab98cc49d907a5929c20
Signed-off-by: Brad Bishop <bradleyb@fuzziesquirrel.com>
diff --git a/presence/fan_enclosure.cpp b/presence/fan_enclosure.cpp
index 7b412bd..0d19e60 100644
--- a/presence/fan_enclosure.cpp
+++ b/presence/fan_enclosure.cpp
@@ -16,6 +16,7 @@
 #include <algorithm>
 #include <phosphor-logging/log.hpp>
 #include "fan_enclosure.hpp"
+#include "sdbusplus.hpp"
 #include "utility.hpp"
 
 namespace phosphor
@@ -26,10 +27,11 @@
 {
 
 using namespace phosphor::logging;
+using namespace std::literals::string_literals;
 
 //TODO Should get these from phosphor-inventory-manager config.h
-constexpr auto INVENTORY_PATH = "/xyz/openbmc_project/inventory";
-constexpr auto INVENTORY_INTF = "xyz.openbmc_project.Inventory.Manager";
+const auto INVENTORY_PATH = "/xyz/openbmc_project/inventory"s;
+const auto INVENTORY_INTF = "xyz.openbmc_project.Inventory.Manager"s;
 
 presenceState FanEnclosure::getCurPresState()
 {
@@ -63,24 +65,12 @@
     // Only update inventory when presence state changed
     if (presState != curPresState)
     {
-        // Get inventory object for this fan
-        ObjectMap invObj = getObjectMap(curPresState);
-        // Get inventory manager service name from mapper
-        std::string invService;
-        invService = phosphor::fan::util::getInvService(bus);
         // Update inventory for this fan
-        auto invMsg = bus.new_method_call(invService.c_str(),
-                                          INVENTORY_PATH,
-                                          INVENTORY_INTF,
-                                          "Notify");
-        invMsg.append(std::move(invObj));
-        auto invMgrResponseMsg = bus.call(invMsg);
-        if (invMgrResponseMsg.is_method_error())
-        {
-            log<level::ERR>(
-                "Error in inventory manager call to update inventory");
-            return;
-        }
+        util::SDBusPlus::lookupAndCallMethod(
+                INVENTORY_PATH,
+                INVENTORY_INTF,
+                "Notify"s,
+                getObjectMap(curPresState));
         // Inventory updated, set presence state to current
         presState = curPresState;
     }
diff --git a/presence/fan_enclosure.hpp b/presence/fan_enclosure.hpp
index 8f5cfdf..8e6925a 100644
--- a/presence/fan_enclosure.hpp
+++ b/presence/fan_enclosure.hpp
@@ -1,7 +1,7 @@
 #pragma once
 
-#include <sdbusplus/bus.hpp>
 #include "fan_properties.hpp"
+#include "sdbusplus.hpp"
 #include "sensor_base.hpp"
 
 
@@ -53,12 +53,9 @@
         /**
          * @brief Constructs Fan Enclosure Object
          *
-         * @param[in] bus - Dbus bus object
          * @param[in] fanProp - Fan enclosure properties
          */
-        FanEnclosure(sdbusplus::bus::bus& bus,
-                     const phosphor::fan::Properties& fanProp) :
-                        bus(bus),
+        explicit FanEnclosure(const phosphor::fan::Properties& fanProp) :
                         invPath(std::get<0>(fanProp)),
                         fanDesc(std::get<1>(fanProp))
         {
@@ -80,8 +77,6 @@
             std::unique_ptr<Sensor>&& sensor);
 
     private:
-        /** @brief Connection for sdbusplus bus */
-        sdbusplus::bus::bus& bus;
         /** @brief Inventory path for this fan enclosure */
         const std::string invPath;
         /** @brief Description used as 'PrettyName' on inventory object */
diff --git a/presence/tach_detect.cpp b/presence/tach_detect.cpp
index 2449f82..dc6356a 100644
--- a/presence/tach_detect.cpp
+++ b/presence/tach_detect.cpp
@@ -14,16 +14,14 @@
  * limitations under the License.
  */
 #include <vector>
-#include <sdbusplus/bus.hpp>
 #include "fan_enclosure.hpp"
 #include "fan_detect_defs.hpp"
+#include "sdbusplus.hpp"
 #include "tach_sensor.hpp"
 
 
 int main(void)
 {
-    auto bus = sdbusplus::bus::new_default();
-
     std::vector<std::unique_ptr<phosphor::fan::presence::FanEnclosure>> fans;
 
     for (auto const& detectMap: fanDetectMap)
@@ -33,13 +31,11 @@
             for (auto const& fanProp: detectMap.second)
             {
                 auto fan = std::make_unique<
-                    phosphor::fan::presence::FanEnclosure>(bus,
-                                                           fanProp);
+                    phosphor::fan::presence::FanEnclosure>(fanProp);
                 for (auto const &fanSensor: std::get<2>(fanProp))
                 {
                     auto sensor = std::make_unique<
-                        phosphor::fan::presence::TachSensor>(bus,
-                                                             fanSensor,
+                        phosphor::fan::presence::TachSensor>(fanSensor,
                                                              *fan);
                     fan->addSensor(std::move(sensor));
                 }
@@ -50,9 +46,10 @@
 
     while (true)
     {
+        using namespace phosphor::fan::util;
         // Respond to dbus signals
-        bus.process_discard();
-        bus.wait();
+        SDBusPlus::getBus().process_discard();
+        SDBusPlus::getBus().wait();
     }
     return 0;
 }
diff --git a/presence/tach_sensor.hpp b/presence/tach_sensor.hpp
index 3de5d69..47d2098 100644
--- a/presence/tach_sensor.hpp
+++ b/presence/tach_sensor.hpp
@@ -1,7 +1,7 @@
 #pragma once
 
-#include <sdbusplus/bus.hpp>
 #include <sdbusplus/server.hpp>
+#include "sdbusplus.hpp"
 #include "sensor_base.hpp"
 
 
@@ -33,17 +33,14 @@
         /**
          * @brief Constructs Tach Sensor Object
          *
-         * @param[in] bus - Dbus bus object
          * @param[in] id - ID name of this sensor
          * @param[in] fanEnc - Reference to the fan enclosure with this sensor
          */
         TachSensor(
-            sdbusplus::bus::bus& bus,
             const std::string& id,
             FanEnclosure& fanEnc) :
                 Sensor(id, fanEnc),
-                bus(bus),
-                tachSignal(bus,
+                tachSignal(util::SDBusPlus::getBus(),
                            match(id).c_str(),
                            std::bind(
                                std::mem_fn(&TachSensor::handleTachChange),
@@ -61,8 +58,6 @@
         bool isPresent();
 
     private:
-        /** @brief Connection for sdbusplus bus */
-        sdbusplus::bus::bus& bus;
         /** @brief Used to subscribe to dbus signals */
         sdbusplus::server::match::match tachSignal;
         /** @brief Tach speed value given from the signal */