blob: ed64a3c7c4da5cee99f3f5e548e2866c968826c0 [file] [log] [blame]
William A. Kennington III52575252018-02-09 15:54:56 -08001#pragma once
Vernon Mauery6a98fe72019-03-11 15:57:48 -07002#include <ipmid/utils.hpp>
William A. Kennington III52575252018-02-09 15:54:56 -08003#include <sdbusplus/bus.hpp>
William A. Kennington IIIb638de22018-02-09 16:12:53 -08004#include <xyz/openbmc_project/State/Watchdog/server.hpp>
William A. Kennington III52575252018-02-09 15:54:56 -08005
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 Venture0b02be92018-08-31 11:55:55 -070011class WatchdogService
12{
13 public:
14 WatchdogService();
William A. Kennington III52575252018-02-09 15:54:56 -080015
Patrick Venture0b02be92018-08-31 11:55:55 -070016 using Action =
17 sdbusplus::xyz::openbmc_project::State::server::Watchdog::Action;
Yong Li118907e2019-01-11 17:36:17 +080018 using TimerUse =
19 sdbusplus::xyz::openbmc_project::State::server::Watchdog::TimerUse;
William A. Kennington IIIb638de22018-02-09 16:12:53 -080020
Patrick Venture0b02be92018-08-31 11:55:55 -070021 /** @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 III4b017a92018-04-27 14:31:08 -070028
Patrick Venture0b02be92018-08-31 11:55:55 -070029 /** @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 Li118907e2019-01-11 17:36:17 +080037 TimerUse timerUse;
Deepak Kumar Sahucfae9482019-05-20 14:58:58 +000038 TimerUse expiredTimerUse;
Patrick Venture0b02be92018-08-31 11:55:55 -070039 uint64_t interval;
40 uint64_t timeRemaining;
41 };
William A. Kennington III52575252018-02-09 15:54:56 -080042
Patrick Venture0b02be92018-08-31 11:55:55 -070043 /** @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 III52575252018-02-09 15:54:56 -080049
Patrick Venture0b02be92018-08-31 11:55:55 -070050 /** @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 III2ecf5122018-04-27 14:31:51 -070056
Patrick Venture0b02be92018-08-31 11:55:55 -070057 /** @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 IIIde14a022018-02-09 16:11:18 -080063
Patrick Venture0b02be92018-08-31 11:55:55 -070064 /** @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 III52575252018-02-09 15:54:56 -080069
Patrick Venture0b02be92018-08-31 11:55:55 -070070 /** @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 IIIb638de22018-02-09 16:12:53 -080075
Yong Li118907e2019-01-11 17:36:17 +080076 /** @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
Deepak Kumar Sahucfae9482019-05-20 14:58:58 +000082 /** @brief Sets the value of the ExpiredTimerUse property on the host
83 * watchdog
84 *
85 * @param[in] timerUse - The new timerUse value
86 */
87 void setExpiredTimerUse(TimerUse timerUse);
88
Patrick Venture0b02be92018-08-31 11:55:55 -070089 /** @brief Sets the value of the interval property on the host watchdog
90 *
91 * @param[in] interval - The new interval value
92 */
93 void setInterval(uint64_t interval);
William A. Kennington III52575252018-02-09 15:54:56 -080094
Patrick Venture0b02be92018-08-31 11:55:55 -070095 /** @brief Sets the value of the timeRemaining property on the host
96 * watchdog
97 *
98 * @param[in] timeRemaining - The new timeRemaining value
99 */
100 void setTimeRemaining(uint64_t timeRemaining);
William A. Kennington III52575252018-02-09 15:54:56 -0800101
Patrick Venture0b02be92018-08-31 11:55:55 -0700102 private:
103 /** @brief sdbusplus handle */
104 sdbusplus::bus::bus bus;
105 /** @brief The name of the mapped host watchdog service */
106 static ipmi::ServiceCache wd_service;
William A. Kennington III52575252018-02-09 15:54:56 -0800107
Patrick Venture0b02be92018-08-31 11:55:55 -0700108 /** @brief Gets the value of the property on the host watchdog
109 *
110 * @param[in] key - The name of the property
111 * @return The value of the property
112 */
113 template <typename T>
114 T getProperty(const std::string& key);
William A. Kennington III2ecf5122018-04-27 14:31:51 -0700115
Patrick Venture0b02be92018-08-31 11:55:55 -0700116 /** @brief Sets the value of the property on the host watchdog
117 *
118 * @param[in] key - The name of the property
119 * @param[in] val - The new value
120 */
121 template <typename T>
122 void setProperty(const std::string& key, const T& val);
William A. Kennington III52575252018-02-09 15:54:56 -0800123};