button-handler: Add power button actions
Create match handlers for the following power button signals:
1) 'Released'
* If the system is off, then power it on.
* If the system is on, then soft power it off.
2) 'PressedLong' (Really means long press released)
* If the system is on, do an immediate power off.
* If the system is off, do nothing.
It only installs the match objects for these if the power button
object exists on D-Bus. This is done so that systems that don't
implement a certain button won't still have watches on their
signals.
Tested: Pushed buttons and watched the magic happen.
Change-Id: I6d17529d0dafc237f90a0e6a121e4b5da1204f81
Signed-off-by: Matt Spinler <spinler@us.ibm.com>
diff --git a/inc/button_handler.hpp b/inc/button_handler.hpp
index 4bc6310..790bbe9 100644
--- a/inc/button_handler.hpp
+++ b/inc/button_handler.hpp
@@ -38,9 +38,58 @@
private:
/**
+ * @brief The handler for a power button press
+ *
+ * It will power on the system if it's currently off,
+ * else it will soft power it off.
+ *
+ * @param[in] msg - sdbusplus message from signal
+ */
+ void powerPressed(sdbusplus::message::message& msg);
+
+ /**
+ * @brief The handler for a long power button press
+ *
+ * If the system is currently powered on, it will
+ * perform an immediate power off.
+ *
+ * @param[in] msg - sdbusplus message from signal
+ */
+ void longPowerPressed(sdbusplus::message::message& msg);
+
+ /**
+ * @brief Checks if system is powered on
+ *
+ * @return true if powered on, false else
+ */
+ bool poweredOn() const;
+
+ /**
+ * @brief Returns the service name for an object
+ *
+ * @param[in] path - the object path
+ * @param[in] interface - the interface name
+ *
+ * @return std::string - the D-Bus service name if found, else
+ * an empty string
+ */
+ std::string getService(const std::string& path,
+ const std::string& interface) const;
+
+ /**
* @brief sdbusplus connection object
*/
sdbusplus::bus::bus& bus;
+
+ /**
+ * @brief Matches on the power button released signal
+ */
+ std::unique_ptr<sdbusplus::bus::match_t> powerButtonReleased;
+
+ /**
+ * @brief Matches on the power button long press released signal
+ */
+ std::unique_ptr<sdbusplus::bus::match_t> powerButtonLongPressReleased;
};
} // namespace button