PEL.Entry - Add managementSystemAck property

Add managementSystemAck property to PEL.Entry interface to support HMC
acknowledgement of event receipt.

Tested:
1. Created a PEL log using busctl and set-property managementSystemAck
to true. Verified that the flag is set by using peltool
 Result:(output of peltool)
    "Host Transmission":        "Not Sent",
    "HMC Transmission":         "Acked"
Restarted phosphor-log-manager and verified that the flag is true.

2. Generated PEL using RAWPEL and verified all the steps as in 1.

Change-Id: Ifa06cca0063c6c609317192f9c18bb2524e2f292
Signed-off-by: Vijay Lobo <vijaylobo@gmail.com>
diff --git a/extensions/openpower-pels/manager.cpp b/extensions/openpower-pels/manager.cpp
index 9ce9b98..df8e50c 100644
--- a/extensions/openpower-pels/manager.cpp
+++ b/extensions/openpower-pels/manager.cpp
@@ -18,6 +18,7 @@
 #include "additional_data.hpp"
 #include "json_utils.hpp"
 #include "pel.hpp"
+#include "pel_entry.hpp"
 #include "service_indicators.hpp"
 
 #include <fmt/format.h>
@@ -808,11 +809,16 @@
         varData.emplace(
             std::string("Subsystem"),
             pv::getValue(attr.subsystem, pel_values::subsystemValues));
+
+        varData.emplace(
+            std::string("ManagementSystemAck"),
+            (attr.hmcState == TransmissionState::acked ? true : false));
+
         // Path to create PELEntry Interface is same as PEL
         auto path = std::string(OBJ_ENTRY) + '/' + std::to_string(obmcLogID);
         // Create Interface for PELEntry and set properties
-        auto pelEntry = std::make_unique<PELEntry>(_logManager.getBus(),
-                                                   path.c_str(), varData);
+        auto pelEntry = std::make_unique<PELEntry>(_logManager.getBus(), path,
+                                                   varData, obmcLogID, &_repo);
         _pelEntries.emplace(std::move(path), std::move(pelEntry));
     }
 }
diff --git a/extensions/openpower-pels/manager.hpp b/extensions/openpower-pels/manager.hpp
index 5923f00..a9476d5 100644
--- a/extensions/openpower-pels/manager.hpp
+++ b/extensions/openpower-pels/manager.hpp
@@ -26,9 +26,6 @@
 using PELInterface = sdbusplus::server::object::object<
     sdbusplus::org::open_power::Logging::server::PEL>;
 
-using PELEntry = sdbusplus::org::open_power::Logging::PEL::server::Entry;
-using PropertiesVariant = PELEntry::PropertiesVariant;
-
 /**
  * @brief PEL manager object
  */
diff --git a/extensions/openpower-pels/meson.build b/extensions/openpower-pels/meson.build
index 1c8ba49..82e86c4 100644
--- a/extensions/openpower-pels/meson.build
+++ b/extensions/openpower-pels/meson.build
@@ -128,6 +128,7 @@
     'extended_user_data.cpp',
     'host_notifier.cpp',
     'manager.cpp',
+    'pel_entry.cpp',
     'pldm_interface.cpp',
     'repository.cpp',
     'src.cpp',
diff --git a/extensions/openpower-pels/pel_entry.cpp b/extensions/openpower-pels/pel_entry.cpp
new file mode 100644
index 0000000..403befd
--- /dev/null
+++ b/extensions/openpower-pels/pel_entry.cpp
@@ -0,0 +1,39 @@
+#include "pel_entry.hpp"

+

+#include <iostream>

+#include <xyz/openbmc_project/Common/error.hpp>

+

+namespace openpower

+{

+namespace pels

+{

+

+namespace common_error = sdbusplus::xyz::openbmc_project::Common::Error;

+

+bool PELEntry::managementSystemAck(bool value)

+{

+    auto current = sdbusplus::org::open_power::Logging::PEL::server::Entry::

+        managementSystemAck();

+    if (value != current)

+    {

+        current = sdbusplus::org::open_power::Logging::PEL::server::Entry::

+            managementSystemAck(value);

+

+        Repository::LogID id{Repository::LogID::Obmc(getMyId())};

+        if (auto logId = _repo->getLogID(id); logId.has_value())

+        {

+            // Update HMC acknowledge bit in PEL

+            _repo->setPELHMCTransState(

+                logId->pelID.id,

+                (value ? TransmissionState::acked : TransmissionState::newPEL));

+        }

+        else

+        {

+            throw common_error::InvalidArgument();

+        }

+    }

+    return current;

+}

+

+} // namespace pels

+} // namespace openpower

