1fb35a325SMatt Spinler #pragma once
2fb35a325SMatt Spinler 
3fb35a325SMatt Spinler #include <sdbusplus/bus.hpp>
4fb35a325SMatt Spinler #include <sdbusplus/bus/match.hpp>
5fb35a325SMatt Spinler 
6fb35a325SMatt Spinler namespace phosphor
7fb35a325SMatt Spinler {
8fb35a325SMatt Spinler namespace button
9fb35a325SMatt Spinler {
10fb35a325SMatt Spinler 
11fb35a325SMatt Spinler /**
12fb35a325SMatt Spinler  * @class Handler
13fb35a325SMatt Spinler  *
14fb35a325SMatt Spinler  * This class acts on the signals generated by the
15fb35a325SMatt Spinler  * xyz.openbmc_project.Chassis.Buttons code when
16fb35a325SMatt Spinler  * it detects button presses.
17fb35a325SMatt Spinler  *
18fb35a325SMatt Spinler  * There are 3 buttons supported - Power, ID, and Reset.
19fb35a325SMatt Spinler  * As not all systems may implement each button, this class will
20fb35a325SMatt Spinler  * check for that button on D-Bus before listening for its signals.
21fb35a325SMatt Spinler  */
22fb35a325SMatt Spinler class Handler
23fb35a325SMatt Spinler {
24fb35a325SMatt Spinler   public:
25fb35a325SMatt Spinler     Handler() = delete;
26fb35a325SMatt Spinler     ~Handler() = default;
27fb35a325SMatt Spinler     Handler(const Handler&) = delete;
28fb35a325SMatt Spinler     Handler& operator=(const Handler&) = delete;
29fb35a325SMatt Spinler     Handler(Handler&&) = delete;
30fb35a325SMatt Spinler     Handler& operator=(Handler&&) = delete;
31fb35a325SMatt Spinler 
32fb35a325SMatt Spinler     /**
33fb35a325SMatt Spinler      * @brief Constructor
34fb35a325SMatt Spinler      *
35fb35a325SMatt Spinler      * @param[in] bus - sdbusplus connection object
36fb35a325SMatt Spinler      */
37fb35a325SMatt Spinler     Handler(sdbusplus::bus::bus& bus);
38fb35a325SMatt Spinler 
39fb35a325SMatt Spinler   private:
40fb35a325SMatt Spinler     /**
41963c65f3SMatt Spinler      * @brief The handler for a power button press
42963c65f3SMatt Spinler      *
43963c65f3SMatt Spinler      * It will power on the system if it's currently off,
44963c65f3SMatt Spinler      * else it will soft power it off.
45963c65f3SMatt Spinler      *
46963c65f3SMatt Spinler      * @param[in] msg - sdbusplus message from signal
47963c65f3SMatt Spinler      */
48963c65f3SMatt Spinler     void powerPressed(sdbusplus::message::message& msg);
49963c65f3SMatt Spinler 
50963c65f3SMatt Spinler     /**
51963c65f3SMatt Spinler      * @brief The handler for a long power button press
52963c65f3SMatt Spinler      *
53963c65f3SMatt Spinler      * If the system is currently powered on, it will
54963c65f3SMatt Spinler      * perform an immediate power off.
55963c65f3SMatt Spinler      *
56963c65f3SMatt Spinler      * @param[in] msg - sdbusplus message from signal
57963c65f3SMatt Spinler      */
58963c65f3SMatt Spinler     void longPowerPressed(sdbusplus::message::message& msg);
59963c65f3SMatt Spinler 
60963c65f3SMatt Spinler     /**
61*06a5bddfSMatt Spinler      * @brief The handler for a reset button press
62*06a5bddfSMatt Spinler      *
63*06a5bddfSMatt Spinler      * Reboots the host if it is powered on.
64*06a5bddfSMatt Spinler      *
65*06a5bddfSMatt Spinler      * @param[in] msg - sdbusplus message from signal
66*06a5bddfSMatt Spinler      */
67*06a5bddfSMatt Spinler     void resetPressed(sdbusplus::message::message& msg);
68*06a5bddfSMatt Spinler 
69*06a5bddfSMatt Spinler     /**
70963c65f3SMatt Spinler      * @brief Checks if system is powered on
71963c65f3SMatt Spinler      *
72963c65f3SMatt Spinler      * @return true if powered on, false else
73963c65f3SMatt Spinler      */
74963c65f3SMatt Spinler     bool poweredOn() const;
75963c65f3SMatt Spinler 
76963c65f3SMatt Spinler     /**
77963c65f3SMatt Spinler      * @brief Returns the service name for an object
78963c65f3SMatt Spinler      *
79963c65f3SMatt Spinler      * @param[in] path - the object path
80963c65f3SMatt Spinler      * @param[in] interface - the interface name
81963c65f3SMatt Spinler      *
82963c65f3SMatt Spinler      * @return std::string - the D-Bus service name if found, else
83963c65f3SMatt Spinler      *                       an empty string
84963c65f3SMatt Spinler      */
85963c65f3SMatt Spinler     std::string getService(const std::string& path,
86963c65f3SMatt Spinler                            const std::string& interface) const;
87963c65f3SMatt Spinler 
88963c65f3SMatt Spinler     /**
89fb35a325SMatt Spinler      * @brief sdbusplus connection object
90fb35a325SMatt Spinler      */
91fb35a325SMatt Spinler     sdbusplus::bus::bus& bus;
92963c65f3SMatt Spinler 
93963c65f3SMatt Spinler     /**
94963c65f3SMatt Spinler      * @brief Matches on the power button released signal
95963c65f3SMatt Spinler      */
96963c65f3SMatt Spinler     std::unique_ptr<sdbusplus::bus::match_t> powerButtonReleased;
97963c65f3SMatt Spinler 
98963c65f3SMatt Spinler     /**
99963c65f3SMatt Spinler      * @brief Matches on the power button long press released signal
100963c65f3SMatt Spinler      */
101963c65f3SMatt Spinler     std::unique_ptr<sdbusplus::bus::match_t> powerButtonLongPressReleased;
102*06a5bddfSMatt Spinler 
103*06a5bddfSMatt Spinler     /**
104*06a5bddfSMatt Spinler      * @brief Matches on the reset button released signal
105*06a5bddfSMatt Spinler      */
106*06a5bddfSMatt Spinler     std::unique_ptr<sdbusplus::bus::match_t> resetButtonReleased;
107fb35a325SMatt Spinler };
108fb35a325SMatt Spinler 
109fb35a325SMatt Spinler } // namespace button
110fb35a325SMatt Spinler } // namespace phosphor
111