Add button-handler framework

This new application will listen for button press
signals generated by the xyz.openbmc_project.Chassis.Buttons
code and perform the necessary actions, like powering off
when the power button is pressed.

This first commit is just the framework, and all of the
functionality will follow.

Change-Id: Ia877684627b53e0fcc6f4b0b82063811e8ced6ea
Signed-off-by: Matt Spinler <spinler@us.ibm.com>
diff --git a/.gitignore b/.gitignore
index c8279f9..ac35ff1 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,4 +1,5 @@
 buttons
+button-handler
 CMakeFiles
 CMakeCache.txt
 cmake_install.cmake
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 790a95b..f5c3078 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -25,8 +25,12 @@
     src/gpio.cpp
 )
 
-option (
-    LOOKUP_GPIO_BASE
+set(HANDLER_SRC_FILES
+    src/button_handler_main.cpp
+    src/button_handler.cpp
+)
+
+option (LOOKUP_GPIO_BASE
     "Look up the GPIO base value in /sys/class/gpio. Otherwise use a base of 0." ON
 )
 
@@ -55,6 +59,9 @@
 add_executable(${PROJECT_NAME} ${SRC_FILES} )
 target_link_libraries(${PROJECT_NAME} "${SDBUSPLUSPLUS_LIBRARIES} -lphosphor_dbus  -lstdc++fs")
 
+add_executable(button-handler ${HANDLER_SRC_FILES})
+target_link_libraries(button-handler "${SDBUSPLUSPLUS_LIBRARIES} -lphosphor_dbus")
+
 set (
     SERVICE_FILES
     ${PROJECT_SOURCE_DIR}/service_files/xyz.openbmc_project.Chassis.Buttons.service
@@ -62,3 +69,4 @@
 
 install (FILES ${SERVICE_FILES} DESTINATION /lib/systemd/system/)
 install (TARGETS ${PROJECT_NAME} DESTINATION ${CMAKE_INSTALL_SBINDIR})
+install (TARGETS button-handler DESTINATION ${CMAKE_INSTALL_SBINDIR})
diff --git a/inc/button_handler.hpp b/inc/button_handler.hpp
new file mode 100644
index 0000000..4bc6310
--- /dev/null
+++ b/inc/button_handler.hpp
@@ -0,0 +1,47 @@
+#pragma once
+
+#include <sdbusplus/bus.hpp>
+#include <sdbusplus/bus/match.hpp>
+
+namespace phosphor
+{
+namespace button
+{
+
+/**
+ * @class Handler
+ *
+ * This class acts on the signals generated by the
+ * xyz.openbmc_project.Chassis.Buttons code when
+ * it detects button presses.
+ *
+ * There are 3 buttons supported - Power, ID, and Reset.
+ * As not all systems may implement each button, this class will
+ * check for that button on D-Bus before listening for its signals.
+ */
+class Handler
+{
+  public:
+    Handler() = delete;
+    ~Handler() = default;
+    Handler(const Handler&) = delete;
+    Handler& operator=(const Handler&) = delete;
+    Handler(Handler&&) = delete;
+    Handler& operator=(Handler&&) = delete;
+
+    /**
+     * @brief Constructor
+     *
+     * @param[in] bus - sdbusplus connection object
+     */
+    Handler(sdbusplus::bus::bus& bus);
+
+  private:
+    /**
+     * @brief sdbusplus connection object
+     */
+    sdbusplus::bus::bus& bus;
+};
+
+} // namespace button
+} // namespace phosphor
diff --git a/src/button_handler.cpp b/src/button_handler.cpp
new file mode 100644
index 0000000..e8edc41
--- /dev/null
+++ b/src/button_handler.cpp
@@ -0,0 +1,11 @@
+#include "button_handler.hpp"
+
+namespace phosphor
+{
+namespace button
+{
+Handler::Handler(sdbusplus::bus::bus& bus) : bus(bus)
+{
+}
+} // namespace button
+} // namespace phosphor
diff --git a/src/button_handler_main.cpp b/src/button_handler_main.cpp
new file mode 100644
index 0000000..e9fcc27
--- /dev/null
+++ b/src/button_handler_main.cpp
@@ -0,0 +1,15 @@
+#include "button_handler.hpp"
+
+int main(int argc, char* argv[])
+{
+    auto bus = sdbusplus::bus::new_default();
+
+    phosphor::button::Handler handler{bus};
+
+    while (true)
+    {
+        bus.process_discard();
+        bus.wait();
+    }
+    return 0;
+}