Disable Debug card display for postcodes if no GPIO's.

Some platforms does not have GPIO pins for debug card display. It
will throw error and will not proceed furthur process. In this
case, postcode display and selector position related code can be
skipped to disabled the 7seg debug card display alone for
postcodes.

It will not affect other process like postcode display in dbus,
etc.

TESTED : Verified multi host postcodes are displaying in the dbus
for Facebook YosemiteV35 and YosemiteV2.

Signed-off-by: Kumar Thangavel <thangavel.k@hcl.com>
Change-Id: Iaa0aeec394523e1d62037650439ac60dc2488a77
diff --git a/ipmisnoop/ipmisnoop.hpp b/ipmisnoop/ipmisnoop.hpp
index 39a35e9..7e4fb46 100644
--- a/ipmisnoop/ipmisnoop.hpp
+++ b/ipmisnoop/ipmisnoop.hpp
@@ -20,6 +20,8 @@
 const int maxPostcode = 255;
 const int maxPosition = 4;
 
+bool sevenSegmentLedEnabled = true;
+
 std::vector<gpiod::line> led_lines;
 
 using Selector =
@@ -55,8 +57,8 @@
     }
     catch (const sdbusplus::exception_t& ex)
     {
-        std::cerr << "GetProperty call failed ";
-        throw std::runtime_error("GetProperty call failed");
+        std::cerr << "GetProperty call failed. " << ex.what() << std::endl;
+        return 0;
     }
 }
 
@@ -73,6 +75,16 @@
                 using secondarycode_t = std::vector<uint8_t>;
                 using postcode_t = std::tuple<primarycode_t, secondarycode_t>;
 
+                /* sevenSegmentLedEnabled flag is set when GPIO pins are not
+                there 7 seg display for fewer platforms. So, the code for
+                postcode dispay and Get Selector position can be skipped in
+                those platforms.
+                */
+                if (!sevenSegmentLedEnabled)
+                {
+                    return;
+                }
+
                 std::string objectName;
                 std::string InterfaceName;
                 std::map<std::string, std::variant<postcode_t>> msgData;
@@ -153,6 +165,11 @@
         {
             std::string errMsg = "Failed to find the " + gpioStr + " line";
             std::cerr << errMsg.c_str() << std::endl;
+
+            /* sevenSegmentLedEnabled flag is unset when GPIO pins are not there
+             * 7 seg display for fewer platforms.
+             */
+            sevenSegmentLedEnabled = false;
             return -1;
         }
 
diff --git a/main.cpp b/main.cpp
index 94603d1..57897f9 100644
--- a/main.cpp
+++ b/main.cpp
@@ -176,7 +176,19 @@
         }
 
         bus.request_name(snoopDbus.c_str());
-        reporters[0]->getSelectorPositionSignal(bus);
+
+        /* sevenSegmentLedEnabled flag is unset when GPIO pins are not there 7
+        seg display for fewer platforms. So, the code for postcode dispay and
+        Get Selector position can be skipped in those platforms.
+        */
+        if (sevenSegmentLedEnabled)
+        {
+            reporters[0]->getSelectorPositionSignal(bus);
+        }
+        else
+        {
+            reporters.clear();
+        }
     }
     catch (const std::exception& e)
     {
@@ -187,7 +199,8 @@
     ret = configGPIODirOutput();
     if (ret < 0)
     {
-        fprintf(stderr, "Failed find the gpio line\n");
+        fprintf(stderr, "Failed find the gpio line. Cannot display postcodes "
+                        "in seven segment display..\n");
     }
 
     while (true)