LEDS: Handle physical LED names containing hyphen
It is possible that LED names can contain hyphen(s) in them making it
inappropriate for announcing the name on dbus. Fix would be to
convert the hyphen to underscores just for announcing on dbus
while using the actual name for rest everything.
Fixes openbmc/openbmc#802
Change-Id: Ia916786e9abf948970b36242f57c27aa90d4a962
Signed-off-by: Vishwanatha Subbanna <vishwa@linux.vnet.ibm.com>
diff --git a/controller.cpp b/controller.cpp
index 4e83f58..d5728da 100644
--- a/controller.cpp
+++ b/controller.cpp
@@ -16,6 +16,7 @@
#include <iostream>
#include <string>
+#include <algorithm>
#include "argument.hpp"
#include "physical.hpp"
#include "config.h"
@@ -50,6 +51,14 @@
// Remove the leading "/"
auto name = path.substr(index + 1);
+ // Convert to lowercase just in case some are not and that
+ // we follow lowercase all over
+ std::transform(name.begin(), name.end(), name.begin(), ::tolower);
+
+ // LED names may have a hyphen and that would be an issue for
+ // dbus paths and hence need to convert them to underscores.
+ std::replace(name.begin(), name.end(), '-', '_');
+
// Unique bus name representing a single LED.
auto busName = std::string(BUSNAME) + '.' + name;
auto objPath = std::string(OBJPATH) + '/' + name;