Implementation of deleteFRUVPD api

The api sets present property of given FRU as false.
If the present property is already set to false, it will
log error.

One of the use case:
This api is to be called before requesting VPD parser to
collect VPD of any given FRU in case of concurrent
maintenance.

Signed-off-by: Sunny Srivastava <sunnsr25@in.ibm.com>
Change-Id: Ibbe2eba34e586e02bcb0bec38945a81d1efe6109
diff --git a/vpd-manager/manager.cpp b/vpd-manager/manager.cpp
index 23e6290..4c8b416 100644
--- a/vpd-manager/manager.cpp
+++ b/vpd-manager/manager.cpp
@@ -12,6 +12,7 @@
 
 #include <filesystem>
 #include <phosphor-logging/elog-errors.hpp>
+#include <xyz/openbmc_project/Common/error.hpp>
 
 using namespace openpower::vpd::constants;
 using namespace openpower::vpd::inventory;
@@ -68,6 +69,11 @@
     interface->register_method("PerformVPDRecollection",
                                [this]() { this->performVPDRecollection(); });
 
+    interface->register_method(
+        "deleteFRUVPD", [this](const sdbusplus::message::object_path& path) {
+            this->deleteFRUVPD(path);
+        });
+
     sd_bus_default(&sdBus);
     initManager();
 }
@@ -585,6 +591,38 @@
     }
 }
 
+void Manager::deleteFRUVPD(const sdbusplus::message::object_path& path)
+{
+    using InvalidArgument =
+        sdbusplus::xyz::openbmc_project::Common::Error::InvalidArgument;
+    using Argument = xyz::openbmc_project::Common::InvalidArgument;
+
+    // if path not found in Json.
+    if (frus.find(path) == frus.end())
+    {
+        elog<InvalidArgument>(
+            Argument::ARGUMENT_NAME("Object Path"),
+            Argument::ARGUMENT_VALUE(std::string(path).c_str()));
+    }
+
+    // if the FRU is not present then log error
+    if (readBusProperty(path, "xyz.openbmc_project.Inventory.Item",
+                        "Present") == "false")
+    {
+        elog<InvalidArgument>(
+            Argument::ARGUMENT_NAME("FRU not preset"),
+            Argument::ARGUMENT_VALUE(std::string(path).c_str()));
+    }
+    else
+    {
+        inventory::ObjectMap objectMap = {
+            {path,
+             {{"xyz.openbmc_project.Inventory.Item", {{"Present", false}}}}}};
+
+        common::utility::callPIM(move(objectMap));
+    }
+}
+
 } // namespace manager
 } // namespace vpd
 } // namespace openpower
\ No newline at end of file