Add missing owner services precondition

Change-Id: Iccd29359ff46084d96df655e0761c86ecfabd567
Signed-off-by: Matthew Barth <msbarth@us.ibm.com>
diff --git a/control/preconditions.cpp b/control/preconditions.cpp
index b2bd420..cd404d1 100644
--- a/control/preconditions.cpp
+++ b/control/preconditions.cpp
@@ -75,6 +75,46 @@
     };
 }
 
+Action services_missing_owner(std::vector<SetSpeedEvent>&& sse)
+{
+    return [sse = std::move(sse)](auto& zone, auto& group)
+    {
+        // Set/update the services of the group
+        zone.setServices(&group);
+        const auto& services = zone.getGroupServices(&group);
+        auto precondState = std::any_of(
+            services.begin(),
+            services.end(),
+            [](const auto& s)
+            {
+                return !std::get<hasOwnerPos>(s);
+            });
+
+        if (precondState)
+        {
+            // Init the events when all the precondition(s) are true
+            std::for_each(
+                sse.begin(),
+                sse.end(),
+                [&zone](auto const& entry)
+                {
+                    zone.initEvent(entry);
+                });
+        }
+        else
+        {
+            // Unsubscribe the events' signals when any precondition is false
+            std::for_each(
+                sse.begin(),
+                sse.end(),
+                [&zone](auto const& entry)
+                {
+                    zone.removeEvent(entry);
+                });
+        }
+    };
+}
+
 } // namespace precondition
 } // namespace control
 } // namespace fan