Only create buttons when their GPIOs are defined
Look in /etc/default/obmc/gpio/gpio_defs.json to see
if the GPIO for a button is defined, and only create
the button object if it is.
This is how a system implementer can specify which
button objects are needed for their particular system.
Change-Id: I359f87875b6bb5741fdf4718b30b0f5b4552a528
Signed-off-by: Matt Spinler <spinler@us.ibm.com>
diff --git a/inc/gpio.hpp b/inc/gpio.hpp
index 98df21b..ca83082 100644
--- a/inc/gpio.hpp
+++ b/inc/gpio.hpp
@@ -19,3 +19,10 @@
int configGpio(const char* gpioName, int* fd, sdbusplus::bus::bus& bus);
void closeGpio(int fd);
+bool gpioDefined(const std::string& gpioName);
+
+template <typename T>
+bool hasGpio()
+{
+ return gpioDefined(T::getGpioName());
+}
diff --git a/inc/id_button.hpp b/inc/id_button.hpp
index a5c4180..af100ef 100644
--- a/inc/id_button.hpp
+++ b/inc/id_button.hpp
@@ -70,6 +70,11 @@
void simPress() override;
+ static const char* getGpioName()
+ {
+ return ID_BUTTON;
+ }
+
static int EventHandler(sd_event_source* es, int fd, uint32_t revents,
void* userdata)
{
diff --git a/inc/power_button.hpp b/inc/power_button.hpp
index d00f1c6..e4cc660 100644
--- a/inc/power_button.hpp
+++ b/inc/power_button.hpp
@@ -71,6 +71,11 @@
void simPress() override;
void simLongPress() override;
+ static const char* getGpioName()
+ {
+ return POWER_BUTTON;
+ }
+
static int EventHandler(sd_event_source* es, int fd, uint32_t revents,
void* userdata)
{
diff --git a/inc/reset_button.hpp b/inc/reset_button.hpp
index b10f241..d0534e8 100644
--- a/inc/reset_button.hpp
+++ b/inc/reset_button.hpp
@@ -70,6 +70,11 @@
void simPress() override;
+ static const char* getGpioName()
+ {
+ return RESET_BUTTON;
+ }
+
static int EventHandler(sd_event_source* es, int fd, uint32_t revents,
void* userdata)
{