manager: refactor loadJsonConfigV1 function

Extract 2 functions to have a 1:1 mapping between the json object being
parsed and the function doing the parsing.

This will also enable testing these functions individually and allow for
easy expansion of the config parser.

Change-Id: I0475c582aeac11538ec2d81c86fcf3819d9a220d
Signed-off-by: Alexander Hansen <alexander.hansen@9elements.com>
diff --git a/manager/json-parser.hpp b/manager/json-parser.hpp
index 05f1a6d..47f0d00 100644
--- a/manager/json-parser.hpp
+++ b/manager/json-parser.hpp
@@ -95,6 +95,54 @@
     }
 }
 
+static void loadJsonConfigV1GroupMember(const Json& member,
+                                        PriorityMap& priorityMap,
+                                        phosphor::led::ActionSet& ledActions)
+{
+    auto name = member.value("Name", "");
+    auto action = getAction(member.value("Action", ""));
+    uint8_t dutyOn = member.value("DutyOn", 50);
+    uint16_t period = member.value("Period", 0);
+
+    // Since only have Blink/On and default priority is Blink
+    auto priority = getAction(member.value("Priority", "Blink"));
+
+    // Same LEDs can be part of multiple groups. However, their
+    // priorities across groups need to match.
+    validatePriority(name, priority, priorityMap);
+
+    phosphor::led::Layout::LedAction ledAction{name, action, dutyOn, period,
+                                               priority};
+    ledActions.emplace(ledAction);
+}
+
+static void loadJsonConfigV1Group(const Json& entry,
+                                  phosphor::led::GroupMap& ledMap,
+                                  PriorityMap& priorityMap)
+{
+    const Json empty{};
+
+    fs::path tmpPath("/xyz/openbmc_project/led/groups");
+
+    const std::string groupName = entry.value("group", "");
+
+    tmpPath /= groupName;
+    auto objpath = tmpPath.string();
+    auto members = entry.value("members", empty);
+
+    lg2::debug("config for '{GROUP}'", "GROUP", groupName);
+
+    phosphor::led::ActionSet ledActions{};
+    for (const auto& member : members)
+    {
+        loadJsonConfigV1GroupMember(member, priorityMap, ledActions);
+    }
+
+    // Generated an std::unordered_map of LedGroupNames to std::set of LEDs
+    // containing the name and properties.
+    ledMap.emplace(objpath, ledActions);
+}
+
 /** @brief Load JSON config and return led map (JSON version 1)
  *
  *  @return phosphor::led::GroupMap
@@ -110,34 +158,7 @@
 
     for (const auto& entry : leds)
     {
-        fs::path tmpPath("/xyz/openbmc_project/led/groups");
-        tmpPath /= entry.value("group", "");
-        auto objpath = tmpPath.string();
-        auto members = entry.value("members", empty);
-
-        phosphor::led::ActionSet ledActions{};
-        for (const auto& member : members)
-        {
-            auto name = member.value("Name", "");
-            auto action = getAction(member.value("Action", ""));
-            uint8_t dutyOn = member.value("DutyOn", 50);
-            uint16_t period = member.value("Period", 0);
-
-            // Since only have Blink/On and default priority is Blink
-            auto priority = getAction(member.value("Priority", "Blink"));
-
-            // Same LEDs can be part of multiple groups. However, their
-            // priorities across groups need to match.
-            validatePriority(name, priority, priorityMap);
-
-            phosphor::led::Layout::LedAction ledAction{name, action, dutyOn,
-                                                       period, priority};
-            ledActions.emplace(ledAction);
-        }
-
-        // Generated an std::unordered_map of LedGroupNames to std::set of LEDs
-        // containing the name and properties.
-        ledMap.emplace(objpath, ledActions);
+        loadJsonConfigV1Group(entry, ledMap, priorityMap);
     }
 
     return ledMap;