Add Rescan specific bus method

Add RescanBus method to rescan FRU on one specific bus.

Tested:
Insert a new PSU, Redfish can show correct FRU of this new PSU.

Signed-off-by: Cheng C Yang <cheng.c.yang@linux.intel.com>
Signed-off-by: James Feist <james.feist@linux.intel.com>
Change-Id: I6c4a69ce90609875cc619460ec531701e73ebf1f
diff --git a/src/FruDevice.cpp b/src/FruDevice.cpp
index 4d93fc1..68f1659 100644
--- a/src/FruDevice.cpp
+++ b/src/FruDevice.cpp
@@ -1164,6 +1164,51 @@
     }
 }
 
+void rescanOneBus(
+    BusMap& busmap, uint8_t busNum,
+    boost::container::flat_map<
+        std::pair<size_t, size_t>,
+        std::shared_ptr<sdbusplus::asio::dbus_interface>>& dbusInterfaceMap)
+{
+    fs::path busPath = fs::path("/dev/i2c-" + std::to_string(busNum));
+    if (!fs::exists(busPath))
+    {
+        std::cerr << "Unable to access i2c bus " << static_cast<int>(busNum)
+                  << "\n";
+        throw std::invalid_argument("Invalid Bus.");
+    }
+
+    std::vector<fs::path> i2cBuses;
+    i2cBuses.emplace_back(busPath);
+
+    for (auto& [pair, interface] : foundDevices)
+    {
+        if (pair.first == static_cast<size_t>(busNum))
+        {
+            objServer.remove_interface(interface);
+            foundDevices.erase(pair);
+        }
+    }
+
+    auto scan = std::make_shared<FindDevicesWithCallback>(
+        i2cBuses, busmap, [busNum, &busmap, &dbusInterfaceMap]() {
+            for (auto& busIface : dbusInterfaceMap)
+            {
+                if (busIface.first.first == static_cast<size_t>(busNum))
+                {
+                    objServer.remove_interface(busIface.second);
+                }
+            }
+            auto& devicemap = busmap[busNum];
+            for (auto& device : *devicemap)
+            {
+                AddFruObjectToDbus(device.second, dbusInterfaceMap,
+                                   static_cast<uint32_t>(busNum), device.first);
+            }
+        });
+    scan->run();
+}
+
 void rescanBusses(
     BusMap& busmap,
     boost::container::flat_map<
@@ -1259,6 +1304,10 @@
     iface->register_method("ReScan",
                            [&]() { rescanBusses(busMap, dbusInterfaceMap); });
 
+    iface->register_method("ReScanBus", [&](uint8_t bus) {
+        rescanOneBus(busMap, bus, dbusInterfaceMap);
+    });
+
     iface->register_method("GetRawFru", getFruInfo);
 
     iface->register_method("WriteFru", [&](const uint8_t bus,