led-layout: use common types everywhere
Rather than scattered map and set typedefs, centralize the two common
structures into 'ledlayout.hpp': ActionSet, GroupMap. Use them
everywhere where previous raw maps and sets were used.
Signed-off-by: Patrick Williams <patrick@stwcx.xyz>
Change-Id: I0ed5203146a6486a49caf4000f545ded0088dc15
diff --git a/manager/group.cpp b/manager/group.cpp
index 33c64f6..d728f2b 100644
--- a/manager/group.cpp
+++ b/manager/group.cpp
@@ -2,6 +2,8 @@
#include "group.hpp"
+#include "ledlayout.hpp"
+
#include <sdbusplus/message.hpp>
namespace phosphor
{
@@ -28,8 +30,8 @@
}
// Introducing these to enable gtest.
- Manager::group ledsAssert{};
- Manager::group ledsDeAssert{};
+ ActionSet ledsAssert{};
+ ActionSet ledsDeAssert{};
// Group management is handled by Manager. The populated leds* sets are not
// really used by production code. They are there to enable gtest for
diff --git a/manager/json-parser.hpp b/manager/json-parser.hpp
index 06fb096..e8819ef 100644
--- a/manager/json-parser.hpp
+++ b/manager/json-parser.hpp
@@ -15,8 +15,6 @@
namespace fs = std::filesystem;
using Json = nlohmann::json;
-using LedAction = std::set<phosphor::led::Layout::LedAction>;
-using LedMap = std::unordered_map<std::string, LedAction>;
// Priority for a particular LED needs to stay SAME across all groups
// phosphor::led::Layout::Action can only be one of `Blink` and `On`
@@ -101,11 +99,11 @@
/** @brief Load JSON config and return led map (JSON version 1)
*
- * @return LedMap - Generated an std::unordered_map of LedAction
+ * @return phosphor::led::GroupMap
*/
-const LedMap loadJsonConfigV1(const Json& json)
+const phosphor::led::GroupMap loadJsonConfigV1(const Json& json)
{
- LedMap ledMap{};
+ phosphor::led::GroupMap ledMap{};
PriorityMap priorityMap{};
// define the default JSON as empty
@@ -119,7 +117,7 @@
auto objpath = tmpPath.string();
auto members = entry.value("members", empty);
- LedAction ledActions{};
+ phosphor::led::ActionSet ledActions{};
for (const auto& member : members)
{
auto name = member.value("Name", "");
@@ -149,9 +147,9 @@
/** @brief Load JSON config and return led map
*
- * @return LedMap - Generated an std::unordered_map of LedAction
+ * @return phosphor::led::GroupMap
*/
-const LedMap loadJsonConfig(const fs::path& path)
+const phosphor::led::GroupMap loadJsonConfig(const fs::path& path)
{
auto json = readJson(path);
@@ -167,18 +165,18 @@
throw std::runtime_error("Unsupported version");
}
- return LedMap{};
+ return phosphor::led::GroupMap{};
}
/** @brief Get led map from LED groups JSON config
*
* @param[in] config - Path to the JSON config.
- * @return LedMap - Generated an std::unordered_map of LedAction
+ * @return phosphor::led::GroupMap
*
* @note if config is an empty string, daemon will interrogate dbus for
* compatible strings.
*/
-const LedMap getSystemLedMap(fs::path config)
+const phosphor::led::GroupMap getSystemLedMap(fs::path config)
{
if (config.empty())
{
diff --git a/manager/lamptest/lamptest.cpp b/manager/lamptest/lamptest.cpp
index 2c93333..99d0318 100644
--- a/manager/lamptest/lamptest.cpp
+++ b/manager/lamptest/lamptest.cpp
@@ -11,8 +11,8 @@
using Json = nlohmann::json;
-bool LampTest::processLEDUpdates(const Manager::group& ledsAssert,
- const Manager::group& ledsDeAssert)
+bool LampTest::processLEDUpdates(const ActionSet& ledsAssert,
+ const ActionSet& ledsDeAssert)
{
// If the physical LED status is updated during the lamp test, it should be
// saved to Queue, and the queue will be processed after the lamp test is
@@ -232,7 +232,7 @@
void LampTest::restorePhysicalLedStates()
{
// restore physical LEDs states before lamp test
- Manager::group ledsDeAssert{};
+ ActionSet ledsDeAssert{};
manager.driveLEDs(physicalLEDStatesPriorToLampTest, ledsDeAssert);
physicalLEDStatesPriorToLampTest.clear();
diff --git a/manager/lamptest/lamptest.hpp b/manager/lamptest/lamptest.hpp
index d69667a..30d6eb2 100644
--- a/manager/lamptest/lamptest.hpp
+++ b/manager/lamptest/lamptest.hpp
@@ -64,8 +64,8 @@
*
* @return Is running lamp test, true running
*/
- bool processLEDUpdates(const Manager::group& ledsAssert,
- const Manager::group& ledsDeAssert);
+ bool processLEDUpdates(const ActionSet& ledsAssert,
+ const ActionSet& ledsDeAssert);
private:
/** @brief Timer used for LEDs lamp test period */
@@ -84,14 +84,13 @@
std::vector<std::string> physicalLEDPaths;
/** @brief Queue to save LED states during lamp test */
- std::queue<std::pair<Manager::group, Manager::group>>
- updatedLEDsDuringLampTest;
+ std::queue<std::pair<ActionSet, ActionSet>> updatedLEDsDuringLampTest;
/** @brief Get state of the lamp test operation */
bool isLampTestRunning{false};
/** @brief Physical LED states prior to lamp test */
- Manager::group physicalLEDStatesPriorToLampTest;
+ ActionSet physicalLEDStatesPriorToLampTest;
/** @brief Vector of names of physical LEDs, whose changes will be forcibly
* updated even during lamp test. */
diff --git a/manager/led-main.cpp b/manager/led-main.cpp
index 8861a64..a6f8f82 100644
--- a/manager/led-main.cpp
+++ b/manager/led-main.cpp
@@ -1,12 +1,12 @@
#include "config.h"
#include "group.hpp"
+#include "ledlayout.hpp"
#ifdef LED_USE_JSON
#include "json-parser.hpp"
#else
#include "led-gen.hpp"
#endif
-#include "ledlayout.hpp"
#include "manager.hpp"
#include "serialize.hpp"
#include "utils.hpp"
@@ -69,14 +69,11 @@
#endif
/** Now create so many dbus objects as there are groups */
- std::ranges::transform(
- systemLedMap, std::back_inserter(groups),
- [&bus, &manager, &serialize](
- const std::pair<std::string,
- std::set<phosphor::led::Layout::LedAction>>& grp) {
- return std::make_unique<phosphor::led::Group>(bus, grp.first,
- manager, serialize);
- });
+ std::ranges::transform(systemLedMap, std::back_inserter(groups),
+ [&bus, &manager, &serialize](auto& grp) {
+ return std::make_unique<phosphor::led::Group>(
+ bus, grp.first, manager, serialize);
+ });
// Attach the bus to sd_event to service user requests
bus.attach_event(event.get(), SD_EVENT_PRIORITY_NORMAL);
diff --git a/manager/ledlayout.hpp b/manager/ledlayout.hpp
index 3424606..7fc896d 100644
--- a/manager/ledlayout.hpp
+++ b/manager/ledlayout.hpp
@@ -49,5 +49,9 @@
}
};
} // namespace Layout
+
+using ActionSet = std::set<Layout::LedAction>;
+using GroupMap = std::unordered_map<std::string, ActionSet>;
+
} // namespace led
} // namespace phosphor
diff --git a/manager/manager.cpp b/manager/manager.cpp
index 998f22d..12f507a 100644
--- a/manager/manager.cpp
+++ b/manager/manager.cpp
@@ -16,7 +16,7 @@
// Assert -or- De-assert
bool Manager::setGroupState(const std::string& path, bool assert,
- group& ledsAssert, group& ledsDeAssert)
+ ActionSet& ledsAssert, ActionSet& ledsDeAssert)
{
if (assert)
{
@@ -30,8 +30,8 @@
}
}
- // This will contain the union of what's already in the asserted group
- group desiredState{};
+ // This will contain the union of what's already in the asserted ActionSet
+ ActionSet desiredState{};
for (const auto& grp : assertedGroups)
{
desiredState.insert(grp->cbegin(), grp->cend());
@@ -39,7 +39,7 @@
// Find difference between Combined and Desired to identify
// which LEDs are getting altered
- group transient{};
+ ActionSet transient{};
std::set_difference(combinedState.begin(), combinedState.end(),
desiredState.begin(), desiredState.end(),
std::inserter(transient, transient.begin()), ledComp);
@@ -47,7 +47,7 @@
{
// Find common LEDs between transient and Desired to know if some LEDs
// are changing state and not really getting DeAsserted
- group ledsTransient{};
+ ActionSet ledsTransient{};
std::set_intersection(
transient.begin(), transient.end(), desiredState.begin(),
desiredState.end(),
@@ -79,7 +79,7 @@
// Now LEDs that are to be Asserted. These could either be fresh asserts
// -or- change between [On]<-->[Blink]
- group temp{};
+ ActionSet temp{};
std::unique_copy(desiredState.begin(), desiredState.end(),
std::inserter(temp, temp.begin()), ledEqual);
if (temp.size())
@@ -100,13 +100,14 @@
}
void Manager::setLampTestCallBack(
- std::function<bool(group& ledsAssert, group& ledsDeAssert)> callBack)
+ std::function<bool(ActionSet& ledsAssert, ActionSet& ledsDeAssert)>
+ callBack)
{
lampTestCallBack = callBack;
}
/** @brief Run through the map and apply action on the LEDs */
-void Manager::driveLEDs(group& ledsAssert, group& ledsDeAssert)
+void Manager::driveLEDs(ActionSet& ledsAssert, ActionSet& ledsDeAssert)
{
#ifdef USE_LAMP_TEST
// Use the lampTestCallBack method and trigger the callback method in the
diff --git a/manager/manager.hpp b/manager/manager.hpp
index 88875d1..2fbc7f2 100644
--- a/manager/manager.hpp
+++ b/manager/manager.hpp
@@ -68,18 +68,15 @@
return left.name == right.name;
}
- using group = std::set<phosphor::led::Layout::LedAction>;
- using LedLayout = std::unordered_map<std::string, group>;
-
/** @brief static global map constructed at compile time */
- const LedLayout& ledMap;
+ const GroupMap& ledMap;
/** @brief Refer the user supplied LED layout and sdbusplus handler
*
* @param [in] bus - sdbusplus handler
- * @param [in] LedLayout - LEDs group layout
+ * @param [in] GroupMap - LEDs group layout
*/
- Manager(sdbusplus::bus::bus& bus, const LedLayout& ledLayout) :
+ Manager(sdbusplus::bus::bus& bus, const GroupMap& ledLayout) :
ledMap(ledLayout), bus(bus)
{
// Nothing here
@@ -95,8 +92,8 @@
*
* @return - Success or exception thrown
*/
- bool setGroupState(const std::string& path, bool assert, group& ledsAssert,
- group& ledsDeAssert);
+ bool setGroupState(const std::string& path, bool assert,
+ ActionSet& ledsAssert, ActionSet& ledsDeAssert);
/** @brief Finds the set of LEDs to operate on and executes action
*
@@ -106,7 +103,7 @@
*
* @return: None
*/
- void driveLEDs(group& ledsAssert, group& ledsDeAssert);
+ void driveLEDs(ActionSet& ledsAssert, ActionSet& ledsDeAssert);
/** @brief Chooses appropriate action to be triggered on physical LED
* and calls into function that applies the actual action.
@@ -124,7 +121,8 @@
* @param[in] callBack - Custom callback when enabled lamp test
*/
void setLampTestCallBack(
- std::function<bool(group& ledsAssert, group& ledsDeAssert)> callBack);
+ std::function<bool(ActionSet& ledsAssert, ActionSet& ledsDeAssert)>
+ callBack);
private:
/** @brief sdbusplus handler */
@@ -137,18 +135,18 @@
DBusHandler dBusHandler;
/** @brief Pointers to groups that are in asserted state */
- std::set<const group*> assertedGroups;
+ std::set<const ActionSet*> assertedGroups;
/** @brief Contains the highest priority actions for all
* asserted LEDs.
*/
- group currentState;
+ ActionSet currentState;
/** @brief Contains the set of all actions for asserted LEDs */
- group combinedState;
+ ActionSet combinedState;
/** @brief Custom callback when enabled lamp test */
- std::function<bool(group& ledsAssert, group& ledsDeAssert)>
+ std::function<bool(ActionSet& ledsAssert, ActionSet& ledsDeAssert)>
lampTestCallBack;
/** @brief Returns action string based on enum