William A. Kennington III | 5257525 | 2018-02-09 15:54:56 -0800 | [diff] [blame] | 1 | #pragma once |
Vernon Mauery | 6a98fe7 | 2019-03-11 15:57:48 -0700 | [diff] [blame] | 2 | #include <ipmid/utils.hpp> |
William A. Kennington III | 5257525 | 2018-02-09 15:54:56 -0800 | [diff] [blame] | 3 | #include <sdbusplus/bus.hpp> |
William A. Kennington III | b638de2 | 2018-02-09 16:12:53 -0800 | [diff] [blame] | 4 | #include <xyz/openbmc_project/State/Watchdog/server.hpp> |
William A. Kennington III | 5257525 | 2018-02-09 15:54:56 -0800 | [diff] [blame] | 5 | |
| 6 | /** @class WatchdogService |
| 7 | * @brief Access to the running OpenBMC watchdog implementation. |
| 8 | * @details Easy accessor for servers that implement the |
| 9 | * xyz.openbmc_project.State.Watchdog DBus API. |
| 10 | */ |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 11 | class WatchdogService |
| 12 | { |
| 13 | public: |
| 14 | WatchdogService(); |
William A. Kennington III | 5257525 | 2018-02-09 15:54:56 -0800 | [diff] [blame] | 15 | |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 16 | using Action = |
| 17 | sdbusplus::xyz::openbmc_project::State::server::Watchdog::Action; |
Yong Li | 118907e | 2019-01-11 17:36:17 +0800 | [diff] [blame] | 18 | using TimerUse = |
| 19 | sdbusplus::xyz::openbmc_project::State::server::Watchdog::TimerUse; |
William A. Kennington III | b638de2 | 2018-02-09 16:12:53 -0800 | [diff] [blame] | 20 | |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 21 | /** @brief Resets the time remaining on the watchdog. |
| 22 | * Equivalent to setTimeRemaining(getInterval()). |
| 23 | * Optionally enables the watchdog. |
| 24 | * |
| 25 | * @param[in] enableWatchdog - Should the call also enable the watchdog |
| 26 | */ |
| 27 | void resetTimeRemaining(bool enableWatchdog); |
William A. Kennington III | 4b017a9 | 2018-04-27 14:31:08 -0700 | [diff] [blame] | 28 | |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 29 | /** @brief Contains a copy of the properties enumerated by the |
| 30 | * watchdog service. |
| 31 | */ |
| 32 | struct Properties |
| 33 | { |
| 34 | bool initialized; |
| 35 | bool enabled; |
| 36 | Action expireAction; |
Yong Li | 118907e | 2019-01-11 17:36:17 +0800 | [diff] [blame] | 37 | TimerUse timerUse; |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 38 | uint64_t interval; |
| 39 | uint64_t timeRemaining; |
| 40 | }; |
William A. Kennington III | 5257525 | 2018-02-09 15:54:56 -0800 | [diff] [blame] | 41 | |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 42 | /** @brief Retrieves a copy of the currently set properties on the |
| 43 | * host watchdog |
| 44 | * |
| 45 | * @return A populated WatchdogProperties struct |
| 46 | */ |
| 47 | Properties getProperties(); |
William A. Kennington III | 5257525 | 2018-02-09 15:54:56 -0800 | [diff] [blame] | 48 | |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 49 | /** @brief Get the value of the initialized property on the host |
| 50 | * watchdog |
| 51 | * |
| 52 | * @return The value of the property |
| 53 | */ |
| 54 | bool getInitialized(); |
William A. Kennington III | 2ecf512 | 2018-04-27 14:31:51 -0700 | [diff] [blame] | 55 | |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 56 | /** @brief Sets the value of the initialized property on the host |
| 57 | * watchdog |
| 58 | * |
| 59 | * @param[in] initialized - The new initializedvalue |
| 60 | */ |
| 61 | void setInitialized(bool initialized); |
William A. Kennington III | de14a02 | 2018-02-09 16:11:18 -0800 | [diff] [blame] | 62 | |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 63 | /** @brief Sets the value of the enabled property on the host watchdog |
| 64 | * |
| 65 | * @param[in] enabled - The new enabled value |
| 66 | */ |
| 67 | void setEnabled(bool enabled); |
William A. Kennington III | 5257525 | 2018-02-09 15:54:56 -0800 | [diff] [blame] | 68 | |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 69 | /** @brief Sets the value of the expireAction property on the host watchdog |
| 70 | * |
| 71 | * @param[in] expireAction - The new expireAction value |
| 72 | */ |
| 73 | void setExpireAction(Action expireAction); |
William A. Kennington III | b638de2 | 2018-02-09 16:12:53 -0800 | [diff] [blame] | 74 | |
Yong Li | 118907e | 2019-01-11 17:36:17 +0800 | [diff] [blame] | 75 | /** @brief Sets the value of the timerUse property on the host watchdog |
| 76 | * |
| 77 | * @param[in] timerUse - The new timerUse value |
| 78 | */ |
| 79 | void setTimerUse(TimerUse timerUse); |
| 80 | |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 81 | /** @brief Sets the value of the interval property on the host watchdog |
| 82 | * |
| 83 | * @param[in] interval - The new interval value |
| 84 | */ |
| 85 | void setInterval(uint64_t interval); |
William A. Kennington III | 5257525 | 2018-02-09 15:54:56 -0800 | [diff] [blame] | 86 | |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 87 | /** @brief Sets the value of the timeRemaining property on the host |
| 88 | * watchdog |
| 89 | * |
| 90 | * @param[in] timeRemaining - The new timeRemaining value |
| 91 | */ |
| 92 | void setTimeRemaining(uint64_t timeRemaining); |
William A. Kennington III | 5257525 | 2018-02-09 15:54:56 -0800 | [diff] [blame] | 93 | |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 94 | private: |
| 95 | /** @brief sdbusplus handle */ |
| 96 | sdbusplus::bus::bus bus; |
| 97 | /** @brief The name of the mapped host watchdog service */ |
| 98 | static ipmi::ServiceCache wd_service; |
William A. Kennington III | 5257525 | 2018-02-09 15:54:56 -0800 | [diff] [blame] | 99 | |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 100 | /** @brief Gets the value of the property on the host watchdog |
| 101 | * |
| 102 | * @param[in] key - The name of the property |
| 103 | * @return The value of the property |
| 104 | */ |
| 105 | template <typename T> |
| 106 | T getProperty(const std::string& key); |
William A. Kennington III | 2ecf512 | 2018-04-27 14:31:51 -0700 | [diff] [blame] | 107 | |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 108 | /** @brief Sets the value of the property on the host watchdog |
| 109 | * |
| 110 | * @param[in] key - The name of the property |
| 111 | * @param[in] val - The new value |
| 112 | */ |
| 113 | template <typename T> |
| 114 | void setProperty(const std::string& key, const T& val); |
William A. Kennington III | 5257525 | 2018-02-09 15:54:56 -0800 | [diff] [blame] | 115 | }; |