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 | 5257525 | 2018-02-09 15:54:56 -0800 | [diff] [blame] | 18 | /** @brief Contains a copy of the properties enumerated by the |
| 19 | * watchdog service. |
| 20 | */ |
| 21 | struct Properties { |
William A. Kennington III | de14a02 | 2018-02-09 16:11:18 -0800 | [diff] [blame] | 22 | bool initialized; |
William A. Kennington III | 5257525 | 2018-02-09 15:54:56 -0800 | [diff] [blame] | 23 | bool enabled; |
William A. Kennington III | b638de2 | 2018-02-09 16:12:53 -0800 | [diff] [blame] | 24 | Action expireAction; |
William A. Kennington III | 5257525 | 2018-02-09 15:54:56 -0800 | [diff] [blame] | 25 | uint64_t interval; |
| 26 | uint64_t timeRemaining; |
| 27 | }; |
| 28 | |
| 29 | /** @brief Retrieves a copy of the currently set properties on the |
| 30 | * host watchdog |
| 31 | * |
| 32 | * @return A populated WatchdogProperties struct |
| 33 | */ |
| 34 | Properties getProperties(); |
| 35 | |
William A. Kennington III | de14a02 | 2018-02-09 16:11:18 -0800 | [diff] [blame] | 36 | /** @brief Sets the value of the initialized property on the host |
| 37 | * watchdog |
| 38 | * |
| 39 | * @param[in] initialized - The new initializedvalue |
| 40 | */ |
| 41 | void setInitialized(bool initialized); |
| 42 | |
William A. Kennington III | 5257525 | 2018-02-09 15:54:56 -0800 | [diff] [blame] | 43 | /** @brief Sets the value of the enabled property on the host watchdog |
| 44 | * |
| 45 | * @param[in] enabled - The new enabled value |
| 46 | */ |
| 47 | void setEnabled(bool enabled); |
| 48 | |
William A. Kennington III | b638de2 | 2018-02-09 16:12:53 -0800 | [diff] [blame] | 49 | /** @brief Sets the value of the expireAction property on the host watchdog |
| 50 | * |
| 51 | * @param[in] expireAction - The new expireAction value |
| 52 | */ |
| 53 | void setExpireAction(Action expireAction); |
| 54 | |
William A. Kennington III | 5257525 | 2018-02-09 15:54:56 -0800 | [diff] [blame] | 55 | /** @brief Sets the value of the interval property on the host watchdog |
| 56 | * |
| 57 | * @param[in] interval - The new interval value |
| 58 | */ |
| 59 | void setInterval(uint64_t interval); |
| 60 | |
| 61 | /** @brief Sets the value of the timeRemaining property on the host |
| 62 | * watchdog |
| 63 | * |
| 64 | * @param[in] timeRemaining - The new timeRemaining value |
| 65 | */ |
| 66 | void setTimeRemaining(uint64_t timeRemaining); |
| 67 | |
| 68 | private: |
| 69 | /** @brief sdbusplus handle */ |
| 70 | sdbusplus::bus::bus bus; |
| 71 | /** @brief The name of the mapped host watchdog service */ |
William A. Kennington III | 25bc7ac | 2018-03-15 11:48:41 -0700 | [diff] [blame] | 72 | static ipmi::ServiceCache wd_service; |
William A. Kennington III | 5257525 | 2018-02-09 15:54:56 -0800 | [diff] [blame] | 73 | |
| 74 | /** @brief Sets the value of the property on the host watchdog |
| 75 | * |
| 76 | * @param[in] key - The name of the property |
| 77 | * @param[in] val - The new value |
| 78 | */ |
| 79 | template <typename T> |
| 80 | void setProperty(const std::string& key, const T& val); |
| 81 | }; |