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