Listener:Present property callback stub

This commit adds APIs in Listener to register "Present" property change
callback for all FRUs for which vpd-manager does not handle presence and
which are hot pluggable. If such a FRU is plugged in/removed,
vpd-manager needs to detect this and collect/delete the VPD of the FRU.
Note: this is a stub implementation, and actual implementation will be
handled in future commit(s).

Change-Id: Ib7edc633bc6395976f2f3d1e4b3c5f90a6b999bc
Signed-off-by: Souvik Roy <souvikroyofficial10@gmail.com>
diff --git a/vpd-manager/include/listener.hpp b/vpd-manager/include/listener.hpp
index 36904f0..719c21d 100644
--- a/vpd-manager/include/listener.hpp
+++ b/vpd-manager/include/listener.hpp
@@ -44,6 +44,14 @@
      */
     void registerAssetTagChangeCallback() const noexcept;
 
+    /**
+     * @brief API to register "Present" property change callback
+     *
+     * This API registers "Present" property change callback for FRUs for
+     * which "monitorPresence" is true in system config JSON.
+     */
+    void registerPresenceChangeCallback() noexcept;
+
   private:
     /**
      * @brief API to process host state change callback.
@@ -59,6 +67,14 @@
      */
     void assetTagChangeCallback(sdbusplus::message_t& i_msg) const noexcept;
 
+    /**
+     * @brief Callback API to be triggered on "Present" property change.
+     *
+     * @param[in] i_msg - Callback message.
+     */
+    void presentPropertyChangeCallback(
+        sdbusplus::message_t& i_msg) const noexcept;
+
     // Shared pointer to worker class
     const std::shared_ptr<Worker>& m_worker;
 
diff --git a/vpd-manager/oem-handler/ibm_handler.cpp b/vpd-manager/oem-handler/ibm_handler.cpp
index 293837f..45e8759 100644
--- a/vpd-manager/oem-handler/ibm_handler.cpp
+++ b/vpd-manager/oem-handler/ibm_handler.cpp
@@ -62,6 +62,7 @@
     m_eventListener = std::make_shared<Listener>(m_worker, m_asioConnection);
     m_eventListener->registerAssetTagChangeCallback();
     m_eventListener->registerHostStateChangeCallback();
+    m_eventListener->registerPresenceChangeCallback();
 
     // set async timer to detect if system VPD is published on D-Bus.
     SetTimerToDetectSVPDOnDbus();
diff --git a/vpd-manager/src/listener.cpp b/vpd-manager/src/listener.cpp
index 736d93a..a95be64 100644
--- a/vpd-manager/src/listener.cpp
+++ b/vpd-manager/src/listener.cpp
@@ -163,4 +163,56 @@
     }
 }
 
+void Listener::registerPresenceChangeCallback() noexcept
+{
+    try
+    {
+        /* TODO:
+            - iterate through all FRUs.
+            - if FRU is runtime replaceable and we do not handle presence for
+           the FRU, register a Present property change callback.
+        */
+    }
+    catch (const std::exception& l_ex)
+    {
+        EventLogger::createSyncPel(
+            EventLogger::getErrorType(l_ex), types::SeverityType::Warning,
+            __FILE__, __FUNCTION__, 0,
+            "Register presence change callback failed, reason: " +
+                std::string(l_ex.what()),
+            std::nullopt, std::nullopt, std::nullopt, std::nullopt);
+    }
+}
+
+void Listener::presentPropertyChangeCallback(
+    sdbusplus::message_t& i_msg) const noexcept
+{
+    try
+    {
+        if (i_msg.is_method_error())
+        {
+            throw DbusException(
+                "Error reading callback message for Present property change");
+        }
+
+        const auto& l_objectPath = i_msg.get_path();
+        (void)l_objectPath;
+        /*TODO:
+         - read "Present" property
+         - if "Present" property = true, trigger "collectSingleFruVpd" for the
+         FRU
+         - if "Present" property = false, trigger "deleteFruVpd" for the FRU
+        */
+    }
+    catch (const std::exception& l_ex)
+    {
+        EventLogger::createSyncPel(
+            EventLogger::getErrorType(l_ex), types::SeverityType::Warning,
+            __FILE__, __FUNCTION__, 0,
+            "Process presence change callback failed, reason: " +
+                std::string(l_ex.what()),
+            std::nullopt, std::nullopt, std::nullopt, std::nullopt);
+    }
+}
+
 } // namespace vpd