| 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 = | 
| Willy Tu | 523e2d1 | 2023-09-05 11:36:48 -0700 | [diff] [blame] | 17 | sdbusplus::server::xyz::openbmc_project::state::Watchdog::Action; | 
| Yong Li | 118907e | 2019-01-11 17:36:17 +0800 | [diff] [blame] | 18 | using TimerUse = | 
| Willy Tu | 523e2d1 | 2023-09-05 11:36:48 -0700 | [diff] [blame] | 19 | sdbusplus::server::xyz::openbmc_project::state::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; | 
| Deepak Kumar Sahu | cfae948 | 2019-05-20 14:58:58 +0000 | [diff] [blame] | 38 | TimerUse expiredTimerUse; | 
| 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 |  | 
| Tim Chao | 65362f4 | 2023-11-14 14:47:25 +0800 | [diff] [blame] | 70 | /** @brief Sets the value of the LogTimeout property on the host watchdog | 
|  | 71 | * | 
|  | 72 | *  @param[in] LogTimeout - The new LogTimeout value | 
|  | 73 | */ | 
|  | 74 | void setLogTimeout(bool LogTimeout); | 
|  | 75 |  | 
| Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 76 | /** @brief Sets the value of the expireAction property on the host watchdog | 
|  | 77 | * | 
|  | 78 | *  @param[in] expireAction - The new expireAction value | 
|  | 79 | */ | 
|  | 80 | void setExpireAction(Action expireAction); | 
| William A. Kennington III | b638de2 | 2018-02-09 16:12:53 -0800 | [diff] [blame] | 81 |  | 
| Yong Li | 118907e | 2019-01-11 17:36:17 +0800 | [diff] [blame] | 82 | /** @brief Sets the value of the timerUse property on the host watchdog | 
|  | 83 | * | 
|  | 84 | *  @param[in] timerUse - The new timerUse value | 
|  | 85 | */ | 
|  | 86 | void setTimerUse(TimerUse timerUse); | 
|  | 87 |  | 
| Deepak Kumar Sahu | cfae948 | 2019-05-20 14:58:58 +0000 | [diff] [blame] | 88 | /** @brief Sets the value of the ExpiredTimerUse property on the host | 
|  | 89 | * watchdog | 
|  | 90 | * | 
|  | 91 | *  @param[in] timerUse - The new timerUse value | 
|  | 92 | */ | 
|  | 93 | void setExpiredTimerUse(TimerUse timerUse); | 
|  | 94 |  | 
| Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 95 | /** @brief Sets the value of the interval property on the host watchdog | 
|  | 96 | * | 
|  | 97 | *  @param[in] interval - The new interval value | 
|  | 98 | */ | 
|  | 99 | void setInterval(uint64_t interval); | 
| 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 | private: | 
|  | 102 | /** @brief sdbusplus handle */ | 
| Patrick Williams | 5d82f47 | 2022-07-22 19:26:53 -0500 | [diff] [blame] | 103 | sdbusplus::bus_t bus; | 
| Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 104 | /** @brief The name of the mapped host watchdog service */ | 
| George Liu | 311d8e8 | 2025-03-12 08:48:19 +0800 | [diff] [blame] | 105 | static ipmi::ServiceCache wdService; | 
| William A. Kennington III | 5257525 | 2018-02-09 15:54:56 -0800 | [diff] [blame] | 106 |  | 
| Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 107 | /** @brief Gets the value of the property on the host watchdog | 
|  | 108 | * | 
|  | 109 | *  @param[in] key - The name of the property | 
|  | 110 | *  @return The value of the property | 
|  | 111 | */ | 
|  | 112 | template <typename T> | 
|  | 113 | T getProperty(const std::string& key); | 
| William A. Kennington III | 2ecf512 | 2018-04-27 14:31:51 -0700 | [diff] [blame] | 114 |  | 
| Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 115 | /** @brief Sets the value of the property on the host watchdog | 
|  | 116 | * | 
|  | 117 | *  @param[in] key - The name of the property | 
|  | 118 | *  @param[in] val - The new value | 
|  | 119 | */ | 
|  | 120 | template <typename T> | 
|  | 121 | void setProperty(const std::string& key, const T& val); | 
| William A. Kennington III | 5257525 | 2018-02-09 15:54:56 -0800 | [diff] [blame] | 122 | }; |