blob: 8056fb74a74fdeea8837c56c7f158f5d1b1702a6 [file] [log] [blame]
William A. Kennington III52575252018-02-09 15:54:56 -08001#pragma once
Patrick Venture0b02be92018-08-31 11:55:55 -07002#include "utils.hpp"
3
William A. Kennington III52575252018-02-09 15:54:56 -08004#include <sdbusplus/bus.hpp>
William A. Kennington IIIb638de22018-02-09 16:12:53 -08005#include <xyz/openbmc_project/State/Watchdog/server.hpp>
William A. Kennington III52575252018-02-09 15:54:56 -08006
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 Venture0b02be92018-08-31 11:55:55 -070012class WatchdogService
13{
14 public:
15 WatchdogService();
William A. Kennington III52575252018-02-09 15:54:56 -080016
Patrick Venture0b02be92018-08-31 11:55:55 -070017 using Action =
18 sdbusplus::xyz::openbmc_project::State::server::Watchdog::Action;
William A. Kennington IIIb638de22018-02-09 16:12:53 -080019
Patrick Venture0b02be92018-08-31 11:55:55 -070020 /** @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 III4b017a92018-04-27 14:31:08 -070027
Patrick Venture0b02be92018-08-31 11:55:55 -070028 /** @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 III52575252018-02-09 15:54:56 -080039
Patrick Venture0b02be92018-08-31 11:55:55 -070040 /** @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 III52575252018-02-09 15:54:56 -080046
Patrick Venture0b02be92018-08-31 11:55:55 -070047 /** @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 III2ecf5122018-04-27 14:31:51 -070053
Patrick Venture0b02be92018-08-31 11:55:55 -070054 /** @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 IIIde14a022018-02-09 16:11:18 -080060
Patrick Venture0b02be92018-08-31 11:55:55 -070061 /** @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 III52575252018-02-09 15:54:56 -080066
Patrick Venture0b02be92018-08-31 11:55:55 -070067 /** @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 IIIb638de22018-02-09 16:12:53 -080072
Patrick Venture0b02be92018-08-31 11:55:55 -070073 /** @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 III52575252018-02-09 15:54:56 -080078
Patrick Venture0b02be92018-08-31 11:55:55 -070079 /** @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 III52575252018-02-09 15:54:56 -080085
Patrick Venture0b02be92018-08-31 11:55:55 -070086 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 III52575252018-02-09 15:54:56 -080091
Patrick Venture0b02be92018-08-31 11:55:55 -070092 /** @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 III2ecf5122018-04-27 14:31:51 -070099
Patrick Venture0b02be92018-08-31 11:55:55 -0700100 /** @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 III52575252018-02-09 15:54:56 -0800107};