dump transfer: set offloaded property

Signed-off-by: Deepak Kodihalli <dkodihal@in.ibm.com>
Change-Id: Idb457d866eb9e6bedeaa77d60545f0e29c4bc9aa
diff --git a/oem/ibm/libpldmresponder/file_io_type_dump.cpp b/oem/ibm/libpldmresponder/file_io_type_dump.cpp
index 2360733..9fe270a 100644
--- a/oem/ibm/libpldmresponder/file_io_type_dump.cpp
+++ b/oem/ibm/libpldmresponder/file_io_type_dump.cpp
@@ -16,6 +16,8 @@
 #include "libpldm/base.h"
 #include "oem/ibm/libpldm/file_io.h"
 
+using namespace pldm::utils;
+
 namespace pldm
 {
 namespace responder
@@ -106,5 +108,60 @@
     return PLDM_SUCCESS;
 }
 
+int DumpHandler::fileAck(uint8_t /*fileStatus*/)
+{
+    if (DumpHandler::fd >= 0)
+    {
+        static constexpr auto dumpObjPath = "/xyz/openbmc_project/dump";
+        static constexpr auto MAPPER_BUSNAME =
+            "xyz.openbmc_project.ObjectMapper";
+        static constexpr auto MAPPER_PATH =
+            "/xyz/openbmc_project/object_mapper";
+        static constexpr auto MAPPER_INTERFACE =
+            "xyz.openbmc_project.ObjectMapper";
+        static constexpr auto systemDumpEntry =
+            "xyz.openbmc_project.Dump.Entry.System";
+        static constexpr auto dumpEntry = "xyz.openbmc_project.Dump.Entry";
+        auto& bus = pldm::utils::DBusHandler::getBus();
+
+        try
+        {
+            std::vector<std::string> paths;
+            auto method =
+                bus.new_method_call(MAPPER_BUSNAME, MAPPER_PATH,
+                                    MAPPER_INTERFACE, "GetSubTreePaths");
+            method.append(dumpObjPath);
+            method.append(0);
+            method.append(std::vector<std::string>({systemDumpEntry}));
+            auto reply = bus.call(method);
+            reply.read(paths);
+            for (auto path : paths)
+            {
+                uint32_t dumpId =
+                    pldm::utils::DBusHandler().getDbusProperty<uint32_t>(
+                        path.c_str(), "SourceDumpId", systemDumpEntry);
+                if (dumpId == fileHandle)
+                {
+                    PropertyValue value{true};
+                    DBusMapping dbusMapping{path, dumpEntry, "Offloaded",
+                                            "bool"};
+                    pldm::utils::DBusHandler().setDbusProperty(dbusMapping,
+                                                               value);
+                    close(DumpHandler::fd);
+                    DumpHandler::fd = -1;
+                    return PLDM_SUCCESS;
+                }
+            }
+        }
+        catch (const std::exception& e)
+        {
+            std::cerr << "failed to make a d-bus call to DUMP manager, ERROR="
+                      << e.what() << "\n";
+        }
+    }
+
+    return PLDM_ERROR;
+}
+
 } // namespace responder
 } // namespace pldm