Add performance improvement to LED group assertions

Consider the below scenario:

1) User turns on Identify_Fan_1, which results in Fan_1's LED to blink
2) Fan_1 is faulted resulting in Fan_1, EncFaultFront and EncFaultBack
   to be asserted.
3) User turuns off Identify_Fan_1. This should result in Fan_1 going
   back to SolidOn state since the Fan_1 is still faulted.

Current implementation handles #3 by first turning off Fan_1 LED and
then turning it back on. So this was adding extra dbus calls to the
actual LED manager and also this would mean that Group manager would
know the underlying LED implementation.

With this patch, Group Manager tells the physical manager to move to
SolidOn state directly from Blink and physical LED manager now has the
job of doing the actual turn off followed by turn on and thus hiding
the implementation locally.

Fixes openbmc/phosphor-led-manager#3

Change-Id: Ic961095d01e59ba39a841ce8b74bbcde8ddec1df
Signed-off-by: Vishwanatha Subbanna <vishwa@linux.vnet.ibm.com>
diff --git a/manager.cpp b/manager.cpp
index 8ed9852..f4b85c7 100644
--- a/manager.cpp
+++ b/manager.cpp
@@ -41,15 +41,13 @@
         desiredState.insert(grp->cbegin(), grp->cend());
     }
 
-    // Always Do execute Turn Off and then Turn on since we have the Blink
-    // taking priority over -on-
-    group ledsToDeAssert {};
-
+    // Has the LEDs that are either to be turned off -or- want a new assertion
+    group transient {};
     std::set_difference(currentState.begin(), currentState.end(),
                         desiredState.begin(), desiredState.end(),
-                        std::inserter(ledsToDeAssert, ledsToDeAssert.begin()));
+                        std::inserter(transient, transient.begin()));
 
-    if(ledsToDeAssert.size())
+    if(transient.size())
     {
         // We really do not want the Manager to know how a particular LED
         // transitions from State-A --> State-B and all this must be handled by
@@ -58,28 +56,37 @@
         // LEDs and then turning it back on and let the physical LED controller
         // handle that.
 
-        // I am still experimenting on the algo..
-        std::cout << "De asserting the LEDs" << std::endl;
-        for (const auto& it: ledsToDeAssert)
-        {
-            std::cout << "\t{" << it.name << "::" << it.action << "}"
-                               << std::endl;
-        }
-
         // If we previously had a FRU in ON state , and then if there was a
         // request to make it blink, the end state would now be blink.
         // If we either turn off blink / fault, then we need to go back to its
         // previous state.
-        group ledsToReAssert {};
+        group ledsUpdate {};
         std::set_intersection(desiredState.begin(), desiredState.end(),
-                              ledsToDeAssert.begin(), ledsToDeAssert.end(),
-                              std::inserter(ledsToReAssert, ledsToReAssert.begin()),
+                              transient.begin(), transient.end(),
+                              std::inserter(ledsUpdate, ledsUpdate.begin()),
                               ledComp);
 
-        if (ledsToReAssert.size())
+        if (ledsUpdate.size())
         {
             std::cout << "Asserting LEDs again" << std::endl;
-            for (const auto& it: ledsToReAssert)
+            for (const auto& it: ledsUpdate)
+            {
+                std::cout << "\t{" << it.name << "::" << it.action << "}"
+                          << std::endl;
+            }
+        }
+
+        // These LEDs are only to be De-Asserted.
+        group ledsDeAssert {};
+        std::set_difference(transient.begin(), transient.end(),
+                            ledsUpdate.begin(), ledsUpdate.end(),
+                            std::inserter(ledsDeAssert, ledsDeAssert.begin()),
+                            ledComp);
+
+        if (ledsDeAssert.size())
+        {
+            std::cout << "De-Asserting LEDs" << std::endl;
+            for (const auto& it: ledsDeAssert)
             {
                 std::cout << "\t{" << it.name << "::" << it.action << "}"
                           << std::endl;
@@ -88,15 +95,15 @@
     }
 
     // Turn on these
-    group ledsToAssert {};
+    group ledsAssert {};
     std::set_difference(desiredState.begin(), desiredState.end(),
                         currentState.begin(), currentState.end(),
-                        std::inserter(ledsToAssert, ledsToAssert.begin()));
+                        std::inserter(ledsAssert, ledsAssert.begin()));
 
-    if(ledsToAssert.size())
+    if(ledsAssert.size())
     {
         std::cout << "Asserting LEDs" << std::endl;
-        for (const auto& it: ledsToAssert)
+        for (const auto& it: ledsAssert)
         {
             std::cout << "\t{" << it.name << "::" << it.action << "}"
                       << std::endl;