Enhance precondition function and tracing

Replace count_if with all_of in the property states match precondition
to stop iterating over the group members once a property state does not
match.

Include additional debug tracing when the precondition passes and fails
to help in determining where the precondition causes fans to be at full
speed.

Tested:
    Verify debug traces align with precondition state

Change-Id: I1c3d8f096a645ac3bfcdfb7b9197682cf7ca52a0
Signed-off-by: Matthew Barth <msbarth@us.ibm.com>
diff --git a/control/preconditions.hpp b/control/preconditions.hpp
index f989f0d..1423ac0 100644
--- a/control/preconditions.hpp
+++ b/control/preconditions.hpp
@@ -1,6 +1,7 @@
 #pragma once
 
 #include <algorithm>
+#include <phosphor-logging/log.hpp>
 
 namespace phosphor
 {
@@ -11,6 +12,8 @@
 namespace precondition
 {
 
+using namespace phosphor::logging;
+
 /**
  * @brief A precondition to compare a group of property values and
  * subscribe/unsubscribe a set speed event group
@@ -34,7 +37,7 @@
             sse = std::move(sse)](auto& zone, auto& group)
     {
         // Compare given precondition entries
-        size_t precondState = std::count_if(
+        auto precondState = std::all_of(
             pg.begin(),
             pg.end(),
             [&zone](auto const& entry)
@@ -54,8 +57,11 @@
                 }
             });
 
-        if (precondState == pg.size())
+        if (precondState)
         {
+            log<level::DEBUG>(
+                "Preconditions passed, init the associated events",
+                entry("EVENT_COUNT=%u", sse.size()));
             // Init the events when all the precondition(s) are true
             std::for_each(
                 sse.begin(),
@@ -67,6 +73,9 @@
         }
         else
         {
+            log<level::DEBUG>(
+                "Preconditions not met for events, events removed if present",
+                entry("EVENT_COUNT=%u", sse.size()));
             // Unsubscribe the events' signals when any precondition is false
             std::for_each(
                 sse.begin(),
@@ -78,7 +87,7 @@
             zone.setFullSpeed();
         }
         // Update group's fan control active allowed
-        zone.setActiveAllow(&group, (precondState == pg.size()));
+        zone.setActiveAllow(&group, precondState);
     };
 }