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