oem ibm: infrastructure for oem handlers

1. This commit adds the framework for an oem handler
which can be used by specific oem use-cases
for implementing various commands.

2. This commit adds implementation for getStateSensorReadings
and setStateEffecterStates commands for oem state sets.

3. Also adds implementation for inband code update.

Change-Id: Ib38a66ee381dd06b93f6a9313d51de1c23e6ee65
Signed-off-by: Sampa Misra <sampmisr@in.ibm.com>
diff --git a/oem/ibm/libpldmresponder/inband_code_update.hpp b/oem/ibm/libpldmresponder/inband_code_update.hpp
new file mode 100644
index 0000000..6607de0
--- /dev/null
+++ b/oem/ibm/libpldmresponder/inband_code_update.hpp
@@ -0,0 +1,128 @@
+#pragma once
+
+#include "common/utils.hpp"
+#include "libpldmresponder/platform.hpp"
+
+#include <string>
+
+using namespace pldm::utils;
+namespace pldm
+{
+namespace responder
+{
+
+static constexpr uint8_t pSideNum = 1;
+static constexpr uint8_t tSideNum = 2;
+static constexpr auto Pside = "P";
+static constexpr auto Tside = "T";
+
+static constexpr auto redundancyIntf =
+    "xyz.openbmc_project.Software.RedundancyPriority";
+
+/** @class CodeUpdate
+ *
+ *  @brief This class performs the necessary operation in pldm for
+ *         inband code update. That includes taking actions on the
+ *         setStateEffecterStates calls from Host and also sending
+ *         notification to phosphor-software-manager app
+ */
+class CodeUpdate
+{
+  public:
+    /** @brief Constructor to create an inband codeupdate object
+     *  @param[in] dBusIntf - D-Bus handler pointer
+     */
+    CodeUpdate(const pldm::utils::DBusHandler* dBusIntf) : dBusIntf(dBusIntf)
+    {
+        currBootSide = Tside;
+        nextBootSide = Tside;
+    }
+
+    /* @brief Method to return the current boot side
+     */
+    std::string fetchCurrentBootSide();
+
+    /* @brief Method to return the next boot side
+     */
+    std::string fetchNextBootSide();
+
+    /* @brief Method to set the current boot side or
+     *        perform a rename operation on current boot side
+     * @param[in] currSide - current side to be set to
+     * @return PLDM_SUCCESS codes
+     */
+    int setCurrentBootSide(const std::string& currSide);
+
+    /* @brief Method to set the next boot side
+     * @param[in] nextSide - next boot side to be set to
+     * @return PLDM_SUCCESS codes
+     */
+    int setNextBootSide(const std::string& nextSide);
+
+    /* @brief Method to set the running and non-running
+     *        images
+     */
+    virtual void setVersions();
+
+    /* @brief Method to return the newly upoaded image id in
+     *        /tmp
+     */
+    std::string fetchnewImageId()
+    {
+        return newImageId;
+    }
+
+    /* @brief Method to set the oem platform handler in CodeUpdate class */
+    void setOemPlatformHandler(pldm::responder::oem_platform::Handler* handler);
+
+    virtual ~CodeUpdate()
+    {}
+
+  private:
+    std::string currBootSide;      //!< current boot side
+    std::string nextBootSide;      //!< next boot side
+    std::string runningVersion;    //!< currently running image
+    std::string nonRunningVersion; //!< alternate image
+    std::string newImageId;        //!< new image id
+    bool codeUpdateInProgress =
+        false; //!< indicates whether codeupdate is going on
+    const pldm::utils::DBusHandler* dBusIntf; //!< D-Bus handler
+    std::vector<std::unique_ptr<sdbusplus::bus::match::match>>
+        captureNextBootSideChange; //!< vector to catch the D-Bus property
+                                   //!< change for next boot side
+    std::unique_ptr<sdbusplus::bus::match::match>
+        fwUpdateMatcher; //!< pointer to capture the interface added signal for
+                         //!< new image
+    pldm::responder::oem_platform::Handler*
+        oemPlatformHandler; //!< oem platform handler
+
+    /* @brief Method to take action when the subscribed D-Bus property is
+     *        changed
+     * @param[in] chProperties - list of properties which have changed
+     * @return - none
+     */
+
+    void
+        processPriorityChangeNotification(const DbusChangedProps& chProperties);
+};
+
+/* @brief Method to fetch current or next boot side
+ * @param[in] entityInstance - entity instance for the sensor
+ * @param[in] codeUpdate - pointer to the CodeUpdate object
+ *
+ * @return - boot side
+ */
+uint8_t fetchBootSide(uint16_t entityInstance, CodeUpdate* codeUpdate);
+
+/* @brief Method to set current or next  boot side
+ * @param[in] entityInstance - entity instance for the effecter
+ * @param[in] currState - state to be set
+ * @param[in] stateField - state field set as sent by Host
+ * @return - PLDM_SUCCESS codes
+ */
+int setBootSide(uint16_t entityInstance, uint8_t currState,
+                const std::vector<set_effecter_state_field>& stateField,
+                CodeUpdate* codeUpdate);
+
+} // namespace responder
+} // namespace pldm