entity-manager: remove global io_context

Remove the global var
```
boost::asio::io_context io
```
and move it to be a local var in the main function.

Since boost::asio::io_context io is declared first, it in scope for the
entire program duration and should not cause any issues from that
perspective.

The io_context is passed through where needed. In case there is a class
already defined, the class now has a reference to the io_context to
avoid passing it through everywhere.

Tested: Capturing or passing a reference which is always valid should
not introduce any issues.

Tested on Tyan S8030:

```
Jul 01 09:59:26 s8030-bmc-30303035c0c1 entity-manager[4204]: Inventory Added: Supermicro PWS 920P SQ 0
Jul 01 09:59:26 s8030-bmc-30303035c0c1 entity-manager[4204]: Inventory Added: Supermicro PWS 920P SQ 1
Jul 01 09:59:26 s8030-bmc-30303035c0c1 entity-manager[4204]: Inventory Added: chassis
Jul 01 09:59:26 s8030-bmc-30303035c0c1 entity-manager[4204]: Inventory Added: MBX 1.57 Chassis
```

busctl tree output as before

Change-Id: Ie8f7d18c38d166c57a9cb645ab45c9103bbdff6e
Signed-off-by: Alexander Hansen <alexander.hansen@9elements.com>
diff --git a/src/entity_manager/perform_scan.cpp b/src/entity_manager/perform_scan.cpp
index 04d3c67..5e56f9c 100644
--- a/src/entity_manager/perform_scan.cpp
+++ b/src/entity_manager/perform_scan.cpp
@@ -44,7 +44,8 @@
 void getInterfaces(
     const DBusInterfaceInstance& instance,
     const std::vector<std::shared_ptr<probe::PerformProbe>>& probeVector,
-    const std::shared_ptr<scan::PerformScan>& scan, size_t retries = 5)
+    const std::shared_ptr<scan::PerformScan>& scan, boost::asio::io_context& io,
+    size_t retries = 5)
 {
     if (retries == 0U)
     {
@@ -54,8 +55,8 @@
     }
 
     scan->_em.systemBus->async_method_call(
-        [instance, scan, probeVector,
-         retries](boost::system::error_code& errc, const DBusInterface& resp) {
+        [instance, scan, probeVector, retries,
+         &io](boost::system::error_code& errc, const DBusInterface& resp) {
             if (errc)
             {
                 std::cerr << "error calling getall on  " << instance.busName
@@ -65,9 +66,9 @@
                 auto timer = std::make_shared<boost::asio::steady_timer>(io);
                 timer->expires_after(std::chrono::seconds(2));
 
-                timer->async_wait([timer, instance, scan, probeVector,
-                                   retries](const boost::system::error_code&) {
-                    getInterfaces(instance, probeVector, scan, retries - 1);
+                timer->async_wait([timer, instance, scan, probeVector, retries,
+                                   &io](const boost::system::error_code&) {
+                    getInterfaces(instance, probeVector, scan, io, retries - 1);
                 });
                 return;
             }
@@ -81,7 +82,7 @@
 static void processDbusObjects(
     std::vector<std::shared_ptr<probe::PerformProbe>>& probeVector,
     const std::shared_ptr<scan::PerformScan>& scan,
-    const GetSubTreeType& interfaceSubtree)
+    const GetSubTreeType& interfaceSubtree, boost::asio::io_context& io)
 {
     for (const auto& [path, object] : interfaceSubtree)
     {
@@ -98,7 +99,8 @@
                 // with the GetAll call to save some cycles.
                 if (!boost::algorithm::starts_with(iface, "org.freedesktop"))
                 {
-                    getInterfaces({busname, path, iface}, probeVector, scan);
+                    getInterfaces({busname, path, iface}, probeVector, scan,
+                                  io);
                 }
             }
         }
@@ -110,7 +112,8 @@
 void findDbusObjects(
     std::vector<std::shared_ptr<probe::PerformProbe>>&& probeVector,
     boost::container::flat_set<std::string>&& interfaces,
-    const std::shared_ptr<scan::PerformScan>& scan, size_t retries = 5)
+    const std::shared_ptr<scan::PerformScan>& scan, boost::asio::io_context& io,
+    size_t retries = 5)
 {
     // Filter out interfaces already obtained.
     for (const auto& [path, probeInterfaces] : scan->dbusProbeObjects)
@@ -127,9 +130,9 @@
 
     // find all connections in the mapper that expose a specific type
     scan->_em.systemBus->async_method_call(
-        [interfaces, probeVector{std::move(probeVector)}, scan,
-         retries](boost::system::error_code& ec,
-                  const GetSubTreeType& interfaceSubtree) mutable {
+        [interfaces, probeVector{std::move(probeVector)}, scan, retries,
+         &io](boost::system::error_code& ec,
+              const GetSubTreeType& interfaceSubtree) mutable {
             if (ec)
             {
                 if (ec.value() == ENOENT)
@@ -150,16 +153,16 @@
 
                 timer->async_wait(
                     [timer, interfaces{std::move(interfaces)}, scan,
-                     probeVector{std::move(probeVector)},
-                     retries](const boost::system::error_code&) mutable {
+                     probeVector{std::move(probeVector)}, retries,
+                     &io](const boost::system::error_code&) mutable {
                         findDbusObjects(std::move(probeVector),
-                                        std::move(interfaces), scan,
+                                        std::move(interfaces), scan, io,
                                         retries - 1);
                     });
                 return;
             }
 
-            processDbusObjects(probeVector, scan, interfaceSubtree);
+            processDbusObjects(probeVector, scan, interfaceSubtree, io);
         },
         "xyz.openbmc_project.ObjectMapper",
         "/xyz/openbmc_project/object_mapper",
@@ -191,12 +194,12 @@
     return std::to_string(std::hash<std::string>{}(probeName + device.dump()));
 }
 
-scan::PerformScan::PerformScan(EntityManager& em,
-                               nlohmann::json& missingConfigurations,
-                               std::list<nlohmann::json>& configurations,
-                               std::function<void()>&& callback) :
+scan::PerformScan::PerformScan(
+    EntityManager& em, nlohmann::json& missingConfigurations,
+    std::list<nlohmann::json>& configurations, boost::asio::io_context& io,
+    std::function<void()>&& callback) :
     _em(em), _missingConfigurations(missingConfigurations),
-    _configurations(configurations), _callback(std::move(callback))
+    _configurations(configurations), _callback(std::move(callback)), io(io)
 {}
 
 static void pruneRecordExposes(nlohmann::json& record)
@@ -608,7 +611,7 @@
     // probe vector stores a shared_ptr to each PerformProbe that cares
     // about a dbus interface
     findDbusObjects(std::move(dbusProbePointers),
-                    std::move(dbusProbeInterfaces), shared_from_this());
+                    std::move(dbusProbeInterfaces), shared_from_this(), io);
 }
 
 scan::PerformScan::~PerformScan()
@@ -616,7 +619,8 @@
     if (_passed)
     {
         auto nextScan = std::make_shared<PerformScan>(
-            _em, _missingConfigurations, _configurations, std::move(_callback));
+            _em, _missingConfigurations, _configurations, io,
+            std::move(_callback));
         nextScan->passedProbes = std::move(passedProbes);
         nextScan->dbusProbeObjects = std::move(dbusProbeObjects);
         nextScan->run();