config: implement group priority

Enable group priority.

Change-Id: I1777906e60d07420835ede904785071ee308c307
Signed-off-by: Alexander Hansen <alexander.hansen@9elements.com>
diff --git a/manager/manager.cpp b/manager/manager.cpp
index ec02419..18d257b 100644
--- a/manager/manager.cpp
+++ b/manager/manager.cpp
@@ -37,16 +37,33 @@
 }
 
 // create the resulting new map from all currently asserted groups
-auto Manager::getNewMap(std::set<const ActionSet*> assertedGroups)
+static auto getNewMapWithGroupPriorities(
+    std::set<const Layout::GroupLayout*, Layout::CompareGroupLayout> sorted)
     -> std::map<LedName, Layout::LedAction>
 {
     std::map<LedName, Layout::LedAction> newState;
 
     // update the new map with the desired state
-    for (const auto it : assertedGroups)
+    for (const auto it : sorted)
     {
         // apply all led actions of that group to the map
-        for (auto action : *it)
+        for (Layout::LedAction action : it->actionSet)
+        {
+            newState[action.name] = action;
+        }
+    }
+    return newState;
+}
+
+static std::map<LedName, Layout::LedAction> getNewMapWithLEDPriorities(
+    std::set<const Layout::GroupLayout*> assertedGroups)
+{
+    std::map<LedName, Layout::LedAction> newState;
+    // update the new map with the desired state
+    for (const Layout::GroupLayout* it : assertedGroups)
+    {
+        // apply all led actions of that group to the map
+        for (Layout::LedAction action : it->actionSet)
         {
             applyGroupAction(newState, action);
         }
@@ -54,6 +71,38 @@
     return newState;
 }
 
+// create the resulting new map from all currently asserted groups
+std::map<LedName, Layout::LedAction>
+    Manager::getNewMap(std::set<const Layout::GroupLayout*> assertedGroups)
+{
+    std::map<LedName, Layout::LedAction> newState;
+
+    std::set<const Layout::GroupLayout*, Layout::CompareGroupLayout> sorted;
+
+    bool groupPriorities = false;
+
+    for (const Layout::GroupLayout* it : assertedGroups)
+    {
+        sorted.insert(it);
+
+        if (it->priority != 0)
+        {
+            groupPriorities = true;
+        }
+    }
+
+    if (groupPriorities)
+    {
+        newState = getNewMapWithGroupPriorities(sorted);
+    }
+    else
+    {
+        newState = getNewMapWithLEDPriorities(assertedGroups);
+    }
+
+    return newState;
+}
+
 // Assert -or- De-assert
 bool Manager::setGroupState(const std::string& path, bool assert,
                             ActionSet& ledsAssert, ActionSet& ledsDeAssert)