blob: dfc913a7000e9c83e6ac3cf6972d206b2bd9c5e2 [file] [log] [blame]
William A. Kennington III52575252018-02-09 15:54:56 -08001#pragma once
2#include <sdbusplus/bus.hpp>
William A. Kennington IIIb638de22018-02-09 16:12:53 -08003#include <xyz/openbmc_project/State/Watchdog/server.hpp>
William A. Kennington III52575252018-02-09 15:54:56 -08004
William A. Kennington III25bc7ac2018-03-15 11:48:41 -07005#include "utils.hpp"
6
William A. Kennington III52575252018-02-09 15:54:56 -08007/** @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 */
12class WatchdogService {
13 public:
14 WatchdogService();
15
William A. Kennington IIIb638de22018-02-09 16:12:53 -080016 using Action = sdbusplus::xyz::openbmc_project::State::server::Watchdog::Action;
17
William A. Kennington III4b017a92018-04-27 14:31:08 -070018 /** @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 III52575252018-02-09 15:54:56 -080026 /** @brief Contains a copy of the properties enumerated by the
27 * watchdog service.
28 */
29 struct Properties {
William A. Kennington IIIde14a022018-02-09 16:11:18 -080030 bool initialized;
William A. Kennington III52575252018-02-09 15:54:56 -080031 bool enabled;
William A. Kennington IIIb638de22018-02-09 16:12:53 -080032 Action expireAction;
William A. Kennington III52575252018-02-09 15:54:56 -080033 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 III2ecf5122018-04-27 14:31:51 -070044 /** @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 IIIde14a022018-02-09 16:11:18 -080051 /** @brief Sets the value of the initialized property on the host
William A. Kennington III2ecf5122018-04-27 14:31:51 -070052 * watchdog
William A. Kennington IIIde14a022018-02-09 16:11:18 -080053 *
54 * @param[in] initialized - The new initializedvalue
55 */
56 void setInitialized(bool initialized);
57
William A. Kennington III52575252018-02-09 15:54:56 -080058 /** @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 IIIb638de22018-02-09 16:12:53 -080064 /** @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 III52575252018-02-09 15:54:56 -080070 /** @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 III25bc7ac2018-03-15 11:48:41 -070087 static ipmi::ServiceCache wd_service;
William A. Kennington III52575252018-02-09 15:54:56 -080088
William A. Kennington III2ecf5122018-04-27 14:31:51 -070089 /** @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 III52575252018-02-09 15:54:56 -080097 /** @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};