PEL: Don't allow duplicate callouts

When adding callouts, check if the callout being added already exists.
If it does, don't add it and rather just update the priority of the
existing one to be the highest of the two.

Callouts are considered to be equal if their location code matches, or
if they have the same maintenance procedure, or if they have the same
symbolic FRU.

The change entails adding an operator== on the Callout object, as well
as an operator> so that the callout with the highest priority can be
determined.  Also use this new operator> in the sort of the callout list
that happens after a callout is added or changed.

Signed-off-by: Matt Spinler <spinler@us.ibm.com>
Change-Id: I5ee148cc12e92f67fb3da233c3615e9665e95355
diff --git a/extensions/openpower-pels/callouts.cpp b/extensions/openpower-pels/callouts.cpp
index 3ba3459..0cb1f7e 100644
--- a/extensions/openpower-pels/callouts.cpp
+++ b/extensions/openpower-pels/callouts.cpp
@@ -18,7 +18,6 @@
 #include <phosphor-logging/log.hpp>
 
 #include <algorithm>
-#include <map>
 
 namespace openpower
 {
@@ -53,28 +52,41 @@
 
 void Callouts::addCallout(std::unique_ptr<Callout> callout)
 {
-    if (_callouts.size() < maxNumberOfCallouts)
-    {
-        _callouts.push_back(std::move(callout));
+    bool shouldAdd = true;
 
-        _subsectionWordLength += _callouts.back()->flattenedSize() / 4;
-    }
-    else
+    // Check if there is already a callout for this FRU
+    auto it = std::ranges::find_if(
+        _callouts, [&callout](const auto& c) { return *callout == *c; });
+
+    // If the callout already exists, but the new one has a higher
+    // priority, change the existing callout's priority to this
+    // new value and don't add the new one.
+    if (it != _callouts.end())
     {
-        using namespace phosphor::logging;
-        log<level::INFO>("Dropping PEL callout because at max");
+        if (*callout > **it)
+        {
+            (*it)->setPriority(callout->priority());
+        }
+        shouldAdd = false;
     }
 
-    // Mapping including the  3 Medium levels as A,B and C
-    const std::map<std::uint8_t, int> priorities = {
-        {'H', 10}, {'M', 9}, {'A', 8}, {'B', 7}, {'C', 6}, {'L', 5}};
+    if (shouldAdd)
+    {
+        if (_callouts.size() < maxNumberOfCallouts)
+        {
+            _callouts.push_back(std::move(callout));
 
-    auto sortPriority = [&priorities](const std::unique_ptr<Callout>& p1,
-                                      const std::unique_ptr<Callout>& p2) {
-        return priorities.at(p1->priority()) > priorities.at(p2->priority());
-    };
+            _subsectionWordLength += _callouts.back()->flattenedSize() / 4;
+        }
+        else
+        {
+            using namespace phosphor::logging;
+            log<level::INFO>("Dropping PEL callout because at max");
+        }
+    }
 
-    std::sort(_callouts.begin(), _callouts.end(), sortPriority);
+    std::ranges::sort(_callouts,
+                      [](const auto& c1, const auto& c2) { return *c1 > *c2; });
 }
 
 } // namespace src