Fix for sensor labeling

In case when more than one item is available for the same type of sensor
and the same channel number, only one dbus sensor was created instead of
few.

This change fixes this shortcoming by adding the ‘item’ suffix to the sensor
label and allowing to distinguish created sensors from each other for
different items. In case of 'input' item the suffix is omitted.

For example, when 3 items are available like: power1 _average, power1 _cap,
power1 _input and the name file contains text ‘Power’, before this change
only one sensor will be created under name:

    |-/xyz/openbmc_project/sensors/power/Power_CPU1

After this change a 3 separate sensors will be created:

    |-/xyz/openbmc_project/sensors/power/Power_Average_CPU1
    |-/xyz/openbmc_project/sensors/power/Power_Cap_CPU1
    |-/xyz/openbmc_project/sensors/power/Power_CPU1

With this commit the name of each sensor will follow the title convention,
where each word starts with upper case.

Tested:
    Tested manually with different items for the same sensor reading.

Signed-off-by: Zbigniew Kurzynski <zbigniew.kurzynski@intel.com>
Change-Id: I981d216e92fbee3b2a45a251e3359e6d41923b7d
diff --git a/src/CPUSensorMain.cpp b/src/CPUSensorMain.cpp
index 0ee9ea7..2261af7 100644
--- a/src/CPUSensorMain.cpp
+++ b/src/CPUSensorMain.cpp
@@ -102,6 +102,36 @@
     boost::container::flat_set<CPUConfig>& cpuConfigs,
     ManagedObjectType& sensorConfigs);
 
+std::string createSensorName(const std::string& label, const std::string& item,
+                             const int& cpuId)
+{
+    std::string sensorName = label;
+    if (item.compare("input") != 0)
+    {
+        sensorName += " " + item;
+    }
+    sensorName += " CPU" + std::to_string(cpuId);
+    // converting to Upper Camel case whole name
+    bool isWordEnd = true;
+    std::transform(sensorName.begin(), sensorName.end(), sensorName.begin(),
+                   [&isWordEnd](int c) {
+                       if (std::isspace(c))
+                       {
+                           isWordEnd = true;
+                       }
+                       else
+                       {
+                           if (isWordEnd)
+                           {
+                               isWordEnd = false;
+                               return std::toupper(c);
+                           }
+                       }
+                       return c;
+                   });
+    return sensorName;
+}
+
 bool createSensors(boost::asio::io_service& io,
                    sdbusplus::asio::object_server& objectServer,
                    std::shared_ptr<sdbusplus::asio::connection>& dbusConnection,
@@ -296,7 +326,7 @@
             std::getline(labelFile, label);
             labelFile.close();
 
-            std::string sensorName = label + " CPU" + std::to_string(cpuId);
+            std::string sensorName = createSensorName(label, item, cpuId);
 
             auto findSensor = gCpuSensors.find(sensorName);
             if (findSensor != gCpuSensors.end())