Trigger VPD recollection at standby

This commit implement changes to trigger VPD collection at
standby for FRUs which can be replaced at standby.

The recollection is trigerred when the Host current state is
set to "TransitioningToRunning". Implies the state between
Bmc standby state and Host running state.

signed-off-by: Sunny Srivastava <sunnsr25@in.ibm.com>
Change-Id: I9296c80df856afe9a9b1c64a5a01cb3727af5e3c
diff --git a/vpd-manager/manager.cpp b/vpd-manager/manager.cpp
index d05dd69..036f843 100644
--- a/vpd-manager/manager.cpp
+++ b/vpd-manager/manager.cpp
@@ -40,6 +40,7 @@
     try
     {
         processJSON();
+        listenHostState();
 
         auto event = sdeventplus::Event::get_default();
         GpioMonitor gpioMon1(jsonFile, event);
@@ -54,6 +55,48 @@
     }
 }
 
+void Manager::listenHostState()
+{
+    static std::shared_ptr<sdbusplus::bus::match::match> hostState =
+        std::make_shared<sdbusplus::bus::match::match>(
+            _bus,
+            sdbusplus::bus::match::rules::propertiesChanged(
+                "/xyz/openbmc_project/state/host0",
+                "xyz.openbmc_project.State.Host"),
+            [this](sdbusplus::message::message& msg) {
+                hostStateCallBack(msg);
+            });
+}
+
+void Manager::hostStateCallBack(sdbusplus::message::message& msg)
+{
+    if (msg.is_method_error())
+    {
+        std::cerr << "Error in reading signal " << std::endl;
+    }
+
+    Path object;
+    PropertyMap propMap;
+    msg.read(object, propMap);
+    const auto itr = propMap.find("CurrentHostState");
+    if (itr != propMap.end())
+    {
+        if (auto hostState = std::get_if<std::string>(&(itr->second)))
+        {
+            // implies system is moving from standby to power on state
+            if (*hostState == "xyz.openbmc_project.State.Host.HostState."
+                              "TransitioningToRunning")
+            {
+                // check and perfrom recollection for FRUs replaceable at
+                // standby.
+                performVPDRecollection();
+                return;
+            }
+        }
+        std::cerr << "Failed to read Host state" << std::endl;
+    }
+}
+
 void Manager::processJSON()
 {
     std::ifstream json(INVENTORY_JSON_SYM_LINK, std::ios::binary);
@@ -99,7 +142,7 @@
                         .get_ref<const nlohmann::json::string_t&>());
             }
 
-            if (itemEEPROM.value("isReplaceable", false))
+            if (itemEEPROM.value("replaceableAtStandby", false))
             {
                 replaceableFrus.emplace_back(itemFRUS.key());
             }