convert sysfs gpio usage to libgpiod

Updated Fan presence sensor monitoring call back
to use pin name and gpiod APIs. Number based sysfs
framework is deprecated and replaced by descriptor
based gpiod framework. With named gpio pin,
code is more portable provided the device tree
defines GPIO pin name consistently.

This requires device tree change (225598) and
configuration file change (entity-manager/+/28119)

Tested By:
remove and insert fans and observe fan presence
status change on dbus fan sensor objects

Signed-off-by: Zhikui Ren <zhikui.ren@intel.com>
Change-Id: Ice17a472285373ce866132ccc0da02cd1e70ddbe
diff --git a/src/FanMain.cpp b/src/FanMain.cpp
index fdd0295..3a3175f 100644
--- a/src/FanMain.cpp
+++ b/src/FanMain.cpp
@@ -159,6 +159,7 @@
                     {
                         continue;
                     }
+
                     auto findIndex = baseConfiguration->second.find("Index");
                     if (findIndex == baseConfiguration->second.end())
                     {
@@ -214,6 +215,7 @@
                 }
 
                 auto findSensorName = baseConfiguration->second.find("Name");
+
                 if (findSensorName == baseConfiguration->second.end())
                 {
                     std::cerr << "could not determine configuration name for "
@@ -222,6 +224,7 @@
                 }
                 std::string sensorName =
                     std::get<std::string>(findSensorName->second);
+
                 // on rescans, only update sensors we were signaled by
                 auto findSensor = tachSensors.find(sensorName);
                 if (!firstScan && findSensor != tachSensors.end())
@@ -258,21 +261,30 @@
                 // presence sensors are optional
                 if (presenceConfig != sensorData->end())
                 {
-                    auto findIndex = presenceConfig->second.find("Index");
                     auto findPolarity = presenceConfig->second.find("Polarity");
+                    auto findPinName = presenceConfig->second.find("PinName");
 
-                    if (findIndex == presenceConfig->second.end() ||
+                    if (findPinName == presenceConfig->second.end() ||
                         findPolarity == presenceConfig->second.end())
                     {
                         std::cerr << "Malformed Presence Configuration\n";
                     }
                     else
                     {
-                        size_t index = std::get<uint64_t>(findIndex->second);
                         bool inverted = std::get<std::string>(
                                             findPolarity->second) == "Low";
-                        presenceSensor = std::make_unique<PresenceSensor>(
-                            index, inverted, io, sensorName);
+                        if (auto pinName =
+                                std::get_if<std::string>(&findPinName->second))
+                        {
+                            presenceSensor = std::make_unique<PresenceSensor>(
+                                *pinName, inverted, io, sensorName);
+                        }
+                        else
+                        {
+                            std::cerr
+                                << "Malformed Presence pinName for sensor "
+                                << sensorName << " \n";
+                        }
                     }
                 }
                 std::optional<RedundancySensor>* redundancy = nullptr;