host_pdr_handler: remove PDRs across boots

Remove PDRs (from the BMC's repo) received by the host when the host
powers off. This is because PDRs could change across host's boots.

Signed-off-by: Deepak Kodihalli <dkodihal@in.ibm.com>
Change-Id: I4a45edd26624068d21bf07099e8480ec7a8a3d0d
diff --git a/host_pdr_handler.cpp b/host_pdr_handler.cpp
index 389a492..17b0b88 100644
--- a/host_pdr_handler.cpp
+++ b/host_pdr_handler.cpp
@@ -12,6 +12,8 @@
 namespace pldm
 {
 
+using namespace pldm::utils;
+using namespace sdbusplus::bus::match::rules;
 using Json = nlohmann::json;
 namespace fs = std::filesystem;
 constexpr auto fruJson = "host_frus.json";
@@ -59,6 +61,26 @@
                       << e.what() << std::endl;
         }
     }
+
+    hostOffMatch = std::make_unique<sdbusplus::bus::match::match>(
+        pldm::utils::DBusHandler::getBus(),
+        propertiesChanged("/xyz/openbmc_project/state/host0",
+                          "xyz.openbmc_project.State.Host"),
+        [repo](sdbusplus::message::message& msg) {
+            DbusChangedProps props{};
+            std::string intf;
+            msg.read(intf, props);
+            const auto itr = props.find("CurrentHostState");
+            if (itr != props.end())
+            {
+                PropertyValue value = itr->second;
+                auto propVal = std::get<std::string>(value);
+                if (propVal == "xyz.openbmc_project.State.Host.HostState.Off")
+                {
+                    pldm_pdr_remove_remote_pdrs(repo);
+                }
+            }
+        });
 }
 
 void HostPDRHandler::fetchPDR(std::vector<uint32_t>&& recordHandles)