update: use sdbusplus instead of sd_bus raw pointers

Update code to use sdbusplus instead of raw sd_bus pointers.

Change-Id: I80cd4492480824827c27fbf19eb54487e28d3b75
Signed-off-by: Patrick Venture <venture@google.com>
diff --git a/readeeprom.cpp b/readeeprom.cpp
index a9dd91d..d518a83 100644
--- a/readeeprom.cpp
+++ b/readeeprom.cpp
@@ -25,9 +25,6 @@
     int rc = 0;
     uint8_t fruid = 0;
 
-    // Handle to per process system bus
-    sd_bus* bus_type = NULL;
-
     // Read the arguments.
     auto cli_options = std::make_unique<ArgumentParser>(argc, argv);
 
@@ -57,23 +54,11 @@
     // Finished getting options out, so release the parser.
     cli_options.release();
 
-    // Get a handle to System Bus
-    rc = sd_bus_open_system(&bus_type);
-    if (rc < 0)
-    {
-        log<level::ERR>("Failed to connect to system bus",
-                        entry("ERRNO=%s", std::strerror(-rc)));
-    }
-    else
-    {
-        // Now that we have the file that contains the eeprom data, go read it
-        // and update the Inventory DB.
-        bool bmc_fru = true;
-        rc = validateFRUArea(fruid, eeprom_file.c_str(), bus_type, bmc_fru);
-    }
-
-    // Cleanup
-    sd_bus_unref(bus_type);
+    // Now that we have the file that contains the eeprom data, go read it
+    // and update the Inventory DB.
+    auto bus = sdbusplus::bus::new_default();
+    bool bmc_fru = true;
+    rc = validateFRUArea(fruid, eeprom_file.c_str(), bus, bmc_fru);
 
     return (rc < 0 ? EXIT_FAILURE : EXIT_SUCCESS);
 }
diff --git a/strgfnhandler.cpp b/strgfnhandler.cpp
index a00fc73..9526525 100644
--- a/strgfnhandler.cpp
+++ b/strgfnhandler.cpp
@@ -6,6 +6,7 @@
 #include <cstdio>
 #include <cstring>
 #include <phosphor-logging/log.hpp>
+#include <sdbusplus/bus.hpp>
 
 void register_netfn_storage_write_fru() __attribute__((constructor));
 
@@ -100,8 +101,9 @@
 
     // We received some bytes. It may be full or partial. Send a valid
     // FRU file to the inventory controller on DBus for the correct number
+    sdbusplus::bus::bus bus{bus_type};
     bool bmc_fru = false;
-    validateFRUArea(reqptr->frunum, fru_file_name, bus_type, bmc_fru);
+    validateFRUArea(reqptr->frunum, fru_file_name, bus, bmc_fru);
 
     return rc;
 }
diff --git a/writefrudata.cpp b/writefrudata.cpp
index 4fbbf72..02cff5f 100644
--- a/writefrudata.cpp
+++ b/writefrudata.cpp
@@ -144,7 +144,7 @@
 // Takes FRU data, invokes Parser for each fru record area and updates
 // Inventory
 //------------------------------------------------------------------------
-int updateInventory(FruAreaVector& area_vec, sd_bus* bus_sd)
+int updateInventory(FruAreaVector& area_vec, sdbusplus::bus::bus& bus)
 {
     // Generic error reporter
     int rc = 0;
@@ -173,7 +173,6 @@
 
     // Here we are just printing the object,interface and the properties.
     // which needs to be called with the new inventory manager implementation.
-    sdbusplus::bus::bus bus{bus_sd};
     using namespace std::string_literals;
     static const auto intf = "xyz.openbmc_project.Inventory.Manager"s;
     static const auto path = "/xyz/openbmc_project/inventory"s;
@@ -514,7 +513,7 @@
 // Accepts the filename and validates per IPMI FRU spec
 //----------------------------------------------------
 int validateFRUArea(const uint8_t fruid, const char* fru_file_name,
-                    sd_bus* bus_type, const bool bmc_fru)
+                    sdbusplus::bus::bus& bus, const bool bmc_fru)
 {
     size_t data_len = 0;
     size_t bytes_read = 0;
@@ -615,7 +614,7 @@
 #ifdef __IPMI_DEBUG__
         std::printf("\n SIZE of vector is : [%d] \n", fru_area_vec.size());
 #endif
-        rc = updateInventory(fru_area_vec, bus_type);
+        rc = updateInventory(fru_area_vec, bus);
         if (rc < 0)
         {
             log<level::ERR>("Error updating inventory.");
diff --git a/writefrudata.hpp b/writefrudata.hpp
index e713bd5..072d4d3 100644
--- a/writefrudata.hpp
+++ b/writefrudata.hpp
@@ -1,7 +1,7 @@
 #ifndef __IPMI_WRITE_FRU_DATA_H__
 #define __IPMI_WRITE_FRU_DATA_H__
 
-#include <systemd/sd-bus.h>
+#include <sdbusplus/bus.hpp>
 
 // IPMI commands for Storage net functions.
 enum ipmi_netfn_storage_cmds
@@ -46,10 +46,10 @@
  *
  * @param[in] fruid - The ID to use for this FRU.
  * @param[in] fru_file_name - the filename of the FRU.
- * @param[in] bus_type - a systemd bus for publishing the information.
+ * @param[in] bus - an sdbusplus systemd bus for publishing the information.
  * @param[in] bmc_fru - If a particular area accessible only by BMC.
  */
 int validateFRUArea(const uint8_t fruid, const char* fru_file_name,
-                    sd_bus* bus_type, const bool bmc_fru);
+                    sdbusplus::bus::bus& bus, const bool bmc_fru);
 
 #endif