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)
diff --git a/host_pdr_handler.hpp b/host_pdr_handler.hpp
index fec6da6..850afdb 100644
--- a/host_pdr_handler.hpp
+++ b/host_pdr_handler.hpp
@@ -117,6 +117,8 @@
      *  association tree
      */
     std::map<EntityType, pldm_entity> parents;
+    /** @brief D-Bus property changed signal match */
+    std::unique_ptr<sdbusplus::bus::match::match> hostOffMatch;
 };
 
 } // namespace pldm
diff --git a/utils.hpp b/utils.hpp
index 830a97f..6ac282d 100644
--- a/utils.hpp
+++ b/utils.hpp
@@ -131,6 +131,8 @@
 using PropertyValue =
     std::variant<bool, uint8_t, int16_t, uint16_t, int32_t, uint32_t, int64_t,
                  uint64_t, double, std::string>;
+using DbusProp = std::string;
+using DbusChangedProps = std::map<DbusProp, PropertyValue>;
 
 /**
  * @brief The interface for DBusHandler