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; |
William A. Kennington III | b638de2 | 2018-02-09 16:12:53 -0800 | [diff] [blame] | 19 | |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 20 | /** @brief Resets the time remaining on the watchdog. |
| 21 | * Equivalent to setTimeRemaining(getInterval()). |
| 22 | * Optionally enables the watchdog. |
| 23 | * |
| 24 | * @param[in] enableWatchdog - Should the call also enable the watchdog |
| 25 | */ |
| 26 | void resetTimeRemaining(bool enableWatchdog); |
William A. Kennington III | 4b017a9 | 2018-04-27 14:31:08 -0700 | [diff] [blame] | 27 | |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 28 | /** @brief Contains a copy of the properties enumerated by the |
| 29 | * watchdog service. |
| 30 | */ |
| 31 | struct Properties |
| 32 | { |
| 33 | bool initialized; |
| 34 | bool enabled; |
| 35 | Action expireAction; |
| 36 | uint64_t interval; |
| 37 | uint64_t timeRemaining; |
| 38 | }; |
William A. Kennington III | 5257525 | 2018-02-09 15:54:56 -0800 | [diff] [blame] | 39 | |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 40 | /** @brief Retrieves a copy of the currently set properties on the |
| 41 | * host watchdog |
| 42 | * |
| 43 | * @return A populated WatchdogProperties struct |
| 44 | */ |
| 45 | Properties getProperties(); |
William A. Kennington III | 5257525 | 2018-02-09 15:54:56 -0800 | [diff] [blame] | 46 | |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 47 | /** @brief Get the value of the initialized property on the host |
| 48 | * watchdog |
| 49 | * |
| 50 | * @return The value of the property |
| 51 | */ |
| 52 | bool getInitialized(); |
William A. Kennington III | 2ecf512 | 2018-04-27 14:31:51 -0700 | [diff] [blame] | 53 | |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 54 | /** @brief Sets the value of the initialized property on the host |
| 55 | * watchdog |
| 56 | * |
| 57 | * @param[in] initialized - The new initializedvalue |
| 58 | */ |
| 59 | void setInitialized(bool initialized); |
William A. Kennington III | de14a02 | 2018-02-09 16:11:18 -0800 | [diff] [blame] | 60 | |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 61 | /** @brief Sets the value of the enabled property on the host watchdog |
| 62 | * |
| 63 | * @param[in] enabled - The new enabled value |
| 64 | */ |
| 65 | void setEnabled(bool enabled); |
William A. Kennington III | 5257525 | 2018-02-09 15:54:56 -0800 | [diff] [blame] | 66 | |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 67 | /** @brief Sets the value of the expireAction property on the host watchdog |
| 68 | * |
| 69 | * @param[in] expireAction - The new expireAction value |
| 70 | */ |
| 71 | void setExpireAction(Action expireAction); |
William A. Kennington III | b638de2 | 2018-02-09 16:12:53 -0800 | [diff] [blame] | 72 | |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 73 | /** @brief Sets the value of the interval property on the host watchdog |
| 74 | * |
| 75 | * @param[in] interval - The new interval value |
| 76 | */ |
| 77 | void setInterval(uint64_t interval); |
William A. Kennington III | 5257525 | 2018-02-09 15:54:56 -0800 | [diff] [blame] | 78 | |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 79 | /** @brief Sets the value of the timeRemaining property on the host |
| 80 | * watchdog |
| 81 | * |
| 82 | * @param[in] timeRemaining - The new timeRemaining value |
| 83 | */ |
| 84 | void setTimeRemaining(uint64_t timeRemaining); |
William A. Kennington III | 5257525 | 2018-02-09 15:54:56 -0800 | [diff] [blame] | 85 | |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 86 | private: |
| 87 | /** @brief sdbusplus handle */ |
| 88 | sdbusplus::bus::bus bus; |
| 89 | /** @brief The name of the mapped host watchdog service */ |
| 90 | static ipmi::ServiceCache wd_service; |
William A. Kennington III | 5257525 | 2018-02-09 15:54:56 -0800 | [diff] [blame] | 91 | |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 92 | /** @brief Gets the value of the property on the host watchdog |
| 93 | * |
| 94 | * @param[in] key - The name of the property |
| 95 | * @return The value of the property |
| 96 | */ |
| 97 | template <typename T> |
| 98 | T getProperty(const std::string& key); |
William A. Kennington III | 2ecf512 | 2018-04-27 14:31:51 -0700 | [diff] [blame] | 99 | |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 100 | /** @brief Sets the value of the property on the host watchdog |
| 101 | * |
| 102 | * @param[in] key - The name of the property |
| 103 | * @param[in] val - The new value |
| 104 | */ |
| 105 | template <typename T> |
| 106 | void setProperty(const std::string& key, const T& val); |
William A. Kennington III | 5257525 | 2018-02-09 15:54:56 -0800 | [diff] [blame] | 107 | }; |