diff --git a/extensions/openpower-pels/pel_entry.hpp b/extensions/openpower-pels/pel_entry.hpp
new file mode 100644
index 0000000..7decb42
--- /dev/null
+++ b/extensions/openpower-pels/pel_entry.hpp
@@ -0,0 +1,68 @@
+#pragma once

+

+#include "manager.hpp"

+namespace openpower

+{

+namespace pels

+{

+

+using PELEntryIface = sdbusplus::org::open_power::Logging::PEL::server::Entry;

+using PropertiesVariant = PELEntryIface::PropertiesVariant;

+

+class PELEntry : public PELEntryIface

+{

+

+  public:

+    PELEntry() = delete;

+    PELEntry(const PELEntry&) = delete;

+    PELEntry& operator=(const PELEntry&) = delete;

+    PELEntry(PELEntry&&) = delete;

+    PELEntry& operator=(PELEntry&&) = delete;

+    virtual ~PELEntry() = default;

+

+    /** @brief Constructor to put an object onto the bus at a dbus path.

+     *  @param[in] bus - Bus to attach to.

+     *  @param[in] path - Path to attach at.

+     *  @param[in] prop - Default property values to be set when this interface

+     * is added to the bus.

+     *  @param[in] id - obmc id for this instance.

+     *  @param[in] repo - Repository pointer to lookup PEL to set appropriate

+     * attributes.

+     */

+

+    PELEntry(sdbusplus::bus::bus& bus, const std::string& path,

+             const std::map<std::string, PropertiesVariant>& prop, uint32_t id,

+             Repository* repo) :

+        PELEntryIface(bus, path.c_str(), prop),

+        _obmcId(id), _repo(repo)

+    {

+    }

+

+    /** @brief Update managementSystemAck flag.

+     *  @param[in] value - A true value says HMC acknowledged the PEL.

+     *  @returns New property value

+     */

+    bool managementSystemAck(bool value) override;

+

+    /**

+     * @brief Returns OpenBMC event log ID associated with this interface.

+     */

+    uint32_t getMyId(void) const

+    {

+        return _obmcId;

+    }

+

+  private:

+    /**

+     * @brief Corresponding OpenBMC event log id of this interface.

+     */

+    uint32_t _obmcId;

+

+    /**

+     * @brief Repository pointer to look for updating PEL fields.

+     */

+    Repository* _repo;

+};

+

+} // namespace pels

+} // namespace openpower
\ No newline at end of file
diff --git a/extensions/openpower-pels/user_header.cpp b/extensions/openpower-pels/user_header.cpp
index a1b6194..34e2fa1 100644
--- a/extensions/openpower-pels/user_header.cpp
+++ b/extensions/openpower-pels/user_header.cpp
@@ -230,12 +230,19 @@
         pv::getValuesBitwise(_actionFlags, pel_values::actionFlagsValues);
 
     std::string hostState{"Invalid"};
+    std::string hmcState{"Invalid"};
     auto iter = pv::transmissionStates.find(
         static_cast<TransmissionState>(hostTransmissionState()));
     if (iter != pv::transmissionStates.end())
     {
         hostState = iter->second;
     }
+    auto iter1 = pv::transmissionStates.find(
+        static_cast<TransmissionState>(hmcTransmissionState()));
+    if (iter1 != pv::transmissionStates.end())
+    {
+        hmcState = iter1->second;
+    }
 
     std::string uh;
     jsonInsert(uh, pv::sectionVer, getNumberString("%d", userHeaderVersion), 1);
@@ -248,6 +255,7 @@
     jsonInsert(uh, "Event Type", eventType, 1);
     jsonInsertArray(uh, "Action Flags", actionFlags, 1);
     jsonInsert(uh, "Host Transmission", hostState, 1);
+    jsonInsert(uh, "HMC Transmission", hmcState, 1);
     uh.erase(uh.size() - 2);
     return uh;
 }