fw-update : Optimize passing infra parameters

Refactor UpdateManager and DeviceUpdater to optimize passing the D-Bus event
loop handle, handler for requester and instance ID requester.

Signed-off-by: Tom Joseph <rushtotom@gmail.com>
Change-Id: I1860ffc49513d941af372423a197b1d42eda6e36
diff --git a/fw-update/device_updater.cpp b/fw-update/device_updater.cpp
index 63e4f73..9a46a15 100644
--- a/fw-update/device_updater.cpp
+++ b/fw-update/device_updater.cpp
@@ -15,7 +15,7 @@
 
 void DeviceUpdater::startFwUpdateFlow()
 {
-    auto instanceId = requester.getInstanceId(eid);
+    auto instanceId = updateManager->requester.getInstanceId(eid);
     // NumberOfComponents
     const auto& applicableComponents =
         std::get<ApplicableComponents>(fwDeviceIDRecord);
@@ -44,13 +44,13 @@
         sizeof(struct pldm_request_update_req) + compImgSetVerStrInfo.length);
     if (rc)
     {
-        requester.markFree(eid, instanceId);
+        updateManager->requester.markFree(eid, instanceId);
         std::cerr << "encode_request_update_req failed, EID=" << unsigned(eid)
                   << ", RC=" << rc << "\n";
         // Handle error scenario
     }
 
-    rc = handler.registerRequest(
+    rc = updateManager->handler.registerRequest(
         eid, instanceId, PLDM_FWUP, PLDM_REQUEST_UPDATE, std::move(request),
         std::move(std::bind_front(&DeviceUpdater::requestUpdate, this)));
     if (rc)
@@ -95,15 +95,16 @@
 
     // Optional fields DeviceMetaData and GetPackageData not handled
     pldmRequest = std::make_unique<sdeventplus::source::Defer>(
-        event, std::bind(&DeviceUpdater::sendPassCompTableRequest, this,
-                         componentIndex));
+        updateManager->event,
+        std::bind(&DeviceUpdater::sendPassCompTableRequest, this,
+                  componentIndex));
 }
 
 void DeviceUpdater::sendPassCompTableRequest(size_t offset)
 {
     pldmRequest.reset();
 
-    auto instanceId = requester.getInstanceId(eid);
+    auto instanceId = updateManager->requester.getInstanceId(eid);
     // TransferFlag
     const auto& applicableComponents =
         std::get<ApplicableComponents>(fwDeviceIDRecord);
@@ -166,13 +167,13 @@
         sizeof(pldm_pass_component_table_req) + compVerStrInfo.length);
     if (rc)
     {
-        requester.markFree(eid, instanceId);
+        updateManager->requester.markFree(eid, instanceId);
         std::cerr << "encode_pass_component_table_req failed, EID="
                   << unsigned(eid) << ", RC=" << rc << "\n";
         // Handle error scenario
     }
 
-    rc = handler.registerRequest(
+    rc = updateManager->handler.registerRequest(
         eid, instanceId, PLDM_FWUP, PLDM_PASS_COMPONENT_TABLE,
         std::move(request),
         std::move(std::bind_front(&DeviceUpdater::passCompTable, this)));
@@ -226,15 +227,17 @@
     {
         componentIndex = 0;
         pldmRequest = std::make_unique<sdeventplus::source::Defer>(
-            event, std::bind(&DeviceUpdater::sendUpdateComponentRequest, this,
-                             componentIndex));
+            updateManager->event,
+            std::bind(&DeviceUpdater::sendUpdateComponentRequest, this,
+                      componentIndex));
     }
     else
     {
         componentIndex++;
         pldmRequest = std::make_unique<sdeventplus::source::Defer>(
-            event, std::bind(&DeviceUpdater::sendPassCompTableRequest, this,
-                             componentIndex));
+            updateManager->event,
+            std::bind(&DeviceUpdater::sendPassCompTableRequest, this,
+                      componentIndex));
     }
 }
 
@@ -242,7 +245,7 @@
 {
     pldmRequest.reset();
 
-    auto instanceId = requester.getInstanceId(eid);
+    auto instanceId = updateManager->requester.getInstanceId(eid);
     const auto& applicableComponents =
         std::get<ApplicableComponents>(fwDeviceIDRecord);
     const auto& comp = compImageInfos[applicableComponents[offset]];
@@ -290,13 +293,13 @@
         sizeof(pldm_update_component_req) + compVerStrInfo.length);
     if (rc)
     {
-        requester.markFree(eid, instanceId);
+        updateManager->requester.markFree(eid, instanceId);
         std::cerr << "encode_update_component_req failed, EID=" << unsigned(eid)
                   << ", RC=" << rc << "\n";
         // Handle error scenario
     }
 
-    rc = handler.registerRequest(
+    rc = updateManager->handler.registerRequest(
         eid, instanceId, PLDM_FWUP, PLDM_UPDATE_COMPONENT, std::move(request),
         std::move(std::bind_front(&DeviceUpdater::updateComponent, this)));
     if (rc)
@@ -594,15 +597,16 @@
     {
         componentIndex = 0;
         pldmRequest = std::make_unique<sdeventplus::source::Defer>(
-            event,
+            updateManager->event,
             std::bind(&DeviceUpdater::sendActivateFirmwareRequest, this));
     }
     else
     {
         componentIndex++;
         pldmRequest = std::make_unique<sdeventplus::source::Defer>(
-            event, std::bind(&DeviceUpdater::sendUpdateComponentRequest, this,
-                             componentIndex));
+            updateManager->event,
+            std::bind(&DeviceUpdater::sendUpdateComponentRequest, this,
+                      componentIndex));
     }
 
     return response;
@@ -611,7 +615,7 @@
 void DeviceUpdater::sendActivateFirmwareRequest()
 {
     pldmRequest.reset();
-    auto instanceId = requester.getInstanceId(eid);
+    auto instanceId = updateManager->requester.getInstanceId(eid);
     Request request(sizeof(pldm_msg_hdr) +
                     sizeof(struct pldm_activate_firmware_req));
     auto requestMsg = reinterpret_cast<pldm_msg*>(request.data());
@@ -621,12 +625,12 @@
         sizeof(pldm_activate_firmware_req));
     if (rc)
     {
-        requester.markFree(eid, instanceId);
+        updateManager->requester.markFree(eid, instanceId);
         std::cerr << "encode_activate_firmware_req failed, EID="
                   << unsigned(eid) << ", RC=" << rc << "\n";
     }
 
-    rc = handler.registerRequest(
+    rc = updateManager->handler.registerRequest(
         eid, instanceId, PLDM_FWUP, PLDM_ACTIVATE_FIRMWARE, std::move(request),
         std::move(std::bind_front(&DeviceUpdater::activateFirmware, this)));
     if (rc)