Enable group gpio configuration

This change adds support to configure single
as well as group gpio config using a single api(configGroupGpio()).
This change is introduced to support the button/input
interfaces which has multiple gpios associated with them.

As an improvement reading of gpio def json file is
done once in main function rather than reading it
everytime before creating the button interface object.

Signed-off-by: Naveen Moses <naveen.mosess@hcl.com>
Change-Id: Ib73dda618c78fd2f14b5d3432fd04c9f4cd2dd9b
diff --git a/inc/power_button.hpp b/inc/power_button.hpp
index e71d9f1..283b149 100644
--- a/inc/power_button.hpp
+++ b/inc/power_button.hpp
@@ -33,17 +33,20 @@
 {
 
     PowerButton(sdbusplus::bus::bus& bus, const char* path, EventPtr& event,
+                buttonConfig& buttonCfg,
                 sd_event_io_handler_t handler = PowerButton::EventHandler) :
         sdbusplus::server::object::object<
             sdbusplus::xyz::openbmc_project::Chassis::Buttons::server::Power>(
             bus, path),
-        fd(-1), bus(bus), event(event), callbackHandler(handler)
+        fd(-1), buttonIFConfig(buttonCfg), bus(bus), event(event),
+        callbackHandler(handler)
     {
 
         int ret = -1;
 
-        // config gpio
-        ret = ::configGpio(POWER_BUTTON, &fd, bus);
+        // config group gpio based on the gpio defs read from the json file
+        ret = configGroupGpio(bus, buttonIFConfig);
+
         if (ret < 0)
         {
             phosphor::logging::log<phosphor::logging::level::ERR>(
@@ -52,6 +55,10 @@
                 IOError();
         }
 
+        // initialize the button io fd from the buttonConfig
+        // which has fd stored when configGroupGpio is called
+        fd = buttonIFConfig.gpios[0].fd;
+
         char buf;
         ::read(fd, &buf, sizeof(buf));
 
@@ -75,7 +82,7 @@
     void simPress() override;
     void simLongPress() override;
 
-    static const char* getGpioName()
+    static const std::string getGpioName()
     {
         return POWER_BUTTON;
     }
@@ -168,6 +175,7 @@
 
   private:
     int fd;
+    buttonConfig buttonIFConfig; // button iface io details
     sdbusplus::bus::bus& bus;
     EventPtr& event;
     sd_event_io_handler_t callbackHandler